]> git.mjollnir.org Git - moodle.git/commitdiff
filelib MDL-19707 Modified file_extension_icon to use extisting function mimeinfo...
authorsamhemelryk <samhemelryk>
Wed, 8 Jul 2009 01:52:16 +0000 (01:52 +0000)
committersamhemelryk <samhemelryk>
Wed, 8 Jul 2009 01:52:16 +0000 (01:52 +0000)
two uses of file_extension_icon in course-lib that were incorrect

course/lib.php
lib/filelib.php

index f4ddffd97ce54a2ee3d49501e30ac22d1b8b75bb..b595fbd650489a934d25ff219dbcdb74dc5446b6 100644 (file)
@@ -1333,9 +1333,9 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
                 if (!empty($customicon)) {
                     if (substr($customicon, 0, 4) === 'mod/') {
                         list($modname, $iconname) = explode('/', substr($customicon, 4), 2);
-                        $icon = $OUTPUT->mod_icon_url(file_extension_icon($iconname), $modname);
+                        $icon = $OUTPUT->mod_icon_url(str_replace(array('.gif', '.png'), '', $customicon), $modname);
                     } else {
-                        $icon = $OUTPUT->old_icon_url(file_extension_icon($customicon));
+                        $icon = $OUTPUT->old_icon_url(str_replace(array('.gif', '.png'), '', $customicon));
                     }
                 } else {
                     $icon = "" . $OUTPUT->mod_icon_url('icon', $mod->modname) . "";
index cd652fcbb4f3897cb46a96b1df18093e6cb20814..1a87d626d50e4df0b69d877d8e52de613b3bc3a5 100644 (file)
@@ -1175,30 +1175,15 @@ function file_mimetype_icon($mimetype, $size=null) {
  * @todo Implement $size
  *
  * @param string filename The filename to get the icon for
- * @param int $size The size of the icon. Not yet implemented
+ * @param int $size The size of the icon. Defaults to null can also be 32
  * @return string
  */
 function file_extension_icon($filename, $size=null) {
-    // Get the extension
-    $extension = substr($filename, strrpos($filename, '.'));
-    $mimeinfo = get_mimetypes_array();
-    foreach ($mimeinfo as $ext=>$mime) {
-        // Check each till we find an exact match for extension
-        if ($ext === $extension) {
-            $icon = $mime['icon'];
-            $icon = substr($icon, 0, strrpos($icon, '.'));
-            if ($size!=null && is_int($size)) {
-                $icon .= '-'.$size;
-            }
-            return 'f/'.$icon;
-        }
-    }
-    // Didn't find a match return the default
-    $icon = $mimeinfo['xxx']['icon'];
-    $icon = substr($icon, 0, strrpos($icon, '.'));
-    if ($size!=null && is_int($size)) {
-        $icon .= '-'.$size;
+    $element = 'icon';
+    if ($size!==null) {
+        $element .= (string)$size;
     }
+    $icon = mimeinfo($element, $filename);
     return 'f/'.$icon;
 }