nieuws: first paragraph teaser as page description
[minimedit.git] / nieuws / index.php
1 <?php
2 include 'nieuws.inc.php';
3
4 $replyform = $Page == 'melding' && !empty($User);
5 @list ($year, $page) = explode('/', trim($Args, '/'));
6
7 if (!empty($User['admin'])) {
8         print '<script src="/nieuws/edit.js"></script>'."\n";
9 }
10
11 if ($page and !is_numeric($page)) {
12         $edit = !empty($User['admin']) ? htmlspecialchars(@$_GET['edit']) : NULL;
13         $article = new ArchiveArticle("$Page$Args.html");
14         $Place['title'] = $edit ?: $article->title;
15         $Place['description'] = $article->teaser;
16         $Place[1] = ' <small class="date">'.$article->date.'</small>';
17         print preg_replace('{(?<=<h2>)(.*?)(?=</h2>)}', ($edit ?: '\1').' [[1]]', ob_get_clean());
18         if ($article->file and $article->image) {
19                 $Place['image'] = "/".$article->thumb('600x');
20         }
21         if (!empty($User['admin'])) {
22                 $taglist = [];
23                 foreach (glob("$Page/.tags/*") as $tagpath) {
24                         $tagname = pathinfo($tagpath, PATHINFO_BASENAME);
25                         $tagvalue = file_exists("$tagpath/$year-$page.html");
26                         $tagtarget = is_writable($tagpath);
27                         $taglist[] = sprintf(
28                                 '<input type="checkbox" name="%s" value="%s" id="%s"%s%s />' .
29                                 '<label for="%3$s"> %s</label>',
30                                 "tags[$tagname]", $tagname, "tag-$tagname",
31                                 $tagvalue ? ' checked' : '',
32                                 ' disabled',
33                                 ucfirst($tagname)
34                         );
35                 }
36                 if ($taglist) {
37                         printf('<p class="tags"><strong>Tags:</strong> %s</p>'."\n",
38                                 implode("\n\t", $taglist)
39                         );
40                 }
41         }
42         if ($replyform) {
43                 print placeholder_include('nieuws/replies');
44         }
45         return 1;
46 }
47
48 if ($year) {
49         ob_clean();
50         $match = $Page;
51         $title = "Nieuws";
52         if (is_numeric($year) and $year > 999) {
53                 $match .= "/$year";
54                 if (is_numeric($page)) {
55                         $title .= ' '.$monthname[intval($page)];
56                         $match .= sprintf('%02d-', $page);
57                 }
58                 $title .= ' '.$year;
59         }
60         elseif ($year === '19') {
61                 $match .= "/19??";
62                 $title .= " vóór 2000";
63         }
64         elseif (file_exists("$Page/.tags/$year")) {
65                 $match .= "/.tags/$year";
66                 $title .= " met $year";
67         }
68
69         print "<h2>$title</h2>\n\n";
70         print placeholder_include('nieuws', [$match]);
71         return 1;
72 }