Name.php 808 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * Pre-transform that changes deprecated name attribute to ID if necessary
  4. */
  5. class HTMLPurifier_AttrTransform_Name extends HTMLPurifier_AttrTransform
  6. {
  7. /**
  8. * @param array $attr
  9. * @param HTMLPurifier_Config $config
  10. * @param HTMLPurifier_Context $context
  11. * @return array
  12. */
  13. public function transform($attr, $config, $context)
  14. {
  15. // Abort early if we're using relaxed definition of name
  16. if ($config->get('HTML.Attr.Name.UseCDATA')) {
  17. return $attr;
  18. }
  19. if (!isset($attr['name'])) {
  20. return $attr;
  21. }
  22. $id = $this->confiscateAttr($attr, 'name');
  23. if (isset($attr['id'])) {
  24. return $attr;
  25. }
  26. $attr['id'] = $id;
  27. return $attr;
  28. }
  29. }
  30. // vim: et sw=4 sts=4