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"; } }
public static function testCss(&$error) { try { Minify_YUICompressor::minifyCss('p{color:red}'); $error = 'OK'; return true; } catch (Exception $exception) { $error = $exception->getMessage(); return false; } }
/** * @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; }
$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(); } * */ }
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 _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; }