filelib MDL-19707 Modified file_extension_icon to use extisting function mimeinfo and reverted

two uses of file_extension_icon in course-lib that were incorrect
This commit is contained in:
samhemelryk 2009-07-08 01:52:16 +00:00
parent 8abf70817a
commit 405efa5f95
2 changed files with 7 additions and 22 deletions

View 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) . "";

View 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;
}