issue: feed subpage for atom xml formatting
[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 and ctype_digit($id)) {
7         $Article->title = "Issue #$id";
8
9         $Issue = $Db->query(
10                 'SELECT * FROM issues WHERE page = ? AND id = ?', [$Page, $id]
11         )->fetch();
12         if (!$Issue) throw new Exception('Issuenummer niet gevonden');
13
14         $Article->title .= ': '.htmlspecialchars($Issue->subject);
15         print "<h2>{$Article->title}</h2>\n";
16         $author = $Issue->author ? new User('profile/'.$Issue->author, FALSE) : NULL;
17         printf('<p><em>%s</em>%s <small class=date>%s</small></p>'."\n",
18                 'Geplaatst',
19                 $author ? " door <strong>{$author->name}</strong>" : '',
20                 showdate(preg_split('/\D/', $Issue->created))
21         );
22         if ($Issue->assign) {
23                 printf('<p><em>%s</em> aan <strong>%s</strong></p>'."\n",
24                         'Toegewezen', htmlspecialchars($Issue->assign)
25                 );
26         }
27         if ($Issue->closed) {
28                 printf('<p><em>%s</em>%s <small class=date>%s</small></p>'."\n",
29                         'Opgelost', '',
30                         showdate(preg_split('/\D/', $Issue->closed))
31                 );
32         }
33         print $Issue->body;
34         $Args = "/$id";  # minimal reference
35         print placeholder_include('reply');
36         return;
37 }
38
39 if ($_POST) {
40                 $html = nl2br(htmlspecialchars($_POST['body']));
41                 $html = empty($html) ? NULL : "<p>$html</p>";
42                 $query = $Db->set('issues', [
43                         'page'    => $Page,
44                         'subject' => $_POST['subject'],
45                         'body'    => $html,
46                         'author'  => $User->login,
47                 ]);
48                 if (!$query->rowCount()) {
49                         throw new Exception('Issue niet opgeslagen.');
50                 }
51                 $_POST = [];
52 }
53
54 $cols = "*, (SELECT count(*) FROM comments WHERE"
55         . " page=i.page||'/'||i.id AND message IS NOT NULL) AS replycount";
56 $sql = "SELECT $cols FROM issues i WHERE page = ?";
57 if (isset($_GET['open'])) {
58         $sql .= ' AND closed IS NULL';
59 }
60 $sql .= ' ORDER BY closed IS NOT NULL, updated DESC';
61 $query = $Db->query($sql, [$Page]);
62
63 if ($id == 'feed') {
64         require 'issue/feed.inc.php';
65 }
66
67 ob_start();
68 print '<ul>';
69 while ($row = $query->fetch()) {
70         printf('<li><a href="%s">%s <small class="date">%s</small>%s</a>',
71                 "/$Page/{$row->id}/{$row->link}",
72                 sprintf($row->closed ? '<strike>%s</strike>' : '%s',
73                         htmlspecialchars($row->subject)),
74                 showdate(array_slice(preg_split('/\D/', $row->updated), 0, 3)),
75                 implode(' ', [
76                         $row->replycount ? sprintf('<span class=right>+%d</span>', $row->replycount) : '',
77                         isset($row->assign) ? ' <em class="right">'.$row->assign.'</em>' : '',
78                 ])
79         );
80         print "</li>\n";
81 }
82 print "</ul>\n";
83 $Place['issuelist'] = ob_get_clean();