login: userless handler call to obtain metadata
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 9 Dec 2020 07:55:48 +0000 (08:55 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 19 Dec 2020 02:01:43 +0000 (03:01 +0100)
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.

edit/index.php
foto/index.php
issue/index.php
login/index.php
login/post/index.php
mail/index.php
nieuws/index.php
sitemap.xml/index.php
thumb/index.php

index 922db803654274bc575929155f2455074fab5505..ae2da7e6031cc2ec565b170e8a98783c2994aee9 100644 (file)
@@ -1,2 +1,3 @@
 <?php
+if (!$User) return;
 abort("aanpasdienst onbekend", '404 unknown');
index 0acd44e7ab701aa6bfb091ed5c4a96ac08221521..c2cc95c730a37361bc82143085340dc8593df233 100644 (file)
@@ -1,6 +1,20 @@
 <?php
 $rootdir = $Page->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 = '<span class="icon icon-locked">&#x1F512;</span> Bewoners';
@@ -16,11 +30,6 @@ if ($User->admin('foto')) {
        print "<aside>$access</aside>\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 "<h2>";
 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('<a href="/%s"><%s /></a>'."\n", $target, $imgtag);
 }
+}
 
 if ($imgs = glob("$rootdir/*", GLOB_ONLYDIR)) {
        natsort($imgs);
index 8c58f415de331bb8e23f42e8a4759e8fcd7fb2b2..e8a36d21e2efb3f3470f2ff17441b553a46e7f59 100644 (file)
@@ -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 "<h2>{$Page->title}</h2>\n";
@@ -40,6 +41,7 @@ if ($id and ctype_digit($id)) {
        print "</div>\n";
        return;
 }
+elseif (!$User) return;
 
 if ($_POST) {
                require_once 'upload.inc.php';
index 7038dcbdcf7d9085b1a802f4c5548f35cd887a35..2b073f03d6da4c563bfbab9639610047070ebcea 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+if (!$User) return;
 $message = NULL;
 
 if (isset($_POST['mail'])) {
@@ -42,9 +43,9 @@ if (!$User or !$User->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();
index 276848e8dfa4aeffd00d13ccbea2a60eb4affd88..442efefd3e2afa8e62486407108b21817c7bf352 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+if (!$User) return;
+
 if (!$User->login) {
        http_response_code(303);
        $target = urlencode($_SERVER['REQUEST_URI']);
index 8fb49c7f8d27ef144c1dd9f4bdab064d7e0d94ee..908e53165c013d4383bc697d59eeb5ec5ca172e2 100644 (file)
@@ -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.";
index 61ba993d39d4d4a571ee0b64a3216d20e4f9a76d..59b24a426674afe04d1292e18647fb89f22952a4 100644 (file)
@@ -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 = '<script src="/nieuws/edit.js"></script>'."\n" . $Page->raw;
 }
index 0e68218fc972a001a6f4abf9d8603c0425bbd9dd..55c293ca9ed31d13e93fdde83a0757627711ff1a 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+if (!$User) return;
 header('Content-Type: application/atom+xml; charset=utf-8');
 print '<?xml version="1.0" encoding="utf-8"?>';
 $siteref = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . '://' . $_SERVER['HTTP_HOST'];
index 104e1df53009d99187019e7129e615d9d12c19ac..a6b5bd7d66cce6d27560b120955a3fae695aaaa1 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+if (!$User) return;
 list ($size, $imgpath) = explode('/', ltrim($Page->path, '/'), 2);
 $imgpath = preg_replace('{^(?=[0-9]+/)}', 'data/', $imgpath, 1);