drupal/modules/tracker.module

115 lines
4.0 KiB
Plaintext

<?php
// $Id$
function tracker_help($section = "admin/help#tracker") {
$output = "";
switch ($section) {
case 'admin/help#tracer':
$output = t("<p>The tracker module is a handy module for displaying the most recent posts. By following the <i>recent posts</i> link in the user block, a user may quickly review all recent postings.</p>");
break;
case 'admin/system/modules#description':
$output = t("Enables tracking of recent posts for users.");
break;
}
return $output;
}
function tracker_link($type) {
$links = array();
if ($type == "system") {
if (user_access("access content")) {
menu("tracker", t("recent posts"), "tracker_page", 1);
}
}
return $links;
}
function tracker_posts($id = 0) {
$header = array(
array("data" => t("type"), "field" => "type"),
array("data" => t("title"), "field" => "title"),
array("data" => t("author"), "field" => "u.name"),
array("data" => t("last post"), "field" => "last_activity", "sort" => "desc")
);
if ($id) {
$sql = "SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.uid = '". check_query($id) ."' AND n.status = 1 GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name";
$sql .= tablesort_sql($header);
$sresult = pager_query($sql, 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1 AND uid = '". check_query($id) ."'");
}
else {
$sql = "SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity 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";
$sql .= tablesort_sql($header);
$sresult = pager_query($sql, 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1");
}
while ($node = db_fetch_object($sresult)) {
if ($id) {
$cresult = db_query("SELECT c.*, u.name FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.uid = %d AND c.nid = %d AND c.status = 0 ORDER BY c.cid DESC", $id, $node->nid);
}
else {
$cresult = db_query("SELECT c.*, u.name FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d AND c.status = 0 ORDER BY c.cid DESC", $node->nid);
}
$type = ucfirst(module_invoke($node->type, "node", "name"));
$title = l($node->title, "node/view/$node->nid") ." ". (node_is_new($node->nid, $node->changed) ? theme("mark") : "");
$author = format_name($node);
$comments = array();
while ($comment = db_fetch_object($cresult)) {
$comments[] = "<li>". t("%subject by %author", array("%subject" => l($comment->subject, "node/view/$node->nid#$comment->cid"), "%author" => format_name($comment))) ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme("mark") : "") ."</li>\n";
}
if ($comments) {
$comments = "<ul>". implode("\n", $comments) ."</ul>";
}
else {
$comments = "";
}
$rows[] = array(array("data" => $type, "class" => "type"), array("data" => $title . $comments, "class" => "content"), array("data" => $author, "class" => "author"), array("data" => format_date($node->last_activity, "small"), "class" => "last_post"));
}
if ($pager = theme("pager", NULL, 10, 0, tablesort_pager())) {
$rows[] = array(array("data" => $pager, "colspan" => 4));
}
$output = "<div id=\"tracker\">";
$output .= theme("table", $header, $rows);
$output .= "</div>";
return $output;
}
function tracker_user($type, &$edit, &$user) {
switch ($type) {
case "view_private":
case "view_public":
if (user_access("access content")) {
return form_item(t("Recent posts"), l(t("recent posts"), "tracker/$user->uid"));
}
}
}
function tracker_page() {
global $user;
if (user_access("access content")) {
print theme("page", tracker_posts(arg(1)), t("Recent posts"));
}
else {
print theme("page", message_access());
}
}
?>