4 [ // adjective and number must be in correct order, even if
5 // you could switch them without introducing ambiguity.
6 // some browsers support that syntax
8 <percentage> | <length> | left | center | right
11 <percentage> | <length> | top | center | bottom
14 [ // this signifies that the vertical and horizontal adjectives
15 // can be arbitrarily ordered, however, there can only be two,
16 // one of each, or none at all
30 keyword + length/percentage must be ordered correctly, as per W3C
32 Internet Explorer and Opera, however, support arbitrary ordering. We
35 Minor issue though, not strictly necessary.
38 // control freaks may appreciate the ability to convert these to
39 // percentages or something, but it's not necessary
42 * Validates the value of background-position.
44 class HTMLPurifier_AttrDef_CSS_BackgroundPosition extends HTMLPurifier_AttrDef
48 * @type HTMLPurifier_AttrDef_CSS_Length
53 * @type HTMLPurifier_AttrDef_CSS_Percentage
55 protected $percentage;
57 public function __construct()
59 $this->length = new HTMLPurifier_AttrDef_CSS_Length();
60 $this->percentage = new HTMLPurifier_AttrDef_CSS_Percentage();
64 * @param string $string
65 * @param HTMLPurifier_Config $config
66 * @param HTMLPurifier_Context $context
69 public function validate($string, $config, $context)
71 $string = $this->parseCDATA($string);
72 $bits = explode(' ', $string);
75 $keywords['h'] = false; // left, right
76 $keywords['v'] = false; // top, bottom
77 $keywords['ch'] = false; // center (first word)
78 $keywords['cv'] = false; // center (second word)
91 foreach ($bits as $bit) {
97 $lbit = ctype_lower($bit) ? $bit : strtolower($bit);
98 if (isset($lookup[$lbit])) {
99 $status = $lookup[$lbit];
100 if ($status == 'c') {
107 $keywords[$status] = $lbit;
112 $r = $this->length->validate($bit, $config, $context);
118 // test for percentage
119 $r = $this->percentage->validate($bit, $config, $context);
128 } // no valid values were caught
133 if ($keywords['h']) {
134 $ret[] = $keywords['h'];
135 } elseif ($keywords['ch']) {
136 $ret[] = $keywords['ch'];
137 $keywords['cv'] = false; // prevent re-use: center = center center
138 } elseif (count($measures)) {
139 $ret[] = array_shift($measures);
142 if ($keywords['v']) {
143 $ret[] = $keywords['v'];
144 } elseif ($keywords['cv']) {
145 $ret[] = $keywords['cv'];
146 } elseif (count($measures)) {
147 $ret[] = array_shift($measures);
153 return implode(' ', $ret);
157 // vim: et sw=4 sts=4