Version Description
Download this release
Release Info
Developer | dipakcg |
Plugin | WP Super Minify |
Version | 1.1 |
Comparing to | |
See all releases |
Code changes from version 1.0 to 1.1
- includes/min/.htaccess +13 -0
- includes/min/builder/.htaccess +4 -0
- includes/min/builder/_index.js +260 -0
- includes/min/builder/bm.js +36 -0
- includes/min/builder/bm2.js +15 -0
- includes/min/builder/index.php +240 -0
- includes/min/builder/jquery-1.6.3.min.js +4 -0
- includes/min/builder/ocCheck.php +36 -0
- includes/min/builder/rewriteTest.js +1 -0
- includes/min/builder/test.php +43 -0
- includes/min/config-test.php +10 -0
- includes/min/config.php +184 -0
- includes/min/groupsConfig.php +17 -0
- includes/min/index.php +72 -0
- includes/min/lib/CSSmin.php +758 -0
- includes/min/lib/DooDigestAuth.php +121 -0
- includes/min/lib/FirePHP.php +1370 -0
- includes/min/lib/HTTP/ConditionalGet.php +366 -0
- includes/min/lib/HTTP/Encoder.php +335 -0
- includes/min/lib/JSMin.php +437 -0
- includes/min/lib/JSMinPlus.php +2086 -0
- includes/min/lib/Minify.php +608 -0
- includes/min/lib/Minify/Build.php +101 -0
- includes/min/lib/Minify/CSS.php +99 -0
- includes/min/lib/Minify/CSS/Compressor.php +249 -0
- includes/min/lib/Minify/CSS/UriRewriter.php +310 -0
- includes/min/lib/Minify/Cache/APC.php +133 -0
- includes/min/lib/Minify/Cache/File.php +194 -0
- includes/min/lib/Minify/Cache/Memcache.php +140 -0
- includes/min/lib/Minify/Cache/XCache.php +126 -0
- includes/min/lib/Minify/Cache/ZendPlatform.php +142 -0
- includes/min/lib/Minify/ClosureCompiler.php +123 -0
- includes/min/lib/Minify/CommentPreserver.php +89 -0
- includes/min/lib/Minify/Controller/Base.php +222 -0
- includes/min/lib/Minify/Controller/Files.php +76 -0
- includes/min/lib/Minify/Controller/Groups.php +91 -0
- includes/min/lib/Minify/Controller/MinApp.php +238 -0
- includes/min/lib/Minify/Controller/Page.php +68 -0
- includes/min/lib/Minify/Controller/Version1.php +119 -0
- includes/min/lib/Minify/DebugDetector.php +26 -0
- includes/min/lib/Minify/HTML.php +257 -0
- includes/min/lib/Minify/HTML/Helper.php +225 -0
- includes/min/lib/Minify/ImportProcessor.php +216 -0
- includes/min/lib/Minify/JS/ClosureCompiler.php +132 -0
- includes/min/lib/Minify/Lines.php +143 -0
- includes/min/lib/Minify/Loader.php +28 -0
- includes/min/lib/Minify/Logger.php +47 -0
- includes/min/lib/Minify/Packer.php +37 -0
- includes/min/lib/Minify/Source.php +187 -0
- includes/min/lib/Minify/YUI/CssCompressor.java +382 -0
- includes/min/lib/Minify/YUI/CssCompressor.php +171 -0
- includes/min/lib/Minify/YUICompressor.php +156 -0
- includes/min/lib/MrClay/Cli.php +384 -0
- includes/min/lib/MrClay/Cli/Arg.php +183 -0
- includes/min/quick-test.css +30 -0
- includes/min/quick-test.js +74 -0
- includes/min/utils.php +81 -0
- readme.txt +12 -6
- wp-super-minify.php +54 -139
includes/min/.htaccess
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<IfModule mod_rewrite.c>
|
2 |
+
RewriteEngine on
|
3 |
+
|
4 |
+
# You may need RewriteBase on some servers
|
5 |
+
#RewriteBase /min
|
6 |
+
|
7 |
+
# rewrite URLs like "/min/f=..." to "/min/?f=..."
|
8 |
+
RewriteRule ^([bfg]=.*) index.php?$1 [L,NE]
|
9 |
+
</IfModule>
|
10 |
+
<IfModule mod_env.c>
|
11 |
+
# In case AddOutputFilterByType has been added
|
12 |
+
SetEnv no-gzip
|
13 |
+
</IfModule>
|
includes/min/builder/.htaccess
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
<IfModule mod_rewrite.c>
|
2 |
+
RewriteEngine on
|
3 |
+
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
|
4 |
+
</IfModule>
|
includes/min/builder/_index.js
ADDED
@@ -0,0 +1,260 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*!
|
2 |
+
* Minify URI Builder
|
3 |
+
*/
|
4 |
+
var MUB = {
|
5 |
+
_uid : 0,
|
6 |
+
_minRoot : '/min/?',
|
7 |
+
checkRewrite : function () {
|
8 |
+
var testUri = location.pathname.replace(/\/[^\/]*$/, '/rewriteTest.js').substr(1);
|
9 |
+
function fail() {
|
10 |
+
$('#minRewriteFailed')[0].className = 'topNote';
|
11 |
+
}
|
12 |
+
$.ajax({
|
13 |
+
url : '../f=' + testUri + '&' + (new Date()).getTime(),
|
14 |
+
success : function (data) {
|
15 |
+
if (data === '1') {
|
16 |
+
MUB._minRoot = '/min/';
|
17 |
+
$('span.minRoot').html('/min/');
|
18 |
+
} else
|
19 |
+
fail();
|
20 |
+
},
|
21 |
+
error : fail
|
22 |
+
});
|
23 |
+
},
|
24 |
+
/**
|
25 |
+
* Get markup for new source LI element
|
26 |
+
*/
|
27 |
+
newLi : function () {
|
28 |
+
return '<li id="li' + MUB._uid + '">http://' + location.host + '/<input type=text size=20>' +
|
29 |
+
' <button title="Remove">x</button> <button title="Include Earlier">↑</button>' +
|
30 |
+
' <button title="Include Later">↓</button> <span></span></li>';
|
31 |
+
},
|
32 |
+
/**
|
33 |
+
* Add new empty source LI and attach handlers to buttons
|
34 |
+
*/
|
35 |
+
addLi : function () {
|
36 |
+
$('#sources').append(MUB.newLi());
|
37 |
+
var li = $('#li' + MUB._uid)[0];
|
38 |
+
$('button[title=Remove]', li).click(function () {
|
39 |
+
$('#results').hide();
|
40 |
+
var hadValue = !!$('input', li)[0].value;
|
41 |
+
$(li).remove();
|
42 |
+
});
|
43 |
+
$('button[title$=Earlier]', li).click(function () {
|
44 |
+
$(li).prev('li').find('input').each(function () {
|
45 |
+
$('#results').hide();
|
46 |
+
// this = previous li input
|
47 |
+
var tmp = this.value;
|
48 |
+
this.value = $('input', li).val();
|
49 |
+
$('input', li).val(tmp);
|
50 |
+
MUB.updateAllTestLinks();
|
51 |
+
});
|
52 |
+
});
|
53 |
+
$('button[title$=Later]', li).click(function () {
|
54 |
+
$(li).next('li').find('input').each(function () {
|
55 |
+
$('#results').hide();
|
56 |
+
// this = next li input
|
57 |
+
var tmp = this.value;
|
58 |
+
this.value = $('input', li).val();
|
59 |
+
$('input', li).val(tmp);
|
60 |
+
MUB.updateAllTestLinks();
|
61 |
+
});
|
62 |
+
});
|
63 |
+
++MUB._uid;
|
64 |
+
},
|
65 |
+
/**
|
66 |
+
* In the context of a source LI element, this will analyze the URI in
|
67 |
+
* the INPUT and check the URL on the site.
|
68 |
+
*/
|
69 |
+
liUpdateTestLink : function () { // call in context of li element
|
70 |
+
if (! $('input', this)[0].value)
|
71 |
+
return;
|
72 |
+
var li = this;
|
73 |
+
$('span', this).html('');
|
74 |
+
var url = location.protocol + '//' + location.host + '/' +
|
75 |
+
$('input', this)[0].value.replace(/^\//, '');
|
76 |
+
$.ajax({
|
77 |
+
url : url,
|
78 |
+
complete : function (xhr, stat) {
|
79 |
+
if ('success' === stat)
|
80 |
+
$('span', li).html('✓');
|
81 |
+
else {
|
82 |
+
$('span', li).html('<button><b>404! </b> recheck</button>')
|
83 |
+
.find('button').click(function () {
|
84 |
+
MUB.liUpdateTestLink.call(li);
|
85 |
+
});
|
86 |
+
}
|
87 |
+
},
|
88 |
+
dataType : 'text'
|
89 |
+
});
|
90 |
+
},
|
91 |
+
/**
|
92 |
+
* Check all source URLs
|
93 |
+
*/
|
94 |
+
updateAllTestLinks : function () {
|
95 |
+
$('#sources li').each(MUB.liUpdateTestLink);
|
96 |
+
},
|
97 |
+
/**
|
98 |
+
* In a given array of strings, find the character they all have at
|
99 |
+
* a particular index
|
100 |
+
* @param Array arr array of strings
|
101 |
+
* @param Number pos index to check
|
102 |
+
* @return mixed a common char or '' if any do not match
|
103 |
+
*/
|
104 |
+
getCommonCharAtPos : function (arr, pos) {
|
105 |
+
var i,
|
106 |
+
l = arr.length,
|
107 |
+
c = arr[0].charAt(pos);
|
108 |
+
if (c === '' || l === 1)
|
109 |
+
return c;
|
110 |
+
for (i = 1; i < l; ++i)
|
111 |
+
if (arr[i].charAt(pos) !== c)
|
112 |
+
return '';
|
113 |
+
return c;
|
114 |
+
},
|
115 |
+
/**
|
116 |
+
* Get the shortest URI to minify the set of source files
|
117 |
+
* @param Array sources URIs
|
118 |
+
*/
|
119 |
+
getBestUri : function (sources) {
|
120 |
+
var pos = 0,
|
121 |
+
base = '',
|
122 |
+
c;
|
123 |
+
while (true) {
|
124 |
+
c = MUB.getCommonCharAtPos(sources, pos);
|
125 |
+
if (c === '')
|
126 |
+
break;
|
127 |
+
else
|
128 |
+
base += c;
|
129 |
+
++pos;
|
130 |
+
}
|
131 |
+
base = base.replace(/[^\/]+$/, '');
|
132 |
+
var uri = MUB._minRoot + 'f=' + sources.join(',');
|
133 |
+
if (base.charAt(base.length - 1) === '/') {
|
134 |
+
// we have a base dir!
|
135 |
+
var basedSources = sources,
|
136 |
+
i,
|
137 |
+
l = sources.length;
|
138 |
+
for (i = 0; i < l; ++i) {
|
139 |
+
basedSources[i] = sources[i].substr(base.length);
|
140 |
+
}
|
141 |
+
base = base.substr(0, base.length - 1);
|
142 |
+
var bUri = MUB._minRoot + 'b=' + base + '&f=' + basedSources.join(',');
|
143 |
+
//window.console && console.log([uri, bUri]);
|
144 |
+
uri = uri.length < bUri.length ? uri : bUri;
|
145 |
+
}
|
146 |
+
return uri;
|
147 |
+
},
|
148 |
+
/**
|
149 |
+
* Create the Minify URI for the sources
|
150 |
+
*/
|
151 |
+
update : function () {
|
152 |
+
MUB.updateAllTestLinks();
|
153 |
+
var sources = [],
|
154 |
+
ext = false,
|
155 |
+
fail = false,
|
156 |
+
markup;
|
157 |
+
$('#sources input').each(function () {
|
158 |
+
var m, val;
|
159 |
+
if (! fail && this.value && (m = this.value.match(/\.(css|js)$/))) {
|
160 |
+
var thisExt = m[1];
|
161 |
+
if (ext === false)
|
162 |
+
ext = thisExt;
|
163 |
+
else if (thisExt !== ext) {
|
164 |
+
fail = true;
|
165 |
+
return alert('extensions must match!');
|
166 |
+
}
|
167 |
+
this.value = this.value.replace(/^\//, '');
|
168 |
+
if (-1 !== $.inArray(this.value, sources)) {
|
169 |
+
fail = true;
|
170 |
+
return alert('duplicate file!');
|
171 |
+
}
|
172 |
+
sources.push(this.value);
|
173 |
+
}
|
174 |
+
});
|
175 |
+
if (fail || ! sources.length)
|
176 |
+
return;
|
177 |
+
$('#groupConfig').val(" 'keyName' => array('//" + sources.join("', '//") + "'),");
|
178 |
+
var uri = MUB.getBestUri(sources),
|
179 |
+
uriH = uri.replace(/</, '<').replace(/>/, '>').replace(/&/, '&');
|
180 |
+
$('#uriA').html(uriH)[0].href = uri;
|
181 |
+
if (ext === 'js') {
|
182 |
+
markup = '<script type="text/javascript" src="' + uriH + '"></script>';
|
183 |
+
} else {
|
184 |
+
markup = '<link type="text/css" rel="stylesheet" href="' + uriH + '" />';
|
185 |
+
}
|
186 |
+
$('#uriHtml').val(markup);
|
187 |
+
$('#results').show();
|
188 |
+
},
|
189 |
+
/**
|
190 |
+
* Handler for the "Add file +" button
|
191 |
+
*/
|
192 |
+
addButtonClick : function () {
|
193 |
+
$('#results').hide();
|
194 |
+
MUB.addLi();
|
195 |
+
MUB.updateAllTestLinks();
|
196 |
+
$('#update').show().click(MUB.update);
|
197 |
+
$('#sources li:last input')[0].focus();
|
198 |
+
},
|
199 |
+
/**
|
200 |
+
* Runs on DOMready
|
201 |
+
*/
|
202 |
+
init : function () {
|
203 |
+
$('#jsDidntLoad').remove();
|
204 |
+
$('#app').show();
|
205 |
+
$('#sources').html('');
|
206 |
+
$('#add button').click(MUB.addButtonClick);
|
207 |
+
// make easier to copy text out of
|
208 |
+
$('#uriHtml, #groupConfig, #symlinkOpt').click(function () {
|
209 |
+
this.select();
|
210 |
+
}).focus(function () {
|
211 |
+
this.select();
|
212 |
+
});
|
213 |
+
$('a.ext').attr({target:'_blank'});
|
214 |
+
if (location.hash) {
|
215 |
+
// make links out of URIs from bookmarklet
|
216 |
+
$('#getBm').hide();
|
217 |
+
var i = 0, found = location.hash.substr(1).split(','), l = found.length;
|
218 |
+
$('#bmUris').html('<p><strong>Found by bookmarklet:</strong> /</p>');
|
219 |
+
var $p = $('#bmUris p');
|
220 |
+
for (; i < l; i++) {
|
221 |
+
$p.append($('<a href=#></a>').text(found[i])[0]);
|
222 |
+
if (i < (l - 1)) {
|
223 |
+
$p.append(', /');
|
224 |
+
}
|
225 |
+
}
|
226 |
+
$('#bmUris a').click(function () {
|
227 |
+
MUB.addButtonClick();
|
228 |
+
$('#sources li:last input').val(this.innerHTML);
|
229 |
+
MUB.liUpdateTestLink.call($('#sources li:last')[0]);
|
230 |
+
$('#results').hide();
|
231 |
+
return false;
|
232 |
+
}).attr({title:'Add file +'});
|
233 |
+
} else {
|
234 |
+
// setup bookmarklet 1
|
235 |
+
$.ajax({
|
236 |
+
url : '../?f=' + location.pathname.replace(/\/[^\/]*$/, '/bm.js').substr(1),
|
237 |
+
success : function (code) {
|
238 |
+
$('#bm')[0].href = code
|
239 |
+
.replace('%BUILDER_URL%', location.href)
|
240 |
+
.replace(/\n/g, ' ');
|
241 |
+
},
|
242 |
+
dataType : 'text'
|
243 |
+
});
|
244 |
+
if ($.browser.msie) {
|
245 |
+
$('#getBm p:last').append(' Sorry, not supported in MSIE!');
|
246 |
+
}
|
247 |
+
MUB.addButtonClick();
|
248 |
+
}
|
249 |
+
// setup bookmarklet 2
|
250 |
+
$.ajax({
|
251 |
+
url : '../?f=' + location.pathname.replace(/\/[^\/]*$/, '/bm2.js').substr(1),
|
252 |
+
success : function (code) {
|
253 |
+
$('#bm2')[0].href = code.replace(/\n/g, ' ');
|
254 |
+
},
|
255 |
+
dataType : 'text'
|
256 |
+
});
|
257 |
+
MUB.checkRewrite();
|
258 |
+
}
|
259 |
+
};
|
260 |
+
$(MUB.init);
|
includes/min/builder/bm.js
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
javascript:(function() {
|
2 |
+
var d = document
|
3 |
+
,uris = []
|
4 |
+
,i = 0
|
5 |
+
,o
|
6 |
+
,home = (location + '').split('/').splice(0, 3).join('/') + '/';
|
7 |
+
function add(uri) {
|
8 |
+
return (0 === uri.indexOf(home))
|
9 |
+
&& (!/[\?&]/.test(uri))
|
10 |
+
&& uris.push(escape(uri.substr(home.length)));
|
11 |
+
};
|
12 |
+
function sheet(ss) {
|
13 |
+
// we must check the domain with add() before accessing ss.cssRules
|
14 |
+
// otherwise a security exception will be thrown
|
15 |
+
if (ss.href && add(ss.href) && ss.cssRules) {
|
16 |
+
var i = 0, r;
|
17 |
+
while (r = ss.cssRules[i++])
|
18 |
+
r.styleSheet && sheet(r.styleSheet);
|
19 |
+
}
|
20 |
+
};
|
21 |
+
while (o = d.getElementsByTagName('script')[i++])
|
22 |
+
o.src && !(o.type && /vbs/i.test(o.type)) && add(o.src);
|
23 |
+
i = 0;
|
24 |
+
while (o = d.styleSheets[i++])
|
25 |
+
/* http://www.w3.org/TR/DOM-Level-2-Style/stylesheets.html#StyleSheets-DocumentStyle-styleSheets
|
26 |
+
document.styleSheet is a list property where [0] accesses the 1st element and
|
27 |
+
[outOfRange] returns null. In IE, styleSheets is a function, and also throws an
|
28 |
+
exception when you check the out of bounds index. (sigh) */
|
29 |
+
sheet(o);
|
30 |
+
if (uris.length)
|
31 |
+
window.open('%BUILDER_URL%#' + uris.join(','));
|
32 |
+
else
|
33 |
+
alert('No js/css files found with URLs within "'
|
34 |
+
+ home.split('/')[2]
|
35 |
+
+ '".\n(This tool is limited to URLs with the same domain.)');
|
36 |
+
})();
|
includes/min/builder/bm2.js
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
javascript:(function(){
|
2 |
+
var d = document
|
3 |
+
,c = d.cookie
|
4 |
+
,m = c.match(/\bminifyDebug=([^; ]+)/)
|
5 |
+
,v = m ? decodeURIComponent(m[1]) : ''
|
6 |
+
,p = prompt('Debug Minify URIs on ' + location.hostname + ' which contain:'
|
7 |
+
+ '\n(empty for none, space = OR, * = any string, ? = any char)', v)
|
8 |
+
;
|
9 |
+
if (p === null) return;
|
10 |
+
p = p.replace(/^\s+|\s+$/, '');
|
11 |
+
v = (p === '')
|
12 |
+
? 'minifyDebug=; expires=Fri, 27 Jul 2001 02:47:11 UTC; path=/'
|
13 |
+
: 'minifyDebug=' + encodeURIComponent(p) + '; path=/';
|
14 |
+
d.cookie = v;
|
15 |
+
})();
|
includes/min/builder/index.php
ADDED
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if (phpversion() < 5) {
|
4 |
+
exit('Minify requires PHP5 or greater.');
|
5 |
+
}
|
6 |
+
|
7 |
+
// check for auto-encoding
|
8 |
+
$encodeOutput = (function_exists('gzdeflate')
|
9 |
+
&& !ini_get('zlib.output_compression'));
|
10 |
+
|
11 |
+
// recommend $min_symlinks setting for Apache UserDir
|
12 |
+
$symlinkOption = '';
|
13 |
+
if (0 === strpos($_SERVER["SERVER_SOFTWARE"], 'Apache/')
|
14 |
+
&& preg_match('@^/\\~(\\w+)/@', $_SERVER['REQUEST_URI'], $m)
|
15 |
+
) {
|
16 |
+
$userDir = DIRECTORY_SEPARATOR . $m[1] . DIRECTORY_SEPARATOR;
|
17 |
+
if (false !== strpos(__FILE__, $userDir)) {
|
18 |
+
$sm = array();
|
19 |
+
$sm["//~{$m[1]}"] = dirname(dirname(__FILE__));
|
20 |
+
$array = str_replace('array (', 'array(', var_export($sm, 1));
|
21 |
+
$symlinkOption = "\$min_symlinks = $array;";
|
22 |
+
}
|
23 |
+
}
|
24 |
+
|
25 |
+
require dirname(__FILE__) . '/../config.php';
|
26 |
+
|
27 |
+
require "$min_libPath/Minify/Loader.php";
|
28 |
+
Minify_Loader::register();
|
29 |
+
|
30 |
+
if (! $min_enableBuilder) {
|
31 |
+
header('Content-Type: text/plain');
|
32 |
+
die('This application is not enabled. See http://code.google.com/p/minify/wiki/BuilderApp');
|
33 |
+
}
|
34 |
+
|
35 |
+
if (isset($min_builderPassword)
|
36 |
+
&& is_string($min_builderPassword)
|
37 |
+
&& $min_builderPassword !== '') {
|
38 |
+
DooDigestAuth::http_auth('Minify Builder', array('admin' => $min_builderPassword));
|
39 |
+
}
|
40 |
+
|
41 |
+
$cachePathCode = '';
|
42 |
+
if (! isset($min_cachePath) && ! function_exists('sys_get_temp_dir')) {
|
43 |
+
$detectedTmp = Minify_Cache_File::tmp();
|
44 |
+
$cachePathCode = "\$min_cachePath = " . var_export($detectedTmp, 1) . ';';
|
45 |
+
}
|
46 |
+
|
47 |
+
ob_start();
|
48 |
+
?>
|
49 |
+
<!DOCTYPE html>
|
50 |
+
<title>Minify URI Builder</title>
|
51 |
+
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
|
52 |
+
<style>
|
53 |
+
body {margin:1em 60px;}
|
54 |
+
h1, h2, h3 {margin-left:-25px; position:relative;}
|
55 |
+
h1 {margin-top:0;}
|
56 |
+
#sources {margin:0; padding:0;}
|
57 |
+
#sources li {margin:0 0 0 40px}
|
58 |
+
#sources li input {margin-left:2px}
|
59 |
+
#add {margin:5px 0 1em 40px}
|
60 |
+
.hide {display:none}
|
61 |
+
#uriTable {border-collapse:collapse;}
|
62 |
+
#uriTable td, #uriTable th {padding-top:10px;}
|
63 |
+
#uriTable th {padding-right:10px;}
|
64 |
+
#groupConfig {font-family:monospace;}
|
65 |
+
b {color:#c00}
|
66 |
+
.topNote {background: #ff9; display:inline-block; padding:.5em .6em; margin:0 0 1em;}
|
67 |
+
.topWarning {background:#c00; color:#fff; padding:.5em .6em; margin:0 0 1em;}
|
68 |
+
.topWarning a {color:#fff;}
|
69 |
+
#jsDidntLoad {display:none;}
|
70 |
+
</style>
|
71 |
+
<body>
|
72 |
+
<?php if ($symlinkOption): ?>
|
73 |
+
<div class=topNote><strong>Note:</strong> It looks like you're running Minify in a user
|
74 |
+
directory. You may need the following option in /min/config.php to have URIs
|
75 |
+
correctly rewritten in CSS output:
|
76 |
+
<br><textarea id=symlinkOpt rows=3 cols=80 readonly><?php echo htmlspecialchars($symlinkOption); ?></textarea>
|
77 |
+
</div>
|
78 |
+
<?php endif; ?>
|
79 |
+
|
80 |
+
<p class=topWarning id=jsDidntLoad><strong>Uh Oh.</strong> Minify was unable to
|
81 |
+
serve Javascript for this app. To troubleshoot this,
|
82 |
+
<a href="http://code.google.com/p/minify/wiki/Debugging">enable FirePHP debugging</a>
|
83 |
+
and request the <a id=builderScriptSrc href=#>Minify URL</a> directly. Hopefully the
|
84 |
+
FirePHP console will report the cause of the error.
|
85 |
+
</p>
|
86 |
+
|
87 |
+
<?php if ($cachePathCode): ?>
|
88 |
+
<p class=topNote><strong>Note:</strong> <code><?php echo
|
89 |
+
htmlspecialchars($detectedTmp); ?></code> was discovered as a usable temp directory.<br>To
|
90 |
+
slightly improve performance you can hardcode this in /min/config.php:
|
91 |
+
<code><?php echo htmlspecialchars($cachePathCode); ?></code></p>
|
92 |
+
<?php endIf; ?>
|
93 |
+
|
94 |
+
<p id=minRewriteFailed class="hide"><strong>Note:</strong> Your webserver does not seem to
|
95 |
+
support mod_rewrite (used in /min/.htaccess). Your Minify URIs will contain "?", which
|
96 |
+
<a href="http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/"
|
97 |
+
>may reduce the benefit of proxy cache servers</a>.</p>
|
98 |
+
|
99 |
+
<h1>Minify URI Builder</h1>
|
100 |
+
|
101 |
+
<noscript><p class="topNote">Javascript and a browser supported by jQuery 1.2.6 is required
|
102 |
+
for this application.</p></noscript>
|
103 |
+
|
104 |
+
<div id=app class=hide>
|
105 |
+
|
106 |
+
<p>Create a list of Javascript or CSS files (or 1 is fine) you'd like to combine
|
107 |
+
and click [Update].</p>
|
108 |
+
|
109 |
+
<ol id=sources><li></li></ol>
|
110 |
+
<div id=add><button>Add file +</button></div>
|
111 |
+
|
112 |
+
<div id=bmUris></div>
|
113 |
+
|
114 |
+
<p><button id=update class=hide>Update</button></p>
|
115 |
+
|
116 |
+
<div id=results class=hide>
|
117 |
+
|
118 |
+
<h2>Minify URI</h2>
|
119 |
+
<p>Place this URI in your HTML to serve the files above combined, minified, compressed and
|
120 |
+
with cache headers.</p>
|
121 |
+
<table id=uriTable>
|
122 |
+
<tr><th>URI</th><td><a id=uriA class=ext>/min</a> <small>(opens in new window)</small></td></tr>
|
123 |
+
<tr><th>HTML</th><td><input id=uriHtml type=text size=100 readonly></td></tr>
|
124 |
+
</table>
|
125 |
+
|
126 |
+
<h2>How to serve these files as a group</h2>
|
127 |
+
<p>For the best performance you can serve these files as a pre-defined group with a URI
|
128 |
+
like: <code><span class=minRoot>/min/?</span>g=keyName</code></p>
|
129 |
+
<p>To do this, add a line like this to /min/groupsConfig.php:</p>
|
130 |
+
|
131 |
+
<pre><code>return array(
|
132 |
+
<span style="color:#666">... your existing groups here ...</span>
|
133 |
+
<input id=groupConfig size=100 type=text readonly>
|
134 |
+
);</code></pre>
|
135 |
+
|
136 |
+
<p><em>Make sure to replace <code>keyName</code> with a unique key for this group.</em></p>
|
137 |
+
</div>
|
138 |
+
|
139 |
+
<div id=getBm>
|
140 |
+
<h3>Find URIs on a Page</h3>
|
141 |
+
<p>You can use the bookmarklet below to fetch all CSS & Javascript URIs from a page
|
142 |
+
on your site. When you active it, this page will open in a new window with a list of
|
143 |
+
available URIs to add.</p>
|
144 |
+
|
145 |
+
<p><a id=bm>Create Minify URIs</a> <small>(right-click, add to bookmarks)</small></p>
|
146 |
+
</div>
|
147 |
+
|
148 |
+
<h3>Combining CSS files that contain <code>@import</code></h3>
|
149 |
+
<p>If your CSS files contain <code>@import</code> declarations, Minify will not
|
150 |
+
remove them. Therefore, you will want to remove those that point to files already
|
151 |
+
in your list, and move any others to the top of the first file in your list
|
152 |
+
(imports below any styles will be ignored by browsers as invalid).</p>
|
153 |
+
<p>If you desire, you can use Minify URIs in imports and they will not be touched
|
154 |
+
by Minify. E.g. <code>@import "<span class=minRoot>/min/?</span>g=css2";</code></p>
|
155 |
+
|
156 |
+
<h3>Debug Mode</h3>
|
157 |
+
<p>When /min/config.php has <code>$min_allowDebugFlag = <strong>true</strong>;</code>
|
158 |
+
you can get debug output by appending <code>&debug</code> to a Minify URL, or
|
159 |
+
by sending the cookie <code>minDebug=<match></code>, where <code><match></code>
|
160 |
+
should be a string in the Minify URIs you'd like to debug. This bookmarklet will allow you to
|
161 |
+
set this cookie.</p>
|
162 |
+
<p><a id=bm2>Minify Debug</a> <small>(right-click, add to bookmarks)</small></p>
|
163 |
+
|
164 |
+
</div><!-- #app -->
|
165 |
+
|
166 |
+
<hr>
|
167 |
+
<p>Need help? Check the <a href="http://code.google.com/p/minify/w/list?can=3">wiki</a>,
|
168 |
+
or post to the <a class=ext href="http://groups.google.com/group/minify">discussion
|
169 |
+
list</a>.</p>
|
170 |
+
<p><small>Powered by Minify <?php echo Minify::VERSION; ?></small></p>
|
171 |
+
|
172 |
+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>
|
173 |
+
<script>window.jQuery || document.write('<script src="jquery-1.6.3.min.js"><\/script>')</script>
|
174 |
+
<script>
|
175 |
+
(function () {
|
176 |
+
// workaround required to test when /min isn't child of web root
|
177 |
+
var src = "../?f=" + location.pathname.replace(/\/[^\/]*$/, '/_index.js').substr(1);
|
178 |
+
// load script immediately
|
179 |
+
document.write('<\script src="' + src + '"><\/script>');
|
180 |
+
$(function () {
|
181 |
+
$('#builderScriptSrc')[0].href = src;
|
182 |
+
// give Minify a few seconds to serve _index.js before showing scary red warning
|
183 |
+
setTimeout(function () {
|
184 |
+
if (! window.MUB) {
|
185 |
+
// Minify didn't load
|
186 |
+
$('#jsDidntLoad').css({display:'block'});
|
187 |
+
}
|
188 |
+
}, 3000);
|
189 |
+
|
190 |
+
// detection of double output encoding
|
191 |
+
var msg = '<\p class=topWarning><\strong>Warning:<\/strong> ';
|
192 |
+
var url = 'ocCheck.php?' + (new Date()).getTime();
|
193 |
+
$.get(url, function (ocStatus) {
|
194 |
+
$.get(url + '&hello=1', function (ocHello) {
|
195 |
+
if (ocHello != 'World!') {
|
196 |
+
msg += 'It appears output is being automatically compressed, interfering '
|
197 |
+
+ ' with Minify\'s own compression. ';
|
198 |
+
if (ocStatus == '1')
|
199 |
+
msg += 'The option "zlib.output_compression" is enabled in your PHP configuration. '
|
200 |
+
+ 'Minify set this to "0", but it had no effect. This option must be disabled '
|
201 |
+
+ 'in php.ini or .htaccess.';
|
202 |
+
else
|
203 |
+
msg += 'The option "zlib.output_compression" is disabled in your PHP configuration '
|
204 |
+
+ 'so this behavior is likely due to a server option.';
|
205 |
+
$(document.body).prepend(msg + '<\/p>');
|
206 |
+
} else
|
207 |
+
if (ocStatus == '1')
|
208 |
+
$(document.body).prepend('<\p class=topNote><\strong>Note:</\strong> The option '
|
209 |
+
+ '"zlib.output_compression" is enabled in your PHP configuration, but has been '
|
210 |
+
+ 'successfully disabled via ini_set(). If you experience mangled output you '
|
211 |
+
+ 'may want to consider disabling this option in your PHP configuration.<\/p>'
|
212 |
+
);
|
213 |
+
});
|
214 |
+
});
|
215 |
+
});
|
216 |
+
})();
|
217 |
+
</script>
|
218 |
+
</body>
|
219 |
+
<?php
|
220 |
+
$content = ob_get_clean();
|
221 |
+
|
222 |
+
// setup Minify
|
223 |
+
Minify::setCache(
|
224 |
+
isset($min_cachePath) ? $min_cachePath : ''
|
225 |
+
,$min_cacheFileLocking
|
226 |
+
);
|
227 |
+
Minify::$uploaderHoursBehind = $min_uploaderHoursBehind;
|
228 |
+
|
229 |
+
Minify::serve('Page', array(
|
230 |
+
'content' => $content
|
231 |
+
,'id' => __FILE__
|
232 |
+
,'lastModifiedTime' => max(
|
233 |
+
// regenerate cache if any of these change
|
234 |
+
filemtime(__FILE__)
|
235 |
+
,filemtime(dirname(__FILE__) . '/../config.php')
|
236 |
+
,filemtime(dirname(__FILE__) . '/../lib/Minify.php')
|
237 |
+
)
|
238 |
+
,'minifyAll' => true
|
239 |
+
,'encodeOutput' => $encodeOutput
|
240 |
+
));
|
includes/min/builder/jquery-1.6.3.min.js
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
/*! jQuery v1.6.3 http://jquery.com/ | http://jquery.org/license */
|
2 |
+
(function(a,b){function cu(a){return f.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cr(a){if(!cg[a]){var b=c.body,d=f("<"+a+">").appendTo(b),e=d.css("display");d.remove();if(e==="none"||e===""){ch||(ch=c.createElement("iframe"),ch.frameBorder=ch.width=ch.height=0),b.appendChild(ch);if(!ci||!ch.createElement)ci=(ch.contentWindow||ch.contentDocument).document,ci.write((c.compatMode==="CSS1Compat"?"<!doctype html>":"")+"<html><body>"),ci.close();d=ci.createElement(a),ci.body.appendChild(d),e=f.css(d,"display"),b.removeChild(ch)}cg[a]=e}return cg[a]}function cq(a,b){var c={};f.each(cm.concat.apply([],cm.slice(0,b)),function(){c[this]=a});return c}function cp(){cn=b}function co(){setTimeout(cp,0);return cn=f.now()}function cf(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function ce(){try{return new a.XMLHttpRequest}catch(b){}}function b$(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d.length,j,k=d[0],l,m,n,o,p;for(g=1;g<i;g++){if(g===1)for(h in a.converters)typeof h=="string"&&(e[h.toLowerCase()]=a.converters[h]);l=k,k=d[g];if(k==="*")k=l;else if(l!=="*"&&l!==k){m=l+" "+k,n=e[m]||e["* "+k];if(!n){p=b;for(o in e){j=o.split(" ");if(j[0]===l||j[0]==="*"){p=e[j[1]+" "+k];if(p){o=e[o],o===!0?n=p:p===!0&&(n=o);break}}}}!n&&!p&&f.error("No conversion from "+m.replace(" "," to ")),n!==!0&&(c=n?n(c):p(o(c)))}}return c}function bZ(a,c,d){var e=a.contents,f=a.dataTypes,g=a.responseFields,h,i,j,k;for(i in g)i in d&&(c[g[i]]=d[i]);while(f[0]==="*")f.shift(),h===b&&(h=a.mimeType||c.getResponseHeader("content-type"));if(h)for(i in e)if(e[i]&&e[i].test(h)){f.unshift(i);break}if(f[0]in d)j=f[0];else{for(i in d){if(!f[0]||a.converters[i+" "+f[0]]){j=i;break}k||(k=i)}j=j||k}if(j){j!==f[0]&&f.unshift(j);return d[j]}}function bY(a,b,c,d){if(f.isArray(b))f.each(b,function(b,e){c||bA.test(a)?d(a,e):bY(a+"["+(typeof e=="object"||f.isArray(e)?b:"")+"]",e,c,d)});else if(!c&&b!=null&&typeof b=="object")for(var e in b)bY(a+"["+e+"]",b[e],c,d);else d(a,b)}function bX(a,c){var d,e,g=f.ajaxSettings.flatOptions||{};for(d in c)c[d]!==b&&((g[d]?a:e||(e={}))[d]=c[d]);e&&f.extend(!0,a,e)}function bW(a,c,d,e,f,g){f=f||c.dataTypes[0],g=g||{},g[f]=!0;var h=a[f],i=0,j=h?h.length:0,k=a===bP,l;for(;i<j&&(k||!l);i++)l=h[i](c,d,e),typeof l=="string"&&(!k||g[l]?l=b:(c.dataTypes.unshift(l),l=bW(a,c,d,e,l,g)));(k||!l)&&!g["*"]&&(l=bW(a,c,d,e,"*",g));return l}function bV(a){return function(b,c){typeof b!="string"&&(c=b,b="*");if(f.isFunction(c)){var d=b.toLowerCase().split(bL),e=0,g=d.length,h,i,j;for(;e<g;e++)h=d[e],j=/^\+/.test(h),j&&(h=h.substr(1)||"*"),i=a[h]=a[h]||[],i[j?"unshift":"push"](c)}}}function by(a,b,c){var d=b==="width"?a.offsetWidth:a.offsetHeight,e=b==="width"?bt:bu;if(d>0){c!=="border"&&f.each(e,function(){c||(d-=parseFloat(f.css(a,"padding"+this))||0),c==="margin"?d+=parseFloat(f.css(a,c+this))||0:d-=parseFloat(f.css(a,"border"+this+"Width"))||0});return d+"px"}d=bv(a,b,b);if(d<0||d==null)d=a.style[b]||0;d=parseFloat(d)||0,c&&f.each(e,function(){d+=parseFloat(f.css(a,"padding"+this))||0,c!=="padding"&&(d+=parseFloat(f.css(a,"border"+this+"Width"))||0),c==="margin"&&(d+=parseFloat(f.css(a,c+this))||0)});return d+"px"}function bl(a,b){b.src?f.ajax({url:b.src,async:!1,dataType:"script"}):f.globalEval((b.text||b.textContent||b.innerHTML||"").replace(bd,"/*$0*/")),b.parentNode&&b.parentNode.removeChild(b)}function bk(a){f.nodeName(a,"input")?bj(a):"getElementsByTagName"in a&&f.grep(a.getElementsByTagName("input"),bj)}function bj(a){if(a.type==="checkbox"||a.type==="radio")a.defaultChecked=a.checked}function bi(a){return"getElementsByTagName"in a?a.getElementsByTagName("*"):"querySelectorAll"in a?a.querySelectorAll("*"):[]}function bh(a,b){var c;if(b.nodeType===1){b.clearAttributes&&b.clearAttributes(),b.mergeAttributes&&b.mergeAttributes(a),c=b.nodeName.toLowerCase();if(c==="object")b.outerHTML=a.outerHTML;else if(c!=="input"||a.type!=="checkbox"&&a.type!=="radio"){if(c==="option")b.selected=a.defaultSelected;else if(c==="input"||c==="textarea")b.defaultValue=a.defaultValue}else a.checked&&(b.defaultChecked=b.checked=a.checked),b.value!==a.value&&(b.value=a.value);b.removeAttribute(f.expando)}}function bg(a,b){if(b.nodeType===1&&!!f.hasData(a)){var c=f.expando,d=f.data(a),e=f.data(b,d);if(d=d[c]){var g=d.events;e=e[c]=f.extend({},d);if(g){delete e.handle,e.events={};for(var h in g)for(var i=0,j=g[h].length;i<j;i++)f.event.add(b,h+(g[h][i].namespace?".":"")+g[h][i].namespace,g[h][i],g[h][i].data)}}}}function bf(a,b){return f.nodeName(a,"table")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function V(a,b,c){b=b||0;if(f.isFunction(b))return f.grep(a,function(a,d){var e=!!b.call(a,d,a);return e===c});if(b.nodeType)return f.grep(a,function(a,d){return a===b===c});if(typeof b=="string"){var d=f.grep(a,function(a){return a.nodeType===1});if(Q.test(b))return f.filter(b,d,!c);b=f.filter(b,d)}return f.grep(a,function(a,d){return f.inArray(a,b)>=0===c})}function U(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function M(a,b){return(a&&a!=="*"?a+".":"")+b.replace(y,"`").replace(z,"&")}function L(a){var b,c,d,e,g,h,i,j,k,l,m,n,o,p=[],q=[],r=f._data(this,"events");if(!(a.liveFired===this||!r||!r.live||a.target.disabled||a.button&&a.type==="click")){a.namespace&&(n=new RegExp("(^|\\.)"+a.namespace.split(".").join("\\.(?:.*\\.)?")+"(\\.|$)")),a.liveFired=this;var s=r.live.slice(0);for(i=0;i<s.length;i++)g=s[i],g.origType.replace(w,"")===a.type?q.push(g.selector):s.splice(i--,1);e=f(a.target).closest(q,a.currentTarget);for(j=0,k=e.length;j<k;j++){m=e[j];for(i=0;i<s.length;i++){g=s[i];if(m.selector===g.selector&&(!n||n.test(g.namespace))&&!m.elem.disabled){h=m.elem,d=null;if(g.preType==="mouseenter"||g.preType==="mouseleave")a.type=g.preType,d=f(a.relatedTarget).closest(g.selector)[0],d&&f.contains(h,d)&&(d=h);(!d||d!==h)&&p.push({elem:h,handleObj:g,level:m.level})}}}for(j=0,k=p.length;j<k;j++){e=p[j];if(c&&e.level>c)break;a.currentTarget=e.elem,a.data=e.handleObj.data,a.handleObj=e.handleObj,o=e.handleObj.origHandler.apply(e.elem,arguments);if(o===!1||a.isPropagationStopped()){c=e.level,o===!1&&(b=!1);if(a.isImmediatePropagationStopped())break}}return b}}function J(a,c,d){var e=f.extend({},d[0]);e.type=a,e.originalEvent={},e.liveFired=b,f.event.handle.call(c,e),e.isDefaultPrevented()&&d[0].preventDefault()}function D(){return!0}function C(){return!1}function m(a,c,d){var e=c+"defer",g=c+"queue",h=c+"mark",i=f.data(a,e,b,!0);i&&(d==="queue"||!f.data(a,g,b,!0))&&(d==="mark"||!f.data(a,h,b,!0))&&setTimeout(function(){!f.data(a,g,b,!0)&&!f.data(a,h,b,!0)&&(f.removeData(a,e,!0),i.resolve())},0)}function l(a){for(var b in a)if(b!=="toJSON")return!1;return!0}function k(a,c,d){if(d===b&&a.nodeType===1){var e="data-"+c.replace(j,"$1-$2").toLowerCase();d=a.getAttribute(e);if(typeof d=="string"){try{d=d==="true"?!0:d==="false"?!1:d==="null"?null:f.isNaN(d)?i.test(d)?f.parseJSON(d):d:parseFloat(d)}catch(g){}f.data(a,c,d)}else d=b}return d}var c=a.document,d=a.navigator,e=a.location,f=function(){function K(){if(!e.isReady){try{c.documentElement.doScroll("left")}catch(a){setTimeout(K,1);return}e.ready()}}var e=function(a,b){return new e.fn.init(a,b,h)},f=a.jQuery,g=a.$,h,i=/^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,j=/\S/,k=/^\s+/,l=/\s+$/,m=/\d/,n=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,o=/^[\],:{}\s]*$/,p=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,q=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,r=/(?:^|:|,)(?:\s*\[)+/g,s=/(webkit)[ \/]([\w.]+)/,t=/(opera)(?:.*version)?[ \/]([\w.]+)/,u=/(msie) ([\w.]+)/,v=/(mozilla)(?:.*? rv:([\w.]+))?/,w=/-([a-z]|[0-9])/ig,x=/^-ms-/,y=function(a,b){return(b+"").toUpperCase()},z=d.userAgent,A,B,C,D=Object.prototype.toString,E=Object.prototype.hasOwnProperty,F=Array.prototype.push,G=Array.prototype.slice,H=String.prototype.trim,I=Array.prototype.indexOf,J={};e.fn=e.prototype={constructor:e,init:function(a,d,f){var g,h,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a==="body"&&!d&&c.body){this.context=c,this[0]=c.body,this.selector=a,this.length=1;return this}if(typeof a=="string"){a.charAt(0)!=="<"||a.charAt(a.length-1)!==">"||a.length<3?g=i.exec(a):g=[null,a,null];if(g&&(g[1]||!d)){if(g[1]){d=d instanceof e?d[0]:d,k=d?d.ownerDocument||d:c,j=n.exec(a),j?e.isPlainObject(d)?(a=[c.createElement(j[1])],e.fn.attr.call(a,d,!0)):a=[k.createElement(j[1])]:(j=e.buildFragment([g[1]],[k]),a=(j.cacheable?e.clone(j.fragment):j.fragment).childNodes);return e.merge(this,a)}h=c.getElementById(g[2]);if(h&&h.parentNode){if(h.id!==g[2])return f.find(a);this.length=1,this[0]=h}this.context=c,this.selector=a;return this}return!d||d.jquery?(d||f).find(a):this.constructor(d).find(a)}if(e.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return e.makeArray(a,this)},selector:"",jquery:"1.6.3",length:0,size:function(){return this.length},toArray:function(){return G.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var d=this.constructor();e.isArray(a)?F.apply(d,a):e.merge(d,a),d.prevObject=this,d.context=this.context,b==="find"?d.selector=this.selector+(this.selector?" ":"")+c:b&&(d.selector=this.selector+"."+b+"("+c+")");return d},each:function(a,b){return e.each(this,a,b)},ready:function(a){e.bindReady(),B.done(a);return this},eq:function(a){return a===-1?this.slice(a):this.slice(a,+a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(G.apply(this,arguments),"slice",G.call(arguments).join(","))},map:function(a){return this.pushStack(e.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:F,sort:[].sort,splice:[].splice},e.fn.init.prototype=e.fn,e.extend=e.fn.extend=function(){var a,c,d,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i=="boolean"&&(l=i,i=arguments[1]||{},j=2),typeof i!="object"&&!e.isFunction(i)&&(i={}),k===j&&(i=this,--j);for(;j<k;j++)if((a=arguments[j])!=null)for(c in a){d=i[c],f=a[c];if(i===f)continue;l&&f&&(e.isPlainObject(f)||(g=e.isArray(f)))?(g?(g=!1,h=d&&e.isArray(d)?d:[]):h=d&&e.isPlainObject(d)?d:{},i[c]=e.extend(l,h,f)):f!==b&&(i[c]=f)}return i},e.extend({noConflict:function(b){a.$===e&&(a.$=g),b&&a.jQuery===e&&(a.jQuery=f);return e},isReady:!1,readyWait:1,holdReady:function(a){a?e.readyWait++:e.ready(!0)},ready:function(a){if(a===!0&&!--e.readyWait||a!==!0&&!e.isReady){if(!c.body)return setTimeout(e.ready,1);e.isReady=!0;if(a!==!0&&--e.readyWait>0)return;B.resolveWith(c,[e]),e.fn.trigger&&e(c).trigger("ready").unbind("ready")}},bindReady:function(){if(!B){B=e._Deferred();if(c.readyState==="complete")return setTimeout(e.ready,1);if(c.addEventListener)c.addEventListener("DOMContentLoaded",C,!1),a.addEventListener("load",e.ready,!1);else if(c.attachEvent){c.attachEvent("onreadystatechange",C),a.attachEvent("onload",e.ready);var b=!1;try{b=a.frameElement==null}catch(d){}c.documentElement.doScroll&&b&&K()}}},isFunction:function(a){return e.type(a)==="function"},isArray:Array.isArray||function(a){return e.type(a)==="array"},isWindow:function(a){return a&&typeof a=="object"&&"setInterval"in a},isNaN:function(a){return a==null||!m.test(a)||isNaN(a)},type:function(a){return a==null?String(a):J[D.call(a)]||"object"},isPlainObject:function(a){if(!a||e.type(a)!=="object"||a.nodeType||e.isWindow(a))return!1;try{if(a.constructor&&!E.call(a,"constructor")&&!E.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}var d;for(d in a);return d===b||E.call(a,d)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw a},parseJSON:function(b){if(typeof b!="string"||!b)return null;b=e.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(o.test(b.replace(p,"@").replace(q,"]").replace(r,"")))return(new Function("return "+b))();e.error("Invalid JSON: "+b)},parseXML:function(c){var d,f;try{a.DOMParser?(f=new DOMParser,d=f.parseFromString(c,"text/xml")):(d=new ActiveXObject("Microsoft.XMLDOM"),d.async="false",d.loadXML(c))}catch(g){d=b}(!d||!d.documentElement||d.getElementsByTagName("parsererror").length)&&e.error("Invalid XML: "+c);return d},noop:function(){},globalEval:function(b){b&&j.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(x,"ms-").replace(w,y)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,d){var f,g=0,h=a.length,i=h===b||e.isFunction(a);if(d){if(i){for(f in a)if(c.apply(a[f],d)===!1)break}else for(;g<h;)if(c.apply(a[g++],d)===!1)break}else if(i){for(f in a)if(c.call(a[f],f,a[f])===!1)break}else for(;g<h;)if(c.call(a[g],g,a[g++])===!1)break;return a},trim:H?function(a){return a==null?"":H.call(a)}:function(a){return a==null?"":(a+"").replace(k,"").replace(l,"")},makeArray:function(a,b){var c=b||[];if(a!=null){var d=e.type(a);a.length==null||d==="string"||d==="function"||d==="regexp"||e.isWindow(a)?F.call(c,a):e.merge(c,a)}return c},inArray:function(a,b){if(!b)return-1;if(I)return I.call(b,a);for(var c=0,d=b.length;c<d;c++)if(b[c]===a)return c;return-1},merge:function(a,c){var d=a.length,e=0;if(typeof c.length=="number")for(var f=c.length;e<f;e++)a[d++]=c[e];else while(c[e]!==b)a[d++]=c[e++];a.length=d;return a},grep:function(a,b,c){var d=[],e;c=!!c;for(var f=0,g=a.length;f<g;f++)e=!!b(a[f],f),c!==e&&d.push(a[f]);return d},map:function(a,c,d){var f,g,h=[],i=0,j=a.length,k=a instanceof e||j!==b&&typeof j=="number"&&(j>0&&a[0]&&a[j-1]||j===0||e.isArray(a));if(k)for(;i<j;i++)f=c(a[i],i,d),f!=null&&(h[h.length]=f);else for(g in a)f=c(a[g],g,d),f!=null&&(h[h.length]=f);return h.concat.apply([],h)},guid:1,proxy:function(a,c){if(typeof c=="string"){var d=a[c];c=a,a=d}if(!e.isFunction(a))return b;var f=G.call(arguments,2),g=function(){return a.apply(c,f.concat(G.call(arguments)))};g.guid=a.guid=a.guid||g.guid||e.guid++;return g},access:function(a,c,d,f,g,h){var i=a.length;if(typeof c=="object"){for(var j in c)e.access(a,j,c[j],f,g,d);return a}if(d!==b){f=!h&&f&&e.isFunction(d);for(var k=0;k<i;k++)g(a[k],c,f?d.call(a[k],k,g(a[k],c)):d,h);return a}return i?g(a[0],c):b},now:function(){return(new Date).getTime()},uaMatch:function(a){a=a.toLowerCase();var b=s.exec(a)||t.exec(a)||u.exec(a)||a.indexOf("compatible")<0&&v.exec(a)||[];return{browser:b[1]||"",version:b[2]||"0"}},sub:function(){function a(b,c){return new a.fn.init(b,c)}e.extend(!0,a,this),a.superclass=this,a.fn=a.prototype=this(),a.fn.constructor=a,a.sub=this.sub,a.fn.init=function(d,f){f&&f instanceof e&&!(f instanceof a)&&(f=a(f));return e.fn.init.call(this,d,f,b)},a.fn.init.prototype=a.fn;var b=a(c);return a},browser:{}}),e.each("Boolean Number String Function Array Date RegExp Object".split(" "),function(a,b){J["[object "+b+"]"]=b.toLowerCase()}),A=e.uaMatch(z),A.browser&&(e.browser[A.browser]=!0,e.browser.version=A.version),e.browser.webkit&&(e.browser.safari=!0),j.test(" ")&&(k=/^[\s\xA0]+/,l=/[\s\xA0]+$/),h=e(c),c.addEventListener?C=function(){c.removeEventListener("DOMContentLoaded",C,!1),e.ready()}:c.attachEvent&&(C=function(){c.readyState==="complete"&&(c.detachEvent("onreadystatechange",C),e.ready())});return e}(),g="done fail isResolved isRejected promise then always pipe".split(" "),h=[].slice;f.extend({_Deferred:function(){var a=[],b,c,d,e={done:function(){if(!d){var c=arguments,g,h,i,j,k;b&&(k=b,b=0);for(g=0,h=c.length;g<h;g++)i=c[g],j=f.type(i),j==="array"?e.done.apply(e,i):j==="function"&&a.push(i);k&&e.resolveWith(k[0],k[1])}return this},resolveWith:function(e,f){if(!d&&!b&&!c){f=f||[],c=1;try{while(a[0])a.shift().apply(e,f)}finally{b=[e,f],c=0}}return this},resolve:function(){e.resolveWith(this,arguments);return this},isResolved:function(){return!!c||!!b},cancel:function(){d=1,a=[];return this}};return e},Deferred:function(a){var b=f._Deferred(),c=f._Deferred(),d;f.extend(b,{then:function(a,c){b.done(a).fail(c);return this},always:function(){return b.done.apply(b,arguments).fail.apply(this,arguments)},fail:c.done,rejectWith:c.resolveWith,reject:c.resolve,isRejected:c.isResolved,pipe:function(a,c){return f.Deferred(function(d){f.each({done:[a,"resolve"],fail:[c,"reject"]},function(a,c){var e=c[0],g=c[1],h;f.isFunction(e)?b[a](function(){h=e.apply(this,arguments),h&&f.isFunction(h.promise)?h.promise().then(d.resolve,d.reject):d[g+"With"](this===b?d:this,[h])}):b[a](d[g])})}).promise()},promise:function(a){if(a==null){if(d)return d;d=a={}}var c=g.length;while(c--)a[g[c]]=b[g[c]];return a}}),b.done(c.cancel).fail(b.cancel),delete b.cancel,a&&a.call(b,b);return b},when:function(a){function i(a){return function(c){b[a]=arguments.length>1?h.call(arguments,0):c,--e||g.resolveWith(g,h.call(b,0))}}var b=arguments,c=0,d=b.length,e=d,g=d<=1&&a&&f.isFunction(a.promise)?a:f.Deferred();if(d>1){for(;c<d;c++)b[c]&&f.isFunction(b[c].promise)?b[c].promise().then(i(c),g.reject):--e;e||g.resolveWith(g,b)}else g!==a&&g.resolveWith(g,d?[a]:[]);return g.promise()}}),f.support=function(){var a=c.createElement("div"),b=c.documentElement,d,e,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u;a.setAttribute("className","t"),a.innerHTML=" <link><table></table><a href='/a' style='top:1px;float:left;opacity:.55;'>a</a><input type=checkbox>",d=a.getElementsByTagName("*"),e=a.getElementsByTagName("a")[0];if(!d||!d.length||!e)return{};g=c.createElement("select"),h=g.appendChild(c.createElement("option")),i=a.getElementsByTagName("input")[0],k={leadingWhitespace:a.firstChild.nodeType===3,tbody:!a.getElementsByTagName("tbody").length,htmlSerialize:!!a.getElementsByTagName("link").length,style:/top/.test(e.getAttribute("style")),hrefNormalized:e.getAttribute("href")==="/a",opacity:/^0.55$/.test(e.style.opacity),cssFloat:!!e.style.cssFloat,checkOn:i.value==="on",optSelected:h.selected,getSetAttribute:a.className!=="t",submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0},i.checked=!0,k.noCloneChecked=i.cloneNode(!0).checked,g.disabled=!0,k.optDisabled=!h.disabled;try{delete a.test}catch(v){k.deleteExpando=!1}!a.addEventListener&&a.attachEvent&&a.fireEvent&&(a.attachEvent("onclick",function(){k.noCloneEvent=!1}),a.cloneNode(!0).fireEvent("onclick")),i=c.createElement("input"),i.value="t",i.setAttribute("type","radio"),k.radioValue=i.value==="t",i.setAttribute("checked","checked"),a.appendChild(i),l=c.createDocumentFragment(),l.appendChild(a.firstChild),k.checkClone=l.cloneNode(!0).cloneNode(!0).lastChild.checked,a.innerHTML="",a.style.width=a.style.paddingLeft="1px",m=c.getElementsByTagName("body")[0],o=c.createElement(m?"div":"body"),p={visibility:"hidden",width:0,height:0,border:0,margin:0,background:"none"},m&&f.extend(p,{position:"absolute",left:"-1000px",top:"-1000px"});for(t in p)o.style[t]=p[t];o.appendChild(a),n=m||b,n.insertBefore(o,n.firstChild),k.appendChecked=i.checked,k.boxModel=a.offsetWidth===2,"zoom"in a.style&&(a.style.display="inline",a.style.zoom=1,k.inlineBlockNeedsLayout=a.offsetWidth===2,a.style.display="",a.innerHTML="<div style='width:4px;'></div>",k.shrinkWrapBlocks=a.offsetWidth!==2),a.innerHTML="<table><tr><td style='padding:0;border:0;display:none'></td><td>t</td></tr></table>",q=a.getElementsByTagName("td"),u=q[0].offsetHeight===0,q[0].style.display="",q[1].style.display="none",k.reliableHiddenOffsets=u&&q[0].offsetHeight===0,a.innerHTML="",c.defaultView&&c.defaultView.getComputedStyle&&(j=c.createElement("div"),j.style.width="0",j.style.marginRight="0",a.appendChild(j),k.reliableMarginRight=(parseInt((c.defaultView.getComputedStyle(j,null)||{marginRight:0}).marginRight,10)||0)===0),o.innerHTML="",n.removeChild(o);if(a.attachEvent)for(t in{submit:1,change:1,focusin:1})s="on"+t,u=s in a,u||(a.setAttribute(s,"return;"),u=typeof a[s]=="function"),k[t+"Bubbles"]=u;o=l=g=h=m=j=a=i=null;return k}(),f.boxModel=f.support.boxModel;var i=/^(?:\{.*\}|\[.*\])$/,j=/([a-z])([A-Z])/g;f.extend({cache:{},uuid:0,expando:"jQuery"+(f.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(a){a=a.nodeType?f.cache[a[f.expando]]:a[f.expando];return!!a&&!l(a)},data:function(a,c,d,e){if(!!f.acceptData(a)){var g,h,i=f.expando,j=typeof c=="string",k=a.nodeType,l=k?f.cache:a,m=k?a[f.expando]:a[f.expando]&&f.expando;if((!m||e&&m&&l[m]&&!l[m][i])&&j&&d===b)return;m||(k?a[f.expando]=m=++f.uuid:m=f.expando),l[m]||(l[m]={},k||(l[m].toJSON=f.noop));if(typeof c=="object"||typeof c=="function")e?l[m][i]=f.extend(l[m][i],c):l[m]=f.extend(l[m],c);g=l[m],e&&(g[i]||(g[i]={}),g=g[i]),d!==b&&(g[f.camelCase(c)]=d);if(c==="events"&&!g[c])return g[i]&&g[i].events;j?(h=g[c],h==null&&(h=g[f.camelCase(c)])):h=g;return h}},removeData:function(a,b,c){if(!!f.acceptData(a)){var d,e=f.expando,g=a.nodeType,h=g?f.cache:a,i=g?a[f.expando]:f.expando;if(!h[i])return;if(b){d=c?h[i][e]:h[i];if(d){d[b]||(b=f.camelCase(b)),delete d[b];if(!l(d))return}}if(c){delete h[i][e];if(!l(h[i]))return}var j=h[i][e];f.support.deleteExpando||!h.setInterval?delete h[i]:h[i]=null,j?(h[i]={},g||(h[i].toJSON=f.noop),h[i][e]=j):g&&(f.support.deleteExpando?delete a[f.expando]:a.removeAttribute?a.removeAttribute(f.expando):a[f.expando]=null)}},_data:function(a,b,c){return f.data(a,b,c,!0)},acceptData:function(a){if(a.nodeName){var b=f.noData[a.nodeName.toLowerCase()];if(b)return b!==!0&&a.getAttribute("classid")===b}return!0}}),f.fn.extend({data:function(a,c){var d=null;if(typeof a=="undefined"){if(this.length){d=f.data(this[0]);if(this[0].nodeType===1){var e=this[0].attributes,g;for(var h=0,i=e.length;h<i;h++)g=e[h].name,g.indexOf("data-")===0&&(g=f.camelCase(g.substring(5)),k(this[0],g,d[g]))}}return d}if(typeof a=="object")return this.each(function(){f.data(this,a)});var j=a.split(".");j[1]=j[1]?"."+j[1]:"";if(c===b){d=this.triggerHandler("getData"+j[1]+"!",[j[0]]),d===b&&this.length&&(d=f.data(this[0],a),d=k(this[0],a,d));return d===b&&j[1]?this.data(j[0]):d}return this.each(function(){var b=f(this),d=[j[0],c];b.triggerHandler("setData"+j[1]+"!",d),f.data(this,a,c),b.triggerHandler("changeData"+j[1]+"!",d)})},removeData:function(a){return this.each(function(){f.removeData(this,a)})}}),f.extend({_mark:function(a,c){a&&(c=(c||"fx")+"mark",f.data(a,c,(f.data(a,c,b,!0)||0)+1,!0))},_unmark:function(a,c,d){a!==!0&&(d=c,c=a,a=!1);if(c){d=d||"fx";var e=d+"mark",g=a?0:(f.data(c,e,b,!0)||1)-1;g?f.data(c,e,g,!0):(f.removeData(c,e,!0),m(c,d,"mark"))}},queue:function(a,c,d){if(a){c=(c||"fx")+"queue";var e=f.data(a,c,b,!0);d&&(!e||f.isArray(d)?e=f.data(a,c,f.makeArray(d),!0):e.push(d));return e||[]}},dequeue:function(a,b){b=b||"fx";var c=f.queue(a,b),d=c.shift(),e;d==="inprogress"&&(d=c.shift()),d&&(b==="fx"&&c.unshift("inprogress"),d.call(a,function(){f.dequeue(a,b)})),c.length||(f.removeData(a,b+"queue",!0),m(a,b,"queue"))}}),f.fn.extend({queue:function(a,c){typeof a!="string"&&(c=a,a="fx");if(c===b)return f.queue(this[0],a);return this.each(function(){var b=f.queue(this,a,c);a==="fx"&&b[0]!=="inprogress"&&f.dequeue(this,a)})},dequeue:function(a){return this.each(function(){f.dequeue(this,a)})},delay:function(a,b){a=f.fx?f.fx.speeds[a]||a:a,b=b||"fx";return this.queue(b,function(){var c=this;setTimeout(function(){f.dequeue(c,b)},a)})},clearQueue:function(a){return this.queue(a||"fx",[])},promise:function(a,c){function m(){--h||d.resolveWith(e,[e])}typeof a!="string"&&(c=a,a=b),a=a||"fx";var d=f.Deferred(),e=this,g=e.length,h=1,i=a+"defer",j=a+"queue",k=a+"mark",l;while(g--)if(l=f.data(e[g],i,b,!0)||(f.data(e[g],j,b,!0)||f.data(e[g],k,b,!0))&&f.data(e[g],i,f._Deferred(),!0))h++,l.done(m);m();return d.promise()}});var n=/[\n\t\r]/g,o=/\s+/,p=/\r/g,q=/^(?:button|input)$/i,r=/^(?:button|input|object|select|textarea)$/i,s=/^a(?:rea)?$/i,t=/^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,u,v;f.fn.extend({attr:function(a,b){return f.access(this,a,b,!0,f.attr)},removeAttr:function(a){return this.each(function(){f.removeAttr(this,a)})},prop:function(a,b){return f.access(this,a,b,!0,f.prop)},removeProp:function(a){a=f.propFix[a]||a;return this.each(function(){try{this[a]=b,delete this[a]}catch(c){}})},addClass:function(a){var b,c,d,e,g,h,i;if(f.isFunction(a))return this.each(function(b){f(this).addClass(a.call(this,b,this.className))});if(a&&typeof a=="string"){b=a.split(o);for(c=0,d=this.length;c<d;c++){e=this[c];if(e.nodeType===1)if(!e.className&&b.length===1)e.className=a;else{g=" "+e.className+" ";for(h=0,i=b.length;h<i;h++)~g.indexOf(" "+b[h]+" ")||(g+=b[h]+" ");e.className=f.trim(g)}}}return this},removeClass:function(a){var c,d,e,g,h,i,j;if(f.isFunction(a))return this.each(function(b){f(this).removeClass(a.call(this,b,this.className))});if(a&&typeof a=="string"||a===b){c=(a||"").split(o);for(d=0,e=this.length;d<e;d++){g=this[d];if(g.nodeType===1&&g.className)if(a){h=(" "+g.className+" ").replace(n," ");for(i=0,j=c.length;i<j;i++)h=h.replace(" "+c[i]+" "," ");g.className=f.trim(h)}else g.className=""}}return this},toggleClass:function(a,b){var c=typeof a,d=typeof b=="boolean";if(f.isFunction(a))return this.each(function(c){f(this).toggleClass(a.call(this,c,this.className,b),b)});return this.each(function(){if(c==="string"){var e,g=0,h=f(this),i=b,j=a.split(o);while(e=j[g++])i=d?i:!h.hasClass(e),h[i?"addClass":"removeClass"](e)}else if(c==="undefined"||c==="boolean")this.className&&f._data(this,"__className__",this.className),this.className=this.className||a===!1?"":f._data(this,"__className__")||""})},hasClass:function(a){var b=" "+a+" ";for(var c=0,d=this.length;c<d;c++)if(this[c].nodeType===1&&(" "+this[c].className+" ").replace(n," ").indexOf(b)>-1)return!0;return!1},val:function(a){var c,d,e=this[0];if(!arguments.length){if(e){c=f.valHooks[e.nodeName.toLowerCase()]||f.valHooks[e.type];if(c&&"get"in c&&(d=c.get(e,"value"))!==b)return d;d=e.value;return typeof d=="string"?d.replace(p,""):d==null?"":d}return b}var g=f.isFunction(a);return this.each(function(d){var e=f(this),h;if(this.nodeType===1){g?h=a.call(this,d,e.val()):h=a,h==null?h="":typeof h=="number"?h+="":f.isArray(h)&&(h=f.map(h,function(a){return a==null?"":a+""})),c=f.valHooks[this.nodeName.toLowerCase()]||f.valHooks[this.type];if(!c||!("set"in c)||c.set(this,h,"value")===b)this.value=h}})}}),f.extend({valHooks:{option:{get:function(a){var b=a.attributes.value;return!b||b.specified?a.value:a.text}},select:{get:function(a){var b,c=a.selectedIndex,d=[],e=a.options,g=a.type==="select-one";if(c<0)return null;for(var h=g?c:0,i=g?c+1:e.length;h<i;h++){var j=e[h];if(j.selected&&(f.support.optDisabled?!j.disabled:j.getAttribute("disabled")===null)&&(!j.parentNode.disabled||!f.nodeName(j.parentNode,"optgroup"))){b=f(j).val();if(g)return b;d.push(b)}}if(g&&!d.length&&e.length)return f(e[c]).val();return d},set:function(a,b){var c=f.makeArray(b);f(a).find("option").each(function(){this.selected=f.inArray(f(this).val(),c)>=0}),c.length||(a.selectedIndex=-1);return c}}},attrFn:{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0},attrFix:{tabindex:"tabIndex"},attr:function(a,c,d,e){var g=a.nodeType;if(!a||g===3||g===8||g===2)return b;if(e&&c in f.attrFn)return f(a)[c](d);if(!("getAttribute"in a))return f.prop(a,c,d);var h,i,j=g!==1||!f.isXMLDoc(a);j&&(c=f.attrFix[c]||c,i=f.attrHooks[c],i||(t.test(c)?i=v:u&&(i=u)));if(d!==b){if(d===null){f.removeAttr(a,c);return b}if(i&&"set"in i&&j&&(h=i.set(a,d,c))!==b)return h;a.setAttribute(c,""+d);return d}if(i&&"get"in i&&j&&(h=i.get(a,c))!==null)return h;h=a.getAttribute(c);return h===null?b:h},removeAttr:function(a,b){var c;a.nodeType===1&&(b=f.attrFix[b]||b,f.attr(a,b,""),a.removeAttribute(b),t.test(b)&&(c=f.propFix[b]||b)in a&&(a[c]=!1))},attrHooks:{type:{set:function(a,b){if(q.test(a.nodeName)&&a.parentNode)f.error("type property can't be changed");else if(!f.support.radioValue&&b==="radio"&&f.nodeName(a,"input")){var c=a.value;a.setAttribute("type",b),c&&(a.value=c);return b}}},value:{get:function(a,b){if(u&&f.nodeName(a,"button"))return u.get(a,b);return b in a?a.value:null},set:function(a,b,c){if(u&&f.nodeName(a,"button"))return u.set(a,b,c);a.value=b}}},propFix:{tabindex:"tabIndex",readonly:"readOnly","for":"htmlFor","class":"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},prop:function(a,c,d){var e=a.nodeType;if(!a||e===3||e===8||e===2)return b;var g,h,i=e!==1||!f.isXMLDoc(a);i&&(c=f.propFix[c]||c,h=f.propHooks[c]);return d!==b?h&&"set"in h&&(g=h.set(a,d,c))!==b?g:a[c]=d:h&&"get"in h&&(g=h.get(a,c))!==null?g:a[c]},propHooks:{tabIndex:{get:function(a){var c=a.getAttributeNode("tabindex");return c&&c.specified?parseInt(c.value,10):r.test(a.nodeName)||s.test(a.nodeName)&&a.href?0:b}}}}),f.attrHooks.tabIndex=f.propHooks.tabIndex,v={get:function(a,c){var d;return f.prop(a,c)===!0||(d=a.getAttributeNode(c))&&d.nodeValue!==!1?c.toLowerCase():b},set:function(a,b,c){var d;b===!1?f.removeAttr(a,c):(d=f.propFix[c]||c,d in a&&(a[d]=!0),a.setAttribute(c,c.toLowerCase()));return c}},f.support.getSetAttribute||(u=f.valHooks.button={get:function(a,c){var d;d=a.getAttributeNode(c);return d&&d.nodeValue!==""?d.nodeValue:b},set:function(a,b,d){var e=a.getAttributeNode(d);e||(e=c.createAttribute(d),a.setAttributeNode(e));return e.nodeValue=b+""}},f.each(["width","height"],function(a,b){f.attrHooks[b]=f.extend(f.attrHooks[b],{set:function(a,c){if(c===""){a.setAttribute(b,"auto");return c}}})})),f.support.hrefNormalized||f.each(["href","src","width","height"],function(a,c){f.attrHooks[c]=f.extend(f.attrHooks[c],{get:function(a){var d=a.getAttribute(c,2);return d===null?b:d}})}),f.support.style||(f.attrHooks.style={get:function(a){return a.style.cssText.toLowerCase()||b},set:function(a,b){return a.style.cssText=""+b}}),f.support.optSelected||(f.propHooks.selected=f.extend(f.propHooks.selected,{get:function(a){var b=a.parentNode;b&&(b.selectedIndex,b.parentNode&&b.parentNode.selectedIndex);return null}})),f.support.checkOn||f.each(["radio","checkbox"],function(){f.valHooks[this]={get:function(a){return a.getAttribute("value")===null?"on":a.value}}}),f.each(["radio","checkbox"],function(){f.valHooks[this]=f.extend(f.valHooks[this],{set:function(a,b){if(f.isArray(b))return a.checked=f.inArray(f(a).val(),b)>=0}})});var w=/\.(.*)$/,x=/^(?:textarea|input|select)$/i,y=/\./g,z=/ /g,A=/[^\w\s.|`]/g,B=function(a){return a.replace(A,"\\$&")};f.event={add:function(a,c,d,e){if(a.nodeType!==3&&a.nodeType!==8){if(d===!1)d=C;else if(!d)return;var g,h;d.handler&&(g=d,d=g.handler),d.guid||(d.guid=f.guid++);var i=f._data(a);if(!i)return;var j=i.events,k=i.handle;j||(i.events=j={}),k||(i.handle=k=function(a){return typeof f!="undefined"&&(!a||f.event.triggered!==a.type)?f.event.handle.apply(k.elem,arguments):b}),k.elem=a,c=c.split(" ");var l,m=0,n;while(l=c[m++]){h=g?f.extend({},g):{handler:d,data:e},l.indexOf(".")>-1?(n=l.split("."),l=n.shift(),h.namespace=n.slice(0).sort().join(".")):(n=[],h.namespace=""),h.type=l,h.guid||(h.guid=d.guid);var o=j[l],p=f.event.special[l]||{};if(!o){o=j[l]=[];if(!p.setup||p.setup.call(a,e,n,k)===!1)a.addEventListener?a.addEventListener(l,k,!1):a.attachEvent&&a.attachEvent("on"+l,k)}p.add&&(p.add.call(a,h),h.handler.guid||(h.handler.guid=d.guid)),o.push(h),f.event.global[l]=!0}a=null}},global:{},remove:function(a,c,d,e){if(a.nodeType!==3&&a.nodeType!==8){d===!1&&(d=C);var g,h,i,j,k=0,l,m,n,o,p,q,r,s=f.hasData(a)&&f._data(a),t=s&&s.events;if(!s||!t)return;c&&c.type&&(d=c.handler,c=c.type);if(!c||typeof c=="string"&&c.charAt(0)==="."){c=c||"";for(h in t)f.event.remove(a,h+c);return}c=c.split(" ");while(h=c[k++]){r=h,q=null,l=h.indexOf(".")<0,m=[],l||(m=h.split("."),h=m.shift(),n=new RegExp("(^|\\.)"+f.map(m.slice(0).sort(),B).join("\\.(?:.*\\.)?")+"(\\.|$)")),p=t[h];if(!p)continue;if(!d){for(j=0;j<p.length;j++){q=p[j];if(l||n.test(q.namespace))f.event.remove(a,r,q.handler,j),p.splice(j--,1)}continue}o=f.event.special[h]||{};for(j=e||0;j<p.length;j++){q=p[j];if(d.guid===q.guid){if(l||n.test(q.namespace))e==null&&p.splice(j--,1),o.remove&&o.remove.call(a,q);if(e!=null)break}}if(p.length===0||e!=null&&p.length===1)(!o.teardown||o.teardown.call(a,m)===!1)&&f.removeEvent(a,h,s.handle),g=null
|
3 |
+
,delete t[h]}if(f.isEmptyObject(t)){var u=s.handle;u&&(u.elem=null),delete s.events,delete s.handle,f.isEmptyObject(s)&&f.removeData(a,b,!0)}}},customEvent:{getData:!0,setData:!0,changeData:!0},trigger:function(c,d,e,g){var h=c.type||c,i=[],j;h.indexOf("!")>=0&&(h=h.slice(0,-1),j=!0),h.indexOf(".")>=0&&(i=h.split("."),h=i.shift(),i.sort());if(!!e&&!f.event.customEvent[h]||!!f.event.global[h]){c=typeof c=="object"?c[f.expando]?c:new f.Event(h,c):new f.Event(h),c.type=h,c.exclusive=j,c.namespace=i.join("."),c.namespace_re=new RegExp("(^|\\.)"+i.join("\\.(?:.*\\.)?")+"(\\.|$)");if(g||!e)c.preventDefault(),c.stopPropagation();if(!e){f.each(f.cache,function(){var a=f.expando,b=this[a];b&&b.events&&b.events[h]&&f.event.trigger(c,d,b.handle.elem)});return}if(e.nodeType===3||e.nodeType===8)return;c.result=b,c.target=e,d=d!=null?f.makeArray(d):[],d.unshift(c);var k=e,l=h.indexOf(":")<0?"on"+h:"";do{var m=f._data(k,"handle");c.currentTarget=k,m&&m.apply(k,d),l&&f.acceptData(k)&&k[l]&&k[l].apply(k,d)===!1&&(c.result=!1,c.preventDefault()),k=k.parentNode||k.ownerDocument||k===c.target.ownerDocument&&a}while(k&&!c.isPropagationStopped());if(!c.isDefaultPrevented()){var n,o=f.event.special[h]||{};if((!o._default||o._default.call(e.ownerDocument,c)===!1)&&(h!=="click"||!f.nodeName(e,"a"))&&f.acceptData(e)){try{l&&e[h]&&(n=e[l],n&&(e[l]=null),f.event.triggered=h,e[h]())}catch(p){}n&&(e[l]=n),f.event.triggered=b}}return c.result}},handle:function(c){c=f.event.fix(c||a.event);var d=((f._data(this,"events")||{})[c.type]||[]).slice(0),e=!c.exclusive&&!c.namespace,g=Array.prototype.slice.call(arguments,0);g[0]=c,c.currentTarget=this;for(var h=0,i=d.length;h<i;h++){var j=d[h];if(e||c.namespace_re.test(j.namespace)){c.handler=j.handler,c.data=j.data,c.handleObj=j;var k=j.handler.apply(this,g);k!==b&&(c.result=k,k===!1&&(c.preventDefault(),c.stopPropagation()));if(c.isImmediatePropagationStopped())break}}return c.result},props:"altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode layerX layerY metaKey newValue offsetX offsetY pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),fix:function(a){if(a[f.expando])return a;var d=a;a=f.Event(d);for(var e=this.props.length,g;e;)g=this.props[--e],a[g]=d[g];a.target||(a.target=a.srcElement||c),a.target.nodeType===3&&(a.target=a.target.parentNode),!a.relatedTarget&&a.fromElement&&(a.relatedTarget=a.fromElement===a.target?a.toElement:a.fromElement);if(a.pageX==null&&a.clientX!=null){var h=a.target.ownerDocument||c,i=h.documentElement,j=h.body;a.pageX=a.clientX+(i&&i.scrollLeft||j&&j.scrollLeft||0)-(i&&i.clientLeft||j&&j.clientLeft||0),a.pageY=a.clientY+(i&&i.scrollTop||j&&j.scrollTop||0)-(i&&i.clientTop||j&&j.clientTop||0)}a.which==null&&(a.charCode!=null||a.keyCode!=null)&&(a.which=a.charCode!=null?a.charCode:a.keyCode),!a.metaKey&&a.ctrlKey&&(a.metaKey=a.ctrlKey),!a.which&&a.button!==b&&(a.which=a.button&1?1:a.button&2?3:a.button&4?2:0);return a},guid:1e8,proxy:f.proxy,special:{ready:{setup:f.bindReady,teardown:f.noop},live:{add:function(a){f.event.add(this,M(a.origType,a.selector),f.extend({},a,{handler:L,guid:a.handler.guid}))},remove:function(a){f.event.remove(this,M(a.origType,a.selector),a)}},beforeunload:{setup:function(a,b,c){f.isWindow(this)&&(this.onbeforeunload=c)},teardown:function(a,b){this.onbeforeunload===b&&(this.onbeforeunload=null)}}}},f.removeEvent=c.removeEventListener?function(a,b,c){a.removeEventListener&&a.removeEventListener(b,c,!1)}:function(a,b,c){a.detachEvent&&a.detachEvent("on"+b,c)},f.Event=function(a,b){if(!this.preventDefault)return new f.Event(a,b);a&&a.type?(this.originalEvent=a,this.type=a.type,this.isDefaultPrevented=a.defaultPrevented||a.returnValue===!1||a.getPreventDefault&&a.getPreventDefault()?D:C):this.type=a,b&&f.extend(this,b),this.timeStamp=f.now(),this[f.expando]=!0},f.Event.prototype={preventDefault:function(){this.isDefaultPrevented=D;var a=this.originalEvent;!a||(a.preventDefault?a.preventDefault():a.returnValue=!1)},stopPropagation:function(){this.isPropagationStopped=D;var a=this.originalEvent;!a||(a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0)},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=D,this.stopPropagation()},isDefaultPrevented:C,isPropagationStopped:C,isImmediatePropagationStopped:C};var E=function(a){var b=a.relatedTarget,c=!1,d=a.type;a.type=a.data,b!==this&&(b&&(c=f.contains(this,b)),c||(f.event.handle.apply(this,arguments),a.type=d))},F=function(a){a.type=a.data,f.event.handle.apply(this,arguments)};f.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(a,b){f.event.special[a]={setup:function(c){f.event.add(this,b,c&&c.selector?F:E,a)},teardown:function(a){f.event.remove(this,b,a&&a.selector?F:E)}}}),f.support.submitBubbles||(f.event.special.submit={setup:function(a,b){if(!f.nodeName(this,"form"))f.event.add(this,"click.specialSubmit",function(a){var b=a.target,c=f.nodeName(b,"input")?b.type:"";(c==="submit"||c==="image")&&f(b).closest("form").length&&J("submit",this,arguments)}),f.event.add(this,"keypress.specialSubmit",function(a){var b=a.target,c=f.nodeName(b,"input")?b.type:"";(c==="text"||c==="password")&&f(b).closest("form").length&&a.keyCode===13&&J("submit",this,arguments)});else return!1},teardown:function(a){f.event.remove(this,".specialSubmit")}});if(!f.support.changeBubbles){var G,H=function(a){var b=f.nodeName(a,"input")?a.type:"",c=a.value;b==="radio"||b==="checkbox"?c=a.checked:b==="select-multiple"?c=a.selectedIndex>-1?f.map(a.options,function(a){return a.selected}).join("-"):"":f.nodeName(a,"select")&&(c=a.selectedIndex);return c},I=function(c){var d=c.target,e,g;if(!!x.test(d.nodeName)&&!d.readOnly){e=f._data(d,"_change_data"),g=H(d),(c.type!=="focusout"||d.type!=="radio")&&f._data(d,"_change_data",g);if(e===b||g===e)return;if(e!=null||g)c.type="change",c.liveFired=b,f.event.trigger(c,arguments[1],d)}};f.event.special.change={filters:{focusout:I,beforedeactivate:I,click:function(a){var b=a.target,c=f.nodeName(b,"input")?b.type:"";(c==="radio"||c==="checkbox"||f.nodeName(b,"select"))&&I.call(this,a)},keydown:function(a){var b=a.target,c=f.nodeName(b,"input")?b.type:"";(a.keyCode===13&&!f.nodeName(b,"textarea")||a.keyCode===32&&(c==="checkbox"||c==="radio")||c==="select-multiple")&&I.call(this,a)},beforeactivate:function(a){var b=a.target;f._data(b,"_change_data",H(b))}},setup:function(a,b){if(this.type==="file")return!1;for(var c in G)f.event.add(this,c+".specialChange",G[c]);return x.test(this.nodeName)},teardown:function(a){f.event.remove(this,".specialChange");return x.test(this.nodeName)}},G=f.event.special.change.filters,G.focus=G.beforeactivate}f.support.focusinBubbles||f.each({focus:"focusin",blur:"focusout"},function(a,b){function e(a){var c=f.event.fix(a);c.type=b,c.originalEvent={},f.event.trigger(c,null,c.target),c.isDefaultPrevented()&&a.preventDefault()}var d=0;f.event.special[b]={setup:function(){d++===0&&c.addEventListener(a,e,!0)},teardown:function(){--d===0&&c.removeEventListener(a,e,!0)}}}),f.each(["bind","one"],function(a,c){f.fn[c]=function(a,d,e){var g;if(typeof a=="object"){for(var h in a)this[c](h,d,a[h],e);return this}if(arguments.length===2||d===!1)e=d,d=b;c==="one"?(g=function(a){f(this).unbind(a,g);return e.apply(this,arguments)},g.guid=e.guid||f.guid++):g=e;if(a==="unload"&&c!=="one")this.one(a,d,e);else for(var i=0,j=this.length;i<j;i++)f.event.add(this[i],a,g,d);return this}}),f.fn.extend({unbind:function(a,b){if(typeof a=="object"&&!a.preventDefault)for(var c in a)this.unbind(c,a[c]);else for(var d=0,e=this.length;d<e;d++)f.event.remove(this[d],a,b);return this},delegate:function(a,b,c,d){return this.live(b,c,d,a)},undelegate:function(a,b,c){return arguments.length===0?this.unbind("live"):this.die(b,null,c,a)},trigger:function(a,b){return this.each(function(){f.event.trigger(a,b,this)})},triggerHandler:function(a,b){if(this[0])return f.event.trigger(a,b,this[0],!0)},toggle:function(a){var b=arguments,c=a.guid||f.guid++,d=0,e=function(c){var e=(f.data(this,"lastToggle"+a.guid)||0)%d;f.data(this,"lastToggle"+a.guid,e+1),c.preventDefault();return b[e].apply(this,arguments)||!1};e.guid=c;while(d<b.length)b[d++].guid=c;return this.click(e)},hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)}});var K={focus:"focusin",blur:"focusout",mouseenter:"mouseover",mouseleave:"mouseout"};f.each(["live","die"],function(a,c){f.fn[c]=function(a,d,e,g){var h,i=0,j,k,l,m=g||this.selector,n=g?this:f(this.context);if(typeof a=="object"&&!a.preventDefault){for(var o in a)n[c](o,d,a[o],m);return this}if(c==="die"&&!a&&g&&g.charAt(0)==="."){n.unbind(g);return this}if(d===!1||f.isFunction(d))e=d||C,d=b;a=(a||"").split(" ");while((h=a[i++])!=null){j=w.exec(h),k="",j&&(k=j[0],h=h.replace(w,""));if(h==="hover"){a.push("mouseenter"+k,"mouseleave"+k);continue}l=h,K[h]?(a.push(K[h]+k),h=h+k):h=(K[h]||h)+k;if(c==="live")for(var p=0,q=n.length;p<q;p++)f.event.add(n[p],"live."+M(h,m),{data:d,selector:m,handler:e,origType:h,origHandler:e,preType:l});else n.unbind("live."+M(h,m),e)}return this}}),f.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error".split(" "),function(a,b){f.fn[b]=function(a,c){c==null&&(c=a,a=null);return arguments.length>0?this.bind(b,a,c):this.trigger(b)},f.attrFn&&(f.attrFn[b]=!0)}),function(){function u(a,b,c,d,e,f){for(var g=0,h=d.length;g<h;g++){var i=d[g];if(i){var j=!1;i=i[a];while(i){if(i.sizcache===c){j=d[i.sizset];break}if(i.nodeType===1){f||(i.sizcache=c,i.sizset=g);if(typeof b!="string"){if(i===b){j=!0;break}}else if(k.filter(b,[i]).length>0){j=i;break}}i=i[a]}d[g]=j}}}function t(a,b,c,d,e,f){for(var g=0,h=d.length;g<h;g++){var i=d[g];if(i){var j=!1;i=i[a];while(i){if(i.sizcache===c){j=d[i.sizset];break}i.nodeType===1&&!f&&(i.sizcache=c,i.sizset=g);if(i.nodeName.toLowerCase()===b){j=i;break}i=i[a]}d[g]=j}}}var a=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,d=0,e=Object.prototype.toString,g=!1,h=!0,i=/\\/g,j=/\W/;[0,0].sort(function(){h=!1;return 0});var k=function(b,d,f,g){f=f||[],d=d||c;var h=d;if(d.nodeType!==1&&d.nodeType!==9)return[];if(!b||typeof b!="string")return f;var i,j,n,o,q,r,s,t,u=!0,w=k.isXML(d),x=[],y=b;do{a.exec(""),i=a.exec(y);if(i){y=i[3],x.push(i[1]);if(i[2]){o=i[3];break}}}while(i);if(x.length>1&&m.exec(b))if(x.length===2&&l.relative[x[0]])j=v(x[0]+x[1],d);else{j=l.relative[x[0]]?[d]:k(x.shift(),d);while(x.length)b=x.shift(),l.relative[b]&&(b+=x.shift()),j=v(b,j)}else{!g&&x.length>1&&d.nodeType===9&&!w&&l.match.ID.test(x[0])&&!l.match.ID.test(x[x.length-1])&&(q=k.find(x.shift(),d,w),d=q.expr?k.filter(q.expr,q.set)[0]:q.set[0]);if(d){q=g?{expr:x.pop(),set:p(g)}:k.find(x.pop(),x.length===1&&(x[0]==="~"||x[0]==="+")&&d.parentNode?d.parentNode:d,w),j=q.expr?k.filter(q.expr,q.set):q.set,x.length>0?n=p(j):u=!1;while(x.length)r=x.pop(),s=r,l.relative[r]?s=x.pop():r="",s==null&&(s=d),l.relative[r](n,s,w)}else n=x=[]}n||(n=j),n||k.error(r||b);if(e.call(n)==="[object Array]")if(!u)f.push.apply(f,n);else if(d&&d.nodeType===1)for(t=0;n[t]!=null;t++)n[t]&&(n[t]===!0||n[t].nodeType===1&&k.contains(d,n[t]))&&f.push(j[t]);else for(t=0;n[t]!=null;t++)n[t]&&n[t].nodeType===1&&f.push(j[t]);else p(n,f);o&&(k(o,h,f,g),k.uniqueSort(f));return f};k.uniqueSort=function(a){if(r){g=h,a.sort(r);if(g)for(var b=1;b<a.length;b++)a[b]===a[b-1]&&a.splice(b--,1)}return a},k.matches=function(a,b){return k(a,null,null,b)},k.matchesSelector=function(a,b){return k(b,null,null,[a]).length>0},k.find=function(a,b,c){var d;if(!a)return[];for(var e=0,f=l.order.length;e<f;e++){var g,h=l.order[e];if(g=l.leftMatch[h].exec(a)){var j=g[1];g.splice(1,1);if(j.substr(j.length-1)!=="\\"){g[1]=(g[1]||"").replace(i,""),d=l.find[h](g,b,c);if(d!=null){a=a.replace(l.match[h],"");break}}}}d||(d=typeof b.getElementsByTagName!="undefined"?b.getElementsByTagName("*"):[]);return{set:d,expr:a}},k.filter=function(a,c,d,e){var f,g,h=a,i=[],j=c,m=c&&c[0]&&k.isXML(c[0]);while(a&&c.length){for(var n in l.filter)if((f=l.leftMatch[n].exec(a))!=null&&f[2]){var o,p,q=l.filter[n],r=f[1];g=!1,f.splice(1,1);if(r.substr(r.length-1)==="\\")continue;j===i&&(i=[]);if(l.preFilter[n]){f=l.preFilter[n](f,j,d,i,e,m);if(!f)g=o=!0;else if(f===!0)continue}if(f)for(var s=0;(p=j[s])!=null;s++)if(p){o=q(p,f,s,j);var t=e^!!o;d&&o!=null?t?g=!0:j[s]=!1:t&&(i.push(p),g=!0)}if(o!==b){d||(j=i),a=a.replace(l.match[n],"");if(!g)return[];break}}if(a===h)if(g==null)k.error(a);else break;h=a}return j},k.error=function(a){throw"Syntax error, unrecognized expression: "+a};var l=k.selectors={order:["ID","NAME","TAG"],match:{ID:/#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,CLASS:/\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,NAME:/\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,ATTR:/\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/,TAG:/^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,CHILD:/:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/,POS:/:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,PSEUDO:/:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/},leftMatch:{},attrMap:{"class":"className","for":"htmlFor"},attrHandle:{href:function(a){return a.getAttribute("href")},type:function(a){return a.getAttribute("type")}},relative:{"+":function(a,b){var c=typeof b=="string",d=c&&!j.test(b),e=c&&!d;d&&(b=b.toLowerCase());for(var f=0,g=a.length,h;f<g;f++)if(h=a[f]){while((h=h.previousSibling)&&h.nodeType!==1);a[f]=e||h&&h.nodeName.toLowerCase()===b?h||!1:h===b}e&&k.filter(b,a,!0)},">":function(a,b){var c,d=typeof b=="string",e=0,f=a.length;if(d&&!j.test(b)){b=b.toLowerCase();for(;e<f;e++){c=a[e];if(c){var g=c.parentNode;a[e]=g.nodeName.toLowerCase()===b?g:!1}}}else{for(;e<f;e++)c=a[e],c&&(a[e]=d?c.parentNode:c.parentNode===b);d&&k.filter(b,a,!0)}},"":function(a,b,c){var e,f=d++,g=u;typeof b=="string"&&!j.test(b)&&(b=b.toLowerCase(),e=b,g=t),g("parentNode",b,f,a,e,c)},"~":function(a,b,c){var e,f=d++,g=u;typeof b=="string"&&!j.test(b)&&(b=b.toLowerCase(),e=b,g=t),g("previousSibling",b,f,a,e,c)}},find:{ID:function(a,b,c){if(typeof b.getElementById!="undefined"&&!c){var d=b.getElementById(a[1]);return d&&d.parentNode?[d]:[]}},NAME:function(a,b){if(typeof b.getElementsByName!="undefined"){var c=[],d=b.getElementsByName(a[1]);for(var e=0,f=d.length;e<f;e++)d[e].getAttribute("name")===a[1]&&c.push(d[e]);return c.length===0?null:c}},TAG:function(a,b){if(typeof b.getElementsByTagName!="undefined")return b.getElementsByTagName(a[1])}},preFilter:{CLASS:function(a,b,c,d,e,f){a=" "+a[1].replace(i,"")+" ";if(f)return a;for(var g=0,h;(h=b[g])!=null;g++)h&&(e^(h.className&&(" "+h.className+" ").replace(/[\t\n\r]/g," ").indexOf(a)>=0)?c||d.push(h):c&&(b[g]=!1));return!1},ID:function(a){return a[1].replace(i,"")},TAG:function(a,b){return a[1].replace(i,"").toLowerCase()},CHILD:function(a){if(a[1]==="nth"){a[2]||k.error(a[0]),a[2]=a[2].replace(/^\+|\s*/g,"");var b=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(a[2]==="even"&&"2n"||a[2]==="odd"&&"2n+1"||!/\D/.test(a[2])&&"0n+"+a[2]||a[2]);a[2]=b[1]+(b[2]||1)-0,a[3]=b[3]-0}else a[2]&&k.error(a[0]);a[0]=d++;return a},ATTR:function(a,b,c,d,e,f){var g=a[1]=a[1].replace(i,"");!f&&l.attrMap[g]&&(a[1]=l.attrMap[g]),a[4]=(a[4]||a[5]||"").replace(i,""),a[2]==="~="&&(a[4]=" "+a[4]+" ");return a},PSEUDO:function(b,c,d,e,f){if(b[1]==="not")if((a.exec(b[3])||"").length>1||/^\w/.test(b[3]))b[3]=k(b[3],null,null,c);else{var g=k.filter(b[3],c,d,!0^f);d||e.push.apply(e,g);return!1}else if(l.match.POS.test(b[0])||l.match.CHILD.test(b[0]))return!0;return b},POS:function(a){a.unshift(!0);return a}},filters:{enabled:function(a){return a.disabled===!1&&a.type!=="hidden"},disabled:function(a){return a.disabled===!0},checked:function(a){return a.checked===!0},selected:function(a){a.parentNode&&a.parentNode.selectedIndex;return a.selected===!0},parent:function(a){return!!a.firstChild},empty:function(a){return!a.firstChild},has:function(a,b,c){return!!k(c[3],a).length},header:function(a){return/h\d/i.test(a.nodeName)},text:function(a){var b=a.getAttribute("type"),c=a.type;return a.nodeName.toLowerCase()==="input"&&"text"===c&&(b===c||b===null)},radio:function(a){return a.nodeName.toLowerCase()==="input"&&"radio"===a.type},checkbox:function(a){return a.nodeName.toLowerCase()==="input"&&"checkbox"===a.type},file:function(a){return a.nodeName.toLowerCase()==="input"&&"file"===a.type},password:function(a){return a.nodeName.toLowerCase()==="input"&&"password"===a.type},submit:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"submit"===a.type},image:function(a){return a.nodeName.toLowerCase()==="input"&&"image"===a.type},reset:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"reset"===a.type},button:function(a){var b=a.nodeName.toLowerCase();return b==="input"&&"button"===a.type||b==="button"},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)},focus:function(a){return a===a.ownerDocument.activeElement}},setFilters:{first:function(a,b){return b===0},last:function(a,b,c,d){return b===d.length-1},even:function(a,b){return b%2===0},odd:function(a,b){return b%2===1},lt:function(a,b,c){return b<c[3]-0},gt:function(a,b,c){return b>c[3]-0},nth:function(a,b,c){return c[3]-0===b},eq:function(a,b,c){return c[3]-0===b}},filter:{PSEUDO:function(a,b,c,d){var e=b[1],f=l.filters[e];if(f)return f(a,c,b,d);if(e==="contains")return(a.textContent||a.innerText||k.getText([a])||"").indexOf(b[3])>=0;if(e==="not"){var g=b[3];for(var h=0,i=g.length;h<i;h++)if(g[h]===a)return!1;return!0}k.error(e)},CHILD:function(a,b){var c=b[1],d=a;switch(c){case"only":case"first":while(d=d.previousSibling)if(d.nodeType===1)return!1;if(c==="first")return!0;d=a;case"last":while(d=d.nextSibling)if(d.nodeType===1)return!1;return!0;case"nth":var e=b[2],f=b[3];if(e===1&&f===0)return!0;var g=b[0],h=a.parentNode;if(h&&(h.sizcache!==g||!a.nodeIndex)){var i=0;for(d=h.firstChild;d;d=d.nextSibling)d.nodeType===1&&(d.nodeIndex=++i);h.sizcache=g}var j=a.nodeIndex-f;return e===0?j===0:j%e===0&&j/e>=0}},ID:function(a,b){return a.nodeType===1&&a.getAttribute("id")===b},TAG:function(a,b){return b==="*"&&a.nodeType===1||a.nodeName.toLowerCase()===b},CLASS:function(a,b){return(" "+(a.className||a.getAttribute("class"))+" ").indexOf(b)>-1},ATTR:function(a,b){var c=b[1],d=l.attrHandle[c]?l.attrHandle[c](a):a[c]!=null?a[c]:a.getAttribute(c),e=d+"",f=b[2],g=b[4];return d==null?f==="!=":f==="="?e===g:f==="*="?e.indexOf(g)>=0:f==="~="?(" "+e+" ").indexOf(g)>=0:g?f==="!="?e!==g:f==="^="?e.indexOf(g)===0:f==="$="?e.substr(e.length-g.length)===g:f==="|="?e===g||e.substr(0,g.length+1)===g+"-":!1:e&&d!==!1},POS:function(a,b,c,d){var e=b[2],f=l.setFilters[e];if(f)return f(a,c,b,d)}}},m=l.match.POS,n=function(a,b){return"\\"+(b-0+1)};for(var o in l.match)l.match[o]=new RegExp(l.match[o].source+/(?![^\[]*\])(?![^\(]*\))/.source),l.leftMatch[o]=new RegExp(/(^(?:.|\r|\n)*?)/.source+l.match[o].source.replace(/\\(\d+)/g,n));var p=function(a,b){a=Array.prototype.slice.call(a,0);if(b){b.push.apply(b,a);return b}return a};try{Array.prototype.slice.call(c.documentElement.childNodes,0)[0].nodeType}catch(q){p=function(a,b){var c=0,d=b||[];if(e.call(a)==="[object Array]")Array.prototype.push.apply(d,a);else if(typeof a.length=="number")for(var f=a.length;c<f;c++)d.push(a[c]);else for(;a[c];c++)d.push(a[c]);return d}}var r,s;c.documentElement.compareDocumentPosition?r=function(a,b){if(a===b){g=!0;return 0}if(!a.compareDocumentPosition||!b.compareDocumentPosition)return a.compareDocumentPosition?-1:1;return a.compareDocumentPosition(b)&4?-1:1}:(r=function(a,b){if(a===b){g=!0;return 0}if(a.sourceIndex&&b.sourceIndex)return a.sourceIndex-b.sourceIndex;var c,d,e=[],f=[],h=a.parentNode,i=b.parentNode,j=h;if(h===i)return s(a,b);if(!h)return-1;if(!i)return 1;while(j)e.unshift(j),j=j.parentNode;j=i;while(j)f.unshift(j),j=j.parentNode;c=e.length,d=f.length;for(var k=0;k<c&&k<d;k++)if(e[k]!==f[k])return s(e[k],f[k]);return k===c?s(a,f[k],-1):s(e[k],b,1)},s=function(a,b,c){if(a===b)return c;var d=a.nextSibling;while(d){if(d===b)return-1;d=d.nextSibling}return 1}),k.getText=function(a){var b="",c;for(var d=0;a[d];d++)c=a[d],c.nodeType===3||c.nodeType===4?b+=c.nodeValue:c.nodeType!==8&&(b+=k.getText(c.childNodes));return b},function(){var a=c.createElement("div"),d="script"+(new Date).getTime(),e=c.documentElement;a.innerHTML="<a name='"+d+"'/>",e.insertBefore(a,e.firstChild),c.getElementById(d)&&(l.find.ID=function(a,c,d){if(typeof c.getElementById!="undefined"&&!d){var e=c.getElementById(a[1]);return e?e.id===a[1]||typeof e.getAttributeNode!="undefined"&&e.getAttributeNode("id").nodeValue===a[1]?[e]:b:[]}},l.filter.ID=function(a,b){var c=typeof a.getAttributeNode!="undefined"&&a.getAttributeNode("id");return a.nodeType===1&&c&&c.nodeValue===b}),e.removeChild(a),e=a=null}(),function(){var a=c.createElement("div");a.appendChild(c.createComment("")),a.getElementsByTagName("*").length>0&&(l.find.TAG=function(a,b){var c=b.getElementsByTagName(a[1]);if(a[1]==="*"){var d=[];for(var e=0;c[e];e++)c[e].nodeType===1&&d.push(c[e]);c=d}return c}),a.innerHTML="<a href='#'></a>",a.firstChild&&typeof a.firstChild.getAttribute!="undefined"&&a.firstChild.getAttribute("href")!=="#"&&(l.attrHandle.href=function(a){return a.getAttribute("href",2)}),a=null}(),c.querySelectorAll&&function(){var a=k,b=c.createElement("div"),d="__sizzle__";b.innerHTML="<p class='TEST'></p>";if(!b.querySelectorAll||b.querySelectorAll(".TEST").length!==0){k=function(b,e,f,g){e=e||c;if(!g&&!k.isXML(e)){var h=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b);if(h&&(e.nodeType===1||e.nodeType===9)){if(h[1])return p(e.getElementsByTagName(b),f);if(h[2]&&l.find.CLASS&&e.getElementsByClassName)return p(e.getElementsByClassName(h[2]),f)}if(e.nodeType===9){if(b==="body"&&e.body)return p([e.body],f);if(h&&h[3]){var i=e.getElementById(h[3]);if(!i||!i.parentNode)return p([],f);if(i.id===h[3])return p([i],f)}try{return p(e.querySelectorAll(b),f)}catch(j){}}else if(e.nodeType===1&&e.nodeName.toLowerCase()!=="object"){var m=e,n=e.getAttribute("id"),o=n||d,q=e.parentNode,r=/^\s*[+~]/.test(b);n?o=o.replace(/'/g,"\\$&"):e.setAttribute("id",o),r&&q&&(e=e.parentNode);try{if(!r||q)return p(e.querySelectorAll("[id='"+o+"'] "+b),f)}catch(s){}finally{n||m.removeAttribute("id")}}}return a(b,e,f,g)};for(var e in a)k[e]=a[e];b=null}}(),function(){var a=c.documentElement,b=a.matchesSelector||a.mozMatchesSelector||a.webkitMatchesSelector||a.msMatchesSelector;if(b){var d=!b.call(c.createElement("div"),"div"),e=!1;try{b.call(c.documentElement,"[test!='']:sizzle")}catch(f){e=!0}k.matchesSelector=function(a,c){c=c.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!k.isXML(a))try{if(e||!l.match.PSEUDO.test(c)&&!/!=/.test(c)){var f=b.call(a,c);if(f||!d||a.document&&a.document.nodeType!==11)return f}}catch(g){}return k(c,null,null,[a]).length>0}}}(),function(){var a=c.createElement("div");a.innerHTML="<div class='test e'></div><div class='test'></div>";if(!!a.getElementsByClassName&&a.getElementsByClassName("e").length!==0){a.lastChild.className="e";if(a.getElementsByClassName("e").length===1)return;l.order.splice(1,0,"CLASS"),l.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!="undefined"&&!c)return b.getElementsByClassName(a[1])},a=null}}(),c.documentElement.contains?k.contains=function(a,b){return a!==b&&(a.contains?a.contains(b):!0)}:c.documentElement.compareDocumentPosition?k.contains=function(a,b){return!!(a.compareDocumentPosition(b)&16)}:k.contains=function(){return!1},k.isXML=function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!=="HTML":!1};var v=function(a,b){var c,d=[],e="",f=b.nodeType?[b]:b;while(c=l.match.PSEUDO.exec(a))e+=c[0],a=a.replace(l.match.PSEUDO,"");a=l.relative[a]?a+"*":a;for(var g=0,h=f.length;g<h;g++)k(a,f[g],d);return k.filter(e,d)};f.find=k,f.expr=k.selectors,f.expr[":"]=f.expr.filters,f.unique=k.uniqueSort,f.text=k.getText,f.isXMLDoc=k.isXML,f.contains=k.contains}();var N=/Until$/,O=/^(?:parents|prevUntil|prevAll)/,P=/,/,Q=/^.[^:#\[\.,]*$/,R=Array.prototype.slice,S=f.expr.match.POS,T={children:!0,contents:!0,next:!0,prev:!0};f.fn.extend({find:function(a){var b=this,c,d;if(typeof a!="string")return f(a).filter(function(){for(c=0,d=b.length;c<d;c++)if(f.contains(b[c],this))return!0});var e=this.pushStack("","find",a),g,h,i;for(c=0,d=this.length;c<d;c++){g=e.length,f.find(a,this[c],e);if(c>0)for(h=g;h<e.length;h++)for(i=0;i<g;i++)if(e[i]===e[h]){e.splice(h--,1);break}}return e},has:function(a){var b=f(a);return this.filter(function(){for(var a=0,c=b.length;a<c;a++)if(f.contains(this,b[a]))return!0})},not:function(a){return this.pushStack(V(this,a,!1),"not",a)},filter:function(a){return this.pushStack(V(this,a,!0),"filter",a)},is:function(a){return!!a&&(typeof a=="string"?f.filter(a,this).length>0:this.filter(a).length>0)},closest:function(a,b){var c=[],d,e,g=this[0];if(f.isArray(a)){var h,i,j={},k=1;if(g&&a.length){for(d=0,e=a.length;d<e;d++)i=a[d],j[i]||(j[i]=S.test(i)?f(i,b||this.context):i);while(g&&g.ownerDocument&&g!==b){for(i in j)h=j[i],(h.jquery?h.index(g)>-1:f(g).is(h))&&c.push({selector:i,elem:g,level:k});g=g.parentNode,k++}}return c}var l=S.test(a)||typeof a!="string"?f(a,b||this.context):0;for(d=0,e=this.length;d<e;d++){g=this[d];while(g){if(l?l.index(g)>-1:f.find.matchesSelector(g,a)){c.push(g);break}g=g.parentNode;if(!g||!g.ownerDocument||g===b||g.nodeType===11)break}}c=c.length>1?f.unique(c):c;return this.pushStack(c,"closest",a)},index:function(a){if(!a)return this[0]&&this[0].parentNode?this.prevAll().length:-1;if(typeof a=="string")return f.inArray(this[0],f(a));return f.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var c=typeof a=="string"?f(a,b):f.makeArray(a&&a.nodeType?[a]:a),d=f.merge(this.get(),c);return this.pushStack(U(c[0])||U(d[0])?d:f.unique(d))},andSelf:function(){return this.add(this.prevObject)}}),f.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return f.dir(a,"parentNode")},parentsUntil:function(a,b,c){return f.dir(a,"parentNode",c)},next:function(a){return f.nth(a,2,"nextSibling")},prev:function(a){return f.nth(a,2,"previousSibling")},nextAll:function(a){return f.dir(a,"nextSibling")},prevAll:function(a){return f.dir(a,"previousSibling")},nextUntil:function(a,b,c){return f.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return f.dir(a,"previousSibling",c)},siblings:function(a){return f.sibling(a.parentNode.firstChild,a)},children:function(a){return f.sibling(a.firstChild)},contents:function(a){return f.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:f.makeArray(a.childNodes)}},function(a,b){f.fn[a]=function(c,d){var e=f.map(this,b,c),g=R.call(arguments);N.test(a)||(d=c),d&&typeof d=="string"&&(e=f.filter(d,e)),e=this.length>1&&!T[a]?f.unique(e):e,(this.length>1||P.test(d))&&O.test(a)&&(e=e.reverse());return this.pushStack(e,a,g.join(","))}}),f.extend({filter:function(a,b,c){c&&(a=":not("+a+")");return b.length===1?f.find.matchesSelector(b[0],a)?[b[0]]:[]:f.find.matches(a,b)},dir:function(a,c,d){var e=[],g=a[c];while(g&&g.nodeType!==9&&(d===b||g.nodeType!==1||!f(g).is(d)))g.nodeType===1&&e.push(g),g=g[c];return e},nth:function(a,b,c,d){b=b||1;var e=0;for(;a;a=a[c])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var W=/ jQuery\d+="(?:\d+|null)"/g,X=/^\s+/,Y=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,Z=/<([\w:]+)/,$=/<tbody/i,_=/<|&#?\w+;/,ba=/<(?:script|object|embed|option|style)/i,bb=/checked\s*(?:[^=]|=\s*.checked.)/i,bc=/\/(java|ecma)script/i,bd=/^\s*<!(?:\[CDATA\[|\-\-)/,be={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],area:[1,"<map>","</map>"],_default:[0,"",""]};be.optgroup=be.option,be.tbody=be.tfoot=be.colgroup=be.caption=be.thead,be.th=be.td,f.support.htmlSerialize||(be._default=[1,"div<div>","</div>"]),f.fn.extend({text:function(a){if(f.isFunction(a))return this.each(function(b){var c=f(this);c.text(a.call(this,b,c.text()))});if(typeof a!="object"&&a!==b)return this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a));return f.text(this)},wrapAll:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapAll(a.call(this,b))});if(this[0]){var b=f(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapInner(a.call(this,b))});return this.each(function(){var b=f(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){return this.each(function(){f(this).wrapAll(a)})},unwrap:function(){return this.parent().each(function(){f.nodeName(this,"body")||f(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=f(arguments[0]);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,f(arguments[0]).toArray());return a}},remove:function(a,b){for(var c=0,d;(d=this[c])!=null;c++)if(!a||f.filter(a,[d]).length)!b&&d.nodeType===1&&(f.cleanData(d.getElementsByTagName("*")),f.cleanData([d])),d.parentNode&&d.parentNode.removeChild(d);return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++){b.nodeType===1&&f.cleanData(b.getElementsByTagName("*"));while(b.firstChild)b.removeChild(b.firstChild)}return this},clone:function(a,b){a=a==null?!1:a,b=b==null?a:b;return this.map(function(){return f.clone(this,a,b)})},html:function(a){if(a===b)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(W,""):null;if(typeof a=="string"&&!ba.test(a)&&(f.support.leadingWhitespace||!X.test(a))&&!be[(Z.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(Y,"<$1></$2>");try{for(var c=0,d=this.length;c<d;c++)this[c].nodeType===1&&(f.cleanData(this[c].getElementsByTagName("*")),this[c].innerHTML=a)}catch(e){this.empty().append(a)}}else f.isFunction(a)?this.each(function(b){var c=f(this);c.html(a.call(this,b,c.html()))}):this.empty().append(a);return this},replaceWith:function(a){if(this[0]&&this[0].parentNode){if(f.isFunction(a))return this.each(function(b){var c=f(this),d=c.html();c.replaceWith(a.call(this,b,d))});typeof a!="string"&&(a=f(a).detach());return this.each(function(){var b=this.nextSibling,c=this.parentNode;f(this).remove(),b?f(b).before(a):f(c).append(a)})}return this.length?this.pushStack(f(f.isFunction(a)?a():a),"replaceWith",a):this},detach:function(a){return this.remove(a,!0)},domManip:function(a,c,d){var e,g,h,i,j=a[0],k=[];if(!f.support.checkClone&&arguments.length===3&&typeof j=="string"&&bb.test(j))return this.each(function(){f(this).domManip(a,c,d,!0)});if(f.isFunction(j))return this.each(function(e){var g=f(this);a[0]=j.call(this,e,c?g.html():b),g.domManip(a,c,d)});if(this[0]){i=j&&j.parentNode,f.support.parentNode&&i&&i.nodeType===11&&i.childNodes.length===this.length?e={fragment:i}:e=f.buildFragment(a,this,k),h=e.fragment,h.childNodes.length===1?g=h=h.firstChild:g=h.firstChild;if(g){c=c&&f.nodeName(g,"tr");for(var l=0,m=this.length,n=m-1;l<m;l++)d.call(c?bf(this[l],g):this[l],e.cacheable||m>1&&l<n?f.clone(h,!0,!0):h)}k.length&&f.each(k,bl)}return this}}),f.buildFragment=function(a,b,d){var e,g,h,i;b&&b[0]&&(i=b[0].ownerDocument||b[0]),i.createDocumentFragment||(i=c),a.length===1&&typeof a[0]=="string"&&a[0].length<512&&i===c&&a[0].charAt(0)==="<"&&!ba.test(a[0])&&(f.support.checkClone||!bb.test(a[0]))&&(g=!0,h=f.fragments[a[0]],h&&h!==1&&(e=h)),e||(e=i.createDocumentFragment(),f.clean(a,i,e,d)),g&&(f.fragments[a[0]]=h?e:1);
|
4 |
+
return{fragment:e,cacheable:g}},f.fragments={},f.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){f.fn[a]=function(c){var d=[],e=f(c),g=this.length===1&&this[0].parentNode;if(g&&g.nodeType===11&&g.childNodes.length===1&&e.length===1){e[b](this[0]);return this}for(var h=0,i=e.length;h<i;h++){var j=(h>0?this.clone(!0):this).get();f(e[h])[b](j),d=d.concat(j)}return this.pushStack(d,a,e.selector)}}),f.extend({clone:function(a,b,c){var d=a.cloneNode(!0),e,g,h;if((!f.support.noCloneEvent||!f.support.noCloneChecked)&&(a.nodeType===1||a.nodeType===11)&&!f.isXMLDoc(a)){bh(a,d),e=bi(a),g=bi(d);for(h=0;e[h];++h)g[h]&&bh(e[h],g[h])}if(b){bg(a,d);if(c){e=bi(a),g=bi(d);for(h=0;e[h];++h)bg(e[h],g[h])}}e=g=null;return d},clean:function(a,b,d,e){var g;b=b||c,typeof b.createElement=="undefined"&&(b=b.ownerDocument||b[0]&&b[0].ownerDocument||c);var h=[],i;for(var j=0,k;(k=a[j])!=null;j++){typeof k=="number"&&(k+="");if(!k)continue;if(typeof k=="string")if(!_.test(k))k=b.createTextNode(k);else{k=k.replace(Y,"<$1></$2>");var l=(Z.exec(k)||["",""])[1].toLowerCase(),m=be[l]||be._default,n=m[0],o=b.createElement("div");o.innerHTML=m[1]+k+m[2];while(n--)o=o.lastChild;if(!f.support.tbody){var p=$.test(k),q=l==="table"&&!p?o.firstChild&&o.firstChild.childNodes:m[1]==="<table>"&&!p?o.childNodes:[];for(i=q.length-1;i>=0;--i)f.nodeName(q[i],"tbody")&&!q[i].childNodes.length&&q[i].parentNode.removeChild(q[i])}!f.support.leadingWhitespace&&X.test(k)&&o.insertBefore(b.createTextNode(X.exec(k)[0]),o.firstChild),k=o.childNodes}var r;if(!f.support.appendChecked)if(k[0]&&typeof (r=k.length)=="number")for(i=0;i<r;i++)bk(k[i]);else bk(k);k.nodeType?h.push(k):h=f.merge(h,k)}if(d){g=function(a){return!a.type||bc.test(a.type)};for(j=0;h[j];j++)if(e&&f.nodeName(h[j],"script")&&(!h[j].type||h[j].type.toLowerCase()==="text/javascript"))e.push(h[j].parentNode?h[j].parentNode.removeChild(h[j]):h[j]);else{if(h[j].nodeType===1){var s=f.grep(h[j].getElementsByTagName("script"),g);h.splice.apply(h,[j+1,0].concat(s))}d.appendChild(h[j])}}return h},cleanData:function(a){var b,c,d=f.cache,e=f.expando,g=f.event.special,h=f.support.deleteExpando;for(var i=0,j;(j=a[i])!=null;i++){if(j.nodeName&&f.noData[j.nodeName.toLowerCase()])continue;c=j[f.expando];if(c){b=d[c]&&d[c][e];if(b&&b.events){for(var k in b.events)g[k]?f.event.remove(j,k):f.removeEvent(j,k,b.handle);b.handle&&(b.handle.elem=null)}h?delete j[f.expando]:j.removeAttribute&&j.removeAttribute(f.expando),delete d[c]}}}});var bm=/alpha\([^)]*\)/i,bn=/opacity=([^)]*)/,bo=/([A-Z]|^ms)/g,bp=/^-?\d+(?:px)?$/i,bq=/^-?\d/,br=/^([\-+])=([\-+.\de]+)/,bs={position:"absolute",visibility:"hidden",display:"block"},bt=["Left","Right"],bu=["Top","Bottom"],bv,bw,bx;f.fn.css=function(a,c){if(arguments.length===2&&c===b)return this;return f.access(this,a,c,!0,function(a,c,d){return d!==b?f.style(a,c,d):f.css(a,c)})},f.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=bv(a,"opacity","opacity");return c===""?"1":c}return a.style.opacity}}},cssNumber:{fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":f.support.cssFloat?"cssFloat":"styleFloat"},style:function(a,c,d,e){if(!!a&&a.nodeType!==3&&a.nodeType!==8&&!!a.style){var g,h,i=f.camelCase(c),j=a.style,k=f.cssHooks[i];c=f.cssProps[i]||i;if(d===b){if(k&&"get"in k&&(g=k.get(a,!1,e))!==b)return g;return j[c]}h=typeof d,h==="string"&&(g=br.exec(d))&&(d=+(g[1]+1)*+g[2]+parseFloat(f.css(a,c)),h="number");if(d==null||h==="number"&&isNaN(d))return;h==="number"&&!f.cssNumber[i]&&(d+="px");if(!k||!("set"in k)||(d=k.set(a,d))!==b)try{j[c]=d}catch(l){}}},css:function(a,c,d){var e,g;c=f.camelCase(c),g=f.cssHooks[c],c=f.cssProps[c]||c,c==="cssFloat"&&(c="float");if(g&&"get"in g&&(e=g.get(a,!0,d))!==b)return e;if(bv)return bv(a,c)},swap:function(a,b,c){var d={};for(var e in b)d[e]=a.style[e],a.style[e]=b[e];c.call(a);for(e in b)a.style[e]=d[e]}}),f.curCSS=f.css,f.each(["height","width"],function(a,b){f.cssHooks[b]={get:function(a,c,d){var e;if(c){if(a.offsetWidth!==0)return by(a,b,d);f.swap(a,bs,function(){e=by(a,b,d)});return e}},set:function(a,b){if(!bp.test(b))return b;b=parseFloat(b);if(b>=0)return b+"px"}}}),f.support.opacity||(f.cssHooks.opacity={get:function(a,b){return bn.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"":b?"1":""},set:function(a,b){var c=a.style,d=a.currentStyle,e=f.isNaN(b)?"":"alpha(opacity="+b*100+")",g=d&&d.filter||c.filter||"";c.zoom=1;if(b>=1&&f.trim(g.replace(bm,""))===""){c.removeAttribute("filter");if(d&&!d.filter)return}c.filter=bm.test(g)?g.replace(bm,e):g+" "+e}}),f(function(){f.support.reliableMarginRight||(f.cssHooks.marginRight={get:function(a,b){var c;f.swap(a,{display:"inline-block"},function(){b?c=bv(a,"margin-right","marginRight"):c=a.style.marginRight});return c}})}),c.defaultView&&c.defaultView.getComputedStyle&&(bw=function(a,c){var d,e,g;c=c.replace(bo,"-$1").toLowerCase();if(!(e=a.ownerDocument.defaultView))return b;if(g=e.getComputedStyle(a,null))d=g.getPropertyValue(c),d===""&&!f.contains(a.ownerDocument.documentElement,a)&&(d=f.style(a,c));return d}),c.documentElement.currentStyle&&(bx=function(a,b){var c,d=a.currentStyle&&a.currentStyle[b],e=a.runtimeStyle&&a.runtimeStyle[b],f=a.style;!bp.test(d)&&bq.test(d)&&(c=f.left,e&&(a.runtimeStyle.left=a.currentStyle.left),f.left=b==="fontSize"?"1em":d||0,d=f.pixelLeft+"px",f.left=c,e&&(a.runtimeStyle.left=e));return d===""?"auto":d}),bv=bw||bx,f.expr&&f.expr.filters&&(f.expr.filters.hidden=function(a){var b=a.offsetWidth,c=a.offsetHeight;return b===0&&c===0||!f.support.reliableHiddenOffsets&&(a.style.display||f.css(a,"display"))==="none"},f.expr.filters.visible=function(a){return!f.expr.filters.hidden(a)});var bz=/%20/g,bA=/\[\]$/,bB=/\r?\n/g,bC=/#.*$/,bD=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,bE=/^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,bF=/^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,bG=/^(?:GET|HEAD)$/,bH=/^\/\//,bI=/\?/,bJ=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,bK=/^(?:select|textarea)/i,bL=/\s+/,bM=/([?&])_=[^&]*/,bN=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,bO=f.fn.load,bP={},bQ={},bR,bS,bT=["*/"]+["*"];try{bR=e.href}catch(bU){bR=c.createElement("a"),bR.href="",bR=bR.href}bS=bN.exec(bR.toLowerCase())||[],f.fn.extend({load:function(a,c,d){if(typeof a!="string"&&bO)return bO.apply(this,arguments);if(!this.length)return this;var e=a.indexOf(" ");if(e>=0){var g=a.slice(e,a.length);a=a.slice(0,e)}var h="GET";c&&(f.isFunction(c)?(d=c,c=b):typeof c=="object"&&(c=f.param(c,f.ajaxSettings.traditional),h="POST"));var i=this;f.ajax({url:a,type:h,dataType:"html",data:c,complete:function(a,b,c){c=a.responseText,a.isResolved()&&(a.done(function(a){c=a}),i.html(g?f("<div>").append(c.replace(bJ,"")).find(g):c)),d&&i.each(d,[c,b,a])}});return this},serialize:function(){return f.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?f.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||bK.test(this.nodeName)||bE.test(this.type))}).map(function(a,b){var c=f(this).val();return c==null?null:f.isArray(c)?f.map(c,function(a,c){return{name:b.name,value:a.replace(bB,"\r\n")}}):{name:b.name,value:c.replace(bB,"\r\n")}}).get()}}),f.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){f.fn[b]=function(a){return this.bind(b,a)}}),f.each(["get","post"],function(a,c){f[c]=function(a,d,e,g){f.isFunction(d)&&(g=g||e,e=d,d=b);return f.ajax({type:c,url:a,data:d,success:e,dataType:g})}}),f.extend({getScript:function(a,c){return f.get(a,b,c,"script")},getJSON:function(a,b,c){return f.get(a,b,c,"json")},ajaxSetup:function(a,b){b?bX(a,f.ajaxSettings):(b=a,a=f.ajaxSettings),bX(a,b);return a},ajaxSettings:{url:bR,isLocal:bF.test(bS[1]),global:!0,type:"GET",contentType:"application/x-www-form-urlencoded",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":bT},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":a.String,"text html":!0,"text json":f.parseJSON,"text xml":f.parseXML},flatOptions:{context:!0,url:!0}},ajaxPrefilter:bV(bP),ajaxTransport:bV(bQ),ajax:function(a,c){function w(a,c,l,m){if(s!==2){s=2,q&&clearTimeout(q),p=b,n=m||"",v.readyState=a>0?4:0;var o,r,u,w=c,x=l?bZ(d,v,l):b,y,z;if(a>=200&&a<300||a===304){if(d.ifModified){if(y=v.getResponseHeader("Last-Modified"))f.lastModified[k]=y;if(z=v.getResponseHeader("Etag"))f.etag[k]=z}if(a===304)w="notmodified",o=!0;else try{r=b$(d,x),w="success",o=!0}catch(A){w="parsererror",u=A}}else{u=w;if(!w||a)w="error",a<0&&(a=0)}v.status=a,v.statusText=""+(c||w),o?h.resolveWith(e,[r,w,v]):h.rejectWith(e,[v,w,u]),v.statusCode(j),j=b,t&&g.trigger("ajax"+(o?"Success":"Error"),[v,d,o?r:u]),i.resolveWith(e,[v,w]),t&&(g.trigger("ajaxComplete",[v,d]),--f.active||f.event.trigger("ajaxStop"))}}typeof a=="object"&&(c=a,a=b),c=c||{};var d=f.ajaxSetup({},c),e=d.context||d,g=e!==d&&(e.nodeType||e instanceof f)?f(e):f.event,h=f.Deferred(),i=f._Deferred(),j=d.statusCode||{},k,l={},m={},n,o,p,q,r,s=0,t,u,v={readyState:0,setRequestHeader:function(a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this},getAllResponseHeaders:function(){return s===2?n:null},getResponseHeader:function(a){var c;if(s===2){if(!o){o={};while(c=bD.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c},overrideMimeType:function(a){s||(d.mimeType=a);return this},abort:function(a){a=a||"abort",p&&p.abort(a),w(0,a);return this}};h.promise(v),v.success=v.done,v.error=v.fail,v.complete=i.done,v.statusCode=function(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this},d.url=((a||d.url)+"").replace(bC,"").replace(bH,bS[1]+"//"),d.dataTypes=f.trim(d.dataType||"*").toLowerCase().split(bL),d.crossDomain==null&&(r=bN.exec(d.url.toLowerCase()),d.crossDomain=!(!r||r[1]==bS[1]&&r[2]==bS[2]&&(r[3]||(r[1]==="http:"?80:443))==(bS[3]||(bS[1]==="http:"?80:443)))),d.data&&d.processData&&typeof d.data!="string"&&(d.data=f.param(d.data,d.traditional)),bW(bP,d,c,v);if(s===2)return!1;t=d.global,d.type=d.type.toUpperCase(),d.hasContent=!bG.test(d.type),t&&f.active++===0&&f.event.trigger("ajaxStart");if(!d.hasContent){d.data&&(d.url+=(bI.test(d.url)?"&":"?")+d.data,delete d.data),k=d.url;if(d.cache===!1){var x=f.now(),y=d.url.replace(bM,"$1_="+x);d.url=y+(y===d.url?(bI.test(d.url)?"&":"?")+"_="+x:"")}}(d.data&&d.hasContent&&d.contentType!==!1||c.contentType)&&v.setRequestHeader("Content-Type",d.contentType),d.ifModified&&(k=k||d.url,f.lastModified[k]&&v.setRequestHeader("If-Modified-Since",f.lastModified[k]),f.etag[k]&&v.setRequestHeader("If-None-Match",f.etag[k])),v.setRequestHeader("Accept",d.dataTypes[0]&&d.accepts[d.dataTypes[0]]?d.accepts[d.dataTypes[0]]+(d.dataTypes[0]!=="*"?", "+bT+"; q=0.01":""):d.accepts["*"]);for(u in d.headers)v.setRequestHeader(u,d.headers[u]);if(d.beforeSend&&(d.beforeSend.call(e,v,d)===!1||s===2)){v.abort();return!1}for(u in{success:1,error:1,complete:1})v[u](d[u]);p=bW(bQ,d,c,v);if(!p)w(-1,"No Transport");else{v.readyState=1,t&&g.trigger("ajaxSend",[v,d]),d.async&&d.timeout>0&&(q=setTimeout(function(){v.abort("timeout")},d.timeout));try{s=1,p.send(l,w)}catch(z){s<2?w(-1,z):f.error(z)}}return v},param:function(a,c){var d=[],e=function(a,b){b=f.isFunction(b)?b():b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};c===b&&(c=f.ajaxSettings.traditional);if(f.isArray(a)||a.jquery&&!f.isPlainObject(a))f.each(a,function(){e(this.name,this.value)});else for(var g in a)bY(g,a[g],c,e);return d.join("&").replace(bz,"+")}}),f.extend({active:0,lastModified:{},etag:{}});var b_=f.now(),ca=/(\=)\?(&|$)|\?\?/i;f.ajaxSetup({jsonp:"callback",jsonpCallback:function(){return f.expando+"_"+b_++}}),f.ajaxPrefilter("json jsonp",function(b,c,d){var e=b.contentType==="application/x-www-form-urlencoded"&&typeof b.data=="string";if(b.dataTypes[0]==="jsonp"||b.jsonp!==!1&&(ca.test(b.url)||e&&ca.test(b.data))){var g,h=b.jsonpCallback=f.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,i=a[h],j=b.url,k=b.data,l="$1"+h+"$2";b.jsonp!==!1&&(j=j.replace(ca,l),b.url===j&&(e&&(k=k.replace(ca,l)),b.data===k&&(j+=(/\?/.test(j)?"&":"?")+b.jsonp+"="+h))),b.url=j,b.data=k,a[h]=function(a){g=[a]},d.always(function(){a[h]=i,g&&f.isFunction(i)&&a[h](g[0])}),b.converters["script json"]=function(){g||f.error(h+" was not called");return g[0]},b.dataTypes[0]="json";return"script"}}),f.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/javascript|ecmascript/},converters:{"text script":function(a){f.globalEval(a);return a}}}),f.ajaxPrefilter("script",function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),f.ajaxTransport("script",function(a){if(a.crossDomain){var d,e=c.head||c.getElementsByTagName("head")[0]||c.documentElement;return{send:function(f,g){d=c.createElement("script"),d.async="async",a.scriptCharset&&(d.charset=a.scriptCharset),d.src=a.url,d.onload=d.onreadystatechange=function(a,c){if(c||!d.readyState||/loaded|complete/.test(d.readyState))d.onload=d.onreadystatechange=null,e&&d.parentNode&&e.removeChild(d),d=b,c||g(200,"success")},e.insertBefore(d,e.firstChild)},abort:function(){d&&d.onload(0,1)}}}});var cb=a.ActiveXObject?function(){for(var a in cd)cd[a](0,1)}:!1,cc=0,cd;f.ajaxSettings.xhr=a.ActiveXObject?function(){return!this.isLocal&&ce()||cf()}:ce,function(a){f.extend(f.support,{ajax:!!a,cors:!!a&&"withCredentials"in a})}(f.ajaxSettings.xhr()),f.support.ajax&&f.ajaxTransport(function(c){if(!c.crossDomain||f.support.cors){var d;return{send:function(e,g){var h=c.xhr(),i,j;c.username?h.open(c.type,c.url,c.async,c.username,c.password):h.open(c.type,c.url,c.async);if(c.xhrFields)for(j in c.xhrFields)h[j]=c.xhrFields[j];c.mimeType&&h.overrideMimeType&&h.overrideMimeType(c.mimeType),!c.crossDomain&&!e["X-Requested-With"]&&(e["X-Requested-With"]="XMLHttpRequest");try{for(j in e)h.setRequestHeader(j,e[j])}catch(k){}h.send(c.hasContent&&c.data||null),d=function(a,e){var j,k,l,m,n;try{if(d&&(e||h.readyState===4)){d=b,i&&(h.onreadystatechange=f.noop,cb&&delete cd[i]);if(e)h.readyState!==4&&h.abort();else{j=h.status,l=h.getAllResponseHeaders(),m={},n=h.responseXML,n&&n.documentElement&&(m.xml=n),m.text=h.responseText;try{k=h.statusText}catch(o){k=""}!j&&c.isLocal&&!c.crossDomain?j=m.text?200:404:j===1223&&(j=204)}}}catch(p){e||g(-1,p)}m&&g(j,k,m,l)},!c.async||h.readyState===4?d():(i=++cc,cb&&(cd||(cd={},f(a).unload(cb)),cd[i]=d),h.onreadystatechange=d)},abort:function(){d&&d(0,1)}}}});var cg={},ch,ci,cj=/^(?:toggle|show|hide)$/,ck=/^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,cl,cm=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]],cn;f.fn.extend({show:function(a,b,c){var d,e;if(a||a===0)return this.animate(cq("show",3),a,b,c);for(var g=0,h=this.length;g<h;g++)d=this[g],d.style&&(e=d.style.display,!f._data(d,"olddisplay")&&e==="none"&&(e=d.style.display=""),e===""&&f.css(d,"display")==="none"&&f._data(d,"olddisplay",cr(d.nodeName)));for(g=0;g<h;g++){d=this[g];if(d.style){e=d.style.display;if(e===""||e==="none")d.style.display=f._data(d,"olddisplay")||""}}return this},hide:function(a,b,c){if(a||a===0)return this.animate(cq("hide",3),a,b,c);for(var d=0,e=this.length;d<e;d++)if(this[d].style){var g=f.css(this[d],"display");g!=="none"&&!f._data(this[d],"olddisplay")&&f._data(this[d],"olddisplay",g)}for(d=0;d<e;d++)this[d].style&&(this[d].style.display="none");return this},_toggle:f.fn.toggle,toggle:function(a,b,c){var d=typeof a=="boolean";f.isFunction(a)&&f.isFunction(b)?this._toggle.apply(this,arguments):a==null||d?this.each(function(){var b=d?a:f(this).is(":hidden");f(this)[b?"show":"hide"]()}):this.animate(cq("toggle",3),a,b,c);return this},fadeTo:function(a,b,c,d){return this.filter(":hidden").css("opacity",0).show().end().animate({opacity:b},a,c,d)},animate:function(a,b,c,d){var e=f.speed(b,c,d);if(f.isEmptyObject(a))return this.each(e.complete,[!1]);a=f.extend({},a);return this[e.queue===!1?"each":"queue"](function(){e.queue===!1&&f._mark(this);var b=f.extend({},e),c=this.nodeType===1,d=c&&f(this).is(":hidden"),g,h,i,j,k,l,m,n,o;b.animatedProperties={};for(i in a){g=f.camelCase(i),i!==g&&(a[g]=a[i],delete a[i]),h=a[g],f.isArray(h)?(b.animatedProperties[g]=h[1],h=a[g]=h[0]):b.animatedProperties[g]=b.specialEasing&&b.specialEasing[g]||b.easing||"swing";if(h==="hide"&&d||h==="show"&&!d)return b.complete.call(this);c&&(g==="height"||g==="width")&&(b.overflow=[this.style.overflow,this.style.overflowX,this.style.overflowY],f.css(this,"display")==="inline"&&f.css(this,"float")==="none"&&(f.support.inlineBlockNeedsLayout?(j=cr(this.nodeName),j==="inline"?this.style.display="inline-block":(this.style.display="inline",this.style.zoom=1)):this.style.display="inline-block"))}b.overflow!=null&&(this.style.overflow="hidden");for(i in a)k=new f.fx(this,b,i),h=a[i],cj.test(h)?k[h==="toggle"?d?"show":"hide":h]():(l=ck.exec(h),m=k.cur(),l?(n=parseFloat(l[2]),o=l[3]||(f.cssNumber[i]?"":"px"),o!=="px"&&(f.style(this,i,(n||1)+o),m=(n||1)/k.cur()*m,f.style(this,i,m+o)),l[1]&&(n=(l[1]==="-="?-1:1)*n+m),k.custom(m,n,o)):k.custom(m,h,""));return!0})},stop:function(a,b){a&&this.queue([]),this.each(function(){var a=f.timers,c=a.length;b||f._unmark(!0,this);while(c--)a[c].elem===this&&(b&&a[c](!0),a.splice(c,1))}),b||this.dequeue();return this}}),f.each({slideDown:cq("show",1),slideUp:cq("hide",1),slideToggle:cq("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){f.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),f.extend({speed:function(a,b,c){var d=a&&typeof a=="object"?f.extend({},a):{complete:c||!c&&b||f.isFunction(a)&&a,duration:a,easing:c&&b||b&&!f.isFunction(b)&&b};d.duration=f.fx.off?0:typeof d.duration=="number"?d.duration:d.duration in f.fx.speeds?f.fx.speeds[d.duration]:f.fx.speeds._default,d.old=d.complete,d.complete=function(a){f.isFunction(d.old)&&d.old.call(this),d.queue!==!1?f.dequeue(this):a!==!1&&f._unmark(this)};return d},easing:{linear:function(a,b,c,d){return c+d*a},swing:function(a,b,c,d){return(-Math.cos(a*Math.PI)/2+.5)*d+c}},timers:[],fx:function(a,b,c){this.options=b,this.elem=a,this.prop=c,b.orig=b.orig||{}}}),f.fx.prototype={update:function(){this.options.step&&this.options.step.call(this.elem,this.now,this),(f.fx.step[this.prop]||f.fx.step._default)(this)},cur:function(){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null))return this.elem[this.prop];var a,b=f.css(this.elem,this.prop);return isNaN(a=parseFloat(b))?!b||b==="auto"?0:b:a},custom:function(a,b,c){function g(a){return d.step(a)}var d=this,e=f.fx;this.startTime=cn||co(),this.start=a,this.end=b,this.unit=c||this.unit||(f.cssNumber[this.prop]?"":"px"),this.now=this.start,this.pos=this.state=0,g.elem=this.elem,g()&&f.timers.push(g)&&!cl&&(cl=setInterval(e.tick,e.interval))},show:function(){this.options.orig[this.prop]=f.style(this.elem,this.prop),this.options.show=!0,this.custom(this.prop==="width"||this.prop==="height"?1:0,this.cur()),f(this.elem).show()},hide:function(){this.options.orig[this.prop]=f.style(this.elem,this.prop),this.options.hide=!0,this.custom(this.cur(),0)},step:function(a){var b=cn||co(),c=!0,d=this.elem,e=this.options,g,h;if(a||b>=e.duration+this.startTime){this.now=this.end,this.pos=this.state=1,this.update(),e.animatedProperties[this.prop]=!0;for(g in e.animatedProperties)e.animatedProperties[g]!==!0&&(c=!1);if(c){e.overflow!=null&&!f.support.shrinkWrapBlocks&&f.each(["","X","Y"],function(a,b){d.style["overflow"+b]=e.overflow[a]}),e.hide&&f(d).hide();if(e.hide||e.show)for(var i in e.animatedProperties)f.style(d,i,e.orig[i]);e.complete.call(d)}return!1}e.duration==Infinity?this.now=b:(h=b-this.startTime,this.state=h/e.duration,this.pos=f.easing[e.animatedProperties[this.prop]](this.state,h,0,1,e.duration),this.now=this.start+(this.end-this.start)*this.pos),this.update();return!0}},f.extend(f.fx,{tick:function(){for(var a=f.timers,b=0;b<a.length;++b)a[b]()||a.splice(b--,1);a.length||f.fx.stop()},interval:13,stop:function(){clearInterval(cl),cl=null},speeds:{slow:600,fast:200,_default:400},step:{opacity:function(a){f.style(a.elem,"opacity",a.now)},_default:function(a){a.elem.style&&a.elem.style[a.prop]!=null?a.elem.style[a.prop]=(a.prop==="width"||a.prop==="height"?Math.max(0,a.now):a.now)+a.unit:a.elem[a.prop]=a.now}}}),f.expr&&f.expr.filters&&(f.expr.filters.animated=function(a){return f.grep(f.timers,function(b){return a===b.elem}).length});var cs=/^t(?:able|d|h)$/i,ct=/^(?:body|html)$/i;"getBoundingClientRect"in c.documentElement?f.fn.offset=function(a){var b=this[0],c;if(a)return this.each(function(b){f.offset.setOffset(this,a,b)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return f.offset.bodyOffset(b);try{c=b.getBoundingClientRect()}catch(d){}var e=b.ownerDocument,g=e.documentElement;if(!c||!f.contains(g,b))return c?{top:c.top,left:c.left}:{top:0,left:0};var h=e.body,i=cu(e),j=g.clientTop||h.clientTop||0,k=g.clientLeft||h.clientLeft||0,l=i.pageYOffset||f.support.boxModel&&g.scrollTop||h.scrollTop,m=i.pageXOffset||f.support.boxModel&&g.scrollLeft||h.scrollLeft,n=c.top+l-j,o=c.left+m-k;return{top:n,left:o}}:f.fn.offset=function(a){var b=this[0];if(a)return this.each(function(b){f.offset.setOffset(this,a,b)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return f.offset.bodyOffset(b);f.offset.initialize();var c,d=b.offsetParent,e=b,g=b.ownerDocument,h=g.documentElement,i=g.body,j=g.defaultView,k=j?j.getComputedStyle(b,null):b.currentStyle,l=b.offsetTop,m=b.offsetLeft;while((b=b.parentNode)&&b!==i&&b!==h){if(f.offset.supportsFixedPosition&&k.position==="fixed")break;c=j?j.getComputedStyle(b,null):b.currentStyle,l-=b.scrollTop,m-=b.scrollLeft,b===d&&(l+=b.offsetTop,m+=b.offsetLeft,f.offset.doesNotAddBorder&&(!f.offset.doesAddBorderForTableAndCells||!cs.test(b.nodeName))&&(l+=parseFloat(c.borderTopWidth)||0,m+=parseFloat(c.borderLeftWidth)||0),e=d,d=b.offsetParent),f.offset.subtractsBorderForOverflowNotVisible&&c.overflow!=="visible"&&(l+=parseFloat(c.borderTopWidth)||0,m+=parseFloat(c.borderLeftWidth)||0),k=c}if(k.position==="relative"||k.position==="static")l+=i.offsetTop,m+=i.offsetLeft;f.offset.supportsFixedPosition&&k.position==="fixed"&&(l+=Math.max(h.scrollTop,i.scrollTop),m+=Math.max(h.scrollLeft,i.scrollLeft));return{top:l,left:m}},f.offset={initialize:function(){var a=c.body,b=c.createElement("div"),d,e,g,h,i=parseFloat(f.css(a,"marginTop"))||0,j="<div style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;'><div></div></div><table style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;' cellpadding='0' cellspacing='0'><tr><td></td></tr></table>";f.extend(b.style,{position:"absolute",top:0,left:0,margin:0,border:0,width:"1px",height:"1px",visibility:"hidden"}),b.innerHTML=j,a.insertBefore(b,a.firstChild),d=b.firstChild,e=d.firstChild,h=d.nextSibling.firstChild.firstChild,this.doesNotAddBorder=e.offsetTop!==5,this.doesAddBorderForTableAndCells=h.offsetTop===5,e.style.position="fixed",e.style.top="20px",this.supportsFixedPosition=e.offsetTop===20||e.offsetTop===15,e.style.position=e.style.top="",d.style.overflow="hidden",d.style.position="relative",this.subtractsBorderForOverflowNotVisible=e.offsetTop===-5,this.doesNotIncludeMarginInBodyOffset=a.offsetTop!==i,a.removeChild(b),f.offset.initialize=f.noop},bodyOffset:function(a){var b=a.offsetTop,c=a.offsetLeft;f.offset.initialize(),f.offset.doesNotIncludeMarginInBodyOffset&&(b+=parseFloat(f.css(a,"marginTop"))||0,c+=parseFloat(f.css(a,"marginLeft"))||0);return{top:b,left:c}},setOffset:function(a,b,c){var d=f.css(a,"position");d==="static"&&(a.style.position="relative");var e=f(a),g=e.offset(),h=f.css(a,"top"),i=f.css(a,"left"),j=(d==="absolute"||d==="fixed")&&f.inArray("auto",[h,i])>-1,k={},l={},m,n;j?(l=e.position(),m=l.top,n=l.left):(m=parseFloat(h)||0,n=parseFloat(i)||0),f.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),"using"in b?b.using.call(a,k):e.css(k)}},f.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),d=ct.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(f.css(a,"marginTop"))||0,c.left-=parseFloat(f.css(a,"marginLeft"))||0,d.top+=parseFloat(f.css(b[0],"borderTopWidth"))||0,d.left+=parseFloat(f.css(b[0],"borderLeftWidth"))||0;return{top:c.top-d.top,left:c.left-d.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&!ct.test(a.nodeName)&&f.css(a,"position")==="static")a=a.offsetParent;return a})}}),f.each(["Left","Top"],function(a,c){var d="scroll"+c;f.fn[d]=function(c){var e,g;if(c===b){e=this[0];if(!e)return null;g=cu(e);return g?"pageXOffset"in g?g[a?"pageYOffset":"pageXOffset"]:f.support.boxModel&&g.document.documentElement[d]||g.document.body[d]:e[d]}return this.each(function(){g=cu(this),g?g.scrollTo(a?f(g).scrollLeft():c,a?c:f(g).scrollTop()):this[d]=c})}}),f.each(["Height","Width"],function(a,c){var d=c.toLowerCase();f.fn["inner"+c]=function(){var a=this[0];return a&&a.style?parseFloat(f.css(a,d,"padding")):null},f.fn["outer"+c]=function(a){var b=this[0];return b&&b.style?parseFloat(f.css(b,d,a?"margin":"border")):null},f.fn[d]=function(a){var e=this[0];if(!e)return a==null?null:this;if(f.isFunction(a))return this.each(function(b){var c=f(this);c[d](a.call(this,b,c[d]()))});if(f.isWindow(e)){var g=e.document.documentElement["client"+c],h=e.document.body;return e.document.compatMode==="CSS1Compat"&&g||h&&h["client"+c]||g}if(e.nodeType===9)return Math.max(e.documentElement["client"+c],e.body["scroll"+c],e.documentElement["scroll"+c],e.body["offset"+c],e.documentElement["offset"+c]);if(a===b){var i=f.css(e,d),j=parseFloat(i);return f.isNaN(j)?i:j}return this.css(d,typeof a=="string"?a:a+"px")}}),a.jQuery=a.$=f})(window);
|
includes/min/builder/ocCheck.php
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* AJAX checks for zlib.output_compression
|
4 |
+
*
|
5 |
+
* @package Minify
|
6 |
+
*/
|
7 |
+
|
8 |
+
$_oc = ini_get('zlib.output_compression');
|
9 |
+
|
10 |
+
// allow access only if builder is enabled
|
11 |
+
require dirname(__FILE__) . '/../config.php';
|
12 |
+
if (! $min_enableBuilder) {
|
13 |
+
header('Location: /');
|
14 |
+
exit();
|
15 |
+
}
|
16 |
+
|
17 |
+
if (isset($_GET['hello'])) {
|
18 |
+
// echo 'World!'
|
19 |
+
|
20 |
+
// try to prevent double encoding (may not have an effect)
|
21 |
+
ini_set('zlib.output_compression', '0');
|
22 |
+
|
23 |
+
require $min_libPath . '/HTTP/Encoder.php';
|
24 |
+
HTTP_Encoder::$encodeToIe6 = true; // just in case
|
25 |
+
$he = new HTTP_Encoder(array(
|
26 |
+
'content' => 'World!'
|
27 |
+
,'method' => 'deflate'
|
28 |
+
));
|
29 |
+
$he->encode();
|
30 |
+
$he->sendAll();
|
31 |
+
|
32 |
+
} else {
|
33 |
+
// echo status "0" or "1"
|
34 |
+
header('Content-Type: text/plain');
|
35 |
+
echo (int)$_oc;
|
36 |
+
}
|
includes/min/builder/rewriteTest.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
1
|
includes/min/builder/test.php
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
exit();
|
3 |
+
/* currently unused.
|
4 |
+
|
5 |
+
// capture PHP's default setting (may get overridden in config
|
6 |
+
$_oc = ini_get('zlib.output_compression');
|
7 |
+
|
8 |
+
// allow access only if builder is enabled
|
9 |
+
require dirname(__FILE__) . '/../config.php';
|
10 |
+
if (! $min_enableBuilder) {
|
11 |
+
exit();
|
12 |
+
}
|
13 |
+
|
14 |
+
if (isset($_GET['oc'])) {
|
15 |
+
header('Content-Type: text/plain');
|
16 |
+
echo (int)$_oc;
|
17 |
+
|
18 |
+
} elseif (isset($_GET['text']) && in_array($_GET['text'], array('js', 'css', 'fake'))) {
|
19 |
+
ini_set('zlib.output_compression', '0');
|
20 |
+
$type = ($_GET['text'] == 'js')
|
21 |
+
? 'application/x-javascript'
|
22 |
+
: "text/{$_GET['text']}";
|
23 |
+
header("Content-Type: {$type}");
|
24 |
+
echo 'Hello';
|
25 |
+
|
26 |
+
} elseif (isset($_GET['docroot'])) {
|
27 |
+
if (false === realpath($_SERVER['DOCUMENT_ROOT'])) {
|
28 |
+
echo "<p class=topWarning><strong>realpath(DOCUMENT_ROOT) failed.</strong> You may need "
|
29 |
+
. "to set \$min_documentRoot manually (hopefully realpath() is not "
|
30 |
+
. "broken in your environment).</p>";
|
31 |
+
}
|
32 |
+
if (0 !== strpos(realpath(__FILE__), realpath($_SERVER['DOCUMENT_ROOT']))) {
|
33 |
+
echo "<p class=topWarning><strong>DOCUMENT_ROOT doesn't contain this file.</strong> You may "
|
34 |
+
. " need to set \$min_documentRoot manually</p>";
|
35 |
+
}
|
36 |
+
if (isset($_SERVER['SUBDOMAIN_DOCUMENT_ROOT'])) {
|
37 |
+
echo "<p class=topNote><strong>\$_SERVER['SUBDOMAIN_DOCUMENT_ROOT'] is set.</strong> "
|
38 |
+
. "You may need to set \$min_documentRoot to this in config.php</p>";
|
39 |
+
}
|
40 |
+
|
41 |
+
}
|
42 |
+
|
43 |
+
//*/
|
includes/min/config-test.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Additional configuration applied when the variable "test" is added to the querystring.
|
4 |
+
*
|
5 |
+
* To test config options, place them in this file and add "&test" to your Minify URL.
|
6 |
+
* Note that if this is on a public server, anyone can execute your test.
|
7 |
+
*
|
8 |
+
* @package Minify
|
9 |
+
*/
|
10 |
+
|
includes/min/config.php
ADDED
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Configuration for "min", the default application built with the Minify
|
4 |
+
* library
|
5 |
+
*
|
6 |
+
* @package Minify
|
7 |
+
*/
|
8 |
+
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Allow use of the Minify URI Builder app. Only set this to true while you need it.
|
12 |
+
*/
|
13 |
+
$min_enableBuilder = false;
|
14 |
+
|
15 |
+
/**
|
16 |
+
* If non-empty, the Builder will be protected with HTTP Digest auth.
|
17 |
+
* The username is "admin".
|
18 |
+
*/
|
19 |
+
$min_builderPassword = 'admin';
|
20 |
+
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Set to true to log messages to FirePHP (Firefox Firebug addon).
|
24 |
+
* Set to false for no error logging (Minify may be slightly faster).
|
25 |
+
* @link http://www.firephp.org/
|
26 |
+
*
|
27 |
+
* If you want to use a custom error logger, set this to your logger
|
28 |
+
* instance. Your object should have a method log(string $message).
|
29 |
+
*/
|
30 |
+
$min_errorLogger = false;
|
31 |
+
|
32 |
+
|
33 |
+
/**
|
34 |
+
* To allow debug mode output, you must set this option to true.
|
35 |
+
*
|
36 |
+
* Once true, you can send the cookie minDebug to request debug mode output. The
|
37 |
+
* cookie value should match the URIs you'd like to debug. E.g. to debug
|
38 |
+
* /min/f=file1.js send the cookie minDebug=file1.js
|
39 |
+
* You can manually enable debugging by appending "&debug" to a URI.
|
40 |
+
* E.g. /min/?f=script1.js,script2.js&debug
|
41 |
+
*
|
42 |
+
* In 'debug' mode, Minify combines files with no minification and adds comments
|
43 |
+
* to indicate line #s of the original files.
|
44 |
+
*/
|
45 |
+
$min_allowDebugFlag = false;
|
46 |
+
|
47 |
+
|
48 |
+
/**
|
49 |
+
* For best performance, specify your temp directory here. Otherwise Minify
|
50 |
+
* will have to load extra code to guess. Some examples below:
|
51 |
+
*/
|
52 |
+
//$min_cachePath = 'c:\\WINDOWS\\Temp';
|
53 |
+
//$min_cachePath = '/tmp';
|
54 |
+
//$min_cachePath = preg_replace('/^\\d+;/', '', session_save_path());
|
55 |
+
/**
|
56 |
+
* To use APC/Memcache/ZendPlatform for cache storage, require the class and
|
57 |
+
* set $min_cachePath to an instance. Example below:
|
58 |
+
*/
|
59 |
+
//require dirname(__FILE__) . '/lib/Minify/Cache/APC.php';
|
60 |
+
//$min_cachePath = new Minify_Cache_APC();
|
61 |
+
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Leave an empty string to use PHP's $_SERVER['DOCUMENT_ROOT'].
|
65 |
+
*
|
66 |
+
* On some servers, this value may be misconfigured or missing. If so, set this
|
67 |
+
* to your full document root path with no trailing slash.
|
68 |
+
* E.g. '/home/accountname/public_html' or 'c:\\xampp\\htdocs'
|
69 |
+
*
|
70 |
+
* If /min/ is directly inside your document root, just uncomment the
|
71 |
+
* second line. The third line might work on some Apache servers.
|
72 |
+
*/
|
73 |
+
$min_documentRoot = '';
|
74 |
+
//$min_documentRoot = substr(__FILE__, 0, -15);
|
75 |
+
//$min_documentRoot = $_SERVER['SUBDOMAIN_DOCUMENT_ROOT'];
|
76 |
+
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Cache file locking. Set to false if filesystem is NFS. On at least one
|
80 |
+
* NFS system flock-ing attempts stalled PHP for 30 seconds!
|
81 |
+
*/
|
82 |
+
$min_cacheFileLocking = true;
|
83 |
+
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Combining multiple CSS files can place @import declarations after rules, which
|
87 |
+
* is invalid. Minify will attempt to detect when this happens and place a
|
88 |
+
* warning comment at the top of the CSS output. To resolve this you can either
|
89 |
+
* move the @imports within your CSS files, or enable this option, which will
|
90 |
+
* move all @imports to the top of the output. Note that moving @imports could
|
91 |
+
* affect CSS values (which is why this option is disabled by default).
|
92 |
+
*/
|
93 |
+
$min_serveOptions['bubbleCssImports'] = false;
|
94 |
+
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Cache-Control: max-age value sent to browser (in seconds). After this period,
|
98 |
+
* the browser will send another conditional GET. Use a longer period for lower
|
99 |
+
* traffic but you may want to shorten this before making changes if it's crucial
|
100 |
+
* those changes are seen immediately.
|
101 |
+
*
|
102 |
+
* Note: Despite this setting, if you include a number at the end of the
|
103 |
+
* querystring, maxAge will be set to one year. E.g. /min/f=hello.css&123456
|
104 |
+
*/
|
105 |
+
$min_serveOptions['maxAge'] = 1800;
|
106 |
+
|
107 |
+
|
108 |
+
/**
|
109 |
+
* To use Google's Closure Compiler API to minify Javascript (falling back to JSMin
|
110 |
+
* on failure), uncomment the following line:
|
111 |
+
*/
|
112 |
+
//$min_serveOptions['minifiers']['application/x-javascript'] = array('Minify_JS_ClosureCompiler', 'minify');
|
113 |
+
|
114 |
+
|
115 |
+
/**
|
116 |
+
* If you'd like to restrict the "f" option to files within/below
|
117 |
+
* particular directories below DOCUMENT_ROOT, set this here.
|
118 |
+
* You will still need to include the directory in the
|
119 |
+
* f or b GET parameters.
|
120 |
+
*
|
121 |
+
* // = shortcut for DOCUMENT_ROOT
|
122 |
+
*/
|
123 |
+
//$min_serveOptions['minApp']['allowDirs'] = array('//js', '//css');
|
124 |
+
|
125 |
+
/**
|
126 |
+
* Set to true to disable the "f" GET parameter for specifying files.
|
127 |
+
* Only the "g" parameter will be considered.
|
128 |
+
*/
|
129 |
+
$min_serveOptions['minApp']['groupsOnly'] = false;
|
130 |
+
|
131 |
+
|
132 |
+
/**
|
133 |
+
* By default, Minify will not minify files with names containing .min or -min
|
134 |
+
* before the extension. E.g. myFile.min.js will not be processed by JSMin
|
135 |
+
*
|
136 |
+
* To minify all files, set this option to null. You could also specify your
|
137 |
+
* own pattern that is matched against the filename.
|
138 |
+
*/
|
139 |
+
//$min_serveOptions['minApp']['noMinPattern'] = '@[-\\.]min\\.(?:js|css)$@i';
|
140 |
+
|
141 |
+
|
142 |
+
/**
|
143 |
+
* If you minify CSS files stored in symlink-ed directories, the URI rewriting
|
144 |
+
* algorithm can fail. To prevent this, provide an array of link paths to
|
145 |
+
* target paths, where the link paths are within the document root.
|
146 |
+
*
|
147 |
+
* Because paths need to be normalized for this to work, use "//" to substitute
|
148 |
+
* the doc root in the link paths (the array keys). E.g.:
|
149 |
+
* <code>
|
150 |
+
* array('//symlink' => '/real/target/path') // unix
|
151 |
+
* array('//static' => 'D:\\staticStorage') // Windows
|
152 |
+
* </code>
|
153 |
+
*/
|
154 |
+
$min_symlinks = array();
|
155 |
+
|
156 |
+
|
157 |
+
/**
|
158 |
+
* If you upload files from Windows to a non-Windows server, Windows may report
|
159 |
+
* incorrect mtimes for the files. This may cause Minify to keep serving stale
|
160 |
+
* cache files when source file changes are made too frequently (e.g. more than
|
161 |
+
* once an hour).
|
162 |
+
*
|
163 |
+
* Immediately after modifying and uploading a file, use the touch command to
|
164 |
+
* update the mtime on the server. If the mtime jumps ahead by a number of hours,
|
165 |
+
* set this variable to that number. If the mtime moves back, this should not be
|
166 |
+
* needed.
|
167 |
+
*
|
168 |
+
* In the Windows SFTP client WinSCP, there's an option that may fix this
|
169 |
+
* issue without changing the variable below. Under login > environment,
|
170 |
+
* select the option "Adjust remote timestamp with DST".
|
171 |
+
* @link http://winscp.net/eng/docs/ui_login_environment#daylight_saving_time
|
172 |
+
*/
|
173 |
+
$min_uploaderHoursBehind = 0;
|
174 |
+
|
175 |
+
|
176 |
+
/**
|
177 |
+
* Path to Minify's lib folder. If you happen to move it, change
|
178 |
+
* this accordingly.
|
179 |
+
*/
|
180 |
+
$min_libPath = dirname(__FILE__) . '/lib';
|
181 |
+
|
182 |
+
|
183 |
+
// try to disable output_compression (may not have an effect)
|
184 |
+
ini_set('zlib.output_compression', '0');
|
includes/min/groupsConfig.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Groups configuration for default Minify implementation
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* You may wish to use the Minify URI Builder app to suggest
|
9 |
+
* changes. http://yourdomain/min/builder/
|
10 |
+
*
|
11 |
+
* See http://code.google.com/p/minify/wiki/CustomSource for other ideas
|
12 |
+
**/
|
13 |
+
|
14 |
+
return array(
|
15 |
+
// 'js' => array('//js/file1.js', '//js/file2.js'),
|
16 |
+
// 'css' => array('//css/file1.css', '//css/file2.css'),
|
17 |
+
);
|
includes/min/index.php
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Front controller for default Minify implementation
|
4 |
+
*
|
5 |
+
* DO NOT EDIT! Configure this utility via config.php and groupsConfig.php
|
6 |
+
*
|
7 |
+
* @package Minify
|
8 |
+
*/
|
9 |
+
|
10 |
+
define('MINIFY_MIN_DIR', dirname(__FILE__));
|
11 |
+
|
12 |
+
// load config
|
13 |
+
require MINIFY_MIN_DIR . '/config.php';
|
14 |
+
|
15 |
+
if (isset($_GET['test'])) {
|
16 |
+
include MINIFY_MIN_DIR . '/config-test.php';
|
17 |
+
}
|
18 |
+
|
19 |
+
require "$min_libPath/Minify/Loader.php";
|
20 |
+
Minify_Loader::register();
|
21 |
+
|
22 |
+
Minify::$uploaderHoursBehind = $min_uploaderHoursBehind;
|
23 |
+
Minify::setCache(
|
24 |
+
isset($min_cachePath) ? $min_cachePath : ''
|
25 |
+
,$min_cacheFileLocking
|
26 |
+
);
|
27 |
+
|
28 |
+
if ($min_documentRoot) {
|
29 |
+
$_SERVER['DOCUMENT_ROOT'] = $min_documentRoot;
|
30 |
+
Minify::$isDocRootSet = true;
|
31 |
+
}
|
32 |
+
|
33 |
+
$min_serveOptions['minifierOptions']['text/css']['symlinks'] = $min_symlinks;
|
34 |
+
// auto-add targets to allowDirs
|
35 |
+
foreach ($min_symlinks as $uri => $target) {
|
36 |
+
$min_serveOptions['minApp']['allowDirs'][] = $target;
|
37 |
+
}
|
38 |
+
|
39 |
+
if ($min_allowDebugFlag) {
|
40 |
+
$min_serveOptions['debug'] = Minify_DebugDetector::shouldDebugRequest($_COOKIE, $_GET, $_SERVER['REQUEST_URI']);
|
41 |
+
}
|
42 |
+
|
43 |
+
if ($min_errorLogger) {
|
44 |
+
if (true === $min_errorLogger) {
|
45 |
+
$min_errorLogger = FirePHP::getInstance(true);
|
46 |
+
}
|
47 |
+
Minify_Logger::setLogger($min_errorLogger);
|
48 |
+
}
|
49 |
+
|
50 |
+
// check for URI versioning
|
51 |
+
if (preg_match('/&\\d/', $_SERVER['QUERY_STRING'])) {
|
52 |
+
$min_serveOptions['maxAge'] = 31536000;
|
53 |
+
}
|
54 |
+
if (isset($_GET['g'])) {
|
55 |
+
// well need groups config
|
56 |
+
$min_serveOptions['minApp']['groups'] = (require MINIFY_MIN_DIR . '/groupsConfig.php');
|
57 |
+
}
|
58 |
+
if (isset($_GET['f']) || isset($_GET['g'])) {
|
59 |
+
// serve!
|
60 |
+
|
61 |
+
if (! isset($min_serveController)) {
|
62 |
+
$min_serveController = new Minify_Controller_MinApp();
|
63 |
+
}
|
64 |
+
Minify::serve($min_serveController, $min_serveOptions);
|
65 |
+
|
66 |
+
} elseif ($min_enableBuilder) {
|
67 |
+
header('Location: builder/');
|
68 |
+
exit();
|
69 |
+
} else {
|
70 |
+
header("Location: /");
|
71 |
+
exit();
|
72 |
+
}
|
includes/min/lib/CSSmin.php
ADDED
@@ -0,0 +1,758 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*!
|
4 |
+
* cssmin.php rev ebaf67b 12/06/2013
|
5 |
+
* Author: Tubal Martin - http://tubalmartin.me/
|
6 |
+
* Repo: https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port
|
7 |
+
*
|
8 |
+
* This is a PHP port of the CSS minification tool distributed with YUICompressor,
|
9 |
+
* itself a port of the cssmin utility by Isaac Schlueter - http://foohack.com/
|
10 |
+
* Permission is hereby granted to use the PHP version under the same
|
11 |
+
* conditions as the YUICompressor.
|
12 |
+
*/
|
13 |
+
|
14 |
+
/*!
|
15 |
+
* YUI Compressor
|
16 |
+
* http://developer.yahoo.com/yui/compressor/
|
17 |
+
* Author: Julien Lecomte - http://www.julienlecomte.net/
|
18 |
+
* Copyright (c) 2013 Yahoo! Inc. All rights reserved.
|
19 |
+
* The copyrights embodied in the content of this file are licensed
|
20 |
+
* by Yahoo! Inc. under the BSD (revised) open source license.
|
21 |
+
*/
|
22 |
+
|
23 |
+
class CSSmin
|
24 |
+
{
|
25 |
+
const NL = '___YUICSSMIN_PRESERVED_NL___';
|
26 |
+
const TOKEN = '___YUICSSMIN_PRESERVED_TOKEN_';
|
27 |
+
const COMMENT = '___YUICSSMIN_PRESERVE_CANDIDATE_COMMENT_';
|
28 |
+
const CLASSCOLON = '___YUICSSMIN_PSEUDOCLASSCOLON___';
|
29 |
+
const QUERY_FRACTION = '___YUICSSMIN_QUERY_FRACTION___';
|
30 |
+
|
31 |
+
private $comments;
|
32 |
+
private $preserved_tokens;
|
33 |
+
private $memory_limit;
|
34 |
+
private $max_execution_time;
|
35 |
+
private $pcre_backtrack_limit;
|
36 |
+
private $pcre_recursion_limit;
|
37 |
+
private $raise_php_limits;
|
38 |
+
|
39 |
+
/**
|
40 |
+
* @param bool|int $raise_php_limits
|
41 |
+
* If true, PHP settings will be raised if needed
|
42 |
+
*/
|
43 |
+
public function __construct($raise_php_limits = TRUE)
|
44 |
+
{
|
45 |
+
// Set suggested PHP limits
|
46 |
+
$this->memory_limit = 128 * 1048576; // 128MB in bytes
|
47 |
+
$this->max_execution_time = 60; // 1 min
|
48 |
+
$this->pcre_backtrack_limit = 1000 * 1000;
|
49 |
+
$this->pcre_recursion_limit = 500 * 1000;
|
50 |
+
|
51 |
+
$this->raise_php_limits = (bool) $raise_php_limits;
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Minify a string of CSS
|
56 |
+
* @param string $css
|
57 |
+
* @param int|bool $linebreak_pos
|
58 |
+
* @return string
|
59 |
+
*/
|
60 |
+
public function run($css = '', $linebreak_pos = FALSE)
|
61 |
+
{
|
62 |
+
if (empty($css)) {
|
63 |
+
return '';
|
64 |
+
}
|
65 |
+
|
66 |
+
if ($this->raise_php_limits) {
|
67 |
+
$this->do_raise_php_limits();
|
68 |
+
}
|
69 |
+
|
70 |
+
$this->comments = array();
|
71 |
+
$this->preserved_tokens = array();
|
72 |
+
|
73 |
+
$start_index = 0;
|
74 |
+
$length = strlen($css);
|
75 |
+
|
76 |
+
$css = $this->extract_data_urls($css);
|
77 |
+
|
78 |
+
// collect all comment blocks...
|
79 |
+
while (($start_index = $this->index_of($css, '/*', $start_index)) >= 0) {
|
80 |
+
$end_index = $this->index_of($css, '*/', $start_index + 2);
|
81 |
+
if ($end_index < 0) {
|
82 |
+
$end_index = $length;
|
83 |
+
}
|
84 |
+
$comment_found = $this->str_slice($css, $start_index + 2, $end_index);
|
85 |
+
$this->comments[] = $comment_found;
|
86 |
+
$comment_preserve_string = self::COMMENT . (count($this->comments) - 1) . '___';
|
87 |
+
$css = $this->str_slice($css, 0, $start_index + 2) . $comment_preserve_string . $this->str_slice($css, $end_index);
|
88 |
+
// Set correct start_index: Fixes issue #2528130
|
89 |
+
$start_index = $end_index + 2 + strlen($comment_preserve_string) - strlen($comment_found);
|
90 |
+
}
|
91 |
+
|
92 |
+
// preserve strings so their content doesn't get accidentally minified
|
93 |
+
$css = preg_replace_callback('/(?:"(?:[^\\\\"]|\\\\.|\\\\)*")|'."(?:'(?:[^\\\\']|\\\\.|\\\\)*')/S", array($this, 'replace_string'), $css);
|
94 |
+
|
95 |
+
// Let's divide css code in chunks of 25.000 chars aprox.
|
96 |
+
// Reason: PHP's PCRE functions like preg_replace have a "backtrack limit"
|
97 |
+
// of 100.000 chars by default (php < 5.3.7) so if we're dealing with really
|
98 |
+
// long strings and a (sub)pattern matches a number of chars greater than
|
99 |
+
// the backtrack limit number (i.e. /(.*)/s) PCRE functions may fail silently
|
100 |
+
// returning NULL and $css would be empty.
|
101 |
+
$charset = '';
|
102 |
+
$charset_regexp = '/(@charset)( [^;]+;)/i';
|
103 |
+
$css_chunks = array();
|
104 |
+
$css_chunk_length = 25000; // aprox size, not exact
|
105 |
+
$start_index = 0;
|
106 |
+
$i = $css_chunk_length; // save initial iterations
|
107 |
+
$l = strlen($css);
|
108 |
+
|
109 |
+
|
110 |
+
// if the number of characters is 25000 or less, do not chunk
|
111 |
+
if ($l <= $css_chunk_length) {
|
112 |
+
$css_chunks[] = $css;
|
113 |
+
} else {
|
114 |
+
// chunk css code securely
|
115 |
+
while ($i < $l) {
|
116 |
+
$i += 50; // save iterations. 500 checks for a closing curly brace }
|
117 |
+
if ($l - $start_index <= $css_chunk_length || $i >= $l) {
|
118 |
+
$css_chunks[] = $this->str_slice($css, $start_index);
|
119 |
+
break;
|
120 |
+
}
|
121 |
+
if ($css[$i - 1] === '}' && $i - $start_index > $css_chunk_length) {
|
122 |
+
// If there are two ending curly braces }} separated or not by spaces,
|
123 |
+
// join them in the same chunk (i.e. @media blocks)
|
124 |
+
$next_chunk = substr($css, $i);
|
125 |
+
if (preg_match('/^\s*\}/', $next_chunk)) {
|
126 |
+
$i = $i + $this->index_of($next_chunk, '}') + 1;
|
127 |
+
}
|
128 |
+
|
129 |
+
$css_chunks[] = $this->str_slice($css, $start_index, $i);
|
130 |
+
$start_index = $i;
|
131 |
+
}
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
// Minify each chunk
|
136 |
+
for ($i = 0, $n = count($css_chunks); $i < $n; $i++) {
|
137 |
+
$css_chunks[$i] = $this->minify($css_chunks[$i], $linebreak_pos);
|
138 |
+
// Keep the first @charset at-rule found
|
139 |
+
if (empty($charset) && preg_match($charset_regexp, $css_chunks[$i], $matches)) {
|
140 |
+
$charset = strtolower($matches[1]) . $matches[2];
|
141 |
+
}
|
142 |
+
// Delete all @charset at-rules
|
143 |
+
$css_chunks[$i] = preg_replace($charset_regexp, '', $css_chunks[$i]);
|
144 |
+
}
|
145 |
+
|
146 |
+
// Update the first chunk and push the charset to the top of the file.
|
147 |
+
$css_chunks[0] = $charset . $css_chunks[0];
|
148 |
+
|
149 |
+
return implode('', $css_chunks);
|
150 |
+
}
|
151 |
+
|
152 |
+
/**
|
153 |
+
* Sets the memory limit for this script
|
154 |
+
* @param int|string $limit
|
155 |
+
*/
|
156 |
+
public function set_memory_limit($limit)
|
157 |
+
{
|
158 |
+
$this->memory_limit = $this->normalize_int($limit);
|
159 |
+
}
|
160 |
+
|
161 |
+
/**
|
162 |
+
* Sets the maximum execution time for this script
|
163 |
+
* @param int|string $seconds
|
164 |
+
*/
|
165 |
+
public function set_max_execution_time($seconds)
|
166 |
+
{
|
167 |
+
$this->max_execution_time = (int) $seconds;
|
168 |
+
}
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Sets the PCRE backtrack limit for this script
|
172 |
+
* @param int $limit
|
173 |
+
*/
|
174 |
+
public function set_pcre_backtrack_limit($limit)
|
175 |
+
{
|
176 |
+
$this->pcre_backtrack_limit = (int) $limit;
|
177 |
+
}
|
178 |
+
|
179 |
+
/**
|
180 |
+
* Sets the PCRE recursion limit for this script
|
181 |
+
* @param int $limit
|
182 |
+
*/
|
183 |
+
public function set_pcre_recursion_limit($limit)
|
184 |
+
{
|
185 |
+
$this->pcre_recursion_limit = (int) $limit;
|
186 |
+
}
|
187 |
+
|
188 |
+
/**
|
189 |
+
* Try to configure PHP to use at least the suggested minimum settings
|
190 |
+
*/
|
191 |
+
private function do_raise_php_limits()
|
192 |
+
{
|
193 |
+
$php_limits = array(
|
194 |
+
'memory_limit' => $this->memory_limit,
|
195 |
+
'max_execution_time' => $this->max_execution_time,
|
196 |
+
'pcre.backtrack_limit' => $this->pcre_backtrack_limit,
|
197 |
+
'pcre.recursion_limit' => $this->pcre_recursion_limit
|
198 |
+
);
|
199 |
+
|
200 |
+
// If current settings are higher respect them.
|
201 |
+
foreach ($php_limits as $name => $suggested) {
|
202 |
+
$current = $this->normalize_int(ini_get($name));
|
203 |
+
// memory_limit exception: allow -1 for "no memory limit".
|
204 |
+
if ($current > -1 && ($suggested == -1 || $current < $suggested)) {
|
205 |
+
ini_set($name, $suggested);
|
206 |
+
}
|
207 |
+
}
|
208 |
+
}
|
209 |
+
|
210 |
+
/**
|
211 |
+
* Does bulk of the minification
|
212 |
+
* @param string $css
|
213 |
+
* @param int|bool $linebreak_pos
|
214 |
+
* @return string
|
215 |
+
*/
|
216 |
+
private function minify($css, $linebreak_pos)
|
217 |
+
{
|
218 |
+
// strings are safe, now wrestle the comments
|
219 |
+
for ($i = 0, $max = count($this->comments); $i < $max; $i++) {
|
220 |
+
|
221 |
+
$token = $this->comments[$i];
|
222 |
+
$placeholder = '/' . self::COMMENT . $i . '___/';
|
223 |
+
|
224 |
+
// ! in the first position of the comment means preserve
|
225 |
+
// so push to the preserved tokens keeping the !
|
226 |
+
if (substr($token, 0, 1) === '!') {
|
227 |
+
$this->preserved_tokens[] = $token;
|
228 |
+
$token_tring = self::TOKEN . (count($this->preserved_tokens) - 1) . '___';
|
229 |
+
$css = preg_replace($placeholder, $token_tring, $css, 1);
|
230 |
+
// Preserve new lines for /*! important comments
|
231 |
+
$css = preg_replace('/\s*[\n\r\f]+\s*(\/\*'. $token_tring .')/S', self::NL.'$1', $css);
|
232 |
+
$css = preg_replace('/('. $token_tring .'\*\/)\s*[\n\r\f]+\s*/', '$1'.self::NL, $css);
|
233 |
+
continue;
|
234 |
+
}
|
235 |
+
|
236 |
+
// \ in the last position looks like hack for Mac/IE5
|
237 |
+
// shorten that to /*\*/ and the next one to /**/
|
238 |
+
if (substr($token, (strlen($token) - 1), 1) === '\\') {
|
239 |
+
$this->preserved_tokens[] = '\\';
|
240 |
+
$css = preg_replace($placeholder, self::TOKEN . (count($this->preserved_tokens) - 1) . '___', $css, 1);
|
241 |
+
$i = $i + 1; // attn: advancing the loop
|
242 |
+
$this->preserved_tokens[] = '';
|
243 |
+
$css = preg_replace('/' . self::COMMENT . $i . '___/', self::TOKEN . (count($this->preserved_tokens) - 1) . '___', $css, 1);
|
244 |
+
continue;
|
245 |
+
}
|
246 |
+
|
247 |
+
// keep empty comments after child selectors (IE7 hack)
|
248 |
+
// e.g. html >/**/ body
|
249 |
+
if (strlen($token) === 0) {
|
250 |
+
$start_index = $this->index_of($css, $this->str_slice($placeholder, 1, -1));
|
251 |
+
if ($start_index > 2) {
|
252 |
+
if (substr($css, $start_index - 3, 1) === '>') {
|
253 |
+
$this->preserved_tokens[] = '';
|
254 |
+
$css = preg_replace($placeholder, self::TOKEN . (count($this->preserved_tokens) - 1) . '___', $css, 1);
|
255 |
+
}
|
256 |
+
}
|
257 |
+
}
|
258 |
+
|
259 |
+
// in all other cases kill the comment
|
260 |
+
$css = preg_replace('/\/\*' . $this->str_slice($placeholder, 1, -1) . '\*\//', '', $css, 1);
|
261 |
+
}
|
262 |
+
|
263 |
+
|
264 |
+
// Normalize all whitespace strings to single spaces. Easier to work with that way.
|
265 |
+
$css = preg_replace('/\s+/', ' ', $css);
|
266 |
+
|
267 |
+
// Shorten & preserve calculations calc(...) since spaces are important
|
268 |
+
$css = preg_replace_callback('/calc(\(((?:[^\(\)]+|(?1))*)\))/i', array($this, 'replace_calc'), $css);
|
269 |
+
|
270 |
+
// Replace positive sign from numbers preceded by : or a white-space before the leading space is removed
|
271 |
+
// +1.2em to 1.2em, +.8px to .8px, +2% to 2%
|
272 |
+
$css = preg_replace('/((?<!\\\\)\:|\s)\+(\.?\d+)/S', '$1$2', $css);
|
273 |
+
|
274 |
+
// Remove leading zeros from integer and float numbers preceded by : or a white-space
|
275 |
+
// 000.6 to .6, -0.8 to -.8, 0050 to 50, -01.05 to -1.05
|
276 |
+
$css = preg_replace('/((?<!\\\\)\:|\s)(\-?)0+(\.?\d+)/S', '$1$2$3', $css);
|
277 |
+
|
278 |
+
// Remove trailing zeros from float numbers preceded by : or a white-space
|
279 |
+
// -6.0100em to -6.01em, .0100 to .01, 1.200px to 1.2px
|
280 |
+
$css = preg_replace('/((?<!\\\\)\:|\s)(\-?)(\d?\.\d+?)0+([^\d])/S', '$1$2$3$4', $css);
|
281 |
+
|
282 |
+
// Remove trailing .0 -> -9.0 to -9
|
283 |
+
$css = preg_replace('/((?<!\\\\)\:|\s)(\-?\d+)\.0([^\d])/S', '$1$2$3', $css);
|
284 |
+
|
285 |
+
// Replace 0 length numbers with 0
|
286 |
+
$css = preg_replace('/((?<!\\\\)\:|\s)\-?\.?0+([^\d])/S', '${1}0$2', $css);
|
287 |
+
|
288 |
+
// Remove the spaces before the things that should not have spaces before them.
|
289 |
+
// But, be careful not to turn "p :link {...}" into "p:link{...}"
|
290 |
+
// Swap out any pseudo-class colons with the token, and then swap back.
|
291 |
+
$css = preg_replace_callback('/(?:^|\})(?:(?:[^\{\:])+\:)+(?:[^\{]*\{)/', array($this, 'replace_colon'), $css);
|
292 |
+
|
293 |
+
// Remove spaces before the things that should not have spaces before them.
|
294 |
+
$css = preg_replace('/\s+([\!\{\}\;\:\>\+\(\)\]\~\=,])/', '$1', $css);
|
295 |
+
|
296 |
+
// Restore spaces for !important
|
297 |
+
$css = preg_replace('/\!important/i', ' !important', $css);
|
298 |
+
|
299 |
+
// bring back the colon
|
300 |
+
$css = preg_replace('/' . self::CLASSCOLON . '/', ':', $css);
|
301 |
+
|
302 |
+
// retain space for special IE6 cases
|
303 |
+
$css = preg_replace_callback('/\:first\-(line|letter)(\{|,)/i', array($this, 'lowercase_pseudo_first'), $css);
|
304 |
+
|
305 |
+
// no space after the end of a preserved comment
|
306 |
+
$css = preg_replace('/\*\/ /', '*/', $css);
|
307 |
+
|
308 |
+
// lowercase some popular @directives
|
309 |
+
$css = preg_replace_callback('/@(font-face|import|(?:-(?:atsc|khtml|moz|ms|o|wap|webkit)-)?keyframe|media|page|namespace)/i', array($this, 'lowercase_directives'), $css);
|
310 |
+
|
311 |
+
// lowercase some more common pseudo-elements
|
312 |
+
$css = preg_replace_callback('/:(active|after|before|checked|disabled|empty|enabled|first-(?:child|of-type)|focus|hover|last-(?:child|of-type)|link|only-(?:child|of-type)|root|:selection|target|visited)/i', array($this, 'lowercase_pseudo_elements'), $css);
|
313 |
+
|
314 |
+
// lowercase some more common functions
|
315 |
+
$css = preg_replace_callback('/:(lang|not|nth-child|nth-last-child|nth-last-of-type|nth-of-type|(?:-(?:moz|webkit)-)?any)\(/i', array($this, 'lowercase_common_functions'), $css);
|
316 |
+
|
317 |
+
// lower case some common function that can be values
|
318 |
+
// NOTE: rgb() isn't useful as we replace with #hex later, as well as and() is already done for us
|
319 |
+
$css = preg_replace_callback('/([:,\( ]\s*)(attr|color-stop|from|rgba|to|url|(?:-(?:atsc|khtml|moz|ms|o|wap|webkit)-)?(?:calc|max|min|(?:repeating-)?(?:linear|radial)-gradient)|-webkit-gradient)/iS', array($this, 'lowercase_common_functions_values'), $css);
|
320 |
+
|
321 |
+
// Put the space back in some cases, to support stuff like
|
322 |
+
// @media screen and (-webkit-min-device-pixel-ratio:0){
|
323 |
+
$css = preg_replace('/\band\(/i', 'and (', $css);
|
324 |
+
|
325 |
+
// Remove the spaces after the things that should not have spaces after them.
|
326 |
+
$css = preg_replace('/([\!\{\}\:;\>\+\(\[\~\=,])\s+/S', '$1', $css);
|
327 |
+
|
328 |
+
// remove unnecessary semicolons
|
329 |
+
$css = preg_replace('/;+\}/', '}', $css);
|
330 |
+
|
331 |
+
// Fix for issue: #2528146
|
332 |
+
// Restore semicolon if the last property is prefixed with a `*` (lte IE7 hack)
|
333 |
+
// to avoid issues on Symbian S60 3.x browsers.
|
334 |
+
$css = preg_replace('/(\*[a-z0-9\-]+\s*\:[^;\}]+)(\})/', '$1;$2', $css);
|
335 |
+
|
336 |
+
// Replace 0 length units 0(px,em,%) with 0.
|
337 |
+
$css = preg_replace('/(^|[^0-9])(?:0?\.)?0(?:em|ex|ch|rem|vw|vh|vm|vmin|cm|mm|in|px|pt|pc|%|deg|g?rad|m?s|k?hz)/iS', '${1}0', $css);
|
338 |
+
|
339 |
+
// Replace 0 0; or 0 0 0; or 0 0 0 0; with 0.
|
340 |
+
$css = preg_replace('/\:0(?: 0){1,3}(;|\}| \!)/', ':0$1', $css);
|
341 |
+
|
342 |
+
// Fix for issue: #2528142
|
343 |
+
// Replace text-shadow:0; with text-shadow:0 0 0;
|
344 |
+
$css = preg_replace('/(text-shadow\:0)(;|\}| \!)/i', '$1 0 0$2', $css);
|
345 |
+
|
346 |
+
// Replace background-position:0; with background-position:0 0;
|
347 |
+
// same for transform-origin
|
348 |
+
// Changing -webkit-mask-position: 0 0 to just a single 0 will result in the second parameter defaulting to 50% (center)
|
349 |
+
$css = preg_replace('/(background\-position|webkit-mask-position|(?:webkit|moz|o|ms|)\-?transform\-origin)\:0(;|\}| \!)/iS', '$1:0 0$2', $css);
|
350 |
+
|
351 |
+
// Shorten colors from rgb(51,102,153) to #336699, rgb(100%,0%,0%) to #ff0000 (sRGB color space)
|
352 |
+
// Shorten colors from hsl(0, 100%, 50%) to #ff0000 (sRGB color space)
|
353 |
+
// This makes it more likely that it'll get further compressed in the next step.
|
354 |
+
$css = preg_replace_callback('/rgb\s*\(\s*([0-9,\s\-\.\%]+)\s*\)(.{1})/i', array($this, 'rgb_to_hex'), $css);
|
355 |
+
$css = preg_replace_callback('/hsl\s*\(\s*([0-9,\s\-\.\%]+)\s*\)(.{1})/i', array($this, 'hsl_to_hex'), $css);
|
356 |
+
|
357 |
+
// Shorten colors from #AABBCC to #ABC or short color name.
|
358 |
+
$css = $this->compress_hex_colors($css);
|
359 |
+
|
360 |
+
// border: none to border:0, outline: none to outline:0
|
361 |
+
$css = preg_replace('/(border\-?(?:top|right|bottom|left|)|outline)\:none(;|\}| \!)/iS', '$1:0$2', $css);
|
362 |
+
|
363 |
+
// shorter opacity IE filter
|
364 |
+
$css = preg_replace('/progid\:DXImageTransform\.Microsoft\.Alpha\(Opacity\=/i', 'alpha(opacity=', $css);
|
365 |
+
|
366 |
+
// Find a fraction that is used for Opera's -o-device-pixel-ratio query
|
367 |
+
// Add token to add the "\" back in later
|
368 |
+
$css = preg_replace('/\(([a-z\-]+):([0-9]+)\/([0-9]+)\)/i', '($1:$2'. self::QUERY_FRACTION .'$3)', $css);
|
369 |
+
|
370 |
+
// Remove empty rules.
|
371 |
+
$css = preg_replace('/[^\};\{\/]+\{\}/S', '', $css);
|
372 |
+
|
373 |
+
// Add "/" back to fix Opera -o-device-pixel-ratio query
|
374 |
+
$css = preg_replace('/'. self::QUERY_FRACTION .'/', '/', $css);
|
375 |
+
|
376 |
+
// Some source control tools don't like it when files containing lines longer
|
377 |
+
// than, say 8000 characters, are checked in. The linebreak option is used in
|
378 |
+
// that case to split long lines after a specific column.
|
379 |
+
if ($linebreak_pos !== FALSE && (int) $linebreak_pos >= 0) {
|
380 |
+
$linebreak_pos = (int) $linebreak_pos;
|
381 |
+
$start_index = $i = 0;
|
382 |
+
while ($i < strlen($css)) {
|
383 |
+
$i++;
|
384 |
+
if ($css[$i - 1] === '}' && $i - $start_index > $linebreak_pos) {
|
385 |
+
$css = $this->str_slice($css, 0, $i) . "\n" . $this->str_slice($css, $i);
|
386 |
+
$start_index = $i;
|
387 |
+
}
|
388 |
+
}
|
389 |
+
}
|
390 |
+
|
391 |
+
// Replace multiple semi-colons in a row by a single one
|
392 |
+
// See SF bug #1980989
|
393 |
+
$css = preg_replace('/;;+/', ';', $css);
|
394 |
+
|
395 |
+
// Restore new lines for /*! important comments
|
396 |
+
$css = preg_replace('/'. self::NL .'/', "\n", $css);
|
397 |
+
|
398 |
+
// Lowercase all uppercase properties
|
399 |
+
$css = preg_replace_callback('/(\{|\;)([A-Z\-]+)(\:)/', array($this, 'lowercase_properties'), $css);
|
400 |
+
|
401 |
+
// restore preserved comments and strings
|
402 |
+
for ($i = 0, $max = count($this->preserved_tokens); $i < $max; $i++) {
|
403 |
+
$css = preg_replace('/' . self::TOKEN . $i . '___/', $this->preserved_tokens[$i], $css, 1);
|
404 |
+
}
|
405 |
+
|
406 |
+
// Trim the final string (for any leading or trailing white spaces)
|
407 |
+
return trim($css);
|
408 |
+
}
|
409 |
+
|
410 |
+
/**
|
411 |
+
* Utility method to replace all data urls with tokens before we start
|
412 |
+
* compressing, to avoid performance issues running some of the subsequent
|
413 |
+
* regexes against large strings chunks.
|
414 |
+
*
|
415 |
+
* @param string $css
|
416 |
+
* @return string
|
417 |
+
*/
|
418 |
+
private function extract_data_urls($css)
|
419 |
+
{
|
420 |
+
// Leave data urls alone to increase parse performance.
|
421 |
+
$max_index = strlen($css) - 1;
|
422 |
+
$append_index = $index = $last_index = $offset = 0;
|
423 |
+
$sb = array();
|
424 |
+
$pattern = '/url\(\s*(["\']?)data\:/i';
|
425 |
+
|
426 |
+
// Since we need to account for non-base64 data urls, we need to handle
|
427 |
+
// ' and ) being part of the data string. Hence switching to indexOf,
|
428 |
+
// to determine whether or not we have matching string terminators and
|
429 |
+
// handling sb appends directly, instead of using matcher.append* methods.
|
430 |
+
|
431 |
+
while (preg_match($pattern, $css, $m, 0, $offset)) {
|
432 |
+
$index = $this->index_of($css, $m[0], $offset);
|
433 |
+
$last_index = $index + strlen($m[0]);
|
434 |
+
$start_index = $index + 4; // "url(".length()
|
435 |
+
$end_index = $last_index - 1;
|
436 |
+
$terminator = $m[1]; // ', " or empty (not quoted)
|
437 |
+
$found_terminator = FALSE;
|
438 |
+
|
439 |
+
if (strlen($terminator) === 0) {
|
440 |
+
$terminator = ')';
|
441 |
+
}
|
442 |
+
|
443 |
+
while ($found_terminator === FALSE && $end_index+1 <= $max_index) {
|
444 |
+
$end_index = $this->index_of($css, $terminator, $end_index + 1);
|
445 |
+
|
446 |
+
// endIndex == 0 doesn't really apply here
|
447 |
+
if ($end_index > 0 && substr($css, $end_index - 1, 1) !== '\\') {
|
448 |
+
$found_terminator = TRUE;
|
449 |
+
if (')' != $terminator) {
|
450 |
+
$end_index = $this->index_of($css, ')', $end_index);
|
451 |
+
}
|
452 |
+
}
|
453 |
+
}
|
454 |
+
|
455 |
+
// Enough searching, start moving stuff over to the buffer
|
456 |
+
$sb[] = $this->str_slice($css, $append_index, $index);
|
457 |
+
|
458 |
+
if ($found_terminator) {
|
459 |
+
$token = $this->str_slice($css, $start_index, $end_index);
|
460 |
+
$token = preg_replace('/\s+/', '', $token);
|
461 |
+
$this->preserved_tokens[] = $token;
|
462 |
+
|
463 |
+
$preserver = 'url(' . self::TOKEN . (count($this->preserved_tokens) - 1) . '___)';
|
464 |
+
$sb[] = $preserver;
|
465 |
+
|
466 |
+
$append_index = $end_index + 1;
|
467 |
+
} else {
|
468 |
+
// No end terminator found, re-add the whole match. Should we throw/warn here?
|
469 |
+
$sb[] = $this->str_slice($css, $index, $last_index);
|
470 |
+
$append_index = $last_index;
|
471 |
+
}
|
472 |
+
|
473 |
+
$offset = $last_index;
|
474 |
+
}
|
475 |
+
|
476 |
+
$sb[] = $this->str_slice($css, $append_index);
|
477 |
+
|
478 |
+
return implode('', $sb);
|
479 |
+
}
|
480 |
+
|
481 |
+
/**
|
482 |
+
* Utility method to compress hex color values of the form #AABBCC to #ABC or short color name.
|
483 |
+
*
|
484 |
+
* DOES NOT compress CSS ID selectors which match the above pattern (which would break things).
|
485 |
+
* e.g. #AddressForm { ... }
|
486 |
+
*
|
487 |
+
* DOES NOT compress IE filters, which have hex color values (which would break things).
|
488 |
+
* e.g. filter: chroma(color="#FFFFFF");
|
489 |
+
*
|
490 |
+
* DOES NOT compress invalid hex values.
|
491 |
+
* e.g. background-color: #aabbccdd
|
492 |
+
*
|
493 |
+
* @param string $css
|
494 |
+
* @return string
|
495 |
+
*/
|
496 |
+
private function compress_hex_colors($css)
|
497 |
+
{
|
498 |
+
// Look for hex colors inside { ... } (to avoid IDs) and which don't have a =, or a " in front of them (to avoid filters)
|
499 |
+
$pattern = '/(\=\s*?["\']?)?#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])(\}|[^0-9a-f{][^{]*?\})/iS';
|
500 |
+
$_index = $index = $last_index = $offset = 0;
|
501 |
+
$sb = array();
|
502 |
+
// See: http://ajaxmin.codeplex.com/wikipage?title=CSS%20Colors
|
503 |
+
$short_safe = array(
|
504 |
+
'#808080' => 'gray',
|
505 |
+
'#008000' => 'green',
|
506 |
+
'#800000' => 'maroon',
|
507 |
+
'#000080' => 'navy',
|
508 |
+
'#808000' => 'olive',
|
509 |
+
'#ffa500' => 'orange',
|
510 |
+
'#800080' => 'purple',
|
511 |
+
'#c0c0c0' => 'silver',
|
512 |
+
'#008080' => 'teal',
|
513 |
+
'#f00' => 'red'
|
514 |
+
);
|
515 |
+
|
516 |
+
while (preg_match($pattern, $css, $m, 0, $offset)) {
|
517 |
+
$index = $this->index_of($css, $m[0], $offset);
|
518 |
+
$last_index = $index + strlen($m[0]);
|
519 |
+
$is_filter = $m[1] !== null && $m[1] !== '';
|
520 |
+
|
521 |
+
$sb[] = $this->str_slice($css, $_index, $index);
|
522 |
+
|
523 |
+
if ($is_filter) {
|
524 |
+
// Restore, maintain case, otherwise filter will break
|
525 |
+
$sb[] = $m[1] . '#' . $m[2] . $m[3] . $m[4] . $m[5] . $m[6] . $m[7];
|
526 |
+
} else {
|
527 |
+
if (strtolower($m[2]) == strtolower($m[3]) &&
|
528 |
+
strtolower($m[4]) == strtolower($m[5]) &&
|
529 |
+
strtolower($m[6]) == strtolower($m[7])) {
|
530 |
+
// Compress.
|
531 |
+
$hex = '#' . strtolower($m[3] . $m[5] . $m[7]);
|
532 |
+
} else {
|
533 |
+
// Non compressible color, restore but lower case.
|
534 |
+
$hex = '#' . strtolower($m[2] . $m[3] . $m[4] . $m[5] . $m[6] . $m[7]);
|
535 |
+
}
|
536 |
+
// replace Hex colors to short safe color names
|
537 |
+
$sb[] = array_key_exists($hex, $short_safe) ? $short_safe[$hex] : $hex;
|
538 |
+
}
|
539 |
+
|
540 |
+
$_index = $offset = $last_index - strlen($m[8]);
|
541 |
+
}
|
542 |
+
|
543 |
+
$sb[] = $this->str_slice($css, $_index);
|
544 |
+
|
545 |
+
return implode('', $sb);
|
546 |
+
}
|
547 |
+
|
548 |
+
/* CALLBACKS
|
549 |
+
* ---------------------------------------------------------------------------------------------
|
550 |
+
*/
|
551 |
+
|
552 |
+
private function replace_string($matches)
|
553 |
+
{
|
554 |
+
$match = $matches[0];
|
555 |
+
$quote = substr($match, 0, 1);
|
556 |
+
// Must use addcslashes in PHP to avoid parsing of backslashes
|
557 |
+
$match = addcslashes($this->str_slice($match, 1, -1), '\\');
|
558 |
+
|
559 |
+
// maybe the string contains a comment-like substring?
|
560 |
+
// one, maybe more? put'em back then
|
561 |
+
if (($pos = $this->index_of($match, self::COMMENT)) >= 0) {
|
562 |
+
for ($i = 0, $max = count($this->comments); $i < $max; $i++) {
|
563 |
+
$match = preg_replace('/' . self::COMMENT . $i . '___/', $this->comments[$i], $match, 1);
|
564 |
+
}
|
565 |
+
}
|
566 |
+
|
567 |
+
// minify alpha opacity in filter strings
|
568 |
+
$match = preg_replace('/progid\:DXImageTransform\.Microsoft\.Alpha\(Opacity\=/i', 'alpha(opacity=', $match);
|
569 |
+
|
570 |
+
$this->preserved_tokens[] = $match;
|
571 |
+
return $quote . self::TOKEN . (count($this->preserved_tokens) - 1) . '___' . $quote;
|
572 |
+
}
|
573 |
+
|
574 |
+
private function replace_colon($matches)
|
575 |
+
{
|
576 |
+
return preg_replace('/\:/', self::CLASSCOLON, $matches[0]);
|
577 |
+
}
|
578 |
+
|
579 |
+
private function replace_calc($matches)
|
580 |
+
{
|
581 |
+
$this->preserved_tokens[] = trim(preg_replace('/\s*([\*\/\(\),])\s*/', '$1', $matches[2]));
|
582 |
+
return 'calc('. self::TOKEN . (count($this->preserved_tokens) - 1) . '___' . ')';
|
583 |
+
}
|
584 |
+
|
585 |
+
private function rgb_to_hex($matches)
|
586 |
+
{
|
587 |
+
// Support for percentage values rgb(100%, 0%, 45%);
|
588 |
+
if ($this->index_of($matches[1], '%') >= 0){
|
589 |
+
$rgbcolors = explode(',', str_replace('%', '', $matches[1]));
|
590 |
+
for ($i = 0; $i < count($rgbcolors); $i++) {
|
591 |
+
$rgbcolors[$i] = $this->round_number(floatval($rgbcolors[$i]) * 2.55);
|
592 |
+
}
|
593 |
+
} else {
|
594 |
+
$rgbcolors = explode(',', $matches[1]);
|
595 |
+
}
|
596 |
+
|
597 |
+
// Values outside the sRGB color space should be clipped (0-255)
|
598 |
+
for ($i = 0; $i < count($rgbcolors); $i++) {
|
599 |
+
$rgbcolors[$i] = $this->clamp_number(intval($rgbcolors[$i], 10), 0, 255);
|
600 |
+
$rgbcolors[$i] = sprintf("%02x", $rgbcolors[$i]);
|
601 |
+
}
|
602 |
+
|
603 |
+
// Fix for issue #2528093
|
604 |
+
if (!preg_match('/[\s\,\);\}]/', $matches[2])){
|
605 |
+
$matches[2] = ' ' . $matches[2];
|
606 |
+
}
|
607 |
+
|
608 |
+
return '#' . implode('', $rgbcolors) . $matches[2];
|
609 |
+
}
|
610 |
+
|
611 |
+
private function hsl_to_hex($matches)
|
612 |
+
{
|
613 |
+
$values = explode(',', str_replace('%', '', $matches[1]));
|
614 |
+
$h = floatval($values[0]);
|
615 |
+
$s = floatval($values[1]);
|
616 |
+
$l = floatval($values[2]);
|
617 |
+
|
618 |
+
// Wrap and clamp, then fraction!
|
619 |
+
$h = ((($h % 360) + 360) % 360) / 360;
|
620 |
+
$s = $this->clamp_number($s, 0, 100) / 100;
|
621 |
+
$l = $this->clamp_number($l, 0, 100) / 100;
|
622 |
+
|
623 |
+
if ($s == 0) {
|
624 |
+
$r = $g = $b = $this->round_number(255 * $l);
|
625 |
+
} else {
|
626 |
+
$v2 = $l < 0.5 ? $l * (1 + $s) : ($l + $s) - ($s * $l);
|
627 |
+
$v1 = (2 * $l) - $v2;
|
628 |
+
$r = $this->round_number(255 * $this->hue_to_rgb($v1, $v2, $h + (1/3)));
|
629 |
+
$g = $this->round_number(255 * $this->hue_to_rgb($v1, $v2, $h));
|
630 |
+
$b = $this->round_number(255 * $this->hue_to_rgb($v1, $v2, $h - (1/3)));
|
631 |
+
}
|
632 |
+
|
633 |
+
return $this->rgb_to_hex(array('', $r.','.$g.','.$b, $matches[2]));
|
634 |
+
}
|
635 |
+
|
636 |
+
private function lowercase_pseudo_first($matches)
|
637 |
+
{
|
638 |
+
return ':first-'. strtolower($matches[1]) .' '. $matches[2];
|
639 |
+
}
|
640 |
+
|
641 |
+
private function lowercase_directives($matches)
|
642 |
+
{
|
643 |
+
return '@'. strtolower($matches[1]);
|
644 |
+
}
|
645 |
+
|
646 |
+
private function lowercase_pseudo_elements($matches)
|
647 |
+
{
|
648 |
+
return ':'. strtolower($matches[1]);
|
649 |
+
}
|
650 |
+
|
651 |
+
private function lowercase_common_functions($matches)
|
652 |
+
{
|
653 |
+
return ':'. strtolower($matches[1]) .'(';
|
654 |
+
}
|
655 |
+
|
656 |
+
private function lowercase_common_functions_values($matches)
|
657 |
+
{
|
658 |
+
return $matches[1] . strtolower($matches[2]);
|
659 |
+
}
|
660 |
+
|
661 |
+
private function lowercase_properties($matches)
|
662 |
+
{
|
663 |
+
return $matches[1].strtolower($matches[2]).$matches[3];
|
664 |
+
}
|
665 |
+
|
666 |
+
/* HELPERS
|
667 |
+
* ---------------------------------------------------------------------------------------------
|
668 |
+
*/
|
669 |
+
|
670 |
+
private function hue_to_rgb($v1, $v2, $vh)
|
671 |
+
{
|
672 |
+
$vh = $vh < 0 ? $vh + 1 : ($vh > 1 ? $vh - 1 : $vh);
|
673 |
+
if ($vh * 6 < 1) return $v1 + ($v2 - $v1) * 6 * $vh;
|
674 |
+
if ($vh * 2 < 1) return $v2;
|
675 |
+
if ($vh * 3 < 2) return $v1 + ($v2 - $v1) * ((2/3) - $vh) * 6;
|
676 |
+
return $v1;
|
677 |
+
}
|
678 |
+
|
679 |
+
private function round_number($n)
|
680 |
+
{
|
681 |
+
return intval(floor(floatval($n) + 0.5), 10);
|
682 |
+
}
|
683 |
+
|
684 |
+
private function clamp_number($n, $min, $max)
|
685 |
+
{
|
686 |
+
return min(max($n, $min), $max);
|
687 |
+
}
|
688 |
+
|
689 |
+
/**
|
690 |
+
* PHP port of Javascript's "indexOf" function for strings only
|
691 |
+
* Author: Tubal Martin http://blog.margenn.com
|
692 |
+
*
|
693 |
+
* @param string $haystack
|
694 |
+
* @param string $needle
|
695 |
+
* @param int $offset index (optional)
|
696 |
+
* @return int
|
697 |
+
*/
|
698 |
+
private function index_of($haystack, $needle, $offset = 0)
|
699 |
+
{
|
700 |
+
$index = strpos($haystack, $needle, $offset);
|
701 |
+
|
702 |
+
return ($index !== FALSE) ? $index : -1;
|
703 |
+
}
|
704 |
+
|
705 |
+
/**
|
706 |
+
* PHP port of Javascript's "slice" function for strings only
|
707 |
+
* Author: Tubal Martin http://blog.margenn.com
|
708 |
+
* Tests: http://margenn.com/tubal/str_slice/
|
709 |
+
*
|
710 |
+
* @param string $str
|
711 |
+
* @param int $start index
|
712 |
+
* @param int|bool $end index (optional)
|
713 |
+
* @return string
|
714 |
+
*/
|
715 |
+
private function str_slice($str, $start = 0, $end = FALSE)
|
716 |
+
{
|
717 |
+
if ($end !== FALSE && ($start < 0 || $end <= 0)) {
|
718 |
+
$max = strlen($str);
|
719 |
+
|
720 |
+
if ($start < 0) {
|
721 |
+
if (($start = $max + $start) < 0) {
|
722 |
+
return '';
|
723 |
+
}
|
724 |
+
}
|
725 |
+
|
726 |
+
if ($end < 0) {
|
727 |
+
if (($end = $max + $end) < 0) {
|
728 |
+
return '';
|
729 |
+
}
|
730 |
+
}
|
731 |
+
|
732 |
+
if ($end <= $start) {
|
733 |
+
return '';
|
734 |
+
}
|
735 |
+
}
|
736 |
+
|
737 |
+
$slice = ($end === FALSE) ? substr($str, $start) : substr($str, $start, $end - $start);
|
738 |
+
return ($slice === FALSE) ? '' : $slice;
|
739 |
+
}
|
740 |
+
|
741 |
+
/**
|
742 |
+
* Convert strings like "64M" or "30" to int values
|
743 |
+
* @param mixed $size
|
744 |
+
* @return int
|
745 |
+
*/
|
746 |
+
private function normalize_int($size)
|
747 |
+
{
|
748 |
+
if (is_string($size)) {
|
749 |
+
switch (substr($size, -1)) {
|
750 |
+
case 'M': case 'm': return $size * 1048576;
|
751 |
+
case 'K': case 'k': return $size * 1024;
|
752 |
+
case 'G': case 'g': return $size * 1073741824;
|
753 |
+
}
|
754 |
+
}
|
755 |
+
|
756 |
+
return (int) $size;
|
757 |
+
}
|
758 |
+
}
|
includes/min/lib/DooDigestAuth.php
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* DooDigestAuth class file.
|
4 |
+
*
|
5 |
+
* @author Leng Sheng Hong <darkredz@gmail.com>
|
6 |
+
* @link http://www.doophp.com/
|
7 |
+
* @copyright Copyright © 2009 Leng Sheng Hong
|
8 |
+
* @license http://www.doophp.com/license
|
9 |
+
*/
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Handles HTTP digest authentication
|
13 |
+
*
|
14 |
+
* <p>HTTP digest authentication can be used with the URI router.
|
15 |
+
* HTTP digest is much more recommended over the use of HTTP Basic auth which doesn't provide any encryption.
|
16 |
+
* If you are running PHP on Apache in CGI/FastCGI mode, you would need to
|
17 |
+
* add the following line to your .htaccess for digest auth to work correctly.</p>
|
18 |
+
* <code>RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]</code>
|
19 |
+
*
|
20 |
+
* <p>This class is tested under Apache 2.2 and Cherokee web server. It should work in both mod_php and cgi mode.</p>
|
21 |
+
*
|
22 |
+
* @author Leng Sheng Hong <darkredz@gmail.com>
|
23 |
+
* @version $Id: DooDigestAuth.php 1000 2009-07-7 18:27:22
|
24 |
+
* @package doo.auth
|
25 |
+
* @since 1.0
|
26 |
+
*/
|
27 |
+
class DooDigestAuth{
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Authenticate against a list of username and passwords.
|
31 |
+
*
|
32 |
+
* <p>HTTP Digest Authentication doesn't work with PHP in CGI mode,
|
33 |
+
* you have to add this into your .htaccess <code>RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]</code></p>
|
34 |
+
*
|
35 |
+
* @param string $realm Name of the authentication session
|
36 |
+
* @param array $users An assoc array of username and password: array('uname1'=>'pwd1', 'uname2'=>'pwd2')
|
37 |
+
* @param string $fail_msg Message to be displayed if the User cancel the login
|
38 |
+
* @param string $fail_url URL to be redirect if the User cancel the login
|
39 |
+
* @return string The username if login success.
|
40 |
+
*/
|
41 |
+
public static function http_auth($realm, $users, $fail_msg=NULL, $fail_url=NULL){
|
42 |
+
$realm = "Restricted area - $realm";
|
43 |
+
|
44 |
+
//user => password
|
45 |
+
//$users = array('admin' => '1234', 'guest' => 'guest');
|
46 |
+
if(!empty($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && strpos($_SERVER['REDIRECT_HTTP_AUTHORIZATION'], 'Digest')===0){
|
47 |
+
$_SERVER['PHP_AUTH_DIGEST'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
|
48 |
+
}
|
49 |
+
|
50 |
+
if (empty($_SERVER['PHP_AUTH_DIGEST'])) {
|
51 |
+
header('WWW-Authenticate: Digest realm="'.$realm.
|
52 |
+
'",qop="auth",nonce="'.uniqid().'",opaque="'.md5($realm).'"');
|
53 |
+
header('HTTP/1.1 401 Unauthorized');
|
54 |
+
if($fail_msg!=NULL)
|
55 |
+
die($fail_msg);
|
56 |
+
if($fail_url!=NULL)
|
57 |
+
die("<script>window.location.href = '$fail_url'</script>");
|
58 |
+
exit;
|
59 |
+
}
|
60 |
+
|
61 |
+
// analyze the PHP_AUTH_DIGEST variable
|
62 |
+
if (!($data = self::http_digest_parse($_SERVER['PHP_AUTH_DIGEST'])) || !isset($users[$data['username']])){
|
63 |
+
header('WWW-Authenticate: Digest realm="'.$realm.
|
64 |
+
'",qop="auth",nonce="'.uniqid().'",opaque="'.md5($realm).'"');
|
65 |
+
header('HTTP/1.1 401 Unauthorized');
|
66 |
+
if($fail_msg!=NULL)
|
67 |
+
die($fail_msg);
|
68 |
+
if($fail_url!=NULL)
|
69 |
+
die("<script>window.location.href = '$fail_url'</script>");
|
70 |
+
exit;
|
71 |
+
}
|
72 |
+
|
73 |
+
// generate the valid response
|
74 |
+
$A1 = md5($data['username'] . ':' . $realm . ':' . $users[$data['username']]);
|
75 |
+
$A2 = md5($_SERVER['REQUEST_METHOD'].':'.$data['uri']);
|
76 |
+
$valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2);
|
77 |
+
|
78 |
+
if ($data['response'] != $valid_response){
|
79 |
+
header('HTTP/1.1 401 Unauthorized');
|
80 |
+
header('WWW-Authenticate: Digest realm="'.$realm.
|
81 |
+
'",qop="auth",nonce="'.uniqid().'",opaque="'.md5($realm).'"');
|
82 |
+
if($fail_msg!=NULL)
|
83 |
+
die($fail_msg);
|
84 |
+
if($fail_url!=NULL)
|
85 |
+
die("<script>window.location.href = '$fail_url'</script>");
|
86 |
+
exit;
|
87 |
+
}
|
88 |
+
|
89 |
+
// ok, valid username & password
|
90 |
+
return $data['username'];
|
91 |
+
}
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Method to parse the http auth header, works with IE.
|
95 |
+
*
|
96 |
+
* Internet Explorer returns a qop="xxxxxxxxxxx" in the header instead of qop=xxxxxxxxxxx as most browsers do.
|
97 |
+
*
|
98 |
+
* @param string $txt header string to parse
|
99 |
+
* @return array An assoc array of the digest auth session
|
100 |
+
*/
|
101 |
+
private static function http_digest_parse($txt)
|
102 |
+
{
|
103 |
+
$res = preg_match("/username=\"([^\"]+)\"/i", $txt, $match);
|
104 |
+
$data['username'] = (isset($match[1]))?$match[1]:null;
|
105 |
+
$res = preg_match('/nonce=\"([^\"]+)\"/i', $txt, $match);
|
106 |
+
$data['nonce'] = $match[1];
|
107 |
+
$res = preg_match('/nc=([0-9]+)/i', $txt, $match);
|
108 |
+
$data['nc'] = $match[1];
|
109 |
+
$res = preg_match('/cnonce=\"([^\"]+)\"/i', $txt, $match);
|
110 |
+
$data['cnonce'] = $match[1];
|
111 |
+
$res = preg_match('/qop=([^,]+)/i', $txt, $match);
|
112 |
+
$data['qop'] = str_replace('"','',$match[1]);
|
113 |
+
$res = preg_match('/uri=\"([^\"]+)\"/i', $txt, $match);
|
114 |
+
$data['uri'] = $match[1];
|
115 |
+
$res = preg_match('/response=\"([^\"]+)\"/i', $txt, $match);
|
116 |
+
$data['response'] = $match[1];
|
117 |
+
return $data;
|
118 |
+
}
|
119 |
+
|
120 |
+
|
121 |
+
}
|
includes/min/lib/FirePHP.php
ADDED
@@ -0,0 +1,1370 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* *** BEGIN LICENSE BLOCK *****
|
4 |
+
*
|
5 |
+
* This file is part of FirePHP (http://www.firephp.org/).
|
6 |
+
*
|
7 |
+
* Software License Agreement (New BSD License)
|
8 |
+
*
|
9 |
+
* Copyright (c) 2006-2008, Christoph Dorn
|
10 |
+
* All rights reserved.
|
11 |
+
*
|
12 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
13 |
+
* are permitted provided that the following conditions are met:
|
14 |
+
*
|
15 |
+
* * Redistributions of source code must retain the above copyright notice,
|
16 |
+
* this list of conditions and the following disclaimer.
|
17 |
+
*
|
18 |
+
* * Redistributions in binary form must reproduce the above copyright notice,
|
19 |
+
* this list of conditions and the following disclaimer in the documentation
|
20 |
+
* and/or other materials provided with the distribution.
|
21 |
+
*
|
22 |
+
* * Neither the name of Christoph Dorn nor the names of its
|
23 |
+
* contributors may be used to endorse or promote products derived from this
|
24 |
+
* software without specific prior written permission.
|
25 |
+
*
|
26 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
27 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
28 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
29 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
30 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
31 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
32 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
33 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
34 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
35 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
36 |
+
*
|
37 |
+
* ***** END LICENSE BLOCK *****
|
38 |
+
*
|
39 |
+
* @copyright Copyright (C) 2007-2008 Christoph Dorn
|
40 |
+
* @author Christoph Dorn <christoph@christophdorn.com>
|
41 |
+
* @license http://www.opensource.org/licenses/bsd-license.php
|
42 |
+
* @package FirePHP
|
43 |
+
*/
|
44 |
+
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Sends the given data to the FirePHP Firefox Extension.
|
48 |
+
* The data can be displayed in the Firebug Console or in the
|
49 |
+
* "Server" request tab.
|
50 |
+
*
|
51 |
+
* For more information see: http://www.firephp.org/
|
52 |
+
*
|
53 |
+
* @copyright Copyright (C) 2007-2008 Christoph Dorn
|
54 |
+
* @author Christoph Dorn <christoph@christophdorn.com>
|
55 |
+
* @license http://www.opensource.org/licenses/bsd-license.php
|
56 |
+
* @package FirePHP
|
57 |
+
*/
|
58 |
+
class FirePHP {
|
59 |
+
|
60 |
+
/**
|
61 |
+
* FirePHP version
|
62 |
+
*
|
63 |
+
* @var string
|
64 |
+
*/
|
65 |
+
const VERSION = '0.2.0';
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Firebug LOG level
|
69 |
+
*
|
70 |
+
* Logs a message to firebug console.
|
71 |
+
*
|
72 |
+
* @var string
|
73 |
+
*/
|
74 |
+
const LOG = 'LOG';
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Firebug INFO level
|
78 |
+
*
|
79 |
+
* Logs a message to firebug console and displays an info icon before the message.
|
80 |
+
*
|
81 |
+
* @var string
|
82 |
+
*/
|
83 |
+
const INFO = 'INFO';
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Firebug WARN level
|
87 |
+
*
|
88 |
+
* Logs a message to firebug console, displays an warning icon before the message and colors the line turquoise.
|
89 |
+
*
|
90 |
+
* @var string
|
91 |
+
*/
|
92 |
+
const WARN = 'WARN';
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Firebug ERROR level
|
96 |
+
*
|
97 |
+
* Logs a message to firebug console, displays an error icon before the message and colors the line yellow. Also increments the firebug error count.
|
98 |
+
*
|
99 |
+
* @var string
|
100 |
+
*/
|
101 |
+
const ERROR = 'ERROR';
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Dumps a variable to firebug's server panel
|
105 |
+
*
|
106 |
+
* @var string
|
107 |
+
*/
|
108 |
+
const DUMP = 'DUMP';
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Displays a stack trace in firebug console
|
112 |
+
*
|
113 |
+
* @var string
|
114 |
+
*/
|
115 |
+
const TRACE = 'TRACE';
|
116 |
+
|
117 |
+
/**
|
118 |
+
* Displays an exception in firebug console
|
119 |
+
*
|
120 |
+
* Increments the firebug error count.
|
121 |
+
*
|
122 |
+
* @var string
|
123 |
+
*/
|
124 |
+
const EXCEPTION = 'EXCEPTION';
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Displays an table in firebug console
|
128 |
+
*
|
129 |
+
* @var string
|
130 |
+
*/
|
131 |
+
const TABLE = 'TABLE';
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Starts a group in firebug console
|
135 |
+
*
|
136 |
+
* @var string
|
137 |
+
*/
|
138 |
+
const GROUP_START = 'GROUP_START';
|
139 |
+
|
140 |
+
/**
|
141 |
+
* Ends a group in firebug console
|
142 |
+
*
|
143 |
+
* @var string
|
144 |
+
*/
|
145 |
+
const GROUP_END = 'GROUP_END';
|
146 |
+
|
147 |
+
/**
|
148 |
+
* Singleton instance of FirePHP
|
149 |
+
*
|
150 |
+
* @var FirePHP
|
151 |
+
*/
|
152 |
+
protected static $instance = null;
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Wildfire protocol message index
|
156 |
+
*
|
157 |
+
* @var int
|
158 |
+
*/
|
159 |
+
protected $messageIndex = 1;
|
160 |
+
|
161 |
+
/**
|
162 |
+
* Options for the library
|
163 |
+
*
|
164 |
+
* @var array
|
165 |
+
*/
|
166 |
+
protected $options = array();
|
167 |
+
|
168 |
+
/**
|
169 |
+
* Filters used to exclude object members when encoding
|
170 |
+
*
|
171 |
+
* @var array
|
172 |
+
*/
|
173 |
+
protected $objectFilters = array();
|
174 |
+
|
175 |
+
/**
|
176 |
+
* A stack of objects used to detect recursion during object encoding
|
177 |
+
*
|
178 |
+
* @var object
|
179 |
+
*/
|
180 |
+
protected $objectStack = array();
|
181 |
+
|
182 |
+
/**
|
183 |
+
* Flag to enable/disable logging
|
184 |
+
*
|
185 |
+
* @var boolean
|
186 |
+
*/
|
187 |
+
protected $enabled = true;
|
188 |
+
|
189 |
+
/**
|
190 |
+
* The object constructor
|
191 |
+
*/
|
192 |
+
function __construct() {
|
193 |
+
$this->options['maxObjectDepth'] = 10;
|
194 |
+
$this->options['maxArrayDepth'] = 20;
|
195 |
+
$this->options['useNativeJsonEncode'] = true;
|
196 |
+
$this->options['includeLineNumbers'] = true;
|
197 |
+
}
|
198 |
+
|
199 |
+
/**
|
200 |
+
* When the object gets serialized only include specific object members.
|
201 |
+
*
|
202 |
+
* @return array
|
203 |
+
*/
|
204 |
+
public function __sleep() {
|
205 |
+
return array('options','objectFilters','enabled');
|
206 |
+
}
|
207 |
+
|
208 |
+
/**
|
209 |
+
* Gets singleton instance of FirePHP
|
210 |
+
*
|
211 |
+
* @param boolean $AutoCreate
|
212 |
+
* @return FirePHP
|
213 |
+
*/
|
214 |
+
public static function getInstance($AutoCreate=false) {
|
215 |
+
if($AutoCreate===true && !self::$instance) {
|
216 |
+
self::init();
|
217 |
+
}
|
218 |
+
return self::$instance;
|
219 |
+
}
|
220 |
+
|
221 |
+
/**
|
222 |
+
* Creates FirePHP object and stores it for singleton access
|
223 |
+
*
|
224 |
+
* @return FirePHP
|
225 |
+
*/
|
226 |
+
public static function init() {
|
227 |
+
return self::$instance = new self();
|
228 |
+
}
|
229 |
+
|
230 |
+
/**
|
231 |
+
* Enable and disable logging to Firebug
|
232 |
+
*
|
233 |
+
* @param boolean $Enabled TRUE to enable, FALSE to disable
|
234 |
+
* @return void
|
235 |
+
*/
|
236 |
+
public function setEnabled($Enabled) {
|
237 |
+
$this->enabled = $Enabled;
|
238 |
+
}
|
239 |
+
|
240 |
+
/**
|
241 |
+
* Check if logging is enabled
|
242 |
+
*
|
243 |
+
* @return boolean TRUE if enabled
|
244 |
+
*/
|
245 |
+
public function getEnabled() {
|
246 |
+
return $this->enabled;
|
247 |
+
}
|
248 |
+
|
249 |
+
/**
|
250 |
+
* Specify a filter to be used when encoding an object
|
251 |
+
*
|
252 |
+
* Filters are used to exclude object members.
|
253 |
+
*
|
254 |
+
* @param string $Class The class name of the object
|
255 |
+
* @param array $Filter An array or members to exclude
|
256 |
+
* @return void
|
257 |
+
*/
|
258 |
+
public function setObjectFilter($Class, $Filter) {
|
259 |
+
$this->objectFilters[$Class] = $Filter;
|
260 |
+
}
|
261 |
+
|
262 |
+
/**
|
263 |
+
* Set some options for the library
|
264 |
+
*
|
265 |
+
* Options:
|
266 |
+
* - maxObjectDepth: The maximum depth to traverse objects (default: 10)
|
267 |
+
* - maxArrayDepth: The maximum depth to traverse arrays (default: 20)
|
268 |
+
* - useNativeJsonEncode: If true will use json_encode() (default: true)
|
269 |
+
* - includeLineNumbers: If true will include line numbers and filenames (default: true)
|
270 |
+
*
|
271 |
+
* @param array $Options The options to be set
|
272 |
+
* @return void
|
273 |
+
*/
|
274 |
+
public function setOptions($Options) {
|
275 |
+
$this->options = array_merge($this->options,$Options);
|
276 |
+
}
|
277 |
+
|
278 |
+
/**
|
279 |
+
* Register FirePHP as your error handler
|
280 |
+
*
|
281 |
+
* Will throw exceptions for each php error.
|
282 |
+
*/
|
283 |
+
public function registerErrorHandler()
|
284 |
+
{
|
285 |
+
//NOTE: The following errors will not be caught by this error handler:
|
286 |
+
// E_ERROR, E_PARSE, E_CORE_ERROR,
|
287 |
+
// E_CORE_WARNING, E_COMPILE_ERROR,
|
288 |
+
// E_COMPILE_WARNING, E_STRICT
|
289 |
+
|
290 |
+
set_error_handler(array($this,'errorHandler'));
|
291 |
+
}
|
292 |
+
|
293 |
+
/**
|
294 |
+
* FirePHP's error handler
|
295 |
+
*
|
296 |
+
* Throws exception for each php error that will occur.
|
297 |
+
*
|
298 |
+
* @param int $errno
|
299 |
+
* @param string $errstr
|
300 |
+
* @param string $errfile
|
301 |
+
* @param int $errline
|
302 |
+
* @param array $errcontext
|
303 |
+
*/
|
304 |
+
public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
|
305 |
+
{
|
306 |
+
// Don't throw exception if error reporting is switched off
|
307 |
+
if (error_reporting() == 0) {
|
308 |
+
return;
|
309 |
+
}
|
310 |
+
// Only throw exceptions for errors we are asking for
|
311 |
+
if (error_reporting() & $errno) {
|
312 |
+
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
|
313 |
+
}
|
314 |
+
}
|
315 |
+
|
316 |
+
/**
|
317 |
+
* Register FirePHP as your exception handler
|
318 |
+
*/
|
319 |
+
public function registerExceptionHandler()
|
320 |
+
{
|
321 |
+
set_exception_handler(array($this,'exceptionHandler'));
|
322 |
+
}
|
323 |
+
|
324 |
+
/**
|
325 |
+
* FirePHP's exception handler
|
326 |
+
*
|
327 |
+
* Logs all exceptions to your firebug console and then stops the script.
|
328 |
+
*
|
329 |
+
* @param Exception $Exception
|
330 |
+
* @throws Exception
|
331 |
+
*/
|
332 |
+
function exceptionHandler($Exception) {
|
333 |
+
$this->fb($Exception);
|
334 |
+
}
|
335 |
+
|
336 |
+
/**
|
337 |
+
* Set custom processor url for FirePHP
|
338 |
+
*
|
339 |
+
* @param string $URL
|
340 |
+
*/
|
341 |
+
public function setProcessorUrl($URL)
|
342 |
+
{
|
343 |
+
$this->setHeader('X-FirePHP-ProcessorURL', $URL);
|
344 |
+
}
|
345 |
+
|
346 |
+
/**
|
347 |
+
* Set custom renderer url for FirePHP
|
348 |
+
*
|
349 |
+
* @param string $URL
|
350 |
+
*/
|
351 |
+
public function setRendererUrl($URL)
|
352 |
+
{
|
353 |
+
$this->setHeader('X-FirePHP-RendererURL', $URL);
|
354 |
+
}
|
355 |
+
|
356 |
+
/**
|
357 |
+
* Start a group for following messages
|
358 |
+
*
|
359 |
+
* @param string $Name
|
360 |
+
* @return true
|
361 |
+
* @throws Exception
|
362 |
+
*/
|
363 |
+
public function group($Name) {
|
364 |
+
return $this->fb(null, $Name, FirePHP::GROUP_START);
|
365 |
+
}
|
366 |
+
|
367 |
+
/**
|
368 |
+
* Ends a group you have started before
|
369 |
+
*
|
370 |
+
* @return true
|
371 |
+
* @throws Exception
|
372 |
+
*/
|
373 |
+
public function groupEnd() {
|
374 |
+
return $this->fb(null, null, FirePHP::GROUP_END);
|
375 |
+
}
|
376 |
+
|
377 |
+
/**
|
378 |
+
* Log object with label to firebug console
|
379 |
+
*
|
380 |
+
* @see FirePHP::LOG
|
381 |
+
* @param mixes $Object
|
382 |
+
* @param string $Label
|
383 |
+
* @return true
|
384 |
+
* @throws Exception
|
385 |
+
*/
|
386 |
+
public function log($Object, $Label=null) {
|
387 |
+
return $this->fb($Object, $Label, FirePHP::LOG);
|
388 |
+
}
|
389 |
+
|
390 |
+
/**
|
391 |
+
* Log object with label to firebug console
|
392 |
+
*
|
393 |
+
* @see FirePHP::INFO
|
394 |
+
* @param mixes $Object
|
395 |
+
* @param string $Label
|
396 |
+
* @return true
|
397 |
+
* @throws Exception
|
398 |
+
*/
|
399 |
+
public function info($Object, $Label=null) {
|
400 |
+
return $this->fb($Object, $Label, FirePHP::INFO);
|
401 |
+
}
|
402 |
+
|
403 |
+
/**
|
404 |
+
* Log object with label to firebug console
|
405 |
+
*
|
406 |
+
* @see FirePHP::WARN
|
407 |
+
* @param mixes $Object
|
408 |
+
* @param string $Label
|
409 |
+
* @return true
|
410 |
+
* @throws Exception
|
411 |
+
*/
|
412 |
+
public function warn($Object, $Label=null) {
|
413 |
+
return $this->fb($Object, $Label, FirePHP::WARN);
|
414 |
+
}
|
415 |
+
|
416 |
+
/**
|
417 |
+
* Log object with label to firebug console
|
418 |
+
*
|
419 |
+
* @see FirePHP::ERROR
|
420 |
+
* @param mixes $Object
|
421 |
+
* @param string $Label
|
422 |
+
* @return true
|
423 |
+
* @throws Exception
|
424 |
+
*/
|
425 |
+
public function error($Object, $Label=null) {
|
426 |
+
return $this->fb($Object, $Label, FirePHP::ERROR);
|
427 |
+
}
|
428 |
+
|
429 |
+
/**
|
430 |
+
* Dumps key and variable to firebug server panel
|
431 |
+
*
|
432 |
+
* @see FirePHP::DUMP
|
433 |
+
* @param string $Key
|
434 |
+
* @param mixed $Variable
|
435 |
+
* @return true
|
436 |
+
* @throws Exception
|
437 |
+
*/
|
438 |
+
public function dump($Key, $Variable) {
|
439 |
+
return $this->fb($Variable, $Key, FirePHP::DUMP);
|
440 |
+
}
|
441 |
+
|
442 |
+
/**
|
443 |
+
* Log a trace in the firebug console
|
444 |
+
*
|
445 |
+
* @see FirePHP::TRACE
|
446 |
+
* @param string $Label
|
447 |
+
* @return true
|
448 |
+
* @throws Exception
|
449 |
+
*/
|
450 |
+
public function trace($Label) {
|
451 |
+
return $this->fb($Label, FirePHP::TRACE);
|
452 |
+
}
|
453 |
+
|
454 |
+
/**
|
455 |
+
* Log a table in the firebug console
|
456 |
+
*
|
457 |
+
* @see FirePHP::TABLE
|
458 |
+
* @param string $Label
|
459 |
+
* @param string $Table
|
460 |
+
* @return true
|
461 |
+
* @throws Exception
|
462 |
+
*/
|
463 |
+
public function table($Label, $Table) {
|
464 |
+
return $this->fb($Table, $Label, FirePHP::TABLE);
|
465 |
+
}
|
466 |
+
|
467 |
+
/**
|
468 |
+
* Check if FirePHP is installed on client
|
469 |
+
*
|
470 |
+
* @return boolean
|
471 |
+
*/
|
472 |
+
public function detectClientExtension() {
|
473 |
+
/* Check if FirePHP is installed on client */
|
474 |
+
if(!@preg_match_all('/\sFirePHP\/([\.|\d]*)\s?/si',$this->getUserAgent(),$m) ||
|
475 |
+
!version_compare($m[1][0],'0.0.6','>=')) {
|
476 |
+
return false;
|
477 |
+
}
|
478 |
+
return true;
|
479 |
+
}
|
480 |
+
|
481 |
+
/**
|
482 |
+
* Log varible to Firebug
|
483 |
+
*
|
484 |
+
* @see http://www.firephp.org/Wiki/Reference/Fb
|
485 |
+
* @param mixed $Object The variable to be logged
|
486 |
+
* @return true Return TRUE if message was added to headers, FALSE otherwise
|
487 |
+
* @throws Exception
|
488 |
+
*/
|
489 |
+
public function fb($Object) {
|
490 |
+
|
491 |
+
if(!$this->enabled) {
|
492 |
+
return false;
|
493 |
+
}
|
494 |
+
|
495 |
+
if (headers_sent($filename, $linenum)) {
|
496 |
+
throw $this->newException('Headers already sent in '.$filename.' on line '.$linenum.'. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.');
|
497 |
+
}
|
498 |
+
|
499 |
+
$Type = null;
|
500 |
+
$Label = null;
|
501 |
+
|
502 |
+
if(func_num_args()==1) {
|
503 |
+
} else
|
504 |
+
if(func_num_args()==2) {
|
505 |
+
switch(func_get_arg(1)) {
|
506 |
+
case self::LOG:
|
507 |
+
case self::INFO:
|
508 |
+
case self::WARN:
|
509 |
+
case self::ERROR:
|
510 |
+
case self::DUMP:
|
511 |
+
case self::TRACE:
|
512 |
+
case self::EXCEPTION:
|
513 |
+
case self::TABLE:
|
514 |
+
case self::GROUP_START:
|
515 |
+
case self::GROUP_END:
|
516 |
+
$Type = func_get_arg(1);
|
517 |
+
break;
|
518 |
+
default:
|
519 |
+
$Label = func_get_arg(1);
|
520 |
+
break;
|
521 |
+
}
|
522 |
+
} else
|
523 |
+
if(func_num_args()==3) {
|
524 |
+
$Type = func_get_arg(2);
|
525 |
+
$Label = func_get_arg(1);
|
526 |
+
} else {
|
527 |
+
throw $this->newException('Wrong number of arguments to fb() function!');
|
528 |
+
}
|
529 |
+
|
530 |
+
|
531 |
+
if(!$this->detectClientExtension()) {
|
532 |
+
return false;
|
533 |
+
}
|
534 |
+
|
535 |
+
$meta = array();
|
536 |
+
$skipFinalObjectEncode = false;
|
537 |
+
|
538 |
+
if($Object instanceof Exception) {
|
539 |
+
|
540 |
+
$meta['file'] = $this->_escapeTraceFile($Object->getFile());
|
541 |
+
$meta['line'] = $Object->getLine();
|
542 |
+
|
543 |
+
$trace = $Object->getTrace();
|
544 |
+
if($Object instanceof ErrorException
|
545 |
+
&& isset($trace[0]['function'])
|
546 |
+
&& $trace[0]['function']=='errorHandler'
|
547 |
+
&& isset($trace[0]['class'])
|
548 |
+
&& $trace[0]['class']=='FirePHP') {
|
549 |
+
|
550 |
+
$severity = false;
|
551 |
+
switch($Object->getSeverity()) {
|
552 |
+
case E_WARNING: $severity = 'E_WARNING'; break;
|
553 |
+
case E_NOTICE: $severity = 'E_NOTICE'; break;
|
554 |
+
case E_USER_ERROR: $severity = 'E_USER_ERROR'; break;
|
555 |
+
case E_USER_WARNING: $severity = 'E_USER_WARNING'; break;
|
556 |
+
case E_USER_NOTICE: $severity = 'E_USER_NOTICE'; break;
|
557 |
+
case E_STRICT: $severity = 'E_STRICT'; break;
|
558 |
+
case E_RECOVERABLE_ERROR: $severity = 'E_RECOVERABLE_ERROR'; break;
|
559 |
+
case E_DEPRECATED: $severity = 'E_DEPRECATED'; break;
|
560 |
+
case E_USER_DEPRECATED: $severity = 'E_USER_DEPRECATED'; break;
|
561 |
+
}
|
562 |
+
|
563 |
+
$Object = array('Class'=>get_class($Object),
|
564 |
+
'Message'=>$severity.': '.$Object->getMessage(),
|
565 |
+
'File'=>$this->_escapeTraceFile($Object->getFile()),
|
566 |
+
'Line'=>$Object->getLine(),
|
567 |
+
'Type'=>'trigger',
|
568 |
+
'Trace'=>$this->_escapeTrace(array_splice($trace,2)));
|
569 |
+
$skipFinalObjectEncode = true;
|
570 |
+
} else {
|
571 |
+
$Object = array('Class'=>get_class($Object),
|
572 |
+
'Message'=>$Object->getMessage(),
|
573 |
+
'File'=>$this->_escapeTraceFile($Object->getFile()),
|
574 |
+
'Line'=>$Object->getLine(),
|
575 |
+
'Type'=>'throw',
|
576 |
+
'Trace'=>$this->_escapeTrace($trace));
|
577 |
+
$skipFinalObjectEncode = true;
|
578 |
+
}
|
579 |
+
$Type = self::EXCEPTION;
|
580 |
+
|
581 |
+
} else
|
582 |
+
if($Type==self::TRACE) {
|
583 |
+
|
584 |
+
$trace = debug_backtrace();
|
585 |
+
if(!$trace) return false;
|
586 |
+
for( $i=0 ; $i<sizeof($trace) ; $i++ ) {
|
587 |
+
|
588 |
+
if(isset($trace[$i]['class'])
|
589 |
+
&& isset($trace[$i]['file'])
|
590 |
+
&& ($trace[$i]['class']=='FirePHP'
|
591 |
+
|| $trace[$i]['class']=='FB')
|
592 |
+
&& (substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php'
|
593 |
+
|| substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) {
|
594 |
+
/* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */
|
595 |
+
} else
|
596 |
+
if(isset($trace[$i]['class'])
|
597 |
+
&& isset($trace[$i+1]['file'])
|
598 |
+
&& $trace[$i]['class']=='FirePHP'
|
599 |
+
&& substr($this->_standardizePath($trace[$i+1]['file']),-18,18)=='FirePHPCore/fb.php') {
|
600 |
+
/* Skip fb() */
|
601 |
+
} else
|
602 |
+
if($trace[$i]['function']=='fb'
|
603 |
+
|| $trace[$i]['function']=='trace'
|
604 |
+
|| $trace[$i]['function']=='send') {
|
605 |
+
$Object = array('Class'=>isset($trace[$i]['class'])?$trace[$i]['class']:'',
|
606 |
+
'Type'=>isset($trace[$i]['type'])?$trace[$i]['type']:'',
|
607 |
+
'Function'=>isset($trace[$i]['function'])?$trace[$i]['function']:'',
|
608 |
+
'Message'=>$trace[$i]['args'][0],
|
609 |
+
'File'=>isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):'',
|
610 |
+
'Line'=>isset($trace[$i]['line'])?$trace[$i]['line']:'',
|
611 |
+
'Args'=>isset($trace[$i]['args'])?$this->encodeObject($trace[$i]['args']):'',
|
612 |
+
'Trace'=>$this->_escapeTrace(array_splice($trace,$i+1)));
|
613 |
+
|
614 |
+
$skipFinalObjectEncode = true;
|
615 |
+
$meta['file'] = isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):'';
|
616 |
+
$meta['line'] = isset($trace[$i]['line'])?$trace[$i]['line']:'';
|
617 |
+
break;
|
618 |
+
}
|
619 |
+
}
|
620 |
+
|
621 |
+
} else
|
622 |
+
if($Type==self::TABLE) {
|
623 |
+
|
624 |
+
if(isset($Object[0]) && is_string($Object[0])) {
|
625 |
+
$Object[1] = $this->encodeTable($Object[1]);
|
626 |
+
} else {
|
627 |
+
$Object = $this->encodeTable($Object);
|
628 |
+
}
|
629 |
+
|
630 |
+
$skipFinalObjectEncode = true;
|
631 |
+
|
632 |
+
} else {
|
633 |
+
if($Type===null) {
|
634 |
+
$Type = self::LOG;
|
635 |
+
}
|
636 |
+
}
|
637 |
+
|
638 |
+
if($this->options['includeLineNumbers']) {
|
639 |
+
if(!isset($meta['file']) || !isset($meta['line'])) {
|
640 |
+
|
641 |
+
$trace = debug_backtrace();
|
642 |
+
for( $i=0 ; $trace && $i<sizeof($trace) ; $i++ ) {
|
643 |
+
|
644 |
+
if(isset($trace[$i]['class'])
|
645 |
+
&& isset($trace[$i]['file'])
|
646 |
+
&& ($trace[$i]['class']=='FirePHP'
|
647 |
+
|| $trace[$i]['class']=='FB')
|
648 |
+
&& (substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php'
|
649 |
+
|| substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) {
|
650 |
+
/* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */
|
651 |
+
} else
|
652 |
+
if(isset($trace[$i]['class'])
|
653 |
+
&& isset($trace[$i+1]['file'])
|
654 |
+
&& $trace[$i]['class']=='FirePHP'
|
655 |
+
&& substr($this->_standardizePath($trace[$i+1]['file']),-18,18)=='FirePHPCore/fb.php') {
|
656 |
+
/* Skip fb() */
|
657 |
+
} else
|
658 |
+
if(isset($trace[$i]['file'])
|
659 |
+
&& substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php') {
|
660 |
+
/* Skip FB::fb() */
|
661 |
+
} else {
|
662 |
+
$meta['file'] = isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):'';
|
663 |
+
$meta['line'] = isset($trace[$i]['line'])?$trace[$i]['line']:'';
|
664 |
+
break;
|
665 |
+
}
|
666 |
+
}
|
667 |
+
|
668 |
+
}
|
669 |
+
} else {
|
670 |
+
unset($meta['file']);
|
671 |
+
unset($meta['line']);
|
672 |
+
}
|
673 |
+
|
674 |
+
$this->setHeader('X-Wf-Protocol-1','http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
|
675 |
+
$this->setHeader('X-Wf-1-Plugin-1','http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/'.self::VERSION);
|
676 |
+
|
677 |
+
$structure_index = 1;
|
678 |
+
if($Type==self::DUMP) {
|
679 |
+
$structure_index = 2;
|
680 |
+
$this->setHeader('X-Wf-1-Structure-2','http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1');
|
681 |
+
} else {
|
682 |
+
$this->setHeader('X-Wf-1-Structure-1','http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1');
|
683 |
+
}
|
684 |
+
|
685 |
+
if($Type==self::DUMP) {
|
686 |
+
$msg = '{"'.$Label.'":'.$this->jsonEncode($Object, $skipFinalObjectEncode).'}';
|
687 |
+
} else {
|
688 |
+
$msg_meta = array('Type'=>$Type);
|
689 |
+
if($Label!==null) {
|
690 |
+
$msg_meta['Label'] = $Label;
|
691 |
+
}
|
692 |
+
if(isset($meta['file'])) {
|
693 |
+
$msg_meta['File'] = $meta['file'];
|
694 |
+
}
|
695 |
+
if(isset($meta['line'])) {
|
696 |
+
$msg_meta['Line'] = $meta['line'];
|
697 |
+
}
|
698 |
+
$msg = '['.$this->jsonEncode($msg_meta).','.$this->jsonEncode($Object, $skipFinalObjectEncode).']';
|
699 |
+
}
|
700 |
+
|
701 |
+
$parts = explode("\n",chunk_split($msg, 5000, "\n"));
|
702 |
+
|
703 |
+
for( $i=0 ; $i<count($parts) ; $i++) {
|
704 |
+
|
705 |
+
$part = $parts[$i];
|
706 |
+
if ($part) {
|
707 |
+
|
708 |
+
if(count($parts)>2) {
|
709 |
+
// Message needs to be split into multiple parts
|
710 |
+
$this->setHeader('X-Wf-1-'.$structure_index.'-'.'1-'.$this->messageIndex,
|
711 |
+
(($i==0)?strlen($msg):'')
|
712 |
+
. '|' . $part . '|'
|
713 |
+
. (($i<count($parts)-2)?'\\':''));
|
714 |
+
} else {
|
715 |
+
$this->setHeader('X-Wf-1-'.$structure_index.'-'.'1-'.$this->messageIndex,
|
716 |
+
strlen($part) . '|' . $part . '|');
|
717 |
+
}
|
718 |
+
|
719 |
+
$this->messageIndex++;
|
720 |
+
|
721 |
+
if ($this->messageIndex > 99999) {
|
722 |
+
throw new Exception('Maximum number (99,999) of messages reached!');
|
723 |
+
}
|
724 |
+
}
|
725 |
+
}
|
726 |
+
|
727 |
+
$this->setHeader('X-Wf-1-Index',$this->messageIndex-1);
|
728 |
+
|
729 |
+
return true;
|
730 |
+
}
|
731 |
+
|
732 |
+
/**
|
733 |
+
* Standardizes path for windows systems.
|
734 |
+
*
|
735 |
+
* @param string $Path
|
736 |
+
* @return string
|
737 |
+
*/
|
738 |
+
protected function _standardizePath($Path) {
|
739 |
+
return preg_replace('/\\\\+/','/',$Path);
|
740 |
+
}
|
741 |
+
|
742 |
+
/**
|
743 |
+
* Escape trace path for windows systems
|
744 |
+
*
|
745 |
+
* @param array $Trace
|
746 |
+
* @return array
|
747 |
+
*/
|
748 |
+
protected function _escapeTrace($Trace) {
|
749 |
+
if(!$Trace) return $Trace;
|
750 |
+
for( $i=0 ; $i<sizeof($Trace) ; $i++ ) {
|
751 |
+
if(isset($Trace[$i]['file'])) {
|
752 |
+
$Trace[$i]['file'] = $this->_escapeTraceFile($Trace[$i]['file']);
|
753 |
+
}
|
754 |
+
if(isset($Trace[$i]['args'])) {
|
755 |
+
$Trace[$i]['args'] = $this->encodeObject($Trace[$i]['args']);
|
756 |
+
}
|
757 |
+
}
|
758 |
+
return $Trace;
|
759 |
+
}
|
760 |
+
|
761 |
+
/**
|
762 |
+
* Escape file information of trace for windows systems
|
763 |
+
*
|
764 |
+
* @param string $File
|
765 |
+
* @return string
|
766 |
+
*/
|
767 |
+
protected function _escapeTraceFile($File) {
|
768 |
+
/* Check if we have a windows filepath */
|
769 |
+
if(strpos($File,'\\')) {
|
770 |
+
/* First strip down to single \ */
|
771 |
+
|
772 |
+
$file = preg_replace('/\\\\+/','\\',$File);
|
773 |
+
|
774 |
+
return $file;
|
775 |
+
}
|
776 |
+
return $File;
|
777 |
+
}
|
778 |
+
|
779 |
+
/**
|
780 |
+
* Send header
|
781 |
+
*
|
782 |
+
* @param string $Name
|
783 |
+
* @param string_type $Value
|
784 |
+
*/
|
785 |
+
protected function setHeader($Name, $Value) {
|
786 |
+
return header($Name.': '.$Value);
|
787 |
+
}
|
788 |
+
|
789 |
+
/**
|
790 |
+
* Get user agent
|
791 |
+
*
|
792 |
+
* @return string|false
|
793 |
+
*/
|
794 |
+
protected function getUserAgent() {
|
795 |
+
if(!isset($_SERVER['HTTP_USER_AGENT'])) return false;
|
796 |
+
return $_SERVER['HTTP_USER_AGENT'];
|
797 |
+
}
|
798 |
+
|
799 |
+
/**
|
800 |
+
* Returns a new exception
|
801 |
+
*
|
802 |
+
* @param string $Message
|
803 |
+
* @return Exception
|
804 |
+
*/
|
805 |
+
protected function newException($Message) {
|
806 |
+
return new Exception($Message);
|
807 |
+
}
|
808 |
+
|
809 |
+
/**
|
810 |
+
* Encode an object into a JSON string
|
811 |
+
*
|
812 |
+
* Uses PHP's jeson_encode() if available
|
813 |
+
*
|
814 |
+
* @param object $Object The object to be encoded
|
815 |
+
* @return string The JSON string
|
816 |
+
*/
|
817 |
+
protected function jsonEncode($Object, $skipObjectEncode=false)
|
818 |
+
{
|
819 |
+
if(!$skipObjectEncode) {
|
820 |
+
$Object = $this->encodeObject($Object);
|
821 |
+
}
|
822 |
+
|
823 |
+
if(function_exists('json_encode')
|
824 |
+
&& $this->options['useNativeJsonEncode']!=false) {
|
825 |
+
|
826 |
+
return json_encode($Object);
|
827 |
+
} else {
|
828 |
+
return $this->json_encode($Object);
|
829 |
+
}
|
830 |
+
}
|
831 |
+
|
832 |
+
/**
|
833 |
+
* Encodes a table by encoding each row and column with encodeObject()
|
834 |
+
*
|
835 |
+
* @param array $Table The table to be encoded
|
836 |
+
* @return array
|
837 |
+
*/
|
838 |
+
protected function encodeTable($Table) {
|
839 |
+
if(!$Table) return $Table;
|
840 |
+
for( $i=0 ; $i<count($Table) ; $i++ ) {
|
841 |
+
if(is_array($Table[$i])) {
|
842 |
+
for( $j=0 ; $j<count($Table[$i]) ; $j++ ) {
|
843 |
+
$Table[$i][$j] = $this->encodeObject($Table[$i][$j]);
|
844 |
+
}
|
845 |
+
}
|
846 |
+
}
|
847 |
+
return $Table;
|
848 |
+
}
|
849 |
+
|
850 |
+
/**
|
851 |
+
* Encodes an object including members with
|
852 |
+
* protected and private visibility
|
853 |
+
*
|
854 |
+
* @param Object $Object The object to be encoded
|
855 |
+
* @param int $Depth The current traversal depth
|
856 |
+
* @return array All members of the object
|
857 |
+
*/
|
858 |
+
protected function encodeObject($Object, $ObjectDepth = 1, $ArrayDepth = 1)
|
859 |
+
{
|
860 |
+
$return = array();
|
861 |
+
|
862 |
+
if (is_object($Object)) {
|
863 |
+
|
864 |
+
if ($ObjectDepth > $this->options['maxObjectDepth']) {
|
865 |
+
return '** Max Object Depth ('.$this->options['maxObjectDepth'].') **';
|
866 |
+
}
|
867 |
+
|
868 |
+
foreach ($this->objectStack as $refVal) {
|
869 |
+
if ($refVal === $Object) {
|
870 |
+
return '** Recursion ('.get_class($Object).') **';
|
871 |
+
}
|
872 |
+
}
|
873 |
+
array_push($this->objectStack, $Object);
|
874 |
+
|
875 |
+
$return['__className'] = $class = get_class($Object);
|
876 |
+
|
877 |
+
$reflectionClass = new ReflectionClass($class);
|
878 |
+
$properties = array();
|
879 |
+
foreach( $reflectionClass->getProperties() as $property) {
|
880 |
+
$properties[$property->getName()] = $property;
|
881 |
+
}
|
882 |
+
|
883 |
+
$members = (array)$Object;
|
884 |
+
|
885 |
+
foreach( $properties as $raw_name => $property ) {
|
886 |
+
|
887 |
+
$name = $raw_name;
|
888 |
+
if($property->isStatic()) {
|
889 |
+
$name = 'static:'.$name;
|
890 |
+
}
|
891 |
+
if($property->isPublic()) {
|
892 |
+
$name = 'public:'.$name;
|
893 |
+
} else
|
894 |
+
if($property->isPrivate()) {
|
895 |
+
$name = 'private:'.$name;
|
896 |
+
$raw_name = "\0".$class."\0".$raw_name;
|
897 |
+
} else
|
898 |
+
if($property->isProtected()) {
|
899 |
+
$name = 'protected:'.$name;
|
900 |
+
$raw_name = "\0".'*'."\0".$raw_name;
|
901 |
+
}
|
902 |
+
|
903 |
+
if(!(isset($this->objectFilters[$class])
|
904 |
+
&& is_array($this->objectFilters[$class])
|
905 |
+
&& in_array($raw_name,$this->objectFilters[$class]))) {
|
906 |
+
|
907 |
+
if(array_key_exists($raw_name,$members)
|
908 |
+
&& !$property->isStatic()) {
|
909 |
+
|
910 |
+
$return[$name] = $this->encodeObject($members[$raw_name], $ObjectDepth + 1, 1);
|
911 |
+
|
912 |
+
} else {
|
913 |
+
if(method_exists($property,'setAccessible')) {
|
914 |
+
$property->setAccessible(true);
|
915 |
+
$return[$name] = $this->encodeObject($property->getValue($Object), $ObjectDepth + 1, 1);
|
916 |
+
} else
|
917 |
+
if($property->isPublic()) {
|
918 |
+
$return[$name] = $this->encodeObject($property->getValue($Object), $ObjectDepth + 1, 1);
|
919 |
+
} else {
|
920 |
+
$return[$name] = '** Need PHP 5.3 to get value **';
|
921 |
+
}
|
922 |
+
}
|
923 |
+
} else {
|
924 |
+
$return[$name] = '** Excluded by Filter **';
|
925 |
+
}
|
926 |
+
}
|
927 |
+
|
928 |
+
// Include all members that are not defined in the class
|
929 |
+
// but exist in the object
|
930 |
+
foreach( $members as $raw_name => $value ) {
|
931 |
+
|
932 |
+
$name = $raw_name;
|
933 |
+
|
934 |
+
if ($name{0} == "\0") {
|
935 |
+
$parts = explode("\0", $name);
|
936 |
+
$name = $parts[2];
|
937 |
+
}
|
938 |
+
|
939 |
+
if(!isset($properties[$name])) {
|
940 |
+
$name = 'undeclared:'.$name;
|
941 |
+
|
942 |
+
if(!(isset($this->objectFilters[$class])
|
943 |
+
&& is_array($this->objectFilters[$class])
|
944 |
+
&& in_array($raw_name,$this->objectFilters[$class]))) {
|
945 |
+
|
946 |
+
$return[$name] = $this->encodeObject($value, $ObjectDepth + 1, 1);
|
947 |
+
} else {
|
948 |
+
$return[$name] = '** Excluded by Filter **';
|
949 |
+
}
|
950 |
+
}
|
951 |
+
}
|
952 |
+
|
953 |
+
array_pop($this->objectStack);
|
954 |
+
|
955 |
+
} elseif (is_array($Object)) {
|
956 |
+
|
957 |
+
if ($ArrayDepth > $this->options['maxArrayDepth']) {
|
958 |
+
return '** Max Array Depth ('.$this->options['maxArrayDepth'].') **';
|
959 |
+
}
|
960 |
+
|
961 |
+
foreach ($Object as $key => $val) {
|
962 |
+
|
963 |
+
// Encoding the $GLOBALS PHP array causes an infinite loop
|
964 |
+
// if the recursion is not reset here as it contains
|
965 |
+
// a reference to itself. This is the only way I have come up
|
966 |
+
// with to stop infinite recursion in this case.
|
967 |
+
if($key=='GLOBALS'
|
968 |
+
&& is_array($val)
|
969 |
+
&& array_key_exists('GLOBALS',$val)) {
|
970 |
+
$val['GLOBALS'] = '** Recursion (GLOBALS) **';
|
971 |
+
}
|
972 |
+
|
973 |
+
$return[$key] = $this->encodeObject($val, 1, $ArrayDepth + 1);
|
974 |
+
}
|
975 |
+
} else {
|
976 |
+
if(self::is_utf8($Object)) {
|
977 |
+
return $Object;
|
978 |
+
} else {
|
979 |
+
return utf8_encode($Object);
|
980 |
+
}
|
981 |
+
}
|
982 |
+
return $return;
|
983 |
+
}
|
984 |
+
|
985 |
+
/**
|
986 |
+
* Returns true if $string is valid UTF-8 and false otherwise.
|
987 |
+
*
|
988 |
+
* @param mixed $str String to be tested
|
989 |
+
* @return boolean
|
990 |
+
*/
|
991 |
+
protected static function is_utf8($str) {
|
992 |
+
$c=0; $b=0;
|
993 |
+
$bits=0;
|
994 |
+
$len=strlen($str);
|
995 |
+
for($i=0; $i<$len; $i++){
|
996 |
+
$c=ord($str[$i]);
|
997 |
+
if($c > 128){
|
998 |
+
if(($c >= 254)) return false;
|
999 |
+
elseif($c >= 252) $bits=6;
|
1000 |
+
elseif($c >= 248) $bits=5;
|
1001 |
+
elseif($c >= 240) $bits=4;
|
1002 |
+
elseif($c >= 224) $bits=3;
|
1003 |
+
elseif($c >= 192) $bits=2;
|
1004 |
+
else return false;
|
1005 |
+
if(($i+$bits) > $len) return false;
|
1006 |
+
while($bits > 1){
|
1007 |
+
$i++;
|
1008 |
+
$b=ord($str[$i]);
|
1009 |
+
if($b < 128 || $b > 191) return false;
|
1010 |
+
$bits--;
|
1011 |
+
}
|
1012 |
+
}
|
1013 |
+
}
|
1014 |
+
return true;
|
1015 |
+
}
|
1016 |
+
|
1017 |
+
/**
|
1018 |
+
* Converts to and from JSON format.
|
1019 |
+
*
|
1020 |
+
* JSON (JavaScript Object Notation) is a lightweight data-interchange
|
1021 |
+
* format. It is easy for humans to read and write. It is easy for machines
|
1022 |
+
* to parse and generate. It is based on a subset of the JavaScript
|
1023 |
+
* Programming Language, Standard ECMA-262 3rd Edition - December 1999.
|
1024 |
+
* This feature can also be found in Python. JSON is a text format that is
|
1025 |
+
* completely language independent but uses conventions that are familiar
|
1026 |
+
* to programmers of the C-family of languages, including C, C++, C#, Java,
|
1027 |
+
* JavaScript, Perl, TCL, and many others. These properties make JSON an
|
1028 |
+
* ideal data-interchange language.
|
1029 |
+
*
|
1030 |
+
* This package provides a simple encoder and decoder for JSON notation. It
|
1031 |
+
* is intended for use with client-side Javascript applications that make
|
1032 |
+
* use of HTTPRequest to perform server communication functions - data can
|
1033 |
+
* be encoded into JSON notation for use in a client-side javascript, or
|
1034 |
+
* decoded from incoming Javascript requests. JSON format is native to
|
1035 |
+
* Javascript, and can be directly eval()'ed with no further parsing
|
1036 |
+
* overhead
|
1037 |
+
*
|
1038 |
+
* All strings should be in ASCII or UTF-8 format!
|
1039 |
+
*
|
1040 |
+
* LICENSE: Redistribution and use in source and binary forms, with or
|
1041 |
+
* without modification, are permitted provided that the following
|
1042 |
+
* conditions are met: Redistributions of source code must retain the
|
1043 |
+
* above copyright notice, this list of conditions and the following
|
1044 |
+
* disclaimer. Redistributions in binary form must reproduce the above
|
1045 |
+
* copyright notice, this list of conditions and the following disclaimer
|
1046 |
+
* in the documentation and/or other materials provided with the
|
1047 |
+
* distribution.
|
1048 |
+
*
|
1049 |
+
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
1050 |
+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
1051 |
+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
1052 |
+
* NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
1053 |
+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
1054 |
+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
1055 |
+
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
1056 |
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
1057 |
+
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
1058 |
+
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
1059 |
+
* DAMAGE.
|
1060 |
+
*
|
1061 |
+
* @category
|
1062 |
+
* @package Services_JSON
|
1063 |
+
* @author Michal Migurski <mike-json@teczno.com>
|
1064 |
+
* @author Matt Knapp <mdknapp[at]gmail[dot]com>
|
1065 |
+
* @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
|
1066 |
+
* @author Christoph Dorn <christoph@christophdorn.com>
|
1067 |
+
* @copyright 2005 Michal Migurski
|
1068 |
+
* @version CVS: $Id: JSON.php,v 1.31 2006/06/28 05:54:17 migurski Exp $
|
1069 |
+
* @license http://www.opensource.org/licenses/bsd-license.php
|
1070 |
+
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
|
1071 |
+
*/
|
1072 |
+
|
1073 |
+
|
1074 |
+
/**
|
1075 |
+
* Keep a list of objects as we descend into the array so we can detect recursion.
|
1076 |
+
*/
|
1077 |
+
private $json_objectStack = array();
|
1078 |
+
|
1079 |
+
|
1080 |
+
/**
|
1081 |
+
* convert a string from one UTF-8 char to one UTF-16 char
|
1082 |
+
*
|
1083 |
+
* Normally should be handled by mb_convert_encoding, but
|
1084 |
+
* provides a slower PHP-only method for installations
|
1085 |
+
* that lack the multibye string extension.
|
1086 |
+
*
|
1087 |
+
* @param string $utf8 UTF-8 character
|
1088 |
+
* @return string UTF-16 character
|
1089 |
+
* @access private
|
1090 |
+
*/
|
1091 |
+
private function json_utf82utf16($utf8)
|
1092 |
+
{
|
1093 |
+
// oh please oh please oh please oh please oh please
|
1094 |
+
if(function_exists('mb_convert_encoding')) {
|
1095 |
+
return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
|
1096 |
+
}
|
1097 |
+
|
1098 |
+
switch(strlen($utf8)) {
|
1099 |
+
case 1:
|
1100 |
+
// this case should never be reached, because we are in ASCII range
|
1101 |
+
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
1102 |
+
return $utf8;
|
1103 |
+
|
1104 |
+
case 2:
|
1105 |
+
// return a UTF-16 character from a 2-byte UTF-8 char
|
1106 |
+
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
1107 |
+
return chr(0x07 & (ord($utf8{0}) >> 2))
|
1108 |
+
. chr((0xC0 & (ord($utf8{0}) << 6))
|
1109 |
+
| (0x3F & ord($utf8{1})));
|
1110 |
+
|
1111 |
+
case 3:
|
1112 |
+
// return a UTF-16 character from a 3-byte UTF-8 char
|
1113 |
+
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
1114 |
+
return chr((0xF0 & (ord($utf8{0}) << 4))
|
1115 |
+
| (0x0F & (ord($utf8{1}) >> 2)))
|
1116 |
+
. chr((0xC0 & (ord($utf8{1}) << 6))
|
1117 |
+
| (0x7F & ord($utf8{2})));
|
1118 |
+
}
|
1119 |
+
|
1120 |
+
// ignoring UTF-32 for now, sorry
|
1121 |
+
return '';
|
1122 |
+
}
|
1123 |
+
|
1124 |
+
/**
|
1125 |
+
* encodes an arbitrary variable into JSON format
|
1126 |
+
*
|
1127 |
+
* @param mixed $var any number, boolean, string, array, or object to be encoded.
|
1128 |
+
* see argument 1 to Services_JSON() above for array-parsing behavior.
|
1129 |
+
* if var is a strng, note that encode() always expects it
|
1130 |
+
* to be in ASCII or UTF-8 format!
|
1131 |
+
*
|
1132 |
+
* @return mixed JSON string representation of input var or an error if a problem occurs
|
1133 |
+
* @access public
|
1134 |
+
*/
|
1135 |
+
private function json_encode($var)
|
1136 |
+
{
|
1137 |
+
|
1138 |
+
if(is_object($var)) {
|
1139 |
+
if(in_array($var,$this->json_objectStack)) {
|
1140 |
+
return '"** Recursion **"';
|
1141 |
+
}
|
1142 |
+
}
|
1143 |
+
|
1144 |
+
switch (gettype($var)) {
|
1145 |
+
case 'boolean':
|
1146 |
+
return $var ? 'true' : 'false';
|
1147 |
+
|
1148 |
+
case 'NULL':
|
1149 |
+
return 'null';
|
1150 |
+
|
1151 |
+
case 'integer':
|
1152 |
+
return (int) $var;
|
1153 |
+
|
1154 |
+
case 'double':
|
1155 |
+
case 'float':
|
1156 |
+
return (float) $var;
|
1157 |
+
|
1158 |
+
case 'string':
|
1159 |
+
// STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
|
1160 |
+
$ascii = '';
|
1161 |
+
$strlen_var = strlen($var);
|
1162 |
+
|
1163 |
+
/*
|
1164 |
+
* Iterate over every character in the string,
|
1165 |
+
* escaping with a slash or encoding to UTF-8 where necessary
|
1166 |
+
*/
|
1167 |
+
for ($c = 0; $c < $strlen_var; ++$c) {
|
1168 |
+
|
1169 |
+
$ord_var_c = ord($var{$c});
|
1170 |
+
|
1171 |
+
switch (true) {
|
1172 |
+
case $ord_var_c == 0x08:
|
1173 |
+
$ascii .= '\b';
|
1174 |
+
break;
|
1175 |
+
case $ord_var_c == 0x09:
|
1176 |
+
$ascii .= '\t';
|
1177 |
+
break;
|
1178 |
+
case $ord_var_c == 0x0A:
|
1179 |
+
$ascii .= '\n';
|
1180 |
+
break;
|
1181 |
+
case $ord_var_c == 0x0C:
|
1182 |
+
$ascii .= '\f';
|
1183 |
+
break;
|
1184 |
+
case $ord_var_c == 0x0D:
|
1185 |
+
$ascii .= '\r';
|
1186 |
+
break;
|
1187 |
+
|
1188 |
+
case $ord_var_c == 0x22:
|
1189 |
+
case $ord_var_c == 0x2F:
|
1190 |
+
case $ord_var_c == 0x5C:
|
1191 |
+
// double quote, slash, slosh
|
1192 |
+
$ascii .= '\\'.$var{$c};
|
1193 |
+
break;
|
1194 |
+
|
1195 |
+
case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
|
1196 |
+
// characters U-00000000 - U-0000007F (same as ASCII)
|
1197 |
+
$ascii .= $var{$c};
|
1198 |
+
break;
|
1199 |
+
|
1200 |
+
case (($ord_var_c & 0xE0) == 0xC0):
|
1201 |
+
// characters U-00000080 - U-000007FF, mask 110XXXXX
|
1202 |
+
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
1203 |
+
$char = pack('C*', $ord_var_c, ord($var{$c + 1}));
|
1204 |
+
$c += 1;
|
1205 |
+
$utf16 = $this->json_utf82utf16($char);
|
1206 |
+
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
1207 |
+
break;
|
1208 |
+
|
1209 |
+
case (($ord_var_c & 0xF0) == 0xE0):
|
1210 |
+
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
|
1211 |
+
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
1212 |
+
$char = pack('C*', $ord_var_c,
|
1213 |
+
ord($var{$c + 1}),
|
1214 |
+
ord($var{$c + 2}));
|
1215 |
+
$c += 2;
|
1216 |
+
$utf16 = $this->json_utf82utf16($char);
|
1217 |
+
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
1218 |
+
break;
|
1219 |
+
|
1220 |
+
case (($ord_var_c & 0xF8) == 0xF0):
|
1221 |
+
// characters U-00010000 - U-001FFFFF, mask 11110XXX
|
1222 |
+
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
1223 |
+
$char = pack('C*', $ord_var_c,
|
1224 |
+
ord($var{$c + 1}),
|
1225 |
+
ord($var{$c + 2}),
|
1226 |
+
ord($var{$c + 3}));
|
1227 |
+
$c += 3;
|
1228 |
+
$utf16 = $this->json_utf82utf16($char);
|
1229 |
+
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
1230 |
+
break;
|
1231 |
+
|
1232 |
+
case (($ord_var_c & 0xFC) == 0xF8):
|
1233 |
+
// characters U-00200000 - U-03FFFFFF, mask 111110XX
|
1234 |
+
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
1235 |
+
$char = pack('C*', $ord_var_c,
|
1236 |
+
ord($var{$c + 1}),
|
1237 |
+
ord($var{$c + 2}),
|
1238 |
+
ord($var{$c + 3}),
|
1239 |
+
ord($var{$c + 4}));
|
1240 |
+
$c += 4;
|
1241 |
+
$utf16 = $this->json_utf82utf16($char);
|
1242 |
+
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
1243 |
+
break;
|
1244 |
+
|
1245 |
+
case (($ord_var_c & 0xFE) == 0xFC):
|
1246 |
+
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
|
1247 |
+
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
1248 |
+
$char = pack('C*', $ord_var_c,
|
1249 |
+
ord($var{$c + 1}),
|
1250 |
+
ord($var{$c + 2}),
|
1251 |
+
ord($var{$c + 3}),
|
1252 |
+
ord($var{$c + 4}),
|
1253 |
+
ord($var{$c + 5}));
|
1254 |
+
$c += 5;
|
1255 |
+
$utf16 = $this->json_utf82utf16($char);
|
1256 |
+
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
1257 |
+
break;
|
1258 |
+
}
|
1259 |
+
}
|
1260 |
+
|
1261 |
+
return '"'.$ascii.'"';
|
1262 |
+
|
1263 |
+
case 'array':
|
1264 |
+
/*
|
1265 |
+
* As per JSON spec if any array key is not an integer
|
1266 |
+
* we must treat the the whole array as an object. We
|
1267 |
+
* also try to catch a sparsely populated associative
|
1268 |
+
* array with numeric keys here because some JS engines
|
1269 |
+
* will create an array with empty indexes up to
|
1270 |
+
* max_index which can cause memory issues and because
|
1271 |
+
* the keys, which may be relevant, will be remapped
|
1272 |
+
* otherwise.
|
1273 |
+
*
|
1274 |
+
* As per the ECMA and JSON specification an object may
|
1275 |
+
* have any string as a property. Unfortunately due to
|
1276 |
+
* a hole in the ECMA specification if the key is a
|
1277 |
+
* ECMA reserved word or starts with a digit the
|
1278 |
+
* parameter is only accessible using ECMAScript's
|
1279 |
+
* bracket notation.
|
1280 |
+
*/
|
1281 |
+
|
1282 |
+
// treat as a JSON object
|
1283 |
+
if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
|
1284 |
+
|
1285 |
+
$this->json_objectStack[] = $var;
|
1286 |
+
|
1287 |
+
$properties = array_map(array($this, 'json_name_value'),
|
1288 |
+
array_keys($var),
|
1289 |
+
array_values($var));
|
1290 |
+
|
1291 |
+
array_pop($this->json_objectStack);
|
1292 |
+
|
1293 |
+
foreach($properties as $property) {
|
1294 |
+
if($property instanceof Exception) {
|
1295 |
+
return $property;
|
1296 |
+
}
|
1297 |
+
}
|
1298 |
+
|
1299 |
+
return '{' . join(',', $properties) . '}';
|
1300 |
+
}
|
1301 |
+
|
1302 |
+
$this->json_objectStack[] = $var;
|
1303 |
+
|
1304 |
+
// treat it like a regular array
|
1305 |
+
$elements = array_map(array($this, 'json_encode'), $var);
|
1306 |
+
|
1307 |
+
array_pop($this->json_objectStack);
|
1308 |
+
|
1309 |
+
foreach($elements as $element) {
|
1310 |
+
if($element instanceof Exception) {
|
1311 |
+
return $element;
|
1312 |
+
}
|
1313 |
+
}
|
1314 |
+
|
1315 |
+
return '[' . join(',', $elements) . ']';
|
1316 |
+
|
1317 |
+
case 'object':
|
1318 |
+
$vars = self::encodeObject($var);
|
1319 |
+
|
1320 |
+
$this->json_objectStack[] = $var;
|
1321 |
+
|
1322 |
+
$properties = array_map(array($this, 'json_name_value'),
|
1323 |
+
array_keys($vars),
|
1324 |
+
array_values($vars));
|
1325 |
+
|
1326 |
+
array_pop($this->json_objectStack);
|
1327 |
+
|
1328 |
+
foreach($properties as $property) {
|
1329 |
+
if($property instanceof Exception) {
|
1330 |
+
return $property;
|
1331 |
+
}
|
1332 |
+
}
|
1333 |
+
|
1334 |
+
return '{' . join(',', $properties) . '}';
|
1335 |
+
|
1336 |
+
default:
|
1337 |
+
return null;
|
1338 |
+
}
|
1339 |
+
}
|
1340 |
+
|
1341 |
+
/**
|
1342 |
+
* array-walking function for use in generating JSON-formatted name-value pairs
|
1343 |
+
*
|
1344 |
+
* @param string $name name of key to use
|
1345 |
+
* @param mixed $value reference to an array element to be encoded
|
1346 |
+
*
|
1347 |
+
* @return string JSON-formatted name-value pair, like '"name":value'
|
1348 |
+
* @access private
|
1349 |
+
*/
|
1350 |
+
private function json_name_value($name, $value)
|
1351 |
+
{
|
1352 |
+
// Encoding the $GLOBALS PHP array causes an infinite loop
|
1353 |
+
// if the recursion is not reset here as it contains
|
1354 |
+
// a reference to itself. This is the only way I have come up
|
1355 |
+
// with to stop infinite recursion in this case.
|
1356 |
+
if($name=='GLOBALS'
|
1357 |
+
&& is_array($value)
|
1358 |
+
&& array_key_exists('GLOBALS',$value)) {
|
1359 |
+
$value['GLOBALS'] = '** Recursion **';
|
1360 |
+
}
|
1361 |
+
|
1362 |
+
$encoded_value = $this->json_encode($value);
|
1363 |
+
|
1364 |
+
if($encoded_value instanceof Exception) {
|
1365 |
+
return $encoded_value;
|
1366 |
+
}
|
1367 |
+
|
1368 |
+
return $this->json_encode(strval($name)) . ':' . $encoded_value;
|
1369 |
+
}
|
1370 |
+
}
|
includes/min/lib/HTTP/ConditionalGet.php
ADDED
@@ -0,0 +1,366 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class HTTP_ConditionalGet
|
4 |
+
* @package Minify
|
5 |
+
* @subpackage HTTP
|
6 |
+
*/
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Implement conditional GET via a timestamp or hash of content
|
10 |
+
*
|
11 |
+
* E.g. Content from DB with update time:
|
12 |
+
* <code>
|
13 |
+
* list($updateTime, $content) = getDbUpdateAndContent();
|
14 |
+
* $cg = new HTTP_ConditionalGet(array(
|
15 |
+
* 'lastModifiedTime' => $updateTime
|
16 |
+
* ,'isPublic' => true
|
17 |
+
* ));
|
18 |
+
* $cg->sendHeaders();
|
19 |
+
* if ($cg->cacheIsValid) {
|
20 |
+
* exit();
|
21 |
+
* }
|
22 |
+
* echo $content;
|
23 |
+
* </code>
|
24 |
+
*
|
25 |
+
* E.g. Shortcut for the above
|
26 |
+
* <code>
|
27 |
+
* HTTP_ConditionalGet::check($updateTime, true); // exits if client has cache
|
28 |
+
* echo $content;
|
29 |
+
* </code>
|
30 |
+
*
|
31 |
+
* E.g. Content from DB with no update time:
|
32 |
+
* <code>
|
33 |
+
* $content = getContentFromDB();
|
34 |
+
* $cg = new HTTP_ConditionalGet(array(
|
35 |
+
* 'contentHash' => md5($content)
|
36 |
+
* ));
|
37 |
+
* $cg->sendHeaders();
|
38 |
+
* if ($cg->cacheIsValid) {
|
39 |
+
* exit();
|
40 |
+
* }
|
41 |
+
* echo $content;
|
42 |
+
* </code>
|
43 |
+
*
|
44 |
+
* E.g. Static content with some static includes:
|
45 |
+
* <code>
|
46 |
+
* // before content
|
47 |
+
* $cg = new HTTP_ConditionalGet(array(
|
48 |
+
* 'lastUpdateTime' => max(
|
49 |
+
* filemtime(__FILE__)
|
50 |
+
* ,filemtime('/path/to/header.inc')
|
51 |
+
* ,filemtime('/path/to/footer.inc')
|
52 |
+
* )
|
53 |
+
* ));
|
54 |
+
* $cg->sendHeaders();
|
55 |
+
* if ($cg->cacheIsValid) {
|
56 |
+
* exit();
|
57 |
+
* }
|
58 |
+
* </code>
|
59 |
+
* @package Minify
|
60 |
+
* @subpackage HTTP
|
61 |
+
* @author Stephen Clay <steve@mrclay.org>
|
62 |
+
*/
|
63 |
+
class HTTP_ConditionalGet {
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Does the client have a valid copy of the requested resource?
|
67 |
+
*
|
68 |
+
* You'll want to check this after instantiating the object. If true, do
|
69 |
+
* not send content, just call sendHeaders() if you haven't already.
|
70 |
+
*
|
71 |
+
* @var bool
|
72 |
+
*/
|
73 |
+
public $cacheIsValid = null;
|
74 |
+
|
75 |
+
/**
|
76 |
+
* @param array $spec options
|
77 |
+
*
|
78 |
+
* 'isPublic': (bool) if false, the Cache-Control header will contain
|
79 |
+
* "private", allowing only browser caching. (default false)
|
80 |
+
*
|
81 |
+
* 'lastModifiedTime': (int) if given, both ETag AND Last-Modified headers
|
82 |
+
* will be sent with content. This is recommended.
|
83 |
+
*
|
84 |
+
* 'encoding': (string) if set, the header "Vary: Accept-Encoding" will
|
85 |
+
* always be sent and a truncated version of the encoding will be appended
|
86 |
+
* to the ETag. E.g. "pub123456;gz". This will also trigger a more lenient
|
87 |
+
* checking of the client's If-None-Match header, as the encoding portion of
|
88 |
+
* the ETag will be stripped before comparison.
|
89 |
+
*
|
90 |
+
* 'contentHash': (string) if given, only the ETag header can be sent with
|
91 |
+
* content (only HTTP1.1 clients can conditionally GET). The given string
|
92 |
+
* should be short with no quote characters and always change when the
|
93 |
+
* resource changes (recommend md5()). This is not needed/used if
|
94 |
+
* lastModifiedTime is given.
|
95 |
+
*
|
96 |
+
* 'eTag': (string) if given, this will be used as the ETag header rather
|
97 |
+
* than values based on lastModifiedTime or contentHash. Also the encoding
|
98 |
+
* string will not be appended to the given value as described above.
|
99 |
+
*
|
100 |
+
* 'invalidate': (bool) if true, the client cache will be considered invalid
|
101 |
+
* without testing. Effectively this disables conditional GET.
|
102 |
+
* (default false)
|
103 |
+
*
|
104 |
+
* 'maxAge': (int) if given, this will set the Cache-Control max-age in
|
105 |
+
* seconds, and also set the Expires header to the equivalent GMT date.
|
106 |
+
* After the max-age period has passed, the browser will again send a
|
107 |
+
* conditional GET to revalidate its cache.
|
108 |
+
*/
|
109 |
+
public function __construct($spec)
|
110 |
+
{
|
111 |
+
$scope = (isset($spec['isPublic']) && $spec['isPublic'])
|
112 |
+
? 'public'
|
113 |
+
: 'private';
|
114 |
+
$maxAge = 0;
|
115 |
+
// backwards compatibility (can be removed later)
|
116 |
+
if (isset($spec['setExpires'])
|
117 |
+
&& is_numeric($spec['setExpires'])
|
118 |
+
&& ! isset($spec['maxAge'])) {
|
119 |
+
$spec['maxAge'] = $spec['setExpires'] - $_SERVER['REQUEST_TIME'];
|
120 |
+
}
|
121 |
+
if (isset($spec['maxAge'])) {
|
122 |
+
$maxAge = $spec['maxAge'];
|
123 |
+
$this->_headers['Expires'] = self::gmtDate(
|
124 |
+
$_SERVER['REQUEST_TIME'] + $spec['maxAge']
|
125 |
+
);
|
126 |
+
}
|
127 |
+
$etagAppend = '';
|
128 |
+
if (isset($spec['encoding'])) {
|
129 |
+
$this->_stripEtag = true;
|
130 |
+
$this->_headers['Vary'] = 'Accept-Encoding';
|
131 |
+
if ('' !== $spec['encoding']) {
|
132 |
+
if (0 === strpos($spec['encoding'], 'x-')) {
|
133 |
+
$spec['encoding'] = substr($spec['encoding'], 2);
|
134 |
+
}
|
135 |
+
$etagAppend = ';' . substr($spec['encoding'], 0, 2);
|
136 |
+
}
|
137 |
+
}
|
138 |
+
if (isset($spec['lastModifiedTime'])) {
|
139 |
+
$this->_setLastModified($spec['lastModifiedTime']);
|
140 |
+
if (isset($spec['eTag'])) { // Use it
|
141 |
+
$this->_setEtag($spec['eTag'], $scope);
|
142 |
+
} else { // base both headers on time
|
143 |
+
$this->_setEtag($spec['lastModifiedTime'] . $etagAppend, $scope);
|
144 |
+
}
|
145 |
+
} elseif (isset($spec['eTag'])) { // Use it
|
146 |
+
$this->_setEtag($spec['eTag'], $scope);
|
147 |
+
} elseif (isset($spec['contentHash'])) { // Use the hash as the ETag
|
148 |
+
$this->_setEtag($spec['contentHash'] . $etagAppend, $scope);
|
149 |
+
}
|
150 |
+
$privacy = ($scope === 'private')
|
151 |
+
? ', private'
|
152 |
+
: '';
|
153 |
+
$this->_headers['Cache-Control'] = "max-age={$maxAge}{$privacy}";
|
154 |
+
// invalidate cache if disabled, otherwise check
|
155 |
+
$this->cacheIsValid = (isset($spec['invalidate']) && $spec['invalidate'])
|
156 |
+
? false
|
157 |
+
: $this->_isCacheValid();
|
158 |
+
}
|
159 |
+
|
160 |
+
/**
|
161 |
+
* Get array of output headers to be sent
|
162 |
+
*
|
163 |
+
* In the case of 304 responses, this array will only contain the response
|
164 |
+
* code header: array('_responseCode' => 'HTTP/1.0 304 Not Modified')
|
165 |
+
*
|
166 |
+
* Otherwise something like:
|
167 |
+
* <code>
|
168 |
+
* array(
|
169 |
+
* 'Cache-Control' => 'max-age=0, public'
|
170 |
+
* ,'ETag' => '"foobar"'
|
171 |
+
* )
|
172 |
+
* </code>
|
173 |
+
*
|
174 |
+
* @return array
|
175 |
+
*/
|
176 |
+
public function getHeaders()
|
177 |
+
{
|
178 |
+
return $this->_headers;
|
179 |
+
}
|
180 |
+
|
181 |
+
/**
|
182 |
+
* Set the Content-Length header in bytes
|
183 |
+
*
|
184 |
+
* With most PHP configs, as long as you don't flush() output, this method
|
185 |
+
* is not needed and PHP will buffer all output and set Content-Length for
|
186 |
+
* you. Otherwise you'll want to call this to let the client know up front.
|
187 |
+
*
|
188 |
+
* @param int $bytes
|
189 |
+
*
|
190 |
+
* @return int copy of input $bytes
|
191 |
+
*/
|
192 |
+
public function setContentLength($bytes)
|
193 |
+
{
|
194 |
+
return $this->_headers['Content-Length'] = $bytes;
|
195 |
+
}
|
196 |
+
|
197 |
+
/**
|
198 |
+
* Send headers
|
199 |
+
*
|
200 |
+
* @see getHeaders()
|
201 |
+
*
|
202 |
+
* Note this doesn't "clear" the headers. Calling sendHeaders() will
|
203 |
+
* call header() again (but probably have not effect) and getHeaders() will
|
204 |
+
* still return the headers.
|
205 |
+
*
|
206 |
+
* @return null
|
207 |
+
*/
|
208 |
+
public function sendHeaders()
|
209 |
+
{
|
210 |
+
$headers = $this->_headers;
|
211 |
+
if (array_key_exists('_responseCode', $headers)) {
|
212 |
+
// FastCGI environments require 3rd arg to header() to be set
|
213 |
+
list(, $code) = explode(' ', $headers['_responseCode'], 3);
|
214 |
+
header($headers['_responseCode'], true, $code);
|
215 |
+
unset($headers['_responseCode']);
|
216 |
+
}
|
217 |
+
foreach ($headers as $name => $val) {
|
218 |
+
header($name . ': ' . $val);
|
219 |
+
}
|
220 |
+
}
|
221 |
+
|
222 |
+
/**
|
223 |
+
* Exit if the client's cache is valid for this resource
|
224 |
+
*
|
225 |
+
* This is a convenience method for common use of the class
|
226 |
+
*
|
227 |
+
* @param int $lastModifiedTime if given, both ETag AND Last-Modified headers
|
228 |
+
* will be sent with content. This is recommended.
|
229 |
+
*
|
230 |
+
* @param bool $isPublic (default false) if true, the Cache-Control header
|
231 |
+
* will contain "public", allowing proxies to cache the content. Otherwise
|
232 |
+
* "private" will be sent, allowing only browser caching.
|
233 |
+
*
|
234 |
+
* @param array $options (default empty) additional options for constructor
|
235 |
+
*/
|
236 |
+
public static function check($lastModifiedTime = null, $isPublic = false, $options = array())
|
237 |
+
{
|
238 |
+
if (null !== $lastModifiedTime) {
|
239 |
+
$options['lastModifiedTime'] = (int)$lastModifiedTime;
|
240 |
+
}
|
241 |
+
$options['isPublic'] = (bool)$isPublic;
|
242 |
+
$cg = new HTTP_ConditionalGet($options);
|
243 |
+
$cg->sendHeaders();
|
244 |
+
if ($cg->cacheIsValid) {
|
245 |
+
exit();
|
246 |
+
}
|
247 |
+
}
|
248 |
+
|
249 |
+
|
250 |
+
/**
|
251 |
+
* Get a GMT formatted date for use in HTTP headers
|
252 |
+
*
|
253 |
+
* <code>
|
254 |
+
* header('Expires: ' . HTTP_ConditionalGet::gmtdate($time));
|
255 |
+
* </code>
|
256 |
+
*
|
257 |
+
* @param int $time unix timestamp
|
258 |
+
*
|
259 |
+
* @return string
|
260 |
+
*/
|
261 |
+
public static function gmtDate($time)
|
262 |
+
{
|
263 |
+
return gmdate('D, d M Y H:i:s \G\M\T', $time);
|
264 |
+
}
|
265 |
+
|
266 |
+
protected $_headers = array();
|
267 |
+
protected $_lmTime = null;
|
268 |
+
protected $_etag = null;
|
269 |
+
protected $_stripEtag = false;
|
270 |
+
|
271 |
+
/**
|
272 |
+
* @param string $hash
|
273 |
+
*
|
274 |
+
* @param string $scope
|
275 |
+
*/
|
276 |
+
protected function _setEtag($hash, $scope)
|
277 |
+
{
|
278 |
+
$this->_etag = '"' . substr($scope, 0, 3) . $hash . '"';
|
279 |
+
$this->_headers['ETag'] = $this->_etag;
|
280 |
+
}
|
281 |
+
|
282 |
+
/**
|
283 |
+
* @param int $time
|
284 |
+
*/
|
285 |
+
protected function _setLastModified($time)
|
286 |
+
{
|
287 |
+
$this->_lmTime = (int)$time;
|
288 |
+
$this->_headers['Last-Modified'] = self::gmtDate($time);
|
289 |
+
}
|
290 |
+
|
291 |
+
/**
|
292 |
+
* Determine validity of client cache and queue 304 header if valid
|
293 |
+
*
|
294 |
+
* @return bool
|
295 |
+
*/
|
296 |
+
protected function _isCacheValid()
|
297 |
+
{
|
298 |
+
if (null === $this->_etag) {
|
299 |
+
// lmTime is copied to ETag, so this condition implies that the
|
300 |
+
// server sent neither ETag nor Last-Modified, so the client can't
|
301 |
+
// possibly has a valid cache.
|
302 |
+
return false;
|
303 |
+
}
|
304 |
+
$isValid = ($this->resourceMatchedEtag() || $this->resourceNotModified());
|
305 |
+
if ($isValid) {
|
306 |
+
$this->_headers['_responseCode'] = 'HTTP/1.0 304 Not Modified';
|
307 |
+
}
|
308 |
+
return $isValid;
|
309 |
+
}
|
310 |
+
|
311 |
+
/**
|
312 |
+
* @return bool
|
313 |
+
*/
|
314 |
+
protected function resourceMatchedEtag()
|
315 |
+
{
|
316 |
+
if (!isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
|
317 |
+
return false;
|
318 |
+
}
|
319 |
+
$clientEtagList = get_magic_quotes_gpc()
|
320 |
+
? stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])
|
321 |
+
: $_SERVER['HTTP_IF_NONE_MATCH'];
|
322 |
+
$clientEtags = explode(',', $clientEtagList);
|
323 |
+
|
324 |
+
$compareTo = $this->normalizeEtag($this->_etag);
|
325 |
+
foreach ($clientEtags as $clientEtag) {
|
326 |
+
if ($this->normalizeEtag($clientEtag) === $compareTo) {
|
327 |
+
// respond with the client's matched ETag, even if it's not what
|
328 |
+
// we would've sent by default
|
329 |
+
$this->_headers['ETag'] = trim($clientEtag);
|
330 |
+
return true;
|
331 |
+
}
|
332 |
+
}
|
333 |
+
return false;
|
334 |
+
}
|
335 |
+
|
336 |
+
/**
|
337 |
+
* @param string $etag
|
338 |
+
*
|
339 |
+
* @return string
|
340 |
+
*/
|
341 |
+
protected function normalizeEtag($etag) {
|
342 |
+
$etag = trim($etag);
|
343 |
+
return $this->_stripEtag
|
344 |
+
? preg_replace('/;\\w\\w"$/', '"', $etag)
|
345 |
+
: $etag;
|
346 |
+
}
|
347 |
+
|
348 |
+
/**
|
349 |
+
* @return bool
|
350 |
+
*/
|
351 |
+
protected function resourceNotModified()
|
352 |
+
{
|
353 |
+
if (!isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
|
354 |
+
return false;
|
355 |
+
}
|
356 |
+
// strip off IE's extra data (semicolon)
|
357 |
+
list($ifModifiedSince) = explode(';', $_SERVER['HTTP_IF_MODIFIED_SINCE'], 2);
|
358 |
+
if (strtotime($ifModifiedSince) >= $this->_lmTime) {
|
359 |
+
// Apache 2.2's behavior. If there was no ETag match, send the
|
360 |
+
// non-encoded version of the ETag value.
|
361 |
+
$this->_headers['ETag'] = $this->normalizeEtag($this->_etag);
|
362 |
+
return true;
|
363 |
+
}
|
364 |
+
return false;
|
365 |
+
}
|
366 |
+
}
|
includes/min/lib/HTTP/Encoder.php
ADDED
@@ -0,0 +1,335 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class HTTP_Encoder
|
4 |
+
* @package Minify
|
5 |
+
* @subpackage HTTP
|
6 |
+
*/
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Encode and send gzipped/deflated content
|
10 |
+
*
|
11 |
+
* The "Vary: Accept-Encoding" header is sent. If the client allows encoding,
|
12 |
+
* Content-Encoding and Content-Length are added.
|
13 |
+
*
|
14 |
+
* <code>
|
15 |
+
* // Send a CSS file, compressed if possible
|
16 |
+
* $he = new HTTP_Encoder(array(
|
17 |
+
* 'content' => file_get_contents($cssFile)
|
18 |
+
* ,'type' => 'text/css'
|
19 |
+
* ));
|
20 |
+
* $he->encode();
|
21 |
+
* $he->sendAll();
|
22 |
+
* </code>
|
23 |
+
*
|
24 |
+
* <code>
|
25 |
+
* // Shortcut to encoding output
|
26 |
+
* header('Content-Type: text/css'); // needed if not HTML
|
27 |
+
* HTTP_Encoder::output($css);
|
28 |
+
* </code>
|
29 |
+
*
|
30 |
+
* <code>
|
31 |
+
* // Just sniff for the accepted encoding
|
32 |
+
* $encoding = HTTP_Encoder::getAcceptedEncoding();
|
33 |
+
* </code>
|
34 |
+
*
|
35 |
+
* For more control over headers, use getHeaders() and getData() and send your
|
36 |
+
* own output.
|
37 |
+
*
|
38 |
+
* Note: If you don't need header mgmt, use PHP's native gzencode, gzdeflate,
|
39 |
+
* and gzcompress functions for gzip, deflate, and compress-encoding
|
40 |
+
* respectively.
|
41 |
+
*
|
42 |
+
* @package Minify
|
43 |
+
* @subpackage HTTP
|
44 |
+
* @author Stephen Clay <steve@mrclay.org>
|
45 |
+
*/
|
46 |
+
class HTTP_Encoder {
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Should the encoder allow HTTP encoding to IE6?
|
50 |
+
*
|
51 |
+
* If you have many IE6 users and the bandwidth savings is worth troubling
|
52 |
+
* some of them, set this to true.
|
53 |
+
*
|
54 |
+
* By default, encoding is only offered to IE7+. When this is true,
|
55 |
+
* getAcceptedEncoding() will return an encoding for IE6 if its user agent
|
56 |
+
* string contains "SV1". This has been documented in many places as "safe",
|
57 |
+
* but there seem to be remaining, intermittent encoding bugs in patched
|
58 |
+
* IE6 on the wild web.
|
59 |
+
*
|
60 |
+
* @var bool
|
61 |
+
*/
|
62 |
+
public static $encodeToIe6 = true;
|
63 |
+
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Default compression level for zlib operations
|
67 |
+
*
|
68 |
+
* This level is used if encode() is not given a $compressionLevel
|
69 |
+
*
|
70 |
+
* @var int
|
71 |
+
*/
|
72 |
+
public static $compressionLevel = 6;
|
73 |
+
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Get an HTTP Encoder object
|
77 |
+
*
|
78 |
+
* @param array $spec options
|
79 |
+
*
|
80 |
+
* 'content': (string required) content to be encoded
|
81 |
+
*
|
82 |
+
* 'type': (string) if set, the Content-Type header will have this value.
|
83 |
+
*
|
84 |
+
* 'method: (string) only set this if you are forcing a particular encoding
|
85 |
+
* method. If not set, the best method will be chosen by getAcceptedEncoding()
|
86 |
+
* The available methods are 'gzip', 'deflate', 'compress', and '' (no
|
87 |
+
* encoding)
|
88 |
+
*/
|
89 |
+
public function __construct($spec)
|
90 |
+
{
|
91 |
+
$this->_useMbStrlen = (function_exists('mb_strlen')
|
92 |
+
&& (ini_get('mbstring.func_overload') !== '')
|
93 |
+
&& ((int)ini_get('mbstring.func_overload') & 2));
|
94 |
+
$this->_content = $spec['content'];
|
95 |
+
$this->_headers['Content-Length'] = $this->_useMbStrlen
|
96 |
+
? (string)mb_strlen($this->_content, '8bit')
|
97 |
+
: (string)strlen($this->_content);
|
98 |
+
if (isset($spec['type'])) {
|
99 |
+
$this->_headers['Content-Type'] = $spec['type'];
|
100 |
+
}
|
101 |
+
if (isset($spec['method'])
|
102 |
+
&& in_array($spec['method'], array('gzip', 'deflate', 'compress', '')))
|
103 |
+
{
|
104 |
+
$this->_encodeMethod = array($spec['method'], $spec['method']);
|
105 |
+
} else {
|
106 |
+
$this->_encodeMethod = self::getAcceptedEncoding();
|
107 |
+
}
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Get content in current form
|
112 |
+
*
|
113 |
+
* Call after encode() for encoded content.
|
114 |
+
*
|
115 |
+
* @return string
|
116 |
+
*/
|
117 |
+
public function getContent()
|
118 |
+
{
|
119 |
+
return $this->_content;
|
120 |
+
}
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Get array of output headers to be sent
|
124 |
+
*
|
125 |
+
* E.g.
|
126 |
+
* <code>
|
127 |
+
* array(
|
128 |
+
* 'Content-Length' => '615'
|
129 |
+
* ,'Content-Encoding' => 'x-gzip'
|
130 |
+
* ,'Vary' => 'Accept-Encoding'
|
131 |
+
* )
|
132 |
+
* </code>
|
133 |
+
*
|
134 |
+
* @return array
|
135 |
+
*/
|
136 |
+
public function getHeaders()
|
137 |
+
{
|
138 |
+
return $this->_headers;
|
139 |
+
}
|
140 |
+
|
141 |
+
/**
|
142 |
+
* Send output headers
|
143 |
+
*
|
144 |
+
* You must call this before headers are sent and it probably cannot be
|
145 |
+
* used in conjunction with zlib output buffering / mod_gzip. Errors are
|
146 |
+
* not handled purposefully.
|
147 |
+
*
|
148 |
+
* @see getHeaders()
|
149 |
+
*/
|
150 |
+
public function sendHeaders()
|
151 |
+
{
|
152 |
+
foreach ($this->_headers as $name => $val) {
|
153 |
+
header($name . ': ' . $val);
|
154 |
+
}
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* Send output headers and content
|
159 |
+
*
|
160 |
+
* A shortcut for sendHeaders() and echo getContent()
|
161 |
+
*
|
162 |
+
* You must call this before headers are sent and it probably cannot be
|
163 |
+
* used in conjunction with zlib output buffering / mod_gzip. Errors are
|
164 |
+
* not handled purposefully.
|
165 |
+
*/
|
166 |
+
public function sendAll()
|
167 |
+
{
|
168 |
+
$this->sendHeaders();
|
169 |
+
echo $this->_content;
|
170 |
+
}
|
171 |
+
|
172 |
+
/**
|
173 |
+
* Determine the client's best encoding method from the HTTP Accept-Encoding
|
174 |
+
* header.
|
175 |
+
*
|
176 |
+
* If no Accept-Encoding header is set, or the browser is IE before v6 SP2,
|
177 |
+
* this will return ('', ''), the "identity" encoding.
|
178 |
+
*
|
179 |
+
* A syntax-aware scan is done of the Accept-Encoding, so the method must
|
180 |
+
* be non 0. The methods are favored in order of gzip, deflate, then
|
181 |
+
* compress. Deflate is always smallest and generally faster, but is
|
182 |
+
* rarely sent by servers, so client support could be buggier.
|
183 |
+
*
|
184 |
+
* @param bool $allowCompress allow the older compress encoding
|
185 |
+
*
|
186 |
+
* @param bool $allowDeflate allow the more recent deflate encoding
|
187 |
+
*
|
188 |
+
* @return array two values, 1st is the actual encoding method, 2nd is the
|
189 |
+
* alias of that method to use in the Content-Encoding header (some browsers
|
190 |
+
* call gzip "x-gzip" etc.)
|
191 |
+
*/
|
192 |
+
public static function getAcceptedEncoding($allowCompress = true, $allowDeflate = true)
|
193 |
+
{
|
194 |
+
// @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
|
195 |
+
|
196 |
+
if (! isset($_SERVER['HTTP_ACCEPT_ENCODING'])
|
197 |
+
|| self::isBuggyIe())
|
198 |
+
{
|
199 |
+
return array('', '');
|
200 |
+
}
|
201 |
+
$ae = $_SERVER['HTTP_ACCEPT_ENCODING'];
|
202 |
+
// gzip checks (quick)
|
203 |
+
if (0 === strpos($ae, 'gzip,') // most browsers
|
204 |
+
|| 0 === strpos($ae, 'deflate, gzip,') // opera
|
205 |
+
) {
|
206 |
+
return array('gzip', 'gzip');
|
207 |
+
}
|
208 |
+
// gzip checks (slow)
|
209 |
+
if (preg_match(
|
210 |
+
'@(?:^|,)\\s*((?:x-)?gzip)\\s*(?:$|,|;\\s*q=(?:0\\.|1))@'
|
211 |
+
,$ae
|
212 |
+
,$m)) {
|
213 |
+
return array('gzip', $m[1]);
|
214 |
+
}
|
215 |
+
if ($allowDeflate) {
|
216 |
+
// deflate checks
|
217 |
+
$aeRev = strrev($ae);
|
218 |
+
if (0 === strpos($aeRev, 'etalfed ,') // ie, webkit
|
219 |
+
|| 0 === strpos($aeRev, 'etalfed,') // gecko
|
220 |
+
|| 0 === strpos($ae, 'deflate,') // opera
|
221 |
+
// slow parsing
|
222 |
+
|| preg_match(
|
223 |
+
'@(?:^|,)\\s*deflate\\s*(?:$|,|;\\s*q=(?:0\\.|1))@', $ae)) {
|
224 |
+
return array('deflate', 'deflate');
|
225 |
+
}
|
226 |
+
}
|
227 |
+
if ($allowCompress && preg_match(
|
228 |
+
'@(?:^|,)\\s*((?:x-)?compress)\\s*(?:$|,|;\\s*q=(?:0\\.|1))@'
|
229 |
+
,$ae
|
230 |
+
,$m)) {
|
231 |
+
return array('compress', $m[1]);
|
232 |
+
}
|
233 |
+
return array('', '');
|
234 |
+
}
|
235 |
+
|
236 |
+
/**
|
237 |
+
* Encode (compress) the content
|
238 |
+
*
|
239 |
+
* If the encode method is '' (none) or compression level is 0, or the 'zlib'
|
240 |
+
* extension isn't loaded, we return false.
|
241 |
+
*
|
242 |
+
* Then the appropriate gz_* function is called to compress the content. If
|
243 |
+
* this fails, false is returned.
|
244 |
+
*
|
245 |
+
* The header "Vary: Accept-Encoding" is added. If encoding is successful,
|
246 |
+
* the Content-Length header is updated, and Content-Encoding is also added.
|
247 |
+
*
|
248 |
+
* @param int $compressionLevel given to zlib functions. If not given, the
|
249 |
+
* class default will be used.
|
250 |
+
*
|
251 |
+
* @return bool success true if the content was actually compressed
|
252 |
+
*/
|
253 |
+
public function encode($compressionLevel = null)
|
254 |
+
{
|
255 |
+
if (! self::isBuggyIe()) {
|
256 |
+
$this->_headers['Vary'] = 'Accept-Encoding';
|
257 |
+
}
|
258 |
+
if (null === $compressionLevel) {
|
259 |
+
$compressionLevel = self::$compressionLevel;
|
260 |
+
}
|
261 |
+
if ('' === $this->_encodeMethod[0]
|
262 |
+
|| ($compressionLevel == 0)
|
263 |
+
|| !extension_loaded('zlib'))
|
264 |
+
{
|
265 |
+
return false;
|
266 |
+
}
|
267 |
+
if ($this->_encodeMethod[0] === 'deflate') {
|
268 |
+
$encoded = gzdeflate($this->_content, $compressionLevel);
|
269 |
+
} elseif ($this->_encodeMethod[0] === 'gzip') {
|
270 |
+
$encoded = gzencode($this->_content, $compressionLevel);
|
271 |
+
} else {
|
272 |
+
$encoded = gzcompress($this->_content, $compressionLevel);
|
273 |
+
}
|
274 |
+
if (false === $encoded) {
|
275 |
+
return false;
|
276 |
+
}
|
277 |
+
$this->_headers['Content-Length'] = $this->_useMbStrlen
|
278 |
+
? (string)mb_strlen($encoded, '8bit')
|
279 |
+
: (string)strlen($encoded);
|
280 |
+
$this->_headers['Content-Encoding'] = $this->_encodeMethod[1];
|
281 |
+
$this->_content = $encoded;
|
282 |
+
return true;
|
283 |
+
}
|
284 |
+
|
285 |
+
/**
|
286 |
+
* Encode and send appropriate headers and content
|
287 |
+
*
|
288 |
+
* This is a convenience method for common use of the class
|
289 |
+
*
|
290 |
+
* @param string $content
|
291 |
+
*
|
292 |
+
* @param int $compressionLevel given to zlib functions. If not given, the
|
293 |
+
* class default will be used.
|
294 |
+
*
|
295 |
+
* @return bool success true if the content was actually compressed
|
296 |
+
*/
|
297 |
+
public static function output($content, $compressionLevel = null)
|
298 |
+
{
|
299 |
+
if (null === $compressionLevel) {
|
300 |
+
$compressionLevel = self::$compressionLevel;
|
301 |
+
}
|
302 |
+
$he = new HTTP_Encoder(array('content' => $content));
|
303 |
+
$ret = $he->encode($compressionLevel);
|
304 |
+
$he->sendAll();
|
305 |
+
return $ret;
|
306 |
+
}
|
307 |
+
|
308 |
+
/**
|
309 |
+
* Is the browser an IE version earlier than 6 SP2?
|
310 |
+
*
|
311 |
+
* @return bool
|
312 |
+
*/
|
313 |
+
public static function isBuggyIe()
|
314 |
+
{
|
315 |
+
if (empty($_SERVER['HTTP_USER_AGENT'])) {
|
316 |
+
return false;
|
317 |
+
}
|
318 |
+
$ua = $_SERVER['HTTP_USER_AGENT'];
|
319 |
+
// quick escape for non-IEs
|
320 |
+
if (0 !== strpos($ua, 'Mozilla/4.0 (compatible; MSIE ')
|
321 |
+
|| false !== strpos($ua, 'Opera')) {
|
322 |
+
return false;
|
323 |
+
}
|
324 |
+
// no regex = faaast
|
325 |
+
$version = (float)substr($ua, 30);
|
326 |
+
return self::$encodeToIe6
|
327 |
+
? ($version < 6 || ($version == 6 && false === strpos($ua, 'SV1')))
|
328 |
+
: ($version < 7);
|
329 |
+
}
|
330 |
+
|
331 |
+
protected $_content = '';
|
332 |
+
protected $_headers = array();
|
333 |
+
protected $_encodeMethod = array('', '');
|
334 |
+
protected $_useMbStrlen = false;
|
335 |
+
}
|
includes/min/lib/JSMin.php
ADDED
@@ -0,0 +1,437 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* JSMin.php - modified PHP implementation of Douglas Crockford's JSMin.
|
4 |
+
*
|
5 |
+
* <code>
|
6 |
+
* $minifiedJs = JSMin::minify($js);
|
7 |
+
* </code>
|
8 |
+
*
|
9 |
+
* This is a modified port of jsmin.c. Improvements:
|
10 |
+
*
|
11 |
+
* Does not choke on some regexp literals containing quote characters. E.g. /'/
|
12 |
+
*
|
13 |
+
* Spaces are preserved after some add/sub operators, so they are not mistakenly
|
14 |
+
* converted to post-inc/dec. E.g. a + ++b -> a+ ++b
|
15 |
+
*
|
16 |
+
* Preserves multi-line comments that begin with /*!
|
17 |
+
*
|
18 |
+
* PHP 5 or higher is required.
|
19 |
+
*
|
20 |
+
* Permission is hereby granted to use this version of the library under the
|
21 |
+
* same terms as jsmin.c, which has the following license:
|
22 |
+
*
|
23 |
+
* --
|
24 |
+
* Copyright (c) 2002 Douglas Crockford (www.crockford.com)
|
25 |
+
*
|
26 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
27 |
+
* this software and associated documentation files (the "Software"), to deal in
|
28 |
+
* the Software without restriction, including without limitation the rights to
|
29 |
+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
30 |
+
* of the Software, and to permit persons to whom the Software is furnished to do
|
31 |
+
* so, subject to the following conditions:
|
32 |
+
*
|
33 |
+
* The above copyright notice and this permission notice shall be included in all
|
34 |
+
* copies or substantial portions of the Software.
|
35 |
+
*
|
36 |
+
* The Software shall be used for Good, not Evil.
|
37 |
+
*
|
38 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
39 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
40 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
41 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
42 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
43 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
44 |
+
* SOFTWARE.
|
45 |
+
* --
|
46 |
+
*
|
47 |
+
* @package JSMin
|
48 |
+
* @author Ryan Grove <ryan@wonko.com> (PHP port)
|
49 |
+
* @author Steve Clay <steve@mrclay.org> (modifications + cleanup)
|
50 |
+
* @author Andrea Giammarchi <http://www.3site.eu> (spaceBeforeRegExp)
|
51 |
+
* @copyright 2002 Douglas Crockford <douglas@crockford.com> (jsmin.c)
|
52 |
+
* @copyright 2008 Ryan Grove <ryan@wonko.com> (PHP port)
|
53 |
+
* @license http://opensource.org/licenses/mit-license.php MIT License
|
54 |
+
* @link http://code.google.com/p/jsmin-php/
|
55 |
+
*/
|
56 |
+
|
57 |
+
class JSMin {
|
58 |
+
const ORD_LF = 10;
|
59 |
+
const ORD_SPACE = 32;
|
60 |
+
const ACTION_KEEP_A = 1;
|
61 |
+
const ACTION_DELETE_A = 2;
|
62 |
+
const ACTION_DELETE_A_B = 3;
|
63 |
+
|
64 |
+
protected $a = "\n";
|
65 |
+
protected $b = '';
|
66 |
+
protected $input = '';
|
67 |
+
protected $inputIndex = 0;
|
68 |
+
protected $inputLength = 0;
|
69 |
+
protected $lookAhead = null;
|
70 |
+
protected $output = '';
|
71 |
+
protected $lastByteOut = '';
|
72 |
+
protected $keptComment = '';
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Minify Javascript.
|
76 |
+
*
|
77 |
+
* @param string $js Javascript to be minified
|
78 |
+
*
|
79 |
+
* @return string
|
80 |
+
*/
|
81 |
+
public static function minify($js)
|
82 |
+
{
|
83 |
+
$jsmin = new JSMin($js);
|
84 |
+
return $jsmin->min();
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* @param string $input
|
89 |
+
*/
|
90 |
+
public function __construct($input)
|
91 |
+
{
|
92 |
+
$this->input = $input;
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Perform minification, return result
|
97 |
+
*
|
98 |
+
* @return string
|
99 |
+
*/
|
100 |
+
public function min()
|
101 |
+
{
|
102 |
+
if ($this->output !== '') { // min already run
|
103 |
+
return $this->output;
|
104 |
+
}
|
105 |
+
|
106 |
+
$mbIntEnc = null;
|
107 |
+
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
|
108 |
+
$mbIntEnc = mb_internal_encoding();
|
109 |
+
mb_internal_encoding('8bit');
|
110 |
+
}
|
111 |
+
$this->input = str_replace("\r\n", "\n", $this->input);
|
112 |
+
$this->inputLength = strlen($this->input);
|
113 |
+
|
114 |
+
$this->action(self::ACTION_DELETE_A_B);
|
115 |
+
|
116 |
+
while ($this->a !== null) {
|
117 |
+
// determine next command
|
118 |
+
$command = self::ACTION_KEEP_A; // default
|
119 |
+
if ($this->a === ' ') {
|
120 |
+
if (($this->lastByteOut === '+' || $this->lastByteOut === '-')
|
121 |
+
&& ($this->b === $this->lastByteOut)) {
|
122 |
+
// Don't delete this space. If we do, the addition/subtraction
|
123 |
+
// could be parsed as a post-increment
|
124 |
+
} elseif (! $this->isAlphaNum($this->b)) {
|
125 |
+
$command = self::ACTION_DELETE_A;
|
126 |
+
}
|
127 |
+
} elseif ($this->a === "\n") {
|
128 |
+
if ($this->b === ' ') {
|
129 |
+
$command = self::ACTION_DELETE_A_B;
|
130 |
+
|
131 |
+
// in case of mbstring.func_overload & 2, must check for null b,
|
132 |
+
// otherwise mb_strpos will give WARNING
|
133 |
+
} elseif ($this->b === null
|
134 |
+
|| (false === strpos('{[(+-!~', $this->b)
|
135 |
+
&& ! $this->isAlphaNum($this->b))) {
|
136 |
+
$command = self::ACTION_DELETE_A;
|
137 |
+
}
|
138 |
+
} elseif (! $this->isAlphaNum($this->a)) {
|
139 |
+
if ($this->b === ' '
|
140 |
+
|| ($this->b === "\n"
|
141 |
+
&& (false === strpos('}])+-"\'', $this->a)))) {
|
142 |
+
$command = self::ACTION_DELETE_A_B;
|
143 |
+
}
|
144 |
+
}
|
145 |
+
$this->action($command);
|
146 |
+
}
|
147 |
+
$this->output = trim($this->output);
|
148 |
+
|
149 |
+
if ($mbIntEnc !== null) {
|
150 |
+
mb_internal_encoding($mbIntEnc);
|
151 |
+
}
|
152 |
+
return $this->output;
|
153 |
+
}
|
154 |
+
|
155 |
+
/**
|
156 |
+
* ACTION_KEEP_A = Output A. Copy B to A. Get the next B.
|
157 |
+
* ACTION_DELETE_A = Copy B to A. Get the next B.
|
158 |
+
* ACTION_DELETE_A_B = Get the next B.
|
159 |
+
*
|
160 |
+
* @param int $command
|
161 |
+
* @throws JSMin_UnterminatedRegExpException|JSMin_UnterminatedStringException
|
162 |
+
*/
|
163 |
+
protected function action($command)
|
164 |
+
{
|
165 |
+
// make sure we don't compress "a + ++b" to "a+++b", etc.
|
166 |
+
if ($command === self::ACTION_DELETE_A_B
|
167 |
+
&& $this->b === ' '
|
168 |
+
&& ($this->a === '+' || $this->a === '-')) {
|
169 |
+
// Note: we're at an addition/substraction operator; the inputIndex
|
170 |
+
// will certainly be a valid index
|
171 |
+
if ($this->input[$this->inputIndex] === $this->a) {
|
172 |
+
// This is "+ +" or "- -". Don't delete the space.
|
173 |
+
$command = self::ACTION_KEEP_A;
|
174 |
+
}
|
175 |
+
}
|
176 |
+
|
177 |
+
switch ($command) {
|
178 |
+
case self::ACTION_KEEP_A: // 1
|
179 |
+
$this->output .= $this->a;
|
180 |
+
|
181 |
+
if ($this->keptComment) {
|
182 |
+
$this->output = rtrim($this->output, "\n");
|
183 |
+
$this->output .= $this->keptComment;
|
184 |
+
$this->keptComment = '';
|
185 |
+
}
|
186 |
+
|
187 |
+
$this->lastByteOut = $this->a;
|
188 |
+
|
189 |
+
// fallthrough intentional
|
190 |
+
case self::ACTION_DELETE_A: // 2
|
191 |
+
$this->a = $this->b;
|
192 |
+
if ($this->a === "'" || $this->a === '"') { // string literal
|
193 |
+
$str = $this->a; // in case needed for exception
|
194 |
+
for(;;) {
|
195 |
+
$this->output .= $this->a;
|
196 |
+
$this->lastByteOut = $this->a;
|
197 |
+
|
198 |
+
$this->a = $this->get();
|
199 |
+
if ($this->a === $this->b) { // end quote
|
200 |
+
break;
|
201 |
+
}
|
202 |
+
if ($this->isEOF($this->a)) {
|
203 |
+
throw new JSMin_UnterminatedStringException(
|
204 |
+
"JSMin: Unterminated String at byte {$this->inputIndex}: {$str}");
|
205 |
+
}
|
206 |
+
$str .= $this->a;
|
207 |
+
if ($this->a === '\\') {
|
208 |
+
$this->output .= $this->a;
|
209 |
+
$this->lastByteOut = $this->a;
|
210 |
+
|
211 |
+
$this->a = $this->get();
|
212 |
+
$str .= $this->a;
|
213 |
+
}
|
214 |
+
}
|
215 |
+
}
|
216 |
+
|
217 |
+
// fallthrough intentional
|
218 |
+
case self::ACTION_DELETE_A_B: // 3
|
219 |
+
$this->b = $this->next();
|
220 |
+
if ($this->b === '/' && $this->isRegexpLiteral()) {
|
221 |
+
$this->output .= $this->a . $this->b;
|
222 |
+
$pattern = '/'; // keep entire pattern in case we need to report it in the exception
|
223 |
+
for(;;) {
|
224 |
+
$this->a = $this->get();
|
225 |
+
$pattern .= $this->a;
|
226 |
+
if ($this->a === '[') {
|
227 |
+
for(;;) {
|
228 |
+
$this->output .= $this->a;
|
229 |
+
$this->a = $this->get();
|
230 |
+
$pattern .= $this->a;
|
231 |
+
if ($this->a === ']') {
|
232 |
+
break;
|
233 |
+
}
|
234 |
+
if ($this->a === '\\') {
|
235 |
+
$this->output .= $this->a;
|
236 |
+
$this->a = $this->get();
|
237 |
+
$pattern .= $this->a;
|
238 |
+
}
|
239 |
+
if ($this->isEOF($this->a)) {
|
240 |
+
throw new JSMin_UnterminatedRegExpException(
|
241 |
+
"JSMin: Unterminated set in RegExp at byte "
|
242 |
+
. $this->inputIndex .": {$pattern}");
|
243 |
+
}
|
244 |
+
}
|
245 |
+
}
|
246 |
+
|
247 |
+
if ($this->a === '/') { // end pattern
|
248 |
+
break; // while (true)
|
249 |
+
} elseif ($this->a === '\\') {
|
250 |
+
$this->output .= $this->a;
|
251 |
+
$this->a = $this->get();
|
252 |
+
$pattern .= $this->a;
|
253 |
+
} elseif ($this->isEOF($this->a)) {
|
254 |
+
throw new JSMin_UnterminatedRegExpException(
|
255 |
+
"JSMin: Unterminated RegExp at byte {$this->inputIndex}: {$pattern}");
|
256 |
+
}
|
257 |
+
$this->output .= $this->a;
|
258 |
+
$this->lastByteOut = $this->a;
|
259 |
+
}
|
260 |
+
$this->b = $this->next();
|
261 |
+
}
|
262 |
+
// end case ACTION_DELETE_A_B
|
263 |
+
}
|
264 |
+
}
|
265 |
+
|
266 |
+
/**
|
267 |
+
* @return bool
|
268 |
+
*/
|
269 |
+
protected function isRegexpLiteral()
|
270 |
+
{
|
271 |
+
if (false !== strpos("(,=:[!&|?+-~*{;", $this->a)) {
|
272 |
+
// we obviously aren't dividing
|
273 |
+
return true;
|
274 |
+
}
|
275 |
+
if ($this->a === ' ' || $this->a === "\n") {
|
276 |
+
$length = strlen($this->output);
|
277 |
+
if ($length < 2) { // weird edge case
|
278 |
+
return true;
|
279 |
+
}
|
280 |
+
// you can't divide a keyword
|
281 |
+
if (preg_match('/(?:case|else|in|return|typeof)$/', $this->output, $m)) {
|
282 |
+
if ($this->output === $m[0]) { // odd but could happen
|
283 |
+
return true;
|
284 |
+
}
|
285 |
+
// make sure it's a keyword, not end of an identifier
|
286 |
+
$charBeforeKeyword = substr($this->output, $length - strlen($m[0]) - 1, 1);
|
287 |
+
if (! $this->isAlphaNum($charBeforeKeyword)) {
|
288 |
+
return true;
|
289 |
+
}
|
290 |
+
}
|
291 |
+
}
|
292 |
+
return false;
|
293 |
+
}
|
294 |
+
|
295 |
+
/**
|
296 |
+
* Return the next character from stdin. Watch out for lookahead. If the character is a control character,
|
297 |
+
* translate it to a space or linefeed.
|
298 |
+
*
|
299 |
+
* @return string
|
300 |
+
*/
|
301 |
+
protected function get()
|
302 |
+
{
|
303 |
+
$c = $this->lookAhead;
|
304 |
+
$this->lookAhead = null;
|
305 |
+
if ($c === null) {
|
306 |
+
// getc(stdin)
|
307 |
+
if ($this->inputIndex < $this->inputLength) {
|
308 |
+
$c = $this->input[$this->inputIndex];
|
309 |
+
$this->inputIndex += 1;
|
310 |
+
} else {
|
311 |
+
$c = null;
|
312 |
+
}
|
313 |
+
}
|
314 |
+
if (ord($c) >= self::ORD_SPACE || $c === "\n" || $c === null) {
|
315 |
+
return $c;
|
316 |
+
}
|
317 |
+
if ($c === "\r") {
|
318 |
+
return "\n";
|
319 |
+
}
|
320 |
+
return ' ';
|
321 |
+
}
|
322 |
+
|
323 |
+
/**
|
324 |
+
* Does $a indicate end of input?
|
325 |
+
*
|
326 |
+
* @param string $a
|
327 |
+
* @return bool
|
328 |
+
*/
|
329 |
+
protected function isEOF($a)
|
330 |
+
{
|
331 |
+
return ord($a) <= self::ORD_LF;
|
332 |
+
}
|
333 |
+
|
334 |
+
/**
|
335 |
+
* Get next char (without getting it). If is ctrl character, translate to a space or newline.
|
336 |
+
*
|
337 |
+
* @return string
|
338 |
+
*/
|
339 |
+
protected function peek()
|
340 |
+
{
|
341 |
+
$this->lookAhead = $this->get();
|
342 |
+
return $this->lookAhead;
|
343 |
+
}
|
344 |
+
|
345 |
+
/**
|
346 |
+
* Return true if the character is a letter, digit, underscore, dollar sign, or non-ASCII character.
|
347 |
+
*
|
348 |
+
* @param string $c
|
349 |
+
*
|
350 |
+
* @return bool
|
351 |
+
*/
|
352 |
+
protected function isAlphaNum($c)
|
353 |
+
{
|
354 |
+
return (preg_match('/^[a-z0-9A-Z_\\$\\\\]$/', $c) || ord($c) > 126);
|
355 |
+
}
|
356 |
+
|
357 |
+
/**
|
358 |
+
* Consume a single line comment from input (possibly retaining it)
|
359 |
+
*/
|
360 |
+
protected function consumeSingleLineComment()
|
361 |
+
{
|
362 |
+
$comment = '';
|
363 |
+
while (true) {
|
364 |
+
$get = $this->get();
|
365 |
+
$comment .= $get;
|
366 |
+
if (ord($get) <= self::ORD_LF) { // end of line reached
|
367 |
+
// if IE conditional comment
|
368 |
+
if (preg_match('/^\\/@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
|
369 |
+
$this->keptComment .= "/{$comment}";
|
370 |
+
}
|
371 |
+
return;
|
372 |
+
}
|
373 |
+
}
|
374 |
+
}
|
375 |
+
|
376 |
+
/**
|
377 |
+
* Consume a multiple line comment from input (possibly retaining it)
|
378 |
+
*
|
379 |
+
* @throws JSMin_UnterminatedCommentException
|
380 |
+
*/
|
381 |
+
protected function consumeMultipleLineComment()
|
382 |
+
{
|
383 |
+
$this->get();
|
384 |
+
$comment = '';
|
385 |
+
for(;;) {
|
386 |
+
$get = $this->get();
|
387 |
+
if ($get === '*') {
|
388 |
+
if ($this->peek() === '/') { // end of comment reached
|
389 |
+
$this->get();
|
390 |
+
if (0 === strpos($comment, '!')) {
|
391 |
+
// preserved by YUI Compressor
|
392 |
+
if (!$this->keptComment) {
|
393 |
+
// don't prepend a newline if two comments right after one another
|
394 |
+
$this->keptComment = "\n";
|
395 |
+
}
|
396 |
+
$this->keptComment .= "/*!" . substr($comment, 1) . "*/\n";
|
397 |
+
} else if (preg_match('/^@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
|
398 |
+
// IE conditional
|
399 |
+
$this->keptComment .= "/*{$comment}*/";
|
400 |
+
}
|
401 |
+
return;
|
402 |
+
}
|
403 |
+
} elseif ($get === null) {
|
404 |
+
throw new JSMin_UnterminatedCommentException(
|
405 |
+
"JSMin: Unterminated comment at byte {$this->inputIndex}: /*{$comment}");
|
406 |
+
}
|
407 |
+
$comment .= $get;
|
408 |
+
}
|
409 |
+
}
|
410 |
+
|
411 |
+
/**
|
412 |
+
* Get the next character, skipping over comments. Some comments may be preserved.
|
413 |
+
*
|
414 |
+
* @return string
|
415 |
+
*/
|
416 |
+
protected function next()
|
417 |
+
{
|
418 |
+
$get = $this->get();
|
419 |
+
if ($get === '/') {
|
420 |
+
switch ($this->peek()) {
|
421 |
+
case '/':
|
422 |
+
$this->consumeSingleLineComment();
|
423 |
+
$get = "\n";
|
424 |
+
break;
|
425 |
+
case '*':
|
426 |
+
$this->consumeMultipleLineComment();
|
427 |
+
$get = ' ';
|
428 |
+
break;
|
429 |
+
}
|
430 |
+
}
|
431 |
+
return $get;
|
432 |
+
}
|
433 |
+
}
|
434 |
+
|
435 |
+
class JSMin_UnterminatedStringException extends Exception {}
|
436 |
+
class JSMin_UnterminatedCommentException extends Exception {}
|
437 |
+
class JSMin_UnterminatedRegExpException extends Exception {}
|
includes/min/lib/JSMinPlus.php
ADDED
@@ -0,0 +1,2086 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* JSMinPlus version 1.4
|
5 |
+
*
|
6 |
+
* Minifies a javascript file using a javascript parser
|
7 |
+
*
|
8 |
+
* This implements a PHP port of Brendan Eich's Narcissus open source javascript engine (in javascript)
|
9 |
+
* References: http://en.wikipedia.org/wiki/Narcissus_(JavaScript_engine)
|
10 |
+
* Narcissus sourcecode: http://mxr.mozilla.org/mozilla/source/js/narcissus/
|
11 |
+
* JSMinPlus weblog: http://crisp.tweakblogs.net/blog/cat/716
|
12 |
+
*
|
13 |
+
* Tino Zijdel <crisp@tweakers.net>
|
14 |
+
*
|
15 |
+
* Usage: $minified = JSMinPlus::minify($script [, $filename])
|
16 |
+
*
|
17 |
+
* Versionlog (see also changelog.txt):
|
18 |
+
* 23-07-2011 - remove dynamic creation of OP_* and KEYWORD_* defines and declare them on top
|
19 |
+
* reduce memory footprint by minifying by block-scope
|
20 |
+
* some small byte-saving and performance improvements
|
21 |
+
* 12-05-2009 - fixed hook:colon precedence, fixed empty body in loop and if-constructs
|
22 |
+
* 18-04-2009 - fixed crashbug in PHP 5.2.9 and several other bugfixes
|
23 |
+
* 12-04-2009 - some small bugfixes and performance improvements
|
24 |
+
* 09-04-2009 - initial open sourced version 1.0
|
25 |
+
*
|
26 |
+
* Latest version of this script: http://files.tweakers.net/jsminplus/jsminplus.zip
|
27 |
+
*
|
28 |
+
*/
|
29 |
+
|
30 |
+
/* ***** BEGIN LICENSE BLOCK *****
|
31 |
+
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
32 |
+
*
|
33 |
+
* The contents of this file are subject to the Mozilla Public License Version
|
34 |
+
* 1.1 (the "License"); you may not use this file except in compliance with
|
35 |
+
* the License. You may obtain a copy of the License at
|
36 |
+
* http://www.mozilla.org/MPL/
|
37 |
+
*
|
38 |
+
* Software distributed under the License is distributed on an "AS IS" basis,
|
39 |
+
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
40 |
+
* for the specific language governing rights and limitations under the
|
41 |
+
* License.
|
42 |
+
*
|
43 |
+
* The Original Code is the Narcissus JavaScript engine.
|
44 |
+
*
|
45 |
+
* The Initial Developer of the Original Code is
|
46 |
+
* Brendan Eich <brendan@mozilla.org>.
|
47 |
+
* Portions created by the Initial Developer are Copyright (C) 2004
|
48 |
+
* the Initial Developer. All Rights Reserved.
|
49 |
+
*
|
50 |
+
* Contributor(s): Tino Zijdel <crisp@tweakers.net>
|
51 |
+
* PHP port, modifications and minifier routine are (C) 2009-2011
|
52 |
+
*
|
53 |
+
* Alternatively, the contents of this file may be used under the terms of
|
54 |
+
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
55 |
+
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
56 |
+
* in which case the provisions of the GPL or the LGPL are applicable instead
|
57 |
+
* of those above. If you wish to allow use of your version of this file only
|
58 |
+
* under the terms of either the GPL or the LGPL, and not to allow others to
|
59 |
+
* use your version of this file under the terms of the MPL, indicate your
|
60 |
+
* decision by deleting the provisions above and replace them with the notice
|
61 |
+
* and other provisions required by the GPL or the LGPL. If you do not delete
|
62 |
+
* the provisions above, a recipient may use your version of this file under
|
63 |
+
* the terms of any one of the MPL, the GPL or the LGPL.
|
64 |
+
*
|
65 |
+
* ***** END LICENSE BLOCK ***** */
|
66 |
+
|
67 |
+
define('TOKEN_END', 1);
|
68 |
+
define('TOKEN_NUMBER', 2);
|
69 |
+
define('TOKEN_IDENTIFIER', 3);
|
70 |
+
define('TOKEN_STRING', 4);
|
71 |
+
define('TOKEN_REGEXP', 5);
|
72 |
+
define('TOKEN_NEWLINE', 6);
|
73 |
+
define('TOKEN_CONDCOMMENT_START', 7);
|
74 |
+
define('TOKEN_CONDCOMMENT_END', 8);
|
75 |
+
|
76 |
+
define('JS_SCRIPT', 100);
|
77 |
+
define('JS_BLOCK', 101);
|
78 |
+
define('JS_LABEL', 102);
|
79 |
+
define('JS_FOR_IN', 103);
|
80 |
+
define('JS_CALL', 104);
|
81 |
+
define('JS_NEW_WITH_ARGS', 105);
|
82 |
+
define('JS_INDEX', 106);
|
83 |
+
define('JS_ARRAY_INIT', 107);
|
84 |
+
define('JS_OBJECT_INIT', 108);
|
85 |
+
define('JS_PROPERTY_INIT', 109);
|
86 |
+
define('JS_GETTER', 110);
|
87 |
+
define('JS_SETTER', 111);
|
88 |
+
define('JS_GROUP', 112);
|
89 |
+
define('JS_LIST', 113);
|
90 |
+
|
91 |
+
define('JS_MINIFIED', 999);
|
92 |
+
|
93 |
+
define('DECLARED_FORM', 0);
|
94 |
+
define('EXPRESSED_FORM', 1);
|
95 |
+
define('STATEMENT_FORM', 2);
|
96 |
+
|
97 |
+
/* Operators */
|
98 |
+
define('OP_SEMICOLON', ';');
|
99 |
+
define('OP_COMMA', ',');
|
100 |
+
define('OP_HOOK', '?');
|
101 |
+
define('OP_COLON', ':');
|
102 |
+
define('OP_OR', '||');
|
103 |
+
define('OP_AND', '&&');
|
104 |
+
define('OP_BITWISE_OR', '|');
|
105 |
+
define('OP_BITWISE_XOR', '^');
|
106 |
+
define('OP_BITWISE_AND', '&');
|
107 |
+
define('OP_STRICT_EQ', '===');
|
108 |
+
define('OP_EQ', '==');
|
109 |
+
define('OP_ASSIGN', '=');
|
110 |
+
define('OP_STRICT_NE', '!==');
|
111 |
+
define('OP_NE', '!=');
|
112 |
+
define('OP_LSH', '<<');
|
113 |
+
define('OP_LE', '<=');
|
114 |
+
define('OP_LT', '<');
|
115 |
+
define('OP_URSH', '>>>');
|
116 |
+
define('OP_RSH', '>>');
|
117 |
+
define('OP_GE', '>=');
|
118 |
+
define('OP_GT', '>');
|
119 |
+
define('OP_INCREMENT', '++');
|
120 |
+
define('OP_DECREMENT', '--');
|
121 |
+
define('OP_PLUS', '+');
|
122 |
+
define('OP_MINUS', '-');
|
123 |
+
define('OP_MUL', '*');
|
124 |
+
define('OP_DIV', '/');
|
125 |
+
define('OP_MOD', '%');
|
126 |
+
define('OP_NOT', '!');
|
127 |
+
define('OP_BITWISE_NOT', '~');
|
128 |
+
define('OP_DOT', '.');
|
129 |
+
define('OP_LEFT_BRACKET', '[');
|
130 |
+
define('OP_RIGHT_BRACKET', ']');
|
131 |
+
define('OP_LEFT_CURLY', '{');
|
132 |
+
define('OP_RIGHT_CURLY', '}');
|
133 |
+
define('OP_LEFT_PAREN', '(');
|
134 |
+
define('OP_RIGHT_PAREN', ')');
|
135 |
+
define('OP_CONDCOMMENT_END', '@*/');
|
136 |
+
|
137 |
+
define('OP_UNARY_PLUS', 'U+');
|
138 |
+
define('OP_UNARY_MINUS', 'U-');
|
139 |
+
|
140 |
+
/* Keywords */
|
141 |
+
define('KEYWORD_BREAK', 'break');
|
142 |
+
define('KEYWORD_CASE', 'case');
|
143 |
+
define('KEYWORD_CATCH', 'catch');
|
144 |
+
define('KEYWORD_CONST', 'const');
|
145 |
+
define('KEYWORD_CONTINUE', 'continue');
|
146 |
+
define('KEYWORD_DEBUGGER', 'debugger');
|
147 |
+
define('KEYWORD_DEFAULT', 'default');
|
148 |
+
define('KEYWORD_DELETE', 'delete');
|
149 |
+
define('KEYWORD_DO', 'do');
|
150 |
+
define('KEYWORD_ELSE', 'else');
|
151 |
+
define('KEYWORD_ENUM', 'enum');
|
152 |
+
define('KEYWORD_FALSE', 'false');
|
153 |
+
define('KEYWORD_FINALLY', 'finally');
|
154 |
+
define('KEYWORD_FOR', 'for');
|
155 |
+
define('KEYWORD_FUNCTION', 'function');
|
156 |
+
define('KEYWORD_IF', 'if');
|
157 |
+
define('KEYWORD_IN', 'in');
|
158 |
+
define('KEYWORD_INSTANCEOF', 'instanceof');
|
159 |
+
define('KEYWORD_NEW', 'new');
|
160 |
+
define('KEYWORD_NULL', 'null');
|
161 |
+
define('KEYWORD_RETURN', 'return');
|
162 |
+
define('KEYWORD_SWITCH', 'switch');
|
163 |
+
define('KEYWORD_THIS', 'this');
|
164 |
+
define('KEYWORD_THROW', 'throw');
|
165 |
+
define('KEYWORD_TRUE', 'true');
|
166 |
+
define('KEYWORD_TRY', 'try');
|
167 |
+
define('KEYWORD_TYPEOF', 'typeof');
|
168 |
+
define('KEYWORD_VAR', 'var');
|
169 |
+
define('KEYWORD_VOID', 'void');
|
170 |
+
define('KEYWORD_WHILE', 'while');
|
171 |
+
define('KEYWORD_WITH', 'with');
|
172 |
+
|
173 |
+
|
174 |
+
class JSMinPlus
|
175 |
+
{
|
176 |
+
private $parser;
|
177 |
+
private $reserved = array(
|
178 |
+
'break', 'case', 'catch', 'continue', 'default', 'delete', 'do',
|
179 |
+
'else', 'finally', 'for', 'function', 'if', 'in', 'instanceof',
|
180 |
+
'new', 'return', 'switch', 'this', 'throw', 'try', 'typeof', 'var',
|
181 |
+
'void', 'while', 'with',
|
182 |
+
// Words reserved for future use
|
183 |
+
'abstract', 'boolean', 'byte', 'char', 'class', 'const', 'debugger',
|
184 |
+
'double', 'enum', 'export', 'extends', 'final', 'float', 'goto',
|
185 |
+
'implements', 'import', 'int', 'interface', 'long', 'native',
|
186 |
+
'package', 'private', 'protected', 'public', 'short', 'static',
|
187 |
+
'super', 'synchronized', 'throws', 'transient', 'volatile',
|
188 |
+
// These are not reserved, but should be taken into account
|
189 |
+
// in isValidIdentifier (See jslint source code)
|
190 |
+
'arguments', 'eval', 'true', 'false', 'Infinity', 'NaN', 'null', 'undefined'
|
191 |
+
);
|
192 |
+
|
193 |
+
private function __construct()
|
194 |
+
{
|
195 |
+
$this->parser = new JSParser($this);
|
196 |
+
}
|
197 |
+
|
198 |
+
public static function minify($js, $filename='')
|
199 |
+
{
|
200 |
+
static $instance;
|
201 |
+
|
202 |
+
// this is a singleton
|
203 |
+
if(!$instance)
|
204 |
+
$instance = new JSMinPlus();
|
205 |
+
|
206 |
+
return $instance->min($js, $filename);
|
207 |
+
}
|
208 |
+
|
209 |
+
private function min($js, $filename)
|
210 |
+
{
|
211 |
+
try
|
212 |
+
{
|
213 |
+
$n = $this->parser->parse($js, $filename, 1);
|
214 |
+
return $this->parseTree($n);
|
215 |
+
}
|
216 |
+
catch(Exception $e)
|
217 |
+
{
|
218 |
+
echo $e->getMessage() . "\n";
|
219 |
+
}
|
220 |
+
|
221 |
+
return false;
|
222 |
+
}
|
223 |
+
|
224 |
+
public function parseTree($n, $noBlockGrouping = false)
|
225 |
+
{
|
226 |
+
$s = '';
|
227 |
+
|
228 |
+
switch ($n->type)
|
229 |
+
{
|
230 |
+
case JS_MINIFIED:
|
231 |
+
$s = $n->value;
|
232 |
+
break;
|
233 |
+
|
234 |
+
case JS_SCRIPT:
|
235 |
+
// we do nothing yet with funDecls or varDecls
|
236 |
+
$noBlockGrouping = true;
|
237 |
+
// FALL THROUGH
|
238 |
+
|
239 |
+
case JS_BLOCK:
|
240 |
+
$childs = $n->treeNodes;
|
241 |
+
$lastType = 0;
|
242 |
+
for ($c = 0, $i = 0, $j = count($childs); $i < $j; $i++)
|
243 |
+
{
|
244 |
+
$type = $childs[$i]->type;
|
245 |
+
$t = $this->parseTree($childs[$i]);
|
246 |
+
if (strlen($t))
|
247 |
+
{
|
248 |
+
if ($c)
|
249 |
+
{
|
250 |
+
$s = rtrim($s, ';');
|
251 |
+
|
252 |
+
if ($type == KEYWORD_FUNCTION && $childs[$i]->functionForm == DECLARED_FORM)
|
253 |
+
{
|
254 |
+
// put declared functions on a new line
|
255 |
+
$s .= "\n";
|
256 |
+
}
|
257 |
+
elseif ($type == KEYWORD_VAR && $type == $lastType)
|
258 |
+
{
|
259 |
+
// mutiple var-statements can go into one
|
260 |
+
$t = ',' . substr($t, 4);
|
261 |
+
}
|
262 |
+
else
|
263 |
+
{
|
264 |
+
// add terminator
|
265 |
+
$s .= ';';
|
266 |
+
}
|
267 |
+
}
|
268 |
+
|
269 |
+
$s .= $t;
|
270 |
+
|
271 |
+
$c++;
|
272 |
+
$lastType = $type;
|
273 |
+
}
|
274 |
+
}
|
275 |
+
|
276 |
+
if ($c > 1 && !$noBlockGrouping)
|
277 |
+
{
|
278 |
+
$s = '{' . $s . '}';
|
279 |
+
}
|
280 |
+
break;
|
281 |
+
|
282 |
+
case KEYWORD_FUNCTION:
|
283 |
+
$s .= 'function' . ($n->name ? ' ' . $n->name : '') . '(';
|
284 |
+
$params = $n->params;
|
285 |
+
for ($i = 0, $j = count($params); $i < $j; $i++)
|
286 |
+
$s .= ($i ? ',' : '') . $params[$i];
|
287 |
+
$s .= '){' . $this->parseTree($n->body, true) . '}';
|
288 |
+
break;
|
289 |
+
|
290 |
+
case KEYWORD_IF:
|
291 |
+
$s = 'if(' . $this->parseTree($n->condition) . ')';
|
292 |
+
$thenPart = $this->parseTree($n->thenPart);
|
293 |
+
$elsePart = $n->elsePart ? $this->parseTree($n->elsePart) : null;
|
294 |
+
|
295 |
+
// empty if-statement
|
296 |
+
if ($thenPart == '')
|
297 |
+
$thenPart = ';';
|
298 |
+
|
299 |
+
if ($elsePart)
|
300 |
+
{
|
301 |
+
// be carefull and always make a block out of the thenPart; could be more optimized but is a lot of trouble
|
302 |
+
if ($thenPart != ';' && $thenPart[0] != '{')
|
303 |
+
$thenPart = '{' . $thenPart . '}';
|
304 |
+
|
305 |
+
$s .= $thenPart . 'else';
|
306 |
+
|
307 |
+
// we could check for more, but that hardly ever applies so go for performance
|
308 |
+
if ($elsePart[0] != '{')
|
309 |
+
$s .= ' ';
|
310 |
+
|
311 |
+
$s .= $elsePart;
|
312 |
+
}
|
313 |
+
else
|
314 |
+
{
|
315 |
+
$s .= $thenPart;
|
316 |
+
}
|
317 |
+
break;
|
318 |
+
|
319 |
+
case KEYWORD_SWITCH:
|
320 |
+
$s = 'switch(' . $this->parseTree($n->discriminant) . '){';
|
321 |
+
$cases = $n->cases;
|
322 |
+
for ($i = 0, $j = count($cases); $i < $j; $i++)
|
323 |
+
{
|
324 |
+
$case = $cases[$i];
|
325 |
+
if ($case->type == KEYWORD_CASE)
|
326 |
+
$s .= 'case' . ($case->caseLabel->type != TOKEN_STRING ? ' ' : '') . $this->parseTree($case->caseLabel) . ':';
|
327 |
+
else
|
328 |
+
$s .= 'default:';
|
329 |
+
|
330 |
+
$statement = $this->parseTree($case->statements, true);
|
331 |
+
if ($statement)
|
332 |
+
{
|
333 |
+
$s .= $statement;
|
334 |
+
// no terminator for last statement
|
335 |
+
if ($i + 1 < $j)
|
336 |
+
$s .= ';';
|
337 |
+
}
|
338 |
+
}
|
339 |
+
$s .= '}';
|
340 |
+
break;
|
341 |
+
|
342 |
+
case KEYWORD_FOR:
|
343 |
+
$s = 'for(' . ($n->setup ? $this->parseTree($n->setup) : '')
|
344 |
+
. ';' . ($n->condition ? $this->parseTree($n->condition) : '')
|
345 |
+
. ';' . ($n->update ? $this->parseTree($n->update) : '') . ')';
|
346 |
+
|
347 |
+
$body = $this->parseTree($n->body);
|
348 |
+
if ($body == '')
|
349 |
+
$body = ';';
|
350 |
+
|
351 |
+
$s .= $body;
|
352 |
+
break;
|
353 |
+
|
354 |
+
case KEYWORD_WHILE:
|
355 |
+
$s = 'while(' . $this->parseTree($n->condition) . ')';
|
356 |
+
|
357 |
+
$body = $this->parseTree($n->body);
|
358 |
+
if ($body == '')
|
359 |
+
$body = ';';
|
360 |
+
|
361 |
+
$s .= $body;
|
362 |
+
break;
|
363 |
+
|
364 |
+
case JS_FOR_IN:
|
365 |
+
$s = 'for(' . ($n->varDecl ? $this->parseTree($n->varDecl) : $this->parseTree($n->iterator)) . ' in ' . $this->parseTree($n->object) . ')';
|
366 |
+
|
367 |
+
$body = $this->parseTree($n->body);
|
368 |
+
if ($body == '')
|
369 |
+
$body = ';';
|
370 |
+
|
371 |
+
$s .= $body;
|
372 |
+
break;
|
373 |
+
|
374 |
+
case KEYWORD_DO:
|
375 |
+
$s = 'do{' . $this->parseTree($n->body, true) . '}while(' . $this->parseTree($n->condition) . ')';
|
376 |
+
break;
|
377 |
+
|
378 |
+
case KEYWORD_BREAK:
|
379 |
+
case KEYWORD_CONTINUE:
|
380 |
+
$s = $n->value . ($n->label ? ' ' . $n->label : '');
|
381 |
+
break;
|
382 |
+
|
383 |
+
case KEYWORD_TRY:
|
384 |
+
$s = 'try{' . $this->parseTree($n->tryBlock, true) . '}';
|
385 |
+
$catchClauses = $n->catchClauses;
|
386 |
+
for ($i = 0, $j = count($catchClauses); $i < $j; $i++)
|
387 |
+
{
|
388 |
+
$t = $catchClauses[$i];
|
389 |
+
$s .= 'catch(' . $t->varName . ($t->guard ? ' if ' . $this->parseTree($t->guard) : '') . '){' . $this->parseTree($t->block, true) . '}';
|
390 |
+
}
|
391 |
+
if ($n->finallyBlock)
|
392 |
+
$s .= 'finally{' . $this->parseTree($n->finallyBlock, true) . '}';
|
393 |
+
break;
|
394 |
+
|
395 |
+
case KEYWORD_THROW:
|
396 |
+
case KEYWORD_RETURN:
|
397 |
+
$s = $n->type;
|
398 |
+
if ($n->value)
|
399 |
+
{
|
400 |
+
$t = $this->parseTree($n->value);
|
401 |
+
if (strlen($t))
|
402 |
+
{
|
403 |
+
if ($this->isWordChar($t[0]) || $t[0] == '\\')
|
404 |
+
$s .= ' ';
|
405 |
+
|
406 |
+
$s .= $t;
|
407 |
+
}
|
408 |
+
}
|
409 |
+
break;
|
410 |
+
|
411 |
+
case KEYWORD_WITH:
|
412 |
+
$s = 'with(' . $this->parseTree($n->object) . ')' . $this->parseTree($n->body);
|
413 |
+
break;
|
414 |
+
|
415 |
+
case KEYWORD_VAR:
|
416 |
+
case KEYWORD_CONST:
|
417 |
+
$s = $n->value . ' ';
|
418 |
+
$childs = $n->treeNodes;
|
419 |
+
for ($i = 0, $j = count($childs); $i < $j; $i++)
|
420 |
+
{
|
421 |
+
$t = $childs[$i];
|
422 |
+
$s .= ($i ? ',' : '') . $t->name;
|
423 |
+
$u = $t->initializer;
|
424 |
+
if ($u)
|
425 |
+
$s .= '=' . $this->parseTree($u);
|
426 |
+
}
|
427 |
+
break;
|
428 |
+
|
429 |
+
case KEYWORD_IN:
|
430 |
+
case KEYWORD_INSTANCEOF:
|
431 |
+
$left = $this->parseTree($n->treeNodes[0]);
|
432 |
+
$right = $this->parseTree($n->treeNodes[1]);
|
433 |
+
|
434 |
+
$s = $left;
|
435 |
+
|
436 |
+
if ($this->isWordChar(substr($left, -1)))
|
437 |
+
$s .= ' ';
|
438 |
+
|
439 |
+
$s .= $n->type;
|
440 |
+
|
441 |
+
if ($this->isWordChar($right[0]) || $right[0] == '\\')
|
442 |
+
$s .= ' ';
|
443 |
+
|
444 |
+
$s .= $right;
|
445 |
+
break;
|
446 |
+
|
447 |
+
case KEYWORD_DELETE:
|
448 |
+
case KEYWORD_TYPEOF:
|
449 |
+
$right = $this->parseTree($n->treeNodes[0]);
|
450 |
+
|
451 |
+
$s = $n->type;
|
452 |
+
|
453 |
+
if ($this->isWordChar($right[0]) || $right[0] == '\\')
|
454 |
+
$s .= ' ';
|
455 |
+
|
456 |
+
$s .= $right;
|
457 |
+
break;
|
458 |
+
|
459 |
+
case KEYWORD_VOID:
|
460 |
+
$s = 'void(' . $this->parseTree($n->treeNodes[0]) . ')';
|
461 |
+
break;
|
462 |
+
|
463 |
+
case KEYWORD_DEBUGGER:
|
464 |
+
throw new Exception('NOT IMPLEMENTED: DEBUGGER');
|
465 |
+
break;
|
466 |
+
|
467 |
+
case TOKEN_CONDCOMMENT_START:
|
468 |
+
case TOKEN_CONDCOMMENT_END:
|
469 |
+
$s = $n->value . ($n->type == TOKEN_CONDCOMMENT_START ? ' ' : '');
|
470 |
+
$childs = $n->treeNodes;
|
471 |
+
for ($i = 0, $j = count($childs); $i < $j; $i++)
|
472 |
+
$s .= $this->parseTree($childs[$i]);
|
473 |
+
break;
|
474 |
+
|
475 |
+
case OP_SEMICOLON:
|
476 |
+
if ($expression = $n->expression)
|
477 |
+
$s = $this->parseTree($expression);
|
478 |
+
break;
|
479 |
+
|
480 |
+
case JS_LABEL:
|
481 |
+
$s = $n->label . ':' . $this->parseTree($n->statement);
|
482 |
+
break;
|
483 |
+
|
484 |
+
case OP_COMMA:
|
485 |
+
$childs = $n->treeNodes;
|
486 |
+
for ($i = 0, $j = count($childs); $i < $j; $i++)
|
487 |
+
$s .= ($i ? ',' : '') . $this->parseTree($childs[$i]);
|
488 |
+
break;
|
489 |
+
|
490 |
+
case OP_ASSIGN:
|
491 |
+
$s = $this->parseTree($n->treeNodes[0]) . $n->value . $this->parseTree($n->treeNodes[1]);
|
492 |
+
break;
|
493 |
+
|
494 |
+
case OP_HOOK:
|
495 |
+
$s = $this->parseTree($n->treeNodes[0]) . '?' . $this->parseTree($n->treeNodes[1]) . ':' . $this->parseTree($n->treeNodes[2]);
|
496 |
+
break;
|
497 |
+
|
498 |
+
case OP_OR: case OP_AND:
|
499 |
+
case OP_BITWISE_OR: case OP_BITWISE_XOR: case OP_BITWISE_AND:
|
500 |
+
case OP_EQ: case OP_NE: case OP_STRICT_EQ: case OP_STRICT_NE:
|
501 |
+
case OP_LT: case OP_LE: case OP_GE: case OP_GT:
|
502 |
+
case OP_LSH: case OP_RSH: case OP_URSH:
|
503 |
+
case OP_MUL: case OP_DIV: case OP_MOD:
|
504 |
+
$s = $this->parseTree($n->treeNodes[0]) . $n->type . $this->parseTree($n->treeNodes[1]);
|
505 |
+
break;
|
506 |
+
|
507 |
+
case OP_PLUS:
|
508 |
+
case OP_MINUS:
|
509 |
+
$left = $this->parseTree($n->treeNodes[0]);
|
510 |
+
$right = $this->parseTree($n->treeNodes[1]);
|
511 |
+
|
512 |
+
switch ($n->treeNodes[1]->type)
|
513 |
+
{
|
514 |
+
case OP_PLUS:
|
515 |
+
case OP_MINUS:
|
516 |
+
case OP_INCREMENT:
|
517 |
+
case OP_DECREMENT:
|
518 |
+
case OP_UNARY_PLUS:
|
519 |
+
case OP_UNARY_MINUS:
|
520 |
+
$s = $left . $n->type . ' ' . $right;
|
521 |
+
break;
|
522 |
+
|
523 |
+
case TOKEN_STRING:
|
524 |
+
//combine concatted strings with same quotestyle
|
525 |
+
if ($n->type == OP_PLUS && substr($left, -1) == $right[0])
|
526 |
+
{
|
527 |
+
$s = substr($left, 0, -1) . substr($right, 1);
|
528 |
+
break;
|
529 |
+
}
|
530 |
+
// FALL THROUGH
|
531 |
+
|
532 |
+
default:
|
533 |
+
$s = $left . $n->type . $right;
|
534 |
+
}
|
535 |
+
break;
|
536 |
+
|
537 |
+
case OP_NOT:
|
538 |
+
case OP_BITWISE_NOT:
|
539 |
+
case OP_UNARY_PLUS:
|
540 |
+
case OP_UNARY_MINUS:
|
541 |
+
$s = $n->value . $this->parseTree($n->treeNodes[0]);
|
542 |
+
break;
|
543 |
+
|
544 |
+
case OP_INCREMENT:
|
545 |
+
case OP_DECREMENT:
|
546 |
+
if ($n->postfix)
|
547 |
+
$s = $this->parseTree($n->treeNodes[0]) . $n->value;
|
548 |
+
else
|
549 |
+
$s = $n->value . $this->parseTree($n->treeNodes[0]);
|
550 |
+
break;
|
551 |
+
|
552 |
+
case OP_DOT:
|
553 |
+
$s = $this->parseTree($n->treeNodes[0]) . '.' . $this->parseTree($n->treeNodes[1]);
|
554 |
+
break;
|
555 |
+
|
556 |
+
case JS_INDEX:
|
557 |
+
$s = $this->parseTree($n->treeNodes[0]);
|
558 |
+
// See if we can replace named index with a dot saving 3 bytes
|
559 |
+
if ( $n->treeNodes[0]->type == TOKEN_IDENTIFIER &&
|
560 |
+
$n->treeNodes[1]->type == TOKEN_STRING &&
|
561 |
+
$this->isValidIdentifier(substr($n->treeNodes[1]->value, 1, -1))
|
562 |
+
)
|
563 |
+
$s .= '.' . substr($n->treeNodes[1]->value, 1, -1);
|
564 |
+
else
|
565 |
+
$s .= '[' . $this->parseTree($n->treeNodes[1]) . ']';
|
566 |
+
break;
|
567 |
+
|
568 |
+
case JS_LIST:
|
569 |
+
$childs = $n->treeNodes;
|
570 |
+
for ($i = 0, $j = count($childs); $i < $j; $i++)
|
571 |
+
$s .= ($i ? ',' : '') . $this->parseTree($childs[$i]);
|
572 |
+
break;
|
573 |
+
|
574 |
+
case JS_CALL:
|
575 |
+
$s = $this->parseTree($n->treeNodes[0]) . '(' . $this->parseTree($n->treeNodes[1]) . ')';
|
576 |
+
break;
|
577 |
+
|
578 |
+
case KEYWORD_NEW:
|
579 |
+
case JS_NEW_WITH_ARGS:
|
580 |
+
$s = 'new ' . $this->parseTree($n->treeNodes[0]) . '(' . ($n->type == JS_NEW_WITH_ARGS ? $this->parseTree($n->treeNodes[1]) : '') . ')';
|
581 |
+
break;
|
582 |
+
|
583 |
+
case JS_ARRAY_INIT:
|
584 |
+
$s = '[';
|
585 |
+
$childs = $n->treeNodes;
|
586 |
+
for ($i = 0, $j = count($childs); $i < $j; $i++)
|
587 |
+
{
|
588 |
+
$s .= ($i ? ',' : '') . $this->parseTree($childs[$i]);
|
589 |
+
}
|
590 |
+
$s .= ']';
|
591 |
+
break;
|
592 |
+
|
593 |
+
case JS_OBJECT_INIT:
|
594 |
+
$s = '{';
|
595 |
+
$childs = $n->treeNodes;
|
596 |
+
for ($i = 0, $j = count($childs); $i < $j; $i++)
|
597 |
+
{
|
598 |
+
$t = $childs[$i];
|
599 |
+
if ($i)
|
600 |
+
$s .= ',';
|
601 |
+
if ($t->type == JS_PROPERTY_INIT)
|
602 |
+
{
|
603 |
+
// Ditch the quotes when the index is a valid identifier
|
604 |
+
if ( $t->treeNodes[0]->type == TOKEN_STRING &&
|
605 |
+
$this->isValidIdentifier(substr($t->treeNodes[0]->value, 1, -1))
|
606 |
+
)
|
607 |
+
$s .= substr($t->treeNodes[0]->value, 1, -1);
|
608 |
+
else
|
609 |
+
$s .= $t->treeNodes[0]->value;
|
610 |
+
|
611 |
+
$s .= ':' . $this->parseTree($t->treeNodes[1]);
|
612 |
+
}
|
613 |
+
else
|
614 |
+
{
|
615 |
+
$s .= $t->type == JS_GETTER ? 'get' : 'set';
|
616 |
+
$s .= ' ' . $t->name . '(';
|
617 |
+
$params = $t->params;
|
618 |
+
for ($i = 0, $j = count($params); $i < $j; $i++)
|
619 |
+
$s .= ($i ? ',' : '') . $params[$i];
|
620 |
+
$s .= '){' . $this->parseTree($t->body, true) . '}';
|
621 |
+
}
|
622 |
+
}
|
623 |
+
$s .= '}';
|
624 |
+
break;
|
625 |
+
|
626 |
+
case TOKEN_NUMBER:
|
627 |
+
$s = $n->value;
|
628 |
+
if (preg_match('/^([1-9]+)(0{3,})$/', $s, $m))
|
629 |
+
$s = $m[1] . 'e' . strlen($m[2]);
|
630 |
+
break;
|
631 |
+
|
632 |
+
case KEYWORD_NULL: case KEYWORD_THIS: case KEYWORD_TRUE: case KEYWORD_FALSE:
|
633 |
+
case TOKEN_IDENTIFIER: case TOKEN_STRING: case TOKEN_REGEXP:
|
634 |
+
$s = $n->value;
|
635 |
+
break;
|
636 |
+
|
637 |
+
case JS_GROUP:
|
638 |
+
if (in_array(
|
639 |
+
$n->treeNodes[0]->type,
|
640 |
+
array(
|
641 |
+
JS_ARRAY_INIT, JS_OBJECT_INIT, JS_GROUP,
|
642 |
+
TOKEN_NUMBER, TOKEN_STRING, TOKEN_REGEXP, TOKEN_IDENTIFIER,
|
643 |
+
KEYWORD_NULL, KEYWORD_THIS, KEYWORD_TRUE, KEYWORD_FALSE
|
644 |
+
)
|
645 |
+
))
|
646 |
+
{
|
647 |
+
$s = $this->parseTree($n->treeNodes[0]);
|
648 |
+
}
|
649 |
+
else
|
650 |
+
{
|
651 |
+
$s = '(' . $this->parseTree($n->treeNodes[0]) . ')';
|
652 |
+
}
|
653 |
+
break;
|
654 |
+
|
655 |
+
default:
|
656 |
+
throw new Exception('UNKNOWN TOKEN TYPE: ' . $n->type);
|
657 |
+
}
|
658 |
+
|
659 |
+
return $s;
|
660 |
+
}
|
661 |
+
|
662 |
+
private function isValidIdentifier($string)
|
663 |
+
{
|
664 |
+
return preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $string) && !in_array($string, $this->reserved);
|
665 |
+
}
|
666 |
+
|
667 |
+
private function isWordChar($char)
|
668 |
+
{
|
669 |
+
return $char == '_' || $char == '$' || ctype_alnum($char);
|
670 |
+
}
|
671 |
+
}
|
672 |
+
|
673 |
+
class JSParser
|
674 |
+
{
|
675 |
+
private $t;
|
676 |
+
private $minifier;
|
677 |
+
|
678 |
+
private $opPrecedence = array(
|
679 |
+
';' => 0,
|
680 |
+
',' => 1,
|
681 |
+
'=' => 2, '?' => 2, ':' => 2,
|
682 |
+
// The above all have to have the same precedence, see bug 330975
|
683 |
+
'||' => 4,
|
684 |
+
'&&' => 5,
|
685 |
+
'|' => 6,
|
686 |
+
'^' => 7,
|
687 |
+
'&' => 8,
|
688 |
+
'==' => 9, '!=' => 9, '===' => 9, '!==' => 9,
|
689 |
+
'<' => 10, '<=' => 10, '>=' => 10, '>' => 10, 'in' => 10, 'instanceof' => 10,
|
690 |
+
'<<' => 11, '>>' => 11, '>>>' => 11,
|
691 |
+
'+' => 12, '-' => 12,
|
692 |
+
'*' => 13, '/' => 13, '%' => 13,
|
693 |
+
'delete' => 14, 'void' => 14, 'typeof' => 14,
|
694 |
+
'!' => 14, '~' => 14, 'U+' => 14, 'U-' => 14,
|
695 |
+
'++' => 15, '--' => 15,
|
696 |
+
'new' => 16,
|
697 |
+
'.' => 17,
|
698 |
+
JS_NEW_WITH_ARGS => 0, JS_INDEX => 0, JS_CALL => 0,
|
699 |
+
JS_ARRAY_INIT => 0, JS_OBJECT_INIT => 0, JS_GROUP => 0
|
700 |
+
);
|
701 |
+
|
702 |
+
private $opArity = array(
|
703 |
+
',' => -2,
|
704 |
+
'=' => 2,
|
705 |
+
'?' => 3,
|
706 |
+
'||' => 2,
|
707 |
+
'&&' => 2,
|
708 |
+
'|' => 2,
|
709 |
+
'^' => 2,
|
710 |
+
'&' => 2,
|
711 |
+
'==' => 2, '!=' => 2, '===' => 2, '!==' => 2,
|
712 |
+
'<' => 2, '<=' => 2, '>=' => 2, '>' => 2, 'in' => 2, 'instanceof' => 2,
|
713 |
+
'<<' => 2, '>>' => 2, '>>>' => 2,
|
714 |
+
'+' => 2, '-' => 2,
|
715 |
+
'*' => 2, '/' => 2, '%' => 2,
|
716 |
+
'delete' => 1, 'void' => 1, 'typeof' => 1,
|
717 |
+
'!' => 1, '~' => 1, 'U+' => 1, 'U-' => 1,
|
718 |
+
'++' => 1, '--' => 1,
|
719 |
+
'new' => 1,
|
720 |
+
'.' => 2,
|
721 |
+
JS_NEW_WITH_ARGS => 2, JS_INDEX => 2, JS_CALL => 2,
|
722 |
+
JS_ARRAY_INIT => 1, JS_OBJECT_INIT => 1, JS_GROUP => 1,
|
723 |
+
TOKEN_CONDCOMMENT_START => 1, TOKEN_CONDCOMMENT_END => 1
|
724 |
+
);
|
725 |
+
|
726 |
+
public function __construct($minifier=null)
|
727 |
+
{
|
728 |
+
$this->minifier = $minifier;
|
729 |
+
$this->t = new JSTokenizer();
|
730 |
+
}
|
731 |
+
|
732 |
+
public function parse($s, $f, $l)
|
733 |
+
{
|
734 |
+
// initialize tokenizer
|
735 |
+
$this->t->init($s, $f, $l);
|
736 |
+
|
737 |
+
$x = new JSCompilerContext(false);
|
738 |
+
$n = $this->Script($x);
|
739 |
+
if (!$this->t->isDone())
|
740 |
+
throw $this->t->newSyntaxError('Syntax error');
|
741 |
+
|
742 |
+
return $n;
|
743 |
+
}
|
744 |
+
|
745 |
+
private function Script($x)
|
746 |
+
{
|
747 |
+
$n = $this->Statements($x);
|
748 |
+
$n->type = JS_SCRIPT;
|
749 |
+
$n->funDecls = $x->funDecls;
|
750 |
+
$n->varDecls = $x->varDecls;
|
751 |
+
|
752 |
+
// minify by scope
|
753 |
+
if ($this->minifier)
|
754 |
+
{
|
755 |
+
$n->value = $this->minifier->parseTree($n);
|
756 |
+
|
757 |
+
// clear tree from node to save memory
|
758 |
+
$n->treeNodes = null;
|
759 |
+
$n->funDecls = null;
|
760 |
+
$n->varDecls = null;
|
761 |
+
|
762 |
+
$n->type = JS_MINIFIED;
|
763 |
+
}
|
764 |
+
|
765 |
+
return $n;
|
766 |
+
}
|
767 |
+
|
768 |
+
private function Statements($x)
|
769 |
+
{
|
770 |
+
$n = new JSNode($this->t, JS_BLOCK);
|
771 |
+
array_push($x->stmtStack, $n);
|
772 |
+
|
773 |
+
while (!$this->t->isDone() && $this->t->peek() != OP_RIGHT_CURLY)
|
774 |
+
$n->addNode($this->Statement($x));
|
775 |
+
|
776 |
+
array_pop($x->stmtStack);
|
777 |
+
|
778 |
+
return $n;
|
779 |
+
}
|
780 |
+
|
781 |
+
private function Block($x)
|
782 |
+
{
|
783 |
+
$this->t->mustMatch(OP_LEFT_CURLY);
|
784 |
+
$n = $this->Statements($x);
|
785 |
+
$this->t->mustMatch(OP_RIGHT_CURLY);
|
786 |
+
|
787 |
+
return $n;
|
788 |
+
}
|
789 |
+
|
790 |
+
private function Statement($x)
|
791 |
+
{
|
792 |
+
$tt = $this->t->get();
|
793 |
+
$n2 = null;
|
794 |
+
|
795 |
+
// Cases for statements ending in a right curly return early, avoiding the
|
796 |
+
// common semicolon insertion magic after this switch.
|
797 |
+
switch ($tt)
|
798 |
+
{
|
799 |
+
case KEYWORD_FUNCTION:
|
800 |
+
return $this->FunctionDefinition(
|
801 |
+
$x,
|
802 |
+
true,
|
803 |
+
count($x->stmtStack) > 1 ? STATEMENT_FORM : DECLARED_FORM
|
804 |
+
);
|
805 |
+
break;
|
806 |
+
|
807 |
+
case OP_LEFT_CURLY:
|
808 |
+
$n = $this->Statements($x);
|
809 |
+
$this->t->mustMatch(OP_RIGHT_CURLY);
|
810 |
+
return $n;
|
811 |
+
|
812 |
+
case KEYWORD_IF:
|
813 |
+
$n = new JSNode($this->t);
|
814 |
+
$n->condition = $this->ParenExpression($x);
|
815 |
+
array_push($x->stmtStack, $n);
|
816 |
+
$n->thenPart = $this->Statement($x);
|
817 |
+
$n->elsePart = $this->t->match(KEYWORD_ELSE) ? $this->Statement($x) : null;
|
818 |
+
array_pop($x->stmtStack);
|
819 |
+
return $n;
|
820 |
+
|
821 |
+
case KEYWORD_SWITCH:
|
822 |
+
$n = new JSNode($this->t);
|
823 |
+
$this->t->mustMatch(OP_LEFT_PAREN);
|
824 |
+
$n->discriminant = $this->Expression($x);
|
825 |
+
$this->t->mustMatch(OP_RIGHT_PAREN);
|
826 |
+
$n->cases = array();
|
827 |
+
$n->defaultIndex = -1;
|
828 |
+
|
829 |
+
array_push($x->stmtStack, $n);
|
830 |
+
|
831 |
+
$this->t->mustMatch(OP_LEFT_CURLY);
|
832 |
+
|
833 |
+
while (($tt = $this->t->get()) != OP_RIGHT_CURLY)
|
834 |
+
{
|
835 |
+
switch ($tt)
|
836 |
+
{
|
837 |
+
case KEYWORD_DEFAULT:
|
838 |
+
if ($n->defaultIndex >= 0)
|
839 |
+
throw $this->t->newSyntaxError('More than one switch default');
|
840 |
+
// FALL THROUGH
|
841 |
+
case KEYWORD_CASE:
|
842 |
+
$n2 = new JSNode($this->t);
|
843 |
+
if ($tt == KEYWORD_DEFAULT)
|
844 |
+
$n->defaultIndex = count($n->cases);
|
845 |
+
else
|
846 |
+
$n2->caseLabel = $this->Expression($x, OP_COLON);
|
847 |
+
break;
|
848 |
+
default:
|
849 |
+
throw $this->t->newSyntaxError('Invalid switch case');
|
850 |
+
}
|
851 |
+
|
852 |
+
$this->t->mustMatch(OP_COLON);
|
853 |
+
$n2->statements = new JSNode($this->t, JS_BLOCK);
|
854 |
+
while (($tt = $this->t->peek()) != KEYWORD_CASE && $tt != KEYWORD_DEFAULT && $tt != OP_RIGHT_CURLY)
|
855 |
+
$n2->statements->addNode($this->Statement($x));
|
856 |
+
|
857 |
+
array_push($n->cases, $n2);
|
858 |
+
}
|
859 |
+
|
860 |
+
array_pop($x->stmtStack);
|
861 |
+
return $n;
|
862 |
+
|
863 |
+
case KEYWORD_FOR:
|
864 |
+
$n = new JSNode($this->t);
|
865 |
+
$n->isLoop = true;
|
866 |
+
$this->t->mustMatch(OP_LEFT_PAREN);
|
867 |
+
|
868 |
+
if (($tt = $this->t->peek()) != OP_SEMICOLON)
|
869 |
+
{
|
870 |
+
$x->inForLoopInit = true;
|
871 |
+
if ($tt == KEYWORD_VAR || $tt == KEYWORD_CONST)
|
872 |
+
{
|
873 |
+
$this->t->get();
|
874 |
+
$n2 = $this->Variables($x);
|
875 |
+
}
|
876 |
+
else
|
877 |
+
{
|
878 |
+
$n2 = $this->Expression($x);
|
879 |
+
}
|
880 |
+
$x->inForLoopInit = false;
|
881 |
+
}
|
882 |
+
|
883 |
+
if ($n2 && $this->t->match(KEYWORD_IN))
|
884 |
+
{
|
885 |
+
$n->type = JS_FOR_IN;
|
886 |
+
if ($n2->type == KEYWORD_VAR)
|
887 |
+
{
|
888 |
+
if (count($n2->treeNodes) != 1)
|
889 |
+
{
|
890 |
+
throw $this->t->SyntaxError(
|
891 |
+
'Invalid for..in left-hand side',
|
892 |
+
$this->t->filename,
|
893 |
+
$n2->lineno
|
894 |
+
);
|
895 |
+
}
|
896 |
+
|
897 |
+
// NB: n2[0].type == IDENTIFIER and n2[0].value == n2[0].name.
|
898 |
+
$n->iterator = $n2->treeNodes[0];
|
899 |
+
$n->varDecl = $n2;
|
900 |
+
}
|
901 |
+
else
|
902 |
+
{
|
903 |
+
$n->iterator = $n2;
|
904 |
+
$n->varDecl = null;
|
905 |
+
}
|
906 |
+
|
907 |
+
$n->object = $this->Expression($x);
|
908 |
+
}
|
909 |
+
else
|
910 |
+
{
|
911 |
+
$n->setup = $n2 ? $n2 : null;
|
912 |
+
$this->t->mustMatch(OP_SEMICOLON);
|
913 |
+
$n->condition = $this->t->peek() == OP_SEMICOLON ? null : $this->Expression($x);
|
914 |
+
$this->t->mustMatch(OP_SEMICOLON);
|
915 |
+
$n->update = $this->t->peek() == OP_RIGHT_PAREN ? null : $this->Expression($x);
|
916 |
+
}
|
917 |
+
|
918 |
+
$this->t->mustMatch(OP_RIGHT_PAREN);
|
919 |
+
$n->body = $this->nest($x, $n);
|
920 |
+
return $n;
|
921 |
+
|
922 |
+
case KEYWORD_WHILE:
|
923 |
+
$n = new JSNode($this->t);
|
924 |
+
$n->isLoop = true;
|
925 |
+
$n->condition = $this->ParenExpression($x);
|
926 |
+
$n->body = $this->nest($x, $n);
|
927 |
+
return $n;
|
928 |
+
|
929 |
+
case KEYWORD_DO:
|
930 |
+
$n = new JSNode($this->t);
|
931 |
+
$n->isLoop = true;
|
932 |
+
$n->body = $this->nest($x, $n, KEYWORD_WHILE);
|
933 |
+
$n->condition = $this->ParenExpression($x);
|
934 |
+
if (!$x->ecmaStrictMode)
|
935 |
+
{
|
936 |
+
// <script language="JavaScript"> (without version hints) may need
|
937 |
+
// automatic semicolon insertion without a newline after do-while.
|
938 |
+
// See http://bugzilla.mozilla.org/show_bug.cgi?id=238945.
|
939 |
+
$this->t->match(OP_SEMICOLON);
|
940 |
+
return $n;
|
941 |
+
}
|
942 |
+
break;
|
943 |
+
|
944 |
+
case KEYWORD_BREAK:
|
945 |
+
case KEYWORD_CONTINUE:
|
946 |
+
$n = new JSNode($this->t);
|
947 |
+
|
948 |
+
if ($this->t->peekOnSameLine() == TOKEN_IDENTIFIER)
|
949 |
+
{
|
950 |
+
$this->t->get();
|
951 |
+
$n->label = $this->t->currentToken()->value;
|
952 |
+
}
|
953 |
+
|
954 |
+
$ss = $x->stmtStack;
|
955 |
+
$i = count($ss);
|
956 |
+
$label = $n->label;
|
957 |
+
if ($label)
|
958 |
+
{
|
959 |
+
do
|
960 |
+
{
|
961 |
+
if (--$i < 0)
|
962 |
+
throw $this->t->newSyntaxError('Label not found');
|
963 |
+
}
|
964 |
+
while ($ss[$i]->label != $label);
|
965 |
+
}
|
966 |
+
else
|
967 |
+
{
|
968 |
+
do
|
969 |
+
{
|
970 |
+
if (--$i < 0)
|
971 |
+
throw $this->t->newSyntaxError('Invalid ' . $tt);
|
972 |
+
}
|
973 |
+
while (!$ss[$i]->isLoop && ($tt != KEYWORD_BREAK || $ss[$i]->type != KEYWORD_SWITCH));
|
974 |
+
}
|
975 |
+
|
976 |
+
$n->target = $ss[$i];
|
977 |
+
break;
|
978 |
+
|
979 |
+
case KEYWORD_TRY:
|
980 |
+
$n = new JSNode($this->t);
|
981 |
+
$n->tryBlock = $this->Block($x);
|
982 |
+
$n->catchClauses = array();
|
983 |
+
|
984 |
+
while ($this->t->match(KEYWORD_CATCH))
|
985 |
+
{
|
986 |
+
$n2 = new JSNode($this->t);
|
987 |
+
$this->t->mustMatch(OP_LEFT_PAREN);
|
988 |
+
$n2->varName = $this->t->mustMatch(TOKEN_IDENTIFIER)->value;
|
989 |
+
|
990 |
+
if ($this->t->match(KEYWORD_IF))
|
991 |
+
{
|
992 |
+
if ($x->ecmaStrictMode)
|
993 |
+
throw $this->t->newSyntaxError('Illegal catch guard');
|
994 |
+
|
995 |
+
if (count($n->catchClauses) && !end($n->catchClauses)->guard)
|
996 |
+
throw $this->t->newSyntaxError('Guarded catch after unguarded');
|
997 |
+
|
998 |
+
$n2->guard = $this->Expression($x);
|
999 |
+
}
|
1000 |
+
else
|
1001 |
+
{
|
1002 |
+
$n2->guard = null;
|
1003 |
+
}
|
1004 |
+
|
1005 |
+
$this->t->mustMatch(OP_RIGHT_PAREN);
|
1006 |
+
$n2->block = $this->Block($x);
|
1007 |
+
array_push($n->catchClauses, $n2);
|
1008 |
+
}
|
1009 |
+
|
1010 |
+
if ($this->t->match(KEYWORD_FINALLY))
|
1011 |
+
$n->finallyBlock = $this->Block($x);
|
1012 |
+
|
1013 |
+
if (!count($n->catchClauses) && !$n->finallyBlock)
|
1014 |
+
throw $this->t->newSyntaxError('Invalid try statement');
|
1015 |
+
return $n;
|
1016 |
+
|
1017 |
+
case KEYWORD_CATCH:
|
1018 |
+
case KEYWORD_FINALLY:
|
1019 |
+
throw $this->t->newSyntaxError($tt + ' without preceding try');
|
1020 |
+
|
1021 |
+
case KEYWORD_THROW:
|
1022 |
+
$n = new JSNode($this->t);
|
1023 |
+
$n->value = $this->Expression($x);
|
1024 |
+
break;
|
1025 |
+
|
1026 |
+
case KEYWORD_RETURN:
|
1027 |
+
if (!$x->inFunction)
|
1028 |
+
throw $this->t->newSyntaxError('Invalid return');
|
1029 |
+
|
1030 |
+
$n = new JSNode($this->t);
|
1031 |
+
$tt = $this->t->peekOnSameLine();
|
1032 |
+
if ($tt != TOKEN_END && $tt != TOKEN_NEWLINE && $tt != OP_SEMICOLON && $tt != OP_RIGHT_CURLY)
|
1033 |
+
$n->value = $this->Expression($x);
|
1034 |
+
else
|
1035 |
+
$n->value = null;
|
1036 |
+
break;
|
1037 |
+
|
1038 |
+
case KEYWORD_WITH:
|
1039 |
+
$n = new JSNode($this->t);
|
1040 |
+
$n->object = $this->ParenExpression($x);
|
1041 |
+
$n->body = $this->nest($x, $n);
|
1042 |
+
return $n;
|
1043 |
+
|
1044 |
+
case KEYWORD_VAR:
|
1045 |
+
case KEYWORD_CONST:
|
1046 |
+
$n = $this->Variables($x);
|
1047 |
+
break;
|
1048 |
+
|
1049 |
+
case TOKEN_CONDCOMMENT_START:
|
1050 |
+
case TOKEN_CONDCOMMENT_END:
|
1051 |
+
$n = new JSNode($this->t);
|
1052 |
+
return $n;
|
1053 |
+
|
1054 |
+
case KEYWORD_DEBUGGER:
|
1055 |
+
$n = new JSNode($this->t);
|
1056 |
+
break;
|
1057 |
+
|
1058 |
+
case TOKEN_NEWLINE:
|
1059 |
+
case OP_SEMICOLON:
|
1060 |
+
$n = new JSNode($this->t, OP_SEMICOLON);
|
1061 |
+
$n->expression = null;
|
1062 |
+
return $n;
|
1063 |
+
|
1064 |
+
default:
|
1065 |
+
if ($tt == TOKEN_IDENTIFIER)
|
1066 |
+
{
|
1067 |
+
$this->t->scanOperand = false;
|
1068 |
+
$tt = $this->t->peek();
|
1069 |
+
$this->t->scanOperand = true;
|
1070 |
+
if ($tt == OP_COLON)
|
1071 |
+
{
|
1072 |
+
$label = $this->t->currentToken()->value;
|
1073 |
+
$ss = $x->stmtStack;
|
1074 |
+
for ($i = count($ss) - 1; $i >= 0; --$i)
|
1075 |
+
{
|
1076 |
+
if ($ss[$i]->label == $label)
|
1077 |
+
throw $this->t->newSyntaxError('Duplicate label');
|
1078 |
+
}
|
1079 |
+
|
1080 |
+
$this->t->get();
|
1081 |
+
$n = new JSNode($this->t, JS_LABEL);
|
1082 |
+
$n->label = $label;
|
1083 |
+
$n->statement = $this->nest($x, $n);
|
1084 |
+
|
1085 |
+
return $n;
|
1086 |
+
}
|
1087 |
+
}
|
1088 |
+
|
1089 |
+
$n = new JSNode($this->t, OP_SEMICOLON);
|
1090 |
+
$this->t->unget();
|
1091 |
+
$n->expression = $this->Expression($x);
|
1092 |
+
$n->end = $n->expression->end;
|
1093 |
+
break;
|
1094 |
+
}
|
1095 |
+
|
1096 |
+
if ($this->t->lineno == $this->t->currentToken()->lineno)
|
1097 |
+
{
|
1098 |
+
$tt = $this->t->peekOnSameLine();
|
1099 |
+
if ($tt != TOKEN_END && $tt != TOKEN_NEWLINE && $tt != OP_SEMICOLON && $tt != OP_RIGHT_CURLY)
|
1100 |
+
throw $this->t->newSyntaxError('Missing ; before statement');
|
1101 |
+
}
|
1102 |
+
|
1103 |
+
$this->t->match(OP_SEMICOLON);
|
1104 |
+
|
1105 |
+
return $n;
|
1106 |
+
}
|
1107 |
+
|
1108 |
+
private function FunctionDefinition($x, $requireName, $functionForm)
|
1109 |
+
{
|
1110 |
+
$f = new JSNode($this->t);
|
1111 |
+
|
1112 |
+
if ($f->type != KEYWORD_FUNCTION)
|
1113 |
+
$f->type = ($f->value == 'get') ? JS_GETTER : JS_SETTER;
|
1114 |
+
|
1115 |
+
if ($this->t->match(TOKEN_IDENTIFIER))
|
1116 |
+
$f->name = $this->t->currentToken()->value;
|
1117 |
+
elseif ($requireName)
|
1118 |
+
throw $this->t->newSyntaxError('Missing function identifier');
|
1119 |
+
|
1120 |
+
$this->t->mustMatch(OP_LEFT_PAREN);
|
1121 |
+
$f->params = array();
|
1122 |
+
|
1123 |
+
while (($tt = $this->t->get()) != OP_RIGHT_PAREN)
|
1124 |
+
{
|
1125 |
+
if ($tt != TOKEN_IDENTIFIER)
|
1126 |
+
throw $this->t->newSyntaxError('Missing formal parameter');
|
1127 |
+
|
1128 |
+
array_push($f->params, $this->t->currentToken()->value);
|
1129 |
+
|
1130 |
+
if ($this->t->peek() != OP_RIGHT_PAREN)
|
1131 |
+
$this->t->mustMatch(OP_COMMA);
|
1132 |
+
}
|
1133 |
+
|
1134 |
+
$this->t->mustMatch(OP_LEFT_CURLY);
|
1135 |
+
|
1136 |
+
$x2 = new JSCompilerContext(true);
|
1137 |
+
$f->body = $this->Script($x2);
|
1138 |
+
|
1139 |
+
$this->t->mustMatch(OP_RIGHT_CURLY);
|
1140 |
+
$f->end = $this->t->currentToken()->end;
|
1141 |
+
|
1142 |
+
$f->functionForm = $functionForm;
|
1143 |
+
if ($functionForm == DECLARED_FORM)
|
1144 |
+
array_push($x->funDecls, $f);
|
1145 |
+
|
1146 |
+
return $f;
|
1147 |
+
}
|
1148 |
+
|
1149 |
+
private function Variables($x)
|
1150 |
+
{
|
1151 |
+
$n = new JSNode($this->t);
|
1152 |
+
|
1153 |
+
do
|
1154 |
+
{
|
1155 |
+
$this->t->mustMatch(TOKEN_IDENTIFIER);
|
1156 |
+
|
1157 |
+
$n2 = new JSNode($this->t);
|
1158 |
+
$n2->name = $n2->value;
|
1159 |
+
|
1160 |
+
if ($this->t->match(OP_ASSIGN))
|
1161 |
+
{
|
1162 |
+
if ($this->t->currentToken()->assignOp)
|
1163 |
+
throw $this->t->newSyntaxError('Invalid variable initialization');
|
1164 |
+
|
1165 |
+
$n2->initializer = $this->Expression($x, OP_COMMA);
|
1166 |
+
}
|
1167 |
+
|
1168 |
+
$n2->readOnly = $n->type == KEYWORD_CONST;
|
1169 |
+
|
1170 |
+
$n->addNode($n2);
|
1171 |
+
array_push($x->varDecls, $n2);
|
1172 |
+
}
|
1173 |
+
while ($this->t->match(OP_COMMA));
|
1174 |
+
|
1175 |
+
return $n;
|
1176 |
+
}
|
1177 |
+
|
1178 |
+
private function Expression($x, $stop=false)
|
1179 |
+
{
|
1180 |
+
$operators = array();
|
1181 |
+
$operands = array();
|
1182 |
+
$n = false;
|
1183 |
+
|
1184 |
+
$bl = $x->bracketLevel;
|
1185 |
+
$cl = $x->curlyLevel;
|
1186 |
+
$pl = $x->parenLevel;
|
1187 |
+
$hl = $x->hookLevel;
|
1188 |
+
|
1189 |
+
while (($tt = $this->t->get()) != TOKEN_END)
|
1190 |
+
{
|
1191 |
+
if ($tt == $stop &&
|
1192 |
+
$x->bracketLevel == $bl &&
|
1193 |
+
$x->curlyLevel == $cl &&
|
1194 |
+
$x->parenLevel == $pl &&
|
1195 |
+
$x->hookLevel == $hl
|
1196 |
+
)
|
1197 |
+
{
|
1198 |
+
// Stop only if tt matches the optional stop parameter, and that
|
1199 |
+
// token is not quoted by some kind of bracket.
|
1200 |
+
break;
|
1201 |
+
}
|
1202 |
+
|
1203 |
+
switch ($tt)
|
1204 |
+
{
|
1205 |
+
case OP_SEMICOLON:
|
1206 |
+
// NB: cannot be empty, Statement handled that.
|
1207 |
+
break 2;
|
1208 |
+
|
1209 |
+
case OP_HOOK:
|
1210 |
+
if ($this->t->scanOperand)
|
1211 |
+
break 2;
|
1212 |
+
|
1213 |
+
while ( !empty($operators) &&
|
1214 |
+
$this->opPrecedence[end($operators)->type] > $this->opPrecedence[$tt]
|
1215 |
+
)
|
1216 |
+
$this->reduce($operators, $operands);
|
1217 |
+
|
1218 |
+
array_push($operators, new JSNode($this->t));
|
1219 |
+
|
1220 |
+
++$x->hookLevel;
|
1221 |
+
$this->t->scanOperand = true;
|
1222 |
+
$n = $this->Expression($x);
|
1223 |
+
|
1224 |
+
if (!$this->t->match(OP_COLON))
|
1225 |
+
break 2;
|
1226 |
+
|
1227 |
+
--$x->hookLevel;
|
1228 |
+
array_push($operands, $n);
|
1229 |
+
break;
|
1230 |
+
|
1231 |
+
case OP_COLON:
|
1232 |
+
if ($x->hookLevel)
|
1233 |
+
break 2;
|
1234 |
+
|
1235 |
+
throw $this->t->newSyntaxError('Invalid label');
|
1236 |
+
break;
|
1237 |
+
|
1238 |
+
case OP_ASSIGN:
|
1239 |
+
if ($this->t->scanOperand)
|
1240 |
+
break 2;
|
1241 |
+
|
1242 |
+
// Use >, not >=, for right-associative ASSIGN
|
1243 |
+
while ( !empty($operators) &&
|
1244 |
+
$this->opPrecedence[end($operators)->type] > $this->opPrecedence[$tt]
|
1245 |
+
)
|
1246 |
+
$this->reduce($operators, $operands);
|
1247 |
+
|
1248 |
+
array_push($operators, new JSNode($this->t));
|
1249 |
+
end($operands)->assignOp = $this->t->currentToken()->assignOp;
|
1250 |
+
$this->t->scanOperand = true;
|
1251 |
+
break;
|
1252 |
+
|
1253 |
+
case KEYWORD_IN:
|
1254 |
+
// An in operator should not be parsed if we're parsing the head of
|
1255 |
+
// a for (...) loop, unless it is in the then part of a conditional
|
1256 |
+
// expression, or parenthesized somehow.
|
1257 |
+
if ($x->inForLoopInit && !$x->hookLevel &&
|
1258 |
+
!$x->bracketLevel && !$x->curlyLevel &&
|
1259 |
+
!$x->parenLevel
|
1260 |
+
)
|
1261 |
+
break 2;
|
1262 |
+
// FALL THROUGH
|
1263 |
+
case OP_COMMA:
|
1264 |
+
// A comma operator should not be parsed if we're parsing the then part
|
1265 |
+
// of a conditional expression unless it's parenthesized somehow.
|
1266 |
+
if ($tt == OP_COMMA && $x->hookLevel &&
|
1267 |
+
!$x->bracketLevel && !$x->curlyLevel &&
|
1268 |
+
!$x->parenLevel
|
1269 |
+
)
|
1270 |
+
break 2;
|
1271 |
+
// Treat comma as left-associative so reduce can fold left-heavy
|
1272 |
+
// COMMA trees into a single array.
|
1273 |
+
// FALL THROUGH
|
1274 |
+
case OP_OR:
|
1275 |
+
case OP_AND:
|
1276 |
+
case OP_BITWISE_OR:
|
1277 |
+
case OP_BITWISE_XOR:
|
1278 |
+
case OP_BITWISE_AND:
|
1279 |
+
case OP_EQ: case OP_NE: case OP_STRICT_EQ: case OP_STRICT_NE:
|
1280 |
+
case OP_LT: case OP_LE: case OP_GE: case OP_GT:
|
1281 |
+
case KEYWORD_INSTANCEOF:
|
1282 |
+
case OP_LSH: case OP_RSH: case OP_URSH:
|
1283 |
+
case OP_PLUS: case OP_MINUS:
|
1284 |
+
case OP_MUL: case OP_DIV: case OP_MOD:
|
1285 |
+
case OP_DOT:
|
1286 |
+
if ($this->t->scanOperand)
|
1287 |
+
break 2;
|
1288 |
+
|
1289 |
+
while ( !empty($operators) &&
|
1290 |
+
$this->opPrecedence[end($operators)->type] >= $this->opPrecedence[$tt]
|
1291 |
+
)
|
1292 |
+
$this->reduce($operators, $operands);
|
1293 |
+
|
1294 |
+
if ($tt == OP_DOT)
|
1295 |
+
{
|
1296 |
+
$this->t->mustMatch(TOKEN_IDENTIFIER);
|
1297 |
+
array_push($operands, new JSNode($this->t, OP_DOT, array_pop($operands), new JSNode($this->t)));
|
1298 |
+
}
|
1299 |
+
else
|
1300 |
+
{
|
1301 |
+
array_push($operators, new JSNode($this->t));
|
1302 |
+
$this->t->scanOperand = true;
|
1303 |
+
}
|
1304 |
+
break;
|
1305 |
+
|
1306 |
+
case KEYWORD_DELETE: case KEYWORD_VOID: case KEYWORD_TYPEOF:
|
1307 |
+
case OP_NOT: case OP_BITWISE_NOT: case OP_UNARY_PLUS: case OP_UNARY_MINUS:
|
1308 |
+
case KEYWORD_NEW:
|
1309 |
+
if (!$this->t->scanOperand)
|
1310 |
+
break 2;
|
1311 |
+
|
1312 |
+
array_push($operators, new JSNode($this->t));
|
1313 |
+
break;
|
1314 |
+
|
1315 |
+
case OP_INCREMENT: case OP_DECREMENT:
|
1316 |
+
if ($this->t->scanOperand)
|
1317 |
+
{
|
1318 |
+
array_push($operators, new JSNode($this->t)); // prefix increment or decrement
|
1319 |
+
}
|
1320 |
+
else
|
1321 |
+
{
|
1322 |
+
// Don't cross a line boundary for postfix {in,de}crement.
|
1323 |
+
$t = $this->t->tokens[($this->t->tokenIndex + $this->t->lookahead - 1) & 3];
|
1324 |
+
if ($t && $t->lineno != $this->t->lineno)
|
1325 |
+
break 2;
|
1326 |
+
|
1327 |
+
if (!empty($operators))
|
1328 |
+
{
|
1329 |
+
// Use >, not >=, so postfix has higher precedence than prefix.
|
1330 |
+
while ($this->opPrecedence[end($operators)->type] > $this->opPrecedence[$tt])
|
1331 |
+
$this->reduce($operators, $operands);
|
1332 |
+
}
|
1333 |
+
|
1334 |
+
$n = new JSNode($this->t, $tt, array_pop($operands));
|
1335 |
+
$n->postfix = true;
|
1336 |
+
array_push($operands, $n);
|
1337 |
+
}
|
1338 |
+
break;
|
1339 |
+
|
1340 |
+
case KEYWORD_FUNCTION:
|
1341 |
+
if (!$this->t->scanOperand)
|
1342 |
+
break 2;
|
1343 |
+
|
1344 |
+
array_push($operands, $this->FunctionDefinition($x, false, EXPRESSED_FORM));
|
1345 |
+
$this->t->scanOperand = false;
|
1346 |
+
break;
|
1347 |
+
|
1348 |
+
case KEYWORD_NULL: case KEYWORD_THIS: case KEYWORD_TRUE: case KEYWORD_FALSE:
|
1349 |
+
case TOKEN_IDENTIFIER: case TOKEN_NUMBER: case TOKEN_STRING: case TOKEN_REGEXP:
|
1350 |
+
if (!$this->t->scanOperand)
|
1351 |
+
break 2;
|
1352 |
+
|
1353 |
+
array_push($operands, new JSNode($this->t));
|
1354 |
+
$this->t->scanOperand = false;
|
1355 |
+
break;
|
1356 |
+
|
1357 |
+
case TOKEN_CONDCOMMENT_START:
|
1358 |
+
case TOKEN_CONDCOMMENT_END:
|
1359 |
+
if ($this->t->scanOperand)
|
1360 |
+
array_push($operators, new JSNode($this->t));
|
1361 |
+
else
|
1362 |
+
array_push($operands, new JSNode($this->t));
|
1363 |
+
break;
|
1364 |
+
|
1365 |
+
case OP_LEFT_BRACKET:
|
1366 |
+
if ($this->t->scanOperand)
|
1367 |
+
{
|
1368 |
+
// Array initialiser. Parse using recursive descent, as the
|
1369 |
+
// sub-grammar here is not an operator grammar.
|
1370 |
+
$n = new JSNode($this->t, JS_ARRAY_INIT);
|
1371 |
+
while (($tt = $this->t->peek()) != OP_RIGHT_BRACKET)
|
1372 |
+
{
|
1373 |
+
if ($tt == OP_COMMA)
|
1374 |
+
{
|
1375 |
+
$this->t->get();
|
1376 |
+
$n->addNode(null);
|
1377 |
+
continue;
|
1378 |
+
}
|
1379 |
+
|
1380 |
+
$n->addNode($this->Expression($x, OP_COMMA));
|
1381 |
+
if (!$this->t->match(OP_COMMA))
|
1382 |
+
break;
|
1383 |
+
}
|
1384 |
+
|
1385 |
+
$this->t->mustMatch(OP_RIGHT_BRACKET);
|
1386 |
+
array_push($operands, $n);
|
1387 |
+
$this->t->scanOperand = false;
|
1388 |
+
}
|
1389 |
+
else
|
1390 |
+
{
|
1391 |
+
// Property indexing operator.
|
1392 |
+
array_push($operators, new JSNode($this->t, JS_INDEX));
|
1393 |
+
$this->t->scanOperand = true;
|
1394 |
+
++$x->bracketLevel;
|
1395 |
+
}
|
1396 |
+
break;
|
1397 |
+
|
1398 |
+
case OP_RIGHT_BRACKET:
|
1399 |
+
if ($this->t->scanOperand || $x->bracketLevel == $bl)
|
1400 |
+
break 2;
|
1401 |
+
|
1402 |
+
while ($this->reduce($operators, $operands)->type != JS_INDEX)
|
1403 |
+
continue;
|
1404 |
+
|
1405 |
+
--$x->bracketLevel;
|
1406 |
+
break;
|
1407 |
+
|
1408 |
+
case OP_LEFT_CURLY:
|
1409 |
+
if (!$this->t->scanOperand)
|
1410 |
+
break 2;
|
1411 |
+
|
1412 |
+
// Object initialiser. As for array initialisers (see above),
|
1413 |
+
// parse using recursive descent.
|
1414 |
+
++$x->curlyLevel;
|
1415 |
+
$n = new JSNode($this->t, JS_OBJECT_INIT);
|
1416 |
+
while (!$this->t->match(OP_RIGHT_CURLY))
|
1417 |
+
{
|
1418 |
+
do
|
1419 |
+
{
|
1420 |
+
$tt = $this->t->get();
|
1421 |
+
$tv = $this->t->currentToken()->value;
|
1422 |
+
if (($tv == 'get' || $tv == 'set') && $this->t->peek() == TOKEN_IDENTIFIER)
|
1423 |
+
{
|
1424 |
+
if ($x->ecmaStrictMode)
|
1425 |
+
throw $this->t->newSyntaxError('Illegal property accessor');
|
1426 |
+
|
1427 |
+
$n->addNode($this->FunctionDefinition($x, true, EXPRESSED_FORM));
|
1428 |
+
}
|
1429 |
+
else
|
1430 |
+
{
|
1431 |
+
switch ($tt)
|
1432 |
+
{
|
1433 |
+
case TOKEN_IDENTIFIER:
|
1434 |
+
case TOKEN_NUMBER:
|
1435 |
+
case TOKEN_STRING:
|
1436 |
+
$id = new JSNode($this->t);
|
1437 |
+
break;
|
1438 |
+
|
1439 |
+
case OP_RIGHT_CURLY:
|
1440 |
+
if ($x->ecmaStrictMode)
|
1441 |
+
throw $this->t->newSyntaxError('Illegal trailing ,');
|
1442 |
+
break 3;
|
1443 |
+
|
1444 |
+
default:
|
1445 |
+
throw $this->t->newSyntaxError('Invalid property name');
|
1446 |
+
}
|
1447 |
+
|
1448 |
+
$this->t->mustMatch(OP_COLON);
|
1449 |
+
$n->addNode(new JSNode($this->t, JS_PROPERTY_INIT, $id, $this->Expression($x, OP_COMMA)));
|
1450 |
+
}
|
1451 |
+
}
|
1452 |
+
while ($this->t->match(OP_COMMA));
|
1453 |
+
|
1454 |
+
$this->t->mustMatch(OP_RIGHT_CURLY);
|
1455 |
+
break;
|
1456 |
+
}
|
1457 |
+
|
1458 |
+
array_push($operands, $n);
|
1459 |
+
$this->t->scanOperand = false;
|
1460 |
+
--$x->curlyLevel;
|
1461 |
+
break;
|
1462 |
+
|
1463 |
+
case OP_RIGHT_CURLY:
|
1464 |
+
if (!$this->t->scanOperand && $x->curlyLevel != $cl)
|
1465 |
+
throw new Exception('PANIC: right curly botch');
|
1466 |
+
break 2;
|
1467 |
+
|
1468 |
+
case OP_LEFT_PAREN:
|
1469 |
+
if ($this->t->scanOperand)
|
1470 |
+
{
|
1471 |
+
array_push($operators, new JSNode($this->t, JS_GROUP));
|
1472 |
+
}
|
1473 |
+
else
|
1474 |
+
{
|
1475 |
+
while ( !empty($operators) &&
|
1476 |
+
$this->opPrecedence[end($operators)->type] > $this->opPrecedence[KEYWORD_NEW]
|
1477 |
+
)
|
1478 |
+
$this->reduce($operators, $operands);
|
1479 |
+
|
1480 |
+
// Handle () now, to regularize the n-ary case for n > 0.
|
1481 |
+
// We must set scanOperand in case there are arguments and
|
1482 |
+
// the first one is a regexp or unary+/-.
|
1483 |
+
$n = end($operators);
|
1484 |
+
$this->t->scanOperand = true;
|
1485 |
+
if ($this->t->match(OP_RIGHT_PAREN))
|
1486 |
+
{
|
1487 |
+
if ($n && $n->type == KEYWORD_NEW)
|
1488 |
+
{
|
1489 |
+
array_pop($operators);
|
1490 |
+
$n->addNode(array_pop($operands));
|
1491 |
+
}
|
1492 |
+
else
|
1493 |
+
{
|
1494 |
+
$n = new JSNode($this->t, JS_CALL, array_pop($operands), new JSNode($this->t, JS_LIST));
|
1495 |
+
}
|
1496 |
+
|
1497 |
+
array_push($operands, $n);
|
1498 |
+
$this->t->scanOperand = false;
|
1499 |
+
break;
|
1500 |
+
}
|
1501 |
+
|
1502 |
+
if ($n && $n->type == KEYWORD_NEW)
|
1503 |
+
$n->type = JS_NEW_WITH_ARGS;
|
1504 |
+
else
|
1505 |
+
array_push($operators, new JSNode($this->t, JS_CALL));
|
1506 |
+
}
|
1507 |
+
|
1508 |
+
++$x->parenLevel;
|
1509 |
+
break;
|
1510 |
+
|
1511 |
+
case OP_RIGHT_PAREN:
|
1512 |
+
if ($this->t->scanOperand || $x->parenLevel == $pl)
|
1513 |
+
break 2;
|
1514 |
+
|
1515 |
+
while (($tt = $this->reduce($operators, $operands)->type) != JS_GROUP &&
|
1516 |
+
$tt != JS_CALL && $tt != JS_NEW_WITH_ARGS
|
1517 |
+
)
|
1518 |
+
{
|
1519 |
+
continue;
|
1520 |
+
}
|
1521 |
+
|
1522 |
+
if ($tt != JS_GROUP)
|
1523 |
+
{
|
1524 |
+
$n = end($operands);
|
1525 |
+
if ($n->treeNodes[1]->type != OP_COMMA)
|
1526 |
+
$n->treeNodes[1] = new JSNode($this->t, JS_LIST, $n->treeNodes[1]);
|
1527 |
+
else
|
1528 |
+
$n->treeNodes[1]->type = JS_LIST;
|
1529 |
+
}
|
1530 |
+
|
1531 |
+
--$x->parenLevel;
|
1532 |
+
break;
|
1533 |
+
|
1534 |
+
// Automatic semicolon insertion means we may scan across a newline
|
1535 |
+
// and into the beginning of another statement. If so, break out of
|
1536 |
+
// the while loop and let the t.scanOperand logic handle errors.
|
1537 |
+
default:
|
1538 |
+
break 2;
|
1539 |
+
}
|
1540 |
+
}
|
1541 |
+
|
1542 |
+
if ($x->hookLevel != $hl)
|
1543 |
+
throw $this->t->newSyntaxError('Missing : in conditional expression');
|
1544 |
+
|
1545 |
+
if ($x->parenLevel != $pl)
|
1546 |
+
throw $this->t->newSyntaxError('Missing ) in parenthetical');
|
1547 |
+
|
1548 |
+
if ($x->bracketLevel != $bl)
|
1549 |
+
throw $this->t->newSyntaxError('Missing ] in index expression');
|
1550 |
+
|
1551 |
+
if ($this->t->scanOperand)
|
1552 |
+
throw $this->t->newSyntaxError('Missing operand');
|
1553 |
+
|
1554 |
+
// Resume default mode, scanning for operands, not operators.
|
1555 |
+
$this->t->scanOperand = true;
|
1556 |
+
$this->t->unget();
|
1557 |
+
|
1558 |
+
while (count($operators))
|
1559 |
+
$this->reduce($operators, $operands);
|
1560 |
+
|
1561 |
+
return array_pop($operands);
|
1562 |
+
}
|
1563 |
+
|
1564 |
+
private function ParenExpression($x)
|
1565 |
+
{
|
1566 |
+
$this->t->mustMatch(OP_LEFT_PAREN);
|
1567 |
+
$n = $this->Expression($x);
|
1568 |
+
$this->t->mustMatch(OP_RIGHT_PAREN);
|
1569 |
+
|
1570 |
+
return $n;
|
1571 |
+
}
|
1572 |
+
|
1573 |
+
// Statement stack and nested statement handler.
|
1574 |
+
private function nest($x, $node, $end = false)
|
1575 |
+
{
|
1576 |
+
array_push($x->stmtStack, $node);
|
1577 |
+
$n = $this->statement($x);
|
1578 |
+
array_pop($x->stmtStack);
|
1579 |
+
|
1580 |
+
if ($end)
|
1581 |
+
$this->t->mustMatch($end);
|
1582 |
+
|
1583 |
+
return $n;
|
1584 |
+
}
|
1585 |
+
|
1586 |
+
private function reduce(&$operators, &$operands)
|
1587 |
+
{
|
1588 |
+
$n = array_pop($operators);
|
1589 |
+
$op = $n->type;
|
1590 |
+
$arity = $this->opArity[$op];
|
1591 |
+
$c = count($operands);
|
1592 |
+
if ($arity == -2)
|
1593 |
+
{
|
1594 |
+
// Flatten left-associative trees
|
1595 |
+
if ($c >= 2)
|
1596 |
+
{
|
1597 |
+
$left = $operands[$c - 2];
|
1598 |
+
if ($left->type == $op)
|
1599 |
+
{
|
1600 |
+
$right = array_pop($operands);
|
1601 |
+
$left->addNode($right);
|
1602 |
+
return $left;
|
1603 |
+
}
|
1604 |
+
}
|
1605 |
+
$arity = 2;
|
1606 |
+
}
|
1607 |
+
|
1608 |
+
// Always use push to add operands to n, to update start and end
|
1609 |
+
$a = array_splice($operands, $c - $arity);
|
1610 |
+
for ($i = 0; $i < $arity; $i++)
|
1611 |
+
$n->addNode($a[$i]);
|
1612 |
+
|
1613 |
+
// Include closing bracket or postfix operator in [start,end]
|
1614 |
+
$te = $this->t->currentToken()->end;
|
1615 |
+
if ($n->end < $te)
|
1616 |
+
$n->end = $te;
|
1617 |
+
|
1618 |
+
array_push($operands, $n);
|
1619 |
+
|
1620 |
+
return $n;
|
1621 |
+
}
|
1622 |
+
}
|
1623 |
+
|
1624 |
+
class JSCompilerContext
|
1625 |
+
{
|
1626 |
+
public $inFunction = false;
|
1627 |
+
public $inForLoopInit = false;
|
1628 |
+
public $ecmaStrictMode = false;
|
1629 |
+
public $bracketLevel = 0;
|
1630 |
+
public $curlyLevel = 0;
|
1631 |
+
public $parenLevel = 0;
|
1632 |
+
public $hookLevel = 0;
|
1633 |
+
|
1634 |
+
public $stmtStack = array();
|
1635 |
+
public $funDecls = array();
|
1636 |
+
public $varDecls = array();
|
1637 |
+
|
1638 |
+
public function __construct($inFunction)
|
1639 |
+
{
|
1640 |
+
$this->inFunction = $inFunction;
|
1641 |
+
}
|
1642 |
+
}
|
1643 |
+
|
1644 |
+
class JSNode
|
1645 |
+
{
|
1646 |
+
private $type;
|
1647 |
+
private $value;
|
1648 |
+
private $lineno;
|
1649 |
+
private $start;
|
1650 |
+
private $end;
|
1651 |
+
|
1652 |
+
public $treeNodes = array();
|
1653 |
+
public $funDecls = array();
|
1654 |
+
public $varDecls = array();
|
1655 |
+
|
1656 |
+
public function __construct($t, $type=0)
|
1657 |
+
{
|
1658 |
+
if ($token = $t->currentToken())
|
1659 |
+
{
|
1660 |
+
$this->type = $type ? $type : $token->type;
|
1661 |
+
$this->value = $token->value;
|
1662 |
+
$this->lineno = $token->lineno;
|
1663 |
+
$this->start = $token->start;
|
1664 |
+
$this->end = $token->end;
|
1665 |
+
}
|
1666 |
+
else
|
1667 |
+
{
|
1668 |
+
$this->type = $type;
|
1669 |
+
$this->lineno = $t->lineno;
|
1670 |
+
}
|
1671 |
+
|
1672 |
+
if (($numargs = func_num_args()) > 2)
|
1673 |
+
{
|
1674 |
+
$args = func_get_args();
|
1675 |
+
for ($i = 2; $i < $numargs; $i++)
|
1676 |
+
$this->addNode($args[$i]);
|
1677 |
+
}
|
1678 |
+
}
|
1679 |
+
|
1680 |
+
// we don't want to bloat our object with all kind of specific properties, so we use overloading
|
1681 |
+
public function __set($name, $value)
|
1682 |
+
{
|
1683 |
+
$this->$name = $value;
|
1684 |
+
}
|
1685 |
+
|
1686 |
+
public function __get($name)
|
1687 |
+
{
|
1688 |
+
if (isset($this->$name))
|
1689 |
+
return $this->$name;
|
1690 |
+
|
1691 |
+
return null;
|
1692 |
+
}
|
1693 |
+
|
1694 |
+
public function addNode($node)
|
1695 |
+
{
|
1696 |
+
if ($node !== null)
|
1697 |
+
{
|
1698 |
+
if ($node->start < $this->start)
|
1699 |
+
$this->start = $node->start;
|
1700 |
+
if ($this->end < $node->end)
|
1701 |
+
$this->end = $node->end;
|
1702 |
+
}
|
1703 |
+
|
1704 |
+
$this->treeNodes[] = $node;
|
1705 |
+
}
|
1706 |
+
}
|
1707 |
+
|
1708 |
+
class JSTokenizer
|
1709 |
+
{
|
1710 |
+
private $cursor = 0;
|
1711 |
+
private $source;
|
1712 |
+
|
1713 |
+
public $tokens = array();
|
1714 |
+
public $tokenIndex = 0;
|
1715 |
+
public $lookahead = 0;
|
1716 |
+
public $scanNewlines = false;
|
1717 |
+
public $scanOperand = true;
|
1718 |
+
|
1719 |
+
public $filename;
|
1720 |
+
public $lineno;
|
1721 |
+
|
1722 |
+
private $keywords = array(
|
1723 |
+
'break',
|
1724 |
+
'case', 'catch', 'const', 'continue',
|
1725 |
+
'debugger', 'default', 'delete', 'do',
|
1726 |
+
'else', 'enum',
|
1727 |
+
'false', 'finally', 'for', 'function',
|
1728 |
+
'if', 'in', 'instanceof',
|
1729 |
+
'new', 'null',
|
1730 |
+
'return',
|
1731 |
+
'switch',
|
1732 |
+
'this', 'throw', 'true', 'try', 'typeof',
|
1733 |
+
'var', 'void',
|
1734 |
+
'while', 'with'
|
1735 |
+
);
|
1736 |
+
|
1737 |
+
private $opTypeNames = array(
|
1738 |
+
';', ',', '?', ':', '||', '&&', '|', '^',
|
1739 |
+
'&', '===', '==', '=', '!==', '!=', '<<', '<=',
|
1740 |
+
'<', '>>>', '>>', '>=', '>', '++', '--', '+',
|
1741 |
+
'-', '*', '/', '%', '!', '~', '.', '[',
|
1742 |
+
']', '{', '}', '(', ')', '@*/'
|
1743 |
+
);
|
1744 |
+
|
1745 |
+
private $assignOps = array('|', '^', '&', '<<', '>>', '>>>', '+', '-', '*', '/', '%');
|
1746 |
+
private $opRegExp;
|
1747 |
+
|
1748 |
+
public function __construct()
|
1749 |
+
{
|
1750 |
+
$this->opRegExp = '#^(' . implode('|', array_map('preg_quote', $this->opTypeNames)) . ')#';
|
1751 |
+
}
|
1752 |
+
|
1753 |
+
public function init($source, $filename = '', $lineno = 1)
|
1754 |
+
{
|
1755 |
+
$this->source = $source;
|
1756 |
+
$this->filename = $filename ? $filename : '[inline]';
|
1757 |
+
$this->lineno = $lineno;
|
1758 |
+
|
1759 |
+
$this->cursor = 0;
|
1760 |
+
$this->tokens = array();
|
1761 |
+
$this->tokenIndex = 0;
|
1762 |
+
$this->lookahead = 0;
|
1763 |
+
$this->scanNewlines = false;
|
1764 |
+
$this->scanOperand = true;
|
1765 |
+
}
|
1766 |
+
|
1767 |
+
public function getInput($chunksize)
|
1768 |
+
{
|
1769 |
+
if ($chunksize)
|
1770 |
+
return substr($this->source, $this->cursor, $chunksize);
|
1771 |
+
|
1772 |
+
return substr($this->source, $this->cursor);
|
1773 |
+
}
|
1774 |
+
|
1775 |
+
public function isDone()
|
1776 |
+
{
|
1777 |
+
return $this->peek() == TOKEN_END;
|
1778 |
+
}
|
1779 |
+
|
1780 |
+
public function match($tt)
|
1781 |
+
{
|
1782 |
+
return $this->get() == $tt || $this->unget();
|
1783 |
+
}
|
1784 |
+
|
1785 |
+
public function mustMatch($tt)
|
1786 |
+
{
|
1787 |
+
if (!$this->match($tt))
|
1788 |
+
throw $this->newSyntaxError('Unexpected token; token ' . $tt . ' expected');
|
1789 |
+
|
1790 |
+
return $this->currentToken();
|
1791 |
+
}
|
1792 |
+
|
1793 |
+
public function peek()
|
1794 |
+
{
|
1795 |
+
if ($this->lookahead)
|
1796 |
+
{
|
1797 |
+
$next = $this->tokens[($this->tokenIndex + $this->lookahead) & 3];
|
1798 |
+
if ($this->scanNewlines && $next->lineno != $this->lineno)
|
1799 |
+
$tt = TOKEN_NEWLINE;
|
1800 |
+
else
|
1801 |
+
$tt = $next->type;
|
1802 |
+
}
|
1803 |
+
else
|
1804 |
+
{
|
1805 |
+
$tt = $this->get();
|
1806 |
+
$this->unget();
|
1807 |
+
}
|
1808 |
+
|
1809 |
+
return $tt;
|
1810 |
+
}
|
1811 |
+
|
1812 |
+
public function peekOnSameLine()
|
1813 |
+
{
|
1814 |
+
$this->scanNewlines = true;
|
1815 |
+
$tt = $this->peek();
|
1816 |
+
$this->scanNewlines = false;
|
1817 |
+
|
1818 |
+
return $tt;
|
1819 |
+
}
|
1820 |
+
|
1821 |
+
public function currentToken()
|
1822 |
+
{
|
1823 |
+
if (!empty($this->tokens))
|
1824 |
+
return $this->tokens[$this->tokenIndex];
|
1825 |
+
}
|
1826 |
+
|
1827 |
+
public function get($chunksize = 1000)
|
1828 |
+
{
|
1829 |
+
while($this->lookahead)
|
1830 |
+
{
|
1831 |
+
$this->lookahead--;
|
1832 |
+
$this->tokenIndex = ($this->tokenIndex + 1) & 3;
|
1833 |
+
$token = $this->tokens[$this->tokenIndex];
|
1834 |
+
if ($token->type != TOKEN_NEWLINE || $this->scanNewlines)
|
1835 |
+
return $token->type;
|
1836 |
+
}
|
1837 |
+
|
1838 |
+
$conditional_comment = false;
|
1839 |
+
|
1840 |
+
// strip whitespace and comments
|
1841 |
+
while(true)
|
1842 |
+
{
|
1843 |
+
$input = $this->getInput($chunksize);
|
1844 |
+
|
1845 |
+
// whitespace handling; gobble up \r as well (effectively we don't have support for MAC newlines!)
|
1846 |
+
$re = $this->scanNewlines ? '/^[ \r\t]+/' : '/^\s+/';
|
1847 |
+
if (preg_match($re, $input, $match))
|
1848 |
+
{
|
1849 |
+
$spaces = $match[0];
|
1850 |
+
$spacelen = strlen($spaces);
|
1851 |
+
$this->cursor += $spacelen;
|
1852 |
+
if (!$this->scanNewlines)
|
1853 |
+
$this->lineno += substr_count($spaces, "\n");
|
1854 |
+
|
1855 |
+
if ($spacelen == $chunksize)
|
1856 |
+
continue; // complete chunk contained whitespace
|
1857 |
+
|
1858 |
+
$input = $this->getInput($chunksize);
|
1859 |
+
if ($input == '' || $input[0] != '/')
|
1860 |
+
break;
|
1861 |
+
}
|
1862 |
+
|
1863 |
+
// Comments
|
1864 |
+
if (!preg_match('/^\/(?:\*(@(?:cc_on|if|elif|else|end))?.*?\*\/|\/[^\n]*)/s', $input, $match))
|
1865 |
+
{
|
1866 |
+
if (!$chunksize)
|
1867 |
+
break;
|
1868 |
+
|
1869 |
+
// retry with a full chunk fetch; this also prevents breakage of long regular expressions (which will never match a comment)
|
1870 |
+
$chunksize = null;
|
1871 |
+
continue;
|
1872 |
+
}
|
1873 |
+
|
1874 |
+
// check if this is a conditional (JScript) comment
|
1875 |
+
if (!empty($match[1]))
|
1876 |
+
{
|
1877 |
+
$match[0] = '/*' . $match[1];
|
1878 |
+
$conditional_comment = true;
|
1879 |
+
break;
|
1880 |
+
}
|
1881 |
+
else
|
1882 |
+
{
|
1883 |
+
$this->cursor += strlen($match[0]);
|
1884 |
+
$this->lineno += substr_count($match[0], "\n");
|
1885 |
+
}
|
1886 |
+
}
|
1887 |
+
|
1888 |
+
if ($input == '')
|
1889 |
+
{
|
1890 |
+
$tt = TOKEN_END;
|
1891 |
+
$match = array('');
|
1892 |
+
}
|
1893 |
+
elseif ($conditional_comment)
|
1894 |
+
{
|
1895 |
+
$tt = TOKEN_CONDCOMMENT_START;
|
1896 |
+
}
|
1897 |
+
else
|
1898 |
+
{
|
1899 |
+
switch ($input[0])
|
1900 |
+
{
|
1901 |
+
case '0':
|
1902 |
+
// hexadecimal
|
1903 |
+
if (($input[1] == 'x' || $input[1] == 'X') && preg_match('/^0x[0-9a-f]+/i', $input, $match))
|
1904 |
+
{
|
1905 |
+
$tt = TOKEN_NUMBER;
|
1906 |
+
break;
|
1907 |
+
}
|
1908 |
+
// FALL THROUGH
|
1909 |
+
|
1910 |
+
case '1': case '2': case '3': case '4': case '5':
|
1911 |
+
case '6': case '7': case '8': case '9':
|
1912 |
+
// should always match
|
1913 |
+
preg_match('/^\d+(?:\.\d*)?(?:[eE][-+]?\d+)?/', $input, $match);
|
1914 |
+
$tt = TOKEN_NUMBER;
|
1915 |
+
break;
|
1916 |
+
|
1917 |
+
case "'":
|
1918 |
+
if (preg_match('/^\'(?:[^\\\\\'\r\n]++|\\\\(?:.|\r?\n))*\'/', $input, $match))
|
1919 |
+
{
|
1920 |
+
$tt = TOKEN_STRING;
|
1921 |
+
}
|
1922 |
+
else
|
1923 |
+
{
|
1924 |
+
if ($chunksize)
|
1925 |
+
return $this->get(null); // retry with a full chunk fetch
|
1926 |
+
|
1927 |
+
throw $this->newSyntaxError('Unterminated string literal');
|
1928 |
+
}
|
1929 |
+
break;
|
1930 |
+
|
1931 |
+
case '"':
|
1932 |
+
if (preg_match('/^"(?:[^\\\\"\r\n]++|\\\\(?:.|\r?\n))*"/', $input, $match))
|
1933 |
+
{
|
1934 |
+
$tt = TOKEN_STRING;
|
1935 |
+
}
|
1936 |
+
else
|
1937 |
+
{
|
1938 |
+
if ($chunksize)
|
1939 |
+
return $this->get(null); // retry with a full chunk fetch
|
1940 |
+
|
1941 |
+
throw $this->newSyntaxError('Unterminated string literal');
|
1942 |
+
}
|
1943 |
+
break;
|
1944 |
+
|
1945 |
+
case '/':
|
1946 |
+
if ($this->scanOperand && preg_match('/^\/((?:\\\\.|\[(?:\\\\.|[^\]])*\]|[^\/])+)\/([gimy]*)/', $input, $match))
|
1947 |
+
{
|
1948 |
+
$tt = TOKEN_REGEXP;
|
1949 |
+
break;
|
1950 |
+
}
|
1951 |
+
// FALL THROUGH
|
1952 |
+
|
1953 |
+
case '|':
|
1954 |
+
case '^':
|
1955 |
+
case '&':
|
1956 |
+
case '<':
|
1957 |
+
case '>':
|
1958 |
+
case '+':
|
1959 |
+
case '-':
|
1960 |
+
case '*':
|
1961 |
+
case '%':
|
1962 |
+
case '=':
|
1963 |
+
case '!':
|
1964 |
+
// should always match
|
1965 |
+
preg_match($this->opRegExp, $input, $match);
|
1966 |
+
$op = $match[0];
|
1967 |
+
if (in_array($op, $this->assignOps) && $input[strlen($op)] == '=')
|
1968 |
+
{
|
1969 |
+
$tt = OP_ASSIGN;
|
1970 |
+
$match[0] .= '=';
|
1971 |
+
}
|
1972 |
+
else
|
1973 |
+
{
|
1974 |
+
$tt = $op;
|
1975 |
+
if ($this->scanOperand)
|
1976 |
+
{
|
1977 |
+
if ($op == OP_PLUS)
|
1978 |
+
$tt = OP_UNARY_PLUS;
|
1979 |
+
elseif ($op == OP_MINUS)
|
1980 |
+
$tt = OP_UNARY_MINUS;
|
1981 |
+
}
|
1982 |
+
$op = null;
|
1983 |
+
}
|
1984 |
+
break;
|
1985 |
+
|
1986 |
+
case '.':
|
1987 |
+
if (preg_match('/^\.\d+(?:[eE][-+]?\d+)?/', $input, $match))
|
1988 |
+
{
|
1989 |
+
$tt = TOKEN_NUMBER;
|
1990 |
+
break;
|
1991 |
+
}
|
1992 |
+
// FALL THROUGH
|
1993 |
+
|
1994 |
+
case ';':
|
1995 |
+
case ',':
|
1996 |
+
case '?':
|
1997 |
+
case ':':
|
1998 |
+
case '~':
|
1999 |
+
case '[':
|
2000 |
+
case ']':
|
2001 |
+
case '{':
|
2002 |
+
case '}':
|
2003 |
+
case '(':
|
2004 |
+
case ')':
|
2005 |
+
// these are all single
|
2006 |
+
$match = array($input[0]);
|
2007 |
+
$tt = $input[0];
|
2008 |
+
break;
|
2009 |
+
|
2010 |
+
case '@':
|
2011 |
+
// check end of conditional comment
|
2012 |
+
if (substr($input, 0, 3) == '@*/')
|
2013 |
+
{
|
2014 |
+
$match = array('@*/');
|
2015 |
+
$tt = TOKEN_CONDCOMMENT_END;
|
2016 |
+
}
|
2017 |
+
else
|
2018 |
+
throw $this->newSyntaxError('Illegal token');
|
2019 |
+
break;
|
2020 |
+
|
2021 |
+
case "\n":
|
2022 |
+
if ($this->scanNewlines)
|
2023 |
+
{
|
2024 |
+
$match = array("\n");
|
2025 |
+
$tt = TOKEN_NEWLINE;
|
2026 |
+
}
|
2027 |
+
else
|
2028 |
+
throw $this->newSyntaxError('Illegal token');
|
2029 |
+
break;
|
2030 |
+
|
2031 |
+
default:
|
2032 |
+
// FIXME: add support for unicode and unicode escape sequence \uHHHH
|
2033 |
+
if (preg_match('/^[$\w]+/', $input, $match))
|
2034 |
+
{
|
2035 |
+
$tt = in_array($match[0], $this->keywords) ? $match[0] : TOKEN_IDENTIFIER;
|
2036 |
+
}
|
2037 |
+
else
|
2038 |
+
throw $this->newSyntaxError('Illegal token');
|
2039 |
+
}
|
2040 |
+
}
|
2041 |
+
|
2042 |
+
$this->tokenIndex = ($this->tokenIndex + 1) & 3;
|
2043 |
+
|
2044 |
+
if (!isset($this->tokens[$this->tokenIndex]))
|
2045 |
+
$this->tokens[$this->tokenIndex] = new JSToken();
|
2046 |
+
|
2047 |
+
$token = $this->tokens[$this->tokenIndex];
|
2048 |
+
$token->type = $tt;
|
2049 |
+
|
2050 |
+
if ($tt == OP_ASSIGN)
|
2051 |
+
$token->assignOp = $op;
|
2052 |
+
|
2053 |
+
$token->start = $this->cursor;
|
2054 |
+
|
2055 |
+
$token->value = $match[0];
|
2056 |
+
$this->cursor += strlen($match[0]);
|
2057 |
+
|
2058 |
+
$token->end = $this->cursor;
|
2059 |
+
$token->lineno = $this->lineno;
|
2060 |
+
|
2061 |
+
return $tt;
|
2062 |
+
}
|
2063 |
+
|
2064 |
+
public function unget()
|
2065 |
+
{
|
2066 |
+
if (++$this->lookahead == 4)
|
2067 |
+
throw $this->newSyntaxError('PANIC: too much lookahead!');
|
2068 |
+
|
2069 |
+
$this->tokenIndex = ($this->tokenIndex - 1) & 3;
|
2070 |
+
}
|
2071 |
+
|
2072 |
+
public function newSyntaxError($m)
|
2073 |
+
{
|
2074 |
+
return new Exception('Parse error: ' . $m . ' in file \'' . $this->filename . '\' on line ' . $this->lineno);
|
2075 |
+
}
|
2076 |
+
}
|
2077 |
+
|
2078 |
+
class JSToken
|
2079 |
+
{
|
2080 |
+
public $type;
|
2081 |
+
public $value;
|
2082 |
+
public $start;
|
2083 |
+
public $end;
|
2084 |
+
public $lineno;
|
2085 |
+
public $assignOp;
|
2086 |
+
}
|
includes/min/lib/Minify.php
ADDED
@@ -0,0 +1,608 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Minify - Combines, minifies, and caches JavaScript and CSS files on demand.
|
9 |
+
*
|
10 |
+
* See README for usage instructions (for now).
|
11 |
+
*
|
12 |
+
* This library was inspired by {@link mailto:flashkot@mail.ru jscsscomp by Maxim Martynyuk}
|
13 |
+
* and by the article {@link http://www.hunlock.com/blogs/Supercharged_Javascript "Supercharged JavaScript" by Patrick Hunlock}.
|
14 |
+
*
|
15 |
+
* Requires PHP 5.1.0.
|
16 |
+
* Tested on PHP 5.1.6.
|
17 |
+
*
|
18 |
+
* @package Minify
|
19 |
+
* @author Ryan Grove <ryan@wonko.com>
|
20 |
+
* @author Stephen Clay <steve@mrclay.org>
|
21 |
+
* @copyright 2008 Ryan Grove, Stephen Clay. All rights reserved.
|
22 |
+
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
23 |
+
* @link http://code.google.com/p/minify/
|
24 |
+
*/
|
25 |
+
class Minify {
|
26 |
+
|
27 |
+
const VERSION = '2.1.7';
|
28 |
+
const TYPE_CSS = 'text/css';
|
29 |
+
const TYPE_HTML = 'text/html';
|
30 |
+
// there is some debate over the ideal JS Content-Type, but this is the
|
31 |
+
// Apache default and what Yahoo! uses..
|
32 |
+
const TYPE_JS = 'application/x-javascript';
|
33 |
+
const URL_DEBUG = 'http://code.google.com/p/minify/wiki/Debugging';
|
34 |
+
|
35 |
+
/**
|
36 |
+
* How many hours behind are the file modification times of uploaded files?
|
37 |
+
*
|
38 |
+
* If you upload files from Windows to a non-Windows server, Windows may report
|
39 |
+
* incorrect mtimes for the files. Immediately after modifying and uploading a
|
40 |
+
* file, use the touch command to update the mtime on the server. If the mtime
|
41 |
+
* jumps ahead by a number of hours, set this variable to that number. If the mtime
|
42 |
+
* moves back, this should not be needed.
|
43 |
+
*
|
44 |
+
* @var int $uploaderHoursBehind
|
45 |
+
*/
|
46 |
+
public static $uploaderHoursBehind = 0;
|
47 |
+
|
48 |
+
/**
|
49 |
+
* If this string is not empty AND the serve() option 'bubbleCssImports' is
|
50 |
+
* NOT set, then serve() will check CSS files for @import declarations that
|
51 |
+
* appear too late in the combined stylesheet. If found, serve() will prepend
|
52 |
+
* the output with this warning.
|
53 |
+
*
|
54 |
+
* @var string $importWarning
|
55 |
+
*/
|
56 |
+
public static $importWarning = "/* See http://code.google.com/p/minify/wiki/CommonProblems#@imports_can_appear_in_invalid_locations_in_combined_CSS_files */\n";
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Has the DOCUMENT_ROOT been set in user code?
|
60 |
+
*
|
61 |
+
* @var bool
|
62 |
+
*/
|
63 |
+
public static $isDocRootSet = false;
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Specify a cache object (with identical interface as Minify_Cache_File) or
|
67 |
+
* a path to use with Minify_Cache_File.
|
68 |
+
*
|
69 |
+
* If not called, Minify will not use a cache and, for each 200 response, will
|
70 |
+
* need to recombine files, minify and encode the output.
|
71 |
+
*
|
72 |
+
* @param mixed $cache object with identical interface as Minify_Cache_File or
|
73 |
+
* a directory path, or null to disable caching. (default = '')
|
74 |
+
*
|
75 |
+
* @param bool $fileLocking (default = true) This only applies if the first
|
76 |
+
* parameter is a string.
|
77 |
+
*
|
78 |
+
* @return null
|
79 |
+
*/
|
80 |
+
public static function setCache($cache = '', $fileLocking = true)
|
81 |
+
{
|
82 |
+
if (is_string($cache)) {
|
83 |
+
self::$_cache = new Minify_Cache_File($cache, $fileLocking);
|
84 |
+
} else {
|
85 |
+
self::$_cache = $cache;
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Serve a request for a minified file.
|
91 |
+
*
|
92 |
+
* Here are the available options and defaults in the base controller:
|
93 |
+
*
|
94 |
+
* 'isPublic' : send "public" instead of "private" in Cache-Control
|
95 |
+
* headers, allowing shared caches to cache the output. (default true)
|
96 |
+
*
|
97 |
+
* 'quiet' : set to true to have serve() return an array rather than sending
|
98 |
+
* any headers/output (default false)
|
99 |
+
*
|
100 |
+
* 'encodeOutput' : set to false to disable content encoding, and not send
|
101 |
+
* the Vary header (default true)
|
102 |
+
*
|
103 |
+
* 'encodeMethod' : generally you should let this be determined by
|
104 |
+
* HTTP_Encoder (leave null), but you can force a particular encoding
|
105 |
+
* to be returned, by setting this to 'gzip' or '' (no encoding)
|
106 |
+
*
|
107 |
+
* 'encodeLevel' : level of encoding compression (0 to 9, default 9)
|
108 |
+
*
|
109 |
+
* 'contentTypeCharset' : appended to the Content-Type header sent. Set to a falsey
|
110 |
+
* value to remove. (default 'utf-8')
|
111 |
+
*
|
112 |
+
* 'maxAge' : set this to the number of seconds the client should use its cache
|
113 |
+
* before revalidating with the server. This sets Cache-Control: max-age and the
|
114 |
+
* Expires header. Unlike the old 'setExpires' setting, this setting will NOT
|
115 |
+
* prevent conditional GETs. Note this has nothing to do with server-side caching.
|
116 |
+
*
|
117 |
+
* 'rewriteCssUris' : If true, serve() will automatically set the 'currentDir'
|
118 |
+
* minifier option to enable URI rewriting in CSS files (default true)
|
119 |
+
*
|
120 |
+
* 'bubbleCssImports' : If true, all @import declarations in combined CSS
|
121 |
+
* files will be move to the top. Note this may alter effective CSS values
|
122 |
+
* due to a change in order. (default false)
|
123 |
+
*
|
124 |
+
* 'debug' : set to true to minify all sources with the 'Lines' controller, which
|
125 |
+
* eases the debugging of combined files. This also prevents 304 responses.
|
126 |
+
* @see Minify_Lines::minify()
|
127 |
+
*
|
128 |
+
* 'minifiers' : to override Minify's default choice of minifier function for
|
129 |
+
* a particular content-type, specify your callback under the key of the
|
130 |
+
* content-type:
|
131 |
+
* <code>
|
132 |
+
* // call customCssMinifier($css) for all CSS minification
|
133 |
+
* $options['minifiers'][Minify::TYPE_CSS] = 'customCssMinifier';
|
134 |
+
*
|
135 |
+
* // don't minify Javascript at all
|
136 |
+
* $options['minifiers'][Minify::TYPE_JS] = '';
|
137 |
+
* </code>
|
138 |
+
*
|
139 |
+
* 'minifierOptions' : to send options to the minifier function, specify your options
|
140 |
+
* under the key of the content-type. E.g. To send the CSS minifier an option:
|
141 |
+
* <code>
|
142 |
+
* // give CSS minifier array('optionName' => 'optionValue') as 2nd argument
|
143 |
+
* $options['minifierOptions'][Minify::TYPE_CSS]['optionName'] = 'optionValue';
|
144 |
+
* </code>
|
145 |
+
*
|
146 |
+
* 'contentType' : (optional) this is only needed if your file extension is not
|
147 |
+
* js/css/html. The given content-type will be sent regardless of source file
|
148 |
+
* extension, so this should not be used in a Groups config with other
|
149 |
+
* Javascript/CSS files.
|
150 |
+
*
|
151 |
+
* Any controller options are documented in that controller's setupSources() method.
|
152 |
+
*
|
153 |
+
* @param mixed $controller instance of subclass of Minify_Controller_Base or string
|
154 |
+
* name of controller. E.g. 'Files'
|
155 |
+
*
|
156 |
+
* @param array $options controller/serve options
|
157 |
+
*
|
158 |
+
* @return null|array if the 'quiet' option is set to true, an array
|
159 |
+
* with keys "success" (bool), "statusCode" (int), "content" (string), and
|
160 |
+
* "headers" (array).
|
161 |
+
*
|
162 |
+
* @throws Exception
|
163 |
+
*/
|
164 |
+
public static function serve($controller, $options = array())
|
165 |
+
{
|
166 |
+
if (! self::$isDocRootSet && 0 === stripos(PHP_OS, 'win')) {
|
167 |
+
self::setDocRoot();
|
168 |
+
}
|
169 |
+
|
170 |
+
if (is_string($controller)) {
|
171 |
+
// make $controller into object
|
172 |
+
$class = 'Minify_Controller_' . $controller;
|
173 |
+
$controller = new $class();
|
174 |
+
/* @var Minify_Controller_Base $controller */
|
175 |
+
}
|
176 |
+
|
177 |
+
// set up controller sources and mix remaining options with
|
178 |
+
// controller defaults
|
179 |
+
$options = $controller->setupSources($options);
|
180 |
+
$options = $controller->analyzeSources($options);
|
181 |
+
self::$_options = $controller->mixInDefaultOptions($options);
|
182 |
+
|
183 |
+
// check request validity
|
184 |
+
if (! $controller->sources) {
|
185 |
+
// invalid request!
|
186 |
+
if (! self::$_options['quiet']) {
|
187 |
+
self::_errorExit(self::$_options['badRequestHeader'], self::URL_DEBUG);
|
188 |
+
} else {
|
189 |
+
list(,$statusCode) = explode(' ', self::$_options['badRequestHeader']);
|
190 |
+
return array(
|
191 |
+
'success' => false
|
192 |
+
,'statusCode' => (int)$statusCode
|
193 |
+
,'content' => ''
|
194 |
+
,'headers' => array()
|
195 |
+
);
|
196 |
+
}
|
197 |
+
}
|
198 |
+
|
199 |
+
self::$_controller = $controller;
|
200 |
+
|
201 |
+
if (self::$_options['debug']) {
|
202 |
+
self::_setupDebug($controller->sources);
|
203 |
+
self::$_options['maxAge'] = 0;
|
204 |
+
}
|
205 |
+
|
206 |
+
// determine encoding
|
207 |
+
if (self::$_options['encodeOutput']) {
|
208 |
+
$sendVary = true;
|
209 |
+
if (self::$_options['encodeMethod'] !== null) {
|
210 |
+
// controller specifically requested this
|
211 |
+
$contentEncoding = self::$_options['encodeMethod'];
|
212 |
+
} else {
|
213 |
+
// sniff request header
|
214 |
+
// depending on what the client accepts, $contentEncoding may be
|
215 |
+
// 'x-gzip' while our internal encodeMethod is 'gzip'. Calling
|
216 |
+
// getAcceptedEncoding(false, false) leaves out compress and deflate as options.
|
217 |
+
list(self::$_options['encodeMethod'], $contentEncoding) = HTTP_Encoder::getAcceptedEncoding(false, false);
|
218 |
+
$sendVary = ! HTTP_Encoder::isBuggyIe();
|
219 |
+
}
|
220 |
+
} else {
|
221 |
+
self::$_options['encodeMethod'] = ''; // identity (no encoding)
|
222 |
+
}
|
223 |
+
|
224 |
+
// check client cache
|
225 |
+
$cgOptions = array(
|
226 |
+
'lastModifiedTime' => self::$_options['lastModifiedTime']
|
227 |
+
,'isPublic' => self::$_options['isPublic']
|
228 |
+
,'encoding' => self::$_options['encodeMethod']
|
229 |
+
);
|
230 |
+
if (self::$_options['maxAge'] > 0) {
|
231 |
+
$cgOptions['maxAge'] = self::$_options['maxAge'];
|
232 |
+
} elseif (self::$_options['debug']) {
|
233 |
+
$cgOptions['invalidate'] = true;
|
234 |
+
}
|
235 |
+
$cg = new HTTP_ConditionalGet($cgOptions);
|
236 |
+
if ($cg->cacheIsValid) {
|
237 |
+
// client's cache is valid
|
238 |
+
if (! self::$_options['quiet']) {
|
239 |
+
$cg->sendHeaders();
|
240 |
+
return;
|
241 |
+
} else {
|
242 |
+
return array(
|
243 |
+
'success' => true
|
244 |
+
,'statusCode' => 304
|
245 |
+
,'content' => ''
|
246 |
+
,'headers' => $cg->getHeaders()
|
247 |
+
);
|
248 |
+
}
|
249 |
+
} else {
|
250 |
+
// client will need output
|
251 |
+
$headers = $cg->getHeaders();
|
252 |
+
unset($cg);
|
253 |
+
}
|
254 |
+
|
255 |
+
if (self::$_options['contentType'] === self::TYPE_CSS
|
256 |
+
&& self::$_options['rewriteCssUris']) {
|
257 |
+
foreach($controller->sources as $key => $source) {
|
258 |
+
if ($source->filepath
|
259 |
+
&& !isset($source->minifyOptions['currentDir'])
|
260 |
+
&& !isset($source->minifyOptions['prependRelativePath'])
|
261 |
+
) {
|
262 |
+
$source->minifyOptions['currentDir'] = dirname($source->filepath);
|
263 |
+
}
|
264 |
+
}
|
265 |
+
}
|
266 |
+
|
267 |
+
// check server cache
|
268 |
+
if (null !== self::$_cache && ! self::$_options['debug']) {
|
269 |
+
// using cache
|
270 |
+
// the goal is to use only the cache methods to sniff the length and
|
271 |
+
// output the content, as they do not require ever loading the file into
|
272 |
+
// memory.
|
273 |
+
$cacheId = self::_getCacheId();
|
274 |
+
$fullCacheId = (self::$_options['encodeMethod'])
|
275 |
+
? $cacheId . '.gz'
|
276 |
+
: $cacheId;
|
277 |
+
// check cache for valid entry
|
278 |
+
$cacheIsReady = self::$_cache->isValid($fullCacheId, self::$_options['lastModifiedTime']);
|
279 |
+
if ($cacheIsReady) {
|
280 |
+
$cacheContentLength = self::$_cache->getSize($fullCacheId);
|
281 |
+
} else {
|
282 |
+
// generate & cache content
|
283 |
+
try {
|
284 |
+
$content = self::_combineMinify();
|
285 |
+
} catch (Exception $e) {
|
286 |
+
self::$_controller->log($e->getMessage());
|
287 |
+
if (! self::$_options['quiet']) {
|
288 |
+
self::_errorExit(self::$_options['errorHeader'], self::URL_DEBUG);
|
289 |
+
}
|
290 |
+
throw $e;
|
291 |
+
}
|
292 |
+
self::$_cache->store($cacheId, $content);
|
293 |
+
if (function_exists('gzencode') && self::$_options['encodeMethod']) {
|
294 |
+
self::$_cache->store($cacheId . '.gz', gzencode($content, self::$_options['encodeLevel']));
|
295 |
+
}
|
296 |
+
}
|
297 |
+
} else {
|
298 |
+
// no cache
|
299 |
+
$cacheIsReady = false;
|
300 |
+
try {
|
301 |
+
$content = self::_combineMinify();
|
302 |
+
} catch (Exception $e) {
|
303 |
+
self::$_controller->log($e->getMessage());
|
304 |
+
if (! self::$_options['quiet']) {
|
305 |
+
self::_errorExit(self::$_options['errorHeader'], self::URL_DEBUG);
|
306 |
+
}
|
307 |
+
throw $e;
|
308 |
+
}
|
309 |
+
}
|
310 |
+
if (! $cacheIsReady && self::$_options['encodeMethod']) {
|
311 |
+
// still need to encode
|
312 |
+
$content = gzencode($content, self::$_options['encodeLevel']);
|
313 |
+
}
|
314 |
+
|
315 |
+
// add headers
|
316 |
+
$headers['Content-Length'] = $cacheIsReady
|
317 |
+
? $cacheContentLength
|
318 |
+
: ((function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
|
319 |
+
? mb_strlen($content, '8bit')
|
320 |
+
: strlen($content)
|
321 |
+
);
|
322 |
+
$headers['Content-Type'] = self::$_options['contentTypeCharset']
|
323 |
+
? self::$_options['contentType'] . '; charset=' . self::$_options['contentTypeCharset']
|
324 |
+
: self::$_options['contentType'];
|
325 |
+
if (self::$_options['encodeMethod'] !== '') {
|
326 |
+
$headers['Content-Encoding'] = $contentEncoding;
|
327 |
+
}
|
328 |
+
if (self::$_options['encodeOutput'] && $sendVary) {
|
329 |
+
$headers['Vary'] = 'Accept-Encoding';
|
330 |
+
}
|
331 |
+
|
332 |
+
if (! self::$_options['quiet']) {
|
333 |
+
// output headers & content
|
334 |
+
foreach ($headers as $name => $val) {
|
335 |
+
header($name . ': ' . $val);
|
336 |
+
}
|
337 |
+
if ($cacheIsReady) {
|
338 |
+
self::$_cache->display($fullCacheId);
|
339 |
+
} else {
|
340 |
+
echo $content;
|
341 |
+
}
|
342 |
+
} else {
|
343 |
+
return array(
|
344 |
+
'success' => true
|
345 |
+
,'statusCode' => 200
|
346 |
+
,'content' => $cacheIsReady
|
347 |
+
? self::$_cache->fetch($fullCacheId)
|
348 |
+
: $content
|
349 |
+
,'headers' => $headers
|
350 |
+
);
|
351 |
+
}
|
352 |
+
}
|
353 |
+
|
354 |
+
/**
|
355 |
+
* Return combined minified content for a set of sources
|
356 |
+
*
|
357 |
+
* No internal caching will be used and the content will not be HTTP encoded.
|
358 |
+
*
|
359 |
+
* @param array $sources array of filepaths and/or Minify_Source objects
|
360 |
+
*
|
361 |
+
* @param array $options (optional) array of options for serve. By default
|
362 |
+
* these are already set: quiet = true, encodeMethod = '', lastModifiedTime = 0.
|
363 |
+
*
|
364 |
+
* @return string
|
365 |
+
*/
|
366 |
+
public static function combine($sources, $options = array())
|
367 |
+
{
|
368 |
+
$cache = self::$_cache;
|
369 |
+
self::$_cache = null;
|
370 |
+
$options = array_merge(array(
|
371 |
+
'files' => (array)$sources
|
372 |
+
,'quiet' => true
|
373 |
+
,'encodeMethod' => ''
|
374 |
+
,'lastModifiedTime' => 0
|
375 |
+
), $options);
|
376 |
+
$out = self::serve('Files', $options);
|
377 |
+
self::$_cache = $cache;
|
378 |
+
return $out['content'];
|
379 |
+
}
|
380 |
+
|
381 |
+
/**
|
382 |
+
* Set $_SERVER['DOCUMENT_ROOT']. On IIS, the value is created from SCRIPT_FILENAME and SCRIPT_NAME.
|
383 |
+
*
|
384 |
+
* @param string $docRoot value to use for DOCUMENT_ROOT
|
385 |
+
*/
|
386 |
+
public static function setDocRoot($docRoot = '')
|
387 |
+
{
|
388 |
+
self::$isDocRootSet = true;
|
389 |
+
if ($docRoot) {
|
390 |
+
$_SERVER['DOCUMENT_ROOT'] = $docRoot;
|
391 |
+
} elseif (isset($_SERVER['SERVER_SOFTWARE'])
|
392 |
+
&& 0 === strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/')) {
|
393 |
+
$_SERVER['DOCUMENT_ROOT'] = substr(
|
394 |
+
$_SERVER['SCRIPT_FILENAME']
|
395 |
+
,0
|
396 |
+
,strlen($_SERVER['SCRIPT_FILENAME']) - strlen($_SERVER['SCRIPT_NAME']));
|
397 |
+
$_SERVER['DOCUMENT_ROOT'] = rtrim($_SERVER['DOCUMENT_ROOT'], '\\');
|
398 |
+
}
|
399 |
+
}
|
400 |
+
|
401 |
+
/**
|
402 |
+
* Any Minify_Cache_* object or null (i.e. no server cache is used)
|
403 |
+
*
|
404 |
+
* @var Minify_Cache_File
|
405 |
+
*/
|
406 |
+
private static $_cache = null;
|
407 |
+
|
408 |
+
/**
|
409 |
+
* Active controller for current request
|
410 |
+
*
|
411 |
+
* @var Minify_Controller_Base
|
412 |
+
*/
|
413 |
+
protected static $_controller = null;
|
414 |
+
|
415 |
+
/**
|
416 |
+
* Options for current request
|
417 |
+
*
|
418 |
+
* @var array
|
419 |
+
*/
|
420 |
+
protected static $_options = null;
|
421 |
+
|
422 |
+
/**
|
423 |
+
* @param string $header
|
424 |
+
*
|
425 |
+
* @param string $url
|
426 |
+
*/
|
427 |
+
protected static function _errorExit($header, $url)
|
428 |
+
{
|
429 |
+
$url = htmlspecialchars($url, ENT_QUOTES);
|
430 |
+
list(,$h1) = explode(' ', $header, 2);
|
431 |
+
$h1 = htmlspecialchars($h1);
|
432 |
+
// FastCGI environments require 3rd arg to header() to be set
|
433 |
+
list(, $code) = explode(' ', $header, 3);
|
434 |
+
header($header, true, $code);
|
435 |
+
header('Content-Type: text/html; charset=utf-8');
|
436 |
+
echo "<h1>$h1</h1>";
|
437 |
+
echo "<p>Please see <a href='$url'>$url</a>.</p>";
|
438 |
+
exit();
|
439 |
+
}
|
440 |
+
|
441 |
+
/**
|
442 |
+
* Set up sources to use Minify_Lines
|
443 |
+
*
|
444 |
+
* @param Minify_Source[] $sources Minify_Source instances
|
445 |
+
*/
|
446 |
+
protected static function _setupDebug($sources)
|
447 |
+
{
|
448 |
+
foreach ($sources as $source) {
|
449 |
+
$source->minifier = array('Minify_Lines', 'minify');
|
450 |
+
$id = $source->getId();
|
451 |
+
$source->minifyOptions = array(
|
452 |
+
'id' => (is_file($id) ? basename($id) : $id)
|
453 |
+
);
|
454 |
+
}
|
455 |
+
}
|
456 |
+
|
457 |
+
/**
|
458 |
+
* Combines sources and minifies the result.
|
459 |
+
*
|
460 |
+
* @return string
|
461 |
+
*
|
462 |
+
* @throws Exception
|
463 |
+
*/
|
464 |
+
protected static function _combineMinify()
|
465 |
+
{
|
466 |
+
$type = self::$_options['contentType']; // ease readability
|
467 |
+
|
468 |
+
// when combining scripts, make sure all statements separated and
|
469 |
+
// trailing single line comment is terminated
|
470 |
+
$implodeSeparator = ($type === self::TYPE_JS)
|
471 |
+
? "\n;"
|
472 |
+
: '';
|
473 |
+
// allow the user to pass a particular array of options to each
|
474 |
+
// minifier (designated by type). source objects may still override
|
475 |
+
// these
|
476 |
+
$defaultOptions = isset(self::$_options['minifierOptions'][$type])
|
477 |
+
? self::$_options['minifierOptions'][$type]
|
478 |
+
: array();
|
479 |
+
// if minifier not set, default is no minification. source objects
|
480 |
+
// may still override this
|
481 |
+
$defaultMinifier = isset(self::$_options['minifiers'][$type])
|
482 |
+
? self::$_options['minifiers'][$type]
|
483 |
+
: false;
|
484 |
+
|
485 |
+
// process groups of sources with identical minifiers/options
|
486 |
+
$content = array();
|
487 |
+
$i = 0;
|
488 |
+
$l = count(self::$_controller->sources);
|
489 |
+
$groupToProcessTogether = array();
|
490 |
+
$lastMinifier = null;
|
491 |
+
$lastOptions = null;
|
492 |
+
do {
|
493 |
+
// get next source
|
494 |
+
$source = null;
|
495 |
+
if ($i < $l) {
|
496 |
+
$source = self::$_controller->sources[$i];
|
497 |
+
/* @var Minify_Source $source */
|
498 |
+
$sourceContent = $source->getContent();
|
499 |
+
|
500 |
+
// allow the source to override our minifier and options
|
501 |
+
$minifier = (null !== $source->minifier)
|
502 |
+
? $source->minifier
|
503 |
+
: $defaultMinifier;
|
504 |
+
$options = (null !== $source->minifyOptions)
|
505 |
+
? array_merge($defaultOptions, $source->minifyOptions)
|
506 |
+
: $defaultOptions;
|
507 |
+
}
|
508 |
+
// do we need to process our group right now?
|
509 |
+
if ($i > 0 // yes, we have at least the first group populated
|
510 |
+
&& (
|
511 |
+
! $source // yes, we ran out of sources
|
512 |
+
|| $type === self::TYPE_CSS // yes, to process CSS individually (avoiding PCRE bugs/limits)
|
513 |
+
|| $minifier !== $lastMinifier // yes, minifier changed
|
514 |
+
|| $options !== $lastOptions) // yes, options changed
|
515 |
+
)
|
516 |
+
{
|
517 |
+
// minify previous sources with last settings
|
518 |
+
$imploded = implode($implodeSeparator, $groupToProcessTogether);
|
519 |
+
$groupToProcessTogether = array();
|
520 |
+
if ($lastMinifier) {
|
521 |
+
try {
|
522 |
+
$content[] = call_user_func($lastMinifier, $imploded, $lastOptions);
|
523 |
+
} catch (Exception $e) {
|
524 |
+
throw new Exception("Exception in minifier: " . $e->getMessage());
|
525 |
+
}
|
526 |
+
} else {
|
527 |
+
$content[] = $imploded;
|
528 |
+
}
|
529 |
+
}
|
530 |
+
// add content to the group
|
531 |
+
if ($source) {
|
532 |
+
$groupToProcessTogether[] = $sourceContent;
|
533 |
+
$lastMinifier = $minifier;
|
534 |
+
$lastOptions = $options;
|
535 |
+
}
|
536 |
+
$i++;
|
537 |
+
} while ($source);
|
538 |
+
|
539 |
+
$content = implode($implodeSeparator, $content);
|
540 |
+
|
541 |
+
if ($type === self::TYPE_CSS && false !== strpos($content, '@import')) {
|
542 |
+
$content = self::_handleCssImports($content);
|
543 |
+
}
|
544 |
+
|
545 |
+
// do any post-processing (esp. for editing build URIs)
|
546 |
+
if (self::$_options['postprocessorRequire']) {
|
547 |
+
require_once self::$_options['postprocessorRequire'];
|
548 |
+
}
|
549 |
+
if (self::$_options['postprocessor']) {
|
550 |
+
$content = call_user_func(self::$_options['postprocessor'], $content, $type);
|
551 |
+
}
|
552 |
+
return $content;
|
553 |
+
}
|
554 |
+
|
555 |
+
/**
|
556 |
+
* Make a unique cache id for for this request.
|
557 |
+
*
|
558 |
+
* Any settings that could affect output are taken into consideration
|
559 |
+
*
|
560 |
+
* @param string $prefix
|
561 |
+
*
|
562 |
+
* @return string
|
563 |
+
*/
|
564 |
+
protected static function _getCacheId($prefix = 'minify')
|
565 |
+
{
|
566 |
+
$name = preg_replace('/[^a-zA-Z0-9\\.=_,]/', '', self::$_controller->selectionId);
|
567 |
+
$name = preg_replace('/\\.+/', '.', $name);
|
568 |
+
$name = substr($name, 0, 200 - 34 - strlen($prefix));
|
569 |
+
$md5 = md5(serialize(array(
|
570 |
+
Minify_Source::getDigest(self::$_controller->sources)
|
571 |
+
,self::$_options['minifiers']
|
572 |
+
,self::$_options['minifierOptions']
|
573 |
+
,self::$_options['postprocessor']
|
574 |
+
,self::$_options['bubbleCssImports']
|
575 |
+
,self::VERSION
|
576 |
+
)));
|
577 |
+
return "{$prefix}_{$name}_{$md5}";
|
578 |
+
}
|
579 |
+
|
580 |
+
/**
|
581 |
+
* Bubble CSS @imports to the top or prepend a warning if an import is detected not at the top.
|
582 |
+
*
|
583 |
+
* @param string $css
|
584 |
+
*
|
585 |
+
* @return string
|
586 |
+
*/
|
587 |
+
protected static function _handleCssImports($css)
|
588 |
+
{
|
589 |
+
if (self::$_options['bubbleCssImports']) {
|
590 |
+
// bubble CSS imports
|
591 |
+
preg_match_all('/@import.*?;/', $css, $imports);
|
592 |
+
$css = implode('', $imports[0]) . preg_replace('/@import.*?;/', '', $css);
|
593 |
+
} else if ('' !== self::$importWarning) {
|
594 |
+
// remove comments so we don't mistake { in a comment as a block
|
595 |
+
$noCommentCss = preg_replace('@/\\*[\\s\\S]*?\\*/@', '', $css);
|
596 |
+
$lastImportPos = strrpos($noCommentCss, '@import');
|
597 |
+
$firstBlockPos = strpos($noCommentCss, '{');
|
598 |
+
if (false !== $lastImportPos
|
599 |
+
&& false !== $firstBlockPos
|
600 |
+
&& $firstBlockPos < $lastImportPos
|
601 |
+
) {
|
602 |
+
// { appears before @import : prepend warning
|
603 |
+
$css = self::$importWarning . $css;
|
604 |
+
}
|
605 |
+
}
|
606 |
+
return $css;
|
607 |
+
}
|
608 |
+
}
|
includes/min/lib/Minify/Build.php
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_Build
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Maintain a single last modification time for a group of Minify sources to
|
9 |
+
* allow use of far off Expires headers in Minify.
|
10 |
+
*
|
11 |
+
* <code>
|
12 |
+
* // in config file
|
13 |
+
* $groupSources = array(
|
14 |
+
* 'js' => array('file1.js', 'file2.js')
|
15 |
+
* ,'css' => array('file1.css', 'file2.css', 'file3.css')
|
16 |
+
* )
|
17 |
+
*
|
18 |
+
* // during HTML generation
|
19 |
+
* $jsBuild = new Minify_Build($groupSources['js']);
|
20 |
+
* $cssBuild = new Minify_Build($groupSources['css']);
|
21 |
+
*
|
22 |
+
* $script = "<script type='text/javascript' src='"
|
23 |
+
* . $jsBuild->uri('/min.php/js') . "'></script>";
|
24 |
+
* $link = "<link rel='stylesheet' type='text/css' href='"
|
25 |
+
* . $cssBuild->uri('/min.php/css') . "'>";
|
26 |
+
*
|
27 |
+
* // in min.php
|
28 |
+
* Minify::serve('Groups', array(
|
29 |
+
* 'groups' => $groupSources
|
30 |
+
* ,'setExpires' => (time() + 86400 * 365)
|
31 |
+
* ));
|
32 |
+
* </code>
|
33 |
+
*
|
34 |
+
* @package Minify
|
35 |
+
* @author Stephen Clay <steve@mrclay.org>
|
36 |
+
*/
|
37 |
+
class Minify_Build {
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Last modification time of all files in the build
|
41 |
+
*
|
42 |
+
* @var int
|
43 |
+
*/
|
44 |
+
public $lastModified = 0;
|
45 |
+
|
46 |
+
/**
|
47 |
+
* String to use as ampersand in uri(). Set this to '&' if
|
48 |
+
* you are not HTML-escaping URIs.
|
49 |
+
*
|
50 |
+
* @var string
|
51 |
+
*/
|
52 |
+
public static $ampersand = '&';
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Get a time-stamped URI
|
56 |
+
*
|
57 |
+
* <code>
|
58 |
+
* echo $b->uri('/site.js');
|
59 |
+
* // outputs "/site.js?1678242"
|
60 |
+
*
|
61 |
+
* echo $b->uri('/scriptaculous.js?load=effects');
|
62 |
+
* // outputs "/scriptaculous.js?load=effects&1678242"
|
63 |
+
* </code>
|
64 |
+
*
|
65 |
+
* @param string $uri
|
66 |
+
* @param boolean $forceAmpersand (default = false) Force the use of ampersand to
|
67 |
+
* append the timestamp to the URI.
|
68 |
+
* @return string
|
69 |
+
*/
|
70 |
+
public function uri($uri, $forceAmpersand = false) {
|
71 |
+
$sep = ($forceAmpersand || strpos($uri, '?') !== false)
|
72 |
+
? self::$ampersand
|
73 |
+
: '?';
|
74 |
+
return "{$uri}{$sep}{$this->lastModified}";
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Create a build object
|
79 |
+
*
|
80 |
+
* @param array $sources array of Minify_Source objects and/or file paths
|
81 |
+
*
|
82 |
+
* @return null
|
83 |
+
*/
|
84 |
+
public function __construct($sources)
|
85 |
+
{
|
86 |
+
$max = 0;
|
87 |
+
foreach ((array)$sources as $source) {
|
88 |
+
if ($source instanceof Minify_Source) {
|
89 |
+
$max = max($max, $source->lastModified);
|
90 |
+
} elseif (is_string($source)) {
|
91 |
+
if (0 === strpos($source, '//')) {
|
92 |
+
$source = $_SERVER['DOCUMENT_ROOT'] . substr($source, 1);
|
93 |
+
}
|
94 |
+
if (is_file($source)) {
|
95 |
+
$max = max($max, filemtime($source));
|
96 |
+
}
|
97 |
+
}
|
98 |
+
}
|
99 |
+
$this->lastModified = $max;
|
100 |
+
}
|
101 |
+
}
|
includes/min/lib/Minify/CSS.php
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_CSS
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Minify CSS
|
9 |
+
*
|
10 |
+
* This class uses Minify_CSS_Compressor and Minify_CSS_UriRewriter to
|
11 |
+
* minify CSS and rewrite relative URIs.
|
12 |
+
*
|
13 |
+
* @package Minify
|
14 |
+
* @author Stephen Clay <steve@mrclay.org>
|
15 |
+
* @author http://code.google.com/u/1stvamp/ (Issue 64 patch)
|
16 |
+
*/
|
17 |
+
class Minify_CSS {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Minify a CSS string
|
21 |
+
*
|
22 |
+
* @param string $css
|
23 |
+
*
|
24 |
+
* @param array $options available options:
|
25 |
+
*
|
26 |
+
* 'preserveComments': (default true) multi-line comments that begin
|
27 |
+
* with "/*!" will be preserved with newlines before and after to
|
28 |
+
* enhance readability.
|
29 |
+
*
|
30 |
+
* 'removeCharsets': (default true) remove all @charset at-rules
|
31 |
+
*
|
32 |
+
* 'prependRelativePath': (default null) if given, this string will be
|
33 |
+
* prepended to all relative URIs in import/url declarations
|
34 |
+
*
|
35 |
+
* 'currentDir': (default null) if given, this is assumed to be the
|
36 |
+
* directory of the current CSS file. Using this, minify will rewrite
|
37 |
+
* all relative URIs in import/url declarations to correctly point to
|
38 |
+
* the desired files. For this to work, the files *must* exist and be
|
39 |
+
* visible by the PHP process.
|
40 |
+
*
|
41 |
+
* 'symlinks': (default = array()) If the CSS file is stored in
|
42 |
+
* a symlink-ed directory, provide an array of link paths to
|
43 |
+
* target paths, where the link paths are within the document root. Because
|
44 |
+
* paths need to be normalized for this to work, use "//" to substitute
|
45 |
+
* the doc root in the link paths (the array keys). E.g.:
|
46 |
+
* <code>
|
47 |
+
* array('//symlink' => '/real/target/path') // unix
|
48 |
+
* array('//static' => 'D:\\staticStorage') // Windows
|
49 |
+
* </code>
|
50 |
+
*
|
51 |
+
* 'docRoot': (default = $_SERVER['DOCUMENT_ROOT'])
|
52 |
+
* see Minify_CSS_UriRewriter::rewrite
|
53 |
+
*
|
54 |
+
* @return string
|
55 |
+
*/
|
56 |
+
public static function minify($css, $options = array())
|
57 |
+
{
|
58 |
+
$options = array_merge(array(
|
59 |
+
'compress' => true,
|
60 |
+
'removeCharsets' => true,
|
61 |
+
'preserveComments' => true,
|
62 |
+
'currentDir' => null,
|
63 |
+
'docRoot' => $_SERVER['DOCUMENT_ROOT'],
|
64 |
+
'prependRelativePath' => null,
|
65 |
+
'symlinks' => array(),
|
66 |
+
), $options);
|
67 |
+
|
68 |
+
if ($options['removeCharsets']) {
|
69 |
+
$css = preg_replace('/@charset[^;]+;\\s*/', '', $css);
|
70 |
+
}
|
71 |
+
if ($options['compress']) {
|
72 |
+
if (! $options['preserveComments']) {
|
73 |
+
$css = Minify_CSS_Compressor::process($css, $options);
|
74 |
+
} else {
|
75 |
+
$css = Minify_CommentPreserver::process(
|
76 |
+
$css
|
77 |
+
,array('Minify_CSS_Compressor', 'process')
|
78 |
+
,array($options)
|
79 |
+
);
|
80 |
+
}
|
81 |
+
}
|
82 |
+
if (! $options['currentDir'] && ! $options['prependRelativePath']) {
|
83 |
+
return $css;
|
84 |
+
}
|
85 |
+
if ($options['currentDir']) {
|
86 |
+
return Minify_CSS_UriRewriter::rewrite(
|
87 |
+
$css
|
88 |
+
,$options['currentDir']
|
89 |
+
,$options['docRoot']
|
90 |
+
,$options['symlinks']
|
91 |
+
);
|
92 |
+
} else {
|
93 |
+
return Minify_CSS_UriRewriter::prepend(
|
94 |
+
$css
|
95 |
+
,$options['prependRelativePath']
|
96 |
+
);
|
97 |
+
}
|
98 |
+
}
|
99 |
+
}
|
includes/min/lib/Minify/CSS/Compressor.php
ADDED
@@ -0,0 +1,249 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_CSS_Compressor
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Compress CSS
|
9 |
+
*
|
10 |
+
* This is a heavy regex-based removal of whitespace, unnecessary
|
11 |
+
* comments and tokens, and some CSS value minimization, where practical.
|
12 |
+
* Many steps have been taken to avoid breaking comment-based hacks,
|
13 |
+
* including the ie5/mac filter (and its inversion), but expect tricky
|
14 |
+
* hacks involving comment tokens in 'content' value strings to break
|
15 |
+
* minimization badly. A test suite is available.
|
16 |
+
*
|
17 |
+
* @package Minify
|
18 |
+
* @author Stephen Clay <steve@mrclay.org>
|
19 |
+
* @author http://code.google.com/u/1stvamp/ (Issue 64 patch)
|
20 |
+
*/
|
21 |
+
class Minify_CSS_Compressor {
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Minify a CSS string
|
25 |
+
*
|
26 |
+
* @param string $css
|
27 |
+
*
|
28 |
+
* @param array $options (currently ignored)
|
29 |
+
*
|
30 |
+
* @return string
|
31 |
+
*/
|
32 |
+
public static function process($css, $options = array())
|
33 |
+
{
|
34 |
+
$obj = new Minify_CSS_Compressor($options);
|
35 |
+
return $obj->_process($css);
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* @var array
|
40 |
+
*/
|
41 |
+
protected $_options = null;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Are we "in" a hack? I.e. are some browsers targetted until the next comment?
|
45 |
+
*
|
46 |
+
* @var bool
|
47 |
+
*/
|
48 |
+
protected $_inHack = false;
|
49 |
+
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Constructor
|
53 |
+
*
|
54 |
+
* @param array $options (currently ignored)
|
55 |
+
*/
|
56 |
+
private function __construct($options) {
|
57 |
+
$this->_options = $options;
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Minify a CSS string
|
62 |
+
*
|
63 |
+
* @param string $css
|
64 |
+
*
|
65 |
+
* @return string
|
66 |
+
*/
|
67 |
+
protected function _process($css)
|
68 |
+
{
|
69 |
+
$css = str_replace("\r\n", "\n", $css);
|
70 |
+
|
71 |
+
// preserve empty comment after '>'
|
72 |
+
// http://www.webdevout.net/css-hacks#in_css-selectors
|
73 |
+
$css = preg_replace('@>/\\*\\s*\\*/@', '>/*keep*/', $css);
|
74 |
+
|
75 |
+
// preserve empty comment between property and value
|
76 |
+
// http://css-discuss.incutio.com/?page=BoxModelHack
|
77 |
+
$css = preg_replace('@/\\*\\s*\\*/\\s*:@', '/*keep*/:', $css);
|
78 |
+
$css = preg_replace('@:\\s*/\\*\\s*\\*/@', ':/*keep*/', $css);
|
79 |
+
|
80 |
+
// apply callback to all valid comments (and strip out surrounding ws
|
81 |
+
$css = preg_replace_callback('@\\s*/\\*([\\s\\S]*?)\\*/\\s*@'
|
82 |
+
,array($this, '_commentCB'), $css);
|
83 |
+
|
84 |
+
// remove ws around { } and last semicolon in declaration block
|
85 |
+
$css = preg_replace('/\\s*{\\s*/', '{', $css);
|
86 |
+
$css = preg_replace('/;?\\s*}\\s*/', '}', $css);
|
87 |
+
|
88 |
+
// remove ws surrounding semicolons
|
89 |
+
$css = preg_replace('/\\s*;\\s*/', ';', $css);
|
90 |
+
|
91 |
+
// remove ws around urls
|
92 |
+
$css = preg_replace('/
|
93 |
+
url\\( # url(
|
94 |
+
\\s*
|
95 |
+
([^\\)]+?) # 1 = the URL (really just a bunch of non right parenthesis)
|
96 |
+
\\s*
|
97 |
+
\\) # )
|
98 |
+
/x', 'url($1)', $css);
|
99 |
+
|
100 |
+
// remove ws between rules and colons
|
101 |
+
$css = preg_replace('/
|
102 |
+
\\s*
|
103 |
+
([{;]) # 1 = beginning of block or rule separator
|
104 |
+
\\s*
|
105 |
+
([\\*_]?[\\w\\-]+) # 2 = property (and maybe IE filter)
|
106 |
+
\\s*
|
107 |
+
:
|
108 |
+
\\s*
|
109 |
+
(\\b|[#\'"-]) # 3 = first character of a value
|
110 |
+
/x', '$1$2:$3', $css);
|
111 |
+
|
112 |
+
// remove ws in selectors
|
113 |
+
$css = preg_replace_callback('/
|
114 |
+
(?: # non-capture
|
115 |
+
\\s*
|
116 |
+
[^~>+,\\s]+ # selector part
|
117 |
+
\\s*
|
118 |
+
[,>+~] # combinators
|
119 |
+
)+
|
120 |
+
\\s*
|
121 |
+
[^~>+,\\s]+ # selector part
|
122 |
+
{ # open declaration block
|
123 |
+
/x'
|
124 |
+
,array($this, '_selectorsCB'), $css);
|
125 |
+
|
126 |
+
// minimize hex colors
|
127 |
+
$css = preg_replace('/([^=])#([a-f\\d])\\2([a-f\\d])\\3([a-f\\d])\\4([\\s;\\}])/i'
|
128 |
+
, '$1#$2$3$4$5', $css);
|
129 |
+
|
130 |
+
// remove spaces between font families
|
131 |
+
$css = preg_replace_callback('/font-family:([^;}]+)([;}])/'
|
132 |
+
,array($this, '_fontFamilyCB'), $css);
|
133 |
+
|
134 |
+
$css = preg_replace('/@import\\s+url/', '@import url', $css);
|
135 |
+
|
136 |
+
// replace any ws involving newlines with a single newline
|
137 |
+
$css = preg_replace('/[ \\t]*\\n+\\s*/', "\n", $css);
|
138 |
+
|
139 |
+
// separate common descendent selectors w/ newlines (to limit line lengths)
|
140 |
+
$css = preg_replace('/([\\w#\\.\\*]+)\\s+([\\w#\\.\\*]+){/', "$1\n$2{", $css);
|
141 |
+
|
142 |
+
// Use newline after 1st numeric value (to limit line lengths).
|
143 |
+
$css = preg_replace('/
|
144 |
+
((?:padding|margin|border|outline):\\d+(?:px|em)?) # 1 = prop : 1st numeric value
|
145 |
+
\\s+
|
146 |
+
/x'
|
147 |
+
,"$1\n", $css);
|
148 |
+
|
149 |
+
// prevent triggering IE6 bug: http://www.crankygeek.com/ie6pebug/
|
150 |
+
$css = preg_replace('/:first-l(etter|ine)\\{/', ':first-l$1 {', $css);
|
151 |
+
|
152 |
+
return trim($css);
|
153 |
+
}
|
154 |
+
|
155 |
+
/**
|
156 |
+
* Replace what looks like a set of selectors
|
157 |
+
*
|
158 |
+
* @param array $m regex matches
|
159 |
+
*
|
160 |
+
* @return string
|
161 |
+
*/
|
162 |
+
protected function _selectorsCB($m)
|
163 |
+
{
|
164 |
+
// remove ws around the combinators
|
165 |
+
return preg_replace('/\\s*([,>+~])\\s*/', '$1', $m[0]);
|
166 |
+
}
|
167 |
+
|
168 |
+
/**
|
169 |
+
* Process a comment and return a replacement
|
170 |
+
*
|
171 |
+
* @param array $m regex matches
|
172 |
+
*
|
173 |
+
* @return string
|
174 |
+
*/
|
175 |
+
protected function _commentCB($m)
|
176 |
+
{
|
177 |
+
$hasSurroundingWs = (trim($m[0]) !== $m[1]);
|
178 |
+
$m = $m[1];
|
179 |
+
// $m is the comment content w/o the surrounding tokens,
|
180 |
+
// but the return value will replace the entire comment.
|
181 |
+
if ($m === 'keep') {
|
182 |
+
return '/**/';
|
183 |
+
}
|
184 |
+
if ($m === '" "') {
|
185 |
+
// component of http://tantek.com/CSS/Examples/midpass.html
|
186 |
+
return '/*" "*/';
|
187 |
+
}
|
188 |
+
if (preg_match('@";\\}\\s*\\}/\\*\\s+@', $m)) {
|
189 |
+
// component of http://tantek.com/CSS/Examples/midpass.html
|
190 |
+
return '/*";}}/* */';
|
191 |
+
}
|
192 |
+
if ($this->_inHack) {
|
193 |
+
// inversion: feeding only to one browser
|
194 |
+
if (preg_match('@
|
195 |
+
^/ # comment started like /*/
|
196 |
+
\\s*
|
197 |
+
(\\S[\\s\\S]+?) # has at least some non-ws content
|
198 |
+
\\s*
|
199 |
+
/\\* # ends like /*/ or /**/
|
200 |
+
@x', $m, $n)) {
|
201 |
+
// end hack mode after this comment, but preserve the hack and comment content
|
202 |
+
$this->_inHack = false;
|
203 |
+
return "/*/{$n[1]}/**/";
|
204 |
+
}
|
205 |
+
}
|
206 |
+
if (substr($m, -1) === '\\') { // comment ends like \*/
|
207 |
+
// begin hack mode and preserve hack
|
208 |
+
$this->_inHack = true;
|
209 |
+
return '/*\\*/';
|
210 |
+
}
|
211 |
+
if ($m !== '' && $m[0] === '/') { // comment looks like /*/ foo */
|
212 |
+
// begin hack mode and preserve hack
|
213 |
+
$this->_inHack = true;
|
214 |
+
return '/*/*/';
|
215 |
+
}
|
216 |
+
if ($this->_inHack) {
|
217 |
+
// a regular comment ends hack mode but should be preserved
|
218 |
+
$this->_inHack = false;
|
219 |
+
return '/**/';
|
220 |
+
}
|
221 |
+
// Issue 107: if there's any surrounding whitespace, it may be important, so
|
222 |
+
// replace the comment with a single space
|
223 |
+
return $hasSurroundingWs // remove all other comments
|
224 |
+
? ' '
|
225 |
+
: '';
|
226 |
+
}
|
227 |
+
|
228 |
+
/**
|
229 |
+
* Process a font-family listing and return a replacement
|
230 |
+
*
|
231 |
+
* @param array $m regex matches
|
232 |
+
*
|
233 |
+
* @return string
|
234 |
+
*/
|
235 |
+
protected function _fontFamilyCB($m)
|
236 |
+
{
|
237 |
+
// Issue 210: must not eliminate WS between words in unquoted families
|
238 |
+
$pieces = preg_split('/(\'[^\']+\'|"[^"]+")/', $m[1], null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
239 |
+
$out = 'font-family:';
|
240 |
+
while (null !== ($piece = array_shift($pieces))) {
|
241 |
+
if ($piece[0] !== '"' && $piece[0] !== "'") {
|
242 |
+
$piece = preg_replace('/\\s+/', ' ', $piece);
|
243 |
+
$piece = preg_replace('/\\s?,\\s?/', ',', $piece);
|
244 |
+
}
|
245 |
+
$out .= $piece;
|
246 |
+
}
|
247 |
+
return $out . $m[2];
|
248 |
+
}
|
249 |
+
}
|
includes/min/lib/Minify/CSS/UriRewriter.php
ADDED
@@ -0,0 +1,310 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_CSS_UriRewriter
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Rewrite file-relative URIs as root-relative in CSS files
|
9 |
+
*
|
10 |
+
* @package Minify
|
11 |
+
* @author Stephen Clay <steve@mrclay.org>
|
12 |
+
*/
|
13 |
+
class Minify_CSS_UriRewriter {
|
14 |
+
|
15 |
+
/**
|
16 |
+
* rewrite() and rewriteRelative() append debugging information here
|
17 |
+
*
|
18 |
+
* @var string
|
19 |
+
*/
|
20 |
+
public static $debugText = '';
|
21 |
+
|
22 |
+
/**
|
23 |
+
* In CSS content, rewrite file relative URIs as root relative
|
24 |
+
*
|
25 |
+
* @param string $css
|
26 |
+
*
|
27 |
+
* @param string $currentDir The directory of the current CSS file.
|
28 |
+
*
|
29 |
+
* @param string $docRoot The document root of the web site in which
|
30 |
+
* the CSS file resides (default = $_SERVER['DOCUMENT_ROOT']).
|
31 |
+
*
|
32 |
+
* @param array $symlinks (default = array()) If the CSS file is stored in
|
33 |
+
* a symlink-ed directory, provide an array of link paths to
|
34 |
+
* target paths, where the link paths are within the document root. Because
|
35 |
+
* paths need to be normalized for this to work, use "//" to substitute
|
36 |
+
* the doc root in the link paths (the array keys). E.g.:
|
37 |
+
* <code>
|
38 |
+
* array('//symlink' => '/real/target/path') // unix
|
39 |
+
* array('//static' => 'D:\\staticStorage') // Windows
|
40 |
+
* </code>
|
41 |
+
*
|
42 |
+
* @return string
|
43 |
+
*/
|
44 |
+
public static function rewrite($css, $currentDir, $docRoot = null, $symlinks = array())
|
45 |
+
{
|
46 |
+
self::$_docRoot = self::_realpath(
|
47 |
+
$docRoot ? $docRoot : $_SERVER['DOCUMENT_ROOT']
|
48 |
+
);
|
49 |
+
self::$_currentDir = self::_realpath($currentDir);
|
50 |
+
self::$_symlinks = array();
|
51 |
+
|
52 |
+
// normalize symlinks
|
53 |
+
foreach ($symlinks as $link => $target) {
|
54 |
+
$link = ($link === '//')
|
55 |
+
? self::$_docRoot
|
56 |
+
: str_replace('//', self::$_docRoot . '/', $link);
|
57 |
+
$link = strtr($link, '/', DIRECTORY_SEPARATOR);
|
58 |
+
self::$_symlinks[$link] = self::_realpath($target);
|
59 |
+
}
|
60 |
+
|
61 |
+
self::$debugText .= "docRoot : " . self::$_docRoot . "\n"
|
62 |
+
. "currentDir : " . self::$_currentDir . "\n";
|
63 |
+
if (self::$_symlinks) {
|
64 |
+
self::$debugText .= "symlinks : " . var_export(self::$_symlinks, 1) . "\n";
|
65 |
+
}
|
66 |
+
self::$debugText .= "\n";
|
67 |
+
|
68 |
+
$css = self::_trimUrls($css);
|
69 |
+
|
70 |
+
// rewrite
|
71 |
+
$css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/'
|
72 |
+
,array(self::$className, '_processUriCB'), $css);
|
73 |
+
$css = preg_replace_callback('/url\\(\\s*([^\\)\\s]+)\\s*\\)/'
|
74 |
+
,array(self::$className, '_processUriCB'), $css);
|
75 |
+
|
76 |
+
return $css;
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* In CSS content, prepend a path to relative URIs
|
81 |
+
*
|
82 |
+
* @param string $css
|
83 |
+
*
|
84 |
+
* @param string $path The path to prepend.
|
85 |
+
*
|
86 |
+
* @return string
|
87 |
+
*/
|
88 |
+
public static function prepend($css, $path)
|
89 |
+
{
|
90 |
+
self::$_prependPath = $path;
|
91 |
+
|
92 |
+
$css = self::_trimUrls($css);
|
93 |
+
|
94 |
+
// append
|
95 |
+
$css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/'
|
96 |
+
,array(self::$className, '_processUriCB'), $css);
|
97 |
+
$css = preg_replace_callback('/url\\(\\s*([^\\)\\s]+)\\s*\\)/'
|
98 |
+
,array(self::$className, '_processUriCB'), $css);
|
99 |
+
|
100 |
+
self::$_prependPath = null;
|
101 |
+
return $css;
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Get a root relative URI from a file relative URI
|
106 |
+
*
|
107 |
+
* <code>
|
108 |
+
* Minify_CSS_UriRewriter::rewriteRelative(
|
109 |
+
* '../img/hello.gif'
|
110 |
+
* , '/home/user/www/css' // path of CSS file
|
111 |
+
* , '/home/user/www' // doc root
|
112 |
+
* );
|
113 |
+
* // returns '/img/hello.gif'
|
114 |
+
*
|
115 |
+
* // example where static files are stored in a symlinked directory
|
116 |
+
* Minify_CSS_UriRewriter::rewriteRelative(
|
117 |
+
* 'hello.gif'
|
118 |
+
* , '/var/staticFiles/theme'
|
119 |
+
* , '/home/user/www'
|
120 |
+
* , array('/home/user/www/static' => '/var/staticFiles')
|
121 |
+
* );
|
122 |
+
* // returns '/static/theme/hello.gif'
|
123 |
+
* </code>
|
124 |
+
*
|
125 |
+
* @param string $uri file relative URI
|
126 |
+
*
|
127 |
+
* @param string $realCurrentDir realpath of the current file's directory.
|
128 |
+
*
|
129 |
+
* @param string $realDocRoot realpath of the site document root.
|
130 |
+
*
|
131 |
+
* @param array $symlinks (default = array()) If the file is stored in
|
132 |
+
* a symlink-ed directory, provide an array of link paths to
|
133 |
+
* real target paths, where the link paths "appear" to be within the document
|
134 |
+
* root. E.g.:
|
135 |
+
* <code>
|
136 |
+
* array('/home/foo/www/not/real/path' => '/real/target/path') // unix
|
137 |
+
* array('C:\\htdocs\\not\\real' => 'D:\\real\\target\\path') // Windows
|
138 |
+
* </code>
|
139 |
+
*
|
140 |
+
* @return string
|
141 |
+
*/
|
142 |
+
public static function rewriteRelative($uri, $realCurrentDir, $realDocRoot, $symlinks = array())
|
143 |
+
{
|
144 |
+
// prepend path with current dir separator (OS-independent)
|
145 |
+
$path = strtr($realCurrentDir, '/', DIRECTORY_SEPARATOR)
|
146 |
+
. DIRECTORY_SEPARATOR . strtr($uri, '/', DIRECTORY_SEPARATOR);
|
147 |
+
|
148 |
+
self::$debugText .= "file-relative URI : {$uri}\n"
|
149 |
+
. "path prepended : {$path}\n";
|
150 |
+
|
151 |
+
// "unresolve" a symlink back to doc root
|
152 |
+
foreach ($symlinks as $link => $target) {
|
153 |
+
if (0 === strpos($path, $target)) {
|
154 |
+
// replace $target with $link
|
155 |
+
$path = $link . substr($path, strlen($target));
|
156 |
+
|
157 |
+
self::$debugText .= "symlink unresolved : {$path}\n";
|
158 |
+
|
159 |
+
break;
|
160 |
+
}
|
161 |
+
}
|
162 |
+
// strip doc root
|
163 |
+
$path = substr($path, strlen($realDocRoot));
|
164 |
+
|
165 |
+
self::$debugText .= "docroot stripped : {$path}\n";
|
166 |
+
|
167 |
+
// fix to root-relative URI
|
168 |
+
$uri = strtr($path, '/\\', '//');
|
169 |
+
$uri = self::removeDots($uri);
|
170 |
+
|
171 |
+
self::$debugText .= "traversals removed : {$uri}\n\n";
|
172 |
+
|
173 |
+
return $uri;
|
174 |
+
}
|
175 |
+
|
176 |
+
/**
|
177 |
+
* Remove instances of "./" and "../" where possible from a root-relative URI
|
178 |
+
*
|
179 |
+
* @param string $uri
|
180 |
+
*
|
181 |
+
* @return string
|
182 |
+
*/
|
183 |
+
public static function removeDots($uri)
|
184 |
+
{
|
185 |
+
$uri = str_replace('/./', '/', $uri);
|
186 |
+
// inspired by patch from Oleg Cherniy
|
187 |
+
do {
|
188 |
+
$uri = preg_replace('@/[^/]+/\\.\\./@', '/', $uri, 1, $changed);
|
189 |
+
} while ($changed);
|
190 |
+
return $uri;
|
191 |
+
}
|
192 |
+
|
193 |
+
/**
|
194 |
+
* Defines which class to call as part of callbacks, change this
|
195 |
+
* if you extend Minify_CSS_UriRewriter
|
196 |
+
*
|
197 |
+
* @var string
|
198 |
+
*/
|
199 |
+
protected static $className = 'Minify_CSS_UriRewriter';
|
200 |
+
|
201 |
+
/**
|
202 |
+
* Get realpath with any trailing slash removed. If realpath() fails,
|
203 |
+
* just remove the trailing slash.
|
204 |
+
*
|
205 |
+
* @param string $path
|
206 |
+
*
|
207 |
+
* @return mixed path with no trailing slash
|
208 |
+
*/
|
209 |
+
protected static function _realpath($path)
|
210 |
+
{
|
211 |
+
$realPath = realpath($path);
|
212 |
+
if ($realPath !== false) {
|
213 |
+
$path = $realPath;
|
214 |
+
}
|
215 |
+
return rtrim($path, '/\\');
|
216 |
+
}
|
217 |
+
|
218 |
+
/**
|
219 |
+
* Directory of this stylesheet
|
220 |
+
*
|
221 |
+
* @var string
|
222 |
+
*/
|
223 |
+
private static $_currentDir = '';
|
224 |
+
|
225 |
+
/**
|
226 |
+
* DOC_ROOT
|
227 |
+
*
|
228 |
+
* @var string
|
229 |
+
*/
|
230 |
+
private static $_docRoot = '';
|
231 |
+
|
232 |
+
/**
|
233 |
+
* directory replacements to map symlink targets back to their
|
234 |
+
* source (within the document root) E.g. '/var/www/symlink' => '/var/realpath'
|
235 |
+
*
|
236 |
+
* @var array
|
237 |
+
*/
|
238 |
+
private static $_symlinks = array();
|
239 |
+
|
240 |
+
/**
|
241 |
+
* Path to prepend
|
242 |
+
*
|
243 |
+
* @var string
|
244 |
+
*/
|
245 |
+
private static $_prependPath = null;
|
246 |
+
|
247 |
+
/**
|
248 |
+
* @param string $css
|
249 |
+
*
|
250 |
+
* @return string
|
251 |
+
*/
|
252 |
+
private static function _trimUrls($css)
|
253 |
+
{
|
254 |
+
return preg_replace('/
|
255 |
+
url\\( # url(
|
256 |
+
\\s*
|
257 |
+
([^\\)]+?) # 1 = URI (assuming does not contain ")")
|
258 |
+
\\s*
|
259 |
+
\\) # )
|
260 |
+
/x', 'url($1)', $css);
|
261 |
+
}
|
262 |
+
|
263 |
+
/**
|
264 |
+
* @param array $m
|
265 |
+
*
|
266 |
+
* @return string
|
267 |
+
*/
|
268 |
+
private static function _processUriCB($m)
|
269 |
+
{
|
270 |
+
// $m matched either '/@import\\s+([\'"])(.*?)[\'"]/' or '/url\\(\\s*([^\\)\\s]+)\\s*\\)/'
|
271 |
+
$isImport = ($m[0][0] === '@');
|
272 |
+
// determine URI and the quote character (if any)
|
273 |
+
if ($isImport) {
|
274 |
+
$quoteChar = $m[1];
|
275 |
+
$uri = $m[2];
|
276 |
+
} else {
|
277 |
+
// $m[1] is either quoted or not
|
278 |
+
$quoteChar = ($m[1][0] === "'" || $m[1][0] === '"')
|
279 |
+
? $m[1][0]
|
280 |
+
: '';
|
281 |
+
$uri = ($quoteChar === '')
|
282 |
+
? $m[1]
|
283 |
+
: substr($m[1], 1, strlen($m[1]) - 2);
|
284 |
+
}
|
285 |
+
// analyze URI
|
286 |
+
if ('/' !== $uri[0] // root-relative
|
287 |
+
&& false === strpos($uri, '//') // protocol (non-data)
|
288 |
+
&& 0 !== strpos($uri, 'data:') // data protocol
|
289 |
+
) {
|
290 |
+
// URI is file-relative: rewrite depending on options
|
291 |
+
if (self::$_prependPath === null) {
|
292 |
+
$uri = self::rewriteRelative($uri, self::$_currentDir, self::$_docRoot, self::$_symlinks);
|
293 |
+
} else {
|
294 |
+
$uri = self::$_prependPath . $uri;
|
295 |
+
if ($uri[0] === '/') {
|
296 |
+
$root = '';
|
297 |
+
$rootRelative = $uri;
|
298 |
+
$uri = $root . self::removeDots($rootRelative);
|
299 |
+
} elseif (preg_match('@^((https?\:)?//([^/]+))/@', $uri, $m) && (false !== strpos($m[3], '.'))) {
|
300 |
+
$root = $m[1];
|
301 |
+
$rootRelative = substr($uri, strlen($root));
|
302 |
+
$uri = $root . self::removeDots($rootRelative);
|
303 |
+
}
|
304 |
+
}
|
305 |
+
}
|
306 |
+
return $isImport
|
307 |
+
? "@import {$quoteChar}{$uri}{$quoteChar}"
|
308 |
+
: "url({$quoteChar}{$uri}{$quoteChar})";
|
309 |
+
}
|
310 |
+
}
|
includes/min/lib/Minify/Cache/APC.php
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_Cache_APC
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* APC-based cache class for Minify
|
9 |
+
*
|
10 |
+
* <code>
|
11 |
+
* Minify::setCache(new Minify_Cache_APC());
|
12 |
+
* </code>
|
13 |
+
*
|
14 |
+
* @package Minify
|
15 |
+
* @author Chris Edwards
|
16 |
+
**/
|
17 |
+
class Minify_Cache_APC {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Create a Minify_Cache_APC object, to be passed to
|
21 |
+
* Minify::setCache().
|
22 |
+
*
|
23 |
+
*
|
24 |
+
* @param int $expire seconds until expiration (default = 0
|
25 |
+
* meaning the item will not get an expiration date)
|
26 |
+
*
|
27 |
+
* @return null
|
28 |
+
*/
|
29 |
+
public function __construct($expire = 0)
|
30 |
+
{
|
31 |
+
$this->_exp = $expire;
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Write data to cache.
|
36 |
+
*
|
37 |
+
* @param string $id cache id
|
38 |
+
*
|
39 |
+
* @param string $data
|
40 |
+
*
|
41 |
+
* @return bool success
|
42 |
+
*/
|
43 |
+
public function store($id, $data)
|
44 |
+
{
|
45 |
+
return apc_store($id, "{$_SERVER['REQUEST_TIME']}|{$data}", $this->_exp);
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Get the size of a cache entry
|
50 |
+
*
|
51 |
+
* @param string $id cache id
|
52 |
+
*
|
53 |
+
* @return int size in bytes
|
54 |
+
*/
|
55 |
+
public function getSize($id)
|
56 |
+
{
|
57 |
+
if (! $this->_fetch($id)) {
|
58 |
+
return false;
|
59 |
+
}
|
60 |
+
return (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
|
61 |
+
? mb_strlen($this->_data, '8bit')
|
62 |
+
: strlen($this->_data);
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Does a valid cache entry exist?
|
67 |
+
*
|
68 |
+
* @param string $id cache id
|
69 |
+
*
|
70 |
+
* @param int $srcMtime mtime of the original source file(s)
|
71 |
+
*
|
72 |
+
* @return bool exists
|
73 |
+
*/
|
74 |
+
public function isValid($id, $srcMtime)
|
75 |
+
{
|
76 |
+
return ($this->_fetch($id) && ($this->_lm >= $srcMtime));
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Send the cached content to output
|
81 |
+
*
|
82 |
+
* @param string $id cache id
|
83 |
+
*/
|
84 |
+
public function display($id)
|
85 |
+
{
|
86 |
+
echo $this->_fetch($id)
|
87 |
+
? $this->_data
|
88 |
+
: '';
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Fetch the cached content
|
93 |
+
*
|
94 |
+
* @param string $id cache id
|
95 |
+
*
|
96 |
+
* @return string
|
97 |
+
*/
|
98 |
+
public function fetch($id)
|
99 |
+
{
|
100 |
+
return $this->_fetch($id)
|
101 |
+
? $this->_data
|
102 |
+
: '';
|
103 |
+
}
|
104 |
+
|
105 |
+
private $_exp = null;
|
106 |
+
|
107 |
+
// cache of most recently fetched id
|
108 |
+
private $_lm = null;
|
109 |
+
private $_data = null;
|
110 |
+
private $_id = null;
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Fetch data and timestamp from apc, store in instance
|
114 |
+
*
|
115 |
+
* @param string $id
|
116 |
+
*
|
117 |
+
* @return bool success
|
118 |
+
*/
|
119 |
+
private function _fetch($id)
|
120 |
+
{
|
121 |
+
if ($this->_id === $id) {
|
122 |
+
return true;
|
123 |
+
}
|
124 |
+
$ret = apc_fetch($id);
|
125 |
+
if (false === $ret) {
|
126 |
+
$this->_id = null;
|
127 |
+
return false;
|
128 |
+
}
|
129 |
+
list($this->_lm, $this->_data) = explode('|', $ret, 2);
|
130 |
+
$this->_id = $id;
|
131 |
+
return true;
|
132 |
+
}
|
133 |
+
}
|
includes/min/lib/Minify/Cache/File.php
ADDED
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_Cache_File
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
class Minify_Cache_File {
|
8 |
+
|
9 |
+
public function __construct($path = '', $fileLocking = false)
|
10 |
+
{
|
11 |
+
if (! $path) {
|
12 |
+
$path = self::tmp();
|
13 |
+
}
|
14 |
+
$this->_locking = $fileLocking;
|
15 |
+
$this->_path = $path;
|
16 |
+
}
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Write data to cache.
|
20 |
+
*
|
21 |
+
* @param string $id cache id (e.g. a filename)
|
22 |
+
*
|
23 |
+
* @param string $data
|
24 |
+
*
|
25 |
+
* @return bool success
|
26 |
+
*/
|
27 |
+
public function store($id, $data)
|
28 |
+
{
|
29 |
+
$flag = $this->_locking
|
30 |
+
? LOCK_EX
|
31 |
+
: null;
|
32 |
+
$file = $this->_path . '/' . $id;
|
33 |
+
if (! @file_put_contents($file, $data, $flag)) {
|
34 |
+
$this->_log("Minify_Cache_File: Write failed to '$file'");
|
35 |
+
}
|
36 |
+
// write control
|
37 |
+
if ($data !== $this->fetch($id)) {
|
38 |
+
@unlink($file);
|
39 |
+
$this->_log("Minify_Cache_File: Post-write read failed for '$file'");
|
40 |
+
return false;
|
41 |
+
}
|
42 |
+
return true;
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Get the size of a cache entry
|
47 |
+
*
|
48 |
+
* @param string $id cache id (e.g. a filename)
|
49 |
+
*
|
50 |
+
* @return int size in bytes
|
51 |
+
*/
|
52 |
+
public function getSize($id)
|
53 |
+
{
|
54 |
+
return filesize($this->_path . '/' . $id);
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Does a valid cache entry exist?
|
59 |
+
*
|
60 |
+
* @param string $id cache id (e.g. a filename)
|
61 |
+
*
|
62 |
+
* @param int $srcMtime mtime of the original source file(s)
|
63 |
+
*
|
64 |
+
* @return bool exists
|
65 |
+
*/
|
66 |
+
public function isValid($id, $srcMtime)
|
67 |
+
{
|
68 |
+
$file = $this->_path . '/' . $id;
|
69 |
+
return (is_file($file) && (filemtime($file) >= $srcMtime));
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Send the cached content to output
|
74 |
+
*
|
75 |
+
* @param string $id cache id (e.g. a filename)
|
76 |
+
*/
|
77 |
+
public function display($id)
|
78 |
+
{
|
79 |
+
if ($this->_locking) {
|
80 |
+
$fp = fopen($this->_path . '/' . $id, 'rb');
|
81 |
+
flock($fp, LOCK_SH);
|
82 |
+
fpassthru($fp);
|
83 |
+
flock($fp, LOCK_UN);
|
84 |
+
fclose($fp);
|
85 |
+
} else {
|
86 |
+
readfile($this->_path . '/' . $id);
|
87 |
+
}
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Fetch the cached content
|
92 |
+
*
|
93 |
+
* @param string $id cache id (e.g. a filename)
|
94 |
+
*
|
95 |
+
* @return string
|
96 |
+
*/
|
97 |
+
public function fetch($id)
|
98 |
+
{
|
99 |
+
if ($this->_locking) {
|
100 |
+
$fp = fopen($this->_path . '/' . $id, 'rb');
|
101 |
+
flock($fp, LOCK_SH);
|
102 |
+
$ret = stream_get_contents($fp);
|
103 |
+
flock($fp, LOCK_UN);
|
104 |
+
fclose($fp);
|
105 |
+
return $ret;
|
106 |
+
} else {
|
107 |
+
return file_get_contents($this->_path . '/' . $id);
|
108 |
+
}
|
109 |
+
}
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Fetch the cache path used
|
113 |
+
*
|
114 |
+
* @return string
|
115 |
+
*/
|
116 |
+
public function getPath()
|
117 |
+
{
|
118 |
+
return $this->_path;
|
119 |
+
}
|
120 |
+
|
121 |
+
/**
|
122 |
+
* Get a usable temp directory
|
123 |
+
*
|
124 |
+
* Adapted from Solar/Dir.php
|
125 |
+
* @author Paul M. Jones <pmjones@solarphp.com>
|
126 |
+
* @license http://opensource.org/licenses/bsd-license.php BSD
|
127 |
+
* @link http://solarphp.com/trac/core/browser/trunk/Solar/Dir.php
|
128 |
+
*
|
129 |
+
* @return string
|
130 |
+
*/
|
131 |
+
public static function tmp()
|
132 |
+
{
|
133 |
+
static $tmp = null;
|
134 |
+
if (! $tmp) {
|
135 |
+
$tmp = function_exists('sys_get_temp_dir')
|
136 |
+
? sys_get_temp_dir()
|
137 |
+
: self::_tmp();
|
138 |
+
$tmp = rtrim($tmp, DIRECTORY_SEPARATOR);
|
139 |
+
}
|
140 |
+
return $tmp;
|
141 |
+
}
|
142 |
+
|
143 |
+
/**
|
144 |
+
* Returns the OS-specific directory for temporary files
|
145 |
+
*
|
146 |
+
* @author Paul M. Jones <pmjones@solarphp.com>
|
147 |
+
* @license http://opensource.org/licenses/bsd-license.php BSD
|
148 |
+
* @link http://solarphp.com/trac/core/browser/trunk/Solar/Dir.php
|
149 |
+
*
|
150 |
+
* @return string
|
151 |
+
*/
|
152 |
+
protected static function _tmp()
|
153 |
+
{
|
154 |
+
// non-Windows system?
|
155 |
+
if (strtolower(substr(PHP_OS, 0, 3)) != 'win') {
|
156 |
+
$tmp = empty($_ENV['TMPDIR']) ? getenv('TMPDIR') : $_ENV['TMPDIR'];
|
157 |
+
if ($tmp) {
|
158 |
+
return $tmp;
|
159 |
+
} else {
|
160 |
+
return '/tmp';
|
161 |
+
}
|
162 |
+
}
|
163 |
+
// Windows 'TEMP'
|
164 |
+
$tmp = empty($_ENV['TEMP']) ? getenv('TEMP') : $_ENV['TEMP'];
|
165 |
+
if ($tmp) {
|
166 |
+
return $tmp;
|
167 |
+
}
|
168 |
+
// Windows 'TMP'
|
169 |
+
$tmp = empty($_ENV['TMP']) ? getenv('TMP') : $_ENV['TMP'];
|
170 |
+
if ($tmp) {
|
171 |
+
return $tmp;
|
172 |
+
}
|
173 |
+
// Windows 'windir'
|
174 |
+
$tmp = empty($_ENV['windir']) ? getenv('windir') : $_ENV['windir'];
|
175 |
+
if ($tmp) {
|
176 |
+
return $tmp;
|
177 |
+
}
|
178 |
+
// final fallback for Windows
|
179 |
+
return getenv('SystemRoot') . '\\temp';
|
180 |
+
}
|
181 |
+
|
182 |
+
/**
|
183 |
+
* Send message to the Minify logger
|
184 |
+
* @param string $msg
|
185 |
+
* @return null
|
186 |
+
*/
|
187 |
+
protected function _log($msg)
|
188 |
+
{
|
189 |
+
Minify_Logger::log($msg);
|
190 |
+
}
|
191 |
+
|
192 |
+
private $_path = null;
|
193 |
+
private $_locking = null;
|
194 |
+
}
|
includes/min/lib/Minify/Cache/Memcache.php
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_Cache_Memcache
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Memcache-based cache class for Minify
|
9 |
+
*
|
10 |
+
* <code>
|
11 |
+
* // fall back to disk caching if memcache can't connect
|
12 |
+
* $memcache = new Memcache;
|
13 |
+
* if ($memcache->connect('localhost', 11211)) {
|
14 |
+
* Minify::setCache(new Minify_Cache_Memcache($memcache));
|
15 |
+
* } else {
|
16 |
+
* Minify::setCache();
|
17 |
+
* }
|
18 |
+
* </code>
|
19 |
+
**/
|
20 |
+
class Minify_Cache_Memcache {
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Create a Minify_Cache_Memcache object, to be passed to
|
24 |
+
* Minify::setCache().
|
25 |
+
*
|
26 |
+
* @param Memcache $memcache already-connected instance
|
27 |
+
*
|
28 |
+
* @param int $expire seconds until expiration (default = 0
|
29 |
+
* meaning the item will not get an expiration date)
|
30 |
+
*
|
31 |
+
* @return null
|
32 |
+
*/
|
33 |
+
public function __construct($memcache, $expire = 0)
|
34 |
+
{
|
35 |
+
$this->_mc = $memcache;
|
36 |
+
$this->_exp = $expire;
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Write data to cache.
|
41 |
+
*
|
42 |
+
* @param string $id cache id
|
43 |
+
*
|
44 |
+
* @param string $data
|
45 |
+
*
|
46 |
+
* @return bool success
|
47 |
+
*/
|
48 |
+
public function store($id, $data)
|
49 |
+
{
|
50 |
+
return $this->_mc->set($id, "{$_SERVER['REQUEST_TIME']}|{$data}", 0, $this->_exp);
|
51 |
+
}
|
52 |
+
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Get the size of a cache entry
|
56 |
+
*
|
57 |
+
* @param string $id cache id
|
58 |
+
*
|
59 |
+
* @return int size in bytes
|
60 |
+
*/
|
61 |
+
public function getSize($id)
|
62 |
+
{
|
63 |
+
if (! $this->_fetch($id)) {
|
64 |
+
return false;
|
65 |
+
}
|
66 |
+
return (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
|
67 |
+
? mb_strlen($this->_data, '8bit')
|
68 |
+
: strlen($this->_data);
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Does a valid cache entry exist?
|
73 |
+
*
|
74 |
+
* @param string $id cache id
|
75 |
+
*
|
76 |
+
* @param int $srcMtime mtime of the original source file(s)
|
77 |
+
*
|
78 |
+
* @return bool exists
|
79 |
+
*/
|
80 |
+
public function isValid($id, $srcMtime)
|
81 |
+
{
|
82 |
+
return ($this->_fetch($id) && ($this->_lm >= $srcMtime));
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Send the cached content to output
|
87 |
+
*
|
88 |
+
* @param string $id cache id
|
89 |
+
*/
|
90 |
+
public function display($id)
|
91 |
+
{
|
92 |
+
echo $this->_fetch($id)
|
93 |
+
? $this->_data
|
94 |
+
: '';
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Fetch the cached content
|
99 |
+
*
|
100 |
+
* @param string $id cache id
|
101 |
+
*
|
102 |
+
* @return string
|
103 |
+
*/
|
104 |
+
public function fetch($id)
|
105 |
+
{
|
106 |
+
return $this->_fetch($id)
|
107 |
+
? $this->_data
|
108 |
+
: '';
|
109 |
+
}
|
110 |
+
|
111 |
+
private $_mc = null;
|
112 |
+
private $_exp = null;
|
113 |
+
|
114 |
+
// cache of most recently fetched id
|
115 |
+
private $_lm = null;
|
116 |
+
private $_data = null;
|
117 |
+
private $_id = null;
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Fetch data and timestamp from memcache, store in instance
|
121 |
+
*
|
122 |
+
* @param string $id
|
123 |
+
*
|
124 |
+
* @return bool success
|
125 |
+
*/
|
126 |
+
private function _fetch($id)
|
127 |
+
{
|
128 |
+
if ($this->_id === $id) {
|
129 |
+
return true;
|
130 |
+
}
|
131 |
+
$ret = $this->_mc->get($id);
|
132 |
+
if (false === $ret) {
|
133 |
+
$this->_id = null;
|
134 |
+
return false;
|
135 |
+
}
|
136 |
+
list($this->_lm, $this->_data) = explode('|', $ret, 2);
|
137 |
+
$this->_id = $id;
|
138 |
+
return true;
|
139 |
+
}
|
140 |
+
}
|
includes/min/lib/Minify/Cache/XCache.php
ADDED
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_Cache_XCache
|
4 |
+
*
|
5 |
+
* @link http://xcache.lighttpd.net/
|
6 |
+
* @package Minify
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* XCache-based cache class for Minify
|
11 |
+
* {@see http://xcache.lighttpd.net/wiki/XcacheApi XCache API}
|
12 |
+
*
|
13 |
+
* <code>
|
14 |
+
* Minify::setCache(new Minify_Cache_XCache());
|
15 |
+
* </code>
|
16 |
+
*
|
17 |
+
* @package Minify
|
18 |
+
* @author Elan Ruusamäe <glen@delfi.ee>
|
19 |
+
**/
|
20 |
+
class Minify_Cache_XCache {
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Create a Minify_Cache_XCache object, to be passed to
|
24 |
+
* Minify::setCache().
|
25 |
+
*
|
26 |
+
* @param int $expire seconds until expiration (default = 0
|
27 |
+
* meaning the item will not get an expiration date)
|
28 |
+
*/
|
29 |
+
public function __construct($expire = 0)
|
30 |
+
{
|
31 |
+
$this->_exp = $expire;
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Write data to cache.
|
36 |
+
*
|
37 |
+
* @param string $id cache id
|
38 |
+
* @param string $data
|
39 |
+
* @return bool success
|
40 |
+
*/
|
41 |
+
public function store($id, $data)
|
42 |
+
{
|
43 |
+
return xcache_set($id, "{$_SERVER['REQUEST_TIME']}|{$data}", $this->_exp);
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Get the size of a cache entry
|
48 |
+
*
|
49 |
+
* @param string $id cache id
|
50 |
+
* @return int size in bytes
|
51 |
+
*/
|
52 |
+
public function getSize($id)
|
53 |
+
{
|
54 |
+
if (! $this->_fetch($id)) {
|
55 |
+
return false;
|
56 |
+
}
|
57 |
+
return (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
|
58 |
+
? mb_strlen($this->_data, '8bit')
|
59 |
+
: strlen($this->_data);
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Does a valid cache entry exist?
|
64 |
+
*
|
65 |
+
* @param string $id cache id
|
66 |
+
* @param int $srcMtime mtime of the original source file(s)
|
67 |
+
* @return bool exists
|
68 |
+
*/
|
69 |
+
public function isValid($id, $srcMtime)
|
70 |
+
{
|
71 |
+
return ($this->_fetch($id) && ($this->_lm >= $srcMtime));
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Send the cached content to output
|
76 |
+
*
|
77 |
+
* @param string $id cache id
|
78 |
+
*/
|
79 |
+
public function display($id)
|
80 |
+
{
|
81 |
+
echo $this->_fetch($id)
|
82 |
+
? $this->_data
|
83 |
+
: '';
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Fetch the cached content
|
88 |
+
*
|
89 |
+
* @param string $id cache id
|
90 |
+
* @return string
|
91 |
+
*/
|
92 |
+
public function fetch($id)
|
93 |
+
{
|
94 |
+
return $this->_fetch($id)
|
95 |
+
? $this->_data
|
96 |
+
: '';
|
97 |
+
}
|
98 |
+
|
99 |
+
private $_exp = null;
|
100 |
+
|
101 |
+
// cache of most recently fetched id
|
102 |
+
private $_lm = null;
|
103 |
+
private $_data = null;
|
104 |
+
private $_id = null;
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Fetch data and timestamp from xcache, store in instance
|
108 |
+
*
|
109 |
+
* @param string $id
|
110 |
+
* @return bool success
|
111 |
+
*/
|
112 |
+
private function _fetch($id)
|
113 |
+
{
|
114 |
+
if ($this->_id === $id) {
|
115 |
+
return true;
|
116 |
+
}
|
117 |
+
$ret = xcache_get($id);
|
118 |
+
if (false === $ret) {
|
119 |
+
$this->_id = null;
|
120 |
+
return false;
|
121 |
+
}
|
122 |
+
list($this->_lm, $this->_data) = explode('|', $ret, 2);
|
123 |
+
$this->_id = $id;
|
124 |
+
return true;
|
125 |
+
}
|
126 |
+
}
|
includes/min/lib/Minify/Cache/ZendPlatform.php
ADDED
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_Cache_ZendPlatform
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
|
8 |
+
/**
|
9 |
+
* ZendPlatform-based cache class for Minify
|
10 |
+
*
|
11 |
+
* Based on Minify_Cache_APC, uses output_cache_get/put (currently deprecated)
|
12 |
+
*
|
13 |
+
* <code>
|
14 |
+
* Minify::setCache(new Minify_Cache_ZendPlatform());
|
15 |
+
* </code>
|
16 |
+
*
|
17 |
+
* @package Minify
|
18 |
+
* @author Patrick van Dissel
|
19 |
+
*/
|
20 |
+
class Minify_Cache_ZendPlatform {
|
21 |
+
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Create a Minify_Cache_ZendPlatform object, to be passed to
|
25 |
+
* Minify::setCache().
|
26 |
+
*
|
27 |
+
* @param int $expire seconds until expiration (default = 0
|
28 |
+
* meaning the item will not get an expiration date)
|
29 |
+
*
|
30 |
+
* @return null
|
31 |
+
*/
|
32 |
+
public function __construct($expire = 0)
|
33 |
+
{
|
34 |
+
$this->_exp = $expire;
|
35 |
+
}
|
36 |
+
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Write data to cache.
|
40 |
+
*
|
41 |
+
* @param string $id cache id
|
42 |
+
*
|
43 |
+
* @param string $data
|
44 |
+
*
|
45 |
+
* @return bool success
|
46 |
+
*/
|
47 |
+
public function store($id, $data)
|
48 |
+
{
|
49 |
+
return output_cache_put($id, "{$_SERVER['REQUEST_TIME']}|{$data}");
|
50 |
+
}
|
51 |
+
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Get the size of a cache entry
|
55 |
+
*
|
56 |
+
* @param string $id cache id
|
57 |
+
*
|
58 |
+
* @return int size in bytes
|
59 |
+
*/
|
60 |
+
public function getSize($id)
|
61 |
+
{
|
62 |
+
return $this->_fetch($id)
|
63 |
+
? strlen($this->_data)
|
64 |
+
: false;
|
65 |
+
}
|
66 |
+
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Does a valid cache entry exist?
|
70 |
+
*
|
71 |
+
* @param string $id cache id
|
72 |
+
*
|
73 |
+
* @param int $srcMtime mtime of the original source file(s)
|
74 |
+
*
|
75 |
+
* @return bool exists
|
76 |
+
*/
|
77 |
+
public function isValid($id, $srcMtime)
|
78 |
+
{
|
79 |
+
$ret = ($this->_fetch($id) && ($this->_lm >= $srcMtime));
|
80 |
+
return $ret;
|
81 |
+
}
|
82 |
+
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Send the cached content to output
|
86 |
+
*
|
87 |
+
* @param string $id cache id
|
88 |
+
*/
|
89 |
+
public function display($id)
|
90 |
+
{
|
91 |
+
echo $this->_fetch($id)
|
92 |
+
? $this->_data
|
93 |
+
: '';
|
94 |
+
}
|
95 |
+
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Fetch the cached content
|
99 |
+
*
|
100 |
+
* @param string $id cache id
|
101 |
+
*
|
102 |
+
* @return string
|
103 |
+
*/
|
104 |
+
public function fetch($id)
|
105 |
+
{
|
106 |
+
return $this->_fetch($id)
|
107 |
+
? $this->_data
|
108 |
+
: '';
|
109 |
+
}
|
110 |
+
|
111 |
+
|
112 |
+
private $_exp = null;
|
113 |
+
|
114 |
+
|
115 |
+
// cache of most recently fetched id
|
116 |
+
private $_lm = null;
|
117 |
+
private $_data = null;
|
118 |
+
private $_id = null;
|
119 |
+
|
120 |
+
|
121 |
+
/**
|
122 |
+
* Fetch data and timestamp from ZendPlatform, store in instance
|
123 |
+
*
|
124 |
+
* @param string $id
|
125 |
+
*
|
126 |
+
* @return bool success
|
127 |
+
*/
|
128 |
+
private function _fetch($id)
|
129 |
+
{
|
130 |
+
if ($this->_id === $id) {
|
131 |
+
return true;
|
132 |
+
}
|
133 |
+
$ret = output_cache_get($id, $this->_exp);
|
134 |
+
if (false === $ret) {
|
135 |
+
$this->_id = null;
|
136 |
+
return false;
|
137 |
+
}
|
138 |
+
list($this->_lm, $this->_data) = explode('|', $ret, 2);
|
139 |
+
$this->_id = $id;
|
140 |
+
return true;
|
141 |
+
}
|
142 |
+
}
|
includes/min/lib/Minify/ClosureCompiler.php
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_ClosureCompiler
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Compress Javascript using the Closure Compiler
|
9 |
+
*
|
10 |
+
* You must set $jarFile and $tempDir before calling the minify functions.
|
11 |
+
* Also, depending on your shell's environment, you may need to specify
|
12 |
+
* the full path to java in $javaExecutable or use putenv() to setup the
|
13 |
+
* Java environment.
|
14 |
+
*
|
15 |
+
* <code>
|
16 |
+
* Minify_ClosureCompiler::$jarFile = '/path/to/closure-compiler-20120123.jar';
|
17 |
+
* Minify_ClosureCompiler::$tempDir = '/tmp';
|
18 |
+
* $code = Minify_ClosureCompiler::minify(
|
19 |
+
* $code,
|
20 |
+
* array('compilation_level' => 'SIMPLE_OPTIMIZATIONS')
|
21 |
+
* );
|
22 |
+
*
|
23 |
+
* --compilation_level WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS, ADVANCED_OPTIMIZATIONS
|
24 |
+
*
|
25 |
+
* </code>
|
26 |
+
*
|
27 |
+
* @todo unit tests, $options docs
|
28 |
+
* @todo more options support (or should just passthru them all?)
|
29 |
+
*
|
30 |
+
* @package Minify
|
31 |
+
* @author Stephen Clay <steve@mrclay.org>
|
32 |
+
* @author Elan Ruusamäe <glen@delfi.ee>
|
33 |
+
*/
|
34 |
+
class Minify_ClosureCompiler {
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Filepath of the Closure Compiler jar file. This must be set before
|
38 |
+
* calling minifyJs().
|
39 |
+
*
|
40 |
+
* @var string
|
41 |
+
*/
|
42 |
+
public static $jarFile = null;
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Writable temp directory. This must be set before calling minifyJs().
|
46 |
+
*
|
47 |
+
* @var string
|
48 |
+
*/
|
49 |
+
public static $tempDir = null;
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Filepath of "java" executable (may be needed if not in shell's PATH)
|
53 |
+
*
|
54 |
+
* @var string
|
55 |
+
*/
|
56 |
+
public static $javaExecutable = 'java';
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Minify a Javascript string
|
60 |
+
*
|
61 |
+
* @param string $js
|
62 |
+
*
|
63 |
+
* @param array $options (verbose is ignored)
|
64 |
+
*
|
65 |
+
* @see https://code.google.com/p/closure-compiler/source/browse/trunk/README
|
66 |
+
*
|
67 |
+
* @return string
|
68 |
+
*/
|
69 |
+
public static function minify($js, $options = array())
|
70 |
+
{
|
71 |
+
self::_prepare();
|
72 |
+
if (! ($tmpFile = tempnam(self::$tempDir, 'cc_'))) {
|
73 |
+
throw new Exception('Minify_ClosureCompiler : could not create temp file.');
|
74 |
+
}
|
75 |
+
file_put_contents($tmpFile, $js);
|
76 |
+
exec(self::_getCmd($options, $tmpFile), $output, $result_code);
|
77 |
+
unlink($tmpFile);
|
78 |
+
if ($result_code != 0) {
|
79 |
+
throw new Exception('Minify_ClosureCompiler : Closure Compiler execution failed.');
|
80 |
+
}
|
81 |
+
return implode("\n", $output);
|
82 |
+
}
|
83 |
+
|
84 |
+
private static function _getCmd($userOptions, $tmpFile)
|
85 |
+
{
|
86 |
+
$o = array_merge(
|
87 |
+
array(
|
88 |
+
'charset' => 'utf-8',
|
89 |
+
'compilation_level' => 'SIMPLE_OPTIMIZATIONS',
|
90 |
+
),
|
91 |
+
$userOptions
|
92 |
+
);
|
93 |
+
$cmd = self::$javaExecutable . ' -jar ' . escapeshellarg(self::$jarFile)
|
94 |
+
. (preg_match('/^[\\da-zA-Z0-9\\-]+$/', $o['charset'])
|
95 |
+
? " --charset {$o['charset']}"
|
96 |
+
: '');
|
97 |
+
|
98 |
+
foreach (array('compilation_level') as $opt) {
|
99 |
+
if ($o[$opt]) {
|
100 |
+
$cmd .= " --{$opt} ". escapeshellarg($o[$opt]);
|
101 |
+
}
|
102 |
+
}
|
103 |
+
return $cmd . ' ' . escapeshellarg($tmpFile);
|
104 |
+
}
|
105 |
+
|
106 |
+
private static function _prepare()
|
107 |
+
{
|
108 |
+
if (! is_file(self::$jarFile)) {
|
109 |
+
throw new Exception('Minify_ClosureCompiler : $jarFile('.self::$jarFile.') is not a valid file.');
|
110 |
+
}
|
111 |
+
if (! is_readable(self::$jarFile)) {
|
112 |
+
throw new Exception('Minify_ClosureCompiler : $jarFile('.self::$jarFile.') is not readable.');
|
113 |
+
}
|
114 |
+
if (! is_dir(self::$tempDir)) {
|
115 |
+
throw new Exception('Minify_ClosureCompiler : $tempDir('.self::$tempDir.') is not a valid direcotry.');
|
116 |
+
}
|
117 |
+
if (! is_writable(self::$tempDir)) {
|
118 |
+
throw new Exception('Minify_ClosureCompiler : $tempDir('.self::$tempDir.') is not writable.');
|
119 |
+
}
|
120 |
+
}
|
121 |
+
}
|
122 |
+
|
123 |
+
/* vim:ts=4:sw=4:et */
|
includes/min/lib/Minify/CommentPreserver.php
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_CommentPreserver
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Process a string in pieces preserving C-style comments that begin with "/*!"
|
9 |
+
*
|
10 |
+
* @package Minify
|
11 |
+
* @author Stephen Clay <steve@mrclay.org>
|
12 |
+
*/
|
13 |
+
class Minify_CommentPreserver {
|
14 |
+
|
15 |
+
/**
|
16 |
+
* String to be prepended to each preserved comment
|
17 |
+
*
|
18 |
+
* @var string
|
19 |
+
*/
|
20 |
+
public static $prepend = "\n";
|
21 |
+
|
22 |
+
/**
|
23 |
+
* String to be appended to each preserved comment
|
24 |
+
*
|
25 |
+
* @var string
|
26 |
+
*/
|
27 |
+
public static $append = "\n";
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Process a string outside of C-style comments that begin with "/*!"
|
31 |
+
*
|
32 |
+
* On each non-empty string outside these comments, the given processor
|
33 |
+
* function will be called. The comments will be surrounded by
|
34 |
+
* Minify_CommentPreserver::$preprend and Minify_CommentPreserver::$append.
|
35 |
+
*
|
36 |
+
* @param string $content
|
37 |
+
* @param callback $processor function
|
38 |
+
* @param array $args array of extra arguments to pass to the processor
|
39 |
+
* function (default = array())
|
40 |
+
* @return string
|
41 |
+
*/
|
42 |
+
public static function process($content, $processor, $args = array())
|
43 |
+
{
|
44 |
+
$ret = '';
|
45 |
+
while (true) {
|
46 |
+
list($beforeComment, $comment, $afterComment) = self::_nextComment($content);
|
47 |
+
if ('' !== $beforeComment) {
|
48 |
+
$callArgs = $args;
|
49 |
+
array_unshift($callArgs, $beforeComment);
|
50 |
+
$ret .= call_user_func_array($processor, $callArgs);
|
51 |
+
}
|
52 |
+
if (false === $comment) {
|
53 |
+
break;
|
54 |
+
}
|
55 |
+
$ret .= $comment;
|
56 |
+
$content = $afterComment;
|
57 |
+
}
|
58 |
+
return $ret;
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Extract comments that YUI Compressor preserves.
|
63 |
+
*
|
64 |
+
* @param string $in input
|
65 |
+
*
|
66 |
+
* @return array 3 elements are returned. If a YUI comment is found, the
|
67 |
+
* 2nd element is the comment and the 1st and 3rd are the surrounding
|
68 |
+
* strings. If no comment is found, the entire string is returned as the
|
69 |
+
* 1st element and the other two are false.
|
70 |
+
*/
|
71 |
+
private static function _nextComment($in)
|
72 |
+
{
|
73 |
+
if (
|
74 |
+
false === ($start = strpos($in, '/*!'))
|
75 |
+
|| false === ($end = strpos($in, '*/', $start + 3))
|
76 |
+
) {
|
77 |
+
return array($in, false, false);
|
78 |
+
}
|
79 |
+
$ret = array(
|
80 |
+
substr($in, 0, $start)
|
81 |
+
,self::$prepend . '/*!' . substr($in, $start + 3, $end - $start - 1) . self::$append
|
82 |
+
);
|
83 |
+
$endChars = (strlen($in) - $end - 2);
|
84 |
+
$ret[] = (0 === $endChars)
|
85 |
+
? ''
|
86 |
+
: substr($in, -$endChars);
|
87 |
+
return $ret;
|
88 |
+
}
|
89 |
+
}
|
includes/min/lib/Minify/Controller/Base.php
ADDED
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_Controller_Base
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Base class for Minify controller
|
9 |
+
*
|
10 |
+
* The controller class validates a request and uses it to create sources
|
11 |
+
* for minification and set options like contentType. It's also responsible
|
12 |
+
* for loading minifier code upon request.
|
13 |
+
*
|
14 |
+
* @package Minify
|
15 |
+
* @author Stephen Clay <steve@mrclay.org>
|
16 |
+
*/
|
17 |
+
abstract class Minify_Controller_Base {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Setup controller sources and set an needed options for Minify::source
|
21 |
+
*
|
22 |
+
* You must override this method in your subclass controller to set
|
23 |
+
* $this->sources. If the request is NOT valid, make sure $this->sources
|
24 |
+
* is left an empty array. Then strip any controller-specific options from
|
25 |
+
* $options and return it. To serve files, $this->sources must be an array of
|
26 |
+
* Minify_Source objects.
|
27 |
+
*
|
28 |
+
* @param array $options controller and Minify options
|
29 |
+
*
|
30 |
+
* @return array $options Minify::serve options
|
31 |
+
*/
|
32 |
+
abstract public function setupSources($options);
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Get default Minify options for this controller.
|
36 |
+
*
|
37 |
+
* Override in subclass to change defaults
|
38 |
+
*
|
39 |
+
* @return array options for Minify
|
40 |
+
*/
|
41 |
+
public function getDefaultMinifyOptions() {
|
42 |
+
return array(
|
43 |
+
'isPublic' => true
|
44 |
+
,'encodeOutput' => function_exists('gzdeflate')
|
45 |
+
,'encodeMethod' => null // determine later
|
46 |
+
,'encodeLevel' => 9
|
47 |
+
,'minifierOptions' => array() // no minifier options
|
48 |
+
,'contentTypeCharset' => 'utf-8'
|
49 |
+
,'maxAge' => 1800 // 30 minutes
|
50 |
+
,'rewriteCssUris' => true
|
51 |
+
,'bubbleCssImports' => false
|
52 |
+
,'quiet' => false // serve() will send headers and output
|
53 |
+
,'debug' => false
|
54 |
+
|
55 |
+
// if you override these, the response codes MUST be directly after
|
56 |
+
// the first space.
|
57 |
+
,'badRequestHeader' => 'HTTP/1.0 400 Bad Request'
|
58 |
+
,'errorHeader' => 'HTTP/1.0 500 Internal Server Error'
|
59 |
+
|
60 |
+
// callback function to see/modify content of all sources
|
61 |
+
,'postprocessor' => null
|
62 |
+
// file to require to load preprocessor
|
63 |
+
,'postprocessorRequire' => null
|
64 |
+
);
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Get default minifiers for this controller.
|
69 |
+
*
|
70 |
+
* Override in subclass to change defaults
|
71 |
+
*
|
72 |
+
* @return array minifier callbacks for common types
|
73 |
+
*/
|
74 |
+
public function getDefaultMinifers() {
|
75 |
+
$ret[Minify::TYPE_JS] = array('JSMin', 'minify');
|
76 |
+
$ret[Minify::TYPE_CSS] = array('Minify_CSS', 'minify');
|
77 |
+
$ret[Minify::TYPE_HTML] = array('Minify_HTML', 'minify');
|
78 |
+
return $ret;
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Is a user-given file within an allowable directory, existing,
|
83 |
+
* and having an extension js/css/html/txt ?
|
84 |
+
*
|
85 |
+
* This is a convenience function for controllers that have to accept
|
86 |
+
* user-given paths
|
87 |
+
*
|
88 |
+
* @param string $file full file path (already processed by realpath())
|
89 |
+
*
|
90 |
+
* @param array $safeDirs directories where files are safe to serve. Files can also
|
91 |
+
* be in subdirectories of these directories.
|
92 |
+
*
|
93 |
+
* @return bool file is safe
|
94 |
+
*
|
95 |
+
* @deprecated use checkAllowDirs, checkNotHidden instead
|
96 |
+
*/
|
97 |
+
public static function _fileIsSafe($file, $safeDirs)
|
98 |
+
{
|
99 |
+
$pathOk = false;
|
100 |
+
foreach ((array)$safeDirs as $safeDir) {
|
101 |
+
if (strpos($file, $safeDir) === 0) {
|
102 |
+
$pathOk = true;
|
103 |
+
break;
|
104 |
+
}
|
105 |
+
}
|
106 |
+
$base = basename($file);
|
107 |
+
if (! $pathOk || ! is_file($file) || $base[0] === '.') {
|
108 |
+
return false;
|
109 |
+
}
|
110 |
+
list($revExt) = explode('.', strrev($base));
|
111 |
+
return in_array(strrev($revExt), array('js', 'css', 'html', 'txt'));
|
112 |
+
}
|
113 |
+
|
114 |
+
/**
|
115 |
+
* @param string $file
|
116 |
+
* @param array $allowDirs
|
117 |
+
* @param string $uri
|
118 |
+
* @return bool
|
119 |
+
* @throws Exception
|
120 |
+
*/
|
121 |
+
public static function checkAllowDirs($file, $allowDirs, $uri)
|
122 |
+
{
|
123 |
+
foreach ((array)$allowDirs as $allowDir) {
|
124 |
+
if (strpos($file, $allowDir) === 0) {
|
125 |
+
return true;
|
126 |
+
}
|
127 |
+
}
|
128 |
+
throw new Exception("File '$file' is outside \$allowDirs. If the path is"
|
129 |
+
. " resolved via an alias/symlink, look into the \$min_symlinks option."
|
130 |
+
. " E.g. \$min_symlinks['/" . dirname($uri) . "'] = '" . dirname($file) . "';");
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* @param string $file
|
135 |
+
* @throws Exception
|
136 |
+
*/
|
137 |
+
public static function checkNotHidden($file)
|
138 |
+
{
|
139 |
+
$b = basename($file);
|
140 |
+
if (0 === strpos($b, '.')) {
|
141 |
+
throw new Exception("Filename '$b' starts with period (may be hidden)");
|
142 |
+
}
|
143 |
+
}
|
144 |
+
|
145 |
+
/**
|
146 |
+
* instances of Minify_Source, which provide content and any individual minification needs.
|
147 |
+
*
|
148 |
+
* @var array
|
149 |
+
*
|
150 |
+
* @see Minify_Source
|
151 |
+
*/
|
152 |
+
public $sources = array();
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Short name to place inside cache id
|
156 |
+
*
|
157 |
+
* The setupSources() method may choose to set this, making it easier to
|
158 |
+
* recognize a particular set of sources/settings in the cache folder. It
|
159 |
+
* will be filtered and truncated to make the final cache id <= 250 bytes.
|
160 |
+
*
|
161 |
+
* @var string
|
162 |
+
*/
|
163 |
+
public $selectionId = '';
|
164 |
+
|
165 |
+
/**
|
166 |
+
* Mix in default controller options with user-given options
|
167 |
+
*
|
168 |
+
* @param array $options user options
|
169 |
+
*
|
170 |
+
* @return array mixed options
|
171 |
+
*/
|
172 |
+
public final function mixInDefaultOptions($options)
|
173 |
+
{
|
174 |
+
$ret = array_merge(
|
175 |
+
$this->getDefaultMinifyOptions(), $options
|
176 |
+
);
|
177 |
+
if (! isset($options['minifiers'])) {
|
178 |
+
$options['minifiers'] = array();
|
179 |
+
}
|
180 |
+
$ret['minifiers'] = array_merge(
|
181 |
+
$this->getDefaultMinifers(), $options['minifiers']
|
182 |
+
);
|
183 |
+
return $ret;
|
184 |
+
}
|
185 |
+
|
186 |
+
/**
|
187 |
+
* Analyze sources (if there are any) and set $options 'contentType'
|
188 |
+
* and 'lastModifiedTime' if they already aren't.
|
189 |
+
*
|
190 |
+
* @param array $options options for Minify
|
191 |
+
*
|
192 |
+
* @return array options for Minify
|
193 |
+
*/
|
194 |
+
public final function analyzeSources($options = array())
|
195 |
+
{
|
196 |
+
if ($this->sources) {
|
197 |
+
if (! isset($options['contentType'])) {
|
198 |
+
$options['contentType'] = Minify_Source::getContentType($this->sources);
|
199 |
+
}
|
200 |
+
// last modified is needed for caching, even if setExpires is set
|
201 |
+
if (! isset($options['lastModifiedTime'])) {
|
202 |
+
$max = 0;
|
203 |
+
foreach ($this->sources as $source) {
|
204 |
+
$max = max($source->lastModified, $max);
|
205 |
+
}
|
206 |
+
$options['lastModifiedTime'] = $max;
|
207 |
+
}
|
208 |
+
}
|
209 |
+
return $options;
|
210 |
+
}
|
211 |
+
|
212 |
+
/**
|
213 |
+
* Send message to the Minify logger
|
214 |
+
*
|
215 |
+
* @param string $msg
|
216 |
+
*
|
217 |
+
* @return null
|
218 |
+
*/
|
219 |
+
public function log($msg) {
|
220 |
+
Minify_Logger::log($msg);
|
221 |
+
}
|
222 |
+
}
|
includes/min/lib/Minify/Controller/Files.php
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_Controller_Files
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Controller class for minifying a set of files
|
9 |
+
*
|
10 |
+
* E.g. the following would serve the minified Javascript for a site
|
11 |
+
* <code>
|
12 |
+
* Minify::serve('Files', array(
|
13 |
+
* 'files' => array(
|
14 |
+
* '//js/jquery.js'
|
15 |
+
* ,'//js/plugins.js'
|
16 |
+
* ,'/home/username/file.js'
|
17 |
+
* )
|
18 |
+
* ));
|
19 |
+
* </code>
|
20 |
+
*
|
21 |
+
* As a shortcut, the controller will replace "//" at the beginning
|
22 |
+
* of a filename with $_SERVER['DOCUMENT_ROOT'] . '/'.
|
23 |
+
*
|
24 |
+
* @package Minify
|
25 |
+
* @author Stephen Clay <steve@mrclay.org>
|
26 |
+
*/
|
27 |
+
class Minify_Controller_Files extends Minify_Controller_Base {
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Set up file sources
|
31 |
+
*
|
32 |
+
* @param array $options controller and Minify options
|
33 |
+
* @return array Minify options
|
34 |
+
*
|
35 |
+
* Controller options:
|
36 |
+
*
|
37 |
+
* 'files': (required) array of complete file paths, or a single path
|
38 |
+
*/
|
39 |
+
public function setupSources($options) {
|
40 |
+
// strip controller options
|
41 |
+
|
42 |
+
$files = $options['files'];
|
43 |
+
// if $files is a single object, casting will break it
|
44 |
+
if (is_object($files)) {
|
45 |
+
$files = array($files);
|
46 |
+
} elseif (! is_array($files)) {
|
47 |
+
$files = (array)$files;
|
48 |
+
}
|
49 |
+
unset($options['files']);
|
50 |
+
|
51 |
+
$sources = array();
|
52 |
+
foreach ($files as $file) {
|
53 |
+
if ($file instanceof Minify_Source) {
|
54 |
+
$sources[] = $file;
|
55 |
+
continue;
|
56 |
+
}
|
57 |
+
if (0 === strpos($file, '//')) {
|
58 |
+
$file = $_SERVER['DOCUMENT_ROOT'] . substr($file, 1);
|
59 |
+
}
|
60 |
+
$realPath = realpath($file);
|
61 |
+
if (is_file($realPath)) {
|
62 |
+
$sources[] = new Minify_Source(array(
|
63 |
+
'filepath' => $realPath
|
64 |
+
));
|
65 |
+
} else {
|
66 |
+
$this->log("The path \"{$file}\" could not be found (or was not a file)");
|
67 |
+
return $options;
|
68 |
+
}
|
69 |
+
}
|
70 |
+
if ($sources) {
|
71 |
+
$this->sources = $sources;
|
72 |
+
}
|
73 |
+
return $options;
|
74 |
+
}
|
75 |
+
}
|
76 |
+
|
includes/min/lib/Minify/Controller/Groups.php
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_Controller_Groups
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Controller class for serving predetermined groups of minimized sets, selected
|
9 |
+
* by PATH_INFO
|
10 |
+
*
|
11 |
+
* <code>
|
12 |
+
* Minify::serve('Groups', array(
|
13 |
+
* 'groups' => array(
|
14 |
+
* 'css' => array('//css/type.css', '//css/layout.css')
|
15 |
+
* ,'js' => array('//js/jquery.js', '//js/site.js')
|
16 |
+
* )
|
17 |
+
* ));
|
18 |
+
* </code>
|
19 |
+
*
|
20 |
+
* If the above code were placed in /serve.php, it would enable the URLs
|
21 |
+
* /serve.php/js and /serve.php/css
|
22 |
+
*
|
23 |
+
* As a shortcut, the controller will replace "//" at the beginning
|
24 |
+
* of a filename with $_SERVER['DOCUMENT_ROOT'] . '/'.
|
25 |
+
*
|
26 |
+
* @package Minify
|
27 |
+
* @author Stephen Clay <steve@mrclay.org>
|
28 |
+
*/
|
29 |
+
class Minify_Controller_Groups extends Minify_Controller_Base {
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Set up groups of files as sources
|
33 |
+
*
|
34 |
+
* @param array $options controller and Minify options
|
35 |
+
*
|
36 |
+
* 'groups': (required) array mapping PATH_INFO strings to arrays
|
37 |
+
* of complete file paths. @see Minify_Controller_Groups
|
38 |
+
*
|
39 |
+
* @return array Minify options
|
40 |
+
*/
|
41 |
+
public function setupSources($options) {
|
42 |
+
// strip controller options
|
43 |
+
$groups = $options['groups'];
|
44 |
+
unset($options['groups']);
|
45 |
+
|
46 |
+
// mod_fcgid places PATH_INFO in ORIG_PATH_INFO
|
47 |
+
$pi = isset($_SERVER['ORIG_PATH_INFO'])
|
48 |
+
? substr($_SERVER['ORIG_PATH_INFO'], 1)
|
49 |
+
: (isset($_SERVER['PATH_INFO'])
|
50 |
+
? substr($_SERVER['PATH_INFO'], 1)
|
51 |
+
: false
|
52 |
+
);
|
53 |
+
if (false === $pi || ! isset($groups[$pi])) {
|
54 |
+
// no PATH_INFO or not a valid group
|
55 |
+
$this->log("Missing PATH_INFO or no group set for \"$pi\"");
|
56 |
+
return $options;
|
57 |
+
}
|
58 |
+
$sources = array();
|
59 |
+
|
60 |
+
$files = $groups[$pi];
|
61 |
+
// if $files is a single object, casting will break it
|
62 |
+
if (is_object($files)) {
|
63 |
+
$files = array($files);
|
64 |
+
} elseif (! is_array($files)) {
|
65 |
+
$files = (array)$files;
|
66 |
+
}
|
67 |
+
foreach ($files as $file) {
|
68 |
+
if ($file instanceof Minify_Source) {
|
69 |
+
$sources[] = $file;
|
70 |
+
continue;
|
71 |
+
}
|
72 |
+
if (0 === strpos($file, '//')) {
|
73 |
+
$file = $_SERVER['DOCUMENT_ROOT'] . substr($file, 1);
|
74 |
+
}
|
75 |
+
$realPath = realpath($file);
|
76 |
+
if (is_file($realPath)) {
|
77 |
+
$sources[] = new Minify_Source(array(
|
78 |
+
'filepath' => $realPath
|
79 |
+
));
|
80 |
+
} else {
|
81 |
+
$this->log("The path \"{$file}\" could not be found (or was not a file)");
|
82 |
+
return $options;
|
83 |
+
}
|
84 |
+
}
|
85 |
+
if ($sources) {
|
86 |
+
$this->sources = $sources;
|
87 |
+
}
|
88 |
+
return $options;
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
includes/min/lib/Minify/Controller/MinApp.php
ADDED
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_Controller_MinApp
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Controller class for requests to /min/index.php
|
9 |
+
*
|
10 |
+
* @package Minify
|
11 |
+
* @author Stephen Clay <steve@mrclay.org>
|
12 |
+
*/
|
13 |
+
class Minify_Controller_MinApp extends Minify_Controller_Base {
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Set up groups of files as sources
|
17 |
+
*
|
18 |
+
* @param array $options controller and Minify options
|
19 |
+
*
|
20 |
+
* @return array Minify options
|
21 |
+
*/
|
22 |
+
public function setupSources($options) {
|
23 |
+
// PHP insecure by default: realpath() and other FS functions can't handle null bytes.
|
24 |
+
foreach (array('g', 'b', 'f') as $key) {
|
25 |
+
if (isset($_GET[$key])) {
|
26 |
+
$_GET[$key] = str_replace("\x00", '', (string)$_GET[$key]);
|
27 |
+
}
|
28 |
+
}
|
29 |
+
|
30 |
+
// filter controller options
|
31 |
+
$cOptions = array_merge(
|
32 |
+
array(
|
33 |
+
'allowDirs' => '//'
|
34 |
+
,'groupsOnly' => false
|
35 |
+
,'groups' => array()
|
36 |
+
,'noMinPattern' => '@[-\\.]min\\.(?:js|css)$@i' // matched against basename
|
37 |
+
)
|
38 |
+
,(isset($options['minApp']) ? $options['minApp'] : array())
|
39 |
+
);
|
40 |
+
unset($options['minApp']);
|
41 |
+
$sources = array();
|
42 |
+
$this->selectionId = '';
|
43 |
+
$firstMissingResource = null;
|
44 |
+
if (isset($_GET['g'])) {
|
45 |
+
// add group(s)
|
46 |
+
$this->selectionId .= 'g=' . $_GET['g'];
|
47 |
+
$keys = explode(',', $_GET['g']);
|
48 |
+
if ($keys != array_unique($keys)) {
|
49 |
+
$this->log("Duplicate group key found.");
|
50 |
+
return $options;
|
51 |
+
}
|
52 |
+
$keys = explode(',', $_GET['g']);
|
53 |
+
foreach ($keys as $key) {
|
54 |
+
if (! isset($cOptions['groups'][$key])) {
|
55 |
+
$this->log("A group configuration for \"{$key}\" was not found");
|
56 |
+
return $options;
|
57 |
+
}
|
58 |
+
$files = $cOptions['groups'][$key];
|
59 |
+
// if $files is a single object, casting will break it
|
60 |
+
if (is_object($files)) {
|
61 |
+
$files = array($files);
|
62 |
+
} elseif (! is_array($files)) {
|
63 |
+
$files = (array)$files;
|
64 |
+
}
|
65 |
+
foreach ($files as $file) {
|
66 |
+
if ($file instanceof Minify_Source) {
|
67 |
+
$sources[] = $file;
|
68 |
+
continue;
|
69 |
+
}
|
70 |
+
if (0 === strpos($file, '//')) {
|
71 |
+
$file = $_SERVER['DOCUMENT_ROOT'] . substr($file, 1);
|
72 |
+
}
|
73 |
+
$realpath = realpath($file);
|
74 |
+
if ($realpath && is_file($realpath)) {
|
75 |
+
$sources[] = $this->_getFileSource($realpath, $cOptions);
|
76 |
+
} else {
|
77 |
+
$this->log("The path \"{$file}\" (realpath \"{$realpath}\") could not be found (or was not a file)");
|
78 |
+
if (null === $firstMissingResource) {
|
79 |
+
$firstMissingResource = basename($file);
|
80 |
+
continue;
|
81 |
+
} else {
|
82 |
+
$secondMissingResource = basename($file);
|
83 |
+
$this->log("More than one file was missing: '$firstMissingResource', '$secondMissingResource'");
|
84 |
+
return $options;
|
85 |
+
}
|
86 |
+
}
|
87 |
+
}
|
88 |
+
if ($sources) {
|
89 |
+
try {
|
90 |
+
$this->checkType($sources[0]);
|
91 |
+
} catch (Exception $e) {
|
92 |
+
$this->log($e->getMessage());
|
93 |
+
return $options;
|
94 |
+
}
|
95 |
+
}
|
96 |
+
}
|
97 |
+
}
|
98 |
+
if (! $cOptions['groupsOnly'] && isset($_GET['f'])) {
|
99 |
+
// try user files
|
100 |
+
// The following restrictions are to limit the URLs that minify will
|
101 |
+
// respond to.
|
102 |
+
if (// verify at least one file, files are single comma separated,
|
103 |
+
// and are all same extension
|
104 |
+
! preg_match('/^[^,]+\\.(css|js)(?:,[^,]+\\.\\1)*$/', $_GET['f'], $m)
|
105 |
+
// no "//"
|
106 |
+
|| strpos($_GET['f'], '//') !== false
|
107 |
+
// no "\"
|
108 |
+
|| strpos($_GET['f'], '\\') !== false
|
109 |
+
) {
|
110 |
+
$this->log("GET param 'f' was invalid");
|
111 |
+
return $options;
|
112 |
+
}
|
113 |
+
$ext = ".{$m[1]}";
|
114 |
+
try {
|
115 |
+
$this->checkType($m[1]);
|
116 |
+
} catch (Exception $e) {
|
117 |
+
$this->log($e->getMessage());
|
118 |
+
return $options;
|
119 |
+
}
|
120 |
+
$files = explode(',', $_GET['f']);
|
121 |
+
if ($files != array_unique($files)) {
|
122 |
+
$this->log("Duplicate files were specified");
|
123 |
+
return $options;
|
124 |
+
}
|
125 |
+
if (isset($_GET['b'])) {
|
126 |
+
// check for validity
|
127 |
+
if (preg_match('@^[^/]+(?:/[^/]+)*$@', $_GET['b'])
|
128 |
+
&& false === strpos($_GET['b'], '..')
|
129 |
+
&& $_GET['b'] !== '.') {
|
130 |
+
// valid base
|
131 |
+
$base = "/{$_GET['b']}/";
|
132 |
+
} else {
|
133 |
+
$this->log("GET param 'b' was invalid");
|
134 |
+
return $options;
|
135 |
+
}
|
136 |
+
} else {
|
137 |
+
$base = '/';
|
138 |
+
}
|
139 |
+
$allowDirs = array();
|
140 |
+
foreach ((array)$cOptions['allowDirs'] as $allowDir) {
|
141 |
+
$allowDirs[] = realpath(str_replace('//', $_SERVER['DOCUMENT_ROOT'] . '/', $allowDir));
|
142 |
+
}
|
143 |
+
$basenames = array(); // just for cache id
|
144 |
+
foreach ($files as $file) {
|
145 |
+
$uri = $base . $file;
|
146 |
+
$path = $_SERVER['DOCUMENT_ROOT'] . $uri;
|
147 |
+
$realpath = realpath($path);
|
148 |
+
if (false === $realpath || ! is_file($realpath)) {
|
149 |
+
$this->log("The path \"{$path}\" (realpath \"{$realpath}\") could not be found (or was not a file)");
|
150 |
+
if (null === $firstMissingResource) {
|
151 |
+
$firstMissingResource = $uri;
|
152 |
+
continue;
|
153 |
+
} else {
|
154 |
+
$secondMissingResource = $uri;
|
155 |
+
$this->log("More than one file was missing: '$firstMissingResource', '$secondMissingResource`'");
|
156 |
+
return $options;
|
157 |
+
}
|
158 |
+
}
|
159 |
+
try {
|
160 |
+
parent::checkNotHidden($realpath);
|
161 |
+
parent::checkAllowDirs($realpath, $allowDirs, $uri);
|
162 |
+
} catch (Exception $e) {
|
163 |
+
$this->log($e->getMessage());
|
164 |
+
return $options;
|
165 |
+
}
|
166 |
+
$sources[] = $this->_getFileSource($realpath, $cOptions);
|
167 |
+
$basenames[] = basename($realpath, $ext);
|
168 |
+
}
|
169 |
+
if ($this->selectionId) {
|
170 |
+
$this->selectionId .= '_f=';
|
171 |
+
}
|
172 |
+
$this->selectionId .= implode(',', $basenames) . $ext;
|
173 |
+
}
|
174 |
+
if ($sources) {
|
175 |
+
if (null !== $firstMissingResource) {
|
176 |
+
array_unshift($sources, new Minify_Source(array(
|
177 |
+
'id' => 'missingFile'
|
178 |
+
// should not cause cache invalidation
|
179 |
+
,'lastModified' => 0
|
180 |
+
// due to caching, filename is unreliable.
|
181 |
+
,'content' => "/* Minify: at least one missing file. See " . Minify::URL_DEBUG . " */\n"
|
182 |
+
,'minifier' => ''
|
183 |
+
)));
|
184 |
+
}
|
185 |
+
$this->sources = $sources;
|
186 |
+
} else {
|
187 |
+
$this->log("No sources to serve");
|
188 |
+
}
|
189 |
+
return $options;
|
190 |
+
}
|
191 |
+
|
192 |
+
/**
|
193 |
+
* @param string $file
|
194 |
+
*
|
195 |
+
* @param array $cOptions
|
196 |
+
*
|
197 |
+
* @return Minify_Source
|
198 |
+
*/
|
199 |
+
protected function _getFileSource($file, $cOptions)
|
200 |
+
{
|
201 |
+
$spec['filepath'] = $file;
|
202 |
+
if ($cOptions['noMinPattern'] && preg_match($cOptions['noMinPattern'], basename($file))) {
|
203 |
+
if (preg_match('~\.css$~i', $file)) {
|
204 |
+
$spec['minifyOptions']['compress'] = false;
|
205 |
+
} else {
|
206 |
+
$spec['minifier'] = '';
|
207 |
+
}
|
208 |
+
}
|
209 |
+
return new Minify_Source($spec);
|
210 |
+
}
|
211 |
+
|
212 |
+
protected $_type = null;
|
213 |
+
|
214 |
+
/**
|
215 |
+
* Make sure that only source files of a single type are registered
|
216 |
+
*
|
217 |
+
* @param string $sourceOrExt
|
218 |
+
*
|
219 |
+
* @throws Exception
|
220 |
+
*/
|
221 |
+
public function checkType($sourceOrExt)
|
222 |
+
{
|
223 |
+
if ($sourceOrExt === 'js') {
|
224 |
+
$type = Minify::TYPE_JS;
|
225 |
+
} elseif ($sourceOrExt === 'css') {
|
226 |
+
$type = Minify::TYPE_CSS;
|
227 |
+
} elseif ($sourceOrExt->contentType !== null) {
|
228 |
+
$type = $sourceOrExt->contentType;
|
229 |
+
} else {
|
230 |
+
return;
|
231 |
+
}
|
232 |
+
if ($this->_type === null) {
|
233 |
+
$this->_type = $type;
|
234 |
+
} elseif ($this->_type !== $type) {
|
235 |
+
throw new Exception('Content-Type mismatch');
|
236 |
+
}
|
237 |
+
}
|
238 |
+
}
|
includes/min/lib/Minify/Controller/Page.php
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_Controller_Page
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Controller class for serving a single HTML page
|
9 |
+
*
|
10 |
+
* @link http://code.google.com/p/minify/source/browse/trunk/web/examples/1/index.php#59
|
11 |
+
* @package Minify
|
12 |
+
* @author Stephen Clay <steve@mrclay.org>
|
13 |
+
*/
|
14 |
+
class Minify_Controller_Page extends Minify_Controller_Base {
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Set up source of HTML content
|
18 |
+
*
|
19 |
+
* @param array $options controller and Minify options
|
20 |
+
* @return array Minify options
|
21 |
+
*
|
22 |
+
* Controller options:
|
23 |
+
*
|
24 |
+
* 'content': (required) HTML markup
|
25 |
+
*
|
26 |
+
* 'id': (required) id of page (string for use in server-side caching)
|
27 |
+
*
|
28 |
+
* 'lastModifiedTime': timestamp of when this content changed. This
|
29 |
+
* is recommended to allow both server and client-side caching.
|
30 |
+
*
|
31 |
+
* 'minifyAll': should all CSS and Javascript blocks be individually
|
32 |
+
* minified? (default false)
|
33 |
+
*
|
34 |
+
* @todo Add 'file' option to read HTML file.
|
35 |
+
*/
|
36 |
+
public function setupSources($options) {
|
37 |
+
if (isset($options['file'])) {
|
38 |
+
$sourceSpec = array(
|
39 |
+
'filepath' => $options['file']
|
40 |
+
);
|
41 |
+
$f = $options['file'];
|
42 |
+
} else {
|
43 |
+
// strip controller options
|
44 |
+
$sourceSpec = array(
|
45 |
+
'content' => $options['content']
|
46 |
+
,'id' => $options['id']
|
47 |
+
);
|
48 |
+
$f = $options['id'];
|
49 |
+
unset($options['content'], $options['id']);
|
50 |
+
}
|
51 |
+
// something like "builder,index.php" or "directory,file.html"
|
52 |
+
$this->selectionId = strtr(substr($f, 1 + strlen(dirname(dirname($f)))), '/\\', ',,');
|
53 |
+
|
54 |
+
if (isset($options['minifyAll'])) {
|
55 |
+
// this will be the 2nd argument passed to Minify_HTML::minify()
|
56 |
+
$sourceSpec['minifyOptions'] = array(
|
57 |
+
'cssMinifier' => array('Minify_CSS', 'minify')
|
58 |
+
,'jsMinifier' => array('JSMin', 'minify')
|
59 |
+
);
|
60 |
+
unset($options['minifyAll']);
|
61 |
+
}
|
62 |
+
$this->sources[] = new Minify_Source($sourceSpec);
|
63 |
+
|
64 |
+
$options['contentType'] = Minify::TYPE_HTML;
|
65 |
+
return $options;
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
includes/min/lib/Minify/Controller/Version1.php
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_Controller_Version1
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Controller class for emulating version 1 of minify.php (mostly a proof-of-concept)
|
9 |
+
*
|
10 |
+
* <code>
|
11 |
+
* Minify::serve('Version1');
|
12 |
+
* </code>
|
13 |
+
*
|
14 |
+
* @package Minify
|
15 |
+
* @author Stephen Clay <steve@mrclay.org>
|
16 |
+
*/
|
17 |
+
class Minify_Controller_Version1 extends Minify_Controller_Base {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Set up groups of files as sources
|
21 |
+
*
|
22 |
+
* @param array $options controller and Minify options
|
23 |
+
* @return array Minify options
|
24 |
+
*
|
25 |
+
*/
|
26 |
+
public function setupSources($options) {
|
27 |
+
// PHP insecure by default: realpath() and other FS functions can't handle null bytes.
|
28 |
+
if (isset($_GET['files'])) {
|
29 |
+
$_GET['files'] = str_replace("\x00", '', (string)$_GET['files']);
|
30 |
+
}
|
31 |
+
|
32 |
+
self::_setupDefines();
|
33 |
+
if (MINIFY_USE_CACHE) {
|
34 |
+
$cacheDir = defined('MINIFY_CACHE_DIR')
|
35 |
+
? MINIFY_CACHE_DIR
|
36 |
+
: '';
|
37 |
+
Minify::setCache($cacheDir);
|
38 |
+
}
|
39 |
+
$options['badRequestHeader'] = 'HTTP/1.0 404 Not Found';
|
40 |
+
$options['contentTypeCharset'] = MINIFY_ENCODING;
|
41 |
+
|
42 |
+
// The following restrictions are to limit the URLs that minify will
|
43 |
+
// respond to. Ideally there should be only one way to reference a file.
|
44 |
+
if (! isset($_GET['files'])
|
45 |
+
// verify at least one file, files are single comma separated,
|
46 |
+
// and are all same extension
|
47 |
+
|| ! preg_match('/^[^,]+\\.(css|js)(,[^,]+\\.\\1)*$/', $_GET['files'], $m)
|
48 |
+
// no "//" (makes URL rewriting easier)
|
49 |
+
|| strpos($_GET['files'], '//') !== false
|
50 |
+
// no "\"
|
51 |
+
|| strpos($_GET['files'], '\\') !== false
|
52 |
+
// no "./"
|
53 |
+
|| preg_match('/(?:^|[^\\.])\\.\\//', $_GET['files'])
|
54 |
+
) {
|
55 |
+
return $options;
|
56 |
+
}
|
57 |
+
|
58 |
+
$files = explode(',', $_GET['files']);
|
59 |
+
if (count($files) > MINIFY_MAX_FILES) {
|
60 |
+
return $options;
|
61 |
+
}
|
62 |
+
|
63 |
+
// strings for prepending to relative/absolute paths
|
64 |
+
$prependRelPaths = dirname($_SERVER['SCRIPT_FILENAME'])
|
65 |
+
. DIRECTORY_SEPARATOR;
|
66 |
+
$prependAbsPaths = $_SERVER['DOCUMENT_ROOT'];
|
67 |
+
|
68 |
+
$goodFiles = array();
|
69 |
+
$hasBadSource = false;
|
70 |
+
|
71 |
+
$allowDirs = isset($options['allowDirs'])
|
72 |
+
? $options['allowDirs']
|
73 |
+
: MINIFY_BASE_DIR;
|
74 |
+
|
75 |
+
foreach ($files as $file) {
|
76 |
+
// prepend appropriate string for abs/rel paths
|
77 |
+
$file = ($file[0] === '/' ? $prependAbsPaths : $prependRelPaths) . $file;
|
78 |
+
// make sure a real file!
|
79 |
+
$file = realpath($file);
|
80 |
+
// don't allow unsafe or duplicate files
|
81 |
+
if (parent::_fileIsSafe($file, $allowDirs)
|
82 |
+
&& !in_array($file, $goodFiles))
|
83 |
+
{
|
84 |
+
$goodFiles[] = $file;
|
85 |
+
$srcOptions = array(
|
86 |
+
'filepath' => $file
|
87 |
+
);
|
88 |
+
$this->sources[] = new Minify_Source($srcOptions);
|
89 |
+
} else {
|
90 |
+
$hasBadSource = true;
|
91 |
+
break;
|
92 |
+
}
|
93 |
+
}
|
94 |
+
if ($hasBadSource) {
|
95 |
+
$this->sources = array();
|
96 |
+
}
|
97 |
+
if (! MINIFY_REWRITE_CSS_URLS) {
|
98 |
+
$options['rewriteCssUris'] = false;
|
99 |
+
}
|
100 |
+
return $options;
|
101 |
+
}
|
102 |
+
|
103 |
+
private static function _setupDefines()
|
104 |
+
{
|
105 |
+
$defaults = array(
|
106 |
+
'MINIFY_BASE_DIR' => realpath($_SERVER['DOCUMENT_ROOT'])
|
107 |
+
,'MINIFY_ENCODING' => 'utf-8'
|
108 |
+
,'MINIFY_MAX_FILES' => 16
|
109 |
+
,'MINIFY_REWRITE_CSS_URLS' => true
|
110 |
+
,'MINIFY_USE_CACHE' => true
|
111 |
+
);
|
112 |
+
foreach ($defaults as $const => $val) {
|
113 |
+
if (! defined($const)) {
|
114 |
+
define($const, $val);
|
115 |
+
}
|
116 |
+
}
|
117 |
+
}
|
118 |
+
}
|
119 |
+
|
includes/min/lib/Minify/DebugDetector.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Detect whether request should be debugged
|
5 |
+
*
|
6 |
+
* @package Minify
|
7 |
+
* @author Stephen Clay <steve@mrclay.org>
|
8 |
+
*/
|
9 |
+
class Minify_DebugDetector {
|
10 |
+
public static function shouldDebugRequest($cookie, $get, $requestUri)
|
11 |
+
{
|
12 |
+
if (isset($get['debug'])) {
|
13 |
+
return true;
|
14 |
+
}
|
15 |
+
if (! empty($cookie['minifyDebug'])) {
|
16 |
+
foreach (preg_split('/\\s+/', $cookie['minifyDebug']) as $debugUri) {
|
17 |
+
$pattern = '@' . preg_quote($debugUri, '@') . '@i';
|
18 |
+
$pattern = str_replace(array('\\*', '\\?'), array('.*', '.'), $pattern);
|
19 |
+
if (preg_match($pattern, $requestUri)) {
|
20 |
+
return true;
|
21 |
+
}
|
22 |
+
}
|
23 |
+
}
|
24 |
+
return false;
|
25 |
+
}
|
26 |
+
}
|
includes/min/lib/Minify/HTML.php
ADDED
@@ -0,0 +1,257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_HTML
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Compress HTML
|
9 |
+
*
|
10 |
+
* This is a heavy regex-based removal of whitespace, unnecessary comments and
|
11 |
+
* tokens. IE conditional comments are preserved. There are also options to have
|
12 |
+
* STYLE and SCRIPT blocks compressed by callback functions.
|
13 |
+
*
|
14 |
+
* A test suite is available.
|
15 |
+
*
|
16 |
+
* @package Minify
|
17 |
+
* @author Stephen Clay <steve@mrclay.org>
|
18 |
+
*/
|
19 |
+
class Minify_HTML {
|
20 |
+
/**
|
21 |
+
* @var boolean
|
22 |
+
*/
|
23 |
+
protected $_jsCleanComments = true;
|
24 |
+
|
25 |
+
/**
|
26 |
+
* "Minify" an HTML page
|
27 |
+
*
|
28 |
+
* @param string $html
|
29 |
+
*
|
30 |
+
* @param array $options
|
31 |
+
*
|
32 |
+
* 'cssMinifier' : (optional) callback function to process content of STYLE
|
33 |
+
* elements.
|
34 |
+
*
|
35 |
+
* 'jsMinifier' : (optional) callback function to process content of SCRIPT
|
36 |
+
* elements. Note: the type attribute is ignored.
|
37 |
+
*
|
38 |
+
* 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
|
39 |
+
* unset, minify will sniff for an XHTML doctype.
|
40 |
+
*
|
41 |
+
* @return string
|
42 |
+
*/
|
43 |
+
public static function minify($html, $options = array()) {
|
44 |
+
$min = new self($html, $options);
|
45 |
+
return $min->process();
|
46 |
+
}
|
47 |
+
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Create a minifier object
|
51 |
+
*
|
52 |
+
* @param string $html
|
53 |
+
*
|
54 |
+
* @param array $options
|
55 |
+
*
|
56 |
+
* 'cssMinifier' : (optional) callback function to process content of STYLE
|
57 |
+
* elements.
|
58 |
+
*
|
59 |
+
* 'jsMinifier' : (optional) callback function to process content of SCRIPT
|
60 |
+
* elements. Note: the type attribute is ignored.
|
61 |
+
*
|
62 |
+
* 'jsCleanComments' : (optional) whether to remove HTML comments beginning and end of script block
|
63 |
+
*
|
64 |
+
* 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
|
65 |
+
* unset, minify will sniff for an XHTML doctype.
|
66 |
+
*
|
67 |
+
* @return null
|
68 |
+
*/
|
69 |
+
public function __construct($html, $options = array())
|
70 |
+
{
|
71 |
+
$this->_html = str_replace("\r\n", "\n", trim($html));
|
72 |
+
if (isset($options['xhtml'])) {
|
73 |
+
$this->_isXhtml = (bool)$options['xhtml'];
|
74 |
+
}
|
75 |
+
if (isset($options['cssMinifier'])) {
|
76 |
+
$this->_cssMinifier = $options['cssMinifier'];
|
77 |
+
}
|
78 |
+
if (isset($options['jsMinifier'])) {
|
79 |
+
$this->_jsMinifier = $options['jsMinifier'];
|
80 |
+
}
|
81 |
+
if (isset($options['jsCleanComments'])) {
|
82 |
+
$this->_jsCleanComments = (bool)$options['jsCleanComments'];
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Minify the markeup given in the constructor
|
89 |
+
*
|
90 |
+
* @return string
|
91 |
+
*/
|
92 |
+
public function process()
|
93 |
+
{
|
94 |
+
if ($this->_isXhtml === null) {
|
95 |
+
$this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML'));
|
96 |
+
}
|
97 |
+
|
98 |
+
$this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']);
|
99 |
+
$this->_placeholders = array();
|
100 |
+
|
101 |
+
// replace SCRIPTs (and minify) with placeholders
|
102 |
+
$this->_html = preg_replace_callback(
|
103 |
+
'/(\\s*)<script(\\b[^>]*?>)([\\s\\S]*?)<\\/script>(\\s*)/i'
|
104 |
+
,array($this, '_removeScriptCB')
|
105 |
+
,$this->_html);
|
106 |
+
|
107 |
+
// replace STYLEs (and minify) with placeholders
|
108 |
+
$this->_html = preg_replace_callback(
|
109 |
+
'/\\s*<style(\\b[^>]*>)([\\s\\S]*?)<\\/style>\\s*/i'
|
110 |
+
,array($this, '_removeStyleCB')
|
111 |
+
,$this->_html);
|
112 |
+
|
113 |
+
// remove HTML comments (not containing IE conditional comments).
|
114 |
+
$this->_html = preg_replace_callback(
|
115 |
+
'/<!--([\\s\\S]*?)-->/'
|
116 |
+
,array($this, '_commentCB')
|
117 |
+
,$this->_html);
|
118 |
+
|
119 |
+
// replace PREs with placeholders
|
120 |
+
$this->_html = preg_replace_callback('/\\s*<pre(\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/i'
|
121 |
+
,array($this, '_removePreCB')
|
122 |
+
,$this->_html);
|
123 |
+
|
124 |
+
// replace TEXTAREAs with placeholders
|
125 |
+
$this->_html = preg_replace_callback(
|
126 |
+
'/\\s*<textarea(\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/i'
|
127 |
+
,array($this, '_removeTextareaCB')
|
128 |
+
,$this->_html);
|
129 |
+
|
130 |
+
// trim each line.
|
131 |
+
// @todo take into account attribute values that span multiple lines.
|
132 |
+
$this->_html = preg_replace('/^\\s+|\\s+$/m', '', $this->_html);
|
133 |
+
|
134 |
+
// remove ws around block/undisplayed elements
|
135 |
+
$this->_html = preg_replace('/\\s+(<\\/?(?:area|base(?:font)?|blockquote|body'
|
136 |
+
.'|caption|center|cite|col(?:group)?|dd|dir|div|dl|dt|fieldset|form'
|
137 |
+
.'|frame(?:set)?|h[1-6]|head|hr|html|legend|li|link|map|menu|meta'
|
138 |
+
.'|ol|opt(?:group|ion)|p|param|t(?:able|body|head|d|h||r|foot|itle)'
|
139 |
+
.'|ul)\\b[^>]*>)/i', '$1', $this->_html);
|
140 |
+
|
141 |
+
// remove ws outside of all elements
|
142 |
+
$this->_html = preg_replace(
|
143 |
+
'/>(\\s(?:\\s*))?([^<]+)(\\s(?:\s*))?</'
|
144 |
+
,'>$1$2$3<'
|
145 |
+
,$this->_html);
|
146 |
+
|
147 |
+
// use newlines before 1st attribute in open tags (to limit line lengths)
|
148 |
+
$this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/i', "$1\n$2", $this->_html);
|
149 |
+
|
150 |
+
// fill placeholders
|
151 |
+
$this->_html = str_replace(
|
152 |
+
array_keys($this->_placeholders)
|
153 |
+
,array_values($this->_placeholders)
|
154 |
+
,$this->_html
|
155 |
+
);
|
156 |
+
// issue 229: multi-pass to catch scripts that didn't get replaced in textareas
|
157 |
+
$this->_html = str_replace(
|
158 |
+
array_keys($this->_placeholders)
|
159 |
+
,array_values($this->_placeholders)
|
160 |
+
,$this->_html
|
161 |
+
);
|
162 |
+
return $this->_html;
|
163 |
+
}
|
164 |
+
|
165 |
+
protected function _commentCB($m)
|
166 |
+
{
|
167 |
+
return (0 === strpos($m[1], '[') || false !== strpos($m[1], '<!['))
|
168 |
+
? $m[0]
|
169 |
+
: '';
|
170 |
+
}
|
171 |
+
|
172 |
+
protected function _reservePlace($content)
|
173 |
+
{
|
174 |
+
$placeholder = '%' . $this->_replacementHash . count($this->_placeholders) . '%';
|
175 |
+
$this->_placeholders[$placeholder] = $content;
|
176 |
+
return $placeholder;
|
177 |
+
}
|
178 |
+
|
179 |
+
protected $_isXhtml = null;
|
180 |
+
protected $_replacementHash = null;
|
181 |
+
protected $_placeholders = array();
|
182 |
+
protected $_cssMinifier = null;
|
183 |
+
protected $_jsMinifier = null;
|
184 |
+
|
185 |
+
protected function _removePreCB($m)
|
186 |
+
{
|
187 |
+
return $this->_reservePlace("<pre{$m[1]}");
|
188 |
+
}
|
189 |
+
|
190 |
+
protected function _removeTextareaCB($m)
|
191 |
+
{
|
192 |
+
return $this->_reservePlace("<textarea{$m[1]}");
|
193 |
+
}
|
194 |
+
|
195 |
+
protected function _removeStyleCB($m)
|
196 |
+
{
|
197 |
+
$openStyle = "<style{$m[1]}";
|
198 |
+
$css = $m[2];
|
199 |
+
// remove HTML comments
|
200 |
+
$css = preg_replace('/(?:^\\s*<!--|-->\\s*$)/', '', $css);
|
201 |
+
|
202 |
+
// remove CDATA section markers
|
203 |
+
$css = $this->_removeCdata($css);
|
204 |
+
|
205 |
+
// minify
|
206 |
+
$minifier = $this->_cssMinifier
|
207 |
+
? $this->_cssMinifier
|
208 |
+
: 'trim';
|
209 |
+
$css = call_user_func($minifier, $css);
|
210 |
+
|
211 |
+
return $this->_reservePlace($this->_needsCdata($css)
|
212 |
+
? "{$openStyle}/*<![CDATA[*/{$css}/*]]>*/</style>"
|
213 |
+
: "{$openStyle}{$css}</style>"
|
214 |
+
);
|
215 |
+
}
|
216 |
+
|
217 |
+
protected function _removeScriptCB($m)
|
218 |
+
{
|
219 |
+
$openScript = "<script{$m[2]}";
|
220 |
+
$js = $m[3];
|
221 |
+
|
222 |
+
// whitespace surrounding? preserve at least one space
|
223 |
+
$ws1 = ($m[1] === '') ? '' : ' ';
|
224 |
+
$ws2 = ($m[4] === '') ? '' : ' ';
|
225 |
+
|
226 |
+
// remove HTML comments (and ending "//" if present)
|
227 |
+
if ($this->_jsCleanComments) {
|
228 |
+
$js = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $js);
|
229 |
+
}
|
230 |
+
|
231 |
+
// remove CDATA section markers
|
232 |
+
$js = $this->_removeCdata($js);
|
233 |
+
|
234 |
+
// minify
|
235 |
+
$minifier = $this->_jsMinifier
|
236 |
+
? $this->_jsMinifier
|
237 |
+
: 'trim';
|
238 |
+
$js = call_user_func($minifier, $js);
|
239 |
+
|
240 |
+
return $this->_reservePlace($this->_needsCdata($js)
|
241 |
+
? "{$ws1}{$openScript}/*<![CDATA[*/{$js}/*]]>*/</script>{$ws2}"
|
242 |
+
: "{$ws1}{$openScript}{$js}</script>{$ws2}"
|
243 |
+
);
|
244 |
+
}
|
245 |
+
|
246 |
+
protected function _removeCdata($str)
|
247 |
+
{
|
248 |
+
return (false !== strpos($str, '<![CDATA['))
|
249 |
+
? str_replace(array('<![CDATA[', ']]>'), '', $str)
|
250 |
+
: $str;
|
251 |
+
}
|
252 |
+
|
253 |
+
protected function _needsCdata($str)
|
254 |
+
{
|
255 |
+
return ($this->_isXhtml && preg_match('/(?:[<&]|\\-\\-|\\]\\]>)/', $str));
|
256 |
+
}
|
257 |
+
}
|
includes/min/lib/Minify/HTML/Helper.php
ADDED
@@ -0,0 +1,225 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_HTML_Helper
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Helpers for writing Minfy URIs into HTML
|
9 |
+
*
|
10 |
+
* @package Minify
|
11 |
+
* @author Stephen Clay <steve@mrclay.org>
|
12 |
+
*/
|
13 |
+
class Minify_HTML_Helper {
|
14 |
+
public $rewriteWorks = true;
|
15 |
+
public $minAppUri = '/min';
|
16 |
+
public $groupsConfigFile = '';
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Get an HTML-escaped Minify URI for a group or set of files
|
20 |
+
*
|
21 |
+
* @param string|array $keyOrFiles a group key or array of filepaths/URIs
|
22 |
+
* @param array $opts options:
|
23 |
+
* 'farExpires' : (default true) append a modified timestamp for cache revving
|
24 |
+
* 'debug' : (default false) append debug flag
|
25 |
+
* 'charset' : (default 'UTF-8') for htmlspecialchars
|
26 |
+
* 'minAppUri' : (default '/min') URI of min directory
|
27 |
+
* 'rewriteWorks' : (default true) does mod_rewrite work in min app?
|
28 |
+
* 'groupsConfigFile' : specify if different
|
29 |
+
* @return string
|
30 |
+
*/
|
31 |
+
public static function getUri($keyOrFiles, $opts = array())
|
32 |
+
{
|
33 |
+
$opts = array_merge(array( // default options
|
34 |
+
'farExpires' => true
|
35 |
+
,'debug' => false
|
36 |
+
,'charset' => 'UTF-8'
|
37 |
+
,'minAppUri' => '/min'
|
38 |
+
,'rewriteWorks' => true
|
39 |
+
,'groupsConfigFile' => ''
|
40 |
+
), $opts);
|
41 |
+
$h = new self;
|
42 |
+
$h->minAppUri = $opts['minAppUri'];
|
43 |
+
$h->rewriteWorks = $opts['rewriteWorks'];
|
44 |
+
$h->groupsConfigFile = $opts['groupsConfigFile'];
|
45 |
+
if (is_array($keyOrFiles)) {
|
46 |
+
$h->setFiles($keyOrFiles, $opts['farExpires']);
|
47 |
+
} else {
|
48 |
+
$h->setGroup($keyOrFiles, $opts['farExpires']);
|
49 |
+
}
|
50 |
+
$uri = $h->getRawUri($opts['farExpires'], $opts['debug']);
|
51 |
+
return htmlspecialchars($uri, ENT_QUOTES, $opts['charset']);
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Get non-HTML-escaped URI to minify the specified files
|
56 |
+
*
|
57 |
+
* @param bool $farExpires
|
58 |
+
* @param bool $debug
|
59 |
+
* @return string
|
60 |
+
*/
|
61 |
+
public function getRawUri($farExpires = true, $debug = false)
|
62 |
+
{
|
63 |
+
$path = rtrim($this->minAppUri, '/') . '/';
|
64 |
+
if (! $this->rewriteWorks) {
|
65 |
+
$path .= '?';
|
66 |
+
}
|
67 |
+
if (null === $this->_groupKey) {
|
68 |
+
// @todo: implement shortest uri
|
69 |
+
$path = self::_getShortestUri($this->_filePaths, $path);
|
70 |
+
} else {
|
71 |
+
$path .= "g=" . $this->_groupKey;
|
72 |
+
}
|
73 |
+
if ($debug) {
|
74 |
+
$path .= "&debug";
|
75 |
+
} elseif ($farExpires && $this->_lastModified) {
|
76 |
+
$path .= "&" . $this->_lastModified;
|
77 |
+
}
|
78 |
+
return $path;
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Set the files that will comprise the URI we're building
|
83 |
+
*
|
84 |
+
* @param array $files
|
85 |
+
* @param bool $checkLastModified
|
86 |
+
*/
|
87 |
+
public function setFiles($files, $checkLastModified = true)
|
88 |
+
{
|
89 |
+
$this->_groupKey = null;
|
90 |
+
if ($checkLastModified) {
|
91 |
+
$this->_lastModified = self::getLastModified($files);
|
92 |
+
}
|
93 |
+
// normalize paths like in /min/f=<paths>
|
94 |
+
foreach ($files as $k => $file) {
|
95 |
+
if (0 === strpos($file, '//')) {
|
96 |
+
$file = substr($file, 2);
|
97 |
+
} elseif (0 === strpos($file, '/')
|
98 |
+
|| 1 === strpos($file, ':\\')) {
|
99 |
+
$file = substr($file, strlen($_SERVER['DOCUMENT_ROOT']) + 1);
|
100 |
+
}
|
101 |
+
$file = strtr($file, '\\', '/');
|
102 |
+
$files[$k] = $file;
|
103 |
+
}
|
104 |
+
$this->_filePaths = $files;
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Set the group of files that will comprise the URI we're building
|
109 |
+
*
|
110 |
+
* @param string $key
|
111 |
+
* @param bool $checkLastModified
|
112 |
+
*/
|
113 |
+
public function setGroup($key, $checkLastModified = true)
|
114 |
+
{
|
115 |
+
$this->_groupKey = $key;
|
116 |
+
if ($checkLastModified) {
|
117 |
+
if (! $this->groupsConfigFile) {
|
118 |
+
$this->groupsConfigFile = dirname(dirname(dirname(dirname(__FILE__)))) . '/groupsConfig.php';
|
119 |
+
}
|
120 |
+
if (is_file($this->groupsConfigFile)) {
|
121 |
+
$gc = (require $this->groupsConfigFile);
|
122 |
+
$keys = explode(',', $key);
|
123 |
+
foreach ($keys as $key) {
|
124 |
+
if (isset($gc[$key])) {
|
125 |
+
$this->_lastModified = self::getLastModified($gc[$key], $this->_lastModified);
|
126 |
+
}
|
127 |
+
}
|
128 |
+
}
|
129 |
+
}
|
130 |
+
}
|
131 |
+
|
132 |
+
/**
|
133 |
+
* Get the max(lastModified) of all files
|
134 |
+
*
|
135 |
+
* @param array|string $sources
|
136 |
+
* @param int $lastModified
|
137 |
+
* @return int
|
138 |
+
*/
|
139 |
+
public static function getLastModified($sources, $lastModified = 0)
|
140 |
+
{
|
141 |
+
$max = $lastModified;
|
142 |
+
foreach ((array)$sources as $source) {
|
143 |
+
if (is_object($source) && isset($source->lastModified)) {
|
144 |
+
$max = max($max, $source->lastModified);
|
145 |
+
} elseif (is_string($source)) {
|
146 |
+
if (0 === strpos($source, '//')) {
|
147 |
+
$source = $_SERVER['DOCUMENT_ROOT'] . substr($source, 1);
|
148 |
+
}
|
149 |
+
if (is_file($source)) {
|
150 |
+
$max = max($max, filemtime($source));
|
151 |
+
}
|
152 |
+
}
|
153 |
+
}
|
154 |
+
return $max;
|
155 |
+
}
|
156 |
+
|
157 |
+
protected $_groupKey = null; // if present, URI will be like g=...
|
158 |
+
protected $_filePaths = array();
|
159 |
+
protected $_lastModified = null;
|
160 |
+
|
161 |
+
|
162 |
+
/**
|
163 |
+
* In a given array of strings, find the character they all have at
|
164 |
+
* a particular index
|
165 |
+
*
|
166 |
+
* @param array $arr array of strings
|
167 |
+
* @param int $pos index to check
|
168 |
+
* @return mixed a common char or '' if any do not match
|
169 |
+
*/
|
170 |
+
protected static function _getCommonCharAtPos($arr, $pos) {
|
171 |
+
if (!isset($arr[0][$pos])) {
|
172 |
+
return '';
|
173 |
+
}
|
174 |
+
$c = $arr[0][$pos];
|
175 |
+
$l = count($arr);
|
176 |
+
if ($l === 1) {
|
177 |
+
return $c;
|
178 |
+
}
|
179 |
+
for ($i = 1; $i < $l; ++$i) {
|
180 |
+
if ($arr[$i][$pos] !== $c) {
|
181 |
+
return '';
|
182 |
+
}
|
183 |
+
}
|
184 |
+
return $c;
|
185 |
+
}
|
186 |
+
|
187 |
+
/**
|
188 |
+
* Get the shortest URI to minify the set of source files
|
189 |
+
*
|
190 |
+
* @param array $paths root-relative URIs of files
|
191 |
+
* @param string $minRoot root-relative URI of the "min" application
|
192 |
+
* @return string
|
193 |
+
*/
|
194 |
+
protected static function _getShortestUri($paths, $minRoot = '/min/') {
|
195 |
+
$pos = 0;
|
196 |
+
$base = '';
|
197 |
+
while (true) {
|
198 |
+
$c = self::_getCommonCharAtPos($paths, $pos);
|
199 |
+
if ($c === '') {
|
200 |
+
break;
|
201 |
+
} else {
|
202 |
+
$base .= $c;
|
203 |
+
}
|
204 |
+
++$pos;
|
205 |
+
}
|
206 |
+
$base = preg_replace('@[^/]+$@', '', $base);
|
207 |
+
$uri = $minRoot . 'f=' . implode(',', $paths);
|
208 |
+
|
209 |
+
if (substr($base, -1) === '/') {
|
210 |
+
// we have a base dir!
|
211 |
+
$basedPaths = $paths;
|
212 |
+
$l = count($paths);
|
213 |
+
for ($i = 0; $i < $l; ++$i) {
|
214 |
+
$basedPaths[$i] = substr($paths[$i], strlen($base));
|
215 |
+
}
|
216 |
+
$base = substr($base, 0, strlen($base) - 1);
|
217 |
+
$bUri = $minRoot . 'b=' . $base . '&f=' . implode(',', $basedPaths);
|
218 |
+
|
219 |
+
$uri = strlen($uri) < strlen($bUri)
|
220 |
+
? $uri
|
221 |
+
: $bUri;
|
222 |
+
}
|
223 |
+
return $uri;
|
224 |
+
}
|
225 |
+
}
|
includes/min/lib/Minify/ImportProcessor.php
ADDED
@@ -0,0 +1,216 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_ImportProcessor
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Linearize a CSS/JS file by including content specified by CSS import
|
9 |
+
* declarations. In CSS files, relative URIs are fixed.
|
10 |
+
*
|
11 |
+
* @imports will be processed regardless of where they appear in the source
|
12 |
+
* files; i.e. @imports commented out or in string content will still be
|
13 |
+
* processed!
|
14 |
+
*
|
15 |
+
* This has a unit test but should be considered "experimental".
|
16 |
+
*
|
17 |
+
* @package Minify
|
18 |
+
* @author Stephen Clay <steve@mrclay.org>
|
19 |
+
* @author Simon Schick <simonsimcity@gmail.com>
|
20 |
+
*/
|
21 |
+
class Minify_ImportProcessor {
|
22 |
+
|
23 |
+
public static $filesIncluded = array();
|
24 |
+
|
25 |
+
public static function process($file)
|
26 |
+
{
|
27 |
+
self::$filesIncluded = array();
|
28 |
+
self::$_isCss = (strtolower(substr($file, -4)) === '.css');
|
29 |
+
$obj = new Minify_ImportProcessor(dirname($file));
|
30 |
+
return $obj->_getContent($file);
|
31 |
+
}
|
32 |
+
|
33 |
+
// allows callback funcs to know the current directory
|
34 |
+
private $_currentDir = null;
|
35 |
+
|
36 |
+
// allows callback funcs to know the directory of the file that inherits this one
|
37 |
+
private $_previewsDir = null;
|
38 |
+
|
39 |
+
// allows _importCB to write the fetched content back to the obj
|
40 |
+
private $_importedContent = '';
|
41 |
+
|
42 |
+
private static $_isCss = null;
|
43 |
+
|
44 |
+
/**
|
45 |
+
* @param String $currentDir
|
46 |
+
* @param String $previewsDir Is only used internally
|
47 |
+
*/
|
48 |
+
private function __construct($currentDir, $previewsDir = "")
|
49 |
+
{
|
50 |
+
$this->_currentDir = $currentDir;
|
51 |
+
$this->_previewsDir = $previewsDir;
|
52 |
+
}
|
53 |
+
|
54 |
+
private function _getContent($file, $is_imported = false)
|
55 |
+
{
|
56 |
+
$file = realpath($file);
|
57 |
+
if (! $file
|
58 |
+
|| in_array($file, self::$filesIncluded)
|
59 |
+
|| false === ($content = @file_get_contents($file))
|
60 |
+
) {
|
61 |
+
// file missing, already included, or failed read
|
62 |
+
return '';
|
63 |
+
}
|
64 |
+
self::$filesIncluded[] = realpath($file);
|
65 |
+
$this->_currentDir = dirname($file);
|
66 |
+
|
67 |
+
// remove UTF-8 BOM if present
|
68 |
+
if (pack("CCC",0xef,0xbb,0xbf) === substr($content, 0, 3)) {
|
69 |
+
$content = substr($content, 3);
|
70 |
+
}
|
71 |
+
// ensure uniform EOLs
|
72 |
+
$content = str_replace("\r\n", "\n", $content);
|
73 |
+
|
74 |
+
// process @imports
|
75 |
+
$content = preg_replace_callback(
|
76 |
+
'/
|
77 |
+
@import\\s+
|
78 |
+
(?:url\\(\\s*)? # maybe url(
|
79 |
+
[\'"]? # maybe quote
|
80 |
+
(.*?) # 1 = URI
|
81 |
+
[\'"]? # maybe end quote
|
82 |
+
(?:\\s*\\))? # maybe )
|
83 |
+
([a-zA-Z,\\s]*)? # 2 = media list
|
84 |
+
; # end token
|
85 |
+
/x'
|
86 |
+
,array($this, '_importCB')
|
87 |
+
,$content
|
88 |
+
);
|
89 |
+
|
90 |
+
// You only need to rework the import-path if the script is imported
|
91 |
+
if (self::$_isCss && $is_imported) {
|
92 |
+
// rewrite remaining relative URIs
|
93 |
+
$content = preg_replace_callback(
|
94 |
+
'/url\\(\\s*([^\\)\\s]+)\\s*\\)/'
|
95 |
+
,array($this, '_urlCB')
|
96 |
+
,$content
|
97 |
+
);
|
98 |
+
}
|
99 |
+
|
100 |
+
return $this->_importedContent . $content;
|
101 |
+
}
|
102 |
+
|
103 |
+
private function _importCB($m)
|
104 |
+
{
|
105 |
+
$url = $m[1];
|
106 |
+
$mediaList = preg_replace('/\\s+/', '', $m[2]);
|
107 |
+
|
108 |
+
if (strpos($url, '://') > 0) {
|
109 |
+
// protocol, leave in place for CSS, comment for JS
|
110 |
+
return self::$_isCss
|
111 |
+
? $m[0]
|
112 |
+
: "/* Minify_ImportProcessor will not include remote content */";
|
113 |
+
}
|
114 |
+
if ('/' === $url[0]) {
|
115 |
+
// protocol-relative or root path
|
116 |
+
$url = ltrim($url, '/');
|
117 |
+
$file = realpath($_SERVER['DOCUMENT_ROOT']) . DIRECTORY_SEPARATOR
|
118 |
+
. strtr($url, '/', DIRECTORY_SEPARATOR);
|
119 |
+
} else {
|
120 |
+
// relative to current path
|
121 |
+
$file = $this->_currentDir . DIRECTORY_SEPARATOR
|
122 |
+
. strtr($url, '/', DIRECTORY_SEPARATOR);
|
123 |
+
}
|
124 |
+
$obj = new Minify_ImportProcessor(dirname($file), $this->_currentDir);
|
125 |
+
$content = $obj->_getContent($file, true);
|
126 |
+
if ('' === $content) {
|
127 |
+
// failed. leave in place for CSS, comment for JS
|
128 |
+
return self::$_isCss
|
129 |
+
? $m[0]
|
130 |
+
: "/* Minify_ImportProcessor could not fetch '{$file}' */";
|
131 |
+
}
|
132 |
+
return (!self::$_isCss || preg_match('@(?:^$|\\ball\\b)@', $mediaList))
|
133 |
+
? $content
|
134 |
+
: "@media {$mediaList} {\n{$content}\n}\n";
|
135 |
+
}
|
136 |
+
|
137 |
+
private function _urlCB($m)
|
138 |
+
{
|
139 |
+
// $m[1] is either quoted or not
|
140 |
+
$quote = ($m[1][0] === "'" || $m[1][0] === '"')
|
141 |
+
? $m[1][0]
|
142 |
+
: '';
|
143 |
+
$url = ($quote === '')
|
144 |
+
? $m[1]
|
145 |
+
: substr($m[1], 1, strlen($m[1]) - 2);
|
146 |
+
if ('/' !== $url[0]) {
|
147 |
+
if (strpos($url, '//') > 0) {
|
148 |
+
// probably starts with protocol, do not alter
|
149 |
+
} else {
|
150 |
+
// prepend path with current dir separator (OS-independent)
|
151 |
+
$path = $this->_currentDir
|
152 |
+
. DIRECTORY_SEPARATOR . strtr($url, '/', DIRECTORY_SEPARATOR);
|
153 |
+
// update the relative path by the directory of the file that imported this one
|
154 |
+
$url = self::getPathDiff(realpath($this->_previewsDir), $path);
|
155 |
+
}
|
156 |
+
}
|
157 |
+
return "url({$quote}{$url}{$quote})";
|
158 |
+
}
|
159 |
+
|
160 |
+
/**
|
161 |
+
* @param string $from
|
162 |
+
* @param string $to
|
163 |
+
* @param string $ps
|
164 |
+
* @return string
|
165 |
+
*/
|
166 |
+
private function getPathDiff($from, $to, $ps = DIRECTORY_SEPARATOR)
|
167 |
+
{
|
168 |
+
$realFrom = $this->truepath($from);
|
169 |
+
$realTo = $this->truepath($to);
|
170 |
+
|
171 |
+
$arFrom = explode($ps, rtrim($realFrom, $ps));
|
172 |
+
$arTo = explode($ps, rtrim($realTo, $ps));
|
173 |
+
while (count($arFrom) && count($arTo) && ($arFrom[0] == $arTo[0]))
|
174 |
+
{
|
175 |
+
array_shift($arFrom);
|
176 |
+
array_shift($arTo);
|
177 |
+
}
|
178 |
+
return str_pad("", count($arFrom) * 3, '..' . $ps) . implode($ps, $arTo);
|
179 |
+
}
|
180 |
+
|
181 |
+
/**
|
182 |
+
* This function is to replace PHP's extremely buggy realpath().
|
183 |
+
* @param string $path The original path, can be relative etc.
|
184 |
+
* @return string The resolved path, it might not exist.
|
185 |
+
* @see http://stackoverflow.com/questions/4049856/replace-phps-realpath
|
186 |
+
*/
|
187 |
+
function truepath($path)
|
188 |
+
{
|
189 |
+
// whether $path is unix or not
|
190 |
+
$unipath = strlen($path) == 0 || $path{0} != '/';
|
191 |
+
// attempts to detect if path is relative in which case, add cwd
|
192 |
+
if (strpos($path, ':') === false && $unipath)
|
193 |
+
$path = $this->_currentDir . DIRECTORY_SEPARATOR . $path;
|
194 |
+
|
195 |
+
// resolve path parts (single dot, double dot and double delimiters)
|
196 |
+
$path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
|
197 |
+
$parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
|
198 |
+
$absolutes = array();
|
199 |
+
foreach ($parts as $part) {
|
200 |
+
if ('.' == $part)
|
201 |
+
continue;
|
202 |
+
if ('..' == $part) {
|
203 |
+
array_pop($absolutes);
|
204 |
+
} else {
|
205 |
+
$absolutes[] = $part;
|
206 |
+
}
|
207 |
+
}
|
208 |
+
$path = implode(DIRECTORY_SEPARATOR, $absolutes);
|
209 |
+
// resolve any symlinks
|
210 |
+
if (file_exists($path) && linkinfo($path) > 0)
|
211 |
+
$path = readlink($path);
|
212 |
+
// put initial separator that could have been lost
|
213 |
+
$path = !$unipath ? '/' . $path : $path;
|
214 |
+
return $path;
|
215 |
+
}
|
216 |
+
}
|
includes/min/lib/Minify/JS/ClosureCompiler.php
ADDED
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_JS_ClosureCompiler
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Minify Javascript using Google's Closure Compiler API
|
9 |
+
*
|
10 |
+
* @link http://code.google.com/closure/compiler/
|
11 |
+
* @package Minify
|
12 |
+
* @author Stephen Clay <steve@mrclay.org>
|
13 |
+
*
|
14 |
+
* @todo can use a stream wrapper to unit test this?
|
15 |
+
*/
|
16 |
+
class Minify_JS_ClosureCompiler {
|
17 |
+
const URL = 'http://closure-compiler.appspot.com/compile';
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Minify Javascript code via HTTP request to the Closure Compiler API
|
21 |
+
*
|
22 |
+
* @param string $js input code
|
23 |
+
* @param array $options unused at this point
|
24 |
+
* @return string
|
25 |
+
*/
|
26 |
+
public static function minify($js, array $options = array())
|
27 |
+
{
|
28 |
+
$obj = new self($options);
|
29 |
+
return $obj->min($js);
|
30 |
+
}
|
31 |
+
|
32 |
+
/**
|
33 |
+
*
|
34 |
+
* @param array $options
|
35 |
+
*
|
36 |
+
* fallbackFunc : default array($this, 'fallback');
|
37 |
+
*/
|
38 |
+
public function __construct(array $options = array())
|
39 |
+
{
|
40 |
+
$this->_fallbackFunc = isset($options['fallbackMinifier'])
|
41 |
+
? $options['fallbackMinifier']
|
42 |
+
: array($this, '_fallback');
|
43 |
+
}
|
44 |
+
|
45 |
+
public function min($js)
|
46 |
+
{
|
47 |
+
$postBody = $this->_buildPostBody($js);
|
48 |
+
$bytes = (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
|
49 |
+
? mb_strlen($postBody, '8bit')
|
50 |
+
: strlen($postBody);
|
51 |
+
if ($bytes > 200000) {
|
52 |
+
throw new Minify_JS_ClosureCompiler_Exception(
|
53 |
+
'POST content larger than 200000 bytes'
|
54 |
+
);
|
55 |
+
}
|
56 |
+
$response = $this->_getResponse($postBody);
|
57 |
+
if (preg_match('/^Error\(\d\d?\):/', $response)) {
|
58 |
+
if (is_callable($this->_fallbackFunc)) {
|
59 |
+
$response = "/* Received errors from Closure Compiler API:\n$response"
|
60 |
+
. "\n(Using fallback minifier)\n*/\n";
|
61 |
+
$response .= call_user_func($this->_fallbackFunc, $js);
|
62 |
+
} else {
|
63 |
+
throw new Minify_JS_ClosureCompiler_Exception($response);
|
64 |
+
}
|
65 |
+
}
|
66 |
+
if ($response === '') {
|
67 |
+
$errors = $this->_getResponse($this->_buildPostBody($js, true));
|
68 |
+
throw new Minify_JS_ClosureCompiler_Exception($errors);
|
69 |
+
}
|
70 |
+
return $response;
|
71 |
+
}
|
72 |
+
|
73 |
+
protected $_fallbackFunc = null;
|
74 |
+
|
75 |
+
protected function _getResponse($postBody)
|
76 |
+
{
|
77 |
+
$allowUrlFopen = preg_match('/1|yes|on|true/i', ini_get('allow_url_fopen'));
|
78 |
+
if ($allowUrlFopen) {
|
79 |
+
$contents = file_get_contents(self::URL, false, stream_context_create(array(
|
80 |
+
'http' => array(
|
81 |
+
'method' => 'POST',
|
82 |
+
'header' => "Content-type: application/x-www-form-urlencoded\r\nConnection: close\r\n",
|
83 |
+
'content' => $postBody,
|
84 |
+
'max_redirects' => 0,
|
85 |
+
'timeout' => 15,
|
86 |
+
)
|
87 |
+
)));
|
88 |
+
} elseif (defined('CURLOPT_POST')) {
|
89 |
+
$ch = curl_init(self::URL);
|
90 |
+
curl_setopt($ch, CURLOPT_POST, true);
|
91 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
92 |
+
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded'));
|
93 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $postBody);
|
94 |
+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
|
95 |
+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
|
96 |
+
$contents = curl_exec($ch);
|
97 |
+
curl_close($ch);
|
98 |
+
} else {
|
99 |
+
throw new Minify_JS_ClosureCompiler_Exception(
|
100 |
+
"Could not make HTTP request: allow_url_open is false and cURL not available"
|
101 |
+
);
|
102 |
+
}
|
103 |
+
if (false === $contents) {
|
104 |
+
throw new Minify_JS_ClosureCompiler_Exception(
|
105 |
+
"No HTTP response from server"
|
106 |
+
);
|
107 |
+
}
|
108 |
+
return trim($contents);
|
109 |
+
}
|
110 |
+
|
111 |
+
protected function _buildPostBody($js, $returnErrors = false)
|
112 |
+
{
|
113 |
+
return http_build_query(array(
|
114 |
+
'js_code' => $js,
|
115 |
+
'output_info' => ($returnErrors ? 'errors' : 'compiled_code'),
|
116 |
+
'output_format' => 'text',
|
117 |
+
'compilation_level' => 'SIMPLE_OPTIMIZATIONS'
|
118 |
+
), null, '&');
|
119 |
+
}
|
120 |
+
|
121 |
+
/**
|
122 |
+
* Default fallback function if CC API fails
|
123 |
+
* @param string $js
|
124 |
+
* @return string
|
125 |
+
*/
|
126 |
+
protected function _fallback($js)
|
127 |
+
{
|
128 |
+
return JSMin::minify($js);
|
129 |
+
}
|
130 |
+
}
|
131 |
+
|
132 |
+
class Minify_JS_ClosureCompiler_Exception extends Exception {}
|
includes/min/lib/Minify/Lines.php
ADDED
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_Lines
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Add line numbers in C-style comments for easier debugging of combined content
|
9 |
+
*
|
10 |
+
* @package Minify
|
11 |
+
* @author Stephen Clay <steve@mrclay.org>
|
12 |
+
* @author Adam Pedersen (Issue 55 fix)
|
13 |
+
*/
|
14 |
+
class Minify_Lines {
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Add line numbers in C-style comments
|
18 |
+
*
|
19 |
+
* This uses a very basic parser easily fooled by comment tokens inside
|
20 |
+
* strings or regexes, but, otherwise, generally clean code will not be
|
21 |
+
* mangled. URI rewriting can also be performed.
|
22 |
+
*
|
23 |
+
* @param string $content
|
24 |
+
*
|
25 |
+
* @param array $options available options:
|
26 |
+
*
|
27 |
+
* 'id': (optional) string to identify file. E.g. file name/path
|
28 |
+
*
|
29 |
+
* 'currentDir': (default null) if given, this is assumed to be the
|
30 |
+
* directory of the current CSS file. Using this, minify will rewrite
|
31 |
+
* all relative URIs in import/url declarations to correctly point to
|
32 |
+
* the desired files, and prepend a comment with debugging information about
|
33 |
+
* this process.
|
34 |
+
*
|
35 |
+
* @return string
|
36 |
+
*/
|
37 |
+
public static function minify($content, $options = array())
|
38 |
+
{
|
39 |
+
$id = (isset($options['id']) && $options['id'])
|
40 |
+
? $options['id']
|
41 |
+
: '';
|
42 |
+
$content = str_replace("\r\n", "\n", $content);
|
43 |
+
|
44 |
+
// Hackily rewrite strings with XPath expressions that are
|
45 |
+
// likely to throw off our dumb parser (for Prototype 1.6.1).
|
46 |
+
$content = str_replace('"/*"', '"/"+"*"', $content);
|
47 |
+
$content = preg_replace('@([\'"])(\\.?//?)\\*@', '$1$2$1+$1*', $content);
|
48 |
+
|
49 |
+
$lines = explode("\n", $content);
|
50 |
+
$numLines = count($lines);
|
51 |
+
// determine left padding
|
52 |
+
$padTo = strlen((string) $numLines); // e.g. 103 lines = 3 digits
|
53 |
+
$inComment = false;
|
54 |
+
$i = 0;
|
55 |
+
$newLines = array();
|
56 |
+
while (null !== ($line = array_shift($lines))) {
|
57 |
+
if (('' !== $id) && (0 == $i % 50)) {
|
58 |
+
if ($inComment) {
|
59 |
+
array_push($newLines, '', "/* {$id} *|", '');
|
60 |
+
} else {
|
61 |
+
array_push($newLines, '', "/* {$id} */", '');
|
62 |
+
}
|
63 |
+
}
|
64 |
+
++$i;
|
65 |
+
$newLines[] = self::_addNote($line, $i, $inComment, $padTo);
|
66 |
+
$inComment = self::_eolInComment($line, $inComment);
|
67 |
+
}
|
68 |
+
$content = implode("\n", $newLines) . "\n";
|
69 |
+
|
70 |
+
// check for desired URI rewriting
|
71 |
+
if (isset($options['currentDir'])) {
|
72 |
+
Minify_CSS_UriRewriter::$debugText = '';
|
73 |
+
$content = Minify_CSS_UriRewriter::rewrite(
|
74 |
+
$content
|
75 |
+
,$options['currentDir']
|
76 |
+
,isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT']
|
77 |
+
,isset($options['symlinks']) ? $options['symlinks'] : array()
|
78 |
+
);
|
79 |
+
$content = "/* Minify_CSS_UriRewriter::\$debugText\n\n"
|
80 |
+
. Minify_CSS_UriRewriter::$debugText . "*/\n"
|
81 |
+
. $content;
|
82 |
+
}
|
83 |
+
|
84 |
+
return $content;
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Is the parser within a C-style comment at the end of this line?
|
89 |
+
*
|
90 |
+
* @param string $line current line of code
|
91 |
+
*
|
92 |
+
* @param bool $inComment was the parser in a comment at the
|
93 |
+
* beginning of the line?
|
94 |
+
*
|
95 |
+
* @return bool
|
96 |
+
*/
|
97 |
+
private static function _eolInComment($line, $inComment)
|
98 |
+
{
|
99 |
+
// crude way to avoid things like // */
|
100 |
+
$line = preg_replace('~//.*?(\\*/|/\\*).*~', '', $line);
|
101 |
+
|
102 |
+
while (strlen($line)) {
|
103 |
+
$search = $inComment
|
104 |
+
? '*/'
|
105 |
+
: '/*';
|
106 |
+
$pos = strpos($line, $search);
|
107 |
+
if (false === $pos) {
|
108 |
+
return $inComment;
|
109 |
+
} else {
|
110 |
+
if ($pos == 0
|
111 |
+
|| ($inComment
|
112 |
+
? substr($line, $pos, 3)
|
113 |
+
: substr($line, $pos-1, 3)) != '*/*')
|
114 |
+
{
|
115 |
+
$inComment = ! $inComment;
|
116 |
+
}
|
117 |
+
$line = substr($line, $pos + 2);
|
118 |
+
}
|
119 |
+
}
|
120 |
+
return $inComment;
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Prepend a comment (or note) to the given line
|
125 |
+
*
|
126 |
+
* @param string $line current line of code
|
127 |
+
*
|
128 |
+
* @param string $note content of note/comment
|
129 |
+
*
|
130 |
+
* @param bool $inComment was the parser in a comment at the
|
131 |
+
* beginning of the line?
|
132 |
+
*
|
133 |
+
* @param int $padTo minimum width of comment
|
134 |
+
*
|
135 |
+
* @return string
|
136 |
+
*/
|
137 |
+
private static function _addNote($line, $note, $inComment, $padTo)
|
138 |
+
{
|
139 |
+
return $inComment
|
140 |
+
? '/* ' . str_pad($note, $padTo, ' ', STR_PAD_RIGHT) . ' *| ' . $line
|
141 |
+
: '/* ' . str_pad($note, $padTo, ' ', STR_PAD_RIGHT) . ' */ ' . $line;
|
142 |
+
}
|
143 |
+
}
|
includes/min/lib/Minify/Loader.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_Loader
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Class autoloader
|
9 |
+
*
|
10 |
+
* @package Minify
|
11 |
+
* @author Stephen Clay <steve@mrclay.org>
|
12 |
+
*/
|
13 |
+
class Minify_Loader {
|
14 |
+
public function loadClass($class)
|
15 |
+
{
|
16 |
+
$file = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR;
|
17 |
+
$file .= strtr($class, "\\_", DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR) . '.php';
|
18 |
+
if (is_readable($file)) {
|
19 |
+
require $file;
|
20 |
+
}
|
21 |
+
}
|
22 |
+
|
23 |
+
static public function register()
|
24 |
+
{
|
25 |
+
$inst = new self();
|
26 |
+
spl_autoload_register(array($inst, 'loadClass'));
|
27 |
+
}
|
28 |
+
}
|
includes/min/lib/Minify/Logger.php
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_Logger
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Message logging class
|
9 |
+
*
|
10 |
+
* @package Minify
|
11 |
+
* @author Stephen Clay <steve@mrclay.org>
|
12 |
+
*
|
13 |
+
* @todo lose this singleton! pass log object in Minify::serve and distribute to others
|
14 |
+
*/
|
15 |
+
class Minify_Logger {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Set logger object.
|
19 |
+
*
|
20 |
+
* The object should have a method "log" that accepts a value as 1st argument and
|
21 |
+
* an optional string label as the 2nd.
|
22 |
+
*
|
23 |
+
* @param mixed $obj or a "falsey" value to disable
|
24 |
+
* @return null
|
25 |
+
*/
|
26 |
+
public static function setLogger($obj = null) {
|
27 |
+
self::$_logger = $obj
|
28 |
+
? $obj
|
29 |
+
: null;
|
30 |
+
}
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Pass a message to the logger (if set)
|
34 |
+
*
|
35 |
+
* @param string $msg message to log
|
36 |
+
* @return null
|
37 |
+
*/
|
38 |
+
public static function log($msg, $label = 'Minify') {
|
39 |
+
if (! self::$_logger) return;
|
40 |
+
self::$_logger->log($msg, $label);
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @var mixed logger object (like FirePHP) or null (i.e. no logger available)
|
45 |
+
*/
|
46 |
+
private static $_logger = null;
|
47 |
+
}
|
includes/min/lib/Minify/Packer.php
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_Packer
|
4 |
+
*
|
5 |
+
* To use this class you must first download the PHP port of Packer
|
6 |
+
* and place the file "class.JavaScriptPacker.php" in /lib (or your
|
7 |
+
* include_path).
|
8 |
+
* @link http://joliclic.free.fr/php/javascript-packer/en/
|
9 |
+
*
|
10 |
+
* Be aware that, as long as HTTP encoding is used, scripts minified with JSMin
|
11 |
+
* will provide better client-side performance, as they need not be unpacked in
|
12 |
+
* client-side code.
|
13 |
+
*
|
14 |
+
* @package Minify
|
15 |
+
*/
|
16 |
+
|
17 |
+
if (false === (@include 'class.JavaScriptPacker.php')) {
|
18 |
+
trigger_error(
|
19 |
+
'The script "class.JavaScriptPacker.php" is required. Please see: http:'
|
20 |
+
.'//code.google.com/p/minify/source/browse/trunk/min/lib/Minify/Packer.php'
|
21 |
+
,E_USER_ERROR
|
22 |
+
);
|
23 |
+
}
|
24 |
+
|
25 |
+
/**
|
26 |
+
* Minify Javascript using Dean Edward's Packer
|
27 |
+
*
|
28 |
+
* @package Minify
|
29 |
+
*/
|
30 |
+
class Minify_Packer {
|
31 |
+
public static function minify($code, $options = array())
|
32 |
+
{
|
33 |
+
// @todo: set encoding options based on $options :)
|
34 |
+
$packer = new JavascriptPacker($code, 'Normal', true, false);
|
35 |
+
return trim($packer->pack());
|
36 |
+
}
|
37 |
+
}
|
includes/min/lib/Minify/Source.php
ADDED
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_Source
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* A content source to be minified by Minify.
|
9 |
+
*
|
10 |
+
* This allows per-source minification options and the mixing of files with
|
11 |
+
* content from other sources.
|
12 |
+
*
|
13 |
+
* @package Minify
|
14 |
+
* @author Stephen Clay <steve@mrclay.org>
|
15 |
+
*/
|
16 |
+
class Minify_Source {
|
17 |
+
|
18 |
+
/**
|
19 |
+
* @var int time of last modification
|
20 |
+
*/
|
21 |
+
public $lastModified = null;
|
22 |
+
|
23 |
+
/**
|
24 |
+
* @var callback minifier function specifically for this source.
|
25 |
+
*/
|
26 |
+
public $minifier = null;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @var array minification options specific to this source.
|
30 |
+
*/
|
31 |
+
public $minifyOptions = null;
|
32 |
+
|
33 |
+
/**
|
34 |
+
* @var string full path of file
|
35 |
+
*/
|
36 |
+
public $filepath = null;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* @var string HTTP Content Type (Minify requires one of the constants Minify::TYPE_*)
|
40 |
+
*/
|
41 |
+
public $contentType = null;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Create a Minify_Source
|
45 |
+
*
|
46 |
+
* In the $spec array(), you can either provide a 'filepath' to an existing
|
47 |
+
* file (existence will not be checked!) or give 'id' (unique string for
|
48 |
+
* the content), 'content' (the string content) and 'lastModified'
|
49 |
+
* (unixtime of last update).
|
50 |
+
*
|
51 |
+
* As a shortcut, the controller will replace "//" at the beginning
|
52 |
+
* of a filepath with $_SERVER['DOCUMENT_ROOT'] . '/'.
|
53 |
+
*
|
54 |
+
* @param array $spec options
|
55 |
+
*/
|
56 |
+
public function __construct($spec)
|
57 |
+
{
|
58 |
+
if (isset($spec['filepath'])) {
|
59 |
+
if (0 === strpos($spec['filepath'], '//')) {
|
60 |
+
$spec['filepath'] = $_SERVER['DOCUMENT_ROOT'] . substr($spec['filepath'], 1);
|
61 |
+
}
|
62 |
+
$segments = explode('.', $spec['filepath']);
|
63 |
+
$ext = strtolower(array_pop($segments));
|
64 |
+
switch ($ext) {
|
65 |
+
case 'js' : $this->contentType = 'application/x-javascript';
|
66 |
+
break;
|
67 |
+
case 'css' : $this->contentType = 'text/css';
|
68 |
+
break;
|
69 |
+
case 'htm' : // fallthrough
|
70 |
+
case 'html' : $this->contentType = 'text/html';
|
71 |
+
break;
|
72 |
+
}
|
73 |
+
$this->filepath = $spec['filepath'];
|
74 |
+
$this->_id = $spec['filepath'];
|
75 |
+
$this->lastModified = filemtime($spec['filepath'])
|
76 |
+
// offset for Windows uploaders with out of sync clocks
|
77 |
+
+ round(Minify::$uploaderHoursBehind * 3600);
|
78 |
+
} elseif (isset($spec['id'])) {
|
79 |
+
$this->_id = 'id::' . $spec['id'];
|
80 |
+
if (isset($spec['content'])) {
|
81 |
+
$this->_content = $spec['content'];
|
82 |
+
} else {
|
83 |
+
$this->_getContentFunc = $spec['getContentFunc'];
|
84 |
+
}
|
85 |
+
$this->lastModified = isset($spec['lastModified'])
|
86 |
+
? $spec['lastModified']
|
87 |
+
: time();
|
88 |
+
}
|
89 |
+
if (isset($spec['contentType'])) {
|
90 |
+
$this->contentType = $spec['contentType'];
|
91 |
+
}
|
92 |
+
if (isset($spec['minifier'])) {
|
93 |
+
$this->minifier = $spec['minifier'];
|
94 |
+
}
|
95 |
+
if (isset($spec['minifyOptions'])) {
|
96 |
+
$this->minifyOptions = $spec['minifyOptions'];
|
97 |
+
}
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
* Get content
|
102 |
+
*
|
103 |
+
* @return string
|
104 |
+
*/
|
105 |
+
public function getContent()
|
106 |
+
{
|
107 |
+
$content = (null !== $this->filepath)
|
108 |
+
? file_get_contents($this->filepath)
|
109 |
+
: ((null !== $this->_content)
|
110 |
+
? $this->_content
|
111 |
+
: call_user_func($this->_getContentFunc, $this->_id)
|
112 |
+
);
|
113 |
+
// remove UTF-8 BOM if present
|
114 |
+
return (pack("CCC",0xef,0xbb,0xbf) === substr($content, 0, 3))
|
115 |
+
? substr($content, 3)
|
116 |
+
: $content;
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Get id
|
121 |
+
*
|
122 |
+
* @return string
|
123 |
+
*/
|
124 |
+
public function getId()
|
125 |
+
{
|
126 |
+
return $this->_id;
|
127 |
+
}
|
128 |
+
|
129 |
+
/**
|
130 |
+
* Verifies a single minification call can handle all sources
|
131 |
+
*
|
132 |
+
* @param array $sources Minify_Source instances
|
133 |
+
*
|
134 |
+
* @return bool true iff there no sources with specific minifier preferences.
|
135 |
+
*/
|
136 |
+
public static function haveNoMinifyPrefs($sources)
|
137 |
+
{
|
138 |
+
foreach ($sources as $source) {
|
139 |
+
if (null !== $source->minifier
|
140 |
+
|| null !== $source->minifyOptions) {
|
141 |
+
return false;
|
142 |
+
}
|
143 |
+
}
|
144 |
+
return true;
|
145 |
+
}
|
146 |
+
|
147 |
+
/**
|
148 |
+
* Get unique string for a set of sources
|
149 |
+
*
|
150 |
+
* @param array $sources Minify_Source instances
|
151 |
+
*
|
152 |
+
* @return string
|
153 |
+
*/
|
154 |
+
public static function getDigest($sources)
|
155 |
+
{
|
156 |
+
foreach ($sources as $source) {
|
157 |
+
$info[] = array(
|
158 |
+
$source->_id, $source->minifier, $source->minifyOptions
|
159 |
+
);
|
160 |
+
}
|
161 |
+
return md5(serialize($info));
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Get content type from a group of sources
|
166 |
+
*
|
167 |
+
* This is called if the user doesn't pass in a 'contentType' options
|
168 |
+
*
|
169 |
+
* @param array $sources Minify_Source instances
|
170 |
+
*
|
171 |
+
* @return string content type. e.g. 'text/css'
|
172 |
+
*/
|
173 |
+
public static function getContentType($sources)
|
174 |
+
{
|
175 |
+
foreach ($sources as $source) {
|
176 |
+
if ($source->contentType !== null) {
|
177 |
+
return $source->contentType;
|
178 |
+
}
|
179 |
+
}
|
180 |
+
return 'text/plain';
|
181 |
+
}
|
182 |
+
|
183 |
+
protected $_content = null;
|
184 |
+
protected $_getContentFunc = null;
|
185 |
+
protected $_id = null;
|
186 |
+
}
|
187 |
+
|
includes/min/lib/Minify/YUI/CssCompressor.java
ADDED
@@ -0,0 +1,382 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* YUI Compressor
|
3 |
+
* http://developer.yahoo.com/yui/compressor/
|
4 |
+
* Author: Julien Lecomte - http://www.julienlecomte.net/
|
5 |
+
* Author: Isaac Schlueter - http://foohack.com/
|
6 |
+
* Author: Stoyan Stefanov - http://phpied.com/
|
7 |
+
* Copyright (c) 2011 Yahoo! Inc. All rights reserved.
|
8 |
+
* The copyrights embodied in the content of this file are licensed
|
9 |
+
* by Yahoo! Inc. under the BSD (revised) open source license.
|
10 |
+
*/
|
11 |
+
package com.yahoo.platform.yui.compressor;
|
12 |
+
|
13 |
+
import java.io.IOException;
|
14 |
+
import java.io.Reader;
|
15 |
+
import java.io.Writer;
|
16 |
+
import java.util.regex.Pattern;
|
17 |
+
import java.util.regex.Matcher;
|
18 |
+
import java.util.ArrayList;
|
19 |
+
|
20 |
+
public class CssCompressor {
|
21 |
+
|
22 |
+
private StringBuffer srcsb = new StringBuffer();
|
23 |
+
|
24 |
+
public CssCompressor(Reader in) throws IOException {
|
25 |
+
// Read the stream...
|
26 |
+
int c;
|
27 |
+
while ((c = in.read()) != -1) {
|
28 |
+
srcsb.append((char) c);
|
29 |
+
}
|
30 |
+
}
|
31 |
+
|
32 |
+
// Leave data urls alone to increase parse performance.
|
33 |
+
protected String extractDataUrls(String css, ArrayList preservedTokens) {
|
34 |
+
|
35 |
+
int maxIndex = css.length() - 1;
|
36 |
+
int appendIndex = 0;
|
37 |
+
|
38 |
+
StringBuffer sb = new StringBuffer();
|
39 |
+
|
40 |
+
Pattern p = Pattern.compile("url\\(\\s*([\"']?)data\\:");
|
41 |
+
Matcher m = p.matcher(css);
|
42 |
+
|
43 |
+
/*
|
44 |
+
* Since we need to account for non-base64 data urls, we need to handle
|
45 |
+
* ' and ) being part of the data string. Hence switching to indexOf,
|
46 |
+
* to determine whether or not we have matching string terminators and
|
47 |
+
* handling sb appends directly, instead of using matcher.append* methods.
|
48 |
+
*/
|
49 |
+
|
50 |
+
while (m.find()) {
|
51 |
+
|
52 |
+
int startIndex = m.start() + 4; // "url(".length()
|
53 |
+
String terminator = m.group(1); // ', " or empty (not quoted)
|
54 |
+
|
55 |
+
if (terminator.length() == 0) {
|
56 |
+
terminator = ")";
|
57 |
+
}
|
58 |
+
|
59 |
+
boolean foundTerminator = false;
|
60 |
+
|
61 |
+
int endIndex = m.end() - 1;
|
62 |
+
while(foundTerminator == false && endIndex+1 <= maxIndex) {
|
63 |
+
endIndex = css.indexOf(terminator, endIndex+1);
|
64 |
+
|
65 |
+
if ((endIndex > 0) && (css.charAt(endIndex-1) != '\\')) {
|
66 |
+
foundTerminator = true;
|
67 |
+
if (!")".equals(terminator)) {
|
68 |
+
endIndex = css.indexOf(")", endIndex);
|
69 |
+
}
|
70 |
+
}
|
71 |
+
}
|
72 |
+
|
73 |
+
// Enough searching, start moving stuff over to the buffer
|
74 |
+
sb.append(css.substring(appendIndex, m.start()));
|
75 |
+
|
76 |
+
if (foundTerminator) {
|
77 |
+
String token = css.substring(startIndex, endIndex);
|
78 |
+
token = token.replaceAll("\\s+", "");
|
79 |
+
preservedTokens.add(token);
|
80 |
+
|
81 |
+
String preserver = "url(___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.size() - 1) + "___)";
|
82 |
+
sb.append(preserver);
|
83 |
+
|
84 |
+
appendIndex = endIndex + 1;
|
85 |
+
} else {
|
86 |
+
// No end terminator found, re-add the whole match. Should we throw/warn here?
|
87 |
+
sb.append(css.substring(m.start(), m.end()));
|
88 |
+
appendIndex = m.end();
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
sb.append(css.substring(appendIndex));
|
93 |
+
|
94 |
+
return sb.toString();
|
95 |
+
}
|
96 |
+
|
97 |
+
public void compress(Writer out, int linebreakpos)
|
98 |
+
throws IOException {
|
99 |
+
|
100 |
+
Pattern p;
|
101 |
+
Matcher m;
|
102 |
+
String css = srcsb.toString();
|
103 |
+
|
104 |
+
int startIndex = 0;
|
105 |
+
int endIndex = 0;
|
106 |
+
int i = 0;
|
107 |
+
int max = 0;
|
108 |
+
ArrayList preservedTokens = new ArrayList(0);
|
109 |
+
ArrayList comments = new ArrayList(0);
|
110 |
+
String token;
|
111 |
+
int totallen = css.length();
|
112 |
+
String placeholder;
|
113 |
+
|
114 |
+
css = this.extractDataUrls(css, preservedTokens);
|
115 |
+
|
116 |
+
StringBuffer sb = new StringBuffer(css);
|
117 |
+
|
118 |
+
// collect all comment blocks...
|
119 |
+
while ((startIndex = sb.indexOf("/*", startIndex)) >= 0) {
|
120 |
+
endIndex = sb.indexOf("*/", startIndex + 2);
|
121 |
+
if (endIndex < 0) {
|
122 |
+
endIndex = totallen;
|
123 |
+
}
|
124 |
+
|
125 |
+
token = sb.substring(startIndex + 2, endIndex);
|
126 |
+
comments.add(token);
|
127 |
+
sb.replace(startIndex + 2, endIndex, "___YUICSSMIN_PRESERVE_CANDIDATE_COMMENT_" + (comments.size() - 1) + "___");
|
128 |
+
startIndex += 2;
|
129 |
+
}
|
130 |
+
css = sb.toString();
|
131 |
+
|
132 |
+
// preserve strings so their content doesn't get accidentally minified
|
133 |
+
sb = new StringBuffer();
|
134 |
+
p = Pattern.compile("(\"([^\\\\\"]|\\\\.|\\\\)*\")|(\'([^\\\\\']|\\\\.|\\\\)*\')");
|
135 |
+
m = p.matcher(css);
|
136 |
+
while (m.find()) {
|
137 |
+
token = m.group();
|
138 |
+
char quote = token.charAt(0);
|
139 |
+
token = token.substring(1, token.length() - 1);
|
140 |
+
|
141 |
+
// maybe the string contains a comment-like substring?
|
142 |
+
// one, maybe more? put'em back then
|
143 |
+
if (token.indexOf("___YUICSSMIN_PRESERVE_CANDIDATE_COMMENT_") >= 0) {
|
144 |
+
for (i = 0, max = comments.size(); i < max; i += 1) {
|
145 |
+
token = token.replace("___YUICSSMIN_PRESERVE_CANDIDATE_COMMENT_" + i + "___", comments.get(i).toString());
|
146 |
+
}
|
147 |
+
}
|
148 |
+
|
149 |
+
// minify alpha opacity in filter strings
|
150 |
+
token = token.replaceAll("(?i)progid:DXImageTransform.Microsoft.Alpha\\(Opacity=", "alpha(opacity=");
|
151 |
+
|
152 |
+
preservedTokens.add(token);
|
153 |
+
String preserver = quote + "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.size() - 1) + "___" + quote;
|
154 |
+
m.appendReplacement(sb, preserver);
|
155 |
+
}
|
156 |
+
m.appendTail(sb);
|
157 |
+
css = sb.toString();
|
158 |
+
|
159 |
+
|
160 |
+
// strings are safe, now wrestle the comments
|
161 |
+
for (i = 0, max = comments.size(); i < max; i += 1) {
|
162 |
+
|
163 |
+
token = comments.get(i).toString();
|
164 |
+
placeholder = "___YUICSSMIN_PRESERVE_CANDIDATE_COMMENT_" + i + "___";
|
165 |
+
|
166 |
+
// ! in the first position of the comment means preserve
|
167 |
+
// so push to the preserved tokens while stripping the !
|
168 |
+
if (token.startsWith("!")) {
|
169 |
+
preservedTokens.add(token);
|
170 |
+
css = css.replace(placeholder, "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.size() - 1) + "___");
|
171 |
+
continue;
|
172 |
+
}
|
173 |
+
|
174 |
+
// \ in the last position looks like hack for Mac/IE5
|
175 |
+
// shorten that to /*\*/ and the next one to /**/
|
176 |
+
if (token.endsWith("\\")) {
|
177 |
+
preservedTokens.add("\\");
|
178 |
+
css = css.replace(placeholder, "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.size() - 1) + "___");
|
179 |
+
i = i + 1; // attn: advancing the loop
|
180 |
+
preservedTokens.add("");
|
181 |
+
css = css.replace("___YUICSSMIN_PRESERVE_CANDIDATE_COMMENT_" + i + "___", "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.size() - 1) + "___");
|
182 |
+
continue;
|
183 |
+
}
|
184 |
+
|
185 |
+
// keep empty comments after child selectors (IE7 hack)
|
186 |
+
// e.g. html >/**/ body
|
187 |
+
if (token.length() == 0) {
|
188 |
+
startIndex = css.indexOf(placeholder);
|
189 |
+
if (startIndex > 2) {
|
190 |
+
if (css.charAt(startIndex - 3) == '>') {
|
191 |
+
preservedTokens.add("");
|
192 |
+
css = css.replace(placeholder, "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.size() - 1) + "___");
|
193 |
+
}
|
194 |
+
}
|
195 |
+
}
|
196 |
+
|
197 |
+
// in all other cases kill the comment
|
198 |
+
css = css.replace("/*" + placeholder + "*/", "");
|
199 |
+
}
|
200 |
+
|
201 |
+
|
202 |
+
// Normalize all whitespace strings to single spaces. Easier to work with that way.
|
203 |
+
css = css.replaceAll("\\s+", " ");
|
204 |
+
|
205 |
+
// Remove the spaces before the things that should not have spaces before them.
|
206 |
+
// But, be careful not to turn "p :link {...}" into "p:link{...}"
|
207 |
+
// Swap out any pseudo-class colons with the token, and then swap back.
|
208 |
+
sb = new StringBuffer();
|
209 |
+
p = Pattern.compile("(^|\\})(([^\\{:])+:)+([^\\{]*\\{)");
|
210 |
+
m = p.matcher(css);
|
211 |
+
while (m.find()) {
|
212 |
+
String s = m.group();
|
213 |
+
s = s.replaceAll(":", "___YUICSSMIN_PSEUDOCLASSCOLON___");
|
214 |
+
s = s.replaceAll( "\\\\", "\\\\\\\\" ).replaceAll( "\\$", "\\\\\\$" );
|
215 |
+
m.appendReplacement(sb, s);
|
216 |
+
}
|
217 |
+
m.appendTail(sb);
|
218 |
+
css = sb.toString();
|
219 |
+
// Remove spaces before the things that should not have spaces before them.
|
220 |
+
css = css.replaceAll("\\s+([!{};:>+\\(\\)\\],])", "$1");
|
221 |
+
// bring back the colon
|
222 |
+
css = css.replaceAll("___YUICSSMIN_PSEUDOCLASSCOLON___", ":");
|
223 |
+
|
224 |
+
// retain space for special IE6 cases
|
225 |
+
css = css.replaceAll(":first\\-(line|letter)(\\{|,)", ":first-$1 $2");
|
226 |
+
|
227 |
+
// no space after the end of a preserved comment
|
228 |
+
css = css.replaceAll("\\*/ ", "*/");
|
229 |
+
|
230 |
+
// If there is a @charset, then only allow one, and push to the top of the file.
|
231 |
+
css = css.replaceAll("^(.*)(@charset \"[^\"]*\";)", "$2$1");
|
232 |
+
css = css.replaceAll("^(\\s*@charset [^;]+;\\s*)+", "$1");
|
233 |
+
|
234 |
+
// Put the space back in some cases, to support stuff like
|
235 |
+
// @media screen and (-webkit-min-device-pixel-ratio:0){
|
236 |
+
css = css.replaceAll("\\band\\(", "and (");
|
237 |
+
|
238 |
+
// Remove the spaces after the things that should not have spaces after them.
|
239 |
+
css = css.replaceAll("([!{}:;>+\\(\\[,])\\s+", "$1");
|
240 |
+
|
241 |
+
// remove unnecessary semicolons
|
242 |
+
css = css.replaceAll(";+}", "}");
|
243 |
+
|
244 |
+
// Replace 0(px,em,%) with 0.
|
245 |
+
css = css.replaceAll("([\\s:])(0)(px|em|%|in|cm|mm|pc|pt|ex)", "$1$2");
|
246 |
+
|
247 |
+
// Replace 0 0 0 0; with 0.
|
248 |
+
css = css.replaceAll(":0 0 0 0(;|})", ":0$1");
|
249 |
+
css = css.replaceAll(":0 0 0(;|})", ":0$1");
|
250 |
+
css = css.replaceAll(":0 0(;|})", ":0$1");
|
251 |
+
|
252 |
+
|
253 |
+
// Replace background-position:0; with background-position:0 0;
|
254 |
+
// same for transform-origin
|
255 |
+
sb = new StringBuffer();
|
256 |
+
p = Pattern.compile("(?i)(background-position|transform-origin|webkit-transform-origin|moz-transform-origin|o-transform-origin|ms-transform-origin):0(;|})");
|
257 |
+
m = p.matcher(css);
|
258 |
+
while (m.find()) {
|
259 |
+
m.appendReplacement(sb, m.group(1).toLowerCase() + ":0 0" + m.group(2));
|
260 |
+
}
|
261 |
+
m.appendTail(sb);
|
262 |
+
css = sb.toString();
|
263 |
+
|
264 |
+
// Replace 0.6 to .6, but only when preceded by : or a white-space
|
265 |
+
css = css.replaceAll("(:|\\s)0+\\.(\\d+)", "$1.$2");
|
266 |
+
|
267 |
+
// Shorten colors from rgb(51,102,153) to #336699
|
268 |
+
// This makes it more likely that it'll get further compressed in the next step.
|
269 |
+
p = Pattern.compile("rgb\\s*\\(\\s*([0-9,\\s]+)\\s*\\)");
|
270 |
+
m = p.matcher(css);
|
271 |
+
sb = new StringBuffer();
|
272 |
+
while (m.find()) {
|
273 |
+
String[] rgbcolors = m.group(1).split(",");
|
274 |
+
StringBuffer hexcolor = new StringBuffer("#");
|
275 |
+
for (i = 0; i < rgbcolors.length; i++) {
|
276 |
+
int val = Integer.parseInt(rgbcolors[i]);
|
277 |
+
if (val < 16) {
|
278 |
+
hexcolor.append("0");
|
279 |
+
}
|
280 |
+
hexcolor.append(Integer.toHexString(val));
|
281 |
+
}
|
282 |
+
m.appendReplacement(sb, hexcolor.toString());
|
283 |
+
}
|
284 |
+
m.appendTail(sb);
|
285 |
+
css = sb.toString();
|
286 |
+
|
287 |
+
// Shorten colors from #AABBCC to #ABC. Note that we want to make sure
|
288 |
+
// the color is not preceded by either ", " or =. Indeed, the property
|
289 |
+
// filter: chroma(color="#FFFFFF");
|
290 |
+
// would become
|
291 |
+
// filter: chroma(color="#FFF");
|
292 |
+
// which makes the filter break in IE.
|
293 |
+
// We also want to make sure we're only compressing #AABBCC patterns inside { }, not id selectors ( #FAABAC {} )
|
294 |
+
// We also want to avoid compressing invalid values (e.g. #AABBCCD to #ABCD)
|
295 |
+
p = Pattern.compile("(\\=\\s*?[\"']?)?" + "#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])" + "(:?\\}|[^0-9a-fA-F{][^{]*?\\})");
|
296 |
+
|
297 |
+
m = p.matcher(css);
|
298 |
+
sb = new StringBuffer();
|
299 |
+
int index = 0;
|
300 |
+
|
301 |
+
while (m.find(index)) {
|
302 |
+
|
303 |
+
sb.append(css.substring(index, m.start()));
|
304 |
+
|
305 |
+
boolean isFilter = (m.group(1) != null && !"".equals(m.group(1)));
|
306 |
+
|
307 |
+
if (isFilter) {
|
308 |
+
// Restore, as is. Compression will break filters
|
309 |
+
sb.append(m.group(1) + "#" + m.group(2) + m.group(3) + m.group(4) + m.group(5) + m.group(6) + m.group(7));
|
310 |
+
} else {
|
311 |
+
if( m.group(2).equalsIgnoreCase(m.group(3)) &&
|
312 |
+
m.group(4).equalsIgnoreCase(m.group(5)) &&
|
313 |
+
m.group(6).equalsIgnoreCase(m.group(7))) {
|
314 |
+
|
315 |
+
// #AABBCC pattern
|
316 |
+
sb.append("#" + (m.group(3) + m.group(5) + m.group(7)).toLowerCase());
|
317 |
+
|
318 |
+
} else {
|
319 |
+
|
320 |
+
// Non-compressible color, restore, but lower case.
|
321 |
+
sb.append("#" + (m.group(2) + m.group(3) + m.group(4) + m.group(5) + m.group(6) + m.group(7)).toLowerCase());
|
322 |
+
}
|
323 |
+
}
|
324 |
+
|
325 |
+
index = m.end(7);
|
326 |
+
}
|
327 |
+
|
328 |
+
sb.append(css.substring(index));
|
329 |
+
css = sb.toString();
|
330 |
+
|
331 |
+
// border: none -> border:0
|
332 |
+
sb = new StringBuffer();
|
333 |
+
p = Pattern.compile("(?i)(border|border-top|border-right|border-bottom|border-right|outline|background):none(;|})");
|
334 |
+
m = p.matcher(css);
|
335 |
+
while (m.find()) {
|
336 |
+
m.appendReplacement(sb, m.group(1).toLowerCase() + ":0" + m.group(2));
|
337 |
+
}
|
338 |
+
m.appendTail(sb);
|
339 |
+
css = sb.toString();
|
340 |
+
|
341 |
+
// shorter opacity IE filter
|
342 |
+
css = css.replaceAll("(?i)progid:DXImageTransform.Microsoft.Alpha\\(Opacity=", "alpha(opacity=");
|
343 |
+
|
344 |
+
// Remove empty rules.
|
345 |
+
css = css.replaceAll("[^\\}\\{/;]+\\{\\}", "");
|
346 |
+
|
347 |
+
// TODO: Should this be after we re-insert tokens. These could alter the break points. However then
|
348 |
+
// we'd need to make sure we don't break in the middle of a string etc.
|
349 |
+
if (linebreakpos >= 0) {
|
350 |
+
// Some source control tools don't like it when files containing lines longer
|
351 |
+
// than, say 8000 characters, are checked in. The linebreak option is used in
|
352 |
+
// that case to split long lines after a specific column.
|
353 |
+
i = 0;
|
354 |
+
int linestartpos = 0;
|
355 |
+
sb = new StringBuffer(css);
|
356 |
+
while (i < sb.length()) {
|
357 |
+
char c = sb.charAt(i++);
|
358 |
+
if (c == '}' && i - linestartpos > linebreakpos) {
|
359 |
+
sb.insert(i, '\n');
|
360 |
+
linestartpos = i;
|
361 |
+
}
|
362 |
+
}
|
363 |
+
|
364 |
+
css = sb.toString();
|
365 |
+
}
|
366 |
+
|
367 |
+
// Replace multiple semi-colons in a row by a single one
|
368 |
+
// See SF bug #1980989
|
369 |
+
css = css.replaceAll(";;+", ";");
|
370 |
+
|
371 |
+
// restore preserved comments and strings
|
372 |
+
for(i = 0, max = preservedTokens.size(); i < max; i++) {
|
373 |
+
css = css.replace("___YUICSSMIN_PRESERVED_TOKEN_" + i + "___", preservedTokens.get(i).toString());
|
374 |
+
}
|
375 |
+
|
376 |
+
// Trim the final string (for any leading or trailing white spaces)
|
377 |
+
css = css.trim();
|
378 |
+
|
379 |
+
// Write the output...
|
380 |
+
out.write(css);
|
381 |
+
}
|
382 |
+
}
|
includes/min/lib/Minify/YUI/CssCompressor.php
ADDED
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_YUI_CssCompressor
|
4 |
+
* @package Minify
|
5 |
+
*
|
6 |
+
* YUI Compressor
|
7 |
+
* Author: Julien Lecomte - http://www.julienlecomte.net/
|
8 |
+
* Author: Isaac Schlueter - http://foohack.com/
|
9 |
+
* Author: Stoyan Stefanov - http://phpied.com/
|
10 |
+
* Author: Steve Clay - http://www.mrclay.org/ (PHP port)
|
11 |
+
* Copyright (c) 2009 Yahoo! Inc. All rights reserved.
|
12 |
+
* The copyrights embodied in the content of this file are licensed
|
13 |
+
* by Yahoo! Inc. under the BSD (revised) open source license.
|
14 |
+
*/
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Compress CSS (incomplete DO NOT USE)
|
18 |
+
*
|
19 |
+
* @see https://github.com/yui/yuicompressor/blob/master/src/com/yahoo/platform/yui/compressor/CssCompressor.java
|
20 |
+
*
|
21 |
+
* @package Minify
|
22 |
+
*/
|
23 |
+
class Minify_YUI_CssCompressor {
|
24 |
+
|
25 |
+
/**
|
26 |
+
* Minify a CSS string
|
27 |
+
*
|
28 |
+
* @param string $css
|
29 |
+
*
|
30 |
+
* @return string
|
31 |
+
*/
|
32 |
+
public function compress($css, $linebreakpos = 0)
|
33 |
+
{
|
34 |
+
$css = str_replace("\r\n", "\n", $css);
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @todo comment removal
|
38 |
+
* @todo re-port from newer Java version
|
39 |
+
*/
|
40 |
+
|
41 |
+
// Normalize all whitespace strings to single spaces. Easier to work with that way.
|
42 |
+
$css = preg_replace('@\s+@', ' ', $css);
|
43 |
+
|
44 |
+
// Make a pseudo class for the Box Model Hack
|
45 |
+
$css = preg_replace("@\"\\\\\"}\\\\\"\"@", "___PSEUDOCLASSBMH___", $css);
|
46 |
+
|
47 |
+
// Remove the spaces before the things that should not have spaces before them.
|
48 |
+
// But, be careful not to turn "p :link {...}" into "p:link{...}"
|
49 |
+
// Swap out any pseudo-class colons with the token, and then swap back.
|
50 |
+
$css = preg_replace_callback("@(^|\\})(([^\\{:])+:)+([^\\{]*\\{)@", array($this, '_removeSpacesCB'), $css);
|
51 |
+
|
52 |
+
$css = preg_replace("@\\s+([!{};:>+\\(\\)\\],])@", "$1", $css);
|
53 |
+
$css = str_replace("___PSEUDOCLASSCOLON___", ":", $css);
|
54 |
+
|
55 |
+
// Remove the spaces after the things that should not have spaces after them.
|
56 |
+
$css = preg_replace("@([!{}:;>+\\(\\[,])\\s+@", "$1", $css);
|
57 |
+
|
58 |
+
// Add the semicolon where it's missing.
|
59 |
+
$css = preg_replace("@([^;\\}])}@", "$1;}", $css);
|
60 |
+
|
61 |
+
// Replace 0(px,em,%) with 0.
|
62 |
+
$css = preg_replace("@([\\s:])(0)(px|em|%|in|cm|mm|pc|pt|ex)@", "$1$2", $css);
|
63 |
+
|
64 |
+
// Replace 0 0 0 0; with 0.
|
65 |
+
$css = str_replace(":0 0 0 0;", ":0;", $css);
|
66 |
+
$css = str_replace(":0 0 0;", ":0;", $css);
|
67 |
+
$css = str_replace(":0 0;", ":0;", $css);
|
68 |
+
|
69 |
+
// Replace background-position:0; with background-position:0 0;
|
70 |
+
$css = str_replace("background-position:0;", "background-position:0 0;", $css);
|
71 |
+
|
72 |
+
// Replace 0.6 to .6, but only when preceded by : or a white-space
|
73 |
+
$css = preg_replace("@(:|\\s)0+\\.(\\d+)@", "$1.$2", $css);
|
74 |
+
|
75 |
+
// Shorten colors from rgb(51,102,153) to #336699
|
76 |
+
// This makes it more likely that it'll get further compressed in the next step.
|
77 |
+
$css = preg_replace_callback("@rgb\\s*\\(\\s*([0-9,\\s]+)\\s*\\)@", array($this, '_shortenRgbCB'), $css);
|
78 |
+
|
79 |
+
// Shorten colors from #AABBCC to #ABC. Note that we want to make sure
|
80 |
+
// the color is not preceded by either ", " or =. Indeed, the property
|
81 |
+
// filter: chroma(color="#FFFFFF");
|
82 |
+
// would become
|
83 |
+
// filter: chroma(color="#FFF");
|
84 |
+
// which makes the filter break in IE.
|
85 |
+
$css = preg_replace_callback("@([^\"'=\\s])(\\s*)#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])@", array($this, '_shortenHexCB'), $css);
|
86 |
+
|
87 |
+
// Remove empty rules.
|
88 |
+
$css = preg_replace("@[^\\}]+\\{;\\}@", "", $css);
|
89 |
+
|
90 |
+
$linebreakpos = isset($this->_options['linebreakpos'])
|
91 |
+
? $this->_options['linebreakpos']
|
92 |
+
: 0;
|
93 |
+
|
94 |
+
if ($linebreakpos > 0) {
|
95 |
+
// Some source control tools don't like it when files containing lines longer
|
96 |
+
// than, say 8000 characters, are checked in. The linebreak option is used in
|
97 |
+
// that case to split long lines after a specific column.
|
98 |
+
$i = 0;
|
99 |
+
$linestartpos = 0;
|
100 |
+
$sb = $css;
|
101 |
+
|
102 |
+
// make sure strlen returns byte count
|
103 |
+
$mbIntEnc = null;
|
104 |
+
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
|
105 |
+
$mbIntEnc = mb_internal_encoding();
|
106 |
+
mb_internal_encoding('8bit');
|
107 |
+
}
|
108 |
+
$sbLength = strlen($css);
|
109 |
+
while ($i < $sbLength) {
|
110 |
+
$c = $sb[$i++];
|
111 |
+
if ($c === '}' && $i - $linestartpos > $linebreakpos) {
|
112 |
+
$sb = substr_replace($sb, "\n", $i, 0);
|
113 |
+
$sbLength++;
|
114 |
+
$linestartpos = $i;
|
115 |
+
}
|
116 |
+
}
|
117 |
+
$css = $sb;
|
118 |
+
|
119 |
+
// undo potential mb_encoding change
|
120 |
+
if ($mbIntEnc !== null) {
|
121 |
+
mb_internal_encoding($mbIntEnc);
|
122 |
+
}
|
123 |
+
}
|
124 |
+
|
125 |
+
// Replace the pseudo class for the Box Model Hack
|
126 |
+
$css = str_replace("___PSEUDOCLASSBMH___", "\"\\\\\"}\\\\\"\"", $css);
|
127 |
+
|
128 |
+
// Replace multiple semi-colons in a row by a single one
|
129 |
+
// See SF bug #1980989
|
130 |
+
$css = preg_replace("@;;+@", ";", $css);
|
131 |
+
|
132 |
+
// prevent triggering IE6 bug: http://www.crankygeek.com/ie6pebug/
|
133 |
+
$css = preg_replace('/:first-l(etter|ine)\\{/', ':first-l$1 {', $css);
|
134 |
+
|
135 |
+
// Trim the final string (for any leading or trailing white spaces)
|
136 |
+
$css = trim($css);
|
137 |
+
|
138 |
+
return $css;
|
139 |
+
}
|
140 |
+
|
141 |
+
protected function _removeSpacesCB($m)
|
142 |
+
{
|
143 |
+
return str_replace(':', '___PSEUDOCLASSCOLON___', $m[0]);
|
144 |
+
}
|
145 |
+
|
146 |
+
protected function _shortenRgbCB($m)
|
147 |
+
{
|
148 |
+
$rgbcolors = explode(',', $m[1]);
|
149 |
+
$hexcolor = '#';
|
150 |
+
for ($i = 0; $i < count($rgbcolors); $i++) {
|
151 |
+
$val = round($rgbcolors[$i]);
|
152 |
+
if ($val < 16) {
|
153 |
+
$hexcolor .= '0';
|
154 |
+
}
|
155 |
+
$hexcolor .= dechex($val);
|
156 |
+
}
|
157 |
+
return $hexcolor;
|
158 |
+
}
|
159 |
+
|
160 |
+
protected function _shortenHexCB($m)
|
161 |
+
{
|
162 |
+
// Test for AABBCC pattern
|
163 |
+
if ((strtolower($m[3])===strtolower($m[4])) &&
|
164 |
+
(strtolower($m[5])===strtolower($m[6])) &&
|
165 |
+
(strtolower($m[7])===strtolower($m[8]))) {
|
166 |
+
return $m[1] . $m[2] . "#" . $m[3] . $m[5] . $m[7];
|
167 |
+
} else {
|
168 |
+
return $m[0];
|
169 |
+
}
|
170 |
+
}
|
171 |
+
}
|
includes/min/lib/Minify/YUICompressor.php
ADDED
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class Minify_YUICompressor
|
4 |
+
* @package Minify
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Compress Javascript/CSS using the YUI Compressor
|
9 |
+
*
|
10 |
+
* You must set $jarFile and $tempDir before calling the minify functions.
|
11 |
+
* Also, depending on your shell's environment, you may need to specify
|
12 |
+
* the full path to java in $javaExecutable or use putenv() to setup the
|
13 |
+
* Java environment.
|
14 |
+
*
|
15 |
+
* <code>
|
16 |
+
* Minify_YUICompressor::$jarFile = '/path/to/yuicompressor-2.4.6.jar';
|
17 |
+
* Minify_YUICompressor::$tempDir = '/tmp';
|
18 |
+
* $code = Minify_YUICompressor::minifyJs(
|
19 |
+
* $code
|
20 |
+
* ,array('nomunge' => true, 'line-break' => 1000)
|
21 |
+
* );
|
22 |
+
* </code>
|
23 |
+
*
|
24 |
+
* Note: In case you run out stack (default is 512k), you may increase stack size in $options:
|
25 |
+
* array('stack-size' => '2048k')
|
26 |
+
*
|
27 |
+
* @todo unit tests, $options docs
|
28 |
+
*
|
29 |
+
* @package Minify
|
30 |
+
* @author Stephen Clay <steve@mrclay.org>
|
31 |
+
*/
|
32 |
+
class Minify_YUICompressor {
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Filepath of the YUI Compressor jar file. This must be set before
|
36 |
+
* calling minifyJs() or minifyCss().
|
37 |
+
*
|
38 |
+
* @var string
|
39 |
+
*/
|
40 |
+
public static $jarFile = null;
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Writable temp directory. This must be set before calling minifyJs()
|
44 |
+
* or minifyCss().
|
45 |
+
*
|
46 |
+
* @var string
|
47 |
+
*/
|
48 |
+
public static $tempDir = null;
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Filepath of "java" executable (may be needed if not in shell's PATH)
|
52 |
+
*
|
53 |
+
* @var string
|
54 |
+
*/
|
55 |
+
public static $javaExecutable = 'java';
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Minify a Javascript string
|
59 |
+
*
|
60 |
+
* @param string $js
|
61 |
+
*
|
62 |
+
* @param array $options (verbose is ignored)
|
63 |
+
*
|
64 |
+
* @see http://www.julienlecomte.net/yuicompressor/README
|
65 |
+
*
|
66 |
+
* @return string
|
67 |
+
*/
|
68 |
+
public static function minifyJs($js, $options = array())
|
69 |
+
{
|
70 |
+
return self::_minify('js', $js, $options);
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Minify a CSS string
|
75 |
+
*
|
76 |
+
* @param string $css
|
77 |
+
*
|
78 |
+
* @param array $options (verbose is ignored)
|
79 |
+
*
|
80 |
+
* @see http://www.julienlecomte.net/yuicompressor/README
|
81 |
+
*
|
82 |
+
* @return string
|
83 |
+
*/
|
84 |
+
public static function minifyCss($css, $options = array())
|
85 |
+
{
|
86 |
+
return self::_minify('css', $css, $options);
|
87 |
+
}
|
88 |
+
|
89 |
+
private static function _minify($type, $content, $options)
|
90 |
+
{
|
91 |
+
self::_prepare();
|
92 |
+
if (! ($tmpFile = tempnam(self::$tempDir, 'yuic_'))) {
|
93 |
+
throw new Exception('Minify_YUICompressor : could not create temp file.');
|
94 |
+
}
|
95 |
+
file_put_contents($tmpFile, $content);
|
96 |
+
exec(self::_getCmd($options, $type, $tmpFile), $output, $result_code);
|
97 |
+
unlink($tmpFile);
|
98 |
+
if ($result_code != 0) {
|
99 |
+
throw new Exception('Minify_YUICompressor : YUI compressor execution failed.');
|
100 |
+
}
|
101 |
+
return implode("\n", $output);
|
102 |
+
}
|
103 |
+
|
104 |
+
private static function _getCmd($userOptions, $type, $tmpFile)
|
105 |
+
{
|
106 |
+
$o = array_merge(
|
107 |
+
array(
|
108 |
+
'charset' => ''
|
109 |
+
,'line-break' => 5000
|
110 |
+
,'type' => $type
|
111 |
+
,'nomunge' => false
|
112 |
+
,'preserve-semi' => false
|
113 |
+
,'disable-optimizations' => false
|
114 |
+
,'stack-size' => ''
|
115 |
+
)
|
116 |
+
,$userOptions
|
117 |
+
);
|
118 |
+
$cmd = self::$javaExecutable
|
119 |
+
. (!empty($o['stack-size'])
|
120 |
+
? ' -Xss' . $o['stack-size']
|
121 |
+
: '')
|
122 |
+
. ' -jar ' . escapeshellarg(self::$jarFile)
|
123 |
+
. " --type {$type}"
|
124 |
+
. (preg_match('/^[\\da-zA-Z0-9\\-]+$/', $o['charset'])
|
125 |
+
? " --charset {$o['charset']}"
|
126 |
+
: '')
|
127 |
+
. (is_numeric($o['line-break']) && $o['line-break'] >= 0
|
128 |
+
? ' --line-break ' . (int)$o['line-break']
|
129 |
+
: '');
|
130 |
+
if ($type === 'js') {
|
131 |
+
foreach (array('nomunge', 'preserve-semi', 'disable-optimizations') as $opt) {
|
132 |
+
$cmd .= $o[$opt]
|
133 |
+
? " --{$opt}"
|
134 |
+
: '';
|
135 |
+
}
|
136 |
+
}
|
137 |
+
return $cmd . ' ' . escapeshellarg($tmpFile);
|
138 |
+
}
|
139 |
+
|
140 |
+
private static function _prepare()
|
141 |
+
{
|
142 |
+
if (! is_file(self::$jarFile)) {
|
143 |
+
throw new Exception('Minify_YUICompressor : $jarFile('.self::$jarFile.') is not a valid file.');
|
144 |
+
}
|
145 |
+
if (! is_readable(self::$jarFile)) {
|
146 |
+
throw new Exception('Minify_YUICompressor : $jarFile('.self::$jarFile.') is not readable.');
|
147 |
+
}
|
148 |
+
if (! is_dir(self::$tempDir)) {
|
149 |
+
throw new Exception('Minify_YUICompressor : $tempDir('.self::$tempDir.') is not a valid direcotry.');
|
150 |
+
}
|
151 |
+
if (! is_writable(self::$tempDir)) {
|
152 |
+
throw new Exception('Minify_YUICompressor : $tempDir('.self::$tempDir.') is not writable.');
|
153 |
+
}
|
154 |
+
}
|
155 |
+
}
|
156 |
+
|
includes/min/lib/MrClay/Cli.php
ADDED
@@ -0,0 +1,384 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace MrClay;
|
4 |
+
|
5 |
+
use MrClay\Cli\Arg;
|
6 |
+
use InvalidArgumentException;
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Forms a front controller for a console app, handling and validating arguments (options)
|
10 |
+
*
|
11 |
+
* Instantiate, add arguments, then call validate(). Afterwards, the user's valid arguments
|
12 |
+
* and their values will be available in $cli->values.
|
13 |
+
*
|
14 |
+
* You may also specify that some arguments be used to provide input/output. By communicating
|
15 |
+
* solely through the file pointers provided by openInput()/openOutput(), you can make your
|
16 |
+
* app more flexible to end users.
|
17 |
+
*
|
18 |
+
* @author Steve Clay <steve@mrclay.org>
|
19 |
+
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
20 |
+
*/
|
21 |
+
class Cli {
|
22 |
+
|
23 |
+
/**
|
24 |
+
* @var array validation errors
|
25 |
+
*/
|
26 |
+
public $errors = array();
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @var array option values available after validation.
|
30 |
+
*
|
31 |
+
* E.g. array(
|
32 |
+
* 'a' => false // option was missing
|
33 |
+
* ,'b' => true // option was present
|
34 |
+
* ,'c' => "Hello" // option had value
|
35 |
+
* ,'f' => "/home/user/file" // file path from root
|
36 |
+
* ,'f.raw' => "~/file" // file path as given to option
|
37 |
+
* )
|
38 |
+
*/
|
39 |
+
public $values = array();
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @var array
|
43 |
+
*/
|
44 |
+
public $moreArgs = array();
|
45 |
+
|
46 |
+
/**
|
47 |
+
* @var array
|
48 |
+
*/
|
49 |
+
public $debug = array();
|
50 |
+
|
51 |
+
/**
|
52 |
+
* @var bool The user wants help info
|
53 |
+
*/
|
54 |
+
public $isHelpRequest = false;
|
55 |
+
|
56 |
+
/**
|
57 |
+
* @var Arg[]
|
58 |
+
*/
|
59 |
+
protected $_args = array();
|
60 |
+
|
61 |
+
/**
|
62 |
+
* @var resource
|
63 |
+
*/
|
64 |
+
protected $_stdin = null;
|
65 |
+
|
66 |
+
/**
|
67 |
+
* @var resource
|
68 |
+
*/
|
69 |
+
protected $_stdout = null;
|
70 |
+
|
71 |
+
/**
|
72 |
+
* @param bool $exitIfNoStdin (default true) Exit() if STDIN is not defined
|
73 |
+
*/
|
74 |
+
public function __construct($exitIfNoStdin = true)
|
75 |
+
{
|
76 |
+
if ($exitIfNoStdin && ! defined('STDIN')) {
|
77 |
+
exit('This script is for command-line use only.');
|
78 |
+
}
|
79 |
+
if (isset($GLOBALS['argv'][1])
|
80 |
+
&& ($GLOBALS['argv'][1] === '-?' || $GLOBALS['argv'][1] === '--help')) {
|
81 |
+
$this->isHelpRequest = true;
|
82 |
+
}
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* @param Arg|string $letter
|
87 |
+
* @return Arg
|
88 |
+
*/
|
89 |
+
public function addOptionalArg($letter)
|
90 |
+
{
|
91 |
+
return $this->addArgument($letter, false);
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* @param Arg|string $letter
|
96 |
+
* @return Arg
|
97 |
+
*/
|
98 |
+
public function addRequiredArg($letter)
|
99 |
+
{
|
100 |
+
return $this->addArgument($letter, true);
|
101 |
+
}
|
102 |
+
|
103 |
+
/**
|
104 |
+
* @param string $letter
|
105 |
+
* @param bool $required
|
106 |
+
* @param Arg|null $arg
|
107 |
+
* @return Arg
|
108 |
+
* @throws InvalidArgumentException
|
109 |
+
*/
|
110 |
+
public function addArgument($letter, $required, Arg $arg = null)
|
111 |
+
{
|
112 |
+
if (! preg_match('/^[a-zA-Z]$/', $letter)) {
|
113 |
+
throw new InvalidArgumentException('$letter must be in [a-zA-Z]');
|
114 |
+
}
|
115 |
+
if (! $arg) {
|
116 |
+
$arg = new Arg($required);
|
117 |
+
}
|
118 |
+
$this->_args[$letter] = $arg;
|
119 |
+
return $arg;
|
120 |
+
}
|
121 |
+
|
122 |
+
/**
|
123 |
+
* @param string $letter
|
124 |
+
* @return Arg|null
|
125 |
+
*/
|
126 |
+
public function getArgument($letter)
|
127 |
+
{
|
128 |
+
return isset($this->_args[$letter]) ? $this->_args[$letter] : null;
|
129 |
+
}
|
130 |
+
|
131 |
+
/*
|
132 |
+
* Read and validate options
|
133 |
+
*
|
134 |
+
* @return bool true if all options are valid
|
135 |
+
*/
|
136 |
+
public function validate()
|
137 |
+
{
|
138 |
+
$options = '';
|
139 |
+
$this->errors = array();
|
140 |
+
$this->values = array();
|
141 |
+
$this->_stdin = null;
|
142 |
+
|
143 |
+
if ($this->isHelpRequest) {
|
144 |
+
return false;
|
145 |
+
}
|
146 |
+
|
147 |
+
$lettersUsed = '';
|
148 |
+
foreach ($this->_args as $letter => $arg) {
|
149 |
+
/* @var Arg $arg */
|
150 |
+
$options .= $letter;
|
151 |
+
$lettersUsed .= $letter;
|
152 |
+
|
153 |
+
if ($arg->mayHaveValue || $arg->mustHaveValue) {
|
154 |
+
$options .= ($arg->mustHaveValue ? ':' : '::');
|
155 |
+
}
|
156 |
+
}
|
157 |
+
|
158 |
+
$this->debug['argv'] = $GLOBALS['argv'];
|
159 |
+
$argvCopy = array_slice($GLOBALS['argv'], 1);
|
160 |
+
$o = getopt($options);
|
161 |
+
$this->debug['getopt_options'] = $options;
|
162 |
+
$this->debug['getopt_return'] = $o;
|
163 |
+
|
164 |
+
foreach ($this->_args as $letter => $arg) {
|
165 |
+
/* @var Arg $arg */
|
166 |
+
$this->values[$letter] = false;
|
167 |
+
if (isset($o[$letter])) {
|
168 |
+
if (is_bool($o[$letter])) {
|
169 |
+
|
170 |
+
// remove from argv copy
|
171 |
+
$k = array_search("-$letter", $argvCopy);
|
172 |
+
if ($k !== false) {
|
173 |
+
array_splice($argvCopy, $k, 1);
|
174 |
+
}
|
175 |
+
|
176 |
+
if ($arg->mustHaveValue) {
|
177 |
+
$this->addError($letter, "Missing value");
|
178 |
+
} else {
|
179 |
+
$this->values[$letter] = true;
|
180 |
+
}
|
181 |
+
} else {
|
182 |
+
// string
|
183 |
+
$this->values[$letter] = $o[$letter];
|
184 |
+
$v =& $this->values[$letter];
|
185 |
+
|
186 |
+
// remove from argv copy
|
187 |
+
// first look for -ovalue or -o=value
|
188 |
+
$pattern = "/^-{$letter}=?" . preg_quote($v, '/') . "$/";
|
189 |
+
$foundInArgv = false;
|
190 |
+
foreach ($argvCopy as $k => $argV) {
|
191 |
+
if (preg_match($pattern, $argV)) {
|
192 |
+
array_splice($argvCopy, $k, 1);
|
193 |
+
$foundInArgv = true;
|
194 |
+
break;
|
195 |
+
}
|
196 |
+
}
|
197 |
+
if (! $foundInArgv) {
|
198 |
+
// space separated
|
199 |
+
$k = array_search("-$letter", $argvCopy);
|
200 |
+
if ($k !== false) {
|
201 |
+
array_splice($argvCopy, $k, 2);
|
202 |
+
}
|
203 |
+
}
|
204 |
+
|
205 |
+
// check that value isn't really another option
|
206 |
+
if (strlen($lettersUsed) > 1) {
|
207 |
+
$pattern = "/^-[" . str_replace($letter, '', $lettersUsed) . "]/i";
|
208 |
+
if (preg_match($pattern, $v)) {
|
209 |
+
$this->addError($letter, "Value was read as another option: %s", $v);
|
210 |
+
return false;
|
211 |
+
}
|
212 |
+
}
|
213 |
+
if ($arg->assertFile || $arg->assertDir) {
|
214 |
+
if ($v[0] !== '/' && $v[0] !== '~') {
|
215 |
+
$this->values["$letter.raw"] = $v;
|
216 |
+
$v = getcwd() . "/$v";
|
217 |
+
}
|
218 |
+
}
|
219 |
+
if ($arg->assertFile) {
|
220 |
+
if ($arg->useAsInfile) {
|
221 |
+
$this->_stdin = $v;
|
222 |
+
} elseif ($arg->useAsOutfile) {
|
223 |
+
$this->_stdout = $v;
|
224 |
+
}
|
225 |
+
if ($arg->assertReadable && ! is_readable($v)) {
|
226 |
+
$this->addError($letter, "File not readable: %s", $v);
|
227 |
+
continue;
|
228 |
+
}
|
229 |
+
if ($arg->assertWritable) {
|
230 |
+
if (is_file($v)) {
|
231 |
+
if (! is_writable($v)) {
|
232 |
+
$this->addError($letter, "File not writable: %s", $v);
|
233 |
+
}
|
234 |
+
} else {
|
235 |
+
if (! is_writable(dirname($v))) {
|
236 |
+
$this->addError($letter, "Directory not writable: %s", dirname($v));
|
237 |
+
}
|
238 |
+
}
|
239 |
+
}
|
240 |
+
} elseif ($arg->assertDir && $arg->assertWritable && ! is_writable($v)) {
|
241 |
+
$this->addError($letter, "Directory not readable: %s", $v);
|
242 |
+
}
|
243 |
+
}
|
244 |
+
} else {
|
245 |
+
if ($arg->isRequired()) {
|
246 |
+
$this->addError($letter, "Missing");
|
247 |
+
}
|
248 |
+
}
|
249 |
+
}
|
250 |
+
$this->moreArgs = $argvCopy;
|
251 |
+
reset($this->moreArgs);
|
252 |
+
return empty($this->errors);
|
253 |
+
}
|
254 |
+
|
255 |
+
/**
|
256 |
+
* Get the full paths of file(s) passed in as unspecified arguments
|
257 |
+
*
|
258 |
+
* @return array
|
259 |
+
*/
|
260 |
+
public function getPathArgs()
|
261 |
+
{
|
262 |
+
$r = $this->moreArgs;
|
263 |
+
foreach ($r as $k => $v) {
|
264 |
+
if ($v[0] !== '/' && $v[0] !== '~') {
|
265 |
+
$v = getcwd() . "/$v";
|
266 |
+
$v = str_replace('/./', '/', $v);
|
267 |
+
do {
|
268 |
+
$v = preg_replace('@/[^/]+/\\.\\./@', '/', $v, 1, $changed);
|
269 |
+
} while ($changed);
|
270 |
+
$r[$k] = $v;
|
271 |
+
}
|
272 |
+
}
|
273 |
+
return $r;
|
274 |
+
}
|
275 |
+
|
276 |
+
/**
|
277 |
+
* Get a short list of errors with options
|
278 |
+
*
|
279 |
+
* @return string
|
280 |
+
*/
|
281 |
+
public function getErrorReport()
|
282 |
+
{
|
283 |
+
if (empty($this->errors)) {
|
284 |
+
return '';
|
285 |
+
}
|
286 |
+
$r = "Some arguments did not pass validation:\n";
|
287 |
+
foreach ($this->errors as $letter => $arr) {
|
288 |
+
$r .= " $letter : " . implode(', ', $arr) . "\n";
|
289 |
+
}
|
290 |
+
$r .= "\n";
|
291 |
+
return $r;
|
292 |
+
}
|
293 |
+
|
294 |
+
/**
|
295 |
+
* @return string
|
296 |
+
*/
|
297 |
+
public function getArgumentsListing()
|
298 |
+
{
|
299 |
+
$r = "\n";
|
300 |
+
foreach ($this->_args as $letter => $arg) {
|
301 |
+
/* @var Arg $arg */
|
302 |
+
$desc = $arg->getDescription();
|
303 |
+
$flag = " -$letter ";
|
304 |
+
if ($arg->mayHaveValue) {
|
305 |
+
$flag .= "[VAL]";
|
306 |
+
} elseif ($arg->mustHaveValue) {
|
307 |
+
$flag .= "VAL";
|
308 |
+
}
|
309 |
+
if ($arg->assertFile) {
|
310 |
+
$flag = str_replace('VAL', 'FILE', $flag);
|
311 |
+
} elseif ($arg->assertDir) {
|
312 |
+
$flag = str_replace('VAL', 'DIR', $flag);
|
313 |
+
}
|
314 |
+
if ($arg->isRequired()) {
|
315 |
+
$desc = "(required) $desc";
|
316 |
+
}
|
317 |
+
$flag = str_pad($flag, 12, " ", STR_PAD_RIGHT);
|
318 |
+
$desc = wordwrap($desc, 70);
|
319 |
+
$r .= $flag . str_replace("\n", "\n ", $desc) . "\n\n";
|
320 |
+
}
|
321 |
+
return $r;
|
322 |
+
}
|
323 |
+
|
324 |
+
/**
|
325 |
+
* Get resource of open input stream. May be STDIN or a file pointer
|
326 |
+
* to the file specified by an option with 'STDIN'.
|
327 |
+
*
|
328 |
+
* @return resource
|
329 |
+
*/
|
330 |
+
public function openInput()
|
331 |
+
{
|
332 |
+
if (null === $this->_stdin) {
|
333 |
+
return STDIN;
|
334 |
+
} else {
|
335 |
+
$this->_stdin = fopen($this->_stdin, 'rb');
|
336 |
+
return $this->_stdin;
|
337 |
+
}
|
338 |
+
}
|
339 |
+
|
340 |
+
public function closeInput()
|
341 |
+
{
|
342 |
+
if (null !== $this->_stdin) {
|
343 |
+
fclose($this->_stdin);
|
344 |
+
}
|
345 |
+
}
|
346 |
+
|
347 |
+
/**
|
348 |
+
* Get resource of open output stream. May be STDOUT or a file pointer
|
349 |
+
* to the file specified by an option with 'STDOUT'. The file will be
|
350 |
+
* truncated to 0 bytes on opening.
|
351 |
+
*
|
352 |
+
* @return resource
|
353 |
+
*/
|
354 |
+
public function openOutput()
|
355 |
+
{
|
356 |
+
if (null === $this->_stdout) {
|
357 |
+
return STDOUT;
|
358 |
+
} else {
|
359 |
+
$this->_stdout = fopen($this->_stdout, 'wb');
|
360 |
+
return $this->_stdout;
|
361 |
+
}
|
362 |
+
}
|
363 |
+
|
364 |
+
public function closeOutput()
|
365 |
+
{
|
366 |
+
if (null !== $this->_stdout) {
|
367 |
+
fclose($this->_stdout);
|
368 |
+
}
|
369 |
+
}
|
370 |
+
|
371 |
+
/**
|
372 |
+
* @param string $letter
|
373 |
+
* @param string $msg
|
374 |
+
* @param string $value
|
375 |
+
*/
|
376 |
+
protected function addError($letter, $msg, $value = null)
|
377 |
+
{
|
378 |
+
if ($value !== null) {
|
379 |
+
$value = var_export($value, 1);
|
380 |
+
}
|
381 |
+
$this->errors[$letter][] = sprintf($msg, $value);
|
382 |
+
}
|
383 |
+
}
|
384 |
+
|
includes/min/lib/MrClay/Cli/Arg.php
ADDED
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace MrClay\Cli;
|
4 |
+
|
5 |
+
use BadMethodCallException;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* An argument for a CLI app. This specifies the argument, what values it expects and
|
9 |
+
* how it's treated during validation.
|
10 |
+
*
|
11 |
+
* By default, the argument will be assumed to be an optional letter flag with no value following.
|
12 |
+
*
|
13 |
+
* If the argument may receive a value, call mayHaveValue(). If there's whitespace after the
|
14 |
+
* flag, the value will be returned as true instead of the string.
|
15 |
+
*
|
16 |
+
* If the argument MUST be accompanied by a value, call mustHaveValue(). In this case, whitespace
|
17 |
+
* is permitted between the flag and its value.
|
18 |
+
*
|
19 |
+
* Use assertFile() or assertDir() to indicate that the argument must return a string value
|
20 |
+
* specifying a file or directory. During validation, the value will be resolved to a
|
21 |
+
* full file/dir path (not necessarily existing!) and the original value will be accessible
|
22 |
+
* via a "*.raw" key. E.g. $cli->values['f.raw']
|
23 |
+
*
|
24 |
+
* Use assertReadable()/assertWritable() to cause the validator to test the file/dir for
|
25 |
+
* read/write permissions respectively.
|
26 |
+
*
|
27 |
+
* @method \MrClay\Cli\Arg mayHaveValue() Assert that the argument, if present, may receive a string value
|
28 |
+
* @method \MrClay\Cli\Arg mustHaveValue() Assert that the argument, if present, must receive a string value
|
29 |
+
* @method \MrClay\Cli\Arg assertFile() Assert that the argument's value must specify a file
|
30 |
+
* @method \MrClay\Cli\Arg assertDir() Assert that the argument's value must specify a directory
|
31 |
+
* @method \MrClay\Cli\Arg assertReadable() Assert that the specified file/dir must be readable
|
32 |
+
* @method \MrClay\Cli\Arg assertWritable() Assert that the specified file/dir must be writable
|
33 |
+
*
|
34 |
+
* @property-read bool mayHaveValue
|
35 |
+
* @property-read bool mustHaveValue
|
36 |
+
* @property-read bool assertFile
|
37 |
+
* @property-read bool assertDir
|
38 |
+
* @property-read bool assertReadable
|
39 |
+
* @property-read bool assertWritable
|
40 |
+
* @property-read bool useAsInfile
|
41 |
+
* @property-read bool useAsOutfile
|
42 |
+
*
|
43 |
+
* @author Steve Clay <steve@mrclay.org>
|
44 |
+
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
45 |
+
*/
|
46 |
+
class Arg {
|
47 |
+
/**
|
48 |
+
* @return array
|
49 |
+
*/
|
50 |
+
public function getDefaultSpec()
|
51 |
+
{
|
52 |
+
return array(
|
53 |
+
'mayHaveValue' => false,
|
54 |
+
'mustHaveValue' => false,
|
55 |
+
'assertFile' => false,
|
56 |
+
'assertDir' => false,
|
57 |
+
'assertReadable' => false,
|
58 |
+
'assertWritable' => false,
|
59 |
+
'useAsInfile' => false,
|
60 |
+
'useAsOutfile' => false,
|
61 |
+
);
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* @var array
|
66 |
+
*/
|
67 |
+
protected $spec = array();
|
68 |
+
|
69 |
+
/**
|
70 |
+
* @var bool
|
71 |
+
*/
|
72 |
+
protected $required = false;
|
73 |
+
|
74 |
+
/**
|
75 |
+
* @var string
|
76 |
+
*/
|
77 |
+
protected $description = '';
|
78 |
+
|
79 |
+
/**
|
80 |
+
* @param bool $isRequired
|
81 |
+
*/
|
82 |
+
public function __construct($isRequired = false)
|
83 |
+
{
|
84 |
+
$this->spec = $this->getDefaultSpec();
|
85 |
+
$this->required = (bool) $isRequired;
|
86 |
+
if ($isRequired) {
|
87 |
+
$this->spec['mustHaveValue'] = true;
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Assert that the argument's value points to a writable file. When
|
93 |
+
* Cli::openOutput() is called, a write pointer to this file will
|
94 |
+
* be provided.
|
95 |
+
* @return Arg
|
96 |
+
*/
|
97 |
+
public function useAsOutfile()
|
98 |
+
{
|
99 |
+
$this->spec['useAsOutfile'] = true;
|
100 |
+
return $this->assertFile()->assertWritable();
|
101 |
+
}
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Assert that the argument's value points to a readable file. When
|
105 |
+
* Cli::openInput() is called, a read pointer to this file will
|
106 |
+
* be provided.
|
107 |
+
* @return Arg
|
108 |
+
*/
|
109 |
+
public function useAsInfile()
|
110 |
+
{
|
111 |
+
$this->spec['useAsInfile'] = true;
|
112 |
+
return $this->assertFile()->assertReadable();
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* @return array
|
117 |
+
*/
|
118 |
+
public function getSpec()
|
119 |
+
{
|
120 |
+
return $this->spec;
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* @param string $desc
|
125 |
+
* @return Arg
|
126 |
+
*/
|
127 |
+
public function setDescription($desc)
|
128 |
+
{
|
129 |
+
$this->description = $desc;
|
130 |
+
return $this;
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* @return string
|
135 |
+
*/
|
136 |
+
public function getDescription()
|
137 |
+
{
|
138 |
+
return $this->description;
|
139 |
+
}
|
140 |
+
|
141 |
+
/**
|
142 |
+
* @return bool
|
143 |
+
*/
|
144 |
+
public function isRequired()
|
145 |
+
{
|
146 |
+
return $this->required;
|
147 |
+
}
|
148 |
+
|
149 |
+
/**
|
150 |
+
* Note: magic methods declared in class PHPDOC
|
151 |
+
*
|
152 |
+
* @param string $name
|
153 |
+
* @param array $args
|
154 |
+
* @return Arg
|
155 |
+
* @throws BadMethodCallException
|
156 |
+
*/
|
157 |
+
public function __call($name, array $args = array())
|
158 |
+
{
|
159 |
+
if (array_key_exists($name, $this->spec)) {
|
160 |
+
$this->spec[$name] = true;
|
161 |
+
if ($name === 'assertFile' || $name === 'assertDir') {
|
162 |
+
$this->spec['mustHaveValue'] = true;
|
163 |
+
}
|
164 |
+
} else {
|
165 |
+
throw new BadMethodCallException('Method does not exist');
|
166 |
+
}
|
167 |
+
return $this;
|
168 |
+
}
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Note: magic properties declared in class PHPDOC
|
172 |
+
*
|
173 |
+
* @param string $name
|
174 |
+
* @return bool|null
|
175 |
+
*/
|
176 |
+
public function __get($name)
|
177 |
+
{
|
178 |
+
if (array_key_exists($name, $this->spec)) {
|
179 |
+
return $this->spec[$name];
|
180 |
+
}
|
181 |
+
return null;
|
182 |
+
}
|
183 |
+
}
|
includes/min/quick-test.css
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*! This file exists only for testing a Minify installation. It's content is not used.
|
2 |
+
*
|
3 |
+
* http://example.org/min/f=min/quick-test.css
|
4 |
+
*/
|
5 |
+
|
6 |
+
@import url( /more.css );
|
7 |
+
|
8 |
+
body, td, th {
|
9 |
+
font-family: Verdana , "Bitstream Vera Sans" , Arial Narrow, sans-serif ;
|
10 |
+
|
11 |
+
font-size : 12px;
|
12 |
+
}
|
13 |
+
|
14 |
+
.nav {
|
15 |
+
margin-left: 20%;
|
16 |
+
}
|
17 |
+
#main-nav {
|
18 |
+
background-color: red;
|
19 |
+
border: 1px solid #00ff77;
|
20 |
+
}
|
21 |
+
|
22 |
+
div#content
|
23 |
+
h1 + p {
|
24 |
+
padding-top: 0;
|
25 |
+
margin-top: 0;
|
26 |
+
}
|
27 |
+
|
28 |
+
@media all and (min-width: 640px) {
|
29 |
+
#media-queries-1 { background-color: #0f0; }
|
30 |
+
}
|
includes/min/quick-test.js
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*! This file exists only for testing a Minify installation. It's content is not used.
|
2 |
+
*
|
3 |
+
* http://example.org/min/f=min/quick-test.js
|
4 |
+
*/
|
5 |
+
|
6 |
+
/* Finds the lowest common multiple of two numbers */
|
7 |
+
function LCMCalculator(x, y) { // constructor function
|
8 |
+
var checkInt = function (x) { // inner function
|
9 |
+
if (x % 1 !== 0) {
|
10 |
+
throw new TypeError(x + " is not an integer"); // throw an exception
|
11 |
+
}
|
12 |
+
return x;
|
13 |
+
};
|
14 |
+
this.a = checkInt(x);
|
15 |
+
// ^ semicolons are optional
|
16 |
+
this.b = checkInt(y);
|
17 |
+
}
|
18 |
+
// The prototype of object instances created by a constructor is
|
19 |
+
// that constructor's "prototype" property.
|
20 |
+
LCMCalculator.prototype = { // object literal
|
21 |
+
constructor: LCMCalculator, // when reassigning a prototype, set the constructor property appropriately
|
22 |
+
gcd: function () { // method that calculates the greatest common divisor
|
23 |
+
// Euclidean algorithm:
|
24 |
+
var a = Math.abs(this.a), b = Math.abs(this.b), t;
|
25 |
+
if (a < b) {
|
26 |
+
// swap variables
|
27 |
+
t = b;
|
28 |
+
b = a;
|
29 |
+
a = t;
|
30 |
+
}
|
31 |
+
while (b !== 0) {
|
32 |
+
t = b;
|
33 |
+
b = a % b;
|
34 |
+
a = t;
|
35 |
+
}
|
36 |
+
// Only need to calculate GCD once, so "redefine" this method.
|
37 |
+
// (Actually not redefinition - it's defined on the instance itself,
|
38 |
+
// so that this.gcd refers to this "redefinition" instead of LCMCalculator.prototype.gcd.)
|
39 |
+
// Also, 'gcd' === "gcd", this['gcd'] === this.gcd
|
40 |
+
this['gcd'] = function () {
|
41 |
+
return a;
|
42 |
+
};
|
43 |
+
return a;
|
44 |
+
},
|
45 |
+
// Object property names can be specified by strings delimited by double (") or single (') quotes.
|
46 |
+
"lcm" : function () {
|
47 |
+
// Variable names don't collide with object properties, e.g. |lcm| is not |this.lcm|.
|
48 |
+
// not using |this.a * this.b| to avoid FP precision issues
|
49 |
+
var lcm = this.a / this.gcd() * this.b;
|
50 |
+
// Only need to calculate lcm once, so "redefine" this method.
|
51 |
+
this.lcm = function () {
|
52 |
+
return lcm;
|
53 |
+
};
|
54 |
+
return lcm;
|
55 |
+
},
|
56 |
+
toString: function () {
|
57 |
+
return "LCMCalculator: a = " + this.a + ", b = " + this.b;
|
58 |
+
}
|
59 |
+
};
|
60 |
+
|
61 |
+
//define generic output function; this implementation only works for web browsers
|
62 |
+
function output(x) {
|
63 |
+
document.write(x + "<br>");
|
64 |
+
}
|
65 |
+
|
66 |
+
// Note: Array's map() and forEach() are defined in JavaScript 1.6.
|
67 |
+
// They are used here to demonstrate JavaScript's inherent functional nature.
|
68 |
+
[[25, 55], [21, 56], [22, 58], [28, 56]].map(function (pair) { // array literal + mapping function
|
69 |
+
return new LCMCalculator(pair[0], pair[1]);
|
70 |
+
}).sort(function (a, b) { // sort with this comparative function
|
71 |
+
return a.lcm() - b.lcm();
|
72 |
+
}).forEach(function (obj) {
|
73 |
+
output(obj + ", gcd = " + obj.gcd() + ", lcm = " + obj.lcm());
|
74 |
+
});
|
includes/min/utils.php
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Utility functions for generating URIs in HTML files
|
4 |
+
*
|
5 |
+
* @warning These functions execute min/groupsConfig.php, sometimes multiple times.
|
6 |
+
* You must make sure that functions are not redefined, and if your use custom sources,
|
7 |
+
* you must require_once dirname(__FILE__) . '/lib/Minify/Source.php' so that
|
8 |
+
* class is available.
|
9 |
+
*
|
10 |
+
* @package Minify
|
11 |
+
*/
|
12 |
+
|
13 |
+
if (! class_exists('Minify_Loader', false)) {
|
14 |
+
require dirname(__FILE__) . '/lib/Minify/Loader.php';
|
15 |
+
Minify_Loader::register();
|
16 |
+
}
|
17 |
+
|
18 |
+
/*
|
19 |
+
* Get an HTML-escaped Minify URI for a group or set of files. By default, URIs
|
20 |
+
* will contain timestamps to allow far-future Expires headers.
|
21 |
+
*
|
22 |
+
* <code>
|
23 |
+
* <link rel="stylesheet" type="text/css" href="<?= Minify_getUri('css'); ?>" />
|
24 |
+
* <script src="<?= Minify_getUri('js'); ?>"></script>
|
25 |
+
* <script src="<?= Minify_getUri(array(
|
26 |
+
* '//scripts/file1.js'
|
27 |
+
* ,'//scripts/file2.js'
|
28 |
+
* )); ?>"></script>
|
29 |
+
* </code>
|
30 |
+
*
|
31 |
+
* @param mixed $keyOrFiles a group key or array of file paths/URIs
|
32 |
+
* @param array $opts options:
|
33 |
+
* 'farExpires' : (default true) append a modified timestamp for cache revving
|
34 |
+
* 'debug' : (default false) append debug flag
|
35 |
+
* 'charset' : (default 'UTF-8') for htmlspecialchars
|
36 |
+
* 'minAppUri' : (default '/min') URI of min directory
|
37 |
+
* 'rewriteWorks' : (default true) does mod_rewrite work in min app?
|
38 |
+
* 'groupsConfigFile' : specify if different
|
39 |
+
* @return string
|
40 |
+
*/
|
41 |
+
function Minify_getUri($keyOrFiles, $opts = array())
|
42 |
+
{
|
43 |
+
return Minify_HTML_Helper::getUri($keyOrFiles, $opts);
|
44 |
+
}
|
45 |
+
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Get the last modification time of several source js/css files. If you're
|
49 |
+
* caching the output of Minify_getUri(), you might want to know if one of the
|
50 |
+
* dependent source files has changed so you can update the HTML.
|
51 |
+
*
|
52 |
+
* Since this makes a bunch of stat() calls, you might not want to check this
|
53 |
+
* on every request.
|
54 |
+
*
|
55 |
+
* @param array $keysAndFiles group keys and/or file paths/URIs.
|
56 |
+
* @return int latest modification time of all given keys/files
|
57 |
+
*/
|
58 |
+
function Minify_mtime($keysAndFiles, $groupsConfigFile = null)
|
59 |
+
{
|
60 |
+
$gc = null;
|
61 |
+
if (! $groupsConfigFile) {
|
62 |
+
$groupsConfigFile = dirname(__FILE__) . '/groupsConfig.php';
|
63 |
+
}
|
64 |
+
$sources = array();
|
65 |
+
foreach ($keysAndFiles as $keyOrFile) {
|
66 |
+
if (is_object($keyOrFile)
|
67 |
+
|| 0 === strpos($keyOrFile, '/')
|
68 |
+
|| 1 === strpos($keyOrFile, ':\\')) {
|
69 |
+
// a file/source obj
|
70 |
+
$sources[] = $keyOrFile;
|
71 |
+
} else {
|
72 |
+
if (! $gc) {
|
73 |
+
$gc = (require $groupsConfigFile);
|
74 |
+
}
|
75 |
+
foreach ($gc[$keyOrFile] as $source) {
|
76 |
+
$sources[] = $source;
|
77 |
+
}
|
78 |
+
}
|
79 |
+
}
|
80 |
+
return Minify_HTML_Helper::getLastModified($sources);
|
81 |
+
}
|
readme.txt
CHANGED
@@ -4,20 +4,22 @@ Tags: minify, compress, combine, html, css, javascript, js, performance, load, s
|
|
4 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3S8BRPLWLNQ38
|
5 |
Requires at least: 3.5
|
6 |
Tested up to: 4.1
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
11 |
-
A very light weight plugin,
|
12 |
|
13 |
== Description ==
|
14 |
-
This plugin
|
15 |
|
16 |
By activating this plugin, you will see the source of your HTML, inline JavaScript and CSS are now compressed. The size will be smaller and quite helpful to improve your page load speed as well as google page speed and yslow grade (if you care).
|
17 |
|
18 |
-
To check whether this plugin works properly, simply view your site source or press Ctrl + U from your keyboard. In the end of the source, you should see message like:
|
19 |
|
20 |
-
*** Total size saved
|
|
|
|
|
21 |
|
22 |
== Installation ==
|
23 |
1. Upload the `wp-super-minify` folder to the `/wp-content/plugins/` directory
|
@@ -27,7 +29,7 @@ To check whether this plugin works properly, simply view your site source or pre
|
|
27 |
== Frequently Asked Questions ==
|
28 |
= What does this plugin do? =
|
29 |
|
30 |
-
This plugin
|
31 |
|
32 |
= Any specific requirements for this plugin to work? =
|
33 |
|
@@ -41,5 +43,9 @@ Pretty much, yeah.
|
|
41 |
1. Admin Settings
|
42 |
|
43 |
== Changelog ==
|
|
|
|
|
|
|
|
|
44 |
= 1.0, Oct 04, 2014 =
|
45 |
* Initial release
|
4 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3S8BRPLWLNQ38
|
5 |
Requires at least: 3.5
|
6 |
Tested up to: 4.1
|
7 |
+
Stable tag: 1.1
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
11 |
+
A very light weight plugin, combines, minifies, and caches JavaScript and CSS files on demand to speed up page loads.
|
12 |
|
13 |
== Description ==
|
14 |
+
This plugin combines, minifies, and caches JavaScript and CSS files on demand to speed up page loads, using [Minify PHP Framework](https://code.google.com/p/minify/).
|
15 |
|
16 |
By activating this plugin, you will see the source of your HTML, inline JavaScript and CSS are now compressed. The size will be smaller and quite helpful to improve your page load speed as well as google page speed and yslow grade (if you care).
|
17 |
|
18 |
+
To check whether this plugin works properly, simply view your site source or press Ctrl + U from your keyboard. In the end of the source, you should see message something like:
|
19 |
|
20 |
+
*** Total size saved: 11.341% | Size before compression: 27104 bytes | Size after compression: 24030 bytes. ***
|
21 |
+
|
22 |
+
**P.S. It is aways the best policy to open a [support thread](http://wordpress.org/support/plugin/wp-super-minify) first before posting a negative review.**
|
23 |
|
24 |
== Installation ==
|
25 |
1. Upload the `wp-super-minify` folder to the `/wp-content/plugins/` directory
|
29 |
== Frequently Asked Questions ==
|
30 |
= What does this plugin do? =
|
31 |
|
32 |
+
This plugin combines, minifies, and caches JavaScript and CSS files on demand to speed up page loads.
|
33 |
|
34 |
= Any specific requirements for this plugin to work? =
|
35 |
|
43 |
1. Admin Settings
|
44 |
|
45 |
== Changelog ==
|
46 |
+
= 1.1, Jan 03, 2015 =
|
47 |
+
* Fixed compression related issues
|
48 |
+
* Replaced manual compression functions with the latest version of [Minify PHP Framework](https://code.google.com/p/minify/)
|
49 |
+
|
50 |
= 1.0, Oct 04, 2014 =
|
51 |
* Initial release
|
wp-super-minify.php
CHANGED
@@ -3,12 +3,20 @@
|
|
3 |
Plugin Name: WP Super Minify
|
4 |
Plugin URI: https://github.com/dipakcg/wp-super-minify
|
5 |
Description: This plugin combine and compress HTML, JavaScript and CSS files to improve page load speed.
|
|
|
6 |
Author: Dipak C. Gajjar
|
7 |
-
|
8 |
-
Author URI: http://www.dipakgajjar.com/
|
9 |
*/
|
10 |
|
11 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
// Register with hook 'wp_enqueue_scripts', which can be used for front end CSS and JavaScript
|
13 |
add_action( 'admin_init', 'wpsmy_add_stylesheet' );
|
14 |
function wpsmy_add_stylesheet() {
|
@@ -21,7 +29,7 @@ function wpsmy_add_stylesheet() {
|
|
21 |
add_action( 'admin_menu', 'wpsmy_add_admin_menu' );
|
22 |
function wpsmy_add_admin_menu() {
|
23 |
// add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function);
|
24 |
-
add_menu_page( 'WP Super Minify
|
25 |
}
|
26 |
|
27 |
function wpsmy_admin_options() {
|
@@ -84,7 +92,7 @@ function wpsmy_admin_options() {
|
|
84 |
<span class="wpsmy_admin_dev_sidebar"> <?php echo '<img src="' . plugins_url( 'assets/images/wpsmy-other-plugins-16x16.png' , __FILE__ ) . '" > '; ?> <a href="http://profiles.wordpress.org/dipakcg#content-plugins" target="_blank"> Get my other plugins </a> </span>
|
85 |
<span class="wpsmy_admin_dev_sidebar"> <?php echo '<img src="' . plugins_url( 'assets/images/wpsmy-twitter-16x16.png' , __FILE__ ) . '" > '; ?>Follow me on Twitter: <a href="https://twitter.com/dipakcgajjar" target="_blank">@dipakcgajjar</a> </span>
|
86 |
<br />
|
87 |
-
<span class="wpsmy_admin_dev_sidebar" style="float: right;"> Version: <strong>
|
88 |
</div>
|
89 |
</td>
|
90 |
</tr>
|
@@ -93,156 +101,63 @@ function wpsmy_admin_options() {
|
|
93 |
<?php
|
94 |
}
|
95 |
|
96 |
-
//
|
97 |
function wpsmy_activate_plugin() {
|
98 |
|
99 |
// Save default options value in the database
|
100 |
update_option( 'wpsmy_combine_js', 'on' );
|
101 |
update_option( 'wpsmy_combine_css', 'on' );
|
102 |
}
|
103 |
-
|
104 |
-
// On plugin activation, call the function that will make flush_rules to be called at the end of the PHP execution
|
105 |
register_activation_hook( __FILE__, 'wpsmy_activate_plugin' );
|
106 |
|
107 |
-
|
108 |
-
{
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
}
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
{
|
127 |
-
return $this->html;
|
128 |
-
}
|
129 |
-
|
130 |
-
protected function bottomComment($raw, $compressed)
|
131 |
-
{
|
132 |
-
$raw = strlen($raw);
|
133 |
-
$compressed = strlen($compressed);
|
134 |
-
|
135 |
-
$savings = ($raw-$compressed) / $raw * 100;
|
136 |
-
|
137 |
-
$savings = round($savings, 2);
|
138 |
-
|
139 |
-
return '<!--'.PHP_EOL.'*** HTML, JavaScript and CSS of this site is combined and compressed by WP Super Minify plugin v1.0 - http://wordpress.org/plugins/wp-super-minify ***'.PHP_EOL.'*** Total size saved '.$savings.'%. From '.$raw.' bytes, now '.$compressed.' bytes. ***'.PHP_EOL.'-->';
|
140 |
-
}
|
141 |
-
|
142 |
-
protected function minifyHTML($html)
|
143 |
-
{
|
144 |
-
$pattern = '/<(?<script>script).*?<\/script\s*>|<(?<style>style).*?<\/style\s*>|<!(?<comment>--).*?-->|<(?<tag>[\/\w.:-]*)(?:".*?"|\'.*?\'|[^\'">]+)*>|(?<text>((<[^!\/\w.:-])?[^<]*)+)|/si';
|
145 |
-
preg_match_all($pattern, $html, $matches, PREG_SET_ORDER);
|
146 |
-
$overriding = false;
|
147 |
-
$raw_tag = false;
|
148 |
-
// Variable reused for output
|
149 |
-
$html = '';
|
150 |
-
foreach ($matches as $token)
|
151 |
-
{
|
152 |
-
$tag = (isset($token['tag'])) ? strtolower($token['tag']) : null;
|
153 |
-
|
154 |
-
$content = $token[0];
|
155 |
-
|
156 |
-
if (is_null($tag)) {
|
157 |
-
if ( !empty($token['script']) ) {
|
158 |
-
// Get the option value of Compress JavaScript
|
159 |
-
$strip = ( get_option('wpsmy_combine_js', 1) == 'on' ? true : false );
|
160 |
-
}
|
161 |
-
else if ( !empty($token['style']) ) {
|
162 |
-
// Get the option value of Compress CSS
|
163 |
-
$strip = ( get_option('wpsmy_combine_css', 1) == 'on' ? true : false );
|
164 |
-
}
|
165 |
-
else if ($content == '<!--wp-html-compression no compression-->') {
|
166 |
-
$overriding = !$overriding;
|
167 |
-
|
168 |
-
// Don't print the comment
|
169 |
-
continue;
|
170 |
-
}
|
171 |
-
else if ($this->remove_comments) {
|
172 |
-
if (!$overriding && $raw_tag != 'textarea') {
|
173 |
-
// Remove any HTML comments, except MSIE conditional comments
|
174 |
-
$content = preg_replace('/<!--(?!\s*(?:\[if [^\]]+]|<!|>))(?:(?!-->).)*-->/s', '', $content);
|
175 |
-
}
|
176 |
-
}
|
177 |
-
}
|
178 |
-
else {
|
179 |
-
if ($tag == 'pre' || $tag == 'textarea') {
|
180 |
-
$raw_tag = $tag;
|
181 |
-
}
|
182 |
-
else if ($tag == '/pre' || $tag == '/textarea') {
|
183 |
-
$raw_tag = false;
|
184 |
-
}
|
185 |
-
else {
|
186 |
-
if ($raw_tag || $overriding) {
|
187 |
-
$strip = false;
|
188 |
-
}
|
189 |
-
else {
|
190 |
-
$strip = true;
|
191 |
-
|
192 |
-
// Remove any empty attributes, except:
|
193 |
-
// action, alt, content, src
|
194 |
-
$content = preg_replace('/(\s+)(\w++(?<!\baction|\balt|\bcontent|\bsrc)="")/', '$1', $content);
|
195 |
-
|
196 |
-
// Remove any space before the end of self-closing XHTML tags
|
197 |
-
// JavaScript excluded
|
198 |
-
$content = str_replace(' />', '/>', $content);
|
199 |
-
}
|
200 |
-
}
|
201 |
-
}
|
202 |
-
|
203 |
-
if ($strip) {
|
204 |
-
$content = $this->removeWhiteSpace($content);
|
205 |
-
}
|
206 |
-
|
207 |
-
$html .= $content;
|
208 |
}
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
public function parseHTML($html)
|
214 |
-
{
|
215 |
-
$this->html = $this->minifyHTML($html);
|
216 |
-
|
217 |
-
if ($this->info_comment) {
|
218 |
-
$this->html .= "\n" . $this->bottomComment($html, $this->html);
|
219 |
}
|
220 |
-
}
|
221 |
|
222 |
-
|
223 |
-
|
224 |
-
$str = str_replace("\t", ' ', $str);
|
225 |
-
$str = str_replace("\n", '', $str);
|
226 |
-
$str = str_replace("\r", '', $str);
|
227 |
|
228 |
-
|
229 |
-
{
|
230 |
-
$str = str_replace(' ', ' ', $str);
|
231 |
-
}
|
232 |
|
233 |
-
|
234 |
-
|
235 |
-
}
|
236 |
|
237 |
-
|
238 |
-
|
239 |
-
return new wpsmy_html_compression($html);
|
240 |
}
|
241 |
|
242 |
-
|
243 |
-
{
|
244 |
-
|
245 |
}
|
246 |
-
|
247 |
-
add_action('get_header', 'wpsmy_html_compression_start');
|
248 |
?>
|
3 |
Plugin Name: WP Super Minify
|
4 |
Plugin URI: https://github.com/dipakcg/wp-super-minify
|
5 |
Description: This plugin combine and compress HTML, JavaScript and CSS files to improve page load speed.
|
6 |
+
Version: 1.1
|
7 |
Author: Dipak C. Gajjar
|
8 |
+
Author URI: http://dipakgajjar.com
|
|
|
9 |
*/
|
10 |
|
11 |
+
// Define plugin version for future releases
|
12 |
+
if (!defined('WPSMY_PLUGIN_VERSION')) {
|
13 |
+
define('WPSMY_PLUGIN_VERSION', 'wpsmy_plugin_version');
|
14 |
+
}
|
15 |
+
if (!defined('WPSMY_PLUGIN_VERSION_NUM')) {
|
16 |
+
define('WPSMY_PLUGIN_VERSION_NUM', '1.1');
|
17 |
+
}
|
18 |
+
update_option(WPSMY_PLUGIN_VERSION, WPSMY_PLUGIN_VERSION_NUM);
|
19 |
+
|
20 |
// Register with hook 'wp_enqueue_scripts', which can be used for front end CSS and JavaScript
|
21 |
add_action( 'admin_init', 'wpsmy_add_stylesheet' );
|
22 |
function wpsmy_add_stylesheet() {
|
29 |
add_action( 'admin_menu', 'wpsmy_add_admin_menu' );
|
30 |
function wpsmy_add_admin_menu() {
|
31 |
// add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function);
|
32 |
+
add_menu_page( 'WP Super Minify Settings', 'WP Super Minify', 'manage_options', 'wp-super-minify', 'wpsmy_admin_options', plugins_url('assets/images/wpsmy-icon-24x24.png', __FILE__) );
|
33 |
}
|
34 |
|
35 |
function wpsmy_admin_options() {
|
92 |
<span class="wpsmy_admin_dev_sidebar"> <?php echo '<img src="' . plugins_url( 'assets/images/wpsmy-other-plugins-16x16.png' , __FILE__ ) . '" > '; ?> <a href="http://profiles.wordpress.org/dipakcg#content-plugins" target="_blank"> Get my other plugins </a> </span>
|
93 |
<span class="wpsmy_admin_dev_sidebar"> <?php echo '<img src="' . plugins_url( 'assets/images/wpsmy-twitter-16x16.png' , __FILE__ ) . '" > '; ?>Follow me on Twitter: <a href="https://twitter.com/dipakcgajjar" target="_blank">@dipakcgajjar</a> </span>
|
94 |
<br />
|
95 |
+
<span class="wpsmy_admin_dev_sidebar" style="float: right;"> Version: <strong> <?php echo get_option('wpsmy_plugin_version'); ?> </strong> </span>
|
96 |
</div>
|
97 |
</td>
|
98 |
</tr>
|
101 |
<?php
|
102 |
}
|
103 |
|
104 |
+
// Make the default value of enable javascript and enable CSS to true on plugin activation
|
105 |
function wpsmy_activate_plugin() {
|
106 |
|
107 |
// Save default options value in the database
|
108 |
update_option( 'wpsmy_combine_js', 'on' );
|
109 |
update_option( 'wpsmy_combine_css', 'on' );
|
110 |
}
|
|
|
|
|
111 |
register_activation_hook( __FILE__, 'wpsmy_activate_plugin' );
|
112 |
|
113 |
+
// Remove filters/functions on plugin deactivation
|
114 |
+
function wpsmy_deactivate_plugin() {
|
115 |
+
delete_option( 'wpsmy_plugin_version' );
|
116 |
+
}
|
117 |
+
register_deactivation_hook( __FILE__, 'wpsmy_deactivate_plugin' );
|
118 |
+
|
119 |
+
function wpsmy_minify_html ($buffer) {
|
120 |
+
$wpsmy_plugin_version = get_option('wpsmy_plugin_version');
|
121 |
+
/* if ( is_user_logged_in() ) {
|
122 |
+
$buffer .= PHP_EOL . '<!--' . PHP_EOL . '*** This site runs WP Super Minify plugin v'. $wpsmy_plugin_version . ' - http://wordpress.org/plugins/wp-super-minify ***' . PHP_EOL . '*** User is logged in, compression is not applied. ***' . PHP_EOL . '-->';
|
123 |
+
return $buffer; // for loggedin users minify is not required
|
124 |
+
} else { */
|
125 |
+
$initial = strlen($buffer);
|
126 |
+
$minify_lib_path = plugin_dir_path( __FILE__ ) . 'includes/min';
|
127 |
+
|
128 |
+
if (!class_exists('Minify_HTML')) {
|
129 |
+
require_once("$minify_lib_path/lib/Minify/HTML.php");
|
130 |
+
ini_set('include_path', ini_get('include_path').":$minify_lib_path/lib");
|
131 |
+
require_once("$minify_lib_path/lib/Minify/CSS.php");
|
132 |
+
require_once("$minify_lib_path/lib/JSMin.php");
|
133 |
+
require ("$minify_lib_path/lib/Minify/Loader.php");
|
134 |
+
Minify_Loader::register();
|
135 |
}
|
136 |
+
if ( get_option('wpsmy_combine_js', 1) == 'on') {
|
137 |
+
$buffer = Minify_HTML::minify($buffer,
|
138 |
+
array('jsMinifier' => array('JSMin', 'minify')));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
}
|
140 |
+
if ( get_option('wpsmy_combine_css', 1) == 'on') {
|
141 |
+
$buffer = Minify_HTML::minify($buffer,
|
142 |
+
array('cssMinifier' => array('Minify_CSS', 'minify')));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
}
|
|
|
144 |
|
145 |
+
$final = strlen($buffer);
|
146 |
+
$savings = round((($initial-$final)/$initial*100), 3);
|
|
|
|
|
|
|
147 |
|
148 |
+
// $buffer .= "<br/><!-- Uncompressed size: $initial bytes; Compressed size: $final bytes; $savings% savings -->";
|
|
|
|
|
|
|
149 |
|
150 |
+
if ($savings != 0) {
|
151 |
+
$buffer .= PHP_EOL . '<!--' . PHP_EOL . '*** This site runs WP Super Minify plugin v'. $wpsmy_plugin_version .' - http://wordpress.org/plugins/wp-super-minify ***' . PHP_EOL . '*** Total size saved: ' . $savings . '% | Size before compression: ' . $initial . ' bytes | Size after compression: ' . $final . ' bytes. ***' . PHP_EOL . '-->';
|
152 |
+
}
|
153 |
|
154 |
+
return $buffer;
|
155 |
+
// }
|
|
|
156 |
}
|
157 |
|
158 |
+
// Minifying HTML
|
159 |
+
function wpsmy_minify() {
|
160 |
+
ob_start('wpsmy_minify_html');
|
161 |
}
|
162 |
+
add_action('get_header', 'wpsmy_minify');
|
|
|
163 |
?>
|