error_reporting(E_ALL);
ini_set('display_errors', TRUE);
+include_once 'auth.inc.php';
+$Edit = isset($_GET['edit']);
+
+# distinguish subpage Args from topmost Page script
+
$Args = '';
$Page = preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']);
$Page = urldecode(trim($Page, '/')) ?: 'index';
while (TRUE) {
- if (file_exists("$Page/index.html")) {
- $Page .= '/index';
- break;
- }
- if (file_exists("$Page.html")) {
- break;
- }
if (file_exists("$Page.php")) {
- # unformatted script override
- require "$Page.php";
- exit;
+ break;
}
$up = strrpos($Page, '/');
+ $Args = substr($Page, $up) . $Args;
+ $Page = substr($Page, 0, $up);
if ($up === FALSE) {
- http_response_code(404);
- $Page = '404';
break;
}
- $Args = substr($Page, $up) . $Args;
- $Page = substr($Page, 0, $up);
}
-$Edit = isset($_GET['edit']);
+# execute dynamic code
+
+$prepend = $append = '';
+if ($Page) {
+ require "./$Page.php";
+ if (ob_get_level() > 1) $append = ob_get_clean();
+ if (ob_get_level() > 0) $prepend = ob_get_clean();
+}
+
+# prepare static contents
+
+include_once 'page.inc.php'; # global html
+
+if (file_exists("$Page$Args/index.html")) {
+ $Args .= '/index';
+}
+
+if (!$Page and !file_exists("$Page$Args.html")) {
+ # include not found
+ $Args = '';
+ if (isset($User) and $User['admin']) {
+ $Page = 'template';
+ }
+ else {
+ $Page = '404';
+ require "./$Page.php";
+ }
+}
+
+# output prepared html
+
+print $prepend;
+
+print '<div class="static">'."\n\n";
+if (file_exists("$Page$Args.html")) {
+include "./$Page$Args.html"; # static contents
+}
+print "</div>\n\n";
+
+print $append;
-include 'page.inc.php';