]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/PageInfo.php
Merge pull request #11531 from annando/display-polls
[friendica.git] / src / Content / PageInfo.php
index 293da75a93673c292add9a5c99aa81b85844ad4b..41ecb3d7fa35a0ec207747a7c174fe9707e51b39 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -253,10 +253,15 @@ class PageInfo
                // Fix for Mastodon where the mentions are in a different format
                $body = preg_replace("~\[url=($URLSearchString)]([#!@])(.*?)\[/url]~is", '$2[url=$1]$3[/url]', $body);
 
-               preg_match("~(?<![!#@])\[url]($URLSearchString)\[/url]$~is", $body, $matches);
+               // Remove all hashtags and mentions
+               $body = preg_replace("/([#@!])\[url\=(.*?)\](.*?)\[\/url\]/ism", '', $body);
+
+               // Search for pure links
+               preg_match("/\[url\](https?:.*?)\[\/url\]/ism", $body, $matches);
 
                if (!$matches) {
-                       preg_match("~(?<![!#@])\[url=($URLSearchString)].*\[/url]$~is", $body, $matches);
+                       // Search for links with descriptions
+                       preg_match("/\[url\=(https?:.*?)\].*?\[\/url\]/ism", $body, $matches);
                }
 
                if (!$matches && $searchNakedUrls) {
@@ -292,7 +297,8 @@ class PageInfo
                        }
 
                        // Stripping link labels that include a shortened version of the URL
-                       if (strpos($url, trim($match[1], '.…')) !== false) {
+                       $trimMatch = trim($match[1], '.…');
+                       if (!empty($trimMatch) && strpos($url, $trimMatch) !== false) {
                                return '';
                        }