1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | class HTMLPurifier_AttrDef_CSS_Background extends HTMLPurifier_AttrDef |
8: | { |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | protected $info; |
16: | |
17: | |
18: | |
19: | |
20: | public function __construct($config) |
21: | { |
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']; |
28: | $this->info['background-size'] = $def->info['background-size']; |
29: | } |
30: | |
31: | |
32: | |
33: | |
34: | |
35: | |
36: | |
37: | public function validate($string, $config, $context) |
38: | { |
39: | |
40: | $string = $this->parseCDATA($string); |
41: | if ($string === '') { |
42: | return false; |
43: | } |
44: | |
45: | |
46: | $string = $this->mungeRgb($string); |
47: | |
48: | |
49: | $bits = explode(' ', $string); |
50: | |
51: | $caught = array(); |
52: | $caught['color'] = false; |
53: | $caught['image'] = false; |
54: | $caught['repeat'] = false; |
55: | $caught['attachment'] = false; |
56: | $caught['position'] = false; |
57: | $caught['size'] = false; |
58: | |
59: | $i = 0; |
60: | |
61: | foreach ($bits as $bit) { |
62: | if ($bit === '') { |
63: | continue; |
64: | } |
65: | foreach ($caught as $key => $status) { |
66: | if ($key != 'position') { |
67: | if ($status !== false) { |
68: | continue; |
69: | } |
70: | $r = $this->info['background-' . $key]->validate($bit, $config, $context); |
71: | } else { |
72: | $r = $bit; |
73: | } |
74: | if ($r === false) { |
75: | continue; |
76: | } |
77: | if ($key == 'position') { |
78: | if ($caught[$key] === false) { |
79: | $caught[$key] = ''; |
80: | } |
81: | $caught[$key] .= $r . ' '; |
82: | } else { |
83: | $caught[$key] = $r; |
84: | } |
85: | $i++; |
86: | break; |
87: | } |
88: | } |
89: | |
90: | if (!$i) { |
91: | return false; |
92: | } |
93: | if ($caught['position'] !== false) { |
94: | $caught['position'] = $this->info['background-position']-> |
95: | validate($caught['position'], $config, $context); |
96: | } |
97: | |
98: | $ret = array(); |
99: | foreach ($caught as $value) { |
100: | if ($value === false) { |
101: | continue; |
102: | } |
103: | $ret[] = $value; |
104: | } |
105: | |
106: | if (empty($ret)) { |
107: | return false; |
108: | } |
109: | return implode(' ', $ret); |
110: | } |
111: | } |
112: | |
113: | |
114: | |