Mercurial > defr > drupal > core
comparison modules/tracker/tracker.pages.inc @ 1:c1f4ac30525a 6.0
Drupal 6.0
author | Franck Deroche <webmaster@defr.org> |
---|---|
date | Tue, 23 Dec 2008 14:28:28 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:5a113a1c4740 | 1:c1f4ac30525a |
---|---|
1 <?php | |
2 // $Id: tracker.pages.inc,v 1.5 2007/11/28 10:29:20 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 */ | |
13 function tracker_page($account = NULL, $set_title = FALSE) { | |
14 // Add CSS | |
15 drupal_add_css(drupal_get_path('module', 'tracker') .'/tracker.css', 'module', 'all', FALSE); | |
16 | |
17 if ($account) { | |
18 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. | |
22 drupal_set_title(check_plain($account->name)); | |
23 } | |
24 // TODO: These queries are very expensive, see http://drupal.org/node/105639 | |
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'; | |
26 $sql = db_rewrite_sql($sql); | |
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)'; | |
28 $sql_count = db_rewrite_sql($sql_count); | |
29 $result = pager_query($sql, 25, 0, $sql_count, COMMENT_PUBLISHED, $account->uid, $account->uid); | |
30 } | |
31 else { | |
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'; | |
33 $sql = db_rewrite_sql($sql); | |
34 $sql_count = 'SELECT COUNT(n.nid) FROM {node} n WHERE n.status = 1'; | |
35 $sql_count = db_rewrite_sql($sql_count); | |
36 $result = pager_query($sql, 25, 0, $sql_count); | |
37 } | |
38 | |
39 $rows = array(); | |
40 while ($node = db_fetch_object($result)) { | |
41 // Determine the number of comments: | |
42 $comments = 0; | |
43 if ($node->comment_count) { | |
44 $comments = $node->comment_count; | |
45 | |
46 if ($new = comment_num_new($node->nid)) { | |
47 $comments .= '<br />'; | |
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')); | |
49 } | |
50 } | |
51 | |
52 $rows[] = array( | |
53 check_plain(node_get_types('name', $node->type)), | |
54 l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)), | |
55 theme('username', $node), | |
56 array('class' => 'replies', 'data' => $comments), | |
57 t('!time ago', array('!time' => format_interval(time() - $node->last_updated))) | |
58 ); | |
59 } | |
60 | |
61 if (!$rows) { | |
62 $rows[] = array(array('data' => t('No posts available.'), 'colspan' => '5')); | |
63 } | |
64 | |
65 $header = array(t('Type'), t('Post'), t('Author'), t('Replies'), t('Last updated')); | |
66 | |
67 $output = '<div id="tracker">'; | |
68 $output .= theme('table', $header, $rows); | |
69 $output .= theme('pager', NULL, 25, 0); | |
70 $output .= '</div>'; | |
71 | |
72 return $output; | |
73 } |