issue: append and ignore page titles in links
[minimedit.git] / issue / index.php
1 <?php
2 global $User, $Db;
3 require_once 'database.inc.php';
4 @list ($id, $title) = explode('/', ltrim($Args, '/'));
5
6 if ($id) {
7         $Article->title = "Issue #$id";
8
9         $row = $Db->query(
10                 'SELECT * FROM issues WHERE id = ?', [$id]
11         )->fetch();
12         if (!$row) throw new Exception('Issuenummer niet gevonden');
13
14         $Article->title .= ': '.htmlspecialchars($row->subject);
15         print "<h2>{$Article->title}</h2>\n";
16         print $row->body;
17         if ($row->closed) {
18                 printf('<p><strong>%s</strong> <small class=date>%s</small></p>'."\n",
19                         'Opgelost', showdate(preg_split('/\D/', $row->closed))
20                 );
21         }
22         $Args = "/$id";  # minimal reference
23         print placeholder_include('reply');
24         return;
25 }
26
27 if ($_POST) {
28                 $html = nl2br(htmlspecialchars($_POST['body']));
29                 $html = empty($html) ? NULL : "<p>$html</p>";
30                 $query = $Db->insert('issues', [
31                         'page'    => $Page,
32                         'subject' => $_POST['subject'],
33                         'body'    => $html,
34                         'author'  => $User->login,
35                 ]);
36                 if (!$query->rowCount()) {
37                         throw new Exception('Issue niet opgeslagen.');
38                 }
39                 $_POST = [];
40 }
41
42 $query = $Db->query('SELECT * FROM issues ORDER BY created DESC');
43
44 ob_start();
45 print '<ul>';
46 while ($row = $query->fetch()) {
47         printf('<li><a href="%s">%s <small class="date">%s</small></a>',
48                 "/$Page/{$row->id}/{$row->link}",
49                 sprintf($row->closed ? '<strike>%s</strike>' : '%s',
50                         htmlspecialchars($row->subject)),
51                 showdate(array_slice(preg_split('/\D/', $row->created), 0, 3))
52         );
53         print "</li>\n";
54 }
55 print "</ul>\n";
56 $Place['issuelist'] = ob_get_clean();