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

Dries's avatar
   
Dries committed
4
5
6
7
8
9
function tracker_help($section = "admin/tracker/help") {

  switch ($section) {
    case "admin/tracker/help":
     return t("<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
10
11
}

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

Dries's avatar
   
Dries committed
17
function tracker_link($type) {
Dries's avatar
   
Dries committed
18

Dries's avatar
   
Dries committed
19
20
  $links = array();

Dries's avatar
   
Dries committed
21
22
  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
23
24
  }

Dries's avatar
   
Dries committed
25
  return $links;
Dries's avatar
   
Dries committed
26
27
}

Dries's avatar
   
Dries committed
28
function tracker_posts($id = 0) {
Dries's avatar
   
Dries committed
29

Dries's avatar
   
Dries committed
30
31
32
33
34
35
  $header = array(
    array("data" => t("Type"), "field" => "type"),
    array("data" => t("Title"), "field" => "title"),
    array("data" => t("Author"), "field" => "uid"),
    array("data" => t("Last Post"), "field" => "last_activity", "sort" => "desc")
  );
Dries's avatar
   
Dries committed
36
  if ($id) {
Dries's avatar
   
Dries committed
37
38
39
40
41

    $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 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";
    $sql .= tablesort_sql($header);
    $sresult = pager_query($sql, 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1 AND uid = '". check_query($id) ."'");

Dries's avatar
   
Dries committed
42
43
44
  }
  else {

Dries's avatar
   
Dries committed
45
46
47
48
49
    $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 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";
    $sql .= tablesort_sql($header);
    $sresult = pager_query($sql, 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1");

  }
Dries's avatar
   
Dries committed
50

Dries's avatar
   
Dries committed
51
52
  while ($node = db_fetch_object($sresult)) {
    if ($id) {
Dries's avatar
   
Dries committed
53
      $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
54
55
    }
    else {
Dries's avatar
   
Dries committed
56
      $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
57
58
    }

Dries's avatar
   
Dries committed
59
    $type = ucfirst(module_invoke($node->type, "node", "name"));
Dries's avatar
   
Dries committed
60
    $title = l($node->title, node_url($node)) ." ". (node_is_new($node->nid, $node->changed) ? theme("theme_mark") : "");
Dries's avatar
   
Dries committed
61
    $author = format_name($node);
Dries's avatar
   
Dries committed
62
63

    $comments = array();
Dries's avatar
   
Dries committed
64
    while ($comment = db_fetch_object($cresult)) {
Dries's avatar
   
Dries committed
65
      $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
66
67
68
    }

    if ($comments) {
Dries's avatar
   
Dries committed
69
70
71
72
      $comments = "<ul>". implode("\n", $comments) ."</ul>";
    }
    else {
      $comments = "";
Dries's avatar
   
Dries committed
73
    }
Dries's avatar
   
Dries committed
74

Dries's avatar
   
Dries committed
75
    $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"));
Dries's avatar
   
Dries committed
76
77
  }

Dries's avatar
Dries committed
78
  if ($pager = pager_display(NULL, 10, 0, "default", tablesort_pager())) {
Dries's avatar
   
Dries committed
79
   $rows[] = array(array("data" => $pager, "colspan" => 4));
Dries's avatar
   
Dries committed
80
81
  }

Dries's avatar
   
Dries committed
82
83
84
85
  $output  = "<div id=\"tracker\">";
  $output .= table($header, $rows);
  $output .= "</div>";

Dries's avatar
   
Dries committed
86
87
88
  return $output;
}

Dries's avatar
   
Dries committed
89
90
function tracker_user($type, &$edit, &$user) {
  switch ($type) {
91
    case "view_private":
Dries's avatar
   
Dries committed
92
93
94
95
96
    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
97
98
99
}

function tracker_page() {
Dries's avatar
   
Dries committed
100
  global $user;
Kjartan's avatar
Kjartan committed
101

Dries's avatar
   
Dries committed
102
103
104
105
  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
106
107
  }
}
Dries's avatar
   
Dries committed
108

Dries's avatar
   
Dries committed
109
?>