本文整理汇总了PHP中OC_Helper::mimeTypeAlias方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_Helper::mimeTypeAlias方法的具体用法?PHP OC_Helper::mimeTypeAlias怎么用?PHP OC_Helper::mimeTypeAlias使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC_Helper
的用法示例。
在下文中一共展示了OC_Helper::mimeTypeAlias方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mimetypeIcon
/**
* get path to icon of file type
* @param string $mimetype mimetype
* @return string the url
*
* Returns the path to the image of this file type.
*/
public static function mimetypeIcon($mimetype)
{
// On first access load the list of mimetype aliases
if (empty(self::$mimeTypeAlias)) {
$file = file_get_contents(OC::$SERVERROOT . '/config/mimetypealiases.dist.json');
self::$mimeTypeAlias = get_object_vars(json_decode($file));
if (file_exists(\OC::$SERVERROOT . '/config/mimetypealiases.json')) {
$custom = get_object_vars(json_decode(file_get_contents(\OC::$SERVERROOT . '/config/mimetypealiases.json')));
self::$mimeTypeAlias = array_merge(self::$mimeTypeAlias, $custom);
}
}
if (isset(self::$mimeTypeAlias[$mimetype])) {
$mimetype = self::$mimeTypeAlias[$mimetype];
}
if (isset(self::$mimetypeIcons[$mimetype])) {
return self::$mimetypeIcons[$mimetype];
}
// Replace slash and backslash with a minus
$icon = str_replace('/', '-', $mimetype);
$icon = str_replace('\\', '-', $icon);
// Is it a dir?
if ($mimetype === 'dir') {
self::$mimetypeIcons[$mimetype] = \OC::$server->getURLGenerator()->imagePath('core', 'filetypes/folder.png');
return self::$mimetypeIcons[$mimetype];
}
if ($mimetype === 'dir-shared') {
self::$mimetypeIcons[$mimetype] = \OC::$server->getURLGenerator()->imagePath('core', 'filetypes/folder-shared.png');
return self::$mimetypeIcons[$mimetype];
}
if ($mimetype === 'dir-external') {
self::$mimetypeIcons[$mimetype] = \OC::$server->getURLGenerator()->imagePath('core', 'filetypes/folder-external.png');
return self::$mimetypeIcons[$mimetype];
}
// Icon exists?
try {
self::$mimetypeIcons[$mimetype] = \OC::$server->getURLGenerator()->imagePath('core', 'filetypes/' . $icon . '.png');
return self::$mimetypeIcons[$mimetype];
} catch (\RuntimeException $e) {
// Specified image not found
}
// Try only the first part of the filetype
$mimePart = substr($icon, 0, strpos($icon, '-'));
try {
self::$mimetypeIcons[$mimetype] = \OC::$server->getURLGenerator()->imagePath('core', 'filetypes/' . $mimePart . '.png');
return self::$mimetypeIcons[$mimetype];
} catch (\RuntimeException $e) {
// Image for the first part of the mimetype not found
}
self::$mimetypeIcons[$mimetype] = \OC::$server->getURLGenerator()->imagePath('core', 'filetypes/file.png');
return self::$mimetypeIcons[$mimetype];
}
示例2: mimetypeIcon
/**
* get path to icon of file type
* @param string $mimetype mimetype
* @return string the url
*
* Returns the path to the image of this file type.
*/
public static function mimetypeIcon($mimetype)
{
// On first access load the list of mimetype aliases
if (empty(self::$mimeTypeAlias)) {
$file = file_get_contents(OC::$SERVERROOT . '/config/mimetypealiases.json');
self::$mimeTypeAlias = get_object_vars(json_decode($file));
}
if (isset(self::$mimeTypeAlias[$mimetype])) {
$mimetype = self::$mimeTypeAlias[$mimetype];
}
if (isset(self::$mimetypeIcons[$mimetype])) {
return self::$mimetypeIcons[$mimetype];
}
// Replace slash and backslash with a minus
$icon = str_replace('/', '-', $mimetype);
$icon = str_replace('\\', '-', $icon);
// Is it a dir?
if ($mimetype === 'dir') {
self::$mimetypeIcons[$mimetype] = OC::$WEBROOT . '/core/img/filetypes/folder.png';
return OC::$WEBROOT . '/core/img/filetypes/folder.png';
}
if ($mimetype === 'dir-shared') {
self::$mimetypeIcons[$mimetype] = OC::$WEBROOT . '/core/img/filetypes/folder-shared.png';
return OC::$WEBROOT . '/core/img/filetypes/folder-shared.png';
}
if ($mimetype === 'dir-external') {
self::$mimetypeIcons[$mimetype] = OC::$WEBROOT . '/core/img/filetypes/folder-external.png';
return OC::$WEBROOT . '/core/img/filetypes/folder-external.png';
}
// Icon exists?
if (file_exists(OC::$SERVERROOT . '/core/img/filetypes/' . $icon . '.png')) {
self::$mimetypeIcons[$mimetype] = OC::$WEBROOT . '/core/img/filetypes/' . $icon . '.png';
return OC::$WEBROOT . '/core/img/filetypes/' . $icon . '.png';
}
// Try only the first part of the filetype
$mimePart = substr($icon, 0, strpos($icon, '-'));
if (file_exists(OC::$SERVERROOT . '/core/img/filetypes/' . $mimePart . '.png')) {
self::$mimetypeIcons[$mimetype] = OC::$WEBROOT . '/core/img/filetypes/' . $mimePart . '.png';
return OC::$WEBROOT . '/core/img/filetypes/' . $mimePart . '.png';
} else {
self::$mimetypeIcons[$mimetype] = OC::$WEBROOT . '/core/img/filetypes/file.png';
return OC::$WEBROOT . '/core/img/filetypes/file.png';
}
}