X-Git-Url: http://git.shiar.nl/minimedit.git/blobdiff_plain/05c560470887c86a30c82360d7be5caf0de1baa4..fc1eaa7b91bd44d7939c67b1d3d8aef50af3c5db:/widget/reply.php?ds=sidebyside
diff --git a/widget/reply.php b/widget/reply.php
index 66e9587..0c5d5a3 100644
--- a/widget/reply.php
+++ b/widget/reply.php
@@ -1,79 +1,12 @@
'Toegewezen aan',
- 'subject' => 'Onderwerp',
-];
+require_once 'upload.inc.php';
if ($_POST) {
- require_once 'upload.inc.php';
try {
- $reply = [];
- if (isset($_POST['reply']) and $body = $_POST['reply']) {
- $reply['raw'] = $body;
- $reply['message'] = messagehtml($body);
- }
- if ($_FILES and !empty($_FILES['image'])) {
- $target = 'data/upload';
- if (!file_exists($target)) {
- throw new Exception("er is geen uploadmap aanwezig op $target");
- }
- $target .= '/' . $User->login;
- if ($result = userupload($_FILES['image'], $target)) {
- $reply['raw'] .= "/$result";
- if (preg_match('(^image/)', $_FILES['image']['type'])) {
- $reply['message'] .= sprintf('
![](/thumb/640x/%s)
', $result);
- }
- else {
- $reply['message'] .= sprintf('Bijgevoegd bestand: %s
',
- $result, basename($result)
- );
- }
- }
- }
- $query = $Db->set('comments', $reply + [
- 'page' => $Page->link,
- 'author' => $User->login,
- ]);
- if (!$query->rowCount()) {
- throw new Exception('Fout bij opslaan');
- }
- $newcomment = $Db->dbh->lastInsertId('comments_id_seq');
-
- if (isset($Issue)) {
- $row = [];
- foreach (array_keys($journalcol) 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,
- ]);
- }
- $Issue = $updated;
- }
- }
-
- $target = "/{$Page->link}/$newcomment#$newcomment";
+ $newcomment = createcomment($_POST, $Issue);
+ $target = "/{$Page->link}?last=$newcomment#$newcomment";
abort($target, ($Page->api ? 200 : 303) . ' reply success');
$_POST['reply'] = NULL;
}
@@ -81,32 +14,47 @@ if ($_POST) {
if ($Page->api) {
abort(ucfirst($e->getMessage()), '500 reply error');
}
- print "Antwoord niet opgeslagen: {$e->getMessage()}.
\n\n";
+ printf("Antwoord niet opgeslagen: %s.
\n\n",
+ nl2br(htmlspecialchars($e->getMessage()))
+ );
}
}
-$cols = '*, (SELECT json_agg(journal.*) FROM journal WHERE comment_id = comments.id) AS journal';
+$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]);
-if ($row = $query->fetch()) {
- print $row->message;
- $Page->teaser = $row->raw;
-}
-
-print '';
+print '';
$imagecount = 0;
-while ($row = $query->fetch()) {
+for ($i = 0; $row = $query->fetch(); $i++) {
$rowuser = new User("profile/{$row->author}");
- printf('- ', $row->id);
- printf('%s %s',
- $rowuser->html, showdate(preg_split('/\D/', $row->created))
- );
+ 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;
- printf("\n%s
\n", $html);
+ if ($i) {
+ $html = "\n$html
\n";
+ }
+ print $html;
}
if ($changes = json_decode($row->journal)) {
print '';
@@ -129,13 +77,24 @@ while ($row = $query->fetch()) {
}
print "
\n";
}
- print " \n";
+ print "\n";
}
if ($User->login) {
- print '- ';
+ print '
';
print '";
print '';
- print " \n";
+ print "\n";
}
-print "
\n\n";
+print "\n\n";