]> git.mxchange.org Git - friendica.git/commitdiff
Move autolink regex in Util\Strings
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 10 Mar 2019 04:25:53 +0000 (23:25 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sun, 10 Mar 2019 04:25:53 +0000 (23:25 -0500)
src/Content/Text/BBCode.php
src/Util/Strings.php

index 2c324a43304b8d6430f364086cd9d5e8c61c7ef9..2d1c681f4f204fb17038501808c1a51e0f1ca36b 100644 (file)
@@ -1268,24 +1268,7 @@ class BBCode extends BaseObject
 
                // if the HTML is used to generate plain text, then don't do this search, but replace all URL of that kind to text
                if (!$for_plaintext) {
-                       // Autolink feature (thanks to https://daringfireball.net/2010/07/improved_regex_for_matching_urls)
-                       $autolink_regex = '@(?xi)
-(?<![=\'\]"/])          # Not preceded by =, \', ], ", /
-\b
-(                       # Capture 1: entire matched URL
-  https?://                 # http or https protocol
-  (?:
-    [^/.][^/]+[.][^/]+/?    # looks like domain name followed by a slash
-  )
-  (?:                       # One or more:
-    [^\s()<>]+                  # Run of non-space, non-()<>
-    |                           #   or
-    \(([^\s()<>]+|(\([^\s()<>]+\)))*\)  # balanced parens, up to 2 levels
-    |                               #   or
-    [^\s`!()\[\]{};:\'".,<>?«»“”‘’]        # not a space or one of these punct chars
-  )*
-)@';
-                       $text = preg_replace($autolink_regex, '[url]$1[/url]', $text);
+                       $text = preg_replace(Strings::autoLinkRegEx(), '[url]$1[/url]', $text);
                        if ($simple_html == 7) {
                                $text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", 'self::convertUrlForOStatusCallback', $text);
                                $text = preg_replace_callback("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", 'self::convertUrlForOStatusCallback', $text);
index 55751d8d8274a901fca6a76b75171a89e886a1e7..3edc9ba90683959fcd685208a62b24b6c18bdfab 100644 (file)
@@ -346,4 +346,30 @@ class Strings
 
                return $return;
        }
+
+       /**
+        * Returns the regular expression string to match URLs in a given text
+        *
+        * @return string
+        * @see https://daringfireball.net/2010/07/improved_regex_for_matching_urls
+        */
+       public static function autoLinkRegEx()
+       {
+               return '@(?xi)
+(?<![=\'\]"/])          # Not preceded by [, =, \', ], ", /
+\b
+(                       # Capture 1: entire matched URL
+  https?://                 # http or https protocol
+  (?:
+    [^/.][^/]+[.][^/]+/?    # looks like domain name followed by a slash
+  )
+  (?:                       # One or more:
+    [^\s()<>]+                  # Run of non-space, non-()<>
+    |                           #   or
+    \(([^\s()<>]+|(\([^\s()<>]+\)))*\)  # balanced parens, up to 2 levels
+    |                               #   or
+    [^\s`!()\[\]{};:\'".,<>?«»“”‘’]        # not a space or one of these punct chars
+  )*
+)@';
+       }
 }