nieuws/replies: shift date part from file names
[minimedit.git] / widget / nieuws / replies.php
1 <?php
2 global $User;
3
4 print '<h3>Reacties</h3>'."\n";
5 $pagelink = $Page.$Args;
6
7 if ($_POST) {
8         try {
9                 @mkdir($pagelink);
10                 $target = $pagelink.'/'.date('YmdHis').':'.$User->login.'.html';
11                 $html = nl2br(htmlspecialchars($_POST['reply']));
12                 $html = "<p>$html</p>\n";
13                 $written = file_put_contents($target, $html);
14                 if ($written === FALSE) {
15                         throw new Exception('Fout bij opslaan');
16                 }
17                 $_POST['reply'] = NULL;
18         }
19         catch (Exception $e) {
20                 print '<p class=warn>Antwoord niet opgeslagen.</p>'."\n\n";
21         }
22 }
23
24 print '<ul class="replies">';
25
26 foreach (glob("$pagelink/*.html") as $reply) {
27         preg_match('</(\d{2,14}) : ([^:]*) [^/]* \.html$>x', $reply, $replymeta);
28         if (!$replymeta) continue;
29         $replydate = str_split($replymeta[1], 2);
30         $replydate[0] = array_shift($replydate) . $replydate[0];
31         $replyuser = new User("profile/{$replymeta[2]}");
32         print '<li>';
33         printf('<strong>%s</strong> <small class=date>%s</small>',
34                 $replyuser->html, showdate($replydate)
35         );
36         printf("<blockquote>%s</blockquote>\n", file_get_contents($reply));
37         print "</li>\n";
38 }
39
40 print '<li>';
41 print '<form method="post" action="">';
42 printf('<textarea id="%s" name="%1$s" cols=60 rows=3 placeholder="%s">%s</textarea>'."\n",
43         'reply',
44         "Bericht van {$User->login}",
45         ''
46 );
47 print '<input type="submit" value="Plaatsen" />'."\n";
48 print "</form></li>\n";
49
50 print "</ul>\n\n";