Completed
Push — master ( b5e696...31910f )
by frank
02:19
created
classes/autoptimizeBase.php 2 patches
Doc Comments   +20 added lines patch added patch discarded remove patch
@@ -139,6 +139,10 @@  discard block
 block discarded – undo
139 139
     }
140 140
 
141 141
     // hide everything between noptimize-comment tags
142
+
143
+    /**
144
+     * @param string $noptimize_in
145
+     */
142 146
     protected function hide_noptimize($noptimize_in) {
143 147
         if ( preg_match( '/<!--\s?noptimize\s?-->/', $noptimize_in ) ) { 
144 148
             $noptimize_out = preg_replace_callback(
@@ -267,6 +271,9 @@  discard block
 block discarded – undo
267 271
         return $url;
268 272
     }
269 273
 
274
+    /**
275
+     * @param string $payload
276
+     */
270 277
     protected function inject_in_html($payload,$replaceTag) {
271 278
         if (strpos($this->content,$replaceTag[0])!== false) {
272 279
             if ($replaceTag[1]==="after") {
@@ -286,6 +293,9 @@  discard block
 block discarded – undo
286 293
         }
287 294
     }
288 295
     
296
+    /**
297
+     * @param string $tag
298
+     */
289 299
     protected function isremovable($tag, $removables) {
290 300
         foreach ($removables as $match) {
291 301
             if (strpos($tag,$match)!==false) {
@@ -296,6 +306,10 @@  discard block
 block discarded – undo
296 306
     }
297 307
     
298 308
     // inject already minified code in optimized JS/CSS
309
+
310
+    /**
311
+     * @return string
312
+     */
299 313
     protected function inject_minified($in) {
300 314
         if ( strpos( $in, '%%INJECTLATER%%' ) !== false ) {
301 315
             $out = preg_replace_callback(
@@ -340,6 +354,9 @@  discard block
 block discarded – undo
340 354
         return $out;
341 355
     }
342 356
     
357
+    /**
358
+     * @param string $pathIn
359
+     */
343 360
     protected function minify_single($pathIn) {
344 361
 		// determine JS or CSS and set var (also mimetype), return false if neither
345 362
 		if ( $this->str_ends_in($pathIn,".js") === true ) {
@@ -403,6 +420,9 @@  discard block
 block discarded – undo
403 420
 		return $_CachedMinifiedUrl;
404 421
 	}
405 422
 	
423
+	/**
424
+	 * @param string $needle
425
+	 */
406 426
 	protected function str_ends_in($haystack,$needle) {
407 427
 		$needleLength = strlen($needle);
408 428
 		$haystackLength = strlen($haystack);
Please login to merge, or discard this 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/autoptimizeStyles.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -656,6 +656,9 @@
 block discarded – undo
656 656
         return $code;
657 657
     }
658 658
     
659
+    /**
660
+     * @param string $tag
661
+     */
659 662
     private function ismovable($tag) {
660 663
 		if (apply_filters('autoptimize_filter_css_dontaggregate',false)) {
661 664
 			return false;
Please login to merge, or discard this 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/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.