File indexing completed on 2024-05-12 06:02:04

0001 <?php
0002 
0003 /**
0004  * Post-transform that copies lang's value to xml:lang (and vice-versa)
0005  * @note Theoretically speaking, this could be a pre-transform, but putting
0006  *       post is more efficient.
0007  */
0008 class HTMLPurifier_AttrTransform_Lang extends HTMLPurifier_AttrTransform
0009 {
0010 
0011     /**
0012      * @param array $attr
0013      * @param HTMLPurifier_Config $config
0014      * @param HTMLPurifier_Context $context
0015      * @return array
0016      */
0017     public function transform($attr, $config, $context)
0018     {
0019         $lang = isset($attr['lang']) ? $attr['lang'] : false;
0020         $xml_lang = isset($attr['xml:lang']) ? $attr['xml:lang'] : false;
0021 
0022         if ($lang !== false && $xml_lang === false) {
0023             $attr['xml:lang'] = $lang;
0024         } elseif ($xml_lang !== false) {
0025             $attr['lang'] = $xml_lang;
0026         }
0027         return $attr;
0028     }
0029 }
0030 
0031 // vim: et sw=4 sts=4