/** * combine attribute values in a tag string */ public static function combineAttributes($string1, $string2) { $attribs1 = is_array($string1) ? $string1 : RLText::getAttributes($string1); $attribs2 = is_array($string2) ? $string2 : RLText::getAttributes($string2); $dublicate_attribs = array_intersect_key($attribs1, $attribs2); // Fill $attribs with the unique ids $attribs = array_diff_key($attribs1, $attribs2) + array_diff_key($attribs2, $attribs1); // Add/combine the duplicate ids $single_value_attributes = array('id', 'href'); foreach ($dublicate_attribs as $key => $val) { if (in_array($key, $single_value_attributes)) { $attribs[$key] = $attribs2[$key]; continue; } // Combine strings, but remove duplicates // "aaa bbb" + "aaa ccc" = "aaa bbb ccc" // use a ';' as a concatenated for javascript values (keys beginning with 'on') $glue = substr($key, 0, 2) == 'on' ? ';' : ' '; $attribs[$key] = implode($glue, array_merge(explode($glue, $attribs1[$key]), explode($glue, $attribs2[$key]))); } foreach ($attribs as $key => &$val) { $val = $key . '="' . $val . '"'; } return implode(' ', $attribs); }