mirror of
https://github.com/mrclay/minify.git
synced 2025-08-07 06:36:29 +02:00
Apply php-cs-fixer fixers
- braces - function_declaration - lowercase_keywords - method_argument_space - no_spaces_inside_parenthesis - no_trailing_whitespace - no_trailing_whitespace_in_comment - single_blank_line_at_eof
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$app = (require __DIR__ . '/../bootstrap.php');
|
$app = (require __DIR__ . '/../bootstrap.php');
|
||||||
/* @var \Minify\App $app */
|
/* @var \Minify\App $app */
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* AJAX checks for zlib.output_compression
|
* AJAX checks for zlib.output_compression
|
||||||
*
|
*
|
||||||
* @package Minify
|
* @package Minify
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -29,7 +29,6 @@ if ($app->env->get('hello')) {
|
|||||||
));
|
));
|
||||||
$he->encode();
|
$he->encode();
|
||||||
$he->sendAll();
|
$he->sendAll();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// echo status "0" or "1"
|
// echo status "0" or "1"
|
||||||
header('Content-Type: text/plain');
|
header('Content-Type: text/plain');
|
||||||
|
@@ -37,7 +37,7 @@ if (isset($_GET['oc'])) {
|
|||||||
echo "<p class=topNote><strong>\$_SERVER['SUBDOMAIN_DOCUMENT_ROOT'] is set.</strong> "
|
echo "<p class=topNote><strong>\$_SERVER['SUBDOMAIN_DOCUMENT_ROOT'] is set.</strong> "
|
||||||
. "You may need to set \$min_documentRoot to this in config.php</p>";
|
. "You may need to set \$min_documentRoot to this in config.php</p>";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//*/
|
//*/
|
||||||
|
@@ -4,7 +4,6 @@
|
|||||||
*
|
*
|
||||||
* To test config options, place them in this file and add "&test" to your Minify URL.
|
* To test config options, place them in this file and add "&test" to your Minify URL.
|
||||||
* Note that if this is on a public server, anyone can execute your test.
|
* Note that if this is on a public server, anyone can execute your test.
|
||||||
*
|
*
|
||||||
* @package Minify
|
* @package Minify
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
39
config.php
39
config.php
@@ -2,7 +2,7 @@
|
|||||||
/**
|
/**
|
||||||
* Configuration for "min", the default application built with the Minify
|
* Configuration for "min", the default application built with the Minify
|
||||||
* library
|
* library
|
||||||
*
|
*
|
||||||
* @package Minify
|
* @package Minify
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ $min_errorLogger = false;
|
|||||||
* /min/f=file1.js send the cookie minDebug=file1.js
|
* /min/f=file1.js send the cookie minDebug=file1.js
|
||||||
* You can manually enable debugging by appending "&debug" to a URI.
|
* You can manually enable debugging by appending "&debug" to a URI.
|
||||||
* E.g. /min/?f=script1.js,script2.js&debug
|
* E.g. /min/?f=script1.js,script2.js&debug
|
||||||
*
|
*
|
||||||
* In 'debug' mode, Minify combines files with no minification and adds comments
|
* In 'debug' mode, Minify combines files with no minification and adds comments
|
||||||
* to indicate line #s of the original files.
|
* to indicate line #s of the original files.
|
||||||
*/
|
*/
|
||||||
@@ -73,11 +73,11 @@ $min_allowDebugFlag = false;
|
|||||||
/**
|
/**
|
||||||
* Leave an empty string to use PHP's $_SERVER['DOCUMENT_ROOT'].
|
* Leave an empty string to use PHP's $_SERVER['DOCUMENT_ROOT'].
|
||||||
*
|
*
|
||||||
* On some servers, this value may be misconfigured or missing. If so, set this
|
* On some servers, this value may be misconfigured or missing. If so, set this
|
||||||
* to your full document root path with no trailing slash.
|
* to your full document root path with no trailing slash.
|
||||||
* E.g. '/home/accountname/public_html' or 'c:\\xampp\\htdocs'
|
* E.g. '/home/accountname/public_html' or 'c:\\xampp\\htdocs'
|
||||||
*
|
*
|
||||||
* If /min/ is directly inside your document root, just uncomment the
|
* If /min/ is directly inside your document root, just uncomment the
|
||||||
* second line. The third line might work on some Apache servers.
|
* second line. The third line might work on some Apache servers.
|
||||||
*/
|
*/
|
||||||
$min_documentRoot = '';
|
$min_documentRoot = '';
|
||||||
@@ -87,7 +87,7 @@ $min_documentRoot = '';
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache file locking. Set to false if filesystem is NFS. On at least one
|
* Cache file locking. Set to false if filesystem is NFS. On at least one
|
||||||
* NFS system flock-ing attempts stalled PHP for 30 seconds!
|
* NFS system flock-ing attempts stalled PHP for 30 seconds!
|
||||||
*/
|
*/
|
||||||
$min_cacheFileLocking = true;
|
$min_cacheFileLocking = true;
|
||||||
@@ -96,9 +96,9 @@ $min_cacheFileLocking = true;
|
|||||||
/**
|
/**
|
||||||
* Combining multiple CSS files can place @import declarations after rules, which
|
* Combining multiple CSS files can place @import declarations after rules, which
|
||||||
* is invalid. Minify will attempt to detect when this happens and place a
|
* is invalid. Minify will attempt to detect when this happens and place a
|
||||||
* warning comment at the top of the CSS output. To resolve this you can either
|
* warning comment at the top of the CSS output. To resolve this you can either
|
||||||
* move the @imports within your CSS files, or enable this option, which will
|
* move the @imports within your CSS files, or enable this option, which will
|
||||||
* move all @imports to the top of the output. Note that moving @imports could
|
* move all @imports to the top of the output. Note that moving @imports could
|
||||||
* affect CSS values (which is why this option is disabled by default).
|
* affect CSS values (which is why this option is disabled by default).
|
||||||
*/
|
*/
|
||||||
$min_serveOptions['bubbleCssImports'] = false;
|
$min_serveOptions['bubbleCssImports'] = false;
|
||||||
@@ -134,8 +134,8 @@ $min_serveOptions['maxAge'] = 1800;
|
|||||||
* particular directories below DOCUMENT_ROOT, set this here.
|
* particular directories below DOCUMENT_ROOT, set this here.
|
||||||
* You will still need to include the directory in the
|
* You will still need to include the directory in the
|
||||||
* f or b GET parameters.
|
* f or b GET parameters.
|
||||||
*
|
*
|
||||||
* // = shortcut for DOCUMENT_ROOT
|
* // = shortcut for DOCUMENT_ROOT
|
||||||
*/
|
*/
|
||||||
//$min_serveOptions['minApp']['allowDirs'] = array('//js', '//css');
|
//$min_serveOptions['minApp']['allowDirs'] = array('//js', '//css');
|
||||||
|
|
||||||
@@ -149,7 +149,7 @@ $min_serveOptions['minApp']['groupsOnly'] = false;
|
|||||||
/**
|
/**
|
||||||
* By default, Minify will not minify files with names containing .min or -min
|
* By default, Minify will not minify files with names containing .min or -min
|
||||||
* before the extension. E.g. myFile.min.js will not be processed by JSMin
|
* before the extension. E.g. myFile.min.js will not be processed by JSMin
|
||||||
*
|
*
|
||||||
* To minify all files, set this option to null. You could also specify your
|
* To minify all files, set this option to null. You could also specify your
|
||||||
* own pattern that is matched against the filename.
|
* own pattern that is matched against the filename.
|
||||||
*/
|
*/
|
||||||
@@ -160,8 +160,8 @@ $min_serveOptions['minApp']['groupsOnly'] = false;
|
|||||||
* If you minify CSS files stored in symlink-ed directories, the URI rewriting
|
* If you minify CSS files stored in symlink-ed directories, the URI rewriting
|
||||||
* algorithm can fail. To prevent this, provide an array of link paths to
|
* algorithm can fail. To prevent this, provide an array of link paths to
|
||||||
* target paths, where the link paths are within the document root.
|
* target paths, where the link paths are within the document root.
|
||||||
*
|
*
|
||||||
* Because paths need to be normalized for this to work, use "//" to substitute
|
* 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.:
|
* the doc root in the link paths (the array keys). E.g.:
|
||||||
* <code>
|
* <code>
|
||||||
* array('//symlink' => '/real/target/path') // unix
|
* array('//symlink' => '/real/target/path') // unix
|
||||||
@@ -173,17 +173,17 @@ $min_symlinks = array();
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* If you upload files from Windows to a non-Windows server, Windows may report
|
* If you upload files from Windows to a non-Windows server, Windows may report
|
||||||
* incorrect mtimes for the files. This may cause Minify to keep serving stale
|
* incorrect mtimes for the files. This may cause Minify to keep serving stale
|
||||||
* cache files when source file changes are made too frequently (e.g. more than
|
* cache files when source file changes are made too frequently (e.g. more than
|
||||||
* once an hour).
|
* once an hour).
|
||||||
*
|
*
|
||||||
* Immediately after modifying and uploading a file, use the touch command to
|
* Immediately after modifying and uploading a file, use the touch command to
|
||||||
* update the mtime on the server. If the mtime jumps ahead by a number of hours,
|
* update the mtime on the server. If the mtime jumps ahead by a number of hours,
|
||||||
* set this variable to that number. If the mtime moves back, this should not be
|
* set this variable to that number. If the mtime moves back, this should not be
|
||||||
* needed.
|
* needed.
|
||||||
*
|
*
|
||||||
* In the Windows SFTP client WinSCP, there's an option that may fix this
|
* In the Windows SFTP client WinSCP, there's an option that may fix this
|
||||||
* issue without changing the variable below. Under login > environment,
|
* issue without changing the variable below. Under login > environment,
|
||||||
* select the option "Adjust remote timestamp with DST".
|
* select the option "Adjust remote timestamp with DST".
|
||||||
* @link http://winscp.net/eng/docs/ui_login_environment#daylight_saving_time
|
* @link http://winscp.net/eng/docs/ui_login_environment#daylight_saving_time
|
||||||
*/
|
*/
|
||||||
@@ -198,4 +198,3 @@ $min_uploaderHoursBehind = 0;
|
|||||||
*/
|
*/
|
||||||
//$min_factories['minify'] = ... a callable accepting a Minify\App object
|
//$min_factories['minify'] = ... a callable accepting a Minify\App object
|
||||||
//$min_factories['controller'] = ... a callable accepting a Minify\App object
|
//$min_factories['controller'] = ... a callable accepting a Minify\App object
|
||||||
|
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Sets up MinApp controller and serves files
|
* Sets up MinApp controller and serves files
|
||||||
*
|
*
|
||||||
* DO NOT EDIT! Configure this utility via config.php and groupsConfig.php
|
* DO NOT EDIT! Configure this utility via config.php and groupsConfig.php
|
||||||
*
|
*
|
||||||
* @package Minify
|
* @package Minify
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@@ -204,9 +204,10 @@ class HTTP_Encoder
|
|||||||
}
|
}
|
||||||
// gzip checks (slow)
|
// gzip checks (slow)
|
||||||
if (preg_match(
|
if (preg_match(
|
||||||
'@(?:^|,)\\s*((?:x-)?gzip)\\s*(?:$|,|;\\s*q=(?:0\\.|1))@'
|
'@(?:^|,)\\s*((?:x-)?gzip)\\s*(?:$|,|;\\s*q=(?:0\\.|1))@',
|
||||||
,$ae
|
$ae,
|
||||||
,$m)) {
|
$m
|
||||||
|
)) {
|
||||||
return array('gzip', $m[1]);
|
return array('gzip', $m[1]);
|
||||||
}
|
}
|
||||||
if ($allowDeflate) {
|
if ($allowDeflate) {
|
||||||
@@ -217,14 +218,17 @@ class HTTP_Encoder
|
|||||||
|| 0 === strpos($ae, 'deflate,') // opera
|
|| 0 === strpos($ae, 'deflate,') // opera
|
||||||
// slow parsing
|
// slow parsing
|
||||||
|| preg_match(
|
|| preg_match(
|
||||||
'@(?:^|,)\\s*deflate\\s*(?:$|,|;\\s*q=(?:0\\.|1))@', $ae)) {
|
'@(?:^|,)\\s*deflate\\s*(?:$|,|;\\s*q=(?:0\\.|1))@',
|
||||||
|
$ae
|
||||||
|
)) {
|
||||||
return array('deflate', 'deflate');
|
return array('deflate', 'deflate');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($allowCompress && preg_match(
|
if ($allowCompress && preg_match(
|
||||||
'@(?:^|,)\\s*((?:x-)?compress)\\s*(?:$|,|;\\s*q=(?:0\\.|1))@'
|
'@(?:^|,)\\s*((?:x-)?compress)\\s*(?:$|,|;\\s*q=(?:0\\.|1))@',
|
||||||
,$ae
|
$ae,
|
||||||
,$m)) {
|
$m
|
||||||
|
)) {
|
||||||
return array('compress', $m[1]);
|
return array('compress', $m[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -242,7 +242,7 @@ class Minify
|
|||||||
if (! $this->options['quiet']) {
|
if (! $this->options['quiet']) {
|
||||||
$this->errorExit($this->options['badRequestHeader'], self::URL_DEBUG);
|
$this->errorExit($this->options['badRequestHeader'], self::URL_DEBUG);
|
||||||
} else {
|
} else {
|
||||||
list(,$statusCode) = explode(' ', $this->options['badRequestHeader']);
|
list(, $statusCode) = explode(' ', $this->options['badRequestHeader']);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'success' => false,
|
'success' => false,
|
||||||
@@ -470,7 +470,7 @@ class Minify
|
|||||||
public function errorExit($header, $url = '', $msgHtml = '')
|
public function errorExit($header, $url = '', $msgHtml = '')
|
||||||
{
|
{
|
||||||
$url = htmlspecialchars($url, ENT_QUOTES);
|
$url = htmlspecialchars($url, ENT_QUOTES);
|
||||||
list(,$h1) = explode(' ', $header, 2);
|
list(, $h1) = explode(' ', $header, 2);
|
||||||
$h1 = htmlspecialchars($h1);
|
$h1 = htmlspecialchars($h1);
|
||||||
// FastCGI environments require 3rd arg to header() to be set
|
// FastCGI environments require 3rd arg to header() to be set
|
||||||
list(, $code) = explode(' ', $header, 3);
|
list(, $code) = explode(' ', $header, 3);
|
||||||
@@ -593,7 +593,8 @@ 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();
|
||||||
|
@@ -82,8 +82,7 @@ class App extends Container
|
|||||||
|
|
||||||
$varDefined = get_defined_vars();
|
$varDefined = get_defined_vars();
|
||||||
|
|
||||||
$varNames = array_filter($varNames, function($name) use($varDefined)
|
$varNames = array_filter($varNames, function ($name) use ($varDefined) {
|
||||||
{
|
|
||||||
return array_key_exists($name, $varDefined);
|
return array_key_exists($name, $varDefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -73,16 +73,16 @@ class Minify_CSSmin
|
|||||||
}
|
}
|
||||||
if ($options['currentDir']) {
|
if ($options['currentDir']) {
|
||||||
return Minify_CSS_UriRewriter::rewrite(
|
return Minify_CSS_UriRewriter::rewrite(
|
||||||
$css
|
$css,
|
||||||
,$options['currentDir']
|
$options['currentDir'],
|
||||||
,$options['docRoot']
|
$options['docRoot'],
|
||||||
,$options['symlinks']
|
$options['symlinks']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Minify_CSS_UriRewriter::prepend(
|
return Minify_CSS_UriRewriter::prepend(
|
||||||
$css
|
$css,
|
||||||
,$options['prependRelativePath']
|
$options['prependRelativePath']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -64,4 +64,4 @@ class Minify_Cache_Null implements Minify_CacheInterface
|
|||||||
public function fetch($id)
|
public function fetch($id)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -136,4 +136,4 @@ class Minify_Cache_WinCache implements Minify_CacheInterface
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -68,4 +68,3 @@ class Minify_Controller_Files extends Minify_Controller_Base
|
|||||||
return new Minify_ServeConfiguration($options, $sources);
|
return new Minify_ServeConfiguration($options, $sources);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -73,4 +73,3 @@ class Minify_Controller_Groups extends Minify_Controller_Files
|
|||||||
return parent::createConfiguration($options);
|
return parent::createConfiguration($options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -66,4 +66,3 @@ class Minify_Controller_Page extends Minify_Controller_Base
|
|||||||
return new Minify_ServeConfiguration($options, $sources, $selectionId);
|
return new Minify_ServeConfiguration($options, $sources, $selectionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -19,4 +19,4 @@ interface Minify_ControllerInterface
|
|||||||
* @return Minify_Env
|
* @return Minify_Env
|
||||||
*/
|
*/
|
||||||
public function getEnv();
|
public function getEnv();
|
||||||
}
|
}
|
||||||
|
@@ -99,32 +99,34 @@ class Minify_HTML
|
|||||||
|
|
||||||
// replace SCRIPTs (and minify) with placeholders
|
// replace SCRIPTs (and minify) with placeholders
|
||||||
$this->_html = preg_replace_callback(
|
$this->_html = preg_replace_callback(
|
||||||
'/(\\s*)<script(\\b[^>]*?>)([\\s\\S]*?)<\\/script>(\\s*)/iu'
|
'/(\\s*)<script(\\b[^>]*?>)([\\s\\S]*?)<\\/script>(\\s*)/iu',
|
||||||
,array($this, '_removeScriptCB')
|
array($this, '_removeScriptCB'),
|
||||||
,$this->_html);
|
$this->_html
|
||||||
|
);
|
||||||
|
|
||||||
// replace STYLEs (and minify) with placeholders
|
// replace STYLEs (and minify) with placeholders
|
||||||
$this->_html = preg_replace_callback(
|
$this->_html = preg_replace_callback(
|
||||||
'/\\s*<style(\\b[^>]*>)([\\s\\S]*?)<\\/style>\\s*/iu'
|
'/\\s*<style(\\b[^>]*>)([\\s\\S]*?)<\\/style>\\s*/iu',
|
||||||
,array($this, '_removeStyleCB')
|
array($this, '_removeStyleCB'),
|
||||||
,$this->_html);
|
$this->_html
|
||||||
|
);
|
||||||
|
|
||||||
// remove HTML comments (not containing IE conditional comments).
|
// remove HTML comments (not containing IE conditional comments).
|
||||||
$this->_html = preg_replace_callback(
|
$this->_html = preg_replace_callback(
|
||||||
'/<!--([\\s\\S]*?)-->/u'
|
'/<!--([\\s\\S]*?)-->/u',
|
||||||
,array($this, '_commentCB')
|
array($this, '_commentCB'),
|
||||||
,$this->_html);
|
$this->_html
|
||||||
|
);
|
||||||
|
|
||||||
// replace PREs with placeholders
|
// replace PREs with placeholders
|
||||||
$this->_html = preg_replace_callback('/\\s*<pre(\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/iu'
|
$this->_html = preg_replace_callback('/\\s*<pre(\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/iu', array($this, '_removePreCB'), $this->_html);
|
||||||
,array($this, '_removePreCB')
|
|
||||||
,$this->_html);
|
|
||||||
|
|
||||||
// replace TEXTAREAs with placeholders
|
// replace TEXTAREAs with placeholders
|
||||||
$this->_html = preg_replace_callback(
|
$this->_html = preg_replace_callback(
|
||||||
'/\\s*<textarea(\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/iu'
|
'/\\s*<textarea(\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/iu',
|
||||||
,array($this, '_removeTextareaCB')
|
array($this, '_removeTextareaCB'),
|
||||||
,$this->_html);
|
$this->_html
|
||||||
|
);
|
||||||
|
|
||||||
// trim each line.
|
// trim each line.
|
||||||
// @todo take into account attribute values that span multiple lines.
|
// @todo take into account attribute values that span multiple lines.
|
||||||
@@ -139,24 +141,25 @@ class Minify_HTML
|
|||||||
|
|
||||||
// remove ws outside of all elements
|
// remove ws outside of all elements
|
||||||
$this->_html = preg_replace(
|
$this->_html = preg_replace(
|
||||||
'/>(\\s(?:\\s*))?([^<]+)(\\s(?:\s*))?</u'
|
'/>(\\s(?:\\s*))?([^<]+)(\\s(?:\s*))?</u',
|
||||||
,'>$1$2$3<'
|
'>$1$2$3<',
|
||||||
,$this->_html);
|
$this->_html
|
||||||
|
);
|
||||||
|
|
||||||
// use newlines before 1st attribute in open tags (to limit line lengths)
|
// use newlines before 1st attribute in open tags (to limit line lengths)
|
||||||
$this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/iu', "$1\n$2", $this->_html);
|
$this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/iu', "$1\n$2", $this->_html);
|
||||||
|
|
||||||
// fill placeholders
|
// fill placeholders
|
||||||
$this->_html = str_replace(
|
$this->_html = str_replace(
|
||||||
array_keys($this->_placeholders)
|
array_keys($this->_placeholders),
|
||||||
,array_values($this->_placeholders)
|
array_values($this->_placeholders),
|
||||||
,$this->_html
|
$this->_html
|
||||||
);
|
);
|
||||||
// issue 229: multi-pass to catch scripts that didn't get replaced in textareas
|
// issue 229: multi-pass to catch scripts that didn't get replaced in textareas
|
||||||
$this->_html = str_replace(
|
$this->_html = str_replace(
|
||||||
array_keys($this->_placeholders)
|
array_keys($this->_placeholders),
|
||||||
,array_values($this->_placeholders)
|
array_values($this->_placeholders),
|
||||||
,$this->_html
|
$this->_html
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this->_html;
|
return $this->_html;
|
||||||
@@ -209,7 +212,8 @@ class Minify_HTML
|
|||||||
: 'trim';
|
: 'trim';
|
||||||
$css = call_user_func($minifier, $css);
|
$css = call_user_func($minifier, $css);
|
||||||
|
|
||||||
return $this->_reservePlace($this->_needsCdata($css)
|
return $this->_reservePlace(
|
||||||
|
$this->_needsCdata($css)
|
||||||
? "{$openStyle}/*<![CDATA[*/{$css}/*]]>*/</style>"
|
? "{$openStyle}/*<![CDATA[*/{$css}/*]]>*/</style>"
|
||||||
: "{$openStyle}{$css}</style>"
|
: "{$openStyle}{$css}</style>"
|
||||||
);
|
);
|
||||||
@@ -238,7 +242,8 @@ class Minify_HTML
|
|||||||
: 'trim';
|
: 'trim';
|
||||||
$js = call_user_func($minifier, $js);
|
$js = call_user_func($minifier, $js);
|
||||||
|
|
||||||
return $this->_reservePlace($this->_needsCdata($js)
|
return $this->_reservePlace(
|
||||||
|
$this->_needsCdata($js)
|
||||||
? "{$ws1}{$openScript}/*<![CDATA[*/{$js}/*]]>*/</script>{$ws2}"
|
? "{$ws1}{$openScript}/*<![CDATA[*/{$js}/*]]>*/</script>{$ws2}"
|
||||||
: "{$ws1}{$openScript}{$js}</script>{$ws2}"
|
: "{$ws1}{$openScript}{$js}</script>{$ws2}"
|
||||||
);
|
);
|
||||||
|
@@ -66,7 +66,7 @@ class Minify_ImportProcessor
|
|||||||
$this->_currentDir = dirname($file);
|
$this->_currentDir = dirname($file);
|
||||||
|
|
||||||
// remove UTF-8 BOM if present
|
// remove UTF-8 BOM if present
|
||||||
if (pack("CCC",0xef,0xbb,0xbf) === substr($content, 0, 3)) {
|
if (pack("CCC", 0xef, 0xbb, 0xbf) === substr($content, 0, 3)) {
|
||||||
$content = substr($content, 3);
|
$content = substr($content, 3);
|
||||||
}
|
}
|
||||||
// ensure uniform EOLs
|
// ensure uniform EOLs
|
||||||
|
@@ -195,13 +195,13 @@ class Minify_JS_ClosureCompiler
|
|||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
} else {
|
} else {
|
||||||
throw new Minify_JS_ClosureCompiler_Exception(
|
throw new Minify_JS_ClosureCompiler_Exception(
|
||||||
"Could not make HTTP request: allow_url_open is false and cURL not available"
|
"Could not make HTTP request: allow_url_open is false and cURL not available"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (false === $contents) {
|
if (false === $contents) {
|
||||||
throw new Minify_JS_ClosureCompiler_Exception(
|
throw new Minify_JS_ClosureCompiler_Exception(
|
||||||
"No HTTP response from server"
|
"No HTTP response from server"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -110,4 +110,4 @@ class Minify_NailgunClosureCompiler extends Minify_ClosureCompiler
|
|||||||
|
|
||||||
$this->shell("$serverCommand </dev/null >/dev/null 2>/dev/null & sleep 10");
|
$this->shell("$serverCommand </dev/null >/dev/null 2>/dev/null & sleep 10");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -170,7 +170,7 @@ class Minify_Source_Factory
|
|||||||
if ($this->options['noMinPattern'] && preg_match($this->options['noMinPattern'], $basename)) {
|
if ($this->options['noMinPattern'] && preg_match($this->options['noMinPattern'], $basename)) {
|
||||||
if (preg_match('~\.(css|less)$~i', $basename)) {
|
if (preg_match('~\.(css|less)$~i', $basename)) {
|
||||||
$spec['minifyOptions']['compress'] = false;
|
$spec['minifyOptions']['compress'] = false;
|
||||||
// we still want URI rewriting to work for CSS
|
// we still want URI rewriting to work for CSS
|
||||||
} else {
|
} else {
|
||||||
$spec['minifier'] = 'Minify::nullMinifier';
|
$spec['minifier'] = 'Minify::nullMinifier';
|
||||||
}
|
}
|
||||||
|
@@ -154,4 +154,3 @@ class Minify_YUICompressor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -390,4 +390,3 @@ class Cli
|
|||||||
$this->errors[$letter][] = sprintf($msg, $value);
|
$this->errors[$letter][] = sprintf($msg, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -27,7 +27,7 @@ $outfile = $cli->values['o'];
|
|||||||
$testRun = $cli->values['t'];
|
$testRun = $cli->values['t'];
|
||||||
$docRoot = $cli->values['d'];
|
$docRoot = $cli->values['d'];
|
||||||
|
|
||||||
$pathRewriter = function($css, $options) {
|
$pathRewriter = function ($css, $options) {
|
||||||
return Minify_CSS_UriRewriter::rewrite($css, $options['currentDir'], $options['docRoot']);
|
return Minify_CSS_UriRewriter::rewrite($css, $options['currentDir'], $options['docRoot']);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -54,9 +54,8 @@ $combined = Minify::combine($sources) . "\n";
|
|||||||
if ($testRun) {
|
if ($testRun) {
|
||||||
echo $combined;
|
echo $combined;
|
||||||
echo Minify_CSS_UriRewriter::$debugText . "\n";
|
echo Minify_CSS_UriRewriter::$debugText . "\n";
|
||||||
} else {
|
} else {
|
||||||
$fp = $cli->openOutput();
|
$fp = $cli->openOutput();
|
||||||
fwrite($fp, $combined);
|
fwrite($fp, $combined);
|
||||||
$cli->closeOutput();
|
$cli->closeOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,6 +4,6 @@
|
|||||||
|
|
||||||
require __DIR__ . '/../config.php';
|
require __DIR__ . '/../config.php';
|
||||||
|
|
||||||
$minifyCachePath = isset($min_cachePath)
|
$minifyCachePath = isset($min_cachePath)
|
||||||
? $min_cachePath
|
? $min_cachePath
|
||||||
: '';
|
: '';
|
||||||
|
@@ -13,7 +13,8 @@ $app->cache = new Minify_Cache_Null();
|
|||||||
|
|
||||||
$env = $app->env;
|
$env = $app->env;
|
||||||
|
|
||||||
function h($txt) {
|
function h($txt)
|
||||||
|
{
|
||||||
return htmlspecialchars($txt, ENT_QUOTES, 'UTF-8');
|
return htmlspecialchars($txt, ENT_QUOTES, 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,13 +23,12 @@ if ($env->post('textIn')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($env->post('method') === 'Minify and serve') {
|
if ($env->post('method') === 'Minify and serve') {
|
||||||
|
|
||||||
$base = trim($env->post('base'));
|
$base = trim($env->post('base'));
|
||||||
if ($base) {
|
if ($base) {
|
||||||
$textIn = preg_replace(
|
$textIn = preg_replace(
|
||||||
'@(<head\\b[^>]*>)@i'
|
'@(<head\\b[^>]*>)@i',
|
||||||
,'$1<base href="' . h($base) . '" />'
|
'$1<base href="' . h($base) . '" />',
|
||||||
,$textIn
|
$textIn
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +58,6 @@ $tpl = array();
|
|||||||
$tpl['classes'] = array('Minify_HTML', 'JSMin\\JSMin', 'Minify_CSS', 'Minify_Lines');
|
$tpl['classes'] = array('Minify_HTML', 'JSMin\\JSMin', 'Minify_CSS', 'Minify_Lines');
|
||||||
|
|
||||||
if (in_array($env->post('method'), $tpl['classes'])) {
|
if (in_array($env->post('method'), $tpl['classes'])) {
|
||||||
|
|
||||||
$args = array($textIn);
|
$args = array($textIn);
|
||||||
if ($env->post('method') === 'Minify_HTML') {
|
if ($env->post('method') === 'Minify_HTML') {
|
||||||
$args[] = array(
|
$args[] = array(
|
||||||
@@ -88,7 +87,8 @@ sendPage($tpl);
|
|||||||
* @param string $input
|
* @param string $input
|
||||||
* @return string HTML
|
* @return string HTML
|
||||||
*/
|
*/
|
||||||
function getExceptionMsg(Exception $e, $input) {
|
function getExceptionMsg(Exception $e, $input)
|
||||||
|
{
|
||||||
$msg = "<p>" . h($e->getMessage()) . "</p>";
|
$msg = "<p>" . h($e->getMessage()) . "</p>";
|
||||||
if (0 === strpos(get_class($e), 'JSMin_Unterminated')
|
if (0 === strpos(get_class($e), 'JSMin_Unterminated')
|
||||||
&& preg_match('~byte (\d+)~', $e->getMessage(), $m)) {
|
&& preg_match('~byte (\d+)~', $e->getMessage(), $m)) {
|
||||||
@@ -113,37 +113,35 @@ function getExceptionMsg(Exception $e, $input) {
|
|||||||
*
|
*
|
||||||
* @param array $vars
|
* @param array $vars
|
||||||
*/
|
*/
|
||||||
function sendPage($vars) {
|
function sendPage($vars)
|
||||||
header('Content-Type: text/html; charset=utf-8');
|
{
|
||||||
?>
|
header('Content-Type: text/html; charset=utf-8'); ?>
|
||||||
<!DOCTYPE html><head><title>minifyTextarea</title></head>
|
<!DOCTYPE html><head><title>minifyTextarea</title></head>
|
||||||
|
|
||||||
<p><strong>Warning! Please do not place this application on a public site.</strong> This should be used only for testing.</p>
|
<p><strong>Warning! Please do not place this application on a public site.</strong> This should be used only for testing.</p>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if (isset($vars['exceptionMsg'])) {
|
if (isset($vars['exceptionMsg'])) {
|
||||||
echo $vars['exceptionMsg'];
|
echo $vars['exceptionMsg'];
|
||||||
}
|
}
|
||||||
if (isset($vars['time'])) {
|
if (isset($vars['time'])) {
|
||||||
echo "
|
echo "
|
||||||
<table>
|
<table>
|
||||||
<tr><th>Bytes in</th><td>{$vars['inBytes']} (after line endings normalized to <code>\\n</code>)</td></tr>
|
<tr><th>Bytes in</th><td>{$vars['inBytes']} (after line endings normalized to <code>\\n</code>)</td></tr>
|
||||||
<tr><th>Bytes out</th><td>{$vars['outBytes']} (reduced " . round(100 - (100 * $vars['outBytes'] / $vars['inBytes'])) . "%)</td></tr>
|
<tr><th>Bytes out</th><td>{$vars['outBytes']} (reduced " . round(100 - (100 * $vars['outBytes'] / $vars['inBytes'])) . "%)</td></tr>
|
||||||
<tr><th>Time (s)</th><td>" . round($vars['time'], 5) . "</td></tr>
|
<tr><th>Time (s)</th><td>" . round($vars['time'], 5) . "</td></tr>
|
||||||
</table>
|
</table>
|
||||||
";
|
";
|
||||||
}
|
} ?>
|
||||||
?>
|
|
||||||
<form action="?2" method="post">
|
<form action="?2" method="post">
|
||||||
<p><label>Content<br><textarea name="textIn" cols="80" rows="35" style="width:99%"><?php
|
<p><label>Content<br><textarea name="textIn" cols="80" rows="35" style="width:99%"><?php
|
||||||
if (isset($vars['output'])) {
|
if (isset($vars['output'])) {
|
||||||
echo h($vars['output']);
|
echo h($vars['output']);
|
||||||
}
|
} ?></textarea></label></p>
|
||||||
?></textarea></label></p>
|
|
||||||
<p>Minify with:
|
<p>Minify with:
|
||||||
<?php foreach ($vars['classes'] as $minClass): ?>
|
<?php foreach ($vars['classes'] as $minClass): ?>
|
||||||
<input type="submit" name="method" value="<?php echo $minClass; ?>">
|
<input type="submit" name="method" value="<?php echo $minClass; ?>">
|
||||||
<?php endForEach; ?>
|
<?php endforeach; ?>
|
||||||
</p>
|
</p>
|
||||||
<p>...or <input type="submit" name="method" value="Minify and serve"> this HTML to the browser. Also minify:
|
<p>...or <input type="submit" name="method" value="Minify and serve"> this HTML to the browser. Also minify:
|
||||||
<label>CSS <input type="checkbox" name="minCss" checked></label> :
|
<label>CSS <input type="checkbox" name="minCss" checked></label> :
|
||||||
|
@@ -12,7 +12,8 @@ $app->cache = new Minify_Cache_Null();
|
|||||||
|
|
||||||
$env = $app->env;
|
$env = $app->env;
|
||||||
|
|
||||||
function getPost($key) {
|
function getPost($key)
|
||||||
|
{
|
||||||
if (! isset($_POST[$key])) {
|
if (! isset($_POST[$key])) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -21,14 +22,16 @@ function getPost($key) {
|
|||||||
: $_POST[$key];
|
: $_POST[$key];
|
||||||
}
|
}
|
||||||
|
|
||||||
function sniffType($headers) {
|
function sniffType($headers)
|
||||||
|
{
|
||||||
$charset = 'utf-8';
|
$charset = 'utf-8';
|
||||||
$type = null;
|
$type = null;
|
||||||
$headers = "\n\n" . implode("\n\n", $headers) . "\n\n";
|
$headers = "\n\n" . implode("\n\n", $headers) . "\n\n";
|
||||||
if (preg_match(
|
if (preg_match(
|
||||||
'@\\n\\nContent-Type: *([\\w/\\+-]+)( *; *charset *= *([\\w-]+))? *\\n\\n@i'
|
'@\\n\\nContent-Type: *([\\w/\\+-]+)( *; *charset *= *([\\w-]+))? *\\n\\n@i',
|
||||||
,$headers
|
$headers,
|
||||||
,$m)) {
|
$m
|
||||||
|
)) {
|
||||||
$sentType = $m[1];
|
$sentType = $m[1];
|
||||||
if (isset($m[3])) {
|
if (isset($m[3])) {
|
||||||
$charset = $m[3];
|
$charset = $m[3];
|
||||||
@@ -49,7 +52,6 @@ function sniffType($headers) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_POST['url'])) {
|
if (isset($_POST['url'])) {
|
||||||
|
|
||||||
require '../config.php';
|
require '../config.php';
|
||||||
|
|
||||||
$url = trim($env->post('url'));
|
$url = trim($env->post('url'));
|
||||||
@@ -88,13 +90,13 @@ if (isset($_POST['url'])) {
|
|||||||
die('Unrecognized Content-Type: ' . $type['sent']);
|
die('Unrecognized Content-Type: ' . $type['sent']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($type['minify'] === 'text/html'
|
if ($type['minify'] === 'text/html'
|
||||||
&& isset($_POST['addBase'])
|
&& isset($_POST['addBase'])
|
||||||
&& ! preg_match('@<base\\b@i', $content)) {
|
&& ! preg_match('@<base\\b@i', $content)) {
|
||||||
$content = preg_replace(
|
$content = preg_replace(
|
||||||
'@(<head\\b[^>]*>)@i'
|
'@(<head\\b[^>]*>)@i',
|
||||||
,'$1<base href="' . htmlspecialchars($url, ENT_QUOTES, 'UTF-8') . '" />'
|
'$1<base href="' . htmlspecialchars($url, ENT_QUOTES, 'UTF-8') . '" />',
|
||||||
,$content
|
$content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,9 +8,13 @@ $env = $app->env;
|
|||||||
|
|
||||||
header('Content-Type: text/html;charset=utf-8');
|
header('Content-Type: text/html;charset=utf-8');
|
||||||
|
|
||||||
function h($str) { return htmlspecialchars($str, ENT_QUOTES); }
|
function h($str)
|
||||||
|
{
|
||||||
|
return htmlspecialchars($str, ENT_QUOTES);
|
||||||
|
}
|
||||||
|
|
||||||
function getInput($name, $default = '', $size = 50) {
|
function getInput($name, $default = '', $size = 50)
|
||||||
|
{
|
||||||
global $env;
|
global $env;
|
||||||
$val = $env->post($name, $default);
|
$val = $env->post($name, $default);
|
||||||
return "<input type='text' name='{$name}' value='" . h($val) . "' size='{$size}' />";
|
return "<input type='text' name='{$name}' value='" . h($val) . "' size='{$size}' />";
|
||||||
|
@@ -13,7 +13,8 @@ if (!$enabled) {
|
|||||||
die('Set $enabled to true to see server info.');
|
die('Set $enabled to true to see server info.');
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertTrue($test, $message) {
|
function assertTrue($test, $message)
|
||||||
|
{
|
||||||
if (!$test) {
|
if (!$test) {
|
||||||
echo "Warning: $message\n";
|
echo "Warning: $message\n";
|
||||||
}
|
}
|
||||||
|
@@ -7,12 +7,12 @@ if (is_file(__DIR__ . '/bootstrap.php')) {
|
|||||||
$bootstrap_file = __DIR__ . '/../bootstrap.php';
|
$bootstrap_file = __DIR__ . '/../bootstrap.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
$send_400 = function($content = 'Bad URL') {
|
$send_400 = function ($content = 'Bad URL') {
|
||||||
http_response_code(400);
|
http_response_code(400);
|
||||||
die($content);
|
die($content);
|
||||||
};
|
};
|
||||||
|
|
||||||
$send_301 = function($url) {
|
$send_301 = function ($url) {
|
||||||
http_response_code(301);
|
http_response_code(301);
|
||||||
header("Cache-Control: max-age=31536000");
|
header("Cache-Control: max-age=31536000");
|
||||||
header("Location: $url");
|
header("Location: $url");
|
||||||
|
@@ -10,7 +10,8 @@ namespace Minify\StaticService;
|
|||||||
* @param string $type "css" or "js"
|
* @param string $type "css" or "js"
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function build_uri($static_uri, $query, $type) {
|
function build_uri($static_uri, $query, $type)
|
||||||
|
{
|
||||||
$static_uri = rtrim($static_uri, '/');
|
$static_uri = rtrim($static_uri, '/');
|
||||||
$query = ltrim($query, '?');
|
$query = ltrim($query, '?');
|
||||||
|
|
||||||
@@ -30,7 +31,8 @@ function build_uri($static_uri, $query, $type) {
|
|||||||
* @param bool $auto_create Automatically create the directory if missing?
|
* @param bool $auto_create Automatically create the directory if missing?
|
||||||
* @return null|string null if missing or can't create
|
* @return null|string null if missing or can't create
|
||||||
*/
|
*/
|
||||||
function get_cache_time($auto_create = true) {
|
function get_cache_time($auto_create = true)
|
||||||
|
{
|
||||||
foreach (scandir(__DIR__) as $entry) {
|
foreach (scandir(__DIR__) as $entry) {
|
||||||
if (ctype_digit($entry)) {
|
if (ctype_digit($entry)) {
|
||||||
return $entry;
|
return $entry;
|
||||||
@@ -50,14 +52,16 @@ function get_cache_time($auto_create = true) {
|
|||||||
return $time;
|
return $time;
|
||||||
}
|
}
|
||||||
|
|
||||||
function flush_cache() {
|
function flush_cache()
|
||||||
|
{
|
||||||
$time = get_cache_time(false);
|
$time = get_cache_time(false);
|
||||||
if ($time) {
|
if ($time) {
|
||||||
remove_tree(__DIR__ . "/$time");
|
remove_tree(__DIR__ . "/$time");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove_tree($dir) {
|
function remove_tree($dir)
|
||||||
|
{
|
||||||
$files = array_diff(scandir($dir), array('.', '..'));
|
$files = array_diff(scandir($dir), array('.', '..'));
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
|
@@ -166,15 +166,15 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
|
|
||||||
|
|
||||||
$len = strlen($data);
|
$len = strlen($data);
|
||||||
if ($len < 18 || strcmp(substr($data,0,2),"\x1f\x8b")) {
|
if ($len < 18 || strcmp(substr($data, 0, 2), "\x1f\x8b")) {
|
||||||
$error = "Not in GZIP format.";
|
$error = "Not in GZIP format.";
|
||||||
if ($mbIntEnc !== null) {
|
if ($mbIntEnc !== null) {
|
||||||
mb_internal_encoding($mbIntEnc);
|
mb_internal_encoding($mbIntEnc);
|
||||||
}
|
}
|
||||||
return null; // Not GZIP format (See RFC 1952)
|
return null; // Not GZIP format (See RFC 1952)
|
||||||
}
|
}
|
||||||
$method = ord(substr($data,2,1)); // Compression method
|
$method = ord(substr($data, 2, 1)); // Compression method
|
||||||
$flags = ord(substr($data,3,1)); // Flags
|
$flags = ord(substr($data, 3, 1)); // Flags
|
||||||
if ($flags & 31 != $flags) {
|
if ($flags & 31 != $flags) {
|
||||||
$error = "Reserved bits not allowed.";
|
$error = "Reserved bits not allowed.";
|
||||||
if ($mbIntEnc !== null) {
|
if ($mbIntEnc !== null) {
|
||||||
@@ -183,10 +183,10 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// NOTE: $mtime may be negative (PHP integer limitations)
|
// NOTE: $mtime may be negative (PHP integer limitations)
|
||||||
$mtime = unpack("V", substr($data,4,4));
|
$mtime = unpack("V", substr($data, 4, 4));
|
||||||
$mtime = $mtime[1];
|
$mtime = $mtime[1];
|
||||||
$xfl = substr($data,8,1);
|
$xfl = substr($data, 8, 1);
|
||||||
$os = substr($data,8,1);
|
$os = substr($data, 8, 1);
|
||||||
$headerlen = 10;
|
$headerlen = 10;
|
||||||
$extralen = 0;
|
$extralen = 0;
|
||||||
$extra = "";
|
$extra = "";
|
||||||
@@ -198,7 +198,7 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
}
|
}
|
||||||
return false; // invalid
|
return false; // invalid
|
||||||
}
|
}
|
||||||
$extralen = unpack("v",substr($data,8,2));
|
$extralen = unpack("v", substr($data, 8, 2));
|
||||||
$extralen = $extralen[1];
|
$extralen = $extralen[1];
|
||||||
if ($len - $headerlen - 2 - $extralen < 8) {
|
if ($len - $headerlen - 2 - $extralen < 8) {
|
||||||
if ($mbIntEnc !== null) {
|
if ($mbIntEnc !== null) {
|
||||||
@@ -206,7 +206,7 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
}
|
}
|
||||||
return false; // invalid
|
return false; // invalid
|
||||||
}
|
}
|
||||||
$extra = substr($data,10,$extralen);
|
$extra = substr($data, 10, $extralen);
|
||||||
$headerlen += 2 + $extralen;
|
$headerlen += 2 + $extralen;
|
||||||
}
|
}
|
||||||
$filenamelen = 0;
|
$filenamelen = 0;
|
||||||
@@ -219,14 +219,14 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
}
|
}
|
||||||
return false; // invalid
|
return false; // invalid
|
||||||
}
|
}
|
||||||
$filenamelen = strpos(substr($data,$headerlen),chr(0));
|
$filenamelen = strpos(substr($data, $headerlen), chr(0));
|
||||||
if ($filenamelen === false || $len - $headerlen - $filenamelen - 1 < 8) {
|
if ($filenamelen === false || $len - $headerlen - $filenamelen - 1 < 8) {
|
||||||
if ($mbIntEnc !== null) {
|
if ($mbIntEnc !== null) {
|
||||||
mb_internal_encoding($mbIntEnc);
|
mb_internal_encoding($mbIntEnc);
|
||||||
}
|
}
|
||||||
return false; // invalid
|
return false; // invalid
|
||||||
}
|
}
|
||||||
$filename = substr($data,$headerlen,$filenamelen);
|
$filename = substr($data, $headerlen, $filenamelen);
|
||||||
$headerlen += $filenamelen + 1;
|
$headerlen += $filenamelen + 1;
|
||||||
}
|
}
|
||||||
$commentlen = 0;
|
$commentlen = 0;
|
||||||
@@ -239,14 +239,14 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
}
|
}
|
||||||
return false; // invalid
|
return false; // invalid
|
||||||
}
|
}
|
||||||
$commentlen = strpos(substr($data,$headerlen),chr(0));
|
$commentlen = strpos(substr($data, $headerlen), chr(0));
|
||||||
if ($commentlen === false || $len - $headerlen - $commentlen - 1 < 8) {
|
if ($commentlen === false || $len - $headerlen - $commentlen - 1 < 8) {
|
||||||
if ($mbIntEnc !== null) {
|
if ($mbIntEnc !== null) {
|
||||||
mb_internal_encoding($mbIntEnc);
|
mb_internal_encoding($mbIntEnc);
|
||||||
}
|
}
|
||||||
return false; // Invalid header format
|
return false; // Invalid header format
|
||||||
}
|
}
|
||||||
$comment = substr($data,$headerlen,$commentlen);
|
$comment = substr($data, $headerlen, $commentlen);
|
||||||
$headerlen += $commentlen + 1;
|
$headerlen += $commentlen + 1;
|
||||||
}
|
}
|
||||||
$headercrc = "";
|
$headercrc = "";
|
||||||
@@ -258,8 +258,8 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
}
|
}
|
||||||
return false; // invalid
|
return false; // invalid
|
||||||
}
|
}
|
||||||
$calccrc = crc32(substr($data,0,$headerlen)) & 0xffff;
|
$calccrc = crc32(substr($data, 0, $headerlen)) & 0xffff;
|
||||||
$headercrc = unpack("v", substr($data,$headerlen,2));
|
$headercrc = unpack("v", substr($data, $headerlen, 2));
|
||||||
$headercrc = $headercrc[1];
|
$headercrc = $headercrc[1];
|
||||||
if ($headercrc != $calccrc) {
|
if ($headercrc != $calccrc) {
|
||||||
$error = "Header checksum failed.";
|
$error = "Header checksum failed.";
|
||||||
@@ -271,9 +271,9 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
$headerlen += 2;
|
$headerlen += 2;
|
||||||
}
|
}
|
||||||
// GZIP FOOTER
|
// GZIP FOOTER
|
||||||
$datacrc = unpack("V",substr($data,-8,4));
|
$datacrc = unpack("V", substr($data, -8, 4));
|
||||||
$datacrc = sprintf('%u',$datacrc[1] & 0xFFFFFFFF);
|
$datacrc = sprintf('%u', $datacrc[1] & 0xFFFFFFFF);
|
||||||
$isize = unpack("V",substr($data,-4));
|
$isize = unpack("V", substr($data, -4));
|
||||||
$isize = $isize[1];
|
$isize = $isize[1];
|
||||||
// decompression:
|
// decompression:
|
||||||
$bodylen = $len-$headerlen-8;
|
$bodylen = $len-$headerlen-8;
|
||||||
@@ -284,13 +284,13 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$body = substr($data,$headerlen,$bodylen);
|
$body = substr($data, $headerlen, $bodylen);
|
||||||
$data = "";
|
$data = "";
|
||||||
if ($bodylen > 0) {
|
if ($bodylen > 0) {
|
||||||
switch ($method) {
|
switch ($method) {
|
||||||
case 8:
|
case 8:
|
||||||
// Currently the only supported compression method:
|
// Currently the only supported compression method:
|
||||||
$data = gzinflate($body,$maxlength);
|
$data = gzinflate($body, $maxlength);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$error = "Unknown compression method.";
|
$error = "Unknown compression method.";
|
||||||
@@ -301,11 +301,11 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
}
|
}
|
||||||
} // zero-byte body content is allowed
|
} // zero-byte body content is allowed
|
||||||
// Verifiy CRC32
|
// Verifiy CRC32
|
||||||
$crc = sprintf("%u",crc32($data));
|
$crc = sprintf("%u", crc32($data));
|
||||||
$crcOK = $crc == $datacrc;
|
$crcOK = $crc == $datacrc;
|
||||||
$lenOK = $isize == strlen($data);
|
$lenOK = $isize == strlen($data);
|
||||||
if (!$lenOK || !$crcOK) {
|
if (!$lenOK || !$crcOK) {
|
||||||
$error = ( $lenOK ? '' : 'Length check FAILED. ') . ( $crcOK ? '' : 'Checksum FAILED.');
|
$error = ($lenOK ? '' : 'Length check FAILED. ') . ($crcOK ? '' : 'Checksum FAILED.');
|
||||||
$ret = false;
|
$ret = false;
|
||||||
}
|
}
|
||||||
$ret = $data;
|
$ret = $data;
|
||||||
@@ -313,4 +313,4 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
mb_internal_encoding($mbIntEnc);
|
mb_internal_encoding($mbIntEnc);
|
||||||
}
|
}
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
@@ -126,4 +126,4 @@ class JSMinTest extends TestCase
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,8 +32,11 @@ class JsClosureCompilerTest extends TestCase
|
|||||||
$this->compile($src);
|
$this->compile($src);
|
||||||
} catch (Minify_JS_ClosureCompiler_Exception $e) {
|
} catch (Minify_JS_ClosureCompiler_Exception $e) {
|
||||||
}
|
}
|
||||||
$this->assertInstanceOf('Minify_JS_ClosureCompiler_Exception', $e,
|
$this->assertInstanceOf(
|
||||||
'Throws Minify_JS_ClosureCompiler_Exception');
|
'Minify_JS_ClosureCompiler_Exception',
|
||||||
|
$e,
|
||||||
|
'Throws Minify_JS_ClosureCompiler_Exception'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test maximum byte size check (default)
|
// Test maximum byte size check (default)
|
||||||
@@ -46,8 +49,11 @@ class JsClosureCompilerTest extends TestCase
|
|||||||
$this->compile($src);
|
$this->compile($src);
|
||||||
} catch (Minify_JS_ClosureCompiler_Exception $e) {
|
} catch (Minify_JS_ClosureCompiler_Exception $e) {
|
||||||
}
|
}
|
||||||
$this->assertInstanceOf('Minify_JS_ClosureCompiler_Exception', $e,
|
$this->assertInstanceOf(
|
||||||
'Throws Minify_JS_ClosureCompiler_Exception');
|
'Minify_JS_ClosureCompiler_Exception',
|
||||||
|
$e,
|
||||||
|
'Throws Minify_JS_ClosureCompiler_Exception'
|
||||||
|
);
|
||||||
|
|
||||||
$expected = 'POST content larger than ' . Minify_JS_ClosureCompiler::DEFAULT_MAX_BYTES . ' bytes';
|
$expected = 'POST content larger than ' . Minify_JS_ClosureCompiler::DEFAULT_MAX_BYTES . ' bytes';
|
||||||
$this->assertEquals($expected, $e->getMessage(), 'Message must tell how big maximum byte size is');
|
$this->assertEquals($expected, $e->getMessage(), 'Message must tell how big maximum byte size is');
|
||||||
@@ -76,8 +82,11 @@ class JsClosureCompilerTest extends TestCase
|
|||||||
));
|
));
|
||||||
} catch (Minify_JS_ClosureCompiler_Exception $e) {
|
} catch (Minify_JS_ClosureCompiler_Exception $e) {
|
||||||
}
|
}
|
||||||
$this->assertInstanceOf('Minify_JS_ClosureCompiler_Exception', $e,
|
$this->assertInstanceOf(
|
||||||
'Throws Minify_JS_ClosureCompiler_Exception');
|
'Minify_JS_ClosureCompiler_Exception',
|
||||||
|
$e,
|
||||||
|
'Throws Minify_JS_ClosureCompiler_Exception'
|
||||||
|
);
|
||||||
|
|
||||||
$expected = 'POST content larger than ' . $allowedBytes . ' bytes';
|
$expected = 'POST content larger than ' . $allowedBytes . ' bytes';
|
||||||
$this->assertEquals($expected, $e->getMessage(), 'Message must tell how big maximum byte size is');
|
$this->assertEquals($expected, $e->getMessage(), 'Message must tell how big maximum byte size is');
|
||||||
@@ -96,8 +105,11 @@ class JsClosureCompilerTest extends TestCase
|
|||||||
));
|
));
|
||||||
} catch (Minify_JS_ClosureCompiler_Exception $e) {
|
} catch (Minify_JS_ClosureCompiler_Exception $e) {
|
||||||
}
|
}
|
||||||
$this->assertInstanceOf('Minify_JS_ClosureCompiler_Exception', $e,
|
$this->assertInstanceOf(
|
||||||
'Throws Minify_JS_ClosureCompiler_Exception');
|
'Minify_JS_ClosureCompiler_Exception',
|
||||||
|
$e,
|
||||||
|
'Throws Minify_JS_ClosureCompiler_Exception'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test7()
|
public function test7()
|
||||||
|
@@ -39,4 +39,4 @@ class LessSourceTest extends TestCase
|
|||||||
|
|
||||||
$this->assertEquals("/min/g=less&{$max}", $res);
|
$this->assertEquals("/min/g=less&{$max}", $res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,4 +25,4 @@ class MinifyBuildTest extends TestCase
|
|||||||
$this->assertEquals($b->uri('/path'), "/path?{$maxTime}", 'uri() with no querystring');
|
$this->assertEquals($b->uri('/path'), "/path?{$maxTime}", 'uri() with no querystring');
|
||||||
$this->assertEquals($b->uri('/path?hello'), "/path?hello&{$maxTime}", 'uri() with existing querystring');
|
$this->assertEquals($b->uri('/path?hello'), "/path?hello&{$maxTime}", 'uri() with existing querystring');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,9 +16,10 @@ class MinifyCSSUriRewriterTest extends TestCase
|
|||||||
$in = file_get_contents(self::$test_files . '/css_uriRewriter/in.css');
|
$in = file_get_contents(self::$test_files . '/css_uriRewriter/in.css');
|
||||||
$expected = file_get_contents(self::$test_files . '/css_uriRewriter/exp.css');
|
$expected = file_get_contents(self::$test_files . '/css_uriRewriter/exp.css');
|
||||||
$actual = Minify_CSS_UriRewriter::rewrite(
|
$actual = Minify_CSS_UriRewriter::rewrite(
|
||||||
$in
|
$in,
|
||||||
, self::$test_files . '/css_uriRewriter' // currentDir
|
self::$test_files . '/css_uriRewriter' // currentDir
|
||||||
, self::$document_root // use DOCUMENT_ROOT = '/full/path/to/min_unit_tests'
|
,
|
||||||
|
self::$document_root // use DOCUMENT_ROOT = '/full/path/to/min_unit_tests'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals($expected, $actual, 'rewrite, debug: ' . Minify_CSS_UriRewriter::$debugText);
|
$this->assertEquals($expected, $actual, 'rewrite, debug: ' . Minify_CSS_UriRewriter::$debugText);
|
||||||
@@ -47,9 +48,9 @@ class MinifyCSSUriRewriterTest extends TestCase
|
|||||||
$in = '../../../../assets/skins/sam/sprite.png';
|
$in = '../../../../assets/skins/sam/sprite.png';
|
||||||
$exp = '/yui/assets/skins/sam/sprite.png';
|
$exp = '/yui/assets/skins/sam/sprite.png';
|
||||||
$actual = Minify_CSS_UriRewriter::rewriteRelative(
|
$actual = Minify_CSS_UriRewriter::rewriteRelative(
|
||||||
$in
|
$in,
|
||||||
, 'sf_root_dir\web\yui\menu\assets\skins\sam'
|
'sf_root_dir\web\yui\menu\assets\skins\sam',
|
||||||
, 'sf_root_dir\web'
|
'sf_root_dir\web'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals($exp, $actual, 'Issue 99, debug: ' . Minify_CSS_UriRewriter::$debugText);
|
$this->assertEquals($exp, $actual, 'Issue 99, debug: ' . Minify_CSS_UriRewriter::$debugText);
|
||||||
|
@@ -22,4 +22,4 @@ class MinifyCacheAPCTest extends TestCase
|
|||||||
$cache = new Minify_Cache_APC();
|
$cache = new Minify_Cache_APC();
|
||||||
$this->assertTestCache($cache, $id, $data);
|
$this->assertTestCache($cache, $id, $data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -45,4 +45,3 @@ class MinifyCacheMemcacheTest extends TestCase
|
|||||||
$this->assertTestCache($cache, $id, $data);
|
$this->assertTestCache($cache, $id, $data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,4 +21,4 @@ class MinifyCacheWinCacheTest extends TestCase
|
|||||||
$cache = new Minify_Cache_WinCache();
|
$cache = new Minify_Cache_WinCache();
|
||||||
$this->assertTestCache($cache, $id, $data);
|
$this->assertTestCache($cache, $id, $data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,4 +22,4 @@ class MinifyCacheZendPlatformTest extends TestCase
|
|||||||
$cache = new Minify_Cache_ZendPlatform();
|
$cache = new Minify_Cache_ZendPlatform();
|
||||||
$this->assertTestCache($cache, $id, $data);
|
$this->assertTestCache($cache, $id, $data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,4 +31,4 @@ class MinifyCommentPreserverTest extends TestCase
|
|||||||
++$callCount;
|
++$callCount;
|
||||||
return $callCount . strtoupper($content);
|
return $callCount . strtoupper($content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -80,4 +80,4 @@ class MinifyHTMLHelperTest extends TestCase
|
|||||||
$this->assertEquals($maxTime, $output, 'utils.php : Minify_mtime w/ obj & group');
|
$this->assertEquals($maxTime, $output, 'utils.php : Minify_mtime w/ obj & group');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,10 @@ class MinifyImportProcessorTest extends TestCase
|
|||||||
realpath($linDir . '/lib/css/example.css'),
|
realpath($linDir . '/lib/css/example.css'),
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals($expectedIncludes, Minify_ImportProcessor::$filesIncluded,
|
$this->assertEquals(
|
||||||
'included right files in right order');
|
$expectedIncludes,
|
||||||
|
Minify_ImportProcessor::$filesIncluded,
|
||||||
|
'included right files in right order'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -54,4 +54,4 @@ class MinifyNailgunClosureCompilerTest extends TestCase
|
|||||||
$this->markTestSkipped($e->getMessage());
|
$this->markTestSkipped($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -62,8 +62,8 @@ class MinifyTest extends TestCase
|
|||||||
|
|
||||||
$content = preg_replace('/\\r\\n?/', "\n", file_get_contents($minifyTestPath . '/minified.js'));
|
$content = preg_replace('/\\r\\n?/', "\n", file_get_contents($minifyTestPath . '/minified.js'));
|
||||||
$lastModified = max(
|
$lastModified = max(
|
||||||
filemtime($minifyTestPath . '/email.js')
|
filemtime($minifyTestPath . '/email.js'),
|
||||||
, filemtime($minifyTestPath . '/QueryString.js')
|
filemtime($minifyTestPath . '/QueryString.js')
|
||||||
);
|
);
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'success' => true,
|
'success' => true,
|
||||||
@@ -153,8 +153,10 @@ class MinifyTest extends TestCase
|
|||||||
));
|
));
|
||||||
$output = $output['content'];
|
$output = $output['content'];
|
||||||
|
|
||||||
$this->assertFalse(strpos($output, $defaultOptions['importWarning']),
|
$this->assertFalse(
|
||||||
'Issue 89 : don\'t warn about valid imports');
|
strpos($output, $defaultOptions['importWarning']),
|
||||||
|
'Issue 89 : don\'t warn about valid imports'
|
||||||
|
);
|
||||||
|
|
||||||
// Test Issue 132
|
// Test Issue 132
|
||||||
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
|
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
|
||||||
@@ -164,8 +166,11 @@ class MinifyTest extends TestCase
|
|||||||
'encodeOutput' => false,
|
'encodeOutput' => false,
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertEquals(77, $output['headers']['Content-Length'],
|
$this->assertEquals(
|
||||||
'Issue 132 : mbstring.func_overload shouldn\'t cause incorrect Content-Length');
|
77,
|
||||||
|
$output['headers']['Content-Length'],
|
||||||
|
'Issue 132 : mbstring.func_overload shouldn\'t cause incorrect Content-Length'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test minifying CSS and responding with Etag/Last-Modified
|
// Test minifying CSS and responding with Etag/Last-Modified
|
||||||
|
@@ -60,4 +60,4 @@ class MinifyYuiCSSTest extends TestCase
|
|||||||
$this->markTestSkipped($e->getMessage());
|
$this->markTestSkipped($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -39,4 +39,4 @@ class ScssSourceTest extends TestCase
|
|||||||
|
|
||||||
$this->assertEquals("/min/g=scss&{$max}", $res);
|
$this->assertEquals("/min/g=scss&{$max}", $res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -70,4 +70,4 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
return $contents;
|
return $contents;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -48,7 +48,7 @@ function Minify_getUri($keyOrFiles, $opts = array())
|
|||||||
*
|
*
|
||||||
* Since this makes a bunch of stat() calls, you might not want to check this
|
* Since this makes a bunch of stat() calls, you might not want to check this
|
||||||
* on every request.
|
* on every request.
|
||||||
*
|
*
|
||||||
* @param array $keysAndFiles group keys and/or file paths/URIs.
|
* @param array $keysAndFiles group keys and/or file paths/URIs.
|
||||||
* @return int latest modification time of all given keys/files
|
* @return int latest modification time of all given keys/files
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user