diff options
author | Dries Buytaert <dries@buytaert.net> | 2000-06-22 18:18:06 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2000-06-22 18:18:06 +0000 |
commit | a2466c54ed7787514f1686445e43f01dba5269a2 (patch) | |
tree | fa7486a1fbdb7c8fd07105e9c4e863a2bab5fd49 | |
parent | 315d060a7524154b7506f739e0c2be0bf04cfc2b (diff) | |
download | brdo-a2466c54ed7787514f1686445e43f01dba5269a2.tar.gz brdo-a2466c54ed7787514f1686445e43f01dba5269a2.tar.bz2 |
* Commited a *temporary* version of the new comment system: I have been
working on it for about 4 a 5 hours today and I considered it would be
smart (backup- or crash-wise) to commit what I have made so far. I'm
aware of a few bugs and I'll keep workin on it:
- removing bugs
- clean up the code to make it very streamlined
- improve error checking
Once we got a stable comment system, I'll add moderation. But right
now I want to sort out the major problems.
* I made my theme the default theme until the other themes are updated.
* Expanded the database abstraction layer with more goodies.
-rw-r--r-- | article.php | 10 | ||||
-rw-r--r-- | comments.php | 510 | ||||
-rw-r--r-- | config.inc | 2 | ||||
-rw-r--r-- | database.inc | 4 |
4 files changed, 200 insertions, 326 deletions
diff --git a/article.php b/article.php index 8b16c05e5..e18068d67 100644 --- a/article.php +++ b/article.php @@ -11,15 +11,11 @@ if ($op == "reply") Header("Location: comments.php?op=reply&pid=0&sid=$sid&mode=$mode&order=$order&thold=$thold"); - $result = db_query("SELECT * FROM stories WHERE id = $id"); + $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(); - $reply = "[ <A HREF=\"\"><FONT COLOR=\"$theme->hlcolor2\">home</FONT></A> | <A HREF=\"comments.php?op=reply&pid=0&sid=$story->sid\"><FONT COLOR=\"$theme->hlcolor2\">add a comment</FONT></A> ]"; - $theme->article($story, $reply); - - // if ($mode != "nocomments") include "comments.php"; - // 21/06/2000 - temporary disabled commnents - + $theme->article($story, "[ <A HREF=\"\"><FONT COLOR=\"$theme->hlcolor2\">home</FONT></A> | <A HREF=\"comments.php?op=reply&pid=0&sid=$story->id\"><FONT COLOR=\"$theme->hlcolor2\">add a comment</FONT></A> ]"); + if ($mode != "nocomments") include "comments.php"; $theme->footer(); ?>
\ No newline at end of file diff --git a/comments.php b/comments.php index 437a471c9..385bd3826 100644 --- a/comments.php +++ b/comments.php @@ -1,100 +1,68 @@ <? -function moderate_1() { - include "config.inc"; - global $admin; - echo "<FORM ACTION=\"comments.php\" METHOD=\"post\">"; -} - -function moderate_2($tid, $reason) { - include "config.inc"; - - echo "<SELECT NAME=\"meta:$tid\">"; - for($i = 0; $i < sizeof($comments_meta_reasons); $i++) { - echo "<OPTION VALUE=\"$i\">$comments_meta_reasons[$i]</OPTION>\n"; - } - echo "</SELECT>"; -} - -function moderate_3($sid, $mode, $order, $thold = 0) { - echo "<INPUT TYPE=\"hidden\" NAME=\"sid\" VALUE=\"$sid\"><INPUT TYPE=\"hidden\" NAME=\"mode\" VALUE=\"$mode\"><INPUT TYPE=\"hidden\" NAME=\"order\" VALUE=\"$order\"><INPUT TYPE=\"hidden\" NAME=\"thold\" VALUE=\"$thold\"><INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Moderate\"></FORM>"; -} - -function displayKids ($tid, $mode, $order = 0, $thold = 0, $level = 0, $dummy = 0) { +function displayKids ($cid, $mode, $order = 0, $thold = 0, $level = 0, $dummy = 0) { global $user, $theme; + include "config.inc"; $comments = 0; - $result = mysql_query("SELECT tid, pid, sid, date, name, email, url, host_name, subject, comment, score, reason FROM comments WHERE pid = $tid ORDER BY date, tid"); + $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 ($mode == 'nested') { - while (list($r_tid, $r_pid, $r_sid, $r_date, $r_name, $r_email, $r_url, $r_host_name, $r_subject, $r_comment, $r_score, $r_reason) = mysql_fetch_row($result)) { - if ($r_score >= $thold) { - if ($level && !$comments) { - echo "<UL>"; - $tblwidth -= 5; - } + if ($mode == "nested") { + while ($comment = db_fetch_object($result)) { + if ($$comment->score >= $thold) { + if ($level && !$comments) print "<UL>"; $comments++; - $link = "<A HREF=\"comments.php?op=reply&pid=$r_tid&sid=$r_sid&mode=$mode&order=$order&thold=$thold\"><FONT COLOR=\"$theme->hlcolor2\">reply to this comment</FONT></A>"; - - $theme->comment($r_name, $r_subject, $r_tid, $r_date, $r_url, $r_email, $r_score, $r_reason, $r_comment, $link); + $link = "<A HREF=\"comments.php?op=reply&pid=$comment->cid&sid=$comment->sid&mode=$mode&order=$order&thold=$thold\"><FONT COLOR=\"$theme->hlcolor2\">reply to this comment</FONT></A>"; + $theme->comment($comment->userid, $comment->subject, $comment->comment, $comment->timestamp, $comment->url, $comment->femail, $comment->score, $comment->cid, $link); - displayKids($r_tid, $mode, $order, $thold, $level + 1, $dummy + 1); + displayKids($comment->cid, $mode, $order, $thold, $level + 1, $dummy + 1); } } - } elseif ($mode == 'flat') { - while (list($r_tid, $r_pid, $r_sid, $r_date, $r_name, $r_email, $r_url, $r_host_name, $r_subject, $r_comment, $r_score, $r_reason) = mysql_fetch_row($result)) { - if ($r_score >= $thold) { - if (!eregi("[a-z0-9]",$r_name)) $r_name = $anonymous; - if (!eregi("[a-z0-9]",$r_subject)) $r_subject = "[no subject]"; - - $link = "<A HREF=\"comments.php?op=reply&pid=$r_tid&sid=$r_sid&mode=$mode&order=$order&thold=$thold\"><FONT COLOR=\"$theme->hlcolor2\">reply to this comment</FONT></A>"; - - $theme->comment($r_name, $r_subject, $r_tid, $r_date, $r_url, $r_email, $r_score, $r_reason, $r_comment, $link); + } + elseif ($mode == "flat") { + while ($comment = db_fetch_object($result)) { + if ($comment->score >= $thold) { + $link = "<A HREF=\"comments.php?op=reply&pid=$comment->cid&sid=$comment->sid&mode=$mode&order=$order&thold=$thold\"><FONT COLOR=\"$theme->hlcolor2\">reply to this comment</FONT></A>"; + $theme->comment($comment->userid, $comment->subject, $comment->comment, $comment->timestamp, $comment->url, $comment->femail, $comment->score, $comment->cid, $link); } - displayKids($r_tid, $mode, $order, $thold); + displayKids($comment->cid, $mode, $order, $thold); } } else { - echo "ERROR: we should not get here!"; + print "ERROR: we should not get here!"; } if ($level && $comments) { - echo "</UL>"; + print "</UL>"; } } -function displayBabies ($tid, $level = 0, $dummy = 0, $thread) { - global $datetime, $theme, $user; - - include "config.inc"; +function displayBabies($cid, $mode, $order, $thold, $level = 0, $thread) { + global $theme, $user; - $comments = 0; - $result = mysql_query("SELECT tid, pid, sid, date, name, email, url, host_name, subject, comment, score, reason FROM comments WHERE pid = $tid ORDER BY date, tid"); + ### 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 (list($r_tid, $r_pid, $r_sid, $r_date, $r_name, $r_email, $r_url, $r_host_name, $r_subject, $r_comment, $r_score, $r_reason) = mysql_fetch_row($result)) { + while ($comment = db_fetch_object($result)) { if ($level && !$comments) { $thread .= "<UL>"; } $comments++; - if (!eregi("[a-z0-9]",$r_name)) { $r_name = $anonymous; } - if (!eregi("[a-z0-9]",$r_subject)) { $r_subject = "[no subject]"; } - if ($user) { - ### Make sure to respect the user preferences: - $thread .= "<LI><A HREF=\"comments.php?op=showreply&tid=$r_tid&pid=$r_pid&sid=$r_sid"; - if (isset($user->umode)) { $thread .= "&mode=$user->umode"; } else { $thread .= "&mode=threaded"; } - if (isset($user->uorder)) { $thread .= "&order=$user->uorder"; } else { $thread .= "&order=0"; } - if (isset($user->thold)) { $thread .= "&thold=$user->thold"; } else { $thread .= "&thold=0"; } - $thread .= "\">$r_subject</A> by $r_name <FONT SIZE=\"2\">(". formatTimestamp($r_date) .")</FONT></LI>"; - } - else { - $thread .= "<LI><A HREF=\"comments.php?op=showreply&tid=$r_tid&pid=$r_pid&sid=$r_sid&mode=threaded&order=1&thold=0\">$r_subject</A> by $r_name <FONT SIZE=\"2\">(". formatTimestamp($r_date) .")</FONT></LI>"; - } - displayBabies($r_tid, $level + 1, $dummy + 1, &$thread); + ### Compose link: + $thread .= "<LI><A HREF=\"comments.php?op=show&cid=$comment->cid&pid=$comment->pid&sid=$comment->sid"; + $thread .= ($mode) ? "&mode=$mode" : "&mode=threaded"; + $thread .= ($order) ? "&order=$order" : "&order=0"; + $thread .= ($thold) ? "&thold=$thold" : "&thold=0"; + $thread .= "\">$comment->subject</A> by $comment->userid <SMALL>(". date("D, M d, Y - H:i:s", $comment->timestamp) .")<SMALL></LI>"; + + ### Recursive: + displayBabies($comment->cid, $mode, $order, $thold, $level + 1, &$thread); } if ($level && $comments) { @@ -104,322 +72,220 @@ function displayBabies ($tid, $level = 0, $dummy = 0, $thread) { return $thread; } -function displayTopic ($sid, $pid = 0, $tid = 0, $mode = "threaded", $order = 0, $thold = 0, $level = 0, $nokids = 0) { - global $user, $theme, $functions; - - ### include required files: - if ($functions) { - include "config.inc"; - } - else { - include "functions.inc"; - include "theme.inc"; - $theme->header(); - } - - ### ensure default value: - if (!isset($pid)) $pid = 0; - - ### connect to database: - dbconnect(); - - $count_times = 0; +function comments_display ($sid = 0, $pid = 0, $cid = 0, $mode = "threaded", $order = 0, $thold = 0, $level = 0, $nokids = 0) { + global $user, $theme; - $q = "SELECT tid, pid, sid, date, name, email, url, host_name, subject, comment, score, reason FROM comments WHERE sid = $sid AND pid = $pid"; + ### 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 != "") { - $q .= " AND score >= $thold"; - } else { - $q .= " AND score >= 0"; - } + 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"); - if ($order == 1) $q .= " ORDER BY date DESC"; - if ($order == 2) $q .= " ORDER BY score DESC"; - - $res = mysql_query("$q"); - - $num_tid = mysql_num_rows($res); - - $theme->commentControl($sid, $title, $thold, $mode, $order); - - moderate_1(); - - while ($count_times < $num_tid) { - list($tid, $pid, $sid, $date, $name, $email, $url, $host_name, $subject, $comment, $score, $reason) = mysql_fetch_row($res); - if ($name == "") { $name = $anonymous; } - if ($subject == "") { $subject = "[no subject]"; } - - ### Dynamically generate the link: + ### Display the comments: + while ($comment = db_fetch_object($result)) { + ### Dynamically compose the `reply'-link: if ($pid != 0) { - list($erin) = mysql_fetch_row(mysql_query("SELECT pid FROM comments WHERE tid=$pid")); - $link = "<A HREF=\"comments.php?sid=$sid&pid=$erin&mode=$mode&order=$order&thold=$thold\"><FONT COLOR=\"$theme->hlcolor2\">return to parent</FONT></A> | <A HREF=\"comments.php?op=reply&pid=$tid&sid=$sid&mode=$mode&order=$order&thold=$thold\"><FONT COLOR=\"$theme->hlcolor2\">reply to this comment</FONT></A>"; + list($pid) = mysql_fetch_row(mysql_query("SELECT pid FROM comments WHERE cid = $comment->pid")); + $link = "<A HREF=\"comments.php?op=show&pid=$pid&sid=$comment->sid&mode=$mode&order=$order&thold=$thold\"><FONT COLOR=\"$theme->hlcolor2\">return to parent</FONT></A> | <A HREF=\"comments.php?op=reply&pid=$comment->cid&sid=$comment->sid&mode=$mode&order=$order&thold=$thold\"><FONT COLOR=\"$theme->hlcolor2\">reply to this comment</FONT></A>"; } else { - $link = "<A HREF=\"comments.php?op=reply&pid=$tid&sid=$sid&mode=$mode&order=$order&thold=$thold\"><FONT COLOR=\"$theme->hlcolor2\">reply to this comment</FONT></A> "; + $link = "<A HREF=\"comments.php?op=reply&pid=$comment->cid&sid=$comment->sid&mode=$mode&order=$order&thold=$thold\"><FONT COLOR=\"$theme->hlcolor2\">reply to this comment</FONT></A> "; } + ### Display the comments: if ($mode == "threaded") { - $thread = displayBabies($tid, $mode, $order, $thold, $level); - $theme->comment($name, $subject, $tid, $date, $url, $email, $score, $reason, $comment, $link, $thread); + $thread = displayBabies($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($name, $subject, $tid, $date, $url, $email, $score, $reason, $comment, $link); - displayKids($tid, $mode, $order, $thold, $level); + $theme->comment($comment->userid, $comment->subject, $comment->comment, $comment->timestamp, $comment->url, $comment->femail, $comment->score, $comment->cid, $link); + displayKids($comment->cid, $mode, $order, $thold, $level); } - - echo "</UL>"; - echo "</P>"; - $count_times += 1; +/* + print "</UL>\n"; + print "</P>\n"; +*/ } - moderate_3($sid, $mode, $order, $thold); - if ($pid == 0) return array($sid, $pid, $subject); - else $theme->footer(); } +function comments_reply($pid, $sid, $mode, $order, $thold) { + global $user, $theme; -function reply($pid, $sid, $mode, $order, $thold) { - include "functions.inc"; - include "theme.inc"; - - global $user; - dbconnect(); - - $theme->header(); - - if ($pid != 0) { - list($date, $name, $email, $url, $subject, $comment, $score) = mysql_fetch_row(mysql_query("SELECT date, name, email, url, subject, comment, score FROM comments WHERE tid = $pid")); - } else { - list($date, $subject, $comment, $name) = mysql_fetch_row(mysql_query("SELECT time, subject, abstract, informant FROM stories WHERE sid = $sid")); + ### 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"); } - - ### Pre-process the variables: - if ($comment == "") $comment = $comment; - if ($subject == "") $subject = "[no subject]"; - if ($name == "") $name = $anonymous; - - ### Display parent comment: - echo "<TABLE WIDTH=\"100%\" BORDER=\"0\">"; - if ($email) { - echo " <TR BGCOLOR=\"$theme->bgcolor1\"><TD><FONT COLOR=\"$theme->hlcolor1\"><B>$subject</B><BR>by <A HREF=\"mailto:$email\">$name</A> <B>($email)</B> on ". formatTimestamp($date) ."</FONT></TD></TR>"; - } else { - echo " <TR BGCOLOR=\"$theme->bgcolor1\"><TD><FONT COLOR=\"$theme->hlcolor1\"><B>$subject</B><BR>by $name on ". formatTimestamp($date) ."</FONT></TD></TR>"; - } - echo " <TR BGCOLOR=\"$theme->bgcolor2\"><TD>$comment</TD></TR>"; - echo "</TABLE>"; - - if (!isset($pid) || !isset($sid)) { exit(); } - if ($pid == 0) { - list($subject) = mysql_fetch_row(mysql_query("SELECT subject FROM stories WHERE sid = $sid")); - } - else { - list($subject) = mysql_fetch_row(mysql_query("SELECT subject FROM comments WHERE tid = $pid")); + $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: - echo "<FORM ACTION=\"comments.php\" METHOD=\"post\">"; + $output .= "<FORM ACTION=\"comments.php\" METHOD=\"post\">\n"; - echo "<B>Your name:</B><BR> "; + ### Name field: if ($user) { - echo "<A HREF=\"account.php\">$user->userid</A> <FONT SIZE=\"2\">[ <A HREF=\"account.php?op=logout\">logout</A> ]</FONT>"; - } - else { - echo "$anonymous"; - $postanon = 2; - } - echo "<BR><BR>"; - - echo "<B>Subject:</B><BR>"; - if (!eregi("Re:",$subject)) $subject = "Re: $subject"; - // Only one 'Re:' will just do fine. ;) - echo "<INPUT TYPE=\"text\" NAME=\"subject\" SIZE=\"60\" MAXLENGTH=\"60\" VALUE=\"$subject\">"; - echo "<BR><BR>"; - - if ($user) { - $userinfo = getusrinfo($user); - echo "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"comment\">$userinfo[signature]</TEXTAREA><BR>"; - echo "<INPUT TYPE=\"checkbox\" NAME=\"postanon\"> Post this comment anonymously."; - echo "<BR><BR>"; + $output .= "<P>\n"; + $output .= " <B>Your name:</B><BR>\n"; + $output .= " <A HREF=\"account.php\">$user->userid</A> <FONT SIZE=\"2\">[ <A HREF=\"account.php?op=logout\">logout</A> ]</FONT>\n"; + $output .= "</P>\n"; } else { - echo "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"comment\"></TEXTAREA>"; - echo "<BR><BR>"; + $output .= "<P>\n"; + $output .= " <B>Your name:</B><BR>\n"; + $output .= " $anonymous\n"; + $output .= "</P>\n"; } - echo "<INPUT TYPE=\"hidden\" NAME=\"pid\" VALUE=\"$pid\">"; - echo "<INPUT TYPE=\"hidden\" NAME=\"sid\" VALUE=\"$sid\"><INPUT TYPE=\"hidden\" NAME=\"mode\" VALUE=\"$mode\">"; - echo "<INPUT TYPE=\"hidden\" NAME=\"order\" VALUE=\"$order\"><INPUT TYPE=\"hidden\" NAME=\"thold\" VALUE=\"$thold\">"; - echo "<INPUT TYPE=submit NAME=op VALUE=\"Preview comment\"> <INPUT TYPE=submit NAME=op VALUE=\"Post comment\"> <SELECT NAME=\"posttype\"><OPTION VALUE=\"exttrans\">HTML to text<OPTION VALUE=\"html\">HTML-formatted<OPTION VALUE=\"plaintext\" SELECTED>Plain text</SELECT></FORM>"; + ### Subject field: + $output .= "<P>\n"; + $output .= " <B>Subject:</B><BR>\n"; + if (!eregi("Re:",$item->subject)) $item->subject = "Re: $item->subject"; + // Only one 'Re:' will just do fine. ;) + $output .= " <INPUT TYPE=\"text\" NAME=\"subject\" SIZE=\"50\" MAXLENGTH=\"60\" VALUE=\"$item->subject\">\n"; + $output .= "</P>\n"; + + ### Comment field: + $output .= "<P>\n"; + $output .= " <B>Comment:</B><BR>\n"; + $output .= " <TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"comment\">$user->signature</TEXTAREA><BR>\n"; + $output .= "</P>\n"; - echo "<FONT SIZE=\"2\">Allowed HTML-tags:<BR>"; - for ($i=0; $i < sizeof($AllowableHTML); $i++) { - if (!eregi("/",$AllowableHTML[$i])) echo " <$AllowableHTML[$i]>"; - } - - $theme->footer(); + ### Hidden fields: + $output .= "<INPUT TYPE=\"hidden\" NAME=\"pid\" VALUE=\"$pid\">\n"; + $output .= "<INPUT TYPE=\"hidden\" NAME=\"sid\" VALUE=\"$sid\">\n"; + $output .= "<INPUT TYPE=\"hidden\" NAME=\"mode\" VALUE=\"$mode\">\n"; + $output .= "<INPUT TYPE=\"hidden\" NAME=\"order\" VALUE=\"$order\">\n"; + $output .= "<INPUT TYPE=\"hidden\" NAME=\"thold\" VALUE=\"$thold\">\n"; + + ### Preview button: + $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Preview comment\"> (You must preview at least once before you can submit.)\n"; + $output .= "</FORM>\n"; + + $theme->box("Reply", $output); } -function replyPreview ($pid, $sid, $subject, $comment, $postanon, $mode, $order, $thold, $posttype) { - include "functions.inc"; - include "theme.inc" ; - - global $user, $bgcolor1, $bgcolor2; +function comment_preview($pid, $sid, $subject, $comment, $mode, $order, $thold) { + global $user, $theme; - $subject = stripslashes($subject); - $comment = stripslashes($comment); + ### 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"); - $theme->header(); + ### Build reply form: + $output .= "<FORM ACTION=\"comments.php\" METHOD=\"post\">\n"; - ### Display preview: - echo "<TABLE WIDTH=\"100%\" BORDER=\"0\">"; + ### Name field: if ($user) { - echo " <TR BGCOLOR=\"$bgcolor1\"><TD><B>$subject</B><BR>by $user->userid.</TD></TR>"; - } - else { - echo " <TR BGCOLOR=\"$bgcolor1\"><TD><B>$subject</B><BR>by $anonymous.</TD></TR>"; - } - - if ($posttype == "exttrans") { - echo " <TR BGCOLOR=\"$bgcolor2\"><TD>". nl2br(htmlspecialchars($comment)) ."</TD></TR>"; - } - elseif ($posttype == "plaintext") { - echo " <TR BGCOLOR=\"$bgcolor2\"><TD>". nl2br($comment) ."</TD></TR>"; + $output .= "<P>\n"; + $output .= " <B>Your name:</B><BR>\n"; + $output .= " <A HREF=\"account.php\">$user->userid</A> <FONT SIZE=\"2\">[ <A HREF=\"account.php?op=logout\">logout</A> ]</FONT>\n"; + $output .= "</P>\n"; } else { - echo " <TR BGCOLOR=\"$bgcolor2\"><TD>$comment</TD></TR>"; + $output .= "<P>\n"; + $output .= " <B>Your name:</B><BR>\n"; + $output .= " $anonymous\n"; + $output .= "</P>\n"; } - echo "</TABLE>"; - ### Build reply form: - echo "<FORM ACTION=\"comments.php\" METHOD=\"post\">"; - - echo "<B>Your name:</B><BR> "; - if ($user) { - echo "<A HREF=\"account.php\">$user->userid</A> <FONT SIZE=\"2\">[ <A HREF=\"account.php?op=logout\">logout</A> ]</FONT>"; - } else { - echo "$anonymous"; - $postanon = 2; - } - echo "<BR><BR>"; - - echo "<B>Subject:</B><BR>"; - if (!eregi("Re:",$subject)) $subject = "Re: $subject"; // one Re: will do ;) - echo "<INPUT TYPE=\"text\" NAME=\"subject\" SIZE=\"60\" MAXLENGTH=\"60\" VALUE=\"$subject\">"; - echo "<BR><BR>"; - - $userinfo = getusrinfo($user); - echo "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"comment\">$comment</TEXTAREA>"; - if ($user) { - if ($postanon) echo "<BR><INPUT TYPE=\"checkbox\" NAME=\"postanon\" CHECKED> Post this comment anonymously."; - else echo "<BR><INPUT TYPE=\"checkbox\" NAME=\"postanon\"> Post this comment anonymously."; + ### Subject field: + $output .= "<P>\n"; + $output .= " <B>Subject:</B><BR>\n"; + $output .= " <INPUT TYPE=\"text\" NAME=\"subject\" SIZE=\"50\" MAXLENGTH=\"60\" VALUE=\"$subject\">\n"; + $output .= "</P>\n"; + + ### Comment field: + $output .= "<P>\n"; + $output .= " <B>Comment:</B><BR>\n"; + $output .= " <TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"comment\">$comment</TEXTAREA><BR>\n"; + $output .= "</P>\n"; + + ### Hidden fields: + $output .= "<INPUT TYPE=\"hidden\" NAME=\"pid\" VALUE=\"$pid\">\n"; + $output .= "<INPUT TYPE=\"hidden\" NAME=\"sid\" VALUE=\"$sid\">\n"; + $output .= "<INPUT TYPE=\"hidden\" NAME=\"mode\" VALUE=\"$mode\">\n"; + $output .= "<INPUT TYPE=\"hidden\" NAME=\"order\" VALUE=\"$order\">\n"; + $output .= "<INPUT TYPE=\"hidden\" NAME=\"thold\" VALUE=\"$thold\">\n"; + + ### Preview and submit buttons: + if (empty($subject)) { + $output .= "<P>\n"; + $output .= " <FONT COLOR=\"red\"><B>Warning:</B></FONT> you did not supply a <U>subject</U>.\n"; + $outout .= "</P>\n"; + $output .= "<P>\n"; + $output .= " <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Preview comment\">\n"; + $output .= "</P>\n"; } - echo "<BR><BR>"; - - echo "<INPUT TYPE=\"hidden\" NAME=\"pid\" VALUE=\"$pid\">"; - echo "<INPUT TYPE=\"hidden\" NAME=\"sid\" VALUE=\"$sid\"><INPUT TYPE=\"hidden\" NAME=\"mode\" VALUE=\"$mode\">"; - echo "<INPUT TYPE=\"hidden\" NAME=\"order\" VALUE=\"$order\"><INPUT TYPE=\"hidden\" NAME=\"thold\" VALUE=\"$thold\">"; - echo "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Preview comment\"> "; - echo "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Post comment\"> "; - echo "<SELECT NAME=\"posttype\">"; - if ($posttype == "exttrans") echo " <OPTION VALUE=\"exttrans\" SELECTED>HTML to text"; - else echo " <OPTION VALUE=\"exttrans\">HTML to text"; - if ($posttype == "html") echo " <OPTION VALUE=\"html\" SELECTED>HTML-formatted"; - else echo " <OPTION VALUE=\"html\">HTML-formatted"; - if ($posttype == "plaintext") echo " <OPTION VALUE=\"plaintext\" SELECTED>Plain text"; - else echo " <OPTION VALUE=\"plaintext\">Plain text"; - echo "</SELECT>"; - echo "</FORM>"; - - echo "<FONT SIZE=\"2\">Allowed HTML-tags:<BR>"; - for ($i=0; $i < sizeof($AllowableHTML); $i++) { - if (!eregi("/",$AllowableHTML[$i])) echo " <$AllowableHTML[$i]>"; + else { + $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Preview comment\">\n"; + $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Post comment\">\n"; + $output .= "</FORM>\n"; } - $theme->footer(); + $theme->box("Reply", $output); } -function postComment($postanon, $subject, $comment, $pid, $sid, $host_name, $mode, $order, $thold, $posttype) { - global $user, $userinfo; - include "functions.inc"; - include "config.inc"; - dbconnect(); - - $subject = FixQuotes($subject); - $comment = FixQuotes($comment); - $author = FixQuotes($author); - - if ($posttype == "exttrans") $comment = nl2br(htmlspecialchars($comment)); - elseif($posttype == "plaintext") $comment = nl2br($comment); - else $comment = $comment; - - if (($user) && (!$postanon)) { - getusrinfo($user); - $name = $userinfo[uname]; - $email = $userinfo[femail]; - $url = $userinfo[url]; - $score = 1; - } else { - $name = ""; - $email = ""; - $url = ""; - $score = 0; - } - $ip = getenv("REMOTE_ADDR"); +function comment_post($pid, $sid, $subject, $comment, $mode, $order, $thold) { + global $user, $theme; ### Check for fake threads: - $fake = mysql_result(mysql_query("SELECT COUNT(*) FROM stories WHERE sid = $sid"), 0); + $fake = db_result(db_query("SELECT COUNT(*) FROM stories WHERE id = $sid"), 0); ### Check for duplicate comments: - $duplicate = mysql_result(mysql_query("SELECT COUNT(*) FROM comments WHERE pid = '$pid' AND sid = '$sid' AND subject = '$subject' AND comment = '$comment'"), 0); - + $duplicate = db_result(db_query("SELECT COUNT(*) FROM comments WHERE pid = '$pid' AND sid = '$sid' AND subject = '$subject' AND comment = '$comment'"), 0); + if ($fake != 1) { - include "theme.inc"; - $theme->header(); $theme->box("fake comment", "fake comment: $fake"); - $theme->footer(); } elseif ($duplicate != 0) { - include "theme.inc"; - $theme->header(); $theme->box("duplicate comment", "duplicate comment: $duplicate"); - $theme->footer(); } - else { - ### Add comment to table: - $reason = (int) sizeof($comments_meta_reasons) / 2; - mysql_query("INSERT INTO comments (tid, pid, sid, date, name, email, url, host_name, subject, comment, score, reason) VALUES (NULL, '$pid', '$sid', now(), '$name', '$email', '$url', '$ip', '$subject', '$comment', '$score', '$reason')"); - - ### Compose header: + else { if ($user) { - $header = "article.php?sid=$sid"; - if (isset($user->umode)) { $header .= "&mode=$user->umode"; } else { $header .= "&mode=threaded"; } - if (isset($user->uorder)) { $header .= "&order=$user->uorder"; } else { $header .= "&order=0"; } - if (isset($user->thold)) { $header .= "&thold=$user->thold"; } else { $header .= "&thold=1"; } + ### Add comment to database: + db_query("INSERT INTO comments (pid, sid, author, subject, comment, hostname, timestamp) VALUES ($pid, $sid, $user->id, '$subject', '$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 { - $header .= "article.php?sid=$sid&mode=threaded&order=1&thold=0"; + ### Add comment to database: + db_query("INSERT INTO comments (pid, sid, subject, comment, hostname, timestamp) VALUES ($pid, $sid, '$subject', '$comment', '". getenv("REMOTE_ADDR") ."', '". time() ."')"); + + ### Compose header: + $header .= "article.php?id=$sid&mode=threaded&order=1&thold=0"; } header("Location: $header"); } } -function moderate($tid, $meta_value = 0) { +function moderate($cid, $meta_value = 0) { include "config.inc"; if ($meta_value != -1) { ### Compose query: $query = "UPDATE comments SET"; if ($meta_value > (sizeof($comments_meta_reasons) / 2)) { - $query .= " score = score + 1, reason = $meta_value WHERE tid = $tid"; + $query .= " score = score + 1, reason = $meta_value WHERE cid = $cid"; } elseif ($meta_value < ((sizeof($comments_meta_reasons) / 2) - 1)) { - $query .= " score = score - 1, reason = $meta_value WHERE tid = $tid"; + $query .= " score = score - 1, reason = $meta_value WHERE cid = $cid"; } else { - $query .= " reason = $meta_value WHERE tid = $tid"; + $query .= " reason = $meta_value WHERE cid = $cid"; } ### Perform query: @@ -427,23 +293,29 @@ function moderate($tid, $meta_value = 0) { } } +if (strstr($PHP_SELF, "comments.php")) { + include "theme.inc"; + include "functions.inc"; +} + switch($op) { case "reply": - reply($pid, $sid, $mode, $order, $thold); + $theme->header(); + comments_reply($pid, $sid, $mode, $order, $thold); + $theme->footer(); break; case "Preview comment": - replyPreview($pid, $sid, $subject, $comment, $postanon, $mode, $order, $thold, $posttype); + $theme->header(); + comment_preview($pid, $sid, $subject, $comment, $mode, $order, $thold); + $theme->footer(); break; case "Post comment": - postComment($postanon, $subject, $comment, $pid, $sid, $host_name, $mode, $order, $thold, $posttype); + comment_post($pid, $sid, $subject, $comment, $mode, $order, $thold); break; case "Moderate": - include "functions.inc"; - dbconnect(); - while (list($name, $value) = each($HTTP_POST_VARS)) { if (eregi("meta", $name)) { - ### extract comment id (tid): + ### extract comment id (cid): $info = explode(":", $name); moderate($info[1], $value); } @@ -451,11 +323,13 @@ switch($op) { Header("Location: article.php?sid=$sid&mode=$mode&order=$order&thold=$thold"); break; - case "showreply": - displayTopic($sid, $pid, $tid, $mode, $order, $thold); + case "show": + $theme->header(); + comments_display($sid, $pid, $cid, $mode, $order, $thold); + $theme->footer(); break; default: - displayTopic($sid, $pid, $tid, $mode, $order, $thold); + comments_display($id, 0, 0, $mode, $order, $thold); } ?>
\ No newline at end of file diff --git a/config.inc b/config.inc index 29bdb025d..c923769f3 100644 --- a/config.inc +++ b/config.inc @@ -64,7 +64,7 @@ $anonymous = "Anonymous Chicken"; # # Default theme: # -$cfg_theme = "default"; +$cfg_theme = "Dries"; # # Submission moderation votes: diff --git a/database.inc b/database.inc index 464885396..83da9e602 100644 --- a/database.inc +++ b/database.inc @@ -47,6 +47,10 @@ function db_fetch_array($qid) { if ($qid) return mysql_fetch_array($qid); } +function db_result($qid, $field) { + if ($qid) return mysql_result($qid, $field); +} + # # Automatically connect to database: # |