316a16e6e4ebe10a8013ef3fb9907e267703b9bb
[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 print '<div id="news">'."\n\n";
89
90 foreach (array_reverse(glob("$Page/2???")) as $page) {
91         $year = basename($page, '.html');
92         printf('<h3><a href="/%s">%s</a></h3>'."\n", $page, $year);
93         printtoc($page);
94 }
95
96 if ($pages = glob("$Page/19??/*.html")) {
97         printf('<h3><a href="/%s">%s</a></h3>'."\n", "$Page/19", 'Eerder');
98         printtoc($pages);
99 }
100
101 print "</div>\n\n";
102
103 if ($replyform) {
104         print "<h3>Melding rapporteren</h3>\n";
105         $_REQUEST['subject'] = 'melding';
106         require 'contact.php';
107 ?>
108 <form method="post">
109 <p>
110         <textarea name="body" cols=60 rows=4></textarea>
111         <input type="submit" value="Versturen" />
112 </p>
113 </form>
114 <?php
115 }
116
117 if (!empty($User['admin'])) {
118         print '<script src="/nieuws/edit.js"></script>'."\n";
119 }