From 72aa68cdc990dde3d67b9c8827cd794e4c447968 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Mon, 26 Apr 2021 18:19:33 +0200 Subject: [PATCH] widget/reply: save raw message input before formatting 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, '
|<\/?p>', '', 'g'), E'\n?', E'\n\\1', 'g'); --- widget/comments.sql | 1 + widget/reply.php | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/widget/comments.sql b/widget/comments.sql index 3a5fcfc..a152079 100644 --- a/widget/comments.sql +++ b/widget/comments.sql @@ -13,6 +13,7 @@ CREATE TABLE issues ( CREATE TABLE comments ( page text, + raw text, message text, created timestamptz DEFAULT now(), author text, diff --git a/widget/reply.php b/widget/reply.php index 4da0ffa..685a611 100644 --- a/widget/reply.php +++ b/widget/reply.php @@ -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('

', $result); + $reply['message'] .= sprintf('

', $result); } else { - $html .= sprintf('

Bijgevoegd bestand: %s

', + $reply['message'] .= sprintf('

Bijgevoegd bestand: %s

', $result, basename($result) ); } } } - $query = $Db->set('comments', [ + $query = $Db->set('comments', $reply + [ 'page' => $Page->link, - 'message' => $html, 'author' => $User->login, ]); if (!$query->rowCount()) { -- 2.30.0