nieuws: inline code to format article overviews
[minimedit.git] / nieuws.php
index 157986cfea7eac64baa31bffc350df81d53c557c..251443842cd67d20105c0af95898bfdb631faeca 100644 (file)
@@ -1,19 +1,75 @@
 <?php
-include 'nieuws.inc.php';
+include_once 'nieuws.inc.php';
 
-if ($Args) {
-       $edit = !empty($User['admin']) ? htmlspecialchars(@$_GET['edit']) : NULL;
-       print shownewsarticle($Args, FALSE, $edit);
-       return;
+if (!function_exists('shownews')) {
+function shownews($input, $limit = 1000)
+{
+       if (!is_array($input)) $input = glob("$input/*.html");
+       foreach (array_reverse($input) as $filename) {
+               $article = new ArchiveArticle($filename);
+               print '<article class="left">';
+               if ($article->thumb) {
+                       $imgattr = ' class="left"';
+                       if (preg_match('{ (\s alt="[^"]+") }x', $article->img, $img)) {
+                               $imgattr .= $img[0];  # preserve alt value
+                       }
+                       printf('<img src="/%s"%s />', $article->thumb, $imgattr);
+               }
+               print '<div>';
+               printf(
+                       '<h3><a href="/%s">%s <small class="date">%s</small></a></h3>',
+                       $article->link, $article->title, $article->date
+               );
+               print $article->body;
+               print '</div>';
+               print "</article>\n\n";
+
+               if (--$limit <= 0) break;
+       }
 }
 
-ob_clean();
-print "<h2>Nieuwsarchief</h2>\n\n";
+function printtoc($input, $class = FALSE)
+{
+       if (!is_array($input)) $input = glob("$input/*.html");
+       print '<ul';
+       if ($class) printf(' class="%s"', $class);
+       print '>';
+       foreach (array_reverse($input) as $page) {
+               $article = new ArchiveArticle($page);
+               $html = $article->safetitle;
+               $dateparts = $article->dateparts;
+               if ($class) {
+                       $dateparts[0] = NULL;  # omit year
+               }
+               $html .= sprintf(' <small class="date">%s</small>', showdate($dateparts));
+               if ($class == 'gallery' and $article->img) {
+                       $html = "<div>$html</div>";
+                       $html = sprintf('<img src="%s" />', $article->thumb(200)) . $html;
+               }
+               $html = sprintf('<a href="/%s">%s</a>', $article->link, $html);
+               print "<li><article>$html</article></li>\n";
+       }
+       print "</ul>\n";
+}
+}
 
-print '<div id="news">'."\n\n";
-shownews($Page, 20);
-print "</div>\n\n";
+$articles = (ltrim($Args, '/') ?: 'nieuws');
+if (strpos($articles, '/') === FALSE) {
+       if (@$Place['view'] === 'toc') {
+               foreach (array_reverse(glob("$articles/2???")) as $page) {
+                       $year = basename($page, '.html');
+                       printf('<h3><a href="/%s">%s</a></h3>'."\n", $page, $year);
+                       printtoc($page, 'gallery');
+               }
+               return;
+       }
+       $articles .= '/????';
+}
 
-if (!empty($User['admin'])) {
-       print '<script src="/nieuws/edit.js"></script>'."\n";
+if (@$Place['view'] === 'toc') {
+       printtoc($articles);
+       return;
 }
+ob_start();
+shownews($articles, @$Place['n'] ?: 5);
+print getoutput();