home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 March / PCWorld_2001-03_cd.bin / KOMUNIK / progweb / progweb.exe / phpnuke / html / mainfile.php < prev    next >
PHP Script  |  2000-12-05  |  25KB  |  663 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 a collection of some usefull global functions
  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. include("config.php");
  18. include("language/lang-$language.php");
  19. mysql_pconnect($dbhost, $dbuname, $dbpass);
  20. @mysql_select_db("$dbname") or die ("Unable to select database");
  21. $mainfile = 1;
  22.  
  23. function dbconnect() {
  24.     global $dbhost, $dbuname, $dbpass, $dbname;
  25.     mysql_pconnect($dbhost, $dbuname, $dbpass);
  26.     @mysql_select_db("$dbname") or die ("Unable to select database");
  27. }
  28.  
  29. function ultramode() {
  30. //    global $nuke_url;
  31. //    $ultradir = dirname($PHP_SELF);
  32.     $ultra = "ultramode.txt";
  33. //    $ultra = "$ultradir$ul";
  34.     $file = fopen("$ultra", "w");
  35.     fwrite($file, "General purpose self-explanatory file with news headlines\n");
  36.     $rfile=mysql_query("select sid, aid, title, time, comments, topic from stories order by time DESC limit 0,10");
  37.     while(list($sid, $aid, $title, $time, $comments, $topic) = mysql_fetch_row($rfile)) {
  38.     $rfile2=mysql_query("select topictext, topicimage from topics where topicid=$topic");
  39.     list($topictext, $topicimage) = mysql_fetch_row($rfile2);
  40.     $content = "%%\n$title\n/article.php?sid=$sid\n$time\n$aid\n$topictext\n$comments\n$topicimage\n";
  41.     fwrite($file, $content);
  42.     }
  43.     fclose($file);
  44. }
  45.  
  46. function counter() {
  47.     mysql_query("UPDATE vars SET value=value+1 where name='totalhits'");
  48. }
  49.  
  50. function cookiedecode($user) {
  51.     global $cookie;
  52.     $user = base64_decode($user);
  53.     $cookie = explode(":", $user);
  54.     return $cookie;
  55. }
  56.  
  57. function getusrinfo($user) {
  58.     global $userinfo;
  59.     $user2 = base64_decode($user);
  60.     $user3 = explode(":", $user2);
  61.     $result = mysql_query("select uid, name, uname, email, femail, url, pass, storynum, umode, uorder, thold, noscore, bio, ublockon, ublock, theme, commentmax from users where uname='$user3[1]' and pass='$user3[2]'");
  62.     if(mysql_num_rows($result)==1) {
  63.         $userinfo = mysql_fetch_array($result);
  64.     } else {
  65.         echo "<b>A problem occured</b><br>";
  66.     }
  67.     return $userinfo;
  68. }
  69.  
  70. function FixQuotes ($what = "") {
  71.     $what = ereg_replace("'","''",$what);
  72.     while (eregi("\\\\'", $what)) {
  73.         $what = ereg_replace("\\\\'","'",$what);
  74.     }
  75.     return $what;
  76. }
  77.  
  78. /*********************************************************/
  79. /* text filter                                           */
  80. /*********************************************************/
  81.  
  82. function check_words($Message) {
  83.     global $EditedMessage, $CensorList, $CensorMode, $CensorReplace;
  84.     $EditedMessage = $Message;
  85.     if ($CensorMode != 0) {
  86.         if (is_array($CensorList)) {
  87.             $Replacement = $CensorReplace;
  88.  
  89.             if ($CensorMode == 1) { # Exact match
  90.                 $RegExPrefix   = '([^[:alpha:]]|^)';
  91.                 $RegExSuffix   = '([^[:alpha:]]|$)';
  92.             } elseif ($CensorMode == 2) {    # Word beginning
  93.                 $RegExPrefix   = '([^[:alpha:]]|^)';
  94.                 $RegExSuffix   = '[[:alpha:]]*([^[:alpha:]]|$)';
  95.             } elseif ($CensorMode == 3) {    # Word fragment
  96.                 $RegExPrefix   = '([^[:alpha:]]*)[[:alpha:]]*';
  97.                 $RegExSuffix   = '[[:alpha:]]*([^[:alpha:]]*)';
  98.             }
  99.  
  100.             for ($i = 0; $i < count($CensorList) && $RegExPrefix != ''; $i++) {
  101.                 $EditedMessage = eregi_replace($RegExPrefix.$CensorList[$i].$RegExSuffix,"\\1$Replacement\\2",$EditedMessage);
  102.             }
  103.         }
  104.     }
  105.     return ($EditedMessage);
  106. }
  107.  
  108.  
  109. function delQuotes($string){ 
  110. # no recursive function to add quote to an HTML tag if needed
  111. # and delete duplicate spaces between attribs.
  112.     $tmp="";    # string buffer
  113.     $result=""; # result string
  114.     $i=0;
  115.     $attrib=-1; # Are us in an HTML attrib ?   -1: no attrib   0: name of the attrib   1: value of the atrib
  116.     $quote=0;   # Is a string quote delimited opened ? 0=no, 1=yes
  117.     $len = strlen($string);
  118.     while ($i<$len) {
  119.         switch($string[$i]) { # What car is it in the buffer ?
  120.             case "\"": #"       # a quote. 
  121.                 if ($quote==0) {
  122.                     $quote=1;
  123.                 } else {
  124.                     $quote=0;
  125.                     if (($attrib>0) && ($tmp != "")) { $result .= "=\"$tmp\""; }
  126.                     $tmp="";
  127.                     $attrib=-1;
  128.                 }
  129.                 break;
  130.             case "=":           # an equal - attrib delimiter
  131.                 if ($quote==0) {  # Is it found in a string ?
  132.                     $attrib=1;
  133.                     if ($tmp!="") $result.=" $tmp";
  134.                     $tmp="";
  135.                 } else $tmp .= '=';
  136.                 break;
  137.             case " ":           # a blank ?
  138.                 if ($attrib>0) {  # add it to the string, if one opened.
  139.                     $tmp .= $string[$i];
  140.                 }
  141.                 break;
  142.             default:            # Other
  143.                 if ($attrib<0)    # If we weren't in an attrib, set attrib to 0
  144.                     $attrib=0;
  145.                 $tmp .= $string[$i];
  146.                 break;
  147.         }
  148.         $i++;
  149.     }
  150.     if (($quote!=0) && ($tmp != "")) {
  151.         if ($attrib==1) $result .= "="; 
  152.     # If it is the value of an atrib, add the '='
  153.         $result .= "\"$tmp\"";# Add quote if needed (the reason of the function ;-)
  154.     }
  155.     #  echo $result;echo ".....";
  156.     return $result;
  157. }
  158.  
  159.  
  160. function check_html ($str, $strip="") {
  161. // The core of this code has been lifted from phpslash
  162. // which is licenced under the GPL.
  163.     include("config.php");
  164.     if ($strip == "nohtml")
  165.         $AllowableHTML=array('');
  166.     $str = stripslashes($str);
  167.     $str = eregi_replace("<[[:space:]]*([^>]*)[[:space:]]*>",
  168.                          '<\\1>', $str);
  169.                // Delete all spaces from html tags .
  170.     $str = eregi_replace("<a[^>]*href[[:space:]]*=[[:space:]]*\"?[[:space:]]*([^\" >]*)[[:space:]]*\"?[^>]*>",
  171.                          '<a href="\\1">', $str); # "
  172.                // Delete all attribs from Anchor, except an href, double quoted.
  173.     $tmp = "";
  174.     while (ereg("<(/?[[:alpha:]]*)[[:space:]]*([^>]*)>",$str,$reg)) {
  175.         $i = strpos($str,$reg[0]);
  176.         $l = strlen($reg[0]);
  177.         if ($reg[1][0] == "/") $tag = strtolower(substr($reg[1],1));
  178.         else $tag = strtolower($reg[1]);  
  179.         if ($a = $AllowableHTML[$tag])
  180.             if ($reg[1][0] == "/") $tag = "</$tag>";
  181.             elseif (($a == 1) || ($reg[2] == "")) $tag = "<$tag>";
  182.             else {
  183.               # Place here the double quote fix function.
  184.               $attrb_list=delQuotes($reg[2]);
  185.               $tag = "<$tag" . $attrb_list . ">";
  186.             } # Attribs in tag allowed
  187.         else $tag = "";
  188.         $tmp .= substr($str,0,$i) . $tag;
  189.         $str = substr($str,$i+$l);
  190.     }
  191.     $str = $tmp . $str;
  192.     return $str;
  193.     exit;
  194.     // Squash PHP tags unconditionally
  195.     $str = ereg_replace("<\?","",$str);
  196.     return $str;
  197. }
  198.  
  199. function filter_text($Message, $strip="") {
  200.     global $EditedMessage;
  201.     check_words($Message);
  202.     $EditedMessage=check_html($EditedMessage, $strip);
  203.     return ($EditedMessage);
  204. }
  205.  
  206. /*********************************************************/
  207. /* formatting stories                                    */
  208. /*********************************************************/
  209.  
  210. function formatTimestamp($time) {
  211.     global $datetime, $locale;
  212.     setlocale ("LC_TIME", "$locale");
  213.     ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime);
  214.     $datetime = strftime("".translate("datestring")."", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
  215.     $datetime = ucfirst($datetime);
  216.     return($datetime);
  217. }
  218.  
  219. function formatAidHeader($aid) {
  220.     $holder = mysql_query("SELECT url, email FROM authors where aid='$aid'");
  221.     if (!$holder) { echo mysql_errno(). ": ".mysql_error(). "<br>";    exit(); }
  222.     list($url, $email) = mysql_fetch_row($holder);
  223.     if (isset($url)) { echo "<a href=\"$url\">$aid</a>";
  224.     } elseif (isset($email)) { echo "<a href=\"mailto:$email\">$aid</a>";
  225.     } else { echo $aid; }
  226. }
  227.  
  228. function oldNews($storynum) {
  229.     global $locale, $oldnum, $storyhome, $cookie;
  230.     $storynum = $storyhome;
  231.     $boxstuff = "";
  232.     $boxTitle = translate("Past Articles");
  233.     $result = mysql_query("select sid, title, time, comments from stories order by time desc limit $storynum, $oldnum");
  234.     $vari = 0;
  235.     if (isset($cookie[4])) { $options .= "&mode=$cookie[4]"; } else { $options .= "&mode=thread"; }
  236.     if (isset($cookie[5])) { $options .= "&order=$cookie[5]"; } else { $options .= "&order=0"; }
  237.     if (isset($cookie[6])) { $options .= "&thold=$cookie[6]"; } else { $options .= "&thold=0"; }
  238.     while(list($sid, $title, $time, $comments) = mysql_fetch_row($result)) {
  239.         setlocale ("LC_TIME", "$locale");
  240.         ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime2);
  241.         $datetime2 = strftime("".translate("datestring2")."", mktime($datetime2[4],$datetime2[5],$datetime2[6],$datetime2[2],$datetime2[3],$datetime2[1]));
  242.         $datetime2 = ucfirst($datetime2);
  243.         if($time2==$datetime2) {
  244.         $boxstuff .= "<li><a href=\"article.php?sid=$sid$options\">$title</a> ($comments)\n";
  245.         } else {
  246.         if($a=="") {
  247.             $boxstuff .= "<b>$datetime2</b><br><br><li><a href=\"article.php?sid=$sid$options\">$title</a> ($comments)\n";
  248.             $time2 = $datetime2;
  249.             $a = 1;
  250.         } else {
  251.             $boxstuff .= "<br><br><b>$datetime2</b><br><br><li><a href=\"article.php?sid=$sid$options\">$title</a> ($comments)\n";
  252.             $time2 = $datetime2;
  253.         }
  254.         }
  255.         $vari++;
  256.         if ($vari==$oldnum) {
  257.         if (isset($cookie[3])) $storynum = $cookie[3]; else $storynum = $storyhome;
  258.         $min = $oldnum + $storynum;
  259.         $boxstuff .= "<br><p align=right><font size=1><a href=search.php?min=$min&type=stories><b>".translate("Older Articles")."</b></a></font>\n";
  260.         }
  261.     
  262.     }
  263.     themesidebox($boxTitle, $boxstuff);
  264. }
  265.  
  266. function mainblock() {
  267.     $result = mysql_query("select title, content from mainblock");
  268.     while(list($title, $content) = mysql_fetch_array($result)) {
  269.         $content = nl2br($content);
  270.         themesidebox($title, $content);
  271.     }
  272. }
  273.  
  274. function rightblocks() {
  275.     $result = mysql_query("select title, content from rblocks");
  276.     while(list($title, $content) = mysql_fetch_array($result)) {
  277.         $content = nl2br($content);
  278.         themesidebox($title, $content);
  279.     }
  280. }
  281.  
  282. function leftblocks() {
  283.     $result = mysql_query("select title, content from lblocks");
  284.     while(list($title, $content) = mysql_fetch_array($result)) {
  285.         $content = nl2br($content);
  286.         themesidebox($title, $content);
  287.     }
  288. }
  289.  
  290. function adminblock() {
  291.     $result = mysql_query("select title, content from adminblock");
  292.     while(list($title, $content) = mysql_fetch_array($result)) {
  293.         $content = nl2br($content);
  294.         themesidebox($title, $content);
  295.     }
  296. }
  297.  
  298. function ephemblock() {
  299.     $today = getdate();
  300.     $eday = $today[mday];
  301.     $emonth = $today[mon];
  302.         $result = mysql_query("select yid, content from ephem where did='$eday' AND mid='$emonth'");
  303.     $title = "".translate("Ephemerids")."";
  304.     $boxstuff = "<center><b>".translate("One Day like Today...")."</b></center><br>";
  305.     while(list($yid, $content) = mysql_fetch_array($result)) {
  306.         if ($cnt==1) {
  307.         $boxstuff .= "<br><br>";
  308.         }
  309.         $boxstuff .= "<b>$yid</b><br>";
  310.             $boxstuff .= "$content";
  311.         $cnt = 1;
  312.     }
  313.     themesidebox($title, $boxstuff);
  314. }
  315.  
  316. function loginbox() {
  317.     $title = "$sitename Login";
  318.     $boxstuff .= "<form action=user.php method=post>";
  319.     $boxstuff .= "<font size=1><center>".translate("Nickname")."<br>";
  320.     $boxstuff .= "<input type=text name=uname size=12 maxlength=25><br>";
  321.     $boxstuff .= "".translate("Password")."<br>";
  322.     $boxstuff .= "<input type=password name=pass size=12 maxlength=20><br>";
  323.     $boxstuff .= "<input type=hidden name=op value=login>";
  324.     $boxstuff .= "<input type=submit value=".translate("Login")."></form>";
  325.     $boxstuff .= "".translate("Don't have an account yet? You can")."";
  326.     $boxstuff .= " <a href=user.php>".translate("create one")."</a>.";
  327.     $boxstuff .= " ".translate("As registered")."";
  328.     $boxstuff .= " ".translate("user you have some advantages like theme manager,")."";
  329.     $boxstuff .= " ".translate("comments configuration and post comments with your name.")."";
  330.     $boxstuff .= "</center>";
  331.     themesidebox($title, $boxstuff);
  332. }
  333.  
  334. /*********************************************************/
  335. /* poll functions                                        */
  336. /*********************************************************/
  337.  
  338. function pollMain($pollID) {
  339.     global $maxOptions, $boxTitle, $boxContent, $uimages, $pollcomm;
  340.     if(!isset($pollID))
  341.       $pollID = 1;
  342.     if(!isset($url))
  343.       $url = sprintf("pollBooth.php?op=results&pollID=%d", $pollID);
  344.     $boxContent .= "<form action=\"pollBooth.php\" method=\"post\">";
  345.     $boxContent .= "<input type=\"hidden\" name=\"pollID\" value=\"".$pollID."\">";
  346.     $boxContent .= "<input type=\"hidden\" name=\"forwarder\" value=\"".$url."\">";
  347.     $result = mysql_query("SELECT pollTitle, voters FROM poll_desc WHERE pollID=$pollID");
  348.     list($pollTitle, $voters) = mysql_fetch_row($result);
  349.     $boxTitle = translate("Survey");
  350.     $boxContent .= "<font size=2><b>$pollTitle</b></font><br><br>\n";
  351.     for($i = 1; $i <= $maxOptions; $i++) {
  352.         $result = mysql_query("SELECT pollID, optionText, optionCount, voteID FROM poll_data WHERE (pollID=$pollID) AND (voteID=$i)");
  353.         $object = mysql_fetch_object($result);
  354.         if(is_object($object)) {
  355.             $optionText = $object->optionText;
  356.             if($optionText != "") {
  357.                 $boxContent .= "<input type=\"radio\" name=\"voteID\" value=\"".$i."\"> $optionText <br>\n";
  358.             }
  359.         }
  360.     }
  361.     $boxContent .= "<br><center><table cellspacing=0 cellpadding=5 border=0 width=111><tr><td align=center> <input type=image src=$uimages/vote.gif border=0></td><td align=center>\n";
  362.     global $user, $cookie;
  363.     cookiedecode($user);
  364.     
  365.     $result = mysql_query("SELECT SUM(optionCount) AS SUM FROM poll_data WHERE pollID=$pollID");
  366.     $sum = (int)mysql_result($result, 0, "SUM");
  367.     
  368.     $boxContent .= "<a href=\"pollBooth.php?op=results&pollID=$pollID&mode=$cookie[4]&order=$cookie[5]&thold=$cookie[6]\"><img src=$uimages/result.gif border=0></a></td></tr></table></form><font size=1><b><a href=\"pollBooth.php\">".translate("Past Surveys")."</a></b></font><br>";
  369.     if ($pollcomm) {
  370.         list($numcom) = mysql_fetch_row(mysql_query("select count(*) from pollcomments where pollID=$pollID"));
  371.         $boxContent .= "<br>".translate("Votes: ")."<b>$sum</b> | ".translate("comments:")."  <b>$numcom</b>\n";
  372.     } else {
  373.         $boxContent .= "<br>".translate("Votes: ")."<b>$sum</b>\n";
  374.     }
  375.     $boxContent .= "</center>\n\n";
  376.     themesidebox($boxTitle, $boxContent);
  377. }
  378.  
  379. function pollLatest() {
  380.     $result = mysql_query("SELECT pollID FROM poll_data ORDER BY pollID DESC");
  381.     $pollID = mysql_fetch_row($result);
  382.     return($pollID[0]);
  383. }
  384.  
  385. function pollNewest() {
  386.     $pollID = pollLatest();
  387.     pollMain($pollID);
  388. }
  389.  
  390. function pollCollector($pollID, $voteID, $forwarder) {
  391.     global $maxOptions, $setCookies, $cookiePrefix, $HTTP_COOKIE_VARS;
  392.     $voteValid = "1";
  393.     if($setCookies>0) {
  394.         // we have to check for cookies, so get timestamp of this poll
  395.         $result = mysql_query("SELECT timeStamp FROM poll_desc WHERE pollID=$pollID");
  396.         $object = mysql_fetch_object($result);
  397.         $timeStamp = $object->timeStamp;
  398.         $cookieName = $cookiePrefix.$timeStamp;
  399.  
  400.         // check if cookie exists
  401.         if($HTTP_COOKIE_VARS["$cookieName"] == "1") {
  402.             // cookie exists, invalidate this vote
  403.             $warn = "You already voted today!";
  404.             $voteValid = "0";
  405.         } else {
  406.             // cookie does not exist yet, set one now
  407.             $cvalue = "1";
  408.             setcookie("$cookieName",$cvalue,time()+86400);
  409.         }
  410.     }
  411.     // update database if the vote is valid
  412.     if($voteValid>0) {
  413.         @mysql_query("UPDATE poll_data SET optionCount=optionCount+1 WHERE (pollID=$pollID) AND (voteID=$voteID)");
  414.         @mysql_query("UPDATE poll_desc SET voters=voters+1 WHERE pollID=$pollID");
  415.         Header("Location: $forwarder");
  416.     } else {
  417.         Header("Location: $forwarder");
  418.     }
  419.     // a lot of browsers can't handle it if there's an empty page
  420.     echo "<html><head></head><body></body></html>";
  421. }
  422.  
  423. function pollList() {
  424.     global $user, $cookie;
  425.     $result = mysql_query("SELECT pollID, pollTitle, timeStamp, voters FROM poll_desc ORDER BY timeStamp"); 
  426.     $counter = 0;
  427.     echo "<table border=0 cellpadding=8><tr><td>";
  428.     echo "<font size=3>";
  429.  
  430.  
  431.  
  432.     while($object = mysql_fetch_object($result)) {
  433.         $resultArray[$counter] = array($object->pollID, $object->pollTitle, $object->timeStamp, $object->voters);
  434.         $counter++;
  435.     }
  436.  
  437.  
  438.     for ($count = 0; $count < count($resultArray); $count++) {
  439.         $id = $resultArray[$count][0];
  440.         $pollTitle = $resultArray[$count][1];
  441.         $voters = $resultArray[$count][3];
  442.         $result2 = mysql_query("SELECT SUM(optionCount) AS SUM FROM poll_data WHERE pollID=$id");
  443.         $sum = (int)mysql_result($result2, 0, "SUM");
  444.  
  445.         echo("<li> <a href=\"pollBooth.php?pollID=$id\">$pollTitle</a> ");
  446.         echo("(<a href=\"pollBooth.php?op=results&pollID=$id&mode=$cookie[4]&order=$cookie[5]&thold=$cookie[6]\">".translate("Results")."</a> - $sum ".translate("votes").")\n");
  447.     }
  448.     echo "</td></tr></table>";
  449. }
  450.  
  451. function pollResults($pollID) {
  452.     global $maxOptions, $BarScale, $resultTableBgColor, $resultBarFile, $setCookies;
  453.     if(!isset($pollID)) $pollID = 1;
  454.     $result = mysql_query("SELECT pollID, pollTitle, timeStamp FROM poll_desc WHERE pollID=$pollID");
  455.     $holdtitle = mysql_fetch_row($result);
  456.     echo "<br><b>$holdtitle[1]</b><br><br>";
  457.     mysql_free_result($result);
  458.     $result = mysql_query("SELECT SUM(optionCount) AS SUM FROM poll_data WHERE pollID=$pollID");
  459.     $sum = (int)mysql_result($result, 0, "SUM"); 
  460.     mysql_free_result($result);
  461.     echo "<table>";
  462.     // cycle through all options
  463.     for($i = 1; $i <= $maxOptions; $i++) {
  464.         // select next vote option
  465.         $result = mysql_query("SELECT pollID, optionText, optionCount, voteID FROM poll_data WHERE (pollID=$pollID) AND (voteID=$i)");
  466.         $object = mysql_fetch_object($result);
  467.         if(is_object($object)) {
  468.             $optionText = $object->optionText;
  469.             $optionCount = $object->optionCount;
  470.             if($optionText != "") {
  471.                 echo "<td>";
  472.                 echo "$optionText";
  473.                 echo "</td>";
  474.                 if($sum) {
  475.                     $percent = 100 * $optionCount * $BarScale / $sum;
  476.                 } else {
  477.                     $percent = 0;
  478.                 }
  479.                 echo "<td>";
  480.                 $percentInt = (int)$percent * 4;
  481.                 $percent2 = (int)$percent;
  482.                 if ($percent > 0) {
  483.                     echo "<img src=\"images/leftbar.gif\" height=14 width=7>";
  484.                     echo "<img src=\"images/mainbar.gif\" height=14 width=$percentInt Alt=\"$percent2 %\">";
  485.                     echo "<img src=\"images/rightbar.gif\" height=14 width=7>";
  486.                 } else {
  487.                     echo "<img src=\"images/leftbar.gif\" height=14 width=7 Alt=\"$percent2 %\">";
  488.                     echo "<img src=\"images/mainbar.gif\" height=14 width=3 Alt=\"$percent2 %\">";
  489.                     echo "<img src=\"images/rightbar.gif\" height=14 width=7 Alt=\"$percent2 %\">";
  490.                 }
  491.                                 printf(" %.2f %% (%d)", $percent, $optionCount);
  492.                 echo "</td>";
  493.                 }
  494.         }
  495.         echo "</tr>";
  496.     }
  497.     echo "</td></tr></table><br>";
  498.     echo "<center><b>".translate("Total Votes: ")."$sum</b><br>";
  499.     if($setCookies>0) {
  500.         echo "<font size=1>".translate("We allow just one vote per day")."</font><br><br><font size=3>";
  501.     } else {
  502.         echo "<br><br>";
  503.     }
  504.     $booth = $pollID;
  505.     echo("[ <a href=\"pollBooth.php?pollID=$booth\">".translate("Voting Booth")."</a> | ");
  506.     echo("<a href=\"pollBooth.php\">".translate("Other Polls")."</a> ]</font>");
  507.     return(1);
  508. }
  509.  
  510. function getTopics($s_sid) {
  511.     global $topicname, $topicimage, $topictext;
  512.     $sid = $s_sid;
  513.     $result=mysql_query("SELECT topic FROM stories where sid=$sid");
  514.     list($topic) = mysql_fetch_row($result);
  515.     $result=mysql_query("SELECT topicid, topicname, topicimage, topictext FROM topics where topicid=$topic");
  516.     list($topicid, $topicname, $topicimage, $topictext) = mysql_fetch_row($result);
  517. }
  518.  
  519.  
  520. function headlines() {
  521.     $result = mysql_query("select sitename, url, headlinesurl from headlines where status=1");
  522.     while (list($sitename, $url, $headlinesurl) = mysql_fetch_row($result)) {
  523.     $boxtitle     =     "$sitename";
  524.     $separ    =    "<li>";
  525.     $cache_file    =    "cache/$sitename.cache";
  526.     $cache_time    =    3600;
  527.     $max_items    =    10;
  528.     $target    =    "new";
  529.     $items    =    0;
  530.     $time    =    split(" ", microtime());
  531.     srand((double)microtime()*1000000);
  532.     $cache_time_rnd    =    300 - rand(0, 600);
  533.     if ( (!(file_exists($cache_file))) || ((filectime($cache_file) + $cache_time - $time[1]) + $cache_time_rnd < 0) || (!(filesize($cache_file))) ) {
  534.     $fpread = fopen($headlinesurl, 'r');
  535.     if(!$fpread) {
  536.     } else {
  537.         $fpwrite = fopen($cache_file, 'w');
  538.         if(!$fpwrite) {
  539.         } else {
  540.             while(! feof($fpread) ) {
  541.             $buffer = ltrim(Chop(fgets($fpread, 256)));
  542.             if (($buffer == "<item>") && ($items < $max_items)) {
  543.                     $title = ltrim(Chop(fgets($fpread, 256)));
  544.                 $link = ltrim(Chop(fgets($fpread, 256)));
  545.                 $title = ereg_replace( "<title>", "", $title );
  546.                 $title = ereg_replace( "</title>", "", $title );
  547.                 $title = ereg_replace( "\"", "\\\"", $title );
  548.                 $link = ereg_replace( "<link>", "", $link );
  549.                 $link = ereg_replace( "</link>", "", $link );
  550.                 fputs($fpwrite, "<?php \$boxstuff .= \"$separ<A HREF=$link TARGET=$target>$title</A>\"; ?>\n");
  551.                 $items++;
  552.             }
  553.             }
  554.         }
  555.         fclose($fpread);
  556.     }
  557.     fclose($fpwrite);
  558.     }
  559.     if (file_exists($cache_file)) {
  560.     include($cache_file);
  561.     }
  562.     themesidebox($boxtitle, $boxstuff);
  563.     $boxstuff = "";
  564.     }
  565. }
  566.  
  567. function online() {
  568.     global $user, $cookie;
  569.     cookiedecode($user);
  570.     $ip = getenv("REMOTE_ADDR");
  571.     $username = $cookie[1];
  572.     if (!isset($username)) {
  573.         $username = "$ip";
  574.         $guest = 1;
  575.     }
  576.     $past = time()-900;
  577.     mysql_query("DELETE FROM session WHERE time < $past");
  578.     $result = mysql_query("SELECT time FROM session WHERE username='$username'");
  579.     $ctime = time();
  580.     if ($row = mysql_fetch_array($result)) {
  581.     mysql_query("UPDATE session SET username='$username', time='$ctime', host_addr='$ip', guest='$guest' WHERE username='$username'");
  582.     } else {
  583.     mysql_query("INSERT INTO session (username, time, host_addr, guest) VALUES ('$username', '$ctime', '$ip', '$guest')");
  584.     }
  585.  
  586.     $result = mysql_query("SELECT username FROM session where guest=1");
  587.     $guest_online_num = mysql_num_rows($result);
  588.     $result = mysql_query("SELECT username FROM session where guest=0");
  589.     $member_online_num = mysql_num_rows($result);
  590.     $who_online_num = $guest_online_num + $member_online_num;
  591.     $who_online = "<CENTER>".translate("There are currently,")." $guest_online_num ".translate("guest(s) and")." $member_online_num ".translate("member(s) that are online.")."<BR><BR>";
  592.     $title = "".translate("Who's Online")."";
  593.     $content = "$who_online";
  594.     if ($user) {
  595.     $content .= "".translate("You are logged as")." <b>$username</b>.";
  596.     } else {
  597.     $content .= "".translate("You are Anonymous user. You can register for free by clicking <a href=user.php>here</a>.")."";
  598.     }
  599.     themesidebox($title, $content);
  600. }
  601.  
  602. function bigstory() {
  603.     global $cookie;
  604.     $today = getdate();
  605.     $day = $today[mday];
  606.     if ($day < 10) {
  607.     $day = "0$day";
  608.     }
  609.     $month = $today[mon];
  610.     if ($month < 10) {
  611.     $month = "0$month";
  612.     }
  613.     $year = $today[year];
  614.     $tdate = "$year-$month-$day";
  615.     $result = mysql_query("select sid, title from stories where (time LIKE '%$tdate%') order by counter DESC limit 0,1");
  616.     list($fsid, $ftitle) = mysql_fetch_row($result);
  617.     if ((!$fsid) AND (!$ftitle)) {
  618.     $content = "<center>".translate("There isn't a Biggest Story for Today, yet.")."</center>";
  619.     } else {
  620.     $content = "<center>".translate("Today's most read Story is:")."<br><br>";
  621.     if (isset($cookie[4])) { $options .= "&mode=$cookie[4]"; } else { $options .= "&mode=thread"; }
  622.     if (isset($cookie[5])) { $options .= "&order=$cookie[5]"; } else { $options .= "&order=0"; }
  623.     if (isset($cookie[6])) { $options .= "&thold=$cookie[6]"; } else { $options .= "&thold=0"; }                       
  624.     $content .= "<a href=article.php?sid=$fsid$options>$ftitle</a></center>";
  625.     }
  626.     $boxtitle = "".translate("Today's Big Story")."";
  627.     themesidebox($boxtitle, $content);
  628. }
  629.  
  630. function automatednews() {
  631.     $today = getdate();
  632.     $day = $today[mday];
  633.     if ($day < 10) {
  634.     $day = "0$day";
  635.     }
  636.     $month = $today[mon];
  637.     if ($month < 10) {
  638.     $month = "0$month";
  639.     }
  640.     $year = $today[year];
  641.     $hour = $today[hours];
  642.     $min = $today[minutes];
  643.     $sec = "00";
  644.     $result = mysql_query("select anid, time from autonews");
  645.     while(list($anid, $time) = mysql_fetch_row($result)) {
  646.     ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $date);
  647.     if (($date[1] <= $year) AND ($date[2] <= $month) AND ($date[3] <= $day)) {
  648.         if (($date[4] < $hour) AND ($date[5] >= $min) OR ($date[4] <= $hour) AND ($date[5] <= $min)) {
  649.         $result2 = mysql_query("select aid, title, hometext, bodytext, topic, informant, notes from autonews where anid='$anid'");
  650.         while(list($aid, $title, $hometext, $bodytext, $topic, $author, $notes) = mysql_fetch_row($result2)) {
  651.             $title = stripslashes(FixQuotes($title));
  652.             $hometext = stripslashes(FixQuotes($hometext));
  653.             $bodytext = stripslashes(FixQuotes($bodytext));
  654.             $notes = stripslashes(FixQuotes($notes));
  655.             mysql_query("insert into stories values (NULL, '$aid', '$title', now(), '$hometext', '$bodytext', '0', '0', '$topic', '$author', '$notes')");
  656.             mysql_query("delete from autonews where anid='$anid'");
  657.         }
  658.         }
  659.     }
  660.     }
  661. }
  662.  
  663. ?>