Răsfoiți Sursa

#280 variable size transcoding bugs

Alex Trofimov 10 ani în urmă
părinte
comite
2b2f0894e8
2 a modificat fișierele cu 17 adăugiri și 10 ștergeri
  1. 3 10
      image_transcoder.php
  2. 14 0
      inc/classes/BxDolTranscoder.php

+ 3 - 10
image_transcoder.php

@@ -7,16 +7,6 @@
  * @{
  * @{
  */
  */
 
 
-if (isset($_GET['devicePixelRatio'])) {
-    $sDpr = $_GET['devicePixelRatio'];
-
-    if ('' . ceil(intval($sDpr)) !== $sDpr)
-        $sDpr = '1';
-
-    setcookie('devicePixelRatio', $sDpr, time()+60*60*24*365);
-    exit();
-}
-
 ob_start();
 ob_start();
 
 
 require_once('./inc/header.inc.php');
 require_once('./inc/header.inc.php');
@@ -34,6 +24,9 @@ if (!$oTranscoder) {
 
 
 ob_end_clean();
 ob_end_clean();
 
 
+if (isset($_GET['dpx']))
+    $oTranscoder->forceDevicePixelRatio((int)$_GET['dpx']);
+
 if (!$oTranscoder->isFileReady($sHandler) && !$oTranscoder->transcode ($sHandler)) {
 if (!$oTranscoder->isFileReady($sHandler) && !$oTranscoder->transcode ($sHandler)) {
     bx_transcoder_error_occured();
     bx_transcoder_error_occured();
     exit;
     exit;

+ 14 - 0
inc/classes/BxDolTranscoder.php

@@ -25,6 +25,7 @@ class BxDolTranscoder extends BxDol implements iBxDolFactoryObject
     protected $_sRetinaSuffix = '@2x'; ///< handler suffix for retina image file
     protected $_sRetinaSuffix = '@2x'; ///< handler suffix for retina image file
     protected $_sQueueTable = ''; ///< table with queued files for transcoding
     protected $_sQueueTable = ''; ///< table with queued files for transcoding
     protected $_sQueueStorage = ''; ///< storage object to storage temporary files
     protected $_sQueueStorage = ''; ///< storage object to storage temporary files
+    protected $_iDevicePixelRatio = false; ///< force device pixel ratio, 1 or 2
 
 
     /**
     /**
      * constructor
      * constructor
@@ -468,8 +469,21 @@ class BxDolTranscoder extends BxDol implements iBxDolFactoryObject
         return $iCount;
         return $iCount;
     }
     }
 
 
+    public function forceDevicePixelRatio ($i)
+    {
+        if (!$i)
+            $this->_iDevicePixelRatio = false;
+        elseif ($i >= 2) 
+            $this->_iDevicePixelRatio = 2;
+        else
+            $this->_iDevicePixelRatio = 1;
+    }
+
     public function getDevicePixelRatio ()
     public function getDevicePixelRatio ()
     {
     {
+        if ($this->_iDevicePixelRatio)
+            return $this->_iDevicePixelRatio;
+
         if (isset($_COOKIE['devicePixelRatio']) && (!isset($this->_aObject['source_params']['disable_retina']) || !$this->_aObject['source_params']['disable_retina'])) {
         if (isset($_COOKIE['devicePixelRatio']) && (!isset($this->_aObject['source_params']['disable_retina']) || !$this->_aObject['source_params']['disable_retina'])) {
             $iDevicePixelRatio = intval($_COOKIE['devicePixelRatio']);
             $iDevicePixelRatio = intval($_COOKIE['devicePixelRatio']);
             if ($iDevicePixelRatio >= 2)
             if ($iDevicePixelRatio >= 2)