示例#1
0
 static function filter_attr($css, $element = 'div')
 {
     safecss_class();
     $css = $element . ' {' . $css . '}';
     $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('discard_invalid_properties', true);
     $csstidy->set_cfg('merge_selectors', false);
     $csstidy->set_cfg('remove_last_;', false);
     $csstidy->set_cfg('css_level', 'CSS3.0');
     $css = preg_replace('/\\\\([0-9a-fA-F]{4})/', '\\\\\\\\$1', $css);
     $css = wp_kses_split($css, array(), array());
     $csstidy->parse($css);
     $css = $csstidy->print->plain();
     $css = str_replace(array("\n", "\r", "\t"), '', $css);
     preg_match("/^{$element}\\s*{(.*)}\\s*\$/", $css, $matches);
     if (empty($matches[1])) {
         return '';
     }
     return $matches[1];
 }
function custom_css_minify($css)
{
    if (!$css) {
        return '';
    }
    safecss_class();
    $csstidy = new csstidy();
    $csstidy->optimise = new safecss($csstidy);
    $csstidy->set_cfg('remove_bslash', false);
    $csstidy->set_cfg('compress_colors', true);
    $csstidy->set_cfg('compress_font-weight', true);
    $csstidy->set_cfg('remove_last_;', true);
    $csstidy->set_cfg('case_properties', true);
    $csstidy->set_cfg('discard_invalid_properties', true);
    $csstidy->set_cfg('css_level', 'CSS3.0');
    $csstidy->set_cfg('template', 'highest');
    $csstidy->parse($css);
    return $csstidy->print->plain();
}
 static function sanitize_css($css)
 {
     $css = stripslashes($css);
     $css = wp_strip_all_tags($css);
     if (function_exists('safecss_class')) {
         // Stolen from the Custom CSS plugin. Sanitize and clean using CSS tidy if available.
         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('discard_invalid_properties', true);
         $csstidy->set_cfg('merge_selectors', false);
         $csstidy->set_cfg('remove_last_;', false);
         $csstidy->set_cfg('css_level', 'CSS3.0');
         $css = preg_replace('/\\\\([0-9a-fA-F]{4})/', '\\\\\\\\$1', $css);
         $csstidy->parse($css);
         $css = $csstidy->print->plain();
     }
     return $css;
 }
 /**
  * If we're not running JetPack, instantiate a custom CSS parser
  */
 function inst_css_parser($css = null)
 {
     if (empty($css)) {
         return '';
     }
     $css = $this->compile_scss($css);
     if (!class_exists('safecss_class')) {
         require_once plugin_dir_path(dirname(__FILE__)) . '/classes/class-safecss-class.php';
     }
     safecss_class();
     $csstidy = new csstidy();
     $csstidy->optimise = new safecss($csstidy);
     $csstidy->set_cfg('remove_bslash', false);
     $csstidy->set_cfg('compress_colors', true);
     $csstidy->set_cfg('compress_font-weight', true);
     $csstidy->set_cfg('remove_last_;', true);
     $csstidy->set_cfg('case_properties', true);
     $csstidy->set_cfg('discard_invalid_properties', true);
     $csstidy->set_cfg('css_level', 'CSS3.0');
     $csstidy->set_cfg('template', 'highest');
     $csstidy->set_cfg('preserve_css', false);
     $csstidy->parse($css);
     return $csstidy->print->plain();
 }
 /**
  * Sanitize the CSS for users without `unfiltered_html`.
  *
  * @param string $css  Input CSS.
  * @param array  $args Array of CSS options.
  *
  * @return mixed|string
  */
 public static function sanitize_css($css, $args = array())
 {
     $args = wp_parse_args($args, array('force' => false, 'preprocessor' => null));
     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', dirname(__FILE__) . '/csstidy/wordpress-standard.tpl');
         $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);
         $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);
         if ($css != $prev) {
             $warnings[] = 'kses found stuff';
         }
         // if we're not using a preprocessor.
         if (!$args['preprocessor']) {
             /** This action is documented in modules/custom-css/custom-css.php */
             do_action('safecss_parse_pre', $csstidy, $css, $args);
             $csstidy->parse($css);
             /** This action is documented in modules/custom-css/custom-css.php */
             do_action('safecss_parse_post', $csstidy, $warnings, $args);
             $css = $csstidy->print->plain();
         }
     }
     return $css;
 }
示例#6
0
/**
 * Initiate SafeCSS
 * @since 0.9
 */
function pixopoint_initiate_safecss()
{
    safecss_class();
}