From 9b69714c3f4d26a94d6381a90b24ec767fe9be5e Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Thu, 27 Dec 2001 20:35:40 +0000 Subject: - Revised the comment links: when a user does not have the required permissions to post comments, the "reply to this comment"-link is no longer shown. Also, when a user is a "comment administrator", an "administer"-link will be displayed. - Revised the threaded_min and threaded_max code: it makes rendering pages with more than 15 comments 200% times faster. --- modules/comment/comment.module | 69 +++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 27 deletions(-) (limited to 'modules/comment/comment.module') diff --git a/modules/comment/comment.module b/modules/comment/comment.module index dc3ca5ad9..e527fa87d 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -244,12 +244,21 @@ function comment_visible($comment, $threshold = 0) { function comment_links($comment, $return = 1) { global $theme; + $links = array(); + if ($return) { - return "lid#$comment->cid\">type\">". t("return") ." | lid&pid=$comment->cid\">type\">". t("reply to this comment") .""; + $links[] = "lid#$comment->cid\">type\">". t("return") .""; } - else { - return "lid&pid=$comment->cid\">type\">". t("reply to this comment") .""; + + if (user_access("administer comments")) { + $links[] = "cid\">type\">". t("administer") .""; } + + if (user_access("post comments")) { + $links[] = "lid&pid=$comment->cid\">type\">". t("reply to this comment") .""; + } + + return $theme->links($links); } function comment_view($comment, $folded = 0) { @@ -263,20 +272,20 @@ function comment_view($comment, $folded = 0) { } } -function comment_thread_min($cid, $threshold) { +function comment_thread_min($comments, $threshold, $pid = 0) { global $user; - $result = db_query("SELECT c.cid, c.pid, c.lid, c.subject, c.comment, c.timestamp, u.uid, u.name, AVG(m.score) AS score, COUNT(m.cid) AS votes FROM comments c LEFT JOIN users u ON c.uid = u.uid LEFT JOIN moderate m ON c.cid = m.cid WHERE c.pid = '$cid' GROUP BY c.cid, c.pid, c.lid, c.subject, c.comment, c.timestamp, u.uid, u.name ORDER BY c.timestamp"); - - while ($comment = db_fetch_object($result)) { - print ""; + foreach ($comments as $comment) { + if ($comment->pid == $pid) { + print ""; + } } } -function comment_thread_max($cid, $mode, $threshold, $level = 0) { +function comment_thread_max($comments, $threshold, $pid = 0, $level = 0) { global $user; /* @@ -288,14 +297,14 @@ function comment_thread_max($cid, $mode, $threshold, $level = 0) { ** in terms of speed and size. */ - $result = db_query("SELECT c.cid, c.pid, c.lid, c.subject, c.comment, c.timestamp, u.uid, u.name, AVG(m.score) AS score, COUNT(m.cid) AS votes FROM comments c LEFT JOIN users u ON c.uid = u.uid LEFT JOIN moderate m ON c.cid = m.cid WHERE c.pid = '$cid' GROUP BY c.cid, c.pid, c.lid, c.subject, c.comment, c.timestamp, u.uid, u.name ORDER BY c.timestamp"); + foreach ($comments as $comment) { + if ($comment->pid == $pid) { + print "
 \n"; + comment_view($comment, (comment_visible($comment, $threshold) ? comment_links($comment, 0) : 0)); + print "
\n"; - while ($comment = db_fetch_object($result)) { - print "
 \n"; - comment_view($comment, (comment_visible($comment, $threshold) ? comment_links($comment, 0) : 0)); - print "
\n"; - - comment_thread_max($comment->cid, $mode, $threshold, $level + 1); + comment_thread_max($comments, $threshold, $comment->cid, $level + 1); + } } } @@ -363,17 +372,23 @@ function comment_render($lid, $cid) { } } else if ($mode == 3) { - $result = comment_query($lid, $order, 0); + $result = comment_query($lid, $order); while ($comment = db_fetch_object($result)) { - comment_view($comment); - comment_thread_min($comment->cid, $threshold); + $comments[] = $comment; + } + + if ($comments) { + comment_thread_min(array_reverse($comments), $threshold); } } else { - $result = comment_query($lid, $order, 0); + $result = comment_query($lid, $order); while ($comment = db_fetch_object($result)) { - comment_view($comment, (comment_visible($comment, $threshold) ? comment_links($comment, 0) : 0)); - comment_thread_max($comment->cid, $mode, $threshold, $level + 1); + $comments[] = $comment; + } + + if ($comments) { + comment_thread_max(array_reverse($comments), $threshold); } } } @@ -397,7 +412,7 @@ function comment_perm() { } function comment_link($type, $node = 0, $main = 0) { - if ($type == "admin" and user_access("administer comments")) { + if ($type == "admin" && user_access("administer comments")) { $links[] = "comments"; } @@ -430,7 +445,7 @@ function comment_link($type, $node = 0, $main = 0) { function comment_node_link($node) { - if (node_get_comments($node->nid)) { + if (user_access("administer comments") && node_get_comments($node->nid)) { /* ** Edit comments: -- cgit v1.2.3