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
2003-10-09 18:53:22 +00:00
function tracker_help($section = "admin/help#tracker") {
2003-10-03 14:55:27 +00:00
$output = "";
2003-08-20 21:06:51 +00:00
switch ($section) {
2003-10-09 18:53:22 +00:00
case 'admin/help#tracer':
2003-10-09 19:45:19 +00:00
$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>");
2003-10-03 14:55:27 +00:00
break;
2003-10-07 18:16:41 +00:00
case 'admin/system/modules#description':
2003-10-03 14:55:27 +00:00
$output = t("Enables tracking of recent posts for users.");
break;
2003-08-20 21:06:51 +00:00
}
2003-10-03 14:55:27 +00:00
return $output;
2002-02-22 19:23:04 +00:00
}
2001-09-20 20:57:35 +00:00
function tracker_link($type) {
2001-10-11 18:54:35 +00:00
2003-04-21 14:55:03 +00:00
$links = array();
2003-09-26 10:04:09 +00:00
if ($type == "system") {
if (user_access("access content")) {
2003-11-20 21:51:23 +00:00
menu("tracker", t("recent posts"), "tracker_page", 1);
2003-09-26 10:04:09 +00:00
}
2001-09-20 20:57:35 +00:00
}
2003-04-21 14:55:03 +00:00
return $links;
2001-09-20 20:57:35 +00:00
}
2003-03-14 20:41:27 +00:00
function tracker_posts($id = 0) {
2001-11-17 17:37:10 +00:00
2003-08-21 15:47:50 +00:00
$header = array(
2003-12-14 19:23:11 +00:00
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")
2003-08-21 15:47:50 +00:00
);
2001-09-20 20:57:35 +00:00
if ($id) {
2003-08-21 15:47:50 +00:00
2003-09-09 18:18:43 +00:00
$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";
2003-08-21 15:47:50 +00:00
$sql .= tablesort_sql($header);
$sresult = pager_query($sql, 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1 AND uid = '". check_query($id) ."'");
2001-09-20 20:57:35 +00:00
}
else {
2003-09-09 18:18:43 +00:00
$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";
2003-08-21 15:47:50 +00:00
$sql .= tablesort_sql($header);
$sresult = pager_query($sql, 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1");
}
2003-03-15 20:00:17 +00:00
2001-09-20 20:57:35 +00:00
while ($node = db_fetch_object($sresult)) {
if ($id) {
2003-09-09 18:18:43 +00:00
$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);
2001-09-20 20:57:35 +00:00
}
else {
2003-09-09 18:18:43 +00:00
$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);
2001-09-20 20:57:35 +00:00
}
2003-03-15 20:00:17 +00:00
$type = ucfirst(module_invoke($node->type, "node", "name"));
2003-11-09 23:27:22 +00:00
$title = l($node->title, "node/view/$node->nid") ." ". (node_is_new($node->nid, $node->changed) ? theme("mark") : "");
2003-03-15 20:00:17 +00:00
$author = format_name($node);
2003-03-14 20:41:27 +00:00
$comments = array();
2001-09-20 20:57:35 +00:00
while ($comment = db_fetch_object($cresult)) {
2003-11-09 23:27:22 +00:00
$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";
2003-03-14 20:41:27 +00:00
}
if ($comments) {
2003-03-15 20:00:17 +00:00
$comments = "<ul>". implode("\n", $comments) ."</ul>";
}
else {
$comments = "";
2001-09-20 20:57:35 +00:00
}
2003-03-15 20:00:17 +00:00
2003-08-21 15:47:50 +00:00
$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"));
2001-09-20 20:57:35 +00:00
}
2003-12-08 18:30:20 +00:00
if ($pager = theme("pager", NULL, 10, 0, tablesort_pager())) {
2003-08-21 15:47:50 +00:00
$rows[] = array(array("data" => $pager, "colspan" => 4));
2003-03-16 07:38:39 +00:00
}
2003-03-15 20:00:17 +00:00
$output = "<div id=\"tracker\">";
2003-11-13 19:52:54 +00:00
$output .= theme("table", $header, $rows);
2003-03-15 20:00:17 +00:00
$output .= "</div>";
2001-09-20 20:57:35 +00:00
return $output;
}
2003-03-14 20:41:27 +00:00
function tracker_user($type, &$edit, &$user) {
switch ($type) {
2003-07-09 18:39:46 +00:00
case "view_private":
2003-03-14 20:41:27 +00:00
case "view_public":
if (user_access("access content")) {
2003-10-09 19:45:19 +00:00
return 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
}
function tracker_page() {
2003-02-15 11:39:56 +00:00
global $user;
2002-05-12 19:31:50 +00:00
2003-03-14 20:41:27 +00:00
if (user_access("access content")) {
2003-11-25 19:26:21 +00:00
print theme("page", tracker_posts(arg(1)), t("Recent posts"));
2001-09-20 20:57:35 +00:00
}
2003-11-20 21:51:23 +00:00
else {
2003-11-25 19:26:21 +00:00
print theme("page", message_access());
2003-11-20 21:51:23 +00:00
}
2001-09-20 20:57:35 +00:00
}
2001-11-01 11:00:51 +00:00
2003-09-26 10:04:09 +00:00
?>