From 772961fd4e9be46ad340cad1e55ee5f28cc5b968 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 3 Dec 2020 20:59:58 +0100 Subject: [PATCH] page: replace global variables by $Page object 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. --- article.inc.php | 6 ++++ edit/foto/cover/index.php | 6 ++-- edit/nieuws/tag/index.php | 4 +-- edit/page/index.php | 6 ++-- foto/album.inc.php | 2 +- foto/index.php | 18 +++++------ head.inc.php | 16 ++++----- issue/feed.inc.php | 4 +-- issue/index.php | 22 ++++++------- login/edit/index.php | 8 ++--- login/index.php | 23 +++++++------ login/post/index.php | 2 +- mail/index.php | 6 ++-- nieuws/feed/index.php | 2 +- nieuws/index.php | 26 +++++++-------- page.inc.php | 8 ++--- page.php | 68 ++++++++++++++++++++------------------- thumb/index.php | 2 +- widget/countdown.php | 4 +-- widget/doclist.php | 4 +-- widget/linkref.php | 2 +- widget/login/commits.php | 2 +- widget/login/list.php | 2 +- widget/nieuws.php | 2 +- widget/page.php | 2 +- widget/reply.php | 6 ++-- widget/search.php | 2 +- widget/sitemap.php | 5 +-- 28 files changed, 134 insertions(+), 126 deletions(-) diff --git a/article.inc.php b/article.inc.php index 93bbe3b..acd219d 100644 --- a/article.inc.php +++ b/article.inc.php @@ -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)); diff --git a/edit/foto/cover/index.php b/edit/foto/cover/index.php index 2558e10..06acc1d 100644 --- a/edit/foto/cover/index.php +++ b/edit/foto/cover/index.php @@ -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; } } diff --git a/edit/nieuws/tag/index.php b/edit/nieuws/tag/index.php index ca477c8..ba57adc 100644 --- a/edit/nieuws/tag/index.php +++ b/edit/nieuws/tag/index.php @@ -1,10 +1,10 @@ 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'); diff --git a/edit/page/index.php b/edit/page/index.php index 910b7c9..13ebd24 100644 --- a/edit/page/index.php +++ b/edit/page/index.php @@ -1,5 +1,5 @@ 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")) diff --git a/foto/album.inc.php b/foto/album.inc.php index 92a7395..692aafa 100644 --- a/foto/album.inc.php +++ b/foto/album.inc.php @@ -26,7 +26,7 @@ function openphotoswipe(index) { 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}}" ); } ?> diff --git a/foto/index.php b/foto/index.php index 27482a4..0acd44e 100644 --- a/foto/index.php +++ b/foto/index.php @@ -1,12 +1,12 @@ link; if ($User->admin('foto')) { - if (!empty($PageAccess)) { + if ($Page->restricted) { $access = '🔒 Bewoners'; - if ($PageAccess != $rootdir) { + if ($Page->restricted != $rootdir) { $access .= sprintf(' vanaf %s', - "/$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 "

"; foreach ($nav as $i => $linktitle) { - $link .= '/' . ($i ? $linktitle : $Page); + $link .= '/' . ($i ? $linktitle : $Page->handler); printf('%s →'."\n", $link, $linktitle); } print $title; print "

\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; diff --git a/head.inc.php b/head.inc.php index 34e0d04..4082b92 100644 --- a/head.inc.php +++ b/head.inc.php @@ -2,18 +2,18 @@ -title) { ?> - <?= htmlspecialchars($Article->safetitle) ?> +title) { ?> + <?= htmlspecialchars($Page->safetitle) ?> -teaser) { ?> - +teaser) { ?> + -image) { ?> - +image) { ?> + - - + + diff --git a/issue/feed.inc.php b/issue/feed.inc.php index f5cf847..1061bf0 100644 --- a/issue/feed.inc.php +++ b/issue/feed.inc.php @@ -16,8 +16,8 @@ $siteref = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . '://' . $_SERVER['HTT while ($row = $query->fetch()) { ?> - id}/{$row->link}" ?> - id}/{$row->link}" ?>" /> + handler}/{$row->id}/{$row->link}" ?> + handler}/{$row->id}/{$row->link}" ?>" /> <?= $row->subject ?> created ?> updated ?> diff --git a/issue/index.php b/issue/index.php index cc17f03..41d3749 100644 --- a/issue/index.php +++ b/issue/index.php @@ -1,23 +1,23 @@ 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 "

{$Article->title}

\n"; + print "

{$Page->title}

\n"; print '