Whoops, forgot to edit WHATSNEW
[htmlpurifier.git] / library / HTMLPurifier / AttrDef / CSS / ListStyle.php
blobe74d42654e292e7f988ba1531590347feaa9dd28
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 validators.
12 * @type HTMLPurifier_AttrDef[]
13 * @note See HTMLPurifier_AttrDef_CSS_Font::$info for a similar impl.
15 protected $info;
17 /**
18 * @param HTMLPurifier_Config $config
20 public function __construct($config)
22 $def = $config->getCSSDefinition();
23 $this->info['list-style-type'] = $def->info['list-style-type'];
24 $this->info['list-style-position'] = $def->info['list-style-position'];
25 $this->info['list-style-image'] = $def->info['list-style-image'];
28 /**
29 * @param string $string
30 * @param HTMLPurifier_Config $config
31 * @param HTMLPurifier_Context $context
32 * @return bool|string
34 public function validate($string, $config, $context)
36 // regular pre-processing
37 $string = $this->parseCDATA($string);
38 if ($string === '') {
39 return false;
42 // assumes URI doesn't have spaces in it
43 $bits = explode(' ', strtolower($string)); // bits to process
45 $caught = array();
46 $caught['type'] = false;
47 $caught['position'] = false;
48 $caught['image'] = false;
50 $i = 0; // number of catches
51 $none = false;
53 foreach ($bits as $bit) {
54 if ($i >= 3) {
55 return;
56 } // optimization bit
57 if ($bit === '') {
58 continue;
60 foreach ($caught as $key => $status) {
61 if ($status !== false) {
62 continue;
64 $r = $this->info['list-style-' . $key]->validate($bit, $config, $context);
65 if ($r === false) {
66 continue;
68 if ($r === 'none') {
69 if ($none) {
70 continue;
71 } else {
72 $none = true;
74 if ($key == 'image') {
75 continue;
78 $caught[$key] = $r;
79 $i++;
80 break;
84 if (!$i) {
85 return false;
88 $ret = array();
90 // construct type
91 if ($caught['type']) {
92 $ret[] = $caught['type'];
95 // construct image
96 if ($caught['image']) {
97 $ret[] = $caught['image'];
100 // construct position
101 if ($caught['position']) {
102 $ret[] = $caught['position'];
105 if (empty($ret)) {
106 return false;
108 return implode(' ', $ret);
112 // vim: et sw=4 sts=4