1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-12 09:05:08 +02:00

improved issue 170

This commit is contained in:
Steve Clay
2011-09-03 20:18:57 -04:00
parent 5ba23db0e8
commit 2f11b725b8
4 changed files with 33 additions and 16 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
# /
/test
/docs
.idea/

View File

@@ -1,15 +1,15 @@
javascript:(function(){
var d = document
,c = d.cookie
,m = c.match(/\bminDebug=([^; ]+)/)
,m = c.match(/\bminifyDebug=([^; ]+)/)
,v = m ? decodeURIComponent(m[1]) : ''
,p = prompt('Debug Minify URIs on ' + location.hostname + ' which contain:'
+ '\n(empty for none, space = OR)', v)
+ '\n(empty for none, space = OR, * = any string, ? = any char)', v)
;
if (p === null) return;
p = p.replace(/^\s+|\s+$/, '');
v = (p === '')
? 'minDebug=; expires=Fri, 27 Jul 2001 02:47:11 UTC; path=/'
: 'minDebug=' + encodeURIComponent(p) + '; path=/';
? 'minifyDebug=; expires=Fri, 27 Jul 2001 02:47:11 UTC; path=/'
: 'minifyDebug=' + encodeURIComponent(p) + '; path=/';
d.cookie = v;
})();

View File

@@ -36,18 +36,8 @@ foreach ($min_symlinks as $uri => $target) {
}
if ($min_allowDebugFlag) {
if (! empty($_COOKIE['minDebug'])) {
foreach (preg_split('/\\s+/', $_COOKIE['minDebug']) as $debugUri) {
if (false !== strpos($_SERVER['REQUEST_URI'], $debugUri)) {
$min_serveOptions['debug'] = true;
break;
}
}
}
// allow GET to override
if (isset($_GET['debug'])) {
$min_serveOptions['debug'] = true;
}
require_once 'Minify/DebugDetector.php';
$min_serveOptions['debug'] = Minify_DebugDetector::shouldDebugRequest($_COOKIE, $_GET, $_SERVER['REQUEST_URI']);
}
if ($min_errorLogger) {

View File

@@ -0,0 +1,26 @@
<?php
/**
* Detect whether request should be debugged
*
* @package Minify
* @author Stephen Clay <steve@mrclay.org>
*/
class Minify_DebugDetector {
public static function shouldDebugRequest($cookie, $get, $requestUri)
{
if (isset($get['debug'])) {
return true;
}
if (! empty($cookie['minifyDebug'])) {
foreach (preg_split('/\\s+/', $cookie['minifyDebug']) as $debugUri) {
$pattern = '@' . preg_quote($debugUri, '@') . '@i';
$pattern = str_replace(array('\\*', '\\?'), array('.*', '.'), $pattern);
if (preg_match($pattern, $requestUri)) {
return true;
}
}
}
return false;
}
}