/** * Returns the icon file path for a file type icon for a given file. * $mimeType = tx_dam::file_getType($filename); * * @param array $mimeType Describes the type of a file. Can be meta record array or array from tx_dam::file_getType(). * @param boolean $absolutePath If set the path to the icon is absolute. By default it's relative to typo3/ folder. * @param string $mode TYPO3_MODE to be used: 'FE', 'BE'. Constant TYPO3_MODE is default. * @return string Icon image file path * @see tx_dam::file_getType() */ function icon_getFileType($mimeType, $absolutePath = false, $mode = TYPO3_MODE) { static $iconCache = array(); static $iconCacheRel = array(); $iconfile = false; // first see if the icon is in the icon cache if (is_array($mimeType)) { if (!$absolutePath && ($cached = $iconCacheRel[$mimeType['file_type']])) { return $cached; } elseif ($cached = $iconCache[$mimeType['file_type']]) { $iconfile = $cached; } else { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dam']['fileIconPaths_' . $mode] as $pathIcons) { // Check defined icons $fileType = tx_dam_db::getMediaExtension($mimeType['file_type']); // See if the icon is a DAM reference if (t3lib_div::testInt($fileType['icon'])) { $fileType['icon'] = tx_dam::file_getPathByUid($fileType['icon']); } if (@file_exists($fileType['icon'])) { $iconfile = $fileType['icon']; $cacheKey = $mimeType['file_type']; $iconCache[$cacheKey] = $iconfile; break; } // then try default PNG if (@file_exists($pathIcons . $mimeType['file_type'] . '.png')) { $iconfile = $pathIcons . $mimeType['file_type'] . '.png'; $cacheKey = $mimeType['file_type']; $iconCache[$cacheKey] = $iconfile; break; } // then go for default GIF if (@file_exists($pathIcons . $mimeType['file_type'] . '.gif')) { $iconfile = $pathIcons . $mimeType['file_type'] . '.gif'; $cacheKey = $mimeType['file_type']; $iconCache[$cacheKey] = $iconfile; break; } } if (!$iconfile && ($mediaType = tx_dam::convert_mediaType($mimeType['media_type']))) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dam']['fileIconPaths_' . $mode] as $pathIcons) { // first try PNG if (@file_exists($pathIcons . 'mtype_' . $mediaType . '.png')) { $iconfile = $pathIcons . 'mtype_' . $mediaType . '.png'; $cacheKey = '_mtype_' . $mimeType['media_type']; $iconCache[$cacheKey] = $iconfile; break; } // then go for GIF if (@file_exists($pathIcons . 'mtype_' . $mediaType . '.gif')) { $iconfile = $pathIcons . 'mtype_' . $mediaType . '.gif'; $cacheKey = '_mtype_' . $mimeType['media_type']; $iconCache[$cacheKey] = $iconfile; break; } } } if (!$iconfile) { $iconfile = PATH_txdam . 'i/18/' . 'mtype_undefined.gif'; $cacheKey = '__undefined'; } } } if (!$absolutePath) { $iconfile = preg_replace('#^' . preg_quote(PATH_site) . '#', '', $iconfile); if (TYPO3_MODE === 'BE') { $iconfile = '../' . $iconfile; $iconCacheRel[$cacheKey] = $iconfile; } } return $iconfile; }