--- aggregator2.module	2005-10-09 15:16:10.000000000 -0500
+++ aggregator2.module.new	2005-10-13 03:55:00.000000000 -0500
@@ -369,6 +369,10 @@ function aggregator2_menu($may_cache) {
     $items[] = array('path' => 'aggregator2/opml', 'title' => t('opml'),
       'callback' => 'aggregator2_page_opml', 'access' => user_access(AGGREGATOR2_PERM_ACCESS_ITEM),
       'type' => MENU_CALLBACK);
+
+    $items[] = array('path' => 'aggregator2/sources', 'title' => t('news feeds'),
+        'callback' => 'aggregator2_page_source', 'access' => user_access(AGGREGATOR2_PERM_ACCESS_FEED),
+		'type' => MENU_NORMAL_ITEM, 'weight' => -10);
   }
   else {
     if (arg(0) == 'node' && is_numeric(arg(1))) {
@@ -391,6 +395,12 @@ function aggregator2_menu($may_cache) {
     }
   }
 
+  $result = db_query(db_rewrite_sql('SELECT n.nid, n.title FROM {node} n WHERE n.type = \'aggregator2-feed\' AND n.status = 1'));
+  while ($feed = db_fetch_object($result)) {
+    $items[] = array('path' => 'aggregator2/sources/'. $feed->nid, 'title' => $feed->title,
+        'callback' => 'aggregator2_page_source', 'access' => user_access(AGGREGATOR2_PERM_ACCESS_FEED),
+		'type' => MENU_NORMAL_ITEM, 'weight' => -10);
+  }
   return $items;
 }
 
@@ -1505,4 +1515,45 @@ function aggregator2_element_data($parse
   }
 }
 
+/**
+ * Menu callback; displays all the items captured from a particular feed.
+ */
+function aggregator2_page_source() {
+  if (arg(2)) {
+    $feed = db_fetch_object(db_query('SELECT af.*, n.body FROM {aggregator2_feed} af LEFT JOIN {node} n ON af.nid=n.nid WHERE af.nid = %d', arg(2)));
+    _aggregator2_page_list('SELECT ai.*, n.title FROM {aggregator2_item} ai LEFT JOIN {node} n ON ai.nid=n.nid WHERE ai.fid = '. $feed->nid .' ORDER BY n.sticky DESC, n.changed DESC, n.created DESC', "<div class=\"feed\">$feed->body</div>");
+  } else {
+    $feeds = db_query('SELECT af.*, n.title, n.body FROM {aggregator2_feed} af LEFT JOIN {node} n ON af.nid=n.nid');
+	$output = '<div id="aggregator"><dl>';
+	while ($feed = db_fetch_object($feeds)) {
+	  $output .= '<dt>' . l($feed->title, "aggregator2/sources/$feed->nid") . "</dt>\n";
+	  $output .= '<dd>' . $feed->body . "</dd>\n";
+	}
+	$output .= '<dl></div>';
+	print theme('page', $output);
+  }
+}
+
+/**
+ * Prints an aggregator page listing a number of feed items. Various
+ * menu callbacks use this function to print their feeds.
+ */
+function _aggregator2_page_list($sql, $header = '') {
+  $output = '<div id="aggregator">';
+  if ($header) {
+    $output .= $header;
+  }
+  $result = pager_query($sql, 20);
+  $rows = array();
+  while ($item = db_fetch_object($result)) {
+    $items[] = l($item->title, "node/$item->nid");
+  }
+  $output .= theme('item_list', $items);
+  $output .= '</div>';
+  if ($pager = theme('pager', NULL, 20, 0)) {
+    $output .= $pager;
+  }
+  print theme('page', $output);
+}
+
 ?>
