{foreach from=$attachmentList->getGroupedObjects($objectID) item=attachment}
{if $attachment->showAsFile() && !$attachment->isEmbedded()}
<li class="box32" data-attachment-id="{@$attachment->attachmentID}">
- <a href="{link controller='Attachment' object=$attachment}{/link}"><span class="icon icon32 fa-paperclip"></span></a>
+ <a href="{link controller='Attachment' object=$attachment}{/link}"><span class="icon icon32 fa-{@$attachment->getIconName()}"></span></a>
<div>
<p><a href="{link controller='Attachment' object=$attachment}{/link}">{$attachment->filename}</a></p>
{if $attachment->tinyThumbnailType}
<img src="{link controller='Attachment' object=$attachment}tiny=1{/link}" alt="" class="attachmentTinyThumbnail">
{else}
- <span class="icon icon64 fa-paperclip"></span>
+ <span class="icon icon64 fa-{@$attachment->getIconName()}"></span>
{/if}
<div>
{foreach from=$objects item=attachment}
<tr class="jsAttachmentRow">
<td class="columnIcon">
- <span class="icon icon16 fa-times jsDeleteButton jsTooltip pointer" title="{lang}wcf.global.button.delete{/lang}" data-object-id="{@$attachment->attachmentID}" data-confirm-message="{lang}wcf.attachment.delete.sure{/lang}"></span>
+ <span class="icon icon24 fa-times jsDeleteButton jsTooltip pointer" title="{lang}wcf.global.button.delete{/lang}" data-object-id="{@$attachment->attachmentID}" data-confirm-message="{lang}wcf.attachment.delete.sure{/lang}"></span>
{event name='rowButtons'}
</td>
{if $attachment->tinyThumbnailType}
<img src="{link controller='Attachment' id=$attachment->attachmentID}tiny=1{/link}" class="attachmentTinyThumbnail" alt="">
{else}
- <span class="icon icon64 fa-paperclip"></span>
+ <span class="icon icon64 fa-{@$attachment->getIconName()}"></span>
{/if}
</a>
}
// show file icon
else {
- $li.children('.fa-spinner').removeClass('fa-spinner').addClass('fa-paperclip');
+ $li.children('.fa-spinner').removeClass('fa-spinner').addClass('fa-' + attachmentData.iconName);
}
// update attachment link
return !$this->showAsImage();
}
+ /**
+ * Returns icon name for this attachment.
+ *
+ * @return string
+ */
+ public function getIconName() {
+ if ($iconName = FileUtil::getIconNameByFilename($this->filename)) {
+ return 'file-' . $iconName . '-o';
+ }
+
+ return 'paperclip';
+ }
+
/**
* Returns the storage path.
*
'thumbnailURL' => $attachment->thumbnailType ? LinkHandler::getInstance()->getLink('Attachment', ['object' => $attachment], 'thumbnail=1') : '',
'url' => LinkHandler::getInstance()->getLink('Attachment', ['object' => $attachment]),
'height' => $attachment->height,
- 'width' => $attachment->width
+ 'width' => $attachment->width,
+ 'iconName' => $attachment->getIconName()
];
}
}
use wcf\data\user\UserProfile;
use wcf\data\DatabaseObjectDecorator;
use wcf\system\cache\runtime\UserProfileRuntimeCache;
+use wcf\util\FileUtil;
use wcf\util\StringUtil;
/**
}
}
- return '<span class="icon icon'.$size.' fa-file-o"></span>';
+ $icon = FileUtil::getIconNameByFilename($this->filename);
+ return '<span class="icon icon' . $size . ' fa-file' . ($icon ? '-' . $icon : '') . '-o"></span>';
}
/**
return self::getMemoryLimit() == -1 || self::getMemoryLimit() > (memory_get_usage() + $neededMemory);
}
+ /**
+ * Returns icon name for given filename.
+ *
+ * @param string $filename
+ * @return string
+ */
+ public static function getIconNameByFilename($filename) {
+ static $mapping = [
+ // archive
+ 'zip' => 'archive', 'rar' => 'archive', 'tar' => 'archive', 'gz' => 'archive',
+ // audio
+ 'mp3' => 'audio', 'ogg' => 'audio', 'wav' => 'audio',
+ // code
+ 'php' => 'code', 'html' => 'code', 'htm' => 'code', 'tpl' => 'code', 'js' => 'code',
+ // excel
+ 'xls' => 'excel', 'ods' => 'excel', 'xlsx' => 'excel',
+ // image
+ 'gif' => 'image', 'jpg' => 'image', 'jpeg' => 'image', 'png' => 'image', 'bmp' => 'image',
+ // video
+ 'avi' => 'video', 'wmv' => 'video', 'mov' => 'video', 'mp4' => 'video', 'mpg' => 'video', 'mpeg' => 'video', 'flv' => 'video',
+ // pdf
+ 'pdf' => 'pdf',
+ // powerpoint
+ 'ppt' => 'powerpoint', 'pptx' => 'powerpoint',
+ // text
+ 'txt' => 'text',
+ // word
+ 'doc' => 'word', 'docx' => 'word', 'odt' => 'word'
+ ];
+
+ $lastDotPosition = strrpos($filename, '.');
+ if ($lastDotPosition !== false) {
+ $extension = substr($filename, $lastDotPosition + 1);
+ if (isset($mapping[$extension])) {
+ return $mapping[$extension];
+ }
+ }
+
+ return '';
+ }
+
/**
* Forbid creation of FileUtil objects.
*/