nieuws: find article image to append on page
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 31 Jul 2018 22:36:57 +0000 (00:36 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 31 Jul 2018 22:36:57 +0000 (00:36 +0200)
nieuws.inc.php

index 3f3f16391f6bf6c0bc8cc5276b558a697dbf6abc..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();
@@ -27,6 +36,17 @@ function shownewsarticle($url, $link = TRUE, $title = NULL)
                getoutput([1 => ' <small class="date">'.$date.'</small>']),
                $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);
 }