]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Diaspora.php
Preview for Videos and images / Video resolution selection
[friendica.git] / src / Protocol / Diaspora.php
index 2a4dfe75e7e516a1aaee9a88106a33af26ea9ea3..4ad70eac0c1661599bad19025692a2fefa4f563d 100644 (file)
@@ -2485,7 +2485,6 @@ class Diaspora
 
                Tag::storeFromBody($datarray['uri-id'], $datarray["body"]);
 
-               //Post\Media::copy($original_item['uri-id'], $datarray['uri-id']);
                $datarray["app"]  = $original_item["app"];
 
                $datarray["plink"] = self::plink($author, $guid);
@@ -2729,8 +2728,6 @@ class Diaspora
                if ($data->photo) {
                        foreach ($data->photo as $photo) {
                                self::storePhotoAsMedia($datarray['uri-id'], $photo);
-                               //$body = "[img]".XML::unescape($photo->remote_photo_path).
-                               //      XML::unescape($photo->remote_photo_name)."[/img]\n".$body;
                        }
 
                        $datarray["object-type"] = Activity\ObjectType::IMAGE;
@@ -3369,6 +3366,36 @@ class Diaspora
                return $eventdata;
        }
 
+       /**
+        * Add media attachments to the body
+        *
+        * @param array $item
+        * @return string body
+        */
+       private static function addAttachments(array $item)
+       {
+               $body = $item['body'];
+
+               foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::IMAGE, Post\Media::AUDIO, Post\Media::VIDEO]) as $media) {
+                       if (Item::containsLink($item['body'], $media['url'])) {
+                               continue;
+                       }
+
+                       if ($media['type'] == Post\Media::IMAGE) {
+                               if (!empty($media['description'])) {
+                                       $body .= "\n[img=" . $media['url'] . ']' . $media['description'] .'[/img]';
+                               } else {
+                                       $body .= "\n[img]" . $media['url'] .'[/img]';
+                               }
+                       } elseif ($media['type'] == Post\Media::AUDIO) {
+                               $body .= "\n[audio]" . $media['url'] . "[/audio]\n";
+                       } elseif ($media['type'] == Post\Media::VIDEO) {
+                               $body .= "\n[video]" . $media['url'] . "[/video]\n";
+                       }
+               }
+               return $body;
+       }
+
        /**
         * Create a post (status message or reshare)
         *
@@ -3409,7 +3436,7 @@ class Diaspora
                        $type = "reshare";
                } else {
                        $title = $item["title"];
-                       $body = $item["body"];
+                       $body = self::addAttachments($item);
 
                        // Fetch the title from an attached link - if there is one
                        if (empty($item["title"]) && DI::pConfig()->get($owner['uid'], 'system', 'attach_link_title')) {
@@ -3623,7 +3650,7 @@ class Diaspora
                        $thread_parent_item = Post::selectFirst(['guid', 'author-id', 'author-link', 'gravity'], ['uri' => $item['thr-parent'], 'uid' => $item['uid']]);
                }
 
-               $body = $item["body"];
+               $body = self::addAttachments($item);
 
                // The replied to autor mention is prepended for clarity if:
                // - Item replied isn't yours