Index: modules/tracker.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/tracker.module,v
retrieving revision 1.127
diff -u -F^f -r1.127 tracker.module
--- modules/tracker.module 21 Feb 2006 18:46:54 -0000 1.127
+++ modules/tracker.module 23 Feb 2006 01:55:19 -0000
@@ -71,24 +71,146 @@ function tracker_track_user() {
}
/**
- * Menu callback. Prints a listing of active nodes on the site.
+ * Menu callback; displays a Drupal page or RSS feed containing recent nodes.
*/
-function tracker_page($uid = 0) {
- if ($uid) {
+function tracker_page($a = NULL, $b = NULL) {
+
+ if (is_numeric($a)) { // $a is a user ID
+ if ($b == 'feed') {
+ return tracker_feed_user($a);
+ }
+ else {
+ return tracker_page_user($a);
+ }
+ }
+ else if ($a == 'feed') {
+ return tracker_feed_last();
+ }
+ else {
+ return tracker_page_last();
+ }
+}
+
+/**
+ * Displays a Drupal page containing recent node entries of a given user.
+ */
+function tracker_page_user($uid) {
+ global $user;
+
+ $account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1));
+
+ $title = '';
+ if ($account->uid) {
+ drupal_set_title($title = t("%name's posts", array('%name' => $account->name)));
+
$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';
$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 = db_rewrite_sql($sql_count);
- $result = pager_query($sql, 25, 0, $sql_count, COMMENT_PUBLISHED, $uid, $uid);
+ $result = pager_query($sql, 25, 0, $sql_count, COMMENT_PUBLISHED, $account->uid, $account->uid);
+
+ $rows = _tracker_get_rows($result);
+ $header = array(t('Type'), t('Post'), t('Author'), t('Replies'), t('Last post'));
+
+ $output = '
';
+ $output .= theme('table', $header, $rows);
+ $output .= theme('pager', NULL, 25, 0);
+ $output .= '
';
+
+ $output .= theme('feed_icon', url("tracker/$uid/feed"));
+
+ drupal_add_link(array('rel' => 'alternate',
+ 'type' => 'application/rss+xml',
+ 'title' => t('RSS - %title', array('%title' => $title)),
+ 'href' => url("tracker/$account->uid/feed")));
+ return $output;
}
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 = db_rewrite_sql($sql);
- $sql_count = 'SELECT COUNT(n.nid) FROM {node} n WHERE n.status = 1';
- $sql_count = db_rewrite_sql($sql_count);
- $result = pager_query($sql, 25, 0, $sql_count);
+ drupal_not_found();
+ }
+}
+
+/**
+ * Displays a Drupal page containing recent entries of all users.
+ */
+function tracker_page_last() {
+ global $user;
+
+ $output = '';
+
+ $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 = db_rewrite_sql($sql);
+ $sql_count = 'SELECT COUNT(n.nid) FROM {node} n WHERE n.status = 1';
+ $sql_count = db_rewrite_sql($sql_count);
+ $result = pager_query($sql, 25, 0, $sql_count);
+
+ $rows = _tracker_get_rows($result);
+ $header = array(t('Type'), t('Post'), t('Author'), t('Replies'), t('Last post'));
+
+ $output = '';
+ $output .= theme('table', $header, $rows);
+ $output .= theme('pager', NULL, 25, 0);
+ $output .= '
';
+ $output .= theme('feed_icon', url('tracker/feed'));
+
+ drupal_add_link(array('rel' => 'alternate',
+ 'type' => 'application/rss+xml',
+ 'title' => t('RSS - All Posts'),
+ 'href' => url("tracker/feed")));
+ return $output;
+}
+
+/**
+ * Displays an RSS feed containing recent entries of all users.
+ */
+function tracker_feed_last() {
+ $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 = db_rewrite_sql($sql);
+ $sql_count = 'SELECT COUNT(n.nid) FROM {node} n WHERE n.status = 1';
+ $sql_count = db_rewrite_sql($sql_count);
+ $result = pager_query($sql, variable_get('feed_default_items', 10), 0, $sql_count);
+ $channel['title'] = variable_get('site_name', 'drupal') .' posts';
+ $channel['link'] = url('tracker', NULL, NULL, TRUE);
+ $channel['description'] = $term->description;
+ node_feed($result, $channel);
+}
+
+/**
+ * Displays an RSS feed containing recent entries from a given user.
+ */
+function tracker_feed_user($uid = 0) {
+ global $user;
+
+ if ($uid) {
+ $account = user_load(array('uid' => $uid, 'status' => 1));
+ }
+ else {
+ $account = $user;
}
+ $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';
+ $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 = db_rewrite_sql($sql_count);
+ $result = pager_query($sql, variable_get('feed_default_items', 10), 0, $sql_count, COMMENT_PUBLISHED, $uid, $uid);
+
+ $channel['title'] = $account->name ."'s blog";
+ $channel['link'] = url("tracker/$uid", NULL, NULL, TRUE);
+ $channel['description'] = $term->description;
+ node_feed($result, $channel);
+}
+
+/**
+ * Return a array suitable for Drupal's table() function.
+ *
+ * @param $result
+ * A DB result object from a query to fetch node objects.
+ * @return
+ * An array to be passed as the $row parameter for the table() function.
+ */
+function _tracker_get_rows($result) {
+ $rows = array();
+
while ($node = db_fetch_object($result)) {
// Determine the number of comments:
$comments = 0;
@@ -110,12 +232,5 @@ function tracker_page($uid = 0) {
);
}
- $header = array(t('Type'), t('Post'), t('Author'), t('Replies'), t('Last post'));
-
- $output = '';
- $output .= theme('table', $header, $rows);
- $output .= theme('pager', NULL, 25, 0);
- $output .= '
';
-
- return $output;
-}
+ return $rows;
+}
\ No newline at end of file