File indexing completed on 2024-12-22 05:36:18
0001 <?php 0002 0003 /** 0004 * Validates a MultiLength as defined by the HTML spec. 0005 * 0006 * A multilength is either a integer (pixel count), a percentage, or 0007 * a relative number. 0008 */ 0009 class HTMLPurifier_AttrDef_HTML_MultiLength extends HTMLPurifier_AttrDef_HTML_Length 0010 { 0011 0012 /** 0013 * @param string $string 0014 * @param HTMLPurifier_Config $config 0015 * @param HTMLPurifier_Context $context 0016 * @return bool|string 0017 */ 0018 public function validate($string, $config, $context) 0019 { 0020 $string = trim($string); 0021 if ($string === '') { 0022 return false; 0023 } 0024 0025 $parent_result = parent::validate($string, $config, $context); 0026 if ($parent_result !== false) { 0027 return $parent_result; 0028 } 0029 0030 $length = strlen($string); 0031 $last_char = $string[$length - 1]; 0032 0033 if ($last_char !== '*') { 0034 return false; 0035 } 0036 0037 $int = substr($string, 0, $length - 1); 0038 0039 if ($int == '') { 0040 return '*'; 0041 } 0042 if (!is_numeric($int)) { 0043 return false; 0044 } 0045 0046 $int = (int)$int; 0047 if ($int < 0) { 0048 return false; 0049 } 0050 if ($int == 0) { 0051 return '0'; 0052 } 0053 if ($int == 1) { 0054 return '*'; 0055 } 0056 return ((string)$int) . '*'; 0057 } 0058 } 0059 0060 // vim: et sw=4 sts=4