nieuws: port excelsior toc and year filtering
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 19 Apr 2018 16:03:33 +0000 (18:03 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Fri, 8 Jun 2018 21:14:52 +0000 (23:14 +0200)
nieuws.inc.php
nieuws.php

index ca16b4a13a0bcddc5d3f62750376c17edf69f5f1..7e723e4095e68febd3abde4fcc957217320168f8 100644 (file)
@@ -32,7 +32,8 @@ function shownewsarticle($url, $link = TRUE, $title = NULL)
 
 function shownews($root, $limit = 5)
 {
-       foreach (array_reverse(glob("$root/*/*.html")) as $url) {
+       if (strpos($root, '/') === FALSE) $root .= '/*';
+       foreach (array_reverse(glob("$root/*.html")) as $url) {
                print "<article>";
                ob_start();
                include $url;
@@ -42,3 +43,16 @@ function shownews($root, $limit = 5)
                if (--$limit <= 0) break;
        }
 }
+
+function printtoc($root)
+{
+       print '<ul>';
+       foreach (array_reverse(glob("$root/*.html")) as $page) {
+               $title = fgets(fopen($page, 'r'));
+               $title = strip_tags($title);
+               $linkurl = preg_replace('/\.html$/', '', $page);
+               printf('<li><a href="/%s">%s <small class="date">%s</small></a></li>',
+                       $linkurl, $title, shownewsdate($linkurl));
+       }
+       print "</ul>\n";
+}
index 157986cfea7eac64baa31bffc350df81d53c557c..84a6172638cd446dc98a342f333497065bdfa9e4 100644 (file)
@@ -1,17 +1,33 @@
 <?php
 include 'nieuws.inc.php';
 
-if ($Args) {
+@list ($year, $month, $page) = explode('/', trim($Args, '/'));
+
+if ($page) {
        $edit = !empty($User['admin']) ? htmlspecialchars(@$_GET['edit']) : NULL;
        print shownewsarticle($Args, FALSE, $edit);
-       return;
+       return 1;
 }
 
-ob_clean();
-print "<h2>Nieuwsarchief</h2>\n\n";
+if ($year) {
+       ob_clean();
+       print "<h2>Nieuws $year</h2>\n\n";
+
+       print '<div id="news">'."\n\n";
+       shownews("$Page/$year/??", 100);
+       print "</div>\n\n";
+
+       return 1;
+}
 
 print '<div id="news">'."\n\n";
-shownews($Page, 20);
+
+foreach (array_reverse(glob("$Page/2???")) as $page) {
+       $year = basename($page, '.html');
+       printf('<h3><a href="/%s">%s</a></h3>'."\n", $page, $year);
+       printtoc("$page/??");
+}
+
 print "</div>\n\n";
 
 if (!empty($User['admin'])) {