From ae806a593dd87759c3d8b2dbf86d01fc3a2b6c3a Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 25 Jan 2019 01:15:43 +0100 Subject: [PATCH] BBCode - added preg_replacers for local [url] without target="_blank" --- src/Content/Text/BBCode.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 78f252b924..f225460645 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1361,7 +1361,16 @@ class BBCode extends BaseObject . ''; }, $text); - $text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $text); + // We need no target="_blank" for local links + // convert links start with System::baseUrl() as local link + $escapedBaseUrl = str_replace('://', '\:\/\/', System::baseUrl()); + $text = preg_replace("/\[url\]($escapedBaseUrl)([$URLSearchString]*)\[\/url\]/ism", '$1$2', $text); + $text = preg_replace("/\[url\=($escapedBaseUrl)([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$3', $text); + // convert links that start with / as local link + $text = preg_replace("/\[url\](\/[$URLSearchString]*)\[\/url\]/ism", '$1', $text); + $text = preg_replace("/\[url\=(\/[$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $text); + + $text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $text); $text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $text); // Red compatibility, though the link can't be authenticated on Friendica