tracker.module 3.6 KB
Newer Older
Dries's avatar
 
Dries committed
1
<?php
2
// $Id$
Dries's avatar
 
Dries committed
3

Dries's avatar
 
Dries committed
4
function tracker_help() {
Dries's avatar
 
Dries committed
5
  $output .= "<p>The tracker module is a handy module for displaying the most recent posts.  By following the <i>view recent posts</i> link in the user block, a user may quickly review all recent postings.</p>";
Dries's avatar
 
Dries committed
6 7 8
  return $output;
}

Dries's avatar
 
Dries committed
9
function tracker_system($field) {
Dries's avatar
 
Dries committed
10
  $system["description"] = t("Enables tracking of recent posts for users.");
11 12 13
  return $system[$field];
}

Dries's avatar
 
Dries committed
14
function tracker_link($type) {
Dries's avatar
 
Dries committed
15

Dries's avatar
 
Dries committed
16 17
  $links = array();

Dries's avatar
 
Dries committed
18 19
  if ($type == "menu.view" && user_access("access content")) {
    $links[] = l(t("view recent posts"), "tracker", array("title" => t("Display an overview of the recent posts.")));
Dries's avatar
 
Dries committed
20 21
  }

Dries's avatar
 
Dries committed
22
  return $links;
Dries's avatar
 
Dries committed
23 24
}

Dries's avatar
 
Dries committed
25
function tracker_posts($id = 0) {
Dries's avatar
 
Dries committed
26

Dries's avatar
 
Dries committed
27
  if ($id) {
Dries's avatar
 
Dries committed
28
    $sresult = pager_query("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 INNER JOIN {comments} c ON n.nid = c.nid LEFT 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 ORDER BY last_activity DESC", 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1 AND uid = '". check_query($id) ."'");
Dries's avatar
 
Dries committed
29 30
  }
  else {
Dries's avatar
 
Dries committed
31
    $sresult = pager_query("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 INNER JOIN {comments} c ON n.nid = c.nid LEFT 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_activity DESC", 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1");
Dries's avatar
 
Dries committed
32 33
  }

Dries's avatar
 
Dries committed
34 35
  $header = array(t("Type"), t("Title"), t("Author"));

Dries's avatar
 
Dries committed
36 37
  while ($node = db_fetch_object($sresult)) {
    if ($id) {
Dries's avatar
 
Dries committed
38
      $cresult = db_query("SELECT c.*, u.name FROM {comments} c LEFT 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);
Dries's avatar
 
Dries committed
39 40
    }
    else {
Dries's avatar
 
Dries committed
41
      $cresult = db_query("SELECT c.*, u.name FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d AND c.status = 0 ORDER BY c.cid DESC", $node->nid);
Dries's avatar
 
Dries committed
42 43
    }

Dries's avatar
 
Dries committed
44
    $type = ucfirst(module_invoke($node->type, "node", "name"));
Dries's avatar
 
Dries committed
45
    $title = l($node->title, node_url($node)) ." ". (node_is_new($node->nid, $node->changed) ? theme("theme_mark") : "");
Dries's avatar
 
Dries committed
46
    $author = format_name($node);
Dries's avatar
 
Dries committed
47 48

    $comments = array();
Dries's avatar
 
Dries committed
49
    while ($comment = db_fetch_object($cresult)) {
Dries's avatar
 
Dries committed
50
      $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("theme_mark") : "") ."</li>\n";
Dries's avatar
 
Dries committed
51 52 53
    }

    if ($comments) {
Dries's avatar
 
Dries committed
54 55 56 57
      $comments = "<ul>". implode("\n", $comments) ."</ul>";
    }
    else {
      $comments = "";
Dries's avatar
 
Dries committed
58
    }
Dries's avatar
 
Dries committed
59 60

    $rows[] = array(array("data" => $type, "class" => "type"), array("data" => $title . $comments, "class" => "content"), array("data" => $author, "class" => "author"));
Dries's avatar
 
Dries committed
61 62
  }

Dries's avatar
 
Dries committed
63 64 65 66
  if ($pager = pager_display(NULL, 10)) {
   $rows[] = array(array("data" => $pager, "colspan" => 3));
  }

Dries's avatar
 
Dries committed
67 68 69 70
  $output  = "<div id=\"tracker\">";
  $output .= table($header, $rows);
  $output .= "</div>";

Dries's avatar
 
Dries committed
71 72 73
  return $output;
}

Dries's avatar
 
Dries committed
74 75
function tracker_user($type, &$edit, &$user) {
  switch ($type) {
76
    case "view_private":
Dries's avatar
 
Dries committed
77 78 79 80 81
    case "view_public":
      if (user_access("access content")) {
        return form_item(t("Recent posts"), l(t("view recent posts"), "tracker/$user->uid"));
      }
  }
Dries's avatar
 
Dries committed
82 83 84
}

function tracker_page() {
Dries's avatar
 
Dries committed
85
  global $user;
Kjartan's avatar
Kjartan committed
86

Dries's avatar
 
Dries committed
87 88 89 90
  if (user_access("access content")) {
    theme("header", t("Recent activity"));
    theme("box", t("Recent activity"), tracker_posts(arg(1)));
    theme("footer");
Dries's avatar
 
Dries committed
91 92
  }
}
Dries's avatar
 
Dries committed
93

Dries's avatar
 
Dries committed
94
?>