login/pass: error messages below page title
[minimedit.git] / widget / nieuws.php
1 <?php
2 if (!function_exists('shownews')) {
3 function shownews($input, $limit = 1000, $abbr = FALSE)
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, showdate($article->dateparts)
21                 );
22                 if ($abbr) {
23                         print '<p>' . $article->teaser;
24                         if ($article->story != "<p>{$article->teaser}</p>\n\n") {
25                                 print ' <small class="footer">(Meer op de site)</small>';
26                         }
27                         print "</p>\n";
28                 }
29                 else {
30                         print $article->story;
31                 }
32                 print '</div>';
33                 print "</article>\n\n";
34
35                 if (--$limit <= 0) break;
36         }
37         print "</div>\n";
38 }
39
40 function printtoc($input, $class = FALSE)
41 {
42         if (!is_array($input)) $input = glob("$input/*.html");
43         print '<ul';
44         if ($class) printf(' class="%s"', $class);
45         print '>';
46         foreach (array_reverse($input) as $page) {
47                 $article = new ArchiveArticle($page);
48                 $html = $article->safetitle;
49                 $dateparts = $article->dateparts;
50                 if ($class) {
51                         $dateparts[0] = NULL;  # omit year
52                 }
53                 $html .= sprintf(' <small class="date">%s</small>', showdate($dateparts));
54                 if ($class == 'gallery' and $article->img) {
55                         $html = "<div>$html</div>";
56                         $html = sprintf('<img src="/%s" />', $article->thumb(200)) . $html;
57                 }
58                 $html = sprintf('<a href="/%s">%s</a>', $article->link, $html);
59                 print "<li><article>$html</article></li>\n";
60         }
61         print "</ul>\n";
62 }
63 }
64
65 $articles = $Page->place[0] ?? 'nieuws';
66 if (strpos($articles, '/') === FALSE) {
67         if (@$Page->place['view'] === 'toc') {
68                 print "<div>\n";
69                 foreach (array_reverse(glob("$articles/2???")) as $page) {
70                         $year = basename($page, '.html');
71                         printf('<h3><a href="/%s">%s</a></h3>'."\n", $page, $year);
72                         printtoc($page, 'gallery');
73                 }
74                 print "</div>\n";
75                 return;
76         }
77         $articles .= '/????';
78 }
79
80 if (@$Page->place['view'] === 'toc') {
81         printtoc($articles);
82         return;
83 }
84 ob_start();
85 shownews($articles, @$Page->place['n'] ?: 5, !empty($Page->place['teaser']));
86 $Page->raw = ob_get_clean();
87 print $Page->render();