From: samhemelryk Date: Tue, 7 Jul 2009 04:03:33 +0000 (+0000) Subject: lib-filelib MDL-19707 Modified file_extension_icon() to accept full filename X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=2dcb7d0be068df8d89235c3867299f458cb63d08;p=moodle.git lib-filelib MDL-19707 Modified file_extension_icon() to accept full filename --- diff --git a/lib/filelib.php b/lib/filelib.php index 1f9cf600a0..cd652fcbb4 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -1159,31 +1159,28 @@ function file_mimetype_icon($mimetype, $size=null) { } /** - * Returns the relative icon path for a given file extension + * Returns the relative icon path for a given file name * * This function should be used in conjuction with $OUTPUT->old_icon_url to produce * a return the full path to an icon. * - * The extension that you should pass should be just the extension, not the whole filename. - * A preceeding . is tolerated. - * * - * $extension = 'jpg'; - * $icon = $OUTPUT->old_icon_url(file_extension_icon($extension)); - * echo ''.$extension.''; + * $filename = 'jpg'; + * $icon = $OUTPUT->old_icon_url(file_extension_icon($filename)); + * echo 'blah'; * * * @todo When an $OUTPUT->icon method is available this function should be altered * to conform with that. * @todo Implement $size * - * @param string $extension The extension of the file to get an icon for + * @param string filename The filename to get the icon for * @param int $size The size of the icon. Not yet implemented * @return string */ -function file_extension_icon($extension, $size=null) { - // Get rid of any preceeding . - $extension = trim($extension, '. '); +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