From 4e132c9fd5ee53b5ad7317de6899f1ea2207ab09 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Thu, 6 Jul 2000 09:37:30 +0000 Subject: [PATCH] * _Major_ update of the comments and moderation system: it's a lot more stream-lined and more compact. There are a few parts I like to optimize prior to heading towards comment moderation. Please test, report bugs and update the footer()-part of your themes a bit (see my theme)!!! -- Dries --- article.php | 21 ---- comments.php | 302 ------------------------------------------------- database.inc | 4 - functions.inc | 37 ++++-- search.php | 4 +- submission.inc | 9 +- submission.php | 47 ++++---- 7 files changed, 62 insertions(+), 362 deletions(-) delete mode 100644 article.php delete mode 100644 comments.php diff --git a/article.php b/article.php deleted file mode 100644 index 63c2277f409..00000000000 --- a/article.php +++ /dev/null @@ -1,21 +0,0 @@ -id'"); - $user->rehash(); - } - - if ($op == "reply") Header("Location: comments.php?op=reply&pid=0&sid=$sid&mode=$mode&order=$order&thold=$thold"); - - $result = db_query("SELECT stories.*, users.userid FROM stories LEFT JOIN users ON stories.author = users.id WHERE stories.status = 2 AND stories.id = $id"); - $story = db_fetch_object($result); - - $theme->header(); - $theme->article($story, "[ hlcolor2\">home | id\">hlcolor2\">add a comment ]"); - include "comments.php"; - $theme->footer(); -?> \ No newline at end of file diff --git a/comments.php b/comments.php deleted file mode 100644 index de7e66ba11b..00000000000 --- a/comments.php +++ /dev/null @@ -1,302 +0,0 @@ -score >= $thold) { - if ($level && !$comments) print ""; - } -} - -function comments_childs($cid, $mode, $order, $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"); - - if ($level == 0) $thread = ""; - $comments = 0; - - while ($comment = db_fetch_object($result)) { - if ($level && !$comments) { - $thread .= ""; - } - - return $thread; -} - -function comments_display ($sid = 0, $pid = 0, $cid = 0, $mode = "threaded", $order = 0, $thold = 0, $level = 0, $nokids = 0) { - global $user, $theme; - - ### Display `comment control'-box: - $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 score >= $thold"; - else $query .= " AND score >= 0"; - } - if ($order == 1) $query .= " ORDER BY timestamp DESC"; - if ($order == 2) $query .= " ORDER BY score DESC"; - $result = db_query("$query"); - - ### Display the comments: - 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")); - $link = "sid&mode=$mode&order=$order&thold=$thold\">hlcolor2\">return to parent | cid&sid=$comment->sid&mode=$mode&order=$order&thold=$thold\">hlcolor2\">reply to this comment"; - } - else { - $link = "cid&sid=$comment->sid&mode=$mode&order=$order&thold=$thold\">hlcolor2\">reply to this comment "; - } - - ### Display the comments: - if ($mode == "threaded") { - $thread = comments_childs($comment->cid, $mode, $order, $thold); - $theme->comment($comment->userid, $comment->subject, $comment->comment, $comment->timestamp, $comment->url, $comment->femail, $comment->score, $comment->cid, $link, $thread); - } - else { - $theme->comment($comment->userid, $comment->subject, $comment->comment, $comment->timestamp, $comment->url, $comment->femail, $comment->score, $comment->cid, $link); - comments_kids($comment->cid, $mode, $order, $thold, $level); - } - } -} - -function comments_reply($pid, $sid, $mode, $order, $thold) { - global $user, $theme; - - ### Extract parent-information/data: - 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")); - $theme->comment($item->userid, $item->subject, $item->comment, $item->timestamp, $item->url, $item->femail, $item->score, $item->cid, "reply to this comment"); - } - else { - $item = db_fetch_object(db_query("SELECT stories.*, users.userid FROM stories LEFT JOIN users ON stories.author = users.id WHERE stories.status = 2 AND stories.id = $sid")); - $theme->article($item, ""); - } - - ### Build reply form: - $output .= "
\n"; - - ### Name field: - if ($user) { - $output .= "

\n"; - $output .= " Your name:
\n"; - $output .= " $user->userid     [ logout ]\n"; - $output .= "

\n"; - } - else { - $output .= "

\n"; - $output .= " Your name:
\n"; - $output .= " $anonymous\n"; - $output .= "

\n"; - } - - ### Subject field: - $output .= "

\n"; - $output .= " Subject:
\n"; - if (!eregi("Re:",$item->subject)) $item->subject = "Re: $item->subject"; - // Only one 'Re:' will just do fine. ;) - $output .= " subject\">\n"; - $output .= "

\n"; - - ### Comment field: - $output .= "

\n"; - $output .= " Comment:
\n"; - $output .= "
\n"; - $output .= "

\n"; - - ### Hidden fields: - $output .= "\n"; - $output .= "\n"; - $output .= "\n"; - $output .= "\n"; - $output .= "\n"; - - ### Preview button: - $output .= " (You must preview at least once before you can submit.)\n"; - $output .= "
\n"; - - $theme->box("Reply", $output); -} - -function comment_preview($pid, $sid, $subject, $comment, $mode, $order, $thold) { - global $user, $theme; - - ### Preview comment: - if ($user) $theme->comment("", $subject, $comment, time(), "", "", "na", "", "reply to this comment"); - else $theme->comment($user->userid, $subject, $comment, time(), $user->url, $user->femail, "na", "", "reply to this comment"); - - ### Build reply form: - $output .= "
\n"; - - ### Name field: - if ($user) { - $output .= "

\n"; - $output .= " Your name:
\n"; - $output .= " $user->userid     [ logout ]\n"; - $output .= "

\n"; - } - else { - $output .= "

\n"; - $output .= " Your name:
\n"; - $output .= " $anonymous\n"; - $output .= "

\n"; - } - - ### Subject field: - $output .= "

\n"; - $output .= " Subject:
\n"; - $output .= " \n"; - $output .= "

\n"; - - ### Comment field: - $output .= "

\n"; - $output .= " Comment:
\n"; - $output .= "
\n"; - $output .= "

\n"; - - ### Hidden fields: - $output .= "\n"; - $output .= "\n"; - $output .= "\n"; - $output .= "\n"; - $output .= "\n"; - - ### Preview and submit buttons: - if (empty($subject)) { - $output .= "

\n"; - $output .= " Warning: you did not supply a subject.\n"; - $outout .= "

\n"; - $output .= "

\n"; - $output .= " \n"; - $output .= "

\n"; - } - else { - $output .= "\n"; - $output .= "\n"; - $output .= "
\n"; - } - - $theme->box("Reply", $output); -} - -function comment_post($pid, $sid, $subject, $comment, $mode, $order, $thold) { - global $user, $theme; - - ### Check for fake threads: - $fake = db_result(db_query("SELECT COUNT(*) FROM stories WHERE id = $sid"), 0); - - ### Check for duplicate comments: - $duplicate = db_result(db_query("SELECT COUNT(*) FROM comments WHERE pid = '$pid' AND sid = '$sid' AND subject = '". addslashes($subject) ."' AND comment = '". addslashes($comment) ."'"), 0); - - if ($fake != 1) { - $theme->box("fake comment", "fake comment: $fake"); - } - elseif ($duplicate != 0) { - $theme->box("duplicate comment", "duplicate comment: $duplicate"); - } - else { - if ($user) { - ### Add comment to database: - db_query("INSERT INTO comments (pid, sid, author, subject, comment, hostname, timestamp) VALUES ($pid, $sid, $user->id, '". addslashes($subject) ."', '". addslashes($comment) ."', '". getenv("REMOTE_ADDR") ."', '". time() ."')"); - - ### Compose header: - $header = "article.php?id=$sid"; - $header .= ($mode) ? "&mode=$mode" : "&mode=threaded"; - $header .= ($order) ? "&order=$order" : "&order=0"; - $header .= ($thold) ? "&thold=$thold" : "&thold=0"; - } - else { - ### Add comment to database: - db_query("INSERT INTO comments (pid, sid, subject, comment, hostname, timestamp) VALUES ($pid, $sid, '". addslashes($subject) ."', '". addslashes($comment) ."', '". getenv("REMOTE_ADDR") ."', '". time() ."')"); - - ### Compose header: - $header .= "article.php?id=$sid&mode=threaded&order=1&thold=0"; - } - header("Location: $header"); - } -} - -if (strstr($PHP_SELF, "comments.php")) { - include "theme.inc"; - include "functions.inc"; -} - -switch($op) { - case "Preview comment": - $theme->header(); - comment_preview($pid, $sid, $subject, $comment, $mode, $order, $thold); - $theme->footer(); - break; - case "Post comment": - comment_post($pid, $sid, $subject, $comment, $mode, $order, $thold); - break; - case "reply": - $theme->header(); - comments_reply($pid, $sid, $mode, $order, $thold); - $theme->footer(); - break; - case "show": - $theme->header(); - comments_display($sid, $pid, $cid, $mode, $order, $thold); - $theme->footer(); - break; - default: - comments_display($id, 0, 0, $mode, $order, $thold); -} - -?> \ No newline at end of file diff --git a/database.inc b/database.inc index 83da9e602c0..4311873b183 100644 --- a/database.inc +++ b/database.inc @@ -7,10 +7,6 @@ * just adjust the handlers to your needs. */ -/////////////////////////////////////////////////////////////////////////// -// NOTE: these functions are under construction and in no way finilized! // -/////////////////////////////////////////////////////////////////////////// - function db_connect() { include "config.inc"; mysql_pconnect($dbhost, $dbuname, $dbpass) or die(mysql_Error()); diff --git a/functions.inc b/functions.inc index e118e98c558..fde0bc37c1d 100644 --- a/functions.inc +++ b/functions.inc @@ -30,13 +30,13 @@ function morelink_bytes($theme, $story) { ### Compose more-link: $morelink = "[ "; if ($story->article) { - $morelink .= "id"; + $morelink .= "id"; $morelink .= ($user->umode) ? "&mode=$user->umode" : "&mode=threaded"; $morelink .= ($user->uorder) ? "&order=$user->uorder" : "&order=0"; $morelink .= ($user->thold) ? "&thold=$user->thold" : "&thold=0"; $morelink .= "\">hlcolor2\">read more | $bytes bytes in body | "; } - $morelink .= "id"; + $morelink .= "id"; $morelink .= ($user->umode) ? "&mode=$user->umode" : "&mode=threaded"; $morelink .= ($user->uorder) ? "&order=$user->uorder" : "&order=0"; $morelink .= ($user->thold) ? "&thold=$user->thold" : "&thold=0"; @@ -96,9 +96,32 @@ function addRefer($url) { } } +function id2story($id) { + ### Perform query: + $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON s.author = u.id WHERE s.id = $id"); + return db_fetch_object($result); +} + +function displayModerationResults($theme, $story) { + global $user; + + if ($user->id && $story->id && $vote = $user->getHistory("s$story->id")) { + $output .= "

You voted `$vote'.

\n"; + $output .= "

\n"; + $output .= "Other people voted:
\n"; + + $result = db_query("SELECT * FROM users WHERE history LIKE '%s$story->id%'"); + while ($account = db_fetch_object($result)) { + $output .= "
userid\">$account->userid voted `". getHistory($account->history, "s$story->id") ."'.
"; + } + + $theme->box("Moderation results", $output); + } +} + function displayRelatedLinks($theme, $story) { ### Parse story for -tags: - $text = "$story->abstract $story->editorial $story->article"; + $text = "$story->abstract $story->updates $story->article"; while ($text = stristr($text, "") + 4); $text = stristr($text, ""); @@ -125,14 +148,14 @@ function displayOldHeadlines($theme, $num = 10) { } if ($user->userid) { - $content .= "

  • id"; + $content .= "
  • id"; $content .= ($user->umode) ? "&mode=$user->umode" : "&mode=threaded"; $content .= ($user->uorder) ? "&order=$user->uorder" : "&order=0"; $content .= ($user->thold) ? "&thold=$user->thold" : "&thold=0"; $content .= "\">$story->subject
  • "; } else { - $content .= "
  • id&mode=threaded&order=1&thold=0\">$story->subject
  • "; + $content .= "
  • id&mode=threaded&order=1&thold=0\">$story->subject
  • "; } } $content .= "

    [ hlcolor2\">more ]

    "; @@ -147,14 +170,14 @@ function displayNewHeadlines($theme, $num = 10) { $result = db_query("SELECT id, subject FROM stories WHERE status = 2 ORDER BY id DESC LIMIT $num"); while ($story = db_fetch_object($result)) { if ($user->userid) { - $content .= "
  • id"; + $content .= "
  • id"; $content .= ($user->umode) ? "&mode=$user->umode" : "&mode=threaded"; $content .= ($user->uorder) ? "&order=$user->uorder" : "&order=0"; $content .= ($user->thold) ? "&thold=$user->thold" : "&thold=0"; $content .= "\">$story->subject
  • "; } else { - $content .= "
  • id&mode=threaded&order=1&thold=0\">$story->subject
  • "; + $content .= "
  • id&mode=threaded&order=1&thold=0\">$story->subject
  • "; } } $content .= "

    [ hlcolor2\">more ]

    "; diff --git a/search.php b/search.php index 48e761c0ebb..c9568165b9e 100644 --- a/search.php +++ b/search.php @@ -57,14 +57,14 @@ $num++; if ($user) { - $link = "id"; + $link = "id"; if (isset($user->umode)) { $link .= "&mode=$user->umode"; } else { $link .= "&mode=threaded"; } if (isset($user->uorder)) { $link .= "&order=$user->uorder"; } else { $link .= "&order=0"; } if (isset($user->thold)) { $link .= "&thold=$user->thold"; } else { $link .= "&thold=0"; } $link .= "\">$entry->subject"; } else { - $link = "id&mode=threaded&order=1&thold=0\">$entry->subject"; + $link = "id&mode=threaded&order=1&thold=0\">$entry->subject"; } $output .= "

    $num) $link
    by userid\">$entry->userid, posted on ". date("l, F d, Y - H:i A", $entry->timestamp) .".

    \n"; diff --git a/submission.inc b/submission.inc index 55f85e051a8..8dc60e3c84a 100644 --- a/submission.inc +++ b/submission.inc @@ -10,7 +10,7 @@ function submission_score($id) { return ($result) ? mysql_result($result, 0) : 0; } -function submission_vote($id, $vote) { +function submission_vote($id, $vote, $comment) { global $user; include "config.inc"; @@ -19,6 +19,9 @@ function submission_vote($id, $vote) { ### Update submission's score- and votes-field: db_query("UPDATE stories SET score = score $vote, votes = votes + 1 WHERE id = $id"); + ### Update the comments (if required): + db_query("INSERT INTO comments (sid, subject, comment, hostname, timestamp) VALUES($id, '". addslashes(substr($comment, 0, 29)) ." ...', '". addslashes($comment) ."', '". getenv("REMOTE_ADDR") ."', '". time() ."')"); + ### Update user's history record: $user->setHistory("s$id", "$vote"); // s = submission $user->save(); @@ -26,8 +29,8 @@ function submission_vote($id, $vote) { ### Update story table (if required): $result = db_query("SELECT * FROM stories WHERE id = $id"); if ($submission = db_fetch_object($result)) { - if ($submission->score >= $submission_post_threshold) db_query("UPDATE stories SET status = 2, timestamp = '". time() ."' WHERE id = $id"); - if ($submission->score <= $submission_dump_threshold) db_query("UPDATE stories SET status = 0, timestamp = '". time() ."' WHERE id = $id"); +# if ($submission->score >= $submission_post_threshold) db_query("UPDATE stories SET status = 2, timestamp = '". time() ."' WHERE id = $id"); +# if ($submission->score <= $submission_dump_threshold) db_query("UPDATE stories SET status = 0, timestamp = '". time() ."' WHERE id = $id"); } } } diff --git a/submission.php b/submission.php index fd967db259b..a734e143326 100644 --- a/submission.php +++ b/submission.php @@ -30,33 +30,34 @@ function submission_displayMain() { function submission_displayItem($id) { global $PHP_SELF, $theme, $user; - include "config.inc"; - - $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON s.author = u.id WHERE s.id = $id"); - $submission = db_fetch_object($result); - - $theme->header(); - $theme->article($submission, "[ hlcolor2\">back ]"); - - if ($vote = getHistory($user->history, "s$submission->id")) { - print "

    You voted `$vote' for this story!
    Score: $submission->score
    Votes: $submission->votes

    \n"; - print "

    \n"; - print "Other people voted:
    \n"; - - $result = db_query("SELECT * FROM users WHERE history LIKE '%s$submission->id%'"); - while ($account = db_fetch_object($result)) { - print "userid\">$account->userid voted `". getHistory($account->history, "s$submission->id") ."'.
    "; - } + if ($vote = getHistory($user->history, "s$id")) { + header("Location: discussion.php?id=$id"); } else { + include "config.inc"; + + $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON s.author = u.id WHERE s.id = $id"); + $submission = db_fetch_object($result); + + $theme->header(); + $theme->article($submission, "[ hlcolor2\">back ]"); + print "

    \n"; + + print "

    \n"; + print " Vote:
    \n"; print " \n"; - print " id\">\n"; - print " \n"; + print "

    \n"; + + print "

    \n"; + print " Comment:
    \n"; + print " \n"; + print "

    \n"; + + print "id\">\n"; + print "\n"; print "
    \n"; } @@ -69,7 +70,7 @@ if ($user) { submission_displayItem($id); break; case "Vote"; - submission_vote($id, $vote); + submission_vote($id, $vote, $comment); submission_displayItem($id); break; default: