From edd439cfabdc5be8de8145c13072ac5187ae6591 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 8 Nov 2020 23:25:46 -0500 Subject: [PATCH 1/2] Simplify code in Content\Text\BBCode::convert - Use performWithEscapedTags instead of custom solution --- src/Content/Text/BBCode.php | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 831d6cf34c..b1cfff0a42 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1509,29 +1509,9 @@ class BBCode $text = str_replace('[hr]', '
', $text); if (!$for_plaintext) { - $escaped = []; - - // Escaping BBCodes susceptible to contain rogue URL we don'' want the autolinker to catch - $text = preg_replace_callback('#\[(url|img|audio|video|youtube|vimeo|share|attachment|iframe|bookmark).+?\[/\1\]#ism', - function ($matches) use (&$escaped) { - $return = '{escaped-' . count($escaped) . '}'; - $escaped[] = $matches[0]; - - return $return; - }, - $text - ); - - // Autolinker for isolated URLs - $text = preg_replace(Strings::autoLinkRegEx(), '[url]$1[/url]', $text); - - // Restoring escaped blocks - $text = preg_replace_callback('/{escaped-([0-9]+)}/iU', - function ($matches) use ($escaped) { - return $escaped[intval($matches[1])] ?? $matches[0]; - }, - $text - ); + $text = self::performWithEscapedTags($text, ['url', 'img', 'audio', 'video', 'youtube', 'vimeo', 'share', 'attachment', 'iframe', 'bookmark'], function ($text) { + return preg_replace(Strings::autoLinkRegEx(), '[url]$1[/url]', $text); + }); } // This is actually executed in Item::prepareBody() From 7debe1e999ca5a620f6e3e7c89f93ab84c50ccc6 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 8 Nov 2020 23:32:02 -0500 Subject: [PATCH 2/2] [AP] Use contact.alias if it exists instead of contact.url for mention links - Make mentions links handled by Mastodon for logged in users --- src/Protocol/ActivityPub/Transmitter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index bc4b31fb12..750c7f625d 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -1253,12 +1253,12 @@ class Transmitter return ''; } - $data = Contact::getByURL($match[1], false, ['url', 'nick']); + $data = Contact::getByURL($match[1], false, ['url', 'alias', 'nick']); if (empty($data['nick'])) { return $match[0]; } - return '[url=' . $data['url'] . ']@' . $data['nick'] . '[/url]'; + return '[url=' . ($data['alias'] ?: $data['url']) . ']@' . $data['nick'] . '[/url]'; } /**