]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16359 - adding support for mimeinfo_from_icon to return all matches
authormjollnir_ <mjollnir_>
Fri, 5 Sep 2008 16:43:44 +0000 (16:43 +0000)
committermjollnir_ <mjollnir_>
Fri, 5 Sep 2008 16:43:44 +0000 (16:43 +0000)
(needed for portfolio format support)

lib/filelib.php

index 0797859baebf8e296c611dfe29e269d3d855c85c..7f3c6f5736b3097461e8467d6ff8847507313504 100644 (file)
@@ -596,24 +596,28 @@ function mimeinfo_from_type($element, $mimetype) {
  * Get information about a filetype based on the icon file.
  * @param string $element Desired information (usually 'icon')
  * @param string $icon Icon file path.
+ * @param boolean $all return all matching entries (defaults to false - last match)
  * @return string Requested piece of information from array
  */
-function mimeinfo_from_icon($element, $icon) {
+function mimeinfo_from_icon($element, $icon, $all=false) {
     $mimeinfo = get_mimetypes_array();
 
     if (preg_match("/\/(.*)/", $icon, $matches)) {
         $icon = $matches[1];
     }
-    $info = $mimeinfo['xxx'][$element]; // Default
+    $info = array($mimeinfo['xxx'][$element]); // Default
     foreach($mimeinfo as $values) {
         if($values['icon']==$icon) {
             if(isset($values[$element])) {
-                $info = $values[$element];
+                $info[] = $values[$element];
             }
             //No break, for example for 'excel.gif' we don't want 'csv'!
         }
     }
-    return $info;
+    if ($all) {
+        return $info;
+    }
+    return array_pop($info); // Return last match (mimicking behaviour/comment inside foreach loop)
 }
 
 /**