Add vim modelines to all files.
[htmlpurifier.git] / library / HTMLPurifier / AttrDef / CSS / ListStyle.php
blob4406868c08b0b2d1e497ac4c1cd9694ca996a6b5
1 <?php
3 /**
4 * Validates shorthand CSS property list-style.
5 * @warning Does not support url tokens that have internal spaces.
6 */
7 class HTMLPurifier_AttrDef_CSS_ListStyle extends HTMLPurifier_AttrDef
10 /**
11 * Local copy of component validators.
12 * @note See HTMLPurifier_AttrDef_CSS_Font::$info for a similar impl.
14 protected $info;
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
32 $caught = array();
33 $caught['type'] = false;
34 $caught['position'] = false;
35 $caught['image'] = false;
37 $i = 0; // number of catches
38 $none = false;
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;
47 if ($r === 'none') {
48 if ($none) continue;
49 else $none = true;
50 if ($key == 'image') continue;
52 $caught[$key] = $r;
53 $i++;
54 break;
58 if (!$i) return false;
60 $ret = array();
62 // construct type
63 if ($caught['type']) $ret[] = $caught['type'];
65 // construct image
66 if ($caught['image']) $ret[] = $caught['image'];
68 // construct position
69 if ($caught['position']) $ret[] = $caught['position'];
71 if (empty($ret)) return false;
72 return implode(' ', $ret);
78 // vim: et sw=4 sts=4