tracker.pages.inc

  1. 7.x drupal-7.x/modules/tracker/tracker.pages.inc
  2. 6.x drupal-6.x/modules/tracker/tracker.pages.inc

User page callbacks for the tracker module.

File

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