Przeglądaj źródła

#888 Remove .bmp extension from supported images in all transcoders/storages

Alex Trofimov 8 lat temu
rodzic
commit
159422c0c8

+ 8 - 0
inc/classes/BxDolTranscoder.php

@@ -334,6 +334,14 @@ class BxDolTranscoder extends BxDolFactory implements iBxDolFactoryObject
         return $this->_oDb;
     }
 
+    /**
+     * check if transcoder suppors given file mime type
+     */ 
+    public function isMimeTypeSupported($sMimeType)
+    {
+        return false;
+    }
+
     /**
      * Get transcoded file url.
      * If transcoded file is ready then direct url to the file is returned.

+ 17 - 0
inc/classes/BxDolTranscoderImage.php

@@ -81,6 +81,23 @@ class BxDolTranscoderImage extends BxDolTranscoder implements iBxDolFactoryObjec
         $this->_sQueueTable = $this->_oDb->getQueueTable();
     }
 
+    /**
+     * check if transcoder suppors given file mime type
+     */ 
+    public function isMimeTypeSupported($sMimeType)
+    {
+        $sMimeType = strtolower($sMimeType);
+        switch ($sMimeType) {
+        case 'image/gif':
+        case 'image/jpeg':
+        case 'image/pjpeg':
+        case 'image/png':
+            return true;
+        }
+
+        return false;
+    }
+    
     /**
      * Get file url when file isn't transcoded yet
      */

+ 20 - 0
inc/classes/BxDolTranscoderProxy.php

@@ -25,6 +25,26 @@ class BxDolTranscoderProxy extends BxDolTranscoder implements iBxDolFactoryObjec
         $this->_sQueueTable = $this->_oDb->getQueueTable();
     }
 
+    /**
+     * check if transcoder suppors given file mime type
+     */ 
+    public function isMimeTypeSupported($sMimeType)
+    {
+        if (!empty($this->_aObject['source_params']['image']))
+            $sTranscoder = $this->_aObject['source_params']['image'];
+        elseif (!empty($this->_aObject['source_params']['video_poster']))
+            $sTranscoder = $this->_aObject['source_params']['video_poster'];
+        elseif (!empty($this->_aObject['source_params']['video']))
+            $sTranscoder = $this->_aObject['source_params']['video'];
+        else
+            return false;
+
+        if (!($oTranscoder = BxDolTranscoder::getObjectInstance($sTranscoder)))
+            return false;        
+        
+        return $oTranscoder->isMimeTypeSupported($sMimeType);
+    }
+    
     /**
      * Depending on original file mime type call appropriate transcoder 
      */

+ 11 - 0
inc/classes/BxDolTranscoderVideo.php

@@ -95,6 +95,17 @@ class BxDolTranscoderVideo extends BxDolTranscoder implements iBxDolFactoryObjec
         return '';
     }
 
+    /**
+     * check if transcoder suppors given file mime type
+     */ 
+    public function isMimeTypeSupported($sMimeType)
+    {
+        if (0 === strncmp($sMimeType, 'video/', 6))
+            return true;
+
+        return false;
+    }
+    
     /**
      * If video isn't processed yet then empty string is returned for video, or predefined image is returned for video poster
      */

+ 2 - 8
inc/classes/BxDolUploader.php

@@ -424,14 +424,8 @@ abstract class BxDolUploader extends BxDolFactory
     {
         if (!$oImagesTranscoder)
             return false;
-        
-        if (0 === strncmp($aFile['mime_type'], 'image/', 6) && (is_a($oImagesTranscoder, 'BxDolTranscoderImage') || is_a($oImagesTranscoder, 'BxDolTranscoderProxy')))
-            return true;
-        
-        if (0 === strncmp($aFile['mime_type'], 'video/', 6) && (is_a($oImagesTranscoder, 'BxDolTranscoderVideo') || is_a($oImagesTranscoder, 'BxDolTranscoderProxy')))
-            return true;
-
-        return false;
+
+        return $oImagesTranscoder->isMimeTypeSupported($aFile['mime_type']);
     }
 
     protected function isAdmin ($iContentId = 0)

+ 1 - 1
template/scripts/BxBaseCmts.php

@@ -744,7 +744,7 @@ class BxBaseCmts extends BxDolCmts
             $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->getTranscoderPreviewName());
 
             foreach($aFiles as $aFile) {
-            	$bImage = strncmp($aFile['mime_type'], 'image/', 6) === 0;
+            	$bImage = $oTranscoder && $oTranscoder->isMimeTypeSupported($aFile['mime_type']);
 
             	$sPreview = '';
             	if($oTranscoder && $bImage)