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