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