3 require_once 'HTMLPurifier/AttrDef.php';
4 require_once 'HTMLPurifier/CSSDefinition.php';
7 * Validates shorthand CSS property background.
8 * @warning Does not support url tokens that have internal spaces.
10 class HTMLPurifier_AttrDef_CSS_Background
extends HTMLPurifier_AttrDef
14 * Local copy of component validators.
15 * @note See HTMLPurifier_AttrDef_Font::$info for a similar impl.
19 function HTMLPurifier_AttrDef_CSS_Background($config) {
20 $def = $config->getCSSDefinition();
21 $this->info
['background-color'] = $def->info
['background-color'];
22 $this->info
['background-image'] = $def->info
['background-image'];
23 $this->info
['background-repeat'] = $def->info
['background-repeat'];
24 $this->info
['background-attachment'] = $def->info
['background-attachment'];
25 $this->info
['background-position'] = $def->info
['background-position'];
28 function validate($string, $config, &$context) {
30 // regular pre-processing
31 $string = $this->parseCDATA($string);
32 if ($string === '') return false;
34 // munge rgb() decl if necessary
35 $string = $this->mungeRgb($string);
37 // assumes URI doesn't have spaces in it
38 $bits = explode(' ', strtolower($string)); // bits to process
41 $caught['color'] = false;
42 $caught['image'] = false;
43 $caught['repeat'] = false;
44 $caught['attachment'] = false;
45 $caught['position'] = false;
47 $i = 0; // number of catches
50 foreach ($bits as $bit) {
51 if ($bit === '') continue;
52 foreach ($caught as $key => $status) {
53 if ($key != 'position') {
54 if ($status !== false) continue;
55 $r = $this->info
['background-' . $key]->validate($bit, $config, $context);
59 if ($r === false) continue;
60 if ($key == 'position') {
61 if ($caught[$key] === false) $caught[$key] = '';
62 $caught[$key] .= $r . ' ';
71 if (!$i) return false;
72 if ($caught['position'] !== false) {
73 $caught['position'] = $this->info
['background-position']->
74 validate($caught['position'], $config, $context);
78 foreach ($caught as $value) {
79 if ($value === false) continue;
83 if (empty($ret)) return false;
84 return implode(' ', $ret);