Example #1
0
File: helper.php Project: jzee/core
 /**
  * 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];
 }
Example #2
0
 /**
  * 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';
     }
 }