예제 #1
0
 /**
  * @param string $data
  * @param string $target
  *
  * @return string
  */
 public function minifyJsCss($data, $target)
 {
     if ($this->isYUICompressEnabled() && $this->isCompressEnabled()) {
         Minify_YUICompressor::$jarFile = Mage::getBaseDir() . DS . 'lib' . DS . 'yuicompressor' . DS . 'yuicompressor.jar';
         Minify_YUICompressor::$tempDir = realpath(sys_get_temp_dir());
     }
     $YUICompressorFailed = false;
     switch (pathinfo($target, PATHINFO_EXTENSION)) {
         case 'js':
             if ($this->isYUICompressEnabled() && $this->isCompressEnabled()) {
                 try {
                     Varien_Profiler::start('Minify_YUICompressor::minifyJs');
                     $data = Minify_YUICompressor::minifyJs($data);
                     Varien_Profiler::stop('Minify_YUICompressor::minifyJs');
                     $YUICompressorFailed = false;
                 } catch (Exception $e) {
                     Mage::log(Minify_YUICompressor::$yuiCommand);
                     Mage::logException($e);
                     $YUICompressorFailed = true;
                 }
             }
             if (!$this->isYUICompressEnabled() && $this->isCompressEnabled() || $YUICompressorFailed === true && $this->isCompressEnabled()) {
                 Varien_Profiler::start('Minify_JSMin::minify');
                 $data = Minify_JSMin::minify($data);
                 Varien_Profiler::stop('Minify_JSMin::minify');
             }
             break;
         case 'css':
             if ($this->isYUICompressEnabled() && $this->isCompressEnabled()) {
                 try {
                     Varien_Profiler::start('Minify_YUICompressor::minifyCss');
                     $data = Minify_YUICompressor::minifyCss($data);
                     Varien_Profiler::stop('Minify_YUICompressor::minifyCss');
                     $YUICompressorFailed = false;
                 } catch (Exception $e) {
                     Mage::log(Minify_YUICompressor::$yuiCommand);
                     Mage::logException($e);
                     $YUICompressorFailed = true;
                 }
             }
             if (!$this->isYUICompressEnabled() && $this->isCompressEnabled() || $YUICompressorFailed === true && $this->isCompressEnabled()) {
                 Varien_Profiler::start('Minify_Css_Compressor::process');
                 $data = Minify_Css_Compressor::process($data);
                 Varien_Profiler::stop('Minify_Css_Compressor::process');
             }
             break;
         default:
             return false;
     }
     return $data;
 }
예제 #2
0
 public function minifyJsCss($data, $target)
 {
     if ($this->canMinifyCss() || $this->canMinifyJs()) {
         if ($this->isYUICompressEnabled()) {
             Minify_YUICompressor::$jarFile = Mage::getBaseDir() . DS . 'bin' . DS . 'yuicompressor-2.4.7.jar';
             Minify_YUICompressor::$tempDir = realpath(sys_get_temp_dir());
         }
         switch (pathinfo($target, PATHINFO_EXTENSION)) {
             case 'js':
                 if ($this->canMinifyJs()) {
                     if ($this->isYUICompressEnabled()) {
                         try {
                             $data = Minify_YUICompressor::minifyJs($data);
                             $YUICompressorFailed = false;
                         } catch (Exception $e) {
                             Mage::logException($e);
                             $YUICompressorFailed = true;
                         }
                     }
                     if (!$this->isYUICompressEnabled() || $YUICompressorFailed) {
                         $data = Minify_JSMin::minify($data);
                     }
                 }
                 break;
             case 'css':
                 if ($this->canMinifyCss()) {
                     if ($this->isYUICompressEnabled()) {
                         try {
                             $data = Minify_YUICompressor::minifyCss($data);
                             $YUICompressorFailed = false;
                         } catch (Exception $e) {
                             Mage::logException($e);
                             $YUICompressorFailed = true;
                         }
                     }
                     if (!$this->isYUICompressEnabled() || $YUICompressorFailed) {
                         $data = Minify_Css_Compressor::process($data);
                     }
                 }
                 break;
             default:
                 return false;
         }
     }
     return $data;
 }