本文整理汇总了PHP中Minify_CSS_Compressor类的典型用法代码示例。如果您正苦于以下问题:PHP Minify_CSS_Compressor类的具体用法?PHP Minify_CSS_Compressor怎么用?PHP Minify_CSS_Compressor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Minify_CSS_Compressor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* Minify a CSS string
*
* @param string $css
*
* @param array $options (currently ignored)
*
* @return string
*/
public static function process($css, $options = array())
{
static $instance;
if (!$instance) {
$instance = new Minify_CSS_Compressor($options);
}
return $instance->_process($css);
}
示例2: minify
/**
* Minify a CSS string
*
* @param string $css
*
* @param array $options available options:
*
* 'preserveComments': (default true) multi-line comments that begin
* with "/*!" will be preserved with newlines before and after to
* enhance readability.
*
* 'removeCharsets': (default true) remove all @charset at-rules
*
* 'prependRelativePath': (default null) if given, this string will be
* prepended to all relative URIs in import/url declarations
*
* 'currentDir': (default null) if given, this is assumed to be the
* directory of the current CSS file. Using this, minify will rewrite
* all relative URIs in import/url declarations to correctly point to
* the desired files. For this to work, the files *must* exist and be
* visible by the PHP process.
*
* 'symlinks': (default = array()) If the CSS file is stored in
* a symlink-ed directory, provide an array of link paths to
* target paths, where the link paths are within the document root. Because
* paths need to be normalized for this to work, use "//" to substitute
* the doc root in the link paths (the array keys). E.g.:
* <code>
* array('//symlink' => '/real/target/path') // unix
* array('//static' => 'D:\\staticStorage') // Windows
* </code>
*
* 'docRoot': (default = $_SERVER['DOCUMENT_ROOT'])
* see Minify_CSS_UriRewriter::rewrite
*
* @return string
*/
public static function minify($css, $options = array())
{
$options = array_merge(array('compress' => true, 'removeCharsets' => true, 'preserveComments' => true, 'currentDir' => null, 'docRoot' => $_SERVER['DOCUMENT_ROOT'], 'prependRelativePath' => null, 'symlinks' => array()), $options);
if ($options['removeCharsets']) {
$css = preg_replace('/@charset[^;]+;\\s*/', '', $css);
}
if ($options['compress']) {
if (!$options['preserveComments']) {
require_once 'Compressor.php';
$css = Minify_CSS_Compressor::process($css, $options);
} else {
require_once 'CommentPreserver.php';
require_once 'Compressor.php';
$css = Minify_CommentPreserver::process($css, array('Minify_CSS_Compressor', 'process'), array($options));
}
}
if (!$options['currentDir'] && !$options['prependRelativePath']) {
return $css;
}
require_once 'UriRewriter.php';
if ($options['currentDir']) {
return Minify_CSS_UriRewriter::rewrite($css, $options['currentDir'], $options['docRoot'], $options['symlinks']);
} else {
return Minify_CSS_UriRewriter::prepend($css, $options['prependRelativePath']);
}
}
示例3: minify
/**
* Minify a CSS string
*
* @param string $css
*
* @param array $options available options:
*
* 'preserveComments': (default true) multi-line comments that begin
* with "/*!" will be preserved with newlines before and after to
* enhance readability.
*
* 'prependRelativePath': (default null) if given, this string will be
* prepended to all relative URIs in import/url declarations
*
* 'currentDir': (default null) if given, this is assumed to be the
* directory of the current CSS file. Using this, minify will rewrite
* all relative URIs in import/url declarations to correctly point to
* the desired files. For this to work, the files *must* exist and be
* visible by the PHP process.
*
* 'symlinks': (default = array()) If the CSS file is stored in
* a symlink-ed directory, provide an array of link paths to
* target paths, where the link paths are within the document root. Because
* paths need to be normalized for this to work, use "//" to substitute
* the doc root in the link paths (the array keys). E.g.:
* <code>
* array('//symlink' => '/real/target/path') // unix
* array('//static' => 'D:\\staticStorage') // Windows
* </code>
*
* @return string
*/
static public function minify($css, $options = array())
{
require_once 'Minify/CSS/Compressor.php';
if (isset($options['preserveComments'])
&& !$options['preserveComments']) {
$css = Minify_CSS_Compressor::process($css, $options);
} else {
require_once 'Minify/CommentPreserver.php';
$css = Minify_CommentPreserver::process(
$css
,array('Minify_CSS_Compressor', 'process')
,array($options)
);
}
if (! isset($options['currentDir']) && ! isset($options['prependRelativePath'])) {
return $css;
}
require_once 'Minify/CSS/UriRewriter.php';
if (isset($options['currentDir'])) {
return Minify_CSS_UriRewriter::rewrite(
$css
,$options['currentDir']
,isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT']
,isset($options['symlinks']) ? $options['symlinks'] : array()
);
} else {
return Minify_CSS_UriRewriter::prepend(
$css
,$options['prependRelativePath']
);
}
}
示例4: doProcessFile
public function doProcessFile($file, $replace = false)
{
$optimizedContent = Minify_CSS_Compressor::process(file_get_contents($file));
if ($replace) {
return parent::replaceFile($file, $optimizedContent);
} else {
return $optimizedContent;
}
}
示例5: buildApiCss
private function buildApiCss()
{
// copy file
$this->getFilesystem()->copy(sfConfig::get('sf_web_dir') . '/css/api_sources/button.css', sfConfig::get('sf_web_dir') . '/css/v1/button.css', array('override' => true));
// replace wildcards
$this->getFilesystem()->replaceTokens(sfConfig::get('sf_web_dir') . '/css/v1/button.css', '##', '##', array('YIID_WIDGET_HOST' => sfConfig::get('app_settings_widgets_host'), 'YIID_BUTTON_HOST' => sfConfig::get('app_settings_button_url')));
$lCssMin = Minify_CSS_Compressor::process(file_get_contents(sfConfig::get('sf_web_dir') . '/css/v1/button.css'));
$lCssMinFile = fopen(sfConfig::get('sf_web_dir') . '/css/v1/button.css', 'w+');
$lDone = fwrite($lCssMinFile, $lCssMin);
fclose($lCssMinFile);
}
示例6: minify
/**
* Minify a CSS string
*
* @param string $css
*
* @param array $options available options:
*
* 'preserveComments': (default true) multi-line comments that begin
* with "/*!" will be preserved with newlines before and after to
* enhance readability.
*
* 'removeCharsets': (default true) remove all @charset at-rules
*
* 'prependRelativePath': (default null) if given, this string will be
* prepended to all relative URIs in import/url declarations
*
* 'currentDir': (default null) if given, this is assumed to be the
* directory of the current CSS file. Using this, minify will rewrite
* all relative URIs in import/url declarations to correctly point to
* the desired files. For this to work, the files *must* exist and be
* visible by the PHP process.
*
* 'symlinks': (default = array()) If the CSS file is stored in
* a symlink-ed directory, provide an array of link paths to
* target paths, where the link paths are within the document root. Because
* paths need to be normalized for this to work, use "//" to substitute
* the doc root in the link paths (the array keys). E.g.:
* <code>
* array('//symlink' => '/real/target/path') // unix
* array('//static' => 'D:\\staticStorage') // Windows
* </code>
*
* 'docRoot': (default = $_SERVER['DOCUMENT_ROOT'])
* see Minify_CSS_UriRewriter::rewrite
*
* @return string
*/
public static function minify($css, $options = array())
{
$options = array_merge(array('removeCharsets' => true, 'preserveComments' => true), $options);
if ($options['removeCharsets']) {
$css = preg_replace('/@charset[^;]+;\\s*/', '', $css);
}
if (!$options['preserveComments']) {
$css = Minify_CSS_Compressor::process($css, $options);
} else {
$css = Minify_CommentPreserver::process($css, array('Minify_CSS_Compressor', 'process'), array($options));
}
return $css;
}
示例7: minify
/**
* Minify a CSS string
*
* @param string $css
*
* @param array $options available options:
*
* 'preserveComments': (default true) multi-line comments that begin
* with "/*!" will be preserved with newlines before and after to
* enhance readability.
*
* 'prependRelativePath': (default null) if given, this string will be
* prepended to all relative URIs in import/url declarations
*
* 'currentDir': (default null) if given, this is assumed to be the
* directory of the current CSS file. Using this, minify will rewrite
* all relative URIs in import/url declarations to correctly point to
* the desired files. For this to work, the files *must* exist and be
* visible by the PHP process.
*
* 'symlinks': (default = array()) If the CSS file is stored in
* a symlink-ed directory, provide an array of link paths to
* target paths, where the link paths are within the document root. Because
* paths need to be normalized for this to work, use "//" to substitute
* the doc root in the link paths (the array keys). E.g.:
* <code>
* array('//symlink' => '/real/target/path') // unix
* array('//static' => 'D:\\staticStorage') // Windows
* </code>
*
* @return string
*/
public static function minify($css, $options = array())
{
require_once W3TC_LIB_MINIFY_DIR . '/Minify/CSS/Compressor.php';
if (isset($options['preserveComments']) && $options['preserveComments']) {
require_once W3TC_LIB_MINIFY_DIR . '/Minify/CommentPreserver.php';
$css = Minify_CommentPreserver::process($css, array('Minify_CSS_Compressor', 'process'), array($options));
} else {
$css = Minify_CSS_Compressor::process($css, $options);
}
require_once W3TC_LIB_MINIFY_DIR . '/Minify/CSS/UriRewriter.php';
$css = Minify_CSS_UriRewriter::rewrite($css, $options);
return $css;
}
示例8: min
public function min()
{
$this->_options = array_merge(array('remove_charsets' => true, 'preserve_comments' => true, 'current_dir' => null, 'doc_root' => $_SERVER['DOCUMENT_ROOT'], 'prepend_relative_path' => null, 'symlinks' => array()), $this->_options);
if ($this->_options['remove_charsets']) {
$this->_css = preg_replace('/@charset[^;]+;\\s*/', '', $this->_css);
}
if (!$this->_options['preserve_comments']) {
$this->_css = Minify_CSS_Compressor::process($this->_css, $this->_options);
} else {
$this->_css = Minify_CSS_Comment_Preserver::process($this->_css, array('Minify_CSS_Compressor', 'process'), array($this->_options));
}
if (!$this->_options['current_dir'] && !$this->_options['prepend_relative_path']) {
return $this->_css;
}
if ($this->_options['current_dir']) {
return Minify_CSS_Uri_Rewriter::rewrite($this->_css, $this->_options['current_dir'], $this->_options['doc_root'], $this->_options['symlinks']);
} else {
return Minify_CSS_Uri_Rewriter::prepend($this->_css, $this->_options['prepend_relative_path']);
}
}
示例9: execute
/**
* Execute preprocessor
*
* This will take all CSS files from the source dir, minify each one and
* then combine them into one file.
*
* @param array $options Options for execution
* @return void
*/
public function execute($options = array())
{
$cssFiles = FileOps::rglob("*.css", 0, $this->getSourceDir());
if (empty($cssFiles)) {
return false;
}
FileOps::ensurePathExists($this->getDestinationDir());
// Just get the basename of the main style sheet, this will be written
// to the destination dir
$mainStylesheet = basename($options['main_stylesheet']);
$mainStylesheet = $this->getDestinationDir() . DIRECTORY_SEPARATOR . $mainStylesheet;
$buffer = array();
foreach ($cssFiles as $file) {
$content = file_get_contents($file);
$newContent = \Minify_CSS_Compressor::process($content);
$buffer[] = $newContent;
}
if ($buffer) {
file_put_contents($mainStylesheet, implode("\n", $buffer));
}
}
示例10: doExecute
/**
* doExecute
*
* @return int
*/
protected function doExecute()
{
$path = $this->getArgument(0);
$package = $this->getOption('p');
$folder = $this->console->get('asset.folder', 'asset');
if ($package = PackageHelper::getPackage($package)) {
$path = $package->getDir() . '/Resources/asset/' . $path;
} else {
$path = WINDWALKER_PUBLIC . '/' . trim($folder, '/') . '/' . $path;
}
if (is_file($path)) {
$files = array(new \SplFileInfo($path));
} elseif (is_dir($path)) {
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::FOLLOW_SYMLINKS));
} else {
throw new \InvalidArgumentException('No path');
}
/** @var \SplFileInfo $file */
foreach ($files as $file) {
$ext = File::getExtension($file->getPathname());
if (StringHelper::endsWith($file->getBasename(), '.min.' . $ext)) {
continue;
}
if ($ext == 'css') {
$this->out('[<comment>Compressing</comment>] ' . $file);
$data = \Minify_CSS_Compressor::process(file_get_contents($file));
$data = str_replace("\n", ' ', $data);
} elseif ($ext == 'js') {
$this->out('[<comment>Compressing</comment>] ' . $file);
$data = \JSMinPlus::minify(file_get_contents($file));
$data = str_replace("\n", ';', $data);
} else {
continue;
}
$newName = $file->getPath() . '/' . File::stripExtension($file->getBasename()) . '.min.' . $ext;
file_put_contents($newName, $data);
$this->out('[<info>Compressed</info>] ' . $newName);
}
}
示例11: minify
/**
* @see sfCombineMinifierInterface
*/
public static function minify($content, array $options = array())
{
return Minify_CSS_Compressor::process($content, $options);
}
示例12: _minifyCss
/**
* Minify CSS
*
* @param string $s CSS string to minify
* @return string minified CSS string.
*/
function _minifyCss($s)
{
require_once BX_DIRECTORY_PATH_PLUGINS . 'minify/lib/Minify/CSS/Compressor.php';
return Minify_CSS_Compressor::process($s);
}
示例13: getStyles
//.........这里部分代码省略.........
$recache = true;
break;
}
}
}
//end of check
if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == '1')) {
$webshopUrl = $registry->get('config')->get('config_ssl');
} else {
$webshopUrl = $registry->get('config')->get('config_url');
}
$webshopUrl = rtrim(preg_replace('~^https?\\:~i', '', $webshopUrl), '/');
include_once $oc_root . DS . 'system' . DS . 'nitro' . DS . 'lib' . DS . 'minifier' . DS . 'CSSMin.php';
foreach ($this->styles as $hash => $style) {
if (empty($style)) {
continue;
}
if (!in_array(basename($style['href']), $cssExclude)) {
$target = '/assets/style/' . getSSLCachePrefix() . 'nitro-combined-' . $megaHashes[$style['rel'] . $style['media']] . '.css';
$targetAbsolutePath = $oc_root . DS . trim(str_replace('/', DS, $target), DS);
$filename = $oc_root . DS . trim(str_replace('/', DS, $style['href']), DS);
$comboHash = $megaHashes[$style['rel'] . $style['media']];
if (empty($combinedStyles[$style['rel'] . $style['media']])) {
$combinedStyles[$style['rel'] . $style['media']] = array('rel' => $style['rel'], 'media' => $style['media'], 'content' => '', 'megaHash' => $comboHash);
}
if ($recache || !file_exists($targetAbsolutePath)) {
if (empty($counters[$style['rel'] . $style['media']])) {
$counters[$style['rel'] . $style['media']] = 0;
}
$urlToCurrentDir = $webshopUrl . dirname('/' . trim($style['href'], '/'));
/* replace relative urls with absolute ones */
$tmpContent = preg_replace('/(url\\()(?![\'\\"]?https?\\:\\/\\/)([\'\\"]?)\\/?/', '$1$2' . $urlToCurrentDir . '/', file_get_contents($filename));
//minify
$tmpContent = Minify_CSS_Compressor::process($tmpContent);
$combinedStyles[$style['rel'] . $style['media']]['content'] .= $tmpContent;
unset($tmpContent);
$cache[$comboHash][$filename] = filemtime($filename);
}
}
}
file_put_contents($cachefile, json_encode($cache));
foreach ($combinedStyles as $key => $value) {
$target = '/assets/style/' . getSSLCachePrefix() . 'nitro-combined-' . $megaHashes[$key] . '.css';
$targetAbsolutePath = $oc_root . DS . trim(str_replace('/', DS, $target), DS);
if ($recache || !file_exists($targetAbsolutePath)) {
file_put_contents($targetAbsolutePath, $value['content']);
}
$result[$megaHashes[$key]] = array('rel' => $value['rel'], 'media' => $value['media'], 'href' => trim($target, '/'));
}
if ($includedCSS > 0) {
return array_merge($excludedCSS, $result);
} else {
return $excludedCSS;
}
} else {
$cachefile = $oc_root . DS . 'assets' . DS . 'style' . DS . getSSLCachePrefix() . 'styles.cache';
if (!file_exists($cachefile)) {
touch($cachefile);
file_put_contents($cachefile, json_encode(array()));
}
$cache = json_decode(file_get_contents($cachefile), true);
if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == '1')) {
$webshopUrl = $registry->get('config')->get('config_ssl');
} else {
$webshopUrl = $registry->get('config')->get('config_url');
}
示例14: process
/**
* Process asset content
*
* @param string $content
* @return string
*/
public static function process($content)
{
// Include the processor
include_once Kohana::find_file('vendor', 'minify_css_compressor/Compressor');
return Minify_CSS_Compressor::process($content);
}
示例15: minifyFile
/**
* Minify the given $content according to the file type indicated in $filename
*
* @param string $filename
* @param string $content
* @return string
*/
protected function minifyFile($filename, $content)
{
// if we have a javascript file and jsmin is enabled, minify the content
$isJS = stripos($filename, '.js');
require_once 'thirdparty/jsmin/jsmin.php';
require_once BASE_PATH . '/minify/code/thirdparty/Compressor.php';
require_once BASE_PATH . '/minify/code/thirdparty/UriRewriter.php';
increase_time_limit_to();
if ($isJS) {
$content = JSMin::minify($content) . ";\n";
} else {
$content = Minify_CSS_UriRewriter::rewrite($content, Director::baseFolder() . "/" . dirname($filename), Director::baseFolder());
$content = Minify_CSS_Compressor::process($content) . "\n";
}
return $content;
}