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.php +47 -116 2.2.4 → 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 /**
@@ -42,17 +44,17 @@
42 44 * Defines constants.
43 45 *
44 46 * @since 1.0.0
45 47 */
46 - const AT_START = 1;
47 - const AT_END = 2;
48 - const SEL_START = 3;
49 - const SEL_END = 4;
50 - const PROPERTY = 5;
51 - const VALUE = 6;
52 - const COMMENT = 7;
53 - const IMPORTANT_COMMENT = 8;
54 - const DEFAULT_AT = 41;
48 + public const AT_START = 1;
49 + public const AT_END = 2;
50 + public const SEL_START = 3;
51 + public const SEL_END = 4;
52 + public const PROPERTY = 5;
53 + public const VALUE = 6;
54 + public const COMMENT = 7;
55 + public const IMPORTANT_COMMENT = 8;
56 + public const DEFAULT_AT = 41;
55 57
56 58 /**
57 59 * The parsed CSS.
58 60 *
@@ -58,67 +60,59 @@
58 60 *
59 61 * This array is empty if preserve_css is on.
60 62 *
61 63 * @since 1.0.0
62 - * @var array
63 64 */
64 - public $css = array();
65 + public array $css = array();
65 66
66 67 /**
67 68 * The raw parsed CSS.
68 69 *
69 70 * @since 1.0.0
70 - * @var array
71 71 */
72 - public $tokens = array();
72 + public array $tokens = array();
73 73
74 74 /**
75 75 * Instance of the CSS Printer class.
76 76 *
77 77 * @since 1.0.0
78 - * @var TablePress_CSSTidy_Print
79 78 */
80 - public $print;
79 + public \TablePress_CSSTidy_Print $print;
81 80
82 81 /**
83 82 * Instance of the CSS Optimiser class.
84 83 *
85 84 * @since 1.0.0
86 - * @var TablePress_CSSTidy_Optimise
87 85 */
88 - public $optimise;
86 + public \TablePress_CSSTidy_Optimise $optimise;
89 87
90 88 /**
91 89 * The CSS charset.
92 90 *
93 91 * @since 1.0.0
94 - * @var string
95 92 */
96 - public $charset = '';
93 + public string $charset = '';
97 94
98 95 /**
99 96 * All @import URLs.
100 97 *
101 98 * @since 1.0.0
102 - * @var array
103 99 */
104 - public $import = array();
100 + public array $import = array();
105 101
106 102 /**
107 103 * The namespace.
108 104 *
109 105 * @since 1.0.0
110 - * @var string
111 106 */
112 - public $namespace = '';
107 + public string $namespace = '';
113 108
114 109 /**
115 110 * The settings.
116 111 *
117 112 * @since 1.0.0
118 - * @var array
119 113 */
120 - protected $settings = array();
114 + protected array $settings = array();
121 115
122 116 /**
123 117 * The parser-status.
124 118 *
@@ -130,19 +124,17 @@
130 124 * - ic = in comment (ignore everything)
131 125 * - at = in @-block
132 126 *
133 127 * @since 1.0.0
134 - * @var string
135 128 */
136 - protected $status = 'is';
129 + protected string $status = 'is';
137 130
138 131 /**
139 132 * The current at rule (@media).
140 133 *
141 134 * @since 1.0.0
142 - * @var string
143 135 */
144 - public $at = '';
136 + public string $at = '';
145 137
146 138 /**
147 139 * The at rule for next selector (during @font-face or other @).
148 140 *
@@ -154,35 +146,31 @@
154 146 /**
155 147 * The current selector.
156 148 *
157 149 * @since 1.0.0
158 - * @var string
159 150 */
160 - public $selector = '';
151 + public string $selector = '';
161 152
162 153 /**
163 154 * The current property.
164 155 *
165 156 * @since 1.0.0
166 - * @var string
167 157 */
168 - public $property = '';
158 + public string $property = '';
169 159
170 160 /**
171 161 * The position of , in selectors.
172 162 *
173 163 * @since 1.0.0
174 - * @var array
175 164 */
176 - protected $sel_separate = array();
165 + protected array $sel_separate = array();
177 166
178 167 /**
179 168 * The current value.
180 169 *
181 170 * @since 1.0.0
182 - * @var string
183 171 */
184 - public $value = '';
172 + public string $value = '';
185 173
186 174 /**
187 175 * The current sub-value.
188 176 *
@@ -191,107 +179,94 @@
191 179 * "url(foo.png)", "red", and "no-repeat" are sub-values,
192 180 * separated by whitespace.
193 181 *
194 182 * @since 1.0.0
195 - * @var string
196 183 */
197 - public $sub_value = '';
184 + public string $sub_value = '';
198 185
199 186 /**
200 187 * All sub-values for a property.
201 188 *
202 189 * @since 1.0.0
203 - * @var array
204 190 */
205 - protected $sub_value_arr = array();
191 + protected array $sub_value_arr = array();
206 192
207 193 /**
208 194 * The stack of characters that opened the current strings.
209 195 *
210 196 * @since 1.0.0
211 - * @var array
212 197 */
213 - public $str_char = array();
198 + public array $str_char = array();
214 199
215 200 /**
216 201 * [$cur_string description]
217 202 *
218 203 * @since 1.0.0
219 - * @var array
220 204 */
221 - public $cur_string = array();
205 + public array $cur_string = array();
222 206
223 207 /**
224 208 * Status from which the parser switched to ic or instr
225 209 *
226 210 * @since 1.0.0
227 - * @var array
228 211 */
229 - protected $from = array();
212 + protected array $from = array();
230 213
231 214 /**
232 215 * True if in invalid at-rule.
233 216 *
234 217 * @since 1.0.0
235 - * @var bool
236 218 */
237 - protected $invalid_at = false;
219 + protected bool $invalid_at = false;
238 220
239 221 /**
240 222 * True if something has been added to the current selector.
241 223 *
242 224 * @since 1.0.0
243 - * @var bool
244 225 */
245 - protected $added = false;
226 + protected bool $added = false;
246 227
247 228 /**
248 229 * The message log.
249 230 *
250 231 * @since 1.0.0
251 - * @var array
252 232 */
253 - public $log = array();
233 + public array $log = array();
254 234
255 235 /**
256 236 * The line number.
257 237 *
258 238 * @since 1.0.0
259 - * @var int
260 239 */
261 - protected $line = 1;
240 + protected int $line = 1;
262 241
263 242 /**
264 243 * Marks if we need to leave quotes for a string.
265 244 *
266 245 * @since 1.0.0
267 - * @var array
268 246 */
269 - protected $quoted_string = array();
247 + protected array $quoted_string = array();
270 248
271 249 /**
272 250 * List of tokens.
273 251 *
274 252 * @since 1.0.0
275 - * @var string
276 253 */
277 - protected $tokens_list = '';
254 + protected string $tokens_list = '';
278 255
279 256 /**
280 257 * Various CSS Data for CSSTidy.
281 258 *
282 259 * @since 1.0.0
283 - * @var array
284 260 */
285 - public $data = array();
261 + public array $data = array();
286 262
287 263 /**
288 264 * The output templates.
289 265 *
290 266 * @since 1.0.0
291 - * @var array
292 267 */
293 - public $template = array();
268 + public array $template = array();
294 269
295 270 /**
296 271 * Loads standard template and sets default settings.
297 272 *
@@ -447,9 +422,9 @@
447 422 }
448 423 ++$i;
449 424 }
450 425
451 - if ( hexdec( $add ) > 47 && hexdec( $add ) < 58 || hexdec( $add ) > 64 && hexdec( $add ) < 91 || hexdec( $add ) > 96 && hexdec( $add ) < 123 ) {
426 + if ( ( hexdec( $add ) > 47 && hexdec( $add ) < 58 ) || ( hexdec( $add ) > 64 && hexdec( $add ) < 91 ) || ( hexdec( $add ) > 96 && hexdec( $add ) < 123 ) ) {
452 427 $this->log( 'Replaced unicode notation: Changed \\' . $add . ' to ' . chr( hexdec( $add ) ), 'Information' );
453 428 $add = chr( hexdec( $add ) );
454 429 $replaced = true;
455 430 } else {
@@ -455,9 +430,9 @@
455 430 } else {
456 431 $add = trim( '\\' . $add );
457 432 }
458 433
459 - if ( @ctype_xdigit( $a_string[ $i + 1 ] ) && ctype_space( $a_string[ $i ] ) && ! $replaced || ! ctype_space( $a_string[ $i ] ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
434 + if ( ( @ctype_xdigit( $a_string[ $i + 1 ] ) && ctype_space( $a_string[ $i ] ) && ! $replaced ) || ! ctype_space( $a_string[ $i ] ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
460 435 --$i;
461 436 }
462 437
463 438 if ( '\\' !== $add || ! $this->get_cfg( 'remove_bslash' ) || str_contains( $this->tokens_list, $a_string[ $i + 1 ] ) ) {
@@ -471,52 +446,8 @@
471 446 return '';
472 447 }
473 448
474 449 /**
475 - * Writes formatted output to a file.
476 - *
477 - * @since 1.0.0
478 - *
479 - * @param string $filename File name.
480 - */
481 - public function write_page( string $filename ): void {
482 - $this->write( $filename, true );
483 - }
484 -
485 - /**
486 - * Writes plain output to a file.
487 - *
488 - * @since 1.0.0
489 - *
490 - * @param string $filename File name.
491 - * @param bool $formatted Optional. Whether to print formatted or not.
492 - * @param string $doctype Optional. When printing formatted, is a shorthand for the document type.
493 - * @param bool $externalcss Optional. When printing formatted, indicates whether styles to be attached internally or as an external stylesheet.
494 - * @param string $title Optional. When printing formatted, is the title to be added in the head of the document.
495 - * @param string $lang Optional. When printing formatted, gives a two-letter language code to be added to the output.
496 - */
497 - public function write( string $filename, bool $formatted = false, string $doctype = 'xhtml1.1', bool $externalcss = true, string $title = '', string $lang = 'en' ): void {
498 - $filename .= ( $formatted ) ? '.xhtml' : '.css';
499 -
500 - if ( ! is_dir( 'temp' ) ) {
501 - $madedir = mkdir( 'temp' );
502 - if ( ! $madedir ) {
503 - print 'Could not make directory "temp" in ' . __DIR__;
504 - exit;
505 - }
506 - }
507 - $handle = fopen( 'temp/' . $filename, 'w' );
508 - if ( $handle ) {
509 - if ( ! $formatted ) {
510 - fwrite( $handle, $this->print->plain() );
511 - } else {
512 - fwrite( $handle, $this->print->formatted_page( $doctype, $externalcss, $title, $lang ) );
513 - }
514 - }
515 - fclose( $handle );
516 - }
517 -
518 - /**
519 450 * Loads a new template.
520 451 *
521 452 * @since 1.0.0
522 453 *
@@ -578,9 +509,9 @@
578 509 * @return bool Whether the CSS code could be parsed successfully.
579 510 */
580 511 public function parse( string $a_string ): bool {
581 512 // Temporarily set locale to en_US in order to handle floats properly.
582 - $old = @setlocale( LC_ALL, 0 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
513 + $old = @setlocale( LC_ALL, '0' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
583 514 @setlocale( LC_ALL, 'C' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
584 515
585 516 $at_rules = &$this->data['csstidy']['at_rules'];
586 517 $quoted_string_properties = &$this->data['csstidy']['quoted_string_properties'];
@@ -618,9 +549,9 @@
618 549 $cur_at .= $a_string[ $i ];
619 550 }
620 551 } else {
621 552 $lastpos = strlen( $cur_at ) - 1;
622 - if ( ! ( ( ctype_space( $cur_at[ $lastpos ] ) || $this->is_token( $cur_at, $lastpos ) && ',' === $cur_at[ $lastpos ] ) && ctype_space( $a_string[ $i ] ) ) ) {
553 + if ( ! ( ( ctype_space( $cur_at[ $lastpos ] ) || ( $this->is_token( $cur_at, $lastpos ) && ',' === $cur_at[ $lastpos ] ) ) && ctype_space( $a_string[ $i ] ) ) ) {
623 554 $cur_at .= $a_string[ $i ];
624 555 }
625 556 }
626 557 break;
@@ -681,9 +612,9 @@
681 612 }
682 613 } elseif ( '{' === $a_string[ $i ] ) {
683 614 $this->status = 'ip';
684 615 if ( '' === $this->at ) {
685 - $this->at = $this->css_new_media_section( $this->at, self::DEFAULT_AT );
616 + $this->at = $this->css_new_media_section( $this->at, (string) self::DEFAULT_AT );
686 617 }
687 618 $this->selector = $this->css_new_selector( $this->at, $this->selector );
688 619 $this->_add_token( self::SEL_START, $this->selector );
689 620 $this->added = false;
@@ -703,9 +634,9 @@
703 634 $this->selector .= $a_string[ $i ];
704 635 }
705 636 } else {
706 637 $lastpos = strlen( $this->selector ) - 1;
707 - if ( -1 === $lastpos || ! ( ( ctype_space( $this->selector[ $lastpos ] ) || $this->is_token( $this->selector, $lastpos ) && ',' === $this->selector[ $lastpos ] ) && ctype_space( $a_string[ $i ] ) ) ) {
638 + if ( -1 === $lastpos || ! ( ( ctype_space( $this->selector[ $lastpos ] ) || ( $this->is_token( $this->selector, $lastpos ) && ',' === $this->selector[ $lastpos ] ) ) && ctype_space( $a_string[ $i ] ) ) ) {
708 639 $this->selector .= $a_string[ $i ];
709 640 }
710 641 }
711 642 break;
@@ -749,9 +680,9 @@
749 680 }
750 681 break;
751 682 /* Case in-value */
752 683 case 'iv':
753 - $pn = ( ( "\n" === $a_string[ $i ] || "\r" === $a_string[ $i ] ) && $this->property_is_next( $a_string, $i + 1 ) || ( strlen( $a_string ) - 1 ) === $i );
684 + $pn = ( ( ( "\n" === $a_string[ $i ] || "\r" === $a_string[ $i ] ) && $this->property_is_next( $a_string, $i + 1 ) ) || ( strlen( $a_string ) - 1 ) === $i );
754 685 if ( ( $this->is_token( $a_string, $i ) || $pn ) && ( ! ( ',' === $a_string[ $i ] && ! ctype_space( $a_string[ $i + 1 ] ) ) ) ) {
755 686 if ( '/' === $a_string[ $i ] && '*' === @$a_string[ $i + 1 ] ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
756 687 $this->status = 'ic';
757 688 ++$i;
@@ -766,9 +697,9 @@
766 697 $this->sub_value = trim( $this->sub_value ) . ',';
767 698 } elseif ( '\\' === $a_string[ $i ] ) {
768 699 $this->sub_value .= $this->_unicode( $a_string, $i );
769 700 } elseif ( ';' === $a_string[ $i ] || $pn ) {
770 - if ( '@' === $this->selector[0] && isset( $at_rules[ substr( $this->selector, 1 ) ] ) && 'iv' === $at_rules[ substr( $this->selector, 1 ) ] ) {
701 + if ( '' !== $this->selector && '@' === $this->selector[0] && isset( $at_rules[ substr( $this->selector, 1 ) ] ) && 'iv' === $at_rules[ substr( $this->selector, 1 ) ] ) {
771 702 $this->status = 'is';
772 703
773 704 switch ( $this->selector ) {
774 705 case '@charset':
@@ -809,9 +740,9 @@
809 740 $this->sub_value .= $a_string[ $i ];
810 741 }
811 742 if ( ( '}' === $a_string[ $i ] || ';' === $a_string[ $i ] || $pn ) && ! empty( $this->selector ) ) {
812 743 if ( '' === $this->at ) {
813 - $this->at = $this->css_new_media_section( $this->at, self::DEFAULT_AT );
744 + $this->at = $this->css_new_media_section( $this->at, (string) self::DEFAULT_AT );
814 745 }
815 746
816 747 // Case settings.
817 748 if ( $this->get_cfg( 'lowercase_s' ) ) {