You are here

function template_preprocess_views_data_export_xml_body in Views data export 6.3

Same name and namespace in other branches
  1. 6 theme/views_data_export.theme.inc \template_preprocess_views_data_export_xml_body()
  2. 6.2 theme/views_data_export.theme.inc \template_preprocess_views_data_export_xml_body()
  3. 7.4 theme/views_data_export.theme.inc \template_preprocess_views_data_export_xml_body()
  4. 7 theme/views_data_export.theme.inc \template_preprocess_views_data_export_xml_body()
  5. 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 368
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);
  _views_data_export_body_shared_preprocess($vars);

  // Compute the tag name based on the views base table, minus any trailing 's'.
  $vars['item_node'] = _views_data_export_xml_tag_clean(rtrim($vars['view']->base_table, 's'));
  foreach ($vars['themed_rows'] as $num => $row) {
    foreach ($row as $field => $content) {

      // 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(
        '&lt;',
        '&gt;',
      ), $content);
      $vars['themed_rows'][$num][$field] = $content;
    }
  }
  foreach ($vars['header'] as $field => $header) {

    // If there is no field label, use 'no name'.
    $vars['xml_tag'][$field] = !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]);
  }
}