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