From b1c66cb5de4b37a5292c6901628b5b0697e8a459 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Mon, 16 Apr 2001 18:21:22 +0000 Subject: Another big update so please read this carefully because there is important information hidden in it. Made it so that we can disable/enable comments on a category by category basis. In order to accomplish this I had to make a few (*temporary*) changes. I moved all comment code from the "module level" (eg. story.module) to the "node level". It was nothing but the logical next step in nodifying drupal. This enables us to add comments to all existing content types including book entries. But also for book entries, this to can be toggled on and off. :-) Moreover module writers don't have to worry about the complex comment logic: it is "abstracted" away. This implies that story.module got smaller, faster and easier to comprehend. :-) In order to accomplish this, I had to update ALL THEMES, which I did - and on my way I updated Goofy, Oranzh and UnConeD - with the previous changes. All themes are up-to-date now! I also had to remove the [ reply to this story ] links, and temporally re-introcuded the "Add comment" button in the "Comment control". Tempora lly that is, UnConeD. ;) I plan to upgrade drop.org either tommorow or wednesday so test away if you have some time to kill. ;) Oh, I also fixed a few bugs and made various small improvements. --- includes/comment.inc | 14 ++++++++------ includes/node.inc | 8 ++++---- includes/structure.inc | 12 ++++++------ includes/variable.inc | 9 ++++++--- 4 files changed, 24 insertions(+), 19 deletions(-) (limited to 'includes') diff --git a/includes/comment.inc b/includes/comment.inc index 1a25c11c2..0d1003530 100644 --- a/includes/comment.inc +++ b/includes/comment.inc @@ -32,10 +32,10 @@ function comment_moderate($moderate) { foreach ($moderate as $id=>$vote) { if ($vote != $comment_votes[$none] && !user_get($user, "history", "c$id")) { - // Update the comment's score: + // update the comment's score: $result = db_query("UPDATE comments SET score = score ". check_input($vote) .", votes = votes + 1 WHERE cid = '". check_input($id) ."'"); - // Update the user's history: + // update the user's history: $user = user_set($user, "history", "c$id", $vote); } } @@ -124,22 +124,23 @@ function comment_preview($pid, $id, $subject, $comment) { function comment_post($pid, $id, $subject, $comment) { global $theme, $user; + // check comment submission rate: throttle("post comment", variable_get(max_comment_rate, 60)); - // Check for duplicate comments: + // check for duplicate comments: $duplicate = db_result(db_query("SELECT COUNT(cid) FROM comments WHERE pid = '$pid' AND lid = '$id' AND subject = '$subject' AND comment = '$comment'"), 0); if ($duplicate != 0) { watchdog("warning", "comment: duplicate '$subject'"); } else { - // Validate subject: + // validate subject: $subject = ($subject) ? $subject : substr($comment, 0, 29); - // Add watchdog entry: + // add watchdog entry: watchdog("special", "comment: added '$subject'"); - // Add comment to database: + // add comment to database: db_query("INSERT INTO comments (lid, pid, author, subject, comment, hostname, timestamp, score) VALUES ('$id', '$pid', '$user->id', '$subject', '$comment', '". getenv("REMOTE_ADDR") ."', '". time() ."', '". ($user->userid ? 1 : 0) ."')"); } } @@ -191,6 +192,7 @@ function comment_controls($threshold = 1, $mode = 3, $order = 1) { $output .= comment_order(($user->id ? $user->sort : $order)); $output .= comment_threshold(($user->id ? $user->threshold : $threshold)); $output .= "\n"; + $output .= "\n"; $output .= "\n"; return $output; } diff --git a/includes/node.inc b/includes/node.inc index 9fc42a120..9a8b9f020 100644 --- a/includes/node.inc +++ b/includes/node.inc @@ -6,7 +6,7 @@ $rstatus = array(0 => dumped, 1 => expired, 2 => queued, 3 => posted); function _node_get($field, $value) { $result = db_query("SELECT lid, type FROM node WHERE $field = '$value'"); if ($node = db_fetch_object($result)) { - return db_query("SELECT n.*, l.*, c.name AS category, t.name AS topic, u.userid FROM node n LEFT JOIN $node->type l ON n.lid = l.lid AND n.nid = l.nid LEFT JOIN users u ON n.author = u.id LEFT JOIN category c ON n.cid = c.cid LEFT JOIN topic t ON n.tid = t.tid WHERE n.$field = '$value' ORDER BY n.timestamp DESC"); + return db_query("SELECT n.*, l.*, c.name AS category, c.comment, t.name AS topic, u.userid FROM node n LEFT JOIN $node->type l ON n.lid = l.lid AND n.nid = l.nid LEFT JOIN users u ON n.author = u.id LEFT JOIN category c ON n.cid = c.cid LEFT JOIN topic t ON n.tid = t.tid WHERE n.$field = '$value' ORDER BY n.timestamp DESC"); } } @@ -131,11 +131,11 @@ function node_save($node) { function node_invoke($node, $name, $arg = 0) { if ($node[type]) $function = $node[type] ."_$name"; if ($node->type) $function = $node->type ."_$name"; - if ($function) return ($arg ? $function($node) : $function($node, $arg)); + if ($function) return ($arg ? $function($node, $arg) : $function($node)); } -function node_view($node, $page = 0) { - return node_invoke($node, "view", $page); +function node_view($node, $main = 0) { + return node_invoke($node, "view", $main); } function node_form($node) { diff --git a/includes/structure.inc b/includes/structure.inc index 4326e092e..ff05b36d2 100644 --- a/includes/structure.inc +++ b/includes/structure.inc @@ -28,19 +28,19 @@ function category_del($cid) { db_query("UPDATE node SET cid = 0 WHERE cid = '". check_input($cid) ."'"); } -function category_post_threshold($cid, $default) { +function category_post_threshold($cid) { $category = db_fetch_object(db_query("SELECT post AS threshold FROM category WHERE cid = '". check_input($cid) ."'")); - return $category->threshold ? $category->threshold : $default; + return $category->threshold; } -function category_dump_threshold($cid, $default) { +function category_dump_threshold($cid) { $category = db_fetch_object(db_query("SELECT dump AS threshold FROM category WHERE cid = '". check_input($cid) ."'")); - return $category->threshold ? $category->threshold : $default; + return $category->threshold; } -function category_expire_threshold($cid, $default) { +function category_expire_threshold($cid) { $category = db_fetch_object(db_query("SELECT expire AS threshold FROM category WHERE cid = '". check_input($cid) ."'")); - return $category->threshold ? $category->threshold : $default; + return $category->threshold; } function category_form_select($type, $edit = array(), $size = 1) { diff --git a/includes/variable.inc b/includes/variable.inc index 083f7d492..fa389e511 100644 --- a/includes/variable.inc +++ b/includes/variable.inc @@ -7,15 +7,18 @@ function variable_init($conf = array()) { } function handler_post_threshold($node, $default) { - return ($threshold = category_post_threshold($node->cid) ? $threshold : $default); + $threshold = category_post_threshold($node->cid); + return $threshold ? $threshold : $default; } function handler_dump_threshold($node, $default) { - return ($threshold = category_dump_threshold($node->cid) ? $threshold : $default); + $threshold = category_dump_threshold($node->cid); + return $threshold ? $threshold : $default; } function handler_expire_threshold($node, $default) { - return ($threshold = category_expire_threshold($node->cid) ? $threshold : $default); + $threshold = category_expire_threshold($node->cid); + return $threshold ? $threshold : $default; } function variable_get($name, $default, $object = 0) { -- cgit v1.2.3