Group images of a message together and not all from one page
authorCyperghost <olaf_schmitz_1@t-online.de>
Tue, 12 Nov 2024 10:35:23 +0000 (11:35 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Tue, 12 Nov 2024 10:35:23 +0000 (11:35 +0100)
com.woltlab.wcf/templates/shared_bbcode_wsm.tpl
ts/WoltLabSuite/Core/Component/Attachment/Entry.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Component/Attachment/Entry.js
wcfsetup/install/files/lib/data/attachment/Attachment.class.php
wcfsetup/install/files/lib/system/bbcode/AttachmentBBCode.class.php
wcfsetup/install/files/lib/system/bbcode/WoltLabSuiteMediaBBCode.class.php
wcfsetup/install/files/lib/system/file/processor/AttachmentFileProcessor.class.php
wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php

index 282c4b1dd2c5d0edb26e14e419c6ed4e70719b62..b87ac393c24b3cb8ef1973aa94afb539f768b1eb 100644 (file)
@@ -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}
index f495f7b1f3cd776e66cf728eabb652aa0ae0e383..edd8e504e23789848da2e266535e036dc2e0cfb5 100644 (file)
@@ -13,6 +13,7 @@ import {
 
 type FileProcessorData = {
   attachmentID: number;
+  messageObjectID: number | null;
 };
 
 function fileInitializationCompleted(element: HTMLElement, file: WoltlabCoreFileElement, editor: HTMLElement): void {
@@ -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;
index 79c9b707390e4054599c5bf4dce64dfd595c230c..1c3d039117cc5240e827af27c6eb9e9515122e0c 100644 (file)
@@ -43,7 +43,8 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Ui/Dropdown/Simple", "
             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.messageObjectID}` : "");
                 link.title = file.filename;
                 link.dataset.caption = file.filename;
                 link.textContent = file.filename;
index c66968aa2d1c8a2812f11e0072ec3a0c5ba3c7b1..1fcef76dcbb41bc330e1d126b7b24b2ecbfffb2d 100644 (file)
@@ -436,6 +436,7 @@ class Attachment extends DatabaseObject implements ILinkableObject, IRouteContro
     {
         return $this->getFile()?->toHtmlElement([
             'attachmentID' => $this->attachmentID,
+            'messageObjectID' => $this->objectID,
         ]);
     }
 
index 1a272f0e50cf0820905417ea038927fd181e9040..b3edb72fa3c1dee4e886dda7bd1c51472e50d8aa 100644 (file)
@@ -93,7 +93,7 @@ final class AttachmentBBCode extends AbstractBBCode
         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
@@ -102,6 +102,8 @@ final class AttachmentBBCode extends AbstractBBCode
                     HTML,
                 $source,
                 $title,
+                MessageEmbeddedObjectManager::getInstance()->getActiveMessageObjectType(),
+                MessageEmbeddedObjectManager::getInstance()->getActiveMessageID(),
                 $class,
                 $width,
                 $imageElement,
@@ -159,9 +161,11 @@ final class AttachmentBBCode extends AbstractBBCode
 
         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,
index cc6e78c02ce660b1386bcd7a36b77d2c60f25809..537d56d81d7d428a3733a0fb53c1d737877ee031 100644 (file)
@@ -78,6 +78,8 @@ final class WoltLabSuiteMediaBBCode extends AbstractBBCode
                         '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', [
index 40e7f8587f1d272ad7ac4e65546e0e45fa923560..13b1e97c6c9b7188fa238436e002fdefb106265d 100644 (file)
@@ -139,6 +139,7 @@ final class AttachmentFileProcessor extends AbstractFileProcessor
 
         return [
             'attachmentID' => $attachment->attachmentID,
+            'messageObjectID' => $attachment->objectID,
         ];
     }
 
index d3d012802c6a348dc1072f93504e8bce61563546..3a6cc76debd0015c48936002490525e8d7548aa7 100644 (file)
@@ -350,6 +350,26 @@ class MessageEmbeddedObjectManager extends SingletonFactory
         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.
      *