Skip to content

Commit

Permalink
Group images of a message together and not all from one page
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyperghost committed Nov 12, 2024
1 parent 27e0dae commit e3cf21b
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion com.woltlab.wcf/templates/shared_bbcode_wsm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{if $media->isImage}
{if $thumbnailSize != 'original'}
{if !$removeLinks}
<a href="{$mediaLink}" data-caption="{$media->title}" class="embeddedAttachmentLink" data-fancybox="attachments">
<a href="{$mediaLink}" data-caption="{$media->title}" class="embeddedAttachmentLink" data-fancybox="message-{$activeMessageObjectType}-{$activeMessageID}">
{/if}
<img src="{$thumbnailLink}" alt="{$media->altText}" title="{$media->title}" width="{@$media->getThumbnailWidth($thumbnailSize)}" height="{@$media->getThumbnailHeight($thumbnailSize)}" loading="lazy">
{if !$removeLinks}
Expand Down
4 changes: 3 additions & 1 deletion ts/WoltLabSuite/Core/Component/Attachment/Entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {

type FileProcessorData = {
attachmentID: number;
messageObjectID: number | null;
};

function fileInitializationCompleted(element: HTMLElement, file: WoltlabCoreFileElement, editor: HTMLElement): void {
Expand Down Expand Up @@ -59,7 +60,8 @@ function fileInitializationCompleted(element: HTMLElement, file: WoltlabCoreFile
if (file.link !== undefined && file.filename !== undefined) {
const link = document.createElement("a");
link.href = file.link!;
link.dataset.fancybox = "uploadedAttachments";
link.dataset.fancybox =
"attachments" + (data.messageObjectID ? `-${(data as FileProcessorData).messageObjectID}` : "");
link.title = file.filename;
link.dataset.caption = file.filename;
link.textContent = file.filename;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ public function toHtmlElement(): ?string
{
return $this->getFile()?->toHtmlElement([
'attachmentID' => $this->attachmentID,
'messageObjectID' => $this->objectID,
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private function showImage(Attachment $attachment, string $outputType, array $at
if (!$hasParentLink && ($attachment->width > ATTACHMENT_THUMBNAIL_WIDTH || $attachment->height > ATTACHMENT_THUMBNAIL_HEIGHT)) {
$result = \sprintf(
<<<'HTML'
<a href="%s" data-caption="%s" data-fancybox="attachments" class="embeddedAttachmentLink %s" style="width: %s">
<a href="%s" data-caption="%s" data-fancybox="message-%s-%d" class="embeddedAttachmentLink %s" style="width: %s">
%s
<span class="embeddedAttachmentLinkEnlarge">
%s
Expand All @@ -102,6 +102,8 @@ private function showImage(Attachment $attachment, string $outputType, array $at
HTML,
$source,
$title,
MessageEmbeddedObjectManager::getInstance()->getActiveMessageObjectType(),
MessageEmbeddedObjectManager::getInstance()->getActiveMessageID(),
$class,
$width,
$imageElement,
Expand Down Expand Up @@ -159,9 +161,11 @@ private function showImageAsThumbnail(Attachment $attachment, string $alignment,

if (!$hasParentLink && $attachment->hasThumbnail() && $attachment->canDownload()) {
$result = \sprintf(
'<a href="%s" data-caption="%s" data-fancybox="attachments" class="embeddedAttachmentLink %s" style="width: %s">%s%s</a>',
'<a href="%s" data-caption="%s" data-fancybox="message-%s-%d" class="embeddedAttachmentLink %s" style="width: %s">%s%s</a>',
StringUtil::encodeHTML($attachment->getLink()),
StringUtil::encodeHTML($attachment->filename),
MessageEmbeddedObjectManager::getInstance()->getActiveMessageObjectType(),
MessageEmbeddedObjectManager::getInstance()->getActiveMessageID(),
$class,
$width,
$imageElement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public function getParsedTag(array $openingTag, $content, array $closingTag, BBC
'media' => $media->getLocalizedVersion(MessageEmbeddedObjectManager::getInstance()->getActiveMessageLanguageID()),
'thumbnailSize' => $thumbnailSize,
'width' => $width,
'activeMessageID' => MessageEmbeddedObjectManager::getInstance()->getActiveMessageID(),
'activeMessageObjectType' => MessageEmbeddedObjectManager::getInstance()->getActiveMessageObjectType(),
], true);
} elseif ($media->isVideo() || $media->isAudio()) {
return WCF::getTPL()->fetch('shared_bbcode_wsm', 'wcf', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public function getUploadResponse(File $file): array

return [
'attachmentID' => $attachment->attachmentID,
'messageObjectID' => $attachment->objectID,
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,26 @@ public function getActiveMessageLanguageID()
return $this->activeMessageLanguageID;
}

/**
* @since 6.2
*/
public function getActiveMessageObjectType(): ?string
{
if (!$this->activeMessageObjectTypeID) {
return null;
}

return ObjectTypeCache::getInstance()->getObjectType($this->activeMessageObjectTypeID)?->objectType;
}

/**
* @since 6.2
*/
public function getActiveMessageID(): ?int
{
return $this->activeMessageID;
}

/**
* Returns all embedded objects of a specific type.
*
Expand Down

0 comments on commit e3cf21b

Please sign in to comment.