/**
  * Merges all fonts properties
  * @param array $input_css
  * @return array
  * @version 1.3
  * @see dissolve_short_font()
  */
 function merge_font($input_css)
 {
     $font_prop_default =& $GLOBALS['csstidy']['font_prop_default'];
     $new_font_value = '';
     $important = '';
     // Skip if not font-family and font-size set
     if (isset($input_css['font-family']) && isset($input_css['font-size'])) {
         // fix several words in font-family - add quotes
         if (isset($input_css['font-family'])) {
             $families = explode(",", $input_css['font-family']);
             $result_families = array();
             foreach ($families as $family) {
                 $family = trim($family);
                 $len = strlen($family);
                 if (strpos($family, " ") && !($family[0] == '"' && $family[$len - 1] == '"' || $family[0] == "'" && $family[$len - 1] == "'")) {
                     $family = '"' . $family . '"';
                 }
                 $result_families[] = $family;
             }
             $input_css['font-family'] = implode(",", $result_families);
         }
         foreach ($font_prop_default as $font_property => $default_value) {
             // Skip if property does not exist
             if (!isset($input_css[$font_property])) {
                 continue;
             }
             $cur_value = $input_css[$font_property];
             // Skip if default value is used
             if ($cur_value === $default_value) {
                 continue;
             }
             // Remove !important
             if (csstidy::is_important($cur_value)) {
                 $important = '!important';
                 $cur_value = csstidy::gvw_important($cur_value);
             }
             $new_font_value .= $cur_value;
             // Add delimiter
             $new_font_value .= $font_property === 'font-size' && isset($input_css['line-height']) ? '/' : ' ';
         }
         $new_font_value = trim($new_font_value);
         // Delete all font-properties
         foreach ($font_prop_default as $font_property => $default_value) {
             if ($font_property !== 'font' or !$new_font_value) {
                 unset($input_css[$font_property]);
             }
         }
         // Add new font property
         if ($new_font_value !== '') {
             $input_css['font'] = $new_font_value . $important;
         }
     }
     return $input_css;
 }
 /**
  * Merges all fonts properties
  * @param array $input_css
  * @return array
  * @version 1.3
  * @see dissolve_short_font()
  */
 function merge_font($input_css)
 {
     $font_prop_default =& $GLOBALS['csstidy']['font_prop_default'];
     $new_font_value = '';
     $important = '';
     // Skip if not font-family and font-size set
     if (isset($input_css['font-family']) && isset($input_css['font-size'])) {
         foreach ($font_prop_default as $font_property => $default_value) {
             // Skip if property does not exist
             if (!isset($input_css[$font_property])) {
                 continue;
             }
             $cur_value = $input_css[$font_property];
             // Skip if default value is used
             if ($cur_value === $default_value) {
                 continue;
             }
             // Remove !important
             if (csstidy::is_important($cur_value)) {
                 $important = '!important';
                 $cur_value = csstidy::gvw_important($cur_value);
             }
             $new_font_value .= $cur_value;
             // Add delimiter
             $new_font_value .= $font_property === 'font-size' && isset($input_css['line-height']) ? '/' : ' ';
         }
         $new_font_value = trim($new_font_value);
         // Delete all font-properties
         foreach ($font_prop_default as $font_property => $default_value) {
             unset($input_css[$font_property]);
         }
         // Add new font property
         if ($new_font_value !== '') {
             $input_css['font'] = $new_font_value . $important;
         }
     }
     return $input_css;
 }
 /**
  * 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(',', csstidy::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 (csstidy::is_important($cur_value)) {
                 $important = ' !important';
                 $cur_value = csstidy::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;
 }
Esempio n. 4
0
 /**
  * Removes unnecessary whitespace in ! important
  * @param string $string
  * @return string
  * @access public
  * @version 1.1
  */
 function compress_important(&$string)
 {
     if (csstidy::is_important($string)) {
         $string = csstidy::gvw_important($string) . '!important';
     }
     return $string;
 }