Skip to content
Snippets Groups Projects
tracker.module 4.83 KiB
Newer Older
Dries Buytaert's avatar
Dries Buytaert committed
<?php
Dries Buytaert's avatar
Dries Buytaert committed

Dries Buytaert's avatar
 
Dries Buytaert committed
function tracker_help() {
  $output .= "<p>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>";
Dries Buytaert's avatar
 
Dries Buytaert committed
  return $output;
}

function tracker_system($field){
  $system["description"] = t("Enables tracking of recent and new comments for users.");
Dries Buytaert's avatar
Dries Buytaert committed
function tracker_link($type) {
Dries Buytaert's avatar
 
Dries Buytaert committed

Kjartan Mannes's avatar
Kjartan Mannes committed
  if ($type == "menu.view" && user_access("access comments")) {
Dries Buytaert's avatar
 
Dries Buytaert committed
    $links[] = l(t("view new comments"), "tracker", array("title" => t("Display an overview of the recent comments.")));
Dries Buytaert's avatar
Dries Buytaert committed
  }

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

Dries Buytaert's avatar
 
Dries Buytaert committed
  $period = array(3600 => format_interval(3600), 10800 => format_interval(10800), 21600 => format_interval(21600), 32400 => format_interval(32400), 43200 => format_interval(43200), 86400 => format_interval(86400), 172800 => format_interval(172800), 259200 => format_interval(259200), 604800 => format_interval(604800), 1209600 => format_interval(1209600), 2419200 => format_interval(2419200), 1000000000 => "All");
  $output .= form_select("Show comments more recent than", "tracker_period", variable_get("tracker_period", 259200), $period, "Comments younger than this get displayed.");
  return $output;
}

Dries Buytaert's avatar
Dries Buytaert committed
function tracker_comments($id = 0) {
Dries Buytaert's avatar
 
Dries Buytaert committed
  $period = time() - variable_get("tracker_period", 259200);  // all comments of the past 3 days if not configured to a different value
Dries Buytaert's avatar
 
Dries Buytaert committed

Dries Buytaert's avatar
Dries Buytaert committed
  if ($id) {
Dries Buytaert's avatar
 
Dries Buytaert committed
    $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.status = 0 AND c.timestamp > $period AND c.uid = '%s' GROUP BY n.nid, n.title ORDER BY last_comment DESC LIMIT 10", $id);
Dries Buytaert's avatar
Dries Buytaert committed
  }
  else {
Dries Buytaert's avatar
 
Dries Buytaert committed
    $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.status = 0 AND c.timestamp > $period GROUP BY n.nid, n.title ORDER BY last_comment DESC LIMIT 10");
Dries Buytaert's avatar
Dries Buytaert committed
  }

  while ($node = db_fetch_object($sresult)) {
Dries Buytaert's avatar
 
Dries Buytaert committed
    $output .= format_plural($node->comments, "1 comment", "%count comments") ." ". t("attached to node") ." ". l($node->title, "node/view/$node->nid") .":\n";
Dries Buytaert's avatar
Dries Buytaert committed

    if ($id) {
Dries Buytaert's avatar
 
Dries Buytaert committed
      $cresult = db_query("SELECT c.*, u.name FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.timestamp > %d AND c.uid = '%d' AND c.nid = '%d' AND c.status = 0 ORDER BY cid DESC", $period, $id, $node->nid);
Dries Buytaert's avatar
Dries Buytaert committed
    }
    else {
Dries Buytaert's avatar
 
Dries Buytaert committed
      $cresult = db_query("SELECT c.*, u.name FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.timestamp > %d AND c.nid = '%d'AND c.status = 0 ORDER BY cid DESC", $period, $node->nid);
Dries Buytaert's avatar
Dries Buytaert committed
    }

    $output .= "<ul>";
    while ($comment = db_fetch_object($cresult)) {
      $output .= " <li>". l($comment->subject, "node/view/$node->nid#$comment->cid") ." ". t("by") ." ". format_name($comment) ." (". t("replies") .": ". comment_num_replies($comment->cid) .") ". (comment_is_new($comment) ? theme("theme_mark") : "") ."</li>\n";
Dries Buytaert's avatar
Dries Buytaert committed
    }
    $output .= " </ul>\n";
  }

  return $output;
}

function tracker_menu() {
  global $user;

Dries Buytaert's avatar
 
Dries Buytaert committed
  $links[] = l(t("your recent comments"), "tracker/$user->uid", array("title" => t("Display an overview of your recent comments.")));
  $links[] = l(t("all recent comments"), "tracker", array("title" => t("Display an overview of all the recent comments.")));
Dries Buytaert's avatar
Dries Buytaert committed

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


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

  if (user_access("access comments")) {
Dries Buytaert's avatar
 
Dries Buytaert committed
    if (arg(1) == $user->uid) {
Dries Buytaert's avatar
 
Dries Buytaert committed
      theme("header", t("Your recent comments"));
      theme("box", t("Tracker"), tracker_menu());
      theme("box", t("Your recent comments"), tracker_comments(arg(1)));
      theme("footer");
Kjartan Mannes's avatar
Kjartan Mannes committed
    }
Dries Buytaert's avatar
 
Dries Buytaert committed
    else if (arg(1)) {
      $account = user_load(array("uid" => arg(1)));
Dries Buytaert's avatar
 
Dries Buytaert committed
      theme("header", t("%u's recent comments", array("%u" => $account->name)));
      theme("box", t("Tracker"), tracker_menu());
      theme("box", t("%u's recent comments", array("%u" => $account->name)), tracker_comments(arg(1)));
      theme("footer");
Kjartan Mannes's avatar
Kjartan Mannes committed
    }
    else {
Dries Buytaert's avatar
 
Dries Buytaert committed
      theme("header", t("All recent comments"));
      theme("box", t("Tracker"), tracker_menu());
      theme("box", t("All recent comments"), tracker_comments());
      theme("footer");
Kjartan Mannes's avatar
Kjartan Mannes committed
    }
Dries Buytaert's avatar
Dries Buytaert committed
  }
}
Dries Buytaert's avatar
 
Dries Buytaert committed

Kjartan Mannes's avatar
Kjartan Mannes committed
function tracker_user($type, &$edit, &$user) {
  switch ($type) {
    case "view_public":
    case "view_private":
      if (user_access("access comments")) {
Dries Buytaert's avatar
 
Dries Buytaert committed
        return form_item(t("Comments"), l(t("view recent comments"), "tracker/$user->uid", array("title" => t("View recent comments."))));
Kjartan Mannes's avatar
Kjartan Mannes committed
      }
  }
}
Dries Buytaert's avatar
Dries Buytaert committed
?>