From b3aec6cf1cd18493d44cf68d88c8f55b6a417f9c Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 24 Oct 2019 23:49:46 +0200 Subject: [PATCH] page: replace output caching by article object --- edit/foto/cover/index.php | 3 +-- edit/index.php | 1 - edit/nieuws/tag/index.php | 2 -- edit/page/index.php | 2 -- foto/index.php | 8 +++++--- login/admin/index.php | 1 - login/edit/index.php | 2 +- login/index.php | 8 +++++--- login/post/index.php | 3 --- nieuws/feed/index.php | 1 - nieuws/index.php | 7 +++---- page.php | 43 ++++++++++++++++----------------------- sitemap.xml/index.php | 1 - thumb/index.php | 2 -- 14 files changed, 32 insertions(+), 52 deletions(-) diff --git a/edit/foto/cover/index.php b/edit/foto/cover/index.php index 3ae5dcf..ab86a2f 100644 --- a/edit/foto/cover/index.php +++ b/edit/foto/cover/index.php @@ -1,6 +1,4 @@ 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; diff --git a/edit/index.php b/edit/index.php index a6a64a2..922db80 100644 --- a/edit/index.php +++ b/edit/index.php @@ -1,3 +1,2 @@ admin('news')) abort("geen beheersrechten", '401 unauthorised'); diff --git a/edit/page/index.php b/edit/page/index.php index 32564ab..086c753 100644 --- a/edit/page/index.php +++ b/edit/page/index.php @@ -1,6 +1,4 @@ admin("edit $Page$Args")) abort("geen beheersrechten", '401 unauthorised'); diff --git a/foto/index.php b/foto/index.php index 550e7a3..d3e9898 100644 --- a/foto/index.php +++ b/foto/index.php @@ -1,6 +1,4 @@ admin('foto')) { @@ -30,7 +28,9 @@ foreach ($nav as $i => $linktitle) { print $title; print "\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; diff --git a/login/admin/index.php b/login/admin/index.php index 28f513d..eb8a877 100644 --- a/login/admin/index.php +++ b/login/admin/index.php @@ -1,6 +1,5 @@ admin('site')) { - ob_clean(); http_response_code(403); ?>

Verboden toegang

diff --git a/login/edit/index.php b/login/edit/index.php index 23e6da4..c56109f 100644 --- a/login/edit/index.php +++ b/login/edit/index.php @@ -1,6 +1,6 @@ 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; diff --git a/login/post/index.php b/login/post/index.php index e491e35..9578d3c 100644 --- a/login/post/index.php +++ b/login/post/index.php @@ -1,6 +1,4 @@ admin('user') and $username = @$_REQUEST['login']) { try { $user = new User("profile/$username"); @@ -28,4 +26,3 @@ else { } print ''."\n"; -print $body; diff --git a/nieuws/feed/index.php b/nieuws/feed/index.php index 66855b1..00fa7ea 100644 --- a/nieuws/feed/index.php +++ b/nieuws/feed/index.php @@ -1,5 +1,4 @@ '; $siteref = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . '://' . $_SERVER['HTTP_HOST']; diff --git a/nieuws/index.php b/nieuws/index.php index 3a50265..53dff0d 100644 --- a/nieuws/index.php +++ b/nieuws/index.php @@ -14,7 +14,7 @@ if ($page and !is_numeric($page)) { if ($Article->dateparts) { $Place[1] = ' '.$Article->date.''; } - print preg_replace('{(?<=

)(.*?)(?=

)}', ($edit ?: '\1').' [[1]]', ob_get_clean()); + print preg_replace('{(?<=

)(.*?)(?=

)}', ($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 "

$title

\n\n"; print placeholder_include('nieuws', [$match]); - return 1; + return; } diff --git a/page.php b/page.php index f5e9749..f02544b 100644 --- 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 '
'."\n\n"; - -$found = FALSE; -if (isset($Article->raw)) { - print $Article->raw; - $found = 1; -} - -print "
\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 = '
'."\n\n".$Article->raw."
\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'; diff --git a/sitemap.xml/index.php b/sitemap.xml/index.php index f0f928b..0e68218 100644 --- a/sitemap.xml/index.php +++ b/sitemap.xml/index.php @@ -1,5 +1,4 @@ '; $siteref = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . '://' . $_SERVER['HTTP_HOST']; diff --git a/thumb/index.php b/thumb/index.php index b4f6091..4549b44 100644 --- a/thumb/index.php +++ b/thumb/index.php @@ -1,6 +1,4 @@