1 : <?php
2 :
3 : /**
4 : * Validates a MultiLength as defined by the HTML spec.
5 : *
6 : * A multilength is either a integer (pixel count), a percentage, or
7 : * a relative number.
8 : */
9 1 : class HTMLPurifier_AttrDef_HTML_MultiLength extends HTMLPurifier_AttrDef_HTML_Length
10 : {
11 :
12 : public function validate($string, $config, $context) {
13 :
14 0 : $string = trim($string);
15 0 : if ($string === '') return false;
16 :
17 0 : $parent_result = parent::validate($string, $config, $context);
18 0 : if ($parent_result !== false) return $parent_result;
19 :
20 0 : $length = strlen($string);
21 0 : $last_char = $string[$length - 1];
22 :
23 0 : if ($last_char !== '*') return false;
24 :
25 0 : $int = substr($string, 0, $length - 1);
26 :
27 0 : if ($int == '') return '*';
28 0 : if (!is_numeric($int)) return false;
29 :
30 0 : $int = (int) $int;
31 :
32 0 : if ($int < 0) return false;
33 0 : if ($int == 0) return '0';
34 0 : if ($int == 1) return '*';
35 0 : return ((string) $int) . '*';
36 :
37 : }
38 :
39 : }
40 :
|