]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/Text/BBCode.php
Merge pull request #7828 from nupplaphil/task/move_enotify
[friendica.git] / src / Content / Text / BBCode.php
index 75f5d506e1b60339943db55943c7ae1afc71c96d..1dffb05073b70f7f7f30c6fe35b86894986147b8 100644 (file)
@@ -24,6 +24,8 @@ use Friendica\Model\Event;
 use Friendica\Model\Photo;
 use Friendica\Network\Probe;
 use Friendica\Object\Image;
+use Friendica\Protocol\Activity;
+use Friendica\Util\Images;
 use Friendica\Util\Map;
 use Friendica\Util\Network;
 use Friendica\Util\ParseUrl;
@@ -75,7 +77,7 @@ class BBCode extends BaseObject
 
                                if (preg_match("/\[img\](.*?)\[\/img\]/ism", $attacheddata, $matches)) {
 
-                                       $picturedata = Image::getInfoFromURL($matches[1]);
+                                       $picturedata = Images::getInfoFromURLCached($matches[1]);
 
                                        if ($picturedata) {
                                                if (($picturedata[0] >= 500) && ($picturedata[0] >= $picturedata[1])) {
@@ -276,7 +278,7 @@ class BBCode extends BaseObject
 
                        if (preg_match_all("(\[url=(.*?)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\])ism", $body, $pictures, PREG_SET_ORDER)) {
                                if ((count($pictures) == 1) && !$has_title) {
-                                       if (!empty($item['object-type']) && ($item['object-type'] == ACTIVITY_OBJ_IMAGE)) {
+                                       if (!empty($item['object-type']) && ($item['object-type'] == Activity\ObjectType::IMAGE)) {
                                                // Replace the preview picture with the real picture
                                                $url = str_replace('-1.', '-0.', $pictures[0][2]);
                                                $data = ['url' => $url, 'type' => 'photo'];
@@ -304,7 +306,7 @@ class BBCode extends BaseObject
                                                $post['preview'] = $pictures[0][2];
                                                $post['text'] = trim(str_replace($pictures[0][0], '', $body));
                                        } else {
-                                               $imgdata = Image::getInfoFromURL($pictures[0][1]);
+                                               $imgdata = Images::getInfoFromURLCached($pictures[0][1]);
                                                if ($imgdata && substr($imgdata['mime'], 0, 6) == 'image/') {
                                                        $post['type'] = 'photo';
                                                        $post['image'] = $pictures[0][1];
@@ -445,7 +447,7 @@ class BBCode extends BaseObject
                                }
 
                                // guess mimetype from headers or filename
-                               $type = Image::guessType($mtch[1], true);
+                               $type = Images::guessType($mtch[1], true);
 
                                if ($i) {
                                        $Image = new Image($i, $type);
@@ -572,17 +574,17 @@ class BBCode extends BaseObject
         * Note: Can produce a [bookmark] tag in the returned string
         *
         * @brief Processes [attachment] tags
-        * @param string   $return
+        * @param string   $text
         * @param bool|int $simplehtml
         * @param bool     $tryoembed
         * @return string
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       private static function convertAttachment($return, $simplehtml = false, $tryoembed = true)
+       private static function convertAttachment($text, $simplehtml = false, $tryoembed = true)
        {
-               $data = self::getAttachmentData($return);
+               $data = self::getAttachmentData($text);
                if (empty($data) || empty($data['url'])) {
-                       return $return;
+                       return $text;
                }
 
                if (isset($data['title'])) {
@@ -599,7 +601,10 @@ class BBCode extends BaseObject
 
                $return = '';
                if (in_array($simplehtml, [7, 9])) {
-                       $return = self::convertUrlForActivityPub($data['url']);
+                       // Only add the link when it isn't already part of the body
+                       if (substr_count($text, $data['url']) == 1) {
+                               $return = self::convertUrlForActivityPub($data['url']);
+                       }
                } elseif (($simplehtml != 4) && ($simplehtml != 0)) {
                        $return = sprintf('<a href="%s" target="_blank">%s</a><br>', $data['url'], $data['title']);
                } else {
@@ -1552,7 +1557,7 @@ class BBCode extends BaseObject
                        function ($matches) use ($simple_html) {
                                $matches[1] = self::proxyUrl($matches[1], $simple_html);
                                $matches[2] = htmlspecialchars($matches[2], ENT_COMPAT);
-                               return '<img src="' . $matches[1] . '" alt="' . $matches[2] . '">';
+                               return '<img src="' . $matches[1] . '" alt="' . $matches[2] . '" title="' . $matches[2] . '">';
                        },
                        $text);
 
@@ -1747,7 +1752,7 @@ class BBCode extends BaseObject
                $text = preg_replace_callback("/(?:#\[url\=.*?\]|\[url\=.*?\]#)(.*?)\[\/url\]/ism", function($matches) {
                        return '#<a href="'
                                . System::baseUrl()     . '/search?tag=' . rawurlencode($matches[1])
-                               . '" class="tag" title="' . XML::escape($matches[1]) . '">'
+                               . '" class="tag" rel="tag" title="' . XML::escape($matches[1]) . '">'
                                . XML::escape($matches[1])
                                . '</a>';
                }, $text);