]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Strings.php
Merge pull request #12850 from nupplaphil/feat/phpstorm_editorconfig
[friendica.git] / src / Util / Strings.php
index 379f2a25213dda4ed89fc8d688eb4dffb4c038f6..2405fbababcfdbcd8d6788f4ed28040c6b954c4f 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -380,29 +380,47 @@ class Strings
         * 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(): string
        {
                return '@
-(?<![=\'\]"/])                 # Not preceded by [, =, \', ], ", /
+(?<![=\'\]"/]) # Not preceded by [, =, \', ], ", /
 \b
-(                                                         # Capture 1: entire matched URL
-  https?://                                                       # http or https protocol
+(              # Capture 1: entire matched URL
+  ' . self::linkRegEx() . '
+)@xiu';
+       }
+
+       /**
+        * Returns the regular expression string to match only an HTTP URL
+        *
+        * @return string
+        */
+       public static function onlyLinkRegEx(): string
+       {
+               return '@^' . self::linkRegEx() . '$@xiu';
+       }
+
+       /**
+        * @return string
+        * @see https://daringfireball.net/2010/07/improved_regex_for_matching_urls
+        */
+       private static function linkRegEx(): string
+       {
+               return 'https?://                   # http or https protocol
   (?:
-       [^/\s\xA0`!()\[\]{};:\'",<>?«»“”‘’.]    # Domain can\'t start with a .
-       [^/\s\xA0`!()\[\]{};:\'",<>?«»“”‘’]+    # Domain can\'t end with a .
+       [^/\s\xA0`!()\[\]{};:\'",<>?«»“”‘’.]    # Domain can\'t start with a .
+       [^/\s\xA0`!()\[\]{};:\'",<>?«»“”‘’]+    # Domain can\'t end with a .
        \.
        [^/\s\xA0`!()\[\]{};:\'".,<>?«»“”‘’]+/? # Followed by a slash
   )
-  (?:                                                             # One or more:
-       [^\s\xA0()<>]+                                             # Run of non-space, non-()<>
-       |                                                                  #   or
-       \(([^\s\xA0()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels
-       |                                                                  #   or
-       [^\s\xA0`!()\[\]{};:\'".,<>?«»“”‘’]    # not a space or one of these punct chars
-  )*
-)@xiu';
+  (?:                                       # One or more:
+       [^\s\xA0()<>]+                            # Run of non-space, non-()<>
+       |                                         #   or
+       \(([^\s\xA0()<>]+|(\([^\s()<>]+\)))*\)    # balanced parens, up to 2 levels
+       |                                                                         #   or
+       [^\s\xA0`!()\[\]{};:\'".,<>?«»“”‘’]         # not a space or one of these punct chars
+  )*';
        }
 
        /**
@@ -493,7 +511,7 @@ class Strings
                );
 
                if (is_null($return)) {
-                       Logger::warning('Received null value from preg_replace_callback', ['text' => $text, 'regex' => $regex, 'blocks' => $blocks, 'executionId' => $executionId, 'callstack' => System::callstack(10)]);
+                       Logger::notice('Received null value from preg_replace_callback', ['text' => $text, 'regex' => $regex, 'blocks' => $blocks, 'executionId' => $executionId, 'callstack' => System::callstack(10)]);
                }
 
                $text = $callback($return ?? $text) ?? '';