Completed
Push — master ( dd1198...8aecdb )
by frank
03:54
created
classlesses/autoptimizeSpeedupper.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -3,62 +3,62 @@  discard block
 block discarded – undo
3 3
 Autoptimize SpeedUp; minify & cache each JS/ CSS separately
4 4
 */
5 5
 
6
-function ao_js_snippetcache($jsin,$jsfilename) {
6
+function ao_js_snippetcache($jsin, $jsfilename) {
7 7
     $md5hash = "snippet_".md5($jsin);
8
-    $ccheck = new autoptimizeCache($md5hash,'js');
9
-    if($ccheck->check()) {
8
+    $ccheck = new autoptimizeCache($md5hash, 'js');
9
+    if ($ccheck->check()) {
10 10
         $scriptsrc = $ccheck->retrieve();
11 11
     } else {
12
-        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 ) ) {
13
-            if(class_exists('JSMin')) {
12
+        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)) {
13
+            if (class_exists('JSMin')) {
14 14
                 $tmp_jscode = trim(JSMin::minify($jsin));
15 15
                 if (!empty($tmp_jscode)) {
16 16
                         $scriptsrc = $tmp_jscode;
17 17
                         unset($tmp_jscode);
18 18
                 } else {
19
-                        $scriptsrc=$jsin;
19
+                        $scriptsrc = $jsin;
20 20
                 }
21 21
             } else {
22
-                $scriptsrc=$jsin;
22
+                $scriptsrc = $jsin;
23 23
             }
24 24
         } else {
25 25
             // do some housekeeping here to remove comments & linebreaks and stuff
26
-            $scriptsrc=preg_replace("#^\s*\/\/.*$#Um","",$jsin);
27
-            $scriptsrc=preg_replace("#^\s*\/\*[^!].*\*\/\s?#Us","",$scriptsrc);
28
-            $scriptsrc=preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $scriptsrc);
26
+            $scriptsrc = preg_replace("#^\s*\/\/.*$#Um", "", $jsin);
27
+            $scriptsrc = preg_replace("#^\s*\/\*[^!].*\*\/\s?#Us", "", $scriptsrc);
28
+            $scriptsrc = preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $scriptsrc);
29 29
 
30
-            if ((substr($scriptsrc,-1,1)!==";")&&(substr($scriptsrc,-1,1)!=="}")) {
31
-                $scriptsrc.=";";
30
+            if ((substr($scriptsrc, -1, 1) !== ";") && (substr($scriptsrc, -1, 1) !== "}")) {
31
+                $scriptsrc .= ";";
32 32
             }
33 33
         }
34
-        if ( !empty($jsfilename) && str_replace( apply_filters('autoptimize_filter_js_speedup_cache',false), '', $jsfilename ) === $jsfilename ) {
34
+        if (!empty($jsfilename) && str_replace(apply_filters('autoptimize_filter_js_speedup_cache', false), '', $jsfilename) === $jsfilename) {
35 35
             // don't cache inline CSS or if filter says no
36
-            $ccheck->cache($scriptsrc,'text/javascript');
36
+            $ccheck->cache($scriptsrc, 'text/javascript');
37 37
         }
38 38
     }
39 39
     unset($ccheck);
40 40
 
41
-    if (get_option("autoptimize_js_trycatch")==="on") {
42
-        $scriptsrc="try{".$scriptsrc."}catch(e){}";
41
+    if (get_option("autoptimize_js_trycatch") === "on") {
42
+        $scriptsrc = "try{".$scriptsrc."}catch(e){}";
43 43
     }
44 44
 
45 45
     return $scriptsrc;
46 46
 }
47 47
 
48
-function ao_css_snippetcache($cssin,$cssfilename) {
48
+function ao_css_snippetcache($cssin, $cssfilename) {
49 49
     $md5hash = "snippet_".md5($cssin);
50
-    $ccheck = new autoptimizeCache($md5hash,'css');
51
-    if($ccheck->check()) {
50
+    $ccheck = new autoptimizeCache($md5hash, 'css');
51
+    if ($ccheck->check()) {
52 52
         $stylesrc = $ccheck->retrieve();
53 53
     } else {
54
-        if ( ( strpos($cssfilename,"min.css") === false ) && ( str_replace( apply_filters('autoptimize_filter_css_consider_minified',false), '', $cssfilename ) === $cssfilename ) ) {
54
+        if ((strpos($cssfilename, "min.css") === false) && (str_replace(apply_filters('autoptimize_filter_css_consider_minified', false), '', $cssfilename) === $cssfilename)) {
55 55
             if (class_exists('Minify_CSS_Compressor')) {
56 56
                 $tmp_code = trim(Minify_CSS_Compressor::process($cssin));
57
-            } else if(class_exists('CSSmin')) {
57
+            } else if (class_exists('CSSmin')) {
58 58
                 $cssmin = new CSSmin();
59
-                if (method_exists($cssmin,"run")) {
59
+                if (method_exists($cssmin, "run")) {
60 60
                     $tmp_code = trim($cssmin->run($cssin));
61
-                } elseif (@is_callable(array($cssmin,"minify"))) {
61
+                } elseif (@is_callable(array($cssmin, "minify"))) {
62 62
                     $tmp_code = trim(CssMin::minify($cssin));
63 63
                 }
64 64
             }
@@ -71,18 +71,18 @@  discard block
 block discarded – undo
71 71
             }
72 72
         } else {
73 73
             // .min.css -> no heavy-lifting, just some cleanup
74
-            $stylesrc=preg_replace("#^\s*\/\*[^!].*\*\/\s?#Us","",$cssin);
75
-            $stylesrc=preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $stylesrc);
76
-            $stylesrc=autoptimizeStyles::fixurls($cssfilename,$stylesrc);
74
+            $stylesrc = preg_replace("#^\s*\/\*[^!].*\*\/\s?#Us", "", $cssin);
75
+            $stylesrc = preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $stylesrc);
76
+            $stylesrc = autoptimizeStyles::fixurls($cssfilename, $stylesrc);
77 77
         }
78
-        if ( !empty($cssfilename) && ( str_replace( apply_filters('autoptimize_filter_css_speedup_cache',false), '', $cssfilename ) === $cssfilename ) ) {
78
+        if (!empty($cssfilename) && (str_replace(apply_filters('autoptimize_filter_css_speedup_cache', false), '', $cssfilename) === $cssfilename)) {
79 79
             // only cache CSS if not inline and allowed by filter
80
-            $ccheck->cache($stylesrc,'text/css');
80
+            $ccheck->cache($stylesrc, 'text/css');
81 81
         }
82 82
     }
83 83
     unset($ccheck);
84 84
     return $stylesrc;
85 85
 }
86 86
 
87
-add_filter('autoptimize_css_individual_style','ao_css_snippetcache',10,2);
88
-add_filter('autoptimize_js_individual_script','ao_js_snippetcache',10,2);
87
+add_filter('autoptimize_css_individual_style', 'ao_css_snippetcache', 10, 2);
88
+add_filter('autoptimize_js_individual_script', 'ao_js_snippetcache', 10, 2);
Please login to merge, or discard this patch.