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