home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 March / PCWorld_2001-03_cd.bin / KOMUNIK / progweb / progweb.exe / phpnuke / html / comments.php < prev    next >
PHP Script  |  2000-12-05  |  29KB  |  587 lines

  1. <?php
  2.  
  3. ######################################################################
  4. # PHP-NUKE: Web Portal System
  5. # ===========================
  6. #
  7. # Copyright (c) 2000 by Francisco Burzi (fburzi@ncc.org.ve)
  8. # http://phpnuke.org
  9. #
  10. # This modules is to manage all user's comments in the site
  11. #
  12. # This program is free software. You can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; either version 2 of the License.
  15. ######################################################################
  16.  
  17.  
  18. function modone() {
  19.     global $admin, $moderate;
  20.     if(((isset($admin)) && ($moderate == 1)) || ($moderate==2)) echo "<form action=\"comments.php\" method=\"post\">";
  21. }
  22.  
  23. function modtwo($tid, $score, $reason) {
  24.     global $admin, $user, $moderate, $reasons;
  25.     if((((isset($admin)) && ($moderate == 1)) || ($moderate == 2)) && ($user)) {
  26.         echo " | <select name=dkn$tid>";
  27.         for($i=0; $i<sizeof($reasons); $i++) {
  28.             echo "<option value=\"$score:$i\">$reasons[$i]</option>\n";
  29.         }
  30.         echo "</select>";
  31.     }
  32. }
  33.  
  34. function modthree($sid, $mode, $order, $thold=0) {
  35.     global $admin, $user, $moderate;
  36.     if((((isset($admin)) && ($moderate == 1)) || ($moderate==2)) && ($user)) echo "<center><input class=textbox type=hidden name=sid value=$sid><input class=textbox type=hidden name=mode value=$mode><input class=textbox type=hidden name=order value=$order><input class=textbox type=hidden name=thold value=$thold>
  37.     <input class=textbox type=hidden name=op value=moderate>
  38.     <input class=textbox type=image src=$uimages/moderate.gif border=0></form></center>";
  39. }
  40.  
  41. function navbar($sid, $title, $thold, $mode, $order) {
  42.     global $user, $bgcolor1, $bgcolor2, $textcolor1, $textcolor2;
  43.     $query = mysql_query("select sid FROM comments where sid=$sid");
  44.     if(!$query) $count = 0; else $count = mysql_num_rows($query);
  45.     if(!isset($thold)) $thold=0; ?>
  46.     <table width=99% border=0 cellspacing=1 cellpadding=2>
  47.     <?php if($title) {
  48.         echo "<tr><td bgcolor=\"$bgcolor2\" align=center><font size=2 color=\"$textcolor1\">\"$title\" | ";
  49.         if($user) {
  50.             echo "<a href=\"user.php\"><font color=\"$textcolor1\">".translate("Configure")."</font></a>";
  51.         } else {
  52.             echo "<a href=\"user.php\"><font color=\"$textcolor1\">".translate("Login/Create Account")."</font></a>";
  53.         }
  54.         if(($count==1)) {
  55.         echo " | <B>$count</B> ".translate("comment")."</font></td></tr>";
  56.         } else {
  57.         echo " | <B>$count</B> ".translate("comment")."s</font></td></tr>";
  58.         }
  59.     } ?>
  60.     <tr><td bgcolor="<?php echo"$bgcolor1"; ?>" align="center">
  61.     <form method=get action="article.php">
  62.     <font color="<?php echo"$textcolor2"; ?>"><?php echo translate("Threshold"); ?></font> <select name=thold>
  63.     <option value="-1" <?PHP if ($thold == -1) { echo "selected"; } ?>>-1
  64.     <option value="0" <?PHP if ($thold == 0) { echo "selected"; } ?>>0
  65.     <option value="1" <?PHP if ($thold == 1) { echo "selected"; } ?>>1
  66.     <option value="2" <?PHP if ($thold == 2) { echo "selected"; } ?>>2
  67.     <option value="3" <?PHP if ($thold == 3) { echo "selected"; } ?>>3
  68.     <option value="4" <?PHP if ($thold == 4) { echo "selected"; } ?>>4
  69.     <option value="5" <?PHP if ($thold == 5) { echo "selected"; } ?>>5
  70.     </select> <select name=mode>
  71.     <option value="nocomments" <?PHP if ($mode == 'nocomments') { echo "selected"; } ?>><?php echo translate("No Comments"); ?>
  72.     <option value="nested" <?PHP if ($mode == 'nested') { echo "selected"; } ?>><?php echo translate("Nested"); ?>
  73.     <option value="flat" <?PHP if ($mode == 'flat') { echo "selected"; } ?>><?php echo translate("Flat"); ?>
  74.     <option value="thread" <?PHP if (!isset($mode) || $mode=='thread' || $mode=="") { echo "selected"; } ?>><?php echo translate("Thread"); ?>
  75.     </select> <select name=order>
  76.     <option value="0" <?PHP if (!$order) { echo "selected"; } ?>><?php echo translate("Oldest First"); ?>
  77.     <option value="1" <?PHP if ($order==1) { echo "selected"; } ?>><?php echo translate("Newest First"); ?>
  78.     <option value="2" <?PHP if ($order==2) { echo "selected"; } ?>><?php echo translate("Highest Scores First"); ?>
  79.     </select>
  80.     <input type=submit value=<?php echo translate("Refresh"); ?>>
  81.     <input type=hidden name=sid value=<?PHP echo "$sid"; ?>>
  82.     </form></td></tr>
  83.     <tr><td bgcolor="<?php echo"$bgcolor2"; ?>" align=center><font size=1 color="#FFFFFF"><?php echo translate("The comments are owned by the poster. We aren't responsible for their content."); ?></td></tr>
  84.     </table>
  85. <?php
  86. }
  87.  
  88. function DisplayKids ($tid, $mode, $order=0, $thold=0, $level=0, $dummy=0, $tblwidth=99) {
  89.     global $datetime, $user, $cookie, $bgcolor1, $reasons, $anonymous, $anonpost, $commentlimit;
  90.     $comments = 0;
  91.     cookiedecode($user);
  92.     $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");
  93.     if ($mode == 'nested') {
  94.         /* without the tblwidth variable, the tables run of the screen with netscape
  95.            in nested mode in long threads so the text can't be read. */
  96.         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)) {
  97.             if($r_score >= $thold) {
  98.                 if (!isset($level)) {
  99.                 } else {
  100.                     if (!$comments) {
  101.                         echo "<ul>";
  102.                         $tblwidth -= 5;
  103.                     }
  104.                 }
  105.                 $comments++;
  106.                 if (!eregi("[a-z0-9]",$r_name)) $r_name = $anonymous;
  107.                 if (!eregi("[a-z0-9]",$r_subject)) $r_subject = "[".translate("No Subject")."]";
  108.             // HIJO enter hex color between first two appostrophe for second alt bgcolor
  109.                 $r_bgcolor = ($dummy%2)?"":"#E6E6D2";
  110.                 echo "<a name=\"$r_tid\">";
  111.                 echo "<table border=0><tr bgcolor=\"$bgcolor1\"><td>";
  112.                 formatTimestamp($r_date);
  113.                 if ($r_email) {
  114.                     echo "<p><b>$r_subject</b> <font size=2>";
  115.                     if(!$cookie[7]) {
  116.                         echo "(".translate("Score: ")."$r_score";
  117.                         if($r_reason>0) echo ", $reasons[$r_reason]";
  118.                         echo ")";
  119.                     }
  120.                     echo "<br>".translate("by")." <a href=\"mailto:$r_email\">$r_name</a> <font size=2><b>($r_email)</b></font> ".translate("on")." $datetime";
  121.                 } else {
  122.                     echo "<p><b>$r_subject</b> <font size=2>";
  123.                     if(!$cookie[7]) {
  124.                         echo "(".translate("Score: ")."$r_score";
  125.                         if($r_reason>0) echo ", $reasons[$r_reason]";
  126.                         echo ")";
  127.                     }
  128.                     echo "<br>".translate("by")." $r_name ".translate("on")." $datetime";
  129.                 }            
  130.                 if ($r_name != $anonymous) { echo "<BR>(<a href=\"user.php?op=userinfo&uname=$r_name\">".translate("User Info")."</a>) "; }
  131.                 if (eregi("http://",$r_url)) { echo "<a href=\"$r_url\" target=\"window\">$r_url</a> "; }
  132.                 echo "</font></td></tr><tr><td>";
  133.                 if(($cookie[10]) && (strlen($r_comment) > $cookie[10])) echo substr("$r_comment", 0, $cookie[10])."<br><br><b><a href=\"comments.php?sid=$r_sid&tid=$r_tid&mode=$mode&order=$order&thold=$thold\">".translate("Read the rest of this comment...")."</a></b>";
  134.                 elseif(strlen($r_comment) > $commentlimit) echo substr("$r_comment", 0, $commentlimit)."<br><br><b><a href=\"comments.php?sid=$r_sid&tid=$r_tid&mode=$mode&order=$order&thold=$thold\">".translate("Read the rest of this comment...")."</a></b>";
  135.                 else echo $r_comment;
  136.                 echo "</td></tr></table><br><p>";
  137.                 if ($anonpost==1 OR $admin OR $user) {
  138.                     echo "<font size=2 color=\"$bgcolor2\"> [ <a href=\"comments.php?op=Reply&pid=$r_tid&sid=$r_sid&mode=$mode&order=$order&thold=$thold\">".translate("Reply")."</a>";
  139.                 }
  140.                 modtwo($r_tid, $r_score, $r_reason);
  141.                 echo " ]</font><p>";
  142.                 DisplayKids($r_tid, $mode, $order, $thold, $level+1, $dummy+1, $tblwidth);
  143.             }
  144.         }
  145.     } elseif ($mode == 'flat') {
  146.         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)) {
  147.             if($r_score >= $thold) {
  148.                 if (!eregi("[a-z0-9]",$r_name)) $r_name = $anonymous;
  149.                 if (!eregi("[a-z0-9]",$r_subject)) $r_subject = "[".translate("No Subject")."]";
  150.                 echo "<a name=\"$r_tid\">";
  151.                 echo "<hr><table width=99% border=0><tr bgcolor=\"$bgcolor1\"><td>";
  152.                 formatTimestamp($r_date);
  153.                 if ($r_email) {
  154.                     echo "<p><b>$r_subject</b> <font size=2>";
  155.                     if(!$cookie[7]) {
  156.                         echo "(".translate("Score: ")."$r_score";
  157.                         if($r_reason>0) echo ", $reasons[$r_reason]";
  158.                         echo ")";
  159.                     }
  160.                     echo "<br>".translate("by")." <a href=\"mailto:$r_email\">$r_name</a> <font size=2><b>($r_email)</b></font> ".translate("on")." $datetime";
  161.                  } else {
  162.                     echo "<p><b>$r_subject</b> <font size=2>";
  163.                     if(!$cookie[7]) {
  164.                         echo "(".translate("Score: ")."$r_score";
  165.                         if($r_reason>0) echo ", $reasons[$r_reason]";
  166.                         echo ")";
  167.                     }
  168.                     echo "<br>".translate("by")." $r_name ".translate("on")." $datetime";
  169.                 }            
  170.                 if ($r_name != $anonymous) { echo "<BR>(<a href=\"user.php?op=userinfo&uname=$r_name\">".translate("User Info")."</a>) "; }
  171.                 if (eregi("http://",$r_url)) { echo "<a href=\"$r_url\" target=\"window\">$r_url</a> "; }
  172.                 echo "</font></td></tr><tr><td>";
  173.                 if(($cookie[10]) && (strlen($r_comment) > $cookie[10])) echo substr("$r_comment", 0, $cookie[10])."<br><br><b><a href=\"comments.php?sid=$r_sid&tid=$r_tid&mode=$mode&order=$order&thold=$thold\">".translate("Read the rest of this comment...")."</a></b>";
  174.                 elseif(strlen($r_comment) > $commentlimit) echo substr("$r_comment", 0, $commentlimit)."<br><br><b><a href=\"comments.php?sid=$r_sid&tid=$r_tid&mode=$mode&order=$order&thold=$thold\">".translate("Read the rest of this comment...")."</a></b>";
  175.                 else echo $r_comment;
  176.                 echo "</td></tr></table><br><p>";
  177.                 if ($anonpost==1 OR $admin OR $user) {
  178.                     echo "<font size=2 color=\"$bgcolor2\"> [ <a href=\"comments.php?op=Reply&pid=$r_tid&sid=$r_sid&mode=$mode&order=$order&thold=$thold\">".translate("Reply")."</a>";
  179.                 }
  180.                 modtwo($r_tid, $r_score, $r_reason);
  181.                 echo " ]</font><p>";
  182.                 DisplayKids($r_tid, $mode, $order, $thold);
  183.             }
  184.         }
  185.     } else {
  186.         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)) {
  187.             if($r_score >= $thold) {
  188.                 if (!isset($level)) {
  189.                 } else {
  190.                     if (!$comments) {
  191.                         echo "<ul>";
  192.                     }
  193.                 }
  194.                 $comments++;
  195.                 if (!eregi("[a-z0-9]",$r_name)) $r_name = $anonymous;
  196.                 if (!eregi("[a-z0-9]",$r_subject)) $r_subject = "[".translate("No Subject")."]";
  197.                 formatTimestamp($r_date);
  198.                 echo "<li><a href=\"comments.php?op=showreply&tid=$r_tid&sid=$r_sid&pid=$r_pid&mode=$mode&order=$order&thold=$thold#$r_tid\">$r_subject</a> ".translate("by")." $r_name <font size=2>".translate("on")." $datetime</font><br>";
  199.  
  200.                 DisplayKids($r_tid, $mode, $order, $thold, $level+1, $dummy+1);
  201.             } 
  202.         }
  203.     }
  204.     if ($level && $comments) {
  205.         echo "</ul>";
  206.     }
  207.  
  208. }
  209.  
  210. function DisplayBabies ($tid, $level=0, $dummy=0) {
  211.     global $datetime, $anonymous;
  212.     $comments = 0;
  213.     $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");
  214.     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))
  215.     {
  216.         if (!isset($level)) {
  217.         } else {
  218.             if (!$comments) {
  219.                 echo "<ul>";
  220.             }
  221.         }
  222.         $comments++;
  223.         if (!eregi("[a-z0-9]",$r_name)) { $r_name = $anonymous; }
  224.         if (!eregi("[a-z0-9]",$r_subject)) { $r_subject = "[".translate("No Subject")."]"; }
  225.  
  226.         formatTimestamp($r_date);
  227.         echo "<a href=\"comments.php?op=showreply&tid=$r_tid&mode=$mode&order=$order&thold=$thold\">$r_subject</a> ".translate("by")." $r_name <font size=2>".translate("on")." $datetime</font><br>";
  228.         DisplayBabies($r_tid, $level+1, $dummy+1);
  229.     } 
  230.     if ($level && $comments) {
  231.         echo "</ul>";
  232.     }
  233. }
  234.  
  235. function DisplayTopic ($sid, $pid=0, $tid=0, $mode="thread", $order=0, $thold=0, $level=0, $nokids=0) {
  236.     global $hr, $user, $datetime, $cookie, $mainfile, $admin, $commentlimit, $anonymous, $reasons, $anonpost;
  237.     if($mainfile) {
  238.         global $title, $bgcolor1, $bgcolor2, $bgcolor3;
  239.     } else {
  240.         global $title, $bgcolor1, $bgcolor2, $bgcolor3;
  241.         include("mainfile.php");
  242.         include("header.php");
  243.     }
  244.     $count_times = 0;
  245.     cookiedecode($user);
  246.     $q = "select tid, pid, sid, date, name, email, url, host_name, subject, comment, score, reason from comments where sid=$sid and pid=$pid";
  247.     if($thold != "") {
  248.         $q .= " and score>=$thold";
  249.     } else {
  250.         $q .= " and score>=0";
  251.     }
  252.     if ($order==1) $q .= " order by date desc";
  253.     if ($order==2) $q .= " order by score desc";
  254.     $something = mysql_query("$q");
  255.     $num_tid = mysql_num_rows($something);
  256.     navbar($sid, $title, $thold, $mode, $order);
  257.     modone();
  258.     while ($count_times < $num_tid) {
  259.         list($tid, $pid, $sid, $date, $name, $email, $url, $host_name, $subject, $comment, $score, $reason) = mysql_fetch_row($something);
  260.         if ($name == "") { $name = $anonymous; }
  261.         if ($subject == "") { $subject = "[".translate("No Subject")."]"; }    
  262.  
  263.         echo "<a name=\"$tid\"></a>";
  264.         echo "<table width=99% border=0><tr bgcolor=\"$bgcolor1\"><td width=500>";
  265.         formatTimestamp($date);
  266.         if ($email) {
  267.             echo "<p><b>$subject</b> <font size=2>";
  268.             if(!$cookie[7]) {
  269.                 echo "(".translate("Score: ")."$score";
  270.                 if($reason>0) echo ", $reasons[$reason]";
  271.                 echo ")";
  272.             }
  273.             echo "<br>".translate("by")." <a href=\"mailto:$email\">$name</a> <b>($email)</b> ".translate("on")." $datetime"; 
  274.         } else {
  275.             echo "<p><b>$subject</b> <font size=2>";
  276.             if(!$cookie[7]) {
  277.                 echo "(".translate("Score: ")."$score";
  278.                 if($reason>0) echo ", $reasons[$reason]";
  279.                 echo ")";
  280.             }
  281.             echo "<br>".translate("by")." $name ".translate("on")." $datetime";
  282.         }            
  283.         
  284.     // If you are admin you can see the Poster IP address (you have this right, no?)
  285.     // with this you can see who is flaming you... ha-ha-ha
  286.         
  287.         if ($name != $anonymous) { echo "<br>(<a href=\"user.php?op=userinfo&uname=$name\">".translate("User Info")."</a>) "; }
  288.         if (eregi("http://",$url)) { echo "<a href=\"$url\" target=\"window\">$url</a> "; }
  289.         
  290.         if($admin) {
  291.             $result= mysql_query("select host_name from comments where tid='$tid'");
  292.             list($host_name) = mysql_fetch_row($result);
  293.             echo "<br><b>(IP: $host_name)</b>";
  294.         }
  295.         
  296.         echo "</font></td></tr><tr><td>";
  297.         if(($cookie[10]) && (strlen($comment) > $cookie[10])) echo substr("$comment", 0, $cookie[10])."<br><br><b><a href=\"comments.php?sid=$sid&tid=$tid&mode=$mode&order=$order&thold=$thold\">".translate("Read the rest of this comment...")."</a></b>";
  298.         elseif(strlen($comment) > $commentlimit) echo substr("$comment", 0, $commentlimit)."<br><br><b><a href=\"comments.php?sid=$sid&tid=$tid&mode=$mode&order=$order&thold=$thold\">".translate("Read the rest of this comment...")."</a></b>";
  299.         else echo $comment;
  300.         echo "</td></tr></table><br><p>";
  301.         if ($anonpost==1 OR $admin OR $user) {
  302.             echo "<font size=2 color=000000> [ <a href=\"comments.php?op=Reply&pid=$tid&sid=$sid&mode=$mode&order=$order&thold=$thold\">".translate("Reply")."</a>";
  303.         } else {
  304.             echo "[ No Comments Allowed for Anonymous, please <a href=user.php>register</a> | ";
  305.         }
  306.         if ($pid != 0) {
  307.             list($erin) = mysql_fetch_row(mysql_query("select pid from comments where tid=$pid"));
  308.             echo " | <a href=\"comments.php?sid=$sid&pid=$erin&mode=$mode&order=$order&thold=$thold\">".translate("Parent")."</a>";
  309.         }
  310.         modtwo($tid, $score, $reason);
  311.         
  312.         if($admin) {
  313.         echo " | <a href=\"admin.php?op=RemoveComment&tid=$tid&sid=$sid\">".translate("Delete")."</a> ]</font><p>";
  314.         } else {
  315.             echo " ]</font><p>";
  316.         }
  317.         
  318.         DisplayKids($tid, $mode, $order, $thold, $level);
  319.         echo "</ul>";
  320.         if($hr) echo "<hr noshade size=1>";
  321.         echo "</p>";
  322.         $count_times += 1;
  323.     }
  324.     modthree($sid, $mode, $order, $thold);
  325.     if($pid==0) return array($sid, $pid, $subject);
  326.     else include("footer.php");
  327. }
  328.  
  329. function singlecomment($tid, $sid, $mode, $order, $thold) {
  330.     include("mainfile.php");
  331.     include("header.php");
  332.     global $user, $cookie, $datetime, $bgcolor1, $bgcolor2, $bgcolor3, $admin;
  333.     $deekayen = mysql_query("select date, name, email, url, subject, comment, score, reason from comments where tid=$tid and sid=$sid");
  334.     list($date, $name, $email, $url, $subject, $comment, $score, $reason) = mysql_fetch_row($deekayen);
  335.     $titlebar = "<b>$subject</b>";
  336.     if($name == "") $name = $anonymous;
  337.     if($subject == "") $subject = "[".translate("No Subject")."]";
  338.     modone();
  339.     echo "<table width=99% border=0><tr bgcolor=\"$bgcolor1\"><td width=500>";
  340.     formatTimestamp($date);
  341.     if($email) echo "<p><b>$subject</b> <font size=2>(".translate("Score: ")."$score)<br>".translate("by")." <a href=\"mailto:$email\"><font color=\"$bgcolor2\">$name</font></a> <font size=2><b>($email)</b></font> ".translate("on")." $datetime";
  342.     else echo "<p><b>$subject</b> <font size=2>(".translate("Score: ")."$score)<br>".translate("by")." $name ".translate("on")." $datetime";
  343.     echo "</td></tr><tr><td>$comment</td></tr></table><br><p>";
  344.     if ($anonpost==1 OR $admin OR $user) {
  345.         echo "<font size=2 color=\"$bgcolor2\"> [ <a href=\"comments.php?op=Reply&pid=$tid&sid=$sid&mode=$mode&order=$order&thold=$thold\">".translate("Reply")."</a> | <a href=\"article.php?sid=$sid&mode=$mode&order=$order&thold=$thold\">Root</a>";
  346.     }
  347.     modtwo($tid, $score, $reason);
  348.     echo " ]";
  349.     modthree($sid, $mode, $order, $thold);
  350.     include("footer.php");
  351. }
  352.  
  353. function reply ($pid, $sid, $mode, $order, $thold) {
  354.     include("mainfile.php");
  355.     include("header.php");
  356.     global $user, $cookie, $datetime, $bgcolor1, $bgcolor2, $bgcolor3;
  357.     if($pid!=0) {
  358.         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"));
  359.     } else {
  360.         list($date, $subject, $temp_comment, $comment, $name, $notes) = mysql_fetch_row(mysql_query("select time, title, hometext, bodytext, informant, notes FROM stories where sid=$sid"));
  361.     }
  362.     if($comment == "") $comment = $temp_comment;
  363.     $titlebar = "<b>$subject</b>";
  364.     if($name == "") $name = $anonymous;
  365.     if($subject == "") $subject = "[".translate("No Subject")."]";
  366.     echo "<table width=99% border=0><tr bgcolor=\"$bgcolor1\"><td width=500>";
  367.     formatTimestamp($date);
  368.     if($email) {
  369.         echo "<p><b>$subject</b> <font size=2>";
  370.         if(!$temp_comment) echo"(".translate("Score: ")."$score)";
  371.         echo "<br>".translate("by")." <a href=\"mailto:$email\"><font color=\"$bgcolor2\">$name</font></a> <font size=2><b>($email)</b></font> ".translate("on")." $datetime";
  372.     } else {
  373.         echo "<p><b>$subject</b> <font size=2>";
  374.         if(!$temp_comment) echo"(".translate("Score: ")."$score)";
  375.         echo "<br>".translate("by")." $name ".translate("on")." $datetime";
  376.     }
  377.     echo "</td></tr><tr><td>$comment $notes</td></tr></table><hr>";
  378.  
  379.     if(!isset($pid) || !isset($sid)) { echo "Something is not right. This message is just to keep things from messing up down the road"; exit(); }
  380.     if($pid == 0) {
  381.         list($subject) = mysql_fetch_row(mysql_query("select title from stories where sid=$sid"));
  382.     } else {
  383.         list($subject) = mysql_fetch_row(mysql_query("select subject from comments where tid=$pid"));
  384.     }
  385.  
  386.     echo "<form action=\"comments.php\" method=post>";
  387.     echo "<P><FONT color=\"$bgcolor2\"><B>".translate("Your Name").":</B></FONT> ";
  388.     if ($user) {
  389.         cookiedecode($user);
  390.         echo "<a href=\"user.php\">$cookie[1]</a> <font size=2>[ <a href=\"user.php?op=logout\">".translate("Logout")."</a> ]</font>";
  391.     } else {
  392.         echo "<font color=Red>$anonymous<font color=Black>";
  393.         echo " [ <a href=user.php>".translate("New User")."</a> ] ";
  394.     }
  395.     echo "<P><FONT color=\"$bgcolor2\"><B>".translate("Subject")."</B></FONT><BR>";
  396.     if (!eregi("Re:",$subject)) $subject = "Re: $subject";
  397.     echo "<input class=textbox type=\"text\" NAME=\"subject\" SIZE=50 maxlength=60 value=\"$subject\"><BR>";
  398.     echo "<P><FONT color=\"$bgcolor2\"><B>".translate("Comment")."</B></FONT><BR>"
  399.         ."<TEXTAREA class=textbox wrap=virtual cols=50 rows=10 name=comment></TEXTAREA><br>
  400.         <font size=2>".translate("Allowed HTML:")."<br>";
  401.         while (list($key,)= each($AllowableHTML)) echo " <".$key.">";
  402.         echo "<br>";
  403.     if ($user) { echo "<input type=checkbox name=xanonpost> ".translate("Post Anonymously")."<br>"; }
  404.     echo "<input class=textbox type=\"hidden\" name=\"pid\" value=\"$pid\">"
  405.         ."<input class=textbox type=\"hidden\" name=\"sid\" value=\"$sid\"><input class=textbox type=\"hidden\" name=\"mode\" value=\"$mode\">"
  406.         ."<input class=textbox type=\"hidden\" name=\"order\" value=\"$order\"><input class=textbox type=\"hidden\" name=\"thold\" value=\"$thold\">"
  407.         ."<input type=submit name=op value=\"Preview\">"
  408.         ."<input type=submit name=op value=\"Ok!\"> <SELECT name=\"posttype\"><OPTION value=\"exttrans\">".translate("Extrans (html tags to text)")."<OPTION value=\"html\" >".translate("HTML Formatted")."<OPTION value=\"plaintext\" SELECTED>".translate("Plain Old Text")."</SELECT></FORM><br>";
  409.         
  410.     include("footer.php");
  411. }
  412.  
  413. function replyPreview ($pid, $sid, $subject, $comment, $xanonpost, $mode, $order, $thold, $posttype) {
  414.     include("mainfile.php");
  415.     include("header.php");
  416.     global $user, $cookie;
  417.     cookiedecode($user);
  418.     $subject = stripslashes($subject);
  419.     $comment = stripslashes($comment);
  420.     if (!isset($pid) || !isset($sid)) { echo "Something is not right with passing a variable to this function. This message is just to keep things from messing up down the road"; exit(); }
  421.     echo "<table width=99% border=0><tr><td>";
  422.     echo "<p><b>$subject</b>";
  423.     echo "<br><font size=2>".translate("by")." ";
  424.     if ($user) echo "$cookie[1]";
  425.     else echo "$anonymous";
  426.     echo "".translate(" on...")."</font></td></tr><tr><td>";
  427.     if($posttype=="exttrans") echo nl2br(htmlspecialchars($comment));
  428.     elseif($posttype=="plaintext") echo nl2br($comment);
  429.     else echo $comment;
  430.     echo "</td></tr></table><br>";
  431.  
  432.     echo "<hr>";
  433.  
  434.     echo "<form action=\"comments.php\" method=post><P><FONT color=\"$bgcolor2\"><B>".translate("Your Name")."</B></FONT> ";
  435.     if ($user) echo "<a href=\"user.php\">$cookie[1]</a> <font size=2>[ <a href=\"user.php?op=logout\">".translate("Logout")."</a> ]</font>";
  436.     else echo "$anonymous";
  437.     echo "<P><FONT color=\"$bgcolor2\"><B>".translate("Subject")."</B></FONT><BR>"
  438.         ."<input class=textbox type=\"text\" NAME=\"subject\" SIZE=50 maxlength=60 value=\"$subject\"><br>"
  439.         ."<P><FONT color=\"$bgcolor2\"><B>".translate("Comment")."</B></FONT><BR>"
  440.         ."<TEXTAREA class=textbox wrap=virtual cols=50 rows=10 name=comment>$comment</TEXTAREA><br>";
  441.         echo"<font size=2>".translate("Allowed HTML:")."<br>";
  442.         while (list($key,) = each($AllowableHTML)) echo " <".$key.">";
  443.         echo "<br>";        
  444.     if ($xanonpost) { echo "<input class=textbox type=checkbox name=xanonpost checked> ".translate("Post Anonymously")."<br>"; } elseif($user) { echo "<input class=textbox type=checkbox name=xanonpost> ".translate("Post Anonymously")."<br>"; }
  445.     echo "<input class=textbox type=\"hidden\" name=\"pid\" value=\"$pid\">"
  446.         ."<input class=textbox type=\"hidden\" name=\"sid\" value=\"$sid\"><input class=textbox type=\"hidden\" name=\"mode\" value=\"$mode\">"
  447.         ."<input class=textbox type=\"hidden\" name=\"order\" value=\"$order\"><input class=textbox type=\"hidden\" name=\"thold\" value=\"$thold\">"
  448.         ."<input type=submit name=op value=\"Preview\">"
  449.         ."<input type=submit name=op value=\"Ok!\"> <SELECT name=\"posttype\"><OPTION value=\"exttrans\"";
  450.         if($posttype=="exttrans") echo" SELECTED";
  451.         echo  ">".translate("Extrans (html tags to text)")."<OPTION value=\"html\"";;
  452.         if($posttype=="html") echo" SELECTED";
  453.         echo ">".translate("HTML Formatted")."<OPTION value=\"plaintext\"";
  454.         if(($posttype!="exttrans") && ($posttype!="html")) echo" SELECTED";
  455.         echo ">".translate("Plain Old Text")."</SELECT></FORM><br>";
  456.  
  457.     include("footer.php");
  458. }
  459.  
  460. function CreateTopic ($xanonpost, $subject, $comment, $pid, $sid, $host_name, $mode, $order, $thold, $posttype) {
  461.     global $user, $userinfo, $EditedMessage, $cookie, $AllowableHTML, $ultramode;
  462.     include("mainfile.php");
  463.     cookiedecode($user);
  464.     $author = FixQuotes($author);
  465.     $subject = FixQuotes(filter_text($subject, "nohtml"));
  466.     if($posttype=="exttrans")
  467.         $comment = FixQuotes(nl2br(htmlspecialchars(check_words($comment))));
  468.     elseif($posttype=="plaintext")
  469.         $comment = FixQuotes(nl2br(filter_text($comment)));
  470.     else
  471.         $comment = FixQuotes(filter_text($comment));
  472.     if($user) getusrinfo($user);
  473.     if (($user) && (!$xanonpost)) {
  474.         getusrinfo($user);
  475.         $name = $userinfo[uname];
  476.         $email = $userinfo[femail];
  477.         $url = $userinfo[url];
  478.         $score = 1;
  479.     } else {
  480.         $name = ""; $email = ""; $url = "";
  481.         $score = 0;
  482.     }
  483.     $ip = getenv("REMOTE_ADDR");
  484. //begin fake thread control
  485.     list($fake) = mysql_fetch_row(mysql_query("select count(*) from stories where sid=$sid"));
  486.     mysql_query("LOCK TABLES comments WRITE");
  487. //begin duplicate control
  488.     list($tia) = mysql_fetch_row(mysql_query("select count(*) from comments where pid='$pid' and sid='$sid' and subject='$subject' and comment='$comment'"));
  489. //begin troll control
  490.     if($user) {
  491.         list($troll) = mysql_fetch_row(mysql_query("select count(*) from comments where (score=-1) and (name='$userinfo[uname]') and (to_days(now()) - to_days(date) < 3)"));
  492.     } elseif(!$score) {
  493.         list($troll) = mysql_fetch_row(mysql_query("select count(*) from comments where (score=-1) and (host_name='$ip') and (to_days(now()) - to_days(date) < 3)"));
  494.     }
  495.     if((!$tia) && ($fake == 1) && ($troll < 6)) {
  496.         mysql_query("insert into comments values (NULL, '$pid', '$sid', now(), '$name', '$email', '$url', '$ip', '$subject', '$comment', '$score', '0')");
  497.     } else {
  498.         mysql_query("UNLOCK TABLES");
  499.         include("header.php");
  500.         if($tia) echo "Duplicate.  Did you submit twice?<br><br><a href=\"article.php?sid=$sid&mode=$mode&order=$order&thold=$thold\">Back to comments</a>";
  501.         elseif($troll > 5) echo "This account or IP has been temporarily disabled.
  502.                 This means that either this IP, or
  503.                 user account has been moderated down more than 5 times in
  504.                 the last few hours.  If you think this is unfair,
  505.                 you should contact the admin.  If you
  506.                 are being a troll, now is the time for you to either
  507.                 grow up, or change your IP.<br><br><a href=\"article.php?sid=$sid&mode=$mode&order=$order&thold=$thold\">Back to comments</a>";
  508.         elseif($fake == 0) echo "According to my records, the topic you are trying 
  509.                 to reply to does not exist. If you're just trying to be 
  510.                 annoying, well then too bad.";
  511.         include("footer.php");
  512.         exit;
  513.     }
  514.     mysql_query("UNLOCK TABLES");
  515.     mysql_query("update stories set comments=comments+1 where sid='$sid'");
  516.     if ($ultramode) {
  517.         ultramode();
  518.     }
  519.     if (isset($cookie[4])) { $options .= "&mode=$cookie[4]"; } else { $options .= "&mode=thread"; }
  520.     if (isset($cookie[5])) { $options .= "&order=$cookie[5]"; } else { $options .= "&order=0"; }
  521.     if (isset($cookie[6])) { $options .= "&thold=$cookie[6]"; } else { $options .= "&thold=0"; }
  522.     Header("Location: article.php?sid=$sid$options");
  523. }
  524.  
  525. switch($op) {
  526.  
  527.     case "Reply":
  528.         reply($pid, $sid, $mode, $order, $thold);
  529.         break;
  530.  
  531.     case "Preview":
  532.         replyPreview ($pid, $sid, $subject, $comment, $xanonpost, $mode, $order, $thold, $posttype);
  533.         break;
  534.  
  535.     case "Ok!":
  536.         CreateTopic($xanonpost, $subject, $comment, $pid, $sid, $host_name, $mode, $order, $thold, $posttype);
  537.         break;
  538.  
  539.     case "moderate":
  540.         if(isset($admin)) {
  541.             include("auth.inc.php");
  542.         } else {
  543.             include("mainfile.php");    
  544.         }
  545.         if(($admintest==1) || ($moderate==2)) {
  546.             while(list($tdw, $emp) = each($HTTP_POST_VARS)) {
  547.                 if (eregi("dkn",$tdw)) {
  548.                     $emp = explode(":", $emp);
  549.                     if($emp[1] != 0) {
  550.                         $tdw = ereg_replace("dkn", "", $tdw);
  551.                         $q = "UPDATE comments SET";
  552.                         if(($emp[1] == 9) && ($emp[0]>=0)) { # Overrated
  553.                             $q .= " score=score-1 where tid=$tdw";
  554.                         } elseif (($emp[1] == 10) && ($emp[0]<=4)) { # Underrated
  555.                             $q .= " score=score+1 where tid=$tdw";
  556.                         } elseif (($emp[1] > 4) && ($emp[0]<=4)) {
  557.                             $q .= " score=score+1, reason=$emp[1] where tid=$tdw";
  558.                         } elseif (($emp[1] < 5) && ($emp[0] > -1)) {
  559.                             $q .= " score=score-1, reason=$emp[1] where tid=$tdw";
  560.                         } elseif (($emp[0] == -1) || ($emp[0] == 5)) {
  561.                             $q .= " reason=$emp[1] where tid=$tdw";
  562.                         }
  563.                         if(strlen($q) > 20) mysql_query("$q");
  564.                     }
  565.                 }
  566.             }
  567.         }
  568.         Header("Location: article.php?sid=$sid&mode=$mode&order=$order&thold=$thold");
  569.         break;
  570.  
  571.     case "showreply":
  572.         DisplayTopic($sid, $pid, $tid, $mode, $order, $thold);
  573.         break;
  574.  
  575.     default:
  576.         if ((isset($tid)) && (!isset($pid))) {
  577.             singlecomment($tid, $sid, $mode, $order, $thold);
  578.         } elseif (($mainfile) xor (($pid==0) || (!isset($pid)))) {
  579.             Header("Location: article.php?sid=$sid&mode=$mode&order=$order&thold=$thold");
  580.         } else {
  581.             if(!isset($pid)) $pid=0;
  582.             DisplayTopic($sid, $pid, $tid, $mode, $order, $thold);
  583.         }
  584.         break;
  585. }
  586.  
  587. ?>