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 +87 -237 1.12 → 3.4 View file →
@@ -7,131 +7,92 @@
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 /**
15 - * CSSTidy - CSS Parser and Optimiser
16 - *
17 17 * CSS Printing class
18 - * This class prints CSS data generated by CSSTidy.
19 18 *
20 - * Copyright 2005, 2006, 2007 Florian Schmitz
21 - *
22 - * This file is part of CSSTidy.
23 - *
24 - * CSSTidy is free software; you can redistribute it and/or modify
25 - * it under the terms of the GNU Lesser General Public License as published by
26 - * the Free Software Foundation; either version 2.1 of the License, or
27 - * (at your option) any later version.
28 - *
29 - * CSSTidy is distributed in the hope that it will be useful,
30 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 - * GNU Lesser General Public License for more details.
33 - *
34 - * You should have received a copy of the GNU Lesser General Public License
35 - * along with this program. If not, see <https://www.gnu.org/licenses/>.
36 - *
37 - * @license https://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
38 - * @package CSSTidy
39 - * @author Florian Schmitz (floele at gmail dot com) 2005-2007
40 - * @author Brett Zamir (brettz9 at yahoo dot com) 2007
41 - * @author Cedric Morin (cedric at yterium dot com) 2010-2012
42 - */
43 -
44 -/**
45 - * CSS Printing class
46 - *
47 19 * This class prints CSS data generated by CSSTidy.
48 20 *
49 21 * @package CSSTidy
50 - * @author Florian Schmitz (floele at gmail dot com) 2005-2006
51 22 * @version 1.1.0
52 23 */
53 -class TablePress_CSSTidy_print {
24 +class TablePress_CSSTidy_Print {
54 25
55 26 /**
56 - * CSSTidy instance.
27 + * TablePress_CSSTidy instance.
57 28 *
58 29 * @since 1.0.0
59 - * @var CSSTidy
60 30 */
61 - public $parser;
31 + public \TablePress_CSSTidy $parser;
62 32
63 33 /**
64 34 * The parsed CSS.
65 35 *
66 36 * @since 1.0.0
67 - * @var array
68 37 */
69 - public $css = array();
38 + public array $css = array();
70 39
71 40 /**
72 41 * The output templates.
73 42 *
74 43 * @since 1.0.0
75 - * @var array
76 44 */
77 - public $template = array();
45 + public array $template = array();
78 46
79 47 /**
80 48 * The raw parsed CSS.
81 49 *
82 50 * @since 1.0.0
83 - * @var array
84 51 */
85 - public $tokens = array();
52 + public array $tokens = array();
86 53
87 54 /**
88 55 * The CSS charset.
89 56 *
90 57 * @since 1.0.0
91 - * @var string
92 58 */
93 - public $charset = '';
59 + public string $charset = '';
94 60
95 61 /**
96 62 * All @import URLs.
97 63 *
98 64 * @since 1.0.0
99 - * @var array
100 65 */
101 - public $import = array();
66 + public array $import = array();
102 67
103 68 /**
104 69 * The namespace.
105 70 *
106 71 * @since 1.0.0
107 - * @var string
108 72 */
109 - public $namespace = '';
73 + public string $namespace = '';
110 74
111 75 /**
112 76 * Saves the input CSS string.
113 77 *
114 78 * @since 1.0.0
115 - * @var string
116 79 */
117 - public $input_css = '';
80 + public string $input_css = '';
118 81
119 82 /**
120 83 * Saves the formatted CSS string.
121 84 *
122 85 * @since 1.0.0
123 - * @var string
124 86 */
125 - public $output_css = '';
87 + public string $output_css = '';
126 88
127 89 /**
128 90 * Saves the formatted CSS string (plain text).
129 91 *
130 92 * @since 1.0.0
131 - * @var string
132 93 */
133 - public $output_css_plain = '';
94 + public string $output_css_plain = '';
134 95
135 96 /**
136 97 * Constructor.
137 98 *
@@ -136,26 +97,26 @@
136 97 * Constructor.
137 98 *
138 99 * @since 1.0
139 100 *
140 - * @param CSSTidy $css Instance of the CSSTidy class.
101 + * @param TablePress_CSSTidy $csstidy Instance of the TablePress_CSSTidy class.
141 102 */
142 - public function __construct( $css ) {
143 - $this->parser = $css;
144 - $this->css = &$css->css;
145 - $this->template = &$css->template;
146 - $this->tokens = &$css->tokens;
147 - $this->charset = &$css->charset;
148 - $this->import = &$css->import;
149 - $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;
150 111 }
151 112
152 113 /**
153 - * Resets output_css and output_css_plain (new css code).
114 + * Resets output_css and output_css_plain (new CSS code).
154 115 *
155 116 * @since 1.0
156 117 */
157 - public function _reset() {
118 + public function _reset(): void {
158 119 $this->output_css = '';
159 120 $this->output_css_plain = '';
160 121 }
161 122
@@ -166,80 +127,22 @@
166 127 *
167 128 * @param string $default_media Optional. Default @media to add to selectors without any @media.
168 129 * @return string Plain CSS.
169 130 */
170 - public function plain( $default_media = '' ) {
131 + public function plain( string $default_media = '' ): string {
171 132 $this->_print( true, $default_media );
172 133 return $this->output_css_plain;
173 134 }
174 135
175 136 /**
176 - * Returns the formatted CSS code.
137 + * Returns the formatted CSS Code and saves it into $this->output_css and $this->output_css_plain.
177 138 *
178 139 * @since 1.0
179 140 *
180 - * @param string $default_media Optional. Default @media to add to selectors without any @media.
181 - * @return string Formatted CSS.
182 - */
183 - public function formatted( $default_media = '' ) {
184 - $this->_print( false, $default_media );
185 - return $this->output_css;
186 - }
187 -
188 - /**
189 - * Returns the formatted CSS code to make a complete webpage.
190 - *
191 - * @since 1.4
192 - *
193 - * @param string $doctype Optional. Shorthand for the document type.
194 - * @param bool $externalcss Optional. Indicates whether styles to be attached internally or as an external stylesheet.
195 - * @param string $title Optional. Title to be added in the head of the document.
196 - * @param string $lang Optional. Two-letter language code to be added to the output.
197 - * @return string Formatted CSS for a full page.
198 - */
199 - public function formatted_page( $doctype = 'html5', $externalcss = true, $title = '', $lang = 'en' ) {
200 - switch ( $doctype ) {
201 - case 'html5':
202 - $doctype_output = '<!DOCTYPE html>';
203 - break;
204 - case 'xhtml1.0strict':
205 - $doctype_output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
206 - break;
207 - case 'xhtml1.1':
208 - default:
209 - $doctype_output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
210 - break;
211 - }
212 -
213 - $output = '';
214 - $this->output_css_plain = &$output;
215 -
216 - $output .= $doctype_output . "\n" . '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . $lang . '"';
217 - $output .= ( 'xhtml1.1' === $doctype ) ? '>' : ' lang="' . $lang . '">';
218 - $output .= "\n<head>\n\t<title>{$title}</title>";
219 -
220 - if ( $externalcss ) {
221 - $output .= "\n\t<style type=\"text/css\">\n";
222 - $output .= file_get_contents( 'cssparsed.css' ); // Adds an invisible BOM or something, but not in css_optimised.php
223 - $output .= "\n</style>";
224 - } else {
225 - $output .= "\n" . '<link rel="stylesheet" type="text/css" href="cssparsed.css" />';
226 - }
227 - $output .= "\n</head>\n<body><code id=\"copytext\">";
228 - $output .= $this->formatted();
229 - $output .= '</code>' . "\n" . '</body></html>';
230 - return $this->output_css_plain;
231 - }
232 -
233 - /**
234 - * Returns the formatted CSS Code and saves it into $this->output_css and $this->output_css_plain.
235 - *
236 - * @since 2.0
237 - *
238 141 * @param bool $plain Optional. Plain text or not.
239 142 * @param string $default_media Optional. Default @media to add to selectors without any @media.
240 143 */
241 - protected function _print( $plain = false, $default_media = '' ) {
144 + protected function _print( bool $plain = false, string $default_media = '' ): void {
242 145 if ( $this->output_css && $this->output_css_plain ) {
243 146 return;
244 147 }
245 148
@@ -254,9 +157,9 @@
254 157 $template = array_map( 'strip_tags', $template );
255 158 }
256 159
257 160 if ( $this->parser->get_cfg( 'timestamp' ) ) {
258 - array_unshift( $this->tokens, array( COMMENT, ' CSSTidy ' . $this->parser->version . ': ' . date( 'r' ) . ' ' ) );
161 + array_unshift( $this->tokens, array( TablePress_CSSTidy::COMMENT, ' CSSTidy: ' . gmdate( 'r' ) . ' ' ) );
259 162 }
260 163
261 164 if ( ! empty( $this->charset ) ) {
262 165 $output .= $template[0] . '@charset ' . $template[5] . $this->charset . $template[6] . $template[13];
@@ -264,15 +167,15 @@
264 167
265 168 if ( ! empty( $this->import ) ) {
266 169 for ( $i = 0, $size = count( $this->import ); $i < $size; $i++ ) {
267 170 $import_components = explode( ' ', $this->import[ $i ] );
268 - 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], ')' ) ) {
269 172 $import_components[0] = '\'' . trim( substr( $import_components[0], 4, -1 ), "'\"" ) . '\'';
270 173 $this->import[ $i ] = implode( ' ', $import_components );
271 174 $this->parser->log( 'Optimised @import : Removed "url("', 'Information' );
272 175 } elseif ( ! preg_match( '/^".+"$/', $this->import[ $i ] ) ) {
273 - // Fixes a bug for @import ".." instead of the expected @import url("..")/
274 - // 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).
275 178 $this->import[ $i ] = '"' . $this->import[ $i ] . '"';
276 179 }
277 180 $output .= $template[0] . '@import ' . $template[5] . $this->import[ $i ] . $template[6] . $template[13];
278 181 }
@@ -278,9 +181,9 @@
278 181 }
279 182 }
280 183
281 184 if ( ! empty( $this->namespace ) ) {
282 - 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
283 186 $this->namespace = substr_replace( $this->namespace, '"', $p, 4 );
284 187 $this->namespace = substr( $this->namespace, 0, -1 ) . '"';
285 188 $this->parser->log( 'Optimised @namespace : Removed "url("', 'Information' );
286 189 }
@@ -292,20 +195,20 @@
292 195 $indent_level = 0;
293 196
294 197 foreach ( $this->tokens as $key => $token ) {
295 198 switch ( $token[0] ) {
296 - case AT_START:
199 + case TablePress_CSSTidy::AT_START:
297 200 if ( $this->parser->get_cfg( 'preserve_css' ) ) {
298 201 $token[1] = str_replace( ',', ",\n", $token[1] );
299 202 }
300 203 $out .= $template[0] . $this->_htmlsp( $token[1], $plain ) . $template[1];
301 - $indent_level++;
204 + ++$indent_level;
302 205 if ( ! isset( $in_at_out[ $indent_level ] ) ) {
303 206 $in_at_out[ $indent_level ] = '';
304 207 }
305 208 $out = &$in_at_out[ $indent_level ];
306 209 break;
307 - case SEL_START:
210 + case TablePress_CSSTidy::SEL_START:
308 211 if ( $this->parser->get_cfg( 'lowercase_s' ) ) {
309 212 $token[1] = strtolower( $token[1] );
310 213 }
311 214 if ( $this->parser->get_cfg( 'preserve_css' ) ) {
@@ -310,12 +213,12 @@
310 213 }
311 214 if ( $this->parser->get_cfg( 'preserve_css' ) ) {
312 215 $token[1] = str_replace( ',', ",\n", $token[1] );
313 216 }
314 - $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 );
315 218 $out .= $template[3];
316 219 break;
317 - case PROPERTY:
220 + case TablePress_CSSTidy::PROPERTY:
318 221 if ( 2 === $this->parser->get_cfg( 'case_properties' ) ) {
319 222 $token[1] = strtoupper( $token[1] );
320 223 } elseif ( 1 === $this->parser->get_cfg( 'case_properties' ) ) {
321 224 $token[1] = strtolower( $token[1] );
@@ -321,26 +224,26 @@
321 224 $token[1] = strtolower( $token[1] );
322 225 }
323 226 $out .= $template[4] . $this->_htmlsp( $token[1], $plain ) . ':' . $template[5];
324 227 break;
325 - case VALUE:
228 + case TablePress_CSSTidy::VALUE:
326 229 $out .= $this->_htmlsp( $token[1], $plain );
327 - 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_;' ) ) {
328 231 $out .= str_replace( ';', '', $template[6] );
329 232 } else {
330 233 $out .= $template[6];
331 234 }
332 235 if ( $this->parser->get_cfg( 'preserve_css' ) ) {
333 - $out .= ( COMMENT === $this->tokens[ $key + 1 ][0] ) ? ' ' : "\n";
236 + $out .= ( TablePress_CSSTidy::COMMENT === $this->tokens[ $key + 1 ][0] ) ? ' ' : "\n";
334 237 }
335 238 break;
336 - case SEL_END:
239 + case TablePress_CSSTidy::SEL_END:
337 240 $out .= $template[7];
338 - if ( AT_END !== $this->_seeknocomment( $key, 1 ) ) {
241 + if ( TablePress_CSSTidy::AT_END !== $this->_seeknocomment( $key, 1 ) ) {
339 242 $out .= $template[8];
340 243 }
341 244 break;
342 - case AT_END:
245 + case TablePress_CSSTidy::AT_END:
343 246 if ( strlen( $template[10] ) ) {
344 247 // Indent the block we are closing.
345 248 $out = str_replace( "\n\n", "\r\n", $out ); // Don't fill empty lines.
346 249 $out = str_replace( "\n", "\n" . $template[10], $out );
@@ -347,22 +250,25 @@
347 250 $out = str_replace( "\r\n", "\n\n", $out );
348 251 }
349 252 if ( $indent_level > 1 ) {
350 253 $out = &$in_at_out[ $indent_level - 1 ];
351 - }else {
254 + } else {
352 255 $out = &$output;
353 256 }
354 - $out .= $template[10] . $in_at_out[$indent_level];
355 - 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 ) ) {
356 262 $out .= $template[9];
357 263 } else {
358 264 $out .= rtrim( $template[9] );
359 265 }
360 266 unset( $in_at_out[ $indent_level ] );
361 - $indent_level--;
267 + --$indent_level;
362 268 break;
363 - case IMPORTANT_COMMENT:
364 - case COMMENT:
269 + case TablePress_CSSTidy::IMPORTANT_COMMENT:
270 + case TablePress_CSSTidy::COMMENT:
365 271 $out .= $template[11] . '/*' . $this->_htmlsp( $token[1], $plain ) . '*/' . $template[12];
366 272 break;
367 273 }
368 274 }
@@ -390,16 +296,16 @@
390 296 * @param int $key Current position.
391 297 * @param int $move Move this far.
392 298 * @return mixed A token type.
393 299 */
394 - protected function _seeknocomment( $key, $move ) {
300 + protected function _seeknocomment( int $key, int $move ) /* : mixed */ {
395 301 $go = ( $move > 0 ) ? 1 : -1;
396 - 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
397 303 if ( ! isset( $this->tokens[ $i ] ) ) {
398 304 return;
399 305 }
400 - if ( COMMENT === $this->tokens[ $i ][0] ) {
401 - $move += 1;
306 + if ( TablePress_CSSTidy::COMMENT === $this->tokens[ $i ][0] ) {
307 + ++$move;
402 308 continue;
403 309 }
404 310 return $this->tokens[ $i ][0];
405 311 }
@@ -411,9 +317,9 @@
411 317 * @since 1.0.0
412 318 *
413 319 * @param string $default_media Optional. Default @media to add to selectors without any @media.
414 320 */
415 - protected function _convert_raw_css( $default_media = '' ) {
321 + protected function _convert_raw_css( string $default_media = '' ): void {
416 322 $this->tokens = array();
417 323 $sort_selectors = $this->parser->get_cfg( 'sort_selectors' );
418 324 $sort_properties = $this->parser->get_cfg( 'sort_properties' );
419 325
@@ -418,9 +324,9 @@
418 324 $sort_properties = $this->parser->get_cfg( 'sort_properties' );
419 325
420 326 // Important comment section?
421 327 if ( isset( $this->css['!'] ) ) {
422 - $this->parser->_add_token( IMPORTANT_COMMENT, rtrim( $this->css['!'] ), true );
328 + $this->parser->_add_token( TablePress_CSSTidy::IMPORTANT_COMMENT, rtrim( $this->css['!'] ), true );
423 329 unset( $this->css['!'] );
424 330 }
425 331
426 332 foreach ( $this->css as $medium => $val ) {
@@ -426,17 +332,18 @@
426 332 foreach ( $this->css as $medium => $val ) {
427 333 if ( $sort_selectors ) {
428 334 ksort( $val );
429 335 }
430 - if ( intval( $medium ) < DEFAULT_AT ) {
431 - // 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.
432 338 if ( strlen( trim( $medium ) ) ) {
433 339 $parts_to_open = explode( '{', $medium );
434 340 foreach ( $parts_to_open as $part ) {
435 - $this->parser->_add_token( AT_START, $part, true );
436 - } }
341 + $this->parser->_add_token( TablePress_CSSTidy::AT_START, $part, true );
342 + }
343 + }
437 344 } elseif ( $default_media ) {
438 - $this->parser->_add_token( AT_START, $default_media, true );
345 + $this->parser->_add_token( TablePress_CSSTidy::AT_START, $default_media, true );
439 346 }
440 347
441 348 foreach ( $val as $selector => $vali ) {
442 349 if ( $sort_properties ) {
@@ -441,46 +348,46 @@
441 348 foreach ( $val as $selector => $vali ) {
442 349 if ( $sort_properties ) {
443 350 ksort( $vali );
444 351 }
445 - $this->parser->_add_token( SEL_START, $selector, true );
352 + $this->parser->_add_token( TablePress_CSSTidy::SEL_START, $selector, true );
446 353
447 354 $invalid = array(
448 - '*' => array(), // IE7 hacks first
449 - '_' => array(), // IE6 hacks
450 - '/' => array(), // IE6 hacks
451 - '-' => array(), // IE6 hacks
355 + '*' => array(), // IE7 hacks first.
356 + '_' => array(), // IE6 hacks.
357 + '/' => array(), // IE6 hacks.
358 + '-' => array(), // IE6 hacks.
452 359 );
453 360 foreach ( $vali as $property => $valj ) {
454 - if ( 0 !== strncmp( $property, '//', 2 ) ) {
361 + if ( ! str_starts_with( $property, '//' ) ) {
455 362 $matches = array();
456 363 if ( $sort_properties && preg_match( '/^(\*|_|\/|-)(?!(ms|moz|o\b|xv|atsc|wap|khtml|webkit|ah|hp|ro|rim|tc)-)/', $property, $matches ) ) {
457 364 $invalid[ $matches[1] ][ $property ] = $valj;
458 365 } else {
459 - $this->parser->_add_token( PROPERTY, $property, true );
460 - $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 );
461 368 }
462 369 }
463 370 }
464 371 foreach ( $invalid as $prefix => $props ) {
465 372 foreach ( $props as $property => $valj ) {
466 - $this->parser->_add_token( PROPERTY, $property, true );
467 - $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 );
468 375 }
469 376 }
470 - $this->parser->_add_token( SEL_END, $selector, true );
377 + $this->parser->_add_token( TablePress_CSSTidy::SEL_END, $selector, true );
471 378 }
472 379
473 - if ( intval( $medium ) < DEFAULT_AT ) {
474 - // 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.
475 382 if ( strlen( trim( $medium ) ) ) {
476 383 $parts_to_close = explode( '{', $medium );
477 384 foreach ( array_reverse( $parts_to_close ) as $part ) {
478 - $this->parser->_add_token( AT_END, $part, true );
385 + $this->parser->_add_token( TablePress_CSSTidy::AT_END, $part, true );
479 386 }
480 387 }
481 388 } elseif ( $default_media ) {
482 - $this->parser->_add_token( AT_END, $default_media, true );
389 + $this->parser->_add_token( TablePress_CSSTidy::AT_END, $default_media, true );
483 390 }
484 391 }
485 392 }
486 393
@@ -490,73 +397,16 @@
490 397 * @since 1.0
491 398 *
492 399 * @see CSSTidy_print::_print()
493 400 *
494 - * @param string $string String.
495 - * @param bool $plain Print plain?
496 - * @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.
497 404 */
498 - protected function _htmlsp( $string, $plain ) {
405 + protected function _htmlsp( string $a_string, bool $plain ): string {
499 406 if ( ! $plain ) {
500 - return htmlspecialchars( $string, ENT_QUOTES, 'utf-8' );
407 + return htmlspecialchars( $a_string, ENT_QUOTES, 'utf-8' );
501 408 }
502 - return $string;
409 + return $a_string;
503 410 }
504 411
505 - /**
506 - * Get compression ratio.
507 - *
508 - * @since 1.2
509 - *
510 - * @return double Compression ratio.
511 - */
512 - public function get_ratio() {
513 - if ( ! $this->output_css_plain ) {
514 - $this->formatted();
515 - }
516 - return round( ( strlen( $this->input_css ) - strlen( $this->output_css_plain ) ) / strlen( $this->input_css ), 3 ) * 100;
517 - }
518 -
519 - /**
520 - * Get difference between the old and new code in bytes and prints the code if necessary.
521 - *
522 - * @since 1.1
523 - *
524 - * @return string Size difference.
525 - */
526 - public function get_diff() {
527 - if ( ! $this->output_css_plain ) {
528 - $this->formatted();
529 - }
530 -
531 - $diff = strlen( $this->output_css_plain ) - strlen( $this->input_css );
532 -
533 - if ( $diff > 0 ) {
534 - return '+' . $diff;
535 - } elseif ( 0 === $diff ) {
536 - return '+-' . $diff;
537 - }
538 -
539 - return $diff;
540 - }
541 -
542 - /**
543 - * Get the size of either input or output CSS in kilobytes (KB).
544 - *
545 - * @since 1.0
546 - *
547 - * @param string $loc Optional. Location of the CSS.
548 - * @return int Size of the CSS.
549 - */
550 - public function size( $loc = 'output' ) {
551 - if ( 'output' === $loc && ! $this->output_css ) {
552 - $this->formatted();
553 - }
554 -
555 - if ( 'input' === $loc ) {
556 - return strlen( $this->input_css ) / 1000;
557 - } else {
558 - return strlen( $this->output_css_plain ) / 1000;
559 - }
560 - }
561 -
562 -} // class TablePress_CSSTidy_print
412 +} // class TablePress_CSSTidy_Print