nieuws: archive pages by year only
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 8 Jun 2018 22:05:43 +0000 (00:05 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 9 Jun 2018 03:18:59 +0000 (05:18 +0200)
nieuws.inc.php
nieuws.php
nieuws/edit.js
nieuws/index.php

index f4d42d8d82223a9b3898ca8a91abb6622e5ba390..8af5694a62dfb5e2c12987d57561e8921c9891a5 100644 (file)
@@ -7,7 +7,7 @@ $monthname = ['?',
 
 function shownewsdate($url)
 {
-       if (!preg_match('</(\d{4})/(\d{2})/(\d{2})->', $url, $parts)) return;
+       if (!preg_match('</(\d{4})/(\d{2})-(\d{2})->', $url, $parts)) return;
        global $monthname;
        return implode(' ', array_filter([
                intval($parts[3]), $parts[2] > 0 ? $monthname[intval($parts[2])] : '', $parts[1],
@@ -30,10 +30,10 @@ function shownewsarticle($url, $link = TRUE, $title = NULL)
        return preg_replace('{<h2>(.*?)</h2>}', $title, $html);
 }
 
-function shownews($root, $limit = 1000)
+function shownews($input, $limit = 1000)
 {
-       if (strpos($root, '/') === FALSE) $root .= '/*';
-       foreach (array_reverse(glob("$root/*.html")) as $url) {
+       if (!is_array($input)) $input = glob("$input/*.html");
+       foreach (array_reverse($input) as $url) {
                print "<article>";
                ob_start();
                include $url;
index 83fdc7a037c840a88b5833acd4a7878ff4a32d44..cafc94c6795a25ec866ee06c04fa689000c64e42 100644 (file)
@@ -1,4 +1,4 @@
 <?php
 include_once 'nieuws.inc.php';
-$articles = ($Page ?: 'nieuws') . '/????/??';
+$articles = ($Page ?: 'nieuws') . '/????';
 shownews($articles, @$_GET['n'] ?: 5);
index 64260e9a2cf339be67ca7b711d9d33b4f9df7c1b..86b0b4ce6e58029965efaa532a4a32444805e03a 100644 (file)
@@ -5,7 +5,7 @@ editlink.onclick = function () {
        var today = new Date().toJSON().slice(0, 10).split('-');
        var input = prompt('Paginatitel', '');
        if (!input) return false;
-       var url = today[0] + '/' + today[1] + '/' + today[2] + '-' +
+       var url = today[0] + '/' + today[1] + '-' + today[2] + '-' +
                input.toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim();
        var title = encodeURIComponent(input.trim());
        window.location = '/nieuws/'+url+'?edit='+title+'#edit';
index bbc002a62eca92583b71832b729746faa01bc8f1..05c995af1a38b1f8b8646bd78f774848c22a335a 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 include 'nieuws.inc.php';
 
-@list ($year, $month, $page) = explode('/', trim($Args, '/'));
+@list ($year, $page) = explode('/', trim($Args, '/'));
 
-if ($page) {
+if ($page and !is_numeric($page)) {
        $edit = !empty($User['admin']) ? htmlspecialchars(@$_GET['edit']) : NULL;
        print shownewsarticle($Args, FALSE, $edit);
        return 1;
@@ -12,19 +12,18 @@ if ($page) {
 if ($year) {
        ob_clean();
        if (is_numeric($year)) {
-               $title = "Nieuws ".($month ? $monthname[$month].' ' : '').$year;
-               $match = implode('/', [
-                       $Page, $year, $month ? sprintf('%02d', $month) : '??',
-               ]);
+               $title = "Nieuws ".($page ? $monthname[$page].' ' : '').$year;
+               $match = "$Page/$year/";
+               if ($page) $match .= sprintf('%02d-', $page);
        }
        else {
                $title = "Nieuws vóór 2000";
-               $match = "$Page/19??/??";
+               $match = "$Page/19??/";
        }
 
        print "<h2>$title</h2>\n\n";
        print '<div id="news">'."\n\n";
-       shownews($match);
+       shownews(glob($match.'*.html'));
        print "</div>\n\n";
        return 1;
 }
@@ -38,10 +37,10 @@ print '<div id="news">'."\n\n";
 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/??");
+       printtoc($page);
 }
 
-if ($pages = glob("$Page/19??/??/*.html")) {
+if ($pages = glob("$Page/19??/*.html")) {
        printf('<h3><a href="/%s">%s</a></h3>'."\n", "$Page/oud", 'Eerder');
        printtoc($pages);
 }