--- comment.module 2004/03/11 02:40:56 1.2
+++ comment.module 2004/03/11 06:12:13
@@ -541,7 +541,7 @@
** Switch to folded/unfolded view of the comment
*/
- if (node_is_new($comment->nid, $comment->timestamp)) {
+ if (comment_is_new($comment->cid)) {
$comment->new = 1;
print "\n";
}
@@ -551,6 +551,7 @@
if ($visible) {
$comment->comment = check_output($comment->comment);
theme("comment", $comment, $links);
+ comment_tag_new($comment->cid);
}
else {
theme("comment_folded", $comment);
@@ -1004,7 +1005,7 @@
$result = pager_query($sql, 50);
while ($comment = db_fetch_object($result)) {
- $rows[] = array(l($comment->subject, "node/view/$comment->nid/$comment->cid#$comment->cid", array("title" => htmlspecialchars(substr($comment->comment, 0, 128)))) ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme_mark() : ""), format_name($comment), ($comment->status == 0 ? t("published") : t("not published")) ."
". format_date($comment->timestamp, "small") ." | ". l(t("edit comment"), "admin/comment/edit/$comment->cid"), l(t("delete comment"), "admin/comment/delete/$comment->cid"));
+ $rows[] = array(l($comment->subject, "node/view/$comment->nid/$comment->cid#$comment->cid", array("title" => htmlspecialchars(substr($comment->comment, 0, 128)))) ." ". (comment_is_new($comment->cid) ? theme_mark() : ""), format_name($comment), ($comment->status == 0 ? t("published") : t("not published")) ." | ". format_date($comment->timestamp, "small") ." | ". l(t("edit comment"), "admin/comment/edit/$comment->cid"), l(t("delete comment"), "admin/comment/delete/$comment->cid"));
}
if ($pager = pager_display(NULL, 50, 0, "admin", tablesort_pager())) {
@@ -1368,6 +1369,7 @@
$output .= " $links ";
$output .= "";
print $output;
+ comment_tag_new($comment->cid);
}
function comment_folded($comment) {
@@ -1526,32 +1528,32 @@
* @param $nid node-id to count comments for
* @param $timestamp time to count from (defaults to time of last user access to node)
*/
-function comment_num_new($nid, $timestamp = 0) {
- global $user;
-
- if ($user->uid) {
- /*
- ** Retrieve the timestamp at which the current user last viewed the
- ** specified node.
- */
-
- if (!$timestamp) {
- $timestamp = node_last_viewed($nid);
- }
+// function comment_num_new($nid, $timestamp = 0) {
+// global $user;
- /*
- ** Use the timestamp to retrieve the number of new comments
- */
-
- $result = db_result(db_query("SELECT COUNT(c.cid) FROM {node} n INNER JOIN {comments} c ON n.nid = c.nid WHERE n.nid = %d AND timestamp > %d AND c.status = 0", $nid, $timestamp));
-
- return $result;
- }
- else {
- return 0;
- }
+// if ($user->uid) {
+// /*
+// ** Retrieve the timestamp at which the current user last viewed the
+// ** specified node.
+// */
+
+// if (!$timestamp) {
+// $timestamp = node_last_viewed($nid);
+// }
+
+// /*
+// ** Use the timestamp to retrieve the number of new comments
+// */
+
+// $result = db_result(db_query("SELECT COUNT(c.cid) FROM {node} n INNER JOIN {comments} c ON n.nid = c.nid WHERE n.nid = %d AND timestamp > %d AND c.status = 0", $nid, $timestamp));
+
+// return $result;
+// }
+// else {
+// return 0;
+// }
-}
+// }
function comment_user_can_moderate($node) {
global $user;
@@ -1662,4 +1664,101 @@
return array(1 => t("Date - newest first"), 2 => t("Date - oldest first"));
}
+function comment_tag_new($cid) {
+ global $user;
+
+ if (! $user->uid) {
+ return;
+ }
+
+ $result = db_query("SELECT uid FROM {comments_history} WHERE uid = %d AND min_cid <= %d and max_cid >= %d", $user->uid, $cid, $cid);
+ if (db_fetch_object($result)) {
+ return;
+ }
+
+ db_query("UPDATE {comments_history} SET min_cid = %d where uid = %d AND min_cid = %d", $cid, $user->uid, $cid + 1);
+ if (db_affected_rows()) {
+ return;
+ }
+
+ db_query("UPDATE {comments_history} SET max_cid = %d where uid = %d AND max_cid = %d", $cid, $user->uid, $cid - 1);
+ if (db_affected_rows()) {
+ return;
+ }
+
+ db_query("INSERT INTO {comments_history} (uid, min_cid, max_cid) VALUES (%d, %d, %d)", $user->uid, $cid, $cid);
+}
+
+function comment_is_new($cid) {
+ global $user;
+
+ if (! $user->uid) {
+ return false;
+ }
+
+ $result = db_query("SELECT * FROM {comments_history} where uid = %d and min_cid <= %d and max_cid >= %d", $user->uid, $cid, $cid);
+ if (db_fetch_object($result)) {
+ return false;
+ }
+
+ return true;
+}
+
+function comment_num_new($nid) {
+ global $user;
+
+ if (! $user->uid) {
+ return 0;
+ }
+
+ $result = db_result(db_query("SELECT COUNT(c.cid) FROM {comments} c LEFT JOIN {comments_history} h ON h.uid = %d AND c.cid >= h.min_cid AND c.cid <= h.max_cid WHERE c.nid = %d AND c.status = 0 AND h.min_cid IS NULL", $user->uid, $nid));
+
+ return $result;
+}
+
+function comment_cron() {
+ $rows = db_query("SELECT * FROM {comments_history} ORDER BY uid, min_cid");
+
+ if (! ($row = db_fetch_object($rows))) {
+ return;
+ }
+
+ $uid = $row->uid;
+ $min = $row->min_cid;
+ $max = $row->max_cid;
+ $updating = false;
+
+ while ($row = db_fetch_object($rows)) {
+ if ($row->uid == $uid && $row->min_cid <= $max + 1) {
+ $updating = true;
+ $max = max($max, $row->max_cid);
+ continue;
+ }
+ if ($updating) {
+ $updates[] = array($uid, $min, $max);
+ }
+ $uid = $row->uid;
+ $min = $row->min_cid;
+ $max = $row->max_cid;
+ $updating = false;
+ }
+
+ if ($updating) {
+ $updates[] = array($uid, $min, $max);
+ }
+
+ if (! $updates) {
+ return;
+ }
+
+ foreach ($updates as $update) {
+ $uid = $update[0];
+ $min = $update[1];
+ $max = $update[2];
+
+ db_query("INSERT INTO {comments_history} (uid, min_cid, max_cid) values (%d, %d, %d)", $uid, $min, $max);
+ db_query("DELETE FROM {comments_history} WHERE uid = %d AND (min_cid > %d and max_cid < %d) OR (min_cid = %d and max_cid < %d) OR (min_cid > %d AND max_cid = %d)", $uid, $min, $max, $min, $max, $min, $max);
+ }
+}
+
?>
|