page: header metadata from article object
[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) {
6         print '<script src="/nieuws/edit.js"></script>'."\n";
7 }
8
9 if ($page and !is_numeric($page)) {
10         $edit = $User && $User->admin ? htmlspecialchars(@$_GET['edit']) : NULL;
11         if ($edit) {
12                 $Article->title = $edit;
13         }
14         if ($Article->file) {
15                 $Place['description'] = $Article->teaser;
16         }
17         $Place[1] = ' <small class="date">'.$Article->date.'</small>';
18         print preg_replace('{(?<=<h2>)(.*?)(?=</h2>)}', ($edit ?: '\1').' [[1]]', ob_get_clean());
19         if ($User and $User->admin) {
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('nieuws/replies');
42         }
43         return 1;
44 }
45
46 if ($year) {
47         ob_clean();
48         $match = $Page;
49         $title = "Nieuws";
50         if (is_numeric($year) and $year > 999) {
51                 $match .= "/$year";
52                 if (is_numeric($page)) {
53                         $title .= ' '.$monthname[intval($page)];
54                         $match .= sprintf('%02d-', $page);
55                 }
56                 $title .= ' '.$year;
57         }
58         elseif ($year === '19') {
59                 $match .= "/19??";
60                 $title .= " vóór 2000";
61         }
62         elseif (file_exists("$Page/.tags/$year")) {
63                 $match .= "/.tags/$year";
64                 $title .= " met $year";
65         }
66
67         print "<h2>$title</h2>\n\n";
68         print placeholder_include('nieuws', [$match]);
69         return 1;
70 }