]> git.mjollnir.org Git - moodle.git/commitdiff
Added way to get a textual description of a file (e.g. 'Word document') based on...
authorsam_marshall <sam_marshall>
Thu, 9 Mar 2006 13:14:33 +0000 (13:14 +0000)
committersam_marshall <sam_marshall>
Thu, 9 Mar 2006 13:14:33 +0000 (13:14 +0000)
lang/en_utf8/mimetypes.php [new file with mode: 0644]
lib/filelib.php

diff --git a/lang/en_utf8/mimetypes.php b/lang/en_utf8/mimetypes.php
new file mode 100644 (file)
index 0000000..0982b02
--- /dev/null
@@ -0,0 +1,26 @@
+<?PHP 
+
+// These should be accessed using get_mimetype_description in filelib.php.
+// They correspond to a (currently small) subset of the MIME types that Moodle
+// supports, which are also listed in filelib.php. Descriptions for other types
+// should be added here.
+
+// Style: initial lower-case letter, except as required for product names etc.
+  
+$string['text/plain'] = 'text file';
+$string['application/pdf'] = 'PDF document';
+$string['application/msword'] = 'Word document';
+$string['text/rtf'] = 'RTF document';
+$string['application/vnd.ms-excel'] = 'Excel spreadsheet';
+$string['audio/wav'] = 'sound file';
+$string['audio/mp3'] = 'MP3 audio file';
+$string['application/vnd.ms-powerpoint'] = 'Powerpoint presentation';
+$string['application/zip'] = 'zip archive';
+$string['image/jpeg'] = 'JPEG image';
+$string['image/gif'] = 'GIF image';
+$string['image/bmp'] = 'uncompressed BMP image';
+
+// Moodle default MIME type used for all types not described 
+$string['document/unknown'] = 'file'; 
+
+?>
index bb52b411f77ae59eec2a2f2d9c605b635232bb98..7224a36e5c96aef9ccdb4221ba28e9855329baa3 100644 (file)
@@ -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
  */