drupal/modules/tracker.module

122 lines
5.3 KiB
Plaintext
Raw Normal View History

<?php
// $Id$
/**
* @file
* Enables tracking of recent posts for users.
*/
2004-05-24 18:37:50 +00:00
/**
* 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 recently added or updated content to a Drupal site. The link to the tracker is labeled <em>recent posts</em> in the user\'s navigation block. Updates include changes to the text by either the original author or someone else that has permission to edit the content, such as an editor or administrator as well as all comments added to an item.</p>
<p>The Tracker module presents a page listing the recently-updated content written by the user with the content type, the title, the user\'s name, how many comments that item has received, as well as how long ago it was updated. If an item was written by someone else, tracker will show that item at the top of the list. An example:</p>
<p>A user named Jessica writes a blog post, then some time passes, and others write blog posts. Then if John posts a comment to Jessica\'s post, and you have bookmarked John\'s tracker page (see below on how to do this) then Jessica\'s content will appear at the top.</p>
<p>If an user with <i>administer comments</i> (e.g. an administrator or editor of a site) deletes a comment (e.g. it is off-topic, inappropriate language, or unsolicited advertisement), the content item will drop down to when it was updated previous to that deleted comment.</p>
<p>To use the Tracker module to "watch" for a user\'s updated content, click on that user\'s profile, then the "track" tab.</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))) {
2004-10-06 20:00:56 +00:00
$items[] = array('path' => 'user/'. arg(1) .'/track', 'title' => t('track'),
'callback' => 'tracker_track_user', 'access' => user_access('access content'),
'type' => MENU_IS_LOCAL_TASK);
$items[] = array('path' => 'user/'. arg(1) .'/track/posts', 'title' => t('track posts'),
'type' => MENU_DEFAULT_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);
return tracker_page($account->uid);
}
}
2004-05-24 18:37:50 +00:00
/**
* Menu callback. Prints a listing of active nodes on the site.
*/
function tracker_page($uid = 0) {
global $user;
$output .= '';
2004-05-24 18:37:50 +00:00
if ($uid) {
$sql = '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 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_post DESC';
$sql = db_rewrite_sql($sql);
$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)';
$sql_count = db_rewrite_sql($sql_count);
$result = pager_query($sql, 25, 0, $sql_count, COMMENT_PUBLISHED, $uid, $uid);
}
else {
$sql = '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 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_post DESC';
$sql = db_rewrite_sql($sql);
$sql_count = 'SELECT COUNT(n.nid) FROM {node} n WHERE n.status = 1';
$sql_count = db_rewrite_sql($sql_count);
2005-01-17 19:00:03 +00:00
$result = pager_query($sql, 25, 0, $sql_count);
}
while ($node = db_fetch_object($result)) {
// Determine the number of comments:
$comments = 0;
if (module_exist('comment') && $node->comment_count) {
$comments = $node->comment_count;
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(
- Patch #29785 by Chx: multiple node types were broken so we refactored part of the node system! If you have a module that implements node types, you'll have to udpate its CVS HEAD version. We replaced _node_name() and _node_types() by _node(). The new _node() hook let's you define one or more node types, including their names. The implementation of the _node() hook needs to: return array($type1 => array('name' => $name1, 'base' => $base1), $type2 => array('name' => $name2, 'base' => $base2)); where $type is the node type, $name is the human readable name of the type and $base is used instead of <hook> for <hook>_load, <hook>_view, etc. For example, the story module's node hook looks like this: function story_node() { return array('story' => array('name' => t('story'), 'base' => 'story')); } The page module's node hook module like: function page_node() { return array('page' => array('name' => t('page'), 'base' => 'page')); } However, more complex node modules like the project module and the flexinode module can use the 'base' parameter to specify a different base. The project module implements two node types, proejcts and issues, so it can do: function project_node() { return array( array('project_project' => array('name' => t('project'), 'base' => 'project'), array('project_issue' => array('name' => t('issue'), 'base' => 'project_issue')); } In the flexinode module's case there can only one base ... This hook will simplify the CCK, and will make it easy (or easier) to merge the story and page module. In addition, node_list() became node_get_types(). In addition, we created the following functions: node_get_name($type) and node_get_base($type).
2005-08-28 15:29:34 +00:00
node_get_name($node->type),
l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)),
theme('username', $node),
array('class' => 'replies', 'data' => $comments),
t('%time ago', array('%time' => format_interval(time() - $node->last_post)))
);
}
$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 .= theme('pager', NULL, 25, 0);
2004-05-24 18:37:50 +00:00
$output .= '</div>';
return $output;
}