widget/reply: save raw message input before formatting
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 26 Apr 2021 16:19:33 +0000 (18:19 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 17 May 2021 18:53:38 +0000 (20:53 +0200)
Prepare for upcoming conversion (errors) and possible debugging.

Restructure earlier posts:

ALTER TABLE comments ADD raw text;
UPDATE comments SET raw = regexp_replace(regexp_replace(raw,
'<br />|<\/?p>', '', 'g'),
E'\n?<img src="/thumb/640x(/.*)" />', E'\n\\1', 'g');

widget/comments.sql
widget/reply.php

index 3a5fcfc2fc6765c262ee484c012c9398379649bc..a1520793c06a2ff121f3b7bb8e9304e64e466c00 100644 (file)
@@ -13,6 +13,7 @@ CREATE TABLE issues (
 
 CREATE TABLE comments (
        page       text,
+       raw        text,
        message    text,
        created    timestamptz DEFAULT now(),
        author     text,
index 4da0ffa884e317fdc1706766cd60f1a2c57120f7..685a611eca98778c7bf77ba8ed8c78f769c3ba45 100644 (file)
@@ -10,7 +10,11 @@ $journalcol = [
 if ($_POST) {
        require_once 'upload.inc.php';
        try {
-               $html = messagehtml($_POST['reply']);
+               $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)) {
@@ -18,19 +22,19 @@ if ($_POST) {
                        }
                        $target .= '/' . $User->login;
                        if ($result = userupload($_FILES['image'], $target)) {
+                               $reply['raw'] .= "/$result";
                                if (preg_match('(^image/)', $_FILES['image']['type'])) {
-                                       $html .= sprintf('<p><img src="/thumb/640x/%s" /></p>', $result);
+                                       $reply['message'] .= sprintf('<p><img src="/thumb/640x/%s" /></p>', $result);
                                }
                                else {
-                                       $html .= sprintf('<p>Bijgevoegd bestand: <a href="/%s" />%s</a></p>',
+                                       $reply['message'] .= sprintf('<p>Bijgevoegd bestand: <a href="/%s" />%s</a></p>',
                                                $result, basename($result)
                                        );
                                }
                        }
                }
-               $query = $Db->set('comments', [
+               $query = $Db->set('comments', $reply + [
                        'page'    => $Page->link,
-                       'message' => $html,
                        'author'  => $User->login,
                ]);
                if (!$query->rowCount()) {