From ee9702f9ff640f0108e52490d256c789acb09433 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sat, 12 Dec 2020 15:41:39 +0100 Subject: [PATCH] page: search results as article objects Wanted to determine page link, but also afterwards in sitemap and likely most other uses. --- article.inc.php | 12 ++++++------ foto/index.php | 4 +++- nieuws/index.php | 2 +- widget/linkref.php | 2 ++ widget/sitemap.php | 3 +-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/article.inc.php b/article.inc.php index a9c6ce4..7f8e622 100644 --- a/article.inc.php +++ b/article.inc.php @@ -276,12 +276,12 @@ class PageSearch function files() { # order alphabetically by link - $dir = iterator_to_array(new RecursiveIteratorIterator($this->iterator)); - array_walk($dir, function (&$row, $name) { - # prepare values for sorting (directory index first) - $row = preg_replace('{/index\.html$}', '', $name); - }); - asort($dir); + $dir = []; + foreach (new RecursiveIteratorIterator($this->iterator) as $name) { + $article = new ArchiveArticle($name); + $dir[$article->link] = $article; + } + ksort($dir); return $dir; } } diff --git a/foto/index.php b/foto/index.php index 1e973c7..7df1d5c 100644 --- a/foto/index.php +++ b/foto/index.php @@ -13,7 +13,9 @@ if (!$User) { $Page->image = "/$img"; } if (!$Page->path) { - return glob("$rootdir/*", GLOB_ONLYDIR); #TODO: recurse + return array_map(function ($dir) { + return new ArchiveArticle($dir . '/index.html'); + }, glob("$rootdir/*", GLOB_ONLYDIR)); #TODO: recurse } return; } diff --git a/nieuws/index.php b/nieuws/index.php index 507f493..6ea68dc 100644 --- a/nieuws/index.php +++ b/nieuws/index.php @@ -4,7 +4,7 @@ $replyform = $Page->handler == 'melding' && $User->login; if (!$User) { if ($Page->path) return; - return array_keys((new PageSearch($Page->link))->files()); + return (new PageSearch($Page->link))->files(); } if ($User->admin("edit {$Page->handler}")) { diff --git a/widget/linkref.php b/widget/linkref.php index 7f0264a..3769ca5 100644 --- a/widget/linkref.php +++ b/widget/linkref.php @@ -1,5 +1,7 @@ place[0]); +} $article->index; # apply handler metadata printf('%s', $article->link, $article->name); if ($article->image) { diff --git a/widget/sitemap.php b/widget/sitemap.php index 42bf7df..4d0fa6e 100644 --- a/widget/sitemap.php +++ b/widget/sitemap.php @@ -2,8 +2,7 @@ # list article details $search = new PageSearch($Page->place[0] ?? '.'); print '