Lang.php 711 B

12345678910111213141516171819202122232425262728
  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. public function transform($attr, $config, $context) {
  10. $lang = isset($attr['lang']) ? $attr['lang'] : false;
  11. $xml_lang = isset($attr['xml:lang']) ? $attr['xml:lang'] : false;
  12. if ($lang !== false && $xml_lang === false) {
  13. $attr['xml:lang'] = $lang;
  14. } elseif ($xml_lang !== false) {
  15. $attr['lang'] = $xml_lang;
  16. }
  17. return $attr;
  18. }
  19. }
  20. // vim: et sw=4 sts=4