source: trunk/library/csstidy/class.csstidy_optimise.php @ 7712

Revision 7712, 25.9 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Revisao das Melhorias de performance no codigo do Expresso.

  • Property svn:executable set to *
Line 
1<?php
2/**
3 * CSSTidy - CSS Parser and Optimiser
4 *
5 * CSS Optimising Class
6 * This class optimises CSS data generated by csstidy.
7 *
8 * This file is part of CSSTidy.
9 *
10 * CSSTidy is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * CSSTidy is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with CSSTidy; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 *
24 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
25 * @package csstidy
26 * @author Florian Schmitz (floele at gmail dot com) 2005-2006
27 */
28
29/**
30 * CSS Optimising Class
31 *
32 * This class optimises CSS data generated by csstidy.
33 *
34 * @package csstidy
35 * @author Florian Schmitz (floele at gmail dot com) 2005-2006
36 * @version 1.0
37 */
38
39class csstidy_optimise
40{
41    /**
42     * Constructor
43     * @param array $css contains the class csstidy
44     * @access private
45     * @version 1.0
46     */
47    function csstidy_optimise(&$css)
48    {
49        $this->parser    =& $css;
50        $this->css       =& $css->css;
51        $this->sub_value =& $css->sub_value;
52        $this->at        =& $css->at;
53        $this->selector  =& $css->selector;
54        $this->property  =& $css->property;
55        $this->value     =& $css->value;
56    }
57
58    /**
59     * Optimises $css after parsing
60     * @access public
61     * @version 1.0
62     */
63    function postparse()
64    {
65        if ($this->parser->get_cfg('preserve_css')) {
66            return;
67        }
68
69        if ($this->parser->get_cfg('merge_selectors') == 2)
70        {
71            foreach ($this->css as $medium => $value)
72            {
73                $this->merge_selectors($this->css[$medium]);
74            }
75        }
76
77        if ($this->parser->get_cfg('optimise_shorthands') > 0)
78        {
79            foreach ($this->css as $medium => $value)
80            {
81                foreach ($value as $selector => $value1)
82                {
83                    $this->css[$medium][$selector] = csstidy_optimise::merge_4value_shorthands($this->css[$medium][$selector]);
84
85                    if ($this->parser->get_cfg('optimise_shorthands') < 2) {
86                        continue;
87                    }
88
89                    $this->css[$medium][$selector] = csstidy_optimise::merge_bg($this->css[$medium][$selector]);
90                    if (empty($this->css[$medium][$selector])) {
91                        unset($this->css[$medium][$selector]);
92                    }
93                }
94            }
95        }
96    }
97
98    /**
99     * Optimises values
100     * @access public
101     * @version 1.0
102     */
103    function value()
104    {
105        $shorthands =& $GLOBALS['csstidy']['shorthands'];
106
107        // optimise shorthand properties
108        if(isset($shorthands[$this->property]))
109        {
110            $temp = csstidy_optimise::shorthand($this->value); // FIXME - move
111            if($temp != $this->value)
112            {
113                $this->parser->log('Optimised shorthand notation ('.$this->property.'): Changed "'.$this->value.'" to "'.$temp.'"','Information');
114            }
115            $this->value = $temp;
116        }
117
118        // Remove whitespace at ! important
119        if($this->value != $this->compress_important($this->value))
120        {
121            $this->parser->log('Optimised !important','Information');
122        }
123    }
124
125    /**
126     * Optimises shorthands
127     * @access public
128     * @version 1.0
129     */
130    function shorthands()
131    {
132        $shorthands =& $GLOBALS['csstidy']['shorthands'];
133
134        if(!$this->parser->get_cfg('optimise_shorthands') || $this->parser->get_cfg('preserve_css')) {
135            return;
136        }
137
138        if($this->property == 'background' && $this->parser->get_cfg('optimise_shorthands') > 1)
139        {
140            unset($this->css[$this->at][$this->selector]['background']);
141            $this->parser->merge_css_blocks($this->at,$this->selector,csstidy_optimise::dissolve_short_bg($this->value));
142        }
143        if(isset($shorthands[$this->property]))
144        {
145            $this->parser->merge_css_blocks($this->at,$this->selector,csstidy_optimise::dissolve_4value_shorthands($this->property,$this->value));
146            if(is_array($shorthands[$this->property]))
147            {
148                unset($this->css[$this->at][$this->selector][$this->property]);
149            }
150        }
151    }
152
153    /**
154     * Optimises a sub-value
155     * @access public
156     * @version 1.0
157     */
158    function subvalue()
159    {
160        $replace_colors =& $GLOBALS['csstidy']['replace_colors'];
161
162        $this->sub_value = trim($this->sub_value);
163        if($this->sub_value == '') // caution : '0'
164        {
165            return;
166        }
167
168        $important = '';
169        if(csstidy::is_important($this->sub_value))
170        {
171            $important = '!important';
172        }
173        $this->sub_value = csstidy::gvw_important($this->sub_value);
174
175        // Compress font-weight
176        if($this->property == 'font-weight' && $this->parser->get_cfg('compress_font-weight'))
177        {
178            if($this->sub_value == 'bold')
179            {
180                $this->sub_value = '700';
181                $this->parser->log('Optimised font-weight: Changed "bold" to "700"','Information');
182            }
183            else if($this->sub_value == 'normal')
184            {
185                $this->sub_value = '400';
186                $this->parser->log('Optimised font-weight: Changed "normal" to "400"','Information');
187            }
188        }
189
190        $temp = $this->compress_numbers($this->sub_value);
191        if($temp != $this->sub_value)
192        {
193            if(strlen($temp) > strlen($this->sub_value)) {
194                $this->parser->log('Fixed invalid number: Changed "'.$this->sub_value.'" to "'.$temp.'"','Warning');
195            } else {
196                $this->parser->log('Optimised number: Changed "'.$this->sub_value.'" to "'.$temp.'"','Information');
197            }
198            $this->sub_value = $temp;
199        }
200        if($this->parser->get_cfg('compress_colors'))
201        {
202            $temp = $this->cut_color($this->sub_value);
203            if($temp !== $this->sub_value)
204            {
205                if(isset($replace_colors[$this->sub_value])) {
206                    $this->parser->log('Fixed invalid color name: Changed "'.$this->sub_value.'" to "'.$temp.'"','Warning');
207                } else {
208                    $this->parser->log('Optimised color: Changed "'.$this->sub_value.'" to "'.$temp.'"','Information');
209                }
210                $this->sub_value = $temp;
211            }
212        }
213        $this->sub_value .= $important;
214    }
215
216    /**
217     * Compresses shorthand values. Example: margin:1px 1px 1px 1px -> margin:1px
218     * @param string $value
219     * @access public
220     * @return string
221     * @version 1.0
222     */
223    function shorthand($value)
224    {
225        $important = '';
226        if(csstidy::is_important($value))
227        {
228            $values = csstidy::gvw_important($value);
229            $important = '!important';
230        }
231        else $values = $value;
232
233        $values = explode(' ',$values);
234        switch(count($values))
235        {
236            case 4:
237            if($values[0] == $values[1] && $values[0] == $values[2] && $values[0] == $values[3])
238            {
239                return $values[0].$important;
240            }
241            elseif($values[1] == $values[3] && $values[0] == $values[2])
242            {
243                return $values[0].' '.$values[1].$important;
244            }
245            elseif($values[1] == $values[3])
246            {
247                return $values[0].' '.$values[1].' '.$values[2].$important;
248            }
249            break;
250
251            case 3:
252            if($values[0] == $values[1] && $values[0] == $values[2])
253            {
254                return $values[0].$important;
255            }
256            elseif($values[0] == $values[2])
257            {
258                return $values[0].' '.$values[1].$important;
259            }
260            break;
261
262            case 2:
263            if($values[0] == $values[1])
264            {
265                return $values[0].$important;
266            }
267            break;
268        }
269
270        return $value;
271    }
272
273    /**
274     * Removes unnecessary whitespace in ! important
275     * @param string $string
276     * @return string
277     * @access public
278     * @version 1.1
279     */
280    function compress_important(&$string)
281    {
282        if(csstidy::is_important($string))
283        {
284            $string = csstidy::gvw_important($string) . '!important';
285        }
286        return $string;
287    }
288
289    /**
290     * Color compression function. Converts all rgb() values to #-values and uses the short-form if possible. Also replaces 4 color names by #-values.
291     * @param string $color
292     * @return string
293     * @version 1.1
294     */
295    function cut_color($color)
296    {
297        $replace_colors =& $GLOBALS['csstidy']['replace_colors'];
298
299        // rgb(0,0,0) -> #000000 (or #000 in this case later)
300        if(strtolower(substr($color,0,4)) == 'rgb(')
301        {
302            $color_tmp = substr($color,4,strlen($color)-5);
303            $color_tmp = explode(',',$color_tmp);
304            for ( $i = 0; $i < count($color_tmp); ++$i )
305            {
306                $color_tmp[$i] = trim ($color_tmp[$i]);
307                if(substr($color_tmp[$i],-1) == '%')
308                {
309                    $color_tmp[$i] = round((255*$color_tmp[$i])/100);
310                }
311                if($color_tmp[$i]>255) $color_tmp[$i] = 255;
312            }
313            $color = '#';
314            for ($i = 0; $i < 3; ++$i )
315            {
316                if($color_tmp[$i]<16) {
317                    $color .= '0' . dechex($color_tmp[$i]);
318                } else {
319                    $color .= dechex($color_tmp[$i]);
320                }
321            }
322        }
323
324        // Fix bad color names
325        if(isset($replace_colors[strtolower($color)]))
326        {
327            $color = $replace_colors[strtolower($color)];
328        }
329
330        // #aabbcc -> #abc
331        if(strlen($color) == 7)
332        {
333            $color_temp = strtolower($color);
334            if($color_temp{0} == '#' && $color_temp{1} == $color_temp{2} && $color_temp{3} == $color_temp{4} && $color_temp{5} == $color_temp{6})
335            {
336                $color = '#'.$color{1}.$color{3}.$color{5};
337            }
338        }
339
340        switch(strtolower($color))
341        {
342            /* color name -> hex code */
343            case 'black': return '#000';
344            case 'fuchsia': return '#F0F';
345            case 'white': return '#FFF';
346            case 'yellow': return '#FF0';
347
348            /* hex code -> color name */
349            case '#800000': return 'maroon';
350            case '#ffa500': return 'orange';
351            case '#808000': return 'olive';
352            case '#800080': return 'purple';
353            case '#008000': return 'green';
354            case '#000080': return 'navy';
355            case '#008080': return 'teal';
356            case '#c0c0c0': return 'silver';
357            case '#808080': return 'gray';
358            case '#f00': return 'red';
359        }
360
361        return $color;
362    }
363
364    /**
365     * Compresses numbers (ie. 1.0 becomes 1 or 1.100 becomes 1.1 )
366     * @param string $subvalue
367     * @return string
368     * @version 1.2
369     */
370    function compress_numbers($subvalue)
371    {
372        $units =& $GLOBALS['csstidy']['units'];
373        $unit_values =& $GLOBALS['csstidy']['unit_values'];
374        $color_values =& $GLOBALS['csstidy']['color_values'];
375
376        // for font:1em/1em sans-serif...;
377        if($this->property == 'font')
378        {
379            $temp = explode('/',$subvalue);
380        }
381        else
382        {
383            $temp = array($subvalue);
384        }
385        $temp_count = count($temp);
386        for ($l = 0; $l < $temp_count; ++$l)
387        {
388            // continue if no numeric value
389            if (!(strlen($temp[$l]) > 0 && ( is_numeric($temp[$l]{0}) || $temp[$l]{0} == '+' || $temp[$l]{0} == '-' ) ))
390            {
391                continue;
392            }
393
394            // Fix bad colors
395            if (in_array($this->property, $color_values))
396            {
397                $temp[$l] = '#'.$temp[$l];
398            }
399
400            if (floatval($temp[$l]) == 0)
401            {
402                $temp[$l] = '0';
403            }
404            else
405            {
406                $unit_found = FALSE;
407                for ($m = 0, $size_4 = count($units); $m < $size_4; ++$m)
408                {
409                    if (strpos(strtolower($temp[$l]),$units[$m]) !== FALSE)
410                    {
411                        $temp[$l] = floatval($temp[$l]).$units[$m];
412                        $unit_found = TRUE;
413                        break;
414                    }
415                }
416                if (!$unit_found && in_array($this->property,$unit_values,TRUE))
417                {
418                    $temp[$l] = floatval($temp[$l]).'px';
419                }
420                else if (!$unit_found)
421                {
422                    $temp[$l] = floatval($temp[$l]);
423                }
424                // Remove leading zero
425                if (abs(floatval($temp[$l])) < 1) {
426                    if (floatval($temp[$l]) < 0) {
427                        $temp[$l] = '-' . substr($temp[$l], 2);
428                    } else {
429                        $temp[$l] = substr($temp[$l], 1);
430                    }
431                }
432            }
433        }
434
435        return ((count($temp) > 1) ? $temp[0].'/'.$temp[1] : $temp[0]);
436    }
437
438    /**
439     * Merges selectors with same properties. Example: a{color:red} b{color:red} -> a,b{color:red}
440     * Very basic and has at least one bug. Hopefully there is a replacement soon.
441     * @param array $array
442     * @return array
443     * @access public
444     * @version 1.2
445     */
446    function merge_selectors(&$array)
447    {
448        $css = $array;
449        foreach($css as $key => $value)
450        {
451            if(!isset($css[$key]))
452            {
453                continue;
454            }
455            $newsel = '';
456
457            // Check if properties also exist in another selector
458            $keys = array();
459            // PHP bug (?) without $css = $array; here
460            foreach($css as $selector => $vali)
461            {
462                if($selector == $key)
463                {
464                    continue;
465                }
466
467                if($css[$key] === $vali)
468                {
469                    $keys[] = $selector;
470                }
471            }
472
473            if(!empty($keys))
474            {
475                $newsel = $key;
476                unset($css[$key]);
477                foreach($keys as $selector)
478                {
479                    unset($css[$selector]);
480                    $newsel .= ','.$selector;
481                }
482                $css[$newsel] = $value;
483            }
484        }
485        $array = $css;
486    }
487
488    /**
489     * Dissolves properties like padding:10px 10px 10px to padding-top:10px;padding-bottom:10px;...
490     * @param string $property
491     * @param string $value
492     * @return array
493     * @version 1.0
494     * @see merge_4value_shorthands()
495     */
496    function dissolve_4value_shorthands($property,$value)
497    {
498        $shorthands =& $GLOBALS['csstidy']['shorthands'];
499        if(!is_array($shorthands[$property]))
500        {
501            $return[$property] = $value;
502            return $return;
503        }
504
505        $important = '';
506        if(csstidy::is_important($value))
507        {
508            $value = csstidy::gvw_important($value);
509            $important = '!important';
510        }
511        $values = explode(' ',$value);
512
513
514        $return = array();
515        if(count($values) == 4)
516        {
517            for($i=0;$i<4;++$i)
518            {
519                $return[$shorthands[$property][$i]] = $values[$i].$important;
520            }
521        }
522        elseif(count($values) == 3)
523        {
524            $return[$shorthands[$property][0]] = $values[0].$important;
525            $return[$shorthands[$property][1]] = $values[1].$important;
526            $return[$shorthands[$property][3]] = $values[1].$important;
527            $return[$shorthands[$property][2]] = $values[2].$important;
528        }
529        elseif(count($values) == 2)
530        {
531            for($i=0;$i<4;++$i)
532            {
533                $return[$shorthands[$property][$i]] = (($i % 2 != 0)) ? $values[1].$important : $values[0].$important;
534            }
535        }
536        else
537        {
538            for($i=0;$i<4;++$i)
539            {
540                $return[$shorthands[$property][$i]] = $values[0].$important;
541            }
542        }
543
544        return $return;
545    }
546
547    /**
548     * Explodes a string as explode() does, however, not if $sep is escaped or within a string.
549     * @param string $sep seperator
550     * @param string $string
551     * @return array
552     * @version 1.0
553     */
554    function explode_ws($sep,$string)
555    {
556        $status = 'st';
557        $to = '';
558
559        $output = array();
560        $num = 0;
561        for($i = 0, $len = strlen($string);$i < $len; ++$i)
562        {
563            switch($status)
564            {
565                case 'st':
566                if($string{$i} == $sep && !csstidy::escaped($string,$i))
567                {
568                    ++$num;
569                }
570                elseif($string{$i} == '"' || $string{$i} == '\'' || $string{$i} == '(' && !csstidy::escaped($string,$i))
571                {
572                    $status = 'str';
573                    $to = ($string{$i} == '(') ? ')' : $string{$i};
574                    (isset($output[$num])) ? $output[$num] .= $string{$i} : $output[$num] = $string{$i};
575                }
576                else
577                {
578                    (isset($output[$num])) ? $output[$num] .= $string{$i} : $output[$num] = $string{$i};
579                }
580                break;
581
582                case 'str':
583                if($string{$i} == $to && !csstidy::escaped($string,$i))
584                {
585                    $status = 'st';
586                }
587                (isset($output[$num])) ? $output[$num] .= $string{$i} : $output[$num] = $string{$i};
588                break;
589            }
590        }
591
592        if(isset($output[0]))
593        {
594            return $output;
595        }
596        else
597        {
598            return array($output);
599        }
600    }
601
602    /**
603     * Merges Shorthand properties again, the opposite of dissolve_4value_shorthands()
604     * @param array $array
605     * @return array
606     * @version 1.2
607     * @see dissolve_4value_shorthands()
608     */
609    function merge_4value_shorthands($array)
610    {
611        $return = $array;
612        $shorthands =& $GLOBALS['csstidy']['shorthands'];
613
614        foreach($shorthands as $key => $value)
615        {
616            if(isset($array[$value[0]]) && isset($array[$value[1]])
617            && isset($array[$value[2]]) && isset($array[$value[3]]) && $value !== 0)
618            {
619                $return[$key] = '';
620
621                $important = '';
622                for($i = 0; $i < 4; ++$i)
623                {
624                    $val = $array[$value[$i]];
625                    if(csstidy::is_important($val))
626                    {
627                        $important = '!important';
628                        $return[$key] .= csstidy::gvw_important($val).' ';
629                    }
630                    else
631                    {
632                        $return[$key] .= $val.' ';
633                    }
634                    unset($return[$value[$i]]);
635                }
636                $return[$key] = csstidy_optimise::shorthand(trim($return[$key].$important));
637            }
638        }
639        return $return;
640    }
641
642    /**
643     * Dissolve background property
644     * @param string $str_value
645     * @return array
646     * @version 1.0
647     * @see merge_bg()
648     * @todo full CSS 3 compliance
649     */
650    function dissolve_short_bg($str_value)
651    {
652        $background_prop_default =& $GLOBALS['csstidy']['background_prop_default'];
653        $repeat = array('repeat','repeat-x','repeat-y','no-repeat','space');
654        $attachment = array('scroll','fixed','local');
655        $clip = array('border','padding');
656        $origin = array('border','padding','content');
657        $pos = array('top','center','bottom','left','right');
658        $important = '';
659        $return = array('background-image' => NULL,'background-size' => NULL,'background-repeat' => NULL,'background-position' => NULL,'background-attachment'=>NULL,'background-clip' => NULL,'background-origin' => NULL,'background-color' => NULL);
660
661        if(csstidy::is_important($str_value))
662        {
663            $important = ' !important';
664            $str_value = csstidy::gvw_important($str_value);
665        }
666
667        $str_value = csstidy_optimise::explode_ws(',',$str_value);
668        $str_value_count = count($str_value);
669        for($i = 0; $i < $str_value_count; ++$i)
670        {
671            $have['clip'] = FALSE; $have['pos'] = FALSE;
672            $have['color'] = FALSE; $have['bg'] = FALSE;
673
674            $str_value[$i] = csstidy_optimise::explode_ws(' ',trim($str_value[$i]));
675
676            $str_value_count = count($str_value[$i]);
677            for($j = 0; $j < $str_value_count; ++$j)
678            {
679                if($have['bg'] === FALSE && (substr($str_value[$i][$j],0,4) == 'url(' || $str_value[$i][$j] === 'none'))
680                {
681                    $return['background-image'] .= $str_value[$i][$j].',';
682                    $have['bg'] = TRUE;
683                }
684                elseif(in_array($str_value[$i][$j],$repeat,TRUE))
685                {
686                    $return['background-repeat'] .= $str_value[$i][$j].',';
687                }
688                elseif(in_array($str_value[$i][$j],$attachment,TRUE))
689                {
690                    $return['background-attachment'] .= $str_value[$i][$j].',';
691                }
692                elseif(in_array($str_value[$i][$j],$clip,TRUE) && !$have['clip'])
693                {
694                    $return['background-clip'] .= $str_value[$i][$j].',';
695                    $have['clip'] = TRUE;
696                }
697                elseif(in_array($str_value[$i][$j],$origin,TRUE))
698                {
699                    $return['background-origin'] .= $str_value[$i][$j].',';
700                }
701                elseif($str_value[$i][$j]{0} == '(')
702                {
703                    $return['background-size'] .= substr($str_value[$i][$j],1,-1).',';
704                }
705                elseif(in_array($str_value[$i][$j],$pos,TRUE) || is_numeric($str_value[$i][$j]{0}) || $str_value[$i][$j]{0} === NULL)
706                {
707                    $return['background-position'] .= $str_value[$i][$j];
708                    if(!$have['pos']) $return['background-position'] .= ' '; else $return['background-position'].= ',';
709                    $have['pos'] = TRUE;
710                }
711                elseif(!$have['color'])
712                {
713                    $return['background-color'] .= $str_value[$i][$j].',';
714                    $have['color'] = TRUE;
715                }
716            }
717        }
718
719        foreach($background_prop_default as $bg_prop => $default_value)
720        {
721            if($return[$bg_prop] !== NULL)
722            {
723                $return[$bg_prop] = substr($return[$bg_prop],0,-1).$important;
724            }
725            else $return[$bg_prop] = $default_value.$important;
726        }
727        return $return;
728    }
729
730    /**
731     * Merges all background properties
732     * @param array $input_css
733     * @return array
734     * @version 1.0
735     * @see dissolve_short_bg()
736     * @todo full CSS 3 compliance
737     */
738    function merge_bg($input_css)
739    {
740        $background_prop_default =& $GLOBALS['csstidy']['background_prop_default'];
741        // Max number of background images. CSS3 not yet fully implemented
742        $number_of_values = @max(count(csstidy_optimise::explode_ws(',',$input_css['background-image'])),count(csstidy_optimise::explode_ws(',',$input_css['background-color'])),1);
743        // Array with background images to check if BG image exists
744        $bg_img_array = @csstidy_optimise::explode_ws(',',csstidy::gvw_important($input_css['background-image']));
745        $new_bg_value = '';
746        $important = '';
747
748        for($i = 0; $i < $number_of_values; ++$i)
749        {
750            foreach($background_prop_default as $bg_property => $default_value)
751            {
752                // Skip if property does not exist
753                if(!isset($input_css[$bg_property]))
754                {
755                    continue;
756                }
757
758                $cur_value = $input_css[$bg_property];
759
760                // Skip some properties if there is no background image
761                if((!isset($bg_img_array[$i]) || $bg_img_array[$i] === 'none')
762                    && ($bg_property === 'background-size' || $bg_property === 'background-position'
763                    || $bg_property === 'background-attachment' || $bg_property === 'background-repeat'))
764                {
765                    continue;
766                }
767
768                // Remove !important
769                if(csstidy::is_important($cur_value))
770                {
771                    $important = ' !important';
772                    $cur_value = csstidy::gvw_important($cur_value);
773                }
774
775                // Do not add default values
776                if($cur_value === $default_value)
777                {
778                    continue;
779                }
780
781                $temp = csstidy_optimise::explode_ws(',',$cur_value);
782
783                if(isset($temp[$i]))
784                {
785                    if($bg_property == 'background-size')
786                    {
787                        $new_bg_value .= '('.$temp[$i].') ';
788                    }
789                    else
790                    {
791                        $new_bg_value .= $temp[$i].' ';
792                    }
793                }
794            }
795
796            $new_bg_value = trim($new_bg_value);
797            if($i != $number_of_values-1) $new_bg_value .= ',';
798        }
799
800        // Delete all background-properties
801        foreach($background_prop_default as $bg_property => $default_value)
802        {
803            unset($input_css[$bg_property]);
804        }
805
806        // Add new background property
807        if($new_bg_value !== '') $input_css['background'] = $new_bg_value.$important;
808
809        return $input_css;
810    }
811}
812?>
Note: See TracBrowser for help on using the repository browser.