X-Git-Url: http://git.shiar.nl/minimedit.git/blobdiff_plain/d33a85fd3d187d76fd86f891bba2d9fe17a035a0..8e1d3422ac745d49bcf56152f11d5b07ea45cb38:/widget/reply.php diff --git a/widget/reply.php b/widget/reply.php index 6fc1fa5..0c5d5a3 100644 --- a/widget/reply.php +++ b/widget/reply.php @@ -1,52 +1,151 @@ Reacties'."\n"; +require_once 'upload.inc.php'; if ($_POST) { try { - $html = nl2br(htmlspecialchars($_POST['reply'])); - $html = "

$html

"; - $query = $Db->insert('comments', [ - 'page' => $Page, - 'message' => $html, - 'author' => $User->login, - ]); - if (!$query->rowCount()) { - throw new Exception('Fout bij opslaan'); - } + $newcomment = createcomment($_POST, $Issue); + $target = "/{$Page->link}?last=$newcomment#$newcomment"; + abort($target, ($Page->api ? 200 : 303) . ' reply success'); $_POST['reply'] = NULL; } catch (Exception $e) { - print '

Antwoord niet opgeslagen.

'."\n\n"; + if ($Page->api) { + abort(ucfirst($e->getMessage()), '500 reply error'); + } + printf("

Antwoord niet opgeslagen: %s.

\n\n", + nl2br(htmlspecialchars($e->getMessage())) + ); } } -$query = $Db->query('SELECT * FROM comments WHERE page = ? ORDER BY created', [$Page]); +$cols = "*, (SELECT json_agg(journal.*) FROM journal WHERE comment_id = comments.id AND property = 'attr') AS journal"; +$query = $Db->query("SELECT $cols FROM comments WHERE page = ? ORDER BY created", [$Page->link]); -print '\n\n"; +print "\n\n";