summaryrefslogtreecommitdiff
path: root/modules/tracker.module
blob: 2ddc4440c8f9cc4e5f9e819915bb513295ce6817 (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
<?php
// $Id$

function tracker_help() {
  $output .= "The tracker module is a handy module for displaying the most recent comments happenning all over your web site.  By following the <i>view new comments</i> link in the user block, a user may quickly review all recent comments.  When a user first arrives at the main tracker page, she sees all recent comments in reverse chronological order, grouped by post.  In addition, a self-centered user may choose to display only his own comments.</p>";
  return $output;
}

function tracker_link($type) {

  if ($type == "menu.view") {
    $links[] = lm(t("view new comments"), array("mod" => "tracker"), t("Display an overview of the recent comments."));
  }

  return $links ? $links : array();
}

function tracker_comments($id = 0) {
  global $theme, $user;

  $period = time() - 259200;  // all comments of the past 3 days

  if ($id) {
    $sresult = db_query("SELECT n.nid, n.title, COUNT(n.nid) AS comments, MAX(c.timestamp) AS last_comment FROM comments c LEFT JOIN node n ON c.nid = n.nid WHERE c.timestamp > $period AND c.uid = '%s' GROUP BY n.nid, n.title DESC ORDER BY last_comment DESC LIMIT 10", $id);
  }
  else {
    $sresult = db_query("SELECT n.nid, n.title, COUNT(n.nid) AS comments, MAX(c.timestamp) AS last_comment FROM comments c LEFT JOIN node n ON c.nid = n.nid WHERE c.timestamp > $period GROUP BY n.nid, n.title DESC ORDER BY last_comment DESC LIMIT 10");
  }

  while ($node = db_fetch_object($sresult)) {
    $output .= format_plural($node->comments, "comment", "comments") ." ". t("attached to node") ." ". l(check_output($node->title), array("id" => $node->nid)) .":\n";

    if ($id) {
      $cresult = db_query("SELECT c.*, u.name FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.timestamp > $period AND c.uid = '%d' AND c.nid = '%d' ORDER BY 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.timestamp > $period AND c.nid = '%d' ORDER BY cid DESC", $node->nid);
    }

    $output .= "<ul>";
    while ($comment = db_fetch_object($cresult)) {
      $output .= " <li>". l(check_output($comment->subject), array("id" => $node->nid, "cid" => $comment->cid, "pid" => $comment->pid ."#". $comment->cid)) ." by ". lm(check_output($comment->name), array("mod" => "user", "op" => "view", "id" => $comment->uid)) ." (". t("replies") .": ". comment_num_replies($comment->cid) .") ". (comment_is_new($comment) ? "<span style=\"color: red;\">*</span>" : "") ."</li>\n";
    }
    $output .= " </ul>\n";
  }

  return $output;
}

function tracker_menu() {
  global $user;

  $links[] = lm(t("your recent comments"), array("mod" => "tracker", "id" => $user->uid), t("Display an overview of your recent comments."));
  $links[] = lm(t("all recent comments"), array("mod" => "tracker"), t("Display an overview of all the recent comments."));

  return "<div align=\"center\">". implode(" &middot; ", $links) ."</div>";
}


function tracker_page() {
  global $theme, $id;

  $theme->header();

  $theme->box(t("Tracker"), tracker_menu());

  if ($id) {
    $theme->box(t("Your recent comments"), tracker_comments($id));
  }
  else {
    $theme->box(t("All recent comments"), tracker_comments());
  }

  $theme->footer();
}

?>