Code coverage for /20081101/modules/tracker/tracker.pages.inc

Line #Times calledCode
1
<?php
2
// $Id: tracker.pages.inc,v 1.12 2008/10/26 18:06:39 dries Exp $
3
4
/**
5
 * @file
6
 * User page callbacks for the tracker module.
7
 */
8
9
10
/**
11
 * Menu callback. Prints a listing of active nodes on the site.
12
 */
138
function tracker_page($account = NULL, $set_title = FALSE) {
14
  // Add CSS
158
  drupal_add_css(drupal_get_path('module', 'tracker') . '/tracker.css',
array('preprocess' => FALSE));
16
178
  if ($account) {
181
    if ($set_title) {
19
      // When viewed from user/%user/track, display the name of the user
20
      // as page title -- the tab title remains Track so this needs to be
done
21
      // here and not in the menu definiton.
221
      drupal_set_title($account->name);
231
    }
24
  // TODO: These queries are very expensive, see
http://drupal.org/node/105639
251
    $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';
261
    $sql = db_rewrite_sql($sql);
271
    $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)';
281
    $sql_count = db_rewrite_sql($sql_count);
291
    $result = pager_query($sql, 25, 0, $sql_count, COMMENT_PUBLISHED,
$account->uid, $account->uid);
301
  }
31
  else {
327
    $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';
337
    $sql = db_rewrite_sql($sql);
347
    $sql_count = 'SELECT COUNT(n.nid) FROM {node} n WHERE n.status = 1';
357
    $sql_count = db_rewrite_sql($sql_count);
367
    $result = pager_query($sql, 25, 0, $sql_count);
37
  }
38
398
  $rows = array();
408
  while ($node = db_fetch_object($result)) {
41
    // Determine the number of comments:
428
    $comments = 0;
438
    if ($node->comment_count) {
442
      $comments = $node->comment_count;
45
462
      if ($new = comment_num_new($node->nid)) {
472
        $comments .= '<br />';
482
        $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'));
492
      }
502
    }
51
528
    $rows[] = array(
538
      check_plain(node_get_types('name', $node->type)),
548
      l($node->title, "node/$node->nid") . ' ' . theme('mark',
node_mark($node->nid, $node->changed)),
558
      theme('username', $node),
568
      array('class' => 'replies', 'data' => $comments),
578
      t('!time ago', array('!time' => format_interval(REQUEST_TIME -
$node->last_updated)))
588
    );
598
  }
60
618
  if (!$rows) {
620
    $rows[] = array(array('data' => t('No posts available.'), 'colspan' =>
'5'));
630
  }
64
658
  $header = array(t('Type'), t('Post'), t('Author'), t('Replies'), t('Last
updated'));
66
678
  $output = '<div id="tracker">';
688
  $output .= theme('table', $header, $rows);
698
  $output .= theme('pager', NULL, 25, 0);
708
  $output .= '</div>';
71
728
  return $output;
730
}
748