Beispiel #1
0
 /**
  * Get path to the icon of a file type
  * @param string $mimetype the MIME type
  * @return string the url
  */
 public function mimeTypeIcon($mimetype)
 {
     $this->loadAliases();
     while (isset($this->mimeTypeAlias[$mimetype])) {
         $mimetype = $this->mimeTypeAlias[$mimetype];
     }
     if (isset($this->mimetypeIcons[$mimetype])) {
         return $this->mimetypeIcons[$mimetype];
     }
     // Replace slash and backslash with a minus
     $icon = str_replace('/', '-', $mimetype);
     $icon = str_replace('\\', '-', $icon);
     // Is it a dir?
     if ($mimetype === 'dir') {
         $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder.svg');
         return $this->mimetypeIcons[$mimetype];
     }
     if ($mimetype === 'dir-shared') {
         $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder-shared.svg');
         return $this->mimetypeIcons[$mimetype];
     }
     if ($mimetype === 'dir-external') {
         $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder-external.svg');
         return $this->mimetypeIcons[$mimetype];
     }
     // Icon exists?
     try {
         $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $icon . '.svg');
         return $this->mimetypeIcons[$mimetype];
     } catch (\RuntimeException $e) {
         // Specified image not found
     }
     // Try only the first part of the filetype
     $mimePart = substr($icon, 0, strpos($icon, '-'));
     try {
         $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $mimePart . '.svg');
         return $this->mimetypeIcons[$mimetype];
     } catch (\RuntimeException $e) {
         // Image for the first part of the mimetype not found
     }
     $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/file.svg');
     return $this->mimetypeIcons[$mimetype];
 }