|
Revision 21, 1.1 kB
(checked in by admin, 18 years ago)
|
|
|
| Line | |
|---|
| 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 | class HTMLPurifier_AttrDef_HTML_MultiLength extends HTMLPurifier_AttrDef_HTML_Length |
|---|
| 10 | { |
|---|
| 11 | |
|---|
| 12 | public function validate($string, $config, $context) { |
|---|
| 13 | |
|---|
| 14 | $string = trim($string); |
|---|
| 15 | if ($string === '') return false; |
|---|
| 16 | |
|---|
| 17 | $parent_result = parent::validate($string, $config, $context); |
|---|
| 18 | if ($parent_result !== false) return $parent_result; |
|---|
| 19 | |
|---|
| 20 | $length = strlen($string); |
|---|
| 21 | $last_char = $string[$length - 1]; |
|---|
| 22 | |
|---|
| 23 | if ($last_char !== '*') return false; |
|---|
| 24 | |
|---|
| 25 | $int = substr($string, 0, $length - 1); |
|---|
| 26 | |
|---|
| 27 | if ($int == '') return '*'; |
|---|
| 28 | if (!is_numeric($int)) return false; |
|---|
| 29 | |
|---|
| 30 | $int = (int) $int; |
|---|
| 31 | |
|---|
| 32 | if ($int < 0) return false; |
|---|
| 33 | if ($int == 0) return '0'; |
|---|
| 34 | if ($int == 1) return '*'; |
|---|
| 35 | return ((string) $int) . '*'; |
|---|
| 36 | |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | } |
|---|
| 40 | |
|---|