function template_preprocess_views_data_export_xml_body in Views data export 7.4
Same name and namespace in other branches
- 6.3 theme/views_data_export.theme.inc \template_preprocess_views_data_export_xml_body()
- 6 theme/views_data_export.theme.inc \template_preprocess_views_data_export_xml_body()
- 6.2 theme/views_data_export.theme.inc \template_preprocess_views_data_export_xml_body()
- 7 theme/views_data_export.theme.inc \template_preprocess_views_data_export_xml_body()
- 7.3 theme/views_data_export.theme.inc \template_preprocess_views_data_export_xml_body()
Preprocess xml output template.
File
- theme/
views_data_export.theme.inc, line 371 - Theme related functions for processing our output style plugins.
Code
function template_preprocess_views_data_export_xml_body(&$vars) {
_views_data_export_header_shared_preprocess($vars);
// We support not outputting fields when they are empty, so indicate so.
$vars['hide_empty_support'] = TRUE;
_views_data_export_body_shared_preprocess($vars);
$view = $vars['view'];
$style_options = $view->display_handler
->get_option('style_options');
$no_encode = isset($style_options['no_entity_encode']) ? $style_options['no_entity_encode'] : array();
$cdata_wrapper = isset($style_options['cdata_wrapper']) ? $style_options['cdata_wrapper'] : array();
$vars['item_node'] = _views_data_export_xml_tag_clean($vars['options']['item_node']);
foreach ($vars['themed_rows'] as $num => $row) {
foreach ($row as $field => $content) {
// Perform xml entity encoding unless excluded by style options.
if (empty($no_encode[$field]) && empty($cdata_wrapper[$field])) {
// Prevent double encoding of the ampersand. Look for the entities produced by check_plain().
$content = preg_replace('/&(?!(amp|quot|#039|lt|gt);)/', '&', $content);
// Convert < and > to HTML entities.
$content = str_replace(array(
'<',
'>',
), array(
'<',
'>',
), $content);
}
// Perform wrapping the field data using the CDATA tag
// unless excluded by style options.
if (!empty($cdata_wrapper[$field])) {
// Escape CDATA end sequence only.
$content = '<![CDATA[' . str_replace(']]>', ']]]]><![CDATA[>', $content) . ']]>';
}
$vars['themed_rows'][$num][$field] = $content;
}
}
foreach ($vars['header'] as $field => $header) {
// If there is no field label, use 'no name'.
if (empty($header)) {
$header = 'no name';
}
if ($vars['options']['transform']) {
switch ($vars['options']['transform_type']) {
case 'dash':
$vars['xml_tag'][$field] = str_replace(' ', '-', $header);
break;
case 'underline':
$vars['xml_tag'][$field] = str_replace(' ', '_', $header);
break;
case 'camel':
$vars['xml_tag'][$field] = str_replace(' ', '', ucwords(strtolower($header)));
// Convert the very first character of the string to lowercase.
$vars['xml_tag'][$field][0] = strtolower($vars['xml_tag'][$field][0]);
break;
case 'pascal':
$vars['xml_tag'][$field] = str_replace(' ', '', ucwords(strtolower($header)));
break;
}
}
// We should always try to output valid XML.
$vars['xml_tag'][$field] = _views_data_export_xml_tag_clean($vars['xml_tag'][$field]);
}
}