Merge pull request 'Hande crossboard invalid links with strikethrough' (#119) from cross-strikethrough into config

Reviewed-on: leftypol/leftypol#119
This commit is contained in:
Zankaria 2025-04-23 13:13:05 -05:00
commit 55508e6210

View file

@ -2229,19 +2229,14 @@ function markup(&$body, $track_cites = false) {
if ($board['uri'] != $_board) { if ($board['uri'] != $_board) {
if (!openBoard($_board)) { if (!openBoard($_board)) {
if (in_array($_board,array_keys($config['boards_alias']))){ if (\in_array($_board, \array_keys($config['boards_alias']))) {
$_board = $config['boards_alias'][$_board]; $_board = $config['boards_alias'][$_board];
if (openBoard($_board)){ if (!openBoard($_board)) {
}
else {
continue; // Unknown board continue; // Unknown board
} }
} } else {
else {
continue; // Unknown board continue; // Unknown board
} }
} }
} }
@ -2282,40 +2277,33 @@ function markup(&$body, $track_cites = false) {
if ($cite) { if ($cite) {
if (isset($cited_posts[$_board][$cite])) { if (isset($cited_posts[$_board][$cite])) {
$link = $cited_posts[$_board][$cite]; $link = $cited_posts[$_board][$cite];
if (isset($original_board)){ $replacement_board = $original_board ?? $_board;
$replacement = '<a ' . $replacement = '<a ' .
($_board == $board['uri'] ? ($_board == $board['uri'] ?
'onclick="highlightReply(\''.$cite.'\', event);" ' 'onclick="highlightReply(\''.$cite.'\', event);" '
: '') . 'href="' . $link . '">' . : '') . 'href="' . $link . '">' .
'&gt;&gt;&gt;/' . $original_board . '/' . $cite . '&gt;&gt;&gt;/' . $replacement_board . '/' . $cite .
'</a>'; '</a>';
if ($track_cites && $config['track_cites']) {
$tracked_cites[] = [ $_board, $cite ];
} }
else { } else {
$replacement = '<a ' . $replacement = "<s>&gt;&gt;&gt;/$_board/$cite</s>";
($_board == $board['uri'] ?
'onclick="highlightReply(\''.$cite.'\', event);" '
: '') . 'href="' . $link . '">' .
'&gt;&gt;&gt;/' . $_board . '/' . $cite .
'</a>';
}
$body = mb_substr_replace($body, $matches[1][0] . $replacement . $matches[4][0], $matches[0][1] + $skip_chars, mb_strlen($matches[0][0]));
$skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[4][0]) - mb_strlen($matches[0][0]);
if ($track_cites && $config['track_cites'])
$tracked_cites[] = array($_board, $cite);
} }
} elseif (isset($crossboard_indexes[$_board])) { } elseif (isset($crossboard_indexes[$_board])) {
$replacement = '<a href="' . $crossboard_indexes[$_board] . '">' . $replacement = '<a href="' . $crossboard_indexes[$_board] . '">' .
'&gt;&gt;&gt;/' . $_board . '/' . '&gt;&gt;&gt;/' . $_board . '/' .
'</a>'; '</a>';
} else {
$replacement = "<s>&gt;&gt;&gt;/$_board/$cite</s>";
}
$body = mb_substr_replace($body, $matches[1][0] . $replacement . $matches[4][0], $matches[0][1] + $skip_chars, mb_strlen($matches[0][0])); $body = mb_substr_replace($body, $matches[1][0] . $replacement . $matches[4][0], $matches[0][1] + $skip_chars, mb_strlen($matches[0][0]));
$skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[4][0]) - mb_strlen($matches[0][0]); $skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[4][0]) - mb_strlen($matches[0][0]);
} }
} }
}
$tracked_cites = array_unique($tracked_cites, SORT_REGULAR); $tracked_cites = array_unique($tracked_cites, SORT_REGULAR);