/[drupal]/contributions/modules/tracker2/tracker2.pages.inc
ViewVC logotype

Contents of /contributions/modules/tracker2/tracker2.pages.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Mon Jan 12 22:09:35 2009 UTC (10 months, 1 week ago) by toddnienkerk
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-ALPHA1, HEAD
Branch point for: DRUPAL-6--1
File MIME type: text/x-php
applied trackerport4.patch [294091]
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * User page callbacks for the tracker2 module.
7 */
8
9 /**
10 * Menu callback. Prints a listing of active nodes on the site.
11 */
12 function tracker2_page($account = NULL) {
13 drupal_add_css(drupal_get_path('module', 'tracker2') .'/tracker2.css', 'module', 'all', FALSE);
14 $nodes_per_page = variable_get('tracker2_pager', 25);
15
16 if ($account) {
17 $sql = "SELECT t2u.nid, t2u.changed AS last_activity FROM {tracker2_user} t2u WHERE t2u.published = 1 AND t2u.uid = %d ORDER BY t2u.changed DESC";
18 $sql = db_rewrite_sql($sql, 't2u');
19 $sql_count = "SELECT COUNT(t2u.nid) FROM {tracker2_user} t2u WHERE t2u.published = 1 AND t2u.uid = %d";
20 $sql_count = db_rewrite_sql($sql_count, 't2u');
21 $result = pager_query($sql, $nodes_per_page, 0, $sql_count, $account->uid);
22 }
23 else {
24 $sql = "SELECT t2n.nid, t2n.changed AS last_activity FROM {tracker2_node} t2n WHERE t2n.published = 1 ORDER BY t2n.changed DESC";
25 $sql = db_rewrite_sql($sql, 't2n');
26 $sql_count = "SELECT COUNT(n.nid) FROM {node} n WHERE n.status = 1";
27 $sql_count = db_rewrite_sql($sql_count);
28 $result = pager_query($sql, $nodes_per_page, 0, $sql_count);
29 }
30
31 // This array acts as a placeholder for the data selected later
32 // while keeping the correct order.
33 $nodes = array();
34 while ($node = db_fetch_object($result)) {
35 $nodes[$node->nid] = $node;
36 }
37 return theme('tracker2_page', $nodes);
38 }
39
40 /**
41 * Override-able output of the tracker2 listings.
42 */
43 function theme_tracker2_page($nodes = array()) {
44 if (!empty($nodes)) {
45 // Now, get the data and put into the placeholder array
46 $placeholders = array_fill(0, count($nodes), '%d');
47
48 $result = db_query("SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, l.comment_count FROM {node} n
49 INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid
50 WHERE n.nid IN (". implode(',', $placeholders) .")", array_keys($nodes));
51 while ($node = db_fetch_object($result)) {
52 $node->last_activity = $nodes[$node->nid]->last_activity;
53 $nodes[$node->nid] = $node;
54 }
55
56 // Finally display the data
57 $rows = array();
58 foreach ($nodes as $node) {
59 // Determine the number of comments:
60 $comments = 0;
61 if ($node->comment_count) {
62 $comments = $node->comment_count;
63
64 if ($new = comment_num_new($node->nid)) {
65 $comments .= '<br />';
66 $comments .= l(format_plural($new, '1 new', '@count new'), 'node/'. $node->nid, array('fragment' => 'new'));
67 }
68 }
69
70 $rows[] = array(
71 check_plain(node_get_types('name', $node->type)),
72 l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)),
73 theme('username', $node),
74 array('class' => 'replies', 'data' => $comments),
75 t('!time ago', array('!time' => format_interval(time() - $node->last_activity)))
76 );
77 }
78 }
79 else {
80 $rows[] = array(array('data' => t('No posts available.'), 'colspan' => '5'));
81 }
82
83 $header = array(t('Type'), t('Post'), t('Author'), t('Replies'), t('Last updated'));
84
85 $output = '<div id="tracker">';
86 $output .= theme('table', $header, $rows);
87 $output .= theme('pager', NULL, variable_get('tracker2_pager', 25), 0);
88 $output .= '</div>';
89 return $output;
90 }
91
92 /**
93 * Menu callback. Prints a listing of active nodes on the site per user.
94 */
95 function tracker2_track_user() {
96 if ($account = user_load(array('uid' => arg(1)))) {
97 if ($account->status || user_access('administer users')) {
98 drupal_set_title(check_plain($account->name));
99 return tracker2_page($account);
100 }
101 else {
102 drupal_access_denied();
103 }
104 }
105 else {
106 drupal_not_found();
107 }
108 }

  ViewVC Help
Powered by ViewVC 1.1.2