summaryrefslogtreecommitdiff
path: root/modules/tracker.module
blob: c6fa4bdc452986c140d47c863bd12f25149bf8d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
// $Id$

function tracker_help() {
  $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>";
  return $output;
}

function tracker_system($field) {
  $system["description"] = t("Enables tracking of recent posts for users.");
  return $system[$field];
}

function tracker_link($type) {

  $links = array();

  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.")));
  }

  return $links;
}

function tracker_posts($id = 0) {

  if ($id) {
    $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) ."'");
  }
  else {
    $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");
  }

  $header = array(t("Type"), t("Title"), t("Author"));

  while ($node = db_fetch_object($sresult)) {
    if ($id) {
      $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);
    }
    else {
      $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);
    }

    $type = ucfirst(module_invoke($node->type, "node", "name"));
    $title = l($node->title, "node/view/$node->nid") ." ". (node_is_new($node->nid, $node->changed) ? theme("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("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"));
  }

  if ($pager = pager_display(NULL, 10)) {
   $rows[] = array(array("data" => $pager, "colspan" => 3));
  }

  $output  = "<div id=\"tracker\">";
  $output .= 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("view recent posts"), "tracker/$user->uid"));
      }
  }
}

function tracker_page() {
  global $user;

  if (user_access("access content")) {
    theme("header", t("Recent activity"));
    theme("box", t("Recent activity"), tracker_posts(arg(1)));
    theme("footer");
  }
}

?>