page: ignore output buffer in article render
[minimedit.git] / widget / 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         print "<div>\n";
7         foreach (array_reverse($input) as $filename) {
8                 $article = new ArchiveArticle($filename);
9                 print '<article class="left">';
10                 if ($article->thumb) {
11                         $imgattr = ' class="left"';
12                         if (preg_match('{ (\s alt="[^"]+") }x', $article->img, $img)) {
13                                 $imgattr .= $img[0];  # preserve alt value
14                         }
15                         printf('<img src="/%s"%s />', $article->thumb, $imgattr);
16                 }
17                 print '<div>';
18                 printf(
19                         '<h3><a href="/%s">%s <small class="date">%s</small></a></h3>',
20                         $article->link, $article->title, $article->date
21                 );
22                 print $article->story;
23                 print '</div>';
24                 print "</article>\n\n";
25
26                 if (--$limit <= 0) break;
27         }
28         print "</div>\n";
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($Page->path, '/') ?: 'nieuws');
57 if (strpos($articles, '/') === FALSE) {
58         if (@$Page->place['view'] === 'toc') {
59                 print "<div>\n";
60                 foreach (array_reverse(glob("$articles/2???")) as $page) {
61                         $year = basename($page, '.html');
62                         printf('<h3><a href="/%s">%s</a></h3>'."\n", $page, $year);
63                         printtoc($page, 'gallery');
64                 }
65                 print "</div>\n";
66                 return;
67         }
68         $articles .= '/????';
69 }
70
71 if (@$Page->place['view'] === 'toc') {
72         printtoc($articles);
73         return;
74 }
75 ob_start();
76 shownews($articles, @$Page->place['n'] ?: 5);
77 $Page->raw = ob_get_clean();
78 print $Page->render();