diff options
author | Robin Appelman <icewind@owncloud.com> | 2013-05-29 15:43:41 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2013-05-29 15:43:41 +0200 |
commit | 24a401a548fd65bd546ed61c38236d286c657eb5 (patch) | |
tree | d2a830e501d906048d725f4ba1654fff2ced831a /lib/helper.php | |
parent | 7c0c6bd779cb73c4fdc9993f6dc78f9dd1138a88 (diff) | |
download | nextcloud-server-24a401a548fd65bd546ed61c38236d286c657eb5.tar.gz nextcloud-server-24a401a548fd65bd546ed61c38236d286c657eb5.zip |
Cache mimetype icons
Diffstat (limited to 'lib/helper.php')
-rw-r--r-- | lib/helper.php | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/helper.php b/lib/helper.php index c69445ed788..9e4978f6b96 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -27,6 +27,7 @@ class OC_Helper { private static $mimetypes=array(); private static $tmpFiles=array(); + private static $mimetypeIcons = array(); /** * @brief Creates an url using a defined route @@ -192,25 +193,32 @@ class OC_Helper { if(isset($alias[$mimetype])) { $mimetype=$alias[$mimetype]; } + if (isset(self::$mimetypeIcons[$mimetype])) { + return self::$mimetypeIcons[$mimetype]; + } // Replace slash and backslash with a minus - $mimetype = str_replace( "/", "-", $mimetype ); - $mimetype = str_replace( "\\", "-", $mimetype ); + $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"; } // Icon exists? - if( file_exists( OC::$SERVERROOT."/core/img/filetypes/$mimetype.png" )) { - return OC::$WEBROOT."/core/img/filetypes/$mimetype.png"; + 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 - $mimetype=substr($mimetype, 0, strpos($mimetype, '-')); - if( file_exists( OC::$SERVERROOT."/core/img/filetypes/$mimetype.png" )) { - return OC::$WEBROOT."/core/img/filetypes/$mimetype.png"; + $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"; } } |