Merge pull request #12174 from annando/duplicate-media

Avoid duplicate media elements
This commit is contained in:
Hypolite Petovan 2022-11-13 19:07:08 -05:00 committed by GitHub
commit e6db31a462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -2995,14 +2995,14 @@ class Item
if (!empty($shared_item['uri-id'])) { if (!empty($shared_item['uri-id'])) {
$shared_uri_id = $shared_item['uri-id']; $shared_uri_id = $shared_item['uri-id'];
$shared_links[] = strtolower($shared_item['plink']); $shared_links[] = strtolower($shared_item['plink']);
$shared_attachments = Post\Media::splitAttachments($shared_uri_id, $shared_item['guid'], [], $shared_item['has-media']); $shared_attachments = Post\Media::splitAttachments($shared_uri_id, [], $shared_item['has-media']);
$shared_links = array_merge($shared_links, array_column($shared_attachments['visual'], 'url')); $shared_links = array_merge($shared_links, array_column($shared_attachments['visual'], 'url'));
$shared_links = array_merge($shared_links, array_column($shared_attachments['link'], 'url')); $shared_links = array_merge($shared_links, array_column($shared_attachments['link'], 'url'));
$shared_links = array_merge($shared_links, array_column($shared_attachments['additional'], 'url')); $shared_links = array_merge($shared_links, array_column($shared_attachments['additional'], 'url'));
$item['body'] = self::replaceVisualAttachments($shared_attachments, $item['body']); $item['body'] = self::replaceVisualAttachments($shared_attachments, $item['body']);
} }
$attachments = Post\Media::splitAttachments($item['uri-id'], $item['guid'] ?? '', $shared_links, $item['has-media'] ?? false); $attachments = Post\Media::splitAttachments($item['uri-id'], $shared_links, $item['has-media'] ?? false);
$item['body'] = self::replaceVisualAttachments($attachments, $item['body'] ?? ''); $item['body'] = self::replaceVisualAttachments($attachments, $item['body'] ?? '');
$item['body'] = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", "\n", $item['body']); $item['body'] = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", "\n", $item['body']);
@ -3184,6 +3184,9 @@ class Item
if (!empty($attachment['preview'])) { if (!empty($attachment['preview'])) {
$preview_url = Post\Media::getPreviewUrlForId($attachment['id'], Proxy::SIZE_LARGE); $preview_url = Post\Media::getPreviewUrlForId($attachment['id'], Proxy::SIZE_LARGE);
if (self::containsLink($item['body'], $preview_url)) {
continue;
}
} else { } else {
$preview_url = ''; $preview_url = '';
} }

View File

@ -642,12 +642,11 @@ class Media
* Split the attachment media in the three segments "visual", "link" and "additional" * Split the attachment media in the three segments "visual", "link" and "additional"
* *
* @param int $uri_id URI id * @param int $uri_id URI id
* @param string $guid GUID
* @param array $links list of links that shouldn't be added * @param array $links list of links that shouldn't be added
* @param bool $has_media * @param bool $has_media
* @return array attachments * @return array attachments
*/ */
public static function splitAttachments(int $uri_id, string $guid = '', array $links = [], bool $has_media = true): array public static function splitAttachments(int $uri_id, array $links = [], bool $has_media = true): array
{ {
$attachments = ['visual' => [], 'link' => [], 'additional' => []]; $attachments = ['visual' => [], 'link' => [], 'additional' => []];