forked from sergejey/majordomo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
135 lines (105 loc) · 3.05 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
<?php
/**
* Main project script
*
* @package MajorDoMo
* @author Serge Dzheigalo <[email protected]>
* @url http://smartliving.ru
* @version 1.2
*/
include_once("./lib/perfmonitor.class.php");
startMeasure('TOTAL');
include_once("./config.php");
include_once("./lib/loader.php");
// start calculation of execution time
startMeasure('prepare');
include_once(DIR_MODULES . "application.class.php");
$session = new session("prj");
startMeasure('load_settings');
include_once("./load_settings.php");
endMeasure('load_settings');
$use_caching = 0;
$cache_expire = 60 * 60; // 60 minutes cache expiration time
$cached_result = '';
$req_url = $_SERVER['REQUEST_URI'];
if ($req_url == '/')
$req_url = '/index.html';
if ($use_caching && preg_match('/^\/([\/\w_-]+)\.html$/', $req_url, $matches) && $_SERVER['REQUEST_METHOD'] != 'POST')
{
$cache_filename = preg_replace('/\W/', '_', $matches[1]) . '.html';
if (file_exists(ROOT . 'cms/cached/' . $cache_filename))
{
if ((time() - filemtime(ROOT . 'cms/cached/' . $cache_filename)) <= $cache_expire)
{
$cached_result = LoadFile(ROOT . 'cms/cached/' . $cache_filename);
}
else
{
unlink(ROOT . 'cms/cached/' . $cache_filename);
}
}
}
endMeasure('prepare');
if ($cached_result == '')
{
if (!file_exists(ROOT . 'cms/modules_installed/control_modules.installed'))
{
include_once(DIR_MODULES . "control_modules/control_modules.class.php");
$ctl = new control_modules();
}
$app = new application();
if ($md != $app->name)
$app->restoreParams();
else
$app->getParams();
if ($app->action != '' && $app->action != 'docs')
$fake_doc = '';
$result = $app->run();
$result = str_replace("nf.php", "index.php", $result);
}
else
{
// show cached result
$result = $cached_result;
}
require(ROOT.'lib/utils/postprocess_general.inc.php');
require(ROOT.'lib/utils/postprocess_subscriptions.inc.php');
require(ROOT.'lib/utils/postprocess_result.inc.php');
/**
* Echo large text
* @param mixed $string Text
* @param mixed $bufferSize Buffer size
* @return void
*/
function echobig($string, $bufferSize = 8192)
{
$chars = strlen($string) - 1;
for ($start = 0; $start <= $chars; $start += $bufferSize)
{
echo substr($string,$start,$bufferSize);
}
}
startMeasure('final_echo');
if (!headers_sent()) {
header("HTTP/1.0: 200 OK\n");
header('Content-Type: text/html; charset=utf-8');
header('Access-Control-Allow-Origin: *');
if (!ob_get_length()) {
if(!ob_start("ob_gzhandler")) ob_start();
}
}
echobig($result);
endMeasure('final_echo', 1);
if ($cache_filename != '' && $cached_result == '')
{
SaveFile(ROOT . 'cms/cached/' . $cache_filename, $result);
}
$session->save();
if (isset($wsClient) && $wsClient) {
$wsClient->disconnect();
}
// end calculation of execution time
endMeasure('TOTAL');
// print performance report
performanceReport();
ob_end_flush();