-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
81 lines (75 loc) · 2.44 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
<?php
/**
* Basic /site loader
*/
$requestPices = explode("/", substr($_SERVER['REQUEST_URI'], 1));
// /REST on CLI
if (php_sapi_name() === 'cli-server' && $requestPices[0] === "REST") {
include dirname(__FILE__) . "/REST/rest.php";
die();
}
// dynamic pages
if (file_exists(dirname(__FILE__)."/site/dynamic/ccCMS_dynamic.conf.php")) {
include dirname(__FILE__)."/site/dynamic/ccCMS_dynamic.conf.php";
if (isset($ccCMS_dynamicConf)) {
if (empty($requestPices[0]) && isset($ccCMS_dynamicConf['home'])) {
header("LOCATION: /" . $ccCMS_dynamicConf['home']);
die();
} else if (!empty($requestPices[0])) {
if (isset($ccCMS_dynamicConf['pages'][$requestPices[0]])) {
if (file_exists(dirname(__FILE__)."/site/dynamic/" . $ccCMS_dynamicConf['pages'][$requestPices[0]])) {
include dirname(__FILE__)."/site/dynamic/" . $ccCMS_dynamicConf['pages'][$requestPices[0]];
die();
}
} else if (in_array($requestPices[0], $ccCMS_dynamicConf['directFiles'])) {
if (file_exists(dirname(__FILE__)."/site/" . $requestPices[0])) {
readfile (dirname(__FILE__)."/site/" . $requestPices[0]);
die();
}
}
}
}
}
//static content
switch($requestPices[0]) {
case 'css':
case 'js':
case 'img':
case 'font':
$fileToServe = dirname(__FILE__) . "/site" . $_SERVER['REQUEST_URI'];
if (is_file($fileToServe)) {
if ($requestPices[0] === "css") {
header('Content-type: text/css');
} else {
$mimetype = mime_content_type($fileToServe);
header('Content-type: ' . $mimetype);
}
$filesize = filesize($fileToServe);
header('Content-Length: ' . $filesize);
$seconds_to_cache = 3600;
$ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
header("Expires: $ts");
header("Pragma: cache");
header("Cache-Control: max-age=$seconds_to_cache");
readfile($fileToServe);
die();
}
break;
default:
$staticRequestCheck = $_SERVER['REQUEST_URI'];
if (empty($staticRequestCheck) || $staticRequestCheck === "/") {
$staticRequestCheck = "/index.html";
}
if (preg_match('/(.*)\.html$/', $staticRequestCheck)) {
$fileHash = md5($staticRequestCheck);
if (file_exists(dirname(__FILE__) . "/site/static/".$fileHash.".html")) {
readfile(dirname(__FILE__) . "/site/static/".$fileHash.".html");
die();
}
}
header("HTTP/1.0 404 Not Found");
if (file_exists(dirname(__FILE__) . "/site/static/404.html")) {
readfile(dirname(__FILE__) . "/site/static/404.html");
}
die();
}