2 error_reporting(E_ALL);
3 ini_set('display_errors', TRUE);
5 function getoutput($blocks = [])
8 foreach ($blocks as $name => $html) {
9 $rep["[[$name]]"] = sprintf('<!--BLOCK:%s-->%s<!--/-->',
10 is_numeric($name) ? '' : "[[$name]]",
11 preg_replace('{<!--[^-]*-->}', '', $html)
14 return str_replace(array_keys($rep), array_values($rep), ob_get_clean());
19 http_response_code(500);
20 include_once 'page.inc.php';
22 require_once './500.html';
23 print getoutput(['debug' => $error]);
25 set_exception_handler('fail');
27 define('E_FATAL', E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR);
28 register_shutdown_function(function () {
29 # display failure page for fatal exceptions
30 $error = error_get_last();
31 if (!($error['type'] & E_FATAL)) return;
32 fail("Fatal: $error[message] in $error[file]:$error[line]");
34 error_reporting(error_reporting() & ~E_FATAL);
36 include_once 'auth.inc.php';
37 $Edit = isset($_GET['edit']);
39 # distinguish subpage Args from topmost Page script
42 $Page = preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']);
43 $Page = urldecode(trim($Page, '/')) ?: 'index';
45 if (file_exists("$Page/.private")) {
48 http_response_code(403);
49 include_once 'page.inc.php';
51 @require_once './403.html';
56 if (file_exists("$Page.php")) {
60 $up = strrpos($Page, '/');
61 $Args = substr($Page, $up) . $Args;
62 $Page = substr($Page, 0, $up);
68 # load static contents
70 ob_start(); # page body
71 ob_start(); # inner html
72 print '<div class="static">'."\n\n";
75 if (file_exists("$Page$Args/index.html")) {
76 $found = include "./$Page$Args/index.html";
78 elseif (file_exists("$Page$Args.html")) {
79 $found = include "./$Page$Args.html";
81 elseif (isset($User) and $User['admin']) {
82 $found = include (file_exists("$Page/template.html") ? "$Page/template.html" : './template.html');
87 # execute dynamic code
90 $found |= @require "./$Page.php";
95 include_once 'page.inc.php';
99 http_response_code(404);
101 @require "./404.html";
102 print getoutput([ 'url' => htmlspecialchars($_SERVER['REQUEST_URI']) ]);