| 1: | <?php
|
| 2: |
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: |
|
| 9: | class HTMLPurifier_AttrDef_HTML_MultiLength extends HTMLPurifier_AttrDef_HTML_Length
|
| 10: | {
|
| 11: |
|
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: |
|
| 18: | public function validate($string, $config, $context)
|
| 19: | {
|
| 20: | $string = trim($string);
|
| 21: | if ($string === '') {
|
| 22: | return false;
|
| 23: | }
|
| 24: |
|
| 25: | $parent_result = parent::validate($string, $config, $context);
|
| 26: | if ($parent_result !== false) {
|
| 27: | return $parent_result;
|
| 28: | }
|
| 29: |
|
| 30: | $length = strlen($string);
|
| 31: | $last_char = $string[$length - 1];
|
| 32: |
|
| 33: | if ($last_char !== '*') {
|
| 34: | return false;
|
| 35: | }
|
| 36: |
|
| 37: | $int = substr($string, 0, $length - 1);
|
| 38: |
|
| 39: | if ($int == '') {
|
| 40: | return '*';
|
| 41: | }
|
| 42: | if (!is_numeric($int)) {
|
| 43: | return false;
|
| 44: | }
|
| 45: |
|
| 46: | $int = (int)$int;
|
| 47: | if ($int < 0) {
|
| 48: | return false;
|
| 49: | }
|
| 50: | if ($int == 0) {
|
| 51: | return '0';
|
| 52: | }
|
| 53: | if ($int == 1) {
|
| 54: | return '*';
|
| 55: | }
|
| 56: | return ((string)$int) . '*';
|
| 57: | }
|
| 58: | }
|
| 59: |
|
| 60: |
|
| 61: | |