-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathloader.php
More file actions
115 lines (106 loc) · 2.71 KB
/
loader.php
File metadata and controls
115 lines (106 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
* Configurations and includes loader
*
* @package Social Ninja
* @version 1.0
* @author InspiredDev <iamrock68@gmail.com>
* @copyright 2015
*/
/**
* start php session
*/
@session_start();
@ob_start();
/**
* check if config file exists otherwise redirect to setup
*/
if(!file_exists(dirname(__FILE__).'/config.php')){
header('location: setup');
exit();
}
/**
* load config file and other necessary files and settings
*/
include(dirname(__FILE__).'/functions.php');
include(dirname(__FILE__).'/config.php');
$mysqli = false;
$mysqli = sql_conn();
if(empty($mysqli)){
die("<h1>Mysql connection failed</h1>");
}
$settings = load_settings();
/**
* class autoloader register
*/
spl_autoload_register('spl_autoloader');
/**
* check authentication
*/
$user_id = 0;
$auth = new auth();
$user_data = $auth->check_login();
if(empty($user_data) || is_numeric($user_data)){
$user_data = array();
$is_logged_in = 0;
}
else{
$is_logged_in = 1;
$user_id = $_SESSION[SESSION_NAME];
load_app_settings($user_id);
}
/**
* check authentication requires or not and take actions accordingly
*/
if(!empty($login_required) && !$is_logged_in){
redirect('login.php?r='.base64_encode($_SERVER['REQUEST_URI']));
}
if(!empty($logout_required) && $is_logged_in){
redirect('dashboard.php');
}
if(!empty($admin_required)){
if(!$is_logged_in)redirect('login.php?r='.base64_encode($_SERVER['REQUEST_URI']));
else if(empty($user_data['is_admin']))redirect('dashboard.php');
}
/**
* Set timezone
*/
if(empty($user_data['time_zone'])){
date_default_timezone_set('UTC');
}
else{
date_default_timezone_set($user_data['time_zone']);
}
/**
* Set language
*/
$default_lang_exists = file_exists(dirname(__FILE__).'/lang/default.php');
if(!empty($_COOKIE['ninja_lang'])){
$lang_ok = 0;
if(!preg_match('/[^a-z0-9\_]/i', $_COOKIE['ninja_lang'])){
$lang_ok = list_lang_files($_COOKIE['ninja_lang']);
if($lang_ok){
require_once(dirname(__FILE__).'/lang/'.$_COOKIE['ninja_lang'].'.php');
}
}
if(!$lang_ok){
if($default_lang_exists)require_once(dirname(__FILE__).'/lang/default.php');
else require_once(dirname(__FILE__).'/lang/en.php');
}
}
else{
if($default_lang_exists)require_once(dirname(__FILE__).'/lang/default.php');
else require_once(dirname(__FILE__).'/lang/en.php');
}
sql_query("UPDATE users SET plan_id = 1 WHERE membership_expiry_time <= NOW() AND plan_id != 1");
$uri = $_SERVER['PHP_SELF'];
$is_index_page = 0;
$is_login_page = 0;
if(preg_match('/index\.php/i', $uri))$is_index_page = 1;
if(preg_match('/login\.php|logout\.php/i', $uri))$is_login_page = 1;
if(!empty($settings['enable_maintenance_mode'])){
if(!$is_index_page && !$is_login_page && empty($user_data['is_admin'])){
redirect(makeuri('index.php', 1));
}
}
?>