widget/reply: lazy image loading in html5
[minimedit.git] / widget / reply.php
index a3b8052a6e7c5ad4a6794ffc6ad5b1acf07a2c3a..4da0ffa884e317fdc1706766cd60f1a2c57120f7 100644 (file)
@@ -4,6 +4,7 @@ require_once 'database.inc.php';
 
 $journalcol = [
        'assign' => 'Toegewezen aan',
+       'subject' => 'Onderwerp',
 ];
 
 if ($_POST) {
@@ -85,13 +86,19 @@ $query = $Db->query("SELECT $cols FROM comments WHERE page = ? ORDER BY created"
 
 print '<ul class="replies">';
 
+$imagecount = 0;
 while ($row = $query->fetch()) {
        $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("<blockquote>\n%s</blockquote>\n", $row->message);
+       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 ($changes = json_decode($row->journal)) {
                print '<ul>';
                foreach ($changes as $change) {