function template_preprocess_views_view_rss

Preprocess an RSS feed

File

drupal/core/modules/views/theme/theme.inc, line 864
Preprocessors and helper functions to make theming easier.

Code

function template_preprocess_views_view_rss(&$vars) {
  global $base_url;
  $view =& $vars['view'];
  $options =& $vars['options'];
  $items =& $vars['rows'];
  $style =& $view->style_plugin;
  $config = config('system.site');

  // The RSS 2.0 "spec" doesn't indicate HTML can be used in the description.
  // We strip all HTML tags, but need to prevent double encoding from properly
  // escaped source data (such as &amp becoming &).
  $vars['description'] = check_plain(decode_entities(strip_tags($style
    ->get_description())));
  if ($view->display_handler
    ->getOption('sitename_title')) {
    $title = $config
      ->get('name');
    if ($slogan = $config
      ->get('slogan')) {
      $title .= ' - ' . $slogan;
    }
  }
  else {
    $title = $view
      ->getTitle();
  }
  $vars['title'] = check_plain($title);

  // Figure out which display which has a path we're using for this feed. If there isn't
  // one, use the global $base_url
  $link_display_id = $view->display_handler
    ->getLinkDisplay();
  if ($link_display_id && !empty($view->displayHandlers[$link_display_id])) {
    $path = $view->displayHandlers[$link_display_id]
      ->getPath();
  }
  if ($path) {
    $path = $view
      ->getUrl(NULL, $path);
    $url_options = array(
      'absolute' => TRUE,
    );
    if (!empty($view->exposed_raw_input)) {
      $url_options['query'] = $view->exposed_raw_input;
    }

    // Compare the link to the default home page; if it's the default home page, just use $base_url.
    if ($path == $config
      ->get('page.front')) {
      $path = '';
    }
    $vars['link'] = check_url(url($path, $url_options));
  }
  $vars['langcode'] = check_plain(language(LANGUAGE_TYPE_INTERFACE)->langcode);
  $vars['namespaces'] = new Attribute($style->namespaces);
  $vars['items'] = $items;
  $vars['channel_elements'] = format_xml_elements($style->channel_elements);

  // During live preview we don't want to output the header since the contents
  // of the feed are being displayed inside a normal HTML page.
  if (empty($vars['view']->live_preview)) {
    $vars['view']
      ->getResponse()->headers
      ->set('Content-Type', 'application/rss+xml; charset=utf-8');
  }
}