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
* @note See HTMLPurifier_AttrDef_Font::$info for a similar impl.
16
public function __construct($config) {
17
$def = $config->getCSSDefinition();
18
$this->info['background-color'] = $def->info['background-color'];
19
$this->info['background-image'] = $def->info['background-image'];
20
$this->info['background-repeat'] = $def->info['background-repeat'];
21
$this->info['background-attachment'] = $def->info['background-attachment'];
22
$this->info['background-position'] = $def->info['background-position'];
25
public function validate($string, $config, $context) {
27
// regular pre-processing
28
$string = $this->parseCDATA($string);
29
if ($string === '') return false;
31
// munge rgb() decl if necessary
32
$string = $this->mungeRgb($string);
34
// assumes URI doesn't have spaces in it
35
$bits = explode(' ', strtolower($string)); // bits to process
38
$caught['color'] = false;
39
$caught['image'] = false;
40
$caught['repeat'] = false;
41
$caught['attachment'] = false;
42
$caught['position'] = false;
44
$i = 0; // number of catches
47
foreach ($bits as $bit) {
48
if ($bit === '') continue;
49
foreach ($caught as $key => $status) {
50
if ($key != 'position') {
51
if ($status !== false) continue;
52
$r = $this->info['background-' . $key]->validate($bit, $config, $context);
56
if ($r === false) continue;
57
if ($key == 'position') {
58
if ($caught[$key] === false) $caught[$key] = '';
59
$caught[$key] .= $r . ' ';
68
if (!$i) return false;
69
if ($caught['position'] !== false) {
70
$caught['position'] = $this->info['background-position']->
71
validate($caught['position'], $config, $context);
75
foreach ($caught as $value) {
76
if ($value === false) continue;
80
if (empty($ret)) return false;
81
return implode(' ', $ret);