@@ -38,18 +38,18 @@ discard block |
||
38 | 38 | $l = floatval(str_replace('%', '', $hslValues[2])); |
39 | 39 | |
40 | 40 | // Wrap and clamp, then fraction! |
41 | - $h = ((($h % 360) + 360) % 360) / 360; |
|
42 | - $s = self::clampNumber($s, 0, 100) / 100; |
|
43 | - $l = self::clampNumber($l, 0, 100) / 100; |
|
41 | + $h = ((($h%360) + 360)%360)/360; |
|
42 | + $s = self::clampNumber($s, 0, 100)/100; |
|
43 | + $l = self::clampNumber($l, 0, 100)/100; |
|
44 | 44 | |
45 | 45 | if ($s == 0) { |
46 | - $r = $g = $b = self::roundNumber(255 * $l); |
|
46 | + $r = $g = $b = self::roundNumber(255*$l); |
|
47 | 47 | } else { |
48 | - $v2 = $l < 0.5 ? $l * (1 + $s) : ($l + $s) - ($s * $l); |
|
49 | - $v1 = (2 * $l) - $v2; |
|
50 | - $r = self::roundNumber(255 * self::hueToRgb($v1, $v2, $h + (1/3))); |
|
51 | - $g = self::roundNumber(255 * self::hueToRgb($v1, $v2, $h)); |
|
52 | - $b = self::roundNumber(255 * self::hueToRgb($v1, $v2, $h - (1/3))); |
|
48 | + $v2 = $l < 0.5 ? $l*(1 + $s) : ($l + $s) - ($s*$l); |
|
49 | + $v1 = (2*$l) - $v2; |
|
50 | + $r = self::roundNumber(255*self::hueToRgb($v1, $v2, $h + (1/3))); |
|
51 | + $g = self::roundNumber(255*self::hueToRgb($v1, $v2, $h)); |
|
52 | + $b = self::roundNumber(255*self::hueToRgb($v1, $v2, $h - (1/3))); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | return array($r, $g, $b); |
@@ -66,16 +66,16 @@ discard block |
||
66 | 66 | { |
67 | 67 | $vh = $vh < 0 ? $vh + 1 : ($vh > 1 ? $vh - 1 : $vh); |
68 | 68 | |
69 | - if ($vh * 6 < 1) { |
|
70 | - return $v1 + ($v2 - $v1) * 6 * $vh; |
|
69 | + if ($vh*6 < 1) { |
|
70 | + return $v1 + ($v2 - $v1)*6*$vh; |
|
71 | 71 | } |
72 | 72 | |
73 | - if ($vh * 2 < 1) { |
|
73 | + if ($vh*2 < 1) { |
|
74 | 74 | return $v2; |
75 | 75 | } |
76 | 76 | |
77 | - if ($vh * 3 < 2) { |
|
78 | - return $v1 + ($v2 - $v1) * ((2 / 3) - $vh) * 6; |
|
77 | + if ($vh*3 < 2) { |
|
78 | + return $v1 + ($v2 - $v1)*((2/3) - $vh)*6; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | return $v1; |
@@ -94,13 +94,13 @@ discard block |
||
94 | 94 | switch ($letter) { |
95 | 95 | case 'M': |
96 | 96 | case 'm': |
97 | - return (int) $size * 1048576; |
|
97 | + return (int) $size*1048576; |
|
98 | 98 | case 'K': |
99 | 99 | case 'k': |
100 | - return (int) $size * 1024; |
|
100 | + return (int) $size*1024; |
|
101 | 101 | case 'G': |
102 | 102 | case 'g': |
103 | - return (int) $size * 1073741824; |
|
103 | + return (int) $size*1073741824; |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | return (int) $size; |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | public static function rgbPercentageToRgbInteger($rgbPercentage) |
115 | 115 | { |
116 | 116 | if (strpos($rgbPercentage, '%') !== false) { |
117 | - $rgbPercentage = self::roundNumber(floatval(str_replace('%', '', $rgbPercentage)) * 2.55); |
|
117 | + $rgbPercentage = self::roundNumber(floatval(str_replace('%', '', $rgbPercentage))*2.55); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | return intval($rgbPercentage, 10); |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | protected $inputLength = 0; |
71 | 71 | protected $lookAhead = null; |
72 | 72 | protected $output = ''; |
73 | - protected $lastByteOut = ''; |
|
73 | + protected $lastByteOut = ''; |
|
74 | 74 | protected $keptComment = ''; |
75 | 75 | |
76 | 76 | /** |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | } |
107 | 107 | |
108 | 108 | $mbIntEnc = null; |
109 | - if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) { |
|
109 | + if (function_exists('mb_strlen') && ((int) ini_get('mbstring.func_overload') & 2)) { |
|
110 | 110 | $mbIntEnc = mb_internal_encoding(); |
111 | 111 | mb_internal_encoding('8bit'); |
112 | 112 | } |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | && ($this->b === $this->lastByteOut)) { |
129 | 129 | // Don't delete this space. If we do, the addition/subtraction |
130 | 130 | // could be parsed as a post-increment |
131 | - } elseif (! $this->isAlphaNum($this->b)) { |
|
131 | + } elseif (!$this->isAlphaNum($this->b)) { |
|
132 | 132 | $command = self::ACTION_DELETE_A; |
133 | 133 | } |
134 | 134 | } elseif ($this->a === "\n") { |
@@ -139,10 +139,10 @@ discard block |
||
139 | 139 | // otherwise mb_strpos will give WARNING |
140 | 140 | } elseif ($this->b === null |
141 | 141 | || (false === strpos('{[(+-!~', $this->b) |
142 | - && ! $this->isAlphaNum($this->b))) { |
|
142 | + && !$this->isAlphaNum($this->b))) { |
|
143 | 143 | $command = self::ACTION_DELETE_A; |
144 | 144 | } |
145 | - } elseif (! $this->isAlphaNum($this->a)) { |
|
145 | + } elseif (!$this->isAlphaNum($this->a)) { |
|
146 | 146 | if ($this->b === ' ' |
147 | 147 | || ($this->b === "\n" |
148 | 148 | && (false === strpos('}])+-"\'', $this->a)))) { |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | $this->a = $this->b; |
199 | 199 | if ($this->a === "'" || $this->a === '"') { // string literal |
200 | 200 | $str = $this->a; // in case needed for exception |
201 | - for(;;) { |
|
201 | + for (;;) { |
|
202 | 202 | $this->output .= $this->a; |
203 | 203 | $this->lastByteOut = $this->a; |
204 | 204 | |
@@ -226,13 +226,13 @@ discard block |
||
226 | 226 | case self::ACTION_DELETE_A_B: // 3 |
227 | 227 | $this->b = $this->next(); |
228 | 228 | if ($this->b === '/' && $this->isRegexpLiteral()) { |
229 | - $this->output .= $this->a . $this->b; |
|
229 | + $this->output .= $this->a.$this->b; |
|
230 | 230 | $pattern = '/'; // keep entire pattern in case we need to report it in the exception |
231 | - for(;;) { |
|
231 | + for (;;) { |
|
232 | 232 | $this->a = $this->get(); |
233 | 233 | $pattern .= $this->a; |
234 | 234 | if ($this->a === '[') { |
235 | - for(;;) { |
|
235 | + for (;;) { |
|
236 | 236 | $this->output .= $this->a; |
237 | 237 | $this->a = $this->get(); |
238 | 238 | $pattern .= $this->a; |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | if ($this->isEOF($this->a)) { |
248 | 248 | throw new JSMin_UnterminatedRegExpException( |
249 | 249 | "JSMin: Unterminated set in RegExp at byte " |
250 | - . $this->inputIndex .": {$pattern}"); |
|
250 | + . $this->inputIndex.": {$pattern}"); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | } |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | |
293 | 293 | // if the "/" follows a keyword, it must be a regexp, otherwise it's best to assume division |
294 | 294 | |
295 | - $subject = $this->output . trim($this->a); |
|
295 | + $subject = $this->output.trim($this->a); |
|
296 | 296 | if (!preg_match('/(?:case|else|in|return|typeof)$/', $subject, $m)) { |
297 | 297 | // not a keyword |
298 | 298 | return false; |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | { |
404 | 404 | $this->get(); |
405 | 405 | $comment = ''; |
406 | - for(;;) { |
|
406 | + for (;;) { |
|
407 | 407 | $get = $this->get(); |
408 | 408 | if ($get === '*') { |
409 | 409 | if ($this->peek() === '/') { // end of comment reached |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | // don't prepend a newline if two comments right after one another |
415 | 415 | $this->keptComment = "\n"; |
416 | 416 | } |
417 | - $this->keptComment .= "/*!" . substr($comment, 1) . "*/\n"; |
|
417 | + $this->keptComment .= "/*!".substr($comment, 1)."*/\n"; |
|
418 | 418 | } else if (preg_match('/^@(?:cc_on|if|elif|else|end)\\b/', $comment)) { |
419 | 419 | // IE conditional |
420 | 420 | $this->keptComment .= "/*{$comment}*/"; |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | { |
71 | 71 | $this->_html = str_replace("\r\n", "\n", trim($html)); |
72 | 72 | if (isset($options['xhtml'])) { |
73 | - $this->_isXhtml = (bool)$options['xhtml']; |
|
73 | + $this->_isXhtml = (bool) $options['xhtml']; |
|
74 | 74 | } |
75 | 75 | if (isset($options['cssMinifier'])) { |
76 | 76 | $this->_cssMinifier = $options['cssMinifier']; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML')); |
96 | 96 | } |
97 | 97 | |
98 | - $this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']); |
|
98 | + $this->_replacementHash = 'MINIFYHTML'.md5($_SERVER['REQUEST_TIME']); |
|
99 | 99 | $this->_placeholders = array(); |
100 | 100 | |
101 | 101 | // replace SCRIPTs (and minify) with placeholders |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | ,$this->_html); |
112 | 112 | |
113 | 113 | // remove HTML comments (not containing IE conditional comments). |
114 | - if ($this->_keepComments == false) { |
|
114 | + if ($this->_keepComments == false) { |
|
115 | 115 | $this->_html = preg_replace_callback( |
116 | 116 | '/<!--([\\s\\S]*?)-->/' |
117 | 117 | ,array($this, '_commentCB') |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | |
174 | 174 | protected function _reservePlace($content) |
175 | 175 | { |
176 | - $placeholder = '%' . $this->_replacementHash . count($this->_placeholders) . '%'; |
|
176 | + $placeholder = '%'.$this->_replacementHash.count($this->_placeholders).'%'; |
|
177 | 177 | $this->_placeholders[$placeholder] = $content; |
178 | 178 | return $placeholder; |
179 | 179 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | |
188 | 188 | protected function _outsideTagCB($m) |
189 | 189 | { |
190 | - return '>' . preg_replace('/^\\s+|\\s+$/', ' ', $m[1]) . '<'; |
|
190 | + return '>'.preg_replace('/^\\s+|\\s+$/', ' ', $m[1]).'<'; |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | protected function _removePreCB($m) |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | protected function _removeCdata($str) |
260 | 260 | { |
261 | 261 | return (false !== strpos($str, '<![CDATA[')) |
262 | - ? str_replace(array('/* <![CDATA[ */','/* ]]> */','/*<![CDATA[*/','/*]]>*/','<![CDATA[', ']]>'), '', $str) |
|
262 | + ? str_replace(array('/* <![CDATA[ */', '/* ]]> */', '/*<![CDATA[*/', '/*]]>*/', '<![CDATA[', ']]>'), '', $str) |
|
263 | 263 | : $str; |
264 | 264 | } |
265 | 265 |
@@ -3,12 +3,12 @@ discard block |
||
3 | 3 | * WP-CLI commands for Autoptimize. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
10 | 10 | // This is a WP-CLI command, so bail if it's not available. |
11 | -if ( ! defined( 'WP_CLI' ) ) { |
|
11 | +if (!defined('WP_CLI')) { |
|
12 | 12 | return; |
13 | 13 | } |
14 | 14 | |
@@ -24,11 +24,11 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @return void |
26 | 26 | */ |
27 | - public function clear( $args, $args_assoc ) { |
|
28 | - WP_CLI::line( esc_html__( 'Flushing the cache...', 'autoptimize' ) ); |
|
27 | + public function clear($args, $args_assoc) { |
|
28 | + WP_CLI::line(esc_html__('Flushing the cache...', 'autoptimize')); |
|
29 | 29 | autoptimizeCache::clearall(); |
30 | - WP_CLI::success( esc_html__( 'Cache flushed.', 'autoptimize' ) ); |
|
30 | + WP_CLI::success(esc_html__('Cache flushed.', 'autoptimize')); |
|
31 | 31 | } |
32 | 32 | } |
33 | 33 | |
34 | -WP_CLI::add_command( 'autoptimize', 'autoptimizeCLI' ); |
|
34 | +WP_CLI::add_command('autoptimize', 'autoptimizeCLI'); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * addons and/or affiliate services. |
5 | 5 | */ |
6 | 6 | |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if (!defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -17,64 +17,64 @@ discard block |
||
17 | 17 | |
18 | 18 | public function run() |
19 | 19 | { |
20 | - if ( $this->enabled() ) { |
|
21 | - add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_partner_tabs' ), 10, 1 ); |
|
20 | + if ($this->enabled()) { |
|
21 | + add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_partner_tabs'), 10, 1); |
|
22 | 22 | } |
23 | - add_action( 'admin_menu', array( $this, 'add_admin_menu' ) ); |
|
23 | + add_action('admin_menu', array($this, 'add_admin_menu')); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | protected function enabled() |
27 | 27 | { |
28 | - return apply_filters( 'autoptimize_filter_show_partner_tabs', true ); |
|
28 | + return apply_filters('autoptimize_filter_show_partner_tabs', true); |
|
29 | 29 | } |
30 | 30 | |
31 | - public function add_partner_tabs( $in ) |
|
31 | + public function add_partner_tabs($in) |
|
32 | 32 | { |
33 | - $in = array_merge( $in, array( |
|
34 | - 'ao_partners' => __( 'Optimize More!', 'autoptimize' ), |
|
35 | - ) ); |
|
33 | + $in = array_merge($in, array( |
|
34 | + 'ao_partners' => __('Optimize More!', 'autoptimize'), |
|
35 | + )); |
|
36 | 36 | |
37 | 37 | return $in; |
38 | 38 | } |
39 | 39 | |
40 | 40 | public function add_admin_menu() |
41 | 41 | { |
42 | - if ( $this->enabled() ) { |
|
43 | - add_submenu_page( null, 'AO partner', 'AO partner', 'manage_options', 'ao_partners', array( $this, 'ao_partners_page' ) ); |
|
42 | + if ($this->enabled()) { |
|
43 | + add_submenu_page(null, 'AO partner', 'AO partner', 'manage_options', 'ao_partners', array($this, 'ao_partners_page')); |
|
44 | 44 | } |
45 | 45 | } |
46 | 46 | |
47 | 47 | protected function get_ao_partner_feed_markup() |
48 | 48 | { |
49 | - $no_feed_text = __( 'Have a look at <a href="http://optimizingmatters.com/">optimizingmatters.com</a> for Autoptimize power-ups!', 'autoptimize' ); |
|
49 | + $no_feed_text = __('Have a look at <a href="http://optimizingmatters.com/">optimizingmatters.com</a> for Autoptimize power-ups!', 'autoptimize'); |
|
50 | 50 | $output = ''; |
51 | - if ( apply_filters( 'autoptimize_settingsscreen_remotehttp', true ) ) { |
|
52 | - $rss = fetch_feed( 'http://feeds.feedburner.com/OptimizingMattersDownloads' ); |
|
51 | + if (apply_filters('autoptimize_settingsscreen_remotehttp', true)) { |
|
52 | + $rss = fetch_feed('http://feeds.feedburner.com/OptimizingMattersDownloads'); |
|
53 | 53 | $maxitems = 0; |
54 | 54 | |
55 | - if ( ! is_wp_error( $rss ) ) { |
|
56 | - $maxitems = $rss->get_item_quantity( 20 ); |
|
57 | - $rss_items = $rss->get_items( 0, $maxitems ); |
|
55 | + if (!is_wp_error($rss)) { |
|
56 | + $maxitems = $rss->get_item_quantity(20); |
|
57 | + $rss_items = $rss->get_items(0, $maxitems); |
|
58 | 58 | } |
59 | 59 | |
60 | - if ( 0 == $maxitems ) { |
|
60 | + if (0 == $maxitems) { |
|
61 | 61 | $output .= $no_feed_text; |
62 | 62 | } else { |
63 | 63 | $output .= '<ul>'; |
64 | - foreach ( $rss_items as $item ) { |
|
65 | - $item_url = esc_url( $item->get_permalink() ); |
|
64 | + foreach ($rss_items as $item) { |
|
65 | + $item_url = esc_url($item->get_permalink()); |
|
66 | 66 | $enclosure = $item->get_enclosure(); |
67 | 67 | |
68 | 68 | $output .= '<li class="itemDetail">'; |
69 | - $output .= '<h3 class="itemTitle"><a href="' . $item_url . '" target="_blank">' . esc_html( $item->get_title() ) . '</a></h3>'; |
|
69 | + $output .= '<h3 class="itemTitle"><a href="'.$item_url.'" target="_blank">'.esc_html($item->get_title()).'</a></h3>'; |
|
70 | 70 | |
71 | - if ( $enclosure && ( false !== strpos( $enclosure->get_type(), 'image' ) ) ) { |
|
72 | - $img_url = esc_url( $enclosure->get_link() ); |
|
73 | - $output .= '<div class="itemImage"><a href="' . $item_url . '" target="_blank"><img src="' . $img_url . '"></a></div>'; |
|
71 | + if ($enclosure && (false !== strpos($enclosure->get_type(), 'image'))) { |
|
72 | + $img_url = esc_url($enclosure->get_link()); |
|
73 | + $output .= '<div class="itemImage"><a href="'.$item_url.'" target="_blank"><img src="'.$img_url.'"></a></div>'; |
|
74 | 74 | } |
75 | 75 | |
76 | - $output .= '<div class="itemDescription">' . wp_kses_post( $item->get_description() ) . '</div>'; |
|
77 | - $output .= '<div class="itemButtonRow"><div class="itemButton button-secondary"><a href="' . $item_url . '" target="_blank">' . __( 'More info', 'autoptimize' ) . '</a></div></div>'; |
|
76 | + $output .= '<div class="itemDescription">'.wp_kses_post($item->get_description()).'</div>'; |
|
77 | + $output .= '<div class="itemButtonRow"><div class="itemButton button-secondary"><a href="'.$item_url.'" target="_blank">'.__('More info', 'autoptimize').'</a></div></div>'; |
|
78 | 78 | $output .= '</li>'; |
79 | 79 | } |
80 | 80 | $output .= '</ul>'; |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | } |
134 | 134 | </style> |
135 | 135 | <div class="wrap"> |
136 | - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> |
|
136 | + <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
137 | 137 | <?php echo autoptimizeConfig::ao_admin_tabs(); ?> |
138 | - <?php echo '<h2>' . __( "These Autoptimize power-ups and related services will improve your site's performance even more!", 'autoptimize' ) . '</h2>'; ?> |
|
138 | + <?php echo '<h2>'.__("These Autoptimize power-ups and related services will improve your site's performance even more!", 'autoptimize').'</h2>'; ?> |
|
139 | 139 | <div> |
140 | 140 | <?php echo $this->get_ao_partner_feed_markup(); ?> |
141 | 141 | </div> |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Thin wrapper around css minifiers to avoid rewriting a bunch of existing code. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param bool $raise_limits Whether to raise memory limits or not. Default true. |
23 | 23 | */ |
24 | - public function __construct( $raise_limits = true ) |
|
24 | + public function __construct($raise_limits = true) |
|
25 | 25 | { |
26 | - $this->minifier = new Autoptimize\tubalmartin\CssMin\Minifier( $raise_limits ); |
|
26 | + $this->minifier = new Autoptimize\tubalmartin\CssMin\Minifier($raise_limits); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -34,9 +34,9 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @return string |
36 | 36 | */ |
37 | - public function run( $css ) |
|
37 | + public function run($css) |
|
38 | 38 | { |
39 | - $result = $this->minifier->run( $css ); |
|
39 | + $result = $this->minifier->run($css); |
|
40 | 40 | |
41 | 41 | return $result; |
42 | 42 | } |
@@ -48,10 +48,10 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return string |
50 | 50 | */ |
51 | - public static function minify( $css ) |
|
51 | + public static function minify($css) |
|
52 | 52 | { |
53 | 53 | $minifier = new self(); |
54 | 54 | |
55 | - return $minifier->run( $css ); |
|
55 | + return $minifier->run($css); |
|
56 | 56 | } |
57 | 57 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Handles version updates and should only be instantiated in autoptimize.php if/when needed. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -16,9 +16,9 @@ discard block |
||
16 | 16 | */ |
17 | 17 | protected $current_major_version = null; |
18 | 18 | |
19 | - public function __construct( $current_version ) |
|
19 | + public function __construct($current_version) |
|
20 | 20 | { |
21 | - $this->current_major_version = substr( $current_version, 0, 3 ); |
|
21 | + $this->current_major_version = substr($current_version, 0, 3); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | { |
30 | 30 | $major_update = false; |
31 | 31 | |
32 | - switch ( $this->current_major_version ) { |
|
32 | + switch ($this->current_major_version) { |
|
33 | 33 | case '1.6': |
34 | 34 | $this->upgrade_from_1_6(); |
35 | 35 | $major_update = true; |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | // No break, intentionally, so all upgrades are ran during a single request... |
49 | 49 | } |
50 | 50 | |
51 | - if ( true === $major_update ) { |
|
51 | + if (true === $major_update) { |
|
52 | 52 | $this->on_major_version_update(); |
53 | 53 | } |
54 | 54 | } |
@@ -60,19 +60,19 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @param string $target Target version to check against (ie., the currently running one). |
62 | 62 | */ |
63 | - public static function check_installed_and_update( $target ) |
|
63 | + public static function check_installed_and_update($target) |
|
64 | 64 | { |
65 | - $db_version = get_option( 'autoptimize_version', 'none' ); |
|
66 | - if ( $db_version !== $target ) { |
|
67 | - if ( 'none' === $db_version ) { |
|
68 | - add_action( 'admin_notices', 'autoptimizeMain::notice_installed' ); |
|
65 | + $db_version = get_option('autoptimize_version', 'none'); |
|
66 | + if ($db_version !== $target) { |
|
67 | + if ('none' === $db_version) { |
|
68 | + add_action('admin_notices', 'autoptimizeMain::notice_installed'); |
|
69 | 69 | } else { |
70 | - $updater = new self( $db_version ); |
|
70 | + $updater = new self($db_version); |
|
71 | 71 | $updater->run_needed_major_upgrades(); |
72 | 72 | } |
73 | 73 | |
74 | 74 | // Versions differed, upgrades happened if needed, store the new version. |
75 | - update_option( 'autoptimize_version', $target ); |
|
75 | + update_option('autoptimize_version', $target); |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | |
@@ -83,10 +83,10 @@ discard block |
||
83 | 83 | protected function on_major_version_update() |
84 | 84 | { |
85 | 85 | // The transients guard here prevents stale object caches from busting the cache on every request. |
86 | - if ( false == get_transient( 'autoptimize_stale_option_buster' ) ) { |
|
87 | - set_transient( 'autoptimize_stale_option_buster', 'Mamsie & Liessie zehhe: ZWIJH!', HOUR_IN_SECONDS ); |
|
86 | + if (false == get_transient('autoptimize_stale_option_buster')) { |
|
87 | + set_transient('autoptimize_stale_option_buster', 'Mamsie & Liessie zehhe: ZWIJH!', HOUR_IN_SECONDS); |
|
88 | 88 | autoptimizeCache::clearall(); |
89 | - add_action( 'admin_notices', 'autoptimizeMain::notice_updated' ); |
|
89 | + add_action('admin_notices', 'autoptimizeMain::notice_updated'); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | private function upgrade_from_1_6() |
97 | 97 | { |
98 | 98 | // If user was on version 1.6.x, force advanced options to be shown by default. |
99 | - update_option( 'autoptimize_show_adv', '1' ); |
|
99 | + update_option('autoptimize_show_adv', '1'); |
|
100 | 100 | |
101 | 101 | // And remove old options. |
102 | 102 | $to_delete_options = array( |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | 'autoptimize_cdn_img_url', |
109 | 109 | 'autoptimize_css_yui', |
110 | 110 | ); |
111 | - foreach ( $to_delete_options as $del_opt ) { |
|
112 | - delete_option( $del_opt ); |
|
111 | + foreach ($to_delete_options as $del_opt) { |
|
112 | + delete_option($del_opt); |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
@@ -120,29 +120,29 @@ discard block |
||
120 | 120 | */ |
121 | 121 | private function upgrade_from_1_7() |
122 | 122 | { |
123 | - if ( ! is_multisite() ) { |
|
124 | - $css_exclude = get_option( 'autoptimize_css_exclude' ); |
|
125 | - if ( empty( $css_exclude ) ) { |
|
123 | + if (!is_multisite()) { |
|
124 | + $css_exclude = get_option('autoptimize_css_exclude'); |
|
125 | + if (empty($css_exclude)) { |
|
126 | 126 | $css_exclude = 'admin-bar.min.css, dashicons.min.css'; |
127 | - } elseif ( false === strpos( $css_exclude, 'dashicons.min.css' ) ) { |
|
127 | + } elseif (false === strpos($css_exclude, 'dashicons.min.css')) { |
|
128 | 128 | $css_exclude .= ', dashicons.min.css'; |
129 | 129 | } |
130 | - update_option( 'autoptimize_css_exclude', $css_exclude ); |
|
130 | + update_option('autoptimize_css_exclude', $css_exclude); |
|
131 | 131 | } else { |
132 | 132 | global $wpdb; |
133 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
|
133 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); |
|
134 | 134 | $original_blog_id = get_current_blog_id(); |
135 | - foreach ( $blog_ids as $blog_id ) { |
|
136 | - switch_to_blog( $blog_id ); |
|
137 | - $css_exclude = get_option( 'autoptimize_css_exclude' ); |
|
138 | - if ( empty( $css_exclude ) ) { |
|
135 | + foreach ($blog_ids as $blog_id) { |
|
136 | + switch_to_blog($blog_id); |
|
137 | + $css_exclude = get_option('autoptimize_css_exclude'); |
|
138 | + if (empty($css_exclude)) { |
|
139 | 139 | $css_exclude = 'admin-bar.min.css, dashicons.min.css'; |
140 | - } elseif ( false === strpos( $css_exclude, 'dashicons.min.css' ) ) { |
|
140 | + } elseif (false === strpos($css_exclude, 'dashicons.min.css')) { |
|
141 | 141 | $css_exclude .= ', dashicons.min.css'; |
142 | 142 | } |
143 | - update_option( 'autoptimize_css_exclude', $css_exclude ); |
|
143 | + update_option('autoptimize_css_exclude', $css_exclude); |
|
144 | 144 | } |
145 | - switch_to_blog( $original_blog_id ); |
|
145 | + switch_to_blog($original_blog_id); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
@@ -154,19 +154,19 @@ discard block |
||
154 | 154 | */ |
155 | 155 | private function upgrade_from_1_9() |
156 | 156 | { |
157 | - if ( ! is_multisite() ) { |
|
158 | - update_option( 'autoptimize_css_include_inline', 'on' ); |
|
159 | - update_option( 'autoptimize_js_include_inline', 'on' ); |
|
157 | + if (!is_multisite()) { |
|
158 | + update_option('autoptimize_css_include_inline', 'on'); |
|
159 | + update_option('autoptimize_js_include_inline', 'on'); |
|
160 | 160 | } else { |
161 | 161 | global $wpdb; |
162 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
|
162 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); |
|
163 | 163 | $original_blog_id = get_current_blog_id(); |
164 | - foreach ( $blog_ids as $blog_id ) { |
|
165 | - switch_to_blog( $blog_id ); |
|
166 | - update_option( 'autoptimize_css_include_inline', 'on' ); |
|
167 | - update_option( 'autoptimize_js_include_inline', 'on' ); |
|
164 | + foreach ($blog_ids as $blog_id) { |
|
165 | + switch_to_blog($blog_id); |
|
166 | + update_option('autoptimize_css_include_inline', 'on'); |
|
167 | + update_option('autoptimize_js_include_inline', 'on'); |
|
168 | 168 | } |
169 | - switch_to_blog( $original_blog_id ); |
|
169 | + switch_to_blog($original_blog_id); |
|
170 | 170 | } |
171 | 171 | } |
172 | 172 | |
@@ -177,17 +177,17 @@ discard block |
||
177 | 177 | */ |
178 | 178 | private function upgrade_from_2_2() |
179 | 179 | { |
180 | - if ( ! is_multisite() ) { |
|
180 | + if (!is_multisite()) { |
|
181 | 181 | $this->do_2_2_settings_update(); |
182 | 182 | } else { |
183 | 183 | global $wpdb; |
184 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
|
184 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); |
|
185 | 185 | $original_blog_id = get_current_blog_id(); |
186 | - foreach ( $blog_ids as $blog_id ) { |
|
187 | - switch_to_blog( $blog_id ); |
|
186 | + foreach ($blog_ids as $blog_id) { |
|
187 | + switch_to_blog($blog_id); |
|
188 | 188 | $this->do_2_2_settings_update(); |
189 | 189 | } |
190 | - switch_to_blog( $original_blog_id ); |
|
190 | + switch_to_blog($original_blog_id); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | */ |
197 | 197 | private function do_2_2_settings_update() |
198 | 198 | { |
199 | - $nogooglefont = get_option( 'autoptimize_css_nogooglefont', '' ); |
|
200 | - $ao_extrasetting = get_option( 'autoptimize_extra_settings', '' ); |
|
201 | - if ( ( $nogooglefont ) && ( empty( $ao_extrasetting ) ) ) { |
|
202 | - update_option( 'autoptimize_extra_settings', autoptimizeConfig::get_ao_extra_default_options() ); |
|
199 | + $nogooglefont = get_option('autoptimize_css_nogooglefont', ''); |
|
200 | + $ao_extrasetting = get_option('autoptimize_extra_settings', ''); |
|
201 | + if (($nogooglefont) && (empty($ao_extrasetting))) { |
|
202 | + update_option('autoptimize_extra_settings', autoptimizeConfig::get_ao_extra_default_options()); |
|
203 | 203 | } |
204 | - delete_option( 'autoptimize_css_nogooglefont' ); |
|
204 | + delete_option('autoptimize_css_nogooglefont'); |
|
205 | 205 | } |
206 | 206 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * new in Autoptimize 2.2 |
5 | 5 | */ |
6 | 6 | |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if (!defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -17,94 +17,94 @@ discard block |
||
17 | 17 | |
18 | 18 | public function add_hooks() |
19 | 19 | { |
20 | - if ( apply_filters( 'autoptimize_js_do_minify', true ) ) { |
|
21 | - add_filter( 'autoptimize_js_individual_script', array( $this, 'js_snippetcacher' ), 10, 2 ); |
|
22 | - add_filter( 'autoptimize_js_after_minify', array( $this, 'js_cleanup' ), 10, 1 ); |
|
20 | + if (apply_filters('autoptimize_js_do_minify', true)) { |
|
21 | + add_filter('autoptimize_js_individual_script', array($this, 'js_snippetcacher'), 10, 2); |
|
22 | + add_filter('autoptimize_js_after_minify', array($this, 'js_cleanup'), 10, 1); |
|
23 | 23 | } |
24 | - if ( apply_filters( 'autoptimize_css_do_minify', true ) ) { |
|
25 | - add_filter( 'autoptimize_css_individual_style', array( $this, 'css_snippetcacher' ), 10, 2 ); |
|
26 | - add_filter( 'autoptimize_css_after_minify', array( $this, 'css_cleanup' ), 10, 1 ); |
|
24 | + if (apply_filters('autoptimize_css_do_minify', true)) { |
|
25 | + add_filter('autoptimize_css_individual_style', array($this, 'css_snippetcacher'), 10, 2); |
|
26 | + add_filter('autoptimize_css_after_minify', array($this, 'css_cleanup'), 10, 1); |
|
27 | 27 | } |
28 | 28 | } |
29 | 29 | |
30 | - public function js_snippetcacher( $jsin, $jsfilename ) |
|
30 | + public function js_snippetcacher($jsin, $jsfilename) |
|
31 | 31 | { |
32 | - $md5hash = 'snippet_' . md5( $jsin ); |
|
33 | - $ccheck = new autoptimizeCache( $md5hash, 'js' ); |
|
34 | - if ( $ccheck->check() ) { |
|
32 | + $md5hash = 'snippet_'.md5($jsin); |
|
33 | + $ccheck = new autoptimizeCache($md5hash, 'js'); |
|
34 | + if ($ccheck->check()) { |
|
35 | 35 | $scriptsrc = $ccheck->retrieve(); |
36 | 36 | } else { |
37 | - if ( false === ( strpos( $jsfilename, 'min.js' ) ) && ( false === strpos( $jsfilename, 'js/jquery/jquery.js' ) ) && ( str_replace( apply_filters( 'autoptimize_filter_js_consider_minified', false ), '', $jsfilename ) === $jsfilename ) ) { |
|
38 | - $tmp_jscode = trim( JSMin::minify( $jsin ) ); |
|
39 | - if ( ! empty( $tmp_jscode ) ) { |
|
37 | + if (false === (strpos($jsfilename, 'min.js')) && (false === strpos($jsfilename, 'js/jquery/jquery.js')) && (str_replace(apply_filters('autoptimize_filter_js_consider_minified', false), '', $jsfilename) === $jsfilename)) { |
|
38 | + $tmp_jscode = trim(JSMin::minify($jsin)); |
|
39 | + if (!empty($tmp_jscode)) { |
|
40 | 40 | $scriptsrc = $tmp_jscode; |
41 | - unset( $tmp_jscode ); |
|
41 | + unset($tmp_jscode); |
|
42 | 42 | } else { |
43 | 43 | $scriptsrc = $jsin; |
44 | 44 | } |
45 | 45 | } else { |
46 | 46 | // Removing comments, linebreaks and stuff! |
47 | - $scriptsrc = preg_replace( '#^\s*\/\/.*$#Um', '', $jsin ); |
|
48 | - $scriptsrc = preg_replace( '#^\s*\/\*[^!].*\*\/\s?#Us', '', $scriptsrc ); |
|
49 | - $scriptsrc = preg_replace( "#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $scriptsrc ); |
|
47 | + $scriptsrc = preg_replace('#^\s*\/\/.*$#Um', '', $jsin); |
|
48 | + $scriptsrc = preg_replace('#^\s*\/\*[^!].*\*\/\s?#Us', '', $scriptsrc); |
|
49 | + $scriptsrc = preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $scriptsrc); |
|
50 | 50 | } |
51 | 51 | |
52 | - $last_char = substr( $scriptsrc, -1, 1 ); |
|
53 | - if ( ';' !== $last_char && '}' !== $last_char ) { |
|
52 | + $last_char = substr($scriptsrc, -1, 1); |
|
53 | + if (';' !== $last_char && '}' !== $last_char) { |
|
54 | 54 | $scriptsrc .= ';'; |
55 | 55 | } |
56 | 56 | |
57 | - if ( ! empty( $jsfilename ) && str_replace( apply_filters( 'autoptimize_filter_js_speedup_cache', false ), '', $jsfilename ) === $jsfilename ) { |
|
57 | + if (!empty($jsfilename) && str_replace(apply_filters('autoptimize_filter_js_speedup_cache', false), '', $jsfilename) === $jsfilename) { |
|
58 | 58 | // Don't cache inline CSS or if filter says no! |
59 | - $ccheck->cache( $scriptsrc, 'text/javascript' ); |
|
59 | + $ccheck->cache($scriptsrc, 'text/javascript'); |
|
60 | 60 | } |
61 | 61 | } |
62 | - unset( $ccheck ); |
|
62 | + unset($ccheck); |
|
63 | 63 | |
64 | 64 | return $scriptsrc; |
65 | 65 | } |
66 | 66 | |
67 | - public function css_snippetcacher( $cssin, $cssfilename ) |
|
67 | + public function css_snippetcacher($cssin, $cssfilename) |
|
68 | 68 | { |
69 | - $md5hash = 'snippet_' . md5( $cssin ); |
|
70 | - $ccheck = new autoptimizeCache( $md5hash, 'css' ); |
|
71 | - if ( $ccheck->check() ) { |
|
69 | + $md5hash = 'snippet_'.md5($cssin); |
|
70 | + $ccheck = new autoptimizeCache($md5hash, 'css'); |
|
71 | + if ($ccheck->check()) { |
|
72 | 72 | $stylesrc = $ccheck->retrieve(); |
73 | 73 | } else { |
74 | - if ( ( false === strpos( $cssfilename, 'min.css' ) ) && ( str_replace( apply_filters( 'autoptimize_filter_css_consider_minified', false ), '', $cssfilename ) === $cssfilename ) ) { |
|
74 | + if ((false === strpos($cssfilename, 'min.css')) && (str_replace(apply_filters('autoptimize_filter_css_consider_minified', false), '', $cssfilename) === $cssfilename)) { |
|
75 | 75 | $cssmin = new autoptimizeCSSmin(); |
76 | - $tmp_code = trim( $cssmin->run( $cssin ) ); |
|
76 | + $tmp_code = trim($cssmin->run($cssin)); |
|
77 | 77 | |
78 | - if ( ! empty( $tmp_code ) ) { |
|
78 | + if (!empty($tmp_code)) { |
|
79 | 79 | $stylesrc = $tmp_code; |
80 | - unset( $tmp_code ); |
|
80 | + unset($tmp_code); |
|
81 | 81 | } else { |
82 | 82 | $stylesrc = $cssin; |
83 | 83 | } |
84 | 84 | } else { |
85 | 85 | // .min.css -> no heavy-lifting, just some cleanup! |
86 | - $stylesrc = preg_replace( '#^\s*\/\*[^!].*\*\/\s?#Us', '', $cssin ); |
|
87 | - $stylesrc = preg_replace( "#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $stylesrc ); |
|
88 | - $stylesrc = autoptimizeStyles::fixurls( $cssfilename, $stylesrc ); |
|
86 | + $stylesrc = preg_replace('#^\s*\/\*[^!].*\*\/\s?#Us', '', $cssin); |
|
87 | + $stylesrc = preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $stylesrc); |
|
88 | + $stylesrc = autoptimizeStyles::fixurls($cssfilename, $stylesrc); |
|
89 | 89 | } |
90 | - if ( ! empty( $cssfilename ) && ( str_replace( apply_filters( 'autoptimize_filter_css_speedup_cache', false ), '', $cssfilename ) === $cssfilename ) ) { |
|
90 | + if (!empty($cssfilename) && (str_replace(apply_filters('autoptimize_filter_css_speedup_cache', false), '', $cssfilename) === $cssfilename)) { |
|
91 | 91 | // Only caching CSS if it's not inline and is allowed by filter! |
92 | - $ccheck->cache( $stylesrc, 'text/css' ); |
|
92 | + $ccheck->cache($stylesrc, 'text/css'); |
|
93 | 93 | } |
94 | 94 | } |
95 | - unset( $ccheck ); |
|
95 | + unset($ccheck); |
|
96 | 96 | |
97 | 97 | return $stylesrc; |
98 | 98 | } |
99 | 99 | |
100 | - public function css_cleanup( $cssin ) |
|
100 | + public function css_cleanup($cssin) |
|
101 | 101 | { |
102 | 102 | // Speedupper results in aggregated CSS not being minified, so the filestart-marker AO adds when aggregating needs to be removed. |
103 | - return trim( str_replace( array( '/*FILESTART*/', '/*FILESTART2*/' ), '', $cssin ) ); |
|
103 | + return trim(str_replace(array('/*FILESTART*/', '/*FILESTART2*/'), '', $cssin)); |
|
104 | 104 | } |
105 | 105 | |
106 | - public function js_cleanup( $jsin ) |
|
106 | + public function js_cleanup($jsin) |
|
107 | 107 | { |
108 | - return trim( $jsin ); |
|
108 | + return trim($jsin); |
|
109 | 109 | } |
110 | 110 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Handles toolbar-related stuff. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -12,32 +12,32 @@ discard block |
||
12 | 12 | public function __construct() |
13 | 13 | { |
14 | 14 | // If Cache is not available we don't add the toolbar. |
15 | - if ( ! autoptimizeCache::cacheavail() ) { |
|
15 | + if (!autoptimizeCache::cacheavail()) { |
|
16 | 16 | return; |
17 | 17 | } |
18 | 18 | |
19 | 19 | // Load admin toolbar feature once WordPress, all plugins, and the theme are fully loaded and instantiated. |
20 | - add_action( 'wp_loaded', array( $this, 'load_toolbar' ) ); |
|
20 | + add_action('wp_loaded', array($this, 'load_toolbar')); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | public function load_toolbar() |
24 | 24 | { |
25 | 25 | // Check permissions and that toolbar is not hidden via filter. |
26 | - if ( current_user_can( 'manage_options' ) && apply_filters( 'autoptimize_filter_toolbar_show', true ) ) { |
|
26 | + if (current_user_can('manage_options') && apply_filters('autoptimize_filter_toolbar_show', true)) { |
|
27 | 27 | |
28 | 28 | // Create a handler for the AJAX toolbar requests. |
29 | - add_action( 'wp_ajax_autoptimize_delete_cache', array( $this, 'delete_cache' ) ); |
|
29 | + add_action('wp_ajax_autoptimize_delete_cache', array($this, 'delete_cache')); |
|
30 | 30 | |
31 | 31 | // Load custom styles, scripts and menu only when needed. |
32 | - if ( is_admin_bar_showing() ) { |
|
33 | - if ( is_admin() ) { |
|
34 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
|
32 | + if (is_admin_bar_showing()) { |
|
33 | + if (is_admin()) { |
|
34 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts')); |
|
35 | 35 | } else { |
36 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
|
36 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts')); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | // Add the Autoptimize Toolbar to the Admin bar. |
40 | - add_action( 'admin_bar_menu', array( $this, 'add_toolbar' ), 100 ); |
|
40 | + add_action('admin_bar_menu', array($this, 'add_toolbar'), 100); |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | } |
@@ -50,17 +50,17 @@ discard block |
||
50 | 50 | $stats = autoptimizeCache::stats(); |
51 | 51 | |
52 | 52 | // Set the Max Size recommended for cache files. |
53 | - $max_size = apply_filters( 'autoptimize_filter_cachecheck_maxsize', 512 * 1024 * 1024 ); |
|
53 | + $max_size = apply_filters('autoptimize_filter_cachecheck_maxsize', 512*1024*1024); |
|
54 | 54 | |
55 | 55 | // Retrieve the current Total Files in cache. |
56 | 56 | $files = $stats[0]; |
57 | 57 | // Retrieve the current Total Size of the cache. |
58 | 58 | $bytes = $stats[1]; |
59 | - $size = $this->format_filesize( $bytes ); |
|
59 | + $size = $this->format_filesize($bytes); |
|
60 | 60 | |
61 | 61 | // Calculate the percentage of cache used. |
62 | - $percentage = ceil( $bytes / $max_size * 100 ); |
|
63 | - if ( $percentage > 100 ) { |
|
62 | + $percentage = ceil($bytes/$max_size*100); |
|
63 | + if ($percentage > 100) { |
|
64 | 64 | $percentage = 100; |
65 | 65 | } |
66 | 66 | |
@@ -70,81 +70,81 @@ discard block |
||
70 | 70 | * - "orange" if over 80%. |
71 | 71 | * - "red" if over 100%. |
72 | 72 | */ |
73 | - $color = ( 100 == $percentage ) ? 'red' : ( ( $percentage > 80 ) ? 'orange' : 'green' ); |
|
73 | + $color = (100 == $percentage) ? 'red' : (($percentage > 80) ? 'orange' : 'green'); |
|
74 | 74 | |
75 | 75 | // Create or add new items into the Admin Toolbar. |
76 | 76 | // Main "Autoptimize" node. |
77 | - $wp_admin_bar->add_node( array( |
|
77 | + $wp_admin_bar->add_node(array( |
|
78 | 78 | 'id' => 'autoptimize', |
79 | - 'title' => '<span class="ab-icon"></span><span class="ab-label">' . __( 'Autoptimize', 'autoptimize' ) . '</span>', |
|
80 | - 'href' => admin_url( 'options-general.php?page=autoptimize' ), |
|
81 | - 'meta' => array( 'class' => 'bullet-' . $color ), |
|
79 | + 'title' => '<span class="ab-icon"></span><span class="ab-label">'.__('Autoptimize', 'autoptimize').'</span>', |
|
80 | + 'href' => admin_url('options-general.php?page=autoptimize'), |
|
81 | + 'meta' => array('class' => 'bullet-'.$color), |
|
82 | 82 | )); |
83 | 83 | |
84 | 84 | // "Cache Info" node. |
85 | - $wp_admin_bar->add_node( array( |
|
85 | + $wp_admin_bar->add_node(array( |
|
86 | 86 | 'id' => 'autoptimize-cache-info', |
87 | - 'title' => '<p>' . __( 'Cache Info', 'autoptimize' ) . '</p>' . |
|
88 | - '<div class="autoptimize-radial-bar" percentage="' . $percentage . '">' . |
|
89 | - '<div class="autoptimize-circle">' . |
|
90 | - '<div class="mask full"><div class="fill bg-' . $color . '"></div></div>' . |
|
91 | - '<div class="mask half"><div class="fill bg-' . $color . '"></div></div>' . |
|
92 | - '<div class="shadow"></div>' . |
|
93 | - '</div>' . |
|
94 | - '<div class="inset"><div class="percentage"><div class="numbers ' . $color . '">' . $percentage . '%</div></div></div>' . |
|
95 | - '</div>' . |
|
96 | - '<table>' . |
|
97 | - '<tr><td>' . __( 'Size', 'autoptimize' ) . ':</td><td class="size ' . $color . '">' . $size . '</td></tr>' . |
|
98 | - '<tr><td>' . __( 'Files', 'autoptimize' ) . ':</td><td class="files white">' . $files . '</td></tr>' . |
|
87 | + 'title' => '<p>'.__('Cache Info', 'autoptimize').'</p>'. |
|
88 | + '<div class="autoptimize-radial-bar" percentage="'.$percentage.'">'. |
|
89 | + '<div class="autoptimize-circle">'. |
|
90 | + '<div class="mask full"><div class="fill bg-'.$color.'"></div></div>'. |
|
91 | + '<div class="mask half"><div class="fill bg-'.$color.'"></div></div>'. |
|
92 | + '<div class="shadow"></div>'. |
|
93 | + '</div>'. |
|
94 | + '<div class="inset"><div class="percentage"><div class="numbers '.$color.'">'.$percentage.'%</div></div></div>'. |
|
95 | + '</div>'. |
|
96 | + '<table>'. |
|
97 | + '<tr><td>'.__('Size', 'autoptimize').':</td><td class="size '.$color.'">'.$size.'</td></tr>'. |
|
98 | + '<tr><td>'.__('Files', 'autoptimize').':</td><td class="files white">'.$files.'</td></tr>'. |
|
99 | 99 | '</table>', |
100 | 100 | 'parent' => 'autoptimize', |
101 | 101 | )); |
102 | 102 | |
103 | 103 | // "Delete Cache" node. |
104 | - $wp_admin_bar->add_node( array( |
|
104 | + $wp_admin_bar->add_node(array( |
|
105 | 105 | 'id' => 'autoptimize-delete-cache', |
106 | - 'title' => __( 'Delete Cache', 'autoptimize' ), |
|
106 | + 'title' => __('Delete Cache', 'autoptimize'), |
|
107 | 107 | 'parent' => 'autoptimize', |
108 | 108 | )); |
109 | 109 | } |
110 | 110 | |
111 | 111 | public function delete_cache() |
112 | 112 | { |
113 | - check_ajax_referer( 'ao_delcache_nonce', 'nonce' ); |
|
113 | + check_ajax_referer('ao_delcache_nonce', 'nonce'); |
|
114 | 114 | |
115 | 115 | $result = false; |
116 | - if ( current_user_can( 'manage_options' ) ) { |
|
116 | + if (current_user_can('manage_options')) { |
|
117 | 117 | // We call the function for cleaning the Autoptimize cache. |
118 | 118 | $result = autoptimizeCache::clearall(); |
119 | 119 | } |
120 | 120 | |
121 | - wp_send_json( $result ); |
|
121 | + wp_send_json($result); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | public function enqueue_scripts() |
125 | 125 | { |
126 | 126 | // Autoptimize Toolbar Styles. |
127 | - wp_enqueue_style( 'autoptimize-toolbar', plugins_url( '/static/toolbar.css', __FILE__ ), array(), AUTOPTIMIZE_PLUGIN_VERSION, 'all' ); |
|
127 | + wp_enqueue_style('autoptimize-toolbar', plugins_url('/static/toolbar.css', __FILE__), array(), AUTOPTIMIZE_PLUGIN_VERSION, 'all'); |
|
128 | 128 | |
129 | 129 | // Autoptimize Toolbar Javascript. |
130 | - wp_enqueue_script( 'autoptimize-toolbar', plugins_url( '/static/toolbar.js', __FILE__ ), array( 'jquery' ), AUTOPTIMIZE_PLUGIN_VERSION, true ); |
|
130 | + wp_enqueue_script('autoptimize-toolbar', plugins_url('/static/toolbar.js', __FILE__), array('jquery'), AUTOPTIMIZE_PLUGIN_VERSION, true); |
|
131 | 131 | |
132 | 132 | // Localizes a registered script with data for a JavaScript variable. |
133 | 133 | // Needed for the AJAX to work properly on the frontend. |
134 | - wp_localize_script( 'autoptimize-toolbar', 'autoptimize_ajax_object', array( |
|
135 | - 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
136 | - 'error_msg' => sprintf( __( 'Your Autoptimize cache might not have been purged successfully, please check on the <a href=%s>Autoptimize settings page</a>.', 'autoptimize' ), admin_url( 'options-general.php?page=autoptimize' ) . ' style="white-space:nowrap;"' ), |
|
137 | - 'dismiss_msg' => __( 'Dismiss this notice.' ), |
|
138 | - 'nonce' => wp_create_nonce( 'ao_delcache_nonce' ), |
|
139 | - ) ); |
|
134 | + wp_localize_script('autoptimize-toolbar', 'autoptimize_ajax_object', array( |
|
135 | + 'ajaxurl' => admin_url('admin-ajax.php'), |
|
136 | + 'error_msg' => sprintf(__('Your Autoptimize cache might not have been purged successfully, please check on the <a href=%s>Autoptimize settings page</a>.', 'autoptimize'), admin_url('options-general.php?page=autoptimize').' style="white-space:nowrap;"'), |
|
137 | + 'dismiss_msg' => __('Dismiss this notice.'), |
|
138 | + 'nonce' => wp_create_nonce('ao_delcache_nonce'), |
|
139 | + )); |
|
140 | 140 | } |
141 | 141 | |
142 | - public function format_filesize( $bytes, $decimals = 2 ) |
|
142 | + public function format_filesize($bytes, $decimals = 2) |
|
143 | 143 | { |
144 | - $units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' ); |
|
144 | + $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); |
|
145 | 145 | |
146 | - for ( $i = 0; ( $bytes / 1024) > 0.9; $i++, $bytes /= 1024 ) {} // @codingStandardsIgnoreLine |
|
146 | + for ($i = 0; ($bytes/1024) > 0.9; $i++, $bytes /= 1024) {} // @codingStandardsIgnoreLine |
|
147 | 147 | |
148 | - return sprintf( "%1.{$decimals}f %s", round( $bytes, $decimals ), $units[ $i ] ); |
|
148 | + return sprintf("%1.{$decimals}f %s", round($bytes, $decimals), $units[$i]); |
|
149 | 149 | } |
150 | 150 | } |