Index: tracker.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/tracker.module,v
retrieving revision 1.125
diff -u -p -r1.125 tracker.module
--- tracker.module	12 Jan 2006 16:22:46 -0000	1.125
+++ tracker.module	22 Jan 2006 14:15:00 -0000
@@ -73,22 +73,47 @@ function tracker_track_user() {
 /**
  * Menu callback. Prints a listing of active nodes on the site.
  */
-function tracker_page($uid = 0) {
-  global $user;
+function tracker_page($uid = NULL, $feed = NULL) {
+  
+  if ($uid == 'feed'){
+    return tracker_feed();
+  }
+  elseif ($feed == 'feed'){
+    return tracker_feed($uid);
+  }
 
-  $output .= '';
+  if ($account = user_load(array('uid' => $uid))){
+    $feedpath = url("tracker/".$uid."/feed", NULL, NULL, TRUE);
+    // add 'alternate' tag for the user
+    drupal_add_link(array(
+      'rel' => 'alternate',
+      'type' => 'application/rss+xml',
+      'title' => t('RSS - %name\'s posts', array('%name' => $account->name)),
+      'href' => $feedpath)
+    );
+  }
+  else {
+    $feedpath = url("tracker/feed", NULL, NULL, TRUE);
+    // add 'alternate' tag for all
+    drupal_add_link(array(
+      'rel' => 'alternate',
+      'type' => 'application/rss+xml',
+      'title' => t('RSS - all posts'),
+      'href' => $feedpath)
+    );
+  }
 
-  if ($uid) {
-    $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, l.last_comment_timestamp AS last_post, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) WHERE n.status = 1 AND (n.uid = %d OR c.uid = %d) ORDER BY last_post DESC';
+  if ($account) {
+    $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, l.last_comment_timestamp AS last_post, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) WHERE n.status = 1 AND n.moderate = 0 AND (n.uid = %d OR c.uid = %d) ORDER BY last_post DESC';
     $sql = db_rewrite_sql($sql);
-    $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) WHERE n.status = 1 AND (n.uid = %d OR c.uid = %d)';
+    $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) WHERE n.status = 1 AND n.moderate = 0 AND (n.uid = %d OR c.uid = %d)';
     $sql_count = db_rewrite_sql($sql_count);
     $result = pager_query($sql, 25, 0, $sql_count, COMMENT_PUBLISHED, $uid, $uid);
   }
   else {
-    $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, l.last_comment_timestamp AS last_post, l.comment_count FROM {node} n INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 ORDER BY last_post DESC';
+    $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, l.last_comment_timestamp AS last_post, l.comment_count FROM {node} n INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND n.moderate = 0 ORDER BY last_post DESC';
     $sql = db_rewrite_sql($sql);
-    $sql_count = 'SELECT COUNT(n.nid) FROM {node} n WHERE n.status = 1';
+    $sql_count = 'SELECT COUNT(n.nid) FROM {node} n WHERE n.status = 1 AND n.moderate = 0';
     $sql_count = db_rewrite_sql($sql_count);
     $result = pager_query($sql, 25, 0, $sql_count);
   }
@@ -119,9 +144,33 @@ function tracker_page($uid = 0) {
   $output .= '<div id="tracker">';
   $output .= theme('table', $header, $rows);
   $output .= theme('pager', NULL, 25, 0);
+  $output .= theme('feed_icon', $feedpath);
   $output .= '</div>';
 
   return $output;
 }
 
-
+/**
+ * Generate an RSS feed for an individual user or entire site
+ *
+ * @param $uid
+ *  User id - leave empty to get feed for all users
+ * @return
+ *  The rendered XML RSS feed
+ */
+
+function tracker_feed($uid = NULL){
+  if (is_null($uid)){
+    $result = db_query('SELECT nid FROM {node} WHERE status = 1 AND moderate = 0 ORDER BY created DESC LIMIT %d', variable_get('feed_default_items', 10));
+    $channel['title'] = t('All posts on %site', array('%site' => variable_get('site_name', 'drupal')));
+    $channel['link'] = url("tracker", NULL, NULL, TRUE);
+  }
+  else {
+    $account = user_load(array('uid' => $uid));
+    $result = db_query('SELECT nid FROM {node} WHERE status = 1 AND moderate = 0 AND uid = %d ORDER BY created DESC LIMIT %d', $uid, variable_get('feed_default_items', 10));
+    $channel['title'] = t('Posts by %name', array('%name' => $account->name));
+    $channel['link'] = url("tracker/$uid", NULL, NULL, TRUE);
+    $channel['description'] = t('%name\'s posts on %site', array('%name' => $account->name, '%site' => variable_get('site_name', 'drupal')));
+  }
+  return node_feed($result, $channel);
+}
