forked from joomla/super-powers
Update 2024-09-18 04:20:10
This commit is contained in:
parent
b4fe424113
commit
1d2430e698
@ -12,12 +12,20 @@
|
|||||||
```uml
|
```uml
|
||||||
@startuml
|
@startuml
|
||||||
abstract MimeHelper #Orange {
|
abstract MimeHelper #Orange {
|
||||||
|
# static $fileExtensionToMimeType
|
||||||
|
+ {static} getFileExtensions(string $target = null, boolean $sorted = false) : array
|
||||||
+ {static} extension(string $file) : string
|
+ {static} extension(string $file) : string
|
||||||
+ {static} mimeType(string $file) : string
|
+ {static} mimeType(string $file) : string
|
||||||
# {static} mimeTypeFilename(string $file) : string
|
# {static} mimeTypeFilename(string $file) : string
|
||||||
+ {static} getFileExtensions(string $target = null, boolean $sorted = false) : array
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
note right of MimeHelper::getFileExtensions
|
||||||
|
Get the file extensions
|
||||||
|
|
||||||
|
since: 5.0.3
|
||||||
|
return: array
|
||||||
|
end note
|
||||||
|
|
||||||
note right of MimeHelper::extension
|
note right of MimeHelper::extension
|
||||||
Get the file extension from a full path OR file name.
|
Get the file extension from a full path OR file name.
|
||||||
|
|
||||||
@ -39,12 +47,6 @@ note right of MimeHelper::mimeTypeFilename
|
|||||||
return: string
|
return: string
|
||||||
end note
|
end note
|
||||||
|
|
||||||
note right of MimeHelper::getFileExtensions
|
|
||||||
Get the file extensions
|
|
||||||
|
|
||||||
return: array
|
|
||||||
end note
|
|
||||||
|
|
||||||
@enduml
|
@enduml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -25,8 +25,9 @@ abstract class MimeHelper
|
|||||||
* http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
|
* http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
|
* @since 5.0.3
|
||||||
*/
|
*/
|
||||||
protected static $fileExtensionToMimeType = array(
|
protected static $fileExtensionToMimeType = [
|
||||||
'123' => 'application/vnd.lotus-1-2-3',
|
'123' => 'application/vnd.lotus-1-2-3',
|
||||||
'3dml' => 'text/vnd.in3d.3dml',
|
'3dml' => 'text/vnd.in3d.3dml',
|
||||||
'3ds' => 'image/x-3ds',
|
'3ds' => 'image/x-3ds',
|
||||||
@ -72,6 +73,7 @@ abstract class MimeHelper
|
|||||||
'atx' => 'application/vnd.antix.game-component',
|
'atx' => 'application/vnd.antix.game-component',
|
||||||
'au' => 'audio/basic',
|
'au' => 'audio/basic',
|
||||||
'avi' => 'video/x-msvideo',
|
'avi' => 'video/x-msvideo',
|
||||||
|
'avif' => 'image/avif',
|
||||||
'aw' => 'application/applixware',
|
'aw' => 'application/applixware',
|
||||||
'azf' => 'application/vnd.airzip.filesecure.azf',
|
'azf' => 'application/vnd.airzip.filesecure.azf',
|
||||||
'azs' => 'application/vnd.airzip.filesecure.azs',
|
'azs' => 'application/vnd.airzip.filesecure.azs',
|
||||||
@ -298,6 +300,7 @@ abstract class MimeHelper
|
|||||||
'geo' => 'application/vnd.dynageo',
|
'geo' => 'application/vnd.dynageo',
|
||||||
'gex' => 'application/vnd.geometry-explorer',
|
'gex' => 'application/vnd.geometry-explorer',
|
||||||
'ggb' => 'application/vnd.geogebra.file',
|
'ggb' => 'application/vnd.geogebra.file',
|
||||||
|
'ggs' => 'application/vnd.geogebra.slides',
|
||||||
'ggt' => 'application/vnd.geogebra.tool',
|
'ggt' => 'application/vnd.geogebra.tool',
|
||||||
'ghf' => 'application/vnd.groove-help',
|
'ghf' => 'application/vnd.groove-help',
|
||||||
'gif' => 'image/gif',
|
'gif' => 'image/gif',
|
||||||
@ -384,9 +387,10 @@ abstract class MimeHelper
|
|||||||
'jpgm' => 'video/jpm',
|
'jpgm' => 'video/jpm',
|
||||||
'jpgv' => 'video/jpeg',
|
'jpgv' => 'video/jpeg',
|
||||||
'jpm' => 'video/jpm',
|
'jpm' => 'video/jpm',
|
||||||
'js' => 'application/javascript',
|
'js' => 'text/javascript',
|
||||||
'json' => 'application/json',
|
'json' => 'application/json',
|
||||||
'jsonml' => 'application/jsonml+json',
|
'jsonml' => 'application/jsonml+json',
|
||||||
|
'jxl' => 'image/jxl',
|
||||||
'kar' => 'audio/midi',
|
'kar' => 'audio/midi',
|
||||||
'karbon' => 'application/vnd.kde.karbon',
|
'karbon' => 'application/vnd.kde.karbon',
|
||||||
'kfo' => 'application/vnd.kde.kformula',
|
'kfo' => 'application/vnd.kde.kformula',
|
||||||
@ -429,6 +433,8 @@ abstract class MimeHelper
|
|||||||
'm1v' => 'video/mpeg',
|
'm1v' => 'video/mpeg',
|
||||||
'm21' => 'application/mp21',
|
'm21' => 'application/mp21',
|
||||||
'm2a' => 'audio/mpeg',
|
'm2a' => 'audio/mpeg',
|
||||||
|
'm2t' => 'video/mp2t',
|
||||||
|
'm2ts' => 'video/mp2t',
|
||||||
'm2v' => 'video/mpeg',
|
'm2v' => 'video/mpeg',
|
||||||
'm3a' => 'audio/mpeg',
|
'm3a' => 'audio/mpeg',
|
||||||
'm3u' => 'audio/x-mpegurl',
|
'm3u' => 'audio/x-mpegurl',
|
||||||
@ -467,6 +473,7 @@ abstract class MimeHelper
|
|||||||
'mime' => 'message/rfc822',
|
'mime' => 'message/rfc822',
|
||||||
'mj2' => 'video/mj2',
|
'mj2' => 'video/mj2',
|
||||||
'mjp2' => 'video/mj2',
|
'mjp2' => 'video/mj2',
|
||||||
|
'mjs' => 'text/javascript',
|
||||||
'mk3d' => 'video/x-matroska',
|
'mk3d' => 'video/x-matroska',
|
||||||
'mka' => 'audio/x-matroska',
|
'mka' => 'audio/x-matroska',
|
||||||
'mks' => 'video/x-matroska',
|
'mks' => 'video/x-matroska',
|
||||||
@ -513,7 +520,7 @@ abstract class MimeHelper
|
|||||||
'msi' => 'application/x-msdownload',
|
'msi' => 'application/x-msdownload',
|
||||||
'msl' => 'application/vnd.mobius.msl',
|
'msl' => 'application/vnd.mobius.msl',
|
||||||
'msty' => 'application/vnd.muvee.style',
|
'msty' => 'application/vnd.muvee.style',
|
||||||
'mts' => 'model/vnd.mts',
|
'mts' => 'video/mp2t',
|
||||||
'mus' => 'application/vnd.musician',
|
'mus' => 'application/vnd.musician',
|
||||||
'musicxml' => 'application/vnd.recordare.musicxml+xml',
|
'musicxml' => 'application/vnd.recordare.musicxml+xml',
|
||||||
'mvb' => 'application/x-msmediaview',
|
'mvb' => 'application/x-msmediaview',
|
||||||
@ -826,6 +833,7 @@ abstract class MimeHelper
|
|||||||
'tr' => 'text/troff',
|
'tr' => 'text/troff',
|
||||||
'tra' => 'application/vnd.trueapp',
|
'tra' => 'application/vnd.trueapp',
|
||||||
'trm' => 'application/x-msterminal',
|
'trm' => 'application/x-msterminal',
|
||||||
|
'ts' => 'video/mp2t',
|
||||||
'tsd' => 'application/timestamped-data',
|
'tsd' => 'application/timestamped-data',
|
||||||
'tsv' => 'text/tab-separated-values',
|
'tsv' => 'text/tab-separated-values',
|
||||||
'ttc' => 'font/collection',
|
'ttc' => 'font/collection',
|
||||||
@ -899,6 +907,7 @@ abstract class MimeHelper
|
|||||||
'vxml' => 'application/voicexml+xml',
|
'vxml' => 'application/voicexml+xml',
|
||||||
'w3d' => 'application/x-director',
|
'w3d' => 'application/x-director',
|
||||||
'wad' => 'application/x-doom',
|
'wad' => 'application/x-doom',
|
||||||
|
'wasm' => 'application/wasm',
|
||||||
'wav' => 'audio/x-wav',
|
'wav' => 'audio/x-wav',
|
||||||
'wax' => 'audio/x-ms-wax',
|
'wax' => 'audio/x-ms-wax',
|
||||||
'wbmp' => 'image/vnd.wap.wbmp',
|
'wbmp' => 'image/vnd.wap.wbmp',
|
||||||
@ -1011,8 +1020,62 @@ abstract class MimeHelper
|
|||||||
'zir' => 'application/vnd.zul',
|
'zir' => 'application/vnd.zul',
|
||||||
'zirz' => 'application/vnd.zul',
|
'zirz' => 'application/vnd.zul',
|
||||||
'zmm' => 'application/vnd.handheld-entertainment+xml'
|
'zmm' => 'application/vnd.handheld-entertainment+xml'
|
||||||
);
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the file extensions
|
||||||
|
*
|
||||||
|
* @param string $target The targeted/filter option
|
||||||
|
* @param boolean $sorted The multidimensional grouping sort (only if targeted filter is used)
|
||||||
|
*
|
||||||
|
* @return array All the extensions (targeted & sorted)
|
||||||
|
* @since 5.0.3
|
||||||
|
*/
|
||||||
|
public static function getFileExtensions($target = null, $sorted = false)
|
||||||
|
{
|
||||||
|
// we have some in-house grouping/filters :)
|
||||||
|
$filters = [
|
||||||
|
'image' => array('image', 'font', 'model'),
|
||||||
|
'document' => array('application', 'text', 'chemical', 'message'),
|
||||||
|
'media' => array('video', 'audio'),
|
||||||
|
'file' => array('image', 'application', 'text', 'video', 'audio'),
|
||||||
|
'all' => array('application', 'text', 'chemical', 'message', 'image', 'font', 'model', 'video', 'audio', 'x-conference')
|
||||||
|
];
|
||||||
|
// sould we filter
|
||||||
|
if ($target)
|
||||||
|
{
|
||||||
|
// the bucket to get extensions
|
||||||
|
$fileextensions = array();
|
||||||
|
// check if filter exist (if not return empty array)
|
||||||
|
if (isset($filters[$target]))
|
||||||
|
{
|
||||||
|
foreach (self::$fileExtensionToMimeType as $extension => $mimetype)
|
||||||
|
{
|
||||||
|
// get the key mime type
|
||||||
|
$mimearr = explode("/", $mimetype, 2);
|
||||||
|
// check if this file extension should be added
|
||||||
|
if (in_array($mimearr[0], $filters[$target]))
|
||||||
|
{
|
||||||
|
if ($sorted)
|
||||||
|
{
|
||||||
|
if (!isset($fileextensions[$mimearr[0]]))
|
||||||
|
{
|
||||||
|
$fileextensions[$mimearr[0]] = array();
|
||||||
|
}
|
||||||
|
$fileextensions[$mimearr[0]][$extension] = $extension;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$fileextensions[$extension] = $extension;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $fileextensions;
|
||||||
|
}
|
||||||
|
// we just return all file extensions
|
||||||
|
return array_keys(self::$fileExtensionToMimeType);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the file extension from a full path OR file name.
|
* Get the file extension from a full path OR file name.
|
||||||
@ -1107,62 +1170,5 @@ abstract class MimeHelper
|
|||||||
// Fallback to application/octet-stream if extension is unknown
|
// Fallback to application/octet-stream if extension is unknown
|
||||||
return 'application/octet-stream';
|
return 'application/octet-stream';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the file extensions
|
|
||||||
*
|
|
||||||
* @param string $target The targeted/filter option
|
|
||||||
* @param boolean $sorted The multidimensional grouping sort (only if targeted filter is used)
|
|
||||||
*
|
|
||||||
* @return array All the extensions (targeted & sorted)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static function getFileExtensions($target = null, $sorted = false)
|
|
||||||
{
|
|
||||||
// we have some in-house grouping/filters :)
|
|
||||||
$filters = array(
|
|
||||||
'image' => array('image', 'font', 'model'),
|
|
||||||
'document' => array('application', 'text', 'chemical', 'message'),
|
|
||||||
'media' => array('video', 'audio'),
|
|
||||||
'file' => array('image', 'application', 'text', 'video', 'audio'),
|
|
||||||
'all' => array('application', 'text', 'chemical', 'message', 'image', 'font', 'model', 'video', 'audio', 'x-conference')
|
|
||||||
);
|
|
||||||
// sould we filter
|
|
||||||
if ($target)
|
|
||||||
{
|
|
||||||
// the bucket to get extensions
|
|
||||||
$fileextensions = array();
|
|
||||||
// check if filter exist (if not return empty array)
|
|
||||||
if (isset($filters[$target]))
|
|
||||||
{
|
|
||||||
foreach (self::$fileExtensionToMimeType as $extension => $mimetype)
|
|
||||||
{
|
|
||||||
// get the key mime type
|
|
||||||
$mimearr = explode("/", $mimetype, 2);
|
|
||||||
// check if this file extension should be added
|
|
||||||
if (in_array($mimearr[0], $filters[$target]))
|
|
||||||
{
|
|
||||||
if ($sorted)
|
|
||||||
{
|
|
||||||
if (!isset($fileextensions[$mimearr[0]]))
|
|
||||||
{
|
|
||||||
$fileextensions[$mimearr[0]] = array();
|
|
||||||
}
|
|
||||||
$fileextensions[$mimearr[0]][$extension] = $extension;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$fileextensions[$extension] = $extension;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $fileextensions;
|
|
||||||
}
|
|
||||||
// we just return all file extensions
|
|
||||||
return array_keys(self::$fileExtensionToMimeType);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user