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

Dries Buytaert's avatar
   
Dries Buytaert committed
4
function tracker_help() {
Dries Buytaert's avatar
   
Dries Buytaert 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 Buytaert's avatar
   
Dries Buytaert committed
6
7
8
  return $output;
}

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

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

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

Dries Buytaert's avatar
   
Dries Buytaert 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 Buytaert's avatar
 
Dries Buytaert committed
20
21
  }

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

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

Dries Buytaert's avatar
 
Dries Buytaert committed
27
  if ($id) {
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 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 ORDER BY last_activity DESC", 10, 0, "SELECT COUNT(nid) FROM node WHERE status = 1 AND uid = '". check_query($id) ."'");
Dries Buytaert's avatar
 
Dries Buytaert committed
29
30
  }
  else {
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 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 ORDER BY last_activity DESC", 10, 0, "SELECT COUNT(nid) FROM node WHERE status = 1");
Dries Buytaert's avatar
 
Dries Buytaert committed
32
33
  }

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

Dries Buytaert's avatar
 
Dries Buytaert committed
36
37
  while ($node = db_fetch_object($sresult)) {
    if ($id) {
Dries Buytaert's avatar
   
Dries Buytaert 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 cid DESC", $id, $node->nid);
Dries Buytaert's avatar
 
Dries Buytaert committed
39
40
    }
    else {
Dries Buytaert's avatar
   
Dries Buytaert 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 cid DESC", $node->nid);
Dries Buytaert's avatar
 
Dries Buytaert committed
42
43
    }

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

    $comments = array();
Dries Buytaert's avatar
 
Dries Buytaert committed
49
    while ($comment = db_fetch_object($cresult)) {
Dries Buytaert's avatar
   
Dries Buytaert 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 Buytaert's avatar
   
Dries Buytaert committed
51
52
53
    }

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

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

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

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

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

Dries Buytaert's avatar
   
Dries Buytaert committed
74
75
function tracker_user($type, &$edit, &$user) {
  switch ($type) {
76
    case "view_private":
Dries Buytaert's avatar
   
Dries Buytaert 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 Buytaert's avatar
 
Dries Buytaert committed
82
83
84
}

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

Dries Buytaert's avatar
   
Dries Buytaert 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 Buytaert's avatar
 
Dries Buytaert committed
91
92
  }
}
Dries Buytaert's avatar
   
Dries Buytaert committed
93

Dries Buytaert's avatar
 
Dries Buytaert committed
94
?>