Skip to content
views_rss_views_fields.theme.inc 2.68 KiB
Newer Older
Alex Barth's avatar
Alex Barth committed
/**
 * Template preprocessor for views-view-views-rss-fields.tpl.php.
 */
function template_preprocess_views_view_views_rss_fields(&$vars) {
  $view = $vars['view'];
  // Set basic info - title, description - about the feed
  if ($view->display_handler->get_option('sitename_title')) {
    $title = variable_get('site_name', 'Drupal');
    if ($slogan = variable_get('site_slogan', '')) {
      $title .= ' - ' . $slogan;
    }
  }
  else {
    $title = $view->get_title();
  }
  $vars['viewtitle'] = check_plain($title);
  if ($view->style_options['description']['feed_description']) {
    $description = $view->style_options['description']['feed_description'];
Alex Barth's avatar
Alex Barth committed
    $description = variable_get('site_mission', '');
Alex Barth's avatar
Alex Barth committed
  $vars['description'] = theme('views_rss_feed_description', $description, $view);
  // Base URL for link tag
  global $base_url;
  $vars['link'] = $base_url;

  // Grab the rows, push to field mapping function, gather namespaces.
  $elements = $namespaces = array();
Alex Barth's avatar
Alex Barth committed
  $rows = '';
  $items = $view->style_plugin->map_rows($vars['rows']);
  foreach($items as $item) {
    // Special handling for GeoRSS.
    if (is_numeric($item['lat']) && is_numeric($item['lon'])) {
      $item['georss:point'] = $item['lat'] .' '.  $item['lon'];
    }
    if(isset($item['featureName'])) {
      $item['georss:featureName'] = $item['featureName'];
    }
Alex Barth's avatar
Alex Barth committed
    unset($item['lat']);
    unset($item['lon']);
    $rows .= theme('views_rss_fields_item', $item);
    foreach ($item as $k => $v) {
      $elements[$k] = $k;
    }
  foreach ($elements as $e) {
    if ($namespace = $view->style_plugin->xml_namespace($e)) {
      $namespaces[] = "xmlns:{$namespace['local']}=\"{$namespace['namespace']}\"";
    }
  $vars['namespaces'] = implode(' ', array_unique($namespaces));
  // Set Headers
  drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
Alex Barth's avatar
Alex Barth committed
 * Template preprocessor for views-rss-fields-item.tpl.php.
function template_preprocess_views_rss_fields_item(&$vars) {
  $item = $vars['item'];
  // Loop through key=>value pairs
Alex Barth's avatar
Alex Barth committed
  $row = '';
  foreach ($item as $key => $value) {
    if ($value) {
      $row .= "<$key>". check_plain(htmlspecialchars_decode($value)) ."</$key>\n";
    }
  }

  $vars['row'] = $row;
}

/**
 * Theme function for feed icon.
 */
function theme_views_rss_feed_icon($url, $title, $icon) {
  if ($image = theme('image', $icon, t('Download RSS Feed'), $title)) {
    return '<a href="'. check_url($url) .'" class="feed-icon">'. $image .'</a>';
  }
}

/**
Alex Barth's avatar
Alex Barth committed
 * Theme function for feed description.
 */
function theme_views_rss_feed_description($description, $view) {
  return $description;
}