3 require_once 'HTMLPurifier/AttrDef.php';
4 require_once 'HTMLPurifier/AttrDef/HTML/Pixels.php';
7 * Validates the HTML type length (not to be confused with CSS's length).
9 * This accepts integer pixels or percentages as lengths for certain
13 class HTMLPurifier_AttrDef_HTML_Length
extends HTMLPurifier_AttrDef_HTML_Pixels
16 function validate($string, $config, &$context) {
18 $string = trim($string);
19 if ($string === '') return false;
21 $parent_result = parent
::validate($string, $config, $context);
22 if ($parent_result !== false) return $parent_result;
24 $length = strlen($string);
25 $last_char = $string[$length - 1];
27 if ($last_char !== '%') return false;
29 $points = substr($string, 0, $length - 1);
31 if (!is_numeric($points)) return false;
33 $points = (int) $points;
35 if ($points < 0) return '0%';
36 if ($points > 100) return '100%';
38 return ((string) $points) . '%';