-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
128 lines (113 loc) · 3.51 KB
/
index.php
File metadata and controls
128 lines (113 loc) · 3.51 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
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
define('SF_INADMIN', false);
define('SF_INSITE', true);
define('SF_INCRON', false);
define('SF_INAPI', false);
//date_default_timezone_set('Europe/Moscow');
date_default_timezone_set('Asia/Yekaterinburg');
// Одна сессия для всех поддоменов
if (SFConfig::$subdomainOneSession) {
$baseDomain = implode('.', array_slice(explode('.', $_SERVER['HTTP_HOST']), 1));
session_set_cookie_params(0, '/', ".$baseDomain");
}
$_ENV['start'] = ['time' => microtime(true), 'memory' => memory_get_usage()];
session_start();
ini_set('default_charset', 'UTF-8');
include 'autoload.php';
include 'config.php';
include 'core/sflog.class.php';
include 'core/sfdb.class.php';
include 'core/sfuser.class.php';
include 'core/sfcore.class.php';
include 'core/sfpage.class.php';
include 'core/sfbuffer.class.php';
SFDB::connect();
SFUser::login();
SFCore::init();
SFPage::init();
ob_start();
SFCore::execute();
$html = ob_get_clean();
$siteParams = SFCore::siteParam();
foreach ($siteParams as $paramAlias => $paramValue) {
$html = str_replace('{' . $paramAlias . '}', $paramValue, $html);
}
$html = str_replace('{year}', date('Y'), $html);
preg_match_all("@\{position_([a-z_\-]+)\}@Ui", $html, $matches);
if (!empty($matches[1])) {
foreach ($matches[1] as $pos) {
ob_start();
SFPage::position($pos);
$ppp = ob_get_clean();
$html = str_replace("{position_$pos}", $ppp, $html);
}
}
echo sanitizeOutput($html);
function imDev() {
if (isset($_GET['setimdev'])) {
setcookie('imdev', 1, time() + 60 * 60 * 24 * 30, '/');
header("location: ./");
exit;
}
$ret = !empty($_COOKIE['imdev']);
$ret |= $_SERVER['REMOTE_ADDR'] == '127.0.0.1';
$ret |= strpos($_SERVER['REMOTE_ADDR'], '192.168') === 0;
return $ret;
}
function barf($f, $l, $debug = false, $printTrace = false) {
if (imDev()) {
$d = & $_ENV['debug_barf'];
$s = & $_ENV['debug_start'];
empty($d) && $d = [];
$di = [];
$di['line'] = $l;
$di['file'] = $f;
$di['time'] = microtime(true) - $s['time'];
$di['m0'] = round((memory_get_usage() - $s['m0']) / 1024);
$di['m1'] = round((memory_get_usage(true) - $s['m1']) / 1024);
$trace = '';
if ($printTrace) {
ob_start();
debug_print_backtrace();
$trace = nl2br(ob_get_clean());
}
$di['debug'] = $debug . $trace;
$d[] = $di;
}
}
function barfOut() {
if (imDev()) {
echo '<table cellpadding=3 border=1>';
foreach ($_ENV['debug_barf'] as $row) {
echo '<tr>';
echo '<td>' . $row['file'] . '</td>';
echo '<td>' . $row['line'] . '</td>';
echo '<td>' . round($row['time'], 3) . '</td>';
echo '<td>' . $row['m0'] . '</td>';
echo '<td>' . $row['m1'] . '</td>';
echo '<td>' . var_export($row['debug'], true) . '</td>';
echo '</tr>';
}
echo '</table>';
die;
}
}
function sanitizeOutput($buffer) {
if (imDev()) {
return $buffer;
}
$search = array(
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
'/(\s)+/s', // shorten multiple whitespace sequences
'/<!--(.|\s)*?-->/' // Remove HTML comments
);
$replace = array(
'>',
'<',
'\\1',
''
);
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}