From ae806a593dd87759c3d8b2dbf86d01fc3a2b6c3a Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 25 Jan 2019 01:15:43 +0100 Subject: [PATCH 1/6] 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 78f252b92..f22546064 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 From a505dbbe5ca3d28fe290d51b695abdf85fee7883 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 25 Jan 2019 01:25:06 +0100 Subject: [PATCH 2/6] BBCode - fixed code styling --- src/Content/Text/BBCode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index f22546064..b710dc13e 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1370,7 +1370,7 @@ class BBCode extends BaseObject $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", '$1', $text); $text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $text); // Red compatibility, though the link can't be authenticated on Friendica From 6ba08e510d1be9f56ca21bbf26d68d6417aa5882 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 25 Jan 2019 15:32:31 +0100 Subject: [PATCH 3/6] BBCode - removed convert for relative URLs --- src/Content/Text/BBCode.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index b710dc13e..0818e28b1 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1362,13 +1362,10 @@ class BBCode extends BaseObject }, $text); // We need no target="_blank" for local links - // convert links start with System::baseUrl() as local link + // convert links start with System::baseUrl() as local link without the target="_blank" attribute $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); From 71e58a0f424b06b22e2ab1257e03809c4653c131 Mon Sep 17 00:00:00 2001 From: Peter Liebetrau Date: Fri, 25 Jan 2019 16:56:28 +0100 Subject: [PATCH 4/6] BBCode - optimized preg escaping of searchstring --- src/Content/Text/BBCode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 0818e28b1..b436fb20e 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1363,7 +1363,7 @@ class BBCode extends BaseObject // We need no target="_blank" for local links // convert links start with System::baseUrl() as local link without the target="_blank" attribute - $escapedBaseUrl = str_replace('://', '\:\/\/', System::baseUrl()); + $escapedBaseUrl = preg_quote(System::baseUrl(), '/'); $text = preg_replace("/\[url\]($escapedBaseUrl)([$URLSearchString]*)\[\/url\]/ism", '$1$2', $text); $text = preg_replace("/\[url\=($escapedBaseUrl)([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$3', $text); From 54bec2bc8e69d7307ee819b7c10c6e05ac188110 Mon Sep 17 00:00:00 2001 From: Peter Liebetrau Date: Fri, 25 Jan 2019 17:25:42 +0100 Subject: [PATCH 5/6] BBCode - optimized preg searchstring --- src/Content/Text/BBCode.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index b436fb20e..24118ef57 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1364,8 +1364,8 @@ class BBCode extends BaseObject // We need no target="_blank" for local links // convert links start with System::baseUrl() as local link without the target="_blank" attribute $escapedBaseUrl = preg_quote(System::baseUrl(), '/'); - $text = preg_replace("/\[url\]($escapedBaseUrl)([$URLSearchString]*)\[\/url\]/ism", '$1$2', $text); - $text = preg_replace("/\[url\=($escapedBaseUrl)([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$3', $text); + $text = preg_replace("/\[url\]($escapedBaseUrl[$URLSearchString]*)\[\/url\]/ism", '$1', $text); + $text = preg_replace("/\[url\=($escapedBaseUrl[$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $text); $text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $text); $text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $text); From 41663c7592abe55a958632c3a48265e0a8544d2b Mon Sep 17 00:00:00 2001 From: Peter Liebetrau Date: Fri, 25 Jan 2019 17:33:25 +0100 Subject: [PATCH 6/6] BBCode - fixed syntax error --- src/Content/Text/BBCode.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 24118ef57..2c2054750 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1364,8 +1364,8 @@ class BBCode extends BaseObject // We need no target="_blank" for local links // convert links start with System::baseUrl() as local link without the target="_blank" attribute $escapedBaseUrl = preg_quote(System::baseUrl(), '/'); - $text = preg_replace("/\[url\]($escapedBaseUrl[$URLSearchString]*)\[\/url\]/ism", '$1', $text); - $text = preg_replace("/\[url\=($escapedBaseUrl[$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $text); + $text = preg_replace("/\[url\](".$escapedBaseUrl."[$URLSearchString]*)\[\/url\]/ism", '$1', $text); + $text = preg_replace("/\[url\=(".$escapedBaseUrl."[$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $text); $text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $text); $text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $text);