]> git.mxchange.org Git - friendica.git/commitdiff
Fix the detection of image posts
authorMichael <heluecht@pirati.ca>
Mon, 10 Jun 2019 16:06:54 +0000 (16:06 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 10 Jun 2019 16:06:54 +0000 (16:06 +0000)
src/Content/Text/BBCode.php

index 6805369d083d4bc7a8c6d53e4288228ce98a1280..0d83b665cdc13256245cb0c69b60c02ab4535997 100644 (file)
@@ -251,8 +251,12 @@ class BBCode extends BaseObject
 
                        if (preg_match_all("(\[url=([$URLSearchString]*)\]\s*\[img\]([$URLSearchString]*)\[\/img\]\s*\[\/url\])ism", $body, $pictures, PREG_SET_ORDER)) {
                                if ((count($pictures) == 1) && !$has_title) {
-                                       // Checking, if the link goes to a picture
-                                       $data = ParseUrl::getSiteinfoCached($pictures[0][1], true);
+                                       if (!empty($item['object-type']) && ($item['object-type'] == ACTIVITY_OBJ_IMAGE)) {
+                                               $data = ['url' => $pictures[0][1], 'type' => 'photo'];
+                                       } else {
+                                               // Checking, if the link goes to a picture
+                                               $data = ParseUrl::getSiteinfoCached($pictures[0][1], true);
+                                       }
 
                                        // Workaround:
                                        // Sometimes photo posts to the own album are not detected at the start.
@@ -271,14 +275,14 @@ class BBCode extends BaseObject
                                                }
 
                                                $post["preview"] = $pictures[0][2];
-                                               $post["text"] = str_replace($pictures[0][0], "", $body);
+                                               $post["text"] = trim(str_replace($pictures[0][0], "", $body));
                                        } else {
                                                $imgdata = Image::getInfoFromURL($pictures[0][1]);
                                                if ($imgdata && substr($imgdata["mime"], 0, 6) == "image/") {
                                                        $post["type"] = "photo";
                                                        $post["image"] = $pictures[0][1];
                                                        $post["preview"] = $pictures[0][2];
-                                                       $post["text"] = str_replace($pictures[0][0], "", $body);
+                                                       $post["text"] = trim(str_replace($pictures[0][0], "", $body));
                                                }
                                        }
                                } elseif (count($pictures) > 0) {