Completed
Pull Request — master (#123)
by
unknown
02:16
created
autoptimize.php 1 patch
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -12,15 +12,15 @@  discard block
 block discarded – undo
12 12
 http://www.gnu.org/licenses/gpl.txt
13 13
 */
14 14
 
15
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
15
+if (!defined('ABSPATH')) exit; // Exit if accessed directly
16 16
 
17
-define('AUTOPTIMIZE_PLUGIN_DIR',plugin_dir_path(__FILE__));
17
+define('AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path(__FILE__));
18 18
 
19 19
 // Load config class
20 20
 include(AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeConfig.php');
21 21
 
22 22
 // Load toolbar class
23
-include( AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeToolbar.php' );
23
+include(AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeToolbar.php');
24 24
 
25 25
 // Load partners tab if admin
26 26
 if (is_admin()) {
@@ -28,29 +28,29 @@  discard block
 block discarded – undo
28 28
 }
29 29
 
30 30
 // Do we gzip when caching (needed early to load autoptimizeCache.php)
31
-define('AUTOPTIMIZE_CACHE_NOGZIP',(bool) get_option('autoptimize_cache_nogzip'));
31
+define('AUTOPTIMIZE_CACHE_NOGZIP', (bool) get_option('autoptimize_cache_nogzip'));
32 32
 
33 33
 // Load cache class
34 34
 include(AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeCache.php');
35 35
 
36 36
 // wp-content dir name (automagically set, should not be needed), dirname of AO cache dir and AO-prefix can be overridden in wp-config.php
37
-if (!defined('AUTOPTIMIZE_WP_CONTENT_NAME')) { define('AUTOPTIMIZE_WP_CONTENT_NAME','/'.wp_basename( WP_CONTENT_DIR )); }
38
-if (!defined('AUTOPTIMIZE_CACHE_CHILD_DIR')) { define('AUTOPTIMIZE_CACHE_CHILD_DIR','/cache/autoptimize/'); }
37
+if (!defined('AUTOPTIMIZE_WP_CONTENT_NAME')) { define('AUTOPTIMIZE_WP_CONTENT_NAME', '/'.wp_basename(WP_CONTENT_DIR)); }
38
+if (!defined('AUTOPTIMIZE_CACHE_CHILD_DIR')) { define('AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/'); }
39 39
 if (!defined('AUTOPTIMIZE_CACHEFILE_PREFIX')) { define('AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_'); }
40 40
 
41 41
 // Plugin dir constants (plugin url's defined later to accomodate domain mapped sites)
42
-if (is_multisite() && apply_filters( 'autoptimize_separate_blog_caches' , true )) {
42
+if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) {
43 43
     $blog_id = get_current_blog_id();
44
-    define('AUTOPTIMIZE_CACHE_DIR', WP_CONTENT_DIR.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/' );
44
+    define('AUTOPTIMIZE_CACHE_DIR', WP_CONTENT_DIR.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/');
45 45
 } else {
46 46
     define('AUTOPTIMIZE_CACHE_DIR', WP_CONTENT_DIR.AUTOPTIMIZE_CACHE_CHILD_DIR);
47 47
 }
48
-define('AUTOPTIMIZE_CACHE_DELAY',true);
49
-define('WP_ROOT_DIR',substr(WP_CONTENT_DIR, 0, strlen(WP_CONTENT_DIR)-strlen(AUTOPTIMIZE_WP_CONTENT_NAME)));
48
+define('AUTOPTIMIZE_CACHE_DELAY', true);
49
+define('WP_ROOT_DIR', substr(WP_CONTENT_DIR, 0, strlen(WP_CONTENT_DIR) - strlen(AUTOPTIMIZE_WP_CONTENT_NAME)));
50 50
 
51 51
 // WP CLI
52
-if ( defined( 'WP_CLI' ) && WP_CLI ) {
53
-	require_once AUTOPTIMIZE_PLUGIN_DIR . 'classes/autoptimizeCLI.php';
52
+if (defined('WP_CLI') && WP_CLI) {
53
+	require_once AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeCLI.php';
54 54
 }
55 55
 
56 56
 // Initialize the cache at least once
@@ -59,65 +59,65 @@  discard block
 block discarded – undo
59 59
 /* Check if we're updating, in which case we might need to do stuff and flush the cache
60 60
 to avoid old versions of aggregated files lingering around */
61 61
 
62
-$autoptimize_version="2.2.0";
63
-$autoptimize_db_version=get_option('autoptimize_version','none');
62
+$autoptimize_version = "2.2.0";
63
+$autoptimize_db_version = get_option('autoptimize_version', 'none');
64 64
 
65 65
 if ($autoptimize_db_version !== $autoptimize_version) {
66
-    if ($autoptimize_db_version==="none") {
66
+    if ($autoptimize_db_version === "none") {
67 67
         add_action('admin_notices', 'autoptimize_install_config_notice');
68 68
     } else {
69 69
         // updating, include the update-code
70 70
         include(AUTOPTIMIZE_PLUGIN_DIR.'classlesses/autoptimizeUpdateCode.php');
71 71
     }
72 72
 
73
-    update_option('autoptimize_version',$autoptimize_version);
74
-    $autoptimize_db_version=$autoptimize_version;
73
+    update_option('autoptimize_version', $autoptimize_version);
74
+    $autoptimize_db_version = $autoptimize_version;
75 75
 }
76 76
 
77 77
 // Load translations
78 78
 function autoptimize_load_plugin_textdomain() {
79
-    load_plugin_textdomain('autoptimize',false,plugin_basename(dirname( __FILE__ )).'/localization');
79
+    load_plugin_textdomain('autoptimize', false, plugin_basename(dirname(__FILE__)).'/localization');
80 80
 }
81
-add_action( 'init', 'autoptimize_load_plugin_textdomain' );
81
+add_action('init', 'autoptimize_load_plugin_textdomain');
82 82
 
83
-function autoptimize_uninstall(){
83
+function autoptimize_uninstall() {
84 84
     autoptimizeCache::clearall();
85 85
 
86
-    $delete_options=array("autoptimize_cache_clean", "autoptimize_cache_nogzip", "autoptimize_css", "autoptimize_css_datauris", "autoptimize_css_justhead", "autoptimize_css_defer", "autoptimize_css_defer_inline", "autoptimize_css_inline", "autoptimize_css_exclude", "autoptimize_html", "autoptimize_html_keepcomments", "autoptimize_js", "autoptimize_js_exclude", "autoptimize_js_forcehead", "autoptimize_js_justhead", "autoptimize_js_trycatch", "autoptimize_version", "autoptimize_show_adv", "autoptimize_cdn_url", "autoptimize_cachesize_notice","autoptimize_css_include_inline","autoptimize_js_include_inline","autoptimize_css_nogooglefont","autoptimize_optimize_logged","autoptimize_optimize_checkout");
86
+    $delete_options = array("autoptimize_cache_clean", "autoptimize_cache_nogzip", "autoptimize_css", "autoptimize_css_datauris", "autoptimize_css_justhead", "autoptimize_css_defer", "autoptimize_css_defer_inline", "autoptimize_css_inline", "autoptimize_css_exclude", "autoptimize_html", "autoptimize_html_keepcomments", "autoptimize_js", "autoptimize_js_exclude", "autoptimize_js_forcehead", "autoptimize_js_justhead", "autoptimize_js_trycatch", "autoptimize_version", "autoptimize_show_adv", "autoptimize_cdn_url", "autoptimize_cachesize_notice", "autoptimize_css_include_inline", "autoptimize_js_include_inline", "autoptimize_css_nogooglefont", "autoptimize_optimize_logged", "autoptimize_optimize_checkout");
87 87
 
88
-    if ( !is_multisite() ) {
89
-        foreach ($delete_options as $del_opt) { delete_option( $del_opt ); }
88
+    if (!is_multisite()) {
89
+        foreach ($delete_options as $del_opt) { delete_option($del_opt); }
90 90
     } else {
91 91
         global $wpdb;
92
-        $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
92
+        $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
93 93
         $original_blog_id = get_current_blog_id();
94
-        foreach ( $blog_ids as $blog_id ) {
95
-            switch_to_blog( $blog_id );
96
-            foreach ($delete_options as $del_opt) { delete_option( $del_opt ); }
94
+        foreach ($blog_ids as $blog_id) {
95
+            switch_to_blog($blog_id);
96
+            foreach ($delete_options as $del_opt) { delete_option($del_opt); }
97 97
         }
98
-        switch_to_blog( $original_blog_id );
98
+        switch_to_blog($original_blog_id);
99 99
     }
100 100
 
101
-    if ( wp_get_schedule( 'ao_cachechecker' ) ) {
102
-        wp_clear_scheduled_hook( 'ao_cachechecker' );
101
+    if (wp_get_schedule('ao_cachechecker')) {
102
+        wp_clear_scheduled_hook('ao_cachechecker');
103 103
     }
104 104
 }
105 105
 
106 106
 function autoptimize_install_config_notice() {
107 107
     echo '<div class="updated"><p>';
108
-    _e('Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize' );
108
+    _e('Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize');
109 109
     echo '</p></div>';
110 110
 }
111 111
 
112 112
 function autoptimize_update_config_notice() {
113 113
     echo '<div class="updated"><p>';
114
-    _e('Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize' );
114
+    _e('Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize');
115 115
     echo '</p></div>';
116 116
 }
117 117
 
118 118
 function autoptimize_cache_unavailable_notice() {
119 119
     echo '<div class="error"><p>';
120
-    printf( __( 'Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize' ), AUTOPTIMIZE_CACHE_DIR );
120
+    printf(__('Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize'), AUTOPTIMIZE_CACHE_DIR);
121 121
     echo '</p></div>';
122 122
 }
123 123
 
@@ -126,27 +126,27 @@  discard block
 block discarded – undo
126 126
     $ao_noptimize = false;
127 127
 
128 128
     // noptimize in qs to get non-optimized page for debugging
129
-    if (array_key_exists("ao_noptimize",$_GET) || array_key_exists("ao_noptirocket",$_GET)) {
130
-        if ( ( ($_GET["ao_noptimize"]==="1") || ($_GET["ao_noptirocket"]==="1") ) && (apply_filters('autoptimize_filter_honor_qs_noptimize',true)) ) {
129
+    if (array_key_exists("ao_noptimize", $_GET) || array_key_exists("ao_noptirocket", $_GET)) {
130
+        if ((($_GET["ao_noptimize"] === "1") || ($_GET["ao_noptirocket"] === "1")) && (apply_filters('autoptimize_filter_honor_qs_noptimize', true))) {
131 131
             $ao_noptimize = true;
132 132
         }
133 133
     }
134 134
 
135 135
     // check for DONOTMINIFY constant as used by e.g. WooCommerce POS
136
-    if (defined('DONOTMINIFY') && (constant('DONOTMINIFY')===true || constant('DONOTMINIFY')==="true")) {
136
+    if (defined('DONOTMINIFY') && (constant('DONOTMINIFY') === true || constant('DONOTMINIFY') === "true")) {
137 137
         $ao_noptimize = true;
138 138
     }
139 139
 
140 140
 	// if setting says not to optimize logged in user and user is logged in
141
-	if ( get_option('autoptimize_optimize_logged','on') !== 'on' && is_user_logged_in() && current_user_can('edit_posts') ) {
141
+	if (get_option('autoptimize_optimize_logged', 'on') !== 'on' && is_user_logged_in() && current_user_can('edit_posts')) {
142 142
 		$ao_noptimize = true;
143 143
 	}
144 144
 
145 145
 	// if setting says not to optimize cart/ checkout
146
-	if ( get_option('autoptimize_optimize_checkout','on') !== 'on' ) {
146
+	if (get_option('autoptimize_optimize_checkout', 'on') !== 'on') {
147 147
 		// checking for woocommerce, easy digital downloads and wp ecommerce
148
-		foreach ( array("is_checkout","is_cart","edd_is_checkout","wpsc_is_cart","wpsc_is_checkout") as $shopCond ) {
149
-			if ( function_exists($shopCond) && $shopCond() ) {
148
+		foreach (array("is_checkout", "is_cart", "edd_is_checkout", "wpsc_is_cart", "wpsc_is_checkout") as $shopCond) {
149
+			if (function_exists($shopCond) && $shopCond()) {
150 150
 				$ao_noptimize = true;
151 151
 				break;
152 152
 			}
@@ -154,11 +154,11 @@  discard block
 block discarded – undo
154 154
 	}
155 155
 
156 156
     // filter you can use to block autoptimization on your own terms
157
-    $ao_noptimize = (bool) apply_filters( 'autoptimize_filter_noptimize', $ao_noptimize );
157
+    $ao_noptimize = (bool) apply_filters('autoptimize_filter_noptimize', $ao_noptimize);
158 158
 
159
-    if (!is_feed() && !$ao_noptimize && !is_admin() && ( !function_exists('is_customize_preview') || !is_customize_preview() ) ) {
159
+    if (!is_feed() && !$ao_noptimize && !is_admin() && (!function_exists('is_customize_preview') || !is_customize_preview())) {
160 160
         // load speedupper conditionally (true by default?)
161
-        if ( apply_filters('autoptimize_filter_speedupper', true) ) {
161
+        if (apply_filters('autoptimize_filter_speedupper', true)) {
162 162
             include(AUTOPTIMIZE_PLUGIN_DIR.'classlesses/autoptimizeSpeedupper.php');
163 163
         }
164 164
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
         include(AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeBase.php');
170 170
 
171 171
         // Load extra classes and set some vars
172
-        if($conf->get('autoptimize_html')) {
172
+        if ($conf->get('autoptimize_html')) {
173 173
             include(AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeHTML.php');
174 174
             // BUG: new minify-html does not support keeping HTML comments, skipping for now
175 175
             // if (defined('AUTOPTIMIZE_LEGACY_MINIFIERS')) {
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
             // }
180 180
         }
181 181
 
182
-        if($conf->get('autoptimize_js')) {
182
+        if ($conf->get('autoptimize_js')) {
183 183
             include(AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeScripts.php');
184 184
             if (!class_exists('JSMin')) {
185 185
                 if (defined('AUTOPTIMIZE_LEGACY_MINIFIERS')) {
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
                     @include(AUTOPTIMIZE_PLUGIN_DIR.'classes/external/php/minify-2.3.1-jsmin.php');
189 189
                 }
190 190
             }
191
-            if ( ! defined( 'CONCATENATE_SCRIPTS' )) {
192
-                define('CONCATENATE_SCRIPTS',false);
191
+            if (!defined('CONCATENATE_SCRIPTS')) {
192
+                define('CONCATENATE_SCRIPTS', false);
193 193
             }
194
-            if ( ! defined( 'COMPRESS_SCRIPTS' )) {
195
-                define('COMPRESS_SCRIPTS',false);
194
+            if (!defined('COMPRESS_SCRIPTS')) {
195
+                define('COMPRESS_SCRIPTS', false);
196 196
             }
197 197
         }
198 198
 
199
-        if($conf->get('autoptimize_css')) {
199
+        if ($conf->get('autoptimize_css')) {
200 200
             include(AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeStyles.php');
201 201
             if (defined('AUTOPTIMIZE_LEGACY_MINIFIERS')) {
202 202
                 if (!class_exists('Minify_CSS_Compressor')) {
@@ -207,13 +207,13 @@  discard block
 block discarded – undo
207 207
                     @include(AUTOPTIMIZE_PLUGIN_DIR.'classes/external/php/yui-php-cssmin-2.4.8-4_fgo.php');
208 208
                 }
209 209
             }
210
-            if ( ! defined( 'COMPRESS_CSS' )) {
211
-                define('COMPRESS_CSS',false);
210
+            if (!defined('COMPRESS_CSS')) {
211
+                define('COMPRESS_CSS', false);
212 212
             }
213 213
         }
214 214
 
215 215
         // filter to be used with care, kills all output buffers when true. use with extreme caution. you have been warned!
216
-        if (apply_filters('autoptimize_filter_obkiller',false)) {
216
+        if (apply_filters('autoptimize_filter_obkiller', false)) {
217 217
             while (ob_get_level() > 0) {
218 218
                 ob_end_clean();
219 219
             }
@@ -225,36 +225,36 @@  discard block
 block discarded – undo
225 225
 
226 226
 // Action on end, this is where the magic happens
227 227
 function autoptimize_end_buffering($content) {
228
-    if ( ((stripos($content,"<html") === false) && (stripos($content,"<!DOCTYPE html") === false)) || preg_match('/<html[^>]*(?:amp|⚡)/',$content) === 1 || stripos($content,"<xsl:stylesheet") !== false ) { return $content; }
228
+    if (((stripos($content, "<html") === false) && (stripos($content, "<!DOCTYPE html") === false)) || preg_match('/<html[^>]*(?:amp|⚡)/', $content) === 1 || stripos($content, "<xsl:stylesheet") !== false) { return $content; }
229 229
 
230 230
     // load URL constants as late as possible to allow domain mapper to kick in
231 231
     if (function_exists("domain_mapping_siteurl")) {
232
-        define('AUTOPTIMIZE_WP_SITE_URL',domain_mapping_siteurl(get_current_blog_id()));
233
-        define('AUTOPTIMIZE_WP_CONTENT_URL',str_replace(get_original_url(AUTOPTIMIZE_WP_SITE_URL),AUTOPTIMIZE_WP_SITE_URL,content_url()));
232
+        define('AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl(get_current_blog_id()));
233
+        define('AUTOPTIMIZE_WP_CONTENT_URL', str_replace(get_original_url(AUTOPTIMIZE_WP_SITE_URL), AUTOPTIMIZE_WP_SITE_URL, content_url()));
234 234
     } else {
235
-        define('AUTOPTIMIZE_WP_SITE_URL',site_url());
236
-        define('AUTOPTIMIZE_WP_CONTENT_URL',content_url());
235
+        define('AUTOPTIMIZE_WP_SITE_URL', site_url());
236
+        define('AUTOPTIMIZE_WP_CONTENT_URL', content_url());
237 237
     }
238 238
 
239
-    if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches' , true ) ) {
239
+    if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) {
240 240
         $blog_id = get_current_blog_id();
241
-        define('AUTOPTIMIZE_CACHE_URL',AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/' );
241
+        define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/');
242 242
     } else {
243
-        define('AUTOPTIMIZE_CACHE_URL',AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR);
243
+        define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR);
244 244
     }
245
-    define('AUTOPTIMIZE_WP_ROOT_URL',str_replace(AUTOPTIMIZE_WP_CONTENT_NAME,'',AUTOPTIMIZE_WP_CONTENT_URL));
246
-    define('AUTOPTIMIZE_HASH',wp_hash(AUTOPTIMIZE_CACHE_DIR));
245
+    define('AUTOPTIMIZE_WP_ROOT_URL', str_replace(AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL));
246
+    define('AUTOPTIMIZE_HASH', wp_hash(AUTOPTIMIZE_CACHE_DIR));
247 247
 
248 248
     // Config element
249 249
     $conf = autoptimizeConfig::instance();
250 250
 
251 251
     // Choose the classes
252 252
     $classes = array();
253
-    if($conf->get('autoptimize_js'))
253
+    if ($conf->get('autoptimize_js'))
254 254
         $classes[] = 'autoptimizeScripts';
255
-    if($conf->get('autoptimize_css'))
255
+    if ($conf->get('autoptimize_css'))
256 256
         $classes[] = 'autoptimizeStyles';
257
-    if($conf->get('autoptimize_html'))
257
+    if ($conf->get('autoptimize_html'))
258 258
         $classes[] = 'autoptimizeHTML';
259 259
 
260 260
     // Set some options
@@ -283,12 +283,12 @@  discard block
 block discarded – undo
283 283
         )
284 284
     );
285 285
 
286
-    $content = apply_filters( 'autoptimize_filter_html_before_minify', $content );
286
+    $content = apply_filters('autoptimize_filter_html_before_minify', $content);
287 287
 
288 288
     // Run the classes
289
-    foreach($classes as $name) {
289
+    foreach ($classes as $name) {
290 290
         $instance = new $name($content);
291
-        if($instance->read($classoptions[$name])) {
291
+        if ($instance->read($classoptions[$name])) {
292 292
             $instance->minify();
293 293
             $instance->cache();
294 294
             $content = $instance->getcontent();
@@ -296,19 +296,19 @@  discard block
 block discarded – undo
296 296
         unset($instance);
297 297
     }
298 298
     
299
-    $content = apply_filters( 'autoptimize_html_after_minify', $content );
299
+    $content = apply_filters('autoptimize_html_after_minify', $content);
300 300
     return $content;
301 301
 }
302 302
 
303
-if ( autoptimizeCache::cacheavail() ) {
303
+if (autoptimizeCache::cacheavail()) {
304 304
     $conf = autoptimizeConfig::instance();
305
-    if( $conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css') ) {
305
+    if ($conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css')) {
306 306
         // Hook to wordpress
307 307
         if (defined('AUTOPTIMIZE_INIT_EARLIER')) {
308
-            add_action('init','autoptimize_start_buffering',-1);
308
+            add_action('init', 'autoptimize_start_buffering', -1);
309 309
         } else {
310 310
             if (!defined('AUTOPTIMIZE_HOOK_INTO')) { define('AUTOPTIMIZE_HOOK_INTO', 'template_redirect'); }
311
-            add_action(constant("AUTOPTIMIZE_HOOK_INTO"),'autoptimize_start_buffering',2);
311
+            add_action(constant("AUTOPTIMIZE_HOOK_INTO"), 'autoptimize_start_buffering', 2);
312 312
         }
313 313
     }
314 314
 } else {
@@ -316,9 +316,9 @@  discard block
 block discarded – undo
316 316
 }
317 317
 
318 318
 function autoptimize_activate() {
319
-    register_uninstall_hook( __FILE__, 'autoptimize_uninstall' );
319
+    register_uninstall_hook(__FILE__, 'autoptimize_uninstall');
320 320
 }
321
-register_activation_hook( __FILE__, 'autoptimize_activate' );
321
+register_activation_hook(__FILE__, 'autoptimize_activate');
322 322
 
323 323
 include_once('classlesses/autoptimizeCacheChecker.php');
324 324
 
Please login to merge, or discard this patch.
classes/autoptimizeCLI.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) {
3
+if (!defined('ABSPATH')) {
4 4
 	exit;
5 5
 }
6 6
 
@@ -11,12 +11,12 @@  discard block
 block discarded – undo
11 11
 	 *
12 12
 	 * @subcommand clear
13 13
 	 */
14
-	public function clear( $args, $args_assoc ) {
15
-		WP_CLI::line( esc_html__( 'Flushing the cache...', 'autoptimize' ) );
14
+	public function clear($args, $args_assoc) {
15
+		WP_CLI::line(esc_html__('Flushing the cache...', 'autoptimize'));
16 16
 		autoptimizeCache::clearall();
17
-		WP_CLI::success( esc_html__( 'Cache flushed.', 'autoptimize' ) );
17
+		WP_CLI::success(esc_html__('Cache flushed.', 'autoptimize'));
18 18
 	}
19 19
 
20 20
 }
21 21
 
22
-WP_CLI::add_command( 'autoptimize', 'autoptimizeCLI' );
22
+WP_CLI::add_command('autoptimize', 'autoptimizeCLI');
Please login to merge, or discard this patch.
classlesses/autoptimizeCacheChecker.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if (!defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /* 
5 5
  * cachechecker code
@@ -13,39 +13,39 @@  discard block
 block discarded – undo
13 13
  */
14 14
 
15 15
 if (is_admin()) {
16
-    add_action('plugins_loaded','ao_cachechecker_setup');
16
+    add_action('plugins_loaded', 'ao_cachechecker_setup');
17 17
 }
18 18
 
19 19
 function ao_cachechecker_setup() {
20
-    $doCacheCheck = (bool) apply_filters( 'autoptimize_filter_cachecheck_do', true);
21
-    $cacheCheckSchedule = wp_get_schedule( 'ao_cachechecker' );
22
-    $AOCCfreq = apply_filters('autoptimize_filter_cachecheck_frequency','daily');
23
-    if (!in_array($AOCCfreq,array('hourly','daily','monthly'))) {
24
-        $AOCCfreq='daily';
20
+    $doCacheCheck = (bool) apply_filters('autoptimize_filter_cachecheck_do', true);
21
+    $cacheCheckSchedule = wp_get_schedule('ao_cachechecker');
22
+    $AOCCfreq = apply_filters('autoptimize_filter_cachecheck_frequency', 'daily');
23
+    if (!in_array($AOCCfreq, array('hourly', 'daily', 'monthly'))) {
24
+        $AOCCfreq = 'daily';
25 25
     }
26
-    if ( $doCacheCheck && ( !$cacheCheckSchedule || $cacheCheckSchedule !== $AOCCfreq ) ) {
26
+    if ($doCacheCheck && (!$cacheCheckSchedule || $cacheCheckSchedule !== $AOCCfreq)) {
27 27
         wp_schedule_event(time(), $AOCCfreq, 'ao_cachechecker');
28
-    } else if ( $cacheCheckSchedule && !$doCacheCheck ) {
29
-        wp_clear_scheduled_hook( 'ao_cachechecker' );
28
+    } else if ($cacheCheckSchedule && !$doCacheCheck) {
29
+        wp_clear_scheduled_hook('ao_cachechecker');
30 30
     }
31 31
 }
32 32
 
33 33
 add_action('ao_cachechecker', 'ao_cachechecker_cronjob');
34 34
 function ao_cachechecker_cronjob() {
35
-    $maxSize = (int) apply_filters( "autoptimize_filter_cachecheck_maxsize", 536870912);
36
-    $doCacheCheck = (bool) apply_filters( "autoptimize_filter_cachecheck_do", true);
37
-    $statArr=autoptimizeCache::stats(); 
38
-    $cacheSize=round($statArr[1]);
39
-    if (($cacheSize>$maxSize) && ($doCacheCheck)) {
40
-        update_option("autoptimize_cachesize_notice",true);
41
-        if (apply_filters('autoptimize_filter_cachecheck_sendmail',true)) {
42
-            $saniSiteUrl=esc_url(site_url());
43
-            $ao_mailto=apply_filters('autoptimize_filter_cachecheck_mailto',get_option('admin_email',''));
44
-            $ao_mailsubject=__('Autoptimize cache size warning','autoptimize')." (".$saniSiteUrl.")";
45
-            $ao_mailbody=__('Autoptimize\'s cache size is getting big, consider purging the cache. Have a look at https://wordpress.org/plugins/autoptimize/faq/ to see how you can keep the cache size under control.', 'autoptimize')." (site: ".$saniSiteUrl.")";
35
+    $maxSize = (int) apply_filters("autoptimize_filter_cachecheck_maxsize", 536870912);
36
+    $doCacheCheck = (bool) apply_filters("autoptimize_filter_cachecheck_do", true);
37
+    $statArr = autoptimizeCache::stats(); 
38
+    $cacheSize = round($statArr[1]);
39
+    if (($cacheSize > $maxSize) && ($doCacheCheck)) {
40
+        update_option("autoptimize_cachesize_notice", true);
41
+        if (apply_filters('autoptimize_filter_cachecheck_sendmail', true)) {
42
+            $saniSiteUrl = esc_url(site_url());
43
+            $ao_mailto = apply_filters('autoptimize_filter_cachecheck_mailto', get_option('admin_email', ''));
44
+            $ao_mailsubject = __('Autoptimize cache size warning', 'autoptimize')." (".$saniSiteUrl.")";
45
+            $ao_mailbody = __('Autoptimize\'s cache size is getting big, consider purging the cache. Have a look at https://wordpress.org/plugins/autoptimize/faq/ to see how you can keep the cache size under control.', 'autoptimize')." (site: ".$saniSiteUrl.")";
46 46
 
47 47
             if (!empty($ao_mailto)) {
48
-                $ao_mailresult=wp_mail($ao_mailto,$ao_mailsubject,$ao_mailbody);
48
+                $ao_mailresult = wp_mail($ao_mailto, $ao_mailsubject, $ao_mailbody);
49 49
                 if (!$ao_mailresult) {
50 50
                     error_log("Autoptimize could not send cache size warning mail.");
51 51
                 }
@@ -56,10 +56,10 @@  discard block
 block discarded – undo
56 56
 
57 57
 add_action('admin_notices', 'autoptimize_cachechecker_notice');
58 58
 function autoptimize_cachechecker_notice() {
59
-    if ((bool) get_option("autoptimize_cachesize_notice",false)) {
59
+    if ((bool) get_option("autoptimize_cachesize_notice", false)) {
60 60
         echo '<div class="notice notice-warning"><p>';
61
-        _e('<strong>Autoptimize\'s cache size is getting big</strong>, consider purging the cache. Have a look at <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank">the Autoptimize FAQ</a> to see how you can keep the cache size under control.', 'autoptimize' );
61
+        _e('<strong>Autoptimize\'s cache size is getting big</strong>, consider purging the cache. Have a look at <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank">the Autoptimize FAQ</a> to see how you can keep the cache size under control.', 'autoptimize');
62 62
         echo '</p></div>';
63
-        update_option("autoptimize_cachesize_notice",false);
63
+        update_option("autoptimize_cachesize_notice", false);
64 64
     }
65 65
 }
Please login to merge, or discard this patch.
classes/autoptimizeStyles.php 1 patch
Spacing   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if (!defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 class autoptimizeStyles extends autoptimizeBase {
5 5
 
@@ -23,12 +23,12 @@  discard block
 block discarded – undo
23 23
 
24 24
     //Reads the page and collects style tags
25 25
     public function read($options) {
26
-        $noptimizeCSS = apply_filters( 'autoptimize_filter_css_noptimize', false, $this->content );
26
+        $noptimizeCSS = apply_filters('autoptimize_filter_css_noptimize', false, $this->content);
27 27
         if ($noptimizeCSS) return false;
28 28
 
29
-        $whitelistCSS = apply_filters( 'autoptimize_filter_css_whitelist', '', $this->content );
29
+        $whitelistCSS = apply_filters('autoptimize_filter_css_whitelist', '', $this->content);
30 30
         if (!empty($whitelistCSS)) {
31
-            $this->whitelist = array_filter(array_map('trim',explode(",",$whitelistCSS)));
31
+            $this->whitelist = array_filter(array_map('trim', explode(",", $whitelistCSS)));
32 32
         }
33 33
         
34 34
         if ($options['nogooglefont'] == true) {
@@ -36,54 +36,54 @@  discard block
 block discarded – undo
36 36
         } else {
37 37
             $removableCSS = "";
38 38
         }
39
-        $removableCSS = apply_filters( 'autoptimize_filter_css_removables', $removableCSS);
39
+        $removableCSS = apply_filters('autoptimize_filter_css_removables', $removableCSS);
40 40
         if (!empty($removableCSS)) {
41
-            $this->cssremovables = array_filter(array_map('trim',explode(",",$removableCSS)));
41
+            $this->cssremovables = array_filter(array_map('trim', explode(",", $removableCSS)));
42 42
         }
43 43
 
44
-        $this->cssinlinesize = apply_filters('autoptimize_filter_css_inlinesize',256);
44
+        $this->cssinlinesize = apply_filters('autoptimize_filter_css_inlinesize', 256);
45 45
 
46 46
         // filter to "late inject minified CSS", default to true for now (it is faster)
47
-        $this->inject_min_late = apply_filters('autoptimize_filter_css_inject_min_late',true);
47
+        $this->inject_min_late = apply_filters('autoptimize_filter_css_inject_min_late', true);
48 48
 
49 49
         // Remove everything that's not the header
50
-        if ( apply_filters('autoptimize_filter_css_justhead',$options['justhead']) == true ) {
51
-            $content = explode('</head>',$this->content,2);
50
+        if (apply_filters('autoptimize_filter_css_justhead', $options['justhead']) == true) {
51
+            $content = explode('</head>', $this->content, 2);
52 52
             $this->content = $content[0].'</head>';
53 53
             $this->restofcontent = $content[1];
54 54
         }
55 55
 
56 56
         // include inline?
57
-        if( apply_filters('autoptimize_css_include_inline',$options['include_inline']) == true ) {
57
+        if (apply_filters('autoptimize_css_include_inline', $options['include_inline']) == true) {
58 58
             $this->include_inline = true;
59 59
         }
60 60
         
61 61
         // what CSS shouldn't be autoptimized
62 62
         $excludeCSS = $options['css_exclude'];
63
-        $excludeCSS = apply_filters( 'autoptimize_filter_css_exclude', $excludeCSS, $this->content );
64
-        if ($excludeCSS!=="") {
65
-            $this->dontmove = array_filter(array_map('trim',explode(",",$excludeCSS)));
63
+        $excludeCSS = apply_filters('autoptimize_filter_css_exclude', $excludeCSS, $this->content);
64
+        if ($excludeCSS !== "") {
65
+            $this->dontmove = array_filter(array_map('trim', explode(",", $excludeCSS)));
66 66
         } else {
67 67
             $this->dontmove = array();
68 68
         }
69 69
         
70 70
         // forcefully exclude CSS with data-noptimize attrib
71
-        $this->dontmove[]="data-noptimize";
71
+        $this->dontmove[] = "data-noptimize";
72 72
 
73 73
         // should we defer css?
74 74
         // value: true/ false
75 75
         $this->defer = $options['defer'];
76
-        $this->defer = apply_filters( 'autoptimize_filter_css_defer', $this->defer, $this->content );
76
+        $this->defer = apply_filters('autoptimize_filter_css_defer', $this->defer, $this->content);
77 77
 
78 78
         // should we inline while deferring?
79 79
         // value: inlined CSS
80 80
         $this->defer_inline = $options['defer_inline'];
81
-        $this->defer_inline = apply_filters( 'autoptimize_filter_css_defer_inline', $this->defer_inline, $this->content );
81
+        $this->defer_inline = apply_filters('autoptimize_filter_css_defer_inline', $this->defer_inline, $this->content);
82 82
 
83 83
         // should we inline?
84 84
         // value: true/ false
85 85
         $this->inline = $options['inline'];
86
-        $this->inline = apply_filters( 'autoptimize_filter_css_inline', $this->inline, $this->content );
86
+        $this->inline = apply_filters('autoptimize_filter_css_inline', $this->inline, $this->content);
87 87
         
88 88
         // get cdn url
89 89
         $this->cdn_url = $options['cdn_url'];
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
         $this->content = $this->hide_noptimize($this->content);
96 96
         
97 97
         // exclude (no)script, as those may contain CSS which should be left as is
98
-        if ( strpos( $this->content, '<script' ) !== false ) { 
98
+        if (strpos($this->content, '<script') !== false) { 
99 99
             $this->content = preg_replace_callback(
100 100
                 '#<(?:no)?script.*?<\/(?:no)?script>#is',
101 101
                 create_function(
@@ -113,65 +113,65 @@  discard block
 block discarded – undo
113 113
         $this->content = $this->hide_comments($this->content);
114 114
         
115 115
         // Get <style> and <link>
116
-        if(preg_match_all('#(<style[^>]*>.*</style>)|(<link[^>]*stylesheet[^>]*>)#Usmi',$this->content,$matches)) {
117
-            foreach($matches[0] as $tag) {
118
-                if ($this->isremovable($tag,$this->cssremovables)) {
119
-                    $this->content = str_replace($tag,'',$this->content);
116
+        if (preg_match_all('#(<style[^>]*>.*</style>)|(<link[^>]*stylesheet[^>]*>)#Usmi', $this->content, $matches)) {
117
+            foreach ($matches[0] as $tag) {
118
+                if ($this->isremovable($tag, $this->cssremovables)) {
119
+                    $this->content = str_replace($tag, '', $this->content);
120 120
                 } else if ($this->ismovable($tag)) {
121 121
                     // Get the media
122
-                    if(strpos($tag,'media=')!==false) {
123
-                        preg_match('#media=(?:"|\')([^>]*)(?:"|\')#Ui',$tag,$medias);
124
-                        $medias = explode(',',$medias[1]);
122
+                    if (strpos($tag, 'media=') !== false) {
123
+                        preg_match('#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $medias);
124
+                        $medias = explode(',', $medias[1]);
125 125
                         $media = array();
126
-                        foreach($medias as $elem) {
127
-                            if (empty($elem)) { $elem="all"; }
126
+                        foreach ($medias as $elem) {
127
+                            if (empty($elem)) { $elem = "all"; }
128 128
                             $media[] = $elem;
129 129
                         }
130 130
                     } else {
131 131
                         // No media specified - applies to all
132 132
                         $media = array('all');
133 133
                     }
134
-                    $media = apply_filters( 'autoptimize_filter_css_tagmedia',$media,$tag );
134
+                    $media = apply_filters('autoptimize_filter_css_tagmedia', $media, $tag);
135 135
                 
136
-                    if(preg_match('#<link.*href=("|\')(.*)("|\')#Usmi',$tag,$source)) {
136
+                    if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source)) {
137 137
                         // <link>
138
-                        $explUrl = explode('?',$source[2],2);
138
+                        $explUrl = explode('?', $source[2], 2);
139 139
                         $url = $explUrl[0];
140 140
                         $path = $this->getpath($url);
141 141
                         
142
-                        if($path!==false && preg_match('#\.css$#',$path)) {
142
+                        if ($path !== false && preg_match('#\.css$#', $path)) {
143 143
                             // Good link
144
-                            $this->css[] = array($media,$path);
145
-                        }else{
144
+                            $this->css[] = array($media, $path);
145
+                        } else {
146 146
                             // Link is dynamic (.php etc)
147 147
                             $tag = '';
148 148
                         }
149 149
                     } else {
150 150
                         // inline css in style tags can be wrapped in comment tags, so restore comments
151 151
                         $tag = $this->restore_comments($tag);
152
-                        preg_match('#<style.*>(.*)</style>#Usmi',$tag,$code);
152
+                        preg_match('#<style.*>(.*)</style>#Usmi', $tag, $code);
153 153
 
154 154
                         // and re-hide them to be able to to the removal based on tag
155 155
                         $tag = $this->hide_comments($tag);
156 156
 
157
-                        if ( $this->include_inline ) {
158
-                            $code = preg_replace('#^.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*$#sm','$1',$code[1]);
159
-                            $this->css[] = array($media,'INLINE;'.$code);
157
+                        if ($this->include_inline) {
158
+                            $code = preg_replace('#^.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*$#sm', '$1', $code[1]);
159
+                            $this->css[] = array($media, 'INLINE;'.$code);
160 160
                         } else {
161 161
                             $tag = '';
162 162
                         }
163 163
                     }
164 164
                     
165 165
                     // Remove the original style tag
166
-                    $this->content = str_replace($tag,'',$this->content);
166
+                    $this->content = str_replace($tag, '', $this->content);
167 167
                 } else {
168 168
 					// excluded CSS, minify if getpath 
169
-					if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi',$tag,$source)) {
170
-						$explUrl = explode('?',$source[2],2);
169
+					if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source)) {
170
+						$explUrl = explode('?', $source[2], 2);
171 171
                         $url = $explUrl[0];
172 172
                         $path = $this->getpath($url);
173 173
  					
174
-						if ($path && apply_filters('autoptimize_filter_css_minify_excluded',false)) {
174
+						if ($path && apply_filters('autoptimize_filter_css_minify_excluded', false)) {
175 175
 							$_CachedMinifiedUrl = $this->minify_single($path);
176 176
 
177 177
 							if (!empty($_CachedMinifiedUrl)) {
@@ -182,12 +182,12 @@  discard block
 block discarded – undo
182 182
 							}
183 183
 							
184 184
 							// remove querystring from URL
185
-							if ( !empty($explUrl[1]) ) {
186
-								$newTag = str_replace("?".$explUrl[1],"",$newTag);
185
+							if (!empty($explUrl[1])) {
186
+								$newTag = str_replace("?".$explUrl[1], "", $newTag);
187 187
 							}
188 188
 
189 189
 							// and replace
190
-							$this->content = str_replace($tag,$newTag,$this->content);
190
+							$this->content = str_replace($tag, $newTag, $this->content);
191 191
 						}
192 192
 					}					
193 193
 				}
@@ -200,31 +200,31 @@  discard block
 block discarded – undo
200 200
     
201 201
     // Joins and optimizes CSS
202 202
     public function minify() {
203
-        foreach($this->css as $group) {
204
-            list($media,$css) = $group;
205
-            if(preg_match('#^INLINE;#',$css)) {
203
+        foreach ($this->css as $group) {
204
+            list($media, $css) = $group;
205
+            if (preg_match('#^INLINE;#', $css)) {
206 206
                 // <style>
207
-                $css = preg_replace('#^INLINE;#','',$css);
208
-                $css = $this->fixurls(ABSPATH.'/index.php',$css);
209
-                $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $css, "" );
210
-                if ( has_filter('autoptimize_css_individual_style') && !empty($tmpstyle) ) {
211
-                    $css=$tmpstyle;
212
-                    $this->alreadyminified=true;
207
+                $css = preg_replace('#^INLINE;#', '', $css);
208
+                $css = $this->fixurls(ABSPATH.'/index.php', $css);
209
+                $tmpstyle = apply_filters('autoptimize_css_individual_style', $css, "");
210
+                if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) {
211
+                    $css = $tmpstyle;
212
+                    $this->alreadyminified = true;
213 213
                 }
214 214
             } else {
215 215
                 //<link>
216
-                if($css !== false && file_exists($css) && is_readable($css)) {
216
+                if ($css !== false && file_exists($css) && is_readable($css)) {
217 217
                     $cssPath = $css;
218 218
                     $cssContents = file_get_contents($cssPath);
219 219
                     $cssHash = md5($cssContents);
220
-                    $css = $this->fixurls($cssPath,$cssContents);
221
-                    $css = preg_replace('/\x{EF}\x{BB}\x{BF}/','',$css);
222
-                    $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $css, $cssPath );
220
+                    $css = $this->fixurls($cssPath, $cssContents);
221
+                    $css = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $css);
222
+                    $tmpstyle = apply_filters('autoptimize_css_individual_style', $css, $cssPath);
223 223
                     if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) {
224
-                        $css=$tmpstyle;
225
-                        $this->alreadyminified=true;
226
-                    } else if ($this->can_inject_late($cssPath,$css)) {
227
-                        $css="/*!%%INJECTLATER%%".base64_encode($cssPath)."|".$cssHash."%%INJECTLATER%%*/";
224
+                        $css = $tmpstyle;
225
+                        $this->alreadyminified = true;
226
+                    } else if ($this->can_inject_late($cssPath, $css)) {
227
+                        $css = "/*!%%INJECTLATER%%".base64_encode($cssPath)."|".$cssHash."%%INJECTLATER%%*/";
228 228
                     }
229 229
                 } else {
230 230
                     // Couldn't read CSS. Maybe getpath isn't working?
@@ -232,8 +232,8 @@  discard block
 block discarded – undo
232 232
                 }
233 233
             }
234 234
             
235
-            foreach($media as $elem) {
236
-                if(!isset($this->csscode[$elem]))
235
+            foreach ($media as $elem) {
236
+                if (!isset($this->csscode[$elem]))
237 237
                     $this->csscode[$elem] = '';
238 238
                 $this->csscode[$elem] .= "\n/*FILESTART*/".$css;
239 239
             }
@@ -242,12 +242,12 @@  discard block
 block discarded – undo
242 242
         // Check for duplicate code
243 243
         $md5list = array();
244 244
         $tmpcss = $this->csscode;
245
-        foreach($tmpcss as $media => $code) {
245
+        foreach ($tmpcss as $media => $code) {
246 246
             $md5sum = md5($code);
247 247
             $medianame = $media;
248
-            foreach($md5list as $med => $sum) {
248
+            foreach ($md5list as $med => $sum) {
249 249
                 // If same code
250
-                if($sum === $md5sum) {
250
+                if ($sum === $md5sum) {
251 251
                     //Add the merged code
252 252
                     $medianame = $med.', '.$media;
253 253
                     $this->csscode[$medianame] = $code;
@@ -267,30 +267,30 @@  discard block
 block discarded – undo
267 267
             $external_imports = "";
268 268
 
269 269
             // remove comments to avoid importing commented-out imports
270
-            $thiscss_nocomments = preg_replace('#/\*.*\*/#Us','',$thiscss);
270
+            $thiscss_nocomments = preg_replace('#/\*.*\*/#Us', '', $thiscss);
271 271
 
272
-            while(preg_match_all('#@import +(?:url)?(?:(?:\\(([\"\']?)(?:[^\"\')]+)\\1\\)|([\"\'])(?:[^\"\']+)\\2)(?:[^,;\"\']+(?:,[^,;\"\']+)*)?)(?:;)#m',$thiscss_nocomments,$matches)) {
273
-                foreach($matches[0] as $import)    {
274
-                    if ($this->isremovable($import,$this->cssremovables)) {
275
-                        $thiscss = str_replace($import,'',$thiscss);
272
+            while (preg_match_all('#@import +(?:url)?(?:(?:\\(([\"\']?)(?:[^\"\')]+)\\1\\)|([\"\'])(?:[^\"\']+)\\2)(?:[^,;\"\']+(?:,[^,;\"\']+)*)?)(?:;)#m', $thiscss_nocomments, $matches)) {
273
+                foreach ($matches[0] as $import) {
274
+                    if ($this->isremovable($import, $this->cssremovables)) {
275
+                        $thiscss = str_replace($import, '', $thiscss);
276 276
                         $import_ok = true;
277 277
                     } else {
278
-                        $url = trim(preg_replace('#^.*((?:https?:|ftp:)?//.*\.css).*$#','$1',trim($import))," \t\n\r\0\x0B\"'");
278
+                        $url = trim(preg_replace('#^.*((?:https?:|ftp:)?//.*\.css).*$#', '$1', trim($import)), " \t\n\r\0\x0B\"'");
279 279
                         $path = $this->getpath($url);
280 280
                         $import_ok = false;
281 281
                         if (file_exists($path) && is_readable($path)) {
282
-                            $code = addcslashes($this->fixurls($path,file_get_contents($path)),"\\");
283
-                            $code = preg_replace('/\x{EF}\x{BB}\x{BF}/','',$code);
284
-                            $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $code, "" );
285
-                            if ( has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) {
286
-                                $code=$tmpstyle;
287
-                                $this->alreadyminified=true;
288
-                            } else if ($this->can_inject_late($path,$code)) {
289
-                                $code="/*!%%INJECTLATER".AUTOPTIMIZE_HASH."%%".base64_encode($path)."|".md5($code)."%%INJECTLATER%%*/";
282
+                            $code = addcslashes($this->fixurls($path, file_get_contents($path)), "\\");
283
+                            $code = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $code);
284
+                            $tmpstyle = apply_filters('autoptimize_css_individual_style', $code, "");
285
+                            if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) {
286
+                                $code = $tmpstyle;
287
+                                $this->alreadyminified = true;
288
+                            } else if ($this->can_inject_late($path, $code)) {
289
+                                $code = "/*!%%INJECTLATER".AUTOPTIMIZE_HASH."%%".base64_encode($path)."|".md5($code)."%%INJECTLATER%%*/";
290 290
                             }
291 291
                             
292
-                            if(!empty($code)) {
293
-                                $tmp_thiscss = preg_replace('#(/\*FILESTART\*/.*)'.preg_quote($import,'#').'#Us','/*FILESTART2*/'.$code.'$1',$thiscss);
292
+                            if (!empty($code)) {
293
+                                $tmp_thiscss = preg_replace('#(/\*FILESTART\*/.*)'.preg_quote($import, '#').'#Us', '/*FILESTART2*/'.$code.'$1', $thiscss);
294 294
                                 if (!empty($tmp_thiscss)) {
295 295
                                     $thiscss = $tmp_thiscss;
296 296
                                     $import_ok = true;
@@ -304,32 +304,32 @@  discard block
 block discarded – undo
304 304
                     if (!$import_ok) {
305 305
                         // external imports and general fall-back
306 306
                         $external_imports .= $import;
307
-                        $thiscss = str_replace($import,'',$thiscss);
307
+                        $thiscss = str_replace($import, '', $thiscss);
308 308
                         $fiximports = true;
309 309
                     }
310 310
                 }
311
-                $thiscss = preg_replace('#/\*FILESTART\*/#','',$thiscss);
312
-                $thiscss = preg_replace('#/\*FILESTART2\*/#','/*FILESTART*/',$thiscss);
311
+                $thiscss = preg_replace('#/\*FILESTART\*/#', '', $thiscss);
312
+                $thiscss = preg_replace('#/\*FILESTART2\*/#', '/*FILESTART*/', $thiscss);
313 313
                 
314 314
                 // and update $thiscss_nocomments before going into next iteration in while loop
315
-                $thiscss_nocomments=preg_replace('#/\*.*\*/#Us','',$thiscss);
315
+                $thiscss_nocomments = preg_replace('#/\*.*\*/#Us', '', $thiscss);
316 316
             }
317 317
             unset($thiscss_nocomments);
318 318
             
319 319
             // add external imports to top of aggregated CSS
320
-            if($fiximports) {
321
-                $thiscss=$external_imports.$thiscss;
320
+            if ($fiximports) {
321
+                $thiscss = $external_imports.$thiscss;
322 322
             }
323 323
         }
324 324
         unset($thiscss);
325 325
         
326 326
         // $this->csscode has all the uncompressed code now. 
327
-        foreach($this->csscode as &$code) {
327
+        foreach ($this->csscode as &$code) {
328 328
             // Check for already-minified code
329 329
             $hash = md5($code);
330
-            do_action( 'autoptimize_action_css_hash', $hash );
331
-            $ccheck = new autoptimizeCache($hash,'css');
332
-            if($ccheck->check()) {
330
+            do_action('autoptimize_action_css_hash', $hash);
331
+            $ccheck = new autoptimizeCache($hash, 'css');
332
+            if ($ccheck->check()) {
333 333
                 $code = $ccheck->retrieve();
334 334
                 $this->hashmap[md5($code)] = $hash;
335 335
                 continue;
@@ -338,44 +338,44 @@  discard block
 block discarded – undo
338 338
 
339 339
             // Do the imaging!
340 340
             $imgreplace = array();
341
-            preg_match_all( self::ASSETS_REGEX, $code, $matches );
341
+            preg_match_all(self::ASSETS_REGEX, $code, $matches);
342 342
 
343
-            if ( ($this->datauris == true) && (function_exists('base64_encode')) && (is_array($matches)) ) {
344
-                foreach($matches[1] as $count => $quotedurl) {
345
-                    $iurl = trim($quotedurl," \t\n\r\0\x0B\"'");
343
+            if (($this->datauris == true) && (function_exists('base64_encode')) && (is_array($matches))) {
344
+                foreach ($matches[1] as $count => $quotedurl) {
345
+                    $iurl = trim($quotedurl, " \t\n\r\0\x0B\"'");
346 346
 
347 347
                     // if querystring, remove it from url
348
-                    if (strpos($iurl,'?') !== false) { $iurl = strtok($iurl,'?'); }
348
+                    if (strpos($iurl, '?') !== false) { $iurl = strtok($iurl, '?'); }
349 349
                     
350 350
                     $ipath = $this->getpath($iurl);
351 351
 
352 352
                     $datauri_max_size = 4096;
353
-                    $datauri_max_size = (int) apply_filters( 'autoptimize_filter_css_datauri_maxsize', $datauri_max_size );
354
-                    $datauri_exclude = apply_filters( 'autoptimize_filter_css_datauri_exclude', "");
353
+                    $datauri_max_size = (int) apply_filters('autoptimize_filter_css_datauri_maxsize', $datauri_max_size);
354
+                    $datauri_exclude = apply_filters('autoptimize_filter_css_datauri_exclude', "");
355 355
                     if (!empty($datauri_exclude)) {
356
-                        $no_datauris=array_filter(array_map('trim',explode(",",$datauri_exclude)));
356
+                        $no_datauris = array_filter(array_map('trim', explode(",", $datauri_exclude)));
357 357
                         foreach ($no_datauris as $no_datauri) {
358
-                            if (strpos($iurl,$no_datauri)!==false) {
359
-                                $ipath=false;
358
+                            if (strpos($iurl, $no_datauri) !== false) {
359
+                                $ipath = false;
360 360
                                 break;
361 361
                             }
362 362
                         }
363 363
                     }
364 364
 
365
-                    if($ipath != false && preg_match('#\.(jpe?g|png|gif|bmp)$#i',$ipath) && file_exists($ipath) && is_readable($ipath) && filesize($ipath) <= $datauri_max_size) {
366
-                        $ihash=md5($ipath);
367
-                        $icheck = new autoptimizeCache($ihash,'img');
368
-                        if($icheck->check()) {
365
+                    if ($ipath != false && preg_match('#\.(jpe?g|png|gif|bmp)$#i', $ipath) && file_exists($ipath) && is_readable($ipath) && filesize($ipath) <= $datauri_max_size) {
366
+                        $ihash = md5($ipath);
367
+                        $icheck = new autoptimizeCache($ihash, 'img');
368
+                        if ($icheck->check()) {
369 369
                             // we have the base64 image in cache
370
-                            $headAndData=$icheck->retrieve();
371
-                            $_base64data=explode(";base64,",$headAndData);
372
-                            $base64data=$_base64data[1];
370
+                            $headAndData = $icheck->retrieve();
371
+                            $_base64data = explode(";base64,", $headAndData);
372
+                            $base64data = $_base64data[1];
373 373
                         } else {
374 374
                             // It's an image and we don't have it in cache, get the type
375
-                            $explA=explode('.',$ipath);
376
-                            $type=end($explA);
375
+                            $explA = explode('.', $ipath);
376
+                            $type = end($explA);
377 377
 
378
-                            switch($type) {
378
+                            switch ($type) {
379 379
                                 case 'jpeg':
380 380
                                     $dataurihead = 'data:image/jpeg;base64,';
381 381
                                     break;
@@ -397,42 +397,42 @@  discard block
 block discarded – undo
397 397
                         
398 398
                             // Encode the data
399 399
                             $base64data = base64_encode(file_get_contents($ipath));
400
-                            $headAndData=$dataurihead.$base64data;
400
+                            $headAndData = $dataurihead.$base64data;
401 401
 
402 402
                             // Save in cache
403
-                            $icheck->cache($headAndData,"text/plain");
403
+                            $icheck->cache($headAndData, "text/plain");
404 404
                         }
405 405
                         unset($icheck);
406 406
 
407 407
                         // Add it to the list for replacement
408
-                        $imgreplace[$matches[0][$count]] = str_replace($quotedurl,$headAndData,$matches[0][$count]);
408
+                        $imgreplace[$matches[0][$count]] = str_replace($quotedurl, $headAndData, $matches[0][$count]);
409 409
                     } else {
410 410
                         // just cdn the URL if applicable
411 411
                         if (!empty($this->cdn_url)) {
412
-                            $imgreplace[$matches[0][$count]] = str_replace($quotedurl,$this->maybe_cdn_urls($quotedurl),$matches[0][$count]);
412
+                            $imgreplace[$matches[0][$count]] = str_replace($quotedurl, $this->maybe_cdn_urls($quotedurl), $matches[0][$count]);
413 413
 						}
414 414
                     }
415 415
                 }
416 416
             } else if ((is_array($matches)) && (!empty($this->cdn_url))) {
417 417
                 // change urls to cdn-url
418
-                foreach($matches[1] as $count => $quotedurl) {
419
-                    $imgreplace[$matches[0][$count]] = str_replace($quotedurl,$this->maybe_cdn_urls($quotedurl),$matches[0][$count]);
418
+                foreach ($matches[1] as $count => $quotedurl) {
419
+                    $imgreplace[$matches[0][$count]] = str_replace($quotedurl, $this->maybe_cdn_urls($quotedurl), $matches[0][$count]);
420 420
                 }
421 421
             }
422 422
             
423
-            if(!empty($imgreplace)) {
424
-                $code = str_replace(array_keys($imgreplace),array_values($imgreplace),$code);
423
+            if (!empty($imgreplace)) {
424
+                $code = str_replace(array_keys($imgreplace), array_values($imgreplace), $code);
425 425
             }
426 426
             
427 427
             // Minify
428
-            if (($this->alreadyminified!==true) && (apply_filters( "autoptimize_css_do_minify", true))) {
428
+            if (($this->alreadyminified !== true) && (apply_filters("autoptimize_css_do_minify", true))) {
429 429
                 if (class_exists('Minify_CSS_Compressor')) {
430 430
                     $tmp_code = trim(Minify_CSS_Compressor::process($code));
431
-                } else if(class_exists('CSSmin')) {
431
+                } else if (class_exists('CSSmin')) {
432 432
                     $cssmin = new CSSmin();
433
-                    if (method_exists($cssmin,"run")) {
433
+                    if (method_exists($cssmin, "run")) {
434 434
                         $tmp_code = trim($cssmin->run($code));
435
-                    } elseif (@is_callable(array($cssmin,"minify"))) {
435
+                    } elseif (@is_callable(array($cssmin, "minify"))) {
436 436
                         $tmp_code = trim(CssMin::minify($code));
437 437
                     }
438 438
                 }
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
             
445 445
             $code = $this->inject_minified($code);
446 446
             
447
-            $tmp_code = apply_filters( 'autoptimize_css_after_minify', $code );
447
+            $tmp_code = apply_filters('autoptimize_css_after_minify', $code);
448 448
             if (!empty($tmp_code)) {
449 449
                 $code = $tmp_code;
450 450
                 unset($tmp_code);
@@ -459,13 +459,13 @@  discard block
 block discarded – undo
459 459
     //Caches the CSS in uncompressed, deflated and gzipped form.
460 460
     public function cache() {
461 461
         // CSS cache
462
-        foreach($this->csscode as $media => $code) {
462
+        foreach ($this->csscode as $media => $code) {
463 463
             $md5 = $this->hashmap[md5($code)];
464 464
                 
465
-            $cache = new autoptimizeCache($md5,'css');
466
-            if(!$cache->check()) {
465
+            $cache = new autoptimizeCache($md5, 'css');
466
+            if (!$cache->check()) {
467 467
                 // Cache our code
468
-                $cache->cache($code,'text/css');
468
+                $cache->cache($code, 'text/css');
469 469
             }
470 470
             $this->url[$media] = AUTOPTIMIZE_CACHE_URL.$cache->getname();
471 471
         }
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
         $this->content = $this->restore_comments($this->content);
481 481
         
482 482
         // restore (no)script
483
-        if ( strpos( $this->content, '%%SCRIPT%%' ) !== false ) { 
483
+        if (strpos($this->content, '%%SCRIPT%%') !== false) { 
484 484
             $this->content = preg_replace_callback(
485 485
                 '#%%SCRIPT'.AUTOPTIMIZE_HASH.'%%(.*?)%%SCRIPT%%#is',
486 486
                 create_function(
@@ -495,55 +495,55 @@  discard block
 block discarded – undo
495 495
         $this->content = $this->restore_noptimize($this->content);
496 496
         
497 497
         //Restore the full content
498
-        if(!empty($this->restofcontent)) {
498
+        if (!empty($this->restofcontent)) {
499 499
             $this->content .= $this->restofcontent;
500 500
             $this->restofcontent = '';
501 501
         }
502 502
         
503 503
         // Inject the new stylesheets
504
-        $replaceTag = array("<title","before");
505
-        $replaceTag = apply_filters( 'autoptimize_filter_css_replacetag', $replaceTag, $this->content );
504
+        $replaceTag = array("<title", "before");
505
+        $replaceTag = apply_filters('autoptimize_filter_css_replacetag', $replaceTag, $this->content);
506 506
 
507 507
         if ($this->inline == true) {
508
-            foreach($this->csscode as $media => $code) {
509
-                $this->inject_in_html('<style type="text/css" media="'.$media.'">'.$code.'</style>',$replaceTag);
508
+            foreach ($this->csscode as $media => $code) {
509
+                $this->inject_in_html('<style type="text/css" media="'.$media.'">'.$code.'</style>', $replaceTag);
510 510
             }
511 511
         } else {
512 512
             if ($this->defer == true) {
513 513
                 $preloadCssBlock = "";
514 514
                 $noScriptCssBlock = "<noscript id=\"aonoscrcss\">";
515
-                $defer_inline_code=$this->defer_inline;
516
-                if(!empty($defer_inline_code)){
517
-                    if ( apply_filters( 'autoptimize_filter_css_critcss_minify', true ) ) {
515
+                $defer_inline_code = $this->defer_inline;
516
+                if (!empty($defer_inline_code)) {
517
+                    if (apply_filters('autoptimize_filter_css_critcss_minify', true)) {
518 518
                         $iCssHash = md5($defer_inline_code);
519
-                        $iCssCache = new autoptimizeCache($iCssHash,'css');
520
-                        if($iCssCache->check()) { 
519
+                        $iCssCache = new autoptimizeCache($iCssHash, 'css');
520
+                        if ($iCssCache->check()) { 
521 521
                             // we have the optimized inline CSS in cache
522
-                            $defer_inline_code=$iCssCache->retrieve();
522
+                            $defer_inline_code = $iCssCache->retrieve();
523 523
                         } else {
524 524
                             if (class_exists('Minify_CSS_Compressor')) {
525 525
                                 $tmp_code = trim(Minify_CSS_Compressor::process($defer_inline_code));
526
-                            } else if(class_exists('CSSmin')) {
526
+                            } else if (class_exists('CSSmin')) {
527 527
                                 $cssmin = new CSSmin();
528 528
                                 $tmp_code = trim($cssmin->run($defer_inline_code));
529 529
                             }
530 530
                             if (!empty($tmp_code)) {
531 531
                                 $defer_inline_code = $tmp_code;
532
-                                $iCssCache->cache($defer_inline_code,"text/css");
532
+                                $iCssCache->cache($defer_inline_code, "text/css");
533 533
                                 unset($tmp_code);
534 534
                             }
535 535
                         }
536 536
                     }
537
-                    $code_out='<style type="text/css" id="aoatfcss" media="all">'.$defer_inline_code.'</style>';
538
-                    $this->inject_in_html($code_out,$replaceTag);
537
+                    $code_out = '<style type="text/css" id="aoatfcss" media="all">'.$defer_inline_code.'</style>';
538
+                    $this->inject_in_html($code_out, $replaceTag);
539 539
                 }
540 540
             }
541 541
 
542
-            foreach($this->url as $media => $url) {
542
+            foreach ($this->url as $media => $url) {
543 543
                 $url = $this->url_replace_cdn($url);
544 544
                 
545 545
                 //Add the stylesheet either deferred (import at bottom) or normal links in head
546
-                if($this->defer == true) {
546
+                if ($this->defer == true) {
547 547
                     
548 548
                     // Filter to modify the onload attribute - passes value and the stylesheet url
549 549
                     $preloadOnLoad = apply_filters('autoptimize_filter_css_preload_onload', "this.rel='stylesheet'", $url);
@@ -553,25 +553,25 @@  discard block
 block discarded – undo
553 553
                     
554 554
                 } else {
555 555
                     if (strlen($this->csscode[$media]) > $this->cssinlinesize) {
556
-                        $this->inject_in_html('<link type="text/css" media="'.$media.'" href="'.$url.'" rel="stylesheet" />',$replaceTag);
557
-                    } else if (strlen($this->csscode[$media])>0) {
558
-                        $this->inject_in_html('<style type="text/css" media="'.$media.'">'.$this->csscode[$media].'</style>',$replaceTag);
556
+                        $this->inject_in_html('<link type="text/css" media="'.$media.'" href="'.$url.'" rel="stylesheet" />', $replaceTag);
557
+                    } else if (strlen($this->csscode[$media]) > 0) {
558
+                        $this->inject_in_html('<style type="text/css" media="'.$media.'">'.$this->csscode[$media].'</style>', $replaceTag);
559 559
                     }
560 560
                 }
561 561
             }
562 562
             
563
-            if($this->defer == true) {
563
+            if ($this->defer == true) {
564 564
                 $preloadPolyfill = '<script data-cfasync=\'false\'>/*! loadCSS. [c]2017 Filament Group, Inc. MIT License */
565 565
 !function(a){"use strict";var b=function(b,c,d){function e(a){return h.body?a():void setTimeout(function(){e(a)})}function f(){i.addEventListener&&i.removeEventListener("load",f),i.media=d||"all"}var g,h=a.document,i=h.createElement("link");if(c)g=c;else{var j=(h.body||h.getElementsByTagName("head")[0]).childNodes;g=j[j.length-1]}var k=h.styleSheets;i.rel="stylesheet",i.href=b,i.media="only x",e(function(){g.parentNode.insertBefore(i,c?g:g.nextSibling)});var l=function(a){for(var b=i.href,c=k.length;c--;)if(k[c].href===b)return a();setTimeout(function(){l(a)})};return i.addEventListener&&i.addEventListener("load",f),i.onloadcssdefined=l,l(f),i};"undefined"!=typeof exports?exports.loadCSS=b:a.loadCSS=b}("undefined"!=typeof global?global:this);
566 566
 /*! loadCSS rel=preload polyfill. [c]2017 Filament Group, Inc. MIT License */
567 567
 !function(a){if(a.loadCSS){var b=loadCSS.relpreload={};if(b.support=function(){try{return a.document.createElement("link").relList.supports("preload")}catch(b){return!1}},b.poly=function(){for(var b=a.document.getElementsByTagName("link"),c=0;c<b.length;c++){var d=b[c];"preload"===d.rel&&"style"===d.getAttribute("as")&&(a.loadCSS(d.href,d,d.getAttribute("media")),d.rel=null)}},!b.support()){b.poly();var c=a.setInterval(b.poly,300);a.addEventListener&&a.addEventListener("load",function(){b.poly(),a.clearInterval(c)}),a.attachEvent&&a.attachEvent("onload",function(){a.clearInterval(c)})}}}(this);</script>';
568 568
                 $noScriptCssBlock .= "</noscript>";
569
-                $this->inject_in_html($preloadCssBlock.$noScriptCssBlock,$replaceTag);
569
+                $this->inject_in_html($preloadCssBlock.$noScriptCssBlock, $replaceTag);
570 570
                 
571 571
                 // Adds preload polyfill at end of body tag
572 572
                 $this->inject_in_html(
573 573
                     apply_filters('autoptimize_css_preload_polyfill', $preloadPolyfill),
574
-                    array('</body>','before')
574
+                    array('</body>', 'before')
575 575
                 );
576 576
             }
577 577
         }
@@ -582,62 +582,62 @@  discard block
 block discarded – undo
582 582
     
583 583
     static function fixurls($file, $code) {
584 584
         // Switch all imports to the url() syntax
585
-        $code = preg_replace( '#@import ("|\')(.+?)\.css.*?("|\')#', '@import url("${2}.css")', $code );
585
+        $code = preg_replace('#@import ("|\')(.+?)\.css.*?("|\')#', '@import url("${2}.css")', $code);
586 586
 
587
-        if ( preg_match_all( self::ASSETS_REGEX, $code, $matches ) ) {
588
-            $file = str_replace( WP_ROOT_DIR, '/', $file );
589
-            $dir = dirname( $file ); // Like /themes/expound/css
587
+        if (preg_match_all(self::ASSETS_REGEX, $code, $matches)) {
588
+            $file = str_replace(WP_ROOT_DIR, '/', $file);
589
+            $dir = dirname($file); // Like /themes/expound/css
590 590
 
591 591
             // $dir should not contain backslashes, since it's used to replace
592 592
             // urls, but it can contain them when running on Windows because
593 593
             // fixurls() is sometimes called with `ABSPATH . 'index.php'`
594
-            $dir = str_replace( '\\', '/', $dir );
595
-            unset( $file ); // not used below at all
594
+            $dir = str_replace('\\', '/', $dir);
595
+            unset($file); // not used below at all
596 596
 
597 597
             $replace = array();
598
-            foreach ( $matches[1] as $k => $url ) {
598
+            foreach ($matches[1] as $k => $url) {
599 599
                 // Remove quotes
600
-                $url    = trim( $url," \t\n\r\0\x0B\"'" );
601
-                $noQurl = trim( $url, "\"'" );
602
-                if ( $url !== $noQurl ) {
600
+                $url    = trim($url, " \t\n\r\0\x0B\"'");
601
+                $noQurl = trim($url, "\"'");
602
+                if ($url !== $noQurl) {
603 603
                     $removedQuotes = true;
604 604
                 } else {
605 605
                     $removedQuotes = false;
606 606
                 }
607 607
 
608
-                if ( '' === $noQurl ) {
608
+                if ('' === $noQurl) {
609 609
                     continue;
610 610
                 }
611 611
 
612 612
                 $url = $noQurl;
613
-                if ( '/' === $url{0} || preg_match( '#^(https?://|ftp://|data:)#i', $url ) ) {
613
+                if ('/' === $url{0} || preg_match('#^(https?://|ftp://|data:)#i', $url)) {
614 614
                     // URL is protocol-relative, host-relative or something we don't touch
615 615
                     continue;
616 616
                 } else {
617 617
                     // Relative URL
618
-                    $newurl = preg_replace( '/https?:/', '', str_replace( ' ', '%20', AUTOPTIMIZE_WP_ROOT_URL . str_replace( '//', '/', $dir . '/' . $url ) ) );
618
+                    $newurl = preg_replace('/https?:/', '', str_replace(' ', '%20', AUTOPTIMIZE_WP_ROOT_URL.str_replace('//', '/', $dir.'/'.$url)));
619 619
 
620 620
                     // Hash the url + whatever was behind potentially for replacement
621 621
                     // We must do this, or different css classes referencing the same bg image (but
622 622
                     // different parts of it, say, in sprites and such) loose their stuff...
623
-                    $hash = md5( $url . $matches[2][$k] );
624
-                    $code = str_replace( $matches[0][$k], $hash, $code );
623
+                    $hash = md5($url.$matches[2][$k]);
624
+                    $code = str_replace($matches[0][$k], $hash, $code);
625 625
 
626
-                    if ( $removedQuotes ) {
627
-                        $replace[$hash] = "url('" . $newurl . "')" . $matches[2][$k];
626
+                    if ($removedQuotes) {
627
+                        $replace[$hash] = "url('".$newurl."')".$matches[2][$k];
628 628
                     } else {
629
-                        $replace[$hash] = 'url(' . $newurl . ')' . $matches[2][$k];
629
+                        $replace[$hash] = 'url('.$newurl.')'.$matches[2][$k];
630 630
                     }
631 631
                 }
632 632
             }
633 633
 
634
-            if ( ! empty( $replace ) ) {
634
+            if (!empty($replace)) {
635 635
                 // Sort the replacements array by key length in desc order (so that the longest strings are replaced first)
636
-                $keys = array_map( 'strlen', array_keys( $replace ) );
637
-                array_multisort( $keys, SORT_DESC, $replace );
636
+                $keys = array_map('strlen', array_keys($replace));
637
+                array_multisort($keys, SORT_DESC, $replace);
638 638
 
639 639
                 // Replace URLs found within $code
640
-                $code = str_replace( array_keys( $replace ), array_values( $replace ), $code );
640
+                $code = str_replace(array_keys($replace), array_values($replace), $code);
641 641
             }
642 642
         }
643 643
 
@@ -645,11 +645,11 @@  discard block
 block discarded – undo
645 645
     }
646 646
     
647 647
     private function ismovable($tag) {
648
-		if ( apply_filters('autoptimize_filter_css_dontaggregate', false) ) {
648
+		if (apply_filters('autoptimize_filter_css_dontaggregate', false)) {
649 649
 			return false;
650 650
         } else if (!empty($this->whitelist)) {
651 651
             foreach ($this->whitelist as $match) {
652
-                if(strpos($tag,$match)!==false) {
652
+                if (strpos($tag, $match) !== false) {
653 653
                     return true;
654 654
                 }
655 655
             }
@@ -657,8 +657,8 @@  discard block
 block discarded – undo
657 657
             return false;
658 658
         } else {
659 659
             if (is_array($this->dontmove)) {
660
-                foreach($this->dontmove as $match) {
661
-                    if(strpos($tag,$match)!==false) {
660
+                foreach ($this->dontmove as $match) {
661
+                    if (strpos($tag, $match) !== false) {
662 662
                         //Matched something
663 663
                         return false;
664 664
                     }
@@ -670,21 +670,21 @@  discard block
 block discarded – undo
670 670
         }
671 671
     }
672 672
     
673
-    private function can_inject_late($cssPath,$css) {
673
+    private function can_inject_late($cssPath, $css) {
674 674
 		$consider_minified_array = apply_filters('autoptimize_filter_css_consider_minified', false, $cssPath);
675
-        if ( $this->inject_min_late !== true ) {
675
+        if ($this->inject_min_late !== true) {
676 676
             // late-inject turned off
677 677
             return false;
678
-        } else if ( (strpos($cssPath,"min.css") === false) && ( str_replace($consider_minified_array, '', $cssPath) === $cssPath ) ) {
678
+        } else if ((strpos($cssPath, "min.css") === false) && (str_replace($consider_minified_array, '', $cssPath) === $cssPath)) {
679 679
 			// file not minified based on filename & filter
680 680
 			return false;
681
-        } else if ( strpos($css,"@import") !== false ) {
681
+        } else if (strpos($css, "@import") !== false) {
682 682
             // can't late-inject files with imports as those need to be aggregated 
683 683
             return false;
684
-        } else if ( (strpos($css,"@font-face")!==false ) && ( apply_filters("autoptimize_filter_css_fonts_cdn",false)===true) && (!empty($this->cdn_url)) ) {
684
+        } else if ((strpos($css, "@font-face") !== false) && (apply_filters("autoptimize_filter_css_fonts_cdn", false) === true) && (!empty($this->cdn_url))) {
685 685
             // don't late-inject CSS with font-src's if fonts are set to be CDN'ed
686 686
             return false;
687
-        } else if ( (($this->datauris == true) || (!empty($this->cdn_url))) && preg_match("#background[^;}]*url\(#Ui",$css) ) {
687
+        } else if ((($this->datauris == true) || (!empty($this->cdn_url))) && preg_match("#background[^;}]*url\(#Ui", $css)) {
688 688
             // don't late-inject CSS with images if CDN is set OR is image inlining is on
689 689
             return false;
690 690
         } else {
@@ -694,11 +694,11 @@  discard block
 block discarded – undo
694 694
     }
695 695
     
696 696
     private function maybe_cdn_urls($inUrl) {
697
-        $url = trim($inUrl," \t\n\r\0\x0B\"'");
698
-        $urlPath = parse_url($url,PHP_URL_PATH);
697
+        $url = trim($inUrl, " \t\n\r\0\x0B\"'");
698
+        $urlPath = parse_url($url, PHP_URL_PATH);
699 699
 
700 700
         // exclude fonts from CDN except if filter returns true
701
-        if ( !preg_match('#\.(woff2?|eot|ttf|otf)$#i',$urlPath) || apply_filters('autoptimize_filter_css_fonts_cdn',false) ) {
701
+        if (!preg_match('#\.(woff2?|eot|ttf|otf)$#i', $urlPath) || apply_filters('autoptimize_filter_css_fonts_cdn', false)) {
702 702
             $cdn_url = $this->url_replace_cdn($url);
703 703
         } else {
704 704
             $cdn_url = $url;
Please login to merge, or discard this patch.