Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions com.woltlab.wcf/templates/attachments.tpl
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{if $attachmentList && $attachmentList->getGroupedObjects($objectID)|count}
{if !$attachments|isset && $attachmentList && $attachmentList->getGroupedObjects($objectID)|count}
{assign var='attachments' value=$attachmentList->getGroupedObjects($objectID)}
{/if}
{if !$attachments|empty}
{hascontent}
<section class="section attachmentThumbnailList">
<h2 class="messageSectionTitle">{lang}wcf.attachment.images{/lang}</h2>

<ul class="inlineList">
{content}
{foreach from=$attachmentList->getGroupedObjects($objectID) item=attachment}
{foreach from=$attachments item=attachment}
{if $attachment->showAsImage() && !$attachment->isEmbedded()}
<li class="attachmentThumbnail" data-attachment-id="{$attachment->attachmentID}">
<a href="{$attachment->getLink()}"{if $attachment->canDownload()} data-type="image" data-fancybox="message-{$attachmentList->getObjectTypeName()}-{$objectID}" data-caption="{$attachment->filename}" aria-label="{lang}wcf.attachment.image.title{/lang}"{/if}>
<a href="{$attachment->getLink()}"{if $attachment->canDownload()} data-type="image" data-fancybox="{$attachment->getFancyboxTag()}" data-caption="{$attachment->filename}" aria-label="{lang}wcf.attachment.image.title{/lang}"{/if}>
<div class="attachmentThumbnailContainer">
<span class="attachmentThumbnailImage">
{if $attachment->hasThumbnail()}
Expand Down Expand Up @@ -66,7 +69,7 @@

<div class="messageAttachmentList">
{content}
{foreach from=$attachmentList->getGroupedObjects($objectID) item=attachment}
{foreach from=$attachments item=attachment}
{if $attachment->showAsFile() && !$attachment->isEmbedded()}
<a href="{$attachment->getLink()}" class="messageAttachment jsTooltip" title="{lang}wcf.attachment.file.title{/lang}">
<span class="messageAttachmentIcon">
Expand Down
11 changes: 7 additions & 4 deletions com.woltlab.wcf/templates/entryAttachments.tpl
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{if $attachmentList && $attachmentList->getGroupedObjects($objectID)|count}
{if !$attachments|isset && $attachmentList && $attachmentList->getGroupedObjects($objectID)|count}
{assign var='attachments' value=$attachmentList->getGroupedObjects($objectID)}
{/if}
{if !$attachments|empty}
{hascontent}
<section class="entry__attachments__thumbnails">
<h2 class="entry__attachments__title">{lang}wcf.attachment.images{/lang}</h2>

<ul class="inlineList">
{content}
{foreach from=$attachmentList->getGroupedObjects($objectID) item=attachment}
{foreach from=$attachments item=attachment}
{if $attachment->showAsImage() && !$attachment->isEmbedded()}
<li class="attachmentThumbnail" data-attachment-id="{$attachment->attachmentID}">
<a href="{$attachment->getLink()}"{if $attachment->canDownload()} data-type="image" data-fancybox="message-{$attachmentList->getObjectTypeName()}-{$objectID}" data-caption="{$attachment->filename}" aria-label="{lang}wcf.attachment.image.title{/lang}"{/if}>
<a href="{$attachment->getLink()}"{if $attachment->canDownload()} data-type="image" data-fancybox="{$attachment->getFancyboxTag()}" data-caption="{$attachment->filename}" aria-label="{lang}wcf.attachment.image.title{/lang}"{/if}>
<div class="attachmentThumbnailContainer">
<span class="attachmentThumbnailImage">
{if $attachment->hasThumbnail()}
Expand Down Expand Up @@ -66,7 +69,7 @@

<div class="messageAttachmentList">
{content}
{foreach from=$attachmentList->getGroupedObjects($objectID) item=attachment}
{foreach from=$attachments item=attachment}
{if $attachment->showAsFile() && !$attachment->isEmbedded()}
<a href="{$attachment->getLink()}" class="messageAttachment jsTooltip" title="{lang}wcf.attachment.file.title{/lang}">
<span class="messageAttachmentIcon">
Expand Down
12 changes: 12 additions & 0 deletions wcfsetup/install/files/lib/data/attachment/Attachment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,4 +538,16 @@ public function getImageData(?int $minWidth = null, ?int $minHeight = null): ?Im

return new ImageData($this->getLink(), $this->width, $this->height);
}

/**
* @return string
*/
public function getFancyboxTag(): string
{
return \sprintf(
'attachments-%s-%s',
ObjectTypeCache::getInstance()->getObjectType($this->objectTypeID)->objectType,
$this->objectID
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,18 @@
/**
* Represents a grouped list of attachments.
*
* @author Marcel Werk
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @author Marcel Werk
* @copyright 2001-2026 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*/
class GroupedAttachmentList extends AttachmentList
{
/**
* grouped objects
* @var array<int, array<int, Attachment>>
*/
public $groupedObjects = [];
public array $groupedObjects = [];

/**
* object type
* @var ObjectType
*/
protected $objectType;
protected ObjectType $objectType;

/**
* @inheritDoc
Expand All @@ -36,19 +31,19 @@ class GroupedAttachmentList extends AttachmentList
*/
public $sqlOrderBy = 'attachment.showOrder';

/**
* Creates a new GroupedAttachmentList object.
*
* @param string $objectType
*/
public function __construct($objectType)
public function __construct(string $objectType)
{
parent::__construct();

$this->objectType = ObjectTypeCache::getInstance()->getObjectTypeByName(
$objectTypeObj = ObjectTypeCache::getInstance()->getObjectTypeByName(
'com.woltlab.wcf.attachment.objectType',
$objectType
);
if ($objectType === null) {
throw new \BadMethodCallException("unknown attachment object type '{$objectType}'");
}

$this->objectType = $objectTypeObj;
$this->getConditionBuilder()->add('attachment.objectTypeID = ?', [$this->objectType->objectTypeID]);

$this->getConditionBuilder()->add(
Expand All @@ -70,10 +65,8 @@ public function __construct($objectType)
);
}

/**
* @inheritDoc
*/
public function readObjects()
#[\Override]
public function readObjects(): void
{
parent::readObjects();

Expand All @@ -91,22 +84,20 @@ public function readObjects()
* Sets the permissions for attachment access.
*
* @param array<string, bool> $permissions
* @return void
*/
public function setPermissions(array $permissions)
public function setPermissions(array $permissions): void
{
foreach ($this->objects as $attachment) {
$attachment->setPermissions($permissions);
}
}

/**
* Returns the objects of the list.
* Returns the attachments associated with the given objectID.
*
* @param int $objectID
* @return Attachment[]
* @return Attachment[]
*/
public function getGroupedObjects($objectID)
public function getGroupedObjects(int $objectID): array
{
if (isset($this->groupedObjects[$objectID])) {
return $this->groupedObjects[$objectID];
Expand Down