@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @param string $url URL to transform. |
66 | 66 | * |
67 | - * @return bool|string |
|
67 | + * @return false|string |
|
68 | 68 | */ |
69 | 69 | public function getpath( $url ) |
70 | 70 | { |
@@ -610,7 +610,7 @@ discard block |
||
610 | 610 | /** |
611 | 611 | * Logs given `$data` for debugging purposes (when debug logging is on). |
612 | 612 | * |
613 | - * @param mixed $data Data to log. |
|
613 | + * @param string $data Data to log. |
|
614 | 614 | * |
615 | 615 | * @return void |
616 | 616 | */ |
@@ -632,7 +632,7 @@ discard block |
||
632 | 632 | * |
633 | 633 | * @param string $filepath Filepath. |
634 | 634 | * |
635 | - * @return bool|string to be minified code or false. |
|
635 | + * @return false|string to be minified code or false. |
|
636 | 636 | */ |
637 | 637 | protected function prepare_minify_single( $filepath ) |
638 | 638 | { |
@@ -412,7 +412,7 @@ |
||
412 | 412 | * First element is the filepath, second is the md5 hash of contents |
413 | 413 | * the filepath had when it was being processed. |
414 | 414 | * If we don't have those, we'll bail out early. |
415 | - */ |
|
415 | + */ |
|
416 | 416 | $filepath = null; |
417 | 417 | $filehash = null; |
418 | 418 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Base class other (more-specific) classes inherit from. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public $cdn_url = ''; |
32 | 32 | |
33 | - public function __construct( $content ) |
|
33 | + public function __construct($content) |
|
34 | 34 | { |
35 | 35 | $this->content = $content; |
36 | 36 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return bool |
44 | 44 | */ |
45 | - abstract public function read( $options ); |
|
45 | + abstract public function read($options); |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * Joins and optimizes collected things. |
@@ -73,40 +73,40 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @return bool|string |
75 | 75 | */ |
76 | - public function getpath( $url ) |
|
76 | + public function getpath($url) |
|
77 | 77 | { |
78 | - $url = apply_filters( 'autoptimize_filter_cssjs_alter_url', $url ); |
|
78 | + $url = apply_filters('autoptimize_filter_cssjs_alter_url', $url); |
|
79 | 79 | |
80 | - if ( false !== strpos( $url, '%' ) ) { |
|
81 | - $url = urldecode( $url ); |
|
80 | + if (false !== strpos($url, '%')) { |
|
81 | + $url = urldecode($url); |
|
82 | 82 | } |
83 | 83 | |
84 | - $site_host = parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ); |
|
85 | - $content_host = parse_url( AUTOPTIMIZE_WP_ROOT_URL, PHP_URL_HOST ); |
|
84 | + $site_host = parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST); |
|
85 | + $content_host = parse_url(AUTOPTIMIZE_WP_ROOT_URL, PHP_URL_HOST); |
|
86 | 86 | |
87 | 87 | // Normalizing attempts... |
88 | - $double_slash_position = strpos( $url, '//' ); |
|
89 | - if ( 0 === $double_slash_position ) { |
|
90 | - if ( is_ssl() ) { |
|
91 | - $url = 'https:' . $url; |
|
88 | + $double_slash_position = strpos($url, '//'); |
|
89 | + if (0 === $double_slash_position) { |
|
90 | + if (is_ssl()) { |
|
91 | + $url = 'https:'.$url; |
|
92 | 92 | } else { |
93 | - $url = 'http:' . $url; |
|
93 | + $url = 'http:'.$url; |
|
94 | 94 | } |
95 | - } elseif ( ( false === $double_slash_position ) && ( false === strpos( $url, $site_host ) ) ) { |
|
96 | - if ( AUTOPTIMIZE_WP_SITE_URL === $site_host ) { |
|
97 | - $url = AUTOPTIMIZE_WP_SITE_URL . $url; |
|
95 | + } elseif ((false === $double_slash_position) && (false === strpos($url, $site_host))) { |
|
96 | + if (AUTOPTIMIZE_WP_SITE_URL === $site_host) { |
|
97 | + $url = AUTOPTIMIZE_WP_SITE_URL.$url; |
|
98 | 98 | } else { |
99 | - $url = AUTOPTIMIZE_WP_SITE_URL . autoptimizeUtils::path_canonicalize( $url ); |
|
99 | + $url = AUTOPTIMIZE_WP_SITE_URL.autoptimizeUtils::path_canonicalize($url); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
103 | - if ( $site_host !== $content_host ) { |
|
104 | - $url = str_replace( AUTOPTIMIZE_WP_CONTENT_URL, AUTOPTIMIZE_WP_SITE_URL . AUTOPTIMIZE_WP_CONTENT_NAME, $url ); |
|
103 | + if ($site_host !== $content_host) { |
|
104 | + $url = str_replace(AUTOPTIMIZE_WP_CONTENT_URL, AUTOPTIMIZE_WP_SITE_URL.AUTOPTIMIZE_WP_CONTENT_NAME, $url); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | // First check; hostname wp site should be hostname of url! |
108 | - $url_host = @parse_url( $url, PHP_URL_HOST ); // @codingStandardsIgnoreLine |
|
109 | - if ( $url_host !== $site_host ) { |
|
108 | + $url_host = @parse_url($url, PHP_URL_HOST); // @codingStandardsIgnoreLine |
|
109 | + if ($url_host !== $site_host) { |
|
110 | 110 | /** |
111 | 111 | * First try to get all domains from WPML (if available) |
112 | 112 | * then explicitely declare $this->cdn_url as OK as well |
@@ -115,20 +115,20 @@ discard block |
||
115 | 115 | */ |
116 | 116 | $multidomains = array(); |
117 | 117 | |
118 | - $multidomains_wpml = apply_filters( 'wpml_setting', array(), 'language_domains' ); |
|
119 | - if ( ! empty( $multidomains_wpml ) ) { |
|
120 | - $multidomains = array_map( array( $this, 'get_url_hostname' ), $multidomains_wpml ); |
|
118 | + $multidomains_wpml = apply_filters('wpml_setting', array(), 'language_domains'); |
|
119 | + if (!empty($multidomains_wpml)) { |
|
120 | + $multidomains = array_map(array($this, 'get_url_hostname'), $multidomains_wpml); |
|
121 | 121 | } |
122 | 122 | |
123 | - if ( ! empty( $this->cdn_url ) ) { |
|
124 | - $multidomains[] = parse_url( $this->cdn_url, PHP_URL_HOST ); |
|
123 | + if (!empty($this->cdn_url)) { |
|
124 | + $multidomains[] = parse_url($this->cdn_url, PHP_URL_HOST); |
|
125 | 125 | } |
126 | 126 | |
127 | - $multidomains = apply_filters( 'autoptimize_filter_cssjs_multidomain', $multidomains ); |
|
127 | + $multidomains = apply_filters('autoptimize_filter_cssjs_multidomain', $multidomains); |
|
128 | 128 | |
129 | - if ( ! empty( $multidomains ) ) { |
|
130 | - if ( in_array( $url_host, $multidomains ) ) { |
|
131 | - $url = str_replace( $url_host, $site_host, $url ); |
|
129 | + if (!empty($multidomains)) { |
|
130 | + if (in_array($url_host, $multidomains)) { |
|
131 | + $url = str_replace($url_host, $site_host, $url); |
|
132 | 132 | } else { |
133 | 133 | return false; |
134 | 134 | } |
@@ -138,28 +138,28 @@ discard block |
||
138 | 138 | } |
139 | 139 | |
140 | 140 | // Try to remove "wp root url" from url while not minding http<>https. |
141 | - $tmp_ao_root = preg_replace( '/https?:/', '', AUTOPTIMIZE_WP_ROOT_URL ); |
|
141 | + $tmp_ao_root = preg_replace('/https?:/', '', AUTOPTIMIZE_WP_ROOT_URL); |
|
142 | 142 | |
143 | - if ( $site_host !== $content_host ) { |
|
143 | + if ($site_host !== $content_host) { |
|
144 | 144 | // As we replaced the content-domain with the site-domain, we should match against that. |
145 | - $tmp_ao_root = preg_replace( '/https?:/', '', AUTOPTIMIZE_WP_SITE_URL ); |
|
145 | + $tmp_ao_root = preg_replace('/https?:/', '', AUTOPTIMIZE_WP_SITE_URL); |
|
146 | 146 | } |
147 | 147 | |
148 | - $tmp_url = preg_replace( '/https?:/', '', $url ); |
|
149 | - $path = str_replace( $tmp_ao_root, '', $tmp_url ); |
|
148 | + $tmp_url = preg_replace('/https?:/', '', $url); |
|
149 | + $path = str_replace($tmp_ao_root, '', $tmp_url); |
|
150 | 150 | |
151 | 151 | // If path starts with :// or //, this is not a URL in the WP context and |
152 | 152 | // we have to assume we can't aggregate. |
153 | - if ( preg_match( '#^:?//#', $path ) ) { |
|
153 | + if (preg_match('#^:?//#', $path)) { |
|
154 | 154 | // External script/css (adsense, etc). |
155 | 155 | return false; |
156 | 156 | } |
157 | 157 | |
158 | 158 | // Prepend with WP_ROOT_DIR to have full path to file. |
159 | - $path = str_replace( '//', '/', WP_ROOT_DIR . $path ); |
|
159 | + $path = str_replace('//', '/', WP_ROOT_DIR.$path); |
|
160 | 160 | |
161 | 161 | // Final check: does file exist and is it readable? |
162 | - if ( file_exists( $path ) && is_file( $path ) && is_readable( $path ) ) { |
|
162 | + if (file_exists($path) && is_file($path) && is_readable($path)) { |
|
163 | 163 | return $path; |
164 | 164 | } else { |
165 | 165 | return false; |
@@ -176,18 +176,18 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @return string |
178 | 178 | */ |
179 | - protected function get_url_hostname( $url ) |
|
179 | + protected function get_url_hostname($url) |
|
180 | 180 | { |
181 | 181 | // Checking that the url starts with something vaguely resembling a protocol. |
182 | - if ( ( 0 !== strpos( $url, 'http' ) ) && ( 0 !== strpos( $url, '//' ) ) ) { |
|
183 | - $url = 'http://' . $url; |
|
182 | + if ((0 !== strpos($url, 'http')) && (0 !== strpos($url, '//'))) { |
|
183 | + $url = 'http://'.$url; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | // Grab the hostname. |
187 | - $hostname = parse_url( $url, PHP_URL_HOST ); |
|
187 | + $hostname = parse_url($url, PHP_URL_HOST); |
|
188 | 188 | |
189 | 189 | // Fallback when parse_url() fails. |
190 | - if ( empty( $hostname ) ) { |
|
190 | + if (empty($hostname)) { |
|
191 | 191 | $hostname = $url; |
192 | 192 | } |
193 | 193 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * |
202 | 202 | * @return string |
203 | 203 | */ |
204 | - protected function hide_noptimize( $markup ) |
|
204 | + protected function hide_noptimize($markup) |
|
205 | 205 | { |
206 | 206 | return $this->replace_contents_with_marker_if_exists( |
207 | 207 | 'NOPTIMIZE', |
@@ -218,9 +218,9 @@ discard block |
||
218 | 218 | * |
219 | 219 | * @return string |
220 | 220 | */ |
221 | - protected function restore_noptimize( $markup ) |
|
221 | + protected function restore_noptimize($markup) |
|
222 | 222 | { |
223 | - return $this->restore_marked_content( 'NOPTIMIZE', $markup ); |
|
223 | + return $this->restore_marked_content('NOPTIMIZE', $markup); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | * |
231 | 231 | * @return string |
232 | 232 | */ |
233 | - protected function hide_iehacks( $markup ) |
|
233 | + protected function hide_iehacks($markup) |
|
234 | 234 | { |
235 | 235 | return $this->replace_contents_with_marker_if_exists( |
236 | 236 | 'IEHACK', // Marker name... |
@@ -247,9 +247,9 @@ discard block |
||
247 | 247 | * |
248 | 248 | * @return string |
249 | 249 | */ |
250 | - protected function restore_iehacks( $markup ) |
|
250 | + protected function restore_iehacks($markup) |
|
251 | 251 | { |
252 | - return $this->restore_marked_content( 'IEHACK', $markup ); |
|
252 | + return $this->restore_marked_content('IEHACK', $markup); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | * |
262 | 262 | * @return string |
263 | 263 | */ |
264 | - protected function hide_comments( $markup ) |
|
264 | + protected function hide_comments($markup) |
|
265 | 265 | { |
266 | 266 | return $this->replace_contents_with_marker_if_exists( |
267 | 267 | 'COMMENTS', |
@@ -279,9 +279,9 @@ discard block |
||
279 | 279 | * |
280 | 280 | * @return string |
281 | 281 | */ |
282 | - protected function restore_comments( $markup ) |
|
282 | + protected function restore_comments($markup) |
|
283 | 283 | { |
284 | - return $this->restore_marked_content( 'COMMENTS', $markup ); |
|
284 | + return $this->restore_marked_content('COMMENTS', $markup); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
@@ -292,44 +292,44 @@ discard block |
||
292 | 292 | * |
293 | 293 | * @return string |
294 | 294 | */ |
295 | - public function url_replace_cdn( $url ) |
|
295 | + public function url_replace_cdn($url) |
|
296 | 296 | { |
297 | 297 | // For 2.3 back-compat in which cdn-ing appeared to be automatically |
298 | 298 | // including WP subfolder/subdirectory into account as part of cdn-ing, |
299 | 299 | // even though it might've caused serious troubles in certain edge-cases. |
300 | - $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed( $this->cdn_url ); |
|
300 | + $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed($this->cdn_url); |
|
301 | 301 | |
302 | 302 | // Allows API/filter to further tweak the cdn url... |
303 | - $cdn_url = apply_filters( 'autoptimize_filter_base_cdnurl', $cdn_url ); |
|
304 | - if ( ! empty( $cdn_url ) ) { |
|
305 | - $this->debug_log( 'before=' . $url ); |
|
303 | + $cdn_url = apply_filters('autoptimize_filter_base_cdnurl', $cdn_url); |
|
304 | + if (!empty($cdn_url)) { |
|
305 | + $this->debug_log('before='.$url); |
|
306 | 306 | |
307 | 307 | // Simple str_replace-based approach fails when $url is protocol-or-host-relative. |
308 | - $is_protocol_relative = autoptimizeUtils::is_protocol_relative( $url ); |
|
309 | - $is_host_relative = ( ! $is_protocol_relative && ( '/' === $url[0] ) ); |
|
310 | - $cdn_url = rtrim( $cdn_url, '/' ); |
|
308 | + $is_protocol_relative = autoptimizeUtils::is_protocol_relative($url); |
|
309 | + $is_host_relative = (!$is_protocol_relative && ('/' === $url[0])); |
|
310 | + $cdn_url = rtrim($cdn_url, '/'); |
|
311 | 311 | |
312 | - if ( $is_host_relative ) { |
|
312 | + if ($is_host_relative) { |
|
313 | 313 | // Prepending host-relative urls with the cdn url. |
314 | - $url = $cdn_url . $url; |
|
314 | + $url = $cdn_url.$url; |
|
315 | 315 | } else { |
316 | 316 | // Either a protocol-relative or "regular" url, replacing it either way. |
317 | - if ( $is_protocol_relative ) { |
|
317 | + if ($is_protocol_relative) { |
|
318 | 318 | // Massage $site_url so that simple str_replace() still "works" by |
319 | 319 | // searching for the protocol-relative version of AUTOPTIMIZE_WP_SITE_URL. |
320 | - $site_url = str_replace( array( 'http:', 'https:' ), '', AUTOPTIMIZE_WP_SITE_URL ); |
|
320 | + $site_url = str_replace(array('http:', 'https:'), '', AUTOPTIMIZE_WP_SITE_URL); |
|
321 | 321 | } else { |
322 | 322 | $site_url = AUTOPTIMIZE_WP_SITE_URL; |
323 | 323 | } |
324 | - $this->debug_log( '`' . $site_url . '` -> `' . $cdn_url . '` in `' . $url . '`' ); |
|
325 | - $url = str_replace( $site_url, $cdn_url, $url ); |
|
324 | + $this->debug_log('`'.$site_url.'` -> `'.$cdn_url.'` in `'.$url.'`'); |
|
325 | + $url = str_replace($site_url, $cdn_url, $url); |
|
326 | 326 | } |
327 | 327 | |
328 | - $this->debug_log( 'after=' . $url ); |
|
328 | + $this->debug_log('after='.$url); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | // Allow API filter to take further care of CDN replacement. |
332 | - $url = apply_filters( 'autoptimize_filter_base_replace_cdn', $url ); |
|
332 | + $url = apply_filters('autoptimize_filter_base_replace_cdn', $url); |
|
333 | 333 | |
334 | 334 | return $url; |
335 | 335 | } |
@@ -347,18 +347,18 @@ discard block |
||
347 | 347 | * |
348 | 348 | * @return void |
349 | 349 | */ |
350 | - protected function inject_in_html( $payload, $where ) |
|
350 | + protected function inject_in_html($payload, $where) |
|
351 | 351 | { |
352 | 352 | $warned = false; |
353 | - $position = autoptimizeUtils::strpos( $this->content, $where[0] ); |
|
354 | - if ( false !== $position ) { |
|
353 | + $position = autoptimizeUtils::strpos($this->content, $where[0]); |
|
354 | + if (false !== $position) { |
|
355 | 355 | // Found the tag, setup content/injection as specified. |
356 | - if ( 'after' === $where[1] ) { |
|
357 | - $content = $where[0] . $payload; |
|
358 | - } elseif ( 'replace' === $where[1] ) { |
|
356 | + if ('after' === $where[1]) { |
|
357 | + $content = $where[0].$payload; |
|
358 | + } elseif ('replace' === $where[1]) { |
|
359 | 359 | $content = $payload; |
360 | 360 | } else { |
361 | - $content = $payload . $where[0]; |
|
361 | + $content = $payload.$where[0]; |
|
362 | 362 | } |
363 | 363 | // Place where specified. |
364 | 364 | $this->content = autoptimizeUtils::substr_replace( |
@@ -367,14 +367,14 @@ discard block |
||
367 | 367 | $position, |
368 | 368 | // Using plain strlen() should be safe here for now, since |
369 | 369 | // we're not searching for multibyte chars here still... |
370 | - strlen( $where[0] ) |
|
370 | + strlen($where[0]) |
|
371 | 371 | ); |
372 | 372 | } else { |
373 | 373 | // Couldn't find what was specified, just append and add a warning. |
374 | 374 | $this->content .= $payload; |
375 | - if ( ! $warned ) { |
|
376 | - $tag_display = str_replace( array( '<', '>' ), '', $where[0] ); |
|
377 | - $this->content .= '<!--noptimize--><!-- Autoptimize found a problem with the HTML in your Theme, tag `' . $tag_display . '` missing --><!--/noptimize-->'; |
|
375 | + if (!$warned) { |
|
376 | + $tag_display = str_replace(array('<', '>'), '', $where[0]); |
|
377 | + $this->content .= '<!--noptimize--><!-- Autoptimize found a problem with the HTML in your Theme, tag `'.$tag_display.'` missing --><!--/noptimize-->'; |
|
378 | 378 | $warned = true; |
379 | 379 | } |
380 | 380 | } |
@@ -388,10 +388,10 @@ discard block |
||
388 | 388 | * |
389 | 389 | * @return bool |
390 | 390 | */ |
391 | - protected function isremovable( $tag, $removables ) |
|
391 | + protected function isremovable($tag, $removables) |
|
392 | 392 | { |
393 | - foreach ( $removables as $match ) { |
|
394 | - if ( false !== strpos( $tag, $match ) ) { |
|
393 | + foreach ($removables as $match) { |
|
394 | + if (false !== strpos($tag, $match)) { |
|
395 | 395 | return true; |
396 | 396 | } |
397 | 397 | } |
@@ -406,10 +406,10 @@ discard block |
||
406 | 406 | * |
407 | 407 | * @return string |
408 | 408 | */ |
409 | - public function inject_minified_callback( $matches ) |
|
409 | + public function inject_minified_callback($matches) |
|
410 | 410 | { |
411 | 411 | static $conf = null; |
412 | - if ( null === $conf ) { |
|
412 | + if (null === $conf) { |
|
413 | 413 | $conf = autoptimizeConfig::instance(); |
414 | 414 | } |
415 | 415 | |
@@ -424,62 +424,62 @@ discard block |
||
424 | 424 | $filehash = null; |
425 | 425 | |
426 | 426 | // Grab the parts we need. |
427 | - $parts = explode( '|', $matches[1] ); |
|
428 | - if ( ! empty( $parts ) ) { |
|
429 | - $filepath = isset( $parts[0] ) ? base64_decode( $parts[0] ) : null; |
|
430 | - $filehash = isset( $parts[1] ) ? $parts[1] : null; |
|
427 | + $parts = explode('|', $matches[1]); |
|
428 | + if (!empty($parts)) { |
|
429 | + $filepath = isset($parts[0]) ? base64_decode($parts[0]) : null; |
|
430 | + $filehash = isset($parts[1]) ? $parts[1] : null; |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | // Bail early if something's not right... |
434 | - if ( ! $filepath || ! $filehash ) { |
|
434 | + if (!$filepath || !$filehash) { |
|
435 | 435 | return "\n"; |
436 | 436 | } |
437 | 437 | |
438 | - $filecontent = file_get_contents( $filepath ); |
|
438 | + $filecontent = file_get_contents($filepath); |
|
439 | 439 | |
440 | 440 | // Some things are differently handled for css/js... |
441 | - $is_js_file = ( '.js' === substr( $filepath, -3, 3 ) ); |
|
441 | + $is_js_file = ('.js' === substr($filepath, -3, 3)); |
|
442 | 442 | |
443 | 443 | $is_css_file = false; |
444 | - if ( ! $is_js_file ) { |
|
445 | - $is_css_file = ( '.css' === substr( $filepath, -4, 4 ) ); |
|
444 | + if (!$is_js_file) { |
|
445 | + $is_css_file = ('.css' === substr($filepath, -4, 4)); |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | // BOMs being nuked here unconditionally (regardless of where they are)! |
449 | - $filecontent = preg_replace( "#\x{EF}\x{BB}\x{BF}#", '', $filecontent ); |
|
449 | + $filecontent = preg_replace("#\x{EF}\x{BB}\x{BF}#", '', $filecontent); |
|
450 | 450 | |
451 | 451 | // Remove comments and blank lines. |
452 | - if ( $is_js_file ) { |
|
453 | - $filecontent = preg_replace( '#^\s*\/\/.*$#Um', '', $filecontent ); |
|
452 | + if ($is_js_file) { |
|
453 | + $filecontent = preg_replace('#^\s*\/\/.*$#Um', '', $filecontent); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | // Nuke un-important comments. |
457 | - $filecontent = preg_replace( '#^\s*\/\*[^!].*\*\/\s?#Um', '', $filecontent ); |
|
457 | + $filecontent = preg_replace('#^\s*\/\*[^!].*\*\/\s?#Um', '', $filecontent); |
|
458 | 458 | |
459 | 459 | // Normalize newlines. |
460 | - $filecontent = preg_replace( '#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#', "\n", $filecontent ); |
|
460 | + $filecontent = preg_replace('#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#', "\n", $filecontent); |
|
461 | 461 | |
462 | 462 | // JS specifics. |
463 | - if ( $is_js_file ) { |
|
463 | + if ($is_js_file) { |
|
464 | 464 | // Append a semicolon at the end of js files if it's missing. |
465 | - $last_char = substr( $filecontent, -1, 1 ); |
|
466 | - if ( ';' !== $last_char && '}' !== $last_char ) { |
|
465 | + $last_char = substr($filecontent, -1, 1); |
|
466 | + if (';' !== $last_char && '}' !== $last_char) { |
|
467 | 467 | $filecontent .= ';'; |
468 | 468 | } |
469 | 469 | // Check if try/catch should be used. |
470 | - $opt_js_try_catch = $conf->get( 'autoptimize_js_trycatch' ); |
|
471 | - if ( 'on' === $opt_js_try_catch ) { |
|
470 | + $opt_js_try_catch = $conf->get('autoptimize_js_trycatch'); |
|
471 | + if ('on' === $opt_js_try_catch) { |
|
472 | 472 | // It should, wrap in try/catch. |
473 | - $filecontent = 'try{' . $filecontent . '}catch(e){}'; |
|
473 | + $filecontent = 'try{'.$filecontent.'}catch(e){}'; |
|
474 | 474 | } |
475 | - } elseif ( $is_css_file ) { |
|
476 | - $filecontent = autoptimizeStyles::fixurls( $filepath, $filecontent ); |
|
475 | + } elseif ($is_css_file) { |
|
476 | + $filecontent = autoptimizeStyles::fixurls($filepath, $filecontent); |
|
477 | 477 | } else { |
478 | 478 | $filecontent = ''; |
479 | 479 | } |
480 | 480 | |
481 | 481 | // Return modified (or empty!) code/content. |
482 | - return "\n" . $filecontent; |
|
482 | + return "\n".$filecontent; |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
@@ -489,13 +489,13 @@ discard block |
||
489 | 489 | * |
490 | 490 | * @return string |
491 | 491 | */ |
492 | - protected function inject_minified( $in ) |
|
492 | + protected function inject_minified($in) |
|
493 | 493 | { |
494 | 494 | $out = $in; |
495 | - if ( false !== strpos( $in, '%%INJECTLATER%%' ) ) { |
|
495 | + if (false !== strpos($in, '%%INJECTLATER%%')) { |
|
496 | 496 | $out = preg_replace_callback( |
497 | - '#\/\*\!%%INJECTLATER' . AUTOPTIMIZE_HASH . '%%(.*?)%%INJECTLATER%%\*\/#is', |
|
498 | - array( $this, 'inject_minified_callback' ), |
|
497 | + '#\/\*\!%%INJECTLATER'.AUTOPTIMIZE_HASH.'%%(.*?)%%INJECTLATER%%\*\/#is', |
|
498 | + array($this, 'inject_minified_callback'), |
|
499 | 499 | $in |
500 | 500 | ); |
501 | 501 | } |
@@ -515,9 +515,9 @@ discard block |
||
515 | 515 | * |
516 | 516 | * @return string |
517 | 517 | */ |
518 | - public static function build_injectlater_marker( $filepath, $hash ) |
|
518 | + public static function build_injectlater_marker($filepath, $hash) |
|
519 | 519 | { |
520 | - $contents = '/*!' . self::build_marker( 'INJECTLATER', $filepath, $hash ) . '*/'; |
|
520 | + $contents = '/*!'.self::build_marker('INJECTLATER', $filepath, $hash).'*/'; |
|
521 | 521 | |
522 | 522 | return $contents; |
523 | 523 | } |
@@ -535,18 +535,18 @@ discard block |
||
535 | 535 | * |
536 | 536 | * @return string |
537 | 537 | */ |
538 | - public static function build_marker( $name, $data, $hash = null ) |
|
538 | + public static function build_marker($name, $data, $hash = null) |
|
539 | 539 | { |
540 | 540 | // Start the marker, add the data. |
541 | - $marker = '%%' . $name . AUTOPTIMIZE_HASH . '%%' . base64_encode( $data ); |
|
541 | + $marker = '%%'.$name.AUTOPTIMIZE_HASH.'%%'.base64_encode($data); |
|
542 | 542 | |
543 | 543 | // Add the hash if provided. |
544 | - if ( null !== $hash ) { |
|
545 | - $marker .= '|' . $hash; |
|
544 | + if (null !== $hash) { |
|
545 | + $marker .= '|'.$hash; |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | // Close the marker. |
549 | - $marker .= '%%' . $name . '%%'; |
|
549 | + $marker .= '%%'.$name.'%%'; |
|
550 | 550 | |
551 | 551 | return $marker; |
552 | 552 | } |
@@ -566,22 +566,22 @@ discard block |
||
566 | 566 | * |
567 | 567 | * @return string |
568 | 568 | */ |
569 | - public static function replace_contents_with_marker_if_exists( $marker, $search, $re_replace_pattern, $content ) |
|
569 | + public static function replace_contents_with_marker_if_exists($marker, $search, $re_replace_pattern, $content) |
|
570 | 570 | { |
571 | 571 | $found = false; |
572 | 572 | |
573 | - $is_regex = autoptimizeUtils::str_is_valid_regex( $search ); |
|
574 | - if ( $is_regex ) { |
|
575 | - $found = preg_match( $search, $content ); |
|
573 | + $is_regex = autoptimizeUtils::str_is_valid_regex($search); |
|
574 | + if ($is_regex) { |
|
575 | + $found = preg_match($search, $content); |
|
576 | 576 | } else { |
577 | - $found = ( false !== strpos( $content, $search ) ); |
|
577 | + $found = (false !== strpos($content, $search)); |
|
578 | 578 | } |
579 | 579 | |
580 | - if ( $found ) { |
|
580 | + if ($found) { |
|
581 | 581 | $content = preg_replace_callback( |
582 | 582 | $re_replace_pattern, |
583 | - function( $matches ) use ( $marker ) { |
|
584 | - return autoptimizeBase::build_marker( $marker, $matches[0] ); |
|
583 | + function($matches) use ($marker) { |
|
584 | + return autoptimizeBase::build_marker($marker, $matches[0]); |
|
585 | 585 | }, |
586 | 586 | $content |
587 | 587 | ); |
@@ -598,13 +598,13 @@ discard block |
||
598 | 598 | * |
599 | 599 | * @return string |
600 | 600 | */ |
601 | - public static function restore_marked_content( $marker, $content ) |
|
601 | + public static function restore_marked_content($marker, $content) |
|
602 | 602 | { |
603 | - if ( false !== strpos( $content, $marker ) ) { |
|
603 | + if (false !== strpos($content, $marker)) { |
|
604 | 604 | $content = preg_replace_callback( |
605 | - '#%%' . $marker . AUTOPTIMIZE_HASH . '%%(.*?)%%' . $marker . '%%#is', |
|
606 | - function ( $matches ) { |
|
607 | - return base64_decode( $matches[1] ); |
|
605 | + '#%%'.$marker.AUTOPTIMIZE_HASH.'%%(.*?)%%'.$marker.'%%#is', |
|
606 | + function($matches) { |
|
607 | + return base64_decode($matches[1]); |
|
608 | 608 | }, |
609 | 609 | $content |
610 | 610 | ); |
@@ -620,17 +620,17 @@ discard block |
||
620 | 620 | * |
621 | 621 | * @return void |
622 | 622 | */ |
623 | - protected function debug_log( $data ) |
|
623 | + protected function debug_log($data) |
|
624 | 624 | { |
625 | - if ( ! isset( $this->debug_log ) || ! $this->debug_log ) { |
|
625 | + if (!isset($this->debug_log) || !$this->debug_log) { |
|
626 | 626 | return; |
627 | 627 | } |
628 | 628 | |
629 | - if ( ! is_string( $data ) && ! is_resource( $data ) ) { |
|
630 | - $data = var_export( $data, true ); |
|
629 | + if (!is_string($data) && !is_resource($data)) { |
|
630 | + $data = var_export($data, true); |
|
631 | 631 | } |
632 | 632 | |
633 | - error_log( $data ); |
|
633 | + error_log($data); |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -640,12 +640,12 @@ discard block |
||
640 | 640 | * |
641 | 641 | * @return bool|string to be minified code or false. |
642 | 642 | */ |
643 | - protected function prepare_minify_single( $filepath ) |
|
643 | + protected function prepare_minify_single($filepath) |
|
644 | 644 | { |
645 | 645 | // Decide what we're dealing with, return false if we don't know. |
646 | - if ( autoptimizeUtils::str_ends_in( $filepath, '.js' ) ) { |
|
646 | + if (autoptimizeUtils::str_ends_in($filepath, '.js')) { |
|
647 | 647 | $type = 'js'; |
648 | - } elseif ( autoptimizeUtils::str_ends_in( $filepath, '.css' ) ) { |
|
648 | + } elseif (autoptimizeUtils::str_ends_in($filepath, '.css')) { |
|
649 | 649 | $type = 'css'; |
650 | 650 | } else { |
651 | 651 | return false; |
@@ -654,18 +654,18 @@ discard block |
||
654 | 654 | // Bail if it looks like its already minifed (by having -min or .min |
655 | 655 | // in filename) or if it looks like WP jquery.js (which is minified). |
656 | 656 | $minified_variants = array( |
657 | - '-min.' . $type, |
|
658 | - '.min.' . $type, |
|
657 | + '-min.'.$type, |
|
658 | + '.min.'.$type, |
|
659 | 659 | 'js/jquery/jquery.js', |
660 | 660 | ); |
661 | - foreach ( $minified_variants as $ending ) { |
|
662 | - if ( autoptimizeUtils::str_ends_in( $filepath, $ending ) ) { |
|
661 | + foreach ($minified_variants as $ending) { |
|
662 | + if (autoptimizeUtils::str_ends_in($filepath, $ending)) { |
|
663 | 663 | return false; |
664 | 664 | } |
665 | 665 | } |
666 | 666 | |
667 | 667 | // Get file contents, bail if empty. |
668 | - $contents = file_get_contents( $filepath ); |
|
668 | + $contents = file_get_contents($filepath); |
|
669 | 669 | |
670 | 670 | return $contents; |
671 | 671 | } |
@@ -678,12 +678,12 @@ discard block |
||
678 | 678 | * |
679 | 679 | * @return string |
680 | 680 | */ |
681 | - protected function build_minify_single_url( autoptimizeCache $cache ) |
|
681 | + protected function build_minify_single_url(autoptimizeCache $cache) |
|
682 | 682 | { |
683 | - $url = AUTOPTIMIZE_CACHE_URL . $cache->getname(); |
|
683 | + $url = AUTOPTIMIZE_CACHE_URL.$cache->getname(); |
|
684 | 684 | |
685 | 685 | // CDN-replace the resulting URL if needed... |
686 | - $url = $this->url_replace_cdn( $url ); |
|
686 | + $url = $this->url_replace_cdn($url); |
|
687 | 687 | |
688 | 688 | return $url; |
689 | 689 | } |
@@ -434,7 +434,7 @@ |
||
434 | 434 | * size = total filesize (in bytes) of found files |
435 | 435 | * timestamp = unix timestamp when the scan was last performed/finished. |
436 | 436 | * |
437 | - * @return array |
|
437 | + * @return integer[] |
|
438 | 438 | */ |
439 | 439 | protected static function stats_scan() |
440 | 440 | { |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Handles disk-cache-related operations. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -38,17 +38,17 @@ discard block |
||
38 | 38 | * @param string $md5 Hash. |
39 | 39 | * @param string $ext Extension. |
40 | 40 | */ |
41 | - public function __construct( $md5, $ext = 'php' ) |
|
41 | + public function __construct($md5, $ext = 'php') |
|
42 | 42 | { |
43 | 43 | $this->cachedir = AUTOPTIMIZE_CACHE_DIR; |
44 | 44 | $this->nogzip = AUTOPTIMIZE_CACHE_NOGZIP; |
45 | - if ( ! $this->nogzip ) { |
|
46 | - $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . '.php'; |
|
45 | + if (!$this->nogzip) { |
|
46 | + $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.'.php'; |
|
47 | 47 | } else { |
48 | - if ( in_array( $ext, array( 'js', 'css' ) ) ) { |
|
49 | - $this->filename = $ext . '/' . AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . '.' . $ext; |
|
48 | + if (in_array($ext, array('js', 'css'))) { |
|
49 | + $this->filename = $ext.'/'.AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.'.'.$ext; |
|
50 | 50 | } else { |
51 | - $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . '.' . $ext; |
|
51 | + $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.'.'.$ext; |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function check() |
62 | 62 | { |
63 | - return file_exists( $this->cachedir . $this->filename ); |
|
63 | + return file_exists($this->cachedir.$this->filename); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -70,11 +70,11 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public function retrieve() |
72 | 72 | { |
73 | - if ( $this->check() ) { |
|
74 | - if ( false == $this->nogzip ) { |
|
75 | - return file_get_contents( $this->cachedir . $this->filename . '.none' ); |
|
73 | + if ($this->check()) { |
|
74 | + if (false == $this->nogzip) { |
|
75 | + return file_get_contents($this->cachedir.$this->filename.'.none'); |
|
76 | 76 | } else { |
77 | - return file_get_contents( $this->cachedir . $this->filename ); |
|
77 | + return file_get_contents($this->cachedir.$this->filename); |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | return false; |
@@ -88,43 +88,43 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return void |
90 | 90 | */ |
91 | - public function cache( $data, $mime ) |
|
91 | + public function cache($data, $mime) |
|
92 | 92 | { |
93 | 93 | // off by default; check if cachedirs exist every time before caching |
94 | 94 | // |
95 | 95 | // to be activated for users that experience these ugly errors; |
96 | 96 | // PHP Warning: file_put_contents failed to open stream: No such file or directory. |
97 | - if ( apply_filters( 'autoptimize_filter_cache_checkdirs_on_write', false ) ) { |
|
97 | + if (apply_filters('autoptimize_filter_cache_checkdirs_on_write', false)) { |
|
98 | 98 | $this->check_and_create_dirs(); |
99 | 99 | } |
100 | 100 | |
101 | - if ( false === $this->nogzip ) { |
|
101 | + if (false === $this->nogzip) { |
|
102 | 102 | // We handle gzipping ourselves. |
103 | 103 | $file = 'default.php'; |
104 | - $phpcode = file_get_contents( AUTOPTIMIZE_PLUGIN_DIR . 'config/' . $file ); |
|
105 | - $phpcode = str_replace( array( '%%CONTENT%%', 'exit;' ), array( $mime, '' ), $phpcode ); |
|
104 | + $phpcode = file_get_contents(AUTOPTIMIZE_PLUGIN_DIR.'config/'.$file); |
|
105 | + $phpcode = str_replace(array('%%CONTENT%%', 'exit;'), array($mime, ''), $phpcode); |
|
106 | 106 | |
107 | - file_put_contents( $this->cachedir . $this->filename, $phpcode ); |
|
108 | - file_put_contents( $this->cachedir . $this->filename . '.none', $data ); |
|
107 | + file_put_contents($this->cachedir.$this->filename, $phpcode); |
|
108 | + file_put_contents($this->cachedir.$this->filename.'.none', $data); |
|
109 | 109 | } else { |
110 | 110 | // Write code to cache without doing anything else. |
111 | - file_put_contents( $this->cachedir . $this->filename, $data ); |
|
111 | + file_put_contents($this->cachedir.$this->filename, $data); |
|
112 | 112 | |
113 | 113 | // save fallback .js or .css file if filter true (to be false by default) but not if snippet or single. |
114 | - if ( self::do_fallback() && strpos( $this->filename, '_snippet_' ) === false && strpos( $this->filename, '_single_' ) === false ) { |
|
115 | - $_extension = pathinfo( $this->filename, PATHINFO_EXTENSION ); |
|
116 | - $_fallback_file = AUTOPTIMIZE_CACHEFILE_PREFIX . 'fallback.' . $_extension; |
|
117 | - if ( ! file_exists( $this->cachedir . $_extension . '/' . $_fallback_file ) ) { |
|
118 | - file_put_contents( $this->cachedir . $_extension . '/' . $_fallback_file, $data ); |
|
114 | + if (self::do_fallback() && strpos($this->filename, '_snippet_') === false && strpos($this->filename, '_single_') === false) { |
|
115 | + $_extension = pathinfo($this->filename, PATHINFO_EXTENSION); |
|
116 | + $_fallback_file = AUTOPTIMIZE_CACHEFILE_PREFIX.'fallback.'.$_extension; |
|
117 | + if (!file_exists($this->cachedir.$_extension.'/'.$_fallback_file)) { |
|
118 | + file_put_contents($this->cachedir.$_extension.'/'.$_fallback_file, $data); |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | |
122 | - if ( apply_filters( 'autoptimize_filter_cache_create_static_gzip', false ) ) { |
|
122 | + if (apply_filters('autoptimize_filter_cache_create_static_gzip', false)) { |
|
123 | 123 | // Create an additional cached gzip file. |
124 | - file_put_contents( $this->cachedir . $this->filename . '.gz', gzencode( $data, 9, FORCE_GZIP ) ); |
|
124 | + file_put_contents($this->cachedir.$this->filename.'.gz', gzencode($data, 9, FORCE_GZIP)); |
|
125 | 125 | // If PHP Brotli extension is installed, create an additional cached Brotli file. |
126 | - if ( function_exists( 'brotli_compress' ) ) { |
|
127 | - file_put_contents( $this->cachedir . $this->filename . '.br', brotli_compress( $data, 11, BROTLI_GENERIC ) ); |
|
126 | + if (function_exists('brotli_compress')) { |
|
127 | + file_put_contents($this->cachedir.$this->filename.'.br', brotli_compress($data, 11, BROTLI_GENERIC)); |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | } |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | // The original idea here was to provide 3rd party code a hook so that |
143 | 143 | // it can "listen" to all the complete autoptimized-urls that the page |
144 | 144 | // will emit... Or something to that effect I think? |
145 | - apply_filters( 'autoptimize_filter_cache_getname', AUTOPTIMIZE_CACHE_URL . $this->filename ); |
|
145 | + apply_filters('autoptimize_filter_cache_getname', AUTOPTIMIZE_CACHE_URL.$this->filename); |
|
146 | 146 | |
147 | 147 | return $this->filename; |
148 | 148 | } |
@@ -155,11 +155,11 @@ discard block |
||
155 | 155 | * @param string $file Filename. |
156 | 156 | * @return bool |
157 | 157 | */ |
158 | - protected static function is_valid_cache_file( $dir, $file ) |
|
158 | + protected static function is_valid_cache_file($dir, $file) |
|
159 | 159 | { |
160 | - if ( '.' !== $file && '..' !== $file && |
|
161 | - false !== strpos( $file, AUTOPTIMIZE_CACHEFILE_PREFIX ) && |
|
162 | - is_file( $dir . $file ) ) { |
|
160 | + if ('.' !== $file && '..' !== $file && |
|
161 | + false !== strpos($file, AUTOPTIMIZE_CACHEFILE_PREFIX) && |
|
162 | + is_file($dir.$file)) { |
|
163 | 163 | |
164 | 164 | // It's a valid file! |
165 | 165 | return true; |
@@ -177,16 +177,16 @@ discard block |
||
177 | 177 | protected static function clear_cache_classic() |
178 | 178 | { |
179 | 179 | $contents = self::get_cache_contents(); |
180 | - foreach ( $contents as $name => $files ) { |
|
181 | - $dir = rtrim( AUTOPTIMIZE_CACHE_DIR . $name, '/' ) . '/'; |
|
182 | - foreach ( $files as $file ) { |
|
183 | - if ( self::is_valid_cache_file( $dir, $file ) ) { |
|
184 | - @unlink( $dir . $file ); // @codingStandardsIgnoreLine |
|
180 | + foreach ($contents as $name => $files) { |
|
181 | + $dir = rtrim(AUTOPTIMIZE_CACHE_DIR.$name, '/').'/'; |
|
182 | + foreach ($files as $file) { |
|
183 | + if (self::is_valid_cache_file($dir, $file)) { |
|
184 | + @unlink($dir.$file); // @codingStandardsIgnoreLine |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | } |
188 | 188 | |
189 | - @unlink( AUTOPTIMIZE_CACHE_DIR . '/.htaccess' ); // @codingStandardsIgnoreLine |
|
189 | + @unlink(AUTOPTIMIZE_CACHE_DIR.'/.htaccess'); // @codingStandardsIgnoreLine |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -197,19 +197,19 @@ discard block |
||
197 | 197 | * |
198 | 198 | * @return bool |
199 | 199 | */ |
200 | - protected static function rmdir( $pathname ) |
|
200 | + protected static function rmdir($pathname) |
|
201 | 201 | { |
202 | - $files = self::get_dir_contents( $pathname ); |
|
203 | - foreach ( $files as $file ) { |
|
204 | - $path = $pathname . '/' . $file; |
|
205 | - if ( is_dir( $path ) ) { |
|
206 | - self::rmdir( $path ); |
|
202 | + $files = self::get_dir_contents($pathname); |
|
203 | + foreach ($files as $file) { |
|
204 | + $path = $pathname.'/'.$file; |
|
205 | + if (is_dir($path)) { |
|
206 | + self::rmdir($path); |
|
207 | 207 | } else { |
208 | - unlink( $path ); |
|
208 | + unlink($path); |
|
209 | 209 | } |
210 | 210 | } |
211 | 211 | |
212 | - return rmdir( $pathname ); |
|
212 | + return rmdir($pathname); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -230,12 +230,12 @@ discard block |
||
230 | 230 | $new_name = self::get_unique_name(); |
231 | 231 | |
232 | 232 | // Makes sure the new pathname is on the same level... |
233 | - $new_pathname = dirname( $dir ) . '/' . $new_name; |
|
234 | - $renamed = @rename( $dir, $new_pathname ); // @codingStandardsIgnoreLine |
|
233 | + $new_pathname = dirname($dir).'/'.$new_name; |
|
234 | + $renamed = @rename($dir, $new_pathname); // @codingStandardsIgnoreLine |
|
235 | 235 | |
236 | 236 | // When renamed, re-create the default cache directory back so it's |
237 | 237 | // available again... |
238 | - if ( $renamed ) { |
|
238 | + if ($renamed) { |
|
239 | 239 | $ok = self::cacheavail(); |
240 | 240 | } |
241 | 241 | |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | */ |
250 | 250 | public static function advanced_cache_clear_enabled() |
251 | 251 | { |
252 | - return apply_filters( 'autoptimize_filter_cache_clear_advanced', false ); |
|
252 | + return apply_filters('autoptimize_filter_cache_clear_advanced', false); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | protected static function get_unique_name() |
261 | 261 | { |
262 | 262 | $prefix = self::get_advanced_cache_clear_prefix(); |
263 | - $new_name = uniqid( $prefix, true ); |
|
263 | + $new_name = uniqid($prefix, true); |
|
264 | 264 | |
265 | 265 | return $new_name; |
266 | 266 | } |
@@ -273,8 +273,8 @@ discard block |
||
273 | 273 | protected static function get_advanced_cache_clear_prefix() |
274 | 274 | { |
275 | 275 | $pathname = self::get_pathname_base(); |
276 | - $basename = basename( $pathname ); |
|
277 | - $prefix = $basename . '-artifact-'; |
|
276 | + $basename = basename($pathname); |
|
277 | + $prefix = $basename.'-artifact-'; |
|
278 | 278 | |
279 | 279 | return $prefix; |
280 | 280 | } |
@@ -287,9 +287,9 @@ discard block |
||
287 | 287 | * |
288 | 288 | * @return array |
289 | 289 | */ |
290 | - protected static function get_dir_contents( $pathname ) |
|
290 | + protected static function get_dir_contents($pathname) |
|
291 | 291 | { |
292 | - return array_slice( scandir( $pathname ), 2 ); |
|
292 | + return array_slice(scandir($pathname), 2); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | /** |
@@ -302,24 +302,24 @@ discard block |
||
302 | 302 | public static function delete_advanced_cache_clear_artifacts() |
303 | 303 | { |
304 | 304 | // Don't go through these motions (called from the cachechecker) if advanced cache clear isn't even active. |
305 | - if ( ! self::advanced_cache_clear_enabled() ) { |
|
305 | + if (!self::advanced_cache_clear_enabled()) { |
|
306 | 306 | return false; |
307 | 307 | } |
308 | 308 | |
309 | 309 | $dir = self::get_pathname_base(); |
310 | 310 | $prefix = self::get_advanced_cache_clear_prefix(); |
311 | - $parent = dirname( $dir ); |
|
311 | + $parent = dirname($dir); |
|
312 | 312 | $ok = false; |
313 | 313 | |
314 | 314 | // Returns the list of files without '.' and '..' elements. |
315 | - $files = self::get_dir_contents( $parent ); |
|
316 | - if ( is_array( $files ) && ! empty( $files ) ) { |
|
317 | - foreach ( $files as $file ) { |
|
318 | - $path = $parent . '/' . $file; |
|
319 | - $prefixed = ( false !== strpos( $path, $prefix ) ); |
|
315 | + $files = self::get_dir_contents($parent); |
|
316 | + if (is_array($files) && !empty($files)) { |
|
317 | + foreach ($files as $file) { |
|
318 | + $path = $parent.'/'.$file; |
|
319 | + $prefixed = (false !== strpos($path, $prefix)); |
|
320 | 320 | // Removing only our own (prefixed) directories... |
321 | - if ( is_dir( $path ) && $prefixed ) { |
|
322 | - $ok = self::rmdir( $path ); |
|
321 | + if (is_dir($path) && $prefixed) { |
|
322 | + $ok = self::rmdir($path); |
|
323 | 323 | } |
324 | 324 | } |
325 | 325 | } |
@@ -339,9 +339,9 @@ discard block |
||
339 | 339 | { |
340 | 340 | $pathname = self::get_pathname_base(); |
341 | 341 | |
342 | - if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) { |
|
342 | + if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) { |
|
343 | 343 | $blog_id = get_current_blog_id(); |
344 | - $pathname .= $blog_id . '/'; |
|
344 | + $pathname .= $blog_id.'/'; |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | return $pathname; |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | */ |
355 | 355 | protected static function get_pathname_base() |
356 | 356 | { |
357 | - $pathname = WP_CONTENT_DIR . AUTOPTIMIZE_CACHE_CHILD_DIR; |
|
357 | + $pathname = WP_CONTENT_DIR.AUTOPTIMIZE_CACHE_CHILD_DIR; |
|
358 | 358 | |
359 | 359 | return $pathname; |
360 | 360 | } |
@@ -366,46 +366,46 @@ discard block |
||
366 | 366 | * |
367 | 367 | * @return bool |
368 | 368 | */ |
369 | - public static function clearall( $propagate = true ) |
|
369 | + public static function clearall($propagate = true) |
|
370 | 370 | { |
371 | - if ( ! self::cacheavail() ) { |
|
371 | + if (!self::cacheavail()) { |
|
372 | 372 | return false; |
373 | 373 | } |
374 | 374 | |
375 | 375 | // TODO/FIXME: If cache is big, switch to advanced/new cache clearing automatically? |
376 | - if ( self::advanced_cache_clear_enabled() ) { |
|
376 | + if (self::advanced_cache_clear_enabled()) { |
|
377 | 377 | self::clear_cache_via_rename(); |
378 | 378 | } else { |
379 | 379 | self::clear_cache_classic(); |
380 | 380 | } |
381 | 381 | |
382 | 382 | // Remove 404 handler if required. |
383 | - if ( self::do_fallback() ) { |
|
384 | - $_fallback_php = trailingslashit( WP_CONTENT_DIR ) . 'autoptimize_404_handler.php'; |
|
385 | - @unlink( $_fallback_php ); // @codingStandardsIgnoreLine |
|
383 | + if (self::do_fallback()) { |
|
384 | + $_fallback_php = trailingslashit(WP_CONTENT_DIR).'autoptimize_404_handler.php'; |
|
385 | + @unlink($_fallback_php); // @codingStandardsIgnoreLine |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | // Remove the transient so it gets regenerated... |
389 | - delete_transient( 'autoptimize_stats' ); |
|
389 | + delete_transient('autoptimize_stats'); |
|
390 | 390 | |
391 | 391 | // Cache was just purged, clear page cache and allow others to hook into our purging... |
392 | - if ( true === $propagate ) { |
|
393 | - if ( ! function_exists( 'autoptimize_do_cachepurged_action' ) ) { |
|
392 | + if (true === $propagate) { |
|
393 | + if (!function_exists('autoptimize_do_cachepurged_action')) { |
|
394 | 394 | function autoptimize_do_cachepurged_action() { |
395 | - do_action( 'autoptimize_action_cachepurged' ); |
|
395 | + do_action('autoptimize_action_cachepurged'); |
|
396 | 396 | } |
397 | 397 | } |
398 | - add_action( 'shutdown', 'autoptimize_do_cachepurged_action', 11 ); |
|
399 | - add_action( 'autoptimize_action_cachepurged', array( 'autoptimizeCache', 'flushPageCache' ), 10, 0 ); |
|
398 | + add_action('shutdown', 'autoptimize_do_cachepurged_action', 11); |
|
399 | + add_action('autoptimize_action_cachepurged', array('autoptimizeCache', 'flushPageCache'), 10, 0); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | // Warm cache (part of speedupper)! |
403 | - if ( apply_filters( 'autoptimize_filter_speedupper', true ) && false == get_transient( 'autoptimize_cache_warmer_protector' ) ) { |
|
404 | - set_transient( 'autoptimize_cache_warmer_protector', 'I shall not warm cache for another 10 minutes.', 60 * 10 ); |
|
405 | - $url = site_url() . '/?ao_speedup_cachebuster=' . rand( 1, 100000 ); |
|
406 | - $url = apply_filters( 'autoptimize_filter_cache_warmer_url', $url ); |
|
407 | - $cache = @wp_remote_get( $url ); // @codingStandardsIgnoreLine |
|
408 | - unset( $cache ); |
|
403 | + if (apply_filters('autoptimize_filter_speedupper', true) && false == get_transient('autoptimize_cache_warmer_protector')) { |
|
404 | + set_transient('autoptimize_cache_warmer_protector', 'I shall not warm cache for another 10 minutes.', 60*10); |
|
405 | + $url = site_url().'/?ao_speedup_cachebuster='.rand(1, 100000); |
|
406 | + $url = apply_filters('autoptimize_filter_cache_warmer_url', $url); |
|
407 | + $cache = @wp_remote_get($url); // @codingStandardsIgnoreLine |
|
408 | + unset($cache); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | return true; |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | */ |
421 | 421 | public static function clearall_actionless() |
422 | 422 | { |
423 | - return self::clearall( false ); |
|
423 | + return self::clearall(false); |
|
424 | 424 | } |
425 | 425 | |
426 | 426 | /** |
@@ -432,8 +432,8 @@ discard block |
||
432 | 432 | { |
433 | 433 | $contents = array(); |
434 | 434 | |
435 | - foreach ( array( '', 'js', 'css' ) as $dir ) { |
|
436 | - $contents[ $dir ] = scandir( AUTOPTIMIZE_CACHE_DIR . $dir ); |
|
435 | + foreach (array('', 'js', 'css') as $dir) { |
|
436 | + $contents[$dir] = scandir(AUTOPTIMIZE_CACHE_DIR.$dir); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | return $contents; |
@@ -446,21 +446,21 @@ discard block |
||
446 | 446 | */ |
447 | 447 | public static function stats() |
448 | 448 | { |
449 | - $stats = get_transient( 'autoptimize_stats' ); |
|
449 | + $stats = get_transient('autoptimize_stats'); |
|
450 | 450 | |
451 | 451 | // If no transient, do the actual scan! |
452 | - if ( ! is_array( $stats ) ) { |
|
453 | - if ( ! self::cacheavail() ) { |
|
452 | + if (!is_array($stats)) { |
|
453 | + if (!self::cacheavail()) { |
|
454 | 454 | return 0; |
455 | 455 | } |
456 | 456 | $stats = self::stats_scan(); |
457 | 457 | $count = $stats[0]; |
458 | - if ( $count > 100 ) { |
|
458 | + if ($count > 100) { |
|
459 | 459 | // Store results in transient. |
460 | 460 | set_transient( |
461 | 461 | 'autoptimize_stats', |
462 | 462 | $stats, |
463 | - apply_filters( 'autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS ) |
|
463 | + apply_filters('autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS) |
|
464 | 464 | ); |
465 | 465 | } |
466 | 466 | } |
@@ -483,30 +483,30 @@ discard block |
||
483 | 483 | $size = 0; |
484 | 484 | |
485 | 485 | // Scan everything in our cache directories. |
486 | - foreach ( self::get_cache_contents() as $name => $files ) { |
|
487 | - $dir = rtrim( AUTOPTIMIZE_CACHE_DIR . $name, '/' ) . '/'; |
|
488 | - foreach ( $files as $file ) { |
|
489 | - if ( self::is_valid_cache_file( $dir, $file ) ) { |
|
490 | - if ( AUTOPTIMIZE_CACHE_NOGZIP && |
|
486 | + foreach (self::get_cache_contents() as $name => $files) { |
|
487 | + $dir = rtrim(AUTOPTIMIZE_CACHE_DIR.$name, '/').'/'; |
|
488 | + foreach ($files as $file) { |
|
489 | + if (self::is_valid_cache_file($dir, $file)) { |
|
490 | + if (AUTOPTIMIZE_CACHE_NOGZIP && |
|
491 | 491 | ( |
492 | - false !== strpos( $file, '.js' ) || |
|
493 | - false !== strpos( $file, '.css' ) || |
|
494 | - false !== strpos( $file, '.img' ) || |
|
495 | - false !== strpos( $file, '.txt' ) |
|
492 | + false !== strpos($file, '.js') || |
|
493 | + false !== strpos($file, '.css') || |
|
494 | + false !== strpos($file, '.img') || |
|
495 | + false !== strpos($file, '.txt') |
|
496 | 496 | ) |
497 | 497 | ) { |
498 | 498 | // Web server is gzipping, we count .js|.css|.img|.txt files. |
499 | 499 | $count++; |
500 | - } elseif ( ! AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos( $file, '.none' ) ) { |
|
500 | + } elseif (!AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos($file, '.none')) { |
|
501 | 501 | // We are gzipping ourselves via php, counting only .none files. |
502 | 502 | $count++; |
503 | 503 | } |
504 | - $size += filesize( $dir . $file ); |
|
504 | + $size += filesize($dir.$file); |
|
505 | 505 | } |
506 | 506 | } |
507 | 507 | } |
508 | 508 | |
509 | - $stats = array( $count, $size, time() ); |
|
509 | + $stats = array($count, $size, time()); |
|
510 | 510 | |
511 | 511 | return $stats; |
512 | 512 | } |
@@ -520,22 +520,22 @@ discard block |
||
520 | 520 | */ |
521 | 521 | public static function cacheavail() |
522 | 522 | { |
523 | - if ( false === autoptimizeCache::check_and_create_dirs() ) { |
|
523 | + if (false === autoptimizeCache::check_and_create_dirs()) { |
|
524 | 524 | return false; |
525 | 525 | } |
526 | 526 | |
527 | 527 | // Using .htaccess inside our cache folder to overrule wp-super-cache. |
528 | - $htaccess = AUTOPTIMIZE_CACHE_DIR . '/.htaccess'; |
|
529 | - if ( ! is_file( $htaccess ) ) { |
|
528 | + $htaccess = AUTOPTIMIZE_CACHE_DIR.'/.htaccess'; |
|
529 | + if (!is_file($htaccess)) { |
|
530 | 530 | /** |
531 | 531 | * Create `wp-content/AO_htaccess_tmpl` file with |
532 | 532 | * whatever htaccess rules you might need |
533 | 533 | * if you want to override default AO htaccess |
534 | 534 | */ |
535 | - $htaccess_tmpl = WP_CONTENT_DIR . '/AO_htaccess_tmpl'; |
|
536 | - if ( is_file( $htaccess_tmpl ) ) { |
|
537 | - $content = file_get_contents( $htaccess_tmpl ); |
|
538 | - } elseif ( is_multisite() || ! AUTOPTIMIZE_CACHE_NOGZIP ) { |
|
535 | + $htaccess_tmpl = WP_CONTENT_DIR.'/AO_htaccess_tmpl'; |
|
536 | + if (is_file($htaccess_tmpl)) { |
|
537 | + $content = file_get_contents($htaccess_tmpl); |
|
538 | + } elseif (is_multisite() || !AUTOPTIMIZE_CACHE_NOGZIP) { |
|
539 | 539 | $content = '<IfModule mod_expires.c> |
540 | 540 | ExpiresActive On |
541 | 541 | ExpiresByType text/css A30672000 |
@@ -589,13 +589,13 @@ discard block |
||
589 | 589 | </IfModule>'; |
590 | 590 | } |
591 | 591 | |
592 | - if ( self::do_fallback() ) { |
|
593 | - $content .= "\nErrorDocument 404 " . trailingslashit( parse_url( content_url(), PHP_URL_PATH ) ) . 'autoptimize_404_handler.php'; |
|
592 | + if (self::do_fallback()) { |
|
593 | + $content .= "\nErrorDocument 404 ".trailingslashit(parse_url(content_url(), PHP_URL_PATH)).'autoptimize_404_handler.php'; |
|
594 | 594 | } |
595 | - @file_put_contents( $htaccess, $content ); // @codingStandardsIgnoreLine |
|
595 | + @file_put_contents($htaccess, $content); // @codingStandardsIgnoreLine |
|
596 | 596 | } |
597 | 597 | |
598 | - if ( self::do_fallback() ) { |
|
598 | + if (self::do_fallback()) { |
|
599 | 599 | self::check_fallback_php(); |
600 | 600 | } |
601 | 601 | |
@@ -610,17 +610,17 @@ discard block |
||
610 | 610 | */ |
611 | 611 | public static function check_fallback_php() { |
612 | 612 | $_fallback_filename = 'autoptimize_404_handler.php'; |
613 | - $_fallback_php = trailingslashit( WP_CONTENT_DIR ) . $_fallback_filename; |
|
613 | + $_fallback_php = trailingslashit(WP_CONTENT_DIR).$_fallback_filename; |
|
614 | 614 | $_fallback_status = true; |
615 | 615 | |
616 | - if ( ! file_exists( $_fallback_php ) ) { |
|
617 | - $_fallback_php_contents = file_get_contents( AUTOPTIMIZE_PLUGIN_DIR . 'config/' . $_fallback_filename ); |
|
618 | - $_fallback_php_contents = str_replace( '<?php exit;', '<?php', $_fallback_php_contents ); |
|
619 | - $_fallback_php_contents = str_replace( '<!--ao-cache-dir-->', AUTOPTIMIZE_CACHE_DIR, $_fallback_php_contents ); |
|
620 | - if ( apply_filters( 'autoptimize_filter_cache_fallback_log_errors', false ) ) { |
|
621 | - $_fallback_php_contents = str_replace( '// error_log', 'error_log', $_fallback_php_contents ); |
|
616 | + if (!file_exists($_fallback_php)) { |
|
617 | + $_fallback_php_contents = file_get_contents(AUTOPTIMIZE_PLUGIN_DIR.'config/'.$_fallback_filename); |
|
618 | + $_fallback_php_contents = str_replace('<?php exit;', '<?php', $_fallback_php_contents); |
|
619 | + $_fallback_php_contents = str_replace('<!--ao-cache-dir-->', AUTOPTIMIZE_CACHE_DIR, $_fallback_php_contents); |
|
620 | + if (apply_filters('autoptimize_filter_cache_fallback_log_errors', false)) { |
|
621 | + $_fallback_php_contents = str_replace('// error_log', 'error_log', $_fallback_php_contents); |
|
622 | 622 | } |
623 | - $_fallback_status = file_put_contents( $_fallback_php, $_fallback_php_contents ); |
|
623 | + $_fallback_status = file_put_contents($_fallback_php, $_fallback_php_contents); |
|
624 | 624 | } |
625 | 625 | |
626 | 626 | return $_fallback_status; |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | * Return bool |
634 | 634 | */ |
635 | 635 | public static function do_fallback() { |
636 | - return apply_filters( 'autoptimize_filter_cache_do_fallback', false ); |
|
636 | + return apply_filters('autoptimize_filter_cache_do_fallback', false); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | /** |
@@ -643,13 +643,13 @@ discard block |
||
643 | 643 | * @return bool |
644 | 644 | */ |
645 | 645 | public static function check_and_create_dirs() { |
646 | - if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) { |
|
646 | + if (!defined('AUTOPTIMIZE_CACHE_DIR')) { |
|
647 | 647 | // We didn't set a cache. |
648 | 648 | return false; |
649 | 649 | } |
650 | 650 | |
651 | - foreach ( array( '', 'js', 'css' ) as $dir ) { |
|
652 | - if ( ! self::check_cache_dir( AUTOPTIMIZE_CACHE_DIR . $dir ) ) { |
|
651 | + foreach (array('', 'js', 'css') as $dir) { |
|
652 | + if (!self::check_cache_dir(AUTOPTIMIZE_CACHE_DIR.$dir)) { |
|
653 | 653 | return false; |
654 | 654 | } |
655 | 655 | } |
@@ -664,25 +664,25 @@ discard block |
||
664 | 664 | * |
665 | 665 | * @return bool |
666 | 666 | */ |
667 | - protected static function check_cache_dir( $dir ) |
|
667 | + protected static function check_cache_dir($dir) |
|
668 | 668 | { |
669 | 669 | // Try creating the dir if it doesn't exist. |
670 | - if ( ! file_exists( $dir ) ) { |
|
671 | - @mkdir( $dir, 0775, true ); // @codingStandardsIgnoreLine |
|
672 | - if ( ! file_exists( $dir ) ) { |
|
670 | + if (!file_exists($dir)) { |
|
671 | + @mkdir($dir, 0775, true); // @codingStandardsIgnoreLine |
|
672 | + if (!file_exists($dir)) { |
|
673 | 673 | return false; |
674 | 674 | } |
675 | 675 | } |
676 | 676 | |
677 | 677 | // If we still cannot write, bail. |
678 | - if ( ! is_writable( $dir ) ) { |
|
678 | + if (!is_writable($dir)) { |
|
679 | 679 | return false; |
680 | 680 | } |
681 | 681 | |
682 | 682 | // Create an index.html in there to avoid prying eyes! |
683 | - $idx_file = rtrim( $dir, '/\\' ) . '/index.html'; |
|
684 | - if ( ! is_file( $idx_file ) ) { |
|
685 | - @file_put_contents( $idx_file, '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>' ); // @codingStandardsIgnoreLine |
|
683 | + $idx_file = rtrim($dir, '/\\').'/index.html'; |
|
684 | + if (!is_file($idx_file)) { |
|
685 | + @file_put_contents($idx_file, '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>'); // @codingStandardsIgnoreLine |
|
686 | 686 | } |
687 | 687 | |
688 | 688 | return true; |
@@ -696,50 +696,50 @@ discard block |
||
696 | 696 | // @codingStandardsIgnoreStart |
697 | 697 | public static function flushPageCache() |
698 | 698 | { |
699 | - if ( function_exists( 'wp_cache_clear_cache' ) ) { |
|
700 | - if ( is_multisite() ) { |
|
699 | + if (function_exists('wp_cache_clear_cache')) { |
|
700 | + if (is_multisite()) { |
|
701 | 701 | $blog_id = get_current_blog_id(); |
702 | - wp_cache_clear_cache( $blog_id ); |
|
702 | + wp_cache_clear_cache($blog_id); |
|
703 | 703 | } else { |
704 | 704 | wp_cache_clear_cache(); |
705 | 705 | } |
706 | - } elseif ( has_action( 'cachify_flush_cache' ) ) { |
|
707 | - do_action( 'cachify_flush_cache' ); |
|
708 | - } elseif ( function_exists( 'w3tc_pgcache_flush' ) ) { |
|
706 | + } elseif (has_action('cachify_flush_cache')) { |
|
707 | + do_action('cachify_flush_cache'); |
|
708 | + } elseif (function_exists('w3tc_pgcache_flush')) { |
|
709 | 709 | w3tc_pgcache_flush(); |
710 | - } elseif ( function_exists( 'wp_fast_cache_bulk_delete_all' ) ) { |
|
710 | + } elseif (function_exists('wp_fast_cache_bulk_delete_all')) { |
|
711 | 711 | wp_fast_cache_bulk_delete_all(); |
712 | - } elseif ( class_exists( 'WpFastestCache' ) ) { |
|
712 | + } elseif (class_exists('WpFastestCache')) { |
|
713 | 713 | $wpfc = new WpFastestCache(); |
714 | 714 | $wpfc->deleteCache(); |
715 | - } elseif ( class_exists( 'c_ws_plugin__qcache_purging_routines' ) ) { |
|
715 | + } elseif (class_exists('c_ws_plugin__qcache_purging_routines')) { |
|
716 | 716 | c_ws_plugin__qcache_purging_routines::purge_cache_dir(); // quick cache |
717 | - } elseif ( class_exists( 'zencache' ) ) { |
|
717 | + } elseif (class_exists('zencache')) { |
|
718 | 718 | zencache::clear(); |
719 | - } elseif ( class_exists( 'comet_cache' ) ) { |
|
719 | + } elseif (class_exists('comet_cache')) { |
|
720 | 720 | comet_cache::clear(); |
721 | - } elseif ( class_exists( 'WpeCommon' ) ) { |
|
721 | + } elseif (class_exists('WpeCommon')) { |
|
722 | 722 | // WPEngine cache purge/flush methods to call by default |
723 | 723 | $wpe_methods = array( |
724 | 724 | 'purge_varnish_cache', |
725 | 725 | ); |
726 | 726 | |
727 | 727 | // More agressive clear/flush/purge behind a filter |
728 | - if ( apply_filters( 'autoptimize_flush_wpengine_aggressive', false ) ) { |
|
729 | - $wpe_methods = array_merge( $wpe_methods, array( 'purge_memcached', 'clear_maxcdn_cache' ) ); |
|
728 | + if (apply_filters('autoptimize_flush_wpengine_aggressive', false)) { |
|
729 | + $wpe_methods = array_merge($wpe_methods, array('purge_memcached', 'clear_maxcdn_cache')); |
|
730 | 730 | } |
731 | 731 | |
732 | 732 | // Filtering the entire list of WpeCommon methods to be called (for advanced usage + easier testing) |
733 | - $wpe_methods = apply_filters( 'autoptimize_flush_wpengine_methods', $wpe_methods ); |
|
733 | + $wpe_methods = apply_filters('autoptimize_flush_wpengine_methods', $wpe_methods); |
|
734 | 734 | |
735 | - foreach ( $wpe_methods as $wpe_method ) { |
|
736 | - if ( method_exists( 'WpeCommon', $wpe_method ) ) { |
|
735 | + foreach ($wpe_methods as $wpe_method) { |
|
736 | + if (method_exists('WpeCommon', $wpe_method)) { |
|
737 | 737 | WpeCommon::$wpe_method(); |
738 | 738 | } |
739 | 739 | } |
740 | - } elseif ( function_exists( 'sg_cachepress_purge_cache' ) ) { |
|
740 | + } elseif (function_exists('sg_cachepress_purge_cache')) { |
|
741 | 741 | sg_cachepress_purge_cache(); |
742 | - } elseif ( array_key_exists( 'KINSTA_CACHE_ZONE', $_SERVER ) ) { |
|
742 | + } elseif (array_key_exists('KINSTA_CACHE_ZONE', $_SERVER)) { |
|
743 | 743 | $_kinsta_clear_cache_url = 'https://localhost/kinsta-clear-cache-all'; |
744 | 744 | $_kinsta_response = wp_remote_get( |
745 | 745 | $_kinsta_clear_cache_url, |
@@ -748,18 +748,18 @@ discard block |
||
748 | 748 | 'timeout' => 5, |
749 | 749 | ) |
750 | 750 | ); |
751 | - } elseif ( defined('NGINX_HELPER_BASENAME') ) { |
|
752 | - do_action( 'rt_nginx_helper_purge_all' ); |
|
753 | - } elseif ( file_exists( WP_CONTENT_DIR . '/wp-cache-config.php' ) && function_exists( 'prune_super_cache' ) ) { |
|
751 | + } elseif (defined('NGINX_HELPER_BASENAME')) { |
|
752 | + do_action('rt_nginx_helper_purge_all'); |
|
753 | + } elseif (file_exists(WP_CONTENT_DIR.'/wp-cache-config.php') && function_exists('prune_super_cache')) { |
|
754 | 754 | // fallback for WP-Super-Cache |
755 | 755 | global $cache_path; |
756 | - if ( is_multisite() ) { |
|
756 | + if (is_multisite()) { |
|
757 | 757 | $blog_id = get_current_blog_id(); |
758 | - prune_super_cache( get_supercache_dir( $blog_id ), true ); |
|
759 | - prune_super_cache( $cache_path . 'blogs/', true ); |
|
758 | + prune_super_cache(get_supercache_dir($blog_id), true); |
|
759 | + prune_super_cache($cache_path.'blogs/', true); |
|
760 | 760 | } else { |
761 | - prune_super_cache( $cache_path . 'supercache/', true ); |
|
762 | - prune_super_cache( $cache_path, true ); |
|
761 | + prune_super_cache($cache_path.'supercache/', true); |
|
762 | + prune_super_cache($cache_path, true); |
|
763 | 763 | } |
764 | 764 | } |
765 | 765 | } |
@@ -418,6 +418,10 @@ discard block |
||
418 | 418 | } |
419 | 419 | |
420 | 420 | // Checks against the white- and blacklists |
421 | + |
|
422 | + /** |
|
423 | + * @param string $tag |
|
424 | + */ |
|
421 | 425 | private function ismergeable($tag) |
422 | 426 | { |
423 | 427 | if ( ! $this->aggregate ) { |
@@ -457,6 +461,10 @@ discard block |
||
457 | 461 | } |
458 | 462 | |
459 | 463 | // Checks agains the blacklist |
464 | + |
|
465 | + /** |
|
466 | + * @param string $tag |
|
467 | + */ |
|
460 | 468 | private function ismovable($tag) |
461 | 469 | { |
462 | 470 | if ( true !== $this->include_inline || apply_filters( 'autoptimize_filter_js_unmovable', true ) ) { |
@@ -538,7 +546,7 @@ discard block |
||
538 | 546 | * @param string $filepath Filepath. |
539 | 547 | * @param bool $cache_miss Optional. Force a cache miss. Default false. |
540 | 548 | * |
541 | - * @return bool|string Url pointing to the minified js file or false. |
|
549 | + * @return false|string Url pointing to the minified js file or false. |
|
542 | 550 | */ |
543 | 551 | public function minify_single( $filepath, $cache_miss = false ) |
544 | 552 | { |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if (!defined('ABSPATH')) { |
|
4 | 4 | exit; |
5 | 5 | } |
6 | 6 | |
@@ -13,18 +13,18 @@ discard block |
||
13 | 13 | ); |
14 | 14 | |
15 | 15 | private $dontmove = array( |
16 | - 'document.write','html5.js','show_ads.js','google_ad','histats.com/js','statcounter.com/counter/counter.js', |
|
17 | - 'ws.amazon.com/widgets','media.fastclick.net','/ads/','comment-form-quicktags/quicktags.php','edToolbar', |
|
18 | - 'intensedebate.com','scripts.chitika.net/','_gaq.push','jotform.com/','admin-bar.min.js','GoogleAnalyticsObject', |
|
19 | - 'plupload.full.min.js','syntaxhighlighter','adsbygoogle','gist.github.com','_stq','nonce','post_id','data-noptimize' |
|
16 | + 'document.write', 'html5.js', 'show_ads.js', 'google_ad', 'histats.com/js', 'statcounter.com/counter/counter.js', |
|
17 | + 'ws.amazon.com/widgets', 'media.fastclick.net', '/ads/', 'comment-form-quicktags/quicktags.php', 'edToolbar', |
|
18 | + 'intensedebate.com', 'scripts.chitika.net/', '_gaq.push', 'jotform.com/', 'admin-bar.min.js', 'GoogleAnalyticsObject', |
|
19 | + 'plupload.full.min.js', 'syntaxhighlighter', 'adsbygoogle', 'gist.github.com', '_stq', 'nonce', 'post_id', 'data-noptimize' |
|
20 | 20 | ,'logHuman' |
21 | 21 | ); |
22 | 22 | private $domove = array( |
23 | - 'gaJsHost','load_cmc','jd.gallery.transitions.js','swfobject.embedSWF(','tiny_mce.js','tinyMCEPreInit.go' |
|
23 | + 'gaJsHost', 'load_cmc', 'jd.gallery.transitions.js', 'swfobject.embedSWF(', 'tiny_mce.js', 'tinyMCEPreInit.go' |
|
24 | 24 | ); |
25 | 25 | private $domovelast = array( |
26 | - 'addthis.com','/afsonline/show_afs_search.js','disqus.js','networkedblogs.com/getnetworkwidget','infolinks.com/js/', |
|
27 | - 'jd.gallery.js.php','jd.gallery.transitions.js','swfobject.embedSWF(','linkwithin.com/widget.js','tiny_mce.js','tinyMCEPreInit.go' |
|
26 | + 'addthis.com', '/afsonline/show_afs_search.js', 'disqus.js', 'networkedblogs.com/getnetworkwidget', 'infolinks.com/js/', |
|
27 | + 'jd.gallery.js.php', 'jd.gallery.transitions.js', 'swfobject.embedSWF(', 'linkwithin.com/widget.js', 'tiny_mce.js', 'tinyMCEPreInit.go' |
|
28 | 28 | ); |
29 | 29 | public $cdn_url = ''; |
30 | 30 | |
@@ -43,92 +43,92 @@ discard block |
||
43 | 43 | private $minify_excluded = true; |
44 | 44 | |
45 | 45 | // Reads the page and collects script tags. |
46 | - public function read( $options ) |
|
46 | + public function read($options) |
|
47 | 47 | { |
48 | - $noptimizeJS = apply_filters( 'autoptimize_filter_js_noptimize', false, $this->content ); |
|
49 | - if ( $noptimizeJS ) { |
|
48 | + $noptimizeJS = apply_filters('autoptimize_filter_js_noptimize', false, $this->content); |
|
49 | + if ($noptimizeJS) { |
|
50 | 50 | return false; |
51 | 51 | } |
52 | 52 | |
53 | 53 | // only optimize known good JS? |
54 | - $whitelistJS = apply_filters( 'autoptimize_filter_js_whitelist', '', $this->content ); |
|
55 | - if ( ! empty( $whitelistJS ) ) { |
|
56 | - $this->whitelist = array_filter( array_map( 'trim', explode( ',', $whitelistJS ) ) ); |
|
54 | + $whitelistJS = apply_filters('autoptimize_filter_js_whitelist', '', $this->content); |
|
55 | + if (!empty($whitelistJS)) { |
|
56 | + $this->whitelist = array_filter(array_map('trim', explode(',', $whitelistJS))); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | // is there JS we should simply remove? |
60 | - $removableJS = apply_filters( 'autoptimize_filter_js_removables', '', $this->content ); |
|
61 | - if ( !empty( $removableJS ) ) { |
|
62 | - $this->jsremovables = array_filter( array_map( 'trim', explode( ',', $removableJS ) ) ); |
|
60 | + $removableJS = apply_filters('autoptimize_filter_js_removables', '', $this->content); |
|
61 | + if (!empty($removableJS)) { |
|
62 | + $this->jsremovables = array_filter(array_map('trim', explode(',', $removableJS))); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | // only header? |
66 | - if ( apply_filters( 'autoptimize_filter_js_justhead', $options['justhead'] ) ) { |
|
67 | - $content = explode( '</head>', $this->content, 2 ); |
|
68 | - $this->content = $content[0] . '</head>'; |
|
66 | + if (apply_filters('autoptimize_filter_js_justhead', $options['justhead'])) { |
|
67 | + $content = explode('</head>', $this->content, 2); |
|
68 | + $this->content = $content[0].'</head>'; |
|
69 | 69 | $this->restofcontent = $content[1]; |
70 | 70 | } |
71 | 71 | |
72 | 72 | // Determine whether we're doing JS-files aggregation or not. |
73 | - if ( ! $options['aggregate'] ) { |
|
73 | + if (!$options['aggregate']) { |
|
74 | 74 | $this->aggregate = false; |
75 | 75 | } |
76 | 76 | // Returning true for "dontaggregate" turns off aggregation. |
77 | - if ( $this->aggregate && apply_filters( 'autoptimize_filter_js_dontaggregate', false ) ) { |
|
77 | + if ($this->aggregate && apply_filters('autoptimize_filter_js_dontaggregate', false)) { |
|
78 | 78 | $this->aggregate = false; |
79 | 79 | } |
80 | 80 | |
81 | 81 | // include inline? |
82 | - if ( apply_filters( 'autoptimize_js_include_inline', $options['include_inline'] ) ) { |
|
82 | + if (apply_filters('autoptimize_js_include_inline', $options['include_inline'])) { |
|
83 | 83 | $this->include_inline = true; |
84 | 84 | } |
85 | 85 | |
86 | 86 | // filter to "late inject minified JS", default to true for now (it is faster). |
87 | - $this->inject_min_late = apply_filters( 'autoptimize_filter_js_inject_min_late', true ); |
|
87 | + $this->inject_min_late = apply_filters('autoptimize_filter_js_inject_min_late', true); |
|
88 | 88 | |
89 | 89 | // filters to override hardcoded do(nt)move(last) array contents (array in, array out!). |
90 | - $this->dontmove = apply_filters( 'autoptimize_filter_js_dontmove', $this->dontmove ); |
|
91 | - $this->domovelast = apply_filters( 'autoptimize_filter_js_movelast', $this->domovelast ); |
|
92 | - $this->domove = apply_filters( 'autoptimize_filter_js_domove', $this->domove ); |
|
90 | + $this->dontmove = apply_filters('autoptimize_filter_js_dontmove', $this->dontmove); |
|
91 | + $this->domovelast = apply_filters('autoptimize_filter_js_movelast', $this->domovelast); |
|
92 | + $this->domove = apply_filters('autoptimize_filter_js_domove', $this->domove); |
|
93 | 93 | |
94 | 94 | // Determine whether excluded files should be minified if not yet so. |
95 | - if ( ! $options['minify_excluded'] && $options['aggregate'] ) { |
|
95 | + if (!$options['minify_excluded'] && $options['aggregate']) { |
|
96 | 96 | $this->minify_excluded = false; |
97 | 97 | } |
98 | - $this->minify_excluded = apply_filters( 'autoptimize_filter_js_minify_excluded', $this->minify_excluded, '' ); |
|
98 | + $this->minify_excluded = apply_filters('autoptimize_filter_js_minify_excluded', $this->minify_excluded, ''); |
|
99 | 99 | |
100 | 100 | // get extra exclusions settings or filter. |
101 | 101 | $excludeJS = $options['js_exclude']; |
102 | - $excludeJS = apply_filters( 'autoptimize_filter_js_exclude', $excludeJS, $this->content ); |
|
102 | + $excludeJS = apply_filters('autoptimize_filter_js_exclude', $excludeJS, $this->content); |
|
103 | 103 | |
104 | - if ( '' !== $excludeJS ) { |
|
105 | - if ( is_array( $excludeJS ) ) { |
|
106 | - if ( ( $removeKeys = array_keys( $excludeJS, 'remove' ) ) !== false ) { |
|
107 | - foreach ( $removeKeys as $removeKey ) { |
|
108 | - unset( $excludeJS[$removeKey] ); |
|
104 | + if ('' !== $excludeJS) { |
|
105 | + if (is_array($excludeJS)) { |
|
106 | + if (($removeKeys = array_keys($excludeJS, 'remove')) !== false) { |
|
107 | + foreach ($removeKeys as $removeKey) { |
|
108 | + unset($excludeJS[$removeKey]); |
|
109 | 109 | $this->jsremovables[] = $removeKey; |
110 | 110 | } |
111 | 111 | } |
112 | - $exclJSArr = array_keys( $excludeJS ); |
|
112 | + $exclJSArr = array_keys($excludeJS); |
|
113 | 113 | } else { |
114 | - $exclJSArr = array_filter( array_map( 'trim', explode( ',', $excludeJS ) ) ); |
|
114 | + $exclJSArr = array_filter(array_map('trim', explode(',', $excludeJS))); |
|
115 | 115 | } |
116 | - $this->dontmove = array_merge( $exclJSArr, $this->dontmove ); |
|
116 | + $this->dontmove = array_merge($exclJSArr, $this->dontmove); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | // Should we add try-catch? |
120 | - if ( $options['trycatch'] ) { |
|
120 | + if ($options['trycatch']) { |
|
121 | 121 | $this->trycatch = true; |
122 | 122 | } |
123 | 123 | |
124 | 124 | // force js in head? |
125 | - if ( $options['forcehead'] ) { |
|
125 | + if ($options['forcehead']) { |
|
126 | 126 | $this->forcehead = true; |
127 | 127 | } else { |
128 | 128 | $this->forcehead = false; |
129 | 129 | } |
130 | 130 | |
131 | - $this->forcehead = apply_filters( 'autoptimize_filter_js_forcehead', $this->forcehead ); |
|
131 | + $this->forcehead = apply_filters('autoptimize_filter_js_forcehead', $this->forcehead); |
|
132 | 132 | |
133 | 133 | // get cdn url. |
134 | 134 | $this->cdn_url = $options['cdn_url']; |
@@ -143,26 +143,26 @@ discard block |
||
143 | 143 | $this->content = $this->hide_comments($this->content); |
144 | 144 | |
145 | 145 | // Get script files. |
146 | - if ( preg_match_all( '#<script.*</script>#Usmi', $this->content, $matches ) ) { |
|
147 | - foreach( $matches[0] as $tag ) { |
|
146 | + if (preg_match_all('#<script.*</script>#Usmi', $this->content, $matches)) { |
|
147 | + foreach ($matches[0] as $tag) { |
|
148 | 148 | // only consider script aggregation for types whitelisted in should_aggregate-function. |
149 | 149 | $should_aggregate = $this->should_aggregate($tag); |
150 | - if ( ! $should_aggregate ) { |
|
150 | + if (!$should_aggregate) { |
|
151 | 151 | $tag = ''; |
152 | 152 | continue; |
153 | 153 | } |
154 | 154 | |
155 | - if ( preg_match( '#<script[^>]*src=("|\')([^>]*)("|\')#Usmi', $tag, $source ) ) { |
|
155 | + if (preg_match('#<script[^>]*src=("|\')([^>]*)("|\')#Usmi', $tag, $source)) { |
|
156 | 156 | // non-inline script. |
157 | - if ( $this->isremovable($tag, $this->jsremovables) ) { |
|
158 | - $this->content = str_replace( $tag, '', $this->content ); |
|
157 | + if ($this->isremovable($tag, $this->jsremovables)) { |
|
158 | + $this->content = str_replace($tag, '', $this->content); |
|
159 | 159 | continue; |
160 | 160 | } |
161 | 161 | |
162 | 162 | $origTag = null; |
163 | - $url = current( explode( '?', $source[2], 2 ) ); |
|
163 | + $url = current(explode('?', $source[2], 2)); |
|
164 | 164 | $path = $this->getpath($url); |
165 | - if ( false !== $path && preg_match( '#\.js$#', $path ) && $this->ismergeable($tag) ) { |
|
165 | + if (false !== $path && preg_match('#\.js$#', $path) && $this->ismergeable($tag)) { |
|
166 | 166 | // ok to optimize, add to array. |
167 | 167 | $this->scripts[] = $path; |
168 | 168 | } else { |
@@ -170,11 +170,11 @@ discard block |
||
170 | 170 | $newTag = $tag; |
171 | 171 | |
172 | 172 | // non-mergeable script (excluded or dynamic or external). |
173 | - if ( is_array( $excludeJS ) ) { |
|
173 | + if (is_array($excludeJS)) { |
|
174 | 174 | // should we add flags? |
175 | - foreach ( $excludeJS as $exclTag => $exclFlags) { |
|
176 | - if ( false !== strpos( $origTag, $exclTag ) && in_array( $exclFlags, array( 'async', 'defer' ) ) ) { |
|
177 | - $newTag = str_replace( '<script ', '<script ' . $exclFlags . ' ', $newTag ); |
|
175 | + foreach ($excludeJS as $exclTag => $exclFlags) { |
|
176 | + if (false !== strpos($origTag, $exclTag) && in_array($exclFlags, array('async', 'defer'))) { |
|
177 | + $newTag = str_replace('<script ', '<script '.$exclFlags.' ', $newTag); |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | } |
@@ -182,28 +182,28 @@ discard block |
||
182 | 182 | // Should we minify the non-aggregated script? |
183 | 183 | // -> if aggregate is on and exclude minify is on |
184 | 184 | // -> if aggregate is off and the file is not in dontmove. |
185 | - if ( $path && $this->minify_excluded ) { |
|
186 | - $consider_minified_array = apply_filters( 'autoptimize_filter_js_consider_minified', false ); |
|
187 | - if ( ( false === $this->aggregate && str_replace( $this->dontmove, '', $path ) === $path ) || ( true === $this->aggregate && ( false === $consider_minified_array || str_replace( $consider_minified_array, '', $path ) === $path ) ) ) { |
|
188 | - $minified_url = $this->minify_single( $path ); |
|
185 | + if ($path && $this->minify_excluded) { |
|
186 | + $consider_minified_array = apply_filters('autoptimize_filter_js_consider_minified', false); |
|
187 | + if ((false === $this->aggregate && str_replace($this->dontmove, '', $path) === $path) || (true === $this->aggregate && (false === $consider_minified_array || str_replace($consider_minified_array, '', $path) === $path))) { |
|
188 | + $minified_url = $this->minify_single($path); |
|
189 | 189 | // replace orig URL with minified URL from cache if so. |
190 | - if ( ! empty( $minified_url ) ) { |
|
191 | - $newTag = str_replace( $url, $minified_url, $newTag ); |
|
190 | + if (!empty($minified_url)) { |
|
191 | + $newTag = str_replace($url, $minified_url, $newTag); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
196 | - if ( $this->ismovable($newTag) ) { |
|
196 | + if ($this->ismovable($newTag)) { |
|
197 | 197 | // can be moved, flags and all. |
198 | - if ( $this->movetolast($newTag) ) { |
|
198 | + if ($this->movetolast($newTag)) { |
|
199 | 199 | $this->move['last'][] = $newTag; |
200 | 200 | } else { |
201 | 201 | $this->move['first'][] = $newTag; |
202 | 202 | } |
203 | 203 | } else { |
204 | 204 | // cannot be moved, so if flag was added re-inject altered tag immediately. |
205 | - if ( $origTag !== $newTag ) { |
|
206 | - $this->content = str_replace( $origTag, $newTag, $this->content ); |
|
205 | + if ($origTag !== $newTag) { |
|
206 | + $this->content = str_replace($origTag, $newTag, $this->content); |
|
207 | 207 | $origTag = ''; |
208 | 208 | } |
209 | 209 | // and forget about the $tag (not to be touched any more). |
@@ -212,23 +212,23 @@ discard block |
||
212 | 212 | } |
213 | 213 | } else { |
214 | 214 | // Inline script. |
215 | - if ( $this->isremovable($tag, $this->jsremovables) ) { |
|
216 | - $this->content = str_replace( $tag, '', $this->content ); |
|
215 | + if ($this->isremovable($tag, $this->jsremovables)) { |
|
216 | + $this->content = str_replace($tag, '', $this->content); |
|
217 | 217 | continue; |
218 | 218 | } |
219 | 219 | |
220 | 220 | // unhide comments, as javascript may be wrapped in comment-tags for old times' sake. |
221 | 221 | $tag = $this->restore_comments($tag); |
222 | - if ( $this->ismergeable($tag) && $this->include_inline ) { |
|
223 | - preg_match( '#<script.*>(.*)</script>#Usmi', $tag , $code ); |
|
224 | - $code = preg_replace('#.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*#sm', '$1', $code[1] ); |
|
225 | - $code = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $code ); |
|
226 | - $this->scripts[] = 'INLINE;' . $code; |
|
222 | + if ($this->ismergeable($tag) && $this->include_inline) { |
|
223 | + preg_match('#<script.*>(.*)</script>#Usmi', $tag, $code); |
|
224 | + $code = preg_replace('#.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*#sm', '$1', $code[1]); |
|
225 | + $code = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $code); |
|
226 | + $this->scripts[] = 'INLINE;'.$code; |
|
227 | 227 | } else { |
228 | 228 | // Can we move this? |
229 | - $autoptimize_js_moveable = apply_filters( 'autoptimize_js_moveable', '', $tag ); |
|
230 | - if ( $this->ismovable($tag) || '' !== $autoptimize_js_moveable ) { |
|
231 | - if ( $this->movetolast($tag) || 'last' === $autoptimize_js_moveable ) { |
|
229 | + $autoptimize_js_moveable = apply_filters('autoptimize_js_moveable', '', $tag); |
|
230 | + if ($this->ismovable($tag) || '' !== $autoptimize_js_moveable) { |
|
231 | + if ($this->movetolast($tag) || 'last' === $autoptimize_js_moveable) { |
|
232 | 232 | $this->move['last'][] = $tag; |
233 | 233 | } else { |
234 | 234 | $this->move['first'][] = $tag; |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | } |
244 | 244 | |
245 | 245 | //Remove the original script tag. |
246 | - $this->content = str_replace( $tag, '', $this->content ); |
|
246 | + $this->content = str_replace($tag, '', $this->content); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | return true; |
@@ -273,21 +273,21 @@ discard block |
||
273 | 273 | // We're only interested in the type attribute of the <script> tag itself, not any possible |
274 | 274 | // inline code that might just contain the 'type=' string... |
275 | 275 | $tag_parts = array(); |
276 | - preg_match( '#<(script[^>]*)>#i', $tag, $tag_parts); |
|
276 | + preg_match('#<(script[^>]*)>#i', $tag, $tag_parts); |
|
277 | 277 | $tag_without_contents = null; |
278 | - if ( ! empty( $tag_parts[1] ) ) { |
|
278 | + if (!empty($tag_parts[1])) { |
|
279 | 279 | $tag_without_contents = $tag_parts[1]; |
280 | 280 | } |
281 | 281 | |
282 | - $has_type = ( strpos( $tag_without_contents, 'type' ) !== false ); |
|
282 | + $has_type = (strpos($tag_without_contents, 'type') !== false); |
|
283 | 283 | |
284 | 284 | $type_valid = false; |
285 | - if ( $has_type ) { |
|
286 | - $type_valid = (bool) preg_match( '/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $tag_without_contents ); |
|
285 | + if ($has_type) { |
|
286 | + $type_valid = (bool) preg_match('/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $tag_without_contents); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | $should_aggregate = false; |
290 | - if ( ! $has_type || $type_valid ) { |
|
290 | + if (!$has_type || $type_valid) { |
|
291 | 291 | $should_aggregate = true; |
292 | 292 | } |
293 | 293 | |
@@ -297,40 +297,40 @@ discard block |
||
297 | 297 | //Joins and optimizes JS |
298 | 298 | public function minify() |
299 | 299 | { |
300 | - foreach ( $this->scripts as $script ) { |
|
300 | + foreach ($this->scripts as $script) { |
|
301 | 301 | // TODO/FIXME: some duplicate code here, can be reduced/simplified |
302 | - if ( preg_match( '#^INLINE;#', $script ) ) { |
|
302 | + if (preg_match('#^INLINE;#', $script)) { |
|
303 | 303 | // Inline script |
304 | - $script = preg_replace( '#^INLINE;#', '', $script ); |
|
305 | - $script = rtrim( $script, ";\n\t\r" ) . ';'; |
|
304 | + $script = preg_replace('#^INLINE;#', '', $script); |
|
305 | + $script = rtrim($script, ";\n\t\r").';'; |
|
306 | 306 | // Add try-catch? |
307 | - if ( $this->trycatch ) { |
|
308 | - $script = 'try{' . $script . '}catch(e){}'; |
|
307 | + if ($this->trycatch) { |
|
308 | + $script = 'try{'.$script.'}catch(e){}'; |
|
309 | 309 | } |
310 | - $tmpscript = apply_filters( 'autoptimize_js_individual_script', $script, '' ); |
|
311 | - if ( has_filter( 'autoptimize_js_individual_script' ) && ! empty( $tmpscript ) ) { |
|
310 | + $tmpscript = apply_filters('autoptimize_js_individual_script', $script, ''); |
|
311 | + if (has_filter('autoptimize_js_individual_script') && !empty($tmpscript)) { |
|
312 | 312 | $script = $tmpscript; |
313 | 313 | $this->alreadyminified = true; |
314 | 314 | } |
315 | - $this->jscode .= "\n" . $script; |
|
315 | + $this->jscode .= "\n".$script; |
|
316 | 316 | } else { |
317 | 317 | // External script |
318 | - if ( false !== $script && file_exists( $script ) && is_readable( $script ) ) { |
|
319 | - $scriptsrc = file_get_contents( $script ); |
|
320 | - $scriptsrc = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $scriptsrc ); |
|
321 | - $scriptsrc = rtrim( $scriptsrc, ";\n\t\r" ) . ';'; |
|
318 | + if (false !== $script && file_exists($script) && is_readable($script)) { |
|
319 | + $scriptsrc = file_get_contents($script); |
|
320 | + $scriptsrc = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $scriptsrc); |
|
321 | + $scriptsrc = rtrim($scriptsrc, ";\n\t\r").';'; |
|
322 | 322 | // Add try-catch? |
323 | - if ( $this->trycatch ) { |
|
324 | - $scriptsrc = 'try{' . $scriptsrc . '}catch(e){}'; |
|
323 | + if ($this->trycatch) { |
|
324 | + $scriptsrc = 'try{'.$scriptsrc.'}catch(e){}'; |
|
325 | 325 | } |
326 | - $tmpscriptsrc = apply_filters( 'autoptimize_js_individual_script', $scriptsrc, $script ); |
|
327 | - if ( has_filter( 'autoptimize_js_individual_script' ) && ! empty( $tmpscriptsrc ) ) { |
|
326 | + $tmpscriptsrc = apply_filters('autoptimize_js_individual_script', $scriptsrc, $script); |
|
327 | + if (has_filter('autoptimize_js_individual_script') && !empty($tmpscriptsrc)) { |
|
328 | 328 | $scriptsrc = $tmpscriptsrc; |
329 | 329 | $this->alreadyminified = true; |
330 | - } else if ( $this->can_inject_late($script) ) { |
|
330 | + } else if ($this->can_inject_late($script)) { |
|
331 | 331 | $scriptsrc = self::build_injectlater_marker($script, md5($scriptsrc)); |
332 | 332 | } |
333 | - $this->jscode .= "\n" . $scriptsrc; |
|
333 | + $this->jscode .= "\n".$scriptsrc; |
|
334 | 334 | }/*else{ |
335 | 335 | //Couldn't read JS. Maybe getpath isn't working? |
336 | 336 | }*/ |
@@ -338,32 +338,32 @@ discard block |
||
338 | 338 | } |
339 | 339 | |
340 | 340 | // Check for already-minified code |
341 | - $this->md5hash = md5( $this->jscode ); |
|
341 | + $this->md5hash = md5($this->jscode); |
|
342 | 342 | $ccheck = new autoptimizeCache($this->md5hash, 'js'); |
343 | - if ( $ccheck->check() ) { |
|
343 | + if ($ccheck->check()) { |
|
344 | 344 | $this->jscode = $ccheck->retrieve(); |
345 | 345 | return true; |
346 | 346 | } |
347 | - unset( $ccheck ); |
|
347 | + unset($ccheck); |
|
348 | 348 | |
349 | 349 | // $this->jscode has all the uncompressed code now. |
350 | - if ( true !== $this->alreadyminified ) { |
|
351 | - if ( apply_filters( 'autoptimize_js_do_minify', true ) ) { |
|
352 | - $tmp_jscode = trim( JSMin::minify( $this->jscode ) ); |
|
353 | - if ( ! empty( $tmp_jscode ) ) { |
|
350 | + if (true !== $this->alreadyminified) { |
|
351 | + if (apply_filters('autoptimize_js_do_minify', true)) { |
|
352 | + $tmp_jscode = trim(JSMin::minify($this->jscode)); |
|
353 | + if (!empty($tmp_jscode)) { |
|
354 | 354 | $this->jscode = $tmp_jscode; |
355 | - unset( $tmp_jscode ); |
|
355 | + unset($tmp_jscode); |
|
356 | 356 | } |
357 | - $this->jscode = $this->inject_minified( $this->jscode ); |
|
358 | - $this->jscode = apply_filters( 'autoptimize_js_after_minify', $this->jscode ); |
|
357 | + $this->jscode = $this->inject_minified($this->jscode); |
|
358 | + $this->jscode = apply_filters('autoptimize_js_after_minify', $this->jscode); |
|
359 | 359 | return true; |
360 | 360 | } else { |
361 | - $this->jscode = $this->inject_minified( $this->jscode ); |
|
361 | + $this->jscode = $this->inject_minified($this->jscode); |
|
362 | 362 | return false; |
363 | 363 | } |
364 | 364 | } |
365 | 365 | |
366 | - $this->jscode = apply_filters( 'autoptimize_js_after_minify', $this->jscode ); |
|
366 | + $this->jscode = apply_filters('autoptimize_js_after_minify', $this->jscode); |
|
367 | 367 | return true; |
368 | 368 | } |
369 | 369 | |
@@ -371,11 +371,11 @@ discard block |
||
371 | 371 | public function cache() |
372 | 372 | { |
373 | 373 | $cache = new autoptimizeCache($this->md5hash, 'js'); |
374 | - if ( ! $cache->check() ) { |
|
374 | + if (!$cache->check()) { |
|
375 | 375 | // Cache our code |
376 | 376 | $cache->cache($this->jscode, 'text/javascript'); |
377 | 377 | } |
378 | - $this->url = AUTOPTIMIZE_CACHE_URL . $cache->getname(); |
|
378 | + $this->url = AUTOPTIMIZE_CACHE_URL.$cache->getname(); |
|
379 | 379 | $this->url = $this->url_replace_cdn($this->url); |
380 | 380 | } |
381 | 381 | |
@@ -383,47 +383,47 @@ discard block |
||
383 | 383 | public function getcontent() |
384 | 384 | { |
385 | 385 | // Restore the full content |
386 | - if ( ! empty( $this->restofcontent ) ) { |
|
386 | + if (!empty($this->restofcontent)) { |
|
387 | 387 | $this->content .= $this->restofcontent; |
388 | 388 | $this->restofcontent = ''; |
389 | 389 | } |
390 | 390 | |
391 | 391 | // Add the scripts taking forcehead/ deferred (default) into account |
392 | - if ( $this->forcehead ) { |
|
393 | - $replaceTag = array( '</head>', 'before' ); |
|
392 | + if ($this->forcehead) { |
|
393 | + $replaceTag = array('</head>', 'before'); |
|
394 | 394 | $defer = ''; |
395 | 395 | } else { |
396 | - $replaceTag = array( '</body>', 'before' ); |
|
396 | + $replaceTag = array('</body>', 'before'); |
|
397 | 397 | $defer = 'defer '; |
398 | 398 | } |
399 | 399 | |
400 | - $defer = apply_filters( 'autoptimize_filter_js_defer', $defer ); |
|
400 | + $defer = apply_filters('autoptimize_filter_js_defer', $defer); |
|
401 | 401 | $type_js = ''; |
402 | - if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) { |
|
402 | + if (apply_filters('autoptimize_filter_cssjs_addtype', false)) { |
|
403 | 403 | $type_js = 'type="text/javascript" '; |
404 | 404 | } |
405 | 405 | |
406 | - $bodyreplacementpayload = '<script ' . $type_js . $defer . 'src="' . $this->url . '"></script>'; |
|
407 | - $bodyreplacementpayload = apply_filters( 'autoptimize_filter_js_bodyreplacementpayload', $bodyreplacementpayload ); |
|
406 | + $bodyreplacementpayload = '<script '.$type_js.$defer.'src="'.$this->url.'"></script>'; |
|
407 | + $bodyreplacementpayload = apply_filters('autoptimize_filter_js_bodyreplacementpayload', $bodyreplacementpayload); |
|
408 | 408 | |
409 | - $bodyreplacement = implode( '', $this->move['first'] ); |
|
409 | + $bodyreplacement = implode('', $this->move['first']); |
|
410 | 410 | $bodyreplacement .= $bodyreplacementpayload; |
411 | - $bodyreplacement .= implode( '', $this->move['last'] ); |
|
411 | + $bodyreplacement .= implode('', $this->move['last']); |
|
412 | 412 | |
413 | - $replaceTag = apply_filters( 'autoptimize_filter_js_replacetag', $replaceTag ); |
|
413 | + $replaceTag = apply_filters('autoptimize_filter_js_replacetag', $replaceTag); |
|
414 | 414 | |
415 | - if ( strlen( $this->jscode ) > 0 ) { |
|
416 | - $this->inject_in_html( $bodyreplacement, $replaceTag ); |
|
415 | + if (strlen($this->jscode) > 0) { |
|
416 | + $this->inject_in_html($bodyreplacement, $replaceTag); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | // Restore comments. |
420 | - $this->content = $this->restore_comments( $this->content ); |
|
420 | + $this->content = $this->restore_comments($this->content); |
|
421 | 421 | |
422 | 422 | // Restore IE hacks. |
423 | - $this->content = $this->restore_iehacks( $this->content ); |
|
423 | + $this->content = $this->restore_iehacks($this->content); |
|
424 | 424 | |
425 | 425 | // Restore noptimize. |
426 | - $this->content = $this->restore_noptimize( $this->content ); |
|
426 | + $this->content = $this->restore_noptimize($this->content); |
|
427 | 427 | |
428 | 428 | // Return the modified HTML. |
429 | 429 | return $this->content; |
@@ -432,32 +432,32 @@ discard block |
||
432 | 432 | // Checks against the white- and blacklists |
433 | 433 | private function ismergeable($tag) |
434 | 434 | { |
435 | - if ( ! $this->aggregate ) { |
|
435 | + if (!$this->aggregate) { |
|
436 | 436 | return false; |
437 | 437 | } |
438 | 438 | |
439 | - if ( ! empty( $this->whitelist ) ) { |
|
440 | - foreach ( $this->whitelist as $match ) { |
|
441 | - if (false !== strpos( $tag, $match ) ) { |
|
439 | + if (!empty($this->whitelist)) { |
|
440 | + foreach ($this->whitelist as $match) { |
|
441 | + if (false !== strpos($tag, $match)) { |
|
442 | 442 | return true; |
443 | 443 | } |
444 | 444 | } |
445 | 445 | // no match with whitelist |
446 | 446 | return false; |
447 | 447 | } else { |
448 | - foreach($this->domove as $match) { |
|
449 | - if ( false !== strpos( $tag, $match ) ) { |
|
448 | + foreach ($this->domove as $match) { |
|
449 | + if (false !== strpos($tag, $match)) { |
|
450 | 450 | // Matched something |
451 | 451 | return false; |
452 | 452 | } |
453 | 453 | } |
454 | 454 | |
455 | - if ( $this->movetolast($tag) ) { |
|
455 | + if ($this->movetolast($tag)) { |
|
456 | 456 | return false; |
457 | 457 | } |
458 | 458 | |
459 | - foreach( $this->dontmove as $match ) { |
|
460 | - if ( false !== strpos( $tag, $match ) ) { |
|
459 | + foreach ($this->dontmove as $match) { |
|
460 | + if (false !== strpos($tag, $match)) { |
|
461 | 461 | // Matched something |
462 | 462 | return false; |
463 | 463 | } |
@@ -471,23 +471,23 @@ discard block |
||
471 | 471 | // Checks agains the blacklist |
472 | 472 | private function ismovable($tag) |
473 | 473 | { |
474 | - if ( true !== $this->include_inline || apply_filters( 'autoptimize_filter_js_unmovable', true ) ) { |
|
474 | + if (true !== $this->include_inline || apply_filters('autoptimize_filter_js_unmovable', true)) { |
|
475 | 475 | return false; |
476 | 476 | } |
477 | 477 | |
478 | - foreach ( $this->domove as $match ) { |
|
479 | - if ( false !== strpos( $tag, $match ) ) { |
|
478 | + foreach ($this->domove as $match) { |
|
479 | + if (false !== strpos($tag, $match)) { |
|
480 | 480 | // Matched something |
481 | 481 | return true; |
482 | 482 | } |
483 | 483 | } |
484 | 484 | |
485 | - if ( $this->movetolast($tag) ) { |
|
485 | + if ($this->movetolast($tag)) { |
|
486 | 486 | return true; |
487 | 487 | } |
488 | 488 | |
489 | - foreach ( $this->dontmove as $match ) { |
|
490 | - if ( false !== strpos( $tag, $match ) ) { |
|
489 | + foreach ($this->dontmove as $match) { |
|
490 | + if (false !== strpos($tag, $match)) { |
|
491 | 491 | // Matched something |
492 | 492 | return false; |
493 | 493 | } |
@@ -499,8 +499,8 @@ discard block |
||
499 | 499 | |
500 | 500 | private function movetolast($tag) |
501 | 501 | { |
502 | - foreach ( $this->domovelast as $match ) { |
|
503 | - if ( false !== strpos( $tag, $match ) ) { |
|
502 | + foreach ($this->domovelast as $match) { |
|
503 | + if (false !== strpos($tag, $match)) { |
|
504 | 504 | // Matched, return true |
505 | 505 | return true; |
506 | 506 | } |
@@ -521,11 +521,11 @@ discard block |
||
521 | 521 | * @return bool |
522 | 522 | */ |
523 | 523 | private function can_inject_late($jsPath) { |
524 | - $consider_minified_array = apply_filters( 'autoptimize_filter_js_consider_minified', false ); |
|
525 | - if ( true !== $this->inject_min_late ) { |
|
524 | + $consider_minified_array = apply_filters('autoptimize_filter_js_consider_minified', false); |
|
525 | + if (true !== $this->inject_min_late) { |
|
526 | 526 | // late-inject turned off |
527 | 527 | return false; |
528 | - } else if ( ( false === strpos( $jsPath, 'min.js' ) ) && ( false === strpos( $jsPath, 'wp-includes/js/jquery/jquery.js' ) ) && ( str_replace( $consider_minified_array, '', $jsPath ) === $jsPath ) ) { |
|
528 | + } else if ((false === strpos($jsPath, 'min.js')) && (false === strpos($jsPath, 'wp-includes/js/jquery/jquery.js')) && (str_replace($consider_minified_array, '', $jsPath) === $jsPath)) { |
|
529 | 529 | // file not minified based on filename & filter |
530 | 530 | return false; |
531 | 531 | } else { |
@@ -552,26 +552,26 @@ discard block |
||
552 | 552 | * |
553 | 553 | * @return bool|string Url pointing to the minified js file or false. |
554 | 554 | */ |
555 | - public function minify_single( $filepath, $cache_miss = false ) |
|
555 | + public function minify_single($filepath, $cache_miss = false) |
|
556 | 556 | { |
557 | - $contents = $this->prepare_minify_single( $filepath ); |
|
557 | + $contents = $this->prepare_minify_single($filepath); |
|
558 | 558 | |
559 | - if ( empty( $contents ) ) { |
|
559 | + if (empty($contents)) { |
|
560 | 560 | return false; |
561 | 561 | } |
562 | 562 | |
563 | 563 | // Check cache. |
564 | - $hash = 'single_' . md5( $contents ); |
|
565 | - $cache = new autoptimizeCache( $hash, 'js' ); |
|
564 | + $hash = 'single_'.md5($contents); |
|
565 | + $cache = new autoptimizeCache($hash, 'js'); |
|
566 | 566 | |
567 | 567 | // If not in cache already, minify... |
568 | - if ( ! $cache->check() || $cache_miss ) { |
|
569 | - $contents = trim( JSMin::minify( $contents ) ); |
|
568 | + if (!$cache->check() || $cache_miss) { |
|
569 | + $contents = trim(JSMin::minify($contents)); |
|
570 | 570 | // Store in cache. |
571 | - $cache->cache( $contents, 'text/javascript' ); |
|
571 | + $cache->cache($contents, 'text/javascript'); |
|
572 | 572 | } |
573 | 573 | |
574 | - $url = $this->build_minify_single_url( $cache ); |
|
574 | + $url = $this->build_minify_single_url($cache); |
|
575 | 575 | |
576 | 576 | return $url; |
577 | 577 | } |
@@ -2,9 +2,9 @@ discard block |
||
2 | 2 | |
3 | 3 | //Check everything exists before using it |
4 | 4 | if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) |
5 | - $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; |
|
5 | + $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; |
|
6 | 6 | if(!isset($_SERVER['HTTP_USER_AGENT'])) |
7 | - $_SERVER['HTTP_USER_AGENT'] = ''; |
|
7 | + $_SERVER['HTTP_USER_AGENT'] = ''; |
|
8 | 8 | |
9 | 9 | // Determine supported compression method |
10 | 10 | $gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'); |
@@ -15,30 +15,30 @@ discard block |
||
15 | 15 | |
16 | 16 | // Check for buggy versions of Internet Explorer |
17 | 17 | if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Opera') && |
18 | - preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) |
|
18 | + preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) |
|
19 | 19 | { |
20 | - $version = floatval($matches[1]); |
|
20 | + $version = floatval($matches[1]); |
|
21 | 21 | |
22 | - if ($version < 6) |
|
23 | - $encoding = 'none'; |
|
22 | + if ($version < 6) |
|
23 | + $encoding = 'none'; |
|
24 | 24 | |
25 | - if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) |
|
26 | - $encoding = 'none'; |
|
25 | + if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) |
|
26 | + $encoding = 'none'; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | //Some servers compress the output of PHP - Don't break in those cases |
30 | 30 | if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) |
31 | - $encoding = 'none'; |
|
31 | + $encoding = 'none'; |
|
32 | 32 | |
33 | 33 | $iscompressed = file_exists(__FILE__.'.'.$encoding); |
34 | 34 | if($encoding != 'none' && $iscompressed == false) |
35 | 35 | { |
36 | - $flag = ($encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE); |
|
37 | - $code = file_get_contents(__FILE__.'.none'); |
|
38 | - $contents = gzencode($code,9,$flag); |
|
36 | + $flag = ($encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE); |
|
37 | + $code = file_get_contents(__FILE__.'.none'); |
|
38 | + $contents = gzencode($code,9,$flag); |
|
39 | 39 | }else{ |
40 | - //Get data |
|
41 | - $contents = file_get_contents(__FILE__.'.'.$encoding); |
|
40 | + //Get data |
|
41 | + $contents = file_get_contents(__FILE__.'.'.$encoding); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | // first check if we have to send 304 |
@@ -52,36 +52,36 @@ discard block |
||
52 | 52 | $modTimeMatch = (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) === $modTime); |
53 | 53 | |
54 | 54 | if (($modTimeMatch)||($eTagMatch)) { |
55 | - header('HTTP/1.1 304 Not Modified'); |
|
56 | - header('Connection: close'); |
|
55 | + header('HTTP/1.1 304 Not Modified'); |
|
56 | + header('Connection: close'); |
|
57 | 57 | } else { |
58 | - // send all sorts of headers |
|
59 | - $expireTime=60*60*24*355; // 1y max according to RFC |
|
60 | - if ($encoding != 'none') { |
|
61 | - header('Content-Encoding: '.$encoding); |
|
62 | - } |
|
63 | - header('Vary: Accept-Encoding'); |
|
64 | - header('Content-Length: '.strlen($contents)); |
|
65 | - header('Content-type: %%CONTENT%%; charset=utf-8'); |
|
66 | - header('Cache-Control: max-age='.$expireTime.', public, must-revalidate'); |
|
67 | - header('Cache-Control: max-age='.$expireTime.', public, immutable'); |
|
68 | - header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT'); |
|
69 | - header('ETag: ' . $eTag); |
|
70 | - header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT'); |
|
58 | + // send all sorts of headers |
|
59 | + $expireTime=60*60*24*355; // 1y max according to RFC |
|
60 | + if ($encoding != 'none') { |
|
61 | + header('Content-Encoding: '.$encoding); |
|
62 | + } |
|
63 | + header('Vary: Accept-Encoding'); |
|
64 | + header('Content-Length: '.strlen($contents)); |
|
65 | + header('Content-type: %%CONTENT%%; charset=utf-8'); |
|
66 | + header('Cache-Control: max-age='.$expireTime.', public, must-revalidate'); |
|
67 | + header('Cache-Control: max-age='.$expireTime.', public, immutable'); |
|
68 | + header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT'); |
|
69 | + header('ETag: ' . $eTag); |
|
70 | + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT'); |
|
71 | 71 | |
72 | - // send output |
|
73 | - echo $contents; |
|
72 | + // send output |
|
73 | + echo $contents; |
|
74 | 74 | |
75 | - //And write to filesystem cache if not done yet |
|
76 | - if($encoding != 'none' && $iscompressed == false) |
|
77 | - { |
|
78 | - //Write the content we sent |
|
79 | - file_put_contents(__FILE__.'.'.$encoding,$contents); |
|
75 | + //And write to filesystem cache if not done yet |
|
76 | + if($encoding != 'none' && $iscompressed == false) |
|
77 | + { |
|
78 | + //Write the content we sent |
|
79 | + file_put_contents(__FILE__.'.'.$encoding,$contents); |
|
80 | 80 | |
81 | - //And write the new content |
|
82 | - $flag = ($encoding == 'gzip' ? FORCE_DEFLATE : FORCE_GZIP); |
|
83 | - $ext = ($encoding == 'gzip' ? 'deflate' : 'gzip'); |
|
84 | - $contents = gzencode($code,9,$flag); |
|
85 | - file_put_contents(__FILE__.'.'.$ext,$contents); |
|
86 | - } |
|
81 | + //And write the new content |
|
82 | + $flag = ($encoding == 'gzip' ? FORCE_DEFLATE : FORCE_GZIP); |
|
83 | + $ext = ($encoding == 'gzip' ? 'deflate' : 'gzip'); |
|
84 | + $contents = gzencode($code,9,$flag); |
|
85 | + file_put_contents(__FILE__.'.'.$ext,$contents); |
|
86 | + } |
|
87 | 87 | } |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php exit; |
2 | 2 | |
3 | 3 | //Check everything exists before using it |
4 | -if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) |
|
4 | +if (!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) |
|
5 | 5 | $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; |
6 | -if(!isset($_SERVER['HTTP_USER_AGENT'])) |
|
6 | +if (!isset($_SERVER['HTTP_USER_AGENT'])) |
|
7 | 7 | $_SERVER['HTTP_USER_AGENT'] = ''; |
8 | 8 | |
9 | 9 | // Determine supported compression method |
@@ -27,16 +27,16 @@ discard block |
||
27 | 27 | } |
28 | 28 | |
29 | 29 | //Some servers compress the output of PHP - Don't break in those cases |
30 | -if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) |
|
30 | +if (ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) |
|
31 | 31 | $encoding = 'none'; |
32 | 32 | |
33 | 33 | $iscompressed = file_exists(__FILE__.'.'.$encoding); |
34 | -if($encoding != 'none' && $iscompressed == false) |
|
34 | +if ($encoding != 'none' && $iscompressed == false) |
|
35 | 35 | { |
36 | 36 | $flag = ($encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE); |
37 | 37 | $code = file_get_contents(__FILE__.'.none'); |
38 | - $contents = gzencode($code,9,$flag); |
|
39 | -}else{ |
|
38 | + $contents = gzencode($code, 9, $flag); |
|
39 | +} else { |
|
40 | 40 | //Get data |
41 | 41 | $contents = file_get_contents(__FILE__.'.'.$encoding); |
42 | 42 | } |
@@ -44,19 +44,19 @@ discard block |
||
44 | 44 | // first check if we have to send 304 |
45 | 45 | // inspired by http://www.jonasjohn.de/snippets/php/caching.htm |
46 | 46 | |
47 | -$eTag=md5($contents); |
|
48 | -$modTime=filemtime(__FILE__.'.none'); |
|
47 | +$eTag = md5($contents); |
|
48 | +$modTime = filemtime(__FILE__.'.none'); |
|
49 | 49 | |
50 | 50 | date_default_timezone_set("UTC"); |
51 | -$eTagMatch = (isset($_SERVER['HTTP_IF_NONE_MATCH']) && strpos($_SERVER['HTTP_IF_NONE_MATCH'],$eTag)); |
|
51 | +$eTagMatch = (isset($_SERVER['HTTP_IF_NONE_MATCH']) && strpos($_SERVER['HTTP_IF_NONE_MATCH'], $eTag)); |
|
52 | 52 | $modTimeMatch = (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) === $modTime); |
53 | 53 | |
54 | -if (($modTimeMatch)||($eTagMatch)) { |
|
54 | +if (($modTimeMatch) || ($eTagMatch)) { |
|
55 | 55 | header('HTTP/1.1 304 Not Modified'); |
56 | 56 | header('Connection: close'); |
57 | 57 | } else { |
58 | 58 | // send all sorts of headers |
59 | - $expireTime=60*60*24*355; // 1y max according to RFC |
|
59 | + $expireTime = 60*60*24*355; // 1y max according to RFC |
|
60 | 60 | if ($encoding != 'none') { |
61 | 61 | header('Content-Encoding: '.$encoding); |
62 | 62 | } |
@@ -66,22 +66,22 @@ discard block |
||
66 | 66 | header('Cache-Control: max-age='.$expireTime.', public, must-revalidate'); |
67 | 67 | header('Cache-Control: max-age='.$expireTime.', public, immutable'); |
68 | 68 | header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT'); |
69 | - header('ETag: ' . $eTag); |
|
69 | + header('ETag: '.$eTag); |
|
70 | 70 | header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT'); |
71 | 71 | |
72 | 72 | // send output |
73 | 73 | echo $contents; |
74 | 74 | |
75 | 75 | //And write to filesystem cache if not done yet |
76 | - if($encoding != 'none' && $iscompressed == false) |
|
76 | + if ($encoding != 'none' && $iscompressed == false) |
|
77 | 77 | { |
78 | 78 | //Write the content we sent |
79 | - file_put_contents(__FILE__.'.'.$encoding,$contents); |
|
79 | + file_put_contents(__FILE__.'.'.$encoding, $contents); |
|
80 | 80 | |
81 | 81 | //And write the new content |
82 | 82 | $flag = ($encoding == 'gzip' ? FORCE_DEFLATE : FORCE_GZIP); |
83 | 83 | $ext = ($encoding == 'gzip' ? 'deflate' : 'gzip'); |
84 | - $contents = gzencode($code,9,$flag); |
|
85 | - file_put_contents(__FILE__.'.'.$ext,$contents); |
|
84 | + $contents = gzencode($code, 9, $flag); |
|
85 | + file_put_contents(__FILE__.'.'.$ext, $contents); |
|
86 | 86 | } |
87 | 87 | } |
@@ -1,10 +1,12 @@ discard block |
||
1 | 1 | <?php exit; |
2 | 2 | |
3 | 3 | //Check everything exists before using it |
4 | -if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) |
|
4 | +if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { |
|
5 | 5 | $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; |
6 | -if(!isset($_SERVER['HTTP_USER_AGENT'])) |
|
6 | +} |
|
7 | +if(!isset($_SERVER['HTTP_USER_AGENT'])) { |
|
7 | 8 | $_SERVER['HTTP_USER_AGENT'] = ''; |
9 | +} |
|
8 | 10 | |
9 | 11 | // Determine supported compression method |
10 | 12 | $gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'); |
@@ -19,16 +21,19 @@ discard block |
||
19 | 21 | { |
20 | 22 | $version = floatval($matches[1]); |
21 | 23 | |
22 | - if ($version < 6) |
|
23 | - $encoding = 'none'; |
|
24 | + if ($version < 6) { |
|
25 | + $encoding = 'none'; |
|
26 | + } |
|
24 | 27 | |
25 | - if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) |
|
26 | - $encoding = 'none'; |
|
27 | -} |
|
28 | + if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) { |
|
29 | + $encoding = 'none'; |
|
30 | + } |
|
31 | + } |
|
28 | 32 | |
29 | 33 | //Some servers compress the output of PHP - Don't break in those cases |
30 | -if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) |
|
34 | +if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) { |
|
31 | 35 | $encoding = 'none'; |
36 | +} |
|
32 | 37 | |
33 | 38 | $iscompressed = file_exists(__FILE__.'.'.$encoding); |
34 | 39 | if($encoding != 'none' && $iscompressed == false) |
@@ -36,7 +41,7 @@ discard block |
||
36 | 41 | $flag = ($encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE); |
37 | 42 | $code = file_get_contents(__FILE__.'.none'); |
38 | 43 | $contents = gzencode($code,9,$flag); |
39 | -}else{ |
|
44 | +} else{ |
|
40 | 45 | //Get data |
41 | 46 | $contents = file_get_contents(__FILE__.'.'.$encoding); |
42 | 47 | } |
@@ -38,18 +38,18 @@ discard block |
||
38 | 38 | $l = floatval(str_replace('%', '', $hslValues[2])); |
39 | 39 | |
40 | 40 | // Wrap and clamp, then fraction! |
41 | - $h = ((($h % 360) + 360) % 360) / 360; |
|
42 | - $s = self::clampNumber($s, 0, 100) / 100; |
|
43 | - $l = self::clampNumber($l, 0, 100) / 100; |
|
41 | + $h = ((($h%360) + 360)%360)/360; |
|
42 | + $s = self::clampNumber($s, 0, 100)/100; |
|
43 | + $l = self::clampNumber($l, 0, 100)/100; |
|
44 | 44 | |
45 | 45 | if ($s == 0) { |
46 | - $r = $g = $b = self::roundNumber(255 * $l); |
|
46 | + $r = $g = $b = self::roundNumber(255*$l); |
|
47 | 47 | } else { |
48 | - $v2 = $l < 0.5 ? $l * (1 + $s) : ($l + $s) - ($s * $l); |
|
49 | - $v1 = (2 * $l) - $v2; |
|
50 | - $r = self::roundNumber(255 * self::hueToRgb($v1, $v2, $h + (1/3))); |
|
51 | - $g = self::roundNumber(255 * self::hueToRgb($v1, $v2, $h)); |
|
52 | - $b = self::roundNumber(255 * self::hueToRgb($v1, $v2, $h - (1/3))); |
|
48 | + $v2 = $l < 0.5 ? $l*(1 + $s) : ($l + $s) - ($s*$l); |
|
49 | + $v1 = (2*$l) - $v2; |
|
50 | + $r = self::roundNumber(255*self::hueToRgb($v1, $v2, $h + (1/3))); |
|
51 | + $g = self::roundNumber(255*self::hueToRgb($v1, $v2, $h)); |
|
52 | + $b = self::roundNumber(255*self::hueToRgb($v1, $v2, $h - (1/3))); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | return array($r, $g, $b); |
@@ -66,16 +66,16 @@ discard block |
||
66 | 66 | { |
67 | 67 | $vh = $vh < 0 ? $vh + 1 : ($vh > 1 ? $vh - 1 : $vh); |
68 | 68 | |
69 | - if ($vh * 6 < 1) { |
|
70 | - return $v1 + ($v2 - $v1) * 6 * $vh; |
|
69 | + if ($vh*6 < 1) { |
|
70 | + return $v1 + ($v2 - $v1)*6*$vh; |
|
71 | 71 | } |
72 | 72 | |
73 | - if ($vh * 2 < 1) { |
|
73 | + if ($vh*2 < 1) { |
|
74 | 74 | return $v2; |
75 | 75 | } |
76 | 76 | |
77 | - if ($vh * 3 < 2) { |
|
78 | - return $v1 + ($v2 - $v1) * ((2 / 3) - $vh) * 6; |
|
77 | + if ($vh*3 < 2) { |
|
78 | + return $v1 + ($v2 - $v1)*((2/3) - $vh)*6; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | return $v1; |
@@ -94,13 +94,13 @@ discard block |
||
94 | 94 | switch ($letter) { |
95 | 95 | case 'M': |
96 | 96 | case 'm': |
97 | - return (int) $size * 1048576; |
|
97 | + return (int) $size*1048576; |
|
98 | 98 | case 'K': |
99 | 99 | case 'k': |
100 | - return (int) $size * 1024; |
|
100 | + return (int) $size*1024; |
|
101 | 101 | case 'G': |
102 | 102 | case 'g': |
103 | - return (int) $size * 1073741824; |
|
103 | + return (int) $size*1073741824; |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | return (int) $size; |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | public static function rgbPercentageToRgbInteger($rgbPercentage) |
115 | 115 | { |
116 | 116 | if (strpos($rgbPercentage, '%') !== false) { |
117 | - $rgbPercentage = self::roundNumber(floatval(str_replace('%', '', $rgbPercentage)) * 2.55); |
|
117 | + $rgbPercentage = self::roundNumber(floatval(str_replace('%', '', $rgbPercentage))*2.55); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | return intval($rgbPercentage, 10); |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | { |
71 | 71 | $this->_html = str_replace("\r\n", "\n", trim($html)); |
72 | 72 | if (isset($options['xhtml'])) { |
73 | - $this->_isXhtml = (bool)$options['xhtml']; |
|
73 | + $this->_isXhtml = (bool) $options['xhtml']; |
|
74 | 74 | } |
75 | 75 | if (isset($options['cssMinifier'])) { |
76 | 76 | $this->_cssMinifier = $options['cssMinifier']; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML')); |
96 | 96 | } |
97 | 97 | |
98 | - $this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']); |
|
98 | + $this->_replacementHash = 'MINIFYHTML'.md5($_SERVER['REQUEST_TIME']); |
|
99 | 99 | $this->_placeholders = array(); |
100 | 100 | |
101 | 101 | // replace SCRIPTs (and minify) with placeholders |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | ,$this->_html); |
112 | 112 | |
113 | 113 | // remove HTML comments (not containing IE conditional comments). |
114 | - if ($this->_keepComments == false) { |
|
114 | + if ($this->_keepComments == false) { |
|
115 | 115 | $this->_html = preg_replace_callback( |
116 | 116 | '/<!--([\\s\\S]*?)-->/' |
117 | 117 | ,array($this, '_commentCB') |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | |
174 | 174 | protected function _reservePlace($content) |
175 | 175 | { |
176 | - $placeholder = '%' . $this->_replacementHash . count($this->_placeholders) . '%'; |
|
176 | + $placeholder = '%'.$this->_replacementHash.count($this->_placeholders).'%'; |
|
177 | 177 | $this->_placeholders[$placeholder] = $content; |
178 | 178 | return $placeholder; |
179 | 179 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | |
188 | 188 | protected function _outsideTagCB($m) |
189 | 189 | { |
190 | - return '>' . preg_replace('/^\\s+|\\s+$/', ' ', $m[1]) . '<'; |
|
190 | + return '>'.preg_replace('/^\\s+|\\s+$/', ' ', $m[1]).'<'; |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | protected function _removePreCB($m) |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | protected function _removeCdata($str) |
260 | 260 | { |
261 | 261 | return (false !== strpos($str, '<![CDATA[')) |
262 | - ? str_replace(array('/* <![CDATA[ */','/* ]]> */','/*<![CDATA[*/','/*]]>*/','<![CDATA[', ']]>'), '', $str) |
|
262 | + ? str_replace(array('/* <![CDATA[ */', '/* ]]> */', '/*<![CDATA[*/', '/*]]>*/', '<![CDATA[', ']]>'), '', $str) |
|
263 | 263 | : $str; |
264 | 264 | } |
265 | 265 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Handles minifying HTML markup. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -27,19 +27,19 @@ discard block |
||
27 | 27 | '<!--/noindex-->', |
28 | 28 | ); |
29 | 29 | |
30 | - public function read( $options ) |
|
30 | + public function read($options) |
|
31 | 31 | { |
32 | 32 | // Remove the HTML comments? |
33 | 33 | $this->keepcomments = (bool) $options['keepcomments']; |
34 | 34 | |
35 | 35 | // Filter to force xhtml. |
36 | - $this->forcexhtml = (bool) apply_filters( 'autoptimize_filter_html_forcexhtml', false ); |
|
36 | + $this->forcexhtml = (bool) apply_filters('autoptimize_filter_html_forcexhtml', false); |
|
37 | 37 | |
38 | 38 | // Filterable strings to be excluded from HTML minification. |
39 | - $exclude = apply_filters( 'autoptimize_filter_html_exclude', '' ); |
|
40 | - if ( '' !== $exclude ) { |
|
41 | - $exclude_arr = array_filter( array_map( 'trim', explode( ',', $exclude ) ) ); |
|
42 | - $this->exclude = array_merge( $exclude_arr, $this->exclude ); |
|
39 | + $exclude = apply_filters('autoptimize_filter_html_exclude', ''); |
|
40 | + if ('' !== $exclude) { |
|
41 | + $exclude_arr = array_filter(array_map('trim', explode(',', $exclude))); |
|
42 | + $this->exclude = array_merge($exclude_arr, $this->exclude); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | // Nothing else for HTML! |
@@ -53,49 +53,49 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function minify() |
55 | 55 | { |
56 | - $noptimize = apply_filters( 'autoptimize_filter_html_noptimize', false, $this->content ); |
|
57 | - if ( $noptimize ) { |
|
56 | + $noptimize = apply_filters('autoptimize_filter_html_noptimize', false, $this->content); |
|
57 | + if ($noptimize) { |
|
58 | 58 | return false; |
59 | 59 | } |
60 | 60 | |
61 | 61 | // Wrap the to-be-excluded strings in noptimize tags. |
62 | - foreach ( $this->exclude as $str ) { |
|
63 | - if ( false !== strpos( $this->content, $str ) ) { |
|
64 | - $replacement = '<!--noptimize-->' . $str . '<!--/noptimize-->'; |
|
65 | - $this->content = str_replace( $str, $replacement, $this->content ); |
|
62 | + foreach ($this->exclude as $str) { |
|
63 | + if (false !== strpos($this->content, $str)) { |
|
64 | + $replacement = '<!--noptimize-->'.$str.'<!--/noptimize-->'; |
|
65 | + $this->content = str_replace($str, $replacement, $this->content); |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | |
69 | 69 | // Noptimize. |
70 | - $this->content = $this->hide_noptimize( $this->content ); |
|
70 | + $this->content = $this->hide_noptimize($this->content); |
|
71 | 71 | |
72 | 72 | // Preparing options for Minify_HTML. |
73 | - $options = array( 'keepComments' => $this->keepcomments ); |
|
74 | - if ( $this->forcexhtml ) { |
|
73 | + $options = array('keepComments' => $this->keepcomments); |
|
74 | + if ($this->forcexhtml) { |
|
75 | 75 | $options['xhtml'] = true; |
76 | 76 | } |
77 | 77 | |
78 | - $tmp_content = Minify_HTML::minify( $this->content, $options ); |
|
79 | - if ( ! empty( $tmp_content ) ) { |
|
78 | + $tmp_content = Minify_HTML::minify($this->content, $options); |
|
79 | + if (!empty($tmp_content)) { |
|
80 | 80 | $this->content = $tmp_content; |
81 | - unset( $tmp_content ); |
|
81 | + unset($tmp_content); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | // Restore noptimize. |
85 | - $this->content = $this->restore_noptimize( $this->content ); |
|
85 | + $this->content = $this->restore_noptimize($this->content); |
|
86 | 86 | |
87 | 87 | // Remove the noptimize-wrapper from around the excluded strings. |
88 | - foreach ( $this->exclude as $str ) { |
|
89 | - $replacement = '<!--noptimize-->' . $str . '<!--/noptimize-->'; |
|
90 | - if ( false !== strpos( $this->content, $replacement ) ) { |
|
91 | - $this->content = str_replace( $replacement, $str, $this->content ); |
|
88 | + foreach ($this->exclude as $str) { |
|
89 | + $replacement = '<!--noptimize-->'.$str.'<!--/noptimize-->'; |
|
90 | + if (false !== strpos($this->content, $replacement)) { |
|
91 | + $this->content = str_replace($replacement, $str, $this->content); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | 95 | // Revslider data attribs somehow suffer from HTML optimization, this fixes that! |
96 | - if ( class_exists( 'RevSlider' ) && apply_filters( 'autoptimize_filter_html_dataattrib_cleanup', false ) ) { |
|
97 | - $this->content = preg_replace( '#\n(data-.*$)\n#Um', ' $1 ', $this->content ); |
|
98 | - $this->content = preg_replace( '#<[^>]*(=\"[^"\'<>\s]*\")(\w)#', '$1 $2', $this->content ); |
|
96 | + if (class_exists('RevSlider') && apply_filters('autoptimize_filter_html_dataattrib_cleanup', false)) { |
|
97 | + $this->content = preg_replace('#\n(data-.*$)\n#Um', ' $1 ', $this->content); |
|
98 | + $this->content = preg_replace('#<[^>]*(=\"[^"\'<>\s]*\")(\w)#', '$1 $2', $this->content); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | return true; |
@@ -3,12 +3,12 @@ discard block |
||
3 | 3 | * WP-CLI commands for Autoptimize. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
10 | 10 | // This is a WP-CLI command, so bail if it's not available. |
11 | -if ( ! defined( 'WP_CLI' ) ) { |
|
11 | +if (!defined('WP_CLI')) { |
|
12 | 12 | return; |
13 | 13 | } |
14 | 14 | |
@@ -24,11 +24,11 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @return void |
26 | 26 | */ |
27 | - public function clear( $args, $args_assoc ) { |
|
28 | - WP_CLI::line( esc_html__( 'Flushing the cache...', 'autoptimize' ) ); |
|
27 | + public function clear($args, $args_assoc) { |
|
28 | + WP_CLI::line(esc_html__('Flushing the cache...', 'autoptimize')); |
|
29 | 29 | autoptimizeCache::clearall(); |
30 | - WP_CLI::success( esc_html__( 'Cache flushed.', 'autoptimize' ) ); |
|
30 | + WP_CLI::success(esc_html__('Cache flushed.', 'autoptimize')); |
|
31 | 31 | } |
32 | 32 | } |
33 | 33 | |
34 | -WP_CLI::add_command( 'autoptimize', 'autoptimizeCLI' ); |
|
34 | +WP_CLI::add_command('autoptimize', 'autoptimizeCLI'); |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Thin wrapper around css minifiers to avoid rewriting a bunch of existing code. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param bool $raise_limits Whether to raise memory limits or not. Default true. |
23 | 23 | */ |
24 | - public function __construct( $raise_limits = true ) |
|
24 | + public function __construct($raise_limits = true) |
|
25 | 25 | { |
26 | - $this->minifier = new Autoptimize\tubalmartin\CssMin\Minifier( $raise_limits ); |
|
26 | + $this->minifier = new Autoptimize\tubalmartin\CssMin\Minifier($raise_limits); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -34,9 +34,9 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @return string |
36 | 36 | */ |
37 | - public function run( $css ) |
|
37 | + public function run($css) |
|
38 | 38 | { |
39 | - $result = $this->minifier->run( $css ); |
|
39 | + $result = $this->minifier->run($css); |
|
40 | 40 | |
41 | 41 | return $result; |
42 | 42 | } |
@@ -48,10 +48,10 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return string |
50 | 50 | */ |
51 | - public static function minify( $css ) |
|
51 | + public static function minify($css) |
|
52 | 52 | { |
53 | 53 | $minifier = new self(); |
54 | 54 | |
55 | - return $minifier->run( $css ); |
|
55 | + return $minifier->run($css); |
|
56 | 56 | } |
57 | 57 | } |