Completed
Push — master ( ae592b...8d63b6 )
by frank
03:07
created
classes/autoptimizeScripts.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -128,27 +128,27 @@  discard block
 block discarded – undo
128 128
                             // should we add flags?
129 129
                             foreach ($excludeJS as $exclTag => $exclFlags) {
130 130
                                 if ( strpos($origTag,$exclTag)!==false && in_array($exclFlags,array("async","defer")) ) {
131
-                                   $newTag = str_replace('<script ','<script '.$exclFlags.' ',$newTag);
131
+                                    $newTag = str_replace('<script ','<script '.$exclFlags.' ',$newTag);
132 132
                                 }
133 133
                             }
134 134
                         }
135 135
                         
136
-   						// should we minify the non-aggregated script?
137
-						if ($path && apply_filters('autoptimize_filter_js_minify_excluded',false)) {
138
-							$_CachedMinifiedUrl = $this->minify_single($path);
136
+                            // should we minify the non-aggregated script?
137
+                        if ($path && apply_filters('autoptimize_filter_js_minify_excluded',false)) {
138
+                            $_CachedMinifiedUrl = $this->minify_single($path);
139 139
 
140
-							// replace orig URL with minified URL from cache if so
141
-							if (!empty($_CachedMinifiedUrl)) {
142
-								$newTag = str_replace($url, $_CachedMinifiedUrl, $newTag);
143
-							}
140
+                            // replace orig URL with minified URL from cache if so
141
+                            if (!empty($_CachedMinifiedUrl)) {
142
+                                $newTag = str_replace($url, $_CachedMinifiedUrl, $newTag);
143
+                            }
144 144
 							
145
-							// remove querystring from URL in newTag
146
-							if ( !empty($explUrl[1]) ) {
147
-								$newTag = str_replace("?".$explUrl[1],"",$newTag);
148
-							}
149
-						}
145
+                            // remove querystring from URL in newTag
146
+                            if ( !empty($explUrl[1]) ) {
147
+                                $newTag = str_replace("?".$explUrl[1],"",$newTag);
148
+                            }
149
+                        }
150 150
 
151
-						// should we move the non-aggregated script?
151
+                        // should we move the non-aggregated script?
152 152
                         if( $this->ismovable($newTag) ) {
153 153
                             // can be moved, flags and all
154 154
                             if( $this->movetolast($newTag) )    {
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
         
262 262
         //$this->jscode has all the uncompressed code now.
263 263
         if ($this->alreadyminified!==true) {
264
-          if (class_exists('JSMin') && apply_filters( 'autoptimize_js_do_minify' , true)) {
264
+            if (class_exists('JSMin') && apply_filters( 'autoptimize_js_do_minify' , true)) {
265 265
             if (@is_callable(array("JSMin","minify"))) {
266 266
                 $tmp_jscode = trim(JSMin::minify($this->jscode));
267 267
                 if (!empty($tmp_jscode)) {
@@ -275,10 +275,10 @@  discard block
 block discarded – undo
275 275
                 $this->jscode = $this->inject_minified($this->jscode);
276 276
                 return false;
277 277
             }
278
-          } else {
279
-              $this->jscode = $this->inject_minified($this->jscode);
278
+            } else {
279
+                $this->jscode = $this->inject_minified($this->jscode);
280 280
             return false;
281
-          }
281
+            }
282 282
         }
283 283
         return true;
284 284
     }
@@ -340,8 +340,8 @@  discard block
 block discarded – undo
340 340
     
341 341
     // Checks against the white- and blacklists
342 342
     private function ismergeable($tag) {
343
-		if (apply_filters('autoptimize_filter_js_dontaggregate',false)) {
344
-			return false;
343
+        if (apply_filters('autoptimize_filter_js_dontaggregate',false)) {
344
+            return false;
345 345
         } else if (!empty($this->whitelist)) {
346 346
             foreach ($this->whitelist as $match) {
347 347
                 if(strpos($tag,$match)!==false) {
@@ -449,15 +449,15 @@  discard block
 block discarded – undo
449 449
      * 
450 450
      * @param string $jsPath
451 451
      * @return bool
452
-	 */
453
-	private function can_inject_late($jsPath) {
454
-		$consider_minified_array = apply_filters('autoptimize_filter_js_consider_minified',false);
452
+     */
453
+    private function can_inject_late($jsPath) {
454
+        $consider_minified_array = apply_filters('autoptimize_filter_js_consider_minified',false);
455 455
         if ( $this->inject_min_late !== true ) {
456 456
             // late-inject turned off
457 457
             return false;
458 458
         } else if ( (strpos($jsPath,"min.js") === false) && ( strpos($jsPath,"wp-includes/js/jquery/jquery.js") === false ) && ( str_replace($consider_minified_array, '', $jsPath) === $jsPath ) ) {
459
-			// file not minified based on filename & filter
460
-			return false;
459
+            // file not minified based on filename & filter
460
+            return false;
461 461
         } else {
462 462
             // phew, all is safe, we can late-inject
463 463
             return true;
Please login to merge, or discard this patch.
classes/autoptimizeHTML.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -66,11 +66,11 @@
 block discarded – undo
66 66
                 }
67 67
             }
68 68
 
69
-			// revslider data attribs somehow suffer from HTML optimization, this fixes that
69
+            // revslider data attribs somehow suffer from HTML optimization, this fixes that
70 70
             if ( class_exists('RevSlider') || apply_filters('autoptimize_filter_html_dataattrib_cleanup', false) ) {
71
-				$this->content = preg_replace('#\n(data-.*$)\n#Um',' $1 ', $this->content);
72
-				$this->content = preg_replace('#(=\"[^"]*\")(\w)#','$1 $2', $this->content);
73
-			}
71
+                $this->content = preg_replace('#\n(data-.*$)\n#Um',' $1 ', $this->content);
72
+                $this->content = preg_replace('#(=\"[^"]*\")(\w)#','$1 $2', $this->content);
73
+            }
74 74
 
75 75
             return true;
76 76
         }
Please login to merge, or discard this patch.
classlesses/autoptimizeSpeedupper.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@  discard block
 block discarded – undo
4 4
 */
5 5
 
6 6
 function ao_js_snippetcache($jsin,$scriptname) {
7
-	// load speedupper conditionally (true by default?)
8
-	if ( apply_filters('autoptimize_filter_speedupper', true) ) {
7
+    // load speedupper conditionally (true by default?)
8
+    if ( apply_filters('autoptimize_filter_speedupper', true) ) {
9 9
         if (strpos($scriptname,"min.js")===false) {
10 10
                 $md5hash = "snippet_".md5($jsin);
11 11
                 $ccheck = new autoptimizeCache($md5hash,'js');
@@ -30,71 +30,71 @@  discard block
 block discarded – undo
30 30
             // do some housekeeping here to remove comments & linebreaks and stuff
31 31
             $scriptsrc=preg_replace("#^\s*\/\/.*$#Um","",$jsin);
32 32
             $scriptsrc=preg_replace("#^\s*\/\*[^!].*\*\/\s?#Us","",$scriptsrc);
33
-			$scriptsrc=preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $scriptsrc);
33
+            $scriptsrc=preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $scriptsrc);
34 34
 
35
-			if ((substr($scriptsrc,-1,1)!==";")&&(substr($scriptsrc,-1,1)!=="}")) {
36
-				$scriptsrc.=";";
37
-			}
35
+            if ((substr($scriptsrc,-1,1)!==";")&&(substr($scriptsrc,-1,1)!=="}")) {
36
+                $scriptsrc.=";";
37
+            }
38 38
 						
39
-			if (get_option("autoptimize_js_trycatch")==="on") {
40
-				$scriptsrc="try{".$scriptsrc."}catch(e){}";
41
-			}
39
+            if (get_option("autoptimize_js_trycatch")==="on") {
40
+                $scriptsrc="try{".$scriptsrc."}catch(e){}";
41
+            }
42 42
         }
43 43
         return $scriptsrc;
44
-	}
44
+    }
45 45
 }
46 46
 
47 47
 function ao_css_snippetcache($cssin,$filename) {
48
-	// load speedupper conditionally (true by default?)
49
-	if ( apply_filters('autoptimize_filter_speedupper', true) ) {
50
-		$md5hash = "snippet_".md5($cssin);
51
-		$ccheck = new autoptimizeCache($md5hash,'css');
52
-		if($ccheck->check()) {
53
-			$stylesrc = $ccheck->retrieve();
54
-		} else {
55
-			if (strpos($filename,"min.css")===false) {
56
-				if (class_exists('Minify_CSS_Compressor')) {
57
-					$tmp_code = trim(Minify_CSS_Compressor::process($cssin));
58
-				} else if(class_exists('CSSmin')) {
59
-					$cssmin = new CSSmin();
60
-					if (method_exists($cssmin,"run")) {
61
-						$tmp_code = trim($cssmin->run($cssin));
62
-					} elseif (@is_callable(array($cssmin,"minify"))) {
63
-						$tmp_code = trim(CssMin::minify($cssin));
64
-					}
65
-				}
48
+    // load speedupper conditionally (true by default?)
49
+    if ( apply_filters('autoptimize_filter_speedupper', true) ) {
50
+        $md5hash = "snippet_".md5($cssin);
51
+        $ccheck = new autoptimizeCache($md5hash,'css');
52
+        if($ccheck->check()) {
53
+            $stylesrc = $ccheck->retrieve();
54
+        } else {
55
+            if (strpos($filename,"min.css")===false) {
56
+                if (class_exists('Minify_CSS_Compressor')) {
57
+                    $tmp_code = trim(Minify_CSS_Compressor::process($cssin));
58
+                } else if(class_exists('CSSmin')) {
59
+                    $cssmin = new CSSmin();
60
+                    if (method_exists($cssmin,"run")) {
61
+                        $tmp_code = trim($cssmin->run($cssin));
62
+                    } elseif (@is_callable(array($cssmin,"minify"))) {
63
+                        $tmp_code = trim(CssMin::minify($cssin));
64
+                    }
65
+                }
66 66
 
67
-				if (!empty($tmp_code)) {
68
-					$stylesrc = $tmp_code;
69
-					unset($tmp_code);
70
-				} else {
71
-					$stylesrc = $cssin;
72
-				}
73
-			} else {
74
-				// .min.css -> no heavy-lifting, just some cleanup
75
-				$stylesrc=preg_replace("#^\s*\/\*[^!].*\*\/\s?#Us","",$cssin);
76
-				$stylesrc=preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $stylesrc);
77
-				$stylesrc=autoptimizeStyles::fixurls($filename,$stylesrc);
78
-			}
79
-			if (!empty($filename)) {
80
-				// don't cache inline CSS to avoid risk of cache-explosion
81
-				$ccheck->cache($stylesrc,'text/css');
82
-			}
83
-			unset($ccheck);
84
-		}
85
-		return $stylesrc;
86
-	}
67
+                if (!empty($tmp_code)) {
68
+                    $stylesrc = $tmp_code;
69
+                    unset($tmp_code);
70
+                } else {
71
+                    $stylesrc = $cssin;
72
+                }
73
+            } else {
74
+                // .min.css -> no heavy-lifting, just some cleanup
75
+                $stylesrc=preg_replace("#^\s*\/\*[^!].*\*\/\s?#Us","",$cssin);
76
+                $stylesrc=preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $stylesrc);
77
+                $stylesrc=autoptimizeStyles::fixurls($filename,$stylesrc);
78
+            }
79
+            if (!empty($filename)) {
80
+                // don't cache inline CSS to avoid risk of cache-explosion
81
+                $ccheck->cache($stylesrc,'text/css');
82
+            }
83
+            unset($ccheck);
84
+        }
85
+        return $stylesrc;
86
+    }
87 87
 }
88 88
 
89 89
 // try to warm (snippet) cache when AO cache is cleared
90 90
 function ao_speedup_warmcache() {
91
-	// load speedupper conditionally (true by default?)
92
-	if ( apply_filters('autoptimize_filter_speedupper', true) ) {
93
-		error_log("speedupper triggered");
94
-		$warmCacheUrl = site_url()."/?ao_speedup_cachebuster=".rand(1,100000);
95
-		$warmCache = @wp_remote_get($warmCacheUrl);
96
-		unset($warmCache);
97
-	}
91
+    // load speedupper conditionally (true by default?)
92
+    if ( apply_filters('autoptimize_filter_speedupper', true) ) {
93
+        error_log("speedupper triggered");
94
+        $warmCacheUrl = site_url()."/?ao_speedup_cachebuster=".rand(1,100000);
95
+        $warmCache = @wp_remote_get($warmCacheUrl);
96
+        unset($warmCache);
97
+    }
98 98
 }
99 99
 
100 100
 add_filter('autoptimize_css_individual_style','ao_css_snippetcache',10,2);
Please login to merge, or discard this patch.