nieuws: prepend link to feed
[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 ($page and !is_numeric($page)) {
8         $edit = !empty($User['admin']) ? htmlspecialchars(@$_GET['edit']) : NULL;
9         $article = new ArchiveArticle("$Page$Args.html");
10         $Place[1] = ' <small class="date">'.$article->date.'</small>';
11         print preg_replace('{(?<=<h2>)(.*?)(?=</h2>)}', ($edit ?: '\1').' [[1]]', ob_get_clean());
12         if ($article->image) {
13                 $Place['image'] = "https://lijtweg.nl/".$article->thumb('600x');
14         }
15
16         if ($replyform) {
17                 print '<h3>Reacties</h3>'."\n";
18                 $pagelink = $Page.$Args;
19
20                 if ($_POST) {
21                         try {
22                                 @mkdir($pagelink);
23                                 $target = $pagelink.'/'.date('YmdHis').':'.$User['name'].'.txt';
24                                 $written = file_put_contents($target, $_POST['reply']);
25                                 if ($written === FALSE) {
26                                         throw new Exception('Fout bij opslaan');
27                                 }
28                                 $_POST['reply'] = NULL;
29                         }
30                         catch (Exception $e) {
31                                 print '<p class=warn>Antwoord niet opgeslagen.</p>'."\n\n";
32                         }
33                 }
34
35                 print '<ul class="replies">';
36
37                 foreach (glob("$pagelink/*.txt") as $reply) {
38                         preg_match('</(\d{2,14}) : ([^:]*) [^/]* \.txt$>x', $reply, $replymeta);
39                         if (!$replymeta) continue;
40                         $replydate = str_split($replymeta[1], 2);
41                         $replydate[1] = $replydate[0] . $replydate[1];
42                         print '<li>';
43                         printf('<strong>%s</strong> <small class=date>%s</small>',
44                                 $replymeta[2], showdate($replydate)
45                         );
46                         $replydata = file_get_contents($reply);
47                         printf('<p>%s</p>', nl2br(htmlspecialchars($replydata)));
48                         print "</li>\n";
49                 }
50
51                 print '<li>';
52                 print '<form method="post" action="">';
53                 printf('<textarea id="%s" name="%1$s" cols=60 rows=3 placeholder="%s">%s</textarea>'."\n",
54                         'reply',
55                         "Bericht van {$User['name']}",
56                         ''
57                 );
58                 print '<input type="submit" value="Plaatsen" />'."\n";
59                 print "</form></li>\n";
60
61                 print "</ul>\n\n";
62         }
63
64         return 1;
65 }
66
67 if ($year) {
68         ob_clean();
69         $title = "Nieuws";
70         if (is_numeric($year) and $year > 999) {
71                 $match = "$Page/$year/";
72                 if (is_numeric($page)) {
73                         $title .= ' '.$monthname[intval($page)];
74                         $match .= sprintf('%02d-', $page);
75                 }
76                 $title .= ' '.$year;
77         }
78         elseif ($year === '19') {
79                 $match = "$Page/19??/";
80                 $title .= " vóór 2000";
81         }
82
83         print "<h2>$title</h2>\n\n";
84         shownews(glob($match.'*.html'));
85         return 1;
86 }
87
88 $html = ob_get_clean();
89 printf('<div class="nav right"><a href="%s">Feed</a></div>'."\n", "/$Page/feed");
90 print $html;
91
92 print '<div id="news">'."\n\n";
93
94 foreach (array_reverse(glob("$Page/2???")) as $page) {
95         $year = basename($page, '.html');
96         printf('<h3><a href="/%s">%s</a></h3>'."\n", $page, $year);
97         printtoc($page);
98 }
99
100 if ($pages = glob("$Page/19??/*.html")) {
101         printf('<h3><a href="/%s">%s</a></h3>'."\n", "$Page/19", 'Eerder');
102         printtoc($pages);
103 }
104
105 print "</div>\n\n";
106
107 if ($replyform) {
108         print "<h3>Melding rapporteren</h3>\n";
109         $_REQUEST['subject'] = 'melding';
110         require 'contact.php';
111 ?>
112 <form method="post">
113 <p>
114         <textarea name="body" cols=60 rows=4></textarea>
115         <input type="submit" value="Versturen" />
116 </p>
117 </form>
118 <?php
119 }
120
121 if (!empty($User['admin'])) {
122         print '<script src="/nieuws/edit.js"></script>'."\n";
123 }