page: replace output caching by article object
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 24 Oct 2019 21:49:46 +0000 (23:49 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 9 Nov 2019 06:08:13 +0000 (07:08 +0100)
14 files changed:
edit/foto/cover/index.php
edit/index.php
edit/nieuws/tag/index.php
edit/page/index.php
foto/index.php
login/admin/index.php
login/edit/index.php
login/index.php
login/post/index.php
nieuws/feed/index.php
nieuws/index.php
page.php
sitemap.xml/index.php
thumb/index.php

index 3ae5dcf99f6e0d4e251eff101c1b0c20b6b4662a..ab86a2f8e71e1abb02e7de640dd932a11f3df7b8 100644 (file)
@@ -1,6 +1,4 @@
 <?php
-ob_clean();
-
 if (!$User or !$User->admin('foto')) {
        http_response_code(403);
        print "Beheerrechten verplicht voor instellen van covers\n";
@@ -31,3 +29,4 @@ if (isset($_GET['img'])) {
 $album = pathinfo($rootdir);
 header("Location: /{$album['dirname']}#{$album['basename']}");
 http_response_code(302);
+exit;
index a6a64a2cb08e4c21b48184a3ba889ef917bdc800..922db803654274bc575929155f2455074fab5505 100644 (file)
@@ -1,3 +1,2 @@
 <?php
-ob_clean();
 abort("aanpasdienst onbekend", '404 unknown');
index 01a385c0c1175b987204b1f7fcb8bb6960824d75..c65b81ebd810cf54d70093d7c57029d8bb888bd4 100644 (file)
@@ -1,6 +1,4 @@
 <?php
-ob_clean();
-
 if (!$User or !$User->admin('news'))
        abort("geen beheersrechten", '401 unauthorised');
 
index 32564ab299d39b345f48b9e0a148ed04f33cbece..086c7531c56683381713bf213fafb915127cae2e 100644 (file)
@@ -1,6 +1,4 @@
 <?php
-ob_clean();
-
 if (!$User or !$User->admin("edit $Page$Args"))
        abort("geen beheersrechten", '401 unauthorised');
 
index 550e7a3e674870ecf7909aba100a53ccc9fadf57..d3e989873ca9c3491f9875c864b6e1ca5c4e8531 100644 (file)
@@ -1,6 +1,4 @@
 <?php
-$intro = ob_get_clean();
-
 $rootdir = $Page . $Args;
 
 if ($User and $User->admin('foto')) {
@@ -30,7 +28,9 @@ foreach ($nav as $i => $linktitle) {
 print $title;
 print "</h2>\n\n";
 
-print $intro;
+if (isset($Article->raw)) {
+       print $Article->raw;  # page intro
+}
 
 function showthumb($path)
 {
@@ -89,3 +89,5 @@ if ($imgs = glob("$rootdir/*.jpg")) {
 
        include 'foto/album.inc.php';
 }
+
+return;
index 28f513d8a3e506f28af95c4525f9d2d95d83818a..eb8a8773d19d2aebdc31a371bd861f5e9499d561 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 if (!$User or !$User->admin('site')) {
-       ob_clean();
        http_response_code(403);
 ?>
 <h2>Verboden toegang</h2>
index 23e6da46acbe95321ec956197853e5867cb1ca16..c56109fbd53df0992d186019fba7fc5e3d53d127 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 if ($Args) {
-       ob_clean();
        $Place['user'] = ltrim($Args, '/');
        include 'login/edit/index.html';
+       return;
 }
index 5cfbdedf8d322d00fd171a1436e48a238a6812f4..66cb0c943c485edd8fe58ea9a7e6a8ebcfe7d091 100644 (file)
@@ -36,7 +36,6 @@ elseif (isset($_GET['logout'])) {
 }
 
 if (empty($User)) {
-       ob_clean();
        require_once 'login/form.inc.php';
        $Place['warn'] = $message;
        $Article->title = 'Inloggen';
@@ -47,18 +46,21 @@ if (empty($User)) {
                        $Article->title .= ' voor ' . $target->title;
                }
        }
-       return TRUE;
+       return;
 }
 
 if (isset($_REQUEST['goto'])) {
-       ob_clean();
        $target = ltrim($_REQUEST['goto'], '/');
        header("Location: /$target");
        http_response_code(302);
        exit;
 }
 
+if (isset($Article->raw)) {
+       print $Article->raw;
+}
 if (empty($Args) and $User and $User->admin) {
        include_once 'login/admin.html';
 }
 
+return;
index e491e357b53c10090a8abef52ca2ab22441dc823..9578d3cc01d8ba41c175ac18ac0e8f2f5c24bb71 100644 (file)
@@ -1,6 +1,4 @@
 <?php
-$body = ob_get_clean();
-
 if ($User->admin('user') and $username = @$_REQUEST['login']) {
        try {
                $user = new User("profile/$username");
@@ -28,4 +26,3 @@ else {
 }
 
 print '<p class="nav right"><a href="javascript:window.print()">Print</a></p>'."\n";
-print $body;
index 66855b149e88e1c8dfaf130bae47eebcf2c3217b..00fa7ea3dcb585c642caee99ee2e85c7e9ae5230 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-ob_clean();
 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 3a50265955977b618d71c73c28cf5afea7151a01..53dff0de76e24400c906372abc61bd8ce0f4f55c 100644 (file)
@@ -14,7 +14,7 @@ if ($page and !is_numeric($page)) {
        if ($Article->dateparts) {
                $Place[1] = ' <small class="date">'.$Article->date.'</small>';
        }
-       print preg_replace('{(?<=<h2>)(.*?)(?=</h2>)}', ($edit ?: '\1').' [[1]]', ob_get_clean());
+       print preg_replace('{(?<=<h2>)(.*?)(?=</h2>)}', ($edit ?: '\1').' [[1]]', $Article->raw);
        if ($User and $User->admin('news')) {
                $taglist = [];
                foreach (glob("$Page/.tags/*") as $tagpath) {
@@ -39,11 +39,10 @@ if ($page and !is_numeric($page)) {
        if ($replyform) {
                print placeholder_include('reply');
        }
-       return 1;
+       return;
 }
 
 if ($year) {
-       ob_clean();
        $match = $Page;
        $title = "Nieuws";
        if (is_numeric($year) and $year > 999) {
@@ -65,5 +64,5 @@ if ($year) {
 
        print "<h2>$title</h2>\n\n";
        print placeholder_include('nieuws', [$match]);
-       return 1;
+       return;
 }
index f5e9749cbeac10837f6d9bf0fb923c5a4234114d..f02544bd0b06dbd7add643d19a17e02bbdca69c2 100644 (file)
--- a/page.php
+++ b/page.php
@@ -163,42 +163,33 @@ elseif ($User and $User->admin("edit $Page$Args")) {
        $staticpage = (file_exists("$Page/template.inc.html") ? "$Page/template.inc.html" : 'template.inc.html');
 }
 
-# load static contents
+# prepare page contents
 
 require_once('article.inc.php');
 $Article = new ArchiveArticle($staticpage);
 
 ob_start(); # page body
-ob_start(); # inner html
-print '<div class="static">'."\n\n";
-
-$found = FALSE;
-if (isset($Article->raw)) {
-       print $Article->raw;
-       $found = 1;
-}
-
-print "</div>\n\n";
-
-# execute dynamic code
-
-$Place = [];
-
-if ($Page) {
-       $found |= require "./$Page/index.php";
-}
-
-$Place += [
+$Place = [
        'user'  => $User ? $User->login : '',
        'url'   => htmlspecialchars($_SERVER['REQUEST_URI']),
 ];
 
-# global html
+if (isset($Article->raw)) {
+       $Article->raw = '<div class="static">'."\n\n".$Article->raw."</div>\n\n";
+}
 
-if (!$found) {
-       # no resulting output
-       http_response_code(404);
-       @require '404.inc.html';
+# output dynamic and/or static html
+
+if (!$Page or require("./$Page/index.php")) {
+       # static contents
+       if (isset($Article->raw)) {
+               print $Article->raw;
+       }
+       else {
+               # no resulting output
+               http_response_code(404);
+               @require '404.inc.html';
+       }
 }
 
 include_once 'page.inc.php';
index f0f928bd5c4db75e9e4fdfb2d9187a0b8a14afdc..0e68218fc972a001a6f4abf9d8603c0425bbd9dd 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-ob_clean();
 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 b4f6091f5005ec405e433504ebb1f98d098cbb36..4549b44e6ab67385c52d6168da8b8b529ea16fe4 100644 (file)
@@ -1,6 +1,4 @@
 <?php
-ob_clean();
-
 list ($size, $imgpath) = explode('/', ltrim($Args, '/'), 2);
 $imgpath = preg_replace('{^(?=[0-9]+/)}', 'data/', $imgpath, 1);