Completed
Push — master ( b5e696...31910f )
by frank
02:19
created
classes/autoptimizeStyles.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -162,29 +162,29 @@  discard block
 block discarded – undo
162 162
                     // Remove the original style tag
163 163
                     $this->content = str_replace($tag,'',$this->content);
164 164
                 } else {
165
-					// excluded CSS, minify if getpath 
166
-					if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi',$tag,$source)) {
167
-						$url = current(explode('?',$source[2],2));
165
+                    // excluded CSS, minify if getpath 
166
+                    if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi',$tag,$source)) {
167
+                        $url = current(explode('?',$source[2],2));
168 168
                         $path = $this->getpath($url);
169 169
  					
170
-						if ($path && apply_filters('autoptimize_filter_css_minify_excluded',false)) {
171
-							$_CachedMinifiedUrl = $this->minify_single($path);
172
-
173
-							if (!empty($_CachedMinifiedUrl)) {
174
-								// replace orig URL with URL to cache
175
-								$newTag = str_replace($url, $_CachedMinifiedUrl, $tag);
176
-							} else {
177
-								$newTag = $tag;
178
-							}
170
+                        if ($path && apply_filters('autoptimize_filter_css_minify_excluded',false)) {
171
+                            $_CachedMinifiedUrl = $this->minify_single($path);
172
+
173
+                            if (!empty($_CachedMinifiedUrl)) {
174
+                                // replace orig URL with URL to cache
175
+                                $newTag = str_replace($url, $_CachedMinifiedUrl, $tag);
176
+                            } else {
177
+                                $newTag = $tag;
178
+                            }
179 179
 							
180
-							// remove querystring from URL
181
-							$_querystr = next(explode('?',$source[2],2));
182
-							$newTag = str_replace("?".$_querystr,"",$newTag);
183
-							// and replace
184
-							$this->content = str_replace($tag,$newTag,$this->content);
185
-						}
186
-					}					
187
-				}
180
+                            // remove querystring from URL
181
+                            $_querystr = next(explode('?',$source[2],2));
182
+                            $newTag = str_replace("?".$_querystr,"",$newTag);
183
+                            // and replace
184
+                            $this->content = str_replace($tag,$newTag,$this->content);
185
+                        }
186
+                    }					
187
+                }
188 188
             }
189 189
             return true;
190 190
         }
@@ -657,8 +657,8 @@  discard block
 block discarded – undo
657 657
     }
658 658
     
659 659
     private function ismovable($tag) {
660
-		if (apply_filters('autoptimize_filter_css_dontaggregate',false)) {
661
-			return false;
660
+        if (apply_filters('autoptimize_filter_css_dontaggregate',false)) {
661
+            return false;
662 662
         } else if (!empty($this->whitelist)) {
663 663
             foreach ($this->whitelist as $match) {
664 664
                 if(strpos($tag,$match)!==false) {
Please login to merge, or discard this patch.
classes/autoptimizeBase.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -341,43 +341,43 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
-		$_CachedMinfiedUrl = $this->url_replace_cdn($_CachedMinifiedUrl);									
400
+        // if CDN, then CDN
401
+        $_CachedMinfiedUrl = $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
 }
Please login to merge, or discard this patch.
classes/autoptimizeScripts.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -128,26 +128,26 @@  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
-							$_querystr = next(explode('?',$source[2],2));
147
-							$newTag = str_replace("?".$_querystr,"",$newTag);
148
-						}
145
+                            // remove querystring from URL in newTag
146
+                            $_querystr = next(explode('?',$source[2],2));
147
+                            $newTag = str_replace("?".$_querystr,"",$newTag);
148
+                        }
149 149
 
150
-						// should we move the non-aggregated script?
150
+                        // should we move the non-aggregated script?
151 151
                         if( $this->ismovable($newTag) ) {
152 152
                             // can be moved, flags and all
153 153
                             if( $this->movetolast($newTag) )    {
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
         
261 261
         //$this->jscode has all the uncompressed code now.
262 262
         if ($this->alreadyminified!==true) {
263
-          if (class_exists('JSMin') && apply_filters( 'autoptimize_js_do_minify' , true)) {
263
+            if (class_exists('JSMin') && apply_filters( 'autoptimize_js_do_minify' , true)) {
264 264
             if (@is_callable(array("JSMin","minify"))) {
265 265
                 $tmp_jscode = trim(JSMin::minify($this->jscode));
266 266
                 if (!empty($tmp_jscode)) {
@@ -274,10 +274,10 @@  discard block
 block discarded – undo
274 274
                 $this->jscode = $this->inject_minified($this->jscode);
275 275
                 return false;
276 276
             }
277
-          } else {
278
-              $this->jscode = $this->inject_minified($this->jscode);
277
+            } else {
278
+                $this->jscode = $this->inject_minified($this->jscode);
279 279
             return false;
280
-          }
280
+            }
281 281
         }
282 282
         return true;
283 283
     }
@@ -339,8 +339,8 @@  discard block
 block discarded – undo
339 339
     
340 340
     // Checks against the white- and blacklists
341 341
     private function ismergeable($tag) {
342
-		if (apply_filters('autoptimize_filter_js_dontaggregate',false)) {
343
-			return false;
342
+        if (apply_filters('autoptimize_filter_js_dontaggregate',false)) {
343
+            return false;
344 344
         } else if (!empty($this->whitelist)) {
345 345
             foreach ($this->whitelist as $match) {
346 346
                 if(strpos($tag,$match)!==false) {
Please login to merge, or discard this patch.