]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/Text/BBCode.php
Replace deprecated use of "self" in callables
[friendica.git] / src / Content / Text / BBCode.php
index ae21d05e13bdfa8ed134410cbfbc8a229863de98..e95ed0675983e48f238c6930f99c9f5db5faf1a3 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
  *
@@ -273,8 +273,8 @@ class BBCode
                // Get all linked images with alternative image description
                if (preg_match_all("/\[img=(http[^\[\]]*)\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures, PREG_SET_ORDER)) {
                        foreach ($pictures as $picture) {
-                               if (Photo::isLocal($picture[1])) {
-                                       $post['images'][] = ['url' => str_replace('-1.', '-0.', $picture[1]), 'description' => $picture[2]];
+                               if ($id = Photo::getIdForName($picture[1])) {
+                                       $post['images'][] = ['url' => str_replace('-1.', '-0.', $picture[1]), 'description' => $picture[2], 'id' => $id];
                                } else {
                                        $post['remote_images'][] = ['url' => $picture[1], 'description' => $picture[2]];
                                }
@@ -286,8 +286,8 @@ class BBCode
 
                if (preg_match_all("/\[img\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures, PREG_SET_ORDER)) {
                        foreach ($pictures as $picture) {
-                               if (Photo::isLocal($picture[1])) {
-                                       $post['images'][] = ['url' => str_replace('-1.', '-0.', $picture[1]), 'description' => ''];
+                               if ($id = Photo::getIdForName($picture[1])) {
+                                       $post['images'][] = ['url' => str_replace('-1.', '-0.', $picture[1]), 'description' => '', 'id' => $id];
                                } else {
                                        $post['remote_images'][] = ['url' => $picture[1], 'description' => ''];
                                }
@@ -1415,8 +1415,8 @@ class BBCode
        public static function cleanPictureLinks(string $text): string
        {
                DI::profiler()->startRecording('rendering');
-               $return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img=(.*)\](.*)\[\/img\]\[\/url\]&Usi", 'self::cleanPictureLinksCallback', $text);
-               $return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'self::cleanPictureLinksCallback', $return);
+               $return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img=(.*)\](.*)\[\/img\]\[\/url\]&Usi", [self::class, 'cleanPictureLinksCallback'], $text);
+               $return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", [self::class, 'cleanPictureLinksCallback'], $return);
                DI::profiler()->stopRecording();
                return $return;
        }
@@ -1450,7 +1450,7 @@ class BBCode
        {
                DI::profiler()->startRecording('rendering');
                $regexp = "/([@!])\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
-               $body = preg_replace_callback($regexp, ['self', 'mentionCallback'], $body);
+               $body = preg_replace_callback($regexp, [self::class, 'mentionCallback'], $body);
                DI::profiler()->stopRecording();
                return $body;
        }
@@ -2002,12 +2002,12 @@ class BBCode
 
                                if (!$for_plaintext) {
                                        if (in_array($simple_html, [self::OSTATUS, self::MASTODON_API, self::TWITTER_API, self::ACTIVITYPUB])) {
-                                               $text = preg_replace_callback("/\[url\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text);
-                                               $text = preg_replace_callback("/\[url\=(.*?)\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text);
+                                               $text = preg_replace_callback("/\[url\](.*?)\[\/url\]/ism", [self::class, 'convertUrlForActivityPubCallback'], $text);
+                                               $text = preg_replace_callback("/\[url\=(.*?)\](.*?)\[\/url\]/ism", [self::class, 'convertUrlForActivityPubCallback'], $text);
                                        }
                                } else {
                                        $text = preg_replace("(\[url\](.*?)\[\/url\])ism", " $1 ", $text);
-                                       $text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'self::removePictureLinksCallback', $text);
+                                       $text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", [self::class, 'removePictureLinksCallback'], $text);
                                }
 
                                // Bookmarks in red - will be converted to bookmarks in friendica
@@ -2017,7 +2017,7 @@ class BBCode
                                                        "[bookmark=$1]$2[/bookmark]", $text);
 
                                if (in_array($simple_html, [self::OSTATUS, self::TWITTER])) {
-                                       $text = preg_replace_callback("/([^#@!])\[url\=([^\]]*)\](.*?)\[\/url\]/ism", "self::expandLinksCallback", $text);
+                                       $text = preg_replace_callback("/([^#@!])\[url\=([^\]]*)\](.*?)\[\/url\]/ism", [self::class, 'expandLinksCallback'], $text);
                                        //$text = preg_replace("/[^#@!]\[url\=([^\]]*)\](.*?)\[\/url\]/ism", ' $2 [url]$1[/url]', $text);
                                        $text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", ' $2 [url]$1[/url]', $text);
                                }
@@ -2327,7 +2327,7 @@ class BBCode
                        $url_search_string = "^\[\]";
                        $text = preg_replace_callback(
                                "/([@!])\[(.*?)\]\(([$url_search_string]*?)\)/ism",
-                               ['self', 'bbCodeMention2DiasporaCallback'],
+                               [self::class, 'bbCodeMention2DiasporaCallback'],
                                $text
                        );
                }
@@ -2355,7 +2355,7 @@ class BBCode
                DI::profiler()->startRecording('rendering');
                $ret = [];
 
-               self::performWithEscapedTags($string, ['noparse', 'pre', 'code', 'img'], function ($string) use (&$ret) {
+               self::performWithEscapedTags($string, ['noparse', 'pre', 'code', 'img', 'attachment'], function ($string) use (&$ret) {
                        // Convert hashtag links to hashtags
                        $string = preg_replace('/#\[url\=([^\[\]]*)\](.*?)\[\/url\]/ism', '#$2 ', $string);
 
@@ -2599,7 +2599,7 @@ class BBCode
                // Bypass attachment if parse url for a comment
                if (!$tryAttachment) {
                        DI::profiler()->stopRecording();
-                       return "\n" . '[url=' . $url . ']' . $siteinfo['title'] . '[/url]';
+                       return "\n" . '[url=' . $url . ']' . ($siteinfo['title'] ?? $url) . '[/url]';
                }
 
                // Format it as BBCode attachment