function subvalue()
 {
     /**
      * Do action before optimizing the subvalue
      *
      * @since ?
      * @module Custom_CSS
      * @param safecss $obj
      **/
     do_action('csstidy_optimize_subvalue', $this);
     return parent::subvalue();
 }
Пример #2
0
 function subvalue()
 {
     $this->sub_value = trim($this->sub_value);
     // Send any urls through our filter
     if (preg_match('!^\\s*url\\s*(?:\\(|\\\\0028)(.*)(?:\\)|\\\\0029).*$!Dis', $this->sub_value, $matches)) {
         $this->sub_value = $this->safe_clean_url($matches[1]);
     }
     // Strip any expressions
     if (preg_match('!^\\s*expression!Dis', $this->sub_value)) {
         $this->sub_value = '';
     }
     return parent::subvalue();
 }
Пример #3
0
 function subvalue()
 {
     /**
      * Fires before optimizing the Custom CSS subvalue.
      *
      * @module custom-css
      *
      * @since 1.8.0
      *
      * @param obj $this CSSTidy object.
      **/
     do_action('csstidy_optimize_subvalue', $this);
     return parent::subvalue();
 }
Пример #4
0
 function subvalue()
 {
     do_action('csstidy_optimize_subvalue', $this);
     return parent::subvalue();
 }
Пример #5
0
 /**
  * Merges all background properties
  * @param array $input_css
  * @return array
  * @version 1.0
  * @see dissolve_short_bg()
  * @todo full CSS 3 compliance
  */
 function merge_bg($input_css)
 {
     $background_prop_default =& $GLOBALS['csstidy']['background_prop_default'];
     // Max number of background images. CSS3 not yet fully implemented
     $number_of_values = @max(count(csstidy_optimise::explode_ws(',', $input_css['background-image'])), count(csstidy_optimise::explode_ws(',', $input_css['background-color'])), 1);
     // Array with background images to check if BG image exists
     $bg_img_array = @csstidy_optimise::explode_ws(',', $this->parser->gvw_important($input_css['background-image']));
     $new_bg_value = '';
     $important = '';
     for ($i = 0; $i < $number_of_values; $i++) {
         foreach ($background_prop_default as $bg_property => $default_value) {
             // Skip if property does not exist
             if (!isset($input_css[$bg_property])) {
                 continue;
             }
             $cur_value = $input_css[$bg_property];
             // Skip some properties if there is no background image
             if ((!isset($bg_img_array[$i]) || $bg_img_array[$i] === 'none') && ($bg_property === 'background-size' || $bg_property === 'background-position' || $bg_property === 'background-attachment' || $bg_property === 'background-repeat')) {
                 continue;
             }
             // Remove !important
             if ($this->parser->is_important($cur_value)) {
                 $important = ' !important';
                 $cur_value = $this->parser->gvw_important($cur_value);
             }
             // Do not add default values
             if ($cur_value === $default_value) {
                 continue;
             }
             $temp = csstidy_optimise::explode_ws(',', $cur_value);
             if (isset($temp[$i])) {
                 if ($bg_property == 'background-size') {
                     $new_bg_value .= '(' . $temp[$i] . ') ';
                 } else {
                     $new_bg_value .= $temp[$i] . ' ';
                 }
             }
         }
         $new_bg_value = trim($new_bg_value);
         if ($i != $number_of_values - 1) {
             $new_bg_value .= ',';
         }
     }
     // Delete all background-properties
     foreach ($background_prop_default as $bg_property => $default_value) {
         unset($input_css[$bg_property]);
     }
     // Add new background property
     if ($new_bg_value !== '') {
         $input_css['background'] = $new_bg_value . $important;
     }
     return $input_css;
 }
 /**
  * Dissolve font property
  * @param string $str_value
  * @return array
  * @version 1.3
  * @see merge_font()
  */
 function dissolve_short_font($str_value)
 {
     $font_prop_default =& $GLOBALS['csstidy']['font_prop_default'];
     $font_weight = array('normal', 'bold', 'bolder', 'lighter', 100, 200, 300, 400, 500, 600, 700, 800, 900);
     $font_variant = array('normal', 'small-caps');
     $font_style = array('normal', 'italic', 'oblique');
     $important = '';
     $return = array('font-style' => null, 'font-variant' => null, 'font-weight' => null, 'font-size' => null, 'line-height' => null, 'font-family' => null);
     if (csstidy::is_important($str_value)) {
         $important = '!important';
         $str_value = csstidy::gvw_important($str_value);
     }
     $have['style'] = false;
     $have['variant'] = false;
     $have['weight'] = false;
     $have['size'] = false;
     // Detects if font-family consists of several words w/o quotes
     $multiwords = false;
     // Workaround with multiple font-family
     $str_value = csstidy_optimise::explode_ws(',', trim($str_value));
     $str_value[0] = csstidy_optimise::explode_ws(' ', trim($str_value[0]));
     for ($j = 0; $j < count($str_value[0]); $j++) {
         if ($have['weight'] === false && in_array($str_value[0][$j], $font_weight)) {
             $return['font-weight'] = $str_value[0][$j];
             $have['weight'] = true;
         } elseif ($have['variant'] === false && in_array($str_value[0][$j], $font_variant)) {
             $return['font-variant'] = $str_value[0][$j];
             $have['variant'] = true;
         } elseif ($have['style'] === false && in_array($str_value[0][$j], $font_style)) {
             $return['font-style'] = $str_value[0][$j];
             $have['style'] = true;
         } elseif ($have['size'] === false && (is_numeric($str_value[0][$j][0]) || $str_value[0][$j][0] === null || $str_value[0][$j][0] === '.')) {
             $size = csstidy_optimise::explode_ws('/', trim($str_value[0][$j]));
             $return['font-size'] = $size[0];
             if (isset($size[1])) {
                 $return['line-height'] = $size[1];
             } else {
                 $return['line-height'] = '';
                 // don't add 'normal' !
             }
             $have['size'] = true;
         } else {
             if (isset($return['font-family'])) {
                 $return['font-family'] .= ' ' . $str_value[0][$j];
                 $multiwords = true;
             } else {
                 $return['font-family'] = $str_value[0][$j];
             }
         }
     }
     // add quotes if we have several qords in font-family
     if ($multiwords !== false) {
         $return['font-family'] = '"' . $return['font-family'] . '"';
     }
     $i = 1;
     while (isset($str_value[$i])) {
         $return['font-family'] .= ',' . trim($str_value[$i]);
         $i++;
     }
     // Fix for 100 and more font-size
     if ($have['size'] === false && isset($return['font-weight']) && is_numeric($return['font-weight'][0])) {
         $return['font-size'] = $return['font-weight'];
         unset($return['font-weight']);
     }
     foreach ($font_prop_default as $font_prop => $default_value) {
         if ($return[$font_prop] !== null) {
             $return[$font_prop] = $return[$font_prop] . $important;
         } else {
             $return[$font_prop] = $default_value . $important;
         }
     }
     return $return;
 }
Пример #7
0
 /**
  * Optimises shorthands
  * @access private
  * @version 1.0
  */
 private function shorthands()
 {
     $shorthands =& $this->meta_css['shorthands'];
     if (!$this->get_cfg('optimise_shorthands') || $this->get_cfg('preserve_css')) {
         return;
     }
     if ($this->property === 'font' && $this->get_cfg('optimise_shorthands') > 0) {
         unset($this->css[$this->at][$this->selector]['font']);
         $this->merge_css_blocks($this->at, $this->selector, csstidy_optimise::dissolve_short_font($this->value));
     }
     if ($this->property === 'background' && $this->get_cfg('optimise_shorthands') > 1) {
         unset($this->css[$this->at][$this->selector]['background']);
         $this->merge_css_blocks($this->at, $this->selector, csstidy_optimise::dissolve_short_bg($this->value));
     }
     if (isset($shorthands[$this->property])) {
         $this->merge_css_blocks($this->at, $this->selector, csstidy_optimise::dissolve_4value_shorthands($this->property, $this->value));
         if (is_array($shorthands[$this->property])) {
             unset($this->css[$this->at][$this->selector][$this->property]);
         }
     }
 }
 /**
  * Optimises a sub-value.
  */
 function subvalue()
 {
     /** This action is documented in modules/custom-css/custom-css.php */
     do_action('csstidy_optimize_subvalue', $this);
     return parent::subvalue();
 }