--- tracker2.module 2009-01-12 13:45:34.000000000 -0500 +++ tracker2.module.new 2009-01-12 13:45:34.000000000 -0500 @@ -299,39 +299,18 @@ function tracker2_comment($a1, $op) { function tracker2_page($uid = 0) { drupal_add_css(drupal_get_path('module', 'tracker2') .'/tracker2.css', 'module', 'all', FALSE); - if ($uid) { - $sql = 'SELECT t2u.nid, t2u.changed FROM {tracker2_user} t2u WHERE t2u.published = 1 AND t2u.uid = %d ORDER BY t2u.changed DESC'; - $sql = db_rewrite_sql($sql, 't2u'); - $sql_count = 'SELECT COUNT(t2u.nid) FROM {tracker2_user} t2u WHERE t2u.published = 1 AND t2u.uid = %d'; - $sql_count = db_rewrite_sql($sql_count, 't2u'); - $result = pager_query($sql, 25, 0, $sql_count, $uid); - } - else { - $sql = 'SELECT t2n.nid, t2n.changed FROM {tracker2_node} t2n WHERE t2n.published = 1 ORDER BY t2n.changed DESC'; - $sql = db_rewrite_sql($sql, 't2n'); - $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 = array(); + $nodes = tracker2_get_nodes_for_user($uid); - // This array acts as a placeholder for the data selected later - // while keeping the correct order. - $nodes = array(); - while ($node = db_fetch_object($result)) { - $nodes[$node->nid] = $node; - } + return theme('tracker2_page', $nodes); +} + +/** + * Make tracker2 themable + */ +function theme_tracker2_page($nodes=array()) { if (!empty($nodes)) { - // Now, get the data and put into the placeholder array - $placeholders = implode(',', array_fill(0, count($nodes), '%d')); - $result = db_query("SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, 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 WHERE n.nid IN ($placeholders)", array_keys($nodes)); - while ($node = db_fetch_object($result)) { - $node->changed = $nodes[$node->nid]->changed; - $nodes[$node->nid] = $node; - } - - // Finally display the data - $rows = array(); foreach ($nodes as $node) { $last_updated = $node->changed; @@ -369,6 +348,47 @@ function tracker2_page($uid = 0) { return $output; } +/** + * Publically callable API to retrieve an array of nodes for the passed user + * id. + * @param int $uid The user id of the user to be tracked. + * @return array Associative array of node properties suitable for listing. + */ +function tracker2_get_nodes_for_user($uid = 0) { + if ($uid) { + $sql = 'SELECT t2u.nid, t2u.changed FROM {tracker2_user} t2u WHERE t2u.published = 1 AND t2u.uid = %d ORDER BY t2u.changed DESC'; + $sql = db_rewrite_sql($sql, 't2u'); + $sql_count = 'SELECT COUNT(t2u.nid) FROM {tracker2_user} t2u WHERE t2u.published = 1 AND t2u.uid = %d'; + $sql_count = db_rewrite_sql($sql_count, 't2u'); + $result = pager_query($sql, 25, 0, $sql_count, $uid); + } + else { + $sql = 'SELECT t2n.nid, t2n.changed FROM {tracker2_node} t2n WHERE t2n.published = 1 ORDER BY t2n.changed DESC'; + $sql = db_rewrite_sql($sql, 't2n'); + $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); + } + + // This array acts as a placeholder for the data selected later + // while keeping the correct order. + $nodes = array(); + while ($node = db_fetch_object($result)) { + $nodes[$node->nid] = $node; + } + + if (!empty($nodes)) { + // Now, get the data and put into the placeholder array + $placeholders = implode(',', array_fill(0, count($nodes), '%d')); + $result = db_query("SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, 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 WHERE n.nid IN ($placeholders)", array_keys($nodes)); + while ($node = db_fetch_object($result)) { + $node->changed = $nodes[$node->nid]->changed; + $nodes[$node->nid] = $node; + } + } + + return $nodes; +} /** * Menu callback. Prints a listing of active nodes on the site.