3 require_once 'HTMLPurifier/AttrDef.php';
4 require_once 'HTMLPurifier/AttrDef/HTML/Length.php';
7 * Validates a MultiLength as defined by the HTML spec.
9 * A multilength is either a integer (pixel count), a percentage, or
12 class HTMLPurifier_AttrDef_HTML_MultiLength
extends HTMLPurifier_AttrDef_HTML_Length
15 function validate($string, $config, &$context) {
17 $string = trim($string);
18 if ($string === '') return false;
20 $parent_result = parent
::validate($string, $config, $context);
21 if ($parent_result !== false) return $parent_result;
23 $length = strlen($string);
24 $last_char = $string[$length - 1];
26 if ($last_char !== '*') return false;
28 $int = substr($string, 0, $length - 1);
30 if ($int == '') return '*';
31 if (!is_numeric($int)) return false;
35 if ($int < 0) return false;
36 if ($int == 0) return '0';
37 if ($int == 1) return '*';
38 return ((string) $int) . '*';