1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-01 20:00:42 +02:00

Big style cleanup

This commit is contained in:
Steve Clay
2016-10-16 15:13:38 -04:00
parent 5fb7ea1ed1
commit 16c811cd93
23 changed files with 257 additions and 266 deletions

View File

@@ -274,7 +274,8 @@ class Minify
// depending on what the client accepts, $contentEncoding may be // depending on what the client accepts, $contentEncoding may be
// 'x-gzip' while our internal encodeMethod is 'gzip'. Calling // 'x-gzip' while our internal encodeMethod is 'gzip'. Calling
// getAcceptedEncoding(false, false) leaves out compress and deflate as options. // getAcceptedEncoding(false, false) leaves out compress and deflate as options.
list($this->options['encodeMethod'], $contentEncoding) = HTTP_Encoder::getAcceptedEncoding(false, false); $list = HTTP_Encoder::getAcceptedEncoding(false, false);
list($this->options['encodeMethod'], $contentEncoding) = $list;
$sendVary = ! HTTP_Encoder::isBuggyIe(); $sendVary = ! HTTP_Encoder::isBuggyIe();
} }
} else { } else {
@@ -515,8 +516,8 @@ class Minify
if ($file if ($file
&& !isset($minifyOptions['currentDir']) && !isset($minifyOptions['currentDir'])
&& !isset($minifyOptions['prependRelativePath']) && !isset($minifyOptions['prependRelativePath'])) {
) {
$minifyOptions['currentDir'] = dirname($file); $minifyOptions['currentDir'] = dirname($file);
$source->setMinifierOptions($minifyOptions); $source->setMinifierOptions($minifyOptions);
} }
@@ -596,8 +597,7 @@ class Minify
! $source // yes, we ran out of sources ! $source // yes, we ran out of sources
|| $type === self::TYPE_CSS // yes, to process CSS individually (avoiding PCRE bugs/limits) || $type === self::TYPE_CSS // yes, to process CSS individually (avoiding PCRE bugs/limits)
|| $minifier !== $lastMinifier // yes, minifier changed || $minifier !== $lastMinifier // yes, minifier changed
|| $options !== $lastOptions) // yes, options changed || $options !== $lastOptions)) { // yes, options changed
) {
// minify previous sources with last settings // minify previous sources with last settings
$imploded = implode($implodeSeparator, $groupToProcessTogether); $imploded = implode($implodeSeparator, $groupToProcessTogether);
$groupToProcessTogether = array(); $groupToProcessTogether = array();

View File

@@ -64,9 +64,10 @@ class App extends Container
$propNames = array_keys(get_object_vars($config)); $propNames = array_keys(get_object_vars($config));
$varNames = array_map(function ($name) { $prefixer = function ($name) {
return "min_$name"; return "min_$name";
}, $propNames); };
$varNames = array_map($prefixer, $propNames);
$vars = compact($varNames); $vars = compact($varNames);

View File

@@ -70,9 +70,7 @@ class Minify_Build
*/ */
public function uri($uri, $forceAmpersand = false) public function uri($uri, $forceAmpersand = false)
{ {
$sep = ($forceAmpersand || strpos($uri, '?') !== false) $sep = ($forceAmpersand || strpos($uri, '?') !== false) ? self::$ampersand : '?';
? self::$ampersand
: '?';
return "{$uri}{$sep}{$this->lastModified}"; return "{$uri}{$sep}{$this->lastModified}";
} }

View File

@@ -71,32 +71,27 @@ class Minify_CSS
if ($options['removeCharsets']) { if ($options['removeCharsets']) {
$css = preg_replace('/@charset[^;]+;\\s*/', '', $css); $css = preg_replace('/@charset[^;]+;\\s*/', '', $css);
} }
if ($options['compress']) { if ($options['compress']) {
if (! $options['preserveComments']) { if (! $options['preserveComments']) {
$css = Minify_CSS_Compressor::process($css, $options); $css = Minify_CSS_Compressor::process($css, $options);
} else { } else {
$css = Minify_CommentPreserver::process( $processor = array('Minify_CSS_Compressor', 'process');
$css $css = Minify_CommentPreserver::process($css, $processor, array($options));
,array('Minify_CSS_Compressor', 'process')
,array($options)
);
} }
} }
if (! $options['currentDir'] && ! $options['prependRelativePath']) { if (! $options['currentDir'] && ! $options['prependRelativePath']) {
return $css; return $css;
} }
if ($options['currentDir']) { if ($options['currentDir']) {
return Minify_CSS_UriRewriter::rewrite( $currentDir = $options['currentDir'];
$css $docRoot = $options['docRoot'];
,$options['currentDir'] $symlinks = $options['symlinks'];
,$options['docRoot'] return Minify_CSS_UriRewriter::rewrite($css, $currentDir, $docRoot, $symlinks);
,$options['symlinks']
);
} else { } else {
return Minify_CSS_UriRewriter::prepend( return Minify_CSS_UriRewriter::prepend($css, $options['prependRelativePath']);
$css
,$options['prependRelativePath']
);
} }
} }
} }

View File

@@ -88,8 +88,8 @@ class Minify_CSS_Compressor
$css = preg_replace('@:\\s*/\\*\\s*\\*/@', ':/*keep*/', $css); $css = preg_replace('@:\\s*/\\*\\s*\\*/@', ':/*keep*/', $css);
// apply callback to all valid comments (and strip out surrounding ws // apply callback to all valid comments (and strip out surrounding ws
$css = preg_replace_callback('@\\s*/\\*([\\s\\S]*?)\\*/\\s*@' $pattern = '@\\s*/\\*([\\s\\S]*?)\\*/\\s*@';
,array($this, '_commentCB'), $css); $css = preg_replace_callback($pattern, array($this, '_commentCB'), $css);
// remove ws around { } and last semicolon in declaration block // remove ws around { } and last semicolon in declaration block
$css = preg_replace('/\\s*{\\s*/', '{', $css); $css = preg_replace('/\\s*{\\s*/', '{', $css);
@@ -99,16 +99,17 @@ class Minify_CSS_Compressor
$css = preg_replace('/\\s*;\\s*/', ';', $css); $css = preg_replace('/\\s*;\\s*/', ';', $css);
// remove ws around urls // remove ws around urls
$css = preg_replace('/ $pattern = '/
url\\( # url( url\\( # url(
\\s* \\s*
([^\\)]+?) # 1 = the URL (really just a bunch of non right parenthesis) ([^\\)]+?) # 1 = the URL (really just a bunch of non right parenthesis)
\\s* \\s*
\\) # ) \\) # )
/x', 'url($1)', $css); /x';
$css = preg_replace($pattern, 'url($1)', $css);
// remove ws between rules and colons // remove ws between rules and colons
$css = preg_replace('/ $pattern = '/
\\s* \\s*
([{;]) # 1 = beginning of block or rule separator ([{;]) # 1 = beginning of block or rule separator
\\s* \\s*
@@ -117,10 +118,11 @@ class Minify_CSS_Compressor
: :
\\s* \\s*
(\\b|[#\'"-]) # 3 = first character of a value (\\b|[#\'"-]) # 3 = first character of a value
/x', '$1$2:$3', $css); /x';
$css = preg_replace($pattern, '$1$2:$3', $css);
// remove ws in selectors // remove ws in selectors
$css = preg_replace_callback('/ $pattern = '/
(?: # non-capture (?: # non-capture
\\s* \\s*
[^~>+,\\s]+ # selector part [^~>+,\\s]+ # selector part
@@ -130,16 +132,16 @@ class Minify_CSS_Compressor
\\s* \\s*
[^~>+,\\s]+ # selector part [^~>+,\\s]+ # selector part
{ # open declaration block { # open declaration block
/x' /x';
,array($this, '_selectorsCB'), $css); $css = preg_replace_callback($pattern, array($this, '_selectorsCB'), $css);
// minimize hex colors // minimize hex colors
$css = preg_replace('/([^=])#([a-f\\d])\\2([a-f\\d])\\3([a-f\\d])\\4([\\s;\\}])/i' $pattern = '/([^=])#([a-f\\d])\\2([a-f\\d])\\3([a-f\\d])\\4([\\s;\\}])/i';
, '$1#$2$3$4$5', $css); $css = preg_replace($pattern, '$1#$2$3$4$5', $css);
// remove spaces between font families // remove spaces between font families
$css = preg_replace_callback('/font-family:([^;}]+)([;}])/' $pattern = '/font-family:([^;}]+)([;}])/';
,array($this, '_fontFamilyCB'), $css); $css = preg_replace_callback($pattern, array($this, '_fontFamilyCB'), $css);
$css = preg_replace('/@import\\s+url/', '@import url', $css); $css = preg_replace('/@import\\s+url/', '@import url', $css);
@@ -147,14 +149,15 @@ class Minify_CSS_Compressor
$css = preg_replace('/[ \\t]*\\n+\\s*/', "\n", $css); $css = preg_replace('/[ \\t]*\\n+\\s*/', "\n", $css);
// separate common descendent selectors w/ newlines (to limit line lengths) // separate common descendent selectors w/ newlines (to limit line lengths)
$css = preg_replace('/([\\w#\\.\\*]+)\\s+([\\w#\\.\\*]+){/', "$1\n$2{", $css); $pattern = '/([\\w#\\.\\*]+)\\s+([\\w#\\.\\*]+){/';
$css = preg_replace($pattern, "$1\n$2{", $css);
// Use newline after 1st numeric value (to limit line lengths). // Use newline after 1st numeric value (to limit line lengths).
$css = preg_replace('/ $pattern = '/
((?:padding|margin|border|outline):\\d+(?:px|em)?) # 1 = prop : 1st numeric value ((?:padding|margin|border|outline):\\d+(?:px|em)?) # 1 = prop : 1st numeric value
\\s+ \\s+
/x' /x';
,"$1\n", $css); $css = preg_replace($pattern, "$1\n", $css);
// prevent triggering IE6 bug: http://www.crankygeek.com/ie6pebug/ // prevent triggering IE6 bug: http://www.crankygeek.com/ie6pebug/
$css = preg_replace('/:first-l(etter|ine)\\{/', ':first-l$1 {', $css); $css = preg_replace('/:first-l(etter|ine)\\{/', ':first-l$1 {', $css);
@@ -191,52 +194,54 @@ class Minify_CSS_Compressor
if ($m === 'keep') { if ($m === 'keep') {
return '/**/'; return '/**/';
} }
if ($m === '" "') { if ($m === '" "') {
// component of http://tantek.com/CSS/Examples/midpass.html // component of http://tantek.com/CSS/Examples/midpass.html
return '/*" "*/'; return '/*" "*/';
} }
if (preg_match('@";\\}\\s*\\}/\\*\\s+@', $m)) { if (preg_match('@";\\}\\s*\\}/\\*\\s+@', $m)) {
// component of http://tantek.com/CSS/Examples/midpass.html // component of http://tantek.com/CSS/Examples/midpass.html
return '/*";}}/* */'; return '/*";}}/* */';
} }
if ($this->_inHack) { if ($this->_inHack) {
// inversion: feeding only to one browser // inversion: feeding only to one browser
if (preg_match('@ $pattern = '@
^/ # comment started like /*/ ^/ # comment started like /*/
\\s* \\s*
(\\S[\\s\\S]+?) # has at least some non-ws content (\\S[\\s\\S]+?) # has at least some non-ws content
\\s* \\s*
/\\* # ends like /*/ or /**/ /\\* # ends like /*/ or /**/
@x', $m, $n)) { @x';
if (preg_match($pattern, $m, $n)) {
// end hack mode after this comment, but preserve the hack and comment content // end hack mode after this comment, but preserve the hack and comment content
$this->_inHack = false; $this->_inHack = false;
return "/*/{$n[1]}/**/"; return "/*/{$n[1]}/**/";
} }
} }
if (substr($m, -1) === '\\') { // comment ends like \*/ if (substr($m, -1) === '\\') { // comment ends like \*/
// begin hack mode and preserve hack // begin hack mode and preserve hack
$this->_inHack = true; $this->_inHack = true;
return '/*\\*/'; return '/*\\*/';
} }
if ($m !== '' && $m[0] === '/') { // comment looks like /*/ foo */ if ($m !== '' && $m[0] === '/') { // comment looks like /*/ foo */
// begin hack mode and preserve hack // begin hack mode and preserve hack
$this->_inHack = true; $this->_inHack = true;
return '/*/*/'; return '/*/*/';
} }
if ($this->_inHack) { if ($this->_inHack) {
// a regular comment ends hack mode but should be preserved // a regular comment ends hack mode but should be preserved
$this->_inHack = false; $this->_inHack = false;
return '/**/'; return '/**/';
} }
// Issue 107: if there's any surrounding whitespace, it may be important, so // Issue 107: if there's any surrounding whitespace, it may be important, so
// replace the comment with a single space // replace the comment with a single space
return $hasSurroundingWs // remove all other comments return $hasSurroundingWs ? ' ' : ''; // remove all other comments
? ' '
: '';
} }
/** /**
@@ -249,8 +254,10 @@ class Minify_CSS_Compressor
protected function _fontFamilyCB($m) protected function _fontFamilyCB($m)
{ {
// Issue 210: must not eliminate WS between words in unquoted families // Issue 210: must not eliminate WS between words in unquoted families
$pieces = preg_split('/(\'[^\']+\'|"[^"]+")/', $m[1], null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $flags = PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY;
$pieces = preg_split('/(\'[^\']+\'|"[^"]+")/', $m[1], null, $flags);
$out = 'font-family:'; $out = 'font-family:';
while (null !== ($piece = array_shift($pieces))) { while (null !== ($piece = array_shift($pieces))) {
if ($piece[0] !== '"' && $piece[0] !== "'") { if ($piece[0] !== '"' && $piece[0] !== "'") {
$piece = preg_replace('/\\s+/', ' ', $piece); $piece = preg_replace('/\\s+/', ' ', $piece);

View File

@@ -52,10 +52,10 @@ class Minify_CSS_UriRewriter
// normalize symlinks in order to map to link // normalize symlinks in order to map to link
foreach ($symlinks as $link => $target) { foreach ($symlinks as $link => $target) {
$link = ($link === '//')
? self::$_docRoot $link = ($link === '//') ? self::$_docRoot : str_replace('//', self::$_docRoot . '/', $link);
: str_replace('//', self::$_docRoot . '/', $link);
$link = strtr($link, '/', DIRECTORY_SEPARATOR); $link = strtr($link, '/', DIRECTORY_SEPARATOR);
self::$_symlinks[$link] = self::_realpath($target); self::$_symlinks[$link] = self::_realpath($target);
} }
@@ -71,10 +71,11 @@ class Minify_CSS_UriRewriter
$css = self::_owlifySvgPaths($css); $css = self::_owlifySvgPaths($css);
// rewrite // rewrite
$css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/' $pattern = '/@import\\s+([\'"])(.*?)[\'"]/';
,array(self::$className, '_processUriCB'), $css); $css = preg_replace_callback($pattern, array(self::$className, '_processUriCB'), $css);
$css = preg_replace_callback('/url\\(\\s*([\'"](.*?)[\'"]|[^\\)\\s]+)\\s*\\)/'
,array(self::$className, '_processUriCB'), $css); $pattern = '/url\\(\\s*([\'"](.*?)[\'"]|[^\\)\\s]+)\\s*\\)/';
$css = preg_replace_callback($pattern, array(self::$className, '_processUriCB'), $css);
$css = self::_unOwlify($css); $css = self::_unOwlify($css);
@@ -99,10 +100,11 @@ class Minify_CSS_UriRewriter
$css = self::_owlifySvgPaths($css); $css = self::_owlifySvgPaths($css);
// append // append
$css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/' $pattern = '/@import\\s+([\'"])(.*?)[\'"]/';
,array(self::$className, '_processUriCB'), $css); $css = preg_replace_callback($pattern, array(self::$className, '_processUriCB'), $css);
$css = preg_replace_callback('/url\\(\\s*([\'"](.*?)[\'"]|[^\\)\\s]+)\\s*\\)/'
,array(self::$className, '_processUriCB'), $css); $pattern = '/url\\(\\s*([\'"](.*?)[\'"]|[^\\)\\s]+)\\s*\\)/';
$css = preg_replace_callback($pattern, array(self::$className, '_processUriCB'), $css);
$css = self::_unOwlify($css); $css = self::_unOwlify($css);
@@ -152,8 +154,8 @@ class Minify_CSS_UriRewriter
public static function rewriteRelative($uri, $realCurrentDir, $realDocRoot, $symlinks = array()) public static function rewriteRelative($uri, $realCurrentDir, $realDocRoot, $symlinks = array())
{ {
// prepend path with current dir separator (OS-independent) // prepend path with current dir separator (OS-independent)
$path = strtr($realCurrentDir, '/', DIRECTORY_SEPARATOR) $path = strtr($realCurrentDir, '/', DIRECTORY_SEPARATOR);
. DIRECTORY_SEPARATOR . strtr($uri, '/', DIRECTORY_SEPARATOR); $path .= DIRECTORY_SEPARATOR . strtr($uri, '/', DIRECTORY_SEPARATOR);
self::$debugText .= "file-relative URI : {$uri}\n" self::$debugText .= "file-relative URI : {$uri}\n"
. "path prepended : {$path}\n"; . "path prepended : {$path}\n";
@@ -263,13 +265,14 @@ class Minify_CSS_UriRewriter
*/ */
private static function _trimUrls($css) private static function _trimUrls($css)
{ {
return preg_replace('/ $pattern = '/
url\\( # url( url\\( # url(
\\s* \\s*
([^\\)]+?) # 1 = URI (assuming does not contain ")") ([^\\)]+?) # 1 = URI (assuming does not contain ")")
\\s* \\s*
\\) # ) \\) # )
/x', 'url($1)', $css); /x';
return preg_replace($pattern, 'url($1)', $css);
} }
/** /**
@@ -287,12 +290,9 @@ class Minify_CSS_UriRewriter
$uri = $m[2]; $uri = $m[2];
} else { } else {
// $m[1] is either quoted or not // $m[1] is either quoted or not
$quoteChar = ($m[1][0] === "'" || $m[1][0] === '"') $quoteChar = ($m[1][0] === "'" || $m[1][0] === '"') ? $m[1][0] : '';
? $m[1][0]
: ''; $uri = ($quoteChar === '') ? $m[1] : substr($m[1], 1, strlen($m[1]) - 2);
$uri = ($quoteChar === '')
? $m[1]
: substr($m[1], 1, strlen($m[1]) - 2);
} }
// if not root/scheme relative and not starts with scheme // if not root/scheme relative and not starts with scheme
if (!preg_match('~^(/|[a-z]+\:)~', $uri)) { if (!preg_match('~^(/|[a-z]+\:)~', $uri)) {
@@ -313,9 +313,11 @@ class Minify_CSS_UriRewriter
} }
} }
return $isImport if ($isImport) {
? "@import {$quoteChar}{$uri}{$quoteChar}" return "@import {$quoteChar}{$uri}{$quoteChar}";
: "url({$quoteChar}{$uri}{$quoteChar})"; } else {
return "url({$quoteChar}{$uri}{$quoteChar})";
}
} }
/** /**
@@ -329,7 +331,8 @@ class Minify_CSS_UriRewriter
*/ */
private static function _owlifySvgPaths($css) 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) 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);
} }
} }

View File

@@ -59,9 +59,11 @@ class Minify_Cache_APC implements Minify_CacheInterface
return false; return false;
} }
return (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
? mb_strlen($this->_data, '8bit') return mb_strlen($this->_data, '8bit');
: strlen($this->_data); } else {
return strlen($this->_data);;
}
} }
/** /**
@@ -85,9 +87,7 @@ class Minify_Cache_APC implements Minify_CacheInterface
*/ */
public function display($id) public function display($id)
{ {
echo $this->_fetch($id) echo $this->_fetch($id) ? $this->_data : '';
? $this->_data
: '';
} }
/** /**
@@ -99,9 +99,7 @@ class Minify_Cache_APC implements Minify_CacheInterface
*/ */
public function fetch($id) public function fetch($id)
{ {
return $this->_fetch($id) return $this->_fetch($id) ? $this->_data : '';
? $this->_data
: '';
} }
private $_exp = null; private $_exp = null;
@@ -126,9 +124,9 @@ class Minify_Cache_APC implements Minify_CacheInterface
$ret = apc_fetch($id); $ret = apc_fetch($id);
if (false === $ret) { if (false === $ret) {
$this->_id = null; $this->_id = null;
return false; return false;
} }
list($this->_lm, $this->_data) = explode('|', $ret, 2); list($this->_lm, $this->_data) = explode('|', $ret, 2);
$this->_id = $id; $this->_id = $id;

View File

@@ -54,13 +54,13 @@ class Minify_Cache_File implements Minify_CacheInterface
*/ */
public function store($id, $data) public function store($id, $data)
{ {
$flag = $this->locking $flag = $this->locking ? LOCK_EX : null;
? LOCK_EX
: null;
$file = $this->path . '/' . $id; $file = $this->path . '/' . $id;
if (! @file_put_contents($file, $data, $flag)) { if (! @file_put_contents($file, $data, $flag)) {
$this->logger->warning("Minify_Cache_File: Write failed to '$file'"); $this->logger->warning("Minify_Cache_File: Write failed to '$file'");
} }
// write control // write control
if ($data !== $this->fetch($id)) { if ($data !== $this->fetch($id)) {
@unlink($file); @unlink($file);
@@ -107,15 +107,16 @@ class Minify_Cache_File implements Minify_CacheInterface
*/ */
public function display($id) public function display($id)
{ {
if ($this->locking) { if (!$this->locking) {
$fp = fopen($this->path . '/' . $id, 'rb');
flock($fp, LOCK_SH);
fpassthru($fp);
flock($fp, LOCK_UN);
fclose($fp);
} else {
readfile($this->path . '/' . $id); readfile($this->path . '/' . $id);
return;
} }
$fp = fopen($this->path . '/' . $id, 'rb');
flock($fp, LOCK_SH);
fpassthru($fp);
flock($fp, LOCK_UN);
fclose($fp);
} }
/** /**
@@ -127,20 +128,21 @@ class Minify_Cache_File implements Minify_CacheInterface
*/ */
public function fetch($id) public function fetch($id)
{ {
if ($this->locking) { if (!$this->locking) {
$fp = fopen($this->path . '/' . $id, 'rb');
if (!$fp) {
return false;
}
flock($fp, LOCK_SH);
$ret = stream_get_contents($fp);
flock($fp, LOCK_UN);
fclose($fp);
return $ret;
} else {
return file_get_contents($this->path . '/' . $id); return file_get_contents($this->path . '/' . $id);
} }
$fp = fopen($this->path . '/' . $id, 'rb');
if (!$fp) {
return false;
}
flock($fp, LOCK_SH);
$ret = stream_get_contents($fp);
flock($fp, LOCK_UN);
fclose($fp);
return $ret;
} }
/** /**

View File

@@ -62,9 +62,11 @@ class Minify_Cache_Memcache implements Minify_CacheInterface
return false; return false;
} }
return (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
? mb_strlen($this->_data, '8bit') return mb_strlen($this->_data, '8bit');
: strlen($this->_data); } else {
return strlen($this->_data);
}
} }
/** /**
@@ -88,9 +90,7 @@ class Minify_Cache_Memcache implements Minify_CacheInterface
*/ */
public function display($id) public function display($id)
{ {
echo $this->_fetch($id) echo $this->_fetch($id) ? $this->_data : '';
? $this->_data
: '';
} }
/** /**
@@ -102,9 +102,7 @@ class Minify_Cache_Memcache implements Minify_CacheInterface
*/ */
public function fetch($id) public function fetch($id)
{ {
return $this->_fetch($id) return $this->_fetch($id) ? $this->_data : '';
? $this->_data
: '';
} }
private $_mc = null; private $_mc = null;
@@ -127,12 +125,14 @@ class Minify_Cache_Memcache implements Minify_CacheInterface
if ($this->_id === $id) { if ($this->_id === $id) {
return true; return true;
} }
$ret = $this->_mc->get($id); $ret = $this->_mc->get($id);
if (false === $ret) { if (false === $ret) {
$this->_id = null; $this->_id = null;
return false; return false;
} }
list($this->_lm, $this->_data) = explode('|', $ret, 2); list($this->_lm, $this->_data) = explode('|', $ret, 2);
$this->_id = $id; $this->_id = $id;

View File

@@ -60,7 +60,11 @@ class Minify_Cache_WinCache implements Minify_CacheInterface
return false; return false;
} }
return (function_exists('mb_strlen') && ((int) ini_get('mbstring.func_overload') & 2)) ? mb_strlen($this->_data, '8bit') : strlen($this->_data); if (function_exists('mb_strlen') && ((int) ini_get('mbstring.func_overload') & 2)) {
return mb_strlen($this->_data, '8bit');
} else {
return strlen($this->_data);
}
} }
/** /**
@@ -118,6 +122,7 @@ class Minify_Cache_WinCache implements Minify_CacheInterface
if ($this->_id === $id) { if ($this->_id === $id) {
return true; return true;
} }
$suc = false; $suc = false;
$ret = wincache_ucache_get($id, $suc); $ret = wincache_ucache_get($id, $suc);
if (!$suc) { if (!$suc) {
@@ -125,6 +130,7 @@ class Minify_Cache_WinCache implements Minify_CacheInterface
return false; return false;
} }
list($this->_lm, $this->_data) = explode('|', $ret, 2); list($this->_lm, $this->_data) = explode('|', $ret, 2);
$this->_id = $id; $this->_id = $id;

View File

@@ -56,9 +56,11 @@ class Minify_Cache_XCache implements Minify_CacheInterface
return false; return false;
} }
return (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
? mb_strlen($this->_data, '8bit') return mb_strlen($this->_data, '8bit');
: strlen($this->_data); } else {
return strlen($this->_data);
}
} }
/** /**
@@ -80,9 +82,7 @@ class Minify_Cache_XCache implements Minify_CacheInterface
*/ */
public function display($id) public function display($id)
{ {
echo $this->_fetch($id) echo $this->_fetch($id) ? $this->_data : '';
? $this->_data
: '';
} }
/** /**
@@ -93,9 +93,7 @@ class Minify_Cache_XCache implements Minify_CacheInterface
*/ */
public function fetch($id) public function fetch($id)
{ {
return $this->_fetch($id) return $this->_fetch($id) ? $this->_data : '';
? $this->_data
: '';
} }
private $_exp = null; private $_exp = null;
@@ -116,12 +114,14 @@ class Minify_Cache_XCache implements Minify_CacheInterface
if ($this->_id === $id) { if ($this->_id === $id) {
return true; return true;
} }
$ret = xcache_get($id); $ret = xcache_get($id);
if (false === $ret) { if (false === $ret) {
$this->_id = null; $this->_id = null;
return false; return false;
} }
list($this->_lm, $this->_data) = explode('|', $ret, 2); list($this->_lm, $this->_data) = explode('|', $ret, 2);
$this->_id = $id; $this->_id = $id;

View File

@@ -55,9 +55,7 @@ class Minify_Cache_ZendPlatform implements Minify_CacheInterface
*/ */
public function getSize($id) public function getSize($id)
{ {
return $this->_fetch($id) return $this->_fetch($id) ? strlen($this->_data) : false;
? strlen($this->_data)
: false;
} }
/** /**
@@ -71,9 +69,7 @@ class Minify_Cache_ZendPlatform implements Minify_CacheInterface
*/ */
public function isValid($id, $srcMtime) public function isValid($id, $srcMtime)
{ {
$ret = ($this->_fetch($id) && ($this->_lm >= $srcMtime)); return ($this->_fetch($id) && ($this->_lm >= $srcMtime));
return $ret;
} }
/** /**
@@ -83,9 +79,7 @@ class Minify_Cache_ZendPlatform implements Minify_CacheInterface
*/ */
public function display($id) public function display($id)
{ {
echo $this->_fetch($id) echo $this->_fetch($id) ? $this->_data : '';
? $this->_data
: '';
} }
/** /**
@@ -97,9 +91,7 @@ class Minify_Cache_ZendPlatform implements Minify_CacheInterface
*/ */
public function fetch($id) public function fetch($id)
{ {
return $this->_fetch($id) return $this->_fetch($id) ? $this->_data : '';
? $this->_data
: '';
} }
private $_exp = null; private $_exp = null;
@@ -121,12 +113,14 @@ class Minify_Cache_ZendPlatform implements Minify_CacheInterface
if ($this->_id === $id) { if ($this->_id === $id) {
return true; return true;
} }
$ret = output_cache_get($id, $this->_exp); $ret = output_cache_get($id, $this->_exp);
if (false === $ret) { if (false === $ret) {
$this->_id = null; $this->_id = null;
return false; return false;
} }
list($this->_lm, $this->_data) = explode('|', $ret, 2); list($this->_lm, $this->_data) = explode('|', $ret, 2);
$this->_id = $id; $this->_id = $id;

View File

@@ -72,21 +72,16 @@ class Minify_CommentPreserver
*/ */
private static function _nextComment($in) private static function _nextComment($in)
{ {
if ( if (false === ($start = strpos($in, '/*!')) || false === ($end = strpos($in, '*/', $start + 3))) {
false === ($start = strpos($in, '/*!'))
|| false === ($end = strpos($in, '*/', $start + 3))
) {
return array($in, false, false); return array($in, false, false);
} }
$ret = array(
substr($in, 0, $start)
,self::$prepend . '/*!' . substr($in, $start + 3, $end - $start - 1) . self::$append
);
$endChars = (strlen($in) - $end - 2);
$ret[] = (0 === $endChars)
? ''
: substr($in, -$endChars);
return $ret; $beforeComment = substr($in, 0, $start);
$comment = self::$prepend . '/*!' . substr($in, $start + 3, $end - $start - 1) . self::$append;
$endChars = (strlen($in) - $end - 2);
$afterComment = (0 === $endChars) ? '' : substr($in, -$endChars);
return array($beforeComment, $comment, $afterComment);
} }
} }

View File

@@ -45,12 +45,14 @@ class Minify_Controller_Groups extends Minify_Controller_Files
$server = $this->env->server(); $server = $this->env->server();
// mod_fcgid places PATH_INFO in ORIG_PATH_INFO // mod_fcgid places PATH_INFO in ORIG_PATH_INFO
$pathInfo = isset($server['ORIG_PATH_INFO']) if (isset($server['ORIG_PATH_INFO'])) {
? substr($server['ORIG_PATH_INFO'], 1) $pathInfo = substr($server['ORIG_PATH_INFO'], 1);
: (isset($server['PATH_INFO']) } elseif (isset($server['PATH_INFO'])) {
? substr($server['PATH_INFO'], 1) $pathInfo = substr($server['PATH_INFO'], 1)
: false } else {
); $pathInfo = false;
}
if (false === $pathInfo || ! isset($groups[$pathInfo])) { if (false === $pathInfo || ! isset($groups[$pathInfo])) {
// no PATH_INFO or not a valid group // no PATH_INFO or not a valid group
$this->logger->info("Missing PATH_INFO or no group set for \"$pathInfo\""); $this->logger->info("Missing PATH_INFO or no group set for \"$pathInfo\"");

View File

@@ -31,14 +31,14 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
} }
// filter controller options // filter controller options
$localOptions = array_merge( $defaults = array(
array( 'groupsOnly' => false,
'groupsOnly' => false, 'groups' => array(),
'groups' => array(), 'symlinks' => array(),
'symlinks' => array(),
)
,(isset($options['minApp']) ? $options['minApp'] : array())
); );
$minApp = isset($options['minApp']) ? $options['minApp'] : array();
$localOptions = array_merge($defaults, $minApp);
unset($options['minApp']); unset($options['minApp']);
// normalize $symlinks in order to map to target // normalize $symlinks in order to map to target
@@ -53,7 +53,7 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
$sources = array(); $sources = array();
$selectionId = ''; $selectionId = '';
$firstMissingResource = null; $firstMissing = null;
if (isset($get['g'])) { if (isset($get['g'])) {
// add group(s) // add group(s)
@@ -83,12 +83,12 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
$sources[] = $source; $sources[] = $source;
} catch (Minify_Source_FactoryException $e) { } catch (Minify_Source_FactoryException $e) {
$this->logger->error($e->getMessage()); $this->logger->error($e->getMessage());
if (null === $firstMissingResource) { if (null === $firstMissing) {
$firstMissingResource = basename($file); $firstMissing = basename($file);
continue; continue;
} else { } else {
$secondMissingResource = basename($file); $secondMissing = basename($file);
$this->logger->info("More than one file was missing: '$firstMissingResource', '$secondMissingResource'"); $this->logger->info("More than one file was missing: '$firstMissing', '$secondMissing'");
return new Minify_ServeConfiguration($options); return new Minify_ServeConfiguration($options);
} }
@@ -100,18 +100,18 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
// try user files // try user files
// The following restrictions are to limit the URLs that minify will // The following restrictions are to limit the URLs that minify will
// respond to. // respond to.
if (// verify at least one file, files are single comma separated,
// and are all same extension // verify at least one file, files are single comma separated, and are all same extension
! preg_match('/^[^,]+\\.(css|less|js)(?:,[^,]+\\.\\1)*$/', $get['f'], $m) $validPattern = preg_match('/^[^,]+\\.(css|less|js)(?:,[^,]+\\.\\1)*$/', $get['f'], $m);
// no "//" $hasComment = strpos($get['f'], '//') !== false;
|| strpos($get['f'], '//') !== false $hasEscape = strpos($get['f'], '\\') !== false;
// no "\"
|| strpos($get['f'], '\\') !== false if (!$validPattern || $hasComment || $hasEscape) {
) {
$this->logger->info("GET param 'f' was invalid"); $this->logger->info("GET param 'f' was invalid");
return new Minify_ServeConfiguration($options); return new Minify_ServeConfiguration($options);
} }
$ext = ".{$m[1]}"; $ext = ".{$m[1]}";
$files = explode(',', $get['f']); $files = explode(',', $get['f']);
if ($files != array_unique($files)) { if ($files != array_unique($files)) {
@@ -119,11 +119,14 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
return new Minify_ServeConfiguration($options); return new Minify_ServeConfiguration($options);
} }
if (isset($get['b'])) { if (isset($get['b'])) {
// check for validity // check for validity
if (preg_match('@^[^/]+(?:/[^/]+)*$@', $get['b']) $isValidBase = preg_match('@^[^/]+(?:/[^/]+)*$@', $get['b']);
&& false === strpos($get['b'], '..') $hasDots = false !== strpos($get['b'], '..');
&& $get['b'] !== '.') { $isDot = $get['b'] === '.';
if ($isValidBase && !$hasDots && !$isDot) {
// valid base // valid base
$base = "/{$get['b']}/"; $base = "/{$get['b']}/";
} else { } else {
@@ -154,12 +157,12 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
$basenames[] = basename($path, $ext); $basenames[] = basename($path, $ext);
} catch (Minify_Source_FactoryException $e) { } catch (Minify_Source_FactoryException $e) {
$this->logger->error($e->getMessage()); $this->logger->error($e->getMessage());
if (null === $firstMissingResource) { if (null === $firstMissing) {
$firstMissingResource = $uri; $firstMissing = $uri;
continue; continue;
} else { } else {
$secondMissingResource = $uri; $secondMissing = $uri;
$this->logger->info("More than one file was missing: '$firstMissingResource', '$secondMissingResource`'"); $this->logger->info("More than one file was missing: '$firstMissing', '$secondMissing`'");
return new Minify_ServeConfiguration($options); return new Minify_ServeConfiguration($options);
} }
@@ -177,14 +180,14 @@ class Minify_Controller_MinApp extends Minify_Controller_Base
return new Minify_ServeConfiguration($options); return new Minify_ServeConfiguration($options);
} }
if (null !== $firstMissingResource) { if (null !== $firstMissing) {
array_unshift($sources, new Minify_Source(array( array_unshift($sources, new Minify_Source(array(
'id' => 'missingFile' 'id' => 'missingFile',
// should not cause cache invalidation // should not cause cache invalidation
,'lastModified' => 0 'lastModified' => 0,
// due to caching, filename is unreliable. // due to caching, filename is unreliable.
,'content' => "/* Minify: at least one missing file. See " . Minify::URL_DEBUG . " */\n" 'content' => "/* Minify: at least one missing file. See " . Minify::URL_DEBUG . " */\n",
,'minifier' => 'Minify::nullMinifier' 'minifier' => 'Minify::nullMinifier',
))); )));
} }

View File

@@ -42,8 +42,8 @@ class Minify_Controller_Page extends Minify_Controller_Base
} else { } else {
// strip controller options // strip controller options
$sourceSpec = array( $sourceSpec = array(
'content' => $options['content'] 'content' => $options['content'],
,'id' => $options['id'] 'id' => $options['id'],
); );
$f = $options['id']; $f = $options['id'];
unset($options['content'], $options['id']); unset($options['content'], $options['id']);
@@ -54,8 +54,8 @@ class Minify_Controller_Page extends Minify_Controller_Base
if (isset($options['minifyAll'])) { if (isset($options['minifyAll'])) {
// this will be the 2nd argument passed to Minify_HTML::minify() // this will be the 2nd argument passed to Minify_HTML::minify()
$sourceSpec['minifyOptions'] = array( $sourceSpec['minifyOptions'] = array(
'cssMinifier' => array('Minify_CSSmin', 'minify') 'cssMinifier' => array('Minify_CSSmin', 'minify'),
,'jsMinifier' => array('JSMin\\JSMin', 'minify') 'jsMinifier' => array('JSMin\\JSMin', 'minify'),
); );
unset($options['minifyAll']); unset($options['minifyAll']);
} }

View File

@@ -13,6 +13,7 @@ class Minify_DebugDetector
if ($env->get('debug') !== null) { if ($env->get('debug') !== null) {
return true; return true;
} }
$cookieValue = $env->cookie('minifyDebug'); $cookieValue = $env->cookie('minifyDebug');
if ($cookieValue) { if ($cookieValue) {
foreach (preg_split('/\\s+/', $cookieValue) as $debugUri) { foreach (preg_split('/\\s+/', $cookieValue) as $debugUri) {

View File

@@ -34,6 +34,7 @@ class Minify_Env
} else { } else {
$this->server['DOCUMENT_ROOT'] = rtrim($this->server['DOCUMENT_ROOT'], '/\\'); $this->server['DOCUMENT_ROOT'] = rtrim($this->server['DOCUMENT_ROOT'], '/\\');
} }
$this->server['DOCUMENT_ROOT'] = $this->normalizePath($this->server['DOCUMENT_ROOT']); $this->server['DOCUMENT_ROOT'] = $this->normalizePath($this->server['DOCUMENT_ROOT']);
$this->get = $options['get']; $this->get = $options['get'];
$this->post = $options['post']; $this->post = $options['post'];
@@ -46,9 +47,7 @@ class Minify_Env
return $this->server; return $this->server;
} }
return isset($this->server[$key]) return isset($this->server[$key]) ? $this->server[$key] : null;
? $this->server[$key]
: null;
} }
public function cookie($key = null, $default = null) public function cookie($key = null, $default = null)
@@ -93,6 +92,7 @@ class Minify_Env
if ($realpath) { if ($realpath) {
$path = $realpath; $path = $realpath;
} }
$path = str_replace('\\', '/', $path); $path = str_replace('\\', '/', $path);
$path = rtrim($path, '/'); $path = rtrim($path, '/');
if (substr($path, 1, 1) === ':') { if (substr($path, 1, 1) === ':') {
@@ -118,11 +118,9 @@ class Minify_Env
if (isset($server['SERVER_SOFTWARE']) && 0 !== strpos($server['SERVER_SOFTWARE'], 'Microsoft-IIS/')) { if (isset($server['SERVER_SOFTWARE']) && 0 !== strpos($server['SERVER_SOFTWARE'], 'Microsoft-IIS/')) {
throw new InvalidArgumentException('DOCUMENT_ROOT is not provided and could not be computed'); throw new InvalidArgumentException('DOCUMENT_ROOT is not provided and could not be computed');
} }
$docRoot = substr(
$server['SCRIPT_FILENAME'] $substrLength = strlen($server['SCRIPT_FILENAME']) - strlen($server['SCRIPT_NAME']);
,0 $docRoot = substr($server['SCRIPT_FILENAME'], 0, $substrLength);
,strlen($server['SCRIPT_FILENAME']) - strlen($server['SCRIPT_NAME'])
);
return rtrim($docRoot, '\\'); return rtrim($docRoot, '\\');
} }

View File

@@ -99,8 +99,7 @@ class Minify_HTML_Helper
foreach ($files as $k => $file) { foreach ($files as $k => $file) {
if (0 === strpos($file, '//')) { if (0 === strpos($file, '//')) {
$file = substr($file, 2); $file = substr($file, 2);
} elseif (0 === strpos($file, '/') } elseif (0 === strpos($file, '/') || 1 === strpos($file, ':\\')) {
|| 1 === strpos($file, ':\\')) {
$file = substr($file, strlen(self::app()->env->getDocRoot()) + 1); $file = substr($file, strlen(self::app()->env->getDocRoot()) + 1);
} }
$file = strtr($file, '\\', '/'); $file = strtr($file, '\\', '/');
@@ -243,9 +242,7 @@ class Minify_HTML_Helper
$base = substr($base, 0, strlen($base) - 1); $base = substr($base, 0, strlen($base) - 1);
$bUri = $minRoot . 'b=' . $base . '&f=' . implode(',', $basedPaths); $bUri = $minRoot . 'b=' . $base . '&f=' . implode(',', $basedPaths);
$uri = strlen($uri) < strlen($bUri) $uri = strlen($uri) < strlen($bUri) ? $uri : $bUri;
? $uri
: $bUri;
} }
return $uri; return $uri;

View File

@@ -57,8 +57,7 @@ class Minify_ImportProcessor
$file = realpath($file); $file = realpath($file);
if (! $file if (! $file
|| in_array($file, self::$filesIncluded) || in_array($file, self::$filesIncluded)
|| false === ($content = @file_get_contents($file)) || false === ($content = @file_get_contents($file))) {
) {
// file missing, already included, or failed read // file missing, already included, or failed read
return ''; return '';
} }
@@ -73,8 +72,7 @@ class Minify_ImportProcessor
$content = str_replace("\r\n", "\n", $content); $content = str_replace("\r\n", "\n", $content);
// process @imports // process @imports
$content = preg_replace_callback( $pattern = '/
'/
@import\\s+ @import\\s+
(?:url\\(\\s*)? # maybe url( (?:url\\(\\s*)? # maybe url(
[\'"]? # maybe quote [\'"]? # maybe quote
@@ -83,19 +81,14 @@ class Minify_ImportProcessor
(?:\\s*\\))? # maybe ) (?:\\s*\\))? # maybe )
([a-zA-Z,\\s]*)? # 2 = media list ([a-zA-Z,\\s]*)? # 2 = media list
; # end token ; # end token
/x' /x';
,array($this, '_importCB') $content = preg_replace_callback($pattern, array($this, '_importCB'), $content);
,$content
);
// You only need to rework the import-path if the script is imported // You only need to rework the import-path if the script is imported
if (self::$_isCss && $is_imported) { if (self::$_isCss && $is_imported) {
// rewrite remaining relative URIs // rewrite remaining relative URIs
$content = preg_replace_callback( $pattern = '/url\\(\\s*([^\\)\\s]+)\\s*\\)/';
'/url\\(\\s*([^\\)\\s]+)\\s*\\)/' $content = preg_replace_callback($pattern, array($this, '_urlCB'), $content);
,array($this, '_urlCB')
,$content
);
} }
return $this->_importedContent . $content; return $this->_importedContent . $content;
@@ -139,12 +132,10 @@ class Minify_ImportProcessor
private function _urlCB($m) private function _urlCB($m)
{ {
// $m[1] is either quoted or not // $m[1] is either quoted or not
$quote = ($m[1][0] === "'" || $m[1][0] === '"') $quote = ($m[1][0] === "'" || $m[1][0] === '"') ? $m[1][0] : '';
? $m[1][0]
: ''; $url = ($quote === '') ? $m[1] : substr($m[1], 1, strlen($m[1]) - 2);
$url = ($quote === '')
? $m[1]
: substr($m[1], 1, strlen($m[1]) - 2);
if ('/' !== $url[0]) { if ('/' !== $url[0]) {
if (strpos($url, '//') > 0) { if (strpos($url, '//') > 0) {
// probably starts with protocol, do not alter // probably starts with protocol, do not alter
@@ -190,8 +181,8 @@ class Minify_ImportProcessor
private function truepath($path) private function truepath($path)
{ {
// whether $path is unix or not // whether $path is unix or not
$unipath = strlen($path) == 0 || $path{0} $unipath = (strlen($path) == 0) || ($path{0} != '/');
!= '/';
// attempts to detect if path is relative in which case, add cwd // attempts to detect if path is relative in which case, add cwd
if (strpos($path, ':') === false && $unipath) { if (strpos($path, ':') === false && $unipath) {
$path = $this->_currentDir . DIRECTORY_SEPARATOR . $path; $path = $this->_currentDir . DIRECTORY_SEPARATOR . $path;
@@ -211,6 +202,7 @@ class Minify_ImportProcessor
$absolutes[] = $part; $absolutes[] = $part;
} }
} }
$path = implode(DIRECTORY_SEPARATOR, $absolutes); $path = implode(DIRECTORY_SEPARATOR, $absolutes);
// resolve any symlinks // resolve any symlinks
if (file_exists($path) && linkinfo($path) > 0) { if (file_exists($path) && linkinfo($path) > 0) {

View File

@@ -37,9 +37,7 @@ class Minify_Lines
*/ */
public static function minify($content, $options = array()) public static function minify($content, $options = array())
{ {
$id = (isset($options['id']) && $options['id']) $id = (isset($options['id']) && $options['id']) ? $options['id'] : '';
? $options['id']
: '';
$content = str_replace("\r\n", "\n", $content); $content = str_replace("\r\n", "\n", $content);
$lines = explode("\n", $content); $lines = explode("\n", $content);
@@ -49,6 +47,7 @@ class Minify_Lines
$inComment = false; $inComment = false;
$i = 0; $i = 0;
$newLines = array(); $newLines = array();
while (null !== ($line = array_shift($lines))) { while (null !== ($line = array_shift($lines))) {
if (('' !== $id) && (0 == $i % 50)) { if (('' !== $id) && (0 == $i % 50)) {
if ($inComment) { if ($inComment) {
@@ -57,24 +56,25 @@ class Minify_Lines
array_push($newLines, '', "/* {$id} */", ''); array_push($newLines, '', "/* {$id} */", '');
} }
} }
++$i; ++$i;
$newLines[] = self::_addNote($line, $i, $inComment, $padTo); $newLines[] = self::_addNote($line, $i, $inComment, $padTo);
$inComment = self::_eolInComment($line, $inComment); $inComment = self::_eolInComment($line, $inComment);
} }
$content = implode("\n", $newLines) . "\n"; $content = implode("\n", $newLines) . "\n";
// check for desired URI rewriting // check for desired URI rewriting
if (isset($options['currentDir'])) { if (isset($options['currentDir'])) {
Minify_CSS_UriRewriter::$debugText = ''; Minify_CSS_UriRewriter::$debugText = '';
$content = Minify_CSS_UriRewriter::rewrite( $docRoot = isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT'];
$content $symlinks = isset($options['symlinks']) ? $options['symlinks'] : array();
,$options['currentDir']
,isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT'] $content = Minify_CSS_UriRewriter::rewrite($content, $options['currentDir'], $docRoot, $symlinks);
,isset($options['symlinks']) ? $options['symlinks'] : array()
);
$content = "/* Minify_CSS_UriRewriter::\$debugText\n\n" $content = "/* Minify_CSS_UriRewriter::\$debugText\n\n"
. Minify_CSS_UriRewriter::$debugText . "*/\n" . Minify_CSS_UriRewriter::$debugText . "*/\n"
. $content; . $content;
} }
return $content; return $content;
@@ -143,9 +143,11 @@ class Minify_Lines
*/ */
private static function _addNote($line, $note, $inComment, $padTo) private static function _addNote($line, $note, $inComment, $padTo)
{ {
$line = $inComment if ($inComment) {
? '/* ' . str_pad($note, $padTo, ' ', STR_PAD_RIGHT) . ' *| ' . $line $line = '/* ' . str_pad($note, $padTo, ' ', STR_PAD_RIGHT) . ' *| ' . $line;
: '/* ' . str_pad($note, $padTo, ' ', STR_PAD_RIGHT) . ' */ ' . $line; } else {
$line = '/* ' . str_pad($note, $padTo, ' ', STR_PAD_RIGHT) . ' */ ' . $line;
}
return rtrim($line); return rtrim($line);
} }

View File

@@ -72,13 +72,13 @@ class Minify_Source implements Minify_SourceInterface
$ext = pathinfo($spec['filepath'], PATHINFO_EXTENSION); $ext = pathinfo($spec['filepath'], PATHINFO_EXTENSION);
switch ($ext) { switch ($ext) {
case 'js': $this->contentType = Minify::TYPE_JS; case 'js': $this->contentType = Minify::TYPE_JS;
break; break;
case 'less': // fallthrough case 'less': // fallthrough
case 'css': $this->contentType = Minify::TYPE_CSS; case 'css': $this->contentType = Minify::TYPE_CSS;
break; break;
case 'htm': // fallthrough case 'htm': // fallthrough
case 'html': $this->contentType = Minify::TYPE_HTML; case 'html': $this->contentType = Minify::TYPE_HTML;
break; break;
} }
$this->filepath = $spec['filepath']; $this->filepath = $spec['filepath'];
$this->id = $spec['filepath']; $this->id = $spec['filepath'];
@@ -97,9 +97,7 @@ class Minify_Source implements Minify_SourceInterface
} else { } else {
$this->getContentFunc = $spec['getContentFunc']; $this->getContentFunc = $spec['getContentFunc'];
} }
$this->lastModified = isset($spec['lastModified']) $this->lastModified = isset($spec['lastModified']) ? $spec['lastModified'] : time();
? $spec['lastModified']
: time();
} }
if (isset($spec['contentType'])) { if (isset($spec['contentType'])) {
$this->contentType = $spec['contentType']; $this->contentType = $spec['contentType'];
@@ -208,8 +206,8 @@ class Minify_Source implements Minify_SourceInterface
{ {
if ($this->filepath if ($this->filepath
&& !isset($this->minifyOptions['currentDir']) && !isset($this->minifyOptions['currentDir'])
&& !isset($this->minifyOptions['prependRelativePath']) && !isset($this->minifyOptions['prependRelativePath'])) {
) {
$this->minifyOptions['currentDir'] = dirname($this->filepath); $this->minifyOptions['currentDir'] = dirname($this->filepath);
} }
} }

View File

@@ -93,6 +93,7 @@ class Minify_YUICompressor
if (! ($tmpFile = tempnam(self::$tempDir, 'yuic_'))) { if (! ($tmpFile = tempnam(self::$tempDir, 'yuic_'))) {
throw new Exception('Minify_YUICompressor : could not create temp file in "'.self::$tempDir.'".'); throw new Exception('Minify_YUICompressor : could not create temp file in "'.self::$tempDir.'".');
} }
file_put_contents($tmpFile, $content); file_put_contents($tmpFile, $content);
exec(self::_getCmd($options, $type, $tmpFile), $output, $result_code); exec(self::_getCmd($options, $type, $tmpFile), $output, $result_code);
unlink($tmpFile); unlink($tmpFile);
@@ -105,22 +106,19 @@ class Minify_YUICompressor
private static function _getCmd($userOptions, $type, $tmpFile) private static function _getCmd($userOptions, $type, $tmpFile)
{ {
$o = array_merge( $defaults = array(
array( 'charset' => '',
'charset' => '' 'line-break' => 5000,
,'line-break' => 5000 'type' => $type,
,'type' => $type 'nomunge' => false,
,'nomunge' => false 'preserve-semi' => false,
,'preserve-semi' => false 'disable-optimizations' => false,
,'disable-optimizations' => false 'stack-size' => '',
,'stack-size' => ''
)
,$userOptions
); );
$o = array_merge($defaults, $userOptions);
$cmd = self::$javaExecutable $cmd = self::$javaExecutable
. (!empty($o['stack-size']) . (!empty($o['stack-size']) ? ' -Xss' . $o['stack-size'] : '')
? ' -Xss' . $o['stack-size']
: '')
. ' -jar ' . escapeshellarg(self::$jarFile) . ' -jar ' . escapeshellarg(self::$jarFile)
. " --type {$type}" . " --type {$type}"
. (preg_match('/^[\\da-zA-Z0-9\\-]+$/', $o['charset']) . (preg_match('/^[\\da-zA-Z0-9\\-]+$/', $o['charset'])