@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Class for CSS optimization. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -161,54 +161,54 @@ discard block |
||
161 | 161 | * |
162 | 162 | * @param array $options all options. |
163 | 163 | */ |
164 | - public function read( $options ) |
|
164 | + public function read($options) |
|
165 | 165 | { |
166 | - $noptimize_css = apply_filters( 'autoptimize_filter_css_noptimize', false, $this->content ); |
|
167 | - if ( $noptimize_css ) { |
|
166 | + $noptimize_css = apply_filters('autoptimize_filter_css_noptimize', false, $this->content); |
|
167 | + if ($noptimize_css) { |
|
168 | 168 | return false; |
169 | 169 | } |
170 | 170 | |
171 | - $allowlist_css = apply_filters( 'autoptimize_filter_css_allowlist', '', $this->content ); |
|
172 | - $allowlist_css = apply_filters( 'autoptimize_filter_css_whitelist', $allowlist_css, $this->content ); // fixme: to be removed in next version. |
|
173 | - if ( ! empty( $allowlist_css ) ) { |
|
174 | - $this->allowlist = array_filter( array_map( 'trim', explode( ',', $allowlist_css ) ) ); |
|
171 | + $allowlist_css = apply_filters('autoptimize_filter_css_allowlist', '', $this->content); |
|
172 | + $allowlist_css = apply_filters('autoptimize_filter_css_whitelist', $allowlist_css, $this->content); // fixme: to be removed in next version. |
|
173 | + if (!empty($allowlist_css)) { |
|
174 | + $this->allowlist = array_filter(array_map('trim', explode(',', $allowlist_css))); |
|
175 | 175 | } |
176 | 176 | |
177 | - $removable_css = apply_filters( 'autoptimize_filter_css_removables', '' ); |
|
178 | - if ( ! empty( $removable_css ) ) { |
|
179 | - $this->cssremovables = array_filter( array_map( 'trim', explode( ',', $removable_css ) ) ); |
|
177 | + $removable_css = apply_filters('autoptimize_filter_css_removables', ''); |
|
178 | + if (!empty($removable_css)) { |
|
179 | + $this->cssremovables = array_filter(array_map('trim', explode(',', $removable_css))); |
|
180 | 180 | } |
181 | 181 | |
182 | - $this->cssinlinesize = apply_filters( 'autoptimize_filter_css_inlinesize', 256 ); |
|
182 | + $this->cssinlinesize = apply_filters('autoptimize_filter_css_inlinesize', 256); |
|
183 | 183 | |
184 | 184 | // filter to "late inject minified CSS", default to true for now (it is faster). |
185 | - $this->inject_min_late = apply_filters( 'autoptimize_filter_css_inject_min_late', true ); |
|
185 | + $this->inject_min_late = apply_filters('autoptimize_filter_css_inject_min_late', true); |
|
186 | 186 | |
187 | 187 | // Remove everything that's not the header. |
188 | - if ( apply_filters( 'autoptimize_filter_css_justhead', $options['justhead'] ) ) { |
|
189 | - $content = explode( '</head>', $this->content, 2 ); |
|
190 | - $this->content = $content[0] . '</head>'; |
|
188 | + if (apply_filters('autoptimize_filter_css_justhead', $options['justhead'])) { |
|
189 | + $content = explode('</head>', $this->content, 2); |
|
190 | + $this->content = $content[0].'</head>'; |
|
191 | 191 | $this->restofcontent = $content[1]; |
192 | 192 | } |
193 | 193 | |
194 | 194 | // Determine whether we're doing CSS-files aggregation or not. |
195 | - if ( isset( $options['aggregate'] ) && ! $options['aggregate'] ) { |
|
195 | + if (isset($options['aggregate']) && !$options['aggregate']) { |
|
196 | 196 | $this->aggregate = false; |
197 | 197 | } |
198 | 198 | // Returning true for "dontaggregate" turns off aggregation. |
199 | - if ( $this->aggregate && apply_filters( 'autoptimize_filter_css_dontaggregate', false ) ) { |
|
199 | + if ($this->aggregate && apply_filters('autoptimize_filter_css_dontaggregate', false)) { |
|
200 | 200 | $this->aggregate = false; |
201 | 201 | } |
202 | 202 | |
203 | 203 | // include inline? |
204 | - if ( apply_filters( 'autoptimize_css_include_inline', $options['include_inline'] ) ) { |
|
204 | + if (apply_filters('autoptimize_css_include_inline', $options['include_inline'])) { |
|
205 | 205 | $this->include_inline = true; |
206 | 206 | } |
207 | 207 | |
208 | 208 | // List of CSS strings which are excluded from autoptimization. |
209 | - $exclude_css = apply_filters( 'autoptimize_filter_css_exclude', $options['css_exclude'], $this->content ); |
|
210 | - if ( '' !== $exclude_css ) { |
|
211 | - $this->dontmove = array_filter( array_map( 'trim', explode( ',', $exclude_css ) ) ); |
|
209 | + $exclude_css = apply_filters('autoptimize_filter_css_exclude', $options['css_exclude'], $this->content); |
|
210 | + if ('' !== $exclude_css) { |
|
211 | + $this->dontmove = array_filter(array_map('trim', explode(',', $exclude_css))); |
|
212 | 212 | } else { |
213 | 213 | $this->dontmove = array(); |
214 | 214 | } |
@@ -219,16 +219,16 @@ discard block |
||
219 | 219 | // Should we defer css? |
220 | 220 | // value: true / false. |
221 | 221 | $this->defer = $options['defer']; |
222 | - $this->defer = apply_filters( 'autoptimize_filter_css_defer', $this->defer, $this->content ); |
|
222 | + $this->defer = apply_filters('autoptimize_filter_css_defer', $this->defer, $this->content); |
|
223 | 223 | |
224 | 224 | // Should we inline while deferring? |
225 | 225 | // value: inlined CSS. |
226 | - $this->defer_inline = apply_filters( 'autoptimize_filter_css_defer_inline', $this->sanitize_css( $options['defer_inline'] ), $this->content ); |
|
226 | + $this->defer_inline = apply_filters('autoptimize_filter_css_defer_inline', $this->sanitize_css($options['defer_inline']), $this->content); |
|
227 | 227 | |
228 | 228 | // Should we inline? |
229 | 229 | // value: true / false. |
230 | 230 | $this->inline = $options['inline']; |
231 | - $this->inline = apply_filters( 'autoptimize_filter_css_inline', $this->inline, $this->content ); |
|
231 | + $this->inline = apply_filters('autoptimize_filter_css_inline', $this->inline, $this->content); |
|
232 | 232 | |
233 | 233 | // Store cdn url. |
234 | 234 | $this->cdn_url = $options['cdn_url']; |
@@ -237,16 +237,16 @@ discard block |
||
237 | 237 | $this->datauris = $options['datauris']; |
238 | 238 | |
239 | 239 | // Determine whether excluded files should be minified if not yet so. |
240 | - if ( ! $options['minify_excluded'] && $options['aggregate'] ) { |
|
240 | + if (!$options['minify_excluded'] && $options['aggregate']) { |
|
241 | 241 | $this->minify_excluded = false; |
242 | 242 | } |
243 | - $this->minify_excluded = apply_filters( 'autoptimize_filter_css_minify_excluded', $this->minify_excluded, '' ); |
|
243 | + $this->minify_excluded = apply_filters('autoptimize_filter_css_minify_excluded', $this->minify_excluded, ''); |
|
244 | 244 | |
245 | 245 | // should we force all media-attributes to all? |
246 | - $this->media_force_all = apply_filters( 'autoptimize_filter_css_tagmedia_forceall', false ); |
|
246 | + $this->media_force_all = apply_filters('autoptimize_filter_css_tagmedia_forceall', false); |
|
247 | 247 | |
248 | 248 | // noptimize me. |
249 | - $this->content = $this->hide_noptimize( $this->content ); |
|
249 | + $this->content = $this->hide_noptimize($this->content); |
|
250 | 250 | |
251 | 251 | // Exclude (no)script, as those may contain CSS which should be left as is. |
252 | 252 | $this->content = $this->replace_contents_with_marker_if_exists( |
@@ -257,25 +257,25 @@ discard block |
||
257 | 257 | ); |
258 | 258 | |
259 | 259 | // Save IE hacks. |
260 | - $this->content = $this->hide_iehacks( $this->content ); |
|
260 | + $this->content = $this->hide_iehacks($this->content); |
|
261 | 261 | |
262 | 262 | // Hide HTML comments. |
263 | - $this->content = $this->hide_comments( $this->content ); |
|
263 | + $this->content = $this->hide_comments($this->content); |
|
264 | 264 | |
265 | 265 | // Get <style> and <link>. |
266 | - if ( preg_match_all( '#(<style[^>]*>.*</style>)|(<link[^>]*stylesheet[^>]*>)#Usmi', $this->content, $matches ) ) { |
|
266 | + if (preg_match_all('#(<style[^>]*>.*</style>)|(<link[^>]*stylesheet[^>]*>)#Usmi', $this->content, $matches)) { |
|
267 | 267 | |
268 | - foreach ( $matches[0] as $tag ) { |
|
269 | - if ( $this->isremovable( $tag, $this->cssremovables ) ) { |
|
270 | - $this->content = str_replace( $tag, '', $this->content ); |
|
271 | - } elseif ( $this->ismovable( $tag ) ) { |
|
268 | + foreach ($matches[0] as $tag) { |
|
269 | + if ($this->isremovable($tag, $this->cssremovables)) { |
|
270 | + $this->content = str_replace($tag, '', $this->content); |
|
271 | + } elseif ($this->ismovable($tag)) { |
|
272 | 272 | // Get the media. |
273 | - if ( false !== strpos( $tag, 'media=' ) ) { |
|
274 | - preg_match( '#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $medias ); |
|
275 | - $medias = explode( ',', $medias[1] ); |
|
273 | + if (false !== strpos($tag, 'media=')) { |
|
274 | + preg_match('#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $medias); |
|
275 | + $medias = explode(',', $medias[1]); |
|
276 | 276 | $media = array(); |
277 | - foreach ( $medias as $elem ) { |
|
278 | - if ( empty( $elem ) ) { |
|
277 | + foreach ($medias as $elem) { |
|
278 | + if (empty($elem)) { |
|
279 | 279 | $elem = 'all'; |
280 | 280 | } |
281 | 281 | |
@@ -283,68 +283,68 @@ discard block |
||
283 | 283 | } |
284 | 284 | } else { |
285 | 285 | // No media specified - applies to all. |
286 | - $media = array( 'all' ); |
|
286 | + $media = array('all'); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | // forcing media attribute to all to merge all in one file. |
290 | - if ( $this->media_force_all ) { |
|
291 | - $media = array( 'all' ); |
|
290 | + if ($this->media_force_all) { |
|
291 | + $media = array('all'); |
|
292 | 292 | } |
293 | 293 | |
294 | - $media = apply_filters( 'autoptimize_filter_css_tagmedia', $media, $tag ); |
|
294 | + $media = apply_filters('autoptimize_filter_css_tagmedia', $media, $tag); |
|
295 | 295 | |
296 | - if ( preg_match( '#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source ) ) { |
|
296 | + if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source)) { |
|
297 | 297 | // <link>. |
298 | - $url = current( explode( '?', $source[2], 2 ) ); |
|
299 | - $path = $this->getpath( $url ); |
|
298 | + $url = current(explode('?', $source[2], 2)); |
|
299 | + $path = $this->getpath($url); |
|
300 | 300 | |
301 | - if ( false !== $path && preg_match( '#\.css$#', $path ) ) { |
|
301 | + if (false !== $path && preg_match('#\.css$#', $path)) { |
|
302 | 302 | // Good link. |
303 | - $this->css[] = array( $media, $path ); |
|
303 | + $this->css[] = array($media, $path); |
|
304 | 304 | } else { |
305 | 305 | // Link is dynamic (.php etc). |
306 | - $new_tag = $this->optionally_defer_excluded( $tag, 'none' ); |
|
307 | - if ( '' !== $new_tag && $new_tag !== $tag ) { |
|
308 | - $this->content = str_replace( $tag, $new_tag, $this->content ); |
|
306 | + $new_tag = $this->optionally_defer_excluded($tag, 'none'); |
|
307 | + if ('' !== $new_tag && $new_tag !== $tag) { |
|
308 | + $this->content = str_replace($tag, $new_tag, $this->content); |
|
309 | 309 | } |
310 | 310 | $tag = ''; |
311 | 311 | } |
312 | 312 | } else { |
313 | 313 | // Inline css in style tags can be wrapped in comment tags, so restore comments. |
314 | - $tag = $this->restore_comments( $tag ); |
|
315 | - preg_match( '#<style.*>(.*)</style>#Usmi', $tag, $code ); |
|
314 | + $tag = $this->restore_comments($tag); |
|
315 | + preg_match('#<style.*>(.*)</style>#Usmi', $tag, $code); |
|
316 | 316 | |
317 | 317 | // And re-hide them to be able to to the removal based on tag. |
318 | - $tag = $this->hide_comments( $tag ); |
|
318 | + $tag = $this->hide_comments($tag); |
|
319 | 319 | |
320 | - if ( $this->include_inline ) { |
|
321 | - $code = preg_replace( '#^.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*$#sm', '$1', $code[1] ); |
|
322 | - $this->css[] = array( $media, 'INLINE;' . $code ); |
|
320 | + if ($this->include_inline) { |
|
321 | + $code = preg_replace('#^.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*$#sm', '$1', $code[1]); |
|
322 | + $this->css[] = array($media, 'INLINE;'.$code); |
|
323 | 323 | } else { |
324 | 324 | $tag = ''; |
325 | 325 | } |
326 | 326 | } |
327 | 327 | |
328 | 328 | // Remove the original style tag. |
329 | - $this->content = str_replace( $tag, '', $this->content ); |
|
329 | + $this->content = str_replace($tag, '', $this->content); |
|
330 | 330 | } else { |
331 | - if ( preg_match( '#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source ) ) { |
|
332 | - $exploded_url = explode( '?', $source[2], 2 ); |
|
331 | + if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source)) { |
|
332 | + $exploded_url = explode('?', $source[2], 2); |
|
333 | 333 | $url = $exploded_url[0]; |
334 | - $path = $this->getpath( $url ); |
|
334 | + $path = $this->getpath($url); |
|
335 | 335 | $new_tag = $tag; |
336 | 336 | |
337 | 337 | // Excluded CSS, minify that file: |
338 | 338 | // -> if aggregate is on and exclude minify is on |
339 | 339 | // -> if aggregate is off and the file is not in dontmove. |
340 | - if ( $path && $this->minify_excluded ) { |
|
341 | - $consider_minified_array = apply_filters( 'autoptimize_filter_css_consider_minified', false ); |
|
342 | - if ( ( false === $this->aggregate && str_replace( $this->dontmove, '', $path ) === $path ) || ( true === $this->aggregate && ( false === $consider_minified_array || str_replace( $consider_minified_array, '', $path ) === $path ) ) ) { |
|
343 | - $minified_url = $this->minify_single( $path ); |
|
344 | - if ( ! empty( $minified_url ) ) { |
|
340 | + if ($path && $this->minify_excluded) { |
|
341 | + $consider_minified_array = apply_filters('autoptimize_filter_css_consider_minified', false); |
|
342 | + if ((false === $this->aggregate && str_replace($this->dontmove, '', $path) === $path) || (true === $this->aggregate && (false === $consider_minified_array || str_replace($consider_minified_array, '', $path) === $path))) { |
|
343 | + $minified_url = $this->minify_single($path); |
|
344 | + if (!empty($minified_url)) { |
|
345 | 345 | // Replace orig URL with cached minified URL. |
346 | - $new_tag = str_replace( $url, $minified_url, $tag ); |
|
347 | - } elseif ( apply_filters( 'autoptimize_filter_ccsjs_remove_empty_minified_url', false ) ) { |
|
346 | + $new_tag = str_replace($url, $minified_url, $tag); |
|
347 | + } elseif (apply_filters('autoptimize_filter_ccsjs_remove_empty_minified_url', false)) { |
|
348 | 348 | // Remove the original style tag, because cache content is empty but only if |
349 | 349 | // filter is true-ed because $minified_url is also false if file is minified already. |
350 | 350 | $new_tag = ''; |
@@ -352,14 +352,14 @@ discard block |
||
352 | 352 | } |
353 | 353 | } |
354 | 354 | |
355 | - if ( '' !== $new_tag ) { |
|
355 | + if ('' !== $new_tag) { |
|
356 | 356 | // Optionally defer (preload) non-aggregated CSS. |
357 | - $new_tag = $this->optionally_defer_excluded( $new_tag, $url ); |
|
357 | + $new_tag = $this->optionally_defer_excluded($new_tag, $url); |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | // And replace! |
361 | - if ( ( '' !== $new_tag && $new_tag !== $tag ) || ( '' === $new_tag && apply_filters( 'autoptimize_filter_css_remove_empty_files', false ) ) ) { |
|
362 | - $this->content = str_replace( $tag, $new_tag, $this->content ); |
|
361 | + if (('' !== $new_tag && $new_tag !== $tag) || ('' === $new_tag && apply_filters('autoptimize_filter_css_remove_empty_files', false))) { |
|
362 | + $this->content = str_replace($tag, $new_tag, $this->content); |
|
363 | 363 | } |
364 | 364 | } |
365 | 365 | } |
@@ -380,30 +380,30 @@ discard block |
||
380 | 380 | * |
381 | 381 | * @return string $new_tag |
382 | 382 | */ |
383 | - private function optionally_defer_excluded( $tag, $url = '' ) |
|
383 | + private function optionally_defer_excluded($tag, $url = '') |
|
384 | 384 | { |
385 | 385 | // Defer single CSS if "inline & defer" is ON and there is inline CSS. |
386 | - if ( ! empty( $tag ) && false === strpos( $tag, ' onload=' ) && $this->defer && ! empty( $this->defer_inline ) && apply_filters( 'autoptimize_filter_css_defer_excluded', true, $tag ) ) { |
|
386 | + if (!empty($tag) && false === strpos($tag, ' onload=') && $this->defer && !empty($this->defer_inline) && apply_filters('autoptimize_filter_css_defer_excluded', true, $tag)) { |
|
387 | 387 | // get media attribute and based on that create onload JS attribute value. |
388 | - if ( false === strpos( $tag, 'media=' ) ) { |
|
389 | - $tag = str_replace( '<link', "<link media='all'", $tag ); |
|
388 | + if (false === strpos($tag, 'media=')) { |
|
389 | + $tag = str_replace('<link', "<link media='all'", $tag); |
|
390 | 390 | } |
391 | 391 | |
392 | - preg_match( '#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $_medias ); |
|
392 | + preg_match('#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $_medias); |
|
393 | 393 | $_media = $_medias[1]; |
394 | - $_preload_onload = autoptimizeConfig::get_ao_css_preload_onload( $_media ); |
|
394 | + $_preload_onload = autoptimizeConfig::get_ao_css_preload_onload($_media); |
|
395 | 395 | |
396 | - if ( 'print' !== $_media ) { |
|
396 | + if ('print' !== $_media) { |
|
397 | 397 | // If not media=print, adapt original <link> element for CSS to be preloaded and add <noscript>-version for fallback. |
398 | - $new_tag = '<noscript>' . autoptimizeUtils::remove_id_from_node( $tag ) . '</noscript>' . str_replace( |
|
398 | + $new_tag = '<noscript>'.autoptimizeUtils::remove_id_from_node($tag).'</noscript>'.str_replace( |
|
399 | 399 | $_medias[0], |
400 | - "media='print' onload=\"" . $_preload_onload . '"', |
|
400 | + "media='print' onload=\"".$_preload_onload.'"', |
|
401 | 401 | $tag |
402 | 402 | ); |
403 | 403 | |
404 | 404 | // Optionally (but default false) preload the (excluded) CSS-file. |
405 | - if ( apply_filters( 'autoptimize_fitler_css_preload_and_print', false ) && 'none' !== $url ) { |
|
406 | - $new_tag = '<link rel="preload" as="stylesheet" href="' . $url . '"/>' . $new_tag; |
|
405 | + if (apply_filters('autoptimize_fitler_css_preload_and_print', false) && 'none' !== $url) { |
|
406 | + $new_tag = '<link rel="preload" as="stylesheet" href="'.$url.'"/>'.$new_tag; |
|
407 | 407 | } |
408 | 408 | } else { |
409 | 409 | $new_tag = $tag; |
@@ -423,22 +423,22 @@ discard block |
||
423 | 423 | * @param string $path image path. |
424 | 424 | * @return boolean |
425 | 425 | */ |
426 | - private function is_datauri_candidate( $path ) |
|
426 | + private function is_datauri_candidate($path) |
|
427 | 427 | { |
428 | 428 | // Call only once since it's called from a loop. |
429 | 429 | static $max_size = null; |
430 | - if ( null === $max_size ) { |
|
430 | + if (null === $max_size) { |
|
431 | 431 | $max_size = $this->get_datauri_maxsize(); |
432 | 432 | } |
433 | 433 | |
434 | - if ( $path && preg_match( '#\.(jpe?g|png|gif|webp|bmp)$#i', $path ) && |
|
435 | - file_exists( $path ) && is_readable( $path ) && filesize( $path ) <= $max_size ) { |
|
434 | + if ($path && preg_match('#\.(jpe?g|png|gif|webp|bmp)$#i', $path) && |
|
435 | + file_exists($path) && is_readable($path) && filesize($path) <= $max_size) { |
|
436 | 436 | |
437 | 437 | // Seems we have a candidate. |
438 | 438 | $is_candidate = true; |
439 | 439 | } else { |
440 | 440 | // Filter allows overriding default decision (which checks for local file existence). |
441 | - $is_candidate = apply_filters( 'autoptimize_filter_css_is_datauri_candidate', false, $path ); |
|
441 | + $is_candidate = apply_filters('autoptimize_filter_css_is_datauri_candidate', false, $path); |
|
442 | 442 | } |
443 | 443 | |
444 | 444 | return $is_candidate; |
@@ -463,29 +463,29 @@ discard block |
||
463 | 463 | * of thing you're probably better of building assets completely |
464 | 464 | * outside of WordPress anyway. |
465 | 465 | */ |
466 | - if ( null === $max_size ) { |
|
467 | - $max_size = (int) apply_filters( 'autoptimize_filter_css_datauri_maxsize', 4096 ); |
|
466 | + if (null === $max_size) { |
|
467 | + $max_size = (int) apply_filters('autoptimize_filter_css_datauri_maxsize', 4096); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | return $max_size; |
471 | 471 | } |
472 | 472 | |
473 | - private function check_datauri_exclude_list( $url ) |
|
473 | + private function check_datauri_exclude_list($url) |
|
474 | 474 | { |
475 | 475 | static $exclude_list = null; |
476 | 476 | $no_datauris = array(); |
477 | 477 | |
478 | 478 | // Again, skip doing certain stuff repeatedly when loop-called. |
479 | - if ( null === $exclude_list ) { |
|
480 | - $exclude_list = apply_filters( 'autoptimize_filter_css_datauri_exclude', '' ); |
|
481 | - $no_datauris = array_filter( array_map( 'trim', explode( ',', $exclude_list ) ) ); |
|
479 | + if (null === $exclude_list) { |
|
480 | + $exclude_list = apply_filters('autoptimize_filter_css_datauri_exclude', ''); |
|
481 | + $no_datauris = array_filter(array_map('trim', explode(',', $exclude_list))); |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | $matched = false; |
485 | 485 | |
486 | - if ( ! empty( $exclude_list ) ) { |
|
487 | - foreach ( $no_datauris as $no_datauri ) { |
|
488 | - if ( false !== strpos( $url, $no_datauri ) ) { |
|
486 | + if (!empty($exclude_list)) { |
|
487 | + foreach ($no_datauris as $no_datauri) { |
|
488 | + if (false !== strpos($url, $no_datauri)) { |
|
489 | 489 | $matched = true; |
490 | 490 | break; |
491 | 491 | } |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | return $matched; |
496 | 496 | } |
497 | 497 | |
498 | - private function build_or_get_datauri_image( $path ) |
|
498 | + private function build_or_get_datauri_image($path) |
|
499 | 499 | { |
500 | 500 | /** |
501 | 501 | * TODO/FIXME: document the required return array format, or better yet, |
@@ -504,27 +504,27 @@ discard block |
||
504 | 504 | */ |
505 | 505 | |
506 | 506 | // Allows short-circuiting datauri generation for an image. |
507 | - $result = apply_filters( 'autoptimize_filter_css_datauri_image', array(), $path ); |
|
508 | - if ( ! empty( $result ) ) { |
|
509 | - if ( is_array( $result ) && isset( $result['full'] ) && isset( $result['base64data'] ) ) { |
|
507 | + $result = apply_filters('autoptimize_filter_css_datauri_image', array(), $path); |
|
508 | + if (!empty($result)) { |
|
509 | + if (is_array($result) && isset($result['full']) && isset($result['base64data'])) { |
|
510 | 510 | return $result; |
511 | 511 | } |
512 | 512 | } |
513 | 513 | |
514 | - $hash = md5( $path ); |
|
515 | - $check = new autoptimizeCache( $hash, 'img' ); |
|
516 | - if ( $check->check() ) { |
|
514 | + $hash = md5($path); |
|
515 | + $check = new autoptimizeCache($hash, 'img'); |
|
516 | + if ($check->check()) { |
|
517 | 517 | // we have the base64 image in cache. |
518 | 518 | $head_and_data = $check->retrieve(); |
519 | - $_base64data = explode( ';base64,', $head_and_data ); |
|
519 | + $_base64data = explode(';base64,', $head_and_data); |
|
520 | 520 | $base64data = $_base64data[1]; |
521 | - unset( $_base64data ); |
|
521 | + unset($_base64data); |
|
522 | 522 | } else { |
523 | 523 | // It's an image and we don't have it in cache, get the type by extension. |
524 | - $exploded_path = explode( '.', $path ); |
|
525 | - $type = end( $exploded_path ); |
|
524 | + $exploded_path = explode('.', $path); |
|
525 | + $type = end($exploded_path); |
|
526 | 526 | |
527 | - switch ( $type ) { |
|
527 | + switch ($type) { |
|
528 | 528 | case 'jpg': |
529 | 529 | case 'jpeg': |
530 | 530 | $dataurihead = 'data:image/jpeg;base64,'; |
@@ -546,13 +546,13 @@ discard block |
||
546 | 546 | } |
547 | 547 | |
548 | 548 | // Encode the data. |
549 | - $base64data = base64_encode( file_get_contents( $path ) ); |
|
550 | - $head_and_data = $dataurihead . $base64data; |
|
549 | + $base64data = base64_encode(file_get_contents($path)); |
|
550 | + $head_and_data = $dataurihead.$base64data; |
|
551 | 551 | |
552 | 552 | // Save in cache. |
553 | - $check->cache( $head_and_data, 'text/plain' ); |
|
553 | + $check->cache($head_and_data, 'text/plain'); |
|
554 | 554 | } |
555 | - unset( $check ); |
|
555 | + unset($check); |
|
556 | 556 | |
557 | 557 | return array( |
558 | 558 | 'full' => $head_and_data, |
@@ -569,13 +569,13 @@ discard block |
||
569 | 569 | * |
570 | 570 | * @return string |
571 | 571 | */ |
572 | - protected static function replace_longest_matches_first( $string, $replacements = array() ) |
|
572 | + protected static function replace_longest_matches_first($string, $replacements = array()) |
|
573 | 573 | { |
574 | - if ( ! empty( $replacements ) ) { |
|
574 | + if (!empty($replacements)) { |
|
575 | 575 | // Sort the replacements array by key length in desc order (so that the longest strings are replaced first). |
576 | - $keys = array_map( 'strlen', array_keys( $replacements ) ); |
|
577 | - array_multisort( $keys, SORT_DESC, $replacements ); |
|
578 | - $string = str_replace( array_keys( $replacements ), array_values( $replacements ), $string ); |
|
576 | + $keys = array_map('strlen', array_keys($replacements)); |
|
577 | + array_multisort($keys, SORT_DESC, $replacements); |
|
578 | + $string = str_replace(array_keys($replacements), array_values($replacements), $string); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | return $string; |
@@ -591,15 +591,15 @@ discard block |
||
591 | 591 | * |
592 | 592 | * @return string |
593 | 593 | */ |
594 | - public function replace_urls( $code = '' ) |
|
594 | + public function replace_urls($code = '') |
|
595 | 595 | { |
596 | 596 | $replacements = array(); |
597 | 597 | |
598 | - preg_match_all( self::ASSETS_REGEX, $code, $url_src_matches ); |
|
599 | - if ( is_array( $url_src_matches ) && ! empty( $url_src_matches ) ) { |
|
600 | - foreach ( $url_src_matches[1] as $count => $original_url ) { |
|
598 | + preg_match_all(self::ASSETS_REGEX, $code, $url_src_matches); |
|
599 | + if (is_array($url_src_matches) && !empty($url_src_matches)) { |
|
600 | + foreach ($url_src_matches[1] as $count => $original_url) { |
|
601 | 601 | // Removes quotes and other cruft. |
602 | - $url = trim( $original_url, " \t\n\r\0\x0B\"'" ); |
|
602 | + $url = trim($original_url, " \t\n\r\0\x0B\"'"); |
|
603 | 603 | |
604 | 604 | /** |
605 | 605 | * TODO/FIXME: Add a way for other code / callable to be called here |
@@ -617,17 +617,17 @@ discard block |
||
617 | 617 | */ |
618 | 618 | |
619 | 619 | // Do CDN replacement if needed. |
620 | - if ( ! empty( $this->cdn_url ) ) { |
|
621 | - $replacement_url = $this->url_replace_cdn( $url ); |
|
620 | + if (!empty($this->cdn_url)) { |
|
621 | + $replacement_url = $this->url_replace_cdn($url); |
|
622 | 622 | // Prepare replacements array. |
623 | - $replacements[ $url_src_matches[1][ $count ] ] = str_replace( |
|
624 | - $original_url, $replacement_url, $url_src_matches[1][ $count ] |
|
623 | + $replacements[$url_src_matches[1][$count]] = str_replace( |
|
624 | + $original_url, $replacement_url, $url_src_matches[1][$count] |
|
625 | 625 | ); |
626 | 626 | } |
627 | 627 | } |
628 | 628 | } |
629 | 629 | |
630 | - $code = self::replace_longest_matches_first( $code, $replacements ); |
|
630 | + $code = self::replace_longest_matches_first($code, $replacements); |
|
631 | 631 | |
632 | 632 | return $code; |
633 | 633 | } |
@@ -640,26 +640,26 @@ discard block |
||
640 | 640 | * @param string $code HTML being processed to hide fonts. |
641 | 641 | * @return string |
642 | 642 | */ |
643 | - public function hide_fontface_and_maybe_cdn( $code ) |
|
643 | + public function hide_fontface_and_maybe_cdn($code) |
|
644 | 644 | { |
645 | 645 | // Proceed only if @font-face declarations exist within $code. |
646 | - preg_match_all( self::FONT_FACE_REGEX, $code, $fontfaces ); |
|
647 | - if ( isset( $fontfaces[0] ) ) { |
|
646 | + preg_match_all(self::FONT_FACE_REGEX, $code, $fontfaces); |
|
647 | + if (isset($fontfaces[0])) { |
|
648 | 648 | // Check if we need to cdn fonts or not. |
649 | - $do_font_cdn = apply_filters( 'autoptimize_filter_css_fonts_cdn', false ); |
|
649 | + $do_font_cdn = apply_filters('autoptimize_filter_css_fonts_cdn', false); |
|
650 | 650 | |
651 | - foreach ( $fontfaces[0] as $full_match ) { |
|
651 | + foreach ($fontfaces[0] as $full_match) { |
|
652 | 652 | // Keep original match so we can search/replace it. |
653 | 653 | $match_search = $full_match; |
654 | 654 | |
655 | 655 | // Do font cdn if needed. |
656 | - if ( $do_font_cdn ) { |
|
657 | - $full_match = $this->replace_urls( $full_match ); |
|
656 | + if ($do_font_cdn) { |
|
657 | + $full_match = $this->replace_urls($full_match); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | // Replace declaration with its base64 encoded string. |
661 | - $replacement = self::build_marker( 'FONTFACE', $full_match ); |
|
662 | - $code = str_replace( $match_search, $replacement, $code ); |
|
661 | + $replacement = self::build_marker('FONTFACE', $full_match); |
|
662 | + $code = str_replace($match_search, $replacement, $code); |
|
663 | 663 | } |
664 | 664 | } |
665 | 665 | |
@@ -673,9 +673,9 @@ discard block |
||
673 | 673 | * @param string $code HTML being processed to unhide fonts. |
674 | 674 | * @return string |
675 | 675 | */ |
676 | - public function restore_fontface( $code ) |
|
676 | + public function restore_fontface($code) |
|
677 | 677 | { |
678 | - return $this->restore_marked_content( 'FONTFACE', $code ); |
|
678 | + return $this->restore_marked_content('FONTFACE', $code); |
|
679 | 679 | } |
680 | 680 | |
681 | 681 | /** |
@@ -684,10 +684,10 @@ discard block |
||
684 | 684 | * @param string $code HTML being processed rewrite assets. |
685 | 685 | * @return string |
686 | 686 | */ |
687 | - public function rewrite_assets( $code ) |
|
687 | + public function rewrite_assets($code) |
|
688 | 688 | { |
689 | 689 | // Handle @font-face rules by hiding and processing them separately. |
690 | - $code = $this->hide_fontface_and_maybe_cdn( $code ); |
|
690 | + $code = $this->hide_fontface_and_maybe_cdn($code); |
|
691 | 691 | |
692 | 692 | /** |
693 | 693 | * TODO/FIXME: |
@@ -704,35 +704,35 @@ discard block |
||
704 | 704 | $imgreplace = array(); |
705 | 705 | |
706 | 706 | // Matches and captures anything specified within the literal `url()` and excludes those containing data: URIs. |
707 | - preg_match_all( self::ASSETS_REGEX, $code, $url_src_matches ); |
|
708 | - if ( is_array( $url_src_matches ) && ! empty( $url_src_matches ) ) { |
|
709 | - foreach ( $url_src_matches[1] as $count => $original_url ) { |
|
707 | + preg_match_all(self::ASSETS_REGEX, $code, $url_src_matches); |
|
708 | + if (is_array($url_src_matches) && !empty($url_src_matches)) { |
|
709 | + foreach ($url_src_matches[1] as $count => $original_url) { |
|
710 | 710 | // Removes quotes and other cruft. |
711 | - $url = trim( $original_url, " \t\n\r\0\x0B\"'" ); |
|
711 | + $url = trim($original_url, " \t\n\r\0\x0B\"'"); |
|
712 | 712 | |
713 | 713 | // If datauri inlining is turned on, do it. |
714 | 714 | $inlined = false; |
715 | - if ( $this->datauris ) { |
|
715 | + if ($this->datauris) { |
|
716 | 716 | $iurl = $url; |
717 | - if ( false !== strpos( $iurl, '?' ) ) { |
|
718 | - $iurl = strtok( $iurl, '?' ); |
|
717 | + if (false !== strpos($iurl, '?')) { |
|
718 | + $iurl = strtok($iurl, '?'); |
|
719 | 719 | } |
720 | 720 | |
721 | - $ipath = $this->getpath( $iurl ); |
|
721 | + $ipath = $this->getpath($iurl); |
|
722 | 722 | |
723 | - $excluded = $this->check_datauri_exclude_list( $ipath ); |
|
724 | - if ( ! $excluded ) { |
|
725 | - $is_datauri_candidate = $this->is_datauri_candidate( $ipath ); |
|
726 | - if ( $is_datauri_candidate ) { |
|
727 | - $datauri = $this->build_or_get_datauri_image( $ipath ); |
|
723 | + $excluded = $this->check_datauri_exclude_list($ipath); |
|
724 | + if (!$excluded) { |
|
725 | + $is_datauri_candidate = $this->is_datauri_candidate($ipath); |
|
726 | + if ($is_datauri_candidate) { |
|
727 | + $datauri = $this->build_or_get_datauri_image($ipath); |
|
728 | 728 | $base64data = $datauri['base64data']; |
729 | 729 | // Add it to the list for replacement. |
730 | - $imgreplace[ $url_src_matches[1][ $count ] ] = str_replace( |
|
730 | + $imgreplace[$url_src_matches[1][$count]] = str_replace( |
|
731 | 731 | $original_url, |
732 | 732 | $datauri['full'], |
733 | - $url_src_matches[1][ $count ] |
|
733 | + $url_src_matches[1][$count] |
|
734 | 734 | ); |
735 | - $inlined = true; |
|
735 | + $inlined = true; |
|
736 | 736 | } |
737 | 737 | } |
738 | 738 | } |
@@ -743,20 +743,20 @@ discard block |
||
743 | 743 | * inlining isn't turned on, or if a resource is skipped from |
744 | 744 | * being inlined for whatever reason above. |
745 | 745 | */ |
746 | - if ( ! $inlined && ( ! empty( $this->cdn_url ) || has_filter( 'autoptimize_filter_base_replace_cdn' ) ) ) { |
|
746 | + if (!$inlined && (!empty($this->cdn_url) || has_filter('autoptimize_filter_base_replace_cdn'))) { |
|
747 | 747 | // Just do the "simple" CDN replacement. |
748 | - $replacement_url = $this->url_replace_cdn( $url ); |
|
749 | - $imgreplace[ $url_src_matches[1][ $count ] ] = str_replace( |
|
750 | - $original_url, $replacement_url, $url_src_matches[1][ $count ] |
|
748 | + $replacement_url = $this->url_replace_cdn($url); |
|
749 | + $imgreplace[$url_src_matches[1][$count]] = str_replace( |
|
750 | + $original_url, $replacement_url, $url_src_matches[1][$count] |
|
751 | 751 | ); |
752 | 752 | } |
753 | 753 | } |
754 | 754 | } |
755 | 755 | |
756 | - $code = self::replace_longest_matches_first( $code, $imgreplace ); |
|
756 | + $code = self::replace_longest_matches_first($code, $imgreplace); |
|
757 | 757 | |
758 | 758 | // Replace back font-face markers with actual font-face declarations. |
759 | - $code = $this->restore_fontface( $code ); |
|
759 | + $code = $this->restore_fontface($code); |
|
760 | 760 | |
761 | 761 | return $code; |
762 | 762 | } |
@@ -766,29 +766,29 @@ discard block |
||
766 | 766 | */ |
767 | 767 | public function minify() |
768 | 768 | { |
769 | - foreach ( $this->css as $group ) { |
|
770 | - list( $media, $css ) = $group; |
|
771 | - if ( preg_match( '#^INLINE;#', $css ) ) { |
|
769 | + foreach ($this->css as $group) { |
|
770 | + list($media, $css) = $group; |
|
771 | + if (preg_match('#^INLINE;#', $css)) { |
|
772 | 772 | // <style>. |
773 | - $css = preg_replace( '#^INLINE;#', '', $css ); |
|
774 | - $css = self::fixurls( ABSPATH . 'index.php', $css ); // ABSPATH already contains a trailing slash. |
|
775 | - $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $css, '' ); |
|
776 | - if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) { |
|
773 | + $css = preg_replace('#^INLINE;#', '', $css); |
|
774 | + $css = self::fixurls(ABSPATH.'index.php', $css); // ABSPATH already contains a trailing slash. |
|
775 | + $tmpstyle = apply_filters('autoptimize_css_individual_style', $css, ''); |
|
776 | + if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) { |
|
777 | 777 | $css = $tmpstyle; |
778 | 778 | $this->alreadyminified = true; |
779 | 779 | } |
780 | 780 | } else { |
781 | 781 | // <link> |
782 | - if ( false !== $css && file_exists( $css ) && is_readable( $css ) ) { |
|
782 | + if (false !== $css && file_exists($css) && is_readable($css)) { |
|
783 | 783 | $css_path = $css; |
784 | - $css = self::fixurls( $css_path, file_get_contents( $css_path ) ); |
|
785 | - $css = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $css ); |
|
786 | - $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $css, $css_path ); |
|
787 | - if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) { |
|
784 | + $css = self::fixurls($css_path, file_get_contents($css_path)); |
|
785 | + $css = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $css); |
|
786 | + $tmpstyle = apply_filters('autoptimize_css_individual_style', $css, $css_path); |
|
787 | + if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) { |
|
788 | 788 | $css = $tmpstyle; |
789 | 789 | $this->alreadyminified = true; |
790 | - } elseif ( $this->can_inject_late( $css_path, $css ) ) { |
|
791 | - $css = self::build_injectlater_marker( $css_path, md5( $css ) ); |
|
790 | + } elseif ($this->can_inject_late($css_path, $css)) { |
|
791 | + $css = self::build_injectlater_marker($css_path, md5($css)); |
|
792 | 792 | } |
793 | 793 | } else { |
794 | 794 | // Couldn't read CSS. Maybe getpath isn't working? |
@@ -796,12 +796,12 @@ discard block |
||
796 | 796 | } |
797 | 797 | } |
798 | 798 | |
799 | - foreach ( $media as $elem ) { |
|
800 | - if ( ! empty( $css ) ) { |
|
801 | - if ( ! isset( $this->csscode[ $elem ] ) ) { |
|
802 | - $this->csscode[ $elem ] = ''; |
|
799 | + foreach ($media as $elem) { |
|
800 | + if (!empty($css)) { |
|
801 | + if (!isset($this->csscode[$elem])) { |
|
802 | + $this->csscode[$elem] = ''; |
|
803 | 803 | } |
804 | - $this->csscode[ $elem ] .= "\n/*FILESTART*/" . $css; |
|
804 | + $this->csscode[$elem] .= "\n/*FILESTART*/".$css; |
|
805 | 805 | } |
806 | 806 | } |
807 | 807 | } |
@@ -809,133 +809,133 @@ discard block |
||
809 | 809 | // Check for duplicate code. |
810 | 810 | $md5list = array(); |
811 | 811 | $tmpcss = $this->csscode; |
812 | - foreach ( $tmpcss as $media => $code ) { |
|
813 | - $md5sum = md5( $code ); |
|
812 | + foreach ($tmpcss as $media => $code) { |
|
813 | + $md5sum = md5($code); |
|
814 | 814 | $medianame = $media; |
815 | - foreach ( $md5list as $med => $sum ) { |
|
815 | + foreach ($md5list as $med => $sum) { |
|
816 | 816 | // If same code. |
817 | - if ( $sum === $md5sum ) { |
|
817 | + if ($sum === $md5sum) { |
|
818 | 818 | // Add the merged code. |
819 | - $medianame = $med . ', ' . $media; |
|
820 | - $this->csscode[ $medianame ] = $code; |
|
821 | - $md5list[ $medianame ] = $md5list[ $med ]; |
|
822 | - unset( $this->csscode[ $med ], $this->csscode[ $media ], $md5list[ $med ] ); |
|
819 | + $medianame = $med.', '.$media; |
|
820 | + $this->csscode[$medianame] = $code; |
|
821 | + $md5list[$medianame] = $md5list[$med]; |
|
822 | + unset($this->csscode[$med], $this->csscode[$media], $md5list[$med]); |
|
823 | 823 | } |
824 | 824 | } |
825 | - $md5list[ $medianame ] = $md5sum; |
|
825 | + $md5list[$medianame] = $md5sum; |
|
826 | 826 | } |
827 | - unset( $tmpcss ); |
|
827 | + unset($tmpcss); |
|
828 | 828 | |
829 | 829 | // Manage @imports, while is for recursive import management. |
830 | - foreach ( $this->csscode as &$thiscss ) { |
|
830 | + foreach ($this->csscode as &$thiscss) { |
|
831 | 831 | // Flag to trigger import reconstitution and var to hold external imports. |
832 | 832 | $fiximports = false; |
833 | 833 | $external_imports = ''; |
834 | 834 | |
835 | 835 | // remove comments to avoid importing commented-out imports. |
836 | - $thiscss_nocomments = preg_replace( '#/\*.*\*/#Us', '', $thiscss ); |
|
837 | - while ( preg_match_all( '#@import +(?:url)?(?:(?:\((["\']?)(?:[^"\')]+)\1\)|(["\'])(?:[^"\']+)\2)(?:[^,;"\']+(?:,[^,;"\']+)*)?)(?:;)#mi', $thiscss_nocomments, $matches ) ) { |
|
838 | - foreach ( $matches[0] as $import ) { |
|
839 | - if ( $this->isremovable( $import, $this->cssremovables ) ) { |
|
840 | - $thiscss = str_replace( $import, '', $thiscss ); |
|
836 | + $thiscss_nocomments = preg_replace('#/\*.*\*/#Us', '', $thiscss); |
|
837 | + while (preg_match_all('#@import +(?:url)?(?:(?:\((["\']?)(?:[^"\')]+)\1\)|(["\'])(?:[^"\']+)\2)(?:[^,;"\']+(?:,[^,;"\']+)*)?)(?:;)#mi', $thiscss_nocomments, $matches)) { |
|
838 | + foreach ($matches[0] as $import) { |
|
839 | + if ($this->isremovable($import, $this->cssremovables)) { |
|
840 | + $thiscss = str_replace($import, '', $thiscss); |
|
841 | 841 | $import_ok = true; |
842 | 842 | } else { |
843 | - $url = trim( preg_replace( '#^.*((?:https?:|ftp:)?//.*\.css).*$#', '$1', trim( $import ) ), " \t\n\r\0\x0B\"'" ); |
|
844 | - $path = $this->getpath( $url ); |
|
843 | + $url = trim(preg_replace('#^.*((?:https?:|ftp:)?//.*\.css).*$#', '$1', trim($import)), " \t\n\r\0\x0B\"'"); |
|
844 | + $path = $this->getpath($url); |
|
845 | 845 | $import_ok = false; |
846 | - if ( file_exists( $path ) && is_readable( $path ) ) { |
|
847 | - $code = addcslashes( self::fixurls( $path, file_get_contents( $path ) ), '\\' ); |
|
848 | - $code = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $code ); |
|
849 | - $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $code, '' ); |
|
850 | - if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) { |
|
846 | + if (file_exists($path) && is_readable($path)) { |
|
847 | + $code = addcslashes(self::fixurls($path, file_get_contents($path)), '\\'); |
|
848 | + $code = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $code); |
|
849 | + $tmpstyle = apply_filters('autoptimize_css_individual_style', $code, ''); |
|
850 | + if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) { |
|
851 | 851 | $code = $tmpstyle; |
852 | 852 | $this->alreadyminified = true; |
853 | - } elseif ( $this->can_inject_late( $path, $code ) ) { |
|
854 | - $code = self::build_injectlater_marker( $path, md5( $code ) ); |
|
853 | + } elseif ($this->can_inject_late($path, $code)) { |
|
854 | + $code = self::build_injectlater_marker($path, md5($code)); |
|
855 | 855 | } |
856 | 856 | |
857 | - if ( ! empty( $code ) ) { |
|
858 | - $tmp_thiscss = preg_replace( '#(/\*FILESTART\*/.*)' . preg_quote( $import, '#' ) . '#Us', '/*FILESTART2*/' . $code . '$1', $thiscss ); |
|
859 | - if ( ! empty( $tmp_thiscss ) ) { |
|
857 | + if (!empty($code)) { |
|
858 | + $tmp_thiscss = preg_replace('#(/\*FILESTART\*/.*)'.preg_quote($import, '#').'#Us', '/*FILESTART2*/'.$code.'$1', $thiscss); |
|
859 | + if (!empty($tmp_thiscss)) { |
|
860 | 860 | $thiscss = $tmp_thiscss; |
861 | 861 | $import_ok = true; |
862 | - unset( $tmp_thiscss ); |
|
862 | + unset($tmp_thiscss); |
|
863 | 863 | } |
864 | 864 | } |
865 | - unset( $code ); |
|
865 | + unset($code); |
|
866 | 866 | } |
867 | 867 | } |
868 | - if ( ! $import_ok ) { |
|
868 | + if (!$import_ok) { |
|
869 | 869 | // External imports and general fall-back. |
870 | 870 | $external_imports .= $import; |
871 | 871 | |
872 | - $thiscss = str_replace( $import, '', $thiscss ); |
|
872 | + $thiscss = str_replace($import, '', $thiscss); |
|
873 | 873 | $fiximports = true; |
874 | 874 | } |
875 | 875 | } |
876 | - $thiscss = preg_replace( '#/\*FILESTART\*/#', '', $thiscss ); |
|
877 | - $thiscss = preg_replace( '#/\*FILESTART2\*/#', '/*FILESTART*/', $thiscss ); |
|
876 | + $thiscss = preg_replace('#/\*FILESTART\*/#', '', $thiscss); |
|
877 | + $thiscss = preg_replace('#/\*FILESTART2\*/#', '/*FILESTART*/', $thiscss); |
|
878 | 878 | |
879 | 879 | // and update $thiscss_nocomments before going into next iteration in while loop. |
880 | - $thiscss_nocomments = preg_replace( '#/\*.*\*/#Us', '', $thiscss ); |
|
880 | + $thiscss_nocomments = preg_replace('#/\*.*\*/#Us', '', $thiscss); |
|
881 | 881 | } |
882 | - unset( $thiscss_nocomments ); |
|
882 | + unset($thiscss_nocomments); |
|
883 | 883 | |
884 | 884 | // Add external imports to top of aggregated CSS. |
885 | - if ( $fiximports ) { |
|
886 | - $thiscss = $external_imports . $thiscss; |
|
885 | + if ($fiximports) { |
|
886 | + $thiscss = $external_imports.$thiscss; |
|
887 | 887 | } |
888 | 888 | } |
889 | - unset( $thiscss ); |
|
889 | + unset($thiscss); |
|
890 | 890 | |
891 | 891 | // $this->csscode has all the uncompressed code now. |
892 | - foreach ( $this->csscode as &$code ) { |
|
892 | + foreach ($this->csscode as &$code) { |
|
893 | 893 | // Check for already-minified code. |
894 | - $hash = md5( $code ); |
|
895 | - do_action( 'autoptimize_action_css_hash', $hash ); |
|
896 | - $ccheck = new autoptimizeCache( $hash, 'css' ); |
|
897 | - if ( $ccheck->check() ) { |
|
894 | + $hash = md5($code); |
|
895 | + do_action('autoptimize_action_css_hash', $hash); |
|
896 | + $ccheck = new autoptimizeCache($hash, 'css'); |
|
897 | + if ($ccheck->check()) { |
|
898 | 898 | $code = $ccheck->retrieve(); |
899 | - $this->hashmap[ md5( $code ) ] = $hash; |
|
899 | + $this->hashmap[md5($code)] = $hash; |
|
900 | 900 | continue; |
901 | 901 | } |
902 | - unset( $ccheck ); |
|
902 | + unset($ccheck); |
|
903 | 903 | |
904 | 904 | // Rewrite and/or inline referenced assets. |
905 | - $code = $this->rewrite_assets( $code ); |
|
905 | + $code = $this->rewrite_assets($code); |
|
906 | 906 | |
907 | 907 | // Minify. |
908 | - $code = $this->run_minifier_on( $code ); |
|
908 | + $code = $this->run_minifier_on($code); |
|
909 | 909 | |
910 | 910 | // Bring back INJECTLATER stuff. |
911 | - $code = $this->inject_minified( $code ); |
|
911 | + $code = $this->inject_minified($code); |
|
912 | 912 | |
913 | 913 | // Filter results. |
914 | - $tmp_code = apply_filters( 'autoptimize_css_after_minify', $code ); |
|
915 | - if ( ! empty( $tmp_code ) ) { |
|
914 | + $tmp_code = apply_filters('autoptimize_css_after_minify', $code); |
|
915 | + if (!empty($tmp_code)) { |
|
916 | 916 | $code = $tmp_code; |
917 | - unset( $tmp_code ); |
|
917 | + unset($tmp_code); |
|
918 | 918 | } |
919 | 919 | |
920 | - $this->hashmap[ md5( $code ) ] = $hash; |
|
920 | + $this->hashmap[md5($code)] = $hash; |
|
921 | 921 | } |
922 | 922 | |
923 | - unset( $code ); |
|
923 | + unset($code); |
|
924 | 924 | return true; |
925 | 925 | } |
926 | 926 | |
927 | - public function run_minifier_on( $code ) |
|
927 | + public function run_minifier_on($code) |
|
928 | 928 | { |
929 | - if ( ! $this->alreadyminified ) { |
|
930 | - $do_minify = apply_filters( 'autoptimize_css_do_minify', true ); |
|
929 | + if (!$this->alreadyminified) { |
|
930 | + $do_minify = apply_filters('autoptimize_css_do_minify', true); |
|
931 | 931 | |
932 | - if ( $do_minify ) { |
|
932 | + if ($do_minify) { |
|
933 | 933 | $cssmin = new autoptimizeCSSmin(); |
934 | - $tmp_code = trim( $cssmin->run( $code ) ); |
|
934 | + $tmp_code = trim($cssmin->run($code)); |
|
935 | 935 | |
936 | - if ( ! empty( $tmp_code ) ) { |
|
936 | + if (!empty($tmp_code)) { |
|
937 | 937 | $code = $tmp_code; |
938 | - unset( $tmp_code ); |
|
938 | + unset($tmp_code); |
|
939 | 939 | } |
940 | 940 | } |
941 | 941 | } |
@@ -949,18 +949,18 @@ discard block |
||
949 | 949 | public function cache() |
950 | 950 | { |
951 | 951 | // CSS cache. |
952 | - foreach ( $this->csscode as $media => $code ) { |
|
953 | - if ( empty( $code ) ) { |
|
952 | + foreach ($this->csscode as $media => $code) { |
|
953 | + if (empty($code)) { |
|
954 | 954 | continue; |
955 | 955 | } |
956 | 956 | |
957 | - $md5 = $this->hashmap[ md5( $code ) ]; |
|
958 | - $cache = new autoptimizeCache( $md5, 'css' ); |
|
959 | - if ( ! $cache->check() ) { |
|
957 | + $md5 = $this->hashmap[md5($code)]; |
|
958 | + $cache = new autoptimizeCache($md5, 'css'); |
|
959 | + if (!$cache->check()) { |
|
960 | 960 | // Cache our code. |
961 | - $cache->cache( $code, 'text/css' ); |
|
961 | + $cache->cache($code, 'text/css'); |
|
962 | 962 | } |
963 | - $this->url[ $media ] = AUTOPTIMIZE_CACHE_URL . $cache->getname(); |
|
963 | + $this->url[$media] = AUTOPTIMIZE_CACHE_URL.$cache->getname(); |
|
964 | 964 | } |
965 | 965 | } |
966 | 966 | |
@@ -970,95 +970,95 @@ discard block |
||
970 | 970 | public function getcontent() |
971 | 971 | { |
972 | 972 | // Restore the full content (only applies when "autoptimize_filter_css_justhead" filter is true). |
973 | - if ( ! empty( $this->restofcontent ) ) { |
|
973 | + if (!empty($this->restofcontent)) { |
|
974 | 974 | $this->content .= $this->restofcontent; |
975 | 975 | $this->restofcontent = ''; |
976 | 976 | } |
977 | 977 | |
978 | 978 | // type is not added by default. |
979 | 979 | $type_css = ''; |
980 | - if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) { |
|
980 | + if (apply_filters('autoptimize_filter_cssjs_addtype', false)) { |
|
981 | 981 | $type_css = 'type="text/css" '; |
982 | 982 | } |
983 | 983 | |
984 | 984 | // Inject the new stylesheets. |
985 | - $replace_tag = array( '<title', 'before' ); |
|
986 | - $replace_tag = apply_filters( 'autoptimize_filter_css_replacetag', $replace_tag, $this->content ); |
|
985 | + $replace_tag = array('<title', 'before'); |
|
986 | + $replace_tag = apply_filters('autoptimize_filter_css_replacetag', $replace_tag, $this->content); |
|
987 | 987 | |
988 | - if ( $this->inline ) { |
|
989 | - foreach ( $this->csscode as $media => $code ) { |
|
990 | - $this->inject_in_html( apply_filters( 'autoptimize_filter_css_bodyreplacementpayload', '<style ' . $type_css . 'media="' . $media . '">' . $code . '</style>' ), $replace_tag ); |
|
988 | + if ($this->inline) { |
|
989 | + foreach ($this->csscode as $media => $code) { |
|
990 | + $this->inject_in_html(apply_filters('autoptimize_filter_css_bodyreplacementpayload', '<style '.$type_css.'media="'.$media.'">'.$code.'</style>'), $replace_tag); |
|
991 | 991 | } |
992 | 992 | } else { |
993 | - if ( $this->defer ) { |
|
993 | + if ($this->defer) { |
|
994 | 994 | $preload_css_block = ''; |
995 | 995 | $inlined_ccss_block = ''; |
996 | 996 | $noscript_css_block = '<noscript id="aonoscrcss">'; |
997 | 997 | |
998 | 998 | $defer_inline_code = $this->defer_inline; |
999 | - if ( ! empty( $defer_inline_code ) ) { |
|
1000 | - if ( apply_filters( 'autoptimize_filter_css_critcss_minify', true ) ) { |
|
1001 | - $icss_hash = md5( $defer_inline_code ); |
|
1002 | - $icss_cache = new autoptimizeCache( $icss_hash, 'css' ); |
|
1003 | - if ( $icss_cache->check() ) { |
|
999 | + if (!empty($defer_inline_code)) { |
|
1000 | + if (apply_filters('autoptimize_filter_css_critcss_minify', true)) { |
|
1001 | + $icss_hash = md5($defer_inline_code); |
|
1002 | + $icss_cache = new autoptimizeCache($icss_hash, 'css'); |
|
1003 | + if ($icss_cache->check()) { |
|
1004 | 1004 | // we have the optimized inline CSS in cache. |
1005 | 1005 | $defer_inline_code = $icss_cache->retrieve(); |
1006 | 1006 | } else { |
1007 | 1007 | $cssmin = new autoptimizeCSSmin(); |
1008 | - $tmp_code = trim( $cssmin->run( $defer_inline_code ) ); |
|
1008 | + $tmp_code = trim($cssmin->run($defer_inline_code)); |
|
1009 | 1009 | |
1010 | - if ( ! empty( $tmp_code ) ) { |
|
1010 | + if (!empty($tmp_code)) { |
|
1011 | 1011 | $defer_inline_code = $tmp_code; |
1012 | - $icss_cache->cache( $defer_inline_code, 'text/css' ); |
|
1013 | - unset( $tmp_code ); |
|
1012 | + $icss_cache->cache($defer_inline_code, 'text/css'); |
|
1013 | + unset($tmp_code); |
|
1014 | 1014 | } |
1015 | 1015 | } |
1016 | 1016 | } |
1017 | 1017 | // inlined critical css set here, but injected when full CSS is injected |
1018 | 1018 | // to avoid CSS containing SVG with <title tag receiving the full CSS link. |
1019 | - $inlined_ccss_block = '<style ' . $type_css . 'id="aoatfcss" media="all">' . $defer_inline_code . '</style>'; |
|
1019 | + $inlined_ccss_block = '<style '.$type_css.'id="aoatfcss" media="all">'.$defer_inline_code.'</style>'; |
|
1020 | 1020 | } |
1021 | 1021 | } |
1022 | 1022 | |
1023 | - foreach ( $this->url as $media => $url ) { |
|
1024 | - $url = $this->url_replace_cdn( $url ); |
|
1023 | + foreach ($this->url as $media => $url) { |
|
1024 | + $url = $this->url_replace_cdn($url); |
|
1025 | 1025 | |
1026 | 1026 | // Add the stylesheet either deferred (import at bottom) or normal links in head. |
1027 | - if ( $this->defer && 'print' !== $media ) { |
|
1028 | - $preload_onload = autoptimizeConfig::get_ao_css_preload_onload( $media ); |
|
1027 | + if ($this->defer && 'print' !== $media) { |
|
1028 | + $preload_onload = autoptimizeConfig::get_ao_css_preload_onload($media); |
|
1029 | 1029 | |
1030 | - $preload_css_block .= '<link rel="stylesheet" media="print" href="' . $url . '" onload="' . $preload_onload . '" />'; |
|
1031 | - if ( apply_filters( 'autoptimize_fitler_css_preload_and_print', false ) ) { |
|
1032 | - $preload_css_block = '<link rel="preload" as="stylesheet" href="' . $url . '"/>' . $preload_css_block; |
|
1030 | + $preload_css_block .= '<link rel="stylesheet" media="print" href="'.$url.'" onload="'.$preload_onload.'" />'; |
|
1031 | + if (apply_filters('autoptimize_fitler_css_preload_and_print', false)) { |
|
1032 | + $preload_css_block = '<link rel="preload" as="stylesheet" href="'.$url.'"/>'.$preload_css_block; |
|
1033 | 1033 | } |
1034 | - $noscript_css_block .= '<link ' . $type_css . 'media="' . $media . '" href="' . $url . '" rel="stylesheet" />'; |
|
1034 | + $noscript_css_block .= '<link '.$type_css.'media="'.$media.'" href="'.$url.'" rel="stylesheet" />'; |
|
1035 | 1035 | } else { |
1036 | - if ( strlen( $this->csscode[ $media ] ) > $this->cssinlinesize ) { |
|
1037 | - $this->inject_in_html( apply_filters( 'autoptimize_filter_css_bodyreplacementpayload', '<link ' . $type_css . 'media="' . $media . '" href="' . $url . '" rel="stylesheet" />' ), $replace_tag ); |
|
1038 | - } elseif ( strlen( $this->csscode[ $media ] ) > 0 ) { |
|
1039 | - $this->inject_in_html( apply_filters( 'autoptimize_filter_css_bodyreplacementpayload', '<style ' . $type_css . 'media="' . $media . '">' . $this->csscode[ $media ] . '</style>' ), $replace_tag ); |
|
1036 | + if (strlen($this->csscode[$media]) > $this->cssinlinesize) { |
|
1037 | + $this->inject_in_html(apply_filters('autoptimize_filter_css_bodyreplacementpayload', '<link '.$type_css.'media="'.$media.'" href="'.$url.'" rel="stylesheet" />'), $replace_tag); |
|
1038 | + } elseif (strlen($this->csscode[$media]) > 0) { |
|
1039 | + $this->inject_in_html(apply_filters('autoptimize_filter_css_bodyreplacementpayload', '<style '.$type_css.'media="'.$media.'">'.$this->csscode[$media].'</style>'), $replace_tag); |
|
1040 | 1040 | } |
1041 | 1041 | } |
1042 | 1042 | } |
1043 | 1043 | |
1044 | - if ( $this->defer ) { |
|
1044 | + if ($this->defer) { |
|
1045 | 1045 | $noscript_css_block .= '</noscript>'; |
1046 | 1046 | // Inject inline critical CSS, the preloaded full CSS and the noscript-CSS. |
1047 | - $this->inject_in_html( apply_filters( 'autoptimize_filter_css_bodyreplacementpayload', $inlined_ccss_block . $preload_css_block . $noscript_css_block ), $replace_tag ); |
|
1047 | + $this->inject_in_html(apply_filters('autoptimize_filter_css_bodyreplacementpayload', $inlined_ccss_block.$preload_css_block.$noscript_css_block), $replace_tag); |
|
1048 | 1048 | } |
1049 | 1049 | } |
1050 | 1050 | |
1051 | 1051 | // restore comments. |
1052 | - $this->content = $this->restore_comments( $this->content ); |
|
1052 | + $this->content = $this->restore_comments($this->content); |
|
1053 | 1053 | |
1054 | 1054 | // restore IE hacks. |
1055 | - $this->content = $this->restore_iehacks( $this->content ); |
|
1055 | + $this->content = $this->restore_iehacks($this->content); |
|
1056 | 1056 | |
1057 | 1057 | // restore (no)script. |
1058 | - $this->content = $this->restore_marked_content( 'SCRIPT', $this->content ); |
|
1058 | + $this->content = $this->restore_marked_content('SCRIPT', $this->content); |
|
1059 | 1059 | |
1060 | 1060 | // Restore noptimize. |
1061 | - $this->content = $this->restore_noptimize( $this->content ); |
|
1061 | + $this->content = $this->restore_noptimize($this->content); |
|
1062 | 1062 | |
1063 | 1063 | // Return the modified stylesheet. |
1064 | 1064 | return $this->content; |
@@ -1070,44 +1070,44 @@ discard block |
||
1070 | 1070 | * @param string $file filename of optimized CSS-file. |
1071 | 1071 | * @param string $code CSS-code in which to fix URL's. |
1072 | 1072 | */ |
1073 | - static function fixurls( $file, $code ) |
|
1073 | + static function fixurls($file, $code) |
|
1074 | 1074 | { |
1075 | 1075 | // Switch all imports to the url() syntax. |
1076 | - $code = preg_replace( '#@import ("|\')(.+?)\.css.*?("|\')#', '@import url("${2}.css")', $code ); |
|
1076 | + $code = preg_replace('#@import ("|\')(.+?)\.css.*?("|\')#', '@import url("${2}.css")', $code); |
|
1077 | 1077 | |
1078 | - if ( preg_match_all( self::ASSETS_REGEX, $code, $matches ) ) { |
|
1079 | - $file = str_replace( WP_ROOT_DIR, '/', $file ); |
|
1078 | + if (preg_match_all(self::ASSETS_REGEX, $code, $matches)) { |
|
1079 | + $file = str_replace(WP_ROOT_DIR, '/', $file); |
|
1080 | 1080 | /** |
1081 | 1081 | * Rollback as per https://github.com/futtta/autoptimize/issues/94 |
1082 | 1082 | * $file = str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', $file ); |
1083 | 1083 | */ |
1084 | - $dir = dirname( $file ); // Like /themes/expound/css. |
|
1084 | + $dir = dirname($file); // Like /themes/expound/css. |
|
1085 | 1085 | |
1086 | 1086 | /** |
1087 | 1087 | * $dir should not contain backslashes, since it's used to replace |
1088 | 1088 | * urls, but it can contain them when running on Windows because |
1089 | 1089 | * fixurls() is sometimes called with `ABSPATH . 'index.php'` |
1090 | 1090 | */ |
1091 | - $dir = str_replace( '\\', '/', $dir ); |
|
1092 | - unset( $file ); // not used below at all. |
|
1091 | + $dir = str_replace('\\', '/', $dir); |
|
1092 | + unset($file); // not used below at all. |
|
1093 | 1093 | |
1094 | 1094 | $replace = array(); |
1095 | - foreach ( $matches[1] as $k => $url ) { |
|
1095 | + foreach ($matches[1] as $k => $url) { |
|
1096 | 1096 | // Remove quotes. |
1097 | - $url = trim( $url, " \t\n\r\0\x0B\"'" ); |
|
1098 | - $no_q_url = trim( $url, "\"'" ); |
|
1099 | - if ( $url !== $no_q_url ) { |
|
1097 | + $url = trim($url, " \t\n\r\0\x0B\"'"); |
|
1098 | + $no_q_url = trim($url, "\"'"); |
|
1099 | + if ($url !== $no_q_url) { |
|
1100 | 1100 | $removed_quotes = true; |
1101 | 1101 | } else { |
1102 | 1102 | $removed_quotes = false; |
1103 | 1103 | } |
1104 | 1104 | |
1105 | - if ( '' === $no_q_url ) { |
|
1105 | + if ('' === $no_q_url) { |
|
1106 | 1106 | continue; |
1107 | 1107 | } |
1108 | 1108 | |
1109 | 1109 | $url = $no_q_url; |
1110 | - if ( '/' === $url[0] || preg_match( '#^(https?://|ftp://|data:)#i', $url ) ) { |
|
1110 | + if ('/' === $url[0] || preg_match('#^(https?://|ftp://|data:)#i', $url)) { |
|
1111 | 1111 | // URL is protocol-relative, host-relative or something we don't touch. |
1112 | 1112 | continue; |
1113 | 1113 | } else { // Relative URL. |
@@ -1116,49 +1116,49 @@ discard block |
||
1116 | 1116 | * rollback as per https://github.com/futtta/autoptimize/issues/94 |
1117 | 1117 | * $newurl = preg_replace( '/https?:/', '', str_replace( ' ', '%20', AUTOPTIMIZE_WP_CONTENT_URL . str_replace( '//', '/', $dir . '/' . $url ) ) ); |
1118 | 1118 | */ |
1119 | - $newurl = preg_replace( '/https?:/', '', str_replace( ' ', '%20', AUTOPTIMIZE_WP_ROOT_URL . str_replace( '//', '/', $dir . '/' . $url ) ) ); |
|
1120 | - $newurl = apply_filters( 'autoptimize_filter_css_fixurl_newurl', $newurl ); |
|
1119 | + $newurl = preg_replace('/https?:/', '', str_replace(' ', '%20', AUTOPTIMIZE_WP_ROOT_URL.str_replace('//', '/', $dir.'/'.$url))); |
|
1120 | + $newurl = apply_filters('autoptimize_filter_css_fixurl_newurl', $newurl); |
|
1121 | 1121 | |
1122 | 1122 | /** |
1123 | 1123 | * Hash the url + whatever was behind potentially for replacement |
1124 | 1124 | * We must do this, or different css classes referencing the same bg image (but |
1125 | 1125 | * different parts of it, say, in sprites and such) loose their stuff... |
1126 | 1126 | */ |
1127 | - $hash = md5( $url . $matches[2][ $k ] ); |
|
1128 | - $code = str_replace( $matches[0][ $k ], $hash, $code ); |
|
1127 | + $hash = md5($url.$matches[2][$k]); |
|
1128 | + $code = str_replace($matches[0][$k], $hash, $code); |
|
1129 | 1129 | |
1130 | - if ( $removed_quotes ) { |
|
1131 | - $replace[ $hash ] = "url('" . $newurl . "')" . $matches[2][ $k ]; |
|
1130 | + if ($removed_quotes) { |
|
1131 | + $replace[$hash] = "url('".$newurl."')".$matches[2][$k]; |
|
1132 | 1132 | } else { |
1133 | - $replace[ $hash ] = 'url(' . $newurl . ')' . $matches[2][ $k ]; |
|
1133 | + $replace[$hash] = 'url('.$newurl.')'.$matches[2][$k]; |
|
1134 | 1134 | } |
1135 | 1135 | } |
1136 | 1136 | } |
1137 | 1137 | |
1138 | - $code = self::replace_longest_matches_first( $code, $replace ); |
|
1138 | + $code = self::replace_longest_matches_first($code, $replace); |
|
1139 | 1139 | } |
1140 | 1140 | |
1141 | 1141 | return $code; |
1142 | 1142 | } |
1143 | 1143 | |
1144 | - private function ismovable( $tag ) |
|
1144 | + private function ismovable($tag) |
|
1145 | 1145 | { |
1146 | - if ( ! $this->aggregate ) { |
|
1146 | + if (!$this->aggregate) { |
|
1147 | 1147 | return false; |
1148 | 1148 | } |
1149 | 1149 | |
1150 | - if ( ! empty( $this->allowlist ) ) { |
|
1151 | - foreach ( $this->allowlist as $match ) { |
|
1152 | - if ( false !== strpos( $tag, $match ) ) { |
|
1150 | + if (!empty($this->allowlist)) { |
|
1151 | + foreach ($this->allowlist as $match) { |
|
1152 | + if (false !== strpos($tag, $match)) { |
|
1153 | 1153 | return true; |
1154 | 1154 | } |
1155 | 1155 | } |
1156 | 1156 | // no match with allowlist. |
1157 | 1157 | return false; |
1158 | 1158 | } else { |
1159 | - if ( is_array( $this->dontmove ) && ! empty( $this->dontmove ) ) { |
|
1160 | - foreach ( $this->dontmove as $match ) { |
|
1161 | - if ( false !== strpos( $tag, $match ) ) { |
|
1159 | + if (is_array($this->dontmove) && !empty($this->dontmove)) { |
|
1160 | + foreach ($this->dontmove as $match) { |
|
1161 | + if (false !== strpos($tag, $match)) { |
|
1162 | 1162 | // Matched something. |
1163 | 1163 | return false; |
1164 | 1164 | } |
@@ -1170,22 +1170,22 @@ discard block |
||
1170 | 1170 | } |
1171 | 1171 | } |
1172 | 1172 | |
1173 | - private function can_inject_late( $css_path, $css ) |
|
1173 | + private function can_inject_late($css_path, $css) |
|
1174 | 1174 | { |
1175 | - $consider_minified_array = apply_filters( 'autoptimize_filter_css_consider_minified', false, $css_path ); |
|
1176 | - if ( true !== $this->inject_min_late ) { |
|
1175 | + $consider_minified_array = apply_filters('autoptimize_filter_css_consider_minified', false, $css_path); |
|
1176 | + if (true !== $this->inject_min_late) { |
|
1177 | 1177 | // late-inject turned off. |
1178 | 1178 | return false; |
1179 | - } elseif ( ( false === strpos( $css_path, 'min.css' ) ) && ( str_replace( $consider_minified_array, '', $css_path ) === $css_path ) ) { |
|
1179 | + } elseif ((false === strpos($css_path, 'min.css')) && (str_replace($consider_minified_array, '', $css_path) === $css_path)) { |
|
1180 | 1180 | // file not minified based on filename & filter. |
1181 | 1181 | return false; |
1182 | - } elseif ( false !== strpos( $css, '@import' ) ) { |
|
1182 | + } elseif (false !== strpos($css, '@import')) { |
|
1183 | 1183 | // can't late-inject files with imports as those need to be aggregated. |
1184 | 1184 | return false; |
1185 | - } elseif ( ( false !== strpos( $css, '@font-face' ) ) && ( apply_filters( 'autoptimize_filter_css_fonts_cdn', false ) === true ) && ( ! empty( $this->cdn_url ) ) ) { |
|
1185 | + } elseif ((false !== strpos($css, '@font-face')) && (apply_filters('autoptimize_filter_css_fonts_cdn', false) === true) && (!empty($this->cdn_url))) { |
|
1186 | 1186 | // don't late-inject CSS with font-src's if fonts are set to be CDN'ed. |
1187 | 1187 | return false; |
1188 | - } elseif ( ( ( true == $this->datauris ) || ( ! empty( $this->cdn_url ) ) ) && preg_match( '#background[^;}]*url\(#Ui', $css ) ) { |
|
1188 | + } elseif (((true == $this->datauris) || (!empty($this->cdn_url))) && preg_match('#background[^;}]*url\(#Ui', $css)) { |
|
1189 | 1189 | // don't late-inject CSS with images if CDN is set OR if image inlining is on. |
1190 | 1190 | return false; |
1191 | 1191 | } else { |
@@ -1203,44 +1203,44 @@ discard block |
||
1203 | 1203 | * |
1204 | 1204 | * @return bool|string Url pointing to the minified css file or false. |
1205 | 1205 | */ |
1206 | - public function minify_single( $filepath, $cache_miss = false ) |
|
1206 | + public function minify_single($filepath, $cache_miss = false) |
|
1207 | 1207 | { |
1208 | - $contents = $this->prepare_minify_single( $filepath ); |
|
1208 | + $contents = $this->prepare_minify_single($filepath); |
|
1209 | 1209 | |
1210 | - if ( empty( $contents ) ) { |
|
1210 | + if (empty($contents)) { |
|
1211 | 1211 | return false; |
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | // Check cache. |
1215 | - $hash = 'single_' . md5( $contents ); |
|
1216 | - $cache = new autoptimizeCache( $hash, 'css' ); |
|
1217 | - do_action( 'autoptimize_action_css_hash', $hash ); |
|
1215 | + $hash = 'single_'.md5($contents); |
|
1216 | + $cache = new autoptimizeCache($hash, 'css'); |
|
1217 | + do_action('autoptimize_action_css_hash', $hash); |
|
1218 | 1218 | |
1219 | 1219 | // If not in cache already, minify... |
1220 | - if ( ! $cache->check() || $cache_miss ) { |
|
1220 | + if (!$cache->check() || $cache_miss) { |
|
1221 | 1221 | // Fixurls... |
1222 | - $contents = self::fixurls( $filepath, $contents ); |
|
1222 | + $contents = self::fixurls($filepath, $contents); |
|
1223 | 1223 | // CDN-replace any referenced assets if needed... |
1224 | - $contents = $this->hide_fontface_and_maybe_cdn( $contents ); |
|
1225 | - $contents = $this->replace_urls( $contents ); |
|
1226 | - $contents = $this->restore_fontface( $contents ); |
|
1224 | + $contents = $this->hide_fontface_and_maybe_cdn($contents); |
|
1225 | + $contents = $this->replace_urls($contents); |
|
1226 | + $contents = $this->restore_fontface($contents); |
|
1227 | 1227 | // Now minify... |
1228 | 1228 | $cssmin = new autoptimizeCSSmin(); |
1229 | - $contents = trim( $cssmin->run( $contents ) ); |
|
1229 | + $contents = trim($cssmin->run($contents)); |
|
1230 | 1230 | |
1231 | 1231 | // Check if minified cache content is empty. |
1232 | - if ( empty( $contents ) ) { |
|
1232 | + if (empty($contents)) { |
|
1233 | 1233 | return false; |
1234 | 1234 | } |
1235 | 1235 | |
1236 | 1236 | // Filter contents of excluded minified CSS. |
1237 | - $contents = apply_filters( 'autoptimize_filter_css_single_after_minify', $contents ); |
|
1237 | + $contents = apply_filters('autoptimize_filter_css_single_after_minify', $contents); |
|
1238 | 1238 | |
1239 | 1239 | // Store in cache. |
1240 | - $cache->cache( $contents, 'text/css' ); |
|
1240 | + $cache->cache($contents, 'text/css'); |
|
1241 | 1241 | } |
1242 | 1242 | |
1243 | - $url = $this->build_minify_single_url( $cache ); |
|
1243 | + $url = $this->build_minify_single_url($cache); |
|
1244 | 1244 | |
1245 | 1245 | return $url; |
1246 | 1246 | } |
@@ -1260,20 +1260,20 @@ discard block |
||
1260 | 1260 | return $this->options; |
1261 | 1261 | } |
1262 | 1262 | |
1263 | - public function replaceOptions( $options ) |
|
1263 | + public function replaceOptions($options) |
|
1264 | 1264 | { |
1265 | 1265 | $this->options = $options; |
1266 | 1266 | } |
1267 | 1267 | |
1268 | - public function setOption( $name, $value ) |
|
1268 | + public function setOption($name, $value) |
|
1269 | 1269 | { |
1270 | - $this->options[ $name ] = $value; |
|
1270 | + $this->options[$name] = $value; |
|
1271 | 1271 | $this->$name = $value; |
1272 | 1272 | } |
1273 | 1273 | |
1274 | - public function getOption( $name ) |
|
1274 | + public function getOption($name) |
|
1275 | 1275 | { |
1276 | - return $this->options[ $name ]; |
|
1276 | + return $this->options[$name]; |
|
1277 | 1277 | } |
1278 | 1278 | |
1279 | 1279 | /** |
@@ -1287,11 +1287,11 @@ discard block |
||
1287 | 1287 | * @param string $css the to be sanitized CSS |
1288 | 1288 | * @return string sanitized CSS. |
1289 | 1289 | */ |
1290 | - public static function sanitize_css( $css ) |
|
1290 | + public static function sanitize_css($css) |
|
1291 | 1291 | { |
1292 | - $css = wp_strip_all_tags( $css ); |
|
1293 | - if ( strpos( $css, '<' ) !== false ) { |
|
1294 | - $css = preg_replace( '#<(\/?\w+)#', '\00003C$1', $css ); |
|
1292 | + $css = wp_strip_all_tags($css); |
|
1293 | + if (strpos($css, '<') !== false) { |
|
1294 | + $css = preg_replace('#<(\/?\w+)#', '\00003C$1', $css); |
|
1295 | 1295 | } |
1296 | 1296 | return $css; |
1297 | 1297 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | global $ao_ccss_unloadccss; |
20 | 20 | |
21 | 21 | // In case domain is not set yet (done in cron.php). |
22 | - if ( empty( $ao_ccss_domain ) ) { |
|
22 | + if (empty($ao_ccss_domain)) { |
|
23 | 23 | $ao_ccss_domain = get_site_url(); |
24 | 24 | } |
25 | 25 | |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | ?> |
29 | 29 | <ul id="adv-panel"> |
30 | 30 | <li class="itemDetail"> |
31 | - <h2 class="itemTitle fleft"><?php _e( 'Advanced Settings', 'autoptimize' ); ?></h2> |
|
31 | + <h2 class="itemTitle fleft"><?php _e('Advanced Settings', 'autoptimize'); ?></h2> |
|
32 | 32 | <button type="button" class="toggle-btn"> |
33 | 33 | <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span> |
34 | 34 | </button> |
@@ -36,114 +36,114 @@ discard block |
||
36 | 36 | <table id="key" class="form-table"> |
37 | 37 | <tr> |
38 | 38 | <th scope="row"> |
39 | - <?php _e( 'Viewport Size', 'autoptimize' ); ?> |
|
39 | + <?php _e('Viewport Size', 'autoptimize'); ?> |
|
40 | 40 | </th> |
41 | 41 | <td> |
42 | - <label for="autoptimize_ccss_vw"><?php _e( 'Width', 'autoptimize' ); ?>:</label> <input type="number" id="autoptimize_ccss_vw" name="autoptimize_ccss_viewport[w]" min="800" max="4096" placeholder="1400" value="<?php echo $viewport['w']; ?>" /> |
|
43 | - <label for="autoptimize_ccss_vh"><?php _e( 'Height', 'autoptimize' ); ?>:</label> <input type="number" id="autoptimize_ccss_vh" name="autoptimize_ccss_viewport[h]" min="600" max="2160" placeholder="1080" value="<?php echo $viewport['h']; ?>" /> |
|
42 | + <label for="autoptimize_ccss_vw"><?php _e('Width', 'autoptimize'); ?>:</label> <input type="number" id="autoptimize_ccss_vw" name="autoptimize_ccss_viewport[w]" min="800" max="4096" placeholder="1400" value="<?php echo $viewport['w']; ?>" /> |
|
43 | + <label for="autoptimize_ccss_vh"><?php _e('Height', 'autoptimize'); ?>:</label> <input type="number" id="autoptimize_ccss_vh" name="autoptimize_ccss_viewport[h]" min="600" max="2160" placeholder="1080" value="<?php echo $viewport['h']; ?>" /> |
|
44 | 44 | <p class="notes"> |
45 | - <?php _e( '<a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> default viewport size is 1400x1080 pixels (width x height). You can change this size by typing a desired width and height values above. Allowed value ranges are from 800 to 4096 for width and from 600 to 2160 for height.', 'autoptimize' ); ?> |
|
45 | + <?php _e('<a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> default viewport size is 1400x1080 pixels (width x height). You can change this size by typing a desired width and height values above. Allowed value ranges are from 800 to 4096 for width and from 600 to 2160 for height.', 'autoptimize'); ?> |
|
46 | 46 | </p> |
47 | 47 | </td> |
48 | 48 | </tr> |
49 | 49 | <tr> |
50 | 50 | <th scope="row"> |
51 | - <?php _e( 'Force Include CSS selectors', 'autoptimize' ); ?> |
|
51 | + <?php _e('Force Include CSS selectors', 'autoptimize'); ?> |
|
52 | 52 | </th> |
53 | 53 | <td> |
54 | - <textarea id="autoptimize_ccss_finclude" name="autoptimize_ccss_finclude" rows='3' maxlenght='500' style="width:100%;" placeholder="<?php _e( '.button-special,//#footer', 'autoptimize' ); ?>"><?php echo trim( esc_textarea( $ao_ccss_finclude ) ); ?></textarea> |
|
54 | + <textarea id="autoptimize_ccss_finclude" name="autoptimize_ccss_finclude" rows='3' maxlenght='500' style="width:100%;" placeholder="<?php _e('.button-special,//#footer', 'autoptimize'); ?>"><?php echo trim(esc_textarea($ao_ccss_finclude)); ?></textarea> |
|
55 | 55 | <p class="notes"> |
56 | - <?php _e( 'Force include CSS selectors can be used to style dynamic content that is not part of the HTML that is seen during the Critical CSS generation. To use this feature, add comma separated values with both simple strings and/or regular expressions to match the desired selectors. Regular expressions must be preceeded by two forward slashes. For instance: <code>.button-special,//#footer</code>. In this example <code>.button-special</code> will match <code>.button-special</code> selector only, while <code>//#footer</code> will match <code>#footer</code>, <code>#footer-address</code> and <code>#footer-phone</code> selectors in case they exist.<br />Do take into account that changing this setting will only affect new/ updated rules, so you might want to remove old rules and clear your page cache to expedite the forceIncludes becoming used.', 'autoptimize' ); ?> |
|
56 | + <?php _e('Force include CSS selectors can be used to style dynamic content that is not part of the HTML that is seen during the Critical CSS generation. To use this feature, add comma separated values with both simple strings and/or regular expressions to match the desired selectors. Regular expressions must be preceeded by two forward slashes. For instance: <code>.button-special,//#footer</code>. In this example <code>.button-special</code> will match <code>.button-special</code> selector only, while <code>//#footer</code> will match <code>#footer</code>, <code>#footer-address</code> and <code>#footer-phone</code> selectors in case they exist.<br />Do take into account that changing this setting will only affect new/ updated rules, so you might want to remove old rules and clear your page cache to expedite the forceIncludes becoming used.', 'autoptimize'); ?> |
|
57 | 57 | </p> |
58 | 58 | </td> |
59 | 59 | </tr> |
60 | 60 | <tr> |
61 | 61 | <th scope="row"> |
62 | - <?php _e( 'Queue processing time limit', 'autoptimize' ); ?> |
|
62 | + <?php _e('Queue processing time limit', 'autoptimize'); ?> |
|
63 | 63 | </th> |
64 | 64 | <td> |
65 | 65 | <input type="number" id="autoptimize_ccss_rtimelimit" name="autoptimize_ccss_rtimelimit" min="0" max="240" placeholder="0" value="<?php echo $ao_ccss_rtimelimit; ?>" /> |
66 | 66 | <p class="notes"> |
67 | - <?php _e( 'The cronned queue processing is an asynchronous process triggerd by (WordPress) cron. To avoid this process from running too long and potentially getting killed, you can set the number of seconds here, 0 means no limit.', 'autoptimize' ); ?> |
|
67 | + <?php _e('The cronned queue processing is an asynchronous process triggerd by (WordPress) cron. To avoid this process from running too long and potentially getting killed, you can set the number of seconds here, 0 means no limit.', 'autoptimize'); ?> |
|
68 | 68 | </p> |
69 | 69 | </td> |
70 | 70 | </tr> |
71 | 71 | <tr> |
72 | 72 | <th scope="row"> |
73 | - <?php _e( 'Fetch Original CSS', 'autoptimize' ); ?> |
|
73 | + <?php _e('Fetch Original CSS', 'autoptimize'); ?> |
|
74 | 74 | </th> |
75 | 75 | <td> |
76 | - <input type="checkbox" id="autoptimize_ccss_noptimize" name="autoptimize_ccss_noptimize" value="1" <?php checked( 1 == $ao_ccss_noptimize ); ?>> |
|
76 | + <input type="checkbox" id="autoptimize_ccss_noptimize" name="autoptimize_ccss_noptimize" value="1" <?php checked(1 == $ao_ccss_noptimize); ?>> |
|
77 | 77 | <p class="notes"> |
78 | - <?php _e( 'In some (rare) cases the generation of critical CSS works better with the original CSS instead of the Autoptimized one, this option enables that behavior.', 'autoptimize' ); ?> |
|
78 | + <?php _e('In some (rare) cases the generation of critical CSS works better with the original CSS instead of the Autoptimized one, this option enables that behavior.', 'autoptimize'); ?> |
|
79 | 79 | </p> |
80 | 80 | </td> |
81 | 81 | </tr> |
82 | 82 | <tr> |
83 | 83 | <th scope="row"> |
84 | - <?php _e( 'Add CCSS for logged in users?', 'autoptimize' ); ?> |
|
84 | + <?php _e('Add CCSS for logged in users?', 'autoptimize'); ?> |
|
85 | 85 | </th> |
86 | 86 | <td> |
87 | - <input type="checkbox" id="autoptimize_ccss_loggedin" name="autoptimize_ccss_loggedin" value="1" <?php checked( 1 == $ao_ccss_loggedin ); ?>> |
|
87 | + <input type="checkbox" id="autoptimize_ccss_loggedin" name="autoptimize_ccss_loggedin" value="1" <?php checked(1 == $ao_ccss_loggedin); ?>> |
|
88 | 88 | <p class="notes"> |
89 | - <?php _e( 'Critical CSS is generated by criticalcss.com from your pages as seen by an "anonymous visitor". Disable this option if you don\'t want the "visitor" critical CSS to be used for logged in users.', 'autoptimize' ); ?> |
|
89 | + <?php _e('Critical CSS is generated by criticalcss.com from your pages as seen by an "anonymous visitor". Disable this option if you don\'t want the "visitor" critical CSS to be used for logged in users.', 'autoptimize'); ?> |
|
90 | 90 | </p> |
91 | 91 | </td> |
92 | 92 | </tr> |
93 | 93 | <tr> |
94 | 94 | <th scope="row"> |
95 | - <?php _e( 'Force path-based rules to be generated for pages?', 'autoptimize' ); ?> |
|
95 | + <?php _e('Force path-based rules to be generated for pages?', 'autoptimize'); ?> |
|
96 | 96 | </th> |
97 | 97 | <td> |
98 | - <input type="checkbox" id="autoptimize_ccss_forcepath" name="autoptimize_ccss_forcepath" value="1" <?php checked( 1 == $ao_ccss_forcepath ); ?>> |
|
98 | + <input type="checkbox" id="autoptimize_ccss_forcepath" name="autoptimize_ccss_forcepath" value="1" <?php checked(1 == $ao_ccss_forcepath); ?>> |
|
99 | 99 | <p class="notes"> |
100 | - <?php _e( 'By default for each page a separate rule is generated. If your pages have (semi-)identical above the fold look and feel and you want to keep the rules lean, you can disable that so one rule is created to all pages.', 'autoptimize' ); ?> |
|
100 | + <?php _e('By default for each page a separate rule is generated. If your pages have (semi-)identical above the fold look and feel and you want to keep the rules lean, you can disable that so one rule is created to all pages.', 'autoptimize'); ?> |
|
101 | 101 | </p> |
102 | 102 | </td> |
103 | 103 | </tr> |
104 | 104 | <tr> |
105 | 105 | <th scope="row"> |
106 | - <?php _e( 'Defer jQuery and other non-aggregated JS-files?', 'autoptimize' ); ?> |
|
106 | + <?php _e('Defer jQuery and other non-aggregated JS-files?', 'autoptimize'); ?> |
|
107 | 107 | </th> |
108 | 108 | <td> |
109 | - <input type="checkbox" id="autoptimize_ccss_deferjquery" name="autoptimize_ccss_deferjquery" value="1" <?php checked( 1 == $ao_ccss_deferjquery ); ?>> |
|
109 | + <input type="checkbox" id="autoptimize_ccss_deferjquery" name="autoptimize_ccss_deferjquery" value="1" <?php checked(1 == $ao_ccss_deferjquery); ?>> |
|
110 | 110 | <p class="notes"> |
111 | - <?php _e( 'Defer all non-aggregated JS, including jQuery and inline JS to fix remaining render-blocking issues. Make sure to test your site thoroughly when activating this option!', 'autoptimize' ); ?> |
|
111 | + <?php _e('Defer all non-aggregated JS, including jQuery and inline JS to fix remaining render-blocking issues. Make sure to test your site thoroughly when activating this option!', 'autoptimize'); ?> |
|
112 | 112 | </p> |
113 | 113 | </td> |
114 | 114 | </tr> |
115 | 115 | <tr> |
116 | 116 | <th scope="row"> |
117 | - <?php _e( 'Unload critical CSS after page load?', 'autoptimize' ); ?> |
|
117 | + <?php _e('Unload critical CSS after page load?', 'autoptimize'); ?> |
|
118 | 118 | </th> |
119 | 119 | <td> |
120 | - <input type="checkbox" id="autoptimize_ccss_unloadccss" name="autoptimize_ccss_unloadccss" value="1" <?php checked( 1 == $ao_ccss_unloadccss ); ?>> |
|
120 | + <input type="checkbox" id="autoptimize_ccss_unloadccss" name="autoptimize_ccss_unloadccss" value="1" <?php checked(1 == $ao_ccss_unloadccss); ?>> |
|
121 | 121 | <p class="notes"> |
122 | - <?php _e( 'In rare cases the critical CSS needs to be removed once the full CSS loads, this option makes it so!', 'autoptimize' ); ?> |
|
122 | + <?php _e('In rare cases the critical CSS needs to be removed once the full CSS loads, this option makes it so!', 'autoptimize'); ?> |
|
123 | 123 | </p> |
124 | 124 | </td> |
125 | 125 | </tr> |
126 | 126 | <tr> |
127 | 127 | <th scope="row"> |
128 | - <?php _e( 'Bound domain', 'autoptimize' ); ?> |
|
128 | + <?php _e('Bound domain', 'autoptimize'); ?> |
|
129 | 129 | </th> |
130 | 130 | <td> |
131 | - <input type="text" id="autoptimize_ccss_domain" name="autoptimize_ccss_domain" style="width:100%;" placeholder="<?php _e( 'Don\'t leave this empty, put e.g. https://example.net/ or simply \'none\' to disable domain binding.', 'autoptimize' ); ?>" value="<?php echo trim( esc_attr( $ao_ccss_domain ) ); ?>"> |
|
131 | + <input type="text" id="autoptimize_ccss_domain" name="autoptimize_ccss_domain" style="width:100%;" placeholder="<?php _e('Don\'t leave this empty, put e.g. https://example.net/ or simply \'none\' to disable domain binding.', 'autoptimize'); ?>" value="<?php echo trim(esc_attr($ao_ccss_domain)); ?>"> |
|
132 | 132 | <p class="notes"> |
133 | - <?php _e( 'Only requests from this domain will be sent for Critical CSS generation (pricing is per domain/ month).', 'autoptimize' ); ?> |
|
133 | + <?php _e('Only requests from this domain will be sent for Critical CSS generation (pricing is per domain/ month).', 'autoptimize'); ?> |
|
134 | 134 | </p> |
135 | 135 | </td> |
136 | 136 | </tr> |
137 | 137 | <tr> |
138 | 138 | <th scope="row"> |
139 | - <?php _e( 'Debug Mode', 'autoptimize' ); ?> |
|
139 | + <?php _e('Debug Mode', 'autoptimize'); ?> |
|
140 | 140 | </th> |
141 | 141 | <td> |
142 | - <input type="checkbox" id="autoptimize_ccss_debug" name="autoptimize_ccss_debug" value="1" <?php checked( 1 == $ao_ccss_debug ); ?>> |
|
142 | + <input type="checkbox" id="autoptimize_ccss_debug" name="autoptimize_ccss_debug" value="1" <?php checked(1 == $ao_ccss_debug); ?>> |
|
143 | 143 | <p class="notes"> |
144 | 144 | <?php |
145 | - _e( '<strong>CAUTION! Only use debug mode on production/live environments for ad-hoc troubleshooting and remember to turn it back off after</strong>, as this generates a lot of log-data.<br />Check the box above to enable Autoptimize CriticalCSS Power-Up debug mode. It provides debug facilities in this screen, to the browser console and to this file: ', 'autoptimize' ); |
|
146 | - echo '<code>' . AO_CCSS_LOG . '</code>'; |
|
145 | + _e('<strong>CAUTION! Only use debug mode on production/live environments for ad-hoc troubleshooting and remember to turn it back off after</strong>, as this generates a lot of log-data.<br />Check the box above to enable Autoptimize CriticalCSS Power-Up debug mode. It provides debug facilities in this screen, to the browser console and to this file: ', 'autoptimize'); |
|
146 | + echo '<code>'.AO_CCSS_LOG.'</code>'; |
|
147 | 147 | ?> |
148 | 148 | </p> |
149 | 149 | </td> |
@@ -17,66 +17,66 @@ discard block |
||
17 | 17 | */ |
18 | 18 | |
19 | 19 | |
20 | -if ( ! defined( 'ABSPATH' ) ) { |
|
20 | +if (!defined('ABSPATH')) { |
|
21 | 21 | exit; |
22 | 22 | } |
23 | 23 | |
24 | -define( 'AUTOPTIMIZE_PLUGIN_VERSION', '2.8.4' ); |
|
24 | +define('AUTOPTIMIZE_PLUGIN_VERSION', '2.8.4'); |
|
25 | 25 | |
26 | 26 | // plugin_dir_path() returns the trailing slash! |
27 | -define( 'AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
|
28 | -define( 'AUTOPTIMIZE_PLUGIN_FILE', __FILE__ ); |
|
27 | +define('AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path(__FILE__)); |
|
28 | +define('AUTOPTIMIZE_PLUGIN_FILE', __FILE__); |
|
29 | 29 | |
30 | 30 | // Bail early if attempting to run on non-supported php versions. |
31 | -if ( version_compare( PHP_VERSION, '5.6', '<' ) ) { |
|
31 | +if (version_compare(PHP_VERSION, '5.6', '<')) { |
|
32 | 32 | function autoptimize_incompatible_admin_notice() { |
33 | - echo '<div class="error"><p>' . __( 'Autoptimize requires PHP 5.6 (or higher) to function properly. Please upgrade PHP. The Plugin has been auto-deactivated.', 'autoptimize' ) . '</p></div>'; |
|
34 | - if ( isset( $_GET['activate'] ) ) { |
|
35 | - unset( $_GET['activate'] ); |
|
33 | + echo '<div class="error"><p>'.__('Autoptimize requires PHP 5.6 (or higher) to function properly. Please upgrade PHP. The Plugin has been auto-deactivated.', 'autoptimize').'</p></div>'; |
|
34 | + if (isset($_GET['activate'])) { |
|
35 | + unset($_GET['activate']); |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 | function autoptimize_deactivate_self() { |
39 | - deactivate_plugins( plugin_basename( AUTOPTIMIZE_PLUGIN_FILE ) ); |
|
39 | + deactivate_plugins(plugin_basename(AUTOPTIMIZE_PLUGIN_FILE)); |
|
40 | 40 | } |
41 | - add_action( 'admin_notices', 'autoptimize_incompatible_admin_notice' ); |
|
42 | - add_action( 'admin_init', 'autoptimize_deactivate_self' ); |
|
41 | + add_action('admin_notices', 'autoptimize_incompatible_admin_notice'); |
|
42 | + add_action('admin_init', 'autoptimize_deactivate_self'); |
|
43 | 43 | return; |
44 | 44 | } |
45 | 45 | |
46 | -function autoptimize_autoload( $class_name ) { |
|
47 | - if ( in_array( $class_name, array( 'AO_Minify_HTML', 'JSMin' ) ) ) { |
|
48 | - $file = strtolower( $class_name ); |
|
49 | - $file = str_replace( '_', '-', $file ); |
|
50 | - $path = dirname( __FILE__ ) . '/classes/external/php/'; |
|
51 | - $filepath = $path . $file . '.php'; |
|
52 | - } elseif ( false !== strpos( $class_name, 'Autoptimize\\tubalmartin\\CssMin' ) ) { |
|
53 | - $file = str_replace( 'Autoptimize\\tubalmartin\\CssMin\\', '', $class_name ); |
|
54 | - $path = dirname( __FILE__ ) . '/classes/external/php/yui-php-cssmin-bundled/'; |
|
55 | - $filepath = $path . $file . '.php'; |
|
56 | - } elseif ( 'autoptimize' === substr( $class_name, 0, 11 ) ) { |
|
46 | +function autoptimize_autoload($class_name) { |
|
47 | + if (in_array($class_name, array('AO_Minify_HTML', 'JSMin'))) { |
|
48 | + $file = strtolower($class_name); |
|
49 | + $file = str_replace('_', '-', $file); |
|
50 | + $path = dirname(__FILE__).'/classes/external/php/'; |
|
51 | + $filepath = $path.$file.'.php'; |
|
52 | + } elseif (false !== strpos($class_name, 'Autoptimize\\tubalmartin\\CssMin')) { |
|
53 | + $file = str_replace('Autoptimize\\tubalmartin\\CssMin\\', '', $class_name); |
|
54 | + $path = dirname(__FILE__).'/classes/external/php/yui-php-cssmin-bundled/'; |
|
55 | + $filepath = $path.$file.'.php'; |
|
56 | + } elseif ('autoptimize' === substr($class_name, 0, 11)) { |
|
57 | 57 | // One of our "old" classes. |
58 | 58 | $file = $class_name; |
59 | - $path = dirname( __FILE__ ) . '/classes/'; |
|
60 | - $filepath = $path . $file . '.php'; |
|
61 | - } elseif ( 'PAnD' === $class_name ) { |
|
59 | + $path = dirname(__FILE__).'/classes/'; |
|
60 | + $filepath = $path.$file.'.php'; |
|
61 | + } elseif ('PAnD' === $class_name) { |
|
62 | 62 | $file = 'persist-admin-notices-dismissal'; |
63 | - $path = dirname( __FILE__ ) . '/classes/external/php/persist-admin-notices-dismissal/'; |
|
64 | - $filepath = $path . $file . '.php'; |
|
63 | + $path = dirname(__FILE__).'/classes/external/php/persist-admin-notices-dismissal/'; |
|
64 | + $filepath = $path.$file.'.php'; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | // If we didn't match one of our rules, bail! |
68 | - if ( ! isset( $filepath ) ) { |
|
68 | + if (!isset($filepath)) { |
|
69 | 69 | return; |
70 | 70 | } |
71 | 71 | |
72 | 72 | require $filepath; |
73 | 73 | } |
74 | 74 | |
75 | -spl_autoload_register( 'autoptimize_autoload' ); |
|
75 | +spl_autoload_register('autoptimize_autoload'); |
|
76 | 76 | |
77 | 77 | // Load WP CLI command(s) on demand. |
78 | -if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
79 | - require AUTOPTIMIZE_PLUGIN_DIR . 'classes/autoptimizeCLI.php'; |
|
78 | +if (defined('WP_CLI') && WP_CLI) { |
|
79 | + require AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeCLI.php'; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | function autoptimize() { |
88 | 88 | static $plugin = null; |
89 | 89 | |
90 | - if ( null === $plugin ) { |
|
91 | - $plugin = new autoptimizeMain( AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE ); |
|
90 | + if (null === $plugin) { |
|
91 | + $plugin = new autoptimizeMain(AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | return $plugin; |