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

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

Dries Buytaert's avatar
 
Dries Buytaert committed
  if ($type == "menu.view") {
Dries Buytaert's avatar
 
Dries Buytaert committed
    $links[] = "<a href=\"module.php?mod=tracker\" title=\"". t("Display an overview of the recent comments.") ."\">". t("view new comments") ."</a>";
Dries Buytaert's avatar
Dries Buytaert committed
  }

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

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

Dries Buytaert's avatar
 
Dries Buytaert committed
  $period = time() - 259200;  // all comments of the past 3 days

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.timestamp > $period AND c.uid = '". check_input($id) ."' GROUP BY n.nid, n.title DESC ORDER BY last_comment DESC LIMIT 10");
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.timestamp > $period GROUP BY n.nid, n.title DESC 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, "comment", "comments") ." ". t("attached to node") ." <a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a>:\n";
Dries Buytaert's avatar
Dries Buytaert committed

    if ($id) {
Dries Buytaert's avatar
 
Dries Buytaert committed
      $cresult = db_query("SELECT * FROM comments WHERE timestamp > $period AND uid = '". check_input($id) ."' AND nid = '$node->nid' ORDER BY cid DESC");
Dries Buytaert's avatar
Dries Buytaert committed
    }
    else {
Dries Buytaert's avatar
 
Dries Buytaert committed
      $cresult = db_query("SELECT * FROM comments WHERE timestamp > $period AND nid = '$node->nid' ORDER BY cid DESC");
Dries Buytaert's avatar
Dries Buytaert committed
    }

    $output .= "<ul>";
    while ($comment = db_fetch_object($cresult)) {
Dries Buytaert's avatar
 
Dries Buytaert committed
      $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) .") ". (comment_is_new($comment) ? "<span style=\"color: red;\">*</span>" : "") ."</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[] = "<a href=\"module.php?mod=tracker&id=$user->uid\" title=\"". t("Display an overview of your recent comments.") ."\">your recent comments</a>";
  $links[] = "<a href=\"module.php?mod=tracker\" title=\"". t("Display an overview of all the recent comments.") ."\">all recent comments</a>";
Dries Buytaert's avatar
Dries Buytaert committed

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


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

  $theme->header();
Dries Buytaert's avatar
 
Dries Buytaert committed

Dries Buytaert's avatar
Dries Buytaert committed
  $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();
}
Dries Buytaert's avatar
 
Dries Buytaert committed

Dries Buytaert's avatar
Dries Buytaert committed
?>