1 views.theme.inc template_preprocess_views_view_rss(&$variables)

Preprocess an RSS feed

File

core/modules/views/templates/views.theme.inc, line 962
Preprocessors and helper functions to make theme development easier.

Code

function template_preprocess_views_view_rss(&$variables) {
  global $base_url;
  global $language_content;

  $view = &$variables['view'];
  $options = &$variables['options'];
  $items = &$variables['rows'];

  $style = &$view->style_plugin;

  // 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 &).
  $variables['description'] = check_plain(decode_entities(strip_tags($style->get_description())));

  if ($view->display_handler->get_option('sitename_title')) {
    $site_config = config('system.core');
    $title = $site_config->get('site_name');
    if ($slogan = $site_config->getTranslated('site_slogan')) {
      $title .= ' - ' . $slogan;
    }
  }
  else {
    $title = $view->get_title();
  }
  $variables['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->get_link_display();
  if ($link_display_id && !empty($view->display[$link_display_id])) {
    $path = $view->display[$link_display_id]->handler->get_path();
  }

  if ($path) {
    $path = $view->get_url(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('system.core', 'site_frontpage')) {
      $path = '';
    }

    $variables['link'] = check_url(url($path, $url_options));
  }

  $variables['langcode'] = check_plain($language_content->langcode);
  $variables['namespaces'] = backdrop_attributes($style->namespaces);
  $variables['items'] = $items;
  $variables['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($variables['view']->live_preview)) {
    backdrop_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8');
  }
}