From 78ace421d598f86cc37d652bb05a0e9a2142d6ea Mon Sep 17 00:00:00 2001 From: themohooks <81331307+themohooks@users.noreply.github.com> Date: Mon, 7 Oct 2024 17:06:43 +0300 Subject: [PATCH] edited comment status --- app/Controllers/Api/Images/Comments/Edit.php | 10 +++++++++- app/Models/Comment.php | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/Controllers/Api/Images/Comments/Edit.php b/app/Controllers/Api/Images/Comments/Edit.php index 816ba8c..20fba30 100644 --- a/app/Controllers/Api/Images/Comments/Edit.php +++ b/app/Controllers/Api/Images/Comments/Edit.php @@ -11,11 +11,19 @@ class Edit $postId = explode('/', $_SERVER['REQUEST_URI'])[4]; + $data = DB::query('SELECT * FROM photos_comments WHERE id=:id', array(':id' => $postId))[0]; + $content = json_decode($data['content'], true); $postuserid = DB::query('SELECT user_id FROM photos_comments WHERE id=:id', array(':id' => $postId))[0]['user_id']; if ($postuserid === Auth::userid()) { $json = file_get_contents('php://input'); $data = json_decode($json, true); - DB::query('UPDATE photos_comments SET body=:body WHERE id=:id', array(':id' => $postId, ':body' => $data['value'])); + $json_arr = $content; + if ($data['value'] != DB::query('SELECT body FROM photos_comments WHERE id=:id', array(':id' => $postId))[0]['body']) { + $json_arr['edited'] = 'true'; + } + + $json_str_updated = json_encode($json_arr); + DB::query('UPDATE photos_comments SET body=:body, content=:c WHERE id=:id', array(':id' => $postId, ':body' => $data['value'], ':c'=>$json_str_updated)); echo json_encode( array( 'errorcode' => '0', diff --git a/app/Models/Comment.php b/app/Models/Comment.php index d908e8b..6072114 100644 --- a/app/Models/Comment.php +++ b/app/Models/Comment.php @@ -16,12 +16,16 @@ class Comment { } public function i() { $user = new User($this->c['user_id']); + $content = json_decode($this->c['content'], true); echo '
'.Date::zmdate($this->c['posted_at']).'
Цитировать · Ссылка + '; + + echo '
'.htmlspecialchars($user->i('username')).' · @@ -32,6 +36,9 @@ class Comment { if (json_decode($user->i('content'), true)['aboutlive']['value'] != null) { echo ' '.htmlspecialchars(json_decode($user->i('content'), true)['aboutlive']['value']); } + if ($content['edited'] === 'true') { + echo '
(отредактировано)'; + } if ($user->i('admin') === 1) { $admintype = ' · Администратор сервера'; } else if ($user->i('admin') === 2) {