From 4a0e498f52106b29d4adae0aaf7e1a6d55f8fd68 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Thu, 27 Sep 2001 20:51:26 +0000 Subject: - a batch of updates, including some experimental changes to the moderation of comments and nodes. --- includes/comment.inc | 186 ++++---- includes/conf.php | 16 - includes/node.inc | 10 +- includes/theme.inc | 22 +- includes/xmlrpc.inc | 1236 +++++++++++++++++++++++++------------------------- includes/xmlrpcs.inc | 434 +++++++++--------- 6 files changed, 950 insertions(+), 954 deletions(-) (limited to 'includes') 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 .= " "; - } - 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 .= " \n"; - $output .= "\n"; - } - else { - // comment has already been moderated: - $output .= "
". t("score") .":". check_output($comment->score) ."
". t("votes") .":". check_output($comment->votes) ."
\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 .= " \n"; } + $output .= "
"; + $output .= "
". ($comment->score ? $comment->score : "--") ." / $comment->votes"; + $output .= "
"; + return $output; } function comment_threshold($threshold) { - for ($i = -1; $i < 6; $i++) $options .= " "; - return "\n"; + for ($i = 0; $i < 6; $i++) $options .= " "; + return "\n"; } function comment_mode($mode) { global $cmodes; - foreach ($cmodes as $key=>$value) $options .= " \n"; - return "\n"; + + foreach ($cmodes as $key=>$value) $options .= " \n"; + return "\n"; } function comment_order($order) { global $corder; - foreach ($corder as $key=>$value) $options .= " \n"; - return "\n"; + + foreach ($corder as $key=>$value) $options .= " \n"; + return "\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 "lid#$comment->cid") ."\">type\">". t("return") ." | lid&pid=$comment->cid") ."\">type\">". t("reply to this comment") .""; - else return "lid&pid=$comment->cid") ."\">type\">". t("reply to this comment") .""; + + if ($return) { + return "lid#$comment->cid\">type\">". t("return") ." | lid&pid=$comment->cid\">type\">". t("reply to this comment") .""; + } + else { + return "lid&pid=$comment->cid\">type\">". t("reply to this comment") .""; + } } 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 "lid&cid=$comment->cid#$comment->cid") ."\">". check_output($comment->subject) ." by ". format_name($comment) ." ($comment->score)

"; + if ($folded) { + $theme->comment($comment, $folded); + } + else { + print "lid&cid=$comment->cid#$comment->cid\">". check_output($comment->subject) ." by ". format_name($comment) ." (". ($comment->score ? $comment->score : "--") ." / $comment->votes)

"; + } } 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 "