You are here

function template_preprocess_views_view_kml in KML 7

Same name and namespace in other branches
  1. 6.2 views/kml_views.theme.inc \template_preprocess_views_view_kml()

@file Theming functions for KML module views output.

File

views/kml_views.theme.inc, line 8
Theming functions for KML module views output.

Code

function template_preprocess_views_view_kml(&$vars) {
  $view = $vars['view'];
  $points = $view->style_plugin
    ->map_rows($vars['rows']);
  $style = theme('kml_style', array(
    'points' => $points,
  ));
  $rows = '';
  foreach ($points as $point) {
    $rows .= theme('kml_placemark', array(
      'point' => $point,
      'points' => $points,
    ));
  }
  $vars['rows'] = $rows;
  $vars['style'] = $style;
  $vars['viewtitle'] = $view
    ->get_title();

  // Checks if filename is manually specified in view style options otherwise
  // it sets it as the name of the view.
  if (!empty($view->style_options['filename'])) {
    $filename = $view->style_options['filename'] . '.kml';
  }
  else {
    $filename = $vars['viewtitle'] . '.kml';
  }
  if (empty($vars['view']->live_preview)) {
    drupal_add_http_header('Content-Type', 'application/vnd.google-earth.kml+xml; charset=utf-8');
    drupal_add_http_header('Content-Disposition', "attachment; filename=\"{$filename}\"");
  }
}