From 0fef1502275e7cd0c185d68a77b89ef9afdd4799 Mon Sep 17 00:00:00 2001 From: Steven Wittens Date: Mon, 17 Jul 2006 15:42:55 +0000 Subject: #74109: format_rss_channel() does not allow attributes (+ clean up code) --- includes/common.inc | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'includes/common.inc') diff --git a/includes/common.inc b/includes/common.inc index 5ee01d2ee..87101ff27 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -717,9 +717,7 @@ function format_rss_channel($title, $link, $description, $items, $language = 'en // escaped source data (such as & becoming &amp;). $output .= ' '. check_plain(decode_entities(strip_tags($description))) ."\n"; $output .= ' '. check_plain($language) ."\n"; - foreach ($args as $key => $value) { - $output .= ' <'. $key .'>'. check_plain($value) ."\n"; - } + $output .= format_xml_elements($args); $output .= $items; $output .= "\n"; @@ -736,16 +734,37 @@ function format_rss_item($title, $link, $description, $args = array()) { $output .= ' '. check_plain($title) ."\n"; $output .= ' '. check_url($link) ."\n"; $output .= ' '. check_plain($description) ."\n"; - foreach ($args as $key => $value) { - if (is_array($value)) { + $output .= format_xml_elements($args); + $output .= "\n"; + + return $output; +} + +/** + * Format XML elements. + * + * @param $array + * An array where each item represent an element and is either a: + * - (key => value) pair (value) + * - Associative array with fields: + * - 'key': element name + * - 'value': element contents + * - 'attributes': associative array of element attributes + * + * In both cases, 'value' can be a simple string, or it can be another array + * with the same format as $array itself for nesting. + */ +function format_xml_elements($array) { + foreach ($array as $key => $value) { + if (is_numeric($key)) { if ($value['key']) { $output .= ' <'. $value['key']; if (isset($value['attributes']) && is_array($value['attributes'])) { $output .= drupal_attributes($value['attributes']); } - if ($value['value']) { - $output .= '>'. $value['value'] .'\n"; + if ($value['value'] != '') { + $output .= '>'. (is_array($value['value']) ? format_xml_tags($value['value']) : check_plain($value['value'])) .'\n"; } else { $output .= " />\n"; @@ -753,11 +772,9 @@ function format_rss_item($title, $link, $description, $args = array()) { } } else { - $output .= ' <'. $key .'>'. check_plain($value) ."\n"; + $output .= ' <'. $key .'>'. (is_array($value) ? format_xml_tags($value) : check_plain($value)) ."\n"; } } - $output .= "\n"; - return $output; } -- cgit v1.2.3