page: replace global variables by $Page object
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 3 Dec 2020 19:59:58 +0000 (20:59 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 19 Dec 2020 02:01:43 +0000 (03:01 +0100)
Former $Article is sufficient to provide all derived values:

$Page       = $Page->handler
$Args       = $Page->path
$PageAccess = $Page->restricted
$Article    = $Page

Swap with more appropriate (and short) $Page name and replace any usage.
Major incompatible cleanup before other upcoming behavioural changes.

28 files changed:
article.inc.php
edit/foto/cover/index.php
edit/nieuws/tag/index.php
edit/page/index.php
foto/album.inc.php
foto/index.php
head.inc.php
issue/feed.inc.php
issue/index.php
login/edit/index.php
login/index.php
login/post/index.php
mail/index.php
nieuws/feed/index.php
nieuws/index.php
page.inc.php
page.php
thumb/index.php
widget/countdown.php
widget/doclist.php
widget/linkref.php
widget/login/commits.php
widget/login/list.php
widget/nieuws.php
widget/page.php
widget/reply.php
widget/search.php
widget/sitemap.php

index 93bbe3b79f46dfb11b6c631d053030a164590c5a..acd219d164aab81397d9da33ef104148f3e23574 100644 (file)
@@ -77,6 +77,12 @@ class ArchiveArticle
                return;
        }
 
+       function restricted()
+       {
+               $this->handler;
+               return $this->restricted;
+       }
+
        function safetitle()
        {
                return trim($this->meta['og:title'] ?? strip_tags($this->title));
index 2558e102fb358644e588741df851fa0b08e81d20..06acc1d22c0e586b6510b42e203c161942b1db47 100644 (file)
@@ -5,13 +5,13 @@ if (!$User->admin('foto')) {
        exit;
 }
 
-$rootdir = 'foto' . $Args;
+$rootdir = 'foto' . $Page->path;
 $target = "$rootdir/index.jpg";
 
 if (is_link($target) or file_exists($target)) {
        if (!unlink($target)) {
                http_response_code(500);
-               print "Kon bestaande cover niet weghalen voor $Args\n";
+               print "Kon bestaande cover niet weghalen voor {$Page->path}\n";
                exit;
        }
 }
@@ -21,7 +21,7 @@ if (isset($_GET['img'])) {
        $img .= ltrim($_GET['img'], '/');
        if (!symlink($img, $target)) {
                http_response_code(500);
-               print "Fout bij instellen van cover voor $Args\n";
+               print "Fout bij instellen van cover voor {$Page->path}\n";
                exit;
        }
 }
index ca477c8c4427e10f133c8589d3ccb1651bb6b964..ba57adcdaef0bf83f1f0ece13ccb7b88df8ad746 100644 (file)
@@ -1,10 +1,10 @@
 <?php
 if (!$_POST)
        abort("niets te doen", '405 post error');
-if (!$Args)
+if (!$Page->path)
        abort("pagina niet opgegeven", '409 input error');
 
-$pagename = ltrim($Args, '/').'.html';
+$pagename = ltrim($Page->path, '/').'.html';
 if (!$User->admin("edit $pagename"))
        abort("geen beheersrechten", '401 unauthorised');
 
index 910b7c9bfacb2051b893916a5f6422c17eda1d2f..13ebd242ec9a91b939832313ce4974a947b02129 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-if (!$User->admin("edit $Page$Args"))
+if (!$User->admin("edit {$Page->link}"))
        abort("geen beheersrechten", '401 unauthorised');
 
 if ($_FILES) {
@@ -7,7 +7,7 @@ if ($_FILES) {
        try {
                require_once('upload.inc.php');
                $datadir = implode('/', ['data', date('Y')]);
-               if ($Args) $datadir .= $Args;
+               if ($Page->path) $datadir .= $Page->path;
                $target = userupload(@$_FILES['upload'], $datadir);
                if ($target) {
                        $response['fileName'] = $_FILES['upload']['name'];
@@ -43,7 +43,7 @@ if ($_FILES) {
 if (!$_POST)
        abort("niets te doen", '405 post error');
 
-$filename = trim($Args, '/') ?: 'index';
+$filename = trim($Page->path, '/') ?: 'index';
 if (preg_match('{^\.}', $filename))
        abort("ongeldige bestandsnaam: $filename", '403 input error');
 if (is_dir($filename) && !file_exists("$filename.html"))
index 92a7395f1df4c263f7cd40303013300b1cea7f0b..692aafa4efa21debc8ec58e458da4d3c2d023b4d 100644 (file)
@@ -26,7 +26,7 @@ function openphotoswipe(index) {
 <?php
 if ($User->admin('foto')) {
        printf("\t\t\t{id:'%s', label:'%s', url:'%s'},\n",
-               'cover', 'Cover instellen', "/edit/foto/cover$Args?img={{image_url}}"
+               'cover', 'Cover instellen', "/edit/foto/cover{$Page->path}?img={{image_url}}"
        );
 }
 ?>
index 27482a484134b72485ed0dc8e5d298112631d563..0acd44e7ab701aa6bfb091ed5c4a96ac08221521 100644 (file)
@@ -1,12 +1,12 @@
 <?php
-$rootdir = $Page . $Args;
+$rootdir = $Page->link;
 
 if ($User->admin('foto')) {
-       if (!empty($PageAccess)) {
+       if ($Page->restricted) {
                $access = '<span class="icon icon-locked">&#x1F512;</span> Bewoners';
-               if ($PageAccess != $rootdir) {
+               if ($Page->restricted != $rootdir) {
                        $access .= sprintf(' vanaf <a href="%s">%s</a>',
-                               "/$PageAccess", pathinfo($PageAccess, PATHINFO_FILENAME)
+                               "/{$Page->restricted}", pathinfo($Page->restricted, PATHINFO_FILENAME)
                        );
                }
        }
@@ -19,19 +19,19 @@ if ($User->admin('foto')) {
 $nav = explode('/', $rootdir);
 $nav[0] = "Foto's"; # override of root 'foto'
 $title = array_pop($nav);
-$Article->title = ($nav ? implode(' ', $nav) . ': ' : '') . $title;
+$Page->title = ($nav ? implode(' ', $nav) . ': ' : '') . $title;
 
 $link = '';
 print "<h2>";
 foreach ($nav as $i => $linktitle) {
-       $link .= '/' . ($i ? $linktitle : $Page);
+       $link .= '/' . ($i ? $linktitle : $Page->handler);
        printf('<a href="%s">%s</a> →'."\n", $link, $linktitle);
 }
 print $title;
 print "</h2>\n\n";
 
-if (isset($Article->raw)) {
-       print $Article->raw;  # page intro
+if (isset($Page->raw)) {
+       print $Page->raw;  # page intro
 }
 
 function showthumb($path)
@@ -81,7 +81,7 @@ if ($imgs = glob("$rootdir/*.jpg")) {
        foreach ($imgs as $img) {
                if ($img == "$rootdir/index.jpg") {
                        # cover image of current album
-                       $Article->image = "/$img";
+                       $Page->image = "/$img";
                        continue;
                }
                if (!is_link($img)) continue;
index 34e0d0439032701a721e7d7ee40de6abfe82d46e..4082b92b77748498a8b42caa3afbce9118cbd687 100644 (file)
@@ -2,18 +2,18 @@
 <html lang="nl">
 <head>
        <meta charset="utf-8" />
-<?php if ($Article->title) { ?>
-       <title property="og:name"><?= htmlspecialchars($Article->safetitle) ?></title>
+<?php if ($Page->title) { ?>
+       <title property="og:name"><?= htmlspecialchars($Page->safetitle) ?></title>
 <?php } ?>
-<?php if ($Article->teaser) { ?>
-       <meta name="description" property="og:description" content="<?= preg_replace('/\s+/', ' ', strip_tags($Article->teaser)) ?>" />
+<?php if ($Page->teaser) { ?>
+       <meta name="description" property="og:description" content="<?= preg_replace('/\s+/', ' ', strip_tags($Page->teaser)) ?>" />
 <?php } ?>
        <meta name="viewport" content="width=device-width" />
        <!--[if lt IE 9]><script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script><![endif]-->
-<?php if ($Article->image) { ?>
-       <meta property="og:image" content="https://<?= $_SERVER['HTTP_HOST'] . '/' . htmlspecialchars($Article->thumb('640x')) ?>" />
+<?php if ($Page->image) { ?>
+       <meta property="og:image" content="https://<?= $_SERVER['HTTP_HOST'] . '/' . htmlspecialchars($Page->thumb('640x')) ?>" />
 <?php } ?>
-       <meta property="og:type" content="<?= $Article->meta['og:type'] ?? 'website' ?>" />
-       <meta property="og:url" content="https://<?= $_SERVER['HTTP_HOST'] . '/' . htmlspecialchars($Article->link) ?>" />
+       <meta property="og:type" content="<?= $Page->meta['og:type'] ?? 'website' ?>" />
+       <meta property="og:url" content="https://<?= $_SERVER['HTTP_HOST'] . '/' . htmlspecialchars($Page->link) ?>" />
 </head>
 <body>
index f5cf847b5b517a5d9cb5e60c8bdad73cb5e95583..1061bf07067b9de815ed5ad3c05dc1f5aa8e14fa 100644 (file)
@@ -16,8 +16,8 @@ $siteref = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . '://' . $_SERVER['HTT
 while ($row = $query->fetch()) {
 ?>
        <entry>
-               <id><?= "$siteref/$Page/{$row->id}/{$row->link}" ?></id>
-               <link href="<?= "$siteref/$Page/{$row->id}/{$row->link}" ?>" />
+               <id><?= "$siteref/{$Page->handler}/{$row->id}/{$row->link}" ?></id>
+               <link href="<?= "$siteref/{$Page->handler}/{$row->id}/{$row->link}" ?>" />
                <title><?= $row->subject ?></title>
                <published><?= $row->created ?></published>
                <updated><?= $row->updated ?></updated>
index cc17f0310ac0cb44f0a1018477fb51dd4256c074..41d37491378b22eac9d670ab7dbb8cf4dfb355f6 100644 (file)
@@ -1,23 +1,23 @@
 <?php
 global $User, $Db;
 require_once 'database.inc.php';
-@list ($id, $title) = explode('/', ltrim($Args, '/'));
+@list ($id, $title) = explode('/', ltrim($Page->path, '/'));
 
 if ($id and ctype_digit($id)) {
-       $Article->title = "Issue #$id";
-       $Args = "/$id";  # minimal reference
+       $Page->title = "Issue #$id";
+       $Page->path = "/$id";  # minimal reference
        $Issue = $Db->query(
-               'SELECT * FROM issues WHERE page = ? AND id = ?', [$Page, $id]
+               'SELECT * FROM issues WHERE page = ? AND id = ?', [$Page->handler, $id]
        )->fetch();
        if (!$Issue) throw new Exception('Issuenummer niet gevonden');
 
        $replies = placeholder_include('reply');  # handle updates
 
-       $Article->title .= ': '.htmlspecialchars($Issue->subject);
-       $Article->teaser = $Issue->body;
-       $Article->body = $replies;  # find image
+       $Page->title .= ': '.htmlspecialchars($Issue->subject);
+       $Page->teaser = $Issue->body;
+       $Page->body = $replies;  # find image
 
-       print "<h2>{$Article->title}</h2>\n";
+       print "<h2>{$Page->title}</h2>\n";
        print '<aside class="metadata"><dl>'."\n";
        print '<dt>Geplaatst</dt>';
        printf('<dd>%s</dd>'."\n", showdate(preg_split('/\D/', $Issue->created)));
@@ -44,7 +44,7 @@ if ($id and ctype_digit($id)) {
 if ($_POST) {
                require_once 'upload.inc.php';
                $query = $Db->set('issues', [
-                       'page'    => $Page,
+                       'page'    => $Page->handler,
                        'subject' => $_POST['subject'],
                        'body'    => messagehtml($_POST['body']),
                        'author'  => $User->login,
@@ -63,7 +63,7 @@ if (isset($_GET['open'])) {
        $sql .= ' AND closed IS NULL';
 }
 $sql .= ' ORDER BY closed IS NOT NULL, updated DESC';
-$query = $Db->query($sql, [$Page]);
+$query = $Db->query($sql, [$Page->handler]);
 
 if ($id == 'feed') {
        require 'issue/feed.inc.php';
@@ -74,7 +74,7 @@ print '<ul>';
 while ($row = $query->fetch()) {
        printf('<li%s><div><a href="%s">',
                $row->closed ? ' class="disabled"' : '',
-               "/$Page/{$row->id}/{$row->link}"
+               "/{$Page->handler}/{$row->id}/{$row->link}"
        );
        printf($row->closed ? '<s>%s</s>' : '%s', htmlspecialchars($row->subject));
        {
index a880b182d7d46d8e4946b3e97eac1d580af22929..3360ec7bab093356a19be45f4313ad3faaf22204 100644 (file)
@@ -1,9 +1,9 @@
 <?php
-if ($Args and $User->admin('user')) {
-       $user = new User(strtolower("profile$Args"), FALSE);
+if ($Page->path and $User->admin('user')) {
+       $user = new User(strtolower("profile{$Page->path}"), FALSE);
        print placeholder_include('login/admin');
-       $Article->title = "Profiel <em>{$user->login}</em>";
-       print "<h2>{$Article->title}</h2>\n";
+       $Page->title = "Profiel <em>{$user->login}</em>";
+       print "<h2>{$Page->title}</h2>\n";
        print placeholder_include('login/edit');
        return;
 }
index 897346d98275f712f1fdfa8906bacbf2085b4eaa..4ecee456f8d77f52dcdbb8c751521cfa875d3377 100644 (file)
@@ -36,32 +36,31 @@ elseif (isset($_GET['logout'])) {
 }
 
 if (!$User or !$User->login) {
-       $Article->title = 'Inloggen';
+       $Page->title = 'Inloggen';
        if (isset($_REQUEST['goto'])) {
                if (empty($message)) http_response_code(403);
                $target = ltrim($_REQUEST['goto'], '/');
                $target = new ArchiveArticle("$target.html");
 
-               if ($Page = $target->handler and $target->handler == 'melding') {
-                       $caller = $Article;
-                       $Article = $target;
-                       $Args = $target->path;
+               if ($target and $target->handler == 'melding') {
+                       $caller = $Page;
+                       $Page = $target;
                        ob_start();
                        include "./{$target->handler}/index.php";
                        ob_end_clean();
-                       $Article = $caller;
+                       $Page = $caller;
                }
 
                if ($target->title) {
-                       $Article->title .= ' voor ' . $target->title;
+                       $Page->title .= ' voor ' . $target->title;
                }
                if ($target->image) {
-                       $Article->image = $target->image;
+                       $Page->image = $target->image;
                }
        }
        ob_start();
        require_once 'login/form.inc.php';
-       $Article->raw = ob_get_clean();
+       $Page->raw = ob_get_clean();
        $Place['warn'] = $message;
        return TRUE;
 }
@@ -73,10 +72,10 @@ if (isset($_REQUEST['goto'])) {
        exit;
 }
 
-if (isset($Article->raw)) {
-       print $Article->raw;
+if (isset($Page->raw)) {
+       print $Page->raw;
 }
-if (empty($Args) and $User->admin) {
+if (empty($Page->path) and $User->admin) {
        include_once 'login/admin.html';
 }
 
index 0beb42ff8b618f6e5cd349370bffc7067d572a6f..f4c77591f988d3d03c6cb80fb1cd8082d2158de4 100644 (file)
@@ -13,7 +13,7 @@ elseif ($User->admin('user') and $username = @$_REQUEST['login']) {
                printf('<p class=warn>%s</p>', $e->getMessage());
                return;
        }
-       $Article->title = $user->login . ': ' . $Article->title;
+       $Page->title = $user->login . ': ' . $Page->title;
 }
 else {
        $user = $User;
index 76ec0334a224b5fc5b560b743ac517b94a81269c..67a076e157cf85614b9ea6cc0142dc279386bba0 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 $mailbox = 'mail/inbox';
-@list ($msgid) = explode('/', ltrim($Args, '/'));
+@list ($msgid) = explode('/', ltrim($Page->path, '/'));
 
 function parsemailhead($headerdata)
 {
@@ -16,7 +16,7 @@ if ($msgid) {
        list ($headerdata, $rawbody) = explode("\n\n", file_get_contents($filename), 2);
        $head = parsemailhead($headerdata);
 
-       $Article->title = 'Mailbericht ' . $head['date']->format('Y-m-d H:i');
+       $Page->title = 'Mailbericht ' . $head['date']->format('Y-m-d H:i');
        printf("<h2>%s</h2>\n", htmlspecialchars($head['Subject'] ?? 'Mailbericht zonder onderwerp'));
 
        print '<dl class="terse">';
@@ -62,7 +62,7 @@ foreach (array_reverse($rows) as $filename) {
        list ($headerdata) = explode("\n\n", file_get_contents($filename));
        $head = parsemailhead($headerdata);
 
-       printf('<li><a href="%s">', "/$Page/".basename($filename));
+       printf('<li><a href="%s">', "/{$Page->handler}/".basename($filename));
 
        print $head['Subject'];
        printf(' <small class="date">%s</small>',
index 0cd5ecb84e016df6ed7fb55ffca9eac059edae43..9fb71a9ae86de7cf7bc2c43e3956a832e717d361 100644 (file)
@@ -14,7 +14,7 @@ $siteref = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . '://' . $_SERVER['HTT
        <icon>/favicon.png</icon>
        <author><name>Lijtweg</name></author>
 <?php
-$root = preg_replace('{/feed$}', '', $Page) . "/2???";
+$root = preg_replace('{/feed$}', '', $Page->handler) . "/2???";
 $pages = array_reverse(glob("$root/*.html"));
 
 foreach ($pages as $i => $page) {
index ff433d5d7b80001921a3d360b66a4796f98f4041..08400153ff15dbaffdf2130d66078b16df0a5971 100644 (file)
@@ -1,27 +1,27 @@
 <?php
-$replyform = $Page == 'melding' && $User->login;
-@list ($year, $page) = explode('/', trim($Args, '/'));
+$replyform = $Page->handler == 'melding' && $User->login;
+@list ($year, $page) = explode('/', trim($Page->path, '/'));
 
-if ($User->admin("edit $Page")) {
+if ($User->admin("edit {$Page->handler}")) {
        print '<script src="/nieuws/edit.js"></script>'."\n";
 }
 
 if ($page and !is_numeric($page)) {
-       $Article->meta['og:type'] = 'article';
-       $edit = $User->admin("edit $Page$Args") ? htmlspecialchars(@$_GET['edit']) : NULL;
+       $Page->meta['og:type'] = 'article';
+       $edit = $User->admin("edit {$Page->link}") ? htmlspecialchars(@$_GET['edit']) : NULL;
        if ($edit) {
-               $Article->title = $edit;
+               $Page->title = $edit;
        }
-       if ($Article->dateparts) {
-               $Place[1] = ' <small class="date">'.$Article->date.'</small>';
+       if ($Page->dateparts) {
+               $Place[1] = ' <small class="date">'.$Page->date.'</small>';
        }
        else {
                $Place[1] = '';
        }
-       print preg_replace('{(?<=<h2>)(.*?)(?=</h2>)}', ($edit ?: '\1').' [[1]]', $Article->raw);
-       if ($User->admin("edit $Page$Args")) {
+       print preg_replace('{(?<=<h2>)(.*?)(?=</h2>)}', ($edit ?: '\1').' [[1]]', $Page->raw);
+       if ($User->admin("edit {$Page->link}")) {
                $taglist = [];
-               foreach (glob("$Page/.tags/*") as $tagpath) {
+               foreach (glob("{$Page->handler}/.tags/*") as $tagpath) {
                        $tagname = pathinfo($tagpath, PATHINFO_BASENAME);
                        $tagvalue = file_exists("$tagpath/$year-$page.html");
                        $tagtarget = is_writable($tagpath);
@@ -47,7 +47,7 @@ if ($page and !is_numeric($page)) {
 }
 
 if ($year) {
-       $match = $Page;
+       $match = $Page->handler;
        $title = "Nieuws";
        if (is_numeric($year) and $year > 999) {
                $match .= "/$year";
@@ -61,7 +61,7 @@ if ($year) {
                $match .= "/19??";
                $title .= " vóór 2000";
        }
-       elseif (file_exists("$Page/.tags/$year")) {
+       elseif (file_exists("{$Page->handler}/.tags/$year")) {
                $match .= "/.tags/$year";
                $title .= " met $year";
        }
index 5753b649f43829eb9c5e8e70220770257b6b31e1..137d266267fab1905b74492b3e556e3b77722684 100644 (file)
@@ -13,8 +13,8 @@ if ($User and property_exists($User, 'login') and $User->login) {
                '<span class="icon icon-user">&#x1F464;</span>',
                '/login', $User->login
        );
-       if ($User->admin("edit $Page$Args")) {
-               $editpage = $Page.$Args;
+       if ($User->admin("edit {$Page->link}")) {
+               $editpage = $Page->link;
                if (is_dir($editpage)) {
                        if (file_exists("$editpage/index.html")) {
                                $editpage .= '/index.html';
@@ -46,8 +46,8 @@ register_shutdown_function(function () {
        @include 'footer.inc.html';
        print "</footer>\n";
 
-       global $User, $Page, $Args;
-       if ($User and $User->admin("edit $Page$Args")) {
+       global $User, $Page;
+       if ($User and $User->admin("edit {$Page->link}")) {
                $ckesrc = '/lib/ckeditor'; # local install
                if (!file_exists(DOCROOT . $ckesrc)) {
                        $ckesrc = '//cdn.ckeditor.com/4.15.1/full-all'; # remote fallback
index d4404fd0e22a1398783c74c332fa47435f641e3f..a469a9d865cec5b765c99f4d7293aae122c17d6f 100644 (file)
--- a/page.php
+++ b/page.php
@@ -16,17 +16,19 @@ function placeholder_include($name, $params = [])
        }
 
        ob_start();
-       $Page = $GLOBALS['Page'] . $GLOBALS['Args'];
-       $Args = '';
+       $Page = clone $GLOBALS['Page'];
+       $Page->handler = $Page->handler . $Page->path; // .= with explicit getter
+       $Page->path = '';
        $Place = $GLOBALS['Place'];
        foreach ($params as $param) {
                if ($set = strpos($param, '=')) {
                        $Place[ substr($param, 0, $set) ] = substr($param, $set + 1);
                }
                elseif (!empty($param)) {
-                       $Args .= '/'.$param;
+                       $Page->path .= '/'.$param;
                }
        }
+       $Page->link .= $Page->path;
        try {
                include "widget/$name.php";
                return ob_get_clean();
@@ -81,12 +83,12 @@ set_include_path(implode(PATH_SEPARATOR, [ DOCROOT, __DIR__ ]));
 
 function fail($error)
 {
-       global $User, $Page, $Args;
+       global $User, $Page;
        http_response_code(500);
-       if (!isset($Article)) {
+       if (!isset($Page)) {
                require_once('article.inc.php');
-               $Article = new ArchiveArticle(NULL);
-               $Article->title = 'Fout';
+               $Page = new ArchiveArticle(NULL);
+               $Page->title = 'Fout';
        }
        include_once 'page.inc.php';
        ob_start();
@@ -122,11 +124,10 @@ $Edit = isset($_GET['edit']);
 
 # setup requested page
 
-$Args = '';
-$Page = preg_replace('/\?.*/', '', @$_SERVER['PATH_INFO'] ?: $_SERVER['REQUEST_URI']);
-$Page = urldecode(trim($Page, '/')) ?: 'index';
+$request = preg_replace('/\?.*/', '', @$_SERVER['PATH_INFO'] ?: $_SERVER['REQUEST_URI']);
+$request = urldecode(trim($request, '/')) ?: 'index';
 
-$staticpage = "$Page.html";
+$staticpage = "$request.html";
 if (file_exists($staticpage)) {
        if (is_link($staticpage)) {
                $target = preg_replace('/\.html$/', '', readlink($staticpage));
@@ -135,21 +136,18 @@ if (file_exists($staticpage)) {
                exit;
        }
 }
-elseif (file_exists("$Page/index.html")) {
-       $staticpage = "$Page/index.html";
+elseif (file_exists("$request/index.html")) {
+       $staticpage = "$request/index.html";
 }
 
 require_once('article.inc.php');
-$Article = new ArchiveArticle($staticpage);
+$Page = new ArchiveArticle($staticpage);
 
-$Page = $Article->handler;
-$Args = $Article->path;
-
-if ($PageAccess = $Article->restricted) {
+if ($Page->restricted) {
        # access restriction
        if (!$User->login) {
                http_response_code(303);
-               $target = urlencode($Article->link);
+               $target = urlencode($Page->link);
                header("Location: /login?goto=$target");
                exit;
        }
@@ -170,32 +168,36 @@ $Place = [
        'url'   => htmlspecialchars($_SERVER['REQUEST_URI']),
 ];
 
-if (!isset($Article->raw) and $User->admin("edit {$Article->link}")) {
-       # open template as initial contents
-       $Article->raw(file_exists("$Page/template.inc.html") ? "$Page/template.inc.html" : 'template.inc.html');
-       $Article->meta['article:published_time'] = date('Y-m-d h:i:s O');
-       $Article->meta['article:author'] = '/' . $User->dir;
+if (!isset($Page->raw) and $User->admin("edit {$Page->link}")) {
+       # open bottom template as initial contents
+       $template = 'template.inc.html';
+       if ($Page->handler and file_exists("{$Page->handler}/$template")) {
+               $template = "{$Page->handler}/$template";
+       }
+       $Page->raw($template);
+       $Page->meta['article:published_time'] = date('Y-m-d h:i:s O');
+       $Page->meta['article:author'] = '/' . $User->dir;
 }
 
-if (isset($Article->raw)) {
-       if ($User->admin("edit $Page$Args")) {
+if (isset($Page->raw)) {
+       if ($User->admin("edit {$Page->link}")) {
                # restore meta tags in static contents for editing
-               foreach (array_reverse($Article->meta) as $metaprop => $val) {
-                       $Article->raw = sprintf(
+               foreach (array_reverse($Page->meta) as $metaprop => $val) {
+                       $Page->raw = sprintf(
                                '<meta property="%s" content="%s">'."\n",
                                $metaprop, $val
-                       ) . $Article->raw;
+                       ) . $Page->raw;
                }
        }
-       $Article->raw = '<div class="static">'."\n\n".$Article->raw."</div>\n\n";
+       $Page->raw = '<div class="static">'."\n\n".$Page->raw."</div>\n\n";
 }
 
 # output dynamic and/or static html
 
-if (!$Page or require("./$Page/index.php")) {
+if (!$Page->handler or require("./{$Page->handler}/index.php")) {
        # static contents
-       if (isset($Article->raw)) {
-               print $Article->raw;
+       if (isset($Page->raw)) {
+               print $Page->raw;
        }
        else {
                # no resulting output
index 63812591820b30be0d43ec92c6baf420f6257d36..104e1df53009d99187019e7129e615d9d12c19ac 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-list ($size, $imgpath) = explode('/', ltrim($Args, '/'), 2);
+list ($size, $imgpath) = explode('/', ltrim($Page->path, '/'), 2);
 $imgpath = preg_replace('{^(?=[0-9]+/)}', 'data/', $imgpath, 1);
 
 if (!file_exists($imgpath)) {
index 746e4b6f88559d1409185525e2142c5c2944fd74..29e73c60f7fe0c2bb457756857edb4bce8f99c09 100644 (file)
@@ -1,8 +1,8 @@
 <?php
-if (empty($Args)) {
+if (empty($Page->path)) {
        return;
 }
-@list ($target, $interval) = explode('+', ltrim($Args, '/'));
+@list ($target, $interval) = explode('+', ltrim($Page->path, '/'));
 $target = new DateTime($target);
 $now = new DateTime('NOW');
 $next = $target->diff($now);  # age
index 589c8d6afcb5a05ccc494d74fc39a70ad5bf4127..2288340a1a609f923c446e996e88560049092dbb 100644 (file)
@@ -2,7 +2,7 @@
 global $User;
 
 $cal = [];
-foreach (glob("$Page$Args/2*") as $url) {
+foreach (glob("{$Page->link}/2*") as $url) {
        $link = preg_replace('/\.html$/', '', $url);
        $name = pathinfo($link, PATHINFO_BASENAME);
        @list ($date, $suffix) = explode('.', $name, 2);
@@ -42,7 +42,7 @@ foreach (array_reverse($cal, TRUE) as $group => $rows) {
                else {
                        print '<span>';
                        print $title;
-                       if ($versions and $User->admin("edit $Page$Args")) {
+                       if ($versions and $User->admin("edit {$Page->link}")) {
                                printf(' (%s)', implode(', ', array_map(
                                        function ($format, $url) {
                                                return sprintf('<a href="/%s">%s</a>', $url, $format);
index 75135f85c1d23d00d4f71a51fd74d1a88f020159..d3ab1eba0498a397d072a9aa4de25a1a3c25fe30 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-       $article = new ArchiveArticle($Args);
+       $article = new ArchiveArticle($Page->path);
        printf('<a href="%s">%s</a>', $article->link, $article->name);
        if ($article->image) {
                printf("\n\t".'<img class="right" src="/%s" />', $article->thumb('100x100'));
index b9cae451be89d515367d0e0c9d91a3948b4f1d1d..d892cb591e169945945eb8646904dd10a3bbeddb 100644 (file)
@@ -26,7 +26,7 @@ if ( $log = popen($gitcmd, 'r') ) {
        print "</ul>\n\n";
        pclose($log);
 
-       $navbase = $Page == 'login/commits' ? '?' : '/login/commits?';
+       $navbase = $Page->handler == 'login/commits' ? '?' : '/login/commits?';
        $nav = [];
        $nav[] = sprintf('Pagina %d', ceil($offset / $pagesize) + 1);
        if ($lines >= $pagesize) {
index 17dbaac9282a81089d9c03a0fac5bdda5220c840..31d913044de23292e376502950621a09a789df64 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 $basepath = 'profile';
-if ($Args) $basepath .= '/.tags' . $Args;
+if ($Page->path) $basepath .= '/.tags' . $Page->path;
 $users = glob("$basepath/*/");
 if (!$users) return;
 
index c1b651a44853bd5ddb49c5383b7d0fb3bb4e4ab9..977357e5e572d4afff1d43b863f44caa0837c309 100644 (file)
@@ -53,7 +53,7 @@ function printtoc($input, $class = FALSE)
 }
 }
 
-$articles = (ltrim($Args, '/') ?: 'nieuws');
+$articles = (ltrim($Page->path, '/') ?: 'nieuws');
 if (strpos($articles, '/') === FALSE) {
        if (@$Place['view'] === 'toc') {
                print "<div>\n";
index c3864cc2ffbd199166ebf2d0eec6cf5796055443..10c3a2d46d85661c0fb8e6189e90a802bedd8340 100644 (file)
@@ -1,2 +1,2 @@
 <?php
-include ".$Args.html";
+include ".{$Page->path}.html";
index 3984349d82c646a6928fbd6d56efc03984e06569..ca38ce970d1885d964e216924e69b6a3e1feb1b8 100644 (file)
@@ -21,7 +21,7 @@ if ($_POST) {
                        }
                }
                $query = $Db->set('comments', [
-                       'page'    => $Page,
+                       'page'    => $Page->handler,
                        'message' => $html,
                        'author'  => $User->login,
                ]);
@@ -68,7 +68,7 @@ if ($_POST) {
 }
 
 $cols = '*, (SELECT json_agg(journal.*) FROM journal WHERE comment_id = comments.id) AS journal';
-$query = $Db->query("SELECT $cols FROM comments WHERE page = ? ORDER BY created", [$Page]);
+$query = $Db->query("SELECT $cols FROM comments WHERE page = ? ORDER BY created", [$Page->handler]);
 
 print '<ul class="replies">';
 
@@ -106,7 +106,7 @@ while ($row = $query->fetch()) {
 if ($User->login) {
        print '<li>';
        print '<form method="post" action="" enctype="multipart/form-data">';
-       if (isset($Issue) and $User->admin("edit $Page")) {
+       if (isset($Issue) and $User->admin("edit {$Page->handler}")) {
                print '<p>';
                printf(
                        '<label for="%s">%s:</label> '
index 20c89f8625a5f25f7511e5b6057a9a244da7a5ae..ff091f795c83b5ff291eadee3eaa1f529e749423 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 $limit = @$Place['limit'] ?: 10;
 $path = ' '.escapeshellarg('*.html');
-$query = @$_REQUEST['q'] ?: $Args ?: $Page;
+$query = @$_REQUEST['q'] ?: $Page->path ?: $Page->handler;
 
 if (!trim($query, '/')) return;
 
index 73b4cdc475d273356fa264742be3e8e77f64dd9c..8d7ba76db614b6748795fcecec8804c555c5832c 100644 (file)
@@ -1,8 +1,9 @@
 <?php
 # list article details
-$search = new PageSearch(ltrim($Args, '/') ?: '.');
+$search = new PageSearch(ltrim($Page->path, '/') ?: '.');
 print '<ul class="replies">'."\n";
-foreach ($search->files() as $Args => $sorted) {
+foreach ($search->files() as $ref => $sorted) {
+       $Page->path = $ref;
        print '<li>';
        include 'linkref.php';
        print "</li>\n";