forked from vichan-devel/infinity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smart_build.php
85 lines (75 loc) · 2.22 KB
/
smart_build.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
<?php
require_once("inc/functions.php");
require_once("inc/route.php");
require_once("inc/controller.php");
if (!$config["smart_build_helper"]) {
die('You need to enable $config["smart_build_helper"]');
}
$config['smart_build'] = false; // Let's disable it, so we can build the page for real
$config['generation_strategies'] = array('strategy_immediate');
function after_open_board() { global $config;
$config['smart_build'] = false;
$config['generation_strategies'] = array('strategy_immediate');
};
$request = $_SERVER['REQUEST_URI'];
$route = route($request);
if (!$route) {
$reached = false;
}
else {
list ($fun, $args) = $route;
$reached = call_user_func_array($fun, $args);
}
function die_404() { global $config;
if (!$config['page_404']) {
header("HTTP/1.1 404 Not Found");
header("Status: 404 Not Found");
echo "<h1>404 Not Found</h1><p>Page doesn't exist<hr><address>vichan</address>";
}
else {
header("Location: ".$config['page_404']);
}
header("X-Accel-Expires: 120");
die();
}
if ($reached) {
if ($request[strlen($request)-1] == '/') {
$request .= 'index.html';
}
$request = '.'.$request;
if (!file_exists($request)) {
die_404();
}
header("HTTP/1.1 200 OK");
header("Status: 200 OK");
if (preg_match('/\.json$/', $request)) {
header("Content-Type", "application/json");
}
elseif (preg_match('/\.js$/', $request)) {
header("Content-Type", "text/javascript; charset=utf-8");
}
elseif (preg_match('/\.xml$/', $request)) {
header("Content-Type", "application/xml");
}
elseif (preg_match('/\.rss$/', $request)) {
header("Content-Type", "application/rss+xml");
}
else {
header("Content-Type", "text/html; charset=utf-8");
}
header("Cache-Control: public, nocache, no-cache, max-age=0, must-revalidate");
header("Expires: Fri, 22 Feb 1991 06:00:00 GMT");
header("Last-Modified: ".date('r', filemtime($request)));
//if (isset ($_SERVER['HTTP_ACCEPT_ENCODING']) && preg_match('/gzip/', $_SERVER['HTTP_ACCEPT_ENCODING']) && file_exists($request.".gz")) {
// header("Content-Encoding: gzip");
// $file = fopen($request.".gz", 'r');
//}
//else {
$file = fopen($request, 'r');
//}
fpassthru($file);
fclose($file);
}
else {
die_404();
}