csstidy
[ class tree: csstidy ] [ index: csstidy ] [ all elements ]

Source for file class.csstidy_optimise.php

Documentation is available at class.csstidy_optimise.php

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

Documentation generated on Mon, 15 May 2006 22:55:34 +0200 by phpDocumentor 1.3.0RC3