You are here

function feedapi_aggregator_page_rss in FeedAPI 5

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

1 string reference to 'feedapi_aggregator_page_rss'
feedapi_aggregator_menu in feedapi_aggregator/feedapi_aggregator.module
Implementation of hook_menu().

File

feedapi_aggregator/feedapi_aggregator.module, line 692

Code

function feedapi_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 {feedapi_aggregator_category} WHERE cid = %d', arg(2)));
    $url = '/categories/' . $category->cid;
    $title = ' ' . t('in category') . ' ' . $category->title;
    $sql = 'SELECT i.*, n.title AS ftitle, f.url AS flink FROM {feedapi_aggregator_category_item} c LEFT JOIN {feedapi_aggregator_item} i ON c.iid = i.iid LEFT JOIN {feedapi} f ON i.feed_nid = f.nid LEFT JOIN {node} n ON f.nid = n.nid 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.*, n.title AS ftitle, f.link AS flink FROM {feedapi_aggregator_item} i INNER JOIN {feedapi} f ON i.feed_nid = f.nid LEFT JOIN {node} n ON f.nid = n.nid 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;
}