Same name and namespace in other branches
  1. 4.7.x modules/node.module \node_feed()
  2. 5.x modules/node/node.module \node_feed()
  3. 6.x modules/node/node.module \node_feed()
  4. 7.x modules/node/node.module \node_feed()

A generic function for generating RSS feeds from a set of nodes.

Parameters

$nodes: An object as returned by db_query() which contains the nid field.

$channel: An associative array containing title, link, description and other keys. The link should be an absolute URL.

2 calls to node_feed()
blog_feed_last in modules/blog.module
Displays an RSS feed containing recent blog entries of all users.
blog_feed_user in modules/blog.module
Displays an RSS feed containing recent blog entries of a given user.

File

modules/node.module, line 1158
The core that allows content to be submitted to the site.

Code

function node_feed($nodes = 0, $channel = array()) {
  global $base_url, $locale;
  if (!$nodes) {
    $nodes = db_query_range(db_rewrite_sql('SELECT n.nid FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.created DESC'), 0, 15);
  }
  while ($node = db_fetch_object($nodes)) {

    // Load the specified node:
    $item = node_load(array(
      'nid' => $node->nid,
    ));
    $link = url("node/{$node->nid}", NULL, NULL, 1);

    // Filter and prepare node teaser
    if (node_hook($item, 'view')) {
      node_invoke($item, 'view', TRUE, FALSE);
    }
    else {
      $item = node_prepare($item, TRUE);
    }

    // Allow modules to change $node->teaser before viewing.
    node_invoke_nodeapi($item, 'view', true, false);

    // Allow modules to add additional item fields
    $extra = node_invoke_nodeapi($item, 'rss item');
    $extra = array_merge($extra, array(
      array(
        'key' => 'pubDate',
        'value' => date('r', $item->created),
      ),
    ));
    $items .= format_rss_item($item->title, $link, $item->teaser, $extra);
  }
  $slogan = variable_get('site_slogan', '');
  $spacer = ' - ';
  if (empty($slogan)) {
    $spacer = '';
  }
  $channel_defaults = array(
    'version' => '2.0',
    'title' => variable_get('site_name', 'drupal') . $spacer . $slogan,
    'link' => $base_url,
    'description' => variable_get('site_mission', ''),
    'language' => $locale,
  );
  $channel = array_merge($channel_defaults, $channel);
  $output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  $output .= "<!DOCTYPE rss [<!ENTITY % HTMLlat1 PUBLIC \"-//W3C//ENTITIES Latin 1 for XHTML//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent\">]>\n";
  $output .= "<rss version=\"" . $channel["version"] . "\" xml:base=\"" . $base_url . "\">\n";
  $output .= format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language']);
  $output .= "</rss>\n";
  drupal_set_header('Content-Type: text/xml; charset=utf-8');
  print $output;
}