Completed
Push — master ( d27635...8b725f )
by frank
02:03
created
classlesses/autoptimizeSpeedupper.php 3 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -88,13 +88,13 @@
 block discarded – undo
88 88
 }
89 89
 
90 90
 function ao_css_speedup_cleanup($cssin) {
91
-	// speedupper results in aggregated CSS not being minified, so the filestart-marker AO adds when aggregating need to be removed
92
-	return trim(str_replace(array('/*FILESTART*/','/*FILESTART2*/'),'',$cssin));
91
+    // speedupper results in aggregated CSS not being minified, so the filestart-marker AO adds when aggregating need to be removed
92
+    return trim(str_replace(array('/*FILESTART*/','/*FILESTART2*/'),'',$cssin));
93 93
 }
94 94
 
95 95
 function ao_js_speedup_cleanup($jsin) {
96
-	// cleanup
97
-	return trim($jsin);
96
+    // cleanup
97
+    return trim($jsin);
98 98
 }
99 99
 
100 100
 add_filter('autoptimize_css_individual_style','ao_css_snippetcacher',10,2);
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -4,64 +4,64 @@  discard block
 block discarded – undo
4 4
 * new in Autoptimize 2.2
5 5
 */
6 6
 
7
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
7
+if (!defined('ABSPATH')) exit; // Exit if accessed directly
8 8
 
9
-function ao_js_snippetcacher($jsin,$jsfilename) {
9
+function ao_js_snippetcacher($jsin, $jsfilename) {
10 10
     $md5hash = "snippet_".md5($jsin);
11
-    $ccheck = new autoptimizeCache($md5hash,'js');
12
-    if($ccheck->check()) {
11
+    $ccheck = new autoptimizeCache($md5hash, 'js');
12
+    if ($ccheck->check()) {
13 13
         $scriptsrc = $ccheck->retrieve();
14 14
     } else {
15
-        if ( (strpos($jsfilename,"min.js") === false) && ( strpos($jsfilename,"js/jquery/jquery.js") === false ) && ( str_replace(apply_filters('autoptimize_filter_js_consider_minified',false), '', $jsfilename) === $jsfilename ) ) {
16
-            if(class_exists('JSMin')) {
15
+        if ((strpos($jsfilename, "min.js") === false) && (strpos($jsfilename, "js/jquery/jquery.js") === false) && (str_replace(apply_filters('autoptimize_filter_js_consider_minified', false), '', $jsfilename) === $jsfilename)) {
16
+            if (class_exists('JSMin')) {
17 17
                 $tmp_jscode = trim(JSMin::minify($jsin));
18 18
                 if (!empty($tmp_jscode)) {
19 19
                         $scriptsrc = $tmp_jscode;
20 20
                         unset($tmp_jscode);
21 21
                 } else {
22
-                        $scriptsrc=$jsin;
22
+                        $scriptsrc = $jsin;
23 23
                 }
24 24
             } else {
25
-                $scriptsrc=$jsin;
25
+                $scriptsrc = $jsin;
26 26
             }
27 27
         } else {
28 28
             // do some housekeeping here to remove comments & linebreaks and stuff
29
-            $scriptsrc=preg_replace("#^\s*\/\/.*$#Um","",$jsin);
30
-            $scriptsrc=preg_replace("#^\s*\/\*[^!].*\*\/\s?#Us","",$scriptsrc);
31
-            $scriptsrc=preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $scriptsrc);
29
+            $scriptsrc = preg_replace("#^\s*\/\/.*$#Um", "", $jsin);
30
+            $scriptsrc = preg_replace("#^\s*\/\*[^!].*\*\/\s?#Us", "", $scriptsrc);
31
+            $scriptsrc = preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $scriptsrc);
32 32
 
33
-            if ((substr($scriptsrc,-1,1)!==";")&&(substr($scriptsrc,-1,1)!=="}")) {
34
-                $scriptsrc.=";";
33
+            if ((substr($scriptsrc, -1, 1) !== ";") && (substr($scriptsrc, -1, 1) !== "}")) {
34
+                $scriptsrc .= ";";
35 35
             }
36 36
         }
37
-        if ( !empty($jsfilename) && str_replace( apply_filters('autoptimize_filter_js_speedup_cache',false), '', $jsfilename ) === $jsfilename ) {
37
+        if (!empty($jsfilename) && str_replace(apply_filters('autoptimize_filter_js_speedup_cache', false), '', $jsfilename) === $jsfilename) {
38 38
             // don't cache inline CSS or if filter says no
39
-            $ccheck->cache($scriptsrc,'text/javascript');
39
+            $ccheck->cache($scriptsrc, 'text/javascript');
40 40
         }
41 41
     }
42 42
     unset($ccheck);
43 43
 
44
-    if (get_option("autoptimize_js_trycatch")==="on") {
45
-        $scriptsrc="try{".$scriptsrc."}catch(e){}";
44
+    if (get_option("autoptimize_js_trycatch") === "on") {
45
+        $scriptsrc = "try{".$scriptsrc."}catch(e){}";
46 46
     }
47 47
 
48 48
     return $scriptsrc;
49 49
 }
50 50
 
51
-function ao_css_snippetcacher($cssin,$cssfilename) {
51
+function ao_css_snippetcacher($cssin, $cssfilename) {
52 52
     $md5hash = "snippet_".md5($cssin);
53
-    $ccheck = new autoptimizeCache($md5hash,'css');
54
-    if($ccheck->check()) {
53
+    $ccheck = new autoptimizeCache($md5hash, 'css');
54
+    if ($ccheck->check()) {
55 55
         $stylesrc = $ccheck->retrieve();
56 56
     } else {
57
-        if ( ( strpos($cssfilename,"min.css") === false ) && ( str_replace( apply_filters('autoptimize_filter_css_consider_minified',false), '', $cssfilename ) === $cssfilename ) ) {
57
+        if ((strpos($cssfilename, "min.css") === false) && (str_replace(apply_filters('autoptimize_filter_css_consider_minified', false), '', $cssfilename) === $cssfilename)) {
58 58
             if (class_exists('Minify_CSS_Compressor')) {
59 59
                 $tmp_code = trim(Minify_CSS_Compressor::process($cssin));
60
-            } else if(class_exists('CSSmin')) {
60
+            } else if (class_exists('CSSmin')) {
61 61
                 $cssmin = new CSSmin();
62
-                if (method_exists($cssmin,"run")) {
62
+                if (method_exists($cssmin, "run")) {
63 63
                     $tmp_code = trim($cssmin->run($cssin));
64
-                } elseif (@is_callable(array($cssmin,"minify"))) {
64
+                } elseif (@is_callable(array($cssmin, "minify"))) {
65 65
                     $tmp_code = trim(CssMin::minify($cssin));
66 66
                 }
67 67
             }
@@ -74,13 +74,13 @@  discard block
 block discarded – undo
74 74
             }
75 75
         } else {
76 76
             // .min.css -> no heavy-lifting, just some cleanup
77
-            $stylesrc=preg_replace("#^\s*\/\*[^!].*\*\/\s?#Us","",$cssin);
78
-            $stylesrc=preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $stylesrc);
79
-            $stylesrc=autoptimizeStyles::fixurls($cssfilename,$stylesrc);
77
+            $stylesrc = preg_replace("#^\s*\/\*[^!].*\*\/\s?#Us", "", $cssin);
78
+            $stylesrc = preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $stylesrc);
79
+            $stylesrc = autoptimizeStyles::fixurls($cssfilename, $stylesrc);
80 80
         }
81
-        if ( !empty($cssfilename) && ( str_replace( apply_filters('autoptimize_filter_css_speedup_cache',false), '', $cssfilename ) === $cssfilename ) ) {
81
+        if (!empty($cssfilename) && (str_replace(apply_filters('autoptimize_filter_css_speedup_cache', false), '', $cssfilename) === $cssfilename)) {
82 82
             // only cache CSS if not inline and allowed by filter
83
-            $ccheck->cache($stylesrc,'text/css');
83
+            $ccheck->cache($stylesrc, 'text/css');
84 84
         }
85 85
     }
86 86
     unset($ccheck);
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 
90 90
 function ao_css_speedup_cleanup($cssin) {
91 91
 	// speedupper results in aggregated CSS not being minified, so the filestart-marker AO adds when aggregating need to be removed
92
-	return trim(str_replace(array('/*FILESTART*/','/*FILESTART2*/'),'',$cssin));
92
+	return trim(str_replace(array('/*FILESTART*/', '/*FILESTART2*/'), '', $cssin));
93 93
 }
94 94
 
95 95
 function ao_js_speedup_cleanup($jsin) {
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	return trim($jsin);
98 98
 }
99 99
 
100
-add_filter('autoptimize_css_individual_style','ao_css_snippetcacher',10,2);
101
-add_filter('autoptimize_js_individual_script','ao_js_snippetcacher',10,2);
102
-add_filter('autoptimize_css_after_minify','ao_css_speedup_cleanup',10,1);
103
-add_filter('autoptimize_js_after_minify','ao_js_speedup_cleanup',10,1);
100
+add_filter('autoptimize_css_individual_style', 'ao_css_snippetcacher', 10, 2);
101
+add_filter('autoptimize_js_individual_script', 'ao_js_snippetcacher', 10, 2);
102
+add_filter('autoptimize_css_after_minify', 'ao_css_speedup_cleanup', 10, 1);
103
+add_filter('autoptimize_js_after_minify', 'ao_js_speedup_cleanup', 10, 1);
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,10 @@
 block discarded – undo
4 4
 * new in Autoptimize 2.2
5 5
 */
6 6
 
7
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
7
+if ( ! defined( 'ABSPATH' ) ) {
8
+    exit;
9
+}
10
+// Exit if accessed directly
8 11
 
9 12
 function ao_js_snippetcacher($jsin,$jsfilename) {
10 13
     $md5hash = "snippet_".md5($jsin);
Please login to merge, or discard this patch.