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

Rewrite relative URIs in CSS by default (adjusted test accordingly)

Minify.php: + 'rewriteCssUris' option
Controller/Base.php: + 'rewriteCssUris' default value
Controller/Version1.php: moved rewriting to serve()
Minify/CSS.php: renamed option 'currentPath' to 'currentDir'
Minify/Source.php: made $filepath public
This commit is contained in:
Steve Clay
2008-08-18 23:38:39 +00:00
parent 711fbeb365
commit 03e1989d35
7 changed files with 58 additions and 26 deletions

View File

@@ -33,8 +33,8 @@ class Minify_CSS {
* 'prependRelativePath': (default null) if given, this string will be
* prepended to all relative URIs in import/url declarations
*
* 'currentPath': (default null) if given, this is assumed to be the
* file path of the current CSS file. Using this, minify will rewrite
* '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.
@@ -185,8 +185,8 @@ class Minify_CSS {
if (isset($options['prependRelativePath'])) {
self::$_tempPrepend = $options['prependRelativePath'];
$rewrite = true;
} elseif (isset($options['currentPath'])) {
self::$_tempCurrentPath = $options['currentPath'];
} elseif (isset($options['currentDir'])) {
self::$_tempCurrentDir = $options['currentDir'];
$rewrite = true;
}
if ($rewrite) {
@@ -195,7 +195,7 @@ class Minify_CSS {
$css = preg_replace_callback('/url\\(([^\\)]+)\\)/'
,array('Minify_CSS', '_urlCB'), $css);
}
self::$_tempPrepend = self::$_tempCurrentPath = '';
self::$_tempPrepend = self::$_tempCurrentDir = '';
return trim($css);
}
@@ -225,9 +225,9 @@ class Minify_CSS {
protected static $_tempPrepend = '';
/**
* @var string path of this stylesheet for rewriting purposes
* @var string directory of this stylesheet for rewriting purposes
*/
protected static $_tempCurrentPath = '';
protected static $_tempCurrentDir = '';
/**
* Process a comment and return a replacement
@@ -302,7 +302,7 @@ class Minify_CSS {
} else {
// rewrite absolute url from scratch!
// prepend path with current dir separator (OS-independent)
$path = self::$_tempCurrentPath
$path = self::$_tempCurrentDir
. DIRECTORY_SEPARATOR . strtr($url, '/', DIRECTORY_SEPARATOR);
// strip doc root
$path = substr($path, strlen($_SERVER['DOCUMENT_ROOT']));

View File

@@ -48,7 +48,8 @@ abstract class Minify_Controller_Base {
,'encodeLevel' => 9
,'minifierOptions' => array() // no minifier options
,'contentTypeCharset' => 'UTF-8'
,'maxAge' => 1800 // 30 minutes
,'maxAge' => 1800 // 30 minutes
,'rewriteCssUris' => true
,'quiet' => false // serve() will send headers and output
,'debug' => false

View File

@@ -84,9 +84,6 @@ class Minify_Controller_Version1 extends Minify_Controller_Base {
$srcOptions = array(
'filepath' => $file
);
if ('css' === $extension && MINIFY_REWRITE_CSS_URLS) {
$srcOptions['minifyOptions']['currentPath'] = dirname($file);
}
$this->sources[] = new Minify_Source($srcOptions);
} else {
$hasBadSource = true;
@@ -95,6 +92,9 @@ class Minify_Controller_Version1 extends Minify_Controller_Base {
}
if ($hasBadSource) {
$this->sources = array();
}
if (! MINIFY_REWRITE_CSS_URLS) {
$options['rewriteCssUris'] = false;
}
return $options;
}

View File

@@ -29,7 +29,12 @@ class Minify_Source {
* @var array minification options specific to this source.
*/
public $minifyOptions = null;
/**
* @var string full path of file
*/
public $filepath = null;
/**
* Create a Minify_Source
*
@@ -49,7 +54,7 @@ class Minify_Source {
if (0 === strpos($spec['filepath'], '//')) {
$spec['filepath'] = $_SERVER['DOCUMENT_ROOT'] . substr($spec['filepath'], 1);
}
$this->_filepath = $spec['filepath'];
$this->filepath = $spec['filepath'];
$this->_id = $spec['filepath'];
$this->lastModified = filemtime($spec['filepath'])
// offset for Windows uploaders with out of sync clocks
@@ -80,8 +85,8 @@ class Minify_Source {
*/
public function getContent()
{
$content = (null !== $this->_filepath)
? file_get_contents($this->_filepath)
$content = (null !== $this->filepath)
? file_get_contents($this->filepath)
: ((null !== $this->_content)
? $this->_content
: call_user_func($this->_getContentFunc, $this->_id)
@@ -154,8 +159,8 @@ class Minify_Source {
,'html' => Minify::TYPE_HTML
);
foreach ($sources as $source) {
if (null !== $source->_filepath) {
$segments = explode('.', $source->_filepath);
if (null !== $source->filepath) {
$segments = explode('.', $source->filepath);
$ext = array_pop($segments);
if (isset($exts[$ext])) {
return $exts[$ext];
@@ -166,8 +171,7 @@ class Minify_Source {
}
protected $_content = null;
protected $_getContentFunc = null;
protected $_filepath = null;
protected $_getContentFunc = null;
protected $_id = null;
}