]>
Commit | Line | Data |
---|---|---|
d4949327 NL |
1 | <?php\r |
2 | \r | |
3 | /**\r | |
4 | * Framework class for strings that involve multiple values.\r | |
5 | *\r | |
6 | * Certain CSS properties such as border-width and margin allow multiple\r | |
7 | * lengths to be specified. This class can take a vanilla border-width\r | |
8 | * definition and multiply it, usually into a max of four.\r | |
9 | *\r | |
10 | * @note Even though the CSS specification isn't clear about it, inherit\r | |
11 | * can only be used alone: it will never manifest as part of a multi\r | |
12 | * shorthand declaration. Thus, this class does not allow inherit.\r | |
13 | */\r | |
14 | class HTMLPurifier_AttrDef_CSS_Multiple extends HTMLPurifier_AttrDef\r | |
15 | {\r | |
16 | /**\r | |
17 | * Instance of component definition to defer validation to.\r | |
18 | * @type HTMLPurifier_AttrDef\r | |
19 | * @todo Make protected\r | |
20 | */\r | |
21 | public $single;\r | |
22 | \r | |
23 | /**\r | |
24 | * Max number of values allowed.\r | |
25 | * @todo Make protected\r | |
26 | */\r | |
27 | public $max;\r | |
28 | \r | |
29 | /**\r | |
30 | * @param HTMLPurifier_AttrDef $single HTMLPurifier_AttrDef to multiply\r | |
31 | * @param int $max Max number of values allowed (usually four)\r | |
32 | */\r | |
33 | public function __construct($single, $max = 4)\r | |
34 | {\r | |
35 | $this->single = $single;\r | |
36 | $this->max = $max;\r | |
37 | }\r | |
38 | \r | |
39 | /**\r | |
40 | * @param string $string\r | |
41 | * @param HTMLPurifier_Config $config\r | |
42 | * @param HTMLPurifier_Context $context\r | |
43 | * @return bool|string\r | |
44 | */\r | |
45 | public function validate($string, $config, $context)\r | |
46 | {\r | |
47 | $string = $this->parseCDATA($string);\r | |
48 | if ($string === '') {\r | |
49 | return false;\r | |
50 | }\r | |
51 | $parts = explode(' ', $string); // parseCDATA replaced \r, \t and \n\r | |
52 | $length = count($parts);\r | |
53 | $final = '';\r | |
54 | for ($i = 0, $num = 0; $i < $length && $num < $this->max; $i++) {\r | |
55 | if (ctype_space($parts[$i])) {\r | |
56 | continue;\r | |
57 | }\r | |
58 | $result = $this->single->validate($parts[$i], $config, $context);\r | |
59 | if ($result !== false) {\r | |
60 | $final .= $result . ' ';\r | |
61 | $num++;\r | |
62 | }\r | |
63 | }\r | |
64 | if ($final === '') {\r | |
65 | return false;\r | |
66 | }\r | |
67 | return rtrim($final);\r | |
68 | }\r | |
69 | }\r | |
70 | \r | |
71 | // vim: et sw=4 sts=4\r |