From 72fc89d033070a72a01fd0b3f7a91d21d7467acb Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 4 Oct 2018 05:26:00 +0000 Subject: [PATCH] Simplified attachment handling --- src/Protocol/ActivityPub/Transmitter.php | 58 +++++++++--------------- 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index afd9582c2d..bb98371178 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -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));