function template_preprocess_views_views_xml_style_raw in Views Datasource 7
Same name and namespace in other branches
- 6 theme/views_views_xml_style.theme.inc \template_preprocess_views_views_xml_style_raw()
@file View template to render view fields as XML.
- $view: The view in use.
- $rows: Array of row objects as rendered by _views_json_render_fields
- $attachment: not used currently
- $options: The options for the style passed in from the UI.
See also
File
- views/
theme/ views_views_xml_style.theme.inc, line 15 - View template to render view fields as XML.
Code
function template_preprocess_views_views_xml_style_raw(&$vars) {
$view = $vars["view"];
$rows = $vars["rows"];
$options = $vars["options"];
$base = $view->base_table;
$root = $options['root_element'];
$endroot = preg_replace("/\\s+.*/", "", $root);
$top_child_object = $options["top_child_object"];
$end_top_child_object = preg_replace("/\\s+.*/", "", $top_child_object);
$plaintext_output = $options["plaintext_output"];
$vars["content_type"] = $options['content_type'] == 'default' ? 'text/xml' : $options['content_type'];
$header = $options['header'];
$xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
if ($header) {
$xml .= $header . "\n";
}
$xml .= "<{$root}>\n";
foreach ($rows as $row) {
$xml .= $options['element_output'] == 'nested' ? " <{$top_child_object}>\n" : " <{$top_child_object}\n";
foreach ($row as $id => $object) {
if ($options['field_output'] == 'normal') {
if ($object->label) {
$label = _views_xml_strip_illegal_xml_name_chars(check_plain(html_entity_decode(strip_tags($object->label))));
}
else {
$label = _views_xml_strip_illegal_xml_name_chars(check_plain(html_entity_decode(strip_tags($id))));
}
if (!$object->is_multiple) {
$content = $plaintext_output ? check_plain(html_entity_decode(strip_tags($object->content))) : _views_xml_xmlEntities($object->content);
}
else {
$content = array();
foreach ($object->content as $n => $oc) {
$content[$n] = $plaintext_output ? check_plain(html_entity_decode(strip_tags($oc))) : _views_xml_xmlEntities($oc);
}
}
}
elseif ($options['field_output'] == 'raw') {
$label = _views_xml_strip_illegal_xml_name_chars(check_plain(html_entity_decode(strip_tags($id))));
if (!$object->is_multiple) {
$content = $plaintext_output ? check_plain(html_entity_decode(strip_tags($object->raw))) : _views_xml_xmlEntities($object->raw);
}
else {
foreach ($object->raw as $n => $oc) {
$content[$n] = $plaintext_output ? check_plain(html_entity_decode(strip_tags($oc))) : _views_xml_xmlEntities($oc);
}
}
}
$endlabel = preg_replace("/\\s+.*/", "", $label);
if ($options['element_output'] == 'nested') {
if (!is_array($content)) {
$xml .= " <{$label}>" . ($options['escape_as_CDATA'] == 'yes' ? "<![CDATA[{$content}]]>" : $content) . "</{$endlabel}>\n";
//_views_xml_debug_stop($xml);
}
else {
foreach ($content as $c) {
$xml .= " <{$label}>";
$xml .= "" . ($options['escape_as_CDATA'] == 'yes' ? "<![CDATA[{$c}]]>" : $c . "");
$xml .= "</{$endlabel}>\n";
}
}
}
elseif ($options['element_output'] == 'attributes') {
if (!is_array($content)) {
$content = _views_xml_strip_illegal_xml_attribute_value_chars($content);
$xml .= " {$label}=\"{$content}\" ";
}
else {
foreach ($content as $n => $c) {
$c = _views_xml_strip_illegal_xml_attribute_value_chars($c);
$label = _views_xml_strip_illegal_xml_name_chars($label);
$xml .= " {$label}{$n}=\"{$c}\" ";
}
}
}
}
$xml .= $options['element_output'] == 'nested' ? " </{$end_top_child_object}>\n" : "/>\n";
}
$xml .= "</{$endroot}>\n";
$vars["xml"] = $xml;
}