method to create user friendly label for a mime type, eg. "PDF file (application/pdf)"

This commit is contained in:
Ralf Becker 2009-04-18 09:53:36 +00:00
parent a694662838
commit 1a8b605c17
2 changed files with 25 additions and 9 deletions

View File

@ -212,14 +212,8 @@ class vfs_widget
}
//error_log(__METHOD__."() type=vfs-mime: value=".array2string($value).": mime=$mime, path=$path");
$cell['type'] = 'image';
if ($mime == egw_vfs::DIR_MIME_TYPE)
{
$cell['label'] = lang('Directory');
}
else
{
$cell['label'] = lang('%1 file',strtoupper(mime_magic::mime2ext($mime))).' ('.$mime.')';
}
$cell['label'] = mime_magic::mime2label($mime);
list($mime_main,$mime_sub) = explode('/',$mime);
if ($mime_main == 'egw')
{

View File

@ -26,6 +26,27 @@
*/
class mime_magic
{
/**
* Get a user friendly label for a mime type: e.g. "PDF file (application/pdf)"
*
* @param string $mime
* @return string
*/
public function mime2label($mime)
{
$mime = strtolower($mime);
if ($mime == egw_vfs::DIR_MIME_TYPE)
{
return lang('Directory');
}
elseif (!($ext = self::mime2ext($mime)))
{
return $mime;
}
return lang('%1 file',strtoupper($ext)).' ('.$mime.')';
}
/**
* Convert a file extension to a MIME type
*
@ -92,6 +113,7 @@ class mime_magic
*/
public static function mime2ext($type)
{
$type = strtolower($type);
$key = array_search($type, self::$mime_extension_map);
if (empty($type) || $key === false)
{
@ -294,7 +316,7 @@ class mime_magic
'odt' => 'application/vnd.oasis.opendocument.text',
'odp' => 'application/vnd.oasis.opendocument.presentation',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
'patch' => 'text/diff',
'patch' => 'text/x-diff',
'pbm' => 'image/x-portable-bitmap',
'pdb' => 'chemical/x-pdb',
'pdf' => 'application/pdf',