@@ -341,43 +341,43 @@ discard block |
||
341 | 341 | } |
342 | 342 | |
343 | 343 | protected function minify_single($pathIn) { |
344 | - // determine JS or CSS and set var (also mimetype), return false if neither |
|
345 | - if ( $this->str_ends_in($pathIn,".js") === true ) { |
|
346 | - $codeType="js"; |
|
347 | - $codeMime="text/javascript"; |
|
348 | - } else if ( $this->str_ends_in($pathIn,".css") === true ) { |
|
349 | - $codeType="css"; |
|
350 | - $codeMime="text/css"; |
|
351 | - } else { |
|
352 | - return false; |
|
353 | - } |
|
344 | + // determine JS or CSS and set var (also mimetype), return false if neither |
|
345 | + if ( $this->str_ends_in($pathIn,".js") === true ) { |
|
346 | + $codeType="js"; |
|
347 | + $codeMime="text/javascript"; |
|
348 | + } else if ( $this->str_ends_in($pathIn,".css") === true ) { |
|
349 | + $codeType="css"; |
|
350 | + $codeMime="text/css"; |
|
351 | + } else { |
|
352 | + return false; |
|
353 | + } |
|
354 | 354 | |
355 | - // if min.js or min.css return false |
|
356 | - 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 ) ) { |
|
357 | - return false; |
|
358 | - } |
|
355 | + // if min.js or min.css return false |
|
356 | + 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 ) ) { |
|
357 | + return false; |
|
358 | + } |
|
359 | 359 | |
360 | - // read file, return false if empty |
|
361 | - $_toMinify = file_get_contents($pathIn); |
|
362 | - if ( empty($_toMinify) ) return false; |
|
360 | + // read file, return false if empty |
|
361 | + $_toMinify = file_get_contents($pathIn); |
|
362 | + if ( empty($_toMinify) ) return false; |
|
363 | 363 | |
364 | - // check cache |
|
365 | - $_md5hash = "single_".md5($_toMinify); |
|
366 | - $_cache = new autoptimizeCache($_md5hash,$codeType); |
|
367 | - if ($_cache->check() ) { |
|
368 | - $_CachedMinifiedUrl = AUTOPTIMIZE_CACHE_URL.$_cache->getname(); |
|
369 | - } else { |
|
370 | - // if not in cache first minify |
|
371 | - $_Minified = $_toMinify; |
|
372 | - if ($codeType === "js") { |
|
373 | - if (class_exists('JSMin') && apply_filters( 'autoptimize_js_do_minify' , true)) { |
|
374 | - if (@is_callable(array("JSMin","minify"))) { |
|
375 | - $tmp_code = trim(JSMin::minify($_toMinify)); |
|
376 | - } |
|
377 | - } |
|
378 | - } else if ($codeType === "css") { |
|
364 | + // check cache |
|
365 | + $_md5hash = "single_".md5($_toMinify); |
|
366 | + $_cache = new autoptimizeCache($_md5hash,$codeType); |
|
367 | + if ($_cache->check() ) { |
|
368 | + $_CachedMinifiedUrl = AUTOPTIMIZE_CACHE_URL.$_cache->getname(); |
|
369 | + } else { |
|
370 | + // if not in cache first minify |
|
371 | + $_Minified = $_toMinify; |
|
372 | + if ($codeType === "js") { |
|
373 | + if (class_exists('JSMin') && apply_filters( 'autoptimize_js_do_minify' , true)) { |
|
374 | + if (@is_callable(array("JSMin","minify"))) { |
|
375 | + $tmp_code = trim(JSMin::minify($_toMinify)); |
|
376 | + } |
|
377 | + } |
|
378 | + } else if ($codeType === "css") { |
|
379 | 379 | if (class_exists('Minify_CSS_Compressor')) { |
380 | - $tmp_code = trim(Minify_CSS_Compressor::process($_toMinify)); |
|
380 | + $tmp_code = trim(Minify_CSS_Compressor::process($_toMinify)); |
|
381 | 381 | } else if(class_exists('CSSmin')) { |
382 | 382 | $cssmin = new CSSmin(); |
383 | 383 | if (method_exists($cssmin,"run")) { |
@@ -386,31 +386,31 @@ discard block |
||
386 | 386 | $tmp_code = trim(CssMin::minify($_toMinify)); |
387 | 387 | } |
388 | 388 | } |
389 | - } |
|
390 | - if (!empty($tmp_code)) { |
|
391 | - $_Minified = $tmp_code; |
|
392 | - unset($tmp_code); |
|
393 | - } |
|
394 | - // and then cache |
|
395 | - $_cache->cache($_Minified,$codeMime); |
|
396 | - $_CachedMinifiedUrl = AUTOPTIMIZE_CACHE_URL.$_cache->getname(); |
|
397 | - } |
|
398 | - unset($_cache); |
|
389 | + } |
|
390 | + if (!empty($tmp_code)) { |
|
391 | + $_Minified = $tmp_code; |
|
392 | + unset($tmp_code); |
|
393 | + } |
|
394 | + // and then cache |
|
395 | + $_cache->cache($_Minified,$codeMime); |
|
396 | + $_CachedMinifiedUrl = AUTOPTIMIZE_CACHE_URL.$_cache->getname(); |
|
397 | + } |
|
398 | + unset($_cache); |
|
399 | 399 | |
400 | - // if CDN, then CDN |
|
401 | - $_CachedMinifiedUrl = $this->url_replace_cdn($_CachedMinifiedUrl); |
|
400 | + // if CDN, then CDN |
|
401 | + $_CachedMinifiedUrl = $this->url_replace_cdn($_CachedMinifiedUrl); |
|
402 | 402 | |
403 | - return $_CachedMinifiedUrl; |
|
404 | - } |
|
403 | + return $_CachedMinifiedUrl; |
|
404 | + } |
|
405 | 405 | |
406 | - protected function str_ends_in($haystack,$needle) { |
|
407 | - $needleLength = strlen($needle); |
|
408 | - $haystackLength = strlen($haystack); |
|
409 | - $lastPos=strrpos($haystack,$needle); |
|
410 | - if ($lastPos === $haystackLength - $needleLength) { |
|
411 | - return true; |
|
412 | - } else { |
|
413 | - return false; |
|
414 | - } |
|
415 | - } |
|
406 | + protected function str_ends_in($haystack,$needle) { |
|
407 | + $needleLength = strlen($needle); |
|
408 | + $haystackLength = strlen($haystack); |
|
409 | + $lastPos=strrpos($haystack,$needle); |
|
410 | + if ($lastPos === $haystackLength - $needleLength) { |
|
411 | + return true; |
|
412 | + } else { |
|
413 | + return false; |
|
414 | + } |
|
415 | + } |
|
416 | 416 | } |