@@ -343,45 +343,45 @@ 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 | // make sure paths to background images/ imported css/ fonts .. are OK |
382 | 382 | $_toMinify = $this->fixurls($pathIn,$_toMinify); |
383 | 383 | if (class_exists('Minify_CSS_Compressor')) { |
384 | - $tmp_code = trim(Minify_CSS_Compressor::process($_toMinify)); |
|
384 | + $tmp_code = trim(Minify_CSS_Compressor::process($_toMinify)); |
|
385 | 385 | } else if(class_exists('CSSmin')) { |
386 | 386 | $cssmin = new CSSmin(); |
387 | 387 | if (method_exists($cssmin,"run")) { |
@@ -390,31 +390,31 @@ discard block |
||
390 | 390 | $tmp_code = trim(CssMin::minify($_toMinify)); |
391 | 391 | } |
392 | 392 | } |
393 | - } |
|
394 | - if (!empty($tmp_code)) { |
|
395 | - $_Minified = $tmp_code; |
|
396 | - unset($tmp_code); |
|
397 | - } |
|
398 | - // and then cache |
|
399 | - $_cache->cache($_Minified,$codeMime); |
|
400 | - $_CachedMinifiedUrl = AUTOPTIMIZE_CACHE_URL.$_cache->getname(); |
|
401 | - } |
|
402 | - unset($_cache); |
|
393 | + } |
|
394 | + if (!empty($tmp_code)) { |
|
395 | + $_Minified = $tmp_code; |
|
396 | + unset($tmp_code); |
|
397 | + } |
|
398 | + // and then cache |
|
399 | + $_cache->cache($_Minified,$codeMime); |
|
400 | + $_CachedMinifiedUrl = AUTOPTIMIZE_CACHE_URL.$_cache->getname(); |
|
401 | + } |
|
402 | + unset($_cache); |
|
403 | 403 | |
404 | - // if CDN, then CDN |
|
405 | - $_CachedMinifiedUrl = $this->url_replace_cdn($_CachedMinifiedUrl); |
|
404 | + // if CDN, then CDN |
|
405 | + $_CachedMinifiedUrl = $this->url_replace_cdn($_CachedMinifiedUrl); |
|
406 | 406 | |
407 | - return $_CachedMinifiedUrl; |
|
408 | - } |
|
407 | + return $_CachedMinifiedUrl; |
|
408 | + } |
|
409 | 409 | |
410 | - protected function str_ends_in($haystack,$needle) { |
|
411 | - $needleLength = strlen($needle); |
|
412 | - $haystackLength = strlen($haystack); |
|
413 | - $lastPos=strrpos($haystack,$needle); |
|
414 | - if ($lastPos === $haystackLength - $needleLength) { |
|
415 | - return true; |
|
416 | - } else { |
|
417 | - return false; |
|
418 | - } |
|
419 | - } |
|
410 | + protected function str_ends_in($haystack,$needle) { |
|
411 | + $needleLength = strlen($needle); |
|
412 | + $haystackLength = strlen($haystack); |
|
413 | + $lastPos=strrpos($haystack,$needle); |
|
414 | + if ($lastPos === $haystackLength - $needleLength) { |
|
415 | + return true; |
|
416 | + } else { |
|
417 | + return false; |
|
418 | + } |
|
419 | + } |
|
420 | 420 | } |