PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
← All changes | libraries/csstidy/class.csstidy_print.php +82 -202 2.1.8 → 3.4 View file →
@@ -7,8 +7,10 @@
7 7 * @author Florian Schmitz, Brett Zamir, Nikolay Matsievsky, Cedric Morin, Christopher Finke, Mark Scherer, Tobias Bäthge
8 8 * @since 1.0.0
9 9 */
10 10
11 +declare(strict_types=1);
12 +
11 13 // Prohibit direct script loading.
12 14 defined( 'ABSPATH' ) || die( 'No direct script access allowed!' );
13 15
14 16 /**
@@ -18,89 +20,79 @@
18 20 *
19 21 * @package CSSTidy
20 22 * @version 1.1.0
21 23 */
22 -class TablePress_CSSTidy_print {
24 +class TablePress_CSSTidy_Print {
23 25
24 26 /**
25 27 * TablePress_CSSTidy instance.
26 28 *
27 29 * @since 1.0.0
28 - * @var TablePress_CSSTidy
29 30 */
30 - public $parser;
31 + public \TablePress_CSSTidy $parser;
31 32
32 33 /**
33 34 * The parsed CSS.
34 35 *
35 36 * @since 1.0.0
36 - * @var array
37 37 */
38 - public $css = array();
38 + public array $css = array();
39 39
40 40 /**
41 41 * The output templates.
42 42 *
43 43 * @since 1.0.0
44 - * @var array
45 44 */
46 - public $template = array();
45 + public array $template = array();
47 46
48 47 /**
49 48 * The raw parsed CSS.
50 49 *
51 50 * @since 1.0.0
52 - * @var array
53 51 */
54 - public $tokens = array();
52 + public array $tokens = array();
55 53
56 54 /**
57 55 * The CSS charset.
58 56 *
59 57 * @since 1.0.0
60 - * @var string
61 58 */
62 - public $charset = '';
59 + public string $charset = '';
63 60
64 61 /**
65 62 * All @import URLs.
66 63 *
67 64 * @since 1.0.0
68 - * @var array
69 65 */
70 - public $import = array();
66 + public array $import = array();
71 67
72 68 /**
73 69 * The namespace.
74 70 *
75 71 * @since 1.0.0
76 - * @var string
77 72 */
78 - public $namespace = '';
73 + public string $namespace = '';
79 74
80 75 /**
81 76 * Saves the input CSS string.
82 77 *
83 78 * @since 1.0.0
84 - * @var string
85 79 */
86 - public $input_css = '';
80 + public string $input_css = '';
87 81
88 82 /**
89 83 * Saves the formatted CSS string.
90 84 *
91 85 * @since 1.0.0
92 - * @var string
93 86 */
94 - public $output_css = '';
87 + public string $output_css = '';
95 88
96 89 /**
97 90 * Saves the formatted CSS string (plain text).
98 91 *
99 92 * @since 1.0.0
100 - * @var string
101 93 */
102 - public $output_css_plain = '';
94 + public string $output_css_plain = '';
103 95
104 96 /**
105 97 * Constructor.
106 98 *
@@ -105,26 +97,26 @@
105 97 * Constructor.
106 98 *
107 99 * @since 1.0
108 100 *
109 - * @param TablePress_CSSTidy $css Instance of the TablePress_CSSTidy class.
101 + * @param TablePress_CSSTidy $csstidy Instance of the TablePress_CSSTidy class.
110 102 */
111 - public function __construct( $css ) {
112 - $this->parser = $css;
113 - $this->css = &$css->css;
114 - $this->template = &$css->template;
115 - $this->tokens = &$css->tokens;
116 - $this->charset = &$css->charset;
117 - $this->import = &$css->import;
118 - $this->namespace = &$css->namespace;
103 + public function __construct( TablePress_CSSTidy $csstidy ) {
104 + $this->parser = $csstidy;
105 + $this->css = &$csstidy->css;
106 + $this->template = &$csstidy->template;
107 + $this->tokens = &$csstidy->tokens;
108 + $this->charset = &$csstidy->charset;
109 + $this->import = &$csstidy->import;
110 + $this->namespace = &$csstidy->namespace;
119 111 }
120 112
121 113 /**
122 - * Resets output_css and output_css_plain (new css code).
114 + * Resets output_css and output_css_plain (new CSS code).
123 115 *
124 116 * @since 1.0
125 117 */
126 - public function _reset() {
118 + public function _reset(): void {
127 119 $this->output_css = '';
128 120 $this->output_css_plain = '';
129 121 }
130 122
@@ -135,72 +127,14 @@
135 127 *
136 128 * @param string $default_media Optional. Default @media to add to selectors without any @media.
137 129 * @return string Plain CSS.
138 130 */
139 - public function plain( $default_media = '' ) {
131 + public function plain( string $default_media = '' ): string {
140 132 $this->_print( true, $default_media );
141 133 return $this->output_css_plain;
142 134 }
143 135
144 136 /**
145 - * Returns the formatted CSS code.
146 - *
147 - * @since 1.0
148 - *
149 - * @param string $default_media Optional. Default @media to add to selectors without any @media.
150 - * @return string Formatted CSS.
151 - */
152 - public function formatted( $default_media = '' ) {
153 - $this->_print( false, $default_media );
154 - return $this->output_css;
155 - }
156 -
157 - /**
158 - * Returns the formatted CSS code to make a complete webpage.
159 - *
160 - * @since 1.0
161 - *
162 - * @param string $doctype Optional. Shorthand for the document type.
163 - * @param bool $externalcss Optional. Indicates whether styles to be attached internally or as an external stylesheet.
164 - * @param string $title Optional. Title to be added in the head of the document.
165 - * @param string $lang Optional. Two-letter language code to be added to the output.
166 - * @return string Formatted CSS for a full page.
167 - */
168 - public function formatted_page( $doctype = 'html5', $externalcss = true, $title = '', $lang = 'en' ) {
169 - switch ( $doctype ) {
170 - case 'html5':
171 - $doctype_output = '<!DOCTYPE html>';
172 - break;
173 - case 'xhtml1.0strict':
174 - $doctype_output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
175 - break;
176 - case 'xhtml1.1':
177 - default:
178 - $doctype_output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
179 - break;
180 - }
181 -
182 - $output = '';
183 - $this->output_css_plain = &$output;
184 -
185 - $output .= $doctype_output . "\n" . '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . $lang . '"';
186 - $output .= ( 'xhtml1.1' === $doctype ) ? '>' : ' lang="' . $lang . '">';
187 - $output .= "\n<head>\n\t<title>{$title}</title>";
188 -
189 - if ( $externalcss ) {
190 - $output .= "\n\t<style>\n";
191 - $output .= file_get_contents( 'cssparsed.css' ); // Adds an invisible BOM or something, but not in css_optimised.php
192 - $output .= "\n</style>";
193 - } else {
194 - $output .= "\n" . '<link rel="stylesheet" type="text/css" href="cssparsed.css" />';
195 - }
196 - $output .= "\n</head>\n<body><code id=\"copytext\">";
197 - $output .= $this->formatted();
198 - $output .= '</code>' . "\n" . '</body></html>';
199 - return $this->output_css_plain;
200 - }
201 -
202 - /**
203 137 * Returns the formatted CSS Code and saves it into $this->output_css and $this->output_css_plain.
204 138 *
205 139 * @since 1.0
206 140 *
@@ -206,9 +140,9 @@
206 140 *
207 141 * @param bool $plain Optional. Plain text or not.
208 142 * @param string $default_media Optional. Default @media to add to selectors without any @media.
209 143 */
210 - protected function _print( $plain = false, $default_media = '' ) {
144 + protected function _print( bool $plain = false, string $default_media = '' ): void {
211 145 if ( $this->output_css && $this->output_css_plain ) {
212 146 return;
213 147 }
214 148
@@ -223,9 +157,9 @@
223 157 $template = array_map( 'strip_tags', $template );
224 158 }
225 159
226 160 if ( $this->parser->get_cfg( 'timestamp' ) ) {
227 - array_unshift( $this->tokens, array( COMMENT, ' CSSTidy ' . $this->parser->version . ': ' . date( 'r' ) . ' ' ) );
161 + array_unshift( $this->tokens, array( TablePress_CSSTidy::COMMENT, ' CSSTidy: ' . gmdate( 'r' ) . ' ' ) );
228 162 }
229 163
230 164 if ( ! empty( $this->charset ) ) {
231 165 $output .= $template[0] . '@charset ' . $template[5] . $this->charset . $template[6] . $template[13];
@@ -233,15 +167,15 @@
233 167
234 168 if ( ! empty( $this->import ) ) {
235 169 for ( $i = 0, $size = count( $this->import ); $i < $size; $i++ ) {
236 170 $import_components = explode( ' ', $this->import[ $i ] );
237 - if ( 'url(' === substr( $import_components[0], 0, 4 ) && ')' === substr( $import_components[0], -1, 1 ) ) {
171 + if ( str_starts_with( $import_components[0], 'url(' ) && str_ends_with( $import_components[0], ')' ) ) {
238 172 $import_components[0] = '\'' . trim( substr( $import_components[0], 4, -1 ), "'\"" ) . '\'';
239 173 $this->import[ $i ] = implode( ' ', $import_components );
240 174 $this->parser->log( 'Optimised @import : Removed "url("', 'Information' );
241 175 } elseif ( ! preg_match( '/^".+"$/', $this->import[ $i ] ) ) {
242 - // Fixes a bug for @import ".." instead of the expected @import url("..")/
243 - // If it comes in due to @import ".." the "" will be missing and the output will become @import .. (which is an error)/
176 + // Fixes a bug for @import ".." instead of the expected @import url("..").
177 + // If it comes in due to @import ".." the "" will be missing and the output will become @import .. (which is an error).
244 178 $this->import[ $i ] = '"' . $this->import[ $i ] . '"';
245 179 }
246 180 $output .= $template[0] . '@import ' . $template[5] . $this->import[ $i ] . $template[6] . $template[13];
247 181 }
@@ -247,9 +181,9 @@
247 181 }
248 182 }
249 183
250 184 if ( ! empty( $this->namespace ) ) {
251 - if ( false !== ( $p = strpos( $this->namespace, 'url(' ) ) && ')' === substr( $this->namespace, -1, 1 ) ) {
185 + if ( false !== ( $p = strpos( $this->namespace, 'url(' ) ) && str_ends_with( $this->namespace, ')' ) ) { // phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.Found,Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
252 186 $this->namespace = substr_replace( $this->namespace, '"', $p, 4 );
253 187 $this->namespace = substr( $this->namespace, 0, -1 ) . '"';
254 188 $this->parser->log( 'Optimised @namespace : Removed "url("', 'Information' );
255 189 }
@@ -261,20 +195,20 @@
261 195 $indent_level = 0;
262 196
263 197 foreach ( $this->tokens as $key => $token ) {
264 198 switch ( $token[0] ) {
265 - case AT_START:
199 + case TablePress_CSSTidy::AT_START:
266 200 if ( $this->parser->get_cfg( 'preserve_css' ) ) {
267 201 $token[1] = str_replace( ',', ",\n", $token[1] );
268 202 }
269 203 $out .= $template[0] . $this->_htmlsp( $token[1], $plain ) . $template[1];
270 - $indent_level++;
204 + ++$indent_level;
271 205 if ( ! isset( $in_at_out[ $indent_level ] ) ) {
272 206 $in_at_out[ $indent_level ] = '';
273 207 }
274 208 $out = &$in_at_out[ $indent_level ];
275 209 break;
276 - case SEL_START:
210 + case TablePress_CSSTidy::SEL_START:
277 211 if ( $this->parser->get_cfg( 'lowercase_s' ) ) {
278 212 $token[1] = strtolower( $token[1] );
279 213 }
280 214 if ( $this->parser->get_cfg( 'preserve_css' ) ) {
@@ -279,12 +213,12 @@
279 213 }
280 214 if ( $this->parser->get_cfg( 'preserve_css' ) ) {
281 215 $token[1] = str_replace( ',', ",\n", $token[1] );
282 216 }
283 - $out .= ( '@' !== $token[1][0] ) ? $template[2] . $this->_htmlsp( $token[1], $plain ) : $template[0] . $this->_htmlsp( $token[1], $plain );
217 + $out .= ( '' !== $token[1] && '@' !== $token[1][0] ) ? $template[2] . $this->_htmlsp( $token[1], $plain ) : $template[0] . $this->_htmlsp( $token[1], $plain );
284 218 $out .= $template[3];
285 219 break;
286 - case PROPERTY:
220 + case TablePress_CSSTidy::PROPERTY:
287 221 if ( 2 === $this->parser->get_cfg( 'case_properties' ) ) {
288 222 $token[1] = strtoupper( $token[1] );
289 223 } elseif ( 1 === $this->parser->get_cfg( 'case_properties' ) ) {
290 224 $token[1] = strtolower( $token[1] );
@@ -290,26 +224,26 @@
290 224 $token[1] = strtolower( $token[1] );
291 225 }
292 226 $out .= $template[4] . $this->_htmlsp( $token[1], $plain ) . ':' . $template[5];
293 227 break;
294 - case VALUE:
228 + case TablePress_CSSTidy::VALUE:
295 229 $out .= $this->_htmlsp( $token[1], $plain );
296 - if ( SEL_END === $this->_seeknocomment( $key, 1 ) && $this->parser->get_cfg( 'remove_last_;' ) ) {
230 + if ( TablePress_CSSTidy::SEL_END === $this->_seeknocomment( $key, 1 ) && $this->parser->get_cfg( 'remove_last_;' ) ) {
297 231 $out .= str_replace( ';', '', $template[6] );
298 232 } else {
299 233 $out .= $template[6];
300 234 }
301 235 if ( $this->parser->get_cfg( 'preserve_css' ) ) {
302 - $out .= ( COMMENT === $this->tokens[ $key + 1 ][0] ) ? ' ' : "\n";
236 + $out .= ( TablePress_CSSTidy::COMMENT === $this->tokens[ $key + 1 ][0] ) ? ' ' : "\n";
303 237 }
304 238 break;
305 - case SEL_END:
239 + case TablePress_CSSTidy::SEL_END:
306 240 $out .= $template[7];
307 - if ( AT_END !== $this->_seeknocomment( $key, 1 ) ) {
241 + if ( TablePress_CSSTidy::AT_END !== $this->_seeknocomment( $key, 1 ) ) {
308 242 $out .= $template[8];
309 243 }
310 244 break;
311 - case AT_END:
245 + case TablePress_CSSTidy::AT_END:
312 246 if ( strlen( $template[10] ) ) {
313 247 // Indent the block we are closing.
314 248 $out = str_replace( "\n\n", "\r\n", $out ); // Don't fill empty lines.
315 249 $out = str_replace( "\n", "\n" . $template[10], $out );
@@ -319,19 +253,22 @@
319 253 $out = &$in_at_out[ $indent_level - 1 ];
320 254 } else {
321 255 $out = &$output;
322 256 }
323 - $out .= $template[10] . $in_at_out[ $indent_level ];
324 - if ( AT_END !== $this->_seeknocomment( $key, 1 ) ) {
257 + $out .= $template[10];
258 + if ( isset( $in_at_out[ $indent_level ] ) ) {
259 + $out .= $in_at_out[ $indent_level ];
260 + }
261 + if ( TablePress_CSSTidy::AT_END !== $this->_seeknocomment( $key, 1 ) ) {
325 262 $out .= $template[9];
326 263 } else {
327 264 $out .= rtrim( $template[9] );
328 265 }
329 266 unset( $in_at_out[ $indent_level ] );
330 - $indent_level--;
267 + --$indent_level;
331 268 break;
332 - case IMPORTANT_COMMENT:
333 - case COMMENT:
269 + case TablePress_CSSTidy::IMPORTANT_COMMENT:
270 + case TablePress_CSSTidy::COMMENT:
334 271 $out .= $template[11] . '/*' . $this->_htmlsp( $token[1], $plain ) . '*/' . $template[12];
335 272 break;
336 273 }
337 274 }
@@ -359,16 +296,16 @@
359 296 * @param int $key Current position.
360 297 * @param int $move Move this far.
361 298 * @return mixed A token type.
362 299 */
363 - protected function _seeknocomment( $key, $move ) {
300 + protected function _seeknocomment( int $key, int $move ) /* : mixed */ {
364 301 $go = ( $move > 0 ) ? 1 : -1;
365 - for ( $i = $key + 1; abs( $key - $i ) - 1 < abs( $move ); $i += $go ) {
302 + for ( $i = $key + 1; abs( $key - $i ) - 1 < abs( $move ); $i += $go ) { // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
366 303 if ( ! isset( $this->tokens[ $i ] ) ) {
367 304 return;
368 305 }
369 - if ( COMMENT === $this->tokens[ $i ][0] ) {
370 - $move += 1;
306 + if ( TablePress_CSSTidy::COMMENT === $this->tokens[ $i ][0] ) {
307 + ++$move;
371 308 continue;
372 309 }
373 310 return $this->tokens[ $i ][0];
374 311 }
@@ -380,9 +317,9 @@
380 317 * @since 1.0.0
381 318 *
382 319 * @param string $default_media Optional. Default @media to add to selectors without any @media.
383 320 */
384 - protected function _convert_raw_css( $default_media = '' ) {
321 + protected function _convert_raw_css( string $default_media = '' ): void {
385 322 $this->tokens = array();
386 323 $sort_selectors = $this->parser->get_cfg( 'sort_selectors' );
387 324 $sort_properties = $this->parser->get_cfg( 'sort_properties' );
388 325
@@ -387,9 +324,9 @@
387 324 $sort_properties = $this->parser->get_cfg( 'sort_properties' );
388 325
389 326 // Important comment section?
390 327 if ( isset( $this->css['!'] ) ) {
391 - $this->parser->_add_token( IMPORTANT_COMMENT, rtrim( $this->css['!'] ), true );
328 + $this->parser->_add_token( TablePress_CSSTidy::IMPORTANT_COMMENT, rtrim( $this->css['!'] ), true );
392 329 unset( $this->css['!'] );
393 330 }
394 331
395 332 foreach ( $this->css as $medium => $val ) {
@@ -395,18 +332,18 @@
395 332 foreach ( $this->css as $medium => $val ) {
396 333 if ( $sort_selectors ) {
397 334 ksort( $val );
398 335 }
399 - if ( (int) $medium < DEFAULT_AT ) {
400 - // un medium vide (contenant @font-face ou autre @) ne produit aucun conteneur
336 + if ( (int) $medium < TablePress_CSSTidy::DEFAULT_AT ) {
337 + // An empty medium (containing @font-face or other @) produces no container.
401 338 if ( strlen( trim( $medium ) ) ) {
402 339 $parts_to_open = explode( '{', $medium );
403 340 foreach ( $parts_to_open as $part ) {
404 - $this->parser->_add_token( AT_START, $part, true );
341 + $this->parser->_add_token( TablePress_CSSTidy::AT_START, $part, true );
405 342 }
406 343 }
407 344 } elseif ( $default_media ) {
408 - $this->parser->_add_token( AT_START, $default_media, true );
345 + $this->parser->_add_token( TablePress_CSSTidy::AT_START, $default_media, true );
409 346 }
410 347
411 348 foreach ( $val as $selector => $vali ) {
412 349 if ( $sort_properties ) {
@@ -411,46 +348,46 @@
411 348 foreach ( $val as $selector => $vali ) {
412 349 if ( $sort_properties ) {
413 350 ksort( $vali );
414 351 }
415 - $this->parser->_add_token( SEL_START, $selector, true );
352 + $this->parser->_add_token( TablePress_CSSTidy::SEL_START, $selector, true );
416 353
417 354 $invalid = array(
418 - '*' => array(), // IE7 hacks first
419 - '_' => array(), // IE6 hacks
420 - '/' => array(), // IE6 hacks
421 - '-' => array(), // IE6 hacks
355 + '*' => array(), // IE7 hacks first.
356 + '_' => array(), // IE6 hacks.
357 + '/' => array(), // IE6 hacks.
358 + '-' => array(), // IE6 hacks.
422 359 );
423 360 foreach ( $vali as $property => $valj ) {
424 - if ( 0 !== strncmp( $property, '//', 2 ) ) {
361 + if ( ! str_starts_with( $property, '//' ) ) {
425 362 $matches = array();
426 363 if ( $sort_properties && preg_match( '/^(\*|_|\/|-)(?!(ms|moz|o\b|xv|atsc|wap|khtml|webkit|ah|hp|ro|rim|tc)-)/', $property, $matches ) ) {
427 364 $invalid[ $matches[1] ][ $property ] = $valj;
428 365 } else {
429 - $this->parser->_add_token( PROPERTY, $property, true );
430 - $this->parser->_add_token( VALUE, $valj, true );
366 + $this->parser->_add_token( TablePress_CSSTidy::PROPERTY, $property, true );
367 + $this->parser->_add_token( TablePress_CSSTidy::VALUE, $valj, true );
431 368 }
432 369 }
433 370 }
434 371 foreach ( $invalid as $prefix => $props ) {
435 372 foreach ( $props as $property => $valj ) {
436 - $this->parser->_add_token( PROPERTY, $property, true );
437 - $this->parser->_add_token( VALUE, $valj, true );
373 + $this->parser->_add_token( TablePress_CSSTidy::PROPERTY, $property, true );
374 + $this->parser->_add_token( TablePress_CSSTidy::VALUE, $valj, true );
438 375 }
439 376 }
440 - $this->parser->_add_token( SEL_END, $selector, true );
377 + $this->parser->_add_token( TablePress_CSSTidy::SEL_END, $selector, true );
441 378 }
442 379
443 - if ( (int) $medium < DEFAULT_AT ) {
444 - // un medium vide (contenant @font-face ou autre @) ne produit aucun conteneur
380 + if ( (int) $medium < TablePress_CSSTidy::DEFAULT_AT ) {
381 + // An empty medium (containing @font-face or other @) produces no container.
445 382 if ( strlen( trim( $medium ) ) ) {
446 383 $parts_to_close = explode( '{', $medium );
447 384 foreach ( array_reverse( $parts_to_close ) as $part ) {
448 - $this->parser->_add_token( AT_END, $part, true );
385 + $this->parser->_add_token( TablePress_CSSTidy::AT_END, $part, true );
449 386 }
450 387 }
451 388 } elseif ( $default_media ) {
452 - $this->parser->_add_token( AT_END, $default_media, true );
389 + $this->parser->_add_token( TablePress_CSSTidy::AT_END, $default_media, true );
453 390 }
454 391 }
455 392 }
456 393
@@ -460,73 +397,16 @@
460 397 * @since 1.0
461 398 *
462 399 * @see CSSTidy_print::_print()
463 400 *
464 - * @param string $string String.
465 - * @param bool $plain Print plain?
466 - * @return string [return value]
401 + * @param string $a_string String.
402 + * @param bool $plain Whether to print plain.
403 + * @return string Original string or htmlspecialchars() version.
467 404 */
468 - protected function _htmlsp( $string, $plain ) {
405 + protected function _htmlsp( string $a_string, bool $plain ): string {
469 406 if ( ! $plain ) {
470 - return htmlspecialchars( $string, ENT_QUOTES, 'utf-8' );
407 + return htmlspecialchars( $a_string, ENT_QUOTES, 'utf-8' );
471 408 }
472 - return $string;
409 + return $a_string;
473 410 }
474 411
475 - /**
476 - * Get compression ratio.
477 - *
478 - * @since 1.2
479 - *
480 - * @return double Compression ratio.
481 - */
482 - public function get_ratio() {
483 - if ( ! $this->output_css_plain ) {
484 - $this->formatted();
485 - }
486 - return round( ( strlen( $this->input_css ) - strlen( $this->output_css_plain ) ) / strlen( $this->input_css ), 3 ) * 100;
487 - }
488 -
489 - /**
490 - * Get difference between the old and new code in bytes and prints the code if necessary.
491 - *
492 - * @since 1.1
493 - *
494 - * @return string Size difference.
495 - */
496 - public function get_diff() {
497 - if ( ! $this->output_css_plain ) {
498 - $this->formatted();
499 - }
500 -
501 - $diff = strlen( $this->output_css_plain ) - strlen( $this->input_css );
502 -
503 - if ( $diff > 0 ) {
504 - return '+' . $diff;
505 - } elseif ( 0 === $diff ) {
506 - return '+-' . $diff;
507 - }
508 -
509 - return $diff;
510 - }
511 -
512 - /**
513 - * Get the size of either input or output CSS in kilobytes (KB).
514 - *
515 - * @since 1.0
516 - *
517 - * @param string $loc Optional. Location of the CSS.
518 - * @return int Size of the CSS.
519 - */
520 - public function size( $loc = 'output' ) {
521 - if ( 'output' === $loc && ! $this->output_css ) {
522 - $this->formatted();
523 - }
524 -
525 - if ( 'input' === $loc ) {
526 - return strlen( $this->input_css ) / 1000;
527 - } else {
528 - return strlen( $this->output_css_plain ) / 1000;
529 - }
530 - }
531 -
532 -} // class TablePress_CSSTidy_print
412 +} // class TablePress_CSSTidy_Print