Thread: H-Tracker v2
View Single Post
  #153  
Old 3rd March 2010, 23:12
melcu66 melcu66 is offline
Member
 
Join Date: Apr 2009
P2P
Posts: 5
Default
Quote:
Originally Posted by raefor View Post
you can try this or edit your functions.php
PHP Code:
<?php
//
//
//
//
error_reporting(E_ALL ^ E_NOTICE);
// register_globals on *fix*
if (!ini_get("register_globals")) {
    
import_request_variables('GPC');
}
 
//If running on a windows server you "may" have to use absolute paths here
 
require_once("mysql.php"); //Get MYSQL Connection Info
require_once("config.php");  //Get Site Settings and Vars ($site_config)  
require("tzs.php"); // Get Timezones
require("ctracker.php");
 
 
function 
dbconn($autoclean = false) {
    global 
$mysql_host, $mysql_user, $mysql_pass, $mysql_db, $THEME, $LANGUAGE, $site_config;
 
    if (!
ob_get_level()) {
        if (
extension_loaded('zlib') && !ini_get('zlib.output_compression'))
            
ob_start('ob_gzhandler');
        else
            
ob_start();
    } 
 
    
header("Content-Type: text/html;charset=$site_config[CHARSET]");
 
    if (!
function_exists("mysql_connect"))
        die(
"MySQL support not available.");
 
    if (!@
mysql_connect($mysql_host, $mysql_user, $mysql_pass))
    {
         die(
"<br /><br /><center><img src=\"http://bvlist.com/images/mysqlerror.png\" border=\"0\" alt=\"Powered by h-tracker.org\"><br /><br /><strong>There seems to be a problem with the MySQL server,<br><font color=red>" . mysql_error() ."</font><br>We should be back shortly.</strong></center>");                                                                                                                   
    }
     
mysql_select_db($mysql_db)
        or die(
"<br /><br /><center><img src=\"http://bvlist.com/images/mysqlerror.png\" border=\"0\" alt=\"Powered by h-tracker.org\"><br /><br /><strong>There seems to be a problem with the MySQL server,<br><font color=red>" . mysql_error() ."</font><br>Check your settings.</strong></center>");
 
    unset(
$mysql_pass); //security
 
    
userlogin(); //Get user info    
 
    //Get language and theme
    
$CURUSER = $GLOBALS["CURUSER"];
    if (
$CURUSER)  {
        
$ss_a = @mysql_fetch_array(@mysql_query("SELECT uri FROM stylesheets WHERE id=$CURUSER[stylesheet]"));
        if (
$ss_a)
            
$THEME = $ss_a["uri"];
        else {
            
$ss_a = @mysql_fetch_array(@mysql_query("select uri from stylesheets where id=$site_config[default_theme]"));
            
$THEME = $ss_a['uri'];
        }
        
$lng_a = @mysql_fetch_array(@mysql_query("select uri from languages where id=$CURUSER[language]"));
        if (
$lng_a)
            
$LANGUAGE = $lng_a["uri"];
        else {
            
$lng_a = @mysql_fetch_array(@mysql_query("select uri from languages where id=$site_config[default_language]"));
            
$LANGUAGE = $lng_a['uri'];
        }
    }else{
//not logged in so get default theme/language
        
$ss_a = mysql_fetch_array(mysql_query("select uri from stylesheets where id='" . $site_config['default_theme'] . "'")) or die(mysql_error());
        if (
$ss_a)
            
$THEME = $ss_a["uri"];
        
$lng_a = mysql_fetch_array(mysql_query("select uri from languages where id='" . $site_config['default_language'] . "'")) or die(mysql_error());
        if (
$lng_a)
            
$LANGUAGE = $lng_a["uri"];
    }
    require_once(
"languages/$LANGUAGE");
 
 
 
    if (
$autoclean)
        
autoclean();
}
 
// Main Cleanup
function autoclean() {
    global 
$site_config;
    require_once(
"cleanup.php");
 
    
$now = gmtime();
 
    
$res = mysql_query("SELECT last_time FROM tasks WHERE task='cleanup'");
    
$row = mysql_fetch_array($res);
    if (!
$row) {
        
mysql_query("INSERT INTO tasks (task, last_time) VALUES ('cleanup',$now)");
        return;
    }
    
$ts = $row[0];
    if (
$ts + $site_config["autoclean_interval"] > $now)
        return;
    
mysql_query("UPDATE tasks SET last_time=$now WHERE task='cleanup' AND last_time = $ts");
    if (!
mysql_affected_rows())
        return;
 
    
do_cleanup();
}
 
// IP Validation
function validip($ip)
{
    if (!empty(
$ip) && $ip == long2ip(ip2long($ip)))
    {
        
$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 (isset(
$_SERVER)) {
     if (isset(
$_SERVER['HTTP_X_FORWARDED_FOR']) && validip($_SERVER['HTTP_X_FORWARDED_FOR'])) {
       
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
     } elseif (isset(
$_SERVER['HTTP_CLIENT_IP']) && validip($_SERVER['HTTP_CLIENT_IP'])) {
       
$ip = $_SERVER['HTTP_CLIENT_IP'];
     } else {
       
$ip = $_SERVER['REMOTE_ADDR'];
     }
   } else {
     if (
getenv('HTTP_X_FORWARDED_FOR') && validip(getenv('HTTP_X_FORWARDED_FOR'))) {
       
$ip = getenv('HTTP_X_FORWARDED_FOR');
     } elseif (
getenv('HTTP_CLIENT_IP') && validip(getenv('HTTP_CLIENT_IP'))) {
       
$ip = getenv('HTTP_CLIENT_IP');
     } else {
       
$ip = getenv('REMOTE_ADDR');
     }
   }
   return 
$ip;
}
 
function 
userlogin() {
    global 
$CURUSER;
    unset(
$GLOBALS["CURUSER"]);
 
    
$ip = getip(); //GET USERS IP
 
    //Check IP bans    
    
$nip = ip2long($ip);
    
$res = mysql_query("SELECT * FROM bans WHERE $nip >= first AND $nip <= last")  or die(mysql_error());
    if (
mysql_num_rows($res) > 0) {
        
$row = mysql_fetch_array($res);
        
header("HTTP/1.0 403 Forbidden");
        echo 
"<html><head><title>Forbidden</title></head><body><h1>Forbidden</h1>Unauthorized IP address.<br />".
        
"Reason for banning: $row[comment]</body></html>";
        die;
    }
 
 
    
//Check The Cookie and get CURUSER details
    
if (empty($_COOKIE["uid"]) || empty($_COOKIE["pass"]))
        return;
 
    
$id = 0 + $_COOKIE["uid"]; //Get User ID from cookie
    
if (!$id)
    return;
 
    
//Get User Details And Permissions
    
$res = mysql_query("SELECT * FROM users INNER JOIN groups ON users.class=groups.group_id WHERE users.id = $id AND users.enabled='yes' AND users.status = 'confirmed'") or die(mysql_error());
    
$row = mysql_fetch_array($res);
 
    if (!
$row)
        return;
 
    
//Check PW in cookie matches DB (after adding secret to the hash)
    
$sec = hash_pad($row["secret"]);
    if (
$_COOKIE["pass"] != md5($sec . $row["password"] . $sec))
        return;
 
    
mysql_query("UPDATE users SET last_access='" . get_date_time() . "', ip=".sqlesc($ip)." WHERE id=" . $row["id"]) or die(mysql_error());
 
    
$GLOBALS["CURUSER"] = $row;
    unset(
$row);
}
 
function 
logincookie($id, $password, $secret, $updatedb = 1, $expires = 0x7fffffff) {
    
$md5 = md5($secret . $password . $secret);
    
setcookie("uid", $id, $expires, "/");
    
setcookie("pass", $md5, $expires, "/");
 
    if (
$updatedb)
        
mysql_query("UPDATE users SET last_login = '".get_date_time()."' WHERE id = $id");
}
 
function 
logoutcookie() {
    
setcookie("uid", "null", time(), "/");
    
setcookie("pass", "null", time(), "/");
}
 
function 
stdhead($title = "") {
    global 
$site_config, $CURUSER, $THEME, $LANGUAGE;  //Define globals
 
    //require_once("cleanup.php");  //temp cleanup linkage :D
    //docleanup();//TEMP CLEANUP CALL
 
    //site online check
    
if (!$site_config["SITE_ONLINE"]){
        if (
$CURUSER["level"]!=="Administrator") {
            echo 
'<BR><BR><BR><CENTER>'. stripslashes($site_config["OFFLINEMSG"]) .'</CENTER><BR><BR>';
            die;
        }else{
            echo 
'<BR><BR><BR><CENTER><B><FONT COLOR=RED>SITE OFFLINE, ADMIN ONLY VIEWING! DO NOT LOGOUT</FONT></B><BR>If you logout please edit backend/config.php and set SITE_ONLINE to true </CENTER><BR><BR>';
        }
    }
    
//end check
 
    
if (!$CURUSER)
        
guestadd();
 
    if (
$title == "")
        
$title = $site_config['SITENAME'];
    else
        
$title = $site_config['SITENAME']. " : ". htmlspecialchars($title);
 
    require_once(
"themes/" . $THEME . "/block.php");
    require_once(
"themes/" . $THEME . "/header.php");
} 
 
function 
stdfoot() {
    global 
$site_config, $CURUSER, $THEME, $LANGUAGE;
    require_once(
"themes/" . $THEME . "/footer.php");
    
mysql_close();
}
 
 
//POLL MULTICOLOR BY HACK346
function get_poolsleft($i)
{
 global 
$site_config, $THEME;
    if (
$i == 0 || $i == 5 || $i == 10 || $i == 15) return "<img src=".$site_config['SITEURL']."/themes/$THEME/images/polls/bar1-l.png border=\"0\">";                                                                            
    if (
$i == 1 || $i == 6 || $i == 11 || $i == 16) return "<img src=".$site_config['SITEURL']."/themes/$THEME/images/polls/bar2-l.png border=\"0\">";                                                                           
    if (
$i == 2 || $i == 7 || $i == 12 || $i == 17) return "<img src=".$site_config['SITEURL']."/themes/$THEME/images/polls/bar3-l.png border=\"0\">"; 
    if (
$i == 3 || $i == 8 || $i == 13 || $i == 18) return "<img src=".$site_config['SITEURL']."/themes/$THEME/images/polls/bar4-l.png border=\"0\">";
    if (
$i == 4 || $i == 9 || $i == 14 || $i == 19) return "<img src=".$site_config['SITEURL']."/themes/$THEME/images/polls/bar5-l.png border=\"0\">";  
  return 
"";
}
 
 
function 
get_poolsmiddle($i)
{
 global 
$site_config, $THEME;
    if (
$i == 0 || $i == 5 || $i == 10 || $i == 15) return "<img src=".$site_config['SITEURL']."/themes/$THEME/images/polls/bar1.png border=\"0\"";                                                                           
    if (
$i == 1 || $i == 6 || $i == 11 || $i == 16) return "<img src=".$site_config['SITEURL']."/themes/$THEME/images/polls/bar2.png border=\"0\"";                                                                             
    if (
$i == 2 || $i == 7 || $i == 12 || $i == 17) return "<img src=".$site_config['SITEURL']."/themes/$THEME/images/polls/bar3.png border=\"0\""; 
    if (
$i == 3 || $i == 8 || $i == 13 || $i == 18) return "<img src=".$site_config['SITEURL']."/themes/$THEME/images/polls/bar4.png border=\"0\"";   
    if (
$i == 4 || $i == 9 || $i == 14 || $i == 19) return "<img src=".$site_config['SITEURL']."/themes/$THEME/images/polls/bar5.png border=\"0\"";   
  return 
"";
}
 
function 
get_poolsright($i)
 {
 global 
$site_config, $THEME; 
    if (
$i == 0 || $i == 5 || $i == 10 || $i == 15) return "<img src=".$site_config['SITEURL']."/themes/$THEME/images/polls/bar1-r.png border=\"0\">";                                                                           
    if (
$i == 1 || $i == 6 || $i == 11 || $i == 16) return "<img src=".$site_config['SITEURL']."/themes/$THEME/images/polls/bar2-r.png border=\"0\">";                                                                            
    if (
$i == 2 || $i == 7 || $i == 12 || $i == 17) return "<img src=".$site_config['SITEURL']."/themes/$THEME/images/polls/bar3-r.png border=\"0\">"; 
    if (
$i == 3 || $i == 8 || $i == 13 || $i == 18) return "<img src=".$site_config['SITEURL']."/themes/$THEME/images/polls/bar4-r.png border=\"0\">"; 
    if (
$i == 4 || $i == 9 || $i == 14 || $i == 19) return "<img src=".$site_config['SITEURL']."/themes/$THEME/images/polls/bar5-r.png border=\"0\">";         
    return 
"";
}     
 
function 
leftblocks() {
    global 
$site_config, $CURUSER, $THEME, $LANGUAGE;  //Define globals
    
$res=mysql_query("SELECT * FROM blocks WHERE position='left' AND enabled=1 ORDER BY sort");
    
$i=0;
    
$blocks=array();
    while(
$result=mysql_fetch_array($res)){
        if(
$result["position"]) { 
            
$block=$result["name"];
            
$blocks[$i++]=$block;
        }
    }
 
    foreach (
$blocks as $blockfilename){
        echo
"<div id=\"ka".$result['id']."\" style=\"display: block;\">\n";                                                                                                         
        include(
"blocks/".$blockfilename."_block.php");
        echo
"</div>";
    }
}
 
function 
rightblocks() {
    global 
$site_config, $CURUSER, $THEME, $LANGUAGE;  //Define globals
    
$res=mysql_query("SELECT * FROM blocks WHERE position='right' AND enabled=1 ORDER BY sort");
    
$i=0;
    
$blocks=array();
    while(
$result=mysql_fetch_array($res)){
        if(
$result["position"]) {
            
$block=$result["name"];
            
$blocks[$i++]=$block;
        }
    }
 
    foreach (
$blocks as $blockfilename){
        include(
"blocks/".$blockfilename."_block.php");
    }
}
 
function 
middleblocks() {
    global 
$site_config, $CURUSER, $THEME, $LANGUAGE;  //Define globals
    
$res=mysql_query("SELECT * FROM blocks WHERE position='middle' AND enabled=1 ORDER BY sort");
    
$i=0;
    
$blocks=array();
    while(
$result=mysql_fetch_array($res)){
        if(
$result["position"]) {
            
$block=$result["name"];
            
$blocks[$i++]=$block;
        }
    }
 
    foreach (
$blocks as $blockfilename){
        include(
"blocks/".$blockfilename."_block.php");
    }
} 
 
function 
show_error_msg($title, $message, $wrapper = "1") {
    if (
$wrapper=="1") {
        
stdhead($title);
        
//echo "<b>DEBUG: stdhead Wrapper ON/Kill php gen further</b>";//remove later
    
}
        
begin_frame("<div class=error>". htmlspecialchars($title) ."</div>");
        print(
"<CENTER><B>" . stripslashes(sqlesc($message)) . "</B></CENTER>\n");
        
end_frame();
 
    if (
$wrapper=="1"){
        
stdfoot();
        die();
    }
}
 
 
function 
show_success_msg($title, $message, $wrapper = "1") {
    if (
$wrapper=="1") {
        
stdhead($title);
        
//echo "<b>DEBUG: stdhead Wrapper ON/Kill php gen further</b>";//remove later
    
}
        
begin_frame("<div class=success>". htmlspecialchars($title) ."</div>");
        print(
"<p><CENTER><B>" . stripslashes(sqlesc($message)) . "</B></CENTER></p>\n");
        
end_frame();
 
    if (
$wrapper=="1"){
        
stdfoot();
        die();
    }
}
 
//calculate health
 
// New (hack346 21/Jan/2009 @ 11:26)
function health($leechers, $seeders) {
    if ((
$leechers == 0 && $seeders == 0) || ($leechers > 0 && $seeders == 0))
        return 
$health0 = "<span><em style=\"left:3%\"></em></span><br>0%"; 
    elseif (
$seeders > $leechers)
        return 
$health10 = "<span><em style=\"left:100%\"></em></span><br>100%"; 
 
    
$ratio = $seeders / $leechers * 100;
    if (
$ratio > 0 && $ratio < 15)
        return 
$health1= "<stan><em style=\"left:10%\">10%</em></span><br>10%";
    elseif (
$ratio >= 15 && $ratio < 25)
        return 
$health2 = "<span><em style=\"left:20%\">20%</em></span><br>20%"; 
    elseif (
$ratio >= 25 && $ratio < 35)
        return 
$health3 = "<span><em style=\"left:30%\">30%</em></span><br>30%"; 
    elseif (
$ratio >= 35 && $ratio < 45)
        return 
$health4 = "<span><em style=\"left:40%\">40%</em></span><br>40%"; 
    elseif (
$ratio >= 45 && $ratio < 55)
        return 
$health5 = "<span><em style=\"left:50%\">50%</em></span><br>50%"; 
    elseif (
$ratio >= 55 && $ratio < 65)
        return 
$health6 = "<span><em style=\"left:60%\">60%</em></span><br>60%"; 
    elseif (
$ratio >= 65 && $ratio < 75)
        return 
$health7 = "<span><em style=\"left:70%\">70%</em></span><br>70%"; 
    elseif (
$ratio >= 75 && $ratio < 85)
        return 
$health8 = "<span><em style=\"left:80%\">80%</em></span><br>80%"; 
    elseif (
$ratio >= 85 && $ratio < 95)
        return 
$health9 = "<span><em style=\"left:90%\">90%</em></span><br>90%"; 
    else
        return 
$health10 = "<span><em style=\"left:100%\">100%</em></span><br>100%"; 
}
 
 
//secure vars
function sqlesc($x) {
   if (
get_magic_quotes_gpc()) {
       
$x = stripslashes($x);
   }
   if (!
is_numeric($x)) {
       
$x = "'".mysql_real_escape_string($x)."'";
   }
   return 
$x;
}
 
 
function 
unesc($x) {
    if (
get_magic_quotes_gpc())
        return 
stripslashes($x);
    return 
$x;
}
 
function 
mkglobal($vars) {
    if (!
is_array($vars))
        
$vars = explode(":", $vars);
    foreach (
$vars as $v) {
        if (isset(
$_GET[$v]))
            
$GLOBALS[$v] = stripslashes($_GET[$v]);
        elseif (isset(
$_POST[$v]))
            
$GLOBALS[$v] = stripslashes($_POST[$v]);
        else
            return 
0;
    }
    return 
1;
}
 
function 
hash_pad($hash) {
    return 
str_pad($hash, 20);
}
 
function 
hash_where($name, $hash) {
    
$shhash = preg_replace('/ *$/s', "", $hash);
    return 
"($name = " . sqlesc($hash) . " OR $name = " . sqlesc($shhash) . ")";
}
 
function 
file_ungzip($fromFile){
    
$zp = @gzopen($fromFile, "r");
    while(!@
gzeof($zp)) { $string .= @gzread($zp, 4096); }
    @
gzclose($zp);
    return 
$string;
}
 
function 
mksize($bytes) {
    if (
$bytes < 1000 * 1024)
        return 
number_format($bytes / 1024, 2) . " KB";
    if (
$bytes < 1000 * 1048576)
        return 
number_format($bytes / 1048576, 2) . " MB";
    if (
$bytes < 1000 * 1073741824)
        return 
number_format($bytes / 1073741824, 2) . " GB";
    return 
number_format($bytes / 1099511627776, 2) . " TB";
}
 
function 
escape_url($url) {
    
$ret = '';
    for(
$i = 0; $i < strlen($url); $i+=2)
    
$ret .= '%'.$url[$i].$url[$i + 1];
    return 
$ret;
}
 
function 
torrent_scrape_url($scrape, $hash) {
    
$ch = curl_init();
    
$timeout = 5;
    
curl_setopt ($ch, CURLOPT_URL, $scrape.'?info_hash='.escape_url($hash));
    
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    
$fp = curl_exec($ch);
    
curl_close($ch);
 
    
$ret = array();
    if(!
$fp) {
        
$ret['seeds'] = -1;
        
$ret['peers'] = -1;
    }else{
        
$stats = BDecode($fp);
        
$binhash = addslashes(pack("H*", $hash));
        
$seeds = $stats['files'][$binhash]['complete'];
        
$peers = $stats['files'][$binhash]['incomplete'];
        
$downloaded = $stats['files'][$binhash]['downloaded'];
        
$ret['seeds'] = $seeds;
        
$ret['peers'] = $peers;
        
$ret['downloaded'] = $downloaded;
    }
    return 
$ret;
}
 
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"]);
        return 
sprintf("%d:%02d", $t["min"], $t["sec"]);
}
 
function 
gmtime() {
    return 
strtotime(get_date_time());
}
 
function 
loggedinonly() {
        global 
$CURUSER;
        if (!
$CURUSER) {
            
header("Refresh: 0; url=account-login.php?returnto=" . urlencode($_SERVER["REQUEST_URI"]));
            exit();
        }
        
$wherethisuser = where ($_SERVER["SCRIPT_FILENAME"],$CURUSER["id"]);
}
 
function 
validfilename($name) {
    return 
preg_match('/^[^\0-\x1f:\\\\\/?*\xff#<>|]+$/si', $name);
}
 
function 
validemail($email) {
//    return preg_match('/^[\w.-]+@([\w.-]+\.)+[a-z]{2,6}$/is', $email);
    
return preg_match('/^([a-z0-9._-](\+[a-z0-9])*)+@[a-z0-9.-]+\.[a-z]{2,6}$/i', $email);
}
 
function 
urlparse($m) {
    
$t = $m[0];
    if (
preg_match(',^\w+://,', $t))
        return 
"<a href=\"$t\">$t</a>";
    return 
"<a href=\"http://$t\">$t</a>";
}
 
function 
parsedescr($d, $html) {
    if (!
$html)
    {
      
$d = htmlspecialchars($d);
      
$d = str_replace("\n", "\n<br />", $d);
    }
    return 
$d;
}
 
function 
mksecret($len = 20) {
    
$ret = "";
    for (
$i = 0; $i < $len; $i++)
        
$ret .= chr(mt_rand(0, 255));
    return 
$ret;
}
 
function 
deletetorrent($id) {
    global 
$site_config;
 
    
$row = @mysql_fetch_array(@mysql_query("SELECT image1,image2 FROM torrents WHERE id=$id"));
 
    foreach(
explode(".","peers.comments.ratings") as $x)
        
mysql_query("DELETE FROM $x WHERE torrent = $id");
 
    if (
file_exists("".$site_config["torrent_dir"]."/$id.torrent"))
        
unlink("".$site_config["torrent_dir"]."/$id.torrent");
 
    if (
$row["image1"]) {
        
$img1 = "".$site_config["torrent_dir"]."/images/".$row["image1"]."";
        
$del = unlink($img1);
    }
 
    if (
$row["image2"]) {
        
$img2 = "".$site_config["torrent_dir"]."/images/".$row["image2"]."";
        
$del = unlink($img2);
    }
 
    
mysql_query("DELETE FROM torrents WHERE id = $id");
}
 
function 
deleteaccount($userid) {
        
mysql_query("DELETE FROM users WHERE id = $userid");
        
mysql_query("DELETE FROM warnings WHERE userid = $userid");
        
mysql_query("DELETE FROM ratings WHERE user = $userid");
}
 
function 
genrelist() {
    
$ret = array();
    
$res = mysql_query("SELECT id, name, parent_cat FROM categories ORDER BY parent_cat ASC, sort_index ASC");
    while (
$row = mysql_fetch_array($res))
        
$ret[] = $row;
    return 
$ret;
}
 
function 
langlist() {
    
$ret = array();
    
$res = mysql_query("SELECT id, name, image FROM torrentlang ORDER BY sort_index, id");
    while (
$row = mysql_fetch_array($res))
        
$ret[] = $row;
    return 
$ret;
}
 
 
function 
agelist() {
    
$ret = array();
    
$res = mysql_query("SELECT id, name, image FROM torrentage ORDER BY sort_index, id");
    while (
$row = mysql_fetch_array($res))
        
$ret[] = $row;
    return 
$ret;
}
 
function 
is_valid_id($id){
    return 
is_numeric($id) && ($id > 0) && (floor($id) == $id);
}
 
function 
sql_timestamp_to_unix_timestamp($s){
    return 
mktime(substr($s, 11, 2), substr($s, 14, 2), substr($s, 17, 2), substr($s, 5, 2), substr($s, 8, 2), substr($s, 0, 4));
}
 
function 
write_log($text){
    
$text = sqlesc($text);
    
$added = sqlesc(get_date_time());
    
mysql_query("INSERT INTO log (added, txt) VALUES($added, $text)") or sqlerr();
}
 
function 
get_elapsed_time($ts){
  
$mins = floor((gmtime() - $ts) / 60);
  
$hours = floor($mins / 60);
  
$mins -= $hours * 60;
  
$days = floor($hours / 24);
  
$hours -= $days * 24;
  
$weeks = floor($days / 7);
  
$days -= $weeks * 7;
  
$t = "";
  if (
$weeks > 0)
    return 
"$weeks wk" . ($weeks > 1 ? "s" : "");
  if (
$days > 0)
    return 
"$days day" . ($days > 1 ? "s" : "");
  if (
$hours > 0)
    return 
"$hours hr" . ($hours > 1 ? "s" : "");
  if (
$mins > 0)
    return 
"$mins min" . ($mins > 1 ? "s" : "");
  return 
"< 1 min";
}
 
function 
hex2bin($hexdata) {
    
$bindata = "";
    for (
$i=0;$i<strlen($hexdata);$i+=2) {
        
$bindata.=chr(hexdec(substr($hexdata,$i,2)));
    }
    return 
$bindata;
}
 
function 
guestadd() {
    
$ip = $_SERVER["REMOTE_ADDR"];
    
$sql = mysql_query("SELECT time FROM guests WHERE ip='$ip'");
    
$ctime = gmtime();
    if (
mysql_fetch_row($sql))
    {
        @
mysql_query("UPDATE guests SET ip='$ip', time='$ctime' WHERE ip='$ip'");
    } else {
        @
mysql_query("INSERT INTO guests (ip, time) VALUES ('$ip', '$ctime')");
    }
}
 
function 
getguests() {
    
$ip = $_SERVER["REMOTE_ADDR"];
    
$past = gmtime()-2400;
    @
mysql_query("DELETE FROM guests WHERE time < $past");
    
$guests = number_format(get_row_count("guests"));
    return 
$guests;
}
 
function 
time_ago($addtime) {
   
$addtime = get_elapsed_time(sql_timestamp_to_unix_timestamp($addtime));
   return 
$addtime;
}
 
function 
CutName ($vTxt, $Car) {
    while(
strlen($vTxt) > $Car) {
        return 
substr($vTxt, 0, $Car) . "...";
    } return 
$vTxt;
}
 
function 
searchfield($s) {
    return 
preg_replace(array('/[^a-z0-9]/si', '/^\s*/s', '/\s*$/s', '/\s+/s'), array(" ", "", "", " "), $s);
}
 
function 
get_row_count($table, $suffix = "") {
  if (
$suffix)
    
$suffix = " $suffix";
  (
$r = mysql_query("SELECT COUNT(*) FROM $table$suffix")) or die(mysql_error());
  (
$a = mysql_fetch_row($r)) or die(mysql_error());
  return 
$a[0];
}
 
function 
sqlerr($query = "") {
    
stdhead();
    
begin_frame("MYSQL Error");
    print(
"<BR><b>MySQL error occured</b>.\n<br />Query: " . $query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());
    
end_frame();
    
stdfoot();
    die;
}
 
function 
get_dt_num(){
    return 
gmdate("YmdHis");
}
 
 
function 
get_date_time($timestamp = 0){
    if (
$timestamp)
    return 
date("Y-m-d H:i:s", $timestamp);
    else
      return 
gmdate("Y-m-d H:i:s");
}
 
// Convert UTC to user's timezone
function utc_to_tz ($timestamp=0) {
    GLOBAL 
$CURUSER;
    if (!
is_numeric($timestamp))
        
$timestamp = sql_timestamp_to_unix_timestamp($timestamp);
    if (
$timestamp == 0)
        
$timestamp = gmtime();
 
    
$timestamp = $timestamp + ($CURUSER['tzoffset']*60);
    return 
date("Y-m-d H:i:s", $timestamp);
}
 
function 
utc_to_tz_time ($timestamp=0) {
    GLOBAL 
$CURUSER;
 
    if (!
is_numeric($timestamp))
        
$timestamp = sql_timestamp_to_unix_timestamp($timestamp);
    if (
$timestamp == 0)
        
$timestamp = gmtime();
 
    
$timestamp = $timestamp + ($CURUSER['tzoffset']*60);
    return 
$timestamp;
}
 
function 
encodehtml($s, $linebreaks = true) {
      
$s = str_replace("<", "&lt;", str_replace("&", "&amp;", $s));
      if (
$linebreaks)
        
$s = nl2br($s);
      return 
$s;
}
 
 
function 
format_urls($s){
    return 
preg_replace(
    
"/(\A|[^=\]'\"a-zA-Z0-9])((http|ftp|https|ftps|irc):\/\/[^<>\s]+)/i",
    
"\\1<a href=http://anonym.to/?\\2 target=_blank>\\2</a>", $s);
}
 
function 
format_comment($text)
{
    global 
$site_config, $smilies, $privatesmilies;
 
    
$s = $text;
 
    
$s = htmlspecialchars($s);
    
$s = stripslashes($s);
    
$s = format_urls($s);
 
    
// [*]
    
$s = preg_replace("/\[\*\]/", "<li>", $s);
 
    
// [b]Bold[/b]
    
$s = preg_replace("/\[b\]((\s|.)+?)\[\/b\]/", "<b>\\1</b>", $s);
 
    
// [i]Italic[/i]
    
$s = preg_replace("/\[i\]((\s|.)+?)\[\/i\]/", "<i>\\1</i>", $s);
 
    
// [u]Underline[/u]
    
$s = preg_replace("/\[u\]((\s|.)+?)\[\/u\]/", "<u>\\1</u>", $s);
 
    
// [u]Underline[/u]
    
$s = preg_replace("/\[u\]((\s|.)+?)\[\/u\]/i", "<u>\\1</u>", $s);
 
    
// [img]http://www/image.gif[/img]
    
$s = preg_replace("/\[img\](http:\/\/[^\s'\"<>]+(\.gif|\.jpg|\.png|\.bmp|\.jpeg))\[\/img\]/i", "<a href=\"\\1\" rel=\"ibox\"><IMG border=\"0\" src=\"\\1\" width=120 title=\"Click to enlarge\"></a>", $s); 
 
    
// [img=http://www/image.gif]
    
$s = preg_replace("/\[img=(http:\/\/[^\s'\"<>]+(\.gif|\.jpg|\.png|\.bmp|\.jpeg))\]/i", "<a href=\"\\1\" rel=\"ibox\"><IMG border=\"0\" src=\"\\1\" width=120 title=\"Click to enlarge\"></a>", $s); 
 
    
// [color=blue]Text[/color]
    
$s = preg_replace(
        
"/\[color=([a-zA-Z]+)\]((\s|.)+?)\[\/color\]/i",[/color]
[
color=([a-zA-Z]        "<font color=\\1>\\2</font>", $s);[/color]
[
color=([a-zA-Z][/color]
[
color=([a-zA-Z]    // [color=#ffcc99]Text[/color]
    
$s = preg_replace(
        
"/\[color=(#[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9])\]((\s|.)+?)\[\/color\]/i",
        
"<font color=\\1>\\2</font>", $s);
 
    
// [url=http://www.example.com]Text[/url]
    
$s = preg_replace(
        
"/\[url=((http|ftp|https|ftps|irc):\/\/[^<>\s]+?)\]((\s|.)+?)\[\/url\]/i",
        
"<a href=http://anonym.to/?\\1 target=_blank>\\3</a>", $s);
 
    
// [url]http://www.example.com[/url]
    
$s = preg_replace(
        
"/\[url\]((http|ftp|https|ftps|irc):\/\/[^<>\s]+?)\[\/url\]/i",
        
"<a href=http://anonym.to/?\\1 target=_blank>\\1</a>", $s);
 
    
// [size=4]Text[/size]
    
$s = preg_replace(
        
"/\[size=([1-7])\]((\s|.)+?)\[\/size\]/i",
        
"<font size=\\1>\\2</font>", $s);
 
    
// [font=Arial]Text[/font]
    
$s = preg_replace(
        
"/\[font=([a-zA-Z ,]+)\]((\s|.)+?)\[\/font\]/i",
        
"<font face=\"\\1\">\\2</font>", $s);
 
    
//<<<@!2!@>>>
    
$s = preg_replace(
        
"/\<<<@!3!@>>>
    
$s = preg_replace(
        "
/\<<<@!2!@>>>
The code is not working !
Please paste here the functions.php if you know to resolve it
Reply With Quote