1: <?php
2:
3: /**
4: * Post-transform that performs validation to the name attribute; if
5: * it is present with an equivalent id attribute, it is passed through;
6: * otherwise validation is performed.
7: */
8: class HTMLPurifier_AttrTransform_NameSync extends HTMLPurifier_AttrTransform
9: {
10:
11: /**
12: * @type HTMLPurifier_AttrDef_HTML_ID
13: */
14: public $idDef;
15:
16: public function __construct()
17: {
18: $this->idDef = new HTMLPurifier_AttrDef_HTML_ID();
19: }
20:
21: /**
22: * @param array $attr
23: * @param HTMLPurifier_Config $config
24: * @param HTMLPurifier_Context $context
25: * @return array
26: */
27: public function transform($attr, $config, $context)
28: {
29: if (!isset($attr['name'])) {
30: return $attr;
31: }
32: $name = $attr['name'];
33: if (isset($attr['id']) && $attr['id'] === $name) {
34: return $attr;
35: }
36: $result = $this->idDef->validate($name, $config, $context);
37: if ($result === false) {
38: unset($attr['name']);
39: } else {
40: $attr['name'] = $result;
41: }
42: return $attr;
43: }
44: }
45:
46: // vim: et sw=4 sts=4
47: