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