MDL-16359 - adding support for mimeinfo_from_icon to return all matches
(needed for portfolio format support)
This commit is contained in:
+8
-4
@@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user