Lang.php 856 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. /**
  3. * Post-transform that copies lang's value to xml:lang (and vice-versa)
  4. * @note Theoretically speaking, this could be a pre-transform, but putting
  5. * post is more efficient.
  6. */
  7. class HTMLPurifier_AttrTransform_Lang extends HTMLPurifier_AttrTransform
  8. {
  9. /**
  10. * @param array $attr
  11. * @param HTMLPurifier_Config $config
  12. * @param HTMLPurifier_Context $context
  13. * @return array
  14. */
  15. public function transform($attr, $config, $context)
  16. {
  17. $lang = isset($attr['lang']) ? $attr['lang'] : false;
  18. $xml_lang = isset($attr['xml:lang']) ? $attr['xml:lang'] : false;
  19. if ($lang !== false && $xml_lang === false) {
  20. $attr['xml:lang'] = $lang;
  21. } elseif ($xml_lang !== false) {
  22. $attr['lang'] = $xml_lang;
  23. }
  24. return $attr;
  25. }
  26. }
  27. // vim: et sw=4 sts=4