2015-04-01 11:50:59 -04:00
|
|
|
<?php
|
|
|
|
require_once("inc/functions.php");
|
2016-05-07 20:50:44 -04:00
|
|
|
require_once("inc/route.php");
|
|
|
|
require_once("inc/controller.php");
|
2015-04-01 11:50:59 -04:00
|
|
|
|
2016-05-06 12:42:33 -04:00
|
|
|
if (!$config['smart_build'] && !$config["smart_build_helper"]) {
|
|
|
|
die('You need to enable $config["smart_build"] or $config["smart_build_helper"]');
|
2015-04-01 11:50:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$config['smart_build'] = false; // Let's disable it, so we can build the page for real
|
|
|
|
|
2015-04-01 12:46:48 -04:00
|
|
|
function after_open_board() { global $config;
|
|
|
|
$config['smart_build'] = false;
|
|
|
|
};
|
|
|
|
|
2015-04-01 11:50:59 -04:00
|
|
|
$request = $_SERVER['REQUEST_URI'];
|
|
|
|
|
2016-05-07 20:50:44 -04:00
|
|
|
$route = route($request);
|
2015-04-01 11:50:59 -04:00
|
|
|
|
2016-05-07 20:50:44 -04:00
|
|
|
if (!$route) {
|
|
|
|
$reached = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
list ($fun, $args) = $route;
|
|
|
|
$reached = call_user_func_array($route);
|
2015-04-01 11:50:59 -04:00
|
|
|
}
|
|
|
|
|
2015-04-02 14:27:10 -04:00
|
|
|
function die_404() { global $config;
|
|
|
|
if (!$config['page_404']) {
|
2015-04-02 14:35:17 -04:00
|
|
|
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>";
|
2015-04-02 14:27:10 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
header("Location: ".$config['page_404']);
|
|
|
|
}
|
2015-04-06 12:42:23 -04:00
|
|
|
header("X-Accel-Expires: 120");
|
2015-04-02 14:27:10 -04:00
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2015-04-01 11:50:59 -04:00
|
|
|
if ($reached) {
|
|
|
|
if ($request[strlen($request)-1] == '/') {
|
|
|
|
$request .= 'index.html';
|
|
|
|
}
|
|
|
|
$request = '.'.$request;
|
|
|
|
|
|
|
|
if (!file_exists($request)) {
|
2015-04-02 14:27:10 -04:00
|
|
|
die_404();
|
2015-04-01 11:50:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
2015-04-02 23:57:39 -04:00
|
|
|
elseif (preg_match('/\.xml$/', $request)) {
|
|
|
|
header("Content-Type", "application/xml");
|
|
|
|
}
|
2015-04-01 11:50:59 -04:00
|
|
|
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 {
|
2015-04-02 14:27:10 -04:00
|
|
|
die_404();
|
2015-04-01 11:50:59 -04:00
|
|
|
}
|