PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 12.1.3
Jetpack – WP Security, Backup, Speed, & Growth v12.1.3
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 14.5.1 14.6.1 14.7.1 14.8.1 14.9.2 15.0.3 15.1.2 15.2.1 15.3.2 15.4.1 15.5.1 15.6.1 15.7.2 15.8.1 15.9.2 16.0.2 16.1.3 16.2-a.5 16.2-a.3 16.1.2 16.2-a.1 16.1.1 16.1 16.1-beta 16.1-beta.2 16.1-beta.3 16.1-a.5 16.1-a.3 16.0.1 16.1-a.1 16.0 16.0-beta 16.0-a.7 16.0-a.5 15.9.1 16.0-a.3 16.0-a.1 15.9 15.9-beta 15.9-a.7 15.9-a.5 15.9-a.3 15.9-a.1 15.8 15.8-beta 15.8-a.7 15.8-a.5 5.2.5 5.3.4 5.4.4 5.5.5 5.6.5 5.7.5 5.8.4 5.9.4 6.0.4 6.1 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.2 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.3 6.3.1 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.4 6.4.1 6.4.2 6.4.3 6.4.4 6.4.5 6.4.6 6.5 6.5.1 6.5.2 6.5.3 6.5.4 6.6 6.6.1 6.6.2 6.6.3 6.6.4 6.6.5 6.7 6.7.1 6.7.2 6.7.3 6.7.4 6.8 6.8.1 6.8.2 6.8.3 6.8.4 6.8.5 6.9 6.9.1 6.9.2 6.9.3 6.9.4 7.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2 7.2.1 7.2.1.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3 7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3 4.7.4 4.8.5 4.9.3 5.0.3 5.1.4 trunk 10.0 10.0.1 10.0.2 10.1 10.1.1 10.1.2 10.2 10.2.1 10.2.2 10.2.3 10.3 10.3.1 10.3.2 10.4 10.4.1 10.4.2 10.5 10.5.1 10.5.2 10.5.3 10.6 10.6.1 10.6.2 10.7 10.7.1 10.7.2 10.8 10.8.1 10.8.2 10.9 10.9.1 10.9.2 10.9.3 11.0 11.0.1 11.0.2 11.1 11.1.1 11.1.2 11.1.3 11.1.4 11.2 11.2.1 11.2.2 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.4 11.4.1 11.4.2 11.5 11.5.1 11.5.2 11.5.3 11.6 11.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / modules / custom-css / csstidy / class.csstidy-print.php
jetpack / modules / custom-css / csstidy Last commit date
class.csstidy-ctype.php 4 years ago class.csstidy-optimise.php 3 years ago class.csstidy-print.php 3 years ago class.csstidy.php 3 years ago cssparse-rtl.css 4 years ago cssparse-rtl.min.css 4 years ago cssparse.css 7 years ago cssparse.min.css 4 years ago cssparsed-rtl.css 4 years ago cssparsed-rtl.min.css 4 years ago cssparsed.css 14 years ago cssparsed.min.css 4 years ago data-wp.inc.php 4 years ago data.inc.php 3 years ago lang.inc.php 4 years ago wordpress-standard.tpl 11 years ago
class.csstidy-print.php
434 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 /**
3 * CSSTidy - CSS Parser and Optimiser
4 *
5 * CSS Printing class
6 * This class prints CSS data generated by csstidy.
7 *
8 * Copyright 2005, 2006, 2007 Florian Schmitz
9 *
10 * This file is part of CSSTidy.
11 *
12 * CSSTidy is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License as published by
14 * the Free Software Foundation; either version 2.1 of the License, or
15 * (at your option) any later version.
16 *
17 * CSSTidy is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 *
25 * @license https://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
26 * @package csstidy
27 * @author Florian Schmitz (floele at gmail dot com) 2005-2007
28 * @author Brett Zamir (brettz9 at yahoo dot com) 2007
29 * @author Cedric Morin (cedric at yterium dot com) 2010
30 */
31
32 /**
33 * CSS Printing class
34 *
35 * This class prints CSS data generated by csstidy.
36 *
37 * @package csstidy
38 * @author Florian Schmitz (floele at gmail dot com) 2005-2006
39 * @version 1.0.1
40 */
41 #[AllowDynamicProperties]
42 class csstidy_print { // phpcs:ignore
43
44 /**
45 * Saves the input CSS string
46 *
47 * @var string
48 * @access private
49 */
50 public $input_css = '';
51 /**
52 * Saves the formatted CSS string
53 *
54 * @var string
55 * @access public
56 */
57 public $output_css = '';
58 /**
59 * Saves the formatted CSS string (plain text)
60 *
61 * @var string
62 * @access public
63 */
64 public $output_css_plain = '';
65
66 /**
67 * Constructor
68 *
69 * @param array $css contains the class csstidy.
70 * @access private
71 * @version 1.0
72 */
73 public function __construct( &$css ) {
74 $this->parser = & $css;
75 $this->css = & $css->css;
76 $this->template = & $css->template;
77 $this->tokens = & $css->tokens;
78 $this->charset = & $css->charset;
79 $this->import = & $css->import;
80 $this->namespace = & $css->namespace;
81 }
82
83 /**
84 * Call constructor function.
85 *
86 * @param object $css - the CSS we're working with.
87 */
88 public function csstidy_print( &$css ) {
89 $this->__construct( $css );
90 }
91
92 /**
93 * Resets output_css and output_css_plain (new css code)
94 *
95 * @access private
96 * @version 1.0
97 */
98 public function _reset() { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
99 $this->output_css = '';
100 $this->output_css_plain = '';
101 }
102
103 /**
104 * Returns the CSS code as plain text
105 *
106 * @param string $default_media default @media to add to selectors without any @media.
107 * @return string
108 * @access public
109 * @version 1.0
110 */
111 public function plain( $default_media = '' ) {
112 $this->_print( true, $default_media );
113 return $this->output_css_plain;
114 }
115
116 /**
117 * Returns the formatted CSS code
118 *
119 * @param string $default_media default @media to add to selectors without any @media.
120 * @return string
121 * @access public
122 * @version 1.0
123 */
124 public function formatted( $default_media = '' ) {
125 $this->_print( false, $default_media );
126 return $this->output_css;
127 }
128
129 /**
130 * Returns the formatted CSS code to make a complete webpage
131 *
132 * @param string $doctype shorthand for the document type.
133 * @param bool $externalcss indicates whether styles to be attached internally or as an external stylesheet.
134 * @param string $title title to be added in the head of the document.
135 * @param string $lang two-letter language code to be added to the output.
136 * @return string
137 * @access public
138 * @version 1.4
139 */
140 public function formatted_page( $doctype = 'xhtml1.1', $externalcss = true, $title = '', $lang = 'en' ) {
141 switch ( $doctype ) {
142 case 'xhtml1.0strict':
143 $doctype_output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
144 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
145 break;
146 case 'xhtml1.1':
147 default:
148 $doctype_output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
149 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
150 break;
151 }
152 $cssparsed = '';
153 $output = '';
154 $this->output_css_plain = & $output;
155
156 $output .= $doctype_output . "\n" . '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . $lang . '"';
157 $output .= ( $doctype === 'xhtml1.1' ) ? '>' : ' lang="' . $lang . '">';
158 $output .= "\n<head>\n <title>$title</title>";
159
160 if ( $externalcss ) {
161 $output .= "\n <style type=\"text/css\">\n";
162 $cssparsed = file_get_contents( 'cssparsed.css' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
163 $output .= $cssparsed; // Adds an invisible BOM or something, but not in css_optimised.php
164 $output .= "\n</style>";
165 } else {
166 $output .= "\n" . ' <link rel="stylesheet" type="text/css" href="cssparsed.css" />'; // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet
167 // }
168 }
169 $output .= "\n</head>\n<body><code id=\"copytext\">";
170 $output .= $this->formatted();
171 $output .= '</code>' . "\n" . '</body></html>';
172 return $this->output_css_plain;
173 }
174
175 /**
176 * Returns the formatted CSS Code and saves it into $this->output_css and $this->output_css_plain
177 *
178 * @param bool $plain plain text or not.
179 * @param string $default_media default @media to add to selectors without any @media.
180 * @access private
181 * @version 2.0
182 */
183 public function _print( $plain = false, $default_media = '' ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore -- print is a reserved word anyway.
184 if ( $this->output_css && $this->output_css_plain ) {
185 return;
186 }
187
188 $output = '';
189 if ( ! $this->parser->get_cfg( 'preserve_css' ) ) {
190 $this->convert_raw_css( $default_media );
191 }
192
193 $template = & $this->template;
194
195 if ( $plain ) {
196 $template = array_map( 'strip_tags', $template );
197 }
198
199 if ( $this->parser->get_cfg( 'timestamp' ) ) {
200 array_unshift( $this->tokens, array( COMMENT, ' CSSTidy ' . $this->parser->version . ': ' . gmdate( 'r' ) . ' ' ) );
201 }
202
203 if ( ! empty( $this->charset ) ) {
204 $output .= $template[0] . '@charset ' . $template[5] . $this->charset . $template[6];
205 }
206
207 if ( ! empty( $this->import ) ) {
208 for ( $i = 0, $size = count( $this->import ); $i < $size; $i++ ) {
209 $import_components = explode( ' ', $this->import[ $i ] );
210 if ( substr( $import_components[0], 0, 4 ) === 'url(' && substr( $import_components[0], -1, 1 ) === ')' ) {
211 $import_components[0] = '\'' . trim( substr( $import_components[0], 4, -1 ), "'\"" ) . '\'';
212 $this->import[ $i ] = implode( ' ', $import_components );
213 $this->parser->log( 'Optimised @import : Removed "url("', 'Information' );
214 }
215 $output .= $template[0] . '@import ' . $template[5] . $this->import[ $i ] . $template[6];
216 }
217 }
218 if ( ! empty( $this->namespace ) ) {
219 if ( substr( $this->namespace, 0, 4 ) === 'url(' && substr( $this->namespace, -1, 1 ) === ')' ) {
220 $this->namespace = '\'' . substr( $this->namespace, 4, -1 ) . '\'';
221 $this->parser->log( 'Optimised @namespace : Removed "url("', 'Information' );
222 }
223 $output .= $template[0] . '@namespace ' . $template[5] . $this->namespace . $template[6];
224 }
225
226 $output .= $template[13];
227 $in_at_out = '';
228 $out = & $output;
229
230 foreach ( $this->tokens as $key => $token ) {
231 switch ( $token[0] ) {
232 case AT_START:
233 $out .= $template[0] . $this->htmlsp( $token[1], $plain ) . $template[1];
234 $out = & $in_at_out;
235 break;
236
237 case SEL_START:
238 if ( $this->parser->get_cfg( 'lowercase_s' ) ) {
239 $token[1] = strtolower( $token[1] );
240 }
241 $out .= ( $token[1][0] !== '@' ) ? $template[2] . $this->htmlsp( $token[1], $plain ) : $template[0] . $this->htmlsp( $token[1], $plain );
242 $out .= $template[3];
243 break;
244
245 case PROPERTY:
246 if ( $this->parser->get_cfg( 'case_properties' ) === 2 ) {
247 $token[1] = strtoupper( $token[1] );
248 } elseif ( $this->parser->get_cfg( 'case_properties' ) === 1 ) {
249 $token[1] = strtolower( $token[1] );
250 }
251 $out .= $template[4] . $this->htmlsp( $token[1], $plain ) . ':' . $template[5];
252 break;
253
254 case VALUE:
255 $out .= $this->htmlsp( $token[1], $plain );
256 if ( $this->seeknocomment( $key, 1 ) === SEL_END && $this->parser->get_cfg( 'remove_last_;' ) ) {
257 $out .= str_replace( ';', '', $template[6] );
258 } else {
259 $out .= $template[6];
260 }
261 break;
262
263 case SEL_END:
264 $out .= $template[7];
265 if ( $this->seeknocomment( $key, 1 ) !== AT_END ) {
266 $out .= $template[8];
267 }
268 break;
269
270 case AT_END:
271 $out = & $output;
272 $out .= $template[10] . str_replace( "\n", "\n" . $template[10], $in_at_out );
273 $in_at_out = '';
274 $out .= $template[9];
275 break;
276
277 case COMMENT:
278 $out .= $template[11] . '/*' . $this->htmlsp( $token[1], $plain ) . '*/' . $template[12];
279 break;
280 }
281 }
282
283 $output = trim( $output );
284
285 if ( ! $plain ) {
286 $this->output_css = $output;
287 $this->_print( true );
288 } else {
289 // If using spaces in the template, don't want these to appear in the plain output
290 $this->output_css_plain = str_replace( '&#160;', '', $output );
291 }
292 }
293
294 /**
295 * Gets the next token type which is $move away from $key, excluding comments
296 *
297 * @param integer $key current position.
298 * @param integer $move move this far.
299 * @return mixed a token type
300 * @access private
301 * @version 1.0
302 */
303 public function seeknocomment( $key, $move ) {
304 $go = ( $move > 0 ) ? 1 : -1;
305 for ( $i = $key + 1; abs( $key - $i ) - 1 < abs( $move ); $i += $go ) { // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
306 if ( ! isset( $this->tokens[ $i ] ) ) {
307 return;
308 }
309 if ( $this->tokens[ $i ][0] === COMMENT ) {
310 ++$move;
311 continue;
312 }
313 return $this->tokens[ $i ][0];
314 }
315 }
316
317 /**
318 * Converts $this->css array to a raw array ($this->tokens)
319 *
320 * @param string $default_media default @media to add to selectors without any @media.
321 * @access private
322 * @version 1.0
323 */
324 public function convert_raw_css( $default_media = '' ) {
325 $this->tokens = array();
326
327 foreach ( $this->css as $medium => $val ) {
328 if ( $this->parser->get_cfg( 'sort_selectors' ) ) {
329 ksort( $val );
330 }
331 if ( (int) $medium < DEFAULT_AT ) {
332 $this->parser->_add_token( AT_START, $medium, true );
333 } elseif ( $default_media ) {
334 $this->parser->_add_token( AT_START, $default_media, true );
335 }
336
337 foreach ( $val as $selector => $vali ) {
338 if ( $this->parser->get_cfg( 'sort_properties' ) ) {
339 ksort( $vali );
340 }
341 $this->parser->_add_token( SEL_START, $selector, true );
342
343 foreach ( $vali as $property => $valj ) {
344 $this->parser->_add_token( PROPERTY, $property, true );
345 $this->parser->_add_token( VALUE, $valj, true );
346 }
347
348 $this->parser->_add_token( SEL_END, $selector, true );
349 }
350
351 if ( (int) $medium < DEFAULT_AT ) {
352 $this->parser->_add_token( AT_END, $medium, true );
353 } elseif ( $default_media ) {
354 $this->parser->_add_token( AT_END, $default_media, true );
355 }
356 }
357 }
358
359 /**
360 * Same as htmlspecialchars, only that chars are not replaced if $plain !== true. This makes print_code() cleaner.
361 *
362 * @param string $string - the string we're converting.
363 * @param bool $plain - plain text or not.
364 * @return string
365 * @see csstidy_print::_print()
366 * @access private
367 * @version 1.0
368 */
369 public function htmlsp( $string, $plain ) {
370 if ( ! $plain ) {
371 return htmlspecialchars( $string, ENT_QUOTES, 'utf-8' );
372 }
373 return $string;
374 }
375
376 /**
377 * Get compression ratio
378 *
379 * @access public
380 * @return float
381 * @version 1.2
382 */
383 public function get_ratio() {
384 if ( ! $this->output_css_plain ) {
385 $this->formatted();
386 }
387 return round( ( strlen( $this->input_css ) - strlen( $this->output_css_plain ) ) / strlen( $this->input_css ), 3 ) * 100;
388 }
389
390 /**
391 * Get difference between the old and new code in bytes and prints the code if necessary.
392 *
393 * @access public
394 * @return string
395 * @version 1.1
396 */
397 public function get_diff() {
398 if ( ! $this->output_css_plain ) {
399 $this->formatted();
400 }
401
402 $diff = strlen( $this->output_css_plain ) - strlen( $this->input_css );
403
404 if ( $diff > 0 ) {
405 return '+' . $diff;
406 } elseif ( $diff === 0 ) {
407 return '+-' . $diff;
408 }
409
410 return $diff;
411 }
412
413 /**
414 * Get the size of either input or output CSS in KB
415 *
416 * @param string $loc default is "output".
417 * @access public
418 * @return integer
419 * @version 1.0
420 */
421 public function size( $loc = 'output' ) {
422 if ( $loc === 'output' && ! $this->output_css ) {
423 $this->formatted();
424 }
425
426 if ( $loc === 'input' ) {
427 return ( strlen( $this->input_css ) / 1000 );
428 } else {
429 return ( strlen( $this->output_css_plain ) / 1000 );
430 }
431 }
432
433 }
434