issue: formatted main message, edit links in admin dates
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 25 Nov 2021 23:41:25 +0000 (00:41 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Fri, 26 Nov 2021 00:08:03 +0000 (01:08 +0100)
Allow first comment to be edited.

widget/reply.php

index 4f6a2c88242f4f1ed5876c52b98a56826370a213..0c5d5a349c9a29987bef16d1d896954627ddcf40 100644 (file)
@@ -23,32 +23,38 @@ if ($_POST) {
 $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 '<section class="replies">';
 
 $imagecount = 0;
-while ($row = $query->fetch()) {
+for ($i = 0; $row = $query->fetch(); $i++) {
        $rowuser = new User("profile/{$row->author}");
        printf('<article id="%d">', $row->id);
-       printf('<strong>%s</strong>', $rowuser->html);
+       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') and $row->updated) {
-               $rowdate = "<s>$rowdate</s> " . showdate(preg_split('/\D/', $row->updated));
+       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 ($User->admin('beheer') and $User->admin('user') || $User->login === $row->author) {
-               printf(' <a href="%s" title="%s" class=icon>%s</a>',
-                       "/{$Page->link}/{$row->id}", 'reactie aanpassen', "\u{270D}");
-       }
        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>';