X-Git-Url: http://git.shiar.nl/minimedit.git/blobdiff_plain/c3764fe0c2916d8d48a5da38d39b224d731ff732..00480c926f002a6bbc7ebd742e8450bc1b1a6f9d:/page.php diff --git a/page.php b/page.php index 51ef900..a9607c0 100644 --- a/page.php +++ b/page.php @@ -2,33 +2,82 @@ error_reporting(E_ALL); ini_set('display_errors', TRUE); -$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; +define('DOCROOT', getcwd()); +set_include_path(implode(PATH_SEPARATOR, [ DOCROOT, __DIR__ ])); + +include_once 'error.inc.php'; + +# setup requested page + +$request = preg_replace('/\?.*/', '', @$_SERVER['PATH_INFO'] ?: $_SERVER['REQUEST_URI']); +$request = urldecode(trim($request, '/')) ?: 'index'; + +$staticpage = "$request.html"; +if (file_exists($staticpage)) { + if (is_link($staticpage)) { + $target = preg_replace('/\.html$/', '', readlink($staticpage)); + abort($target, '302 Shorthand'); } - if (file_exists("$Page.php")) { - # unformatted script override - require "$Page.php"; - exit; +} +elseif (file_exists("$request/index.html")) { + $staticpage = "$request/index.html"; +} + +require_once('article.inc.php'); +$Page = new ArchiveArticle($staticpage); + +# user login and control + +include_once 'auth.inc.php'; // sets global $User + +if ($Page->restricted) { + # access restriction + if (!$User->login) { + $target = urlencode($Page->link); + abort("/login?goto=$target", '303 Eerst inloggen'); } +} + +# prepare page contents + +header(sprintf('Content-Security-Policy: %s', implode('; ', [ + "default-src 'self' 'unsafe-inline' http://cdn.ckeditor.com", # some overrides remain + "img-src 'self' data: blob: http://cdn.ckeditor.com", # inline svg (in css) + "base-uri 'self'", # only local pages + "frame-ancestors 'none'", # prevent malicious embedding +]))); + +$Page->place += [ + 'user' => $User->login ?: '', + 'url' => htmlspecialchars($_SERVER['REQUEST_URI']), +]; + +if ($User->admin("edit {$Page->link}")) { + include_once 'edit/head.inc.php'; +} - $up = strrpos($Page, '/'); - if ($up === FALSE) { +if (isset($Page->raw)) { + $Page->raw = '
'."\n\n".$Page->raw."
\n\n"; +} + +# output dynamic and/or static html + +include_once 'format.inc.php'; + +ob_start(); +if ($Page->handler and !require("./{$Page->handler}/index.php")) { + # replace contents by code output on false return + $Page->raw = ob_get_clean(); +} +else { + # keep article contents + if (!isset($Page->body)) { + # no resulting output http_response_code(404); - $Page = '404'; - break; + @require '404.inc.html'; + $Page->raw = ob_get_clean() . $Page->raw; } - $Args = substr($Page, $up) . $Args; - $Page = substr($Page, 0, $up); } -$Edit = isset($_GET['edit']); +include_once 'page.inc.php'; -include 'head.inc.php';