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