]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/Text/BBCode.php
New BBCode constant for Bluesky
[friendica.git] / src / Content / Text / BBCode.php
index 89bd802027c49e7c570c340736b1deaa6a98c480..e321b13e70378c25c5431c1df97f6bbf21b6b430 100644 (file)
@@ -62,6 +62,7 @@ class BBCode
        const TWITTER      = 8;
        const BACKLINK     = 8;
        const ACTIVITYPUB  = 9;
+       const BLUESKY      = 10;
 
        const TOP_ANCHOR = '<br class="top-anchor">';
        const BOTTOM_ANCHOR = '<br class="button-anchor">';
@@ -508,26 +509,7 @@ class BBCode
         */
        private static function convertUrlForActivityPub(string $url): string
        {
-               return sprintf('<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>', $url, self::getStyledURL($url));
-       }
-
-       /**
-        * Converts an URL in a nicer format (without the scheme and possibly shortened)
-        *
-        * @param string $url URL that is about to be reformatted
-        * @return string reformatted link
-        */
-       private static function getStyledURL(string $url): string
-       {
-               $parts = parse_url($url);
-               $scheme = $parts['scheme'] . '://';
-               $styled_url = str_replace($scheme, '', $url);
-
-               if (strlen($styled_url) > 30) {
-                       $styled_url = substr($styled_url, 0, 30) . "…";
-               }
-
-               return $styled_url;
+               return sprintf('<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>', $url, Strings::getStyledURL($url));
        }
 
        /*
@@ -1790,7 +1772,7 @@ class BBCode
                                        $text
                                );
 
-                               if (in_array($simple_html, [self::OSTATUS, self::TWITTER])) {
+                               if (in_array($simple_html, [self::OSTATUS, self::TWITTER, self::BLUESKY])) {
                                        $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);