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