4 * Validates shorthand CSS property background.
5 * @warning Does not support url tokens that have internal spaces.
7 class HTMLPurifier_AttrDef_CSS_Background extends HTMLPurifier_AttrDef
11 * Local copy of component validators.
12 * @type HTMLPurifier_AttrDef[]
13 * @note See HTMLPurifier_AttrDef_Font::$info for a similar impl.
18 * @param HTMLPurifier_Config $config
20 public function __construct($config)
22 $def = $config->getCSSDefinition();
23 $this->info['background-color'] = $def->info['background-color'];
24 $this->info['background-image'] = $def->info['background-image'];
25 $this->info['background-repeat'] = $def->info['background-repeat'];
26 $this->info['background-attachment'] = $def->info['background-attachment'];
27 $this->info['background-position'] = $def->info['background-position'];
31 * @param string $string
32 * @param HTMLPurifier_Config $config
33 * @param HTMLPurifier_Context $context
36 public function validate($string, $config, $context)
38 // regular pre-processing
39 $string = $this->parseCDATA($string);
44 // munge rgb() decl if necessary
45 $string = $this->mungeRgb($string);
47 // assumes URI doesn't have spaces in it
48 $bits = explode(' ', $string); // bits to process
51 $caught['color'] = false;
52 $caught['image'] = false;
53 $caught['repeat'] = false;
54 $caught['attachment'] = false;
55 $caught['position'] = false;
57 $i = 0; // number of catches
59 foreach ($bits as $bit) {
63 foreach ($caught as $key => $status) {
64 if ($key != 'position') {
65 if ($status !== false) {
68 $r = $this->info['background-' . $key]->validate($bit, $config, $context);
75 if ($key == 'position') {
76 if ($caught[$key] === false) {
79 $caught[$key] .= $r . ' ';
91 if ($caught['position'] !== false) {
92 $caught['position'] = $this->info['background-position']->
93 validate($caught['position'], $config, $context);
97 foreach ($caught as $value) {
98 if ($value === false) {
107 return implode(' ', $ret);
111 // vim: et sw=4 sts=4