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) . "";
* @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;
}