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