De-singleton-ized (HTML|CSS)Definition, tying them to the configuration and making...
[htmlpurifier.git] / library / HTMLPurifier / AttrDef / ListStyle.php
bloba2df527ac823fb404af63b7bb241712bcec6179f
1 <?php
3 require_once 'HTMLPurifier/AttrDef.php';
5 /**
6 * Validates shorthand CSS property list-style.
7 * @note This currently does not support list-style-image, as that functionality
8 * is not implemented yet elsewhere.
9 */
10 class HTMLPurifier_AttrDef_ListStyle extends HTMLPurifier_AttrDef
13 /**
14 * Local copy of component validators.
15 * @note See HTMLPurifier_AttrDef_Font::$info for a similar impl.
17 var $info;
19 function HTMLPurifier_AttrDef_ListStyle($config) {
20 $def = $config->getCSSDefinition();
21 $this->info['list-style-type'] = $def->info['list-style-type'];
22 $this->info['list-style-position'] = $def->info['list-style-position'];
25 function validate($string, $config, &$context) {
27 // regular pre-processing
28 $string = $this->parseCDATA($string);
29 if ($string === '') return false;
31 $bits = explode(' ', strtolower($string)); // bits to process
33 $caught_type = false;
34 $caught_position = false;
35 $caught_none = false; // as in keyword none, which is in all of them
37 $ret = '';
39 foreach ($bits as $bit) {
40 if ($caught_none && ($caught_type || $caught_position)) break;
41 if ($caught_type && $caught_position) break;
43 if ($bit === '') continue;
45 if ($bit === 'none') {
46 if ($caught_none) continue;
47 $caught_none = true;
48 $ret .= 'none ';
49 continue;
52 // if we add anymore, roll it into a loop
54 $r = $this->info['list-style-type']->validate($bit, $config, $context);
55 if ($r !== false) {
56 if ($caught_type) continue;
57 $caught_type = true;
58 $ret .= $r . ' ';
59 continue;
62 $r = $this->info['list-style-position']->validate($bit, $config, $context);
63 if ($r !== false) {
64 if ($caught_position) continue;
65 $caught_position = true;
66 $ret .= $r . ' ';
67 continue;
71 $ret = rtrim($ret);
72 return $ret ? $ret : false;