-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.php
244 lines (200 loc) · 8.71 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
<?php
//
// Copyright (C) 2006-2016 Next Generation CMS (http://ngcms.ru)
// Name: index.php
// Description: core index file
// Author: NGCMS project team
//
// Override charset
@header('content-type: text/html; charset=utf-8');
// Check for minimum supported PHP version
if (version_compare(PHP_VERSION, '7.2.0') < 0) {
@header('content-type: text/html; charset=utf-8');
echo "<html><head><title>NGCMS required PHP version 7.2+ / Необходима версия PHP 7.2 или выше</title></head><body><div style='font: 24px verdana; background-color: #EEEEEE; border: #ABCDEF 1px solid; margin: 1px; padding: 3px;'><span style='color: red;'>FATAL ERROR / Фатальная ошибка</span><br/><br/><span style=\"font: 16px arial;\"> NGCMS requires PHP version <b>7.2+</b><br/>Please ask your hosting provider to upgrade your account</span><br/><hr/><span style=\"font: 16px arial;\"> Для работы NGCMS требуется PHP версии <b>7.2</b> или выше.<br/>Обратитесь к вашему хостинг провайдеру для обновления версии</span></div></body></html>";
exit;
}
// Load CORE module
include_once 'engine/core.php';
/**
* @var $config
* @var $userROW
* @var $twig
* @var $timer
* @var $systemAccessURL
* @var $UHANDLER
* @var $EXTRA_CSS
* @var $mysql
* @var $tpl
* @var $SUPRESS_TEMPLATE_SHOW
* @var $SUPRESS_MAINBLOCK_SHOW
* @var $cron
*/
// Init GZip handler
initGZipHandler();
// Define default TITLE
$SYSTEM_FLAGS['info']['title'] = [];
$SYSTEM_FLAGS['info']['title']['header'] = home_title;
// Initialize main template array
$template = [
'vars' => [
'what' => engineName,
'version' => engineVersion,
'home' => home,
'titles' => home_title,
'home_title' => home_title,
'mainblock' => '',
'htmlvars' => '',
],
];
// ===================================================================
// Check if site access is locked [ for everyone except admins ]
// ===================================================================
if ($config['lock'] && (!is_array($userROW) || (!checkPermission(['plugin' => '#admin', 'item' => 'system'], null, 'lockedsite.view')))) {
// Generate sitelock.tpl instead of content page
if (!file_exists(tpl_site.'sitelock.tpl')) {
echo 'Site is disabled with reason: '.$config['lock_reason'];
} else {
$tVars = $template['vars'];
$tVars['lock_reason'] = $config['lock_reason'];
$xt = $twig->loadTemplate('sitelock.tpl');
echo $xt->render($tVars);
}
// STOP SCRIPT EXECUTION
exit;
}
// ===================================================================
// Start generating page
// ===================================================================
// External call: before executing URL handler
executeActionHandler('index_pre');
// Deactivate block [sitelock] ... [/sitelock]
$template['vars']['[sitelock]'] = '';
$template['vars']['[/sitelock]'] = '';
// /////////////////////////////////////////////////////////// //
// You may modify variable $systemAccessURL here (for hacks) //
// /////////////////////////////////////////////////////////// //
// /////////////////////////////////////////////////////////// //
$timer->registerEvent('Search route for URL "'.$systemAccessURL.'"');
// Give domainName to URL handler engine for generating absolute links
$UHANDLER->setOptions(['domainPrefix' => $config['home_url']]);
// Check if engine is installed in subdirectory
if (preg_match('#^http\:\/\/([^\/])+(\/.+)#', $config['home_url'], $match)) {
$UHANDLER->setOptions(['localPrefix' => $match[2]]);
}
$runResult = $UHANDLER->run($systemAccessURL, ['debug' => false]);
// [[MARKER]] URL handler execution is finished
$timer->registerEvent('URL handler execution is finished');
// Generate fatal 404 error [NOT FOUND] if URL handler didn't found any task for execution
if (!$runResult) {
error404();
}
// External call: after executing URL handler
executeActionHandler('index');
// ===================================================================
// Generate additional informational blocks
// ===================================================================
$timer->registerEvent('General plugins execution is finished');
// Generate category menu
$template['vars']['categories'] = generateCategoryMenu();
$timer->registerEvent('Category menu created');
// Generate page title
$template['vars']['titles'] = implode(' : ', array_values($SYSTEM_FLAGS['info']['title']));
// Generate user menu
coreUserMenu();
// Generate search form
coreSearchForm();
// Save 'category' variable
$template['vars']['category'] = (isset($_REQUEST['category']) && ($_REQUEST['category'] != '')) ? secure_html($_REQUEST['category']) : '';
// ====================================================================
// External call: All variables for main template are generated
// ===================================================================
executeActionHandler('index_post');
// ===================================================================
// Prepare JS/CSS/RSS references
// Make empty OLD STYLE variables
$template['vars']['metatags'] = '';
$template['vars']['extracss'] = '';
// Fill extra CSS links
foreach ($EXTRA_CSS as $css => $null) {
$EXTRA_HTML_VARS[] = ['type' => 'css', 'data' => $css];
}
// Generate metatags
$EXTRA_HTML_VARS[] = ['type' => 'plain', 'data' => GetMetatags()];
// Fill additional HTML vars
$htmlrow = [];
$dupCheck = [];
foreach ($EXTRA_HTML_VARS as $htmlvar) {
// Skip empty
if (!$htmlvar['data']) {
continue;
}
// Check for duplicated rows
if (in_array($htmlvar['data'], $dupCheck)) {
continue;
}
$dupCheck[] = $htmlvar['data'];
switch ($htmlvar['type']) {
case 'css':
$htmlrow[] = '<link href="'.$htmlvar['data'].'" rel="stylesheet" type="text/css" />';
break;
case 'js':
$htmlrow[] = '<script type="text/javascript" src="'.$htmlvar['data'].'"></script>';
break;
case 'rss':
$htmlrow[] = '<link href="'.$htmlvar['data'].'" rel="alternate" type="application/rss+xml" title="RSS" />';
break;
case 'plain':
$htmlrow[] = $htmlvar['data'];
break;
}
}
if (count($htmlrow)) {
$template['vars']['htmlvars'] .= implode("\n", $htmlrow);
}
// Add support of blocks [is-logged] .. [/isnt-logged] in main template
$template['regx']['#\[is-logged\](.+?)\[/is-logged\]#is'] = is_array($userROW) ? '$1' : '';
$template['regx']['#\[isnt-logged\](.+?)\[/isnt-logged\]#is'] = is_array($userROW) ? '' : '$1';
// ***** EXECUTION TIME CATCH POINT *****
// Calculate script execution time
$template['vars']['queries'] = $mysql->qcnt();
$template['vars']['exectime'] = $timer->stop();
// Fill debug information (if it is requested)
if ($config['debug']) {
$timer->registerEvent('Templates generation time: '.$tpl->execTime.' ('.$tpl->execCount.' times called)');
$timer->registerEvent('Generate DEBUG output');
if (checkPermission(['plugin' => '#admin', 'item' => 'system'], $userROW, 'debug.view')) {
$template['vars']['debug_queries'] = ($config['debug_queries']) ? ('<b><u>SQL queries:</u></b><br>'.implode("<br />\n", $mysql->query_list).'<br />') : '';
$template['vars']['debug_profiler'] = ($config['debug_profiler']) ? ('<b><u>Time profiler:</u></b>'.$timer->printEvents(1).'<br />') : '';
$template['vars']['[debug]'] = '';
$template['vars']['[/debug]'] = '';
} else {
$template['regx']["#\[debug\].*?\[/debug\]#si"] = '';
}
}
// ===================================================================
// Generate template for main page
// ===================================================================
// 0. Calculate memory PEAK usage
$template['vars']['memPeakUsage'] = sprintf('%7.3f', (memory_get_peak_usage() / 1024 / 1024));
// 1. Determine template name & path
$mainTemplateName = isset($SYSTEM_FLAGS['template.main.name']) ? $SYSTEM_FLAGS['template.main.name'] : 'main';
$mainTemplatePath = isset($SYSTEM_FLAGS['template.main.path']) ? $SYSTEM_FLAGS['template.main.path'] : tpl_site;
// 2. Load & show template
$tpl->template($mainTemplateName, $mainTemplatePath);
$tpl->vars($mainTemplateName, $template);
if (!$SUPRESS_TEMPLATE_SHOW) {
printHTTPheaders();
echo $tpl->show($mainTemplateName);
} elseif (!$SUPRESS_MAINBLOCK_SHOW) {
printHTTPheaders();
echo $template['vars']['mainblock'];
}
// ===================================================================
// Maintanance activities
// ===================================================================
// Close opened sessions to avoid blocks
session_write_close();
// Run CRON
$cron->run();
// Terminate execution of script
coreNormalTerminate();