issue: formatted main message, edit links in admin dates
[minimedit.git] / widget / reply.php
index 010b1de4dcb90e9e1c0179a7e9da608797917b0e..0c5d5a349c9a29987bef16d1d896954627ddcf40 100644 (file)
@@ -6,7 +6,7 @@ require_once 'upload.inc.php';
 if ($_POST) {
        try {
                $newcomment = createcomment($_POST, $Issue);
-               $target = "/{$Page->link}/$newcomment#$newcomment";
+               $target = "/{$Page->link}?last=$newcomment#$newcomment";
                abort($target, ($Page->api ? 200 : 303) . ' reply success');
                $_POST['reply'] = NULL;
        }
@@ -14,32 +14,47 @@ if ($_POST) {
                if ($Page->api) {
                        abort(ucfirst($e->getMessage()), '500 reply error');
                }
-               print "<p class=warn>Antwoord niet opgeslagen: {$e->getMessage()}.</p>\n\n";
+               printf("<p class=warn>Antwoord niet opgeslagen: %s.</p>\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 '<ul class="replies">';
+print '<section class="replies">';
 
 $imagecount = 0;
-while ($row = $query->fetch()) {
+for ($i = 0; $row = $query->fetch(); $i++) {
        $rowuser = new User("profile/{$row->author}");
-       printf('<li id="%d">', $row->id);
-       printf('<strong>%s</strong> <small class=date>%s</small>',
-               $rowuser->html, showdate(preg_split('/\D/', $row->created))
-       );
+       printf('<article id="%d">', $row->id);
+       if ($i) {
+               # subsequent reply header
+               printf('<strong>%s</strong>', $rowuser->html);
+       }
+       else {
+               $Page->teaser = $row->raw;
+       }
+       $rowdate = showdate(preg_split('/\D/', $row->created));
+       if ($User->admin('beheer')) {
+               if ($row->updated) {
+                       $rowdate = "<s>$rowdate</s> " . showdate(preg_split('/\D/', $row->updated));
+               }
+               if ($User->admin('user') || $User->login === $row->author) {
+                       $rowdate .= sprintf(' <a href="%s" title="%s" class=icon>%s</a>',
+                               "/{$Page->link}/{$row->id}", 'reactie aanpassen', "\u{270D}");
+               }
+       }
+       printf(' <small class=date>%s</small>', $rowdate);
        if ($html = $row->message) {
                $html = preg_replace('/(?<=<img )/',
                        $imagecount > 2 ? 'loading="lazy" ' : '', $html, -1, $found);
                $imagecount += $found;
-               printf("<blockquote>\n%s</blockquote>\n", $html);
+               if ($i) {
+                       $html = "<blockquote>\n$html</blockquote>\n";
+               }
+               print $html;
        }
        if ($changes = json_decode($row->journal)) {
                print '<ul>';
@@ -62,13 +77,24 @@ while ($row = $query->fetch()) {
                }
                print "</ul>\n";
        }
-       print "</li>\n";
+       print "</article>\n";
 }
 
 if ($User->login) {
-       print '<li>';
+       print '<article><hr />';
        print '<form method="post" action="" enctype="multipart/form-data">';
        if (isset($Issue) and $User->admin("edit {$Page->link}")) {
+               print "<aside>\n";
+               print '<p>';
+               printf(
+                       '<label for="%s">%s:</label> '
+                       . '<input id="%1$s" name="%1$s" value="%s" />'."\n",
+                       'subject',
+                       $journalcol['subject'],
+                       htmlspecialchars($Issue->subject ?? '')
+               );
+               print "</p>\n";
+
                print '<p>';
                printf(
                        '<label for="%s">%s:</label> '
@@ -87,6 +113,7 @@ if ($User->login) {
                        'Gesloten'
                );
                print "</p>\n";
+               print "</aside>\n";
        }
        {
                print '<p>';
@@ -118,7 +145,7 @@ if ($User->login) {
        print '<input type="submit" value="Plaatsen" />'."\n";
        print "</form>";
        print '<script src="/upload/progress.js"></script>';
-       print "</li>\n";
+       print "</article>\n";
 }
 
-print "</ul>\n\n";
+print "</section>\n\n";