reply: setup database to fetch objects
[minimedit.git] / widget / reply.php
1 <?php
2 global $User;
3 require_once 'database.inc.php';
4
5 print '<h3>Reacties</h3>'."\n";
6
7 if ($_POST) {
8         try {
9                 $html = nl2br(htmlspecialchars($_POST['reply']));
10                 $html = "<p>$html</p>";
11                 $query = $Db->insert('comments', [
12                         'page'    => $Page,
13                         'message' => $html,
14                         'author'  => $User->login,
15                 ]);
16                 if (!$query->rowCount()) {
17                         throw new Exception('Fout bij opslaan');
18                 }
19                 $_POST['reply'] = NULL;
20         }
21         catch (Exception $e) {
22                 print '<p class=warn>Antwoord niet opgeslagen.</p>'."\n\n";
23         }
24 }
25
26 $query = $Db->query('SELECT * FROM comments WHERE page = ? ORDER BY created', [$Page]);
27
28 print '<ul class="replies">';
29
30 while ($row = $query->fetch()) {
31         $rowuser = new User("profile/{$row->author}");
32         print '<li>';
33         printf('<strong>%s</strong> <small class=date>%s</small>',
34                 $rowuser->html, showdate(preg_split('/\D/', $row->created))
35         );
36         printf("<blockquote>%s</blockquote>\n", $row->message);
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";