tracker.module 4.05 KB
Newer Older
1
<?php
2
// $Id$
3

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

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

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

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

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

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

28
function tracker_posts($id = 0) {
29

30 31 32
  $header = array(
    array("data" => t("Type"), "field" => "type"),
    array("data" => t("Title"), "field" => "title"),
33
    array("data" => t("Author"), "field" => "u.name"),
34 35
    array("data" => t("Last Post"), "field" => "last_activity", "sort" => "desc")
  );
36
  if ($id) {
37

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

42 43 44
  }
  else {

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

  }
50

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

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

    $comments = array();
64
    while ($comment = db_fetch_object($cresult)) {
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";
66 67 68
    }

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

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

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

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

86 87 88
  return $output;
}

89 90
function tracker_user($type, &$edit, &$user) {
  switch ($type) {
91
    case "view_private":
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"));
      }
  }
97 98 99
}

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

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");
106 107
  }
}
108

109
?>