@@ -2,9 +2,9 @@ discard block |
||
2 | 2 | |
3 | 3 | //Check everything exists before using it |
4 | 4 | if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) |
5 | - $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; |
|
5 | + $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; |
|
6 | 6 | if(!isset($_SERVER['HTTP_USER_AGENT'])) |
7 | - $_SERVER['HTTP_USER_AGENT'] = ''; |
|
7 | + $_SERVER['HTTP_USER_AGENT'] = ''; |
|
8 | 8 | |
9 | 9 | // Determine supported compression method |
10 | 10 | $gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'); |
@@ -15,20 +15,20 @@ discard block |
||
15 | 15 | |
16 | 16 | // Check for buggy versions of Internet Explorer |
17 | 17 | if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Opera') && |
18 | - preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) |
|
18 | + preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) |
|
19 | 19 | { |
20 | - $version = floatval($matches[1]); |
|
20 | + $version = floatval($matches[1]); |
|
21 | 21 | |
22 | - if ($version < 6) |
|
23 | - $encoding = 'none'; |
|
22 | + if ($version < 6) |
|
23 | + $encoding = 'none'; |
|
24 | 24 | |
25 | - if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) |
|
26 | - $encoding = 'none'; |
|
25 | + if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) |
|
26 | + $encoding = 'none'; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | //Some servers compress the output of PHP - Don't break in those cases |
30 | 30 | if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) |
31 | - $encoding = 'none'; |
|
31 | + $encoding = 'none'; |
|
32 | 32 | |
33 | 33 | //Get data |
34 | 34 | $contents = file_get_contents(__FILE__.'.'.$encoding); |
@@ -41,24 +41,24 @@ discard block |
||
41 | 41 | $modTimeMatch = (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) === $modTime); |
42 | 42 | |
43 | 43 | if (($modTimeMatch)||($eTagMatch)) { |
44 | - header('HTTP/1.1 304 Not Modified'); |
|
45 | - header('Connection: close'); |
|
44 | + header('HTTP/1.1 304 Not Modified'); |
|
45 | + header('Connection: close'); |
|
46 | 46 | } else { |
47 | - // send all sorts of headers |
|
48 | - $expireTime=60*60*24*356; // 1y max according to RFC |
|
47 | + // send all sorts of headers |
|
48 | + $expireTime=60*60*24*356; // 1y max according to RFC |
|
49 | 49 | |
50 | - if(isset($encoding) && $encoding != 'none') |
|
51 | - { |
|
52 | - header('Content-Encoding: '.$encoding); |
|
53 | - } |
|
54 | - header('Vary: Accept-Encoding'); |
|
55 | - header('Content-Length: '.strlen($contents)); |
|
56 | - header('Content-type: %%CONTENT%%; charset=utf-8'); |
|
57 | - header('Cache-Control: max-age='.$expireTime.', public, immutable'); |
|
58 | - header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT'); //10 years |
|
59 | - header('ETag: ' . $eTag); |
|
60 | - header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT'); |
|
50 | + if(isset($encoding) && $encoding != 'none') |
|
51 | + { |
|
52 | + header('Content-Encoding: '.$encoding); |
|
53 | + } |
|
54 | + header('Vary: Accept-Encoding'); |
|
55 | + header('Content-Length: '.strlen($contents)); |
|
56 | + header('Content-type: %%CONTENT%%; charset=utf-8'); |
|
57 | + header('Cache-Control: max-age='.$expireTime.', public, immutable'); |
|
58 | + header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT'); //10 years |
|
59 | + header('ETag: ' . $eTag); |
|
60 | + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT'); |
|
61 | 61 | |
62 | - // send output |
|
63 | - echo $contents; |
|
62 | + // send output |
|
63 | + echo $contents; |
|
64 | 64 | } |
@@ -2,9 +2,9 @@ discard block |
||
2 | 2 | |
3 | 3 | //Check everything exists before using it |
4 | 4 | if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) |
5 | - $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; |
|
5 | + $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; |
|
6 | 6 | if(!isset($_SERVER['HTTP_USER_AGENT'])) |
7 | - $_SERVER['HTTP_USER_AGENT'] = ''; |
|
7 | + $_SERVER['HTTP_USER_AGENT'] = ''; |
|
8 | 8 | |
9 | 9 | // Determine supported compression method |
10 | 10 | $gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'); |
@@ -15,30 +15,30 @@ discard block |
||
15 | 15 | |
16 | 16 | // Check for buggy versions of Internet Explorer |
17 | 17 | if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Opera') && |
18 | - preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) |
|
18 | + preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) |
|
19 | 19 | { |
20 | - $version = floatval($matches[1]); |
|
20 | + $version = floatval($matches[1]); |
|
21 | 21 | |
22 | - if ($version < 6) |
|
23 | - $encoding = 'none'; |
|
22 | + if ($version < 6) |
|
23 | + $encoding = 'none'; |
|
24 | 24 | |
25 | - if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) |
|
26 | - $encoding = 'none'; |
|
25 | + if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) |
|
26 | + $encoding = 'none'; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | //Some servers compress the output of PHP - Don't break in those cases |
30 | 30 | if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) |
31 | - $encoding = 'none'; |
|
31 | + $encoding = 'none'; |
|
32 | 32 | |
33 | 33 | $iscompressed = file_exists(__FILE__.'.'.$encoding); |
34 | 34 | if($encoding != 'none' && $iscompressed == false) |
35 | 35 | { |
36 | - $flag = ($encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE); |
|
37 | - $code = file_get_contents(__FILE__.'.none'); |
|
38 | - $contents = gzencode($code,9,$flag); |
|
36 | + $flag = ($encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE); |
|
37 | + $code = file_get_contents(__FILE__.'.none'); |
|
38 | + $contents = gzencode($code,9,$flag); |
|
39 | 39 | }else{ |
40 | - //Get data |
|
41 | - $contents = file_get_contents(__FILE__.'.'.$encoding); |
|
40 | + //Get data |
|
41 | + $contents = file_get_contents(__FILE__.'.'.$encoding); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | // first check if we have to send 304 |
@@ -51,35 +51,35 @@ discard block |
||
51 | 51 | $modTimeMatch = (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) === $modTime); |
52 | 52 | |
53 | 53 | if (($modTimeMatch)||($eTagMatch)) { |
54 | - header('HTTP/1.1 304 Not Modified'); |
|
55 | - header('Connection: close'); |
|
54 | + header('HTTP/1.1 304 Not Modified'); |
|
55 | + header('Connection: close'); |
|
56 | 56 | } else { |
57 | - // send all sorts of headers |
|
58 | - $expireTime=60*60*24*355; // 1y max according to RFC |
|
59 | - if ($encoding != 'none') { |
|
60 | - header('Content-Encoding: '.$encoding); |
|
61 | - } |
|
62 | - header('Vary: Accept-Encoding'); |
|
63 | - header('Content-Length: '.strlen($contents)); |
|
64 | - header('Content-type: %%CONTENT%%; charset=utf-8'); |
|
65 | - header('Cache-Control: max-age='.$expireTime.', public, immutable'); |
|
66 | - header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT'); |
|
67 | - header('ETag: ' . $eTag); |
|
68 | - header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT'); |
|
57 | + // send all sorts of headers |
|
58 | + $expireTime=60*60*24*355; // 1y max according to RFC |
|
59 | + if ($encoding != 'none') { |
|
60 | + header('Content-Encoding: '.$encoding); |
|
61 | + } |
|
62 | + header('Vary: Accept-Encoding'); |
|
63 | + header('Content-Length: '.strlen($contents)); |
|
64 | + header('Content-type: %%CONTENT%%; charset=utf-8'); |
|
65 | + header('Cache-Control: max-age='.$expireTime.', public, immutable'); |
|
66 | + header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT'); |
|
67 | + header('ETag: ' . $eTag); |
|
68 | + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT'); |
|
69 | 69 | |
70 | - // send output |
|
71 | - echo $contents; |
|
70 | + // send output |
|
71 | + echo $contents; |
|
72 | 72 | |
73 | - //And write to filesystem cache if not done yet |
|
74 | - if($encoding != 'none' && $iscompressed == false) |
|
75 | - { |
|
76 | - //Write the content we sent |
|
77 | - file_put_contents(__FILE__.'.'.$encoding,$contents); |
|
73 | + //And write to filesystem cache if not done yet |
|
74 | + if($encoding != 'none' && $iscompressed == false) |
|
75 | + { |
|
76 | + //Write the content we sent |
|
77 | + file_put_contents(__FILE__.'.'.$encoding,$contents); |
|
78 | 78 | |
79 | - //And write the new content |
|
80 | - $flag = ($encoding == 'gzip' ? FORCE_DEFLATE : FORCE_GZIP); |
|
81 | - $ext = ($encoding == 'gzip' ? 'deflate' : 'gzip'); |
|
82 | - $contents = gzencode($code,9,$flag); |
|
83 | - file_put_contents(__FILE__.'.'.$ext,$contents); |
|
84 | - } |
|
79 | + //And write the new content |
|
80 | + $flag = ($encoding == 'gzip' ? FORCE_DEFLATE : FORCE_GZIP); |
|
81 | + $ext = ($encoding == 'gzip' ? 'deflate' : 'gzip'); |
|
82 | + $contents = gzencode($code,9,$flag); |
|
83 | + file_put_contents(__FILE__.'.'.$ext,$contents); |
|
84 | + } |
|
85 | 85 | } |
@@ -179,32 +179,32 @@ discard block |
||
179 | 179 | // Remove the original style tag |
180 | 180 | $this->content = str_replace($tag,'',$this->content); |
181 | 181 | } else { |
182 | - // excluded CSS, minify if getpath |
|
183 | - if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi',$tag,$source)) { |
|
184 | - $explUrl = explode('?',$source[2],2); |
|
182 | + // excluded CSS, minify if getpath |
|
183 | + if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi',$tag,$source)) { |
|
184 | + $explUrl = explode('?',$source[2],2); |
|
185 | 185 | $url = $explUrl[0]; |
186 | 186 | $path = $this->getpath($url); |
187 | 187 | |
188 | - if ($path && apply_filters('autoptimize_filter_css_minify_excluded',false)) { |
|
189 | - $_CachedMinifiedUrl = $this->minify_single($path); |
|
190 | - |
|
191 | - if (!empty($_CachedMinifiedUrl)) { |
|
192 | - // replace orig URL with URL to cache |
|
193 | - $newTag = str_replace($url, $_CachedMinifiedUrl, $tag); |
|
194 | - } else { |
|
195 | - $newTag = $tag; |
|
196 | - } |
|
188 | + if ($path && apply_filters('autoptimize_filter_css_minify_excluded',false)) { |
|
189 | + $_CachedMinifiedUrl = $this->minify_single($path); |
|
190 | + |
|
191 | + if (!empty($_CachedMinifiedUrl)) { |
|
192 | + // replace orig URL with URL to cache |
|
193 | + $newTag = str_replace($url, $_CachedMinifiedUrl, $tag); |
|
194 | + } else { |
|
195 | + $newTag = $tag; |
|
196 | + } |
|
197 | 197 | |
198 | - // remove querystring from URL |
|
199 | - if ( !empty($explUrl[1]) ) { |
|
200 | - $newTag = str_replace("?".$explUrl[1],"",$newTag); |
|
201 | - } |
|
202 | - |
|
203 | - // and replace |
|
204 | - $this->content = str_replace($tag,$newTag,$this->content); |
|
205 | - } |
|
206 | - } |
|
207 | - } |
|
198 | + // remove querystring from URL |
|
199 | + if ( !empty($explUrl[1]) ) { |
|
200 | + $newTag = str_replace("?".$explUrl[1],"",$newTag); |
|
201 | + } |
|
202 | + |
|
203 | + // and replace |
|
204 | + $this->content = str_replace($tag,$newTag,$this->content); |
|
205 | + } |
|
206 | + } |
|
207 | + } |
|
208 | 208 | } |
209 | 209 | return true; |
210 | 210 | } |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | // just cdn the URL if applicable |
427 | 427 | if (!empty($this->cdn_url)) { |
428 | 428 | $imgreplace[$matches[0][$count]] = str_replace($quotedurl,$this->url_replace_cdn($quotedurl),$matches[0][$count]); |
429 | - } |
|
429 | + } |
|
430 | 430 | } |
431 | 431 | } |
432 | 432 | } else if ((is_array($matches)) && (!empty($this->cdn_url))) { |
@@ -647,8 +647,8 @@ discard block |
||
647 | 647 | } |
648 | 648 | |
649 | 649 | private function ismovable($tag) { |
650 | - if ( apply_filters('autoptimize_filter_css_dontaggregate', false) ) { |
|
651 | - return false; |
|
650 | + if ( apply_filters('autoptimize_filter_css_dontaggregate', false) ) { |
|
651 | + return false; |
|
652 | 652 | } else if (!empty($this->whitelist)) { |
653 | 653 | foreach ($this->whitelist as $match) { |
654 | 654 | if(strpos($tag,$match)!==false) { |
@@ -673,13 +673,13 @@ discard block |
||
673 | 673 | } |
674 | 674 | |
675 | 675 | private function can_inject_late($cssPath,$css) { |
676 | - $consider_minified_array = apply_filters('autoptimize_filter_css_consider_minified', false, $cssPath); |
|
676 | + $consider_minified_array = apply_filters('autoptimize_filter_css_consider_minified', false, $cssPath); |
|
677 | 677 | if ( $this->inject_min_late !== true ) { |
678 | 678 | // late-inject turned off |
679 | 679 | return false; |
680 | 680 | } else if ( (strpos($cssPath,"min.css") === false) && ( str_replace($consider_minified_array, '', $cssPath) === $cssPath ) ) { |
681 | - // file not minified based on filename & filter |
|
682 | - return false; |
|
681 | + // file not minified based on filename & filter |
|
682 | + return false; |
|
683 | 683 | } else if ( strpos($css,"@import") !== false ) { |
684 | 684 | // can't late-inject files with imports as those need to be aggregated |
685 | 685 | return false; |
@@ -343,43 +343,43 @@ discard block |
||
343 | 343 | } |
344 | 344 | |
345 | 345 | protected function minify_single($pathIn) { |
346 | - // determine JS or CSS and set var (also mimetype), return false if neither |
|
347 | - if ( $this->str_ends_in($pathIn,".js") === true ) { |
|
348 | - $codeType="js"; |
|
349 | - $codeMime="text/javascript"; |
|
350 | - } else if ( $this->str_ends_in($pathIn,".css") === true ) { |
|
351 | - $codeType="css"; |
|
352 | - $codeMime="text/css"; |
|
353 | - } else { |
|
354 | - return false; |
|
355 | - } |
|
346 | + // determine JS or CSS and set var (also mimetype), return false if neither |
|
347 | + if ( $this->str_ends_in($pathIn,".js") === true ) { |
|
348 | + $codeType="js"; |
|
349 | + $codeMime="text/javascript"; |
|
350 | + } else if ( $this->str_ends_in($pathIn,".css") === true ) { |
|
351 | + $codeType="css"; |
|
352 | + $codeMime="text/css"; |
|
353 | + } else { |
|
354 | + return false; |
|
355 | + } |
|
356 | 356 | |
357 | - // if min.js or min.css return false |
|
358 | - if (( $this->str_ends_in($pathIn,"-min.".$codeType) === true ) || ( $this->str_ends_in($pathIn,".min.".$codeType) === true ) || ( $this->str_ends_in($pathIn,"js/jquery/jquery.js") === true ) ) { |
|
359 | - return false; |
|
360 | - } |
|
357 | + // if min.js or min.css return false |
|
358 | + if (( $this->str_ends_in($pathIn,"-min.".$codeType) === true ) || ( $this->str_ends_in($pathIn,".min.".$codeType) === true ) || ( $this->str_ends_in($pathIn,"js/jquery/jquery.js") === true ) ) { |
|
359 | + return false; |
|
360 | + } |
|
361 | 361 | |
362 | - // read file, return false if empty |
|
363 | - $_toMinify = file_get_contents($pathIn); |
|
364 | - if ( empty($_toMinify) ) return false; |
|
362 | + // read file, return false if empty |
|
363 | + $_toMinify = file_get_contents($pathIn); |
|
364 | + if ( empty($_toMinify) ) return false; |
|
365 | 365 | |
366 | - // check cache |
|
367 | - $_md5hash = "single_".md5($_toMinify); |
|
368 | - $_cache = new autoptimizeCache($_md5hash,$codeType); |
|
369 | - if ($_cache->check() ) { |
|
370 | - $_CachedMinifiedUrl = AUTOPTIMIZE_CACHE_URL.$_cache->getname(); |
|
371 | - } else { |
|
372 | - // if not in cache first minify |
|
373 | - $_Minified = $_toMinify; |
|
374 | - if ($codeType === "js") { |
|
375 | - if (class_exists('JSMin') && apply_filters( 'autoptimize_js_do_minify' , true)) { |
|
376 | - if (@is_callable(array("JSMin","minify"))) { |
|
377 | - $tmp_code = trim(JSMin::minify($_toMinify)); |
|
378 | - } |
|
379 | - } |
|
380 | - } else if ($codeType === "css") { |
|
366 | + // check cache |
|
367 | + $_md5hash = "single_".md5($_toMinify); |
|
368 | + $_cache = new autoptimizeCache($_md5hash,$codeType); |
|
369 | + if ($_cache->check() ) { |
|
370 | + $_CachedMinifiedUrl = AUTOPTIMIZE_CACHE_URL.$_cache->getname(); |
|
371 | + } else { |
|
372 | + // if not in cache first minify |
|
373 | + $_Minified = $_toMinify; |
|
374 | + if ($codeType === "js") { |
|
375 | + if (class_exists('JSMin') && apply_filters( 'autoptimize_js_do_minify' , true)) { |
|
376 | + if (@is_callable(array("JSMin","minify"))) { |
|
377 | + $tmp_code = trim(JSMin::minify($_toMinify)); |
|
378 | + } |
|
379 | + } |
|
380 | + } else if ($codeType === "css") { |
|
381 | 381 | if (class_exists('Minify_CSS_Compressor')) { |
382 | - $tmp_code = trim(Minify_CSS_Compressor::process($_toMinify)); |
|
382 | + $tmp_code = trim(Minify_CSS_Compressor::process($_toMinify)); |
|
383 | 383 | } else if(class_exists('CSSmin')) { |
384 | 384 | $cssmin = new CSSmin(); |
385 | 385 | if (method_exists($cssmin,"run")) { |
@@ -388,33 +388,33 @@ discard block |
||
388 | 388 | $tmp_code = trim(CssMin::minify($_toMinify)); |
389 | 389 | } |
390 | 390 | } |
391 | - } |
|
392 | - if (!empty($tmp_code)) { |
|
393 | - $_Minified = $tmp_code; |
|
394 | - unset($tmp_code); |
|
395 | - } |
|
396 | - // and then cache |
|
397 | - $_cache->cache($_Minified,$codeMime); |
|
398 | - $_CachedMinifiedUrl = AUTOPTIMIZE_CACHE_URL.$_cache->getname(); |
|
399 | - } |
|
400 | - unset($_cache); |
|
391 | + } |
|
392 | + if (!empty($tmp_code)) { |
|
393 | + $_Minified = $tmp_code; |
|
394 | + unset($tmp_code); |
|
395 | + } |
|
396 | + // and then cache |
|
397 | + $_cache->cache($_Minified,$codeMime); |
|
398 | + $_CachedMinifiedUrl = AUTOPTIMIZE_CACHE_URL.$_cache->getname(); |
|
399 | + } |
|
400 | + unset($_cache); |
|
401 | 401 | |
402 | - // if CDN, then CDN |
|
403 | - $_CachedMinifiedUrl = $this->url_replace_cdn($_CachedMinifiedUrl); |
|
402 | + // if CDN, then CDN |
|
403 | + $_CachedMinifiedUrl = $this->url_replace_cdn($_CachedMinifiedUrl); |
|
404 | 404 | |
405 | - return $_CachedMinifiedUrl; |
|
406 | - } |
|
405 | + return $_CachedMinifiedUrl; |
|
406 | + } |
|
407 | 407 | |
408 | - protected function str_ends_in($haystack,$needle) { |
|
409 | - $needleLength = strlen($needle); |
|
410 | - $haystackLength = strlen($haystack); |
|
411 | - $lastPos=strrpos($haystack,$needle); |
|
412 | - if ($lastPos === $haystackLength - $needleLength) { |
|
413 | - return true; |
|
414 | - } else { |
|
415 | - return false; |
|
416 | - } |
|
417 | - } |
|
408 | + protected function str_ends_in($haystack,$needle) { |
|
409 | + $needleLength = strlen($needle); |
|
410 | + $haystackLength = strlen($haystack); |
|
411 | + $lastPos=strrpos($haystack,$needle); |
|
412 | + if ($lastPos === $haystackLength - $needleLength) { |
|
413 | + return true; |
|
414 | + } else { |
|
415 | + return false; |
|
416 | + } |
|
417 | + } |
|
418 | 418 | |
419 | 419 | /** |
420 | 420 | * Specialized method to create the INJECTLATER marker. |