<div class="messageTabMenuContent" id="attachments_{if $wysiwygSelector|isset}{$wysiwygSelector}{else}text{/if}">
- {@$attachmentHandler->getHtmlElement()}
+ {unsafe:$attachmentHandler->getHtmlElement()}
<dl class="wide">
<dt></dt>
<dd>
- <div data-max-size="{@$attachmentHandler->getMaxSize()}"></div>
+ <div data-max-size="{$attachmentHandler->getMaxSize()}"></div>
<small>{lang}wcf.attachment.upload.limits{/lang}</small>
</dd>
</dl>
+ {foreach from=$attachmentHandler->getAttachmentList() item=attachment}
+ {unsafe:$attachment->toHtmlElement()}
+ {/foreach}
+
<script data-relocate="true">
require(["WoltLabSuite/Core/Component/Attachment/List"], ({ setup }) => {
setup("{if $wysiwygSelector|isset}{$wysiwygSelector}{else}text{/if}");
use wcf\data\ILinkableObject;
use wcf\data\IThumbnailFile;
use wcf\data\file\File;
+use wcf\data\file\thumbnail\FileThumbnailList;
use wcf\data\object\type\ObjectTypeCache;
use wcf\system\request\IRouteController;
use wcf\system\request\LinkHandler;
if (!isset($this->file)) {
$this->file = new File($fileID);
+
+ $thumbnailList = new FileThumbnailList();
+ $thumbnailList->getConditionBuilder()->add("fileID = ?", [$this->file->fileID]);
+ $thumbnailList->readObjects();
+ foreach ($thumbnailList as $thumbnail) {
+ $this->file->addThumbnail($thumbnail);
+ }
}
return $this->file;
};
}
+ public function toHtmlElement(): ?string
+ {
+ return $this->getFile()?->toHtmlElement();
+ }
+
public static function findByFileID(int $fileID): ?Attachment
{
$sql = "SELECT *
*/
public $className = Attachment::class;
+ public $enableFileLoading = true;
+
#[\Override]
public function readObjects()
{
parent::readObjects();
+ if ($this->enableFileLoading) {
+ $this->loadFiles();
+ }
+ }
+
+ private function loadFiles(): void
+ {
$fileIDs = [];
foreach ($this->objects as $attachment) {
if ($attachment->fileID) {
use wcf\system\file\processor\FileProcessor;
use wcf\system\file\processor\IFileProcessor;
use wcf\system\request\LinkHandler;
+use wcf\util\StringUtil;
/**
* @author Alexander Ebert
{
return $this->thumbnails[$identifier] ?? null;
}
+
+ public function toHtmlElement(): string
+ {
+ $thumbnails = [];
+ foreach ($this->thumbnails as $thumbnail) {
+ $thumbnails[] = [
+ 'identifier' => $thumbnail->identifier,
+ 'link' => $thumbnail->getLink(),
+ ];
+ }
+
+ // TODO: Icon and preview url is missing.
+ return \sprintf(
+ <<<'EOT'
+ <woltlab-core-file
+ file-id="%d"
+ data-filename="%s"
+ data-mime-type="%s"
+ data-thumbnails="%s"
+ ></woltlab-core-file>
+ EOT,
+ $this->fileID,
+ StringUtil::encodeHTML($this->filename),
+ StringUtil::encodeHTML($this->mimeType),
+ StringUtil::encodeHTML(\json_encode($thumbnails)),
+ );
+ }
}