page: api attribute indicate index requests
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 27 Dec 2020 18:33:48 +0000 (19:33 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Fri, 1 Jan 2021 17:30:40 +0000 (18:30 +0100)
Replaces userless calls for better fault tolerance and permission support.

article.inc.php
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 9e920942c76b888bbf1da2cb5b8a8a0b06f70ceb..1dbda25e0dc1b3c70186114979605e71a8a9acfa 100644 (file)
@@ -4,6 +4,7 @@ class ArchiveArticle
        public $raw, $title, $body; # file contents
        public $meta = [];  # head metadata properties
        public $place = []; # template variables replaced in render()
+       public $api = FALSE; # requested programming interface
 
        function __construct($path)
        {
@@ -71,7 +72,7 @@ class ArchiveArticle
                if (empty($this->handler)) {
                        return;
                }
-               $User = NULL;
+               $this->api = TRUE;
                $Page = $this;
                $res = include "./{$this->handler}/index.php";
                return $res;
index ae2da7e6031cc2ec565b170e8a98783c2994aee9..ebf3d5d9fe086257a745dffc048b4236b4147dd1 100644 (file)
@@ -1,3 +1,3 @@
 <?php
-if (!$User) return;
+if ($Page->api) return;
 abort("aanpasdienst onbekend", '404 unknown');
index 7df1d5c26daa1c27ed9efda43531f6997fe96d4e..a6378ef8f393487113b64b430a121adb4d33d511 100644 (file)
@@ -6,7 +6,7 @@ $nav[0] = "Foto's"; # override of root 'foto'
 $title = array_pop($nav);
 $Page->title = ($nav ? implode(' ', $nav) . ': ' : '') . $title;
 
-if (!$User) {
+if ($Page->api) {
        $img = "$rootdir/index.jpg";
        if (file_exists($img)) {
                # cover image of current album
index e8a36d21e2efb3f3470f2ff17441b553a46e7f59..87b22a39d876ac8774a1a1a512e52e025e9176b0 100644 (file)
@@ -15,7 +15,7 @@ if ($id and ctype_digit($id)) {
 
        $Page->title .= ': '.htmlspecialchars($Issue->subject);
        $Page->teaser = $Issue->body;
-       if (!$User) return;
+       if ($Page->api) return;
        $Page->body = $replies;  # find image
 
        print "<h2>{$Page->title}</h2>\n";
@@ -41,7 +41,6 @@ if ($id and ctype_digit($id)) {
        print "</div>\n";
        return;
 }
-elseif (!$User) return;
 
 if ($_POST) {
                require_once 'upload.inc.php';
@@ -56,6 +55,7 @@ if ($_POST) {
                }
                $_POST = [];
 }
+if ($Page->api) return;
 
 $subsql = "SELECT count(*) FROM comments WHERE page=i.page||'/'||i.id";
 $cols = "*, ($subsql AND message IS NOT NULL) AS replycount";
index 8e36628be24128aae6c4664555581390c443694d..38b7c234465006445ac2d89491b9c3cc7c60cc7b 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-if (!$User) return;
+if ($Page->api) return;
 $message = NULL;
 
 if (isset($_POST['mail'])) {
index 23c445146e95820b5b2612967eecf459303c2f63..c4dcffce17d16f0b42188ebe01631a07d07a7162 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-if (!$User) return;
+if ($Page->api) return;
 
 if (!$User->login) {
        $target = urlencode($_SERVER['REQUEST_URI']);
index 2b6e6008214199078b2f663a8ae55449badbd922..ee7365aa62cb321de3af6581704edea85cf063e2 100644 (file)
@@ -55,7 +55,7 @@ if ($msgid) {
        return;
 }
 
-if (!$User) {
+if ($Page->api) {
        return;
 }
 if (!$User->admin('user')) {
index 6ea68dc43a7fc130805a9a1ffcac7b288c905fb0..1cbaf9459c488571249aa020b17e2fd83a6fee9b 100644 (file)
@@ -2,7 +2,7 @@
 $replyform = $Page->handler == 'melding' && $User->login;
 @list ($year, $page) = explode('/', trim($Page->path, '/'));
 
-if (!$User) {
+if ($Page->api) {
        if ($Page->path) return;
        return (new PageSearch($Page->link))->files();
 }
index 82abc75ab7bd639f51a244f10813e221bac747cd..99b6fcfb0a93d2e98655bcbc9a8bc0e376d3ae4e 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-if (!$User) return;
+if ($Page->api) 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 42e9362e41fb762085050fa62881a7c008699dea..9232b3332be5de1c33370705b4ea41e273b427d3 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-if (!$User) return;
+if ($Page->api) return;
 $imgpath = ltrim($Page->path, '/');
 if (!preg_match('{^[0-9x]+/}', $imgpath)) {
        return;