Skip to content

Commit

Permalink
Merge pull request #8271 from Sesquipedalian/2.1/merge_topic_link
Browse files Browse the repository at this point in the history
2.1/merge topic link
  • Loading branch information
Sesquipedalian authored Jul 1, 2024
2 parents 7285205 + dfe8091 commit 03738fd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Sources/MoveTopic.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function MoveTopic2()
{
// Replace tokens with links in the reason.
$reason_replacements = array(
$txt['movetopic_auto_board'] => '[url="' . $scripturl . '?board=' . $_POST['toboard'] . '.0"]' . $board_name . '[/url]',
$txt['movetopic_auto_board'] => '[url="' . $scripturl . '?board=' . $_POST['toboard'] . '.0"]' . $board_name . '[/url]',
$txt['movetopic_auto_topic'] => '[iurl]' . $scripturl . '?topic=' . $topic . '.0[/iurl]',
);

Expand All @@ -277,7 +277,7 @@ function MoveTopic2()

// Make sure we catch both languages in the reason.
$reason_replacements += array(
$txt['movetopic_auto_board'] => '[url="' . $scripturl . '?board=' . $_POST['toboard'] . '.0"]' . $board_name . '[/url]',
$txt['movetopic_auto_board'] => '[url="' . $scripturl . '?board=' . $_POST['toboard'] . '.0"]' . $board_name . '[/url]',
$txt['movetopic_auto_topic'] => '[iurl]' . $scripturl . '?topic=' . $topic . '.0[/iurl]',
);
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/SplitTopics.php
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@ function MergeExecute($topics = array())
{
// Replace tokens with links in the reason.
$reason_replacements = array(
$txt['movetopic_auto_topic'] => '[iurl="' . $scripturl . '?topic=' . $id_topic . '.0"]' . $target_subject . '[/iurl]',
$txt['movetopic_auto_topic'] => '[iurl="' . $scripturl . '?topic=' . $id_topic . '.0"]' . $target_subject . '[/iurl]',
);

// Should be in the boardwide language.
Expand All @@ -1411,7 +1411,7 @@ function MergeExecute($topics = array())

// Make sure we catch both languages in the reason.
$reason_replacements += array(
$txt['movetopic_auto_topic'] => '[iurl="' . $scripturl . '?topic=' . $id_topic . '.0"]' . $target_subject . '[/iurl]',
$txt['movetopic_auto_topic'] => '[iurl="' . $scripturl . '?topic=' . $id_topic . '.0"]' . $target_subject . '[/iurl]',
);
}

Expand Down
31 changes: 19 additions & 12 deletions Sources/Subs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3657,17 +3657,21 @@ function($matches) use ($schemes)
// The value may be quoted for some tags - check.
if (isset($tag['quoted']))
{
$quoted = substr($message, $pos1, 6) == '"';
// Anything passed through the preparser will use ",
// but we need to handle raw quotation marks too.
$quot = substr($message, $pos1, 1) === '"' ? '"' : '"';

$quoted = substr($message, $pos1, strlen($quot)) == $quot;
if ($tag['quoted'] != 'optional' && !$quoted)
continue;

if ($quoted)
$pos1 += 6;
$pos1 += strlen($quot);
}
else
$quoted = false;

$pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1);
$pos2 = strpos($message, $quoted == false ? ']' : $quot . ']', $pos1);
if ($pos2 === false)
continue;

Expand All @@ -3676,7 +3680,7 @@ function($matches) use ($schemes)
continue;

$data = array(
substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
substr($message, $pos2 + ($quoted == false ? 1 : 1 + strlen($quot)), $pos3 - ($pos2 + ($quoted == false ? 1 : 1 + strlen($quot)))),
substr($message, $pos1, $pos2 - $pos1)
);

Expand Down Expand Up @@ -3759,29 +3763,32 @@ function($matches) use ($schemes)
// The value may be quoted for some tags - check.
if (isset($tag['quoted']))
{
$quoted = substr($message, $pos1, 6) == '"';
// Will normally be '"' but might be '"'.
$quot = substr($message, $pos1, 1) === '"' ? '"' : '"';

$quoted = substr($message, $pos1, strlen($quot)) == $quot;
if ($tag['quoted'] != 'optional' && !$quoted)
continue;

if ($quoted)
$pos1 += 6;
$pos1 += strlen($quot);
}
else
$quoted = false;

if ($quoted)
{
$end_of_value = strpos($message, '"]', $pos1);
$nested_tag = strpos($message, '="', $pos1);
$end_of_value = strpos($message, $quot . ']', $pos1);
$nested_tag = strpos($message, '=' . $quot, $pos1);
// Check so this is not just an quoted url ending with a =
if ($nested_tag && substr($message, $nested_tag, 8) == '="]')
if ($nested_tag && substr($message, $nested_tag, 2 + strlen($quot)) == '=' . $quot . ']')
$nested_tag = false;
if ($nested_tag && $nested_tag < $end_of_value)
// Nested tag with quoted value detected, use next end tag
$nested_tag_pos = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1) + 6;
$nested_tag_pos = strpos($message, $quoted == false ? ']' : $quot . ']', $pos1) + strlen($quot);
}

$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', isset($nested_tag_pos) ? $nested_tag_pos : $pos1);
$pos2 = strpos($message, $quoted == false ? ']' : $quot . ']', isset($nested_tag_pos) ? $nested_tag_pos : $pos1);
if ($pos2 === false)
continue;

Expand All @@ -3800,7 +3807,7 @@ function($matches) use ($schemes)
$open_tags[] = $tag;

$code = strtr($tag['before'], array('$1' => $data));
$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + ($quoted == false ? 1 : 7));
$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + ($quoted == false ? 1 : 1 + strlen($quot)));
$pos += strlen($code) - 1 + 2;
}

Expand Down

0 comments on commit 03738fd

Please sign in to comment.