/
index.php
314 lines (294 loc) · 11 KB
/
index.php
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<?php
/**
*
* @package MyPage
* @author PhuocPham
* @copyright MyPage Team
* @link http://www.MyPage.vn
* @since Version 1.0
* @filesource
*
*/
$abspath = preg_replace('/\\\/', '/', dirname(__FILE__));
if (!file_exists($abspath . '/app/configs/config.php')) {
define('PF_VERSION', '1.0');
require $abspath . '/lib/functions.php';
redirect_to_install($abspath);
}
require $abspath . '/app/configs/config.php';
if(!defined('ADMIN_FOLDER')){
define('ADMIN_FOLDER','admin');
}
if(!defined('DB_PREFIX')){
define('DB_PREFIX','vi_');
}
session_name('MyPage' . sha1(__SECURITY_SALT__ . __SECURITY_CIPHER_SEED__));
@session_start();
require ABSPATH . '/lib/helper/url-helper.php';
require ABSPATH . '/lib/error-handler-class.php';
require ABSPATH . '/lib/pf-class.php';
require ABSPATH . '/lib/option.php';
require ABSPATH . '/lib/functions.php';
require ABSPATH . '/app/plugins/default/user/class/authentication/auth.php';
require ABSPATH . '/app/plugins/default/user/class/pf-user.php';
require ABSPATH . '/lib/plugin-class.php';
require ABSPATH . '/lib/File_Gettext/File/Gettext.php';
require ABSPATH . '/lib/File_Gettext/File/Gettext/MO.php';
require ABSPATH . '/lib/File_Gettext/File/Gettext/PO.php';
require ABSPATH . '/lib/helper/l10n-helper.php';
require ABSPATH . '/lib/helper/form-helper.php';
require_once ABSPATH . '/lib/paginator-class.php';
require ABSPATH . '/lib/common/libs/image/simple_image.php';
// require mvc library
require ABSPATH . '/lib/mvc/pf-base-object.php';
require ABSPATH . '/lib/mvc/pf-session-class.php';
require ABSPATH . '/lib/mvc/pf-post-class.php';
require ABSPATH . '/lib/mvc/pf-get-class.php';
require ABSPATH . '/lib/mvc/pf-request-class.php';
require ABSPATH . '/lib/mvc/pf-controller-class.php';
require ABSPATH . '/lib/mvc/pf-shortcode-class.php';
require ABSPATH . '/lib/mvc/pf-widget-class.php';
require ABSPATH . '/lib/mvc/pf-model-class.php';
require ABSPATH . '/lib/mvc/pf-view-class.php';
global $pattern_templates;
global $_public_css;
global $_public_js;
if (is_null(Pf::auth()->get_session("user-id")) && Pf::auth()->check_cookie("id")) {
set_session(Pf::auth()->get_cookie("id"));
}
/**
* Blocking Blacklist
*/
$blacklist = get_option('ip_blacklist');
$arr = explode("\n",$blacklist);
if(in_array(get_client_ip(),$arr)){
exit("Thank you for visiting our website but your IP has been banned!");
}
/**
* Configuration
*/
$setting = Pf::setting();
define('DEFAULT_LOCALE', get_configuration('site_language'));
define('HTML_LANGUAGE', $setting->get_element_value('general', 'html_language'));
define('NUM_PER_PAGE', get_configuration('items_per_page'));
date_default_timezone_set(get_configuration('time_zone'));
if (get_configuration('enable_log') == 1) {
new Pf_Error_Handler();
}
/*
* lang
*/
global $locale;
$locale = (!empty($_GET ['lang'])) ? $_GET ['lang'] : DEFAULT_LOCALE;
$_SESSION['lang'] = $locale;
load_includes_language();
/*
* Charset
* */
$charset = get_configuration('charset_html');
$exception = false;
//Check site offline
if (get_configuration('site_offline') && !(!empty($_POST) && _get('ajax') == '1') && !is_admin()) {
$url = $_GET['pf_page_url'] = get_page_url_by_id(get_configuration('site_offline_page'));
$reqUrl = $url;
$exception = 'pf-default-site-offline';
} else {
// Get page url.
$reqUrl = $_SERVER ['REQUEST_URI'];
if (strpos($reqUrl, '/index.php') !== false) {
$reqUrl = substr($reqUrl, strlen(RELATIVE_PATH . '/index.php/'), strlen($reqUrl) + 1);
} else {
$reqUrl = substr($reqUrl, strlen(RELATIVE_PATH . '/'), strlen($reqUrl));
}
if (get_configuration('accessibility') == 'onlymember' && !is_login()) {
$allow_reg = get_configuration("allow_reg","pf_user");
$register = ($allow_reg == 1 && preg_match('/\buser\/user-action:register\b/i',$reqUrl));
$forgot = (preg_match('/\buser\/user-action:forgot\b/i',$reqUrl));
$reset = (preg_match('/\buser\/user-page:reset\b/i',$reqUrl));
$activation = (preg_match('/\buser\/user-page:activation\b/i',$reqUrl));
if(!($register||$forgot||$reset||$activation)){
$_GET['ref'] = $reqUrl;
$reqUrl = 'user';
}
}
if (strpos($reqUrl, '?') !== false) {
$reqUrl = explode('?', $reqUrl);
$reqUrl = $reqUrl[0];
}
$reqUrl = trim($reqUrl);
if (empty($reqUrl)) {
// Set default page.
$page_default = get_page_url_by_id(get_configuration('default_page'));
if (trim($page_default) != '') {
$reqUrl = $page_default;
}
$exception = 'pf-default-homepage';
}
$reqs = explode('/', $reqUrl);
$reqUrl = '';
$slash = '';
$page_flag = true;
if (count($reqs) > 0) {
foreach ($reqs as $v) {
if (trim($v) != '') {
$rs = explode(':', $v);
if (count($rs) == 2) {
$page_flag = false;
$_GET[$rs[0]] = $rs[1];
if (!empty($_REQUEST[$rs[0]])) {
$_REQUEST[$rs[0]] = $_GET[$rs[0]];
}
}else if (count($rs) == 1 && $page_flag == true){
$reqUrl .= $slash.$rs[0];
$slash = '/';
}
}
}
}
$_GET['pf_page_url'] = $reqUrl;
}
// get page
$db = Pf::database();
$db->select('*', ''.DB_PREFIX.'pages', 'page_url = ? and page_status = 1', array(
$reqUrl
), '', 1);
$rs = $db->fetch_assoc();
if (empty($rs)){
while (strripos($reqUrl, '/') !== false){
$reqUrl = substr($reqUrl, 0, strripos($reqUrl, '/'));
$db->select('*', ''.DB_PREFIX.'pages', 'page_url = ? and page_status = 1', array(
$reqUrl
), '', 1);
$rs = $db->fetch_assoc();
if (!empty($rs)){
break;
}
}
}
// Page not found. Get page error
if (empty($rs)) {
if ($exception !== false) {
$db->select('*', ''.DB_PREFIX.'pages', 'page_url = ? and page_status = 1', array(
$exception
), '', 1);
$rs = $db->fetch_assoc();
}
if (empty($rs)) {
$db->select('*', ''.DB_PREFIX.'pages', 'page_url = ? and page_status = 1', array(
get_page_url_by_id(get_configuration('error_page'))
), '', 1);
$rs = $db->fetch_assoc();
$exception = 'pf-default-error';
}
if (empty($rs)) {
$db->select('*', ''.DB_PREFIX.'pages', 'page_url = ? and page_status = 1', array(
$exception
), '', 1);
$rs = $db->fetch_assoc();
}
}
if (!empty($rs)) {
// Check visible page
if (!check_visible_page($rs['page_visible'])) {
header('Location: ' . public_base_url() . get_page_url_by_id(get_configuration('error_page')));
exit();
}
// Background
$background_data = json_decode($rs['page_theme_options'], true);
$background_option = !empty($background_data['background']) && (!empty($background_data['data']['color']) || !empty($background_data['data']['image'])) ? $background_data['background'] : '';
$wrapper_background = !empty($background_data['wrapper_background']) ? $background_data['wrapper_background'] : '';
// Set info head (Title, Keyword, Description)
$head_info = array(
'title' => get_configuration('site_name') .' - '.(!empty($rs['page_meta_title']) ? $rs['page_meta_title'] : ''),
'keywords' => !empty($rs['page_meta_keywords']) ? $rs['page_meta_keywords'] : get_configuration('site_meta_keywords'),
'description' => !empty($rs['page_meta_description']) ? $rs['page_meta_description'] : get_configuration('site_meta_description'),
'charset' => empty($charset) ? "utf-8" : $charset
);
set_head_info($head_info);
load_admin_plugins(DEFAULT_PLUGIN_PATH, 'public_init');
load_active_plugins('public_init');
if (is_ajax()) {
$tags = Pf::shortcode()->get_tags();
foreach ($tags as $ns => $tag) {
if (!empty($_GET[$ns . '_code'])) {
die(call_user_func($tag[$_GET[$ns . '_code']], $_REQUEST, null, $_GET[$ns . '_code']));
}
}
}
// get layout
$layout = array();
$layouts = get_option('layouts');
foreach ($layouts as $v) {
if ($v['id'] == $rs['page_layout']) {
$layout = $v;
break;
}
}
if (get_configuration('accessibility') == 'onlymember' && !is_login()) {
$layout = array(
'layout_name' => '',
'pattern' => 1,
'json_data' => '{}',
'setting_data' => Array
(
)
);
}
$widgets = array();
if (!empty($layout['json_data'])) {
$widgets = json_decode($layout['json_data'], true);
$active_widgets = get_option('active_widgets');
}
$setting_data = array();
if (!empty($layout['setting_data'])) {
$setting_data = $layout['setting_data'];
}
// get footer
$footer = get_option('footer');
$widgets_footer = array();
if (!empty($footer['json_data'])) {
$widgets_footer = json_decode($footer['json_data'], true);
}
$setting_footer = array();
if (!empty($footer['setting_data'])) {
$setting_footer = $footer['setting_data'];
}
// Check layout
if (!empty($layout)) {
// Get active theme
$theme = get_option('active_theme');
$layout ['layout_type'] = (isset($layout ['layout_type']))?$layout ['layout_type']:'1';
// Check theme
if (is_file(ABSPATH . '/app/themes/' . $theme . '/' . $theme . '.php')) {
load_theme_language($theme . '-theme', '', $theme);
require ABSPATH . '/app/themes/' . $theme . '/' . $theme . '.php';
if (!empty($rs['page_content'])){
$rs['page_content'] = Pf::shortcode()->exec($rs['page_content']);
}
$html = null;
if (is_file(ABSPATH . '/app/themes/' . $theme . '/patterns.php') && $layout['pattern'] == 1) {
ob_start();
require ABSPATH . '/app/themes/' . $theme . '/patterns.php';
$html = ob_get_contents();
ob_get_clean();
}else if (is_file(ABSPATH . '/app/themes/' . $theme . '/index.php')) {
ob_start();
require ABSPATH . '/app/themes/' . $theme . '/index.php';
$html = ob_get_contents();
ob_get_clean();
}
if ($html !== null) {
echo load_css_js($html, $theme);
}else{
// Error: Pattern template not found.
}
} else {
// Error: Them not found
}
} else {
// Error: Layout not found
}
}
if (true === DEBUG) {
Pf::database()->show_debug_console();
}