mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
NOBUG mimetypes - improve a bit mimeinfo_from_icon() so, before using the
"return last" strategy (leading to all images returning image/tiff always) it will try one "return by extension match" if possible.
This commit is contained in:
parent
c329e370d8
commit
637a60dc5f
@ -1290,7 +1290,7 @@ function mimeinfo_from_type($element, $mimetype) {
|
||||
*
|
||||
* @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)
|
||||
* @param boolean $all return all matching entries (defaults to false - best (by ext)/last match)
|
||||
* @return string Requested piece of information from array
|
||||
*/
|
||||
function mimeinfo_from_icon($element, $icon, $all=false) {
|
||||
@ -1299,11 +1299,16 @@ function mimeinfo_from_icon($element, $icon, $all=false) {
|
||||
if (preg_match("/\/(.*)/", $icon, $matches)) {
|
||||
$icon = $matches[1];
|
||||
}
|
||||
// Try to get the extension
|
||||
$extension = '';
|
||||
if (($cutat = strrpos($icon, '.')) !== false && $cutat < strlen($icon)-1) {
|
||||
$extension = substr($icon, $cutat + 1);
|
||||
}
|
||||
$info = array($mimeinfo['xxx'][$element]); // Default
|
||||
foreach($mimeinfo as $values) {
|
||||
foreach($mimeinfo as $key => $values) {
|
||||
if($values['icon']==$icon) {
|
||||
if(isset($values[$element])) {
|
||||
$info[] = $values[$element];
|
||||
$info[$key] = $values[$element];
|
||||
}
|
||||
//No break, for example for 'excel.gif' we don't want 'csv'!
|
||||
}
|
||||
@ -1312,8 +1317,14 @@ function mimeinfo_from_icon($element, $icon, $all=false) {
|
||||
if (count($info) > 1) {
|
||||
array_shift($info); // take off document/unknown if we have better options
|
||||
}
|
||||
return $info;
|
||||
return array_values($info); // Keep keys out when requesting all
|
||||
}
|
||||
|
||||
// Requested only one, try to get the best by extension coincidence, else return the last
|
||||
if ($extension && isset($info[$extension])) {
|
||||
return $info[$extension];
|
||||
}
|
||||
|
||||
return array_pop($info); // Return last match (mimicking behaviour/comment inside foreach loop)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user