Commits

Joachim Werner committed 32b44e3

Added filetype icon for unknown types. Added mapping for file extension to filetype icon.

Comments (0)

Files changed (2)

assets/filetypeicons/unknown.png

Added
New image

controllers/DefaultController.php

     public function actionThumbnail()
     {
         $file = urldecode($_GET['path']);
+        /*
         $mimeType = mime_content_type($file);
         if(preg_match("/image\/(.*)/",$mimeType,$matches)) {
             $this->imagePreview($file, isset($_GET['x']) ? (int)$_GET['x'] : 100);
         } else {
             $this->imagePreview($file, 100);
         }
+         */
+        $this->imagePreview($file, isset($_GET['x']) ? (int)$_GET['x'] : 100);
     } // }}} 
     // {{{ actionPreview
     public function actionPreview()
             die;
         }
 
-        // Do we hav a non-image file?
+        // Do we have a non-image file?
         $mimeType = mime_content_type($image);
         if(strpos($mimeType,'image/')===false) {
             // No image
             if(preg_match("/\.([^\.]+)$/",$image,$matches)){
                 $extension = $matches[1];
                 $iconPath = dirname(__FILE__).'/../../../../'.str_replace(Yii::app()->baseUrl.'/', '',$this->module->assetsUrl).'/filetypeicons';
-                $extensionIcon = $iconPath.'/'.$extension.'.png';
+                $extensionIcon = $iconPath.'/'.$this->getFileIconByExtension($extension);
                 if(!file_exists($extensionIcon))
                     $extensionIcon=$iconPath.'/fileicon_bg.png';
                 header('Content-Type: image/png');
         fclose ($image);
         die;
     } // }}}
+    private function getFileIconByExtension($extension)
+    {
+        $icons = array(
+            'zip'=>'compressed',
+            'css'=>'css',
+            'ini'=>'developer',
+            'php'=>'developer',
+            'vb'=>'developer',
+            'bash'=>'developer',
+            'sh'=>'developer',
+            'xlsb'=>'excel',
+            'xlsx'=>'excel',
+            'xls'=>'excel',
+            //'fileicon_bg',
+            //'fireworks',
+            'flv'=>'flash',
+            'swf'=>'flash',
+            //'folder',
+            'htm'=>'html',
+            'html'=>'html',
+            //'illustrator',
+            'jpg'=>'image',
+            'png'=>'image',
+            'keynote',
+            'avi'=>'movie',
+            'mp4'=>'movie',
+            'avi'=>'movie',
+            'divx'=>'movie',
+            'mpg'=>'movie',
+            'mpeg'=>'movie',
+            'mp3'=>'music',
+            'wav'=>'music',
+            'csv'=>'numbers',
+            // 'pages',
+            'pdf'=>'pdf',
+            'psd'=>'photoshop',
+            'pptx'=>'powerpoint',
+            'ppt'=>'powerpoint',
+            'txt'=>'text',
+            'md'=>'text',
+            'mkd'=>'text',
+            'markdown'=>'text',
+            //'unknown',
+            'doc'=>'word',
+            'docx'=>'word',
+        );
+        if(array_key_exists($extension, $icons))
+            return $icons[$extension].'.png';
+        else
+            return 'unknown.png';
+    }
     // }}} End Methods
 }
 // {{{ myPar