Skip to content
Commits on Source (1)
<?php
/**
* CSSTidy - CSS Parser and Optimiser
*
* CSS ctype functions
* Defines some functions that can be not defined.
*
* This file is part of CSSTidy.
*
* CSSTidy is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* CSSTidy is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CSSTidy; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @license https://opensource.org/licenses/gpl-license.php GNU Public License
* @package csstidy
* @author Nikolay Matsievsky (speed at webo dot name) 2009-2010
* @version 1.0
*/
if ( ! function_exists( 'ctype_space' ) ) {
/**
* Check for whitespace character(s).
*
* @param string $text - the text.
*/
function ctype_space( $text ) {
return ! preg_match( "/[^\s\r\n\t\f]/", $text );
}
}
if ( ! function_exists( 'ctype_alpha' ) ) {
/**
* Check for alphabetic character(s)
*
* @param string $text - the text.
*/
function ctype_alpha( $text ) {
return preg_match( '/[a-zA-Z]/', $text );
}
}
This diff is collapsed.
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
/**
* CSSTidy - CSS Parser and Optimiser
*
* CSS Printing class
* This class prints CSS data generated by csstidy.
*
* Copyright 2005, 2006, 2007 Florian Schmitz
*
* This file is part of CSSTidy.
*
* CSSTidy is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* CSSTidy is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @license https://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
* @package csstidy
* @author Florian Schmitz (floele at gmail dot com) 2005-2007
* @author Brett Zamir (brettz9 at yahoo dot com) 2007
* @author Cedric Morin (cedric at yterium dot com) 2010
*/
/**
* CSS Printing class
*
* This class prints CSS data generated by csstidy.
*
* @package csstidy
* @author Florian Schmitz (floele at gmail dot com) 2005-2006
* @version 1.0.1
*/
class csstidy_print { // phpcs:ignore
/**
* Saves the input CSS string
*
* @var string
* @access private
*/
public $input_css = '';
/**
* Saves the formatted CSS string
*
* @var string
* @access public
*/
public $output_css = '';
/**
* Saves the formatted CSS string (plain text)
*
* @var string
* @access public
*/
public $output_css_plain = '';
/**
* Constructor
*
* @param array $css contains the class csstidy.
* @access private
* @version 1.0
*/
public function __construct( &$css ) {
$this->parser = & $css;
$this->css = & $css->css;
$this->template = & $css->template;
$this->tokens = & $css->tokens;
$this->charset = & $css->charset;
$this->import = & $css->import;
$this->namespace = & $css->namespace;
}
/**
* Call constructor function.
*
* @param object $css - the CSS we're working with.
*/
public function csstidy_print( &$css ) {
$this->__construct( $css );
}
/**
* Resets output_css and output_css_plain (new css code)
*
* @access private
* @version 1.0
*/
public function _reset() { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
$this->output_css = '';
$this->output_css_plain = '';
}
/**
* Returns the CSS code as plain text
*
* @param string $default_media default @media to add to selectors without any @media.
* @return string
* @access public
* @version 1.0
*/
public function plain( $default_media = '' ) {
$this->_print( true, $default_media );
return $this->output_css_plain;
}
/**
* Returns the formatted CSS code
*
* @param string $default_media default @media to add to selectors without any @media.
* @return string
* @access public
* @version 1.0
*/
public function formatted( $default_media = '' ) {
$this->_print( false, $default_media );
return $this->output_css;
}
/**
* Returns the formatted CSS code to make a complete webpage
*
* @param string $doctype shorthand for the document type.
* @param bool $externalcss indicates whether styles to be attached internally or as an external stylesheet.
* @param string $title title to be added in the head of the document.
* @param string $lang two-letter language code to be added to the output.
* @return string
* @access public
* @version 1.4
*/
public function formatted_page( $doctype = 'xhtml1.1', $externalcss = true, $title = '', $lang = 'en' ) {
switch ( $doctype ) {
case 'xhtml1.0strict':
$doctype_output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
break;
case 'xhtml1.1':
default:
$doctype_output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
break;
}
$cssparsed = '';
$output = '';
$this->output_css_plain = & $output;
$output .= $doctype_output . "\n" . '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . $lang . '"';
$output .= ( $doctype === 'xhtml1.1' ) ? '>' : ' lang="' . $lang . '">';
$output .= "\n<head>\n <title>$title</title>";
if ( $externalcss ) {
$output .= "\n <style type=\"text/css\">\n";
$cssparsed = file_get_contents( 'cssparsed.css' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$output .= $cssparsed; // Adds an invisible BOM or something, but not in css_optimised.php
$output .= "\n</style>";
} else {
$output .= "\n" . ' <link rel="stylesheet" type="text/css" href="cssparsed.css" />'; // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet
// }
}
$output .= "\n</head>\n<body><code id=\"copytext\">";
$output .= $this->formatted();
$output .= '</code>' . "\n" . '</body></html>';
return $this->output_css_plain;
}
/**
* Returns the formatted CSS Code and saves it into $this->output_css and $this->output_css_plain
*
* @param bool $plain plain text or not.
* @param string $default_media default @media to add to selectors without any @media.
* @access private
* @version 2.0
*/
public function _print( $plain = false, $default_media = '' ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore -- print is a reserved word anyway.
if ( $this->output_css && $this->output_css_plain ) {
return;
}
$output = '';
if ( ! $this->parser->get_cfg( 'preserve_css' ) ) {
$this->convert_raw_css( $default_media );
}
$template = & $this->template;
if ( $plain ) {
$template = array_map( 'strip_tags', $template );
}
if ( $this->parser->get_cfg( 'timestamp' ) ) {
array_unshift( $this->tokens, array( COMMENT, ' CSSTidy ' . $this->parser->version . ': ' . gmdate( 'r' ) . ' ' ) );
}
if ( ! empty( $this->charset ) ) {
$output .= $template[0] . '@charset ' . $template[5] . $this->charset . $template[6];
}
if ( ! empty( $this->import ) ) {
for ( $i = 0, $size = count( $this->import ); $i < $size; $i++ ) {
$import_components = explode( ' ', $this->import[ $i ] );
if ( substr( $import_components[0], 0, 4 ) === 'url(' && substr( $import_components[0], -1, 1 ) === ')' ) {
$import_components[0] = '\'' . trim( substr( $import_components[0], 4, -1 ), "'\"" ) . '\'';
$this->import[ $i ] = implode( ' ', $import_components );
$this->parser->log( 'Optimised @import : Removed "url("', 'Information' );
}
$output .= $template[0] . '@import ' . $template[5] . $this->import[ $i ] . $template[6];
}
}
if ( ! empty( $this->namespace ) ) {
if ( substr( $this->namespace, 0, 4 ) === 'url(' && substr( $this->namespace, -1, 1 ) === ')' ) {
$this->namespace = '\'' . substr( $this->namespace, 4, -1 ) . '\'';
$this->parser->log( 'Optimised @namespace : Removed "url("', 'Information' );
}
$output .= $template[0] . '@namespace ' . $template[5] . $this->namespace . $template[6];
}
$output .= $template[13];
$in_at_out = '';
$out = & $output;
foreach ( $this->tokens as $key => $token ) {
switch ( $token[0] ) {
case AT_START:
$out .= $template[0] . $this->htmlsp( $token[1], $plain ) . $template[1];
$out = & $in_at_out;
break;
case SEL_START:
if ( $this->parser->get_cfg( 'lowercase_s' ) ) {
$token[1] = strtolower( $token[1] );
}
$out .= ( $token[1][0] !== '@' ) ? $template[2] . $this->htmlsp( $token[1], $plain ) : $template[0] . $this->htmlsp( $token[1], $plain );
$out .= $template[3];
break;
case PROPERTY:
if ( $this->parser->get_cfg( 'case_properties' ) === 2 ) {
$token[1] = strtoupper( $token[1] );
} elseif ( $this->parser->get_cfg( 'case_properties' ) === 1 ) {
$token[1] = strtolower( $token[1] );
}
$out .= $template[4] . $this->htmlsp( $token[1], $plain ) . ':' . $template[5];
break;
case VALUE:
$out .= $this->htmlsp( $token[1], $plain );
if ( $this->seeknocomment( $key, 1 ) === SEL_END && $this->parser->get_cfg( 'remove_last_;' ) ) {
$out .= str_replace( ';', '', $template[6] );
} else {
$out .= $template[6];
}
break;
case SEL_END:
$out .= $template[7];
if ( $this->seeknocomment( $key, 1 ) !== AT_END ) {
$out .= $template[8];
}
break;
case AT_END:
$out = & $output;
$out .= $template[10] . str_replace( "\n", "\n" . $template[10], $in_at_out );
$in_at_out = '';
$out .= $template[9];
break;
case COMMENT:
$out .= $template[11] . '/*' . $this->htmlsp( $token[1], $plain ) . '*/' . $template[12];
break;
}
}
$output = trim( $output );
if ( ! $plain ) {
$this->output_css = $output;
$this->_print( true );
} else {
// If using spaces in the template, don't want these to appear in the plain output
$this->output_css_plain = str_replace( '&#160;', '', $output );
}
}
/**
* Gets the next token type which is $move away from $key, excluding comments
*
* @param integer $key current position.
* @param integer $move move this far.
* @return mixed a token type
* @access private
* @version 1.0
*/
public function seeknocomment( $key, $move ) {
$go = ( $move > 0 ) ? 1 : -1;
for ( $i = $key + 1; abs( $key - $i ) - 1 < abs( $move ); $i += $go ) { // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
if ( ! isset( $this->tokens[ $i ] ) ) {
return;
}
if ( $this->tokens[ $i ][0] === COMMENT ) {
++$move;
continue;
}
return $this->tokens[ $i ][0];
}
}
/**
* Converts $this->css array to a raw array ($this->tokens)
*
* @param string $default_media default @media to add to selectors without any @media.
* @access private
* @version 1.0
*/
public function convert_raw_css( $default_media = '' ) {
$this->tokens = array();
foreach ( $this->css as $medium => $val ) {
if ( $this->parser->get_cfg( 'sort_selectors' ) ) {
ksort( $val );
}
if ( (int) $medium < DEFAULT_AT ) {
$this->parser->_add_token( AT_START, $medium, true );
} elseif ( $default_media ) {
$this->parser->_add_token( AT_START, $default_media, true );
}
foreach ( $val as $selector => $vali ) {
if ( $this->parser->get_cfg( 'sort_properties' ) ) {
ksort( $vali );
}
$this->parser->_add_token( SEL_START, $selector, true );
foreach ( $vali as $property => $valj ) {
$this->parser->_add_token( PROPERTY, $property, true );
$this->parser->_add_token( VALUE, $valj, true );
}
$this->parser->_add_token( SEL_END, $selector, true );
}
if ( (int) $medium < DEFAULT_AT ) {
$this->parser->_add_token( AT_END, $medium, true );
} elseif ( $default_media ) {
$this->parser->_add_token( AT_END, $default_media, true );
}
}
}
/**
* Same as htmlspecialchars, only that chars are not replaced if $plain !== true. This makes print_code() cleaner.
*
* @param string $string - the string we're converting.
* @param bool $plain - plain text or not.
* @return string
* @see csstidy_print::_print()
* @access private
* @version 1.0
*/
public function htmlsp( $string, $plain ) {
if ( ! $plain ) {
return htmlspecialchars( $string, ENT_QUOTES, 'utf-8' );
}
return $string;
}
/**
* Get compression ratio
*
* @access public
* @return float
* @version 1.2
*/
public function get_ratio() {
if ( ! $this->output_css_plain ) {
$this->formatted();
}
return round( ( strlen( $this->input_css ) - strlen( $this->output_css_plain ) ) / strlen( $this->input_css ), 3 ) * 100;
}
/**
* Get difference between the old and new code in bytes and prints the code if necessary.
*
* @access public
* @return string
* @version 1.1
*/
public function get_diff() {
if ( ! $this->output_css_plain ) {
$this->formatted();
}
$diff = strlen( $this->output_css_plain ) - strlen( $this->input_css );
if ( $diff > 0 ) {
return '+' . $diff;
} elseif ( $diff === 0 ) {
return '+-' . $diff;
}
return $diff;
}
/**
* Get the size of either input or output CSS in KB
*
* @param string $loc default is "output".
* @access public
* @return integer
* @version 1.0
*/
public function size( $loc = 'output' ) {
if ( $loc === 'output' && ! $this->output_css ) {
$this->formatted();
}
if ( $loc === 'input' ) {
return ( strlen( $this->input_css ) / 1000 );
} else {
return ( strlen( $this->output_css_plain ) / 1000 );
}
}
}
This diff is collapsed.
code#copytext {
white-space: pre;
font-family: Verdana;
}
.at {
color: darkblue;
}
.format {
color: gray;
}
.property {
color: green;
}
.selector {
color: blue;
}
.value {
color: red;
right: 500px;
}
.comment {
color: orange;
}
html, body {
font: 0.8em Verdana, Helvetica, sans-serif;
background: #F8F8F6;
}
code {
font-size: 1.2em;
}
div#rightcol {
padding-right: 32em;
}
fieldset {
display: block;
margin: 0.5em 0;
padding: 1em;
border: solid #7284AB 2px;
}
fieldset.code_output {
display: inline;
}
h1 {
font-size: 2em;
}
small {
font-size: 0.7em;
}
fieldset#field_input {
float: right;
margin: 0 0 1em 0.5em;
}
fieldset#options, fieldset#code_layout {
width: 31em;
}
input#submit {
clear: both;
display: block;
margin: 1em;
}
select {
margin: 2px 0 0;
}
label.block {
display: block;
}
legend {
background: #c4E1C3;
padding: 2px 4px;
border: dashed 1px;
}
textarea#css_text {
width: 27em;
height: 370px;
display: block;
margin-left: 1em;
}
.help {
cursor: help;
}
p.important {
border: solid 1px red;
font-weight: bold;
padding: 1em;
background: white;
}
p {
margin: 1em 0;
}
dl {
padding-right: 0.5em;
}
dt {
font-weight: bold;
margin: 0;
float: right;
clear: both;
height: 1.5em;
}
dd {
margin: 0 4em 0 0;
height: 1.5em;
}
fieldset#messages {
background: white;
padding: 0 1em 0 0;
}
fieldset#messages div {
height: 10em;
overflow: auto;
}
dd.Warning {
color: orange;
}
dd.Information {
color: green;
}
code#copytext{font-family:Verdana;white-space:pre}.at{color:#00008b}.format{color:gray}.property{color:green}.selector{color:blue}.value{color:red;right:500px}.comment{color:orange}body,html{background:#f8f8f6;font:.8em Verdana,Helvetica,sans-serif}code{font-size:1.2em}div#rightcol{padding-right:32em}fieldset{border:2px solid #7284ab;display:block;margin:.5em 0;padding:1em}fieldset.code_output{display:inline}h1{font-size:2em}small{font-size:.7em}fieldset#field_input{float:right;margin:0 0 1em .5em}fieldset#code_layout,fieldset#options{width:31em}input#submit{clear:both;display:block;margin:1em}select{margin:2px 0 0}label.block{display:block}legend{background:#c4e1c3;border:1px dashed;padding:2px 4px}textarea#css_text{display:block;height:370px;margin-left:1em;width:27em}.help{cursor:help}p.important{background:#fff;border:1px solid red;font-weight:700;padding:1em}p{margin:1em 0}dl{padding-right:.5em}dt{clear:both;float:right;font-weight:700;margin:0}dd,dt{height:1.5em}dd{margin:0 4em 0 0}fieldset#messages{background:#fff;padding:0 1em 0 0}fieldset#messages div{height:10em;overflow:auto}dd.Warning{color:orange}dd.Information{color:green}
\ No newline at end of file
@import url("./cssparsed.css");
html, body {
font:0.8em Verdana,Helvetica,sans-serif;
background:#F8F8F6;
}
code {
font-size:1.2em;
}
div#rightcol {
padding-left:32em;
}
fieldset {
display:block;
margin:0.5em 0;
padding:1em;
border:solid #7284AB 2px;
}
fieldset.code_output {
display:inline;
}
h1 {
font-size:2em;
}
small {
font-size:0.7em;
}
fieldset#field_input {
float:left;
margin:0 0.5em 1em 0;
}
fieldset#options,fieldset#code_layout {
width:31em;
}
input#submit {
clear:both;
display:block;
margin:1em;
}
select {
margin:2px 0 0;
}
label.block {
display:block;
}
legend {
background:#c4E1C3;
padding:2px 4px;
border:dashed 1px;
}
textarea#css_text {
width:27em;
height:370px;
display:block;
margin-right:1em;
}
.help {
cursor:help;
}
p.important {
border:solid 1px red;
font-weight:bold;
padding:1em;
background:white;
}
p {
margin:1em 0;
}
dl {
padding-left:0.5em;
}
dt {
font-weight:bold;
margin:0;
float:left;
clear:both;
height:1.5em;
}
dd {
margin:0 0 0 4em;
height:1.5em;
}
fieldset#messages {
background:white;
padding:0 0 0 1em;
}
fieldset#messages div {
height:10em;
overflow:auto;
}
dd.Warning {
color:orange;
}
dd.Information {
color:green;
}
code#copytext{font-family:Verdana;white-space:pre}.at{color:#00008b}.format{color:gray}.property{color:green}.selector{color:blue}.value{color:red;left:500px}.comment{color:orange}body,html{background:#f8f8f6;font:.8em Verdana,Helvetica,sans-serif}code{font-size:1.2em}div#rightcol{padding-left:32em}fieldset{border:2px solid #7284ab;display:block;margin:.5em 0;padding:1em}fieldset.code_output{display:inline}h1{font-size:2em}small{font-size:.7em}fieldset#field_input{float:left;margin:0 .5em 1em 0}fieldset#code_layout,fieldset#options{width:31em}input#submit{clear:both;display:block;margin:1em}select{margin:2px 0 0}label.block{display:block}legend{background:#c4e1c3;border:1px dashed;padding:2px 4px}textarea#css_text{display:block;height:370px;margin-right:1em;width:27em}.help{cursor:help}p.important{background:#fff;border:1px solid red;font-weight:700;padding:1em}p{margin:1em 0}dl{padding-left:.5em}dt{clear:both;float:left;font-weight:700;margin:0}dd,dt{height:1.5em}dd{margin:0 0 0 4em}fieldset#messages{background:#fff;padding:0 0 0 1em}fieldset#messages div{height:10em;overflow:auto}dd.Warning{color:orange}dd.Information{color:green}
\ No newline at end of file
code#copytext {
white-space: pre;
font-family: Verdana;
}
.at {
color: darkblue;
}
.format {
color: gray;
}
.property {
color: green;
}
.selector {
color: blue;
}
.value {
color: red;
right: 500px;
}
.comment {
color: orange;
}
code#copytext{font-family:Verdana;white-space:pre}.at{color:#00008b}.format{color:gray}.property{color:green}.selector{color:blue}.value{color:red;right:500px}.comment{color:orange}
\ No newline at end of file
code#copytext {
white-space: pre;
font-family: Verdana;
}
.at {
color:darkblue;
}
.format {
color:gray;
}
.property {
color:green;
}
.selector {
color:blue;
}
.value {
color:red;
left: 500px;
}
.comment {
color:orange;
}
\ No newline at end of file
code#copytext{font-family:Verdana;white-space:pre}.at{color:#00008b}.format{color:gray}.property{color:green}.selector{color:blue}.value{color:red;left:500px}.comment{color:orange}
\ No newline at end of file
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
unset( $GLOBALS['csstidy']['all_properties']['binding'] );
$GLOBALS['csstidy']['all_properties']['text-size-adjust'] = 'CSS3.0';
// Support browser prefixes for properties only in the latest CSS draft
foreach ( $GLOBALS['csstidy']['all_properties'] as $property => $levels ) {
if ( strpos( $levels, ',' ) === false ) {
$GLOBALS['csstidy']['all_properties'][ '-moz-' . $property ] = $levels;
$GLOBALS['csstidy']['all_properties'][ '-webkit-' . $property ] = $levels;
$GLOBALS['csstidy']['all_properties'][ '-ms-' . $property ] = $levels;
$GLOBALS['csstidy']['all_properties'][ '-o-' . $property ] = $levels;
$GLOBALS['csstidy']['all_properties'][ '-khtml-' . $property ] = $levels;
if ( in_array( $property, $GLOBALS['csstidy']['unit_values'], true ) ) {
$GLOBALS['csstidy']['unit_values'][] = '-moz-' . $property;
$GLOBALS['csstidy']['unit_values'][] = '-webkit-' . $property;
$GLOBALS['csstidy']['unit_values'][] = '-ms-' . $property;
$GLOBALS['csstidy']['unit_values'][] = '-o-' . $property;
$GLOBALS['csstidy']['unit_values'][] = '-khtml-' . $property;
}
if ( in_array( $property, $GLOBALS['csstidy']['color_values'], true ) ) {
$GLOBALS['csstidy']['color_values'][] = '-moz-' . $property;
$GLOBALS['csstidy']['color_values'][] = '-webkit-' . $property;
$GLOBALS['csstidy']['color_values'][] = '-ms-' . $property;
$GLOBALS['csstidy']['color_values'][] = '-o-' . $property;
$GLOBALS['csstidy']['color_values'][] = '-khtml-' . $property;
}
}
}
// Add `display` to the list of properties that can be used multiple times in a single selector
$GLOBALS['csstidy']['multiple_properties'][] = 'display';
// Allow vendor prefixes for any property that is allowed to be used multiple times inside a single selector
foreach ( $GLOBALS['csstidy']['multiple_properties'] as $property ) {
if ( '-' !== $property[0] ) {
$GLOBALS['csstidy']['multiple_properties'][] = '-o-' . $property;
$GLOBALS['csstidy']['multiple_properties'][] = '-ms-' . $property;
$GLOBALS['csstidy']['multiple_properties'][] = '-webkit-' . $property;
$GLOBALS['csstidy']['multiple_properties'][] = '-moz-' . $property;
$GLOBALS['csstidy']['multiple_properties'][] = '-khtml-' . $property;
}
}
/**
* CSS Animation
*
* @see https://developer.mozilla.org/en/CSS/CSS_animations
*/
$GLOBALS['csstidy']['at_rules']['-webkit-keyframes'] = 'at';
$GLOBALS['csstidy']['at_rules']['-moz-keyframes'] = 'at';
$GLOBALS['csstidy']['at_rules']['-ms-keyframes'] = 'at';
$GLOBALS['csstidy']['at_rules']['-o-keyframes'] = 'at';
/**
* Non-standard viewport rule.
*/
$GLOBALS['csstidy']['at_rules']['viewport'] = 'is';
$GLOBALS['csstidy']['at_rules']['-webkit-viewport'] = 'is';
$GLOBALS['csstidy']['at_rules']['-moz-viewport'] = 'is';
$GLOBALS['csstidy']['at_rules']['-ms-viewport'] = 'is';
/**
* Non-standard CSS properties. They're not part of any spec, but we say
* they're in all of them so that we can support them.
*/
$GLOBALS['csstidy']['all_properties']['-webkit-filter'] = 'CSS2.0,CSS2.1,CSS3.0';
$GLOBALS['csstidy']['all_properties']['-moz-filter'] = 'CSS2.0,CSS2.1,CSS3.0';
$GLOBALS['csstidy']['all_properties']['-ms-filter'] = 'CSS2.0,CSS2.1,CSS3.0';
$GLOBALS['csstidy']['all_properties']['filter'] = 'CSS2.0,CSS2.1,CSS3.0';
$GLOBALS['csstidy']['all_properties']['scrollbar-face-color'] = 'CSS2.0,CSS2.1,CSS3.0';
$GLOBALS['csstidy']['all_properties']['-ms-interpolation-mode'] = 'CSS2.0,CSS2.1,CSS3.0';
$GLOBALS['csstidy']['all_properties']['text-rendering'] = 'CSS2.0,CSS2.1,CSS3.0';
$GLOBALS['csstidy']['all_properties']['-webkit-transform-origin-x'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['-webkit-transform-origin-y'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['-webkit-transform-origin-z'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['-webkit-font-smoothing'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['-moz-osx-font-smoothing'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['-font-smooth'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['-o-object-fit'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['object-fit'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['-o-object-position'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['object-position'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['text-overflow'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['zoom'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['pointer-events'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['font-feature-settings'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['font-kerning'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['font-language-override'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['font-synthesis'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['font-variant-alternates'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['font-variant-caps'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['font-variant-east-asian'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['font-variant-ligatures'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['font-variant-numeric'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['font-variant-position'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['font-variation-settings'] = 'CSS3.0';
$GLOBALS['csstidy']['all_properties']['line-height-step'] = 'CSS3.0';
This diff is collapsed.
<?php
/**
* Localization of CSS Optimiser Interface of CSSTidy
*
* Copyright 2005, 2006, 2007 Florian Schmitz
*
* This file is part of CSSTidy.
*
* CSSTidy is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* CSSTidy is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @license https://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
* @package csstidy
* @author Florian Schmitz (floele at gmail dot com) 2005-2007, Brett Zamir (brettz9 at yahoo dot com) 2007
*/
if ( isset( $_GET['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no changes made to the site, determening language for translations.
$l = sanitize_text_field( wp_unslash( $_GET['lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no changes made to the site, determining language for translations.
} elseif ( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) {
$l = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$l = strtolower( substr( $l, 0, 2 ) );
} else {
$l = '';
}
$l = ( in_array( $l, array( 'de', 'fr', 'zh' ), true ) ) ? $l : 'en';
// note 5 in all but French, and 40 in all are orphaned
$lang = array();
$lang['en'][0] = 'CSS Formatter and Optimiser/Optimizer (based on CSSTidy ';
$lang['en'][1] = 'CSS Formatter and Optimiser';
$lang['en'][2] = '(based on';
$lang['en'][3] = '(plaintext)';
$lang['en'][4] = 'Important Note:';
$lang['en'][6] = 'Your code should be well-formed. This is <strong>not a validator</strong> which points out errors in your CSS code. To make sure that your code is valid, use the <a href="https://jigsaw.w3.org/css-validator/">W3C Validator</a>.';
$lang['en'][7] = 'all comments are removed';
$lang['en'][8] = 'CSS Input:';
$lang['en'][9] = 'CSS-Code:';
$lang['en'][10] = 'CSS from URL:';
$lang['en'][11] = 'Code Layout:';
$lang['en'][12] = 'Compression&#160;(code&#160;layout):';
$lang['en'][13] = 'Highest (no readability, smallest size)';
$lang['en'][14] = 'High (moderate readability, smaller size)';
$lang['en'][15] = 'Standard (balance between readability and size)';
$lang['en'][16] = 'Low (higher readability)';
$lang['en'][17] = 'Custom (enter below)';
$lang['en'][18] = 'Custom <a href="http://csstidy.sourceforge.net/templates.php">template</a>';
$lang['en'][19] = 'Options';
$lang['en'][20] = 'Sort Selectors (caution)';
$lang['en'][21] = 'Sort Properties';
$lang['en'][22] = 'Regroup selectors';
$lang['en'][23] = 'Optimise shorthands';
$lang['en'][24] = 'Compress colors';
$lang['en'][25] = 'Lowercase selectors';
$lang['en'][26] = 'Case for properties:';
$lang['en'][27] = 'Lowercase';
$lang['en'][28] = 'No or invalid CSS input or wrong URL!';
$lang['en'][29] = 'Uppercase';
$lang['en'][30] = 'lowercase elementnames needed for XHTML';
$lang['en'][31] = 'Remove unnecessary backslashes';
$lang['en'][32] = 'convert !important-hack';
$lang['en'][33] = 'Output as file';
$lang['en'][34] = 'Bigger compression because of smaller newlines (copy &#38; paste doesn\'t work)';
$lang['en'][35] = 'Process CSS';
$lang['en'][36] = 'Compression Ratio';
$lang['en'][37] = 'Input';
$lang['en'][38] = 'Output';
$lang['en'][39] = 'Language';
$lang['en'][41] = 'Attention: This may change the behavior of your CSS Code!';
$lang['en'][42] = 'Remove last ;';
$lang['en'][43] = 'Discard invalid properties';
$lang['en'][44] = 'Only safe optimisations';
$lang['en'][45] = 'Compress font-weight';
$lang['en'][46] = 'Save comments';
$lang['en'][47] = 'Do not change anything';
$lang['en'][48] = 'Only separate selectors (split at ,)';
$lang['en'][49] = 'Merge selectors with the same properties (fast)';
$lang['en'][50] = 'Merge selectors intelligently (slow)';
$lang['en'][51] = 'Preserve CSS';
$lang['en'][52] = 'Save comments, hacks, etc. Most optimisations can *not* be applied if this is enabled.';
$lang['en'][53] = 'None';
$lang['en'][54] = 'Don\'t optimise';
$lang['en'][55] = 'Safe optimisations';
$lang['en'][56] = 'All optimisations';
$lang['en'][57] = 'Add timestamp';
$lang['en'][58] = 'Copy to clipboard';
$lang['en'][59] = 'Back to top';
$lang['en'][60] = 'Your browser doesn\'t support copy to clipboard.';
$lang['en'][61] = 'For bugs and suggestions feel free to';
$lang['en'][62] = 'contact me';
$lang['en'][63] = 'Output CSS code as complete HTML document';
$lang['en'][64] = 'Code';
$lang['en'][65] = 'CSS to style CSS output';
$lang['en'][66] = 'You need to go to about:config in your URL bar, select \'signed.applets.codebase_principal_support\' in the filter field, and set its value to true in order to use this feature; however, be aware that doing so increases security risks.';
$lang['de'][0] = 'CSS Formatierer und Optimierer (basierend auf CSSTidy ';
$lang['de'][1] = 'CSS Formatierer und Optimierer';
$lang['de'][2] = '(basierend auf';
$lang['de'][3] = '(Textversion)';
$lang['de'][4] = 'Wichtiger Hinweis:';
$lang['de'][6] = 'Der CSS Code sollte wohlgeformt sein. Der CSS Code wird <strong>nicht auf Gültigkeit überprüft</strong>. Um sicherzugehen dass dein Code valide ist, benutze den <a href="https://jigsaw.w3.org/css-validator/">W3C Validierungsservice</a>.';
$lang['de'][7] = 'alle Kommentare werden entfernt';
$lang['de'][8] = 'CSS Eingabe:';
$lang['de'][9] = 'CSS-Code:';
$lang['de'][10] = 'CSS von URL:';
$lang['de'][11] = 'Code Layout:';
$lang['de'][12] = 'Komprimierung&#160;(Code&#160;Layout):';
$lang['de'][13] = 'Höchste (keine Lesbarkeit, niedrigste Größe)';
$lang['de'][14] = 'Hoch (mittelmäßige Lesbarkeit, geringe Größe)';
$lang['de'][15] = 'Standard (Kompromiss zwischen Lesbarkeit und Größe)';
$lang['de'][16] = 'Niedrig (höhere Lesbarkeit)';
$lang['de'][17] = 'Benutzerdefiniert (unten eingeben)';
$lang['de'][18] = 'Benutzerdefinierte <a href="http://csstidy.sourceforge.net/templates.php">Vorlage</a>';
$lang['de'][19] = 'Optionen';
$lang['de'][20] = 'Selektoren sortieren (Vorsicht)';
$lang['de'][21] = 'Eigenschaften sortieren';
$lang['de'][22] = 'Selektoren umgruppieren';
$lang['de'][23] = 'Shorthands optimieren';
$lang['de'][24] = 'Farben komprimieren';
$lang['de'][25] = 'Selektoren in Kleinbuchstaben';
$lang['de'][26] = 'Groß-/Kleinschreibung für Eigenschaften';
$lang['de'][27] = 'Kleinbuchstaben';
$lang['de'][28] = 'Keine oder ungültige CSS Eingabe oder falsche URL!';
$lang['de'][29] = 'Großbuchstaben';
$lang['de'][30] = 'kleingeschriebene Elementnamen benötigt für XHTML';
$lang['de'][31] = 'Unnötige Backslashes entfernen';
$lang['de'][32] = '!important-Hack konvertieren';
$lang['de'][33] = 'Als Datei ausgeben';
$lang['de'][34] = 'Größere Komprimierung augrund von kleineren Neuezeile-Zeichen';
$lang['de'][35] = 'CSS verarbeiten';
$lang['de'][36] = 'Komprimierungsrate';
$lang['de'][37] = 'Eingabe';
$lang['de'][38] = 'Ausgabe';
$lang['de'][39] = 'Sprache';
$lang['de'][41] = 'Achtung: Dies könnte das Verhalten ihres CSS-Codes verändern!';
$lang['de'][42] = 'Letztes ; entfernen';
$lang['de'][43] = 'Ungültige Eigenschaften entfernen';
$lang['de'][44] = 'Nur sichere Optimierungen';
$lang['de'][45] = 'font-weight komprimieren';
$lang['de'][46] = 'Kommentare beibehalten';
$lang['de'][47] = 'Nichts ändern';
$lang['de'][48] = 'Selektoren nur trennen (am Komma)';
$lang['de'][49] = 'Selektoren mit gleichen Eigenschaften zusammenfassen (schnell)';
$lang['de'][50] = 'Selektoren intelligent zusammenfassen (langsam!)';
$lang['de'][51] = 'CSS erhalten';
$lang['de'][52] = 'Kommentare, Hacks, etc. speichern. Viele Optimierungen sind dann aber nicht mehr möglich.';
$lang['de'][53] = 'Keine';
$lang['de'][54] = 'Nicht optimieren';
$lang['de'][55] = 'Sichere Optimierungen';
$lang['de'][56] = 'Alle Optimierungen';
$lang['de'][57] = 'Zeitstempel hinzufügen';
$lang['de'][58] = 'Copy to clipboard';
$lang['de'][59] = 'Back to top';
$lang['de'][60] = 'Your browser doesn\'t support copy to clipboard.';
$lang['de'][61] = 'For bugs and suggestions feel free to';
$lang['de'][62] = 'contact me';
$lang['de'][63] = 'Output CSS code as complete HTML document';
$lang['de'][64] = 'Code';
$lang['de'][65] = 'CSS to style CSS output';
$lang['de'][66] = 'You need to go to about:config in your URL bar, select \'signed.applets.codebase_principal_support\' in the filter field, and set its value to true in order to use this feature; however, be aware that doing so increases security risks.';
$lang['fr'][0] = 'CSS Formatteur et Optimiseur (basé sur CSSTidy ';
$lang['fr'][1] = 'CSS Formatteur et Optimiseur';
$lang['fr'][2] = '(basé sur ';
$lang['fr'][3] = '(Version texte)';
$lang['fr'][4] = 'Note Importante&#160;:';
$lang['fr'][6] = 'Votre code doit être valide. Ce n’est <strong>pas un validateur</strong> qui signale les erreurs dans votre code CSS. Pour être sûr que votre code est correct, utilisez le validateur&#160;: <a href="https://jigsaw.w3.org/css-validator/">W3C Validator</a>.';
$lang['fr'][7] = 'tous les commentaires sont enlevés';
$lang['fr'][8] = 'Champ CSS&#160;:';
$lang['fr'][9] = 'Code CSS&#160;:';
$lang['fr'][10] = 'CSS en provenance d’une URL&#160;:<br />';
$lang['fr'][11] = 'Mise en page du code&#160;:';
$lang['fr'][12] = 'Compression (mise en page du code)&#160;:';
$lang['fr'][13] = 'La plus élevée (aucune lisibilité, taille minimale)';
$lang['fr'][14] = 'Élevée (lisibilité modérée, petite taille)';
$lang['fr'][15] = 'Normale (équilibre entre lisibilité et taille)';
$lang['fr'][16] = 'Faible (lisibilité élevée)';
$lang['fr'][17] = 'Sur mesure (entrer ci-dessous)';
$lang['fr'][18] = '<a href="http://csstidy.sourceforge.net/templates.php">Gabarit</a> sur mesure';
$lang['fr'][19] = 'Options';
$lang['fr'][20] = 'Trier les sélecteurs (attention)';
$lang['fr'][21] = 'Trier les propriétés';
$lang['fr'][22] = 'Regrouper les sélecteurs';
$lang['fr'][23] = 'Propriétés raccourcies';
$lang['fr'][24] = 'Compresser les couleurs';
$lang['fr'][25] = 'Sélecteurs en minuscules';
$lang['fr'][26] = 'Case pour les propriétés&#160;:';
$lang['fr'][27] = 'Minuscule';
$lang['fr'][28] = 'CSS non valide ou URL incorrecte&#160;!';
$lang['fr'][29] = 'Majuscule';
$lang['fr'][30] = 'les noms des éléments en minuscules (indispensables pour XHTML)';
$lang['fr'][31] = 'enlever les antislashs inutiles';
$lang['fr'][32] = 'convertir !important-hack';
$lang['fr'][33] = 'Sauver en tant que fichier';
$lang['fr'][34] = 'Meilleure compression grâce aux caractères de saut de ligne plus petits (copier &#38; coller ne marche pas)';
$lang['fr'][35] = 'Compresser la CSS';
$lang['fr'][36] = 'Facteur de Compression';
$lang['fr'][37] = 'Entrée';
$lang['fr'][38] = 'Sortie';
$lang['fr'][39] = 'Langue';
$lang['fr'][41] = 'Attention&#160;: ceci peut changer le comportement de votre code CSS&#160;!';
$lang['fr'][42] = 'Enlever le dernier ;';
$lang['fr'][43] = 'Supprimer les propriétés non valide';
$lang['fr'][44] = 'Seulement les optimisations sûres';
$lang['fr'][45] = 'Compresser font-weight';
$lang['fr'][46] = 'Sauvegarder les commentaires ';
$lang['fr'][47] = 'Ne rien changer';
$lang['fr'][48] = 'Sépare les sélecteurs (sépare au niveau de ,)';
$lang['fr'][49] = 'Fusionne les sélecteurs avec les mêmes propriétés (rapide)';
$lang['fr'][50] = 'Fusionne les sélecteurs intelligemment (lent)';
$lang['fr'][51] = 'Préserver la CSS';
$lang['fr'][52] = 'Sauvegarder les commentaires, hacks, etc. La plupart des optimisations ne peuvent *pas* être appliquées si cela est activé.';
$lang['fr'][53] = 'Aucun';
$lang['fr'][54] = 'Ne pas optimiser';
$lang['fr'][55] = 'Optimisations sûres';
$lang['fr'][56] = 'Toutes les optimisations';
$lang['fr'][57] = 'Ajouter un timestamp';
$lang['fr'][58] = 'Copier dans le presse-papiers';
$lang['fr'][59] = 'Retour en haut';
$lang['fr'][60] = 'Votre navigateur ne suporte pas la copie vers le presse-papiers.';
$lang['fr'][61] = 'Pour signaler des bugs ou pour des suggestions,';
$lang['fr'][62] = 'contactez-moi';
$lang['fr'][63] = 'Sauver le code CSS comme document complet HTML';
$lang['fr'][64] = 'Code';
$lang['fr'][65] = 'CSS pour colorier la sortie CSS';
$lang['fr'][66] = 'Vous devez aller dans about:config dans votre barre d’adresse, selectionner \'signed.applets.codebase_principal_support\' dans le champ Filtre et attribuez-lui la valeur \'true\' pour utiliser cette fonctionnalité; toutefois, soyez conscient que cela augmente les risques de sécurité.';
$lang['zh'][0] = 'CSS整形與最佳化工具(使用 CSSTidy ';
$lang['zh'][1] = 'CSS整形與最佳化工具';
$lang['zh'][2] = '(使用';
$lang['zh'][3] = '(純文字)';
$lang['zh'][4] = '重要事項:';
$lang['zh'][6] = '你的原始碼必須是良構的(well-formed). 這個工具<strong>沒有內建驗證器(validator)</strong>. 驗證器能夠指出你CSS原始碼裡的錯誤. 請使用 <a href="https://jigsaw.w3.org/css-validator/">W3C 驗證器</a>, 確保你的原始碼合乎規範.';
$lang['zh'][7] = '所有註解都移除了';
$lang['zh'][8] = 'CSS 輸入:';
$lang['zh'][9] = 'CSS 原始碼:';
$lang['zh'][10] = 'CSS 檔案網址(URL):';
$lang['zh'][11] = '原始碼規劃:';
$lang['zh'][12] = '壓縮程度(原始碼規劃):';
$lang['zh'][13] = '最高 (沒有辦法讀, 檔案最小)';
$lang['zh'][14] = '高 (適度的可讀性, 檔案小)';
$lang['zh'][15] = '標準 (兼顧可讀性與檔案大小)';
$lang['zh'][16] = '低 (注重可讀性)';
$lang['zh'][17] = '自訂 (在下方設定)';
$lang['zh'][18] = '自訂<a href="http://csstidy.sourceforge.net/templates.php">樣板</a>';
$lang['zh'][19] = '選項';
$lang['zh'][20] = '整理選擇符(請謹慎使用)';
$lang['zh'][21] = '整理屬性';
$lang['zh'][22] = '重組選擇符';
$lang['zh'][23] = '速記法(shorthand)最佳化';
$lang['zh'][24] = '壓縮色彩語法';
$lang['zh'][25] = '改用小寫選擇符';
$lang['zh'][26] = '屬性的字形:';
$lang['zh'][27] = '小寫';
$lang['zh'][28] = '沒有輸入CSS, 語法不符合規定, 或是網址錯誤!';
$lang['zh'][29] = '大寫';
$lang['zh'][30] = 'XHTML必須使用小寫的元素名稱';
$lang['zh'][31] = '移除不必要的反斜線';
$lang['zh'][32] = '轉換 !important-hack';
$lang['zh'][33] = '輸出成檔案形式';
$lang['zh'][34] = '由於比較少換行字元, 會有更大的壓縮比率(複製&#38;貼上沒有用)';
$lang['zh'][35] = '執行';
$lang['zh'][36] = '壓縮比率';
$lang['zh'][37] = '輸入';
$lang['zh'][38] = '輸出';
$lang['zh'][39] = '語言';
$lang['zh'][41] = '注意: 這或許會變更你CSS原始碼的行為!';
$lang['zh'][42] = '除去最後一個分號';
$lang['zh'][43] = '拋棄不符合規定的屬性';
$lang['zh'][44] = '只安全地最佳化';
$lang['zh'][45] = '壓縮 font-weight';
$lang['zh'][46] = '保留註解';
$lang['zh'][47] = '什麼都不要改';
$lang['zh'][48] = '只分開原本用逗號分隔的選擇符';
$lang['zh'][49] = '合併有相同屬性的選擇符(快速)';
$lang['zh'][50] = '聰明地合併選擇符(慢速)';
$lang['zh'][51] = '保護CSS';
$lang['zh'][52] = '保留註解與 hack 等等. 如果啟用這個選項, 大多數的最佳化程序都不會執行.';
$lang['zh'][53] = '不改變';
$lang['zh'][54] = '不做最佳化';
$lang['zh'][55] = '安全地最佳化';
$lang['zh'][56] = '全部最佳化';
$lang['zh'][57] = '加上時間戳記';
$lang['zh'][58] = '复制到剪贴板';
$lang['zh'][59] = '回到页面上方';
$lang['zh'][60] = '你的浏览器不支持复制到剪贴板。';
$lang['zh'][61] = '如果程序有错误或你有建议,欢迎';
$lang['zh'][62] = '和我联系';
$lang['zh'][63] = 'Output CSS code as complete HTML document';
$lang['zh'][64] = '代码';
$lang['zh'][65] = 'CSS to style CSS output';
$lang['zh'][66] = 'You need to go to about:config in your URL bar, select \'signed.applets.codebase_principal_support\' in the filter field, and set its value to true in order to use this feature; however, be aware that doing so increases security risks.';
| {
|| {
| | |;
|}|
|
}
| ||
|
<?php
/*
* Plugin Name: A/I - Sanitize Custom CSS
* Description: Sanitize Custom CSS by preventing url() references
* Version: 0.0.1
* Author: Autistici/Inventati
* Author URI: https://autistici.org
*/
// The following code is heavily inspired by the Jetpack plugin custom-css module.
function ai_sanitize_css( $css, $args = array() ) {
require_once(__DIR__ . '/csstidy/class.csstidy.php');
$args = wp_parse_args(
$args,
array(
'force' => false,
)
);
if ($args['force'] || !current_user_can('unfiltered_html')) {
$warnings = array();
safecss_class();
$csstidy = new csstidy();
$csstidy->optimise = new safecss( $csstidy );
$csstidy->set_cfg( 'remove_bslash', false );
$csstidy->set_cfg( 'compress_colors', false );
$csstidy->set_cfg( 'compress_font-weight', false );
$csstidy->set_cfg( 'optimise_shorthands', 0 );
$csstidy->set_cfg( 'remove_last_;', false );
$csstidy->set_cfg( 'case_properties', false );
$csstidy->set_cfg( 'discard_invalid_properties', true );
$csstidy->set_cfg( 'css_level', 'CSS3.0' );
$csstidy->set_cfg( 'preserve_css', true );
$csstidy->set_cfg( 'template', __DIR__ . '/csstidy/wordpress-standard.tpl' );
// Test for some preg_replace stuff.
$prev = $css;
$css = preg_replace( '/\\\\([0-9a-fA-F]{4})/', '\\\\\\\\$1', $css );
// prevent content: '\3434' from turning into '\\3434'.
$css = str_replace( array( '\'\\\\', '"\\\\' ), array( '\'\\', '"\\' ), $css );
if ( $css !== $prev ) {
$warnings[] = 'preg_replace found stuff';
}
// Some people put weird stuff in their CSS, KSES tends to be greedy.
$css = str_replace( '<=', '&lt;=', $css );
// Test for some kses stuff.
$prev = $css;
// Why KSES instead of strip_tags? Who knows?
$css = wp_kses_split( $css, array(), array() );
$css = str_replace( '&gt;', '>', $css ); // kses replaces lone '>' with &gt;
// Why both KSES and strip_tags? Because we just added some '>'.
$css = strip_tags( $css ); // phpcs:ignore WordPress.WP.AlternativeFunctions.strip_tags_strip_tags -- scared to update this to wp_strip_all_tags since we're building a CSS file here.
if ( $css !== $prev ) {
$warnings[] = 'kses found stuff';
}
$csstidy->parse( $css );
$css = $csstidy->print->plain();
}
return $css;
}
add_filter('update_custom_css_data', function($args) {
$css = $args['css'];
$args['css'] = ai_sanitize_css($css);
return $args;
}, 10, 2);