From 7983570288ed2798470a552ec04f64aa646b664a Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 3 Dec 2020 22:28:09 +0100 Subject: [PATCH] page: move placeholder_include() to widget method --- article.inc.php | 32 ++++++++++++++++++++++++++++++++ issue/index.php | 2 +- login/edit/index.php | 4 ++-- nieuws/index.php | 4 ++-- page.php | 32 -------------------------------- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/article.inc.php b/article.inc.php index acd219d..b676dd0 100644 --- a/article.inc.php +++ b/article.inc.php @@ -170,6 +170,38 @@ class ArchiveArticle $this->image ); } + + function widget($name, $params = []) + { + $path = stream_resolve_include_path("widget/$name.php"); + if (!file_exists($path)) { + return ''.$name.' ontbreekt'; + } + + ob_start(); + $Page = clone $this; + $Page->handler = $Page->handler . $Page->path; // .= with explicit getter + $Page->path = ''; + $Place = $GLOBALS['Place']; + foreach ($params as $param) { + if ($set = strpos($param, '=')) { + $Place[ substr($param, 0, $set) ] = substr($param, $set + 1); + } + elseif (!empty($param)) { + $Page->path .= '/'.$param; + } + } + $Page->link .= $Page->path; + try { + include "widget/$name.php"; + return ob_get_clean(); + } + catch (Exception $e) { + return sprintf('%s', + "fout in $name: {$e->getMessage()}" + ); + } + } } class PageSearch diff --git a/issue/index.php b/issue/index.php index 41d3749..181d5b7 100644 --- a/issue/index.php +++ b/issue/index.php @@ -11,7 +11,7 @@ if ($id and ctype_digit($id)) { )->fetch(); if (!$Issue) throw new Exception('Issuenummer niet gevonden'); - $replies = placeholder_include('reply'); # handle updates + $replies = $Page->widget('reply'); # handle updates $Page->title .= ': '.htmlspecialchars($Issue->subject); $Page->teaser = $Issue->body; diff --git a/login/edit/index.php b/login/edit/index.php index 3360ec7..2ba0cf3 100644 --- a/login/edit/index.php +++ b/login/edit/index.php @@ -1,9 +1,9 @@ path and $User->admin('user')) { $user = new User(strtolower("profile{$Page->path}"), FALSE); - print placeholder_include('login/admin'); + print $Page->widget('login/admin'); $Page->title = "Profiel {$user->login}"; print "

{$Page->title}

\n"; - print placeholder_include('login/edit'); + print $Page->widget('login/edit'); return; } diff --git a/nieuws/index.php b/nieuws/index.php index 0840015..0bb72f9 100644 --- a/nieuws/index.php +++ b/nieuws/index.php @@ -41,7 +41,7 @@ if ($page and !is_numeric($page)) { } } if ($replyform) { - print placeholder_include('reply'); + print $Page->widget('reply'); } return; } @@ -67,6 +67,6 @@ if ($year) { } print "

$title

\n\n"; - print placeholder_include('nieuws', [$match]); + print $Page->widget('nieuws', [$match]); return; } diff --git a/page.php b/page.php index a469a9d..d5c78cd 100644 --- a/page.php +++ b/page.php @@ -8,38 +8,6 @@ function abort($body, $status = NULL) { exit; } -function placeholder_include($name, $params = []) -{ - $path = stream_resolve_include_path("widget/$name.php"); - if (!file_exists($path)) { - return ''.$name.' ontbreekt'; - } - - ob_start(); - $Page = clone $GLOBALS['Page']; - $Page->handler = $Page->handler . $Page->path; // .= with explicit getter - $Page->path = ''; - $Place = $GLOBALS['Place']; - foreach ($params as $param) { - if ($set = strpos($param, '=')) { - $Place[ substr($param, 0, $set) ] = substr($param, $set + 1); - } - elseif (!empty($param)) { - $Page->path .= '/'.$param; - } - } - $Page->link .= $Page->path; - try { - include "widget/$name.php"; - return ob_get_clean(); - } - catch (Exception $e) { - return sprintf('%s', - "fout in $name: {$e->getMessage()}" - ); - } -} - function getoutput($blocks = []) { $doc = ob_get_clean(); -- 2.30.0