Index: minify_helper.php =================================================================== --- minify_helper.php (revision 14836) +++ minify_helper.php (working copy) @@ -182,35 +182,57 @@ */ public function compressString(&$string, $extension) { - $tmp_file = tempnam('/tmp', 'to_compress_'); - $fp = fopen($tmp_file, 'w'); - fwrite($fp, $string); - fclose($fp); + $vars = kUtil::getConfigVars(); - $command = 'java -jar ' . dirname(__FILE__) . DIRECTORY_SEPARATOR . 'yuicompressor-2.4.2.jar --type ' . $extension . ' --charset utf-8 ' . $tmp_file; - $compressed_string = shell_exec($command); + if ( !array_key_exists('CompressionEngine', $vars) ) { + // compression method not specified - use none + return; + } - unlink($tmp_file); + switch ( $vars['CompressionEngine'] ) { + case 'yui': + $this->compressViaJava($string, $extension); + break; - if (!is_null($compressed_string) && $compressed_string) { - $string = $compressed_string; - return ; + case 'php': + $this->compressViaPHP($string, $extension); + break; } + } - // failed to compress using YUICompressor (maybe java not installed) + /** + * Compresses string using YUI compressor (uses Java) + * + * @param string $string + * @param string $extension + * @return void + * @access protected + */ + protected function compressViaJava(&$string, $extension) + { + $tmp_file = tempnam('/tmp', 'to_compress_'); + file_put_contents($tmp_file, $string); - if ($extension == 'js') { - $minifier =& $this->Application->makeClass('JsMinifyHelper'); - /* @var $minifier JsMinifyHelper */ + $command = 'java -jar ' . dirname(__FILE__) . DIRECTORY_SEPARATOR . 'yuicompressor-2.4.2.jar --type ' . $extension . ' --charset utf-8 ' . $tmp_file; + $string = shell_exec($command); - $string = $minifier->minify($string); - } - elseif ($extension == 'css') { - $minifier =& $this->Application->makeClass('CssMinifyHelper'); - /* @var $minifier CssMinifyHelper */ + unlink($tmp_file); + } - $string = $minifier->minify($string); - } + /** + * Compresses string using PHP compressor + * + * @param string $string + * @param string $extension + * @return void + * @access protected + */ + protected function compressViaPHP(&$string, $extension) + { + $minifier =& $this->Application->makeClass($extension == 'js' ? 'JsMinifyHelper' : 'CssMinifyHelper'); + /* @var $minifier JsMinifyHelper */ + + $string = $minifier->minify($string); } /**