From: Mischa POSLAWSKY Date: Wed, 9 Dec 2020 07:55:48 +0000 (+0100) Subject: login: userless handler call to obtain metadata X-Git-Tag: v5.0~20 X-Git-Url: http://git.shiar.nl/minimedit.git/commitdiff_plain/b9757db57858fdcff8af1a6566e299559e491b17 login: userless handler call to obtain metadata Generic solution (previously hardcoded to only /melding) to run code of any forwarding request, returning at least custom title, teaser, and image, without having to construct full html. --- diff --git a/edit/index.php b/edit/index.php index 922db80..ae2da7e 100644 --- a/edit/index.php +++ b/edit/index.php @@ -1,2 +1,3 @@ link; +$nav = explode('/', $rootdir); +$nav[0] = "Foto's"; # override of root 'foto' +$title = array_pop($nav); +$Page->title = ($nav ? implode(' ', $nav) . ': ' : '') . $title; + +if (!$User) { + $img = "$rootdir/index.jpg"; + if (file_exists($img)) { + # cover image of current album + $Page->image = "/$img"; + } + return; +} + if ($User->admin('foto')) { if ($Page->restricted) { $access = '🔒 Bewoners'; @@ -16,11 +30,6 @@ if ($User->admin('foto')) { print "\n\n"; } -$nav = explode('/', $rootdir); -$nav[0] = "Foto's"; # override of root 'foto' -$title = array_pop($nav); -$Page->title = ($nav ? implode(' ', $nav) . ': ' : '') . $title; - $link = ''; print "

"; foreach ($nav as $i => $linktitle) { @@ -34,6 +43,7 @@ if (isset($Page->raw)) { print $Page->raw; # page intro } +if (!function_exists('showthumb')) { function showthumb($path) { // assume all album entries are symlinks to archive originals @@ -51,6 +61,7 @@ function showthumb($path) return sprintf('<%s />'."\n", $target, $imgtag); } +} if ($imgs = glob("$rootdir/*", GLOB_ONLYDIR)) { natsort($imgs); diff --git a/issue/index.php b/issue/index.php index 8c58f41..e8a36d2 100644 --- a/issue/index.php +++ b/issue/index.php @@ -15,6 +15,7 @@ if ($id and ctype_digit($id)) { $Page->title .= ': '.htmlspecialchars($Issue->subject); $Page->teaser = $Issue->body; + if (!$User) return; $Page->body = $replies; # find image print "

{$Page->title}

\n"; @@ -40,6 +41,7 @@ if ($id and ctype_digit($id)) { print "\n"; return; } +elseif (!$User) return; if ($_POST) { require_once 'upload.inc.php'; diff --git a/login/index.php b/login/index.php index 7038dcb..2b073f0 100644 --- a/login/index.php +++ b/login/index.php @@ -1,4 +1,5 @@ login) { $target = ltrim($_REQUEST['goto'], '/'); $target = new ArchiveArticle("$target.html"); - if ($target and $target->handler == 'melding') { + if ($target and $target->handler) { # run forbidden handler to determine metadata - #TODO: generic solution + $User = NULL; $caller = $Page; $Page = $target; ob_start(); diff --git a/login/post/index.php b/login/post/index.php index 276848e..442efef 100644 --- a/login/post/index.php +++ b/login/post/index.php @@ -1,4 +1,6 @@ login) { http_response_code(303); $target = urlencode($_SERVER['REQUEST_URI']); diff --git a/mail/index.php b/mail/index.php index 8fb49c7..908e531 100644 --- a/mail/index.php +++ b/mail/index.php @@ -49,6 +49,9 @@ if ($msgid) { return; } +if (!$User) { + return; +} if (!$User->admin('user')) { http_response_code(403); $Page->place['warn'] = "Geen gebruikersrechten om e-mails in te zien."; diff --git a/nieuws/index.php b/nieuws/index.php index 61ba993..59b24a4 100644 --- a/nieuws/index.php +++ b/nieuws/index.php @@ -2,6 +2,8 @@ $replyform = $Page->handler == 'melding' && $User->login; @list ($year, $page) = explode('/', trim($Page->path, '/')); +if (!$User) return; + if ($User->admin("edit {$Page->handler}")) { $Page->raw = ''."\n" . $Page->raw; } diff --git a/sitemap.xml/index.php b/sitemap.xml/index.php index 0e68218..55c293c 100644 --- a/sitemap.xml/index.php +++ b/sitemap.xml/index.php @@ -1,4 +1,5 @@ '; $siteref = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . '://' . $_SERVER['HTTP_HOST']; diff --git a/thumb/index.php b/thumb/index.php index 104e1df..a6b5bd7 100644 --- a/thumb/index.php +++ b/thumb/index.php @@ -1,4 +1,5 @@ path, '/'), 2); $imgpath = preg_replace('{^(?=[0-9]+/)}', 'data/', $imgpath, 1);