-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
executable file
·79 lines (60 loc) · 1.91 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
<?php
/**
* @author Julian Bogdani <[email protected]>
* @copyright 2007-2021 Julian Bogdani
* @license AGPL-3.0; see LICENSE file
* @since Dec 1, 2012
*/
ob_start();
try {
require_once 'lib/Bootstrap.php';
// with PHP higher or equal 7 run Phpfastcache
if (version_compare(phpversion(), '7.0.0') > -1){
require_once 'lib/vendor/phpfastcache/lib/Phpfastcache/Autoload/Autoload.php';
\Phpfastcache\CacheManager::setDefaultConfig(new \Phpfastcache\Config\Config([
"path" => TMP_DIR,
"itemDetailedDate" => false
]));
if ( !$_SESSION['debug']
&& !$_SESSION['user_email']
&& !preg_match('/\.map$/', $_SERVER['REQUEST_URI'])
&& !preg_match('/\.json$/', $_SERVER['REQUEST_URI'])
&& !preg_match('/controller\.php/', $_SERVER['REQUEST_URI'])
&& $_SERVER['REQUEST_URI'] !== '/admin'
&& !preg_match('/\.draft$/', $_SERVER['REQUEST_URI'])
){
$InstanceCache = \Phpfastcache\CacheManager::getInstance('files');
$key = md5($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].$_SERVER['QUERY_STRING']);
$CachedString = $InstanceCache->getItem($key);
$html = $CachedString->get();
}
if ( !$html ) {
Router::run();
$html = ob_get_contents();
ob_end_clean();
if ($CachedString){
$CachedString->set($html)->expiresAfter(60);
$InstanceCache->save($CachedString);
}
}
echo $html;
} else {
Router::run();
}
} catch (Throwable $e) {
error_log($e);
header('Content-Type: text/html; charset=utf-8');
if ($_SESSION['debug'] || defined('CREATE_SITE')) {
// var_dump($e->getTraceAsString());
echo '<h2>' . $e->getMessage() . '</h2>'
. "<p>File: " . $e->getFile()
. "<br>Line: " . $e->getLine()
. "<br>Code: " . $e->getCode()
. "</p><hr>"
.'<pre>'
. $e->getTraceAsString()
. '</pre>';
} else {
echo tr::get('error_check_log');
}
}