File indexing completed on 2024-12-22 05:36:19
0001 <?php 0002 0003 /** 0004 * Post-transform that performs validation to the name attribute; if 0005 * it is present with an equivalent id attribute, it is passed through; 0006 * otherwise validation is performed. 0007 */ 0008 class HTMLPurifier_AttrTransform_NameSync extends HTMLPurifier_AttrTransform 0009 { 0010 0011 public function __construct() 0012 { 0013 $this->idDef = new HTMLPurifier_AttrDef_HTML_ID(); 0014 } 0015 0016 /** 0017 * @param array $attr 0018 * @param HTMLPurifier_Config $config 0019 * @param HTMLPurifier_Context $context 0020 * @return array 0021 */ 0022 public function transform($attr, $config, $context) 0023 { 0024 if (!isset($attr['name'])) { 0025 return $attr; 0026 } 0027 $name = $attr['name']; 0028 if (isset($attr['id']) && $attr['id'] === $name) { 0029 return $attr; 0030 } 0031 $result = $this->idDef->validate($name, $config, $context); 0032 if ($result === false) { 0033 unset($attr['name']); 0034 } else { 0035 $attr['name'] = $result; 0036 } 0037 return $attr; 0038 } 0039 } 0040 0041 // vim: et sw=4 sts=4