Merge pull request #11987 from annando/quoted-media

Fix attached media in quoted posts
This commit is contained in:
Hypolite Petovan 2022-10-11 19:54:44 -04:00 committed by GitHub
commit ec9059c395
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

@ -666,8 +666,16 @@ class Item
$shared_content .= '[h3]' . $item['title'] . "[/h3]\n"; $shared_content .= '[h3]' . $item['title'] . "[/h3]\n";
} }
$shared = BBCode::fetchShareAttributes($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 it is a reshared post then reformat it to avoid display problems with two share elements
if (Diaspora::isReshare($item['body'], false)) { if (Diaspora::isReshare($item['body'], false)) {
if (!empty($shared['guid']) && ($encaspulated_share = self::createSharedPostByGuid($shared['guid']))) {
$item['body'] = preg_replace("/\[share.*?\](.*)\[\/share\]/ism", $encaspulated_share, $item['body']);
}
$item['body'] = HTML::toBBCode(BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::ACTIVITYPUB)); $item['body'] = HTML::toBBCode(BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::ACTIVITYPUB));
} }

View file

@ -648,11 +648,13 @@ class Media
/** /**
* Add media attachments to the body * Add media attachments to the body
* *
* @param int $uriid * @param int $uriid
* @param string $body * @param string $body
* @param array $types
*
* @return string body * @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)) { if (empty($body)) {
$item = Post::selectFirst(['body'], ['uri-id' => $uriid]); $item = Post::selectFirst(['body'], ['uri-id' => $uriid]);
@ -665,7 +667,7 @@ class Media
$body = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", '', $body); $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'])) { if (Item::containsLink($body, $media['preview'] ?? $media['url'], $media['type'])) {
continue; continue;
} }