From 0e82f64d71b598a1349ac22973148715f7182fdd Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 11 Oct 2022 21:39:28 +0000 Subject: [PATCH] Only attach images --- src/Content/Item.php | 2 +- src/Model/Post/Media.php | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Content/Item.php b/src/Content/Item.php index 1b07c5585..d1cdbc679 100644 --- a/src/Content/Item.php +++ b/src/Content/Item.php @@ -668,7 +668,7 @@ class Item $shared = BBCode::fetchShareAttributes($item['body']); - $item['body'] = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']); + $item['body'] = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body'], [Post\Media::IMAGE]); // If it is a reshared post then reformat it to avoid display problems with two share elements if (Diaspora::isReshare($item['body'], false)) { diff --git a/src/Model/Post/Media.php b/src/Model/Post/Media.php index 8fb10ddd8..ce00b205c 100644 --- a/src/Model/Post/Media.php +++ b/src/Model/Post/Media.php @@ -648,11 +648,13 @@ class Media /** * Add media attachments to the body * - * @param int $uriid + * @param int $uriid * @param string $body + * @param array $types + * * @return string body */ - public static function addAttachmentsToBody(int $uriid, string $body = ''): string + public static function addAttachmentsToBody(int $uriid, string $body = '', array $types = [self::IMAGE, self::AUDIO, self::VIDEO]): string { if (empty($body)) { $item = Post::selectFirst(['body'], ['uri-id' => $uriid]); @@ -665,7 +667,7 @@ class Media $body = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", '', $body); - foreach (self::getByURIId($uriid, [self::IMAGE, self::AUDIO, self::VIDEO]) as $media) { + foreach (self::getByURIId($uriid, $types) as $media) { if (Item::containsLink($body, $media['preview'] ?? $media['url'], $media['type'])) { continue; }