nieuws: include admin edit javascript on subpages
[minimedit.git] / nieuws / index.php
1 <?php
2 include 'nieuws.inc.php';
3
4 $replyform = $Page == 'melding' && !empty($User);
5 @list ($year, $page) = explode('/', trim($Args, '/'));
6
7 if (!empty($User['admin'])) {
8         print '<script src="/nieuws/edit.js"></script>'."\n";
9 }
10
11 if ($page and !is_numeric($page)) {
12         $edit = !empty($User['admin']) ? htmlspecialchars(@$_GET['edit']) : NULL;
13         $article = new ArchiveArticle("$Page$Args.html");
14         $Place[1] = ' <small class="date">'.$article->date.'</small>';
15         print preg_replace('{(?<=<h2>)(.*?)(?=</h2>)}', ($edit ?: '\1').' [[1]]', ob_get_clean());
16         if ($article->image) {
17                 $Place['image'] = "https://lijtweg.nl/".$article->thumb('600x');
18         }
19         if (!empty($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="%2$s"> %s</label>',
28                                 "tags[$tagname]", $tagname, "tag-$tagname",
29                                 $tagvalue ? ' checked' : '',
30                                 ' onclick="return false"',
31                                 ucfirst($tagname)
32                         );
33                 }
34                 printf("<p><strong>Tags:</strong> %s</p>\n",
35                         implode("\n\t", $taglist)
36                 );
37         }
38         if ($replyform) {
39                 print placeholder_include('nieuws/replies');
40         }
41         return 1;
42 }
43
44 if ($year) {
45         ob_clean();
46         $match = $Page;
47         $title = "Nieuws";
48         if (is_numeric($year) and $year > 999) {
49                 $match .= "/$year";
50                 if (is_numeric($page)) {
51                         $title .= ' '.$monthname[intval($page)];
52                         $match .= sprintf('%02d-', $page);
53                 }
54                 $title .= ' '.$year;
55         }
56         elseif ($year === '19') {
57                 $match .= "/19??";
58                 $title .= " vóór 2000";
59         }
60         elseif (file_exists("$Page/.tags/$year")) {
61                 $match .= "/.tags/$year";
62                 $title .= " met $year";
63         }
64
65         print "<h2>$title</h2>\n\n";
66         print placeholder_include('nieuws', [$match]);
67         return 1;
68 }