page: promote news article class to represent all pages
[minimedit.git] / nieuws.php
1 <?php
2 if (!function_exists('shownews')) {
3 function shownews($input, $limit = 1000)
4 {
5         if (!is_array($input)) $input = glob("$input/*.html");
6         foreach (array_reverse($input) as $filename) {
7                 $article = new ArchiveArticle($filename);
8                 print '<article class="left">';
9                 if ($article->thumb) {
10                         $imgattr = ' class="left"';
11                         if (preg_match('{ (\s alt="[^"]+") }x', $article->img, $img)) {
12                                 $imgattr .= $img[0];  # preserve alt value
13                         }
14                         printf('<img src="/%s"%s />', $article->thumb, $imgattr);
15                 }
16                 print '<div>';
17                 printf(
18                         '<h3><a href="/%s">%s <small class="date">%s</small></a></h3>',
19                         $article->link, $article->title, $article->date
20                 );
21                 print $article->body;
22                 print '</div>';
23                 print "</article>\n\n";
24
25                 if (--$limit <= 0) break;
26         }
27 }
28
29 function printtoc($input, $class = FALSE)
30 {
31         if (!is_array($input)) $input = glob("$input/*.html");
32         print '<ul';
33         if ($class) printf(' class="%s"', $class);
34         print '>';
35         foreach (array_reverse($input) as $page) {
36                 $article = new ArchiveArticle($page);
37                 $html = $article->safetitle;
38                 $dateparts = $article->dateparts;
39                 if ($class) {
40                         $dateparts[0] = NULL;  # omit year
41                 }
42                 $html .= sprintf(' <small class="date">%s</small>', showdate($dateparts));
43                 if ($class == 'gallery' and $article->img) {
44                         $html = "<div>$html</div>";
45                         $html = sprintf('<img src="%s" />', $article->thumb(200)) . $html;
46                 }
47                 $html = sprintf('<a href="/%s">%s</a>', $article->link, $html);
48                 print "<li><article>$html</article></li>\n";
49         }
50         print "</ul>\n";
51 }
52 }
53
54 $articles = (ltrim($Args, '/') ?: 'nieuws');
55 if (strpos($articles, '/') === FALSE) {
56         if (@$Place['view'] === 'toc') {
57                 foreach (array_reverse(glob("$articles/2???")) as $page) {
58                         $year = basename($page, '.html');
59                         printf('<h3><a href="/%s">%s</a></h3>'."\n", $page, $year);
60                         printtoc($page, 'gallery');
61                 }
62                 return;
63         }
64         $articles .= '/????';
65 }
66
67 if (@$Place['view'] === 'toc') {
68         printtoc($articles);
69         return;
70 }
71 ob_start();
72 shownews($articles, @$Place['n'] ?: 5);
73 print getoutput();