From 801db51a1c29b2bd324404a31125b8be465f5bfd Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Fri, 13 Oct 2000 10:17:30 +0000 Subject: * removed poll.php - it's totally outdated. * fixed 2 bugs in the discussion forum. --- discussion.php | 61 ++++++++++++++++++++++++---------------------------------- 1 file changed, 25 insertions(+), 36 deletions(-) (limited to 'discussion.php') diff --git a/discussion.php b/discussion.php index 79e48d0dc..1a06b0426 100644 --- a/discussion.php +++ b/discussion.php @@ -8,25 +8,27 @@ function discussion_score($comment) { function discussion_moderate($moderate) { global $user, $comment_votes; - $na = $comment_votes[key($comment_votes)]; + if ($user->id && $moderate) { + $na = $comment_votes[key($comment_votes)]; - foreach ($moderate as $id=>$vote) { - if ($user->id && $vote != $comment_votes[$na] && !user_getHistory($user->history, "c$id")) { - ### Update the comment's score: - $result = db_query("UPDATE comments SET score = score $vote, votes = votes + 1 WHERE cid = $id"); + foreach ($moderate as $id=>$vote) { + if ($vote != $comment_votes[$na] && !user_getHistory($user->history, "c$id")) { + ### Update the comment's score: + $result = db_query("UPDATE comments SET score = score $vote, votes = votes + 1 WHERE cid = $id"); - ### Update the user's history: - user_setHistory($user, "c$id", $vote); + ### Update the user's history: + user_setHistory($user, "c$id", $vote); + } } } } -function discussion_kids($cid, $mode, $level = 0, $dummy = 0) { +function discussion_kids($cid, $mode, $thold, $level = 0, $dummy = 0) { global $user, $theme; $comments = 0; - $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"); + $result = db_query("SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.pid = $cid AND (c.votes = 0 OR c.score / c.votes >= $thold) ORDER BY c.timestamp, c.cid"); if ($mode == "nested") { while ($comment = db_fetch_object($result)) { @@ -37,33 +39,30 @@ function discussion_kids($cid, $mode, $level = 0, $dummy = 0) { $link = "sid&pid=$comment->cid\">hlcolor2\">reply to this comment"; $theme->comment($comment->userid, stripslashes($comment->subject), stripslashes($comment->comment), $comment->timestamp, stripslashes($comment->url), stripslashes($comment->femail), discussion_score($comment), $comment->votes, $comment->cid, $link); - discussion_kids($comment->cid, $mode, $level + 1, $dummy + 1); + discussion_kids($comment->cid, $mode, $thold, $level + 1, $dummy + 1); } } } - elseif ($mode == "flat") { + else { // mode == 'flat' while ($comment = db_fetch_object($result)) { if ($comment->score >= $thold) { $link = "sid&pid=$comment->cid\">hlcolor2\">reply to this comment"; $theme->comment($comment->userid, check_output($comment->subject), check_output($comment->comment), $comment->timestamp, $comment->url, $comment->femail, discussion_score($comment), $comment->votes, $comment->cid, $link); } - discussion_kids($comment->cid, $mode); + discussion_kids($comment->cid, $mode, $thold); } } - else { - print "ERROR: we should not get here!"; - } if ($level && $comments) { print ""; } } -function discussion_childs($cid, $level = 0, $thread) { +function discussion_childs($cid, $thold, $level = 0, $thread) { global $theme, $user; ### Perform SQL query: - $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"); + $result = db_query("SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.pid = $cid AND (c.votes = 0 OR c.score / c.votes >= $thold) ORDER BY c.timestamp, c.cid"); if ($level == 0) $thread = ""; $comments = 0; @@ -79,7 +78,7 @@ function discussion_childs($cid, $level = 0, $thread) { $thread .= "
  • sid&cid=$comment->cid&pid=$comment->pid\">". check_output($comment->subject) ." by ". format_username($comment->userid) ." (". discussion_score($comment) .")
  • "; ### Recursive: - discussion_childs($comment->cid, $level + 1, &$thread); + discussion_childs($comment->cid, $thold, $level + 1, &$thread); } if ($level && $comments) { @@ -113,27 +112,17 @@ function discussion_display($sid, $pid, $cid, $level = 0) { $story = db_fetch_object($result); ### Display story: - if ($story->status == 1) { - $theme->article($story, "[ hlcolor2\">submission queue | id&pid=0\">hlcolor2\">add a comment ]"); - } - else { - $theme->article($story, "[ hlcolor2\">home | id&pid=0\">hlcolor2\">add a comment ]"); - } + if ($story->status == 1) $theme->article($story, "[ hlcolor2\">submission queue | id&pid=0\">hlcolor2\">add a comment ]"); + else $theme->article($story, "[ hlcolor2\">home | id&pid=0\">hlcolor2\">add a comment ]"); ### Display `comment control'-box: - if ($user->id) { - $theme->commentControl($sid, $title, $thold, $mode, $order); - } + if ($user->id) $theme->commentControl($sid, $title, $thold, $mode, $order); ### Compose query: - $query = "SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.sid = $sid AND c.pid = $pid"; - if ($mode == 'threaded' || mode == 'nested') { - if ($thold != "") $query .= " AND c.score >= $thold"; - else $query .= " AND c.score >= 0"; - } + $query .= "SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.sid = $sid AND c.pid = $pid AND (c.votes = 0 OR c.score / c.votes >= $thold)"; if ($order == 1) $query .= " ORDER BY c.timestamp DESC"; if ($order == 2) $query .= " ORDER BY c.score DESC"; - $result = db_query("$query"); + $result = db_query($query); print "
    \n"; @@ -141,7 +130,7 @@ function discussion_display($sid, $pid, $cid, $level = 0) { while ($comment = db_fetch_object($result)) { ### Dynamically compose the `reply'-link: if ($pid != 0) { - list($pid) = mysql_fetch_row(mysql_query("SELECT pid FROM comments WHERE cid = $comment->pid")); + list($pid) = db_fetch_row(db_query("SELECT pid FROM comments WHERE cid = $comment->pid")); $link = "sid&pid=$pid\">hlcolor2\">return to parent | sid&pid=$comment->cid\">hlcolor2\">reply to this comment"; } else { @@ -150,12 +139,12 @@ function discussion_display($sid, $pid, $cid, $level = 0) { ### Display the comments: if (empty($mode) || $mode == "threaded") { - $thread = discussion_childs($comment->cid); + $thread = discussion_childs($comment->cid, $thold); $theme->comment($comment->userid, check_output($comment->subject), check_output($comment->comment), $comment->timestamp, $comment->url, $comment->femail, discussion_score($comment), $comment->votes, $comment->cid, $link, $thread); } else { $theme->comment($comment->userid, check_output($comment->subject), check_output($comment->comment), $comment->timestamp, $comment->url, $comment->femail, discussion_score($comment), $comment->votes, $comment->cid, $link); - discussion_kids($comment->cid, $mode, $level); + discussion_kids($comment->cid, $mode, $thold, $level); } } -- cgit v1.2.3