From fe095f5a24baef737f425591770819ac6260778f Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 24 Mar 2001 16:46:11 +0000 Subject: - simplified the comment code: the SQL queries are less complex, thus faster now. --- includes/comment.inc | 53 +++++++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 30 deletions(-) (limited to 'includes') diff --git a/includes/comment.inc b/includes/comment.inc index eb66919c4..c775be98f 100644 --- a/includes/comment.inc +++ b/includes/comment.inc @@ -8,7 +8,6 @@ if (strstr($id, " ") || strstr($pid, " ") || strstr($lid, " ") || strstr($mode, $cmodes = array(1 => "List - min", 2 => "List - max", 3 => "Threaded - min", 4 => "Threaded - max"); $corder = array(1 => "Date - new", 2 => "Date - old", 3 => "Rate - high", 4 => "Rate - low"); -$link = ($mod) ? $mod : substr(strrchr($PHP_SELF, "/"), 1, strrchr($PHP_SELF, "/") - 4); class Comment { function Comment($userid, $subject, $comment, $timestamp, $url, $fake_email, $score, $votes, $cid, $lid) { @@ -49,19 +48,13 @@ function comment_settings($mode, $order, $threshold) { } function comment_reply($pid, $id) { - global $allowed_html, $link, $REQUEST_URI, $theme, $user; + global $allowed_html, $REQUEST_URI, $theme, $user; if ($pid) { $item = db_fetch_object(db_query("SELECT comments.*, users.userid FROM comments LEFT JOIN users ON comments.author = users.id WHERE comments.cid = '$pid'")); comment_view(new Comment($item->userid, $item->subject, $item->comment, $item->timestamp, $item->url, $item->fake_email, comment_score($comment), $comment->votes, $item->cid, $item->lid), t("reply to this comment")); } - else { - $pid = 0; - if ($link == "story") { - $item = db_fetch_object(db_query("SELECT stories.*, users.userid FROM stories LEFT JOIN users ON stories.author = users.id WHERE stories.status != 0 AND stories.id = '$id'")); - $theme->story($item, "[ ". t("reply to this story") ." ]"); - } - } + else $pid = 0; // Build reply form: $output .= "
\n"; @@ -91,7 +84,7 @@ function comment_reply($pid, $id) { } function comment_preview($pid, $id, $subject, $comment) { - global $allowed_html, $link, $REQUEST_URI, $theme, $user; + global $allowed_html, $REQUEST_URI, $theme, $user; // Preview comment: comment_view(new Comment($user->userid, $subject, $comment, time(), $user->url, $user->fake_email, 0, 0, 0, 0), t("reply to this comment")); @@ -129,10 +122,10 @@ function comment_preview($pid, $id, $subject, $comment) { } function comment_post($pid, $id, $subject, $comment) { - global $theme, $link, $user; + global $theme, $user; // Check for duplicate comments: - $duplicate = db_result(db_query("SELECT COUNT(cid) FROM comments WHERE link = '$link' AND pid = '$pid' AND lid = '$id' AND subject = '$subject' AND comment = '$comment'"), 0); + $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("error", "comment: attempt to insert duplicate comment"); @@ -145,7 +138,7 @@ function comment_post($pid, $id, $subject, $comment) { watchdog("comment", "comment: added comment with subject '$subject'"); // Add comment to database: - db_query("INSERT INTO comments (link, lid, pid, author, subject, comment, hostname, timestamp, score) VALUES ('$link', '$id', '$pid', '$user->id', '$subject', '$comment', '". getenv("REMOTE_ADDR") ."', '". time() ."', '". ($user->userid ? 1 : 0) ."')"); + 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) ."')"); } } @@ -219,8 +212,8 @@ function comment_order($order) { return "\n"; } -function comment_query($link, $lid, $order, $pid = -1) { - $query .= "SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id WHERE link = '$link' AND c.lid = '$lid'"; +function comment_query($lid, $order, $pid = -1) { + $query .= "SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id 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"; @@ -236,19 +229,19 @@ function comment_visible($comment, $threshold = 0) { } function comment_uri($args = 0) { - global $link, $mod; - if ($args) return ($mod) ? "module.php?mod=$mod&$args" : $link .".php?$args"; - else return ($mod) ? "module.php?mod=$mod" : $link .".php"; + 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_link($comment, $return = 1) { - global $link, $theme; - if ($return) return "lid#$comment->cid") ."\">link\">". t("return") ." | lid&pid=$comment->cid") ."\">link\">". t("reply to this comment") .""; - else return "lid&pid=$comment->cid") ."\">link\">". t("reply to this comment") .""; + 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") .""; } function comment_view($comment, $folded = 0) { - global $link, $theme; + global $theme; // calculate comment's score: $comment->score = comment_score($comment); @@ -272,9 +265,9 @@ function comment_thread_min($cid, $threshold) { } function comment_thread_max($cid, $mode, $threshold, $level = 0, $dummy = 0) { - global $link, $user; + global $user; - $result = db_query("SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id WHERE link = '$link' AND c.pid = '$cid' ORDER BY c.timestamp, c.cid"); + $result = db_query("SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.pid = '$cid' ORDER BY c.timestamp, c.cid"); print "