This fixes duplicated media in quoted posts
This commit is contained in:
parent
744d0fdde4
commit
eca52627c1
1 changed files with 20 additions and 11 deletions
|
@ -3006,6 +3006,7 @@ class Item
|
||||||
$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']);
|
||||||
|
$bbcode = $item['body'];
|
||||||
self::putInCache($item);
|
self::putInCache($item);
|
||||||
$item['body'] = $body;
|
$item['body'] = $body;
|
||||||
$s = $item["rendered-html"];
|
$s = $item["rendered-html"];
|
||||||
|
@ -3050,13 +3051,13 @@ class Item
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($shared_attachments)) {
|
if (!empty($shared_attachments)) {
|
||||||
$s = self::addVisualAttachments($shared_attachments, $item, $s, true);
|
$s = self::addVisualAttachments($shared_attachments, $item, $s, true, $bbcode);
|
||||||
$s = self::addLinkAttachment($shared_uri_id ?: $item['uri-id'], $shared_attachments, $body, $s, true, []);
|
$s = self::addLinkAttachment($shared_uri_id ?: $item['uri-id'], $shared_attachments, $body, $s, true, []);
|
||||||
$s = self::addNonVisualAttachments($shared_attachments, $item, $s, true);
|
$s = self::addNonVisualAttachments($shared_attachments, $item, $s, true);
|
||||||
$body = BBCode::removeSharedData($body);
|
$body = BBCode::removeSharedData($body);
|
||||||
}
|
}
|
||||||
|
|
||||||
$s = self::addVisualAttachments($attachments, $item, $s, false);
|
$s = self::addVisualAttachments($attachments, $item, $s, false, $bbcode);
|
||||||
$s = self::addLinkAttachment($item['uri-id'], $attachments, $body, $s, false, $shared_links);
|
$s = self::addLinkAttachment($item['uri-id'], $attachments, $body, $s, false, $shared_links);
|
||||||
$s = self::addNonVisualAttachments($attachments, $item, $s, false);
|
$s = self::addNonVisualAttachments($attachments, $item, $s, false);
|
||||||
$s = self::addQuestions($item, $s);
|
$s = self::addQuestions($item, $s);
|
||||||
|
@ -3165,12 +3166,13 @@ class Item
|
||||||
/**
|
/**
|
||||||
* Add visual attachments to the content
|
* Add visual attachments to the content
|
||||||
*
|
*
|
||||||
* @param array $attachments
|
* @param array $attachments
|
||||||
* @param array $item
|
* @param array $item
|
||||||
* @param string $content
|
* @param string $content
|
||||||
|
* @param string $body
|
||||||
* @return string modified content
|
* @return string modified content
|
||||||
*/
|
*/
|
||||||
private static function addVisualAttachments(array $attachments, array $item, string $content, bool $shared): string
|
private static function addVisualAttachments(array $attachments, array $item, string $content, bool $shared, string $body): string
|
||||||
{
|
{
|
||||||
DI::profiler()->startRecording('rendering');
|
DI::profiler()->startRecording('rendering');
|
||||||
$leading = '';
|
$leading = '';
|
||||||
|
@ -3182,15 +3184,18 @@ class Item
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($attachment['preview'])) {
|
if ($attachment['filetype'] == 'image') {
|
||||||
|
$preview_url = Post\Media::getPreviewUrlForId($attachment['id'], ($attachment['width'] > $attachment['height']) ? Proxy::SIZE_MEDIUM : Proxy::SIZE_LARGE);
|
||||||
|
} elseif (!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 = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($preview_url && (self::containsLink($item['body'], $preview_url) || self::containsLink($body, $preview_url))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (($attachment['filetype'] == 'video')) {
|
if (($attachment['filetype'] == 'video')) {
|
||||||
/// @todo Move the template to /content as well
|
/// @todo Move the template to /content as well
|
||||||
$media = Renderer::replaceMacros(Renderer::getMarkupTemplate('video_top.tpl'), [
|
$media = Renderer::replaceMacros(Renderer::getMarkupTemplate('video_top.tpl'), [
|
||||||
|
@ -3222,10 +3227,14 @@ class Item
|
||||||
$trailing .= $media;
|
$trailing .= $media;
|
||||||
}
|
}
|
||||||
} elseif ($attachment['filetype'] == 'image') {
|
} elseif ($attachment['filetype'] == 'image') {
|
||||||
|
$src_url = Post\Media::getUrlForId($attachment['id']);
|
||||||
|
if (self::containsLink($item['body'], $src_url) || self::containsLink($body, $src_url)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$media = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/image.tpl'), [
|
$media = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/image.tpl'), [
|
||||||
'$image' => [
|
'$image' => [
|
||||||
'src' => Post\Media::getUrlForId($attachment['id']),
|
'src' => $src_url,
|
||||||
'preview' => Post\Media::getPreviewUrlForId($attachment['id'], ($attachment['width'] > $attachment['height']) ? Proxy::SIZE_MEDIUM : Proxy::SIZE_LARGE),
|
'preview' => $preview_url,
|
||||||
'attachment' => $attachment,
|
'attachment' => $attachment,
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Reference in a new issue