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 # user login and control
12 include_once 'auth.inc.php'; // sets global $User
13 $Edit = isset($_GET['edit']);
15 # setup requested page
17 $request = preg_replace('/\?.*/', '', @$_SERVER['PATH_INFO'] ?: $_SERVER['REQUEST_URI']);
18 $request = urldecode(trim($request, '/')) ?: 'index';
20 $staticpage = "$request.html";
21 if (file_exists($staticpage)) {
22 if (is_link($staticpage)) {
23 $target = preg_replace('/\.html$/', '', readlink($staticpage));
24 header("HTTP/1.1 302 Shorthand");
25 header("Location: $target");
29 elseif (file_exists("$request/index.html")) {
30 $staticpage = "$request/index.html";
33 require_once('article.inc.php');
34 $Page = new ArchiveArticle($staticpage);
36 if ($Page->restricted) {
39 http_response_code(303);
40 $target = urlencode($Page->link);
41 header("Location: /login?goto=$target");
46 # prepare page contents
48 header(sprintf('Content-Security-Policy: %s', implode('; ', [
49 "default-src 'self' 'unsafe-inline' http://cdn.ckeditor.com", # some overrides remain
50 "img-src 'self' data: http://cdn.ckeditor.com", # inline svg (in css)
51 "base-uri 'self'", # only local pages
52 "frame-ancestors 'none'", # prevent malicious embedding
56 'user' => $User->login ?: '',
57 'url' => htmlspecialchars($_SERVER['REQUEST_URI']),
60 if (!isset($Page->raw) and $User->admin("edit {$Page->link}")) {
61 # open bottom template as initial contents
62 $template = 'template.inc.html';
63 if ($Page->handler and file_exists("{$Page->handler}/$template")) {
64 $template = "{$Page->handler}/$template";
66 $Page->raw($template);
67 $Page->meta['article:published_time'] = date('Y-m-d h:i:s O');
68 $Page->meta['article:author'] = '/' . $User->dir;
72 if (isset($Page->raw)) {
73 if ($User->admin("edit {$Page->link}")) {
74 # restore meta tags in static contents for editing
75 foreach (array_reverse($Page->meta) as $metaprop => $val) {
77 '<meta property="%s" content="%s">'."\n",
82 $Page->raw = '<div class="static">'."\n\n".$Page->raw."</div>\n\n";
85 # output dynamic and/or static html
88 if ($Page->handler and !require("./{$Page->handler}/index.php")) {
89 # replace contents by code output on false return
90 $Page->raw = ob_get_clean();
93 # keep article contents
94 if (!isset($Page->body)) {
96 http_response_code(404);
97 @require '404.inc.html';
98 $Page->raw = ob_get_clean() . $Page->raw;
102 include_once 'page.inc.php';