4 * Framework class for strings that involve multiple values.
6 * Certain CSS properties such as border-width and margin allow multiple
7 * lengths to be specified. This class can take a vanilla border-width
8 * definition and multiply it, usually into a max of four.
10 * @note Even though the CSS specification isn't clear about it, inherit
11 * can only be used alone: it will never manifest as part of a multi
12 * shorthand declaration. Thus, this class does not allow inherit.
14 class HTMLPurifier_AttrDef_CSS_Multiple extends HTMLPurifier_AttrDef
18 * Instance of component definition to defer validation to.
19 * @todo Make protected
24 * Max number of values allowed.
25 * @todo Make protected
30 * @param $single HTMLPurifier_AttrDef to multiply
31 * @param $max Max number of values allowed (usually four)
33 public function __construct($single, $max = 4) {
34 $this->single = $single;
38 public function validate($string, $config, $context) {
39 $string = $this->parseCDATA($string);
40 if ($string === '') return false;
41 $parts = explode(' ', $string); // parseCDATA replaced \r, \t and \n
42 $length = count($parts);
44 for ($i = 0, $num = 0; $i < $length && $num < $this->max; $i++) {
45 if (ctype_space($parts[$i])) continue;
46 $result = $this->single->validate($parts[$i], $config, $context);
47 if ($result !== false) {
48 $final .= $result . ' ';
52 if ($final === '') return false;