From: Mischa POSLAWSKY Date: Sun, 6 Dec 2020 08:08:38 +0000 (+0100) Subject: widget: unnamed options as placeholders instead of path X-Git-Tag: v5.0~22 X-Git-Url: http://git.shiar.nl/minimedit.git/commitdiff_plain/f547127c637332119b42329ca78d0e1a659d9739 widget: unnamed options as placeholders instead of path --- diff --git a/article.inc.php b/article.inc.php index 2104ef9..30de51e 100644 --- a/article.inc.php +++ b/article.inc.php @@ -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 = "$html"; } diff --git a/mail/index.php b/mail/index.php index d8195f6..8fb49c7 100644 --- a/mail/index.php +++ b/mail/index.php @@ -93,8 +93,6 @@ foreach (array_reverse($rows) as $filename) { } print "\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(); diff --git a/widget/countdown.php b/widget/countdown.php index 29e73c6..70d4382 100644 --- a/widget/countdown.php +++ b/widget/countdown.php @@ -1,8 +1,8 @@ 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 diff --git a/widget/doclist.php b/widget/doclist.php index 2288340..123271b 100644 --- a/widget/doclist.php +++ b/widget/doclist.php @@ -1,5 +1,8 @@ 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 diff --git a/widget/linkref.php b/widget/linkref.php index d3ab1eb..1734d8c 100644 --- a/widget/linkref.php +++ b/widget/linkref.php @@ -1,5 +1,5 @@ path); + $article = new ArchiveArticle($Page->place[0]); printf('%s', $article->link, $article->name); if ($article->image) { printf("\n\t".'', $article->thumb('100x100')); diff --git a/widget/login/commits.php b/widget/login/commits.php index 0327f3f..18447a7 100644 --- a/widget/login/commits.php +++ b/widget/login/commits.php @@ -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' : '', + ]); } diff --git a/widget/login/list.php b/widget/login/list.php index 94440dc..0500ef2 100644 --- a/widget/login/list.php +++ b/widget/login/list.php @@ -1,6 +1,8 @@ path) $basepath .= '/.tags' . $Page->path; +if (isset($Page->place[0])) { + $basepath .= '/.tags/' . $Page->place[0]; +} $users = glob("$basepath/*/"); if (!$users) return; diff --git a/widget/nieuws.php b/widget/nieuws.php index c12efc8..73258b2 100644 --- a/widget/nieuws.php +++ b/widget/nieuws.php @@ -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 "
\n"; diff --git a/widget/page.php b/widget/page.php index 37c31fa..4ae0967 100644 --- a/widget/page.php +++ b/widget/page.php @@ -1,3 +1,3 @@ path}.html"); +$article = new ArchiveArticle("{$Page->place[0]}.html"); print $article->render(); diff --git a/widget/reply.php b/widget/reply.php index ca38ce9..d305fc7 100644 --- a/widget/reply.php +++ b/widget/reply.php @@ -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 '