widget: unnamed options as placeholders instead of path
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 6 Dec 2020 08:08:38 +0000 (09:08 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 19 Dec 2020 02:01:43 +0000 (03:01 +0100)
12 files changed:
article.inc.php
mail/index.php
widget/countdown.php
widget/doclist.php
widget/linkref.php
widget/login/commits.php
widget/login/list.php
widget/nieuws.php
widget/page.php
widget/reply.php
widget/search.php
widget/sitemap.php

index 2104ef9d65025e0b3a0687d0d49dc0a0e9ff34ce..30de51e770ba18bf9b2cb87a9b962a77d8674ff2 100644 (file)
@@ -164,17 +164,20 @@ class ArchiveArticle
 
                ob_start();
                $Page = clone $this;
-               $Page->handler = $Page->handler . $Page->path; // .= with explicit getter
-               $Page->path = '';
-               foreach ($params as $param) {
-                       if ($set = strpos($param, '=')) {
-                               $Page->place[ substr($param, 0, $set) ] = substr($param, $set + 1);
-                       }
-                       elseif (!empty($param)) {
-                               $Page->path .= '/'.$param;
+               if (is_array($params)) {
+                       $Page->place += $params;
+               }
+               else {
+                       foreach (explode(' ', $params) as $param) {
+                               if ($set = strpos($param, '=')) {
+                                       $Page->place[ substr($param, 0, $set) ] = substr($param, $set + 1);
+                               }
+                               elseif (!empty($param)) {
+                                       $Page->place[] = $param;
+                               }
                        }
                }
-               $Page->link .= $Page->path;
+
                try {
                        include "widget/$name.php";
                        return ob_get_clean();
@@ -210,7 +213,7 @@ class ArchiveArticle
                        function ($sub) {
                                list ($placeholder, $name, $params) = $sub;
                                $html = $this->place[$name] ??
-                                       $this->widget($name, explode(' ', $params));
+                                       $this->widget($name, $params);
                                if (empty($html) or $html[0] != '<') {
                                        $html = "<span>$html</span>";
                                }
index d8195f689f3eaa5f9eb1fa4f628581582512e363..8fb49c7f8d27ef144c1dd9f4bdab064d7e0d94ee 100644 (file)
@@ -93,8 +93,6 @@ foreach (array_reverse($rows) as $filename) {
 }
 print "</ul>\n";
 
-print $Page->widget('nav', [
-       "start=$nav[start]", "n=$nav[n]", "total=$nav[total]",
-]);
+print $Page->widget('nav', $nav);
 
 $Page->place['maillist'] = ob_get_clean();
index 29e73c60f7fe0c2bb457756857edb4bce8f99c09..70d4382e45c153ba6cb0455953d6784c7e84e4f1 100644 (file)
@@ -1,8 +1,8 @@
 <?php
-if (empty($Page->path)) {
+if (empty($Page->place[0])) {
        return;
 }
-@list ($target, $interval) = explode('+', ltrim($Page->path, '/'));
+@list ($target, $interval) = explode('+', $Page->place[0]);
 $target = new DateTime($target);
 $now = new DateTime('NOW');
 $next = $target->diff($now);  # age
index 2288340a1a609f923c446e996e88560049092dbb..123271bf63e024bd1292dc9253234b4782f364b6 100644 (file)
@@ -1,5 +1,8 @@
 <?php
 global $User;
+if (isset($Page->place[0])) {
+       $Page->link .= '/'.$Page->place[0];
+}
 
 $cal = [];
 foreach (glob("{$Page->link}/2*") as $url) {
@@ -14,6 +17,9 @@ foreach (glob("{$Page->link}/2*") as $url) {
                $cal[$group][$date][$suffix] = $link;
        }
 }
+if (!$cal) {
+       return;
+}
 
 $year = 3600 * 24 * 365;  # seconds per year
 $scale = 7;  # em width per year
index d3ab1eba0498a397d072a9aa4de25a1a3c25fe30..1734d8c76f01526e6f7edf0406d74f208ab07a28 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-       $article = new ArchiveArticle($Page->path);
+       $article = new ArchiveArticle($Page->place[0]);
        printf('<a href="%s">%s</a>', $article->link, $article->name);
        if ($article->image) {
                printf("\n\t".'<img class="right" src="/%s" />', $article->thumb('100x100'));
index 0327f3fd6f7da25cd5f54e79548bedec5998fc3c..18447a7091a006fec841496f87474aa71aaf022a 100644 (file)
@@ -27,9 +27,8 @@ if ( $log = popen($gitcmd, 'r') ) {
        pclose($log);
 
        $limit = $offset + $lines + 1; # assume one more
-       $navoptions = ["start=$offset", "n=$pagesize", "total=$limit"];
-       if ($Page->handler != 'login/commits') {
-               $navoptions[] = 'link=login/commits';
-       }
-       print $Page->widget('nav', $navoptions);
+       print $Page->widget('nav', [
+               'start' => $offset, 'n' => $pagesize, 'total' => $limit,
+               'link' => $Page->link != 'login/commits' ? 'login/commits' : '',
+       ]);
 }
index 94440dc88be215279cc72cee30c2db315380c3c8..0500ef2746acd1a0a86573a0812643a0f50b38cd 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 $basepath = 'profile';
-if ($Page->path) $basepath .= '/.tags' . $Page->path;
+if (isset($Page->place[0])) {
+       $basepath .= '/.tags/' . $Page->place[0];
+}
 $users = glob("$basepath/*/");
 if (!$users) return;
 
index c12efc8db3348b5b262f1c24dfe77357832bc4d5..73258b2a31c53024f2693d0b5d7cc1cb5531b77b 100644 (file)
@@ -53,7 +53,7 @@ function printtoc($input, $class = FALSE)
 }
 }
 
-$articles = (ltrim($Page->path, '/') ?: 'nieuws');
+$articles = $Page->place[0] ?? 'nieuws';
 if (strpos($articles, '/') === FALSE) {
        if (@$Page->place['view'] === 'toc') {
                print "<div>\n";
index 37c31fa1be68ca6b4a58a7d8ec94374956763406..4ae0967067965309538aad950812ef0768585ce8 100644 (file)
@@ -1,3 +1,3 @@
 <?php
-$article = new ArchiveArticle(".{$Page->path}.html");
+$article = new ArchiveArticle("{$Page->place[0]}.html");
 print $article->render();
index ca38ce970d1885d964e216924e69b6a3e1feb1b8..d305fc7c946e4abac1a8fcc761a0cb185bea6931 100644 (file)
@@ -21,7 +21,7 @@ if ($_POST) {
                        }
                }
                $query = $Db->set('comments', [
-                       'page'    => $Page->handler,
+                       'page'    => $Page->link,
                        'message' => $html,
                        'author'  => $User->login,
                ]);
@@ -68,7 +68,7 @@ if ($_POST) {
 }
 
 $cols = '*, (SELECT json_agg(journal.*) FROM journal WHERE comment_id = comments.id) AS journal';
-$query = $Db->query("SELECT $cols FROM comments WHERE page = ? ORDER BY created", [$Page->handler]);
+$query = $Db->query("SELECT $cols FROM comments WHERE page = ? ORDER BY created", [$Page->link]);
 
 print '<ul class="replies">';
 
@@ -106,7 +106,7 @@ while ($row = $query->fetch()) {
 if ($User->login) {
        print '<li>';
        print '<form method="post" action="" enctype="multipart/form-data">';
-       if (isset($Issue) and $User->admin("edit {$Page->handler}")) {
+       if (isset($Issue) and $User->admin("edit {$Page->link}")) {
                print '<p>';
                printf(
                        '<label for="%s">%s:</label> '
index 6c5788eabc49598da412a43211831f0f72f05f20..fe3b54ee0a9b416f331309c417aff6d79ebfae88 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 $limit = @$Page->place['limit'] ?: 10;
 $path = ' '.escapeshellarg('*.html');
-$query = @$_REQUEST['q'] ?: $Page->path ?: $Page->handler;
+$query = @$_REQUEST['q'] ?: $Page->place[0] ?? $Page->link;
 
 if (!trim($query, '/')) return;
 
index 8d7ba76db614b6748795fcecec8804c555c5832c..42bf7dfe3e0ce3c787088d302748fce5789eb702 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 # list article details
-$search = new PageSearch(ltrim($Page->path, '/') ?: '.');
+$search = new PageSearch($Page->place[0] ?? '.');
 print '<ul class="replies">'."\n";
 foreach ($search->files() as $ref => $sorted) {
-       $Page->path = $ref;
+       $Page->place[0] = $ref;
        print '<li>';
        include 'linkref.php';
        print "</li>\n";