nieuws: consistent url input to article parser
[minimedit.git] / nieuws.inc.php
index 3d88a263810e58205354a7459f65890fe64505a7..3f3f16391f6bf6c0bc8cc5276b558a697dbf6abc 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+global $monthname;
 $monthname = ['?',
        'januari', 'februari', 'maart', 'april', 'mei', 'juni',
        'juli', 'augustus', 'september', 'oktober', 'november', 'december',
@@ -6,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],
@@ -24,19 +25,19 @@ function shownewsarticle($url, $link = TRUE, $title = NULL)
        $title = sprintf(
                $link ? '<h3><a href="/%2$s">%s</a></h3>' : '<h2>%s</h2>',
                getoutput([1 => ' <small class="date">'.$date.'</small>']),
-               preg_replace('/\.html$/', '', $url)
+               $url
        );
        return preg_replace('{<h2>(.*?)</h2>}', $title, $html);
 }
 
-function shownews($root, $limit = 5)
+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;
-               print shownewsarticle($url);
+               print shownewsarticle(preg_replace('/\.html$/', '', $url));
                print "</article>\n\n";
 
                if (--$limit <= 0) break;