]> source.dussan.org Git - nextcloud-server.git/commitdiff
Cache mimetype icons
authorRobin Appelman <icewind@owncloud.com>
Wed, 29 May 2013 13:43:41 +0000 (15:43 +0200)
committerRobin Appelman <icewind@owncloud.com>
Wed, 29 May 2013 15:22:00 +0000 (17:22 +0200)
lib/helper.php

index 195722057eb003b2184367775b75ab91c5fdf6d5..81b0851ef162b6ff83e49c513c449c8b5d351d5b 100644 (file)
@@ -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";
                }
        }