nieuws: find article image to append on page
[minimedit.git] / nieuws.inc.php
index 8af5694a62dfb5e2c12987d57561e8921c9891a5..454c91c023a9f457da5d3b735e4abb313d82495d 100644 (file)
@@ -14,6 +14,15 @@ function shownewsdate($url)
        ]));
 }
 
+function shownewsimage($url)
+{
+       foreach (['jpg', 'png'] as $ext) {
+               if (file_exists("$url.$ext")) {
+                       return "$url.$ext";
+               }
+       }
+}
+
 function shownewsarticle($url, $link = TRUE, $title = NULL)
 {
        $html = ob_get_clean();
@@ -25,8 +34,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
        );
+
+       if (!$link and $image = shownewsimage($url)) {
+               global $Place;
+               $Place['image'] = "https://lijtweg.nl/thumb/600x/".$image;
+               ob_start();
+               print '[[1]]';
+               $html .= getoutput([
+                       1 => sprintf("\n".'<p><img src="%s" /></p>', "/thumb/640x/".$image),
+               ]);
+       }
+
        return preg_replace('{<h2>(.*?)</h2>}', $title, $html);
 }
 
@@ -37,7 +57,7 @@ function shownews($input, $limit = 1000)
                print "<article>";
                ob_start();
                include $url;
-               print shownewsarticle($url);
+               print shownewsarticle(preg_replace('/\.html$/', '', $url));
                print "</article>\n\n";
 
                if (--$limit <= 0) break;