\n";
for ($x=0; $x < $cols; $x++) {
if ($row[$x]==NULL){
$row[$x]=' ';
}
$toreturn .= "\t
$row[$x]
\n";
}
$toreturn .= "
\n";
}
$toreturn .= '
';
return $toreturn;
}
function local_user()
{
global $_SERVER;
return $_SERVER["SERVER_ADDR"] == $_SERVER["REMOTE_ADDR"];
}
/**** validip/getip courtesy of manolete ****/
// IP Validation
function validip($ip)
{
if (!empty($ip) && ip2long($ip)!=-1)
{
// reserved IANA IPv4 addresses
// http://www.iana.org/assignments/ipv4-address-space
$reserved_ips = array (
array('0.0.0.0','2.255.255.255'),
array('10.0.0.0','10.255.255.255'),
array('127.0.0.0','127.255.255.255'),
array('169.254.0.0','169.254.255.255'),
array('172.16.0.0','172.31.255.255'),
array('192.0.2.0','192.0.2.255'),
array('192.168.0.0','192.168.255.255'),
array('255.255.255.0','255.255.255.255')
);
foreach ($reserved_ips as $r)
{
$min = ip2long($r[0]);
$max = ip2long($r[1]);
if ((ip2long($ip) >= $min) && (ip2long($ip) <= $max)) return false;
}
return true;
}
else return false;
}
function getip()
{
/* if (validip($_SERVER['HTTP_CLIENT_IP'])) return $_SERVER['HTTP_CLIENT_IP'];
elseif ($_SERVER['HTTP_X_FORWARDED_FOR']!="")
{
$forwarded=str_replace(",","",$_SERVER['HTTP_X_FORWARDED_FOR']);
$forwarded_array=split(" ",$forwarded);
foreach($forwarded_array as $value) if (validip($value)) return $value;
}
*/
return $_SERVER['REMOTE_ADDR'];
}
function dbconn($autoclean = true)
{
global $mysql_host, $mysql_user, $mysql_pass, $mysql_db;
if (!@mysql_connect($mysql_host, $mysql_user, $mysql_pass))
{
switch (mysql_errno())
{
case 1040:
case 2002:
if ($_SERVER[REQUEST_METHOD] == "GET")
die("
The server load is very high at the moment. Retrying, please wait...
");
else
die("Too many users. Please press the Refresh button in your browser to retry.");
default:
die("[" . mysql_errno() . "] dbconn: mysql_connect: " . mysql_error());
}
}
if( $GLOBALS['settings']['mysql_41'] )
mysql_query("SET time_zone = '+00:00'");
mysql_select_db($mysql_db)
or die('dbconn: mysql_select_db: ' + mysql_error());
userlogin();
if ($autoclean)
register_shutdown_function("autoclean");
}
function userlogin() {
global $SITE_ONLINE;
unset($GLOBALS["CURUSER"]);
$ip = getip();
$nip = ip2long($ip);
//Just use .htaccess for banning...well that's what i prefer so that's why it can be disabled ;)
if($GLOBALS['settings']['mod_bans'])
{
$res_sql = sprintf('SELECT * FROM bans WHERE %u >= first AND %u <= last ', $nip, $nip);
$res = do_mysql_query($res_sql) or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) > 0)
{
header("HTTP/1.0 403 Forbidden");
print("
403 Forbidden
Unauthorized.\n");
die;
}
}
if (!$SITE_ONLINE || empty($_COOKIE["uid"]) || empty($_COOKIE["pass"]))
return;
$id = (int) $_COOKIE["uid"];
if (!$id || !preg_match('/[a-f0-9]{32}/', $_COOKIE["pass"]) )
return;
$res = do_mysql_query("SELECT
acceptpms,
age,
anonymous,
avatar,
avatars,
class,
country,
deletepms,
donated,
donor,
downloaded,
email,
gender,
id,
info,
invites,
language,
last_browse,
logintype,
maxtorrents,
menubar,
notifs,
override_class,
parked,
passhash,
passkey,
postsperpage,
privacy,
savepms,
showemail,
showsig,
showwebsite,
sidebar,
signatureinfo,
stylesheet,
toolbar,
topicsperpage,
torrentsperpage,
uploaded,
username,
warned,
website,
IF( users.downloaded > 0, ROUND(users.uploaded / users.downloaded, 3), '---') as ratio,
IF( users.donor = 'yes', '', '' ) as donor_img,
IF( users.warned = 'yes', '', '' ) as warned_img,
UNIX_TIMESTAMP() - UNIX_TIMESTAMP(users.last_access) as time_last_online,
UNIX_TIMESTAMP() - last_browse as time_last_browse
FROM
users WHERE id = ".$id."
AND enabled='yes' AND status = 'confirmed'") or die(mysql_error());
$row = mysql_fetch_assoc($res);
if (!$row)
return;
$sec = hash_pad($row["secret"]);
if ($_COOKIE["pass"] !== $row["passhash"])
return;
if ((md5($ip.$_COOKIE['pass']) !== $row['loginhash'] && !$row['logintype'] == "secure") || $_COOKIE['pass'] !== $row['passhash'])
return;
if( $row['time_last_online'] > 60 )
{
do_mysql_query("UPDATE users SET last_access=NOW(), ip='".$ip."' WHERE id=" . $row["id"]);
}
$row['ip'] = $ip;
if ($row['override_class'] < $row['class']) $row['class'] = $row['override_class'];
$GLOBALS["CURUSER"] = $row;
// I18N support information here
$language = isset($GLOBALS['CURUSER']['language']) ? $GLOBALS['CURUSER']['language'] :'en';
putenv("LANG=".$language);
setlocale(LC_ALL, $language);
// Set the text domain as 'messages'
$domain = 'messages';
bindtextdomain($domain, $GLOBALS['LOCALE_PATH']);
textdomain($domain);
}
function autoclean() {
global $autoclean_interval;
$now = time();
$docleanup = 0;
$res = do_mysql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime'");
$row = mysql_fetch_array($res);
if (!$row) {
do_mysql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime',$now)");
return;
}
$ts = $row[0];
if ($ts + $autoclean_interval > $now)
return;
do_mysql_query("UPDATE avps SET value_u=$now WHERE arg='lastcleantime' AND value_u = $ts");
if (!mysql_affected_rows())
return;
docleanup();
}
function unesc($x) {
if (get_magic_quotes_gpc())
return stripslashes($x);
return $x;
}
function mksize($bytes)
{
if ($bytes < 1000 * 1024)
return number_format($bytes / 1024, 2) . " kB";
elseif ($bytes < 1000 * 1048576)
return number_format($bytes / 1048576, 2) . " MB";
elseif ($bytes < 1000 * 1073741824)
return number_format($bytes / 1073741824, 2) . " GB";
else
return number_format($bytes / 1099511627776, 2) . " TB";
}
function mksizeint($bytes)
{
$bytes = max(0, $bytes);
if ($bytes < 1000)
return floor($bytes) . " B";
elseif ($bytes < 1000 * 1024)
return floor($bytes / 1024) . " kB";
elseif ($bytes < 1000 * 1048576)
return floor($bytes / 1048576) . " MB";
elseif ($bytes < 1000 * 1073741824)
return floor($bytes / 1073741824) . " GB";
else
return floor($bytes / 1099511627776) . " TB";
}
function deadtime() {
global $announce_interval;
return time() - floor($announce_interval * 1.3);
}
function mkprettytime($s) {
if ($s < 0)
$s = 0;
$t = array();
foreach (array("60:sec","60:min","24:hour","0:day") as $x) {
$y = explode(":", $x);
if ($y[0] > 1) {
$v = $s % $y[0];
$s = floor($s / $y[0]);
}
else
$v = $s;
$t[$y[1]] = $v;
}
if ($t["day"])
return $t["day"] . "d " . sprintf("%02d:%02d:%02d", $t["hour"], $t["min"], $t["sec"]);
if ($t["hour"])
return sprintf("%d:%02d:%02d", $t["hour"], $t["min"], $t["sec"]);
// if ($t["min"])
return sprintf("%d:%02d", $t["min"], $t["sec"]);
// return $t["sec"] . " secs";
}
function mkglobal($vars) {
if (!is_array($vars))
$vars = explode(":", $vars);
foreach ($vars as $v) {
if (isset($_GET[$v]))
$GLOBALS[$v] = unesc($_GET[$v]);
elseif (isset($_POST[$v]))
$GLOBALS[$v] = unesc($_POST[$v]);
else
return 0;
}
return 1;
}
function tr($x,$y,$noesc=0) {
if ($noesc)
$a = $y;
else {
$a = htmlspecialchars($y);
$a = str_replace("\n", " \n", $a);
}
print("
$x
$a
\n");
}
function validfilename($name) {
return preg_match('/^[^\0-\x1f:\\\\\/?*\xff#<>|]+$/si', $name);
}
function validemail($email) {
$qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
$dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
$atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
'\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
$quoted_pair = '\\x5c\\x00-\\x7f';
$domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
$quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
$domain_ref = $atom;
$sub_domain = "($domain_ref|$domain_literal)";
$word = "($atom|$quoted_string)";
$domain = "$sub_domain(\\x2e$sub_domain)*";
$local_part = "$word(\\x2e$word)*";
$addr_spec = "$local_part\\x40$domain";
return preg_match("!^$addr_spec$!", $email) ? true : false;
}
function is_valid_type($type)
{
$valid_types = array('cat_name', 'name', 'numfiles', 'comments', 'rating', 'added', 'size', 'times_completed', 'seeders', 'leechers', 'username');
return in_array($type, $valid_types);
}
function is_valid_sort($sort)
{
if($sort == 'ASC' || $sort == 'DESC')
return true;
return false;
}
function sqlesc($x) {
return "'".mysql_real_escape_string($x)."'";
}
function sqlwildcardesc($x) {
return str_replace(array("%","_"), array("\\%","\\_"), mysql_real_escape_string($x));
}
function urlparse($m) {
$t = $m[0];
if (preg_match(',^\w+://,', $t))
return "$t";
return "$t";
}
function parsedescr($d, $html) {
if (!$html)
{
$d = htmlspecialchars($d);
$d = str_replace("\n", "\n ", $d);
}
return $d;
}
function stdhead($title = "", $msgalert = true) {
global $CURUSER, $SITE_ONLINE, $FUNDS, $SITENAME;
if (!$SITE_ONLINE)
die("Site is down for maintenance, please check back again later... thanks ");
header("Content-Type: text/html; charset=iso-8859-1");
//header("Pragma: No-cache");
if ($title == "")
$title = $SITENAME;
else
$title = "$SITENAME :: " . htmlspecialchars($title);
if ($CURUSER)
{
$ss_a = @mysql_fetch_array(@do_mysql_query("select uri from stylesheets where id=" . $CURUSER["stylesheet"]));
if ($ss_a) $ss_uri = $ss_a["uri"];
}
if (!$ss_uri)
{
($r = do_mysql_query("SELECT uri FROM stylesheets WHERE id=1")) or die(mysql_error());
($a = mysql_fetch_array($r)) or die(mysql_error());
$ss_uri = $a["uri"];
}
if ($msgalert && $CURUSER)
{
$res = do_mysql_query("SELECT COUNT(*) FROM messages WHERE receiver=" . $CURUSER["id"] . " && unread='yes'") or die("OopppsY!");
$arr = mysql_fetch_row($res);
$unread = (int) $arr[0];
}
///////////////////for spacer/////////////////////////
if (!$CURUSER || $CURUSER['toolbar'] == "yes")
$size = "900px";
elseif ($CURUSER['toolbar'] == "no")
$size = "700px";
?>
= $title ?>
$sr = isset($CURUSER) ? $CURUSER['donated'] : '';
if ($CURUSER['toolbar'] == "yes")
{
$date=gmdate("D, M d Y H:i");
$uped = mksize($CURUSER['uploaded']);
$downed = mksize($CURUSER['downloaded']);
$color = get_ratio_color($CURUSER['ratio']);
$ratio = ''.$CURUSER['ratio'].'';
$warn = $CURUSER['warn_img'];
//// check for messages //////////////////
$res1 = do_mysql_query("SELECT unread, COUNT( * ) as mesg_count
FROM messages
WHERE receiver =".$CURUSER['id']."
AND location
IN (
'in', 'both'
)
GROUP BY unread");
$messages_array = array("yes" => 0, "no" => 0, "" => 0);
while($arr = mysql_fetch_assoc($res1))
{
$messages_array[ $arr['unread'] ] += $arr['mesg_count'];
}
$messages = array_sum($messages_array);
$unread = $messages_array['yes'];
if ($unread > 0)
$inboxpic = "";
else
$inboxpic = "";
//sender
$res1 = do_mysql_query("SELECT unread, COUNT( * ) as mesg_count
FROM messages
WHERE sender =".$CURUSER['id']."
AND location
IN (
'out', 'both'
)
GROUP BY unread");
$messages_array2 = array("yes" => 0, "no" => 0);
while($arr = mysql_fetch_assoc($res1))
{
$messages_array2[ $arr['unread'] ] += $arr['mesg_count'];
}
$outmessages = array_sum($messages_array2);
if ($unread > 0)
$inboxpic = '';
else
$inboxpic = '';
//// check active torrents ///////////////////////
$res2 = do_mysql_query("SELECT seeder, COUNT( seeder ) AS seeders
FROM peers
WHERE userid =".$CURUSER['id']."
GROUP BY seeder");
$active_torrents = array();
while($inf = mysql_fetch_assoc($res2))
{
$active_torrents[ $inf['seeder'] ] = $inf['seeders'];
}
$activeseed = ( isset($active_torrents['yes']) ? $active_torrents['yes'] : 0 );
$activeleech = ( isset($active_torrents['no']) ? $active_torrents['no'] : 0 );
//// end
$usrclass = '';
if ($CURUSER['override_class'] != 255) $usrclass = " (".get_user_class_name($CURUSER['class']).") ";
elseif(get_user_class() >= UC_MODERATOR) $usrclass = " (".get_user_class_name($CURUSER['class']).") ";
?>