2001-09-20 20:57:35 +00:00
<?php
2001-10-20 18:57:09 +00:00
// $Id$
2001-09-20 20:57:35 +00:00
2004-08-21 06:42:38 +00:00
/**
* @file
* Enables tracking of recent posts for users.
*/
2004-05-24 18:37:50 +00:00
/**
* Implementation of hook_help().
*/
function tracker_help($section) {
2003-08-20 21:06:51 +00:00
switch ($section) {
2004-03-20 13:23:34 +00:00
case 'admin/help#tracker':
2004-03-20 13:29:06 +00:00
return t('<p>The tracker module is a handy module for displaying the most recent posts. By following the <em>recent posts</em> link in the user block, a user may quickly review all recent postings.</p>');
2004-06-18 15:04:37 +00:00
case 'admin/modules#description':
2004-02-21 22:20:21 +00:00
return t('Enables tracking of recent posts for users.');
2003-08-20 21:06:51 +00:00
}
2002-02-22 19:23:04 +00:00
}
2004-04-21 13:56:38 +00:00
/**
2004-06-18 15:04:37 +00:00
* Implementation of hook_menu().
2004-04-21 13:56:38 +00:00
*/
2004-09-16 07:17:56 +00:00
function tracker_menu($may_cache) {
2004-07-11 06:53:39 +00:00
global $user;
2004-06-18 15:04:37 +00:00
$items = array();
2004-09-16 07:17:56 +00:00
if ($may_cache) {
$items[] = array('path' => 'tracker', 'title' => t('recent posts'),
'callback' => 'tracker_page', 'access' => user_access('access content'),
'weight' => 1);
if ($user->uid) {
$items[] = array('path' => 'tracker/all', 'title' => t('all recent posts'),
'type' => MENU_DEFAULT_LOCAL_TASK);
$items[] = array('path' => 'tracker/'. $user->uid, 'title' => t('my recent posts'),
'type' => MENU_LOCAL_TASK);
}
2004-07-11 06:53:39 +00:00
}
2004-10-06 18:26:01 +00:00
else {
if (arg(0) == 'user' && is_numeric(arg(1))) {
2004-10-06 20:00:56 +00:00
$items[] = array('path' => 'user/'. arg(1) .'/track', 'title' => t('track'),
2004-10-06 18:26:01 +00:00
'callback' => 'tracker_track_user', 'access' => user_access('access content'),
2004-11-23 22:20:41 +00:00
'type' => MENU_IS_LOCAL_TASK);
$items[] = array('path' => 'user/'. arg(1) .'/track/posts', 'title' => t('track posts'),
'type' => MENU_DEFAULT_LOCAL_TASK);
2004-10-06 18:26:01 +00:00
}
}
2004-07-11 06:53:39 +00:00
2004-06-18 15:04:37 +00:00
return $items;
2001-09-20 20:57:35 +00:00
}
2004-10-06 18:26:01 +00:00
/**
* Menu callback. Prints a listing of active nodes on the site.
*/
function tracker_track_user() {
2004-10-06 20:43:05 +00:00
if ($account = user_load(array('uid' => arg(1)))) {
drupal_set_title($account->name);
tracker_page($account->uid);
}
2004-10-06 18:26:01 +00:00
}
2004-05-24 18:37:50 +00:00
/**
* Menu callback. Prints a listing of active nodes on the site.
*/
function tracker_page($uid = 0) {
2004-03-20 13:23:34 +00:00
global $user;
$output .= '';
2004-05-24 18:37:50 +00:00
if ($uid) {
2004-11-04 20:17:07 +00:00
$result = pager_query('SELECT DISTINCT n.nid, n.title, n.type, n.changed, n.uid, u.name, l.last_comment_timestamp AS last_post, l.comment_count FROM {node} n '. node_access_join_sql() .' 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 = 0 WHERE n.status = 1 AND '. node_access_where_sql() .' AND (n.uid = %d OR c.uid = %d) ORDER BY last_post DESC', 25, 0, 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '. node_access_join_sql() .' LEFT JOIN {comments} c ON n.nid = c.nid AND c.status = 0 WHERE n.status = 1 AND '. node_access_where_sql() .' AND (n.uid = %d OR c.uid = %d)', $uid, $uid);
2001-09-20 20:57:35 +00:00
}
else {
2004-11-04 20:17:07 +00:00
$result = pager_query('SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, l.last_comment_timestamp AS last_post, l.comment_count FROM {node} n '. node_access_join_sql() .' INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND '. node_access_where_sql() .' ORDER BY last_post DESC', 25, 0, 'SELECT COUNT(n.nid) FROM {node} n '. node_access_join_sql() .' WHERE n.status = 1 AND '. node_access_where_sql());
2003-08-21 15:47:50 +00:00
}
2004-11-15 11:16:39 +00:00
2004-03-20 13:23:34 +00:00
while ($node = db_fetch_object($result)) {
// Determine the number of comments:
2004-07-08 06:15:49 +00:00
$comments = 0;
2004-11-04 20:17:07 +00:00
if (module_exist('comment') && $node->comment_count) {
$comments = $node->comment_count;
2004-07-08 06:15:49 +00:00
if ($new = comment_num_new($node->nid)) {
$comments .= '<br />';
$comments .= l(t('%num new', array('%num' => $new)), "node/$node->nid", NULL, NULL, 'new');
2004-03-20 13:23:34 +00:00
}
2003-03-15 20:00:17 +00:00
}
2004-03-20 13:23:34 +00:00
$rows[] = array(
2004-08-06 20:15:32 +00:00
node_invoke($node->type, 'node_name'),
2004-06-18 15:04:37 +00:00
l($node->title, "node/$node->nid") .' '. (node_is_new($node->nid, $node->changed) ? theme('mark') : ''),
2004-03-20 13:23:34 +00:00
format_name($node),
array('class' => 'replies', 'data' => $comments),
2004-10-15 05:10:35 +00:00
t('%time ago', array('%time' => format_interval(time() - $node->last_post)))
2004-03-20 13:23:34 +00:00
);
2001-09-20 20:57:35 +00:00
}
2004-03-20 13:23:34 +00:00
if ($pager = theme('pager', NULL, 25, 0)) {
2004-11-15 11:16:39 +00:00
$rows[] = array(array('data' => $pager, 'colspan' => '5'));
2003-03-16 07:38:39 +00:00
}
2004-08-19 15:41:57 +00:00
$header = array(t('Type'), t('Post'), t('Author'), t('Replies'), t('Last post'));
2004-03-20 13:23:34 +00:00
2004-05-24 18:37:50 +00:00
$output .= '<div id="tracker">';
$output .= theme('table', $header, $rows);
$output .= '</div>';
2003-03-15 20:00:17 +00:00
2004-03-20 13:23:34 +00:00
print theme('page', $output);
2001-09-20 20:57:35 +00:00
}
2003-09-26 10:04:09 +00:00
?>