Index: modules/aggregator.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/aggregator.module,v
retrieving revision 1.271
diff -u -F^f -r1.271 aggregator.module
--- modules/aggregator.module	10 Feb 2006 05:25:57 -0000	1.271
+++ modules/aggregator.module	16 Feb 2006 12:56:47 -0000
@@ -928,8 +928,6 @@ function aggregator_page_category() {
 function _aggregator_page_list($sql, $op, $header = '') {
   $categorize = (user_access('administer news feeds') && ($op == 'categorize'));
 
-  $output = '<div id="aggregator">';
-
   $form['header'] = array('#value' => $header);
   $output .= $form['header']['#value'];
 
@@ -960,7 +958,7 @@ function _aggregator_page_list($sql, $op
       );
     }
   }
-  $output .= '</div>';
+  $output = theme('aggregator', $output);
   $form['submit'] = array('#type' => 'submit', '#value' => t('Save categories'));
   $form['pager'] = array('#value' => theme('pager', NULL, 20, 0));
   $output .= $form['pager']['#value'];
@@ -978,9 +976,13 @@ function _aggregator_page_list($sql, $op
   return ($categorize) ? drupal_get_form('aggregator_page_list', $form) : $output;
 }
 
+
+/**
+ * Formats the form of _aggregator_page_list()
+ * @ingroup themeable
+ */
 function theme_aggregator_page_list($form) {
-  $output = '<div id="aggregator">';
-  $output .= form_render($form['header']);
+  $output = form_render($form['header']);
   $rows = array();
   if ($form['items']) {
     foreach (element_children($form['items']) as $key) {
@@ -991,7 +993,8 @@ function theme_aggregator_page_list($for
   }
   $output .= theme('table', array('', t('Categorize')), $rows);
   $output .= form_render($form['submit']);
-  $output .= '</div>';
+
+  $output = theme('aggregator', $output);
   $output .= form_render($form);
   return $output;
 }
@@ -1022,24 +1025,41 @@ function aggregator_page_list_submit($fo
  */
 function aggregator_page_sources() {
   $result = db_query('SELECT f.fid, f.title, f.description, f.image, MAX(i.timestamp) AS last FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.description, f.image ORDER BY last DESC, f.title');
-  $output = "<div id=\"aggregator\">\n";
+  $feeds = array();
+  $summary_items = array();
   while ($feed = db_fetch_object($result)) {
-    $output .= '<h2>'. check_plain($feed->title) ."</h2>\n";
-
     // Most recent items:
-    $list = array();
     if (variable_get('aggregator_summary_items', 3)) {
+      $list = array();
       $items = db_query_range('SELECT i.title, i.timestamp, i.link FROM {aggregator_item} i WHERE i.fid = %d ORDER BY i.timestamp DESC', $feed->fid, 0, variable_get('aggregator_summary_items', 3));
       while ($item = db_fetch_object($items)) {
         $list[] = theme('aggregator_summary_item', $item);
       }
+      $summary_items[] = $list;
     }
-    $output .= theme('item_list', $list);
+    $feeds[] = $feed;
+  }
+  return theme('aggregator_page_sources', $feeds, $summary_items);
+}
+
+/**
+ * Formats a list of all the feeds used by the aggregator.
+ *
+ * @param $feeds an array of feed-objects
+ * @param $summary_items an array of the most recent items of the specific feed.
+ * @return A string containing the output.
+ *
+ * @ingroup themeable
+ */
+function theme_aggregator_page_sources($feeds, $summary_items) {
+  foreach ($feeds as $key => $feed) {
+    $output .= '<h2>'. check_plain($feed->title) .'</h2>';
+    $output .= theme('item_list', $summary_items[$key]);
     $output .= '<div class="links">'. theme('links', array(l(t('more'), 'aggregator/sources/'. $feed->fid))) ."</div>\n";
   }
   $output .= theme('xml_icon', url('aggregator/opml'));
-  $output .= '</div>';
-  return $output;
+
+  return theme('aggregator', $output);
 }
 
 /**
@@ -1123,23 +1143,43 @@ function aggregator_page_opml($cid = NUL
  */
 function aggregator_page_categories() {
   $result = db_query('SELECT c.cid, c.title, c.description FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid LEFT JOIN {aggregator_item} i ON ci.iid = i.iid GROUP BY c.cid, c.title, c.description');
-  $output = "<div id=\"aggregator\">\n";
 
+  $categories = array();
+  $summary_items = array();
   while ($category = db_fetch_object($result)) {
-    $output .= '<h2>'. check_plain($category->title) ."</h2>\n";
+    // Most recent items:
     if (variable_get('aggregator_summary_items', 3)) {
       $list = array();
       $items = db_query_range('SELECT i.title, i.timestamp, i.link, f.title as feed_title, f.link as feed_link FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON i.iid = ci.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE ci.cid = %d ORDER BY i.timestamp DESC', $category->cid, 0, variable_get('aggregator_summary_items', 3));
       while ($item = db_fetch_object($items)) {
         $list[] = theme('aggregator_summary_item', $item);
       }
-      $output .= theme('item_list', $list);
+      $summary_items[] = $list;
     }
+    $categories[] = $category;
+  }
+
+  return theme('aggregator_page_categories', $categories, $summary_items);
+}
+
+
+/**
+ * Formats a list of all the categories used by the aggregator.
+ *
+ * @param $categories an array of category-objects
+ * @param $summary_items an array of the most recent items of the specific category.
+ * @return A string containing the output.
+ *
+ * @ingroup themeable
+ */
+function theme_aggregator_page_categories($categories, $summary_items) {
+  foreach ($categories as $key => $category) {
+    $output .= '<h2>'. check_plain($category->title) .'</h2>';
+    $output .= theme('item_list', $summary_items[$key]);
     $output .= '<div class="links">'. theme('links', array(l(t('more'), 'aggregator/categories/'. $category->cid))) ."</div>\n";
   }
-  $output .= '</div>';
 
-  return $output;
+  return theme('aggregator', $output);
 }
 
 /**
@@ -1242,4 +1282,11 @@ function theme_aggregator_page_item($ite
   return $output;
 }
 
-
+/**
+ * Puts the aggregator output in a container
+ *
+ * @ingroup themeable
+ */
+function theme_aggregator($output) {
+  return '<div id="aggregator">'. $output .'</div';
+}
\ No newline at end of file
