/**
  * Test minifier action
  *
  * @return void
  */
 function w3tc_test_minifier()
 {
     $engine = Util_Request::get_string('engine');
     $path_java = Util_Request::get_string('path_java');
     $path_jar = Util_Request::get_string('path_jar');
     $result = false;
     $error = '';
     if ($engine != 'googleccjs') {
         if (!$path_java) {
             $error = __('Empty JAVA executable path.', 'w3-total-cache');
         } elseif (!$path_jar) {
             $error = __('Empty JAR file path.', 'w3-total-cache');
         }
     }
     if (empty($error)) {
         switch ($engine) {
             case 'yuijs':
                 Minify_YUICompressor::$tempDir = Util_File::create_tmp_dir();
                 Minify_YUICompressor::$javaExecutable = $path_java;
                 Minify_YUICompressor::$jarFile = $path_jar;
                 $result = Minify_YUICompressor::testJs($error);
                 break;
             case 'yuicss':
                 Minify_YUICompressor::$tempDir = Util_File::create_tmp_dir();
                 Minify_YUICompressor::$javaExecutable = $path_java;
                 Minify_YUICompressor::$jarFile = $path_jar;
                 $result = Minify_YUICompressor::testCss($error);
                 break;
             case 'ccjs':
                 Minify_ClosureCompiler::$tempDir = Util_File::create_tmp_dir();
                 Minify_ClosureCompiler::$javaExecutable = $path_java;
                 Minify_ClosureCompiler::$jarFile = $path_jar;
                 $result = Minify_ClosureCompiler::test($error);
                 break;
             case 'googleccjs':
                 $result = Minify_JS_ClosureCompiler::test($error);
                 break;
             default:
                 $error = __('Invalid engine.', 'w3-total-cache');
                 break;
         }
     }
     $response = array('result' => $result, 'error' => $error);
     echo json_encode($response);
 }
示例#2
0
 /**
  * Atomically writes file inside W3TC_CACHE_DIR dir
  *
  * @param unknown $filename
  * @param unknown $content
  * @throws Exception
  * @return void
  */
 public static function file_put_contents_atomic($filename, $content)
 {
     Util_File::create_tmp_dir();
     $temp = tempnam(W3TC_CACHE_TMP_DIR, 'temp');
     try {
         if (!($f = @fopen($temp, 'wb'))) {
             if (file_exists($temp)) {
                 @unlink($temp);
             }
             throw new \Exception('Can\'t write to temporary file <strong>' . $temp . '</strong>');
         }
         fwrite($f, $content);
         fclose($f);
         if (!@rename($temp, $filename)) {
             @unlink($filename);
             if (!@rename($temp, $filename)) {
                 Util_File::mkdir_from(dirname($filename), W3TC_CACHE_DIR);
                 if (!@rename($temp, $filename)) {
                     throw new \Exception('Can\'t write to file <strong>' . $filename . '</strong>');
                 }
             }
         }
         $chmod = 0644;
         if (defined('FS_CHMOD_FILE')) {
             $chmod = FS_CHMOD_FILE;
         }
         @chmod($filename, $chmod);
     } catch (\Exception $ex) {
         if (file_exists($temp)) {
             @unlink($temp);
         }
         throw $ex;
     }
 }
 /**
  * Initializes minifier
  *
  * @param string  $engine
  * @return void
  */
 function init($engine)
 {
     switch ($engine) {
         case 'yuijs':
             Minify_YUICompressor::$tempDir = Util_File::create_tmp_dir();
             Minify_YUICompressor::$javaExecutable = $this->_config->get_string('minify.yuijs.path.java');
             Minify_YUICompressor::$jarFile = $this->_config->get_string('minify.yuijs.path.jar');
             break;
         case 'yuicss':
             Minify_YUICompressor::$tempDir = Util_File::create_tmp_dir();
             Minify_YUICompressor::$javaExecutable = $this->_config->get_string('minify.yuicss.path.java');
             Minify_YUICompressor::$jarFile = $this->_config->get_string('minify.yuicss.path.jar');
             break;
         case 'ccjs':
             Minify_ClosureCompiler::$tempDir = Util_File::create_tmp_dir();
             Minify_ClosureCompiler::$javaExecutable = $this->_config->get_string('minify.ccjs.path.java');
             Minify_ClosureCompiler::$jarFile = $this->_config->get_string('minify.ccjs.path.jar');
             break;
     }
 }