111 lines
4.0 KiB
Plaintext
111 lines
4.0 KiB
Plaintext
<?php
|
|
// $Id$
|
|
|
|
/**
|
|
* @file
|
|
* Enables tracking of recent posts for users.
|
|
*/
|
|
|
|
/**
|
|
* Implementation of hook_help().
|
|
*/
|
|
function tracker_help($section) {
|
|
switch ($section) {
|
|
case 'admin/help#tracker':
|
|
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>');
|
|
case 'admin/modules#description':
|
|
return t('Enables tracking of recent posts for users.');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implementation of hook_menu().
|
|
*/
|
|
function tracker_menu($may_cache) {
|
|
global $user;
|
|
$items = array();
|
|
|
|
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);
|
|
}
|
|
}
|
|
else {
|
|
if (arg(0) == 'user' && is_numeric(arg(1))) {
|
|
$items[] = array('path' => 'user/'. arg(1) .'/track', 'title' => t('track'),
|
|
'callback' => 'tracker_track_user', 'access' => user_access('access content'),
|
|
'type' => MENU_LOCAL_TASK);
|
|
}
|
|
}
|
|
|
|
return $items;
|
|
}
|
|
|
|
/**
|
|
* Menu callback. Prints a listing of active nodes on the site.
|
|
*/
|
|
function tracker_track_user() {
|
|
if ($account = user_load(array('uid' => arg(1)))) {
|
|
drupal_set_title($account->name);
|
|
tracker_page($account->uid);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Menu callback. Prints a listing of active nodes on the site.
|
|
*/
|
|
function tracker_page($uid = 0) {
|
|
global $user;
|
|
|
|
$output .= '';
|
|
|
|
if ($uid) {
|
|
$result = pager_query('SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_post FROM {node} n '. node_access_join_sql() .' LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND '. node_access_where_sql() .' AND (n.uid = %d OR c.uid = %d) 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 '. node_access_join_sql() .' LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.status = 1 AND '. node_access_where_sql() .' AND (n.uid = %d OR c.uid = %d)', $uid, $uid);
|
|
}
|
|
else {
|
|
$result = pager_query('SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_post FROM {node} n '. node_access_join_sql() .' LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND '. node_access_where_sql() .' 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 '. node_access_join_sql() .' WHERE n.status = 1 AND '. node_access_where_sql());
|
|
}
|
|
|
|
while ($node = db_fetch_object($result)) {
|
|
// Determine the number of comments:
|
|
$comments = 0;
|
|
if (module_exist('comment') && $all = comment_num_all($node->nid)) {
|
|
$comments = $all;
|
|
|
|
if ($new = comment_num_new($node->nid)) {
|
|
$comments .= '<br />';
|
|
$comments .= l(t('%num new', array('%num' => $new)), "node/$node->nid", NULL, NULL, 'new');
|
|
}
|
|
}
|
|
|
|
$rows[] = array(
|
|
node_invoke($node->type, 'node_name'),
|
|
l($node->title, "node/$node->nid") .' '. (node_is_new($node->nid, $node->changed) ? theme('mark') : ''),
|
|
format_name($node),
|
|
array('class' => 'replies', 'data' => $comments),
|
|
t('%time ago', array('%time' => format_interval(time() - $node->last_post)))
|
|
);
|
|
}
|
|
|
|
if ($pager = theme('pager', NULL, 25, 0)) {
|
|
$rows[] = array(array('data' => $pager, 'colspan' => 5));
|
|
}
|
|
|
|
$header = array(t('Type'), t('Post'), t('Author'), t('Replies'), t('Last post'));
|
|
|
|
$output .= '<div id="tracker">';
|
|
$output .= theme('table', $header, $rows);
|
|
$output .= '</div>';
|
|
|
|
print theme('page', $output);
|
|
}
|
|
|
|
?>
|