Example #1
0
 /**
  * Make sure merger dir exists and writeable
  * Also can clean it up
  *
  * @param string $dirRelativeName
  * @param bool $cleanup
  * @return bool|string
  */
 public function initMergerDir($dirRelativeName, $cleanup = false)
 {
     $mediaDir = Mage::getBaseDir('media');
     try {
         $dir = Mage::getBaseDir('media') . DS . $dirRelativeName;
         if ($cleanup) {
             Diglin_Io_File::rmdirRecursive($dir);
         }
         if (!is_dir($dir)) {
             mkdir($dir);
         }
         return is_writeable($dir) ? $dir : false;
     } catch (Exception $e) {
         Mage::logException($e);
     }
     return false;
 }
Example #2
0
 /**
  * Compress JS files and write them to media/js folders
  * 
  * @param string $name
  * @param string|array $mergeCallback
  * @param bool $static
  * @return string
  */
 protected function _prepareJsCompression($name, $mergeCallback = null, $static = false)
 {
     $config = Mage::getStoreConfig('uioptimization/jscompression');
     $uiHelper = Mage::helper('uioptimization');
     $options = array();
     $info = $uiHelper->getCompressedInfo($name, 'js', $static);
     if (!isset($info['result']) || $info['result'] != false) {
         $info['result'] = true;
     }
     if (!file_exists($info['targetPathFile']) && $info['result'] || !Mage::getStoreConfigFlag('uioptimization/general/cronupdate') && $info['result'] && filemtime($info['orgskin_path']) > filemtime($info['targetPathFile'])) {
         switch ($config['type']) {
             case 'packer':
                 $minifier = 'Diglin_Minify_Packer';
                 $method = 'minify';
                 break;
             case 'yuicompressor':
                 $minifier = 'Diglin_Minify_YUICompressor';
                 $method = 'minifyJs';
                 Diglin_Minify_YUICompressor::$jarFile = Mage::getBaseDir('lib') . DS . 'Diglin' . DS . 'yuicompressor' . DS . 'yuicompressor.jar';
                 Diglin_Minify_YUICompressor::$tempDir = Mage::getBaseDir('tmp');
                 if (strlen($config['java_path']) > 0) {
                     Diglin_Minify_YUICompressor::$javaExecutable = $config['java_path'];
                 }
                 $options = array('minifierOptions' => array(Diglin_Minify::TYPE_JS => array('disable-optimizations' => $config['disable_alloptimisation'], 'preserve-semi' => $config['preserve_semic'], 'nomunge' => $config['minify_only'])));
                 break;
             case 'jsmin':
             default:
                 $minifier = 'Diglin_JSMin';
                 $method = 'minify';
                 break;
         }
         $options += array('quiet' => true, 'minifiers' => array(Diglin_Minify::TYPE_JS => array($minifier, $method)), 'files' => array($info['orgskin_path']), 'encodeMethod' => '');
         $results = Diglin_Minify::serve('Files', $options);
         if ($results['success']) {
             $io = new Diglin_Io_File();
             $info['result'] = $io->write($info['targetPathFile'], $results['content'], 0644);
         } else {
             $info['result'] = false;
         }
     }
     return $uiHelper->getResultPath($info, $mergeCallback);
 }