From: Mischa POSLAWSKY Date: Thu, 3 Dec 2020 21:22:28 +0000 (+0100) Subject: page: store placeholder values in $Page object X-Git-Tag: v5.0~39 X-Git-Url: http://git.shiar.nl/minimedit.git/commitdiff_plain/b04f76050d54c67844d5d4026993f6fab0edeae5 page: store placeholder values in $Page object --- diff --git a/article.inc.php b/article.inc.php index c630898..cff69ff 100644 --- a/article.inc.php +++ b/article.inc.php @@ -18,6 +18,7 @@ class ArchiveArticle { public $raw, $title, $body; # file contents public $meta = []; # head metadata properties + public $place = []; # template variables replaced in render() function __construct($path) { @@ -184,10 +185,9 @@ class ArchiveArticle $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); + $Page->place[ substr($param, 0, $set) ] = substr($param, $set + 1); } elseif (!empty($param)) { $Page->path .= '/'.$param; @@ -205,11 +205,11 @@ class ArchiveArticle } } - function render($blocks = []) + function render() { $doc = ob_get_clean(); - if (!empty($blocks['warn'])) { + if (!empty($this->place['warn'])) { $warn = '

[[warn]]

'; if ($offset = strpos($doc, '')) { $doc = substr_replace($doc, "\n\n".$warn, $offset + 5, 0); @@ -226,9 +226,9 @@ class ArchiveArticle return preg_replace_callback( '{ \[\[ ([^] ]+) ([^]]*) \]\] }x', - function ($sub) use ($blocks) { + function ($sub) { list ($placeholder, $name, $params) = $sub; - $html = $blocks[$name] ?? + $html = $this->place[$name] ?? $this->widget($name, explode(' ', $params)); if (empty($html) or $html[0] != '<') { $html = "$html"; diff --git a/issue/index.php b/issue/index.php index 181d5b7..8c58f41 100644 --- a/issue/index.php +++ b/issue/index.php @@ -97,4 +97,4 @@ while ($row = $query->fetch()) { print "\n"; } print "\n"; -$Place['issuelist'] = ob_get_clean(); +$Page->place['issuelist'] = ob_get_clean(); diff --git a/login/index.php b/login/index.php index 4ecee45..e1f0cae 100644 --- a/login/index.php +++ b/login/index.php @@ -61,7 +61,7 @@ if (!$User or !$User->login) { ob_start(); require_once 'login/form.inc.php'; $Page->raw = ob_get_clean(); - $Place['warn'] = $message; + $Page->place['warn'] = $message; return TRUE; } diff --git a/login/post/index.php b/login/post/index.php index f4c7759..276848e 100644 --- a/login/post/index.php +++ b/login/post/index.php @@ -19,16 +19,16 @@ else { $user = $User; } -$Place['login/name'] = $user->name ?: 'bewoner'; -$Place['user'] = $user->login; +$Page->place['login/name'] = $user->name ?: 'bewoner'; +$Page->place['user'] = $user->login; if ( $password = trim(@file_get_contents("{$user->dir}/.passwd")) ) { if (substr($password, 0, 1) == '$') { $password = NULL; // hashed } - $Place['pass'] = htmlspecialchars($password) ?: 'zelf ingesteld'; + $Page->place['pass'] = htmlspecialchars($password) ?: 'zelf ingesteld'; } else { - $Place['pass'] = 'onbekend'; + $Page->place['pass'] = 'onbekend'; } print ''."\n"; diff --git a/mail/index.php b/mail/index.php index 67a076e..37b1edc 100644 --- a/mail/index.php +++ b/mail/index.php @@ -45,8 +45,8 @@ if ($msgid) { if (!$User->admin('user')) { http_response_code(403); - $Place['warn'] = "Geen gebruikersrechten om e-mails in te zien."; - $Place['maillist'] = ''; + $Page->place['warn'] = "Geen gebruikersrechten om e-mails in te zien."; + $Page->place['maillist'] = ''; return TRUE; } @@ -72,4 +72,4 @@ foreach (array_reverse($rows) as $filename) { print "\n"; } print "\n"; -$Place['maillist'] = ob_get_clean(); +$Page->place['maillist'] = ob_get_clean(); diff --git a/nieuws/index.php b/nieuws/index.php index 0bb72f9..f6e63a4 100644 --- a/nieuws/index.php +++ b/nieuws/index.php @@ -13,10 +13,10 @@ if ($page and !is_numeric($page)) { $Page->title = $edit; } if ($Page->dateparts) { - $Place[1] = ' '.$Page->date.''; + $Page->place[1] = ' '.$Page->date.''; } else { - $Place[1] = ''; + $Page->place[1] = ''; } print preg_replace('{(?<=

)(.*?)(?=

)}', ($edit ?: '\1').' [[1]]', $Page->raw); if ($User->admin("edit {$Page->link}")) { diff --git a/page.inc.php b/page.inc.php index 78cca99..afaa970 100644 --- a/page.inc.php +++ b/page.inc.php @@ -1,5 +1,5 @@ render(@$Place); +$body = $Page->render(); include_once 'head.inc.php'; @@ -30,7 +30,8 @@ if ($User and property_exists($User, 'login') and $User->login) { } print "

\n"; } -$nav = $menu->render(['login' => ob_get_clean()]); +$menu->place['login'] = ob_get_clean(); +$nav = $menu->render(); $nav = preg_replace_callback('{(.*?)}', function ($m) { $request = $_SERVER['REQUEST_URI']; diff --git a/page.php b/page.php index 214f9d2..5eefadb 100644 --- a/page.php +++ b/page.php @@ -25,7 +25,8 @@ function fail($error) include_once 'page.inc.php'; ob_start(); require '500.inc.html'; - print $Page->render(['debug' => htmlspecialchars($error)]); + $Page->place['debug'] = htmlspecialchars($error); + print $Page->render(); } set_exception_handler('fail'); @@ -95,7 +96,7 @@ header(sprintf('Content-Security-Policy: %s', implode('; ', [ ]))); ob_start(); # page body -$Place = [ +$Page->place += [ 'user' => $User->login ?: '', 'url' => htmlspecialchars($_SERVER['REQUEST_URI']), ]; diff --git a/widget/login/commits.php b/widget/login/commits.php index d892cb5..72f897e 100644 --- a/widget/login/commits.php +++ b/widget/login/commits.php @@ -4,7 +4,7 @@ if (!function_exists('popen')) { return; } -$pagesize = intval(@$Place['n'] ?: @$_GET['n']) ?: 20; +$pagesize = intval(@$Page->place['n'] ?: @$_GET['n']) ?: 20; $gitcmd = "git log -n $pagesize --pretty='%at\t%an\t%s'"; if ( $offset = intval(@$_GET['start']) ) { diff --git a/widget/login/list.php b/widget/login/list.php index 31d9130..94440dc 100644 --- a/widget/login/list.php +++ b/widget/login/list.php @@ -8,8 +8,8 @@ foreach ($users as $col => $userdir) { $users[$col] = new User($userdir); } -if (isset($Place['order'])) { - $ordercol = $Place['order']; +if (isset($Page->place['order'])) { + $ordercol = $Page->place['order']; $order = array_map(function ($row) use ($ordercol) { return $row->$ordercol; }, $users); @@ -23,12 +23,12 @@ if (isset($Place['order'])) { } } -if (isset($Place['n'])) { - array_splice($users, $Place['n']); # limit number of results +if (isset($Page->place['n'])) { + array_splice($users, $Page->place['n']); # limit number of results } print 'place['view'] == 'avatar') { print ' class="gallery cat"'; } elseif (count($users) > 5) { @@ -43,7 +43,7 @@ foreach ($users as $user) { $name = sprintf('%s', $link, $name); } - switch (@$Place['view']) { + switch (@$Page->place['view']) { case 'avatar': if (!file_exists("{$user->dir}/avatar.jpg")) { break; diff --git a/widget/nieuws.php b/widget/nieuws.php index 4f4fd45..7185036 100644 --- a/widget/nieuws.php +++ b/widget/nieuws.php @@ -55,7 +55,7 @@ function printtoc($input, $class = FALSE) $articles = (ltrim($Page->path, '/') ?: 'nieuws'); if (strpos($articles, '/') === FALSE) { - if (@$Place['view'] === 'toc') { + if (@$Page->place['view'] === 'toc') { print "
\n"; foreach (array_reverse(glob("$articles/2???")) as $page) { $year = basename($page, '.html'); @@ -68,10 +68,10 @@ if (strpos($articles, '/') === FALSE) { $articles .= '/????'; } -if (@$Place['view'] === 'toc') { +if (@$Page->place['view'] === 'toc') { printtoc($articles); return; } ob_start(); -shownews($articles, @$Place['n'] ?: 5); +shownews($articles, @$Page->place['n'] ?: 5); print $Page->render(); diff --git a/widget/search.php b/widget/search.php index ff091f7..6c5788e 100644 --- a/widget/search.php +++ b/widget/search.php @@ -1,11 +1,11 @@ place['limit'] ?: 10; $path = ' '.escapeshellarg('*.html'); $query = @$_REQUEST['q'] ?: $Page->path ?: $Page->handler; if (!trim($query, '/')) return; -if (!empty($Place['suggest'])) { +if (!empty($Page->place['suggest'])) { $cmd = "git ls-files -- $path"; exec($cmd, $ls); if (!$ls) { @@ -28,7 +28,7 @@ else { } } -if (isset($Place['verbose'])) { +if (isset($Page->place['verbose'])) { printf("

%s gevonden voor %s:

\n", $results ? count($results).' resultaten' : 'Niets', htmlspecialchars($query)