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
12 changes: 12 additions & 0 deletions com.woltlab.wcf/templates/shared_bbcode_wsm_file.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<a href="{$media->getLink()}" class="messageAttachment jsTooltip" title="{lang}wcf.media.file.title{/lang}">
<span class="messageAttachmentIcon">
<span class="messageAttachmentIconDefault">
{icon size=32 name=$media->getIconName()}
</span>
<span class="messageAttachmentIconDownload">
{icon size=32 name='download'}
</span>
</span>
<span class="messageAttachmentFilename">{$media->getTitle()}</span>
<span class="messageAttachmentMeta">{lang}wcf.media.file.info{/lang}</span>
</a>
15 changes: 15 additions & 0 deletions wcfsetup/install/files/lib/data/media/Media.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use wcf\system\request\IRouteController;
use wcf\system\request\LinkHandler;
use wcf\system\WCF;
use wcf\util\FileUtil;

/**
* Represents a media file.
Expand Down Expand Up @@ -183,6 +184,20 @@ public function getTitle(): string
return $this->filename;
}

/**
* Returns the icon name for this media file based on its filename.
*
* @since 6.3
*/
public function getIconName(): string
{
if ($iconName = FileUtil::getIconNameByFilename($this->filename)) {
return 'file-' . $iconName;
}

return 'file';
}

/**
* Returns the i18n media data grouped by language id for all language.
*
Expand Down
10 changes: 1 addition & 9 deletions wcfsetup/install/files/lib/data/media/ViewableMedia.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use wcf\data\user\UserProfile;
use wcf\system\cache\runtime\UserProfileRuntimeCache;
use wcf\system\style\FontAwesomeIcon;
use wcf\util\FileUtil;
use wcf\util\StringUtil;

/**
Expand Down Expand Up @@ -182,14 +181,7 @@ public function getElementTag(int $size)
</span>';
}

$icon = FileUtil::getIconNameByFilename($this->filename);
if ($icon) {
$icon = "file-{$icon}";
} else {
$icon = 'file';
}

return FontAwesomeIcon::fromValues($icon, false)->toHtml($size);
return FontAwesomeIcon::fromValues($this->getIconName(), false)->toHtml($size);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public function getParsedTag(array $openingTag, string $content, array $closingT

if ($parser->getOutputType() == 'text/html') {
$float = (!empty($openingTag['attributes'][2])) ? $openingTag['attributes'][2] : 'none';
$localizedMedia = MessageEmbeddedObjectManager::getInstance()->getActiveMessageLanguageID()
? $media->getLocalizedVersion(MessageEmbeddedObjectManager::getInstance()->getActiveMessageLanguageID())
: $media;

if ($media->isImage) {
$thumbnailSize = (!empty($openingTag['attributes'][1])) ? $openingTag['attributes'][1] : 'original';
Expand All @@ -72,7 +75,7 @@ public function getParsedTag(array $openingTag, string $content, array $closingT
$thumbnailSize
) : '',
'float' => $float,
'media' => $media->getLocalizedVersion(MessageEmbeddedObjectManager::getInstance()->getActiveMessageLanguageID()),
'media' => $localizedMedia,
'thumbnailSize' => $thumbnailSize,
'width' => $width,
'activeMessageID' => MessageEmbeddedObjectManager::getInstance()->getActiveMessageID(),
Expand All @@ -83,12 +86,14 @@ public function getParsedTag(array $openingTag, string $content, array $closingT
'mediaLink' => $media->getLink(),
'removeLinks' => $removeLinks,
'float' => $float,
'media' => $media->getLocalizedVersion(MessageEmbeddedObjectManager::getInstance()->getActiveMessageLanguageID()),
'media' => $localizedMedia,
'width' => 'auto',
]);
} else {
return WCF::getTPL()->render('wcf', 'shared_bbcode_wsm_file', [
'media' => $localizedMedia,
]);
}

return StringUtil::getAnchorTag($media->getLink(), $media->getTitle());
} elseif ($parser->getOutputType() == 'text/simplified-html') {
return StringUtil::getAnchorTag($media->getLink(), $media->getTitle());
}
Expand Down
2 changes: 1 addition & 1 deletion wcfsetup/install/files/lib/util/FileUtil.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ public static function getIconNameByFilename(string $filename): string

$lastDotPosition = \strrpos($filename, '.');
if ($lastDotPosition !== false) {
$extension = \substr($filename, $lastDotPosition + 1);
$extension = \strtolower(\substr($filename, $lastDotPosition + 1));
if (isset($mapping[$extension])) {
return $mapping[$extension];
}
Expand Down
1 change: 1 addition & 0 deletions wcfsetup/install/files/style/ui/attachment.scss
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ html[data-color-scheme="dark"] {
"icon filename"
"icon meta";
grid-template-columns: 32px auto;
max-width: 300px;
padding: 8px;
row-gap: 1px;
user-select: none;
Expand Down
2 changes: 2 additions & 0 deletions wcfsetup/install/lang/de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4285,6 +4285,8 @@ Erlaubte Dateiendungen: gif, jpg, jpeg, png, webp]]></item>
<item name="wcf.media.setCategory"><![CDATA[Kategorie bearbeiten]]></item>
<item name="wcf.media.downloads"><![CDATA[Downloads]]></item>
<item name="wcf.media.lastDownloadTime"><![CDATA[Letzter Download]]></item>
<item name="wcf.media.file.info"><![CDATA[{$media->filesize|filesize} – {plural value=$media->downloads 1="1 Download" other="# Downloads"}]]></item>
<item name="wcf.media.file.title"><![CDATA[Datei „{$media->filename}“ herunterladen]]></item>
</category>
<category name="wcf.message">
<item name="wcf.message.autosave.prompt"><![CDATA[Gespeicherten Entwurf wiederherstellen?]]></item>
Expand Down
2 changes: 2 additions & 0 deletions wcfsetup/install/lang/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4231,6 +4231,8 @@ Allowed extensions: gif, jpg, jpeg, png, webp]]></item>
<item name="wcf.media.setCategory"><![CDATA[Edit Category]]></item>
<item name="wcf.media.downloads"><![CDATA[Downloads]]></item>
<item name="wcf.media.lastDownloadTime"><![CDATA[Last Download]]></item>
<item name="wcf.media.file.info"><![CDATA[{$media->filesize|filesize} – {plural value=$media->downloads 1="1 Download" other="# Downloads"}]]></item>
<item name="wcf.media.file.title"><![CDATA[Download File “{$media->filename}”]]></item>
</category>
<category name="wcf.message">
<item name="wcf.message.autosave.prompt"><![CDATA[Restore saved draft?]]></item>
Expand Down
Loading