From b73f22a0a225457c84b8db4ff36c0dc9be891317 Mon Sep 17 00:00:00 2001 From: John Rayes Date: Fri, 1 Nov 2024 02:06:44 -0700 Subject: [PATCH 1/2] Fetch message for quotefast action via Msg object --- Sources/Actions/QuoteFast.php | 83 +++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 32 deletions(-) diff --git a/Sources/Actions/QuoteFast.php b/Sources/Actions/QuoteFast.php index b7164da925..7263b8e3a8 100644 --- a/Sources/Actions/QuoteFast.php +++ b/Sources/Actions/QuoteFast.php @@ -19,6 +19,7 @@ use SMF\ActionTrait; use SMF\Config; use SMF\Db\DatabaseApi as Db; +use SMF\IntegrationHook; use SMF\Lang; use SMF\Msg; use SMF\Theme; @@ -47,52 +48,68 @@ class QuoteFast implements ActionInterface */ public function execute(): void { - $moderate_boards = User::$me->boardsAllowedTo('moderate_board'); - - $request = Db::$db->query( - '', - 'SELECT COALESCE(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.body, m.id_topic, m.subject, - m.id_board, m.id_member, m.approved, m.modified_time, m.modified_name, m.modified_reason - FROM {db_prefix}messages AS m - INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic) - LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) - WHERE {query_see_message_board} - AND m.id_msg = {int:id_msg}' . (isset($_REQUEST['modify']) || (!empty($moderate_boards) && $moderate_boards[0] == 0) ? '' : ' - AND (t.locked = {int:not_locked}' . (empty($moderate_boards) ? '' : ' OR m.id_board IN ({array_int:moderation_board_list})') . ')') . ' - LIMIT 1', - [ - 'current_member' => User::$me->id, - 'moderation_board_list' => $moderate_boards, - 'id_msg' => (int) $_REQUEST['quote'], + $query_customizations = [ + 'selects' => [ + 'COALESCE(mem.real_name, m.poster_name) AS poster_name', + 'm.poster_time', + 'm.body', + 'm.id_msg', + 'm.id_topic', + 'm.subject', + 'm.id_board', + 'm.id_member', + 'm.approved', + 'm.modified_time', + 'm.modified_name', + 'm.modified_reason', + ], + 'joins' => [ + 'JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)', + 'LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)', + ], + 'where' => [ + '{query_see_message_board}', + 'm.id_msg IN ({array_int:message_list})' + ], + 'order' => [], + 'params' => [ 'not_locked' => 0, ], - ); - Utils::$context['close_window'] = Db::$db->num_rows($request) == 0; - $row = Db::$db->fetch_assoc($request); - Db::$db->free_result($request); + ]; - Utils::$context['sub_template'] = 'quotefast'; + $bq = User::$me->mod_cache['bq']; - if (!empty($row)) { - $can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == User::$me->id) || User::$me->allowedTo('approve_posts', $row['id_board']); + if (isset($_REQUEST['modify']) || $bq != '1=1') { + $query_customizations['where'][] = 't.locked = {int:not_locked}' . ($bq == '0=1' ? '' : 'm.' . $bq); } - if (!empty($can_view_post)) { + $row = current(Msg::load((int) $_REQUEST['quote'], $query_customizations)); + + if ($row === false) { + return; + } + + Utils::$context['sub_template'] = 'quotefast'; + + $can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == User::$me->id) || User::$me->allowedTo('approve_posts', $row['id_board']); + + if ($can_view_post) { // Remove special formatting we don't want anymore. - $row['body'] = Msg::un_preparsecode($row['body']); + $body = Msg::un_preparsecode($row['body']); + $subject = $row['subject']; // Censor the message! - Lang::censorText($row['body']); + Lang::censorText($body); // Want to modify a single message by double clicking it? if (isset($_REQUEST['modify'])) { - Lang::censorText($row['subject']); + Lang::censorText($subject); Utils::$context['sub_template'] = 'modifyfast'; Utils::$context['message'] = [ 'id' => $_REQUEST['quote'], - 'body' => $row['body'], - 'subject' => addcslashes($row['subject'], '"'), + 'body' => $body, + 'subject' => addcslashes($subject, '"'), 'reason' => [ 'name' => $row['modified_name'], 'text' => $row['modified_reason'], @@ -105,13 +122,13 @@ public function execute(): void // Remove any nested quotes. if (!empty(Config::$modSettings['removeNestedQuotes'])) { - $row['body'] = preg_replace(['~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'], '', $row['body']); + $body = preg_replace(['~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'], '', $body); } $lb = "\n"; // Add a quote string on the front and end. - Utils::$context['quote']['xml'] = '[quote author=' . $row['poster_name'] . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $row['poster_time'] . ']' . $lb . $row['body'] . $lb . '[/quote]'; + Utils::$context['quote']['xml'] = '[quote author=' . $row['poster_name'] . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $row['poster_time'] . ']' . $lb . $body . $lb . '[/quote]'; Utils::$context['quote']['text'] = strtr(Utils::htmlspecialcharsDecode(Utils::$context['quote']['xml']), ['\'' => '\\\'', '\\' => '\\\\', "\n" => '\\n', '' => '']); Utils::$context['quote']['xml'] = strtr(Utils::$context['quote']['xml'], [' ' => ' ', '<' => '<', '>' => '>']); @@ -138,6 +155,8 @@ public function execute(): void 'text' => '', ]; } + + IntegrationHook::call('integrate_quotefast', [$row]); } /****************** From 2149279119c39ff77315c1adbc77e6b9f223a63a Mon Sep 17 00:00:00 2001 From: John Rayes Date: Thu, 28 Nov 2024 02:19:48 -0700 Subject: [PATCH 2/2] Update Sources/Actions/QuoteFast.php Co-authored-by: Jon Stovell --- Sources/Actions/QuoteFast.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Actions/QuoteFast.php b/Sources/Actions/QuoteFast.php index 7263b8e3a8..bdcf3fdc44 100644 --- a/Sources/Actions/QuoteFast.php +++ b/Sources/Actions/QuoteFast.php @@ -80,7 +80,7 @@ public function execute(): void $bq = User::$me->mod_cache['bq']; if (isset($_REQUEST['modify']) || $bq != '1=1') { - $query_customizations['where'][] = 't.locked = {int:not_locked}' . ($bq == '0=1' ? '' : 'm.' . $bq); + $query_customizations['where'][] = 't.locked = {int:not_locked}' . ($bq == '0=1' ? '' : ' OR m.' . $bq); } $row = current(Msg::load((int) $_REQUEST['quote'], $query_customizations));