Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / lib / htmlpurifier / HTMLPurifier / AttrDef / HTML / MultiLength.php
blobf50259b6fd57bd3c8a6fc085632ebf04bcf19146
1 <?php
3 require_once 'HTMLPurifier/AttrDef.php';
4 require_once 'HTMLPurifier/AttrDef/HTML/Length.php';
6 /**
7 * Validates a MultiLength as defined by the HTML spec.
8 *
9 * A multilength is either a integer (pixel count), a percentage, or
10 * a relative number.
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;
33 $int = (int) $int;
35 if ($int < 0) return false;
36 if ($int == 0) return '0';
37 if ($int == 1) return '*';
38 return ((string) $int) . '*';