X-Git-Url: http://git.shiar.nl/minimedit.git/blobdiff_plain/fc5ac7212dade29d2d12ddad934c1dcfe4653794..ed1cd294e32647b117688b25a465889e4664fe03:/widget/reply.php diff --git a/widget/reply.php b/widget/reply.php index 328a58f..b740c2a 100644 --- a/widget/reply.php +++ b/widget/reply.php @@ -1,67 +1,80 @@ Reacties'."\n"; +require_once 'upload.inc.php'; if ($_POST) { try { - $html = nl2br(htmlspecialchars($_POST['reply'])); - $html = "

$html

"; - $query = $Db->set('comments', [ - 'page' => $Page, - 'message' => $html, - 'author' => $User->login, - ]); - if (!$query->rowCount()) { - throw new Exception('Fout bij opslaan'); - } - - if (isset($Issue)) { - $row = ['updated' => ['now()']]; - foreach (['assign'] as $col) { - if (!isset($_POST[$col])) continue; - $row[$col] = $_POST[$col] ?: NULL; - } - if (isset($_POST['status'])) { - $reset = !empty($_POST['status']); - if (isset($Issue->closed) !== $reset) { - $row['closed'] = $reset ? ['now()'] : NULL; - } - } - $Db->set('issues', $row, ['id = ?', $Issue->id]); - } + $newcomment = createcomment($_POST, $Issue); + $target = "/{$Page->link}/$newcomment#$newcomment"; + abort($target, ($Page->api ? 200 : 303) . ' reply success'); $_POST['reply'] = NULL; } catch (Exception $e) { + if ($Page->api) { + abort(ucfirst($e->getMessage()), '500 reply error'); + } print "

Antwoord niet opgeslagen: {$e->getMessage()}.

\n\n"; } } -$query = $Db->query('SELECT * FROM comments WHERE page = ? ORDER BY created', [$Page]); +$cols = '*, (SELECT json_agg(journal.*) FROM journal WHERE comment_id = comments.id) AS journal'; +$query = $Db->query("SELECT $cols FROM comments WHERE page = ? ORDER BY created", [$Page->link]); + +if ($row = $query->fetch()) { + print $row->message; + $Page->teaser = $row->raw; +} print '\n\n";