Skip to content

Commit b73f22a

Browse files
committed
Fetch message for quotefast action via Msg object
1 parent 003f2a4 commit b73f22a

File tree

1 file changed

+51
-32
lines changed

1 file changed

+51
-32
lines changed

Sources/Actions/QuoteFast.php

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use SMF\ActionTrait;
2020
use SMF\Config;
2121
use SMF\Db\DatabaseApi as Db;
22+
use SMF\IntegrationHook;
2223
use SMF\Lang;
2324
use SMF\Msg;
2425
use SMF\Theme;
@@ -47,52 +48,68 @@ class QuoteFast implements ActionInterface
4748
*/
4849
public function execute(): void
4950
{
50-
$moderate_boards = User::$me->boardsAllowedTo('moderate_board');
51-
52-
$request = Db::$db->query(
53-
'',
54-
'SELECT COALESCE(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.body, m.id_topic, m.subject,
55-
m.id_board, m.id_member, m.approved, m.modified_time, m.modified_name, m.modified_reason
56-
FROM {db_prefix}messages AS m
57-
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
58-
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
59-
WHERE {query_see_message_board}
60-
AND m.id_msg = {int:id_msg}' . (isset($_REQUEST['modify']) || (!empty($moderate_boards) && $moderate_boards[0] == 0) ? '' : '
61-
AND (t.locked = {int:not_locked}' . (empty($moderate_boards) ? '' : ' OR m.id_board IN ({array_int:moderation_board_list})') . ')') . '
62-
LIMIT 1',
63-
[
64-
'current_member' => User::$me->id,
65-
'moderation_board_list' => $moderate_boards,
66-
'id_msg' => (int) $_REQUEST['quote'],
51+
$query_customizations = [
52+
'selects' => [
53+
'COALESCE(mem.real_name, m.poster_name) AS poster_name',
54+
'm.poster_time',
55+
'm.body',
56+
'm.id_msg',
57+
'm.id_topic',
58+
'm.subject',
59+
'm.id_board',
60+
'm.id_member',
61+
'm.approved',
62+
'm.modified_time',
63+
'm.modified_name',
64+
'm.modified_reason',
65+
],
66+
'joins' => [
67+
'JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)',
68+
'LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)',
69+
],
70+
'where' => [
71+
'{query_see_message_board}',
72+
'm.id_msg IN ({array_int:message_list})'
73+
],
74+
'order' => [],
75+
'params' => [
6776
'not_locked' => 0,
6877
],
69-
);
70-
Utils::$context['close_window'] = Db::$db->num_rows($request) == 0;
71-
$row = Db::$db->fetch_assoc($request);
72-
Db::$db->free_result($request);
78+
];
7379

74-
Utils::$context['sub_template'] = 'quotefast';
80+
$bq = User::$me->mod_cache['bq'];
7581

76-
if (!empty($row)) {
77-
$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == User::$me->id) || User::$me->allowedTo('approve_posts', $row['id_board']);
82+
if (isset($_REQUEST['modify']) || $bq != '1=1') {
83+
$query_customizations['where'][] = 't.locked = {int:not_locked}' . ($bq == '0=1' ? '' : 'm.' . $bq);
7884
}
7985

80-
if (!empty($can_view_post)) {
86+
$row = current(Msg::load((int) $_REQUEST['quote'], $query_customizations));
87+
88+
if ($row === false) {
89+
return;
90+
}
91+
92+
Utils::$context['sub_template'] = 'quotefast';
93+
94+
$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == User::$me->id) || User::$me->allowedTo('approve_posts', $row['id_board']);
95+
96+
if ($can_view_post) {
8197
// Remove special formatting we don't want anymore.
82-
$row['body'] = Msg::un_preparsecode($row['body']);
98+
$body = Msg::un_preparsecode($row['body']);
99+
$subject = $row['subject'];
83100

84101
// Censor the message!
85-
Lang::censorText($row['body']);
102+
Lang::censorText($body);
86103

87104
// Want to modify a single message by double clicking it?
88105
if (isset($_REQUEST['modify'])) {
89-
Lang::censorText($row['subject']);
106+
Lang::censorText($subject);
90107

91108
Utils::$context['sub_template'] = 'modifyfast';
92109
Utils::$context['message'] = [
93110
'id' => $_REQUEST['quote'],
94-
'body' => $row['body'],
95-
'subject' => addcslashes($row['subject'], '"'),
111+
'body' => $body,
112+
'subject' => addcslashes($subject, '"'),
96113
'reason' => [
97114
'name' => $row['modified_name'],
98115
'text' => $row['modified_reason'],
@@ -105,13 +122,13 @@ public function execute(): void
105122

106123
// Remove any nested quotes.
107124
if (!empty(Config::$modSettings['removeNestedQuotes'])) {
108-
$row['body'] = preg_replace(['~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'], '', $row['body']);
125+
$body = preg_replace(['~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'], '', $body);
109126
}
110127

111128
$lb = "\n";
112129

113130
// Add a quote string on the front and end.
114-
Utils::$context['quote']['xml'] = '[quote author=' . $row['poster_name'] . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $row['poster_time'] . ']' . $lb . $row['body'] . $lb . '[/quote]';
131+
Utils::$context['quote']['xml'] = '[quote author=' . $row['poster_name'] . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $row['poster_time'] . ']' . $lb . $body . $lb . '[/quote]';
115132
Utils::$context['quote']['text'] = strtr(Utils::htmlspecialcharsDecode(Utils::$context['quote']['xml']), ['\'' => '\\\'', '\\' => '\\\\', "\n" => '\\n', '</script>' => '</\' + \'script>']);
116133
Utils::$context['quote']['xml'] = strtr(Utils::$context['quote']['xml'], ['&nbsp;' => '&#160;', '<' => '&lt;', '>' => '&gt;']);
117134

@@ -138,6 +155,8 @@ public function execute(): void
138155
'text' => '',
139156
];
140157
}
158+
159+
IntegrationHook::call('integrate_quotefast', [$row]);
141160
}
142161

143162
/******************

0 commit comments

Comments
 (0)