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