@@ -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 | |
@@ -34,19 +34,19 @@ discard block |
||
34 | 34 | '<!--/noindex-->', |
35 | 35 | ); |
36 | 36 | |
37 | - public function read( $options ) |
|
37 | + public function read($options) |
|
38 | 38 | { |
39 | 39 | // Remove the HTML comments? |
40 | 40 | $this->keepcomments = (bool) $options['keepcomments']; |
41 | 41 | |
42 | 42 | // Filter to force xhtml. |
43 | - $this->forcexhtml = (bool) apply_filters( 'autoptimize_filter_html_forcexhtml', false ); |
|
43 | + $this->forcexhtml = (bool) apply_filters('autoptimize_filter_html_forcexhtml', false); |
|
44 | 44 | |
45 | 45 | // Filterable strings to be excluded from HTML minification. |
46 | - $exclude = apply_filters( 'autoptimize_filter_html_exclude', '' ); |
|
47 | - if ( '' !== $exclude ) { |
|
48 | - $exclude_arr = array_filter( array_map( 'trim', explode( ',', $exclude ) ) ); |
|
49 | - $this->exclude = array_merge( $exclude_arr, $this->exclude ); |
|
46 | + $exclude = apply_filters('autoptimize_filter_html_exclude', ''); |
|
47 | + if ('' !== $exclude) { |
|
48 | + $exclude_arr = array_filter(array_map('trim', explode(',', $exclude))); |
|
49 | + $this->exclude = array_merge($exclude_arr, $this->exclude); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | // Nothing else for HTML! |
@@ -60,49 +60,49 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function minify() |
62 | 62 | { |
63 | - $noptimize = apply_filters( 'autoptimize_filter_html_noptimize', false, $this->content ); |
|
64 | - if ( $noptimize ) { |
|
63 | + $noptimize = apply_filters('autoptimize_filter_html_noptimize', false, $this->content); |
|
64 | + if ($noptimize) { |
|
65 | 65 | return false; |
66 | 66 | } |
67 | 67 | |
68 | 68 | // Wrap the to-be-excluded strings in noptimize tags. |
69 | - foreach ( $this->exclude as $str ) { |
|
70 | - if ( false !== strpos( $this->content, $str ) ) { |
|
71 | - $replacement = '<!--noptimize-->' . $str . '<!--/noptimize-->'; |
|
72 | - $this->content = str_replace( $str, $replacement, $this->content ); |
|
69 | + foreach ($this->exclude as $str) { |
|
70 | + if (false !== strpos($this->content, $str)) { |
|
71 | + $replacement = '<!--noptimize-->'.$str.'<!--/noptimize-->'; |
|
72 | + $this->content = str_replace($str, $replacement, $this->content); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
76 | 76 | // Noptimize. |
77 | - $this->content = $this->hide_noptimize( $this->content ); |
|
77 | + $this->content = $this->hide_noptimize($this->content); |
|
78 | 78 | |
79 | 79 | // Preparing options for Minify_HTML. |
80 | - $options = array( 'keepComments' => $this->keepcomments ); |
|
81 | - if ( $this->forcexhtml ) { |
|
80 | + $options = array('keepComments' => $this->keepcomments); |
|
81 | + if ($this->forcexhtml) { |
|
82 | 82 | $options['xhtml'] = true; |
83 | 83 | } |
84 | 84 | |
85 | - $tmp_content = AO_Minify_HTML::minify( $this->content, $options ); |
|
86 | - if ( ! empty( $tmp_content ) ) { |
|
85 | + $tmp_content = AO_Minify_HTML::minify($this->content, $options); |
|
86 | + if (!empty($tmp_content)) { |
|
87 | 87 | $this->content = $tmp_content; |
88 | - unset( $tmp_content ); |
|
88 | + unset($tmp_content); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | // Restore noptimize. |
92 | - $this->content = $this->restore_noptimize( $this->content ); |
|
92 | + $this->content = $this->restore_noptimize($this->content); |
|
93 | 93 | |
94 | 94 | // Remove the noptimize-wrapper from around the excluded strings. |
95 | - foreach ( $this->exclude as $str ) { |
|
96 | - $replacement = '<!--noptimize-->' . $str . '<!--/noptimize-->'; |
|
97 | - if ( false !== strpos( $this->content, $replacement ) ) { |
|
98 | - $this->content = str_replace( $replacement, $str, $this->content ); |
|
95 | + foreach ($this->exclude as $str) { |
|
96 | + $replacement = '<!--noptimize-->'.$str.'<!--/noptimize-->'; |
|
97 | + if (false !== strpos($this->content, $replacement)) { |
|
98 | + $this->content = str_replace($replacement, $str, $this->content); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | 102 | // Revslider data attribs somehow suffer from HTML optimization, this fixes that! |
103 | - if ( class_exists( 'RevSlider' ) && apply_filters( 'autoptimize_filter_html_dataattrib_cleanup', false ) ) { |
|
104 | - $this->content = preg_replace( '#\n(data-.*$)\n#Um', ' $1 ', $this->content ); |
|
105 | - $this->content = preg_replace( '#<[^>]*(=\"[^"\'<>\s]*\")(\w)#', '$1 $2', $this->content ); |
|
103 | + if (class_exists('RevSlider') && apply_filters('autoptimize_filter_html_dataattrib_cleanup', false)) { |
|
104 | + $this->content = preg_replace('#\n(data-.*$)\n#Um', ' $1 ', $this->content); |
|
105 | + $this->content = preg_replace('#<[^>]*(=\"[^"\'<>\s]*\")(\w)#', '$1 $2', $this->content); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | return true; |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | { |
74 | 74 | $this->_html = str_replace("\r\n", "\n", trim($html)); |
75 | 75 | if (isset($options['xhtml'])) { |
76 | - $this->_isXhtml = (bool)$options['xhtml']; |
|
76 | + $this->_isXhtml = (bool) $options['xhtml']; |
|
77 | 77 | } |
78 | 78 | if (isset($options['cssMinifier'])) { |
79 | 79 | $this->_cssMinifier = $options['cssMinifier']; |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML')); |
99 | 99 | } |
100 | 100 | |
101 | - $this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']); |
|
101 | + $this->_replacementHash = 'MINIFYHTML'.md5($_SERVER['REQUEST_TIME']); |
|
102 | 102 | $this->_placeholders = array(); |
103 | 103 | |
104 | 104 | // replace SCRIPTs (and minify) with placeholders |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | ,$this->_html); |
115 | 115 | |
116 | 116 | // remove HTML comments (not containing IE conditional comments). |
117 | - if ($this->_keepComments == false) { |
|
117 | + if ($this->_keepComments == false) { |
|
118 | 118 | $this->_html = preg_replace_callback( |
119 | 119 | '/<!--([\\s\\S]*?)-->/' |
120 | 120 | ,array($this, '_commentCB') |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | //$this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/i', "$1\n$2", $this->_html); |
160 | 160 | |
161 | 161 | // reverse order while preserving keys to ensure the last replacement is done first, etc ... |
162 | - $this->_placeholders = array_reverse( $this->_placeholders, true ); |
|
162 | + $this->_placeholders = array_reverse($this->_placeholders, true); |
|
163 | 163 | |
164 | 164 | // fill placeholders |
165 | 165 | $this->_html = str_replace( |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | |
180 | 180 | protected function _reservePlace($content) |
181 | 181 | { |
182 | - $placeholder = '%' . $this->_replacementHash . count($this->_placeholders) . '%'; |
|
182 | + $placeholder = '%'.$this->_replacementHash.count($this->_placeholders).'%'; |
|
183 | 183 | $this->_placeholders[$placeholder] = $content; |
184 | 184 | return $placeholder; |
185 | 185 | } |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | |
194 | 194 | protected function _outsideTagCB($m) |
195 | 195 | { |
196 | - return '>' . preg_replace('/^\\s+|\\s+$/', ' ', $m[1]) . '<'; |
|
196 | + return '>'.preg_replace('/^\\s+|\\s+$/', ' ', $m[1]).'<'; |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | protected function _removePreCB($m) |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | protected function _removeCdata($str) |
266 | 266 | { |
267 | 267 | return (false !== strpos($str, '<![CDATA[')) |
268 | - ? str_replace(array('/* <![CDATA[ */','/* ]]> */','/*<![CDATA[*/','/*]]>*/','<![CDATA[', ']]>'), '', $str) |
|
268 | + ? str_replace(array('/* <![CDATA[ */', '/* ]]> */', '/*<![CDATA[*/', '/*]]>*/', '<![CDATA[', ']]>'), '', $str) |
|
269 | 269 | : $str; |
270 | 270 | } |
271 | 271 |
@@ -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.3' ); |
|
24 | +define('AUTOPTIMIZE_PLUGIN_VERSION', '2.8.3'); |
|
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; |