summaryrefslogtreecommitdiff
path: root/modules/tracker/tracker.module
blob: 462a649b405badf9900b69aefae0918619d2dc57 (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
<?php

function tracker_link($type) {

  if ($type == "menu") {
    $links[] = "<a href=\"module.php?mod=tracker\">". t("recent comments") ."</a>";
  }

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

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

  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.lid = n.nid WHERE c.author = '". check_input($id) ."' GROUP BY n.nid, n.title DESC ORDER BY last_comment DESC LIMIT 10");
  }
  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.lid = n.nid 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") ." <a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a>:\n";

    if ($id) {
      $cresult = db_query("SELECT * FROM comments WHERE author = '". check_input($id) ."' AND lid = '$node->nid' ORDER BY cid DESC");
    }
    else {
      $cresult = db_query("SELECT * FROM comments WHERE lid = '$node->nid' ORDER BY cid DESC");
    }

    $output .= "<ul>";
    while ($comment = db_fetch_object($cresult)) {
      $output .= " <li><a href=\"node.php?id=$node->nid&cid=$comment->cid&pid=$comment->pid#$comment->cid\">". check_output($comment->subject) ."</a> (". t("replies") .": ". comment_num_replies($comment->cid) .")</li>\n";
    }
    $output .= " </ul>\n";
  }

  return $output;
}

function tracker_menu() {
  global $user;

  $links[] = "<a href=\"module.php?mod=tracker&id=$user->uid\">your recent comments</a>";
  $links[] = "<a href=\"module.php?mod=tracker\">all recent comments</a>";

  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();
}

?>