PluginProbe
Autoptimize / 2.1.2
Autoptimize v2.1.2
2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 All 107 releases
← All changes | classes/autoptimizeBase.php +5 -97 2.3.42.1.2 View file →
@@ -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,81 +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 - // make sure paths to background images/ imported css/ fonts .. are OK
382 - $_toMinify = autoptimizeStyles::fixurls($pathIn,$_toMinify);
383 - if (class_exists('Minify_CSS_Compressor')) {
384 - $tmp_code = trim(Minify_CSS_Compressor::process($_toMinify));
385 - } else if(class_exists('CSSmin')) {
386 - $cssmin = new CSSmin();
387 - if (method_exists($cssmin,"run")) {
388 - $tmp_code = trim($cssmin->run($_toMinify));
389 - } elseif (@is_callable(array($cssmin,"minify"))) {
390 - $tmp_code = trim(CssMin::minify($_toMinify));
391 - }
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);
403 -
404 - // if CDN, then CDN
405 - $_CachedMinifiedUrl = $this->url_replace_cdn($_CachedMinifiedUrl);
406 -
407 - return $_CachedMinifiedUrl;
408 - }
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 - }
420 328 }