summaryrefslogtreecommitdiff
path: root/includes/comment.inc
diff options
context:
space:
mode:
Diffstat (limited to 'includes/comment.inc')
-rw-r--r--includes/comment.inc186
1 files changed, 96 insertions, 90 deletions
diff --git a/includes/comment.inc b/includes/comment.inc
index a680d476e..cea35102f 100644
--- a/includes/comment.inc
+++ b/includes/comment.inc
@@ -10,33 +10,29 @@ $cmodes = array(1 => "List - min", 2 => "List - max", 3 => "Threaded - min", 4 =
$corder = array(1 => "Date - new", 2 => "Date - old", 3 => "Rate - high", 4 => "Rate - low");
class Comment {
- function Comment($uid, $name, $subject, $comment, $timestamp, $url, $score, $votes, $cid, $lid) {
+ function Comment($uid, $name, $subject, $comment, $timestamp, $url, $cid, $lid) {
$this->uid = $uid;
$this->name = $name;
$this->subject = $subject;
$this->comment = $comment;
$this->timestamp = $timestamp;
$this->url = $url;
- $this->score = $score;
- $this->votes = $votes;
$this->cid = $cid;
$this->lid = $lid;
}
}
function comment_moderate($moderate) {
- global $user, $comment_votes;
+ global $user;
if ($user->uid && $moderate) {
- $none = $comment_votes[key($comment_votes)];
-
- foreach ($moderate as $id=>$vote) {
- if ($vote != $comment_votes[$none]) {
- $id = check_output($id);
- $vote = check_output($vote);
- $comment = db_fetch_object(db_query("SELECT * FROM comments WHERE cid = '$id'"));
- if ($comment && !field_get($comment->users, $user->uid)) {
- $result = db_query("UPDATE comments SET score = score $vote, votes = votes + 1, users = '". field_set($comment->users, $user->uid, $vote) ."' WHERE cid = '$id'");
+ foreach ($moderate as $cid => $score) {
+ if ($score > 0 && $score < 6) {
+ if (db_fetch_object(db_query("SELECT * FROM moderate WHERE uid = '". check_query($user->uid) ."' AND cid = '". check_query($cid) ."'"))) {
+ db_query("UPDATE moderate SET score = '". check_query($score) ."' WHERE uid = '". check_query($user->uid) ."' AND cid = '". check_query($cid) ."'");
+ }
+ else {
+ db_query("INSERT INTO moderate (uid, cid, score, timestamp) VALUES ('". check_query($user->uid) ."', '". check_query($cid) ."', '". check_query($score) ."', '". time() ."')");
}
}
}
@@ -83,7 +79,7 @@ function comment_reply($pid, $id) {
if ($pid) {
$item = db_fetch_object(db_query("SELECT c.*, u.name FROM comments c LEFT JOIN user u ON c.author = u.uid WHERE c.cid = '$pid'"));
- comment_view(new Comment($item->uid, $item->name, $item->subject, $item->comment, $item->timestamp, $item->url, comment_score($comment), $comment->votes, $item->cid, $item->lid), t("reply to this comment"));
+ comment_view(new Comment($item->uid, $item->name, $item->subject, $item->comment, $item->timestamp, $item->url, $item->cid, $item->lid), t("reply to this comment"));
}
else {
node_view(node_get_object(array("nid" => $id)));
@@ -128,7 +124,7 @@ function comment_post($edit) {
watchdog("special", "comment: added '$edit[subject]'");
// add comment to database:
- db_query("INSERT INTO comments (lid, pid, author, subject, comment, hostname, timestamp, score) VALUES ('". check_input($edit[id]) ."', '". check_input($edit[pid]) ."', '$user->uid', '". check_input($edit[subject]) ."', '". check_input($edit[comment]) ."', '". getenv("REMOTE_ADDR") ."', '". time() ."', '". ($user->name ? 1 : 0) ."')");
+ db_query("INSERT INTO comments (lid, pid, author, subject, comment, hostname, timestamp) VALUES ('". check_input($edit[id]) ."', '". check_input($edit[pid]) ."', '$user->uid', '". check_input($edit[subject]) ."', '". check_input($edit[comment]) ."', '". getenv("REMOTE_ADDR") ."', '". time() ."')");
// clear cache:
cache_clear();
@@ -136,96 +132,112 @@ function comment_post($edit) {
}
}
-function comment_score($comment) {
- $value = ($comment->votes) ? ($comment->score / $comment->votes) : (($comment->score) ? $comment->score : 0);
- return ((strpos($value, ".")) ? substr($value ."00", 0, 4) : $value .".00");
-}
-
function comment_num_replies($id, $count = 0) {
+
$result = db_query("SELECT COUNT(cid) FROM comments WHERE pid = '$id'");
return ($result) ? db_result($result, 0) : 0;
+
}
function comment_moderation($comment) {
- global $comment_votes, $op, $user;
+ global $user;
- if ($op == "reply") {
- // preview comment:
- $output .= "&nbsp;";
- }
- else if ($user->uid && $user->name != $comment->name && !field_get($comment->users, $user->uid)) {
- // comment hasn't been moderated yet:
- foreach ($comment_votes as $key=>$value) $options .= " <OPTION VALUE=\"$value\">$key</OPTION>\n";
- $output .= "<SELECT NAME=\"moderate[$comment->cid]\">$options</SELECT>\n";
- }
- else {
- // comment has already been moderated:
- $output .= "<TABLE BORDER=\"0\" CELLSPACING=\"1\" CELLPADDING=\"1\"><TR><TD ALIGN=\"right\">". t("score") .":</TD><TD>". check_output($comment->score) ."</TD></TR><TR><TD ALIGN=\"right\">". t("votes") .":</TD><TD>". check_output($comment->votes) ."</TD></TR></TABLE>\n";
+ $values = array("--", 1, 2, 3, 4, 5);
+
+ $moderate = db_fetch_object(db_query("SELECT * FROM moderate WHERE cid = '$comment->cid' AND uid = '$user->uid'"));
+
+ foreach ($values as $key => $value) {
+ $options .= " <option value=\"$key\"". ($moderate->score == $key ? " selected=\"selected\"" : "") .">$value</option>\n";
}
+ $output .= "<div align=\"center\">";
+ $output .= " <select name=\"moderate[comment][$comment->cid]\">$options</select><br />". ($comment->score ? $comment->score : "--") ." / $comment->votes";
+ $output .= "</div>";
+
return $output;
}
function comment_threshold($threshold) {
- for ($i = -1; $i < 6; $i++) $options .= " <OPTION VALUE=\"$i\"". ($threshold == $i ? " SELECTED" : "") .">". t("Filter") ." - $i</OPTION>";
- return "<SELECT NAME=\"threshold\">$options</SELECT>\n";
+ for ($i = 0; $i < 6; $i++) $options .= " <option value=\"$i\"". ($threshold == $i ? " SELECTED" : "") .">". t("Visibility") ." - $i</option>";
+ return "<select name=\"threshold\">$options</select>\n";
}
function comment_mode($mode) {
global $cmodes;
- foreach ($cmodes as $key=>$value) $options .= " <OPTION VALUE=\"$key\"". ($mode == $key ? " SELECTED" : "") .">$value</OPTION>\n";
- return "<SELECT NAME=\"mode\">$options</SELECT>\n";
+
+ foreach ($cmodes as $key=>$value) $options .= " <option value=\"$key\"". ($mode == $key ? " SELECTED" : "") .">$value</option>\n";
+ return "<select name=\"mode\">$options</select>\n";
}
function comment_order($order) {
global $corder;
- foreach ($corder as $key=>$value) $options .= " <OPTION VALUE=\"$key\"". ($order == $key ? " SELECTED" : "") .">$value</OPTION>\n";
- return "<SELECT NAME=\"order\">$options</SELECT>\n";
+
+ foreach ($corder as $key=>$value) $options .= " <option value=\"$key\"". ($order == $key ? " SELECTED" : "") .">$value</option>\n";
+ return "<select name=\"order\">$options</select>\n";
}
function comment_query($lid, $order, $pid = -1) {
- $query .= "SELECT u.*, c.* FROM comments c LEFT JOIN user u ON c.author = u.uid WHERE c.lid = '$lid'";
- if ($pid >= 0) $query .= " AND pid = '$pid'";
- if ($order == 1) $query .= " ORDER BY c.timestamp DESC";
- else if ($order == 2) $query .= " ORDER BY c.timestamp";
- else if ($order == 3) $query .= " ORDER BY c.score DESC";
- else if ($order == 4) $query .= " ORDER BY c.score";
+
+ $query .= "SELECT u.*, c.*, SUM(m.score) / COUNT(m.cid) AS score, COUNT(m.cid) AS votes FROM comments c LEFT JOIN user u ON c.author = u.uid LEFT JOIN moderate m ON c.cid = m.cid WHERE c.lid = '$lid'";
+
+ if ($pid >= 0) {
+ $query .= " AND pid = '$pid'";
+ }
+
+ $query .= " GROUP BY c.cid";
+
+ if ($order == 1) {
+ $query .= " ORDER BY c.timestamp DESC";
+ }
+ else if ($order == 2) {
+ $query .= " ORDER BY c.timestamp";
+ }
+ else if ($order == 3) {
+ $query .= " ORDER BY score DESC";
+ }
+ else if ($order == 4) {
+ $query .= " ORDER BY score";
+ }
+
return db_query($query);
-}
-function comment_visible($comment, $threshold = 0) {
- if ($comment->votes == 0 && $comment->score >= $threshold) return 1;
- else if ($comment->votes > 0 && $comment->score / $comment->votes >= $threshold) return 1;
- else return 0;
}
-function comment_uri($args = 0) {
- global $mod;
- if ($args) return ($mod) ? "module.php?mod=$mod;$args" : "node.php?$args";
- else return ($mod) ? "module.php?mod=$mod" : "node.php";
+function comment_visible($comment, $threshold = 0) {
+ if ($comment->votes == 0 || $comment->score >= $threshold) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
function comment_links($comment, $return = 1) {
global $theme;
- if ($return) return "<A HREF=\"". comment_uri("id=$comment->lid#$comment->cid") ."\"><FONT COLOR=\"$theme->type\">". t("return") ."</FONT></A> | <A HREF=\"". comment_uri("op=reply&id=$comment->lid&pid=$comment->cid") ."\"><FONT COLOR=\"$theme->type\">". t("reply to this comment") ."</FONT></A>";
- else return "<A HREF=\"". comment_uri("op=reply&id=$comment->lid&pid=$comment->cid") ."\"><FONT COLOR=\"$theme->type\">". t("reply to this comment") ."</FONT></A>";
+
+ if ($return) {
+ return "<a href=\"node.php?id=$comment->lid#$comment->cid\"><font color=\"$theme->type\">". t("return") ."</font></a> | <a href=\"node.php?op=reply&id=$comment->lid&pid=$comment->cid\"><font color=\"$theme->type\">". t("reply to this comment") ."</font></a>";
+ }
+ else {
+ return "<a href=\"node.php?op=reply&id=$comment->lid&pid=$comment->cid\"><font color=\"$theme->type\">". t("reply to this comment") ."</font></a>";
+ }
}
function comment_view($comment, $folded = 0) {
global $theme;
- // calculate comment's score:
- $comment->score = comment_score($comment);
-
- // display comment:
- if ($folded) $theme->comment($comment, $folded);
- else print "<A HREF=\"". comment_uri("id=$comment->lid&cid=$comment->cid#$comment->cid") ."\">". check_output($comment->subject) ."</A> by ". format_name($comment) ." <SMALL>($comment->score)</SMALL><P>";
+ if ($folded) {
+ $theme->comment($comment, $folded);
+ }
+ else {
+ print "<a href=\"node.php?id=$comment->lid&cid=$comment->cid#$comment->cid\">". check_output($comment->subject) ."</a> by ". format_name($comment) ." <small>(". ($comment->score ? $comment->score : "--") ." / $comment->votes)</small><p />";
+ }
}
function comment_thread_min($cid, $threshold) {
global $user;
- $result = db_query("SELECT u.*, c.* FROM comments c LEFT JOIN user u ON c.author = u.uid WHERE c.pid = '$cid' ORDER BY c.timestamp, c.cid");
+ $result = db_query("SELECT u.*, c.*, SUM(m.score) / COUNT(m.cid) AS score, COUNT(m.cid) AS votes FROM comments c LEFT JOIN user u ON c.author = u.uid LEFT JOIN moderate m ON c.cid = m.cid WHERE c.pid = '$cid' GROUP BY c.cid ORDER BY c.timestamp, c.cid");
while ($comment = db_fetch_object($result)) {
print "<ul>";
@@ -239,15 +251,15 @@ function comment_thread_max($cid, $mode, $threshold, $level = 0, $dummy = 0) {
global $user;
/*
- ** We had quite a few browser specific issues with expanded comments below
- ** the top level getting truncated on the right hand side. A range of
- ** solutions have been suggested and tried but either the right margins of
- ** the comments didn't line up as well, or the heavily nested tables made
- ** for slow rendering and cluttered HTML. This is the best work-around in
- ** terms of speed and size.
+ ** We had quite a few browser specific issues: expanded comments below
+ ** the top level got truncated on the right hand side. A range of
+ ** solutions have been proposed and tried but either the right margins of
+ ** the comments didn't line up well, or the heavily nested tables made
+ ** for slow rendering and cluttered HTML. This is the best work-around
+ ** in terms of speed and size.
*/
- $result = db_query("SELECT u.*, c.* FROM comments c LEFT JOIN user u ON c.author = u.uid WHERE c.pid = '$cid' ORDER BY c.timestamp, c.cid");
+ $result = db_query("SELECT u.*, c.*, SUM(m.score) / COUNT(m.cid) AS score, COUNT(m.cid) AS votes FROM comments c LEFT JOIN user u ON c.author = u.uid LEFT JOIN moderate m ON c.cid = m.cid WHERE c.pid = '$cid' GROUP BY c.cid ORDER BY c.timestamp, c.cid");
while ($comment = db_fetch_object($result)) {
print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td width=\"". ($level * 25) ."\">&nbsp;</td><td>\n";
@@ -265,7 +277,7 @@ function comment_render($lid, $cid) {
if (user_access("access comments")) {
/*
- ** pre-process variables:
+ ** Pre-process variables:
*/
if (empty($lid)) {
@@ -273,7 +285,7 @@ function comment_render($lid, $cid) {
}
if (empty($cid)) {
- $cide = 0;
+ $cid = 0;
}
if (empty($mode)) {
@@ -288,19 +300,17 @@ function comment_render($lid, $cid) {
$threshold = $user->uid ? $user->threshold : variable_get(default_comment_threshold, 3);
}
+ print "<form method=\"post\" action=\"$REQUEST_URI\">\n";
+ // print " <INPUT TYPE=\"hidden\" NAME=\"id\" value=\"$lid\">\n";
+
/*
- ** Render comment control:
+ ** Render control panel:
*/
- $theme->box(t("Comment control"), $theme->comment_controls($threshold, $mode, $order));
-
- if ($user->uid) {
- // Print moderation form:
- print "<FORM METHOD=\"post\" ACTION=\"$REQUEST_URI\">\n";
- }
+ $theme->box(t("Control panel"), $theme->comment_controls($threshold, $mode, $order));
if ($cid > 0) {
- $result = db_query("SELECT u.*, c.* FROM comments c LEFT JOIN user u ON c.author = u.uid WHERE cid = '$cid'");
+ $result = db_query("SELECT u.*, c.*, SUM(m.score) / COUNT(m.cid) AS score, COUNT(m.cid) AS votes FROM comments c LEFT JOIN user u ON c.author = u.uid LEFT JOIN moderate m ON c.cid = m.cid WHERE c.cid = '$cid' GROUP BY c.cid");
if ($comment = db_fetch_object($result)) {
comment_view($comment, comment_links($comment));
}
@@ -308,14 +318,14 @@ function comment_render($lid, $cid) {
else {
if ($mode == 1) {
$result = comment_query($lid, $order);
- print "<TABLE BORDER=\"0\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
- print " <TR><TH>Subject</TH><TH>Author</TH><TH>Date</TH><TH>Score</TH></TR>\n";
+ print "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n";
+ print " <tr><th>Subject</th><th>Author</th><th>Date</th><th>Score</th></tr>\n";
while ($comment = db_fetch_object($result)) {
if (comment_visible($comment, $threshold)) {
- print " <TR><TD><A HREF=\"". comment_uri("id=$comment->lid&cid=$comment->cid#$comment->cid") ."\">". check_output($comment->subject) ."</A></TD><TD>". format_name($comment) ."</TD><TD>". format_date($comment->timestamp, "small") ."</TD><TD>". comment_score($comment) ."</TD></TR>\n";
+ print " <tr><td><a href=\"node.php?id=$comment->lid&cid=$comment->cid#$comment->cid\">". check_output($comment->subject) ."</a></td><td>". format_name($comment) ."</td><td>". format_date($comment->timestamp, "small") ."</td><td>$comment->score</td></tr>\n";
}
}
- print "</TABLE>\n";
+ print "</table>\n";
}
else if ($mode == 2) {
$result = comment_query($lid, $order);
@@ -339,12 +349,8 @@ function comment_render($lid, $cid) {
}
}
- if ($user->uid) {
- // Print moderation form:
- print " <INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$lid\">\n";
- print " <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Moderate comments") ."\">\n";
- print "</FORM>\n";
- }
+ print "</form>";
+
}
}