You must set $jarFile and $tempDir before calling the minify functions.
Also, depending on your shell's environment, you may need to specify
the full path to java in $javaExecutable or use putenv() to setup the
Java environment.
Minify_YUICompressor::$jarFile = '/path/to/yuicompressor-2.4.6.jar';
Minify_YUICompressor::$tempDir = '/tmp';
$code = Minify_YUICompressor::minifyJs(
$code
,array('nomunge' => true, 'line-break' => 1000)
);
Note: In case you run out stack (default is 512k), you may increase stack size in $options:
array('stack-size' => '2048k')
function yuiJs($js) { require_once 'Minify/YUICompressor.php'; Minify_YUICompressor::$jarFile = dirname(__FILE__) . '/lib/yuicompressor-2.4.2.jar'; Minify_YUICompressor::$tempDir = GLOBAL_ROOT_PATH . $core->sysConfig->path->cache->min; return Minify_YUICompressor::minifyJs($js); }
function test_Minify_YuiCSS() { if (!is_file(MINIFY_TESTS_YUICOMPRESSOR_JAR_FILE)) { echo " Minify_YUICompressor : To test this, install the .jar file and customize the constant in:\n"; echo " " . __FILE__ . "\n"; return; } Minify_YUICompressor::$jarFile = MINIFY_TESTS_YUICOMPRESSOR_JAR_FILE; Minify_YUICompressor::$tempDir = sys_get_temp_dir(); $src = "/* stack overflow test */\n div.image {\n width: 100px;\n height: 100px;\n background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAALCAYAAABGbhwYAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJk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4bXAuZGlkOkM0RjRBMzAwNTY3NzExRTI5Q0IwRjk3N0M3OUY3ODcxIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+2Di36AAAALBJREFUeNpi+P//PwMQ60NpdMwIxAYgNogTBsQHgNgGi0IVIN4CxH4whSDwAk2xLBCvh8odhgmuRlNsCMSboWLHgDgE2Zp5SIrXQNlXgNgI5kZkh9+AKvgGpZWAmAUkz8SAADxAfAfK5oTS7ED8B8yCmqYOxOuA+AcQXwDiJVATn8I8CFIUCA0CmMNNoZqXILnZHiQQjeRwU7RwhCk+xAB17A4gdgFiNiyBDlKcBBBgAG/qVav+VuC1AAAAAElFTkSuQmCC')}"; // fails with java.lang.StackOverflowError as of Yui 2.4.6 // unfortunately error output is not caught from yui, so have to guess try { $minOutput = Minify_YUICompressor::minifyCss($src); echo " Minify_YUICompressor : Correctly handles input which caused stack overflow in 2.4.6\n"; } catch (Exception $e) { assertTrue($e->getMessage() == 'Minify_YUICompressor : YUI compressor execution failed.', 'Minify_YUICompressor : got expected Exception'); } try { $options = array('stack-size' => '2m'); $minOutput = Minify_YUICompressor::minifyCss($src, $options); } catch (Exception $e) { assertTrue(false, $e->getMessage()); $minOutput = false; } $passed = assertTrue($minExpected == $minOutput, 'Minify_YUICompressor : Overall'); if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) { echo "\n---Output: " . countBytes($minOutput) . " bytes\n\n{$minOutput}\n\n"; echo "---Expected: " . countBytes($minExpected) . " bytes\n\n{$minExpected}\n\n"; echo "---Source: " . countBytes($src) . " bytes\n\n{$src}\n\n\n"; } }
/** * @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; }
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; }
public function minify($js) { try { if ($this->conf->outputfilters->javascriptminifyalgorithm == "jsminplus") { $js = JSMinPlus::minify($js); } else { if ($this->conf->outputfilters->javascriptminifyalgorithm == "yuicompressor") { Minify_YUICompressor::$tempDir = PIMCORE_TEMPORARY_DIRECTORY; Minify_YUICompressor::$jarFile = PIMCORE_PATH . "/lib/Minify/yuicompressor-2.4.2.jar"; $js = Minify_YUICompressor::minifyJs($js); } else { $js = JSMin::minify($js); } } } catch (Exception $e) { Logger::error("Unable to minify javascript"); Logger::error($e); } return $js; }
/** * Test minifier action * * @return void */ function action_test_minifier() { w3_require_once(W3TC_LIB_W3_DIR . '/Request.php'); $engine = W3_Request::get_string('engine'); $path_java = W3_Request::get_string('path_java'); $path_jar = W3_Request::get_string('path_jar'); $result = false; $error = ''; if (!$path_java) { $error = __('Empty JAVA executable path.', 'w3-total-cache'); } elseif (!$path_jar) { $error = __('Empty JAR file path.', 'w3-total-cache'); } else { switch ($engine) { case 'yuijs': w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/YUICompressor.php'); Minify_YUICompressor::setPathJava($path_java); Minify_YUICompressor::setPathJar($path_jar); $result = Minify_YUICompressor::testJs($error); break; case 'yuicss': w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/YUICompressor.php'); Minify_YUICompressor::setPathJava($path_java); Minify_YUICompressor::setPathJar($path_jar); $result = Minify_YUICompressor::testCss($error); break; case 'ccjs': w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/ClosureCompiler.php'); Minify_ClosureCompiler::setPathJava($path_java); Minify_ClosureCompiler::setPathJar($path_jar); $result = Minify_ClosureCompiler::test($error); break; default: $error = __('Invalid engine.', 'w3-total-cache'); break; } } $response = array('result' => $result, 'error' => $error); echo json_encode($response); }
$core_files[$core_name] .= Minify_CSS::minify(file_get_contents($filePath), array( 'currentDir' => dirname($filePath) )); */ //echo "Proccessing: $filePath<br />\n"; $full_script_size[$core_name] += getFileSize($filePath); $core_files[$core_name] .= Minify_CSS_UriRewriter::rewrite(file_get_contents($filePath), dirname($filePath)); //$core_files[$core_name] .= Minify_YUICompressor::minifyCss(file_get_contents($filePath), array()); // $core_files[$core_name] .= Minify_ClosureStylesheets::minify(file_get_contents($filePath), array()); } else { $errors[] = "Unable to find CSS file for {$core_name}: {$filePath}"; break; } } if (!count($errors)) { $core_files[$core_name] = Minify_YUICompressor::minifyCss($core_files[$core_name], array()); // //$core_files[$core_name] = Minify_ClosureStylesheets::minify($core_files[$core_name], array()); /* if($core_name == "core_dining.css"){ $result = $cssTidy->parse($core_files[$core_name]); if($result){ $core_files[$core_name] = $cssTidy->print->plain(); } else { $errors[] = "Error compressing with CSS Tidy!"; } die(); } * */ }
/** * Initializes minifier * * @param string $engine * @return void */ function init($engine) { switch ($engine) { case 'js': w3_require_once(W3TC_LIB_MINIFY_DIR . '/JSMin.php'); break; case 'css': w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/CSS.php'); break; case 'yuijs': w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/YUICompressor.php'); Minify_YUICompressor::setPathJava($this->_config->get_string('minify.yuijs.path.java')); Minify_YUICompressor::setPathJar($this->_config->get_string('minify.yuijs.path.jar')); break; case 'yuicss': w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/YUICompressor.php'); Minify_YUICompressor::setPathJava($this->_config->get_string('minify.yuicss.path.java')); Minify_YUICompressor::setPathJar($this->_config->get_string('minify.yuicss.path.jar')); break; case 'ccjs': w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/ClosureCompiler.php'); Minify_ClosureCompiler::setPathJava($this->_config->get_string('minify.ccjs.path.java')); Minify_ClosureCompiler::setPathJar($this->_config->get_string('minify.ccjs.path.jar')); break; case 'csstidy': w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/CSSTidy.php'); break; case 'html': case 'htmlxml': w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/HTML.php'); break; case 'htmltidy': case 'htmltidyxml': w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/HTMLTidy.php'); break; } }
<?php require_once '2.1.3/min/lib/Minify/YUICompressor.php'; /** * only if server is capable of executing JAR files!!! */ class LBoxMinify_YUICompressor extends Minify_YUICompressor { } /* set jar file path */ Minify_YUICompressor::$jarFile = ""; Minify_YUICompressor::$tempDir = LBOX_PATH_CACHE . "/minify";
protected function _yui_compression_css($script) { if ($this->config->item('output.package.enable') == false) { return $script; } $this->load->library('web_apps/Minify_YUICompressor'); $packed = Minify_YUICompressor::minifyCss($script); return $packed; }
protected function buildScript() { $pkgHandle = FRONTEND_DEVELOPER_PACKAGE_HANDLE; Loader::library("3rdparty/jsminify/JSMin", $pkgHandle); Loader::library("3rdparty/jsminify/Minify/YUICompressor", $pkgHandle); Loader::model('file_list'); $fh = Loader::helper('file'); $files = $this->post("module"); $packType = $this->post("packType"); $output = ""; $pl = new MootoolsPluginList(); foreach ($files as $key => $fID) { $file = File::getByID($fID); $output .= file_get_contents($file->getPath()) . "\n"; } switch ($packType) { case MootoolsPluginBuildFormBlockController::PACKTYPE_JSMin_COMPRESSOR: $output = JSMin::minify($output); break; case MootoolsPluginBuildFormBlockController::PACKTYPE_NO_COMPRESSOR: break; case MootoolsPluginBuildFormBlockController::PACKTYPE_YUI_COMPRESSOR: default: $yui = DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_LIBRARIES . '/' . '3rdparty/yui/yuicompressor-2.4.2.jar'; $tmp = $fh->getTemporaryDirectory() . '/'; Minify_YUICompressor::$jarFile = $yui; Minify_YUICompressor::$tempDir = $tmp; $output = Minify_YUICompressor::minifyJs($output); } $output = $this->header . "\n" . $output; $file = $this->javascript . ".js"; header("Content-disposition: attachment; filename=" . $file); header("Content-type: application/octet-stream; name=" . $file); echo $output; exit; }
protected function _yui_compression_css($script) { if ($this->_is_config_package_enable() == false) { return $script; } $this->load->library('web_apps/Minify_YUICompressor'); $packed = Minify_YUICompressor::minifyCss($script); return $packed; }
/** * override method: get content of css files */ function getCssContents($files, $isCompressed = true, $isYUI = false) { $contents = "/**ICE-ENGINE-CSS**/"; foreach ($files as $key => $file) { $subpath = str_replace('/', DS, $file); $fullpath = JPATH_ROOT . DS . $subpath; $basepath = preg_replace('/^\\//', '', dirname($this->getRequestURI() . $file)); $contentFile = ''; if (preg_match('/\\.php/', $file)) { $contentFile = @file_get_contents(JURI::base() . str_replace("&", "&", $file)); } else { if (file_exists($fullpath)) { // get Content Of File; $contentFile = @file_get_contents($fullpath); } } if ($contentFile) { //$contentFile = str_replace('url(..', 'url(/'.dirname($basepath), $contentFile ); //$contentFile = str_replace('url(\'..', 'url(\'/'.dirname($basepath), $contentFile ); //$contentFile = str_replace('url("..', 'url("/'.dirname($basepath), $contentFile ); $contentFile = str_replace('url("', 'url("123', $contentFile); $contentFile = str_replace('url(\'', 'url(\'123', $contentFile); $contentFile = str_replace('url(', 'url(123', $contentFile); $path = dirname($this->getRequestURI() . $file) . '/'; $contentFile = str_replace('url(123../', 'url(' . dirname($path) . '/', $contentFile); $contentFile = str_replace('url(\'123../', 'url(\'' . dirname($path) . '/', $contentFile); $contentFile = str_replace('url("123../', 'url("' . dirname($path) . '/', $contentFile); $contentFile = str_replace('url(123\'123', 'url(\'' . $path, $contentFile); $contentFile = str_replace('url(123"123', 'url("' . $path, $contentFile); $contentFile = str_replace('url(123', 'url(' . $path, $contentFile); // start clean up file $contents .= "/** '.{$subpath}.' **/\t"; $contents .= $this->cleanUpText($contentFile); } } if ($isCompressed) { if ($isYUI) { $app =& JFactory::getApplication(); Minify_YUICompressor::$jarFile = dirname(__FILE__) . DS . 'Minify' . DS . 'yuicompressor-2.4.6.jar'; Minify_YUICompressor::$tempDir = $app->getCfg("tmp_path"); $contents = Minify_YUICompressor::minifyCss($contents, array('nomunge' => true, 'line-break' => 1000)); } else { $contents = Minify_CSS::process($contents); } } return $contents; }
/** * @param $type * @param $content * @param $options * * @return string * @throws Exception */ protected static function _minify($type, $content, $options) { self::_prepare(); if (!($tmpFile = tempnam(self::$tempDir, 'yuic_'))) { throw new Exception('Minify_YUICompressor : could not create temp file.'); } file_put_contents($tmpFile, $content); self::$yuiCommand = self::_getCmd($options, $type, $tmpFile); $result_code = 0; $output = array(); exec(self::$yuiCommand, $output, $result_code); unlink($tmpFile); if ((int) $result_code !== 0) { throw new Exception('Minify_YUICompressor : YUI compressor execution failed.'); } return implode("\n", $output); }
/** * Returns compressed content (done with given compression type, see constants) * @param string $content * @param string $method * @return string */ private function compress($content, $method) { switch ($method) { case self::CSS_MINIFY: require_once t3lib_extMgm::extPath('queo_speedup', 'res/Minify_CSS_Compressor.php'); return Minify_CSS_Compressor::process($content); break; case self::CSS_YIU: require_once t3lib_extMgm::extPath('queo_speedup', 'res/YUICompressor.php'); $this->configureYUI($this->conf); return Minify_YUICompressor::minifyCSS($content, array('nomunge' => true, 'line-break' => 1000)); break; case self::JS_YUI: require_once t3lib_extMgm::extPath('queo_speedup', 'res/YUICompressor.php'); $this->configureYUI($this->conf); return Minify_YUICompressor::minifyJs($content, array('line-break' => 1000)); break; case self::JS_MIN: require_once PATH_typo3 . 'contrib/jsmin/jsmin.php'; return JSMin::minify($content); break; case self::JS_MINPLUS: require_once t3lib_extMgm::extPath('queo_speedup', 'res/JSMinPlus.php'); return JSMinPlus::minify($content); break; default: case self::NO_COMPRESSION: //unknown compression type return $content; break; } }
/** * 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); }
public static function testCss(&$error) { try { Minify_YUICompressor::minifyCss('p{color:red}'); $error = 'OK'; return true; } catch (Exception $exception) { $error = $exception->getMessage(); return false; } }
/** * 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; } }
fclose($fp); } echo "Finished building {$OUTPUT_DIR}{$OUTPUT_FILE} (" . filesize($OUTPUT_DIR . $OUTPUT_FILE) . " bytes): Took " . (microtime_float() - $time_start) . "s\n\n"; fclose($fpOut); echo "Building Compressed File: {$OUTPUT_DIR}{$OUTPUT_FILE_COMPRESSED}\n\r"; $time_start = microtime_float(); Minify_YUICompressor::$jarFile = $YUI_COMPRESSOR_JAR; Minify_YUICompressor::$tempDir = $TMP_DIR; Minify_YUICompressor::$javaExecutable = $JDK_HOME . "/bin/java"; $fp = fopen($OUTPUT_DIR . $OUTPUT_FILE, "r"); $uncompressed = ""; while (!feof($fp)) { $uncompressed .= fgets($fp); } fclose($fp); $compressed = Minify_YUICompressor::minifyJs($uncompressed, array()); $fp = fopen($OUTPUT_DIR . $OUTPUT_FILE_COMPRESSED, "w"); fwrite($fp, $compressed); fclose($fp); echo "Finished building {$OUTPUT_DIR}{$OUTPUT_FILE_COMPRESSED} (" . filesize($OUTPUT_DIR . $OUTPUT_FILE_COMPRESSED) . " bytes): Took " . (microtime_float() - $time_start) . "s\n"; echo "\nCopying Resources to {$OUTPUT_DIR}{$OUTPUT_RESOURCES}\n"; if (!is_dir($OUTPUT_DIR . $OUTPUT_RESOURCES)) { mkdir($OUTPUT_DIR . 'resources'); } copydir($RESOURCES_DIR, $OUTPUT_DIR . $OUTPUT_RESOURCES); echo "\nCopying Documentation to {$OUTPUT_DIR}{$OUTPUT_DOCUMENTATION}\n"; if (!is_dir($OUTPUT_DIR . $OUTPUT_DOCUMENTATION)) { mkdir($OUTPUT_DIR . $OUTPUT_DOCUMENTATION); } copydir($DOCUMENTATION_DIR, $OUTPUT_DIR . $OUTPUT_DOCUMENTATION, '*'); echo "\nCopying Libraries to {$OUTPUT_DIR}{$OUTPUT_LIBS}\n";
public static function setPathJar($pathJar) { self::$_pathJar = $pathJar; }