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-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>');
2003-10-07 18:16:41 +00:00
case 'admin/system/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
/**
* Implementation of hook_link().
*/
2001-09-20 20:57:35 +00:00
function tracker_link($type) {
2004-04-21 13:56:38 +00:00
if ($type == 'system') {
menu('tracker', t('recent posts'), user_access('access content') ? 'tracker_page' : MENU_DENIED, 1);
2001-09-20 20:57:35 +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 .= '';
if ($user->uid) {
2004-05-24 18:37:50 +00:00
$output .= '<ul>';
$output .= ' <li>'. l(t('Your active posts and discussions'), "tracker/$user->uid") .'</li>';
$output .= ' <li>'. l(t('All active posts and discussions'), 'tracker') .'</li>';
$output .= '</ul>';
2004-03-20 13:23:34 +00:00
}
2001-11-17 17:37:10 +00:00
2004-05-24 18:37:50 +00:00
if ($uid) {
$uid = check_query($uid);
2003-08-21 15:47:50 +00:00
2004-05-24 18:37:50 +00:00
$result = pager_query("SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_post FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND (n.uid = $uid OR c.uid = $uid) GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_post DESC", 25, 0, "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.status = 1 AND (n.uid = $uid OR c.uid = $uid)");
2003-08-21 15:47:50 +00:00
2001-09-20 20:57:35 +00:00
}
else {
2004-05-24 18:37:50 +00:00
$result = pager_query('SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_post FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_post DESC', 25, 0, 'SELECT COUNT(nid) FROM {node} WHERE status = 1');
2003-08-21 15:47:50 +00:00
}
2003-03-15 20:00:17 +00:00
2004-03-20 13:23:34 +00:00
while ($node = db_fetch_object($result)) {
// Determine the number of comments:
if ($all = comment_num_all($node->nid)) {
$comments = $all;
2003-03-14 20:41:27 +00:00
2004-03-20 13:23:34 +00:00
if ($new = comment_num_new($node->nid)) {
$comments .= '<br />';
2004-03-29 19:00:07 +00:00
$comments .= l(t('%num new', array('%num' => $new)), "node/view/$node->nid", NULL, NULL, 'new');
2004-03-20 13:23:34 +00:00
}
2003-03-15 20:00:17 +00:00
}
else {
2004-03-20 13:23:34 +00:00
$comments = 0;
2001-09-20 20:57:35 +00:00
}
2003-03-15 20:00:17 +00:00
2004-03-20 13:23:34 +00:00
$rows[] = array(
2004-05-24 18:37:50 +00:00
ucfirst(node_invoke($node->type, 'node_name')),
l($node->title, "node/view/$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-05-24 18:37:50 +00:00
format_interval(time() - $node->last_post) .' '. t('ago')
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)) {
$rows[] = array(array('data' => $pager, 'colspan' => 4));
2003-03-16 07:38:39 +00:00
}
2004-03-20 13:23:34 +00:00
$header = array(t('Type'), t('Post'), t('Author'), t('Replies'), t('Last post'));
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-03-14 20:41:27 +00:00
function tracker_user($type, &$edit, &$user) {
2004-05-24 18:37:50 +00:00
if ($type == 'view' && user_access('access content')) {
return array(t('History') => form_item(t('Recent posts'), l(t('recent posts'), "tracker/$user->uid")));
2003-03-14 20:41:27 +00:00
}
2001-09-20 20:57:35 +00:00
}
2003-09-26 10:04:09 +00:00
?>