|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00009 class HTMLPurifier_AttrDef_HTML_MultiLength extends HTMLPurifier_AttrDef_HTML_Length 00010 { 00011 00012 public function validate($string, $config, $context) { 00013 00014 $string = trim($string); 00015 if ($string === '') return false; 00016 00017 $parent_result = parent::validate($string, $config, $context); 00018 if ($parent_result !== false) return $parent_result; 00019 00020 $length = strlen($string); 00021 $last_char = $string[$length - 1]; 00022 00023 if ($last_char !== '*') return false; 00024 00025 $int = substr($string, 0, $length - 1); 00026 00027 if ($int == '') return '*'; 00028 if (!is_numeric($int)) return false; 00029 00030 $int = (int) $int; 00031 00032 if ($int < 0) return false; 00033 if ($int == 0) return '0'; 00034 if ($int == 1) return '*'; 00035 return ((string) $int) . '*'; 00036 00037 } 00038 00039 } 00040 00041 // vim: et sw=4 sts=4