Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 51 additions & 32 deletions Sources/Actions/QuoteFast.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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' ? '' : ' OR 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'],
Expand All @@ -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', '</script>' => '</\' + \'script>']);
Utils::$context['quote']['xml'] = strtr(Utils::$context['quote']['xml'], ['&nbsp;' => '&#160;', '<' => '&lt;', '>' => '&gt;']);

Expand All @@ -138,6 +155,8 @@ public function execute(): void
'text' => '',
];
}

IntegrationHook::call('integrate_quotefast', [$row]);
}

/******************
Expand Down
Loading