]> git.mxchange.org Git - friendica.git/commitdiff
Simplified attachment handling
authorMichael <heluecht@pirati.ca>
Thu, 4 Oct 2018 05:26:00 +0000 (05:26 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 4 Oct 2018 05:26:00 +0000 (05:26 +0000)
src/Protocol/ActivityPub/Transmitter.php

index afd9582c2d93017c8ef04e64fefa2103e4a33ceb..bb983711787ac97fac0e268c38fdfb07668cb0ee 100644 (file)
@@ -604,47 +604,14 @@ class Transmitter
         * @brief Adds attachment data to the JSON document
         *
         * @param array $item Data of the item that is to be posted
+        * @param text $type Object type
         * @return attachment array
         */
 
-       private static function createAttachmentList($item)
+       private static function createAttachmentList($item, $type)
        {
                $attachments = [];
 
-               $siteinfo = BBCode::getAttachedData($item['body']);
-
-               switch ($siteinfo['type']) {
-                       case 'photo':
-                               if (!empty($siteinfo['image'])) {
-                                       $imgdata = Image::getInfoFromURL($siteinfo['image']);
-                                       if ($imgdata) {
-                                               $attachments[] = ['type' => 'Document',
-                                                               'mediaType' => $imgdata['mime'],
-                                                               'url' => $siteinfo['image'],
-                                                               'name' => null];
-                                       }
-                               }
-                               break;
-                       case 'video':
-                               $attachments[] = ['type' => 'Document',
-                                               'mediaType' => 'text/html; charset=UTF-8',
-                                               'url' => $siteinfo['url'],
-                                               'name' => defaults($siteinfo, 'title', $siteinfo['url'])];
-                               break;
-                       default:
-                               break;
-               }
-
-               if (!Config::get('system', 'ostatus_not_attach_preview') && ($siteinfo['type'] != 'photo') && isset($siteinfo['image'])) {
-                       $imgdata = Image::getInfoFromURL($siteinfo['image']);
-                       if ($imgdata) {
-                               $attachments[] = ['type' => 'Document',
-                                               'mediaType' => $imgdata['mime'],
-                                               'url' => $siteinfo['image'],
-                                               'name' => null];
-                       }
-               }
-
                $arr = explode('[/attach],', $item['attach']);
                if (count($arr)) {
                        foreach ($arr as $r) {
@@ -665,6 +632,25 @@ class Transmitter
                        }
                }
 
+               if ($type != 'Note') {
+                       return $attachments;
+               }
+
+               /// @todo Replace this with a function that takes all pictures from the post
+               $siteinfo = BBCode::getAttachedData($item['body']);
+
+               if (!empty($siteinfo['image']) &&
+                       (($siteinfo['type'] == 'photo') ||
+                       !Config::get('system', 'ostatus_not_attach_preview'))) {
+                               $imgdata = Image::getInfoFromURL($siteinfo['image']);
+                               if ($imgdata) {
+                                       $attachments[] = ['type' => 'Document',
+                                                       'mediaType' => $imgdata['mime'],
+                                                       'url' => $siteinfo['image'],
+                                                       'name' => null];
+                               }
+               }
+
                return $attachments;
        }
 
@@ -753,7 +739,7 @@ class Transmitter
                        $data['diaspora:comment'] = $item['signed_text'];
                }
 
-               $data['attachment'] = self::createAttachmentList($item);
+               $data['attachment'] = self::createAttachmentList($item, $type);
                $data['tag'] = self::createTagList($item);
                $data = array_merge($data, self::createPermissionBlockForItem($item));