mirror of
https://github.com/mrclay/minify.git
synced 2025-08-16 19:14:01 +02:00
Big style cleanup
This commit is contained in:
@@ -52,10 +52,10 @@ class Minify_CSS_UriRewriter
|
||||
|
||||
// normalize symlinks in order to map to link
|
||||
foreach ($symlinks as $link => $target) {
|
||||
$link = ($link === '//')
|
||||
? self::$_docRoot
|
||||
: str_replace('//', self::$_docRoot . '/', $link);
|
||||
|
||||
$link = ($link === '//') ? self::$_docRoot : str_replace('//', self::$_docRoot . '/', $link);
|
||||
$link = strtr($link, '/', DIRECTORY_SEPARATOR);
|
||||
|
||||
self::$_symlinks[$link] = self::_realpath($target);
|
||||
}
|
||||
|
||||
@@ -71,10 +71,11 @@ class Minify_CSS_UriRewriter
|
||||
$css = self::_owlifySvgPaths($css);
|
||||
|
||||
// rewrite
|
||||
$css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/'
|
||||
,array(self::$className, '_processUriCB'), $css);
|
||||
$css = preg_replace_callback('/url\\(\\s*([\'"](.*?)[\'"]|[^\\)\\s]+)\\s*\\)/'
|
||||
,array(self::$className, '_processUriCB'), $css);
|
||||
$pattern = '/@import\\s+([\'"])(.*?)[\'"]/';
|
||||
$css = preg_replace_callback($pattern, array(self::$className, '_processUriCB'), $css);
|
||||
|
||||
$pattern = '/url\\(\\s*([\'"](.*?)[\'"]|[^\\)\\s]+)\\s*\\)/';
|
||||
$css = preg_replace_callback($pattern, array(self::$className, '_processUriCB'), $css);
|
||||
|
||||
$css = self::_unOwlify($css);
|
||||
|
||||
@@ -99,10 +100,11 @@ class Minify_CSS_UriRewriter
|
||||
$css = self::_owlifySvgPaths($css);
|
||||
|
||||
// append
|
||||
$css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/'
|
||||
,array(self::$className, '_processUriCB'), $css);
|
||||
$css = preg_replace_callback('/url\\(\\s*([\'"](.*?)[\'"]|[^\\)\\s]+)\\s*\\)/'
|
||||
,array(self::$className, '_processUriCB'), $css);
|
||||
$pattern = '/@import\\s+([\'"])(.*?)[\'"]/';
|
||||
$css = preg_replace_callback($pattern, array(self::$className, '_processUriCB'), $css);
|
||||
|
||||
$pattern = '/url\\(\\s*([\'"](.*?)[\'"]|[^\\)\\s]+)\\s*\\)/';
|
||||
$css = preg_replace_callback($pattern, array(self::$className, '_processUriCB'), $css);
|
||||
|
||||
$css = self::_unOwlify($css);
|
||||
|
||||
@@ -152,8 +154,8 @@ class Minify_CSS_UriRewriter
|
||||
public static function rewriteRelative($uri, $realCurrentDir, $realDocRoot, $symlinks = array())
|
||||
{
|
||||
// prepend path with current dir separator (OS-independent)
|
||||
$path = strtr($realCurrentDir, '/', DIRECTORY_SEPARATOR)
|
||||
. DIRECTORY_SEPARATOR . strtr($uri, '/', DIRECTORY_SEPARATOR);
|
||||
$path = strtr($realCurrentDir, '/', DIRECTORY_SEPARATOR);
|
||||
$path .= DIRECTORY_SEPARATOR . strtr($uri, '/', DIRECTORY_SEPARATOR);
|
||||
|
||||
self::$debugText .= "file-relative URI : {$uri}\n"
|
||||
. "path prepended : {$path}\n";
|
||||
@@ -263,13 +265,14 @@ class Minify_CSS_UriRewriter
|
||||
*/
|
||||
private static function _trimUrls($css)
|
||||
{
|
||||
return preg_replace('/
|
||||
$pattern = '/
|
||||
url\\( # url(
|
||||
\\s*
|
||||
([^\\)]+?) # 1 = URI (assuming does not contain ")")
|
||||
\\s*
|
||||
\\) # )
|
||||
/x', 'url($1)', $css);
|
||||
/x';
|
||||
return preg_replace($pattern, 'url($1)', $css);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,12 +290,9 @@ class Minify_CSS_UriRewriter
|
||||
$uri = $m[2];
|
||||
} else {
|
||||
// $m[1] is either quoted or not
|
||||
$quoteChar = ($m[1][0] === "'" || $m[1][0] === '"')
|
||||
? $m[1][0]
|
||||
: '';
|
||||
$uri = ($quoteChar === '')
|
||||
? $m[1]
|
||||
: substr($m[1], 1, strlen($m[1]) - 2);
|
||||
$quoteChar = ($m[1][0] === "'" || $m[1][0] === '"') ? $m[1][0] : '';
|
||||
|
||||
$uri = ($quoteChar === '') ? $m[1] : substr($m[1], 1, strlen($m[1]) - 2);
|
||||
}
|
||||
// if not root/scheme relative and not starts with scheme
|
||||
if (!preg_match('~^(/|[a-z]+\:)~', $uri)) {
|
||||
@@ -313,9 +313,11 @@ class Minify_CSS_UriRewriter
|
||||
}
|
||||
}
|
||||
|
||||
return $isImport
|
||||
? "@import {$quoteChar}{$uri}{$quoteChar}"
|
||||
: "url({$quoteChar}{$uri}{$quoteChar})";
|
||||
if ($isImport) {
|
||||
return "@import {$quoteChar}{$uri}{$quoteChar}";
|
||||
} else {
|
||||
return "url({$quoteChar}{$uri}{$quoteChar})";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -329,7 +331,8 @@ class Minify_CSS_UriRewriter
|
||||
*/
|
||||
private static function _owlifySvgPaths($css)
|
||||
{
|
||||
return preg_replace('~\b((?:clip-path|mask|-webkit-mask)\s*\:\s*)url(\(\s*#\w+\s*\))~', '$1owl$2', $css);
|
||||
$pattern = '~\b((?:clip-path|mask|-webkit-mask)\s*\:\s*)url(\(\s*#\w+\s*\))~';
|
||||
return preg_replace($pattern, '$1owl$2', $css);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -342,6 +345,7 @@ class Minify_CSS_UriRewriter
|
||||
*/
|
||||
private static function _unOwlify($css)
|
||||
{
|
||||
return preg_replace('~\b((?:clip-path|mask|-webkit-mask)\s*\:\s*)owl~', '$1url', $css);
|
||||
$pattern = '~\b((?:clip-path|mask|-webkit-mask)\s*\:\s*)owl~';
|
||||
return preg_replace($pattern, '$1url', $css);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user