X-Git-Url: http://git.shiar.nl/minimedit.git/blobdiff_plain/fac6ba761f971deb77a5686ead99ec6534f931d2..6bdc514b94fb0127159c809e8f311cccc230d4ee:/widget/reply.php?ds=sidebyside
diff --git a/widget/reply.php b/widget/reply.php
index ab04137..0c5d5a3 100644
--- a/widget/reply.php
+++ b/widget/reply.php
@@ -1,83 +1,106 @@
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');
- }
- $newcomment = $Db->dbh->lastInsertId('comments_id_seq');
-
- if (isset($Issue)) {
- $row = [];
- 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;
- }
- }
- $derived = ['updated' => ['now()']];
- $filter = ['id = ? RETURNING *', $Issue->id];
- $subquery = $Db->set('issues', $row + $derived, $filter);
-
- if ($updated = $subquery->fetch()) {
- foreach (array_keys($row) as $col) {
- if ($updated->$col === $Issue->$col) continue; # unaltered
- $Db->set('journal', [
- 'comment_id' => $newcomment,
- 'property' => 'attr',
- 'col' => $col,
- 'old_value' => $Issue->$col,
- 'value' => $updated->$col,
- ]);
- }
- }
- }
+ $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: {$e->getMessage()}.
\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 '';
+print '';
-while ($row = $query->fetch()) {
+$imagecount = 0;
+for ($i = 0; $row = $query->fetch(); $i++) {
$rowuser = new User("profile/{$row->author}");
- print '- ';
- printf('%s %s',
- $rowuser->html, showdate(preg_split('/\D/', $row->created))
- );
- printf("
%s
\n", $row->message);
- print " \n";
+ printf('', $row->id);
+ if ($i) {
+ # subsequent reply header
+ printf('%s', $rowuser->html);
+ }
+ else {
+ $Page->teaser = $row->raw;
+ }
+ $rowdate = showdate(preg_split('/\D/', $row->created));
+ if ($User->admin('beheer')) {
+ if ($row->updated) {
+ $rowdate = "$rowdate " . showdate(preg_split('/\D/', $row->updated));
+ }
+ if ($User->admin('user') || $User->login === $row->author) {
+ $rowdate .= sprintf(' %s',
+ "/{$Page->link}/{$row->id}", 'reactie aanpassen', "\u{270D}");
+ }
+ }
+ printf(' %s', $rowdate);
+ if ($html = $row->message) {
+ $html = preg_replace('/(?<= 2 ? 'loading="lazy" ' : '', $html, -1, $found);
+ $imagecount += $found;
+ if ($i) {
+ $html = "\n$html
\n";
+ }
+ print $html;
+ }
+ if ($changes = json_decode($row->journal)) {
+ print '';
+ foreach ($changes as $change) {
+ print '- ';
+ if ($change->col == 'closed') {
+ printf('%s', isset($change->value) ? 'Gesloten' : 'Heropend');
+ }
+ else {
+ printf("%s %s",
+ $journalcol[$change->col], sprintf(
+ !isset($change->old_value) ? 'gewijzigd naar
%2$s
' :
+ (!isset($change->value) ? 'verwijderd (%s)' :
+ 'gewijzigd van %s
naar %s
'),
+ $change->old_value, $change->value
+ )
+ );
+ }
+ print " \n";
+ }
+ print "
\n";
+ }
+ print "\n";
}
-if ($User) {
- print '- ';
- print '
\n";
+ print "";
+ print '';
+ print "\n";
}
-print "
\n\n";
+print "\n\n";