/** * Merges all background properties * @param array $input_css * @return array * @version 1.0 * @see dissolve_short_bg() * @todo full CSS 3 compliance */ public 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(self::explode_ws(',', $input_css['background-image'])), count(self::explode_ws(',', $input_css['background-color'])), 1); // Array with background images to check if BG image exists $bg_img_array = @self::explode_ws(',', Diglin_Csstidy_Core::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 (Diglin_Csstidy_Core::is_important($cur_value)) { $important = ' !important'; $cur_value = Diglin_Csstidy_Core::gvw_important($cur_value); } // Do not add default values if ($cur_value === $default_value) { continue; } $temp = self::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; }