Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
User Posts

Go to Profile

Emails — 2024-02-19 18:52:04 in General Chat
use pear
http://pear.php.net/Mail
shell
pear install Mail


or you can use ((phpmailer))
https://torrenttrader.uk/post/4689
fix torrents name — 2024-02-08 03:55:24 in v3 Support
torrents.php

name of files torrent its short
look img  know what is problem

its working
dont change  this line in config.php
$site_config['PASSKEYURL'] =  "$site_config[SITEURL]/announce.php?passkey=%s"; // Announce URL to use for passkey


solved
100%
every thing work
bbcode.php
functions.php

i dont know hoe use your code
this my 2 files
i dont know how use your code

functions.php
<?php


error_reporting(E_ALL ^ E_NOTICE);

// Prefer unescaped. Data will be escaped as needed.
if (ini_get("magic_quotes_gpc")) {
$_POST = array_map_recursive("unesc", $_POST);
$_GET = array_map_recursive("unesc", $_GET);
$_REQUEST = array_map_recursive("unesc", $_REQUEST);
$_COOKIE = array_map_recursive("unesc", $_COOKIE);
}

if (function_exists("date_default_timezone_set"))
date_default_timezone_set("Europe/London"); // Do NOT change this. All times are converted to user's chosen timezone.

/// each() replacement for php 7+. Change all instances of each() to thisEach() in all TT files. each() deprecated as of 7.2
function thisEach(&$arr) {
   $key = key($arr);
   $result = ($key === null) ? false : [$key, current($arr), 'key' => $key, 'value' => current($arr)];
   next($arr);
   return $result;
}
///end each() replacement

///mysql_result replacement for php 7+. Change all mysql_result to mysqli_result in all TT files. mysql_result deprercated/removed, so emulate it. Should switch to data_seek
function mysqli_result($res,$row=0,$col=0){
   $numrows = mysqli_num_rows($res);
   if ($numrows && $row <= ($numrows-1) && $row >=0){
       mysqli_data_seek($res,$row);
       $resrow = (is_numeric($col)) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res);
       if (isset($resrow[$col])){
           return $resrow[$col];
       }
   }
   return false;
}
///end mysql_result replacement

define("BASEPATH", str_replace("backend", "", dirname(__FILE__)));
$BASEPATH = BASEPATH;
define("BACKEND", dirname(__FILE__));
$BACKEND = BACKEND;

require_once(BACKEND."/mysql.php"); //Get MYSQL Connection Info
require_once(BACKEND."/config.php");  //Get Site Settings and Vars ($site_config)
require(BACKEND."/tzs.php"); // Get Timezones
require_once(BACKEND."/cache.php"); // Caching
require_once(BACKEND."/mail.php"); // Mail functions
require_once(BACKEND."/mysql.class.php");
require_once(BACKEND."/languages.php");

$GLOBALS['tstart'] = array_sum(explode(" ", microtime()));


/**
* Connect to the database and load user details
*
* @param $autoclean
*   (optional) boolean - Check whether or not to run cleanup (default: false)
*/
function dbconn($autoclean = false) {
global $mysql_host, $mysql_user, $mysql_pass, $mysql_db, $THEME, $LANGUAGE, $LANG, $site_config;
$THEME = $LANGUAGE = null;

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]");

function_exists("mysqli_connect") or die("MySQLi support not available.");

$GLOBALS["DBconnector"] = mysqli_connect($mysql_host, $mysql_user, $mysql_pass) or die('DATABASE: mysqli_connect: ' . mysqli_error($GLOBALS["DBconnector"]));
mysqli_select_db($GLOBALS["DBconnector"],$mysql_db) or die('DATABASE: mysqli_select_db: ' . mysqli_error($GLOBALS["DBconnector"]));

unset($mysql_pass); //security

userlogin(); //Get user info

//Get language and theme
$CURUSER = $GLOBALS["CURUSER"];

   $ss_a = mysqli_fetch_assoc(SQL_Query_exec("select uri from stylesheets where id='" . ( $CURUSER ? $CURUSER['stylesheet'] : $site_config['default_theme'] )  . "'"));
$THEME = $ss_a["uri"];

$lng_a = mysqli_fetch_assoc(SQL_Query_exec("select uri from languages where id='" .  ( $CURUSER ? $CURUSER['language'] : $site_config['default_language'] )  . "'"));
$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 = SQL_Query_exec("SELECT last_time FROM tasks WHERE task='cleanup'");
   $row = mysqli_fetch_row($res);
   if (!$row) {
       SQL_Query_exec("INSERT INTO tasks (task, last_time) VALUES ('cleanup',$now)");
       return;
   }
   $ts = $row[0];
   if ($ts + $site_config["autoclean_interval"] > $now)
       return;
   SQL_Query_exec("UPDATE tasks SET last_time=$now WHERE task='cleanup' AND last_time = $ts");
   if (!mysqli_affected_rows($GLOBALS["DBconnector"]))
       return;

   do_cleanup();
}

// IP Validation
function validip($ip) {
if (extension_loaded("filter")) {
return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
}

if (preg_match('![:a-f0-9]!i', $ip))
return true;

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;
}
return false;
}


//== Updated getip with validation
function getip()
{
  if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
      $ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
      return $ip;
  }
  foreach (array(
      'HTTP_CLIENT_IP',
      'HTTP_X_FORWARDED_FOR',
      'HTTP_X_FORWARDED',
      'HTTP_X_CLUSTER_CLIENT_IP',
      'HTTP_FORWARDED_FOR',
      'HTTP_FORWARDED',
      'HTTP_CF_CONNECTING_IP',
      'REMOTE_ADDR'
  ) as $key) {
      if (array_key_exists($key, $_SERVER) === true) {
          foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
              if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) {
                  return $ip;
              }
          }
      }
  }
}

 


function userlogin() {
$ip = getip();
// If there's no IP a script is being ran from CLI. Any checks here will fail, skip all.
if ($ip == "") return;

GLOBAL $CURUSER;
unset($GLOBALS["CURUSER"]);

//Check IP bans
if (is_ipv6($ip))
$nip = ip2long6($ip);
else
$nip = ip2long($ip);
$res = SQL_Query_exec("SELECT * FROM bans");
while ($row = mysqli_fetch_assoc($res)) {
$banned = false;
if (is_ipv6($row["first"]) && is_ipv6($row["last"]) && is_ipv6($ip)) {
$row["first"] = ip2long6($row["first"]);
$row["last"] = ip2long6($row["last"]);
$banned = bccomp($row["first"], $nip) != -1 && bccomp($row["last"], $nip) != -1;
} else {
$row["first"] = ip2long($row["first"]);
$row["last"] = ip2long($row["last"]);
$banned = $nip >= $row["first"] && $nip <= $row["last"];
}
if ($banned) {
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 (strlen($_COOKIE["pass"]) != 40 || !is_numeric($_COOKIE["uid"])) {
logoutcookie();
return;
}

//Get User Details And Permissions
$res = SQL_Query_exec("SELECT * FROM users INNER JOIN groups ON users.class=groups.group_id WHERE id=$_COOKIE[uid] AND users.enabled='yes' AND users.status = 'confirmed'");
$row = mysqli_fetch_assoc($res);

if (!$row || sha1($row["id"].$row["secret"].$row["password"].$ip.$row["secret"]) != $_COOKIE["pass"]) {
logoutcookie();
return;
}

$where = where ($_SERVER["SCRIPT_FILENAME"], $row["id"], 0);
SQL_Query_exec("UPDATE users SET last_access='" . get_date_time() . "', ip=".sqlesc($ip).", page=".sqlesc($where)." WHERE id=" . $row["id"]);


$GLOBALS["CURUSER"] = $row;
unset($row);
}

function logincookie($id, $password, $secret, $updatedb = 1, $expires = 0x7fffffff) {
$hash = sha1($id.$secret.$password.getip().$secret);
setcookie("pass", $hash, $expires, "/");
setcookie("uid", $id, $expires, "/");

if ($updatedb)
SQL_Query_exec("UPDATE users SET last_login = '".get_date_time()."' WHERE id = $id");
}

function logoutcookie() {
setcookie("pass", null, time(), "/");
setcookie("uid", null, time(), "/");
}

function stdhead($title = "") {
global $site_config, $CURUSER, $THEME, $LANGUAGE;  //Define globals

//site online check
if (!$site_config["SITE_ONLINE"]){
if ($CURUSER["control_panel"] != "yes") {
echo '<br /><br /><br /><center>'. stripslashes($site_config["OFFLINEMSG"]) .'</center><br /><br />';
die;
}else{
echo '<br /><br /><br /><center><b><font color="#ff0000">SITE OFFLINE, STAFF 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");
mysqli_close($GLOBALS["DBconnector"]);
}

function leftblocks() {
   global $site_config, $CURUSER, $THEME, $LANGUAGE, $TTCache, $blockfilename;  //Define globals

   if (($blocks=$TTCache->get("blocks_left", 900)) === false) {
       $res = SQL_Query_exec("SELECT * FROM blocks WHERE position='left' AND enabled=1 ORDER BY sort");
       $blocks = array();
       while ($result = mysqli_fetch_assoc($res)) {
               $blocks[] = $result["name"];
       }
       $TTCache->Set("blocks_left", $blocks, 900);
   }

   foreach ($blocks as $blockfilename){
       include("blocks/".$blockfilename."_block.php");
   }
}

function rightblocks() {
   global $site_config, $CURUSER, $THEME, $LANGUAGE, $TTCache, $blockfilename;  //Define globals

   if (($blocks=$TTCache->get("blocks_right", 900)) === false) {
       $res = SQL_Query_exec("SELECT * FROM blocks WHERE position='right' AND enabled=1 ORDER BY sort");
       $blocks = array();
       while ($result = mysqli_fetch_assoc($res)) {
               $blocks[] = $result["name"];
       }
       $TTCache->Set("blocks_right", $blocks, 900);
   }

   foreach ($blocks as $blockfilename){
       include("blocks/".$blockfilename."_block.php");
   }
}

function middleblocks() {
   global $site_config, $CURUSER, $THEME, $LANGUAGE, $TTCache;  //Define globals

   if (($blocks=$TTCache->get("blocks_middle", 900)) === false) {
       $res = SQL_Query_exec("SELECT * FROM blocks WHERE position='middle' AND enabled=1 ORDER BY sort");
       $blocks = array();
       while ($result = mysqli_fetch_assoc($res)) {
               $blocks[] = $result["name"];
       }
       $TTCache->Set("blocks_middle", $blocks, 900);
   }

   foreach ($blocks as $blockfilename){
       include("blocks/".$blockfilename."_block.php");
   }
}

function show_error_msg($title, $message, $wrapper = "1") {
if ($wrapper) {
       ob_start();
       ob_clean();
stdhead($title);
}
begin_frame("<font class='error'>". htmlspecialchars($title) ."</font>");
print("<center><b>" . $message . "</b></center>\n");
end_frame();

if ($wrapper){
stdfoot();
die();
}
}

function health($leechers, $seeders) {
if (($leechers == 0 && $seeders == 0) || ($leechers > 0 && $seeders == 0))
return 0;
elseif ($seeders > $leechers)
return 10;

$ratio = $seeders / $leechers * 100;
if ($ratio > 0 && $ratio < 15)
return 1;
elseif ($ratio >= 15 && $ratio < 25)
return 2;
elseif ($ratio >= 25 && $ratio < 35)
return 3;
elseif ($ratio >= 35 && $ratio < 45)
return 4;
elseif ($ratio >= 45 && $ratio < 55)
return 5;
elseif ($ratio >= 55 && $ratio < 65)
return 6;
elseif ($ratio >= 65 && $ratio < 75)
return 7;
elseif ($ratio >= 75 && $ratio < 85)
return 8;
elseif ($ratio >= 85 && $ratio < 95)
return 9;
else
return 10;
}


// MySQL escaping
function sqlesc($x) {
  if (!is_numeric($x)) {
      $x = "'".mysqli_real_escape_string($GLOBALS["DBconnector"],$x)."'";
  }
  return $x;
}


function unesc($x) {
if (get_magic_quotes_gpc())
return stripslashes($x);
return $x;
}

/**
* Convert bytes to readable format
*
* @param $s
*   integer: bytes
* @param $precision
*   (optional) integer: decimal precision (default: 2)
* @return
*   string: formatted size
*/
function mksize ($s, $precision = 2) {
$suf = array("B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");

for ($i = 1, $x = 0; $i <= count($suf); $i++, $x++) {
if ($s < pow(1024, $i) || $i == count($suf)) // Change 1024 to 1000 if you want 0.98GB instead of 1,0000MB
return number_format($s/pow(1024, $x), $precision)." ".$suf[$x];
}
}

function escape_url($url) {
$ret = '';
for($i = 0; $i < strlen($url); $i+=2)
$ret .= '%'.$url[$i].$url[$i + 1];
return $ret;
}

/**
* Scrape torrent and return stats
*
* @param $scrape
*   string: Scrape URL
* @param $hash
*   string: SHA1 hash (info_hash) of torrent
* @return
*   array:
*     All -1 if failed
*     - seeds: integer - number of seeders
*     - leechers: integer - number of leechers
*     - downloaded: integer - number of complete downloads
*
*/
function torrent_scrape_url($scrape, $hash) {
if (function_exists("curl_exec")) {
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $scrape.'?info_hash='.escape_url($hash));
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
       curl_setopt ($ch, CURLOPT_HEADER, false);
$fp = curl_exec($ch);
curl_close($ch);
} else {
ini_set('default_socket_timeout',10);
$fp = @file_get_contents($scrape.'?info_hash='.escape_url($hash));
}
$ret = array();
if ($fp) {
$stats = BDecode($fp);
$binhash = pack("H*", $hash);
       $binhash = addslashes($binhash);
$seeds = $stats['files'][$binhash]['complete'];
$peers = $stats['files'][$binhash]['incomplete'];
$downloaded = $stats['files'][$binhash]['downloaded'];
$ret['seeds'] = $seeds;
$ret['peers'] = $peers;
$ret['downloaded'] = $downloaded;
}

if ($ret['seeds'] === null) {
$ret['seeds'] = -1;
$ret['peers'] = -1;
$ret['downloaded'] = -1;
}

return $ret;
}

function mkprettytime($s) {
if ($s < 0)
$s = 0;

$t = array();
$t["day"] = floor($s / 86400);
$s -= $t["day"] * 86400;

$t["hour"] = floor($s / 3600);
$s -= $t["hour"] * 3600;

$t["min"] = floor($s / 60);
$s -= $t["min"] * 60;

$t["sec"] = $s;

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 sql_timestamp_to_unix_timestamp(get_date_time());
}

function loggedinonly() {
global $CURUSER;
if (!$CURUSER) {
header("Refresh: 0; url=account-login.php?returnto=" . urlencode($_SERVER["REQUEST_URI"]));
exit();
}
}

function validfilename($name) {
   return preg_match('/^[^\0-\x1f:\\\\\/?*\xff#<>|]+$/si', $name);
}

function validemail($email) {
if (function_exists("filter_var"))
return filter_var($email, FILTER_VALIDATE_EMAIL);
return preg_match('/^([a-z0-9._-](\+[a-z0-9])*)+@[a-z0-9.-]+\.[a-z]{2,6}$/i', $email);
}

function mksecret($len = 20) {
$chars = array_merge(range(0, 9), range("A", "Z"), range("a", "z"));
shuffle($chars);
$x = count($chars) - 1;
for ($i = 1; $i <= $len; $i++)
$str .= $chars[mt_rand(0, $x)];
return $str;
}

function deletetorrent($id) {
global $site_config;

$row = @mysqli_fetch_assoc(@SQL_Query_exec("SELECT image1,image2 FROM torrents WHERE id=$id"));

foreach(explode(".","peers.comments.ratings.files.announce") as $x)
SQL_Query_exec("DELETE FROM $x WHERE torrent = $id");

SQL_Query_exec("DELETE FROM completed WHERE torrentid = $id");

   if (file_exists($site_config["torrent_dir"] . "/$id.torrent"))
       unlink($site_config["torrent_dir"] . "/$id.torrent");
   
   if ($row["image1"]) {                            
       unlink($site_config['torrent_dir'] . "/images/" . $row["image1"]);
   }
   
   if ($row["image2"]) {
       unlink($site_config['torrent_dir'] . "/images/" . $row["image2"]);
   }

@unlink($site_config["nfo_dir"]."/$id.nfo");

SQL_Query_exec("DELETE FROM torrents WHERE id = $id");
   SQL_Query_exec("DELETE FROM reports WHERE votedfor = $id AND type = 'torrent'");
SQL_Query_exec("DELETE FROM `snatched` WHERE `tid` = '$id'");
}

function deleteaccount($userid)
{
SQL_Query_exec("DELETE FROM users WHERE id = $userid");
SQL_Query_exec("DELETE FROM warnings WHERE userid = $userid");
SQL_Query_exec("DELETE FROM ratings WHERE user = $userid");
SQL_Query_exec("DELETE FROM peers WHERE userid = $userid");
   SQL_Query_exec("DELETE FROM completed WHERE userid = $userid");
   SQL_Query_exec("DELETE FROM reports WHERE addedby = $userid");
   SQL_Query_exec("DELETE FROM reports WHERE votedfor = $userid AND type = 'user'");
   SQL_Query_exec("DELETE FROM forum_readposts WHERE userid = $userid");
   SQL_Query_exec("DELETE FROM pollanswers WHERE userid = $userid");
SQL_Query_exec("DELETE FROM `snatched` WHERE `uid` = '$userid'");
}

function genrelist() {
   $ret = array();
   $res = SQL_Query_exec("SELECT id, name, parent_cat FROM categories ORDER BY parent_cat ASC, sort_index ASC");
   while ($row = mysqli_fetch_assoc($res))
       $ret[] = $row;
   return $ret;
}

function langlist() {
   $ret = array();
   $res = SQL_Query_exec("SELECT id, name, image FROM torrentlang ORDER BY sort_index, id");
   while ($row = mysqli_fetch_assoc($res))
       $ret[] = $row;
   return $ret;
}

function is_valid_id($id){
return is_numeric($id) && ($id > 0) && (floor($id) == $id);
}

function is_valid_int($id){
return is_numeric($id) && (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());
SQL_Query_exec("INSERT INTO log (added, txt) VALUES($added, $text)");
}

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 guestadd() {
   $ip = $_SERVER['REMOTE_ADDR'];
   $time = gmtime();
   SQL_Query_exec("INSERT INTO `guests` (`ip`, `time`) VALUES ('$ip', '$time') ON DUPLICATE KEY UPDATE `time` = '$time'");
}
                               
function getguests() {
   $past = (gmtime() - 2400);
   SQL_Query_exec("DELETE FROM `guests` WHERE `time` < $past");
   return get_row_count("guests");
}

function time_ago($addtime) {
  $addtime = get_elapsed_time(sql_timestamp_to_unix_timestamp($addtime));
  return $addtime;
}

function CutName ($vTxt, $Car) {
if (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 = "") {
   $res = SQL_Query_exec("SELECT COUNT(*) FROM $table $suffix");
   $row = mysqli_fetch_row($res);
   return $row[0];
}

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, $tzs;

if (method_exists("DateTime", "setTimezone")) {
if (!$timestamp)
$timestamp = get_date_time();
$date = new DateTime($timestamp, new DateTimeZone("UTC"));

$date->setTimezone(new DateTimeZone($CURUSER ? $tzs[$CURUSER["tzoffset"]][1] : "Europe/London"));
return $date->format('Y-m-d H:i:s');
}
if (!is_numeric($timestamp))
$timestamp = sql_timestamp_to_unix_timestamp($timestamp);
if ($timestamp == 0)
$timestamp = gmtime();

$timestamp = $timestamp + ($CURUSER['tzoffset']*60);
if (date("I")) $timestamp += 3600; // DST Fix
return date("Y-m-d H:i:s", $timestamp);
}

function utc_to_tz_time ($timestamp=0) {
GLOBAL $CURUSER, $tzs;

if (method_exists("DateTime", "setTimezone")) {
if (!$timestamp)
$timestamp = get_date_time();
$date = new DateTime($timestamp, new DateTimeZone("UTC"));
$date->setTimezone(new DateTimeZone($CURUSER ? $tzs[$CURUSER["tzoffset"]][1] : "Europe/London"));
return sql_timestamp_to_unix_timestamp($date->format('Y-m-d H:i:s'));
}

if (!is_numeric($timestamp))
$timestamp = sql_timestamp_to_unix_timestamp($timestamp);
if ($timestamp == 0)
$timestamp = gmtime();

$timestamp = $timestamp + ($CURUSER['tzoffset']*60);
if (date("I")) $timestamp += 3600; // DST Fix

return $timestamp;
}

function encodehtml($s, $linebreaks = true) {
 $s = str_replace("<", "<", str_replace("&", "&", $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='\\2' target='_blank'>\\2</a>", $s);
}

function format_comment($text) {
   global $site_config, $smilies;

   $s = $text;

   $s = htmlspecialchars($s);
   $s = format_urls($s);
   //

  •    $s = preg_replace("/\[\*\]/", "<li>", $s);
       //
    Centrer
    ou
    center

       $s = preg_replace("#\[center\](.+)\[/center\]#isU", "<center>$1</center>", $s);
       // Bold
       $s = preg_replace("/\[b\]((\s|.)+?)\[\/b\]/", "<b>\\1</b>", $s);
       // Italic
       $s = preg_replace("/\[i\]((\s|.)+?)\[\/i\]/", "<i>\\1</i>", $s);
       // Underline
       $s = preg_replace("/\[u\]((\s|.)+?)\[\/u\]/", "<u>\\1</u>", $s);
       // Line
       $s = preg_replace("#\[s\](.+)\[/s\]#isU", "<span style='text-decoration:line-through;'>$1</span>", $s);
       // List 1
       $s = preg_replace("#\[list\](.+)\[/list\]#isU", "<li style= 'margin-left: 20px;'>$1</li>", $s);
       // List 2
       $s = preg_replace("#\[*\](.+)\[/*\]#isU", "<li style= 'margin-left: 20px;'>$1</li>", $s);
       // Quote 1
       while (preg_match("#\[quote\](.+)\[/quote\]#isU", $s))
           $s = preg_replace("#\[quote\](.+)\[/quote\]#isU", "<blockquote><strong> Quote : </strong></blockquote><table class='main' border='1' cellspacing='0' cellpadding='10'><tr><td style='border: 1px black dotted'>$1</td></tr></table><br />", $s);
       // Quote 2
       while (preg_match("#\[quote=(.+)\](.+)\[/quote\]#isU", $s))
           $s = preg_replace("#\[quote=(.*?)\](.+)\[/quote\]#isU", "<blockquote><strong>$1 écrit : </strong></blockquote><table class='main' border='1' cellspacing='0' cellpadding='10'><tr><td style='border: 1px black dotted'>$2</td></tr></table><br />", $s);
       ///Multi Quote For Private Message
       while(preg_match( '#\[reponse(.*)\](.+)\[/reponse\]#isU', $s))
           $s= preg_replace('#\[reponse(.*)\](.+)\[/reponse\]#isU','<table class=main border=2 cellspacing=0 cellpadding=10><tr><td style=border: 1px black dotted>$2</td></tr></table><br />',$s);
       // Extract the Code
       $s = preg_replace("#\[code\](.+)\[/code\]#isU", "<p class='sub'><b> Extract the Code : </b><center><table class=bbcodecode border=1 cellspacing=0 cellpadding=5><tr><td style='border: 1px lime solid'>$1</td></tr></table></center></p><br />", $s);
       // Links
       // Text
       $s = preg_replace("#\[url=((?:ftp|https?)://.*?)\](.*?)\[/url\]#i", "<a href='$1' target='_blank'>$2</a>", $s);
        // http://www.exemple.fr
       $s = preg_replace("#\[url\]((?:ftp|https?)://.*?)\[/url\]#i", "<a href='$1' target='_blank'>$1</a>", $s);
       // Image
       //
       $s = preg_replace("#\[img\]((?:ftp|https?)://[a-z0-9._/-]+(\.gif|\.jpg|\.png|\.bmp|\.jpeg))\[/img\]#isU", "<img src='$1' width='320px' />", $s);
       // [img=http://www/image.gif]
       $s = preg_replace("#\[img=((?:ftp|https?)://[a-z0-9._/-]+(\.gif|\.jpg|\.png|\.bmp|\.jpeg))\]\[/img\]#isU", "<img src='$1' width='320px' />", $s);
       // [video]http://youtube.com/[/video]
       $s = preg_replace("#\[video\](https://www.youtube.com.*v=.+)\[\/video\]#isU", "<center><embed src='https://www.youtube.com/v/$1' type='video' height='140'></embed></center>", $s);
       // [audio]http://image.gif[/audio]
       $s = preg_replace("#\[audio\]((?:ftp|https?)://[a-z0-9._/-]+(\.mp3|\.wav|\.wma|\.aac|\.bwf|\.ogg|\.ac3|\.flac|\.asx|\.pls|\.alac))\[/audio\]#isU", "<img src='$1' />", $s);
       // Polices
       // Text
       $s = preg_replace("#\[color=([a-zA-Z]+)\](.+)\[/color\]#isU", "<font color='$1'>$2</font>", $s);
       // [color=#XXX ou #XXXXXX]Text[/color]
       $s = preg_replace("#\[color=\#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})\](.+)\[/color\]#isU", "<font color='$1'>$2</font>", $s);
       // Size of Style
       $s = preg_replace("#\[size=([1-7])\](.+)\[/size\]#isU", "<font size='$1'>$2</font>", $s);
       // Type of Style
       $s = preg_replace("#\[font=([a-zA-Z].*?)\](.+)\[/font\]#isU", "<font face='$1'>$2</font>", $s);
       // Blink
       $s = preg_replace("#\[blink\](.+)\[/blink\]#isU", "<div id='blink'>$1</div>", $s);
        // Scroller
       $s = preg_replace("#\[df\](.+)\[/df\]#isU", "<div class='marquee'>$1</div>", $s);
       // Text Alignment
       //[align=(center|left|right)]text[/align]
       $s = preg_replace(
       "/\[align=([a-zA-Z]+)\](.+?)\[\/align\]/is",
       "<div style=\"text-align:\\1\">\\2</div>", $s);
       // HTML HTML tag If Need Horizontal Line
       // Attention The Color Is Considered Only On IE For Info
       //

       $s = preg_replace("/\[hr\]/i", "<hr />", $s);
       //[hr=#ffffff] [hr=red]
       $s = preg_replace("/\[hr=((#[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9])|([a-zA-z]+))\]/i", "<hr color=\"\\1\"/>", $s);
       // Linebreaks
       $s = nl2br($s);
       // Maintain spacing
       $s = str_replace("  ", " &nbsp;", $s);

       // Smilies
    require_once("smilies.php");
    reset($smilies);
    while (list($code, $url) = thisEach($smilies))
           $s = str_replace($code, '<img border="0" src="'.$site_config["SITEURL"].'/images/smilies/'.$url.'" alt="'.$code.'" title="'.$code.'" />', $s);

    if($site_config["OLD_CENSOR"])
    {
       $r = SQL_Query_exec("SELECT * FROM censor");
    while($rr=mysqli_fetch_row($r))
    $s = preg_replace("/".preg_quote($rr[0])."/i", $rr[1], $s);
       }
    else
    {

       $f = @fopen("censor.txt","r");
       
       if ($f && filesize("censor.txt") != 0) {
       
          $bw = fread($f, filesize("censor.txt"));
          $badwords = explode("\n",$bw);
         
          for ($i=0; $i<count($badwords); ++$i)
              $badwords[$i] = trim($badwords[$i]);
          $s = str_replace($badwords, "<img src='images/censored.png' border='0' alt='Censored' title='Censored' />", $s);
       }
       @fclose($f);
    }

    return $s;
    }

    function torrenttable($res) {
    global $site_config, $CURUSER, $THEME, $LANGUAGE;  //Define globals

    if ($site_config["MEMBERSONLY_WAIT"] && $site_config["MEMBERSONLY"] && in_array($CURUSER["class"], explode(",",$site_config["WAIT_CLASS"]))) {
    $gigs = $CURUSER["uploaded"] / (1024*1024*1024);
    $ratio = (($CURUSER["downloaded"] > 0) ? ($CURUSER["uploaded"] / $CURUSER["downloaded"]) : 0);
    if ($ratio < 0 || $gigs < 0) $wait = $site_config["WAITA"];
    elseif ($ratio < $site_config["RATIOA"] || $gigs < $site_config["GIGSA"]) $wait = $site_config["WAITA"];
    elseif ($ratio < $site_config["RATIOB"] || $gigs < $site_config["GIGSB"]) $wait = $site_config["WAITB"];
    elseif ($ratio < $site_config["RATIOC"] || $gigs < $site_config["GIGSC"]) $wait = $site_config["WAITC"];
    elseif ($ratio < $site_config["RATIOD"] || $gigs < $site_config["GIGSD"]) $wait = $site_config["WAITD"];
    else $wait = 0;
    }

    // Columns
    $cols = explode(",", $site_config["torrenttable_columns"]);
    $cols = array_map("strtolower", $cols);
    $cols = array_map("trim", $cols);
    $colspan = count($cols);
    // End

    // Expanding Area
    $expandrows = array();
    if (!empty($site_config["torrenttable_expand"])) {
    $expandrows = explode(",", $site_config["torrenttable_expand"]);
    $expandrows = array_map("strtolower", $expandrows);
    $expandrows = array_map("trim", $expandrows);
    }
    // End

    echo '<table align="center" class="ttable_headinner" width="100%"><thead><tr class="ttable_head">';

    foreach ($cols as $col) {
    switch ($col) {
    case 'category':
    echo "<th>".T_("TYPE")."</th>";
    break;
    case 'name':
    echo "<th>".T_("NAME")."</th>";
    break;
    case 'dl':
    echo "<th>".T_("DL")."</th>";
    break;
    case 'uploader':
    echo "<th>".T_("UPLOADER")."</th>";
    break;
    case 'comments':
    echo "<th>".T_("COMM")."</th>";
    break;
    case 'nfo':
    echo "<th>".T_("NFO")."</th>";
    break;
    case 'size':
    echo "<th>".T_("SIZE")."</th>";
    break;
    case 'completed':
    echo "<th>".T_("C")."</th>";
    break;
    case 'seeders':
    echo "<th>".T_("S")."</th>";
    break;
    case 'leechers':
    echo "<th>".T_("L")."</th>";
    break;
    case 'health':
    echo "<th>".T_("HEALTH")."</th>";
    break;
    case 'external':
    if ($site_config["ALLOWEXTERNAL"])
    echo "<th>".T_("L/E")."</th>";
    break;
    case 'added':
    echo "<th>".T_("ADDED")."</th>";
    break;
    case 'speed':
    echo "<th>".T_("SPEED")."</th>";
    break;
    case 'wait':
    if ($wait)
    echo "<th>".T_("WAIT")."</th>";
    break;
    case 'rating':
    echo "<th>".T_("RATINGS")."</th>";
    break;
    }
    }
    if ($wait && !in_array("wait", $cols))
    echo "<th>".T_("WAIT")."</th>";

    echo "</tr></thead>";

    while ($row = mysqli_fetch_assoc($res)) {
    $id = $row["id"];

    print("<tr class='t-row'>\n");

    $x = 1;

    foreach ($cols as $col) {
    switch ($col) {
    case 'category':
    print("<td class='ttable_col$x' align='center' valign='middle'>");
    if (!empty($row["cat_name"])) {
    print("<a href=\"torrents.php?cat=" . $row["category"] . "\">");
    if (!empty($row["cat_pic"]) && $row["cat_pic"] != "")
    print("<img border=\"0\"src=\"" . $site_config['SITEURL'] . "/images/categories/" . $row["cat_pic"] . "\" alt=\"" . $row["cat_name"] . "\" />");
    else
    print($row["cat_parent"].": ".$row["cat_name"]);
    print("</a>");
    } else
    print("-");
    print("</td>\n");
    break;
    case 'name':
    $char1 = 35; //cut name length
    $smallname = htmlspecialchars(CutName($row["name"], $char1));
    $dispname = "<b>".$smallname."</b>";
                   
    $last_access = $CURUSER["last_browse"];
    $time_now = gmtime();
    if ($last_access > $time_now || !is_numeric($last_access))
    $last_access = $time_now;
    if (sql_timestamp_to_unix_timestamp($row["added"]) >= $last_access)
    $dispname .= "<b><font color='#ff0000'> - (".T_("NEW")."!)</font></b>";

    if ($row["freeleech"] == 1)
    $dispname .= " <img src='images/free.gif' border='0' alt='' />";
    print("<td class='ttable_col$x' nowrap='nowrap'>".(count($expandrows)?"<a href=\"javascript: klappe_torrent('t".$row['id']."')\"><img border=\"0\" src=\"".$site_config["SITEURL"]."/images/plus.gif\" id=\"pict".$row['id']."\" alt=\"Show/Hide\" class=\"showthecross\" /></a>":"")."&nbsp;<a title=\"".$row["name"]."\" href=\"torrents-details.php?id=$id&hit=1\">$dispname</a></td>");
    break;
    case 'dl':
    print("<td class='ttable_col$x' align='center'><a href=\"download.php?id=$id&name=" . rawurlencode($row["filename"]) . "\"><img src='" . $site_config['SITEURL'] . "/images/icon_download.gif' border='0' alt=\"Download .torrent\" /></a></td>");
    break;
    case 'uploader':
    echo "<td class='ttable_col$x' align='center'>";
    if (($row["anon"] == "yes" || $row["privacy"] == "strong") && $CURUSER["id"] != $row["owner"] && $CURUSER["edit_torrents"] != "yes")
    echo "Anonymous";
    elseif ($row["username"])
    echo "<a href='account-details.php?id=$row[owner]'>$row[username]</a>";
    else
    echo "Unknown";
    echo "</td>";
    break;
    case 'comments':
    print("<td class='ttable_col$x' align='center'><font size='1' face='verdana'><a href='comments.php?type=torrent&id=$id'>" . number_format($row["comments"]) . "</a></font></td>\n");
    break;
    case 'nfo':
    if ($row["nfo"] == "yes")
    print("<td class='ttable_col$x' align='center'><a href='nfo-view.php?id=$row[id]'><img src='" . $site_config['SITEURL'] . "/images/icon_nfo.gif' border='0' alt='View NFO' /></a></td>");
    else
    print("<td class='ttable_col$x' align='center'>-</td>");
    break;
    case 'size':
    print("<td class='ttable_col$x' align='center'>".mksize($row["size"])."</td>\n");
    break;
    case 'completed':    
    print("<td class='ttable_col$x' align='center'><font color='orange'><b>".number_format($row["times_completed"])."</b></font></td>");
    break;
    case 'seeders':
    print("<td class='ttable_col$x' align='center'><font color='green'><b>".number_format($row["seeders"])."</b></font></td>\n");
    break;
    case 'leechers':
    print("<td class='ttable_col$x' align='center'><font color='#ff0000'><b>" . number_format($row["leechers"]) . "</b></font></td>\n");
    break;
    case 'health':
    print("<td class='ttable_col$x' align='center'><img src='".$site_config["SITEURL"]."/images/health/health_".health($row["leechers"], $row["seeders"]).".gif' alt='' /></td>\n");
    break;
    case 'external':
    if ($site_config["ALLOWEXTERNAL"]){
    if ($row["external"]=='yes')
    print("<td class='ttable_col$x' align='center'>".T_("E")."</td>\n");
    else
    print("<td class='ttable_col$x' align='center'>".T_("L")."</td>\n");
    }
    break;
    case 'added':
    print("<td class='ttable_col$x' align='center'>".date("d-m-Y H:i:s", utc_to_tz_time($row['added']))."</td>");
    break;
    case 'speed':
    if ($row["external"] != "yes" && $row["leechers"] >= 1){
    $speedQ = SQL_Query_exec("SELECT (SUM(downloaded)) / (UNIX_TIMESTAMP('".get_date_time()."') - UNIX_TIMESTAMP(started)) AS totalspeed FROM peers WHERE seeder = 'no' AND torrent = '$id' ORDER BY started ASC");
    $a = mysqli_fetch_assoc($speedQ);
    $totalspeed = mksize($a["totalspeed"]) . "/s";
    } else
    $totalspeed = "--";
    print("<td class='ttable_col$x' align='center'>$totalspeed</td>");
    break;
    case 'wait':
    if ($wait){
    $elapsed = floor((gmtime() - strtotime($row["added"])) / 3600);
    if ($elapsed < $wait && $row["external"] != "yes") {
    $color = dechex(floor(127*($wait - $elapsed)/48 + 128)*65536);
    print("<td class='ttable_col$x' align='center'><a href=\"faq.php#section46\"><font color=\"$color\">" . number_format($wait - $elapsed) . " h</font></a></td>\n");
    } else
    print("<td class='ttable_col$x' align='center'>--</td>\n");
    }
    break;
    case 'rating':
    if (!$row["rating"])
    $rating = "--";
    else
    $rating = "<a title='$row[rating]/5'>".ratingpic($row["rating"])."</a>";
    //$rating = ratingpic($row["rating"]);
                        //$srating .= "$rpic (" . $row["rating"] . " out of 5) " . $row["numratings"] . " users have rated this torrent";
    print("<td class='ttable_col$x' align='center'>$rating</td>");
    break;
    }
    if ($x == 2)
    $x--;
    else
    $x++;
    }


    //Wait Time Check
    if ($wait && !in_array("wait", $cols)) {
    $elapsed = floor((gmtime() - strtotime($row["added"])) / 3600);
    if ($elapsed < $wait && $row["external"] != "yes") {
    $color = dechex(floor(127*($wait - $elapsed)/48 + 128)*65536);
    print("<td class='ttable_col$x' align='center'><a href=\"faq.php\"><font color=\"$color\">" . number_format($wait - $elapsed) . " h</font></a></td>\n");
    } else
    print("<td class='ttable_col$x' align='center'>--</td>\n");
    $colspan++;
    if ($x == 2)
    $x--;
    else
    $x++;
    }

    print("</tr>\n");

    //Expanding area
    if (count($expandrows)) {
    print("<tr class='t-row'><td class='ttable_col$x' colspan='$colspan'><div id=\"kt".$row['id']."\" style=\"margin-left: 2px; display: none;\">");
    print("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");
    foreach ($expandrows as $expandrow) {
    switch ($expandrow) {
    case 'size':
    print("<tr><td><b>".T_("SIZE")."</b>: ".mksize($row['size'])."</td></tr>");
    break;
    case 'speed':
    if ($row["external"] != "yes" && $row["leechers"] >= 1){
    $speedQ = SQL_Query_exec("SELECT (SUM(downloaded)) / (UNIX_TIMESTAMP('".get_date_time()."') - UNIX_TIMESTAMP(started)) AS totalspeed FROM peers WHERE seeder = 'no' AND torrent = '$id' ORDER BY started ASC");
    $a = mysqli_fetch_assoc($speedQ);
    $totalspeed = mksize($a["totalspeed"]) . "/s";
    print("<tr><td><b>".T_("SPEED").":</b> $totalspeed</td></tr>");
    }
    break;
    case 'added':
    print("<tr><td><b>".T_("ADDED").":</b> ".date("d-m-Y \\a\\t H:i:s", utc_to_tz_time($row['added']))."</td></tr>");
    break;
    case 'tracker':
    if ($row["external"] == "yes")
    print("<tr><td><b>".T_("TRACKER").":</b> ".htmlspecialchars($row["announce"])."</td></tr>");
    break;
    case 'completed':
    print("<tr><td><b>".T_("COMPLETED")."</b>: ".number_format($row['times_completed'])."</td></tr>");
    break;
    }
    }
    print("</table></div></td></tr>\n");
    }
    //End Expanding Area


    }

    print("</table><br />\n");

    }

    function pager($rpp, $count, $href, $opts = array()) {
       $pages = ceil($count / $rpp);

       if (!$opts["lastpagedefault"])
           $pagedefault = 0;
       else {
           $pagedefault = floor(($count - 1) / $rpp);
           if ($pagedefault < 0)
               $pagedefault = 0;
       }

       if (isset($_GET["page"])) {
           $page = (int) $_GET["page"];
           if ($page < 0)
               $page = $pagedefault;
       }
       else
           $page = $pagedefault;

       $pager = "";

       $mp = $pages - 1;
       $as = "<b><<&nbsp;".T_("PREVIOUS")."</b>";
       if ($page >= 1) {
           $pager .= "<a href=\"{$href}page=" . ($page - 1) . "\">";
           $pager .= $as;
           $pager .= "</a>";
       }
       else
           $pager .= $as;
       $pager .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
       $as = "<b>".T_("NEXT")."&nbsp;>></b>";
       if ($page < $mp && $mp >= 0) {
           $pager .= "<a href=\"{$href}page=" . ($page + 1) . "\">";
           $pager .= $as;
           $pager .= "</a>";
       }
       else
           $pager .= $as;

       if ($count) {
           $pagerarr = array();
           $dotted = 0;
           $dotspace = 3;
           $dotend = $pages - $dotspace;
           $curdotend = $page - $dotspace;
           $curdotstart = $page + $dotspace;
           for ($i = 0; $i < $pages; $i++) {
               if (($i >= $dotspace && $i <= $curdotend) || ($i >= $curdotstart && $i < $dotend)) {
                   if (!$dotted)
                       $pagerarr[] = "...";
                   $dotted = 1;
                   continue;
               }
               $dotted = 0;
               $start = $i * $rpp + 1;
               $end = $start + $rpp - 1;
               if ($end > $count)
                   $end = $count;
               $text = "$start&nbsp;-&nbsp;$end";
               if ($i != $page)
                   $pagerarr[] = "<a href=\"{$href}page=$i\"><b>$text</b></a>";
               else
                   $pagerarr[] = "<b>$text</b>";
           }
           $pagerstr = join(" | ", $pagerarr);
           $pagertop = "<p align=\"center\">$pager<br />$pagerstr</p>\n";
           $pagerbottom = "<p align=\"center\">$pagerstr<br />$pager</p>\n";
       }
       else {
           $pagertop = "<p align=\"center\">$pager</p>\n";
           $pagerbottom = $pagertop;
       }

       $start = $page * $rpp;

       return array($pagertop, $pagerbottom, "LIMIT $start,$rpp");
    }

    function commenttable($res, $type = null) {
    global $site_config, $CURUSER, $THEME, $LANGUAGE;  //Define globals

    while ($row = mysqli_fetch_assoc($res)) {

    $postername = htmlspecialchars($row["username"]);
    if ($postername == "") {
    $postername = T_("DELUSER");
    $title = T_("DELETED_ACCOUNT");
    $avatar = "";
    $usersignature = "";
    $userdownloaded = "";
    $useruploaded = "";
    }else {
    $privacylevel = $row["privacy"];
    $avatar = htmlspecialchars($row["avatar"]);
    $title =  format_comment($row["title"]);
    $usersignature = stripslashes(format_comment($row["signature"]));
    $userdownloaded = mksize($row["downloaded"]);
    $useruploaded = mksize($row["uploaded"]);
    }

    if ($row["downloaded"] > 0)
    $userratio = number_format($row["uploaded"] / $row["downloaded"], 2);
    else
    $userratio = "---";

    if (!$avatar)
    $avatar = $site_config["SITEURL"]."/images/default_avatar.png";

    $commenttext = format_comment($row["text"]);
     
           $edit = null;
           if ($type == "torrent" && $CURUSER["edit_torrents"] == "yes" || $type == "news" && $CURUSER["edit_news"] == "yes" || $CURUSER['id'] == $row['user'])
               $edit = '[<a href="comments.php?id='.$row["id"].'&type='.$type.'&edit=1">Edit</a>]&nbsp;';
         
           $delete = null;
           if ($type == "torrent" && $CURUSER["delete_torrents"] == "yes" || $type == "news" && $CURUSER["delete_news"] == "yes")
               $delete = '[<a href="comments.php?id='.$row["id"].'&type='.$type.'&delete=1">Delete</a>]&nbsp;';
           
           print('<div class="f-post f-border"><table cellspacing="0" width="100%">');
           print('<tr class="p-title">');
           print('<th align="center" width="150"></th>');
           print('<th align="right">' . $edit . $delete . '[<a href="report.php?comment='.$row["id"].'">Report</a>] Posted: '.date("d-m-Y \\a\\t H:i:s", utc_to_tz_time($row["added"])).'<a id="comment'.$row["id"].'"></a></th>');
           print('</tr>');
           print('<tr valign="top">');
           if ($CURUSER['edit_users'] == 'no' && $privacylevel == 'strong')
               print('<td class="f-border comment-details" align="left" width="150"><center><b>'.$postername.'</b><br /><i>'.$title.'</i><br /><img width="80" height="80" src="'.$avatar.'" alt="" /><br /><br />Uploaded: ---<br />Downloaded: ---<br />Ratio: ---<br /><br /><a href="account-details.php?id='.$row["user"].'"><img src="themes/'.$THEME.'/forums/icon_profile.png" border="" alt="" /></a> <a href="mailbox.php?compose&id='.$row["user"].'"><img src="themes/'.$THEME.'/forums/icon_pm.png" border="0" alt="" /></a></center></td>');
           else
               print('<td class="f-border comment-details" align="left" width="150"><center><b>'.$postername.'</b><br /><i>'.$title.'</i><br /><img width="80" height="80" src="'.$avatar.'" alt="" /><br /><br />Uploaded: '.$useruploaded.'<br />Downloaded: '.$userdownloaded.'<br />Ratio: '.$userratio.'<br /><br /><a href="account-details.php?id='.$row["user"].'"><img src="themes/'.$THEME.'/forums/icon_profile.png" border="0" alt="" /></a> <a href="mailbox.php?compose&id='.$row["user"].'"><img src="themes/'.$THEME.'/forums/icon_pm.png" border="0" alt="" /></a></center></td>');
           print('<td class="f-border comment">'.$commenttext.'<hr />'.$usersignature.'</td>');
           print('</tr>');
           print('</table></div>');  
           print('<br />');      
    }
    }

    function where ($scriptname = "index", $userid, $update=1){
    if (!is_valid_id($userid))
    die;
    if (preg_match("/torrents-details/i", $scriptname))
    $where = "Browsing Torrents Details (ID: $_GET[id])...";
    elseif (preg_match("/torrents.php/i", $scriptname))
    $where = "Browsing Torrents...";
    elseif (preg_match("/account-details/i", $scriptname))
    $where = "Browsing Account Details (ID: $_GET[id])...";
    elseif (preg_match("/torrents-upload/i", $scriptname))
    $where = "Uploading Torrent..";
    elseif (preg_match("/account/i", $scriptname))
    $where = "Browsing User Control Panel...";
    elseif (preg_match("/torrents-search/i", $scriptname))
    $where = "Searching Torrents...";
    elseif (preg_match("/forums/i", $scriptname))
    $where = "Browsing Forums...";
    elseif (preg_match("/index/i", $scriptname))
    $where = "Browsing Homepage...";
    else
    $where = "Unknown Location...";

    if ($update) {
    $query = sprintf("UPDATE users SET page=".sqlesc($where)." WHERE id ='%s'", mysqli_real_escape_string($GLOBALS["DBconnector"],$userid));
    $result = SQL_Query_exec($query);
    }
    return $where;
    }

    function get_user_class_name($i){
    GLOBAL $CURUSER;
    if ($i == $CURUSER["class"])
    return $CURUSER["level"];

    $res=SQL_Query_exec("SELECT level FROM groups WHERE group_id=".$i."");
    $row=mysqli_fetch_row($res);
    return $row[0];
    }

    function get_user_class(){
    return $GLOBALS["CURUSER"]["class"];
    }

    function get_ratio_color($ratio) {
    if ($ratio < 0.1) return "#ff0000";
    if ($ratio < 0.2) return "#ee0000";
    if ($ratio < 0.3) return "#dd0000";
    if ($ratio < 0.4) return "#cc0000";
    if ($ratio < 0.5) return "#bb0000";
    if ($ratio < 0.6) return "#aa0000";
    if ($ratio < 0.7) return "#990000";
    if ($ratio < 0.8) return "#880000";
    if ($ratio < 0.9) return "#770000";
    if ($ratio < 1) return "#660000";
    return "#000000";
    }

    function ratingpic($num) {
    GLOBAL $site_config;
       $r = round($num * 2) / 2;
    if ($r != $num) {
    $n = $num-$r;
    if ($n < .25)
    $n = 0;
    elseif ($n >= .25 && $n < .75)
    $n = .5;
    $r += $n;
    }
       if ($r < 1 || $r > 5)
           return;

       return "<img src=\"".$site_config["SITEURL"]."/images/rating/$r.png\" border=\"0\" alt=\"rating: $num/5\" title=\"rating: $num/5\" />";
    }

    function DateDiff ($start, $end) {
    if (!is_numeric($start))
    $start = sql_timestamp_to_unix_timestamp($start);
    if (!is_numeric($end))
    $end = sql_timestamp_to_unix_timestamp($end);
    return ($end - $start);
    }

    function classlist() {
       $ret = array();
       $res = SQL_Query_exec("SELECT * FROM groups ORDER BY group_id ASC");
       while ($row = mysqli_fetch_assoc($res))
           $ret[] = $row;
       return $ret;
    }

    function array_map_recursive ($callback, $array) {
    $ret = array();

    if (!is_array($array))
    return $callback($array);

    foreach ($array as $key => $val) {
    $ret[$key] = array_map_recursive($callback, $val);
    }
    return $ret;
    }

    function strtobytes ($str) {
    $str = trim($str);
    if (!preg_match('!^([\d\.]+)\s*(\w\w)?$!', $str, $matches))
    return 0;

    $num = $matches[1];
    $suffix = strtolower($matches[2]);
    switch ($suffix) {
    case "tb": // TeraByte
    return $num * 1099511627776;
    case "gb": // GigaByte
    return $num * 1073741824;
    case "mb": // MegaByte
    return $num * 1048576;
    case "kb": // KiloByte
    return $num * 1024;
    case "b": // Byte
    default:
    return $num;
    }
    }

    function cleanstr ($s) {
    if (function_exists("filter_var")) {
    return filter_var($s, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
    } else {
    return preg_replace('/[\x00-\x1F]/', "", $s);
    }
    }

    function is_ipv6 ($s) {
    return is_int(strpos($s, ":"));
    }

    // Taken from php.net comments
    function ip2long6($ipv6) {
     $ip_n = inet_pton($ipv6);
     $bits = 15; // 16 x 8 bit = 128bit
     while ($bits >= 0) {
       $bin = sprintf("%08b",(ord($ip_n[$bits])));
       $ipv6long = $bin.$ipv6long;
       $bits--;
     }
     return gmp_strval(gmp_init($ipv6long,2),10);
    }

    function long2ip6($ipv6long) {

     $bin = gmp_strval(gmp_init($ipv6long,10),2);
     if (strlen($bin) < 128) {
       $pad = 128 - strlen($bin);
       for ($i = 1; $i <= $pad; $i++) {
       $bin = "0".$bin;
       }
     }
     $bits = 0;
     while ($bits <= 7) {
       $bin_part = substr($bin,($bits*16),16);
       $ipv6 .= dechex(bindec($bin_part)).":";
       $bits++;
     }
     // compress

     return inet_ntop(inet_pton(substr($ipv6,0,-1)));
    }

    function passhash ($text) {
    GLOBAL $site_config;

    switch (strtolower($site_config["passhash_method"])) {
    case "sha1":
    return sha1($text);
    break;
    case "md5":
    return md5($text);
    break;
    case "hmac":
    $ret = hash_hmac($site_config["passhash_algorithm"], $text, $site_config["passhash_salt"]);
    return $ret ? $ret : die("Config Error: Unknown algorithm '$site_config[passhash_algorithm]'");
    break;
    default:
    die("Unrecognised passhash_method. Check your config.");
    }
    }

     function autolink($al_url, $al_msg) {
         stdhead();
         begin_frame("");
         echo "\n<meta http-equiv=\"refresh\" content=\"3; url=$al_url\">\n";
         echo "<b>$al_msg</b>\n";
         echo "\n<b>Redirecting ...</b>\n";
         echo "\n[ <a href='$al_url'>link</a> ]\n";
         end_frame();
         stdfoot();
         exit;
     }
     function seedtime($ts = 0)
    {                                                                                                  
       $days = floor($ts / 86400);
       $hours = floor($ts / 3600 ) % 24;  
       $mins = floor($ts / 60) % 60;
       $secs = $ts % 60;
       return sprintf( '%d days, %d hours, %d minutes, %d seconds...', $days, $hours, $mins, $secs);
    }  
    function reqcommenttable($rows)
    {
    GLOBAL $CURUSER;
    begin_frame();
    $count = 0;
    foreach ($rows as $row) {
    if (isset($row["username"])) {
    $username = $row["username"];
    $ratres =SQL_Query_exec("SELECT uploaded, downloaded from users where username='$username'");
    $rat = mysqli_fetch_array($ratres);
    if ($rat["downloaded"] > 0) {
    $ratio = $rat['uploaded'] / $rat['downloaded'];
    $ratio = number_format($ratio, 3);
    $color = get_ratio_color($ratio);
     if ($color)
     $ratio = "<font color=$color>$ratio</font>";
     } elseif ($rat["uploaded"] > 0)
     $ratio = "Inf.";
     else
     $ratio = "---";
     $title = $row["title"];
     if ($title == "")
     $title = get_user_class_name($row["class"]);
     else
     $title = htmlspecialchars($title);
                print("<br><br><a name=comm" . $row["id"] . " href=account-details.php?id=" . $row["user"] . "><b>" . htmlspecialchars($row["username"]) . "</b></a>" . ($row["donor"] == "yes" ? "<img src=images/star.gif alt='Donor'>" : "") . ($row["warned"] == "yes" ? "<img src=" . "/images/requests/warned.gif alt=\"Warned\">" : "") . " ($title) (Ratio: $ratio)n");
            } else
                print("<a name=comm" . $row["id"] . "><i>(orphaned)</i></a>n");
            print(" at " . $row["added"] . " GMT" . ($row["user"] == $CURUSER["id"] || get_user_class() >= 5 ? "- [<a href=reqcomment.php?action=edit&cid=$row[id]>Edit</a>]" : "") . (get_user_class() >= 5 ? "- [<a href=reqcomment.php?action=delete&cid=$row[id]>Delete</a>]" : "") . ($row["editedby"] && get_user_class() >= 5 ? "- [<a href=reqcomment.php?action=vieworiginal&cid=$row[id]>View original</a>]" : "") . "</p>n");
            $avatar = ($CURUSER["avatar"] != "" ? htmlspecialchars($row["avatar"]) : "");
            if (!$avatar)
                $avatar = "/images/default_avatar.gif";
            $text = format_comment($row["text"]);
            if ($row["editedby"])
                $text .= "<p><font size=1 class=small>Edited by <a href=account-details.php?id=$row[editedby]><b>$row[username]</b></a> $row[editedat] GMT</font></p>n";
            begin_table(true);
            print("<tr valign=top>n");
            print("<td align=center width=80 style='padding: 5px'><img width=80 height=80 src=$avatar></td>n");
            print("<td class=text>$text</td>n");
            print("</tr>n");
            end_table();
        }
        end_frame();

    function class_user($name)
    {
    global $site_config;
      $a ="SELECT class, donated, warned FROM `users` WHERE username ='".$name."'";
          $res = SQL_Query_exec($a);
    $classy = @mysqli_fetch_row($res);
      switch ($classy[0]) {
    case 8: // SYS:
    $col = "#15CFCD";
    break;
    case 7: // ADMINISTRATORSYS:
    $col = "#ff0000";
    break;
    case 6: // Administrator
    $col = "teal";
    break;
    case 5: // Super Moderator
    $col = "#3300CC";
    break;
    case 4: // Moderator
    $col = "#006600";
    break;
    case 3: // VIP
    $col = "#FFFF00";
    break;
    case 2: // Uploader
    $col = "#33FF33";
    break;
    default: // User
    $name = $name;
    }
    if ($classy[1]>0){
    $star="<img src='".$site_config[SITEURL]."/images/star.gif' alt='donated' border='0'>";
    }else{
    $star="";
    }
    if($classy[2]=="yes"){
    $warn="<img src='".$site_config[SITEURL]."/images/warn.gif' alt='warned' border=0>";
    }else{
    $warn="";
    }
    return unesc("<font color='".$col."'>".$name."".$star."".$warn."</font>");
    }

    }
     

    ?>


  • bbecode
    <?php
    // Function To Display BBCodes And Emotions
    function textbbcode($form,$name,$content=""){
    //$form = Form Name
    //$name = Name of Text Area (Textarea)
    //$content = Content Textarea (Only to edit Pages, etc ...)
    // Includen JS Function For BBCode
    include($_SERVER["DOCUMENT_ROOT"]."/backend/BBTag.js");
    // Desired Format Creation In Divs And Tables Form
    print ("<div class='Frame-BBCode' width='70%'><table align='center' width='90%' border='0' cellpadding='1' cellspacing='0'>");
    print ("<tr><td colspan='2' align='center' >");
    // Image of Available BBCodes
    print ("<br /><input id='BBCode' type='button' name='Bold' value='' style=\"background: url('/images/bbcodes/Bold.png'); background-size:100%;\" onclick=\"bbcomment('', '')\" alt='Bold' title='Bold' />");
    print ("<input id='BBCode' type='button' name='Italique' value='' style=\"background: url('/images/bbcodes/Italique.png'); background-size:100%;\" onclick=\"bbcomment('', '')\" alt='Italique' title='Italique' />");
    print ("<input id='BBCode' type='button' name='Highlight' value='' style=\"background: url('/images/bbcodes/Highlight.png'); background-size:100%;\" onclick=\"bbcomment('', '')\" alt='Highlight' title='Highlight' />");
    print ("<input id='BBCode' type='button' name='Barré' value='' style=\"background: url('/images/bbcodes/Barrer.png'); background-size:100%;\" onclick=\"bbcomment('', '')\" alt='Ligne Barrée' title='Ligne Barrée' />&nbsp;&nbsp;&nbsp;");
    print ("<input id='BBCode' type='button' name='List' value='' style=\"background: url('/images/bbcodes/List.png'); background-size:100%;\" onclick=\"bbcomment('
      ', '
    ')\" alt='List' title='List' />");
    print ("<input id='BBCode' type='button' name='Quote'       value='' style=\"background: url('/images/bbcodes/Quote.png'); background-size:100%;\" onclick=\"bbcomment('
    Quote:
    ', '
    ')\" alt='Quote' title='Quote' />");
    print ("<input id='BBCode' type='button' name='Code' value='' style=\"background: url('/images/bbcodes/Code.png'); background-size:100%;\" onclick=\"bbcomment('[code]', '
    ')\" alt='Code' title='Code' />");
    print ("<input id='BBCode' type='button' name='Url' value='' style=\"background: url('/images/bbcodes/Link.png'); background-size:100%;\" onclick=\"bbcomment('[url]', '[/url]')\" alt='Lnk' title='Link' />");
    print ("<input id='BBCode' type='button' name='Image' value='' style=\"background: url('/images/bbcodes/Image.png'); background-size:100%;\" onclick=\"bbcomment('[img]', '[/img]')\" alt='Image' title='Image' />");
    print ("<input id='BBCode' type='button' name='Video' value='' style=\"background: url('/images/bbcodes/Video.png'); background-size:100%;\" onclick=\"bbcomment('[video]', '[/video]')\" alt='Vidéo' title='Vidéo' />");
    print ("<input id='BBCode' type='button' name='Audio' value='' style=\"background: url('/images/bbcodes/Audio.png'); background-size:100%;\" onclick=\"bbcomment('[audio]', '[/audio]')\"   alt='Audio' title='Audio' />");
    print ("<input id='BBCode' type='button' name='Blink'               value='' style=\"background: url('/images/bbcodes/Blink.png'); background-size:100%;\"        onclick=\"bbcomment('[blink]','[/blink]')\" alt='Blink' title='Blink' />");
    print ("<input id='BBCode' type='button' name='scroller' value='' style=\"background: url('/images/bbcodes/scroller.png'); background-size:100%;\" onclick=\"bbcomment('
    ', '
    ')\" alt='scroller' title='scroller' />&nbsp;&nbsp;&nbsp;&nbsp;");
    print ("<input id='BBCode' type='button' name='Align Right'             value='' style=\"background: url('/images/bbcodes/Right.png'); background-size:100%;\" onclick=\"bbcomment('
    ','
    ')\" alt='Align Right' title='Align Right' />");
    print ("<input id='BBCode' type='button' name='Align Center'         value='' style=\"background: url('/images/bbcodes/Center.png'); background-size:100%;\" onclick=\"bbcomment('
    ','
    ')\" alt='Align Center' title='Align Center' />");
    print ("<input id='BBCode' type='button' name='Align Left'             value='' style=\"background: url('/images/bbcodes/Left.png'); background-size:100%;\" onclick=\"bbcomment('
    ','
    ')\" alt='Align Left'       title='Align Left' /><br />");
    // Choose the colour
    print ("</td></tr><tr><td colspan='2' align='center' ><select name='color' style='padding-bottom:3px;' onChange='bbcouleur(this.value);' title='Couleur'>");
    print ("<option value='0' name='color'>Colour</option>");
    print ("<option value='#000000' style='BACKGROUND-COLOR:#000000'>Black</option>");
    print ("<option value='#686868' style='BACKGROUND-COLOR:#686868'>Grey</option>");
    print ("<option value='#708090' style='BACKGROUND-COLOR:#708090'>Dark Grey</option>");
    print ("<option value='#C0C0C0' style='BACKGROUND-COLOR:#C0C0C0'>Light Grey</option>");
    print ("<option value='#FFFFFF' style='BACKGROUND-COLOR:#FFFFFF'>White</option>");
    print ("<option value='#FFFFE0' style='BACKGROUND-COLOR:#FFFFE0'>Beech</option>");
    print ("<option value='#880000' style='BACKGROUND-COLOR:#880000'>Dark Red</option>");
    print ("<option value='#B82428' style='BACKGROUND-COLOR:#B82428'>Light Red</option>");
    print ("<option value='#FF0000' style='BACKGROUND-COLOR:#FF0000'>Red</option>");
    print ("<option value='#FF1490' style='BACKGROUND-COLOR:#FF1490'>Dark Pink</option>");
    print ("<option value='#FF68B0' style='BACKGROUND-COLOR:#FF68B0'>Pink</option>");
    print ("<option value='#FFC0C8' style='BACKGROUND-COLOR:#FFC0C8'>Light Pink</option>");
    print ("<option value='#FF4400' style='BACKGROUND-COLOR:#FF4400'>Dark Orange</option>");
    print ("<option value='#FF6448' style='BACKGROUND-COLOR:#FF6448'>Redish Orange</option>");
    print ("<option value='#FFA800' style='BACKGROUND-COLOR:#FFA800'>Orange</option>");
    print ("<option value='#FFD800' style='BACKGROUND-COLOR:#FFD800'>Dark Yellow</option>");
    print ("<option value='#FFFF00' style='BACKGROUND-COLOR:#FFFF00'>Yellow</option>");            
    print ("<option value='#FF00FF' style='BACKGROUND-COLOR:#FF00FF'>Light Purple</option>");
    print ("<option value='#C01480' style='BACKGROUND-COLOR:#C01480'>Dark Purple</option>");
    print ("<option value='#B854D8' style='BACKGROUND-COLOR:#B854D8'>Dark Violet</option>");
    print ("<option value='#D8A0D8' style='BACKGROUND-COLOR:#D8A0D8'>Light Violet</option>");
    print ("<option value='#000080' style='BACKGROUND-COLOR:#000080'>Darkest Blue</option>");          
    print ("<option value='#0000FF' style='BACKGROUND-COLOR:#0000FF'>Dark Blue</option>");            
    print ("<option value='#2090FF' style='BACKGROUND-COLOR:#2090FF'>Ble</option>");
    print ("<option value='#00BCFF' style='BACKGROUND-COLOR:#00BCFF'>Light Blue</option>");
    print ("<option value='#B0E0E8' style='BACKGROUND-COLOR:#B0E0E8'>Faint Blue</option>");
    print ("<option value='#A02828' style='BACKGROUND-COLOR:#A02828'>Brown</option>");
    print ("<option value='#F0A460' style='BACKGROUND-COLOR:#F0A460'>Brown Creme</option>");  
    print ("<option value='#D0B488' style='BACKGROUND-COLOR:#D0B488'>Light Brown</option>");              
    print ("<option value='#B8B868' style='BACKGROUND-COLOR:#B8B868'>Brown/Green</option>");
    print ("<option value='#008000' style='BACKGROUND-COLOR:#008000'>Dark Green</option>");
    print ("<option value='#30CC30' style='BACKGROUND-COLOR:#30CC30'>Green</option>");
    print ("<option value='#00FF80' style='BACKGROUND-COLOR:#00FF80'>Light Green</option>");
    print ("<option value='#98FC98' style='BACKGROUND-COLOR:#98FC98'>Light Lime</option>");
    print ("<option value='#98CC30' style='BACKGROUND-COLOR:#98CC30'>Dark Lime</option>");
    print ("<option value='#40E0D0' style='BACKGROUND-COLOR:#40E0D0'>Turquois</option>");
    print ("<option value='#20B4A8' style='BACKGROUND-COLOR:#20B4A8'>Aquarium</option></select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
    // Type of Style
    print ("<select name='font' onChange='bbfont(this.value);' title='Style'>");
    print ("<option value='0' name='font'>Style</option><option value='Arial' style='font-family: Arial;'>Arial</option>");
    print ("<option value='Comic Sans MS' style='font-family: Comic Sans MS;'>Comic</option><option value='Trebuchet MS' style='font-family: Trebuchet MS;'>Trebuchet</option>");
    print ("<option value='Courier New' style='font-family: Courier New;'>Courier</option><option value='Georgia' style='font-family: Georgia;'>Georgia</option>");
    print ("<option value='Impact' style='font-family: Impact;'>Impact</option><option value='Lucida Sans Unicode' style='font-family: Lucida Sans Unicode;'>Lucida</option>");
    print ("<option value='Microsoft Sans Serif' style='font-family: Microsoft Sans Serif;'>Microsoft</option>");
    print ("<option value='Tahoma' style='font-family:Tahoma;'>Tahoma</option><option value='Times New Roman' style='font-family:Times New Roman;'>Roman</option>");
    print ("<option value='Verdana' style='font-family:Verdana;'>Verdana</option><option value='Palatino Linotype' style='font-family:Palatino Linotype;'>Palatino</option>");
    print ("<option value='Ravie' style='font-family:Ravie;'>Ravie</option><option value='WESTERN' style='font-family:WESTERN;'>Western</option>");
    print ("<option value='Amerika' style='font-family:Amerika;'>Amerika</option><option value='Goudy Old Style' style='font-family:Goudy Old Style;'>Goudy</option>");
    print ("<option value='Papyrus' style='font-family: Papyrus;'>Papyrus</option><option value='Brush Script MT' style='font-family:Brush Script MT;'>Brush</option></select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
    // Size of Style
    print ("<select name='size' onchange='bbsize(this.value);' title='Size'><option value='0' name='size'>Size &nbsp;&nbsp;</option>");
    print ("<option value='1'>1x</option><option value='2'>2x</option><option value='3'>3x</option><option value='4'>4x</option>");
    print ("<option value='5'>5x</option><option value='6'>6x</option><option value='7'>7x</option></select></td></tr>");

    // text area
    ?><tr><td align='center' valign='top'><div class='BBCode-Contour'><textarea id='BBCode-Contour2' name="<?php echo $name; ?>" rows="30" cols="90"><?php echo $content; ?></textarea></div></td><?php
    // smilies
    print ("<td align='center' valign='top'>");
    print ("<div class='BBCode-Contour'><a href='#' onClick=\"window.open('http://www.zupimages.net','_blank');return(false)\"> <input id='BBCode' type='button' value='' style=\"background: url('/images/bbcodes/Hebergeur.png'); background-size:100%;\" alt='Upload Image' title='Upload Image' /></a>");
    print ("<a href='#' onClick=\"window.open('http://www.youtube.com','_blank');return(false)\"> <input id='BBCode' type='button' value='' style=\"background: url('/images/bbcodes/Youtube.png'); background-size:100%;\" alt='YouTube' title='YouTube' /></a>");
    print ("<a href=\"javascript:PopMoreSmiles('$form','$name');\"> <input id='BBCode' type='button' value='' style=\"background: url('/images/bbcodes/Emotions.png'); background-size:100%;\" alt='More Smilies' title='More Smilies'  /></a>");
    print ("<a href=\"javascript:PopMoreTags();\"> <input id='BBCode' type='button' value='' style=\"background: url('/images/bbcodes/Tags.png'); background-size:100%;\" alt='More Tags' title='More Tags' /></a>");
    print ("<table border='0' cellpadding='3' cellspacing='3' align='center'><tr>");
       ?>
        <table border="0" cellpadding="3" cellspacing="3" align="center">
         <tr>
             <td width="26"><a href="javascript:SmileIT(':)','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/smile.png" border="0" alt=':)' title=':)' /></a></td>
             <td width="26"><a href="javascript:SmileIT(':(','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/sad.png" border="0" alt=':(' title=':(' /></a></td>
             <td width="26"><a href="javascript:SmileIT(':D','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/grin.png" border="0" alt=':D' title=':D' /></a></td>
             <td width="26"><a href="javascript:SmileIT(':P','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/razz.png" border="0" alt=':P' title=':P' /></a></td>  
         </tr>
         <tr>
             <td width="26"><a href="javascript:SmileIT(':-)','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/smile-big.png" border="0" alt=':-)' title=':-)' /></a></td>
             <td width="26"><a href="javascript:SmileIT('B)','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/cool.png" border="0" alt='B)' title='B)' /></a></td>
             <td width="26"><a href="javascript:SmileIT('8o','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/eek.png" border="0" alt='8o' title='8o' /></a></td>
             <td width="26"><a href="javascript:SmileIT(':?','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/confused.png" border="0" alt=':?' title=':?' /></a></td>    
         </tr>
         <tr>
             <td width="26"><a href="javascript:SmileIT('8)','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/glasses.png" border="0" alt='8)' title='8)' /></a></td>
             <td width="26"><a href="javascript:SmileIT(';)','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/wink.png" border="0" alt=';)' title=';)' /></a></td>
             <td width="26"><a href="javascript:SmileIT(':-*','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/kiss.png" border="0" alt=':-*' title=':-*' /></a></td>
             <td width="26"><a href="javascript:SmileIT(':-(','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/crying.png" border="0" alt=':-(' title=':-(' /></a></td>
         </tr>
         <tr>
             <td width="26"><a href="javascript:SmileIT(':|','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/plain.png" border="0" alt=':|' title=':|' /></a></td>
             <td width="26"><a href="javascript:SmileIT('O:-D','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/angel.png" border="0" alt='O:-D' title='0:-D' /></a></td>
             <td width="26"><a href="javascript:SmileIT(':-@','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/devilish.png" border="0" alt=':-@' title=':-@' /></a></td>
             <td width="26"><a href="javascript:SmileIT(':o)','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/monkey.png" border="0" alt=':o)' title=':o)' /></a></td>
         </tr>
         <tr>
              <td width="26"><a href="javascript:SmileIT('brb','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/brb.png" border="0" alt='brb' title='brb' /></a></td>
              <td width="26"><a href="javascript:SmileIT(':warn','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/warn.png" border="0" alt=':warn' title=':warn' /></a></td>
              <td width="26"><a href="javascript:SmileIT(':help','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/help.png" border="0" alt=':help' title=':help' /></a></td>
              <td width="26"><a href="javascript:SmileIT(':bad','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/bad.png" border="0" alt=':bad' title=':bad' /></a></td>
         </tr>
         <tr>
             <td width="26"><a href="javascript:SmileIT(':love','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/love.png" border="0" alt=':love' title=':love' /></a></td>
             <td width="26"><a href="javascript:SmileIT(':idea','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/idea.png" border="0" alt=':idea' title=':idea' /></a></td>
             <td width="26"><a href="javascript:SmileIT(':bomb','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/bomb.png" border="0" alt=':bomb' title=':bomb' /></a></td>
             <td width="26"><a href="javascript:SmileIT(':!','<?php echo $form; ?>','<?php echo $name; ?>')"><img src="images/smilies/important.png" border="0" alt=':!' title=':!' /></a></td>
         </tr>
         </table>
         <?php
         print ("</div>");
    // Additional Links As Image Host, More Emotions And More Tags
    print ("</td></tr></table>");
    // Refresh And Preview Button
    print ("<center><input type='reset' value='Refresh' />&nbsp;<input type='button' value='Preview' onClick='visualisation()' /></center>");
    // Creation of the Preview Area
    print ("<table align='center' width='0'><tr><td><center><font style='font-color:black;'>");
    print ("<div id='previsualisation' width='200px' height='200px'></div></font></center></td></tr></table></div>");
    }
    [/code]
    private torrents — 2024-01-09 05:19:41 in v3 Support
    can you make edit torrent tracker
    to our web site tracker

    member just upload any web site
    and any downloaded found our tracker
    private torrents — 2024-01-09 05:19:41 in v3 Support
    can you make edit torrent tracker
    to our web site tracker

    member just upload any web site
    and any downloaded found our tracker
    NFO fix [TTv3] — 2023-12-16 15:18:15 in v3 Mods Completed
    Dimensions nfo
    Go off the page


    how fix it
    error sql — 2023-11-13 07:23:14 in v3 Support


    if (is_array($updateset) && !empty($updateset)) {
          $updatesString = implode(',', $updateset);
          SQL_Query_exec("UPDATE torrents SET $updatesString WHERE id=$torrentid");
    }


    thanks

    but steal error
    I want to tracker it on a different domain

    Is there an admin in C Panel or Direct?
    I put specific files for the domain

    i show many web site doing like this tracker on different domain
    also it privet
    chomd change

    edit MySQL.PHP
    edit config.PHP

    after that first signup will be admin

    blank page ((solved))

    problem it was setting clodeflare
    error sql — 2023-10-07 19:01:16 in v3 Support
    error sql
    Database Error in announce.php on line 363: BIGINT UNSIGNED value is out of range in '`admin_ll53`.`torrents`.`leechers` - 1'. Query was: UPDATE torrents SET leechers = leechers - 1,seeders = seeders + 1,visible = 'yes',last_action = '2023-09-30 23:25:40' WHERE id=51.



    announce.php
    <?php
    // Please Note: Languages should not be implemented here...
                 
    error_reporting(E_ALL ^ E_NOTICE);
    require_once("backend/mysql.php");
    require_once("backend/config.php");
    require_once("backend/mysql.class.php");

    $GLOBALS["DBconnector"] = @mysqli_connect($mysql_host, $mysql_user, $mysql_pass) or err('dbconn: mysqli_connect: ' . mysqli_connect_error());
    @mysqli_select_db($GLOBALS["DBconnector"],$mysql_db) or err('dbconn: mysqli_select_db: ' . mysqli_error($GLOBALS["DBconnector"]));

    $MEMBERSONLY = $site_config["MEMBERSONLY"];
    $MEMBERSONLY_WAIT = $site_config["MEMBERSONLY_WAIT"];

    $_GET = array_map_recursive("unesc", $_GET);

    //START FUNCTIONS
    function array_map_recursive ($callback, $array) {
    $ret = array();

    if (!is_array($array))
    return $callback($array);

    foreach ($array as $key => $val) {
    $ret[$key] = array_map_recursive($callback, $val);
    }
    return $ret;
    }


    function unesc($x) {
    if (get_magic_quotes_gpc())
    return stripslashes($x);
    return $x;
    }

    function is_valid_id($id) {
    return is_numeric($id) && ($id > 0) && (floor($id) == $id);
    }

    function sqlesc($x) {
       return "'".mysqli_real_escape_string($GLOBALS["DBconnector"],$x)."'";
    }

    function err($msg) {
      mysqli_close($GLOBALS["DBconnector"]);
      return benc_resp_raw("d".benc_str("failure reason").benc_str($msg)."e");
    }

    function benc_str($s) {
    return strlen($s) . ":$s";
    }

    function benc_int($i) {
    return "i" . $i . "e";
    }

    function benc_resp_raw($x) {
    header("Content-Type: text/plain");
    header("Pragma: no-cache");

    if (extension_loaded('zlib') && !ini_get('zlib.output_compression') && $_SERVER["HTTP_ACCEPT_ENCODING"] == "gzip") {
    header("Content-Encoding: gzip");
    echo gzencode($x, 9, FORCE_GZIP);
    } else
    print($x);

    exit();
    }

    function gmtime() {
    return strtotime(get_date_time());
    }

    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");
    }

    function portblacklisted($port) {
    // direct connect
    if ($port >= 411 && $port <= 413) return true;

    // kazaa
    if ($port == 1214) return true;

    // gnutella
    if ($port >= 6346 && $port <= 6347) return true;

    // emule
    if ($port == 4662) return true;

    // winmx
    if ($port == 6699) return true;

    return false;
    }

    //////////////////////// NOW WE DO THE ANNOUNCE CODE ////////////////////////
                                                 
    // BLOCK ACCESS WITH WEB BROWSERS
    $agent = $_SERVER["HTTP_USER_AGENT"];
    if (preg_match("/^Mozilla|^Opera|^Links|^Lynx/i", $agent))
    die("No");

    //GET DETAILS OF PEERS ANNOUNCE
    foreach (array("passkey","info_hash","peer_id","ip","event") as $x) {
           $GLOBALS[$x] = $_GET[$x];
    }

    foreach (array("port","downloaded","uploaded","left") as $x)
       $GLOBALS[$x] = 0 + $_GET[$x];

    if (strpos($passkey, "?")) {
       $tmp = substr($passkey, strpos($passkey, "?"));
       $passkey = substr($passkey, 0, strpos($passkey, "?"));
       $tmpname = substr($tmp, 1, strpos($tmp, "=")-1);
       $tmpvalue = substr($tmp, strpos($tmp, "=")+1);
       $GLOBALS[$tmpname] = $tmpvalue;
    }

    foreach (array("passkey","info_hash","peer_id","port","downloaded","uploaded","left") as $x)
    if (!isset($$x))
    err("Missing key: $x");

    if (strlen($peer_id) != 20)
    err("Invalid peer_id");

    $no_peer_id = (int) $_GET["no_peer_id"];

       if (strlen($GLOBALS['info_hash']) == 20)
           $GLOBALS['info_hash'] = bin2hex($GLOBALS['info_hash']);
       else if (strlen($GLOBALS['info_hash']) != 40)
           err("Invalid info hash value.");
       $GLOBALS['info_hash'] = strtolower($GLOBALS['info_hash']);

    if ($MEMBERSONLY){
    if (strlen($passkey) != 32)
    err("Invalid passkey (" . strlen($passkey) . " - $passkey)");
    }

    $ip = $_SERVER["REMOTE_ADDR"];

    foreach(array("num want", "numwant", "num_want") as $k)
    {
       if (isset($_GET[$k]))
       {
           $rsize = (int) $_GET[$k];
           break;
       }
    }

    //PORT CHECK
    if (!$port || $port > 0xffff)
       err("invalid port");

    //TRACKER EVENT CHECK
    if (!isset($event))
       $event = "";

    $seeder = ($left == 0) ? "yes" : "no";

    //Agent Ban
    $agentarray = array_map("trim", explode(",", $site_config["BANNED_AGENTS"]));
    $useragent = substr($peer_id, 0, 8);
    foreach($agentarray as $bannedclient)
    if (@strpos($useragent, $bannedclient) !== false)
    err("Client is banned");
    //End Agent Bans

    if (portblacklisted($port))
    err("Port $port is blacklisted.");

    $userfields = "u.id, u.class, u.uploaded, u.downloaded, u.ip, u.passkey, g.can_download"; //user details to get
               
    $peerfields = "seeder, UNIX_TIMESTAMP(last_action) AS ez, peer_id, ip, port, uploaded, downloaded, userid, passkey"; //peers details to get

    $torrentfields = "id, info_hash, banned, freeleech, seeders + leechers AS numpeers, UNIX_TIMESTAMP(added) AS ts, seeders, leechers, times_completed"; //torrent details to get

    $userid = 0;
    if ($MEMBERSONLY){
    //check passkey is valid, and get users details
    $res = SQL_Query_exec("SELECT $userfields FROM users u INNER JOIN groups g ON u.class = g.group_id WHERE u.passkey=".sqlesc($passkey)." AND u.enabled = 'yes' AND u.status = 'confirmed' LIMIT 1") or err("Cannot Get User Details");
    $user = mysqli_fetch_assoc($res);
    if (!$user)
    err("Cannot locate a user with that passkey!");
       if ($user["can_download"] == "no")
           err("You do not have permission to download.");
    $userid = $user["id"]; //etc
    }


    //check torrent is valid and get torrent fields
    $res = SQL_Query_exec("SELECT $torrentfields FROM torrents WHERE info_hash=".sqlesc($info_hash)) or err("Cannot Get Torrent Details");
    $torrent = mysqli_fetch_assoc($res);

    if (!$torrent)
       err("Torrent not found on this tracker - hash = " . $info_hash);
    if ($torrent["banned"]=='yes')
       err("Torrent has been banned - hash = " . $info_hash);
    $torrentid = $torrent["id"];


    //Now get data from peers table
    $peerlimit = 50;
    $numpeers = $torrent["numpeers"];
    if ($numpeers > $peerlimit){
       $limit = "ORDER BY RAND() LIMIT $peerlimit";
    }else{
       $limit = "";
    }
    $res = SQL_Query_exec("SELECT $peerfields FROM peers WHERE torrent = $torrentid $limit") or err("Error Selecting Peers");

    //DO SOME BENC STUFF TO THE PEERS CONNECTION
    $resp = "d8:completei$torrent[seeders]e10:downloadedi$torrent[times_completed]e10:incompletei$torrent[leechers]e";
    $resp .= benc_str("interval") . "i" . $site_config['announce_interval'] . "e" . benc_str("min interval") . "i300e" . benc_str("peers");
    unset($self);
    while ($row = mysqli_fetch_assoc($res)) {
    if ($row["peer_id"] === $peer_id) {
    $self = $row;
    continue;
    }

    $peers .= "d" . benc_str("ip") . benc_str($row["ip"]);
           if (!$no_peer_id)
    $peers .= benc_str("peer id") . benc_str($row["peer_id"]);
           $peers .= benc_str("port") . "i" . $row["port"] . "ee";
    }
    $resp .= "l{$peers}e";
    $resp .= "ee";

    $selfwhere = "torrent = $torrentid AND peer_id = ".sqlesc($peer_id);



    // FILL $SELF WITH DETAILS FROM PEERS TABLE (CONNECTING PEERS DETAILS)
    if (!isset($self)){

    //check passkey isnt leaked
    if ($MEMBERSONLY) {
    $valid = @mysqli_fetch_row(@SQL_Query_exec("SELECT COUNT(*) FROM peers WHERE torrent=$torrentid AND passkey=" . sqlesc($passkey)));

    if ($valid[0] >= 1 && $seeder == 'no')
    err("Connection limit exceeded! You may only leech from one location at a time.");

    if ($valid[0] >= 3 && $seeder == 'yes')
    err("Connection limit exceeded!");
    }

    $res = SQL_Query_exec("SELECT $peerfields FROM peers WHERE $selfwhere");
    $row = mysqli_fetch_assoc($res);
    if ($row){
           $self = $row;
    }
    }
    // END $SELF FILL


    if (!isset($self)){ //IF PEER IS NOT IN PEERS TABLE DO THE WAIT TIME CHECK
    if ($MEMBERSONLY_WAIT && $MEMBERSONLY){
    //wait time check
    if($left > 0 && in_array($user["class"], explode(",",$site_config["WAIT_CLASS"]))){ //check only leechers and lowest user class
    $gigs = $user["uploaded"] / (1024*1024*1024);
    $elapsed = floor((gmtime() - $torrent["ts"]) / 3600);
    $ratio = (($user["downloaded"] > 0) ? ($user["uploaded"] / $user["downloaded"]) : 1);
    if ($ratio == 0 && $gigs == 0) $wait = $site_config["WAITA"];
    elseif ($ratio < $site_config["RATIOA"] || $gigs < $site_config["GIGSA"]) $wait = $site_config["WAITA"];
    elseif ($ratio < $site_config["RATIOB"] || $gigs < $site_config["GIGSB"]) $wait = $site_config["WAITB"];
    elseif ($ratio < $site_config["RATIOC"] || $gigs < $site_config["GIGSC"]) $wait = $site_config["WAITC"];
    elseif ($ratio < $site_config["RATIOD"] || $gigs < $site_config["GIGSD"]) $wait = $site_config["WAITD"];
    else $wait = 0;
    if ($elapsed < $wait)
    err("Wait Time (" . ($wait - $elapsed) . " hours) - Visit ".$site_config["SITEURL"]." for more info");
    }
    }
    $sockres = @fsockopen($ip, $port, $errno, $errstr, 5);
    if (!$sockres)
    $connectable = "no";
    else
    $connectable = "yes";
    @fclose($sockres);

    }else{
    $elapsed = ($self['seeder'] == 'yes') ? $site_config['announce_interval'] - floor(($self['ez'] - time()) / 60) : 0;
       $upthis = max(0, $uploaded - $self["uploaded"]);
       $downthis = max(0, $downloaded - $self["downloaded"]);

       if (($upthis > 0 || $downthis > 0 || $elapsed > 0) && is_valid_id($userid)){ // LIVE STATS!)
    if ($torrent["freeleech"] == 1){
    SQL_Query_exec("UPDATE users SET uploaded = uploaded + $upthis WHERE id=$userid") or err("Tracker error: Unable to update stats");
    }else{
    SQL_Query_exec("UPDATE users SET uploaded = uploaded + $upthis, downloaded = downloaded + $downthis WHERE id=$userid") or err("Tracker error: Unable to update stats");
    SQL_Query_exec("UPDATE LOW_PRIORITY `snatched` SET `uload` = `uload` + '$upthis', `dload` = `dload` + '$downthis', `utime` = '".gmtime()."', `ltime` = `ltime` + '$elapsed' WHERE `tid` = '$torrentid' AND `uid` = '$userid'");
    }
       }
    }//END WAIT AND STATS UPDATE

    $updateset = array();

    ////////////////// NOW WE DO THE TRACKER EVENT UPDATES ///////////////////

    if ($event == "stopped") { // UPDATE "STOPPED" EVENT
           SQL_Query_exec("DELETE FROM peers WHERE $selfwhere");
           if (mysqli_affected_rows($GLOBALS["DBconnector"])){
               if ($self["seeder"] == "yes")
                   $updateset[] = "seeders = seeders - 1";
               else
                   $updateset[] = "leechers = leechers - 1";
           }
    }

    if ($event == "completed") { // UPDATE "COMPLETED" EVENT    
       $updateset[] = "times_completed = times_completed + 1";

    if ($MEMBERSONLY)
    {
       SQL_Query_exec("INSERT INTO completed (userid, torrentid, date) VALUES ($userid, $torrentid, '".get_date_time()."')");
       SQL_Query_exec("UPDATE LOW_PRIORITY `snatched` SET `completed` = '1' WHERE `tid` = '$torrentid' AND `uid` = '$userid' AND `utime` = '" . gmtime() . "'");
    }
    }//END COMPLETED

    if (isset($self)){// NO EVENT? THEN WE MUST BE A NEW PEER OR ARE NOW SEEDING A COMPLETED TORRENT
       
       SQL_Query_exec("UPDATE peers SET ip = " . sqlesc($ip) . ", passkey = " . sqlesc($passkey) . ", port = $port, uploaded = $uploaded, downloaded = $downloaded, to_go = $left, last_action = '".get_date_time()."', client = " . sqlesc($agent) . ", seeder = '$seeder' WHERE $selfwhere");

       if (mysqli_affected_rows($GLOBALS["DBconnector"]) && $self["seeder"] != $seeder){
           if ($seeder == "yes"){
               $updateset[] = "seeders = seeders + 1";
               $updateset[] = "leechers = leechers - 1";
           } else {
               $updateset[] = "seeders = seeders - 1";
               $updateset[] = "leechers = leechers + 1";
           }
       }

    } else {

       $ret = SQL_Query_exec("INSERT INTO peers (connectable, torrent, peer_id, ip, passkey, port, uploaded, downloaded, to_go, started, last_action, seeder, userid, client) VALUES ('$connectable', $torrentid, " . sqlesc($peer_id) . ", " . sqlesc($ip) . ", " . sqlesc($passkey) . ", $port, $uploaded, $downloaded, $left, '".get_date_time()."', '".get_date_time()."', '$seeder', '$userid', " . sqlesc($agent) . ")");
           if ( ($MEMBERSONLY) && (($seeder == 'no' && $torrent['freeleech'] == 0)) ) {
       SQL_Query_exec("INSERT INTO `snatched` (`uid`, `tid`, `stime`, `utime`) VALUES ('$userid', '$torrentid', '".gmtime()."', '".gmtime()."') ON DUPLICATE KEY UPDATE `utime` = '" . gmtime() . "'");
    }
       if ($ret){
           if ($seeder == "yes")
               $updateset[] = "seeders = seeders + 1";
           else
               $updateset[] = "leechers = leechers + 1";
       }
    }

    //////////////////    END TRACKER EVENT UPDATES ///////////////////

    // SEEDED, LETS MAKE IT VISIBLE THEN
    if ($seeder == "yes") {
       if ($torrent["banned"] != "yes") // DONT MAKE BANNED ONES VISIBLE
           $updateset[] = "visible = 'yes'";
       $updateset[] = "last_action = '".get_date_time()."'";
    }

    // NOW WE UPDATE THE TORRENT AS PER ABOVE
    if (count($updateset))
       SQL_Query_exec("UPDATE torrents SET " . join(",", $updateset) . " WHERE id=$torrentid") or err("Tracker error: Unable to update torrent");

    // NOW BENC THE DATA AND SEND TO CLIENT???
    benc_resp_raw($resp);
    mysqli_close($GLOBALS["DBconnector"]);
    ?>
    https://torrenttrader.uk/post/9869

    can you plz update this mod   ((make REQ by seed point))

    my website Mysql Version: 10.6.24-MariaDB
    PHP Version: 7.4.33
    Apache Version: Apache/2
    blank page


    should use
    Quote:
    ((Page Rules))
    Page Rules let you control which Cloudflare settings trigger on a given URL. Only one Page Rule will trigger per URL, so it is helpful if you sort Page Rules in priority order, and make your URL patterns as specific as possible.


    i dnot know how use it
    youtube function ?
    dosent work
    can updated plz    thanks
    Users online

    No users online

    Search



    Statistics

      Torrents

    • Tracking: 3
    • Todays torrents: 0
    • Seeders: 0
    • Leechers: 0
    • Peers: 0
    • Downloaded: 89.96 GB
    • Uploaded: 9.86 GB

    • Members

    • We have: 838
    • New today: 0
    • Guest today: 9

    • Online

    • Total online: 1
    • Members: 0
    • Guests online: 1
    • Comments: 3
    • Messages: 1,728