4 * Validates shorthand CSS property list-style.
5 * @warning Does not support url tokens that have internal spaces.
7 class HTMLPurifier_AttrDef_CSS_ListStyle extends HTMLPurifier_AttrDef
11 * Local copy of component validators.
12 * @note See HTMLPurifier_AttrDef_CSS_Font::$info for a similar impl.
16 public function __construct($config) {
17 $def = $config->getCSSDefinition();
18 $this->info['list-style-type'] = $def->info['list-style-type'];
19 $this->info['list-style-position'] = $def->info['list-style-position'];
20 $this->info['list-style-image'] = $def->info['list-style-image'];
23 public function validate($string, $config, $context) {
25 // regular pre-processing
26 $string = $this->parseCDATA($string);
27 if ($string === '') return false;
29 // assumes URI doesn't have spaces in it
30 $bits = explode(' ', strtolower($string)); // bits to process
33 $caught['type'] = false;
34 $caught['position'] = false;
35 $caught['image'] = false;
37 $i = 0; // number of catches
40 foreach ($bits as $bit) {
41 if ($i >= 3) return; // optimization bit
42 if ($bit === '') continue;
43 foreach ($caught as $key => $status) {
44 if ($status !== false) continue;
45 $r = $this->info['list-style-' . $key]->validate($bit, $config, $context);
46 if ($r === false) continue;
50 if ($key == 'image') continue;
58 if (!$i) return false;
63 if ($caught['type']) $ret[] = $caught['type'];
66 if ($caught['image']) $ret[] = $caught['image'];
69 if ($caught['position']) $ret[] = $caught['position'];
71 if (empty($ret)) return false;
72 return implode(' ', $ret);