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