3 require_once 'HTMLPurifier/AttrDef.php';
6 * Validates shorthand CSS property list-style.
7 * @warning Does not support url tokens that have internal spaces.
9 class HTMLPurifier_AttrDef_CSS_ListStyle
extends HTMLPurifier_AttrDef
13 * Local copy of component validators.
14 * @note See HTMLPurifier_AttrDef_CSS_Font::$info for a similar impl.
18 function HTMLPurifier_AttrDef_CSS_ListStyle($config) {
19 $def = $config->getCSSDefinition();
20 $this->info
['list-style-type'] = $def->info
['list-style-type'];
21 $this->info
['list-style-position'] = $def->info
['list-style-position'];
22 $this->info
['list-style-image'] = $def->info
['list-style-image'];
25 function validate($string, $config, &$context) {
27 // regular pre-processing
28 $string = $this->parseCDATA($string);
29 if ($string === '') return false;
31 // assumes URI doesn't have spaces in it
32 $bits = explode(' ', strtolower($string)); // bits to process
35 $caught['type'] = false;
36 $caught['position'] = false;
37 $caught['image'] = false;
39 $i = 0; // number of catches
42 foreach ($bits as $bit) {
43 if ($i >= 3) return; // optimization bit
44 if ($bit === '') continue;
45 foreach ($caught as $key => $status) {
46 if ($status !== false) continue;
47 $r = $this->info
['list-style-' . $key]->validate($bit, $config, $context);
48 if ($r === false) continue;
52 if ($key == 'image') continue;
60 if (!$i) return false;
65 if ($caught['type']) $ret[] = $caught['type'];
68 if ($caught['image']) $ret[] = $caught['image'];
71 if ($caught['position']) $ret[] = $caught['position'];
73 if (empty($ret)) return false;
74 return implode(' ', $ret);