Forked from guedressel/font-awesome-mime-type-icons.php
Last active
October 7, 2020 12:39
-
-
Save fyrye/d0b0d1e8672e255beec225d458848b36 to your computer and use it in GitHub Desktop.
Font Awesome File Icons: Mapping MIME Types to correct icon classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get font awesome file icon class for specific MIME Type | |
* @see https://gist.github.com/guedressel/0daa170c0fde65ce5551 | |
* @param string|null $mime_type | |
* @return string | |
*/ | |
function font_awesome_file_icon_class(?string $mime_type): string | |
{ | |
// List of official MIME Types: http://www.iana.org/assignments/media-types/media-types.xhtml | |
static $font_awesome_file_icon_classes = [ | |
// Images | |
'image' => 'fa-file-image', | |
// Audio | |
'audio' => 'fa-file-audio', | |
// Video | |
'video' => 'fa-file-video', | |
// Documents | |
'application/pdf' => 'fa-file-pdf', | |
'application/msword' => 'fa-file-word', | |
'application/vnd.ms-word' => 'fa-file-word', | |
'application/vnd.oasis.opendocument.text' => 'fa-file-word', | |
'application/vnd.openxmlformats-officedocument.wordprocessingml' => 'fa-file-word', | |
'application/vnd.ms-excel' => 'fa-file-excel', | |
'application/vnd.openxmlformats-officedocument.spreadsheetml' => 'fa-file-excel', | |
'application/vnd.oasis.opendocument.spreadsheet' => 'fa-file-excel', | |
'application/vnd.ms-powerpoint' => 'fa-file-powerpoint', | |
'application/vnd.openxmlformats-officedocument.presentationml' => 'ffa-file-powerpoint', | |
'application/vnd.oasis.opendocument.presentation' => 'fa-file-powerpoint', | |
'text/plain' => 'fa-file-alt', | |
'text/html' => 'fa-file-code', | |
'application/json' => 'fa-file-code', | |
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'fa-file-word', | |
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'fa-file-excel', | |
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'fa-file-powerpoint', | |
// Archives | |
'application/gzip' => 'fa-file-archive', | |
'application/zip' => 'fa-file-archive', | |
'application/x-zip-compressed' => 'fa-file-archive', | |
// Misc | |
'application/octet-stream' => 'fa-file-archive', | |
]; | |
return $font_awesome_file_icon_classes[$mime_type] ?? | |
$font_awesome_file_icon_classes[\substr($mime_type, 0, \strpos($mime_type, '/') ? : \strlen($mime_type))] ?? | |
'fa-file'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to php >= 7.0 with type-hinting, null coalescing operator
??
andsubstr
to retrieve value.