2 error_reporting(E_ALL);
3 ini_set('display_errors', TRUE);
5 define('DOCROOT', getcwd());
6 set_include_path(implode(PATH_SEPARATOR, [ DOCROOT, __DIR__ ]));
8 include_once 'error.inc.php';
10 # setup requested page
12 $request = preg_replace('/\?.*/', '', @$_SERVER['PATH_INFO'] ?: $_SERVER['REQUEST_URI']);
13 $request = urldecode(trim($request, '/')) ?: 'index';
15 $staticpage = "$request.html";
16 if (file_exists($staticpage)) {
17 if (is_link($staticpage)) {
18 $target = preg_replace('/\.html$/', '', readlink($staticpage));
19 abort($target, '307 Shorthand');
22 elseif (file_exists("$request/index.html")) {
23 $staticpage = "$request/index.html";
26 require_once('article.inc.php');
27 $Page = new ArchiveArticle($staticpage);
29 if (@$_SERVER['HTTP_ACCEPT'] === 'text/plain') {
33 # user login and control
35 include_once 'auth.inc.php'; // sets global $User
37 if ($Page->restricted) {
40 $target = urlencode($Page->link);
41 abort("/login?goto=$target", '303 Eerst inloggen');
45 # prepare page contents
47 header(sprintf('Content-Security-Policy: %s', implode('; ', [
48 "default-src 'self' 'unsafe-inline' http://cdn.ckeditor.com", # some overrides remain
49 "img-src 'self' data: blob: http://cdn.ckeditor.com", # inline svg (in css)
50 "base-uri 'self'", # only local pages
51 "frame-ancestors 'none'", # prevent malicious embedding
53 header('Referrer-Policy: no-referrer-when-downgrade');
56 'user' => $User->login ?: '',
57 'url' => htmlspecialchars($_SERVER['REQUEST_URI']),
60 if ($Page->editable = $User->admin("edit {$Page->link}")) {
61 include_once 'edit/head.inc.php';
65 and @$_SERVER['HTTP_ACCEPT'] !== 'application/xml') {
66 $Page->raw = '<div class="static">'."\n\n".$Page->raw."</div>\n\n";
69 # output dynamic and/or static html
71 include_once 'format.inc.php';
74 if ($Page->handler and !$Page->index($Page->api)) {
75 # replace contents by code output on false return
76 $Page->raw = ob_get_clean();
79 # keep article contents
80 if (!isset($Page->body)) {
82 http_response_code(404);
83 @require '404.inc.html';
84 $Page->raw = ob_get_clean() . $Page->raw;
88 if (@$_SERVER['HTTP_ACCEPT'] === 'application/xml') {
89 header('Access-Control-Allow-Origin: *');
91 elseif (!$Page->api) {
92 include_once 'page.inc.php';
94 print $Page->render();