]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/Text/BBCode.php
Hashtag handling with Diaspora improved
[friendica.git] / src / Content / Text / BBCode.php
index 9ea0775075ba5098e7ff597cced3674d9165c89e..601bf63b25e23dc2ee1250fbe7473da736052424 100644 (file)
@@ -453,6 +453,10 @@ class BBCode
        {
                $s = $srctext;
 
+               // Simplify image links
+               $s = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $s);
+               $s = preg_replace("/\[img\=(.*?)\](.*?)\[\/img\]/ism", '[img]$1[/img]', $s);
+
                $matches = null;
                $c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism', $s, $matches, PREG_SET_ORDER);
                if ($c) {
@@ -464,13 +468,14 @@ class BBCode
                                        continue;
                                }
 
-                               $i = Network::fetchUrl($mtch[1]);
-                               if (!$i) {
-                                       return $srctext;
+                               $curlResult = Network::curl($mtch[1], true);
+                               if (!$curlResult->isSuccess()) {
+                                       continue;
                                }
 
-                               // guess mimetype from headers or filename
-                               $type = Images::guessType($mtch[1], true);
+                               $i = $curlResult->getBody();
+                               $type = $curlResult->getContentType();
+                               $type = Images::getMimeTypeByData($i, $mtch[1], $type);
 
                                if ($i) {
                                        $Image = new Image($i, $type);
@@ -975,7 +980,8 @@ class BBCode
                                Contact::getIdForURL($attributes['profile'], 0, true, $default);
 
                                $author_contact = Contact::getDetailsByURL($attributes['profile']);
-                               $author_contact['addr'] = ($author_contact['addr']  ?? '') ?: Protocol::getAddrFromProfileUrl($attributes['profile']);
+                               $author_contact['url'] = ($author_contact['url'] ?? $attributes['profile']);
+                               $author_contact['addr'] = ($author_contact['addr'] ?? '') ?: Protocol::getAddrFromProfileUrl($attributes['profile']);
 
                                $attributes['author']   = ($author_contact['name']  ?? '') ?: $attributes['author'];
                                $attributes['avatar']   = ($author_contact['micro'] ?? '') ?: $attributes['avatar'];
@@ -1630,7 +1636,7 @@ class BBCode
                // Try to Oembed
                if ($try_oembed) {
                        $text = preg_replace("/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4).*?)\[\/video\]/ism", '<video src="$1" controls="controls" width="' . $a->videowidth . '" height="' . $a->videoheight . '" loop="true"><a href="$1">$1</a></video>', $text);
-                       $text = preg_replace("/\[audio\](.*?\.(ogg|ogv|oga|ogm|webm|mp4|mp3).*?)\[\/audio\]/ism", '<audio src="$1" controls="controls"><a href="$1">$1</a></audio>', $text);
+                       $text = preg_replace("/\[audio\](.*?)\[\/audio\]/ism", '<audio src="$1" controls="controls"><a href="$1">$1</a></audio>', $text);
 
                        $text = preg_replace_callback("/\[video\](.*?)\[\/video\]/ism", $try_oembed_callback, $text);
                        $text = preg_replace_callback("/\[audio\](.*?)\[\/audio\]/ism", $try_oembed_callback, $text);
@@ -2004,8 +2010,6 @@ class BBCode
         */
        public static function toMarkdown($text, $for_diaspora = true)
        {
-               $a = DI::app();
-
                $original_text = $text;
 
                // Since Diaspora is creating a summary for links, this function removes them before posting
@@ -2096,7 +2100,7 @@ class BBCode
                $ret = [];
 
                // Convert hashtag links to hashtags
-               $string = preg_replace('/#\[url\=([^\[\]]*)\](.*?)\[\/url\]/ism', '#$2', $string);
+               $string = preg_replace('/#\[url\=([^\[\]]*)\](.*?)\[\/url\]/ism', '#$2 ', $string);
 
                // ignore anything in a code block
                $string = preg_replace('/\[code.*?\].*?\[\/code\]/sm', '', $string);