@@ -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. |