本文整理汇总了PHP中Minify_CSS_UriRewriter类的典型用法代码示例。如果您正苦于以下问题:PHP Minify_CSS_UriRewriter类的具体用法?PHP Minify_CSS_UriRewriter怎么用?PHP Minify_CSS_UriRewriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Minify_CSS_UriRewriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_Minify_CSS_UriRewriter
function test_Minify_CSS_UriRewriter()
{
global $thisDir;
Minify_CSS_UriRewriter::$debugText = '';
$in = file_get_contents($thisDir . '/_test_files/css_uriRewriter/in.css');
$expected = file_get_contents($thisDir . '/_test_files/css_uriRewriter/exp.css');
$actual = Minify_CSS_UriRewriter::rewrite($in, $thisDir . '/_test_files/css_uriRewriter', $thisDir);
$passed = assertTrue($expected === $actual, 'Minify_CSS_UriRewriter');
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
echo "\n---Input:\n\n{$in}\n";
echo "\n---Output: " . strlen($actual) . " bytes\n\n{$actual}\n\n";
if (!$passed) {
echo "---Expected: " . strlen($expected) . " bytes\n\n{$expected}\n\n\n";
}
// show debugging only when test run directly
echo "--- Minify_CSS_UriRewriter::\$debugText\n\n", Minify_CSS_UriRewriter::$debugText;
}
Minify_CSS_UriRewriter::$debugText = '';
$in = '../../../../assets/skins/sam/sprite.png';
$exp = '/yui/assets/skins/sam/sprite.png';
$actual = Minify_CSS_UriRewriter::rewriteRelative($in, 'sf_root_dir\\web\\yui\\menu\\assets\\skins\\sam', 'sf_root_dir\\web');
$passed = assertTrue($exp === $actual, 'Minify_CSS_UriRewriter : Issue 99');
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
echo "\n---Input:\n\n{$in}\n";
echo "\n---Output: " . strlen($actual) . " bytes\n\n{$actual}\n\n";
if (!$passed) {
echo "---Expected: " . strlen($exp) . " bytes\n\n{$exp}\n\n\n";
}
// show debugging only when test run directly
echo "--- Minify_CSS_UriRewriter::\$debugText\n\n", Minify_CSS_UriRewriter::$debugText;
}
}
示例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.
*
* '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']
);
}
}
示例3: minify
/**
* Add line numbers in C-style comments
*
* This uses a very basic parser easily fooled by comment tokens inside
* strings or regexes, but, otherwise, generally clean code will not be
* mangled. URI rewriting can also be performed.
*
* @param string $content
*
* @param array $options available options:
*
* 'id': (optional) string to identify file. E.g. file name/path
*
* '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, and prepend a comment with debugging information about
* this process.
*
* @return string
*/
public static function minify($content, $options = array())
{
$id = isset($options['id']) && $options['id'] ? $options['id'] : '';
$content = str_replace("\r\n", "\n", $content);
$lines = explode("\n", $content);
$numLines = count($lines);
// determine left padding
$padTo = strlen($numLines);
$inComment = false;
$i = 0;
$newLines = array();
while (null !== ($line = array_shift($lines))) {
if ('' !== $id && 0 == $i % 50) {
array_push($newLines, '', "/* {$id} */", '');
}
++$i;
$newLines[] = self::_addNote($line, $i, $inComment, $padTo);
$inComment = self::_eolInComment($line, $inComment);
}
$content = implode("\n", $newLines) . "\n";
// check for desired URI rewriting
require_once W3TC_LIB_MINIFY_DIR . '/Minify/CSS/UriRewriter.php';
$content = Minify_CSS_UriRewriter::rewrite($content, $options);
return $content;
}
示例4: minifyCss
public static function minifyCss($css, $options = array())
{
w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/CSS/UriRewriter.php');
$css = self::_minify('css', $css, $options);
$css = Minify_CSS_UriRewriter::rewrite($css, $options);
return $css;
}
示例5: 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']);
}
}
示例6: minify
/**
* Add line numbers in C-style comments
*
* This uses a very basic parser easily fooled by comment tokens inside
* strings or regexes, but, otherwise, generally clean code will not be
* mangled. URI rewriting can also be performed.
*
* @param string $content
*
* @param array $options available options:
*
* 'id': (optional) string to identify file. E.g. file name/path
*
* '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, and prepend a comment with debugging information about
* this process.
*
* @return string
*/
public static function minify($content, $options = array())
{
$id = isset($options['id']) && $options['id'] ? $options['id'] : '';
$content = str_replace("\r\n", "\n", $content);
$lines = explode("\n", $content);
$numLines = count($lines);
// determine left padding
$padTo = strlen($numLines);
$inComment = false;
$i = 0;
$newLines = array();
while (null !== ($line = array_shift($lines))) {
if ('' !== $id && 0 == $i % 50) {
array_push($newLines, '', "/* {$id} */", '');
}
++$i;
$newLines[] = self::_addNote($line, $i, $inComment, $padTo);
$inComment = self::_eolInComment($line, $inComment);
}
$content = implode("\n", $newLines) . "\n";
// check for desired URI rewriting
if (isset($options['currentDir'])) {
require_once W3TC_LIB_MINIFY_DIR . '/Minify/CSS/UriRewriter.php';
Minify_CSS_UriRewriter::$debugText = '';
$content = Minify_CSS_UriRewriter::rewrite($content, $options['currentDir'], isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT'], isset($options['symlinks']) ? $options['symlinks'] : array(), isset($options['browserCacheId']) ? $options['browserCacheId'] : 0, isset($options['browserCacheExtensions']) ? $options['browserCacheExtensions'] : array());
$content = "/* Minify_CSS_UriRewriter::\$debugText\n\n" . Minify_CSS_UriRewriter::$debugText . "*/\n" . $content;
} elseif (isset($options['prependRelativePath'])) {
require_once W3TC_LIB_MINIFY_DIR . '/Minify/CSS/UriRewriter.php';
Minify_CSS_UriRewriter::$debugText = '';
$content = Minify_CSS_UriRewriter::prepend($content, $options['prependRelativePath'], isset($options['browserCacheId']) ? $options['browserCacheId'] : 0, isset($options['browserCacheExtensions']) ? $options['browserCacheExtensions'] : array());
}
return $content;
}
示例7: minify
/**
* Add line numbers in C-style comments
*
* This uses a very basic parser easily fooled by comment tokens inside
* strings or regexes, but, otherwise, generally clean code will not be
* mangled. URI rewriting can also be performed.
*
* @param string $content
*
* @param array $options available options:
*
* 'id': (optional) string to identify file. E.g. file name/path
*
* '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, and prepend a comment with debugging information about
* this process.
*
* @return string
*/
public static function minify($content, $options = array())
{
$id = isset($options['id']) && $options['id'] ? $options['id'] : '';
$content = str_replace("\r\n", "\n", $content);
// Hackily rewrite strings with XPath expressions that are
// likely to throw off our dumb parser (for Prototype 1.6.1).
$content = str_replace('"/*"', '"/"+"*"', $content);
$content = preg_replace('@([\'"])(\\.?//?)\\*@', '$1$2$1+$1*', $content);
$lines = explode("\n", $content);
$numLines = count($lines);
// determine left padding
$padTo = strlen((string) $numLines);
// e.g. 103 lines = 3 digits
$inComment = false;
$i = 0;
$newLines = array();
while (null !== ($line = array_shift($lines))) {
if ('' !== $id && 0 == $i % 50) {
array_push($newLines, '', "/* {$id} */", '');
}
++$i;
$newLines[] = self::_addNote($line, $i, $inComment, $padTo);
$inComment = self::_eolInComment($line, $inComment);
}
$content = implode("\n", $newLines) . "\n";
// check for desired URI rewriting
if (isset($options['currentDir'])) {
//require _once MINIFY_MIN_DIR.'/Minify/CSS/UriRewriter.php';
Minify_CSS_UriRewriter::$debugText = '';
$content = Minify_CSS_UriRewriter::rewrite($content, $options['currentDir'], isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT'], isset($options['symlinks']) ? $options['symlinks'] : array());
$content = "/* Minify_CSS_UriRewriter::\$debugText\n\n" . Minify_CSS_UriRewriter::$debugText . "*/\n" . $content;
}
return $content;
}
示例8: minify
/**
* Add line numbers in C-style comments
*
* This uses a very basic parser easily fooled by comment tokens inside
* strings or regexes, but, otherwise, generally clean code will not be
* mangled. URI rewriting can also be performed.
*
* @param string $content
*
* @param array $options available options:
*
* 'id': (optional) string to identify file. E.g. file name/path
*
* '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, and prepend a comment with debugging information about
* this process.
*
* @return string
*/
public static function minify($content, $options = array())
{
$id = isset($options['id']) && $options['id'] ? $options['id'] : '';
$content = str_replace("\r\n", "\n", $content);
$lines = explode("\n", $content);
$numLines = count($lines);
// determine left padding
$padTo = strlen((string) $numLines);
// e.g. 103 lines = 3 digits
$inComment = false;
$i = 0;
$newLines = array();
while (null !== ($line = array_shift($lines))) {
if ('' !== $id && 0 == $i % 50) {
if ($inComment) {
array_push($newLines, '', "/* {$id} *|", '');
} else {
array_push($newLines, '', "/* {$id} */", '');
}
}
++$i;
$newLines[] = self::_addNote($line, $i, $inComment, $padTo);
$inComment = self::_eolInComment($line, $inComment);
}
$content = implode("\n", $newLines) . "\n";
// check for desired URI rewriting
if (isset($options['currentDir'])) {
Minify_CSS_UriRewriter::$debugText = '';
$docRoot = isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT'];
$symlinks = isset($options['symlinks']) ? $options['symlinks'] : array();
$content = Minify_CSS_UriRewriter::rewrite($content, $options['currentDir'], $docRoot, $symlinks);
$content = "/* Minify_CSS_UriRewriter::\$debugText\n\n" . Minify_CSS_UriRewriter::$debugText . "*/\n" . $content;
}
return $content;
}
示例9: minify
public static function minify($css, $options = array())
{
$options = array_merge(array('remove_bslash' => true, 'compress_colors' => true, 'compress_font-weight' => true, 'lowercase_s' => false, 'optimise_shorthands' => 1, 'remove_last_;' => false, 'case_properties' => 1, 'sort_properties' => false, 'sort_selectors' => false, 'merge_selectors' => 2, 'discard_invalid_properties' => false, 'css_level' => 'CSS2.1', 'preserve_css' => false, 'timestamp' => false, 'template' => 'default'), $options);
set_include_path(get_include_path() . PATH_SEPARATOR . W3TC_LIB_CSSTIDY_DIR);
require_once 'class.csstidy.php';
$csstidy = new csstidy();
foreach ($options as $option => $value) {
$csstidy->set_cfg($option, $value);
}
$csstidy->load_template($options['template']);
$csstidy->parse($css);
$css = $csstidy->print->plain();
if (isset($options['currentDir']) || isset($options['prependRelativePath'])) {
require_once W3TC_LIB_MINIFY_DIR . '/Minify/CSS/UriRewriter.php';
$browsercache_id = isset($options['browserCacheId']) ? $options['browserCacheId'] : 0;
$browsercache_extensions = isset($options['browserCacheExtensions']) ? $options['browserCacheExtensions'] : array();
if (isset($options['currentDir'])) {
$document_root = isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT'];
$symlinks = isset($options['symlinks']) ? $options['symlinks'] : array();
return Minify_CSS_UriRewriter::rewrite($css, $options['currentDir'], $document_root, $symlinks, $browsercache_id, $browsercache_extensions);
} else {
return Minify_CSS_UriRewriter::prepend($css, $options['prependRelativePath'], $browsercache_id, $browsercache_extensions);
}
}
return $css;
}
示例10: minify
/**
* Minifies content
* @param string $content
* @param array $options
* @return string
*/
public static function minify($content, $options = array())
{
if (isset($options['currentDir'])) {
require_once W3TC_LIB_MINIFY_DIR . '/Minify/CSS/UriRewriter.php';
$content = Minify_CSS_UriRewriter::rewrite($content, $options['currentDir'], isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT'], isset($options['symlinks']) ? $options['symlinks'] : array());
} elseif (isset($options['prependRelativePath'])) {
require_once W3TC_LIB_MINIFY_DIR . '/Minify/CSS/UriRewriter.php';
$content = Minify_CSS_UriRewriter::prepend($content, $options['prependRelativePath']);
}
return $content;
}
示例11: filterDump
public function filterDump(AssetInterface $asset)
{
$sourceBase = $asset->getSourceRoot();
$sourcePath = $asset->getSourcePath();
$targetPath = $asset->getTargetPath();
if (null === $sourcePath || null === $targetPath || $sourcePath == $targetPath) {
return;
}
$content = \Minify_CSS_UriRewriter::rewrite($asset->getContent(), $sourceBase);
$asset->setContent($content);
}
示例12: 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;
}
示例13: minify
/**
* Minifies content
* @param string $content
* @param array $options
* @return string
*/
public static function minify($content, $options = array())
{
$browsercache_id = isset($options['browserCacheId']) ? $options['browserCacheId'] : 0;
$browsercache_extensions = isset($options['browserCacheExtensions']) ? $options['browserCacheExtensions'] : array();
if (isset($options['currentDir'])) {
require_once W3TC_LIB_MINIFY_DIR . '/Minify/CSS/UriRewriter.php';
$document_root = isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT'];
$symlinks = isset($options['symlinks']) ? $options['symlinks'] : array();
$content = Minify_CSS_UriRewriter::rewrite($content, $options['currentDir'], $document_root, $symlinks, $browsercache_id, $browsercache_extensions);
} elseif (isset($options['prependRelativePath'])) {
require_once W3TC_LIB_MINIFY_DIR . '/Minify/CSS/UriRewriter.php';
$content = Minify_CSS_UriRewriter::prepend($content, $options['prependRelativePath'], $browsercache_id, $browsercache_extensions);
}
return $content;
}
示例14: test_Minify_CSS_UriRewriter
function test_Minify_CSS_UriRewriter()
{
global $thisDir;
$in = file_get_contents($thisDir . '/_test_files/css_uriRewriter/in.css');
$expected = file_get_contents($thisDir . '/_test_files/css_uriRewriter/exp.css');
$actual = Minify_CSS_UriRewriter::rewrite($in, $thisDir . '/_test_files/css_uriRewriter', $thisDir);
$passed = assertTrue($expected === $actual, 'Minify_CSS_UriRewriter');
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
echo "\n---Input:\n\n{$in}\n";
echo "\n---Output: " . strlen($actual) . " bytes\n\n{$actual}\n\n";
if (!$passed) {
echo "---Expected: " . strlen($expected) . " bytes\n\n{$expected}\n\n\n";
}
}
}
示例15: minify
public static function minify($css, $options = array())
{
$options = array_merge(array('remove_bslash' => true, 'compress_colors' => true, 'compress_font-weight' => true, 'lowercase_s' => false, 'optimise_shorthands' => 1, 'remove_last_;' => false, 'case_properties' => 1, 'sort_properties' => false, 'sort_selectors' => false, 'merge_selectors' => 2, 'discard_invalid_properties' => false, 'css_level' => 'CSS2.1', 'preserve_css' => false, 'timestamp' => false, 'template' => 'default'), $options);
set_include_path(get_include_path() . PATH_SEPARATOR . W3TC_LIB_DIR . '/CSSTidy');
require_once 'class.csstidy.php';
$csstidy = new csstidy();
foreach ($options as $option => $value) {
$csstidy->set_cfg($option, $value);
}
$csstidy->load_template($options['template']);
$csstidy->parse($css);
$css = $csstidy->print->plain();
$css = Minify_CSS_UriRewriter::rewrite($css, $options);
return $css;
}