function dbconnect() {
include("config.php3");
mysql_pconnect($dbhost, $dbuname, $dbpass);
@mysql_select_db("$dbname") or die ("Unable to select database");
}
function counter() {
dbconnect();
mysql_query("UPDATE vars SET value=value+1 where name='totalhits'");
}
function cookiedecode($user) {
global $cookie;
$user = base64_decode($user);
$cookie = explode(":", $user);
return $cookie;
}
function getusrinfo($user) {
global $userinfo;
$user2 = base64_decode($user);
dbconnect();
$user3 = explode(":", $user2);
$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]'");
if(mysql_num_rows($result)==1) {
$userinfo = mysql_fetch_array($result);
} else {
echo "A problem occured
";
}
return $userinfo;
}
function FixQuotes ($what = "") {
$what = ereg_replace("'","''",$what);
while (eregi("\\\\'", $what)) {
$what = ereg_replace("\\\\'","'",$what);
}
return $what;
}
/*********************************************************/
/* text filter */
/*********************************************************/
function check_words($Message) {
global $EditedMessage, $CensorList, $CensorMode, $CensorReplace;
$EditedMessage = $Message;
if ($CensorMode != 0) {
if (is_array($CensorList)) {
$Replacement = $CensorReplace;
if ($CensorMode == 1) { # Exact match
$RegExPrefix = '([^[:alpha:]]|^)';
$RegExSuffix = '([^[:alpha:]]|$)';
} elseif ($CensorMode == 2) { # Word beginning
$RegExPrefix = '([^[:alpha:]]|^)';
$RegExSuffix = '[[:alpha:]]*([^[:alpha:]]|$)';
} elseif ($CensorMode == 3) { # Word fragment
$RegExPrefix = '([^[:alpha:]]*)[[:alpha:]]*';
$RegExSuffix = '[[:alpha:]]*([^[:alpha:]]*)';
}
for ($i = 0; $i < count($CensorList) && $RegExPrefix != ''; $i++) {
$EditedMessage = eregi_replace($RegExPrefix.$CensorList[$i].$RegExSuffix,"\\1$Replacement\\2",$EditedMessage);
}
}
}
return ($EditedMessage);
}
function check_html ($str, $strip="") {
include("config.php3");
if ($strip == "nohtml")
$AllowableHTML=array('');
$str = stripslashes($str);
$str = eregi_replace("<[[:space:]]*([^>]*)[[:space:]]*>","<\\1>",$str);
$tmp = "";
while (eregi("<([^> ]*)([^>]*)>",$str,$reg)) {
$i = strpos($str,$reg[0]);
$l = strlen($reg[0]);
if ($reg[1][0] == "/") $tag = strtolower(substr($reg[1],1));
else $tag = strtolower($reg[1]);
if ($a = $AllowableHTML[$tag])
if ($reg[1][0] == "/") $tag = "$tag>";
elseif ($a == 1) $tag = "<$tag>";
else $tag = "<$tag " . $reg[2] . ">";
else $tag = "";
$tmp .= substr($str,0,$i) . $tag;
$str = substr($str,$i+$l);
}
$str = $tmp . $str;
// Squash PHP tags unconditionally
$str = ereg_replace("<\?","",$str);
$str = ereg_replace("\"","",$str);
return $str;
}
function filter_text($Message, $strip="") {
global $EditedMessage;
check_words($Message);
$EditedMessage=check_html($EditedMessage, $strip);
return ($EditedMessage);
}
/*********************************************************/
/* formatting stories */
/*********************************************************/
function formatTimestamp($time) {
include ("config.php3");
global $datetime;
setlocale ("LC_TIME", "$locale");
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);
$datetime = strftime("".translate("datestring")."", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
$datetime = ucfirst($datetime);
return($datetime);
}
function formatAidHeader($aid) {
$holder = mysql_query("SELECT url, email FROM authors where aid='$aid'");
if (!$holder) { echo mysql_errno(). ": ".mysql_error(). "
"; exit(); }
list($url, $email) = mysql_fetch_row($holder);
if (isset($url)) { echo "$aid";
} elseif (isset($email)) { echo "$aid";
} else { echo $aid; }
}
function oldNews($storynum) {
include ("config.php3");
$boxstuff = "";
$boxTitle = "Past News";
$result = mysql_query("select sid, title, time, comments from stories order by time desc limit $storynum, $oldnum");
while(list($sid, $title, $time, $comments) = mysql_fetch_row($result)) {
setlocale ("LC_TIME", "$locale");
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);
$datetime2 = strftime("".translate("datestring2")."", mktime($datetime2[4],$datetime2[5],$datetime2[6],$datetime2[2],$datetime2[3],$datetime2[1]));
$datetime2 = ucfirst($datetime2);
if($time2==$datetime2) {
$boxstuff .= "$title ($comments)";
} else {
if($a=="") {
$boxstuff .= "$datetime2
$title ($comments)";
$time2 = $datetime2;
$a = 1;
} else {
$boxstuff .= "
$datetime2
$title ($comments)";
$time2 = $datetime2;
}
}
}
themesidebox($boxTitle, $boxstuff);
}
function mainblock() {
// dbconnect();
$result = mysql_query("select title, content from mainblock");
while(list($title, $content) = mysql_fetch_array($result)) {
$content = nl2br($content);
themesidebox($title, $content);
}
}
function rightblocks() {
$result = mysql_query("select title, content from rblocks");
while(list($title, $content) = mysql_fetch_array($result)) {
$content = nl2br($content);
themesidebox($title, $content);
}
}
function leftblocks() {
$result = mysql_query("select title, content from lblocks");
while(list($title, $content) = mysql_fetch_array($result)) {
$content = nl2br($content);
themesidebox($title, $content);
}
}
function adminblock() {
$result = mysql_query("select title, content from adminblock");
while(list($title, $content) = mysql_fetch_array($result)) {
$content = nl2br($content);
themesidebox($title, $content);
}
}
/*********************************************************/
/* poll functions */
/*********************************************************/
function pollMain($pollID) {
global $maxOptions, $boxTitle, $boxContent, $uimages;
include("config.php3");
dbconnect();
if(!isset($pollID))
$pollID = 1;
if(!isset($url))
$url = sprintf("pollBooth.php3?op=results&pollID=%d", $pollID);
$boxContent .= "";
themesidebox($boxTitle, $boxContent);
}
function pollLatest() {
dbconnect();
$result = mysql_query("SELECT pollID FROM poll_data ORDER BY pollID DESC");
$pollID = mysql_fetch_row($result);
return($pollID[0]);
}
function pollNewest() {
$pollID = pollLatest();
pollMain($pollID);
}
function pollCollector($pollID, $voteID, $forwarder) {
global $maxOptions, $setCookies, $cookiePrefix, $HTTP_COOKIE_VARS;
dbconnect();
$voteValid = "1";
if($setCookies>0) {
// we have to check for cookies, so get timestamp of this poll
$result = mysql_query("SELECT timeStamp FROM poll_desc WHERE pollID=$pollID");
$object = mysql_fetch_object($result);
$timeStamp = $object->timeStamp;
$cookieName = $cookiePrefix.$timeStamp;
// check if cookie exists
if($HTTP_COOKIE_VARS["$cookieName"] == "1") {
// cookie exists, invalidate this vote
$warn = "You already voted today!";
$voteValid = "0";
} else {
// cookie does not exist yet, set one now
$cvalue = "1";
setcookie("$cookieName",$cvalue,time()+86400);
}
}
// update database if the vote is valid
if($voteValid>0) {
@mysql_query("UPDATE poll_data SET optionCount=optionCount+1 WHERE (pollID=$pollID) AND (voteID=$voteID)");
@mysql_query("UPDATE poll_desc SET voters=voters+1 WHERE pollID=$pollID");
Header("Location: $forwarder");
} else {
Header("Location: $forwarder");
}
// a lot of browsers can't handle it if there's an empty page
echo "
";
}
function pollList() {
dbconnect();
$result = mysql_query("SELECT pollID, pollTitle, timeStamp, voters FROM poll_desc ORDER BY timeStamp");
$counter = 0;
echo "| ";
echo "";
while($object = mysql_fetch_object($result)) {
$resultArray[$counter] = array($object->pollID, $object->pollTitle, $object->timeStamp, $object->voters);
$counter++;
}
for ($count = 0; $count < count($resultArray); $count++) {
$id = $resultArray[$count][0];
$pollTitle = $resultArray[$count][1];
$voters = $resultArray[$count][3];
echo(" $pollTitle ");
echo("(".translate("Results")." - $voters ".translate("votes").")\n");
}
echo " |
";
}
function pollResults($pollID) {
global $maxOptions, $BarScale, $resultTableBgColor, $resultBarFile, $setCookies;
if(!isset($pollID)) $pollID = 1;
dbconnect();
$result = mysql_query("SELECT pollID, pollTitle, timeStamp FROM poll_desc WHERE pollID=$pollID");
$holdtitle = mysql_fetch_row($result);
echo "
$holdtitle[1]
";
mysql_free_result($result);
$result = mysql_query("SELECT SUM(optionCount) AS SUM FROM poll_data WHERE pollID=$pollID");
$sum = (int)mysql_result($result, 0, "SUM");
mysql_free_result($result);
echo "";
// cycle through all options
for($i = 1; $i <= $maxOptions; $i++) {
// select next vote option
$result = mysql_query("SELECT pollID, optionText, optionCount, voteID FROM poll_data WHERE (pollID=$pollID) AND (voteID=$i)");
$object = mysql_fetch_object($result);
if(is_object($object)) {
$optionText = $object->optionText;
$optionCount = $object->optionCount;
echo "";
if($optionText != "") {
echo "| ";
echo "$optionText";
echo " | ";
if($sum) {
$percent = 100 * $optionCount * $BarScale / $sum;
} else {
$percent = 0;
}
echo "";
$percentInt = (int)$percent * 4;
$percent2 = (int)$percent;
if ($percent > 0) {
echo " ";
echo " ";
echo " ";
} else {
echo " ";
echo " ";
echo " ";
}
printf(" %.2f %% (%d)", $percent, $optionCount);
echo " | ";
}
}
echo "
";
}
echo "
";
echo "".translate("Total Votes: ")."$sum
";
if($setCookies>0) {
echo "".translate("We allow just one vote per day")."
";
} else {
echo "
";
}
$booth = $pollID;
echo("[ ".translate("Voting Booth")." | ");
echo("".translate("Other Polls")." ]");
return(1);
}
function getTopics($s_sid) {
global $topicname, $topicimage, $topictext;
$sid = $s_sid;
dbconnect();
$result=mysql_query("SELECT topic FROM stories where sid=$sid");
list($topic) = mysql_fetch_row($result);
$result=mysql_query("SELECT topicid, topicname, topicimage, topictext FROM topics where topicid=$topic");
list($topicid, $topicname, $topicimage, $topictext) = mysql_fetch_row($result);
}
function nbc($user_status, $cookiepopi){
global $REMOTE_ADDR, $dbtable, $nbc_timeout, $dbhost, $dbuname, $dbpass, $dbname;
if ($cookiepopi) {
dbconnect();
$result666 = mysql_query("SELECT uname, ulvl FROM rsimembers where ppass='$cookiepopi'");
list($uname, $ulvl) = mysql_fetch_row($result666);
$myuser = $uname ;
$mylvl = $ulvl ;
} else {
$myuser = "zzzzGuest" ;
$mylvl = "10" ;
}
$db=new phpDB();
$db->pconnect($dbhost, $dbuname, $dbpass, $dbname) or die("Impossible de se connecter au serveur");
$db->execute("DELETE FROM $dbtable WHERE HeureLimite < now()");
if ($myuser!="Guest") {
$chk=0;
$cnt=0;
dbconnect();
$result666 = mysql_query("SELECT IP, HeureLimite, who, wher, lvl FROM nbconnecte");
$chk=$uname;
while(list($IP, $HeureLimite, $who, $wher, $lvl) = mysql_fetch_row($result666)) {
$result667 = mysql_query("SELECT who FROM nbconnecte where who='$chk'");
while(list($who) = mysql_fetch_row($result667)) {
if ($chk==$who) {
mysql_query("DELETE FROM nbconnecte WHERE who='$chk'");
}
}
}
}
$res=$db->execute("SELECT count(*) FROM $dbtable WHERE IP='$REMOTE_ADDR'");
if($res->fields[0]){
// Déjà connecté
$db->execute("UPDATE $dbtable SET HeureLimite=HeureLimite + $nbc_timeout, who='$myuser', wher='$user_status', lvl='$mylvl' WHERE IP='$REMOTE_ADDR'");
}else{
// Nouvelle connexion
$db->execute("INSERT INTO $dbtable (IP, HeureLimite, who, wher, lvl) VALUES ('$REMOTE_ADDR', now()+ $nbc_timeout, '$myuser', '$user_status', '$mylvl')");
}
$res->close();
$res=$db->execute("SELECT count(*) FROM $dbtable");
$count=$res->fields[0];
$res->close();
return $count;
}
function update_whoonline($user_status, $cookiepopi) {
}
?>