You are here

function aggregator_page_rss in Drupal 5

Same name and namespace in other branches
  1. 4 modules/aggregator.module \aggregator_page_rss()
  2. 6 modules/aggregator/aggregator.pages.inc \aggregator_page_rss()
  3. 7 modules/aggregator/aggregator.pages.inc \aggregator_page_rss()

Menu callback; generate an RSS 0.92 feed of aggregator items or categories.

1 string reference to 'aggregator_page_rss'
aggregator_menu in modules/aggregator/aggregator.module
Implementation of hook_menu().

File

modules/aggregator/aggregator.module, line 1205
Used to aggregate syndicated content (RSS, RDF, and Atom).

Code

function aggregator_page_rss() {

  // arg(2) is the passed cid, only select for that category
  $result = NULL;
  if (arg(2)) {
    $category = db_fetch_object(db_query('SELECT cid, title FROM {aggregator_category} WHERE cid = %d', arg(2)));
    $url = '/categories/' . $category->cid;
    $title = ' ' . t('in category') . ' ' . $category->title;
    $sql = 'SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_category_item} c LEFT JOIN {aggregator_item} i ON c.iid = i.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE cid = %d ORDER BY timestamp DESC, iid DESC';
    $result = db_query_range($sql, $category->cid, 0, variable_get('feed_default_items', 10));
  }
  else {
    $sql = 'SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_item} i INNER JOIN {aggregator_feed} f ON i.fid = f.fid ORDER BY i.timestamp DESC, i.iid DESC';
    $result = db_query_range($sql, 0, variable_get('feed_default_items', 10));
  }
  while ($item = db_fetch_object($result)) {
    switch (variable_get('feed_item_length', 'teaser')) {
      case 'teaser':
        $teaser = node_teaser($item->description);
        if ($teaser != $item->description) {
          $teaser .= '<p><a href="' . check_url($item->link) . '">' . t('read more') . "</a></p>\n";
        }
        $item->description = $teaser;
        break;
      case 'title':
        $item->description = '';
        break;
    }
    $items .= format_rss_item($item->ftitle . ': ' . $item->title, $item->link, $item->description, array(
      'pubDate' => date('r', $item->timestamp),
    ));
  }
  $output .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  $output .= "<rss version=\"2.0\">\n";
  $output .= format_rss_channel(variable_get('site_name', 'Drupal') . ' ' . t('aggregator'), url('aggregator' . $url, NULL, NULL, TRUE), variable_get('site_name', 'Drupal') . ' - ' . t('aggregated feeds') . $title, $items, 'en');
  $output .= "</rss>\n";
  drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
  print $output;
}