* 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)
}
/**