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 +117 -237 1.9.2 → 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 }
@@ -286,21 +189,26 @@
286 189 }
287 190 $output .= $template[0] . '@namespace ' . $template[5] . $this->namespace . $template[6] . $template[13];
288 191 }
289 192
290 - $in_at_out = '';
193 + $in_at_out = array();
291 194 $out = &$output;
195 + $indent_level = 0;
292 196
293 197 foreach ( $this->tokens as $key => $token ) {
294 198 switch ( $token[0] ) {
295 - case AT_START:
199 + case TablePress_CSSTidy::AT_START:
296 200 if ( $this->parser->get_cfg( 'preserve_css' ) ) {
297 201 $token[1] = str_replace( ',', ",\n", $token[1] );
298 202 }
299 203 $out .= $template[0] . $this->_htmlsp( $token[1], $plain ) . $template[1];
300 - $out = &$in_at_out;
204 + ++$indent_level;
205 + if ( ! isset( $in_at_out[ $indent_level ] ) ) {
206 + $in_at_out[ $indent_level ] = '';
207 + }
208 + $out = &$in_at_out[ $indent_level ];
301 209 break;
302 - case SEL_START:
210 + case TablePress_CSSTidy::SEL_START:
303 211 if ( $this->parser->get_cfg( 'lowercase_s' ) ) {
304 212 $token[1] = strtolower( $token[1] );
305 213 }
306 214 if ( $this->parser->get_cfg( 'preserve_css' ) ) {
@@ -305,12 +213,12 @@
305 213 }
306 214 if ( $this->parser->get_cfg( 'preserve_css' ) ) {
307 215 $token[1] = str_replace( ',', ",\n", $token[1] );
308 216 }
309 - $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 );
310 218 $out .= $template[3];
311 219 break;
312 - case PROPERTY:
220 + case TablePress_CSSTidy::PROPERTY:
313 221 if ( 2 === $this->parser->get_cfg( 'case_properties' ) ) {
314 222 $token[1] = strtoupper( $token[1] );
315 223 } elseif ( 1 === $this->parser->get_cfg( 'case_properties' ) ) {
316 224 $token[1] = strtolower( $token[1] );
@@ -316,34 +224,51 @@
316 224 $token[1] = strtolower( $token[1] );
317 225 }
318 226 $out .= $template[4] . $this->_htmlsp( $token[1], $plain ) . ':' . $template[5];
319 227 break;
320 - case VALUE:
228 + case TablePress_CSSTidy::VALUE:
321 229 $out .= $this->_htmlsp( $token[1], $plain );
322 - 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_;' ) ) {
323 231 $out .= str_replace( ';', '', $template[6] );
324 232 } else {
325 233 $out .= $template[6];
326 234 }
327 235 if ( $this->parser->get_cfg( 'preserve_css' ) ) {
328 - $out .= ( COMMENT === $this->tokens[ $key + 1 ][0] ) ? ' ' : "\n";
236 + $out .= ( TablePress_CSSTidy::COMMENT === $this->tokens[ $key + 1 ][0] ) ? ' ' : "\n";
329 237 }
330 238 break;
331 - case SEL_END:
239 + case TablePress_CSSTidy::SEL_END:
332 240 $out .= $template[7];
333 - if ( AT_END !== $this->_seeknocomment( $key, 1 ) ) {
241 + if ( TablePress_CSSTidy::AT_END !== $this->_seeknocomment( $key, 1 ) ) {
334 242 $out .= $template[8];
335 243 }
336 244 break;
337 - case AT_END:
338 - $out = &$output;
339 - $in_at_out = str_replace( "\n\n", "\r\n", $in_at_out ); // don't fill empty lines
340 - $in_at_out = str_replace( "\n", "\n" . $template[10], $in_at_out );
341 - $in_at_out = str_replace( "\r\n", "\n\n", $in_at_out );
342 - $out .= $template[10] . $in_at_out . $template[9];
343 - $in_at_out = '';
245 + case TablePress_CSSTidy::AT_END:
246 + if ( strlen( $template[10] ) ) {
247 + // Indent the block we are closing.
248 + $out = str_replace( "\n\n", "\r\n", $out ); // Don't fill empty lines.
249 + $out = str_replace( "\n", "\n" . $template[10], $out );
250 + $out = str_replace( "\r\n", "\n\n", $out );
251 + }
252 + if ( $indent_level > 1 ) {
253 + $out = &$in_at_out[ $indent_level - 1 ];
254 + } else {
255 + $out = &$output;
256 + }
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 ) ) {
262 + $out .= $template[9];
263 + } else {
264 + $out .= rtrim( $template[9] );
265 + }
266 + unset( $in_at_out[ $indent_level ] );
267 + --$indent_level;
344 268 break;
345 - case COMMENT:
269 + case TablePress_CSSTidy::IMPORTANT_COMMENT:
270 + case TablePress_CSSTidy::COMMENT:
346 271 $out .= $template[11] . '/*' . $this->_htmlsp( $token[1], $plain ) . '*/' . $template[12];
347 272 break;
348 273 }
349 274 }
@@ -371,16 +296,16 @@
371 296 * @param int $key Current position.
372 297 * @param int $move Move this far.
373 298 * @return mixed A token type.
374 299 */
375 - protected function _seeknocomment( $key, $move ) {
300 + protected function _seeknocomment( int $key, int $move ) /* : mixed */ {
376 301 $go = ( $move > 0 ) ? 1 : -1;
377 - 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
378 303 if ( ! isset( $this->tokens[ $i ] ) ) {
379 304 return;
380 305 }
381 - if ( COMMENT === $this->tokens[ $i ][0] ) {
382 - $move += 1;
306 + if ( TablePress_CSSTidy::COMMENT === $this->tokens[ $i ][0] ) {
307 + ++$move;
383 308 continue;
384 309 }
385 310 return $this->tokens[ $i ][0];
386 311 }
@@ -392,24 +317,33 @@
392 317 * @since 1.0.0
393 318 *
394 319 * @param string $default_media Optional. Default @media to add to selectors without any @media.
395 320 */
396 - protected function _convert_raw_css( $default_media = '' ) {
321 + protected function _convert_raw_css( string $default_media = '' ): void {
397 322 $this->tokens = array();
398 323 $sort_selectors = $this->parser->get_cfg( 'sort_selectors' );
399 324 $sort_properties = $this->parser->get_cfg( 'sort_properties' );
400 325
326 + // Important comment section?
327 + if ( isset( $this->css['!'] ) ) {
328 + $this->parser->_add_token( TablePress_CSSTidy::IMPORTANT_COMMENT, rtrim( $this->css['!'] ), true );
329 + unset( $this->css['!'] );
330 + }
331 +
401 332 foreach ( $this->css as $medium => $val ) {
402 333 if ( $sort_selectors ) {
403 334 ksort( $val );
404 335 }
405 - if ( intval( $medium ) < DEFAULT_AT ) {
406 - // 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.
407 338 if ( strlen( trim( $medium ) ) ) {
408 - $this->parser->_add_token( AT_START, $medium, true );
339 + $parts_to_open = explode( '{', $medium );
340 + foreach ( $parts_to_open as $part ) {
341 + $this->parser->_add_token( TablePress_CSSTidy::AT_START, $part, true );
342 + }
409 343 }
410 344 } elseif ( $default_media ) {
411 - $this->parser->_add_token( AT_START, $default_media, true );
345 + $this->parser->_add_token( TablePress_CSSTidy::AT_START, $default_media, true );
412 346 }
413 347
414 348 foreach ( $val as $selector => $vali ) {
415 349 if ( $sort_properties ) {
@@ -414,43 +348,46 @@
414 348 foreach ( $val as $selector => $vali ) {
415 349 if ( $sort_properties ) {
416 350 ksort( $vali );
417 351 }
418 - $this->parser->_add_token( SEL_START, $selector, true );
352 + $this->parser->_add_token( TablePress_CSSTidy::SEL_START, $selector, true );
419 353
420 354 $invalid = array(
421 - '*' => array(), // IE7 hacks first
422 - '_' => array(), // IE6 hacks
423 - '/' => array(), // IE6 hacks
424 - '-' => array(), // IE6 hacks
355 + '*' => array(), // IE7 hacks first.
356 + '_' => array(), // IE6 hacks.
357 + '/' => array(), // IE6 hacks.
358 + '-' => array(), // IE6 hacks.
425 359 );
426 360 foreach ( $vali as $property => $valj ) {
427 - if ( 0 !== strncmp( $property, '//', 2 ) ) {
361 + if ( ! str_starts_with( $property, '//' ) ) {
428 362 $matches = array();
429 363 if ( $sort_properties && preg_match( '/^(\*|_|\/|-)(?!(ms|moz|o\b|xv|atsc|wap|khtml|webkit|ah|hp|ro|rim|tc)-)/', $property, $matches ) ) {
430 364 $invalid[ $matches[1] ][ $property ] = $valj;
431 365 } else {
432 - $this->parser->_add_token( PROPERTY, $property, true );
433 - $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 );
434 368 }
435 369 }
436 370 }
437 371 foreach ( $invalid as $prefix => $props ) {
438 372 foreach ( $props as $property => $valj ) {
439 - $this->parser->_add_token( PROPERTY, $property, true );
440 - $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 );
441 375 }
442 376 }
443 - $this->parser->_add_token( SEL_END, $selector, true );
377 + $this->parser->_add_token( TablePress_CSSTidy::SEL_END, $selector, true );
444 378 }
445 379
446 - if ( intval( $medium ) < DEFAULT_AT ) {
447 - // 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.
448 382 if ( strlen( trim( $medium ) ) ) {
449 - $this->parser->_add_token( AT_END, $medium, true );
383 + $parts_to_close = explode( '{', $medium );
384 + foreach ( array_reverse( $parts_to_close ) as $part ) {
385 + $this->parser->_add_token( TablePress_CSSTidy::AT_END, $part, true );
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