1
0
mirror of https://github.com/mrclay/minify.git synced 2025-01-17 21:28:14 +01:00

min: + options for maxAge, uploaderHoursBehind, debug

Minify: better docblock for uploaderHoursBehind
This commit is contained in:
Steve Clay 2008-08-24 00:30:30 +00:00
parent 5b1b3381db
commit 4b3e92ca91
3 changed files with 59 additions and 32 deletions

View File

@ -9,8 +9,17 @@
* For best performance, specify your temp directory here.
* Otherwise Minify will have to load extra code to guess.
*/
//$minifyCachePath = 'c:\\WINDOWS\Temp';
//$minifyCachePath = '/tmp';
//$min_cachePath = 'c:\\WINDOWS\Temp';
//$min_cachePath = '/tmp';
/**
* Maximum age of browser cache in seconds. After this period,
* the browser will send another conditional GET. You might
* want to shorten this before making changes if it's crucial
* those changes are seen immediately.
*/
$min_serveOptions['maxAge'] = 1800;
/**
@ -21,17 +30,36 @@
*
* // = DOCUMENT_ROOT
*/
//$minifyAllowDirs = array('//js', '//css');
//$min_allowDirs = array('//js', '//css');
/**
* Manually set the path to Minify's lib folder
*/
//$minifyLibPath = 'lib';
//$min_libPath = 'lib';
/**
* Set to true to disable the "f" GET parameter for specifying files.
* Only the "g" parameter will be considered.
*/
$minifyGroupsOnly = false;
$min_groupsOnly = false;
/**
* Uncomment to enable debug mode. Files will be combined with no
* minification, and comments will be added to indicate the line #s
* of the original files.
*/
//$min_serveOptions['debug'] = true;
/**
* If you upload files from Windows to a non-Windows server, Windows may report
* incorrect mtimes for the files. 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, set this variable to that number. If the mtime
* moves back, this should not be needed.
*/
$min_uploaderHoursBehind = 0;

View File

@ -13,59 +13,60 @@ define('MINIFY_MIN_DIR', dirname(__FILE__));
require MINIFY_MIN_DIR . '/config.php';
// setup include path
if (!isset($minifyLibPath)) {
if (!isset($min_libPath)) {
// default lib path is inside this directory
$minifyLibPath = MINIFY_MIN_DIR . '/lib';
$min_libPath = MINIFY_MIN_DIR . '/lib';
}
set_include_path($minifyLibPath . PATH_SEPARATOR . get_include_path());
set_include_path($min_libPath . PATH_SEPARATOR . get_include_path());
// friendly error if lib wasn't in the include_path
if (! (include 'Minify.php')) {
trigger_error(
'Minify: You must add Minify/lib to the include_path or set $minifyLibPath in config.php'
'Minify: You must add Minify/lib to the include_path or set $min_libPath in config.php'
,E_USER_ERROR
);
}
}
Minify::$uploaderHoursBehind = $min_uploaderHoursBehind;
if (isset($_GET['g'])) {
Minify::setCache(isset($minifyCachePath) ? $minifyCachePath : null);
Minify::setCache(isset($min_cachePath) ? $min_cachePath : null);
// Groups expects the group key as PATH_INFO
// we want to allow ?g=groupKey
$_SERVER['PATH_INFO'] = '/' . $_GET['g'];
$serveOpts['groups'] = (require MINIFY_MIN_DIR . '/groupsConfig.php');
$min_serveOptions['groups'] = (require MINIFY_MIN_DIR . '/groupsConfig.php');
if (preg_match('/&\\d/', $_SERVER['QUERY_STRING'])) {
$serveOpts['maxAge'] = 31536000;
$min_serveOptions['maxAge'] = 31536000;
}
Minify::serve('Groups', $serveOpts);
Minify::serve('Groups', $min_serveOptions);
} elseif (!$minifyGroupsOnly && isset($_GET['f'])) {
} elseif (!$min_groupsOnly && isset($_GET['f'])) {
/**
* crude initial implementation hacked onto on Version1 controller
* @todo encapsulate this in a new controller
*/
if (isset($minifyCachePath)) {
define('MINIFY_CACHE_DIR', $minifyCachePath);
if (isset($min_cachePath)) {
define('MINIFY_CACHE_DIR', $min_cachePath);
}
$serveOpts = array();
if (isset($minifyAllowDirs)) {
foreach ((array)$minifyAllowDirs as $_allowDir) {
$serveOpts['allowDirs'][] = realpath(
if (isset($min_allowDirs)) {
foreach ((array)$min_allowDirs as $_allowDir) {
$min_serveOptions['allowDirs'][] = realpath(
$_SERVER['DOCUMENT_ROOT'] . substr($_allowDir, 1)
);
}
}
// Version1 already does validation. All we want is to prepend "b"
// to each file if it looks right.
$base = (isset($_GET['b']) && preg_match('@^[^/.]+(?:/[^/.]+)*$@', $_GET['b']))
$min_base = (isset($_GET['b']) && preg_match('@^[^/.]+(?:/[^/.]+)*$@', $_GET['b']))
? '/' . $_GET['b'] . '/'
: '/';
// Version1 expects ?files=/js/file1.js,/js/file2.js,/js/file3.js
// we want to allow ?f=js/file1.js,js/file2.js,js/file3.js
// or ?b=js&f=file1.js,file2.js,file3.js
$_GET['files'] = $base . str_replace(',', ',' . $base, $_GET['f']);
$_GET['files'] = $min_base . str_replace(',', ',' . $min_base, $_GET['f']);
Minify::serve('Version1', $serveOpts);
Minify::serve('Version1', $min_serveOptions);
}

View File

@ -38,11 +38,11 @@ class Minify {
/**
* How many hours behind are the file modification times of uploaded files?
*
* The mtime of files on Windows can behind what they should be on the server.
* 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, set this variable to that number. If the mtime moves back,
* this should not be needed.
* If you upload files from Windows to a non-Windows server, Windows may report
* incorrect mtimes for the files. 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, set this variable to that number. If the mtime
* moves back, this should not be needed.
*
* @var int $uploaderHoursBehind
*/
@ -151,8 +151,6 @@ class Minify {
* @return mixed null, or, if the 'quiet' option is set to true, an array
* with keys "success" (bool), "statusCode" (int), "content" (string), and
* "headers" (array).
*
* @todo add option to auto-fix relative URIs in CSS (default = true)
*/
public static function serve($controller, $options = array()) {
if (is_string($controller)) {