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+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDo1RDg4RDYwQzU2N0ExMUUyOUNCMEY5NzdD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uC1AAAAAElFTkSuQmCC')}"; // 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"; } }
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); }
/** * Configures YUI compressor. * @param array $conf typoscript options */ private function configureYUI($conf) { if ($conf['jarpath.']['isrelative'] && $conf['jarpath.']['isrelative'] == 1) { $conf['jarpath'] = $_SERVER['DOCUMENT_ROOT'] . $conf['jarpath']; } Minify_YUICompressor::$jarFile = $conf['jarpath']; Minify_YUICompressor::$tempDir = $conf['tmpdir']; //sys_get_temp_dir(); Minify_YUICompressor::$javaExecutable = $conf['javapath']; }
/** * @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; }
foreach ($src as $i => $fn) { echo "- Reading {$fn}\n"; $fp = fopen($fn, "r") or die("Failed: Cannot open {$fn}"); $contents = ""; while (!feof($fp)) { $contents .= fgets($fp); } $contents = substr($contents, strpos($contents, "*/") + 2); fwrite($fpOut, $contents); 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)) {
//$pathToClosureStylesheets = $pathToLib.'/closure-stylesheets-custom.jar'; $pathToAssets = dirname(dirname(__FILE__)); $pathToRoot = dirname(dirname(dirname(dirname(__FILE__)))); $baseVersionFile = $pathToAssets + "/script.ver"; //$pathToCss = $pathToAssets . '/stylesheets/sitewide.css'; $getScripts = "http://" . $_SERVER['HTTP_HOST'] . "/v5/servlet/getScripts"; $pathToCore = $pathToAssets . '/core'; if (!file_exists($pathToTmp)) { if (!mkdir($pathToTmp)) { die('unable to create tmp folder'); } } // Set up Minify require "{$pathToLib}/Minify/Loader.php"; Minify_Loader::register(); Minify_YUICompressor::$jarFile = $pathToYui; Minify_YUICompressor::$tempDir = $pathToTmp; Minify_ClosureCompiler::$jarFile = $pathToClosureCompiler; Minify_ClosureCompiler::$tempDir = $pathToTmp; Minify_ClosureStylesheets::$jarFile = $pathToClosureStylesheets; Minify_ClosureStylesheets::$tempDir = $pathToTmp; // Set up CSSTidy define('ABSPATH', $pathToCssTidy); require $pathToCssTidy . '/class.csstidy.php'; require $pathToCssTidy . '/lang.inc.php'; /* $css->settings['optimise_shorthands'] = true; $css->settings['template'] = 'highest'; //$css->settings['css_level'] = 'CSS3.1'; $css->settings['remove_bslash'] = true; $css->settings['compress_colors'] = true;
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; }
/** * 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); }
/** * 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; } }
<?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";
/** * 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; }