File indexing completed on 2024-12-22 05:36:18
0001 <?php 0002 0003 /** 0004 * Framework class for strings that involve multiple values. 0005 * 0006 * Certain CSS properties such as border-width and margin allow multiple 0007 * lengths to be specified. This class can take a vanilla border-width 0008 * definition and multiply it, usually into a max of four. 0009 * 0010 * @note Even though the CSS specification isn't clear about it, inherit 0011 * can only be used alone: it will never manifest as part of a multi 0012 * shorthand declaration. Thus, this class does not allow inherit. 0013 */ 0014 class HTMLPurifier_AttrDef_CSS_Multiple extends HTMLPurifier_AttrDef 0015 { 0016 /** 0017 * Instance of component definition to defer validation to. 0018 * @type HTMLPurifier_AttrDef 0019 * @todo Make protected 0020 */ 0021 public $single; 0022 0023 /** 0024 * Max number of values allowed. 0025 * @todo Make protected 0026 */ 0027 public $max; 0028 0029 /** 0030 * @param HTMLPurifier_AttrDef $single HTMLPurifier_AttrDef to multiply 0031 * @param int $max Max number of values allowed (usually four) 0032 */ 0033 public function __construct($single, $max = 4) 0034 { 0035 $this->single = $single; 0036 $this->max = $max; 0037 } 0038 0039 /** 0040 * @param string $string 0041 * @param HTMLPurifier_Config $config 0042 * @param HTMLPurifier_Context $context 0043 * @return bool|string 0044 */ 0045 public function validate($string, $config, $context) 0046 { 0047 $string = $this->mungeRgb($this->parseCDATA($string)); 0048 if ($string === '') { 0049 return false; 0050 } 0051 $parts = explode(' ', $string); // parseCDATA replaced \r, \t and \n 0052 $length = count($parts); 0053 $final = ''; 0054 for ($i = 0, $num = 0; $i < $length && $num < $this->max; $i++) { 0055 if (ctype_space($parts[$i])) { 0056 continue; 0057 } 0058 $result = $this->single->validate($parts[$i], $config, $context); 0059 if ($result !== false) { 0060 $final .= $result . ' '; 0061 $num++; 0062 } 0063 } 0064 if ($final === '') { 0065 return false; 0066 } 0067 return rtrim($final); 0068 } 0069 } 0070 0071 // vim: et sw=4 sts=4