From c0381e22da2cf2ecf8b17ffc55462a68cf84c6aa Mon Sep 17 00:00:00 2001 From: sam_marshall Date: Thu, 9 Mar 2006 13:14:33 +0000 Subject: [PATCH] Added way to get a textual description of a file (e.g. 'Word document') based on its MIME type. --- lang/en_utf8/mimetypes.php | 26 ++++++++++++++++++++++++++ lib/filelib.php | 20 ++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 lang/en_utf8/mimetypes.php diff --git a/lang/en_utf8/mimetypes.php b/lang/en_utf8/mimetypes.php new file mode 100644 index 0000000000..0982b02e24 --- /dev/null +++ b/lang/en_utf8/mimetypes.php @@ -0,0 +1,26 @@ + diff --git a/lib/filelib.php b/lib/filelib.php index bb52b411f7..7224a36e5c 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -182,6 +182,26 @@ function mimeinfo_from_type($element, $mimetype) { return $mimeinfo['xxx'][$element]; // Default } +/** + * Obtains descriptions for file types (e.g. 'Microsoft Word document') from the + * mimetypes.php language file. + * @param string $mimetype MIME type (can be obtained using the mimeinfo function) + * @param bool $capitalise If true, capitalises first character of result + * @return string Text description + */ +function get_mimetype_description($mimetype,$capitalise=false) { + $result=get_string($mimetype,'mimetypes'); + // Surrounded by square brackets indicates that there isn't a string for that + // (maybe there is a better way to find this out?) + if(strpos($result,'[')===0) { + $result=get_string('document/unknown','mimetypes'); + } + if($capitalise) { + $result=ucfirst($result); + } + return $result; +} + /** * @PARAM $filter int 0=no filtering, 1=all files, 2=html files only */ -- 2.39.5