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