| @@ -29,9 +29,8 @@ | ||
| 29 | 29 | $url=urldecode($url); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | $siteHost=parse_url(AUTOPTIMIZE_WP_SITE_URL,PHP_URL_HOST); |
| 33 | - $contentHost=parse_url(AUTOPTIMIZE_WP_ROOT_URL,PHP_URL_HOST); | |
| 34 | 33 | |
| 35 | 34 | // normalize |
| 36 | 35 | if (strpos($url,'//')===0) { |
| 37 | 36 | if (is_ssl()) { |
| @@ -46,12 +45,8 @@ | ||
| 46 | 45 | $subdir_levels=substr_count(preg_replace("/https?:\/\//","",AUTOPTIMIZE_WP_SITE_URL),"/"); |
| 47 | 46 | $url = AUTOPTIMIZE_WP_SITE_URL.str_repeat("/..",$subdir_levels).$url; |
| 48 | 47 | } |
| 49 | 48 | } |
| 50 | - | |
| 51 | - if ($siteHost !== $contentHost) { | |
| 52 | - $url=str_replace(AUTOPTIMIZE_WP_CONTENT_URL,AUTOPTIMIZE_WP_SITE_URL.AUTOPTIMIZE_WP_CONTENT_NAME,$url); | |
| 53 | - } | |
| 54 | 49 | |
| 55 | 50 | // first check; hostname wp site should be hostname of url |
| 56 | 51 | $thisHost=@parse_url($url,PHP_URL_HOST); |
| 57 | 52 | if ($thisHost !== $siteHost) { |
| @@ -86,30 +81,19 @@ | ||
| 86 | 81 | } |
| 87 | 82 | |
| 88 | 83 | // try to remove "wp root url" from url while not minding http<>https |
| 89 | 84 | $tmp_ao_root = preg_replace('/https?:/','',AUTOPTIMIZE_WP_ROOT_URL); |
| 90 | - if ($siteHost !== $contentHost) { | |
| 91 | - // as we replaced the content-domain with the site-domain, we should match against that | |
| 92 | - $tmp_ao_root = preg_replace('/https?:/','',AUTOPTIMIZE_WP_SITE_URL); | |
| 93 | - } | |
| 94 | 85 | $tmp_url = preg_replace('/https?:/','',$url); |
| 95 | 86 | $path = str_replace($tmp_ao_root,'',$tmp_url); |
| 96 | 87 | |
| 97 | - // if path starts with :// or //, this is not a URL in the WP context and we have to assume we can't aggregate | |
| 88 | + // final check; if path starts with :// or //, this is not a URL in the WP context and we have to assume we can't aggregate | |
| 98 | 89 | if (preg_match('#^:?//#',$path)) { |
| 99 | 90 | /** External script/css (adsense, etc) */ |
| 100 | 91 | return false; |
| 101 | 92 | } |
| 102 | 93 | |
| 103 | - // prepend with WP_ROOT_DIR to have full path to file | |
| 104 | 94 | $path = str_replace('//','/',WP_ROOT_DIR.$path); |
| 105 | - | |
| 106 | - // final check: does file exist and is it readable | |
| 107 | - if (file_exists($path) && is_file($path) && is_readable($path)) { | |
| 108 | - return $path; | |
| 109 | - } else { | |
| 110 | - return false; | |
| 111 | - } | |
| 95 | + return $path; | |
| 112 | 96 | } |
| 113 | 97 | |
| 114 | 98 | // needed for WPML-filter |
| 115 | 99 | protected function ao_getDomain($in) { |
| @@ -298,14 +282,14 @@ | ||
| 298 | 282 | // inject already minified code in optimized JS/CSS |
| 299 | 283 | protected function inject_minified($in) { |
| 300 | 284 | if ( strpos( $in, '%%INJECTLATER%%' ) !== false ) { |
| 301 | 285 | $out = preg_replace_callback( |
| 302 | - '#\/\*\!%%INJECTLATER'.AUTOPTIMIZE_HASH.'%%(.*?)%%INJECTLATER%%\*\/#is', | |
| 286 | + '#%%INJECTLATER'.AUTOPTIMIZE_HASH.'%%(.*?)%%INJECTLATER%%#is', | |
| 303 | 287 | create_function( |
| 304 | 288 | '$matches', |
| 305 | 289 | '$filepath=base64_decode(strtok($matches[1],"|")); |
| 306 | 290 | $filecontent=file_get_contents($filepath); |
| 307 | - | |
| 291 | + | |
| 308 | 292 | // remove BOM |
| 309 | 293 | $filecontent = preg_replace("#\x{EF}\x{BB}\x{BF}#","",$filecontent); |
| 310 | 294 | |
| 311 | 295 | // remove comments and blank lines |
| @@ -315,9 +299,9 @@ | ||
| 315 | 299 | |
| 316 | 300 | $filecontent=preg_replace("#^\s*\/\*[^!].*\*\/\s?#Um","",$filecontent); |
| 317 | 301 | $filecontent=preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $filecontent); |
| 318 | 302 | |
| 319 | - // differentiate between JS, CSS and other files | |
| 303 | + // specific stuff for JS-files | |
| 320 | 304 | if (substr($filepath,-3,3)===".js") { |
| 321 | 305 | if ((substr($filecontent,-1,1)!==";")&&(substr($filecontent,-1,1)!=="}")) { |
| 322 | 306 | $filecontent.=";"; |
| 323 | 307 | } |
| @@ -340,79 +324,5 @@ | ||
| 340 | 324 | $out = $in; |
| 341 | 325 | } |
| 342 | 326 | return $out; |
| 343 | 327 | } |
| 344 | - | |
| 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 | - } | |
| 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 | - } | |
| 361 | - | |
| 362 | - // read file, return false if empty | |
| 363 | - $_toMinify = file_get_contents($pathIn); | |
| 364 | - if ( empty($_toMinify) ) return false; | |
| 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") { | |
| 381 | - if (class_exists('Minify_CSS_Compressor')) { | |
| 382 | - $tmp_code = trim(Minify_CSS_Compressor::process($_toMinify)); | |
| 383 | - } else if(class_exists('CSSmin')) { | |
| 384 | - $cssmin = new CSSmin(); | |
| 385 | - if (method_exists($cssmin,"run")) { | |
| 386 | - $tmp_code = trim($cssmin->run($_toMinify)); | |
| 387 | - } elseif (@is_callable(array($cssmin,"minify"))) { | |
| 388 | - $tmp_code = trim(CssMin::minify($_toMinify)); | |
| 389 | - } | |
| 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); | |
| 401 | - | |
| 402 | - // if CDN, then CDN | |
| 403 | - $_CachedMinifiedUrl = $this->url_replace_cdn($_CachedMinifiedUrl); | |
| 404 | - | |
| 405 | - return $_CachedMinifiedUrl; | |
| 406 | - } | |
| 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 | - } | |
| 418 | 328 | } |