| webmaster@1 | 1 <?php | 
| webmaster@1 | 2 // $Id: tracker.pages.inc,v 1.5 2007/11/28 10:29:20 dries Exp $ | 
| webmaster@1 | 3 | 
| webmaster@1 | 4 /** | 
| webmaster@1 | 5  * @file | 
| webmaster@1 | 6  * User page callbacks for the tracker module. | 
| webmaster@1 | 7  */ | 
| webmaster@1 | 8 | 
| webmaster@1 | 9 | 
| webmaster@1 | 10 /** | 
| webmaster@1 | 11  * Menu callback. Prints a listing of active nodes on the site. | 
| webmaster@1 | 12  */ | 
| webmaster@1 | 13 function tracker_page($account = NULL, $set_title = FALSE) { | 
| webmaster@1 | 14   // Add CSS | 
| webmaster@1 | 15   drupal_add_css(drupal_get_path('module', 'tracker') .'/tracker.css', 'module', 'all', FALSE); | 
| webmaster@1 | 16 | 
| webmaster@1 | 17   if ($account) { | 
| webmaster@1 | 18     if ($set_title) { | 
| webmaster@1 | 19       // When viewed from user/%user/track, display the name of the user | 
| webmaster@1 | 20       // as page title -- the tab title remains Track so this needs to be done | 
| webmaster@1 | 21       // here and not in the menu definiton. | 
| webmaster@1 | 22       drupal_set_title(check_plain($account->name)); | 
| webmaster@1 | 23     } | 
| webmaster@1 | 24   // TODO: These queries are very expensive, see http://drupal.org/node/105639 | 
| webmaster@1 | 25     $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, GREATEST(n.changed, l.last_comment_timestamp) AS last_updated, 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_updated DESC'; | 
| webmaster@1 | 26     $sql = db_rewrite_sql($sql); | 
| webmaster@1 | 27     $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)'; | 
| webmaster@1 | 28     $sql_count = db_rewrite_sql($sql_count); | 
| webmaster@1 | 29     $result = pager_query($sql, 25, 0, $sql_count, COMMENT_PUBLISHED, $account->uid, $account->uid); | 
| webmaster@1 | 30   } | 
| webmaster@1 | 31   else { | 
| webmaster@1 | 32     $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, GREATEST(n.changed, l.last_comment_timestamp) AS last_updated, 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_updated DESC'; | 
| webmaster@1 | 33     $sql = db_rewrite_sql($sql); | 
| webmaster@1 | 34     $sql_count = 'SELECT COUNT(n.nid) FROM {node} n WHERE n.status = 1'; | 
| webmaster@1 | 35     $sql_count = db_rewrite_sql($sql_count); | 
| webmaster@1 | 36     $result = pager_query($sql, 25, 0, $sql_count); | 
| webmaster@1 | 37   } | 
| webmaster@1 | 38 | 
| webmaster@1 | 39   $rows = array(); | 
| webmaster@1 | 40   while ($node = db_fetch_object($result)) { | 
| webmaster@1 | 41     // Determine the number of comments: | 
| webmaster@1 | 42     $comments = 0; | 
| webmaster@1 | 43     if ($node->comment_count) { | 
| webmaster@1 | 44       $comments = $node->comment_count; | 
| webmaster@1 | 45 | 
| webmaster@1 | 46       if ($new = comment_num_new($node->nid)) { | 
| webmaster@1 | 47         $comments .= '<br />'; | 
| webmaster@1 | 48         $comments .= l(format_plural($new, '1 new', '@count new'), "node/$node->nid", array('query' => comment_new_page_count($node->comment_count, $new, $node), 'fragment' => 'new')); | 
| webmaster@1 | 49       } | 
| webmaster@1 | 50     } | 
| webmaster@1 | 51 | 
| webmaster@1 | 52     $rows[] = array( | 
| webmaster@1 | 53       check_plain(node_get_types('name', $node->type)), | 
| webmaster@1 | 54       l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)), | 
| webmaster@1 | 55       theme('username', $node), | 
| webmaster@1 | 56       array('class' => 'replies', 'data' => $comments), | 
| webmaster@1 | 57       t('!time ago', array('!time' => format_interval(time() - $node->last_updated))) | 
| webmaster@1 | 58     ); | 
| webmaster@1 | 59   } | 
| webmaster@1 | 60 | 
| webmaster@1 | 61   if (!$rows) { | 
| webmaster@1 | 62     $rows[] = array(array('data' => t('No posts available.'), 'colspan' => '5')); | 
| webmaster@1 | 63   } | 
| webmaster@1 | 64 | 
| webmaster@1 | 65   $header = array(t('Type'), t('Post'), t('Author'), t('Replies'), t('Last updated')); | 
| webmaster@1 | 66 | 
| webmaster@1 | 67   $output = '<div id="tracker">'; | 
| webmaster@1 | 68   $output .= theme('table', $header, $rows); | 
| webmaster@1 | 69   $output .= theme('pager', NULL, 25, 0); | 
| webmaster@1 | 70   $output .= '</div>'; | 
| webmaster@1 | 71 | 
| webmaster@1 | 72   return $output; | 
| webmaster@1 | 73 } |