NameSync.php 798 B

123456789101112131415161718192021222324252627
  1. <?php
  2. /**
  3. * Post-transform that performs validation to the name attribute; if
  4. * it is present with an equivalent id attribute, it is passed through;
  5. * otherwise validation is performed.
  6. */
  7. class HTMLPurifier_AttrTransform_NameSync extends HTMLPurifier_AttrTransform
  8. {
  9. public function __construct() {
  10. $this->idDef = new HTMLPurifier_AttrDef_HTML_ID();
  11. }
  12. public function transform($attr, $config, $context) {
  13. if (!isset($attr['name'])) return $attr;
  14. $name = $attr['name'];
  15. if (isset($attr['id']) && $attr['id'] === $name) return $attr;
  16. $result = $this->idDef->validate($name, $config, $context);
  17. if ($result === false) unset($attr['name']);
  18. else $attr['name'] = $result;
  19. return $attr;
  20. }
  21. }
  22. // vim: et sw=4 sts=4