<?php
/*
* Home page: http://vinaget.us
* Blog:	http://blog.vinaget.us
* Script Name: Vinaget 
* Version: getlink.vn (1.12.2011)
* Description: 
	- Vinaget is script generator premium link that allows you to download files instantly and at the best of your Internet speed.
	- Vinaget is your personal proxy host protecting your real IP to download files hosted on hosters like RapidShare, megaupload, hotfile...
	- You can now download files with full resume support from filehosts using download managers like IDM etc
	- Vinaget is a Free Open Source, supported by a growing community.
* Code LeechViet by VinhNhaTrang
* Developed by ..:: [H] ::..

*/

##################################### Begin class getinfo #####################################
class getinfo {
	function config(){
		include("config.php");
		$this->self = strtolower('http://'.$_SERVER['HTTP_HOST'].preg_replace('/\?.*$/', '', isset($_SERVER['REQUEST_URI'])? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']));
		if (!defined('vinaget')){
		  echo '<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=http://'.$homepage.'">';
		  exit;
		}
		
		if (!file_exists(".htaccess")) {
			echo "<CENTER><font color=red size=4>Can't find file <B>.htaccess</B></font></CENTER>";
			exit;
		}
		if(!file_exists($fileinfo_dir.'/info.backup.php') && !file_exists($fileinfo_dir."/info.php")) { 
			$str = "<?php";
			$str .= "\n\$SecureID = \"".$passdefault."\";";
			$str .= "\n\$email = \"\";";
			$str .= "\n\$username = \"\";";
			$str .= "\n\$old = \"\";";
			$str .= "\n\$mobile = \"\";";
			$str .= "\n\$address = \"\";";
			$str .= "\n\$created = ".time().";";
			$str .= "\n\$expired = 0;";
			$str .= "\n?>";

			$clog=fopen($fileinfo_dir."/info.php","a") 
			or die('<CENTER><font color=red size=3>Could not create to file ! Try to chmod the folder "<B>files</B>" to 777</font></CENTER>');
			fwrite($clog,$str);
			fclose($clog);
		}
		if (!file_exists ($fileinfo_dir."/files/")) {
			mkdir($fileinfo_dir."/files/", 0777)  
			or die('<CENTER><font color=red size=4>Could not create folder! Try to chmod the folder "<B>files</B>" to 777</font></CENTER>');
		}
		if(!file_exists($fileinfo_dir."/index.php")) { 
			$clog=fopen($fileinfo_dir."/index.php","a") 
			or die('<CENTER><font color=red size=3>Could not create to file ! Try to chmod the folder "<B>files</B>" to 777</font></CENTER>');
			fwrite($clog,'<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=http://'.$homepage.'">');
			fclose($clog);
		}
		if(!file_exists($fileinfo_dir."/files/index.php")) { 
			$clog=fopen($fileinfo_dir."/files/index.php","a") 
			or die('<CENTER><font color=red size=3>Could not create to file ! Try to chmod the folder "<B>files</B>" to 777</font></CENTER>');
			fwrite($clog,'<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=http://'.$homepage.'">');
			fclose($clog);
		}

		if ($Secure == true) $this->Deny = true;
		if(isset($_COOKIE["secureid"]) && isset($SecureID) && $_COOKIE["secureid"] == md5($SecureID)) {
			$this->Deny = false;
		}

		$this->lang = $lang;
		$this->Secure = $Secure;
		$this->fileinfo_dir = $fileinfo_dir;
		$this->fileinfo_ext = $fileinfo_ext;
		$this->fileinfo = $fileinfo;
		$this->download_prefix = $download_prefix;
		$this->banned = explode(' ', '.htaccess .htpasswd .php .php3 .php4 .php5 .phtml .asp .aspx .cgi .pl');    // banned filetypes
		$this->UserAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0';
		$this->unit = 1024; 
		$this->limitMBIP = $limitMBIP;
		$this->maxbw = $maxbw;
		$this->ttl = $ttl;
		$this->max_load = $max_load;
		$this->listfile = $listfile;
		$this->privatef = $privatefile;
		$this->privateip = $privateip;
		$this->passgate = $passgate;
		$this->linkgate = $linkgate;
		$this->linkmagnet = $linkmagnet;
		$this->passmagnet = $passmagnet;
		$this->infomagnet = $infomagnet;
		if(isset($email)) $this->email = $email;
		if(isset($mobile)) $this->mobile = $mobile;
		if(isset($SecureID)) $this->SecureID = $SecureID;
		if(isset($created)) $this->created = $created;
		if(isset($expired)) $this->expired = $expired;
		$this->linkmail = $linkmail;
		$this->passmail = $passmail;
		$this->mailerror = $mailerror;
		$this->max_ip = $max_ip_login;
		$this->linkreport = $linkreport;
		$this->pathphim = $pathphim;
		$this->facebook = $facebook;
		$this->group = $group;
		$this->acc_type = $acc_type;
		if (!isset($this->hosts)) die('Phiên bản cũ vui lòng liên hệ getlink để cập nhật phiên bản mới hơn');

		//check isp and set cookie network
		$this->checkisp = $checkisp.'?ip=';
		if(preg_match("/^(\d{1,3}\.\d{1,3}\.\d{1,3})/i", $_SERVER['REMOTE_ADDR'], $value)) $ip = $value[1];
		else $ip = $_SERVER['REMOTE_ADDR'];
		//$ip = '118.71.182';
		if(!isset($_COOKIE['ip']) || stristr($ip,$_COOKIE['ip']) == false) {
			$data = $this->curl($this->checkisp.$ip,"","");
			if(stristr($data,'fpt')) $network = 'fpt';
			elseif(stristr($data,'viettel')) $network = 'viettel';
			elseif(stristr($data,'vnpt')) $network = 'vnpt';
			elseif(stristr($data,'vdc')) $network = 'vnpt';
			else $network = 'other';
			setcookie('network',$network,time()+3600*24*365);
			setcookie('ip',$ip,time()+3600*24*365);
		}
		//echo $_COOKIE['network'].$_COOKIE['ip'];exit;
		//check isp and set cookie network
	}

	function ip_proxy($link_acc){
		$folder_db = '../../../../../accounts/proxy_ip/';
		if(isset($_SERVER['HTTP_X_REAL_IP'])) $ip = $_SERVER['HTTP_X_REAL_IP'];
		else $ip = $_SERVER['REMOTE_ADDR'];
		if(preg_match("/^(\d{1,3}\.\d{1,3}\.\d{1,3})/i", $ip, $value)) $ip = $value[1];
		if (!file_exists ($folder_db)) {
			mkdir($folder_db, 0777)  or die('<CENTER><font color=red size=4>Could not create folder logs ip!</font></CENTER>');
		}
		list($db_proxy, $px_lists, $px_tmp_old) = $this->load_data($folder_db);
		$hash_px = md5($link_acc);
		$time = time();

		if(isset($db_proxy[$hash_px]['logs'][$ip])) return;

		if(isset($db_proxy[$hash_px]['logs']) && count($db_proxy[$hash_px]['logs']) == 5) {
			$logs = $db_proxy[$hash_px]['logs'];
			unset($db_proxy[$hash_px]['logs']);
			$i = 1;
			$compare = $this->datecmp('time'); 
			usort($array, $compare);
			foreach($logs as $key=>$val) {
				if($i == 5) break;
				$db_proxy[$hash_px]['logs'][$val['ip']] = $val;
				$i++;
			}
		}

		$db_proxy[$hash_px]['account'] = $link_acc;
		$db_proxy[$hash_px]['hash'] = $hash_px;
		$db_proxy[$hash_px]['time'] = $time;
		$db_proxy[$hash_px]['status'] = 1;
		$db_proxy[$hash_px]['logs'][$ip]['time'] = $time;
		$db_proxy[$hash_px]['logs'][$ip]['ip'] = $ip;
		if(isset($_SERVER['HTTP_USER_AGENT'])) $db_proxy[$hash_px]['logs'][$ip]['HTTP_USER_AGENT'] = $_SERVER['HTTP_USER_AGENT'];
		else $db_proxy[$hash_px]['logs'][$ip]['HTTP_USER_AGENT'] = '';

		$file_porxy = $this->rand_filename($folder_db);
		$tmp = @json_encode($db_proxy);
		if($px_tmp_old == $tmp) return;
		$px_tmp_old == $tmp;

		$fh = fopen($file_porxy, 'w') or die('<CENTER><font color=red size=3>Could not open folder proxy data!!!</font></CENTER>');
		fwrite($fh, $tmp);
		fclose($fh);
		@chmod($file_jobs, 0666);
		if (count($px_lists)) foreach ($px_lists as $file) if (file_exists($file)) @unlink($file);
		$txt = '';
		$db_ip = array();
		foreach($db_proxy as $list_acc) {
			foreach($list_acc['logs'] as $ip_acc=>$time_acc) {
				if(!isset($db_ip[$ip_acc])) {
					$txt .= $ip_acc.".1/24\r\n";
					//$db_ip[$ip_acc] = $ip_acc.'.1/24#'.'	'.date( 'H:i:s- d.m.Y',$time_acc['time']).' | '.$list_acc['account'].' | '.$time_acc['HTTP_USER_AGENT']."\r\n";
					$db_ip[$ip_acc] = $ip_acc.".1/24\r\n";
				}
			}
		}
		$file_txt_logs = $folder_db.'list_ip_porxy.txt';
		if(!empty($txt)) $this->savefile($file_txt_logs,$txt);

		return true;

	}

	function notice(){
		if(!isset($this->info["bandwitdh"]["time"]) || !isset($this->info["bandwitdh"]["value"]))  {
			printf($this->lang['notfilebw'],$this->lang['mail_hotro']);
			return;
		}
		//save log ip login to proxy
		$link_acc = str_replace('index.php','',$this->self);
		$this->ip_proxy($link_acc);
		//save log ip login to proxy

		if(preg_match("/^(\d{1,3}\.\d{1,3}\.\d{1,3})/i", $_SERVER['REMOTE_ADDR'], $value)) $ip = $value[1].'.***';
		else $ip = $_SERVER['REMOTE_ADDR'];
		$data = $this->curl($this->checkisp.$_SERVER['REMOTE_ADDR'],"","");
		$json =  @json_decode($data, true);
		if(stristr($data,'fpt')) $network = 'fpt';
		elseif(stristr($data,'viettel')) $network = 'viettel';
		elseif(stristr($data,'vnpt')) $network = 'vnpt';
		elseif(stristr($data,'vdc')) $network = 'vnpt';
		else $network = $json['isp'];
		$ip = $ip.' ('.strtoupper($network).' - '.$json['country'].')';
		$time = $this->expired - time();
		$expired = Tools_get::convert_time($time);

		$mydomain = str_replace("my.","",$_SERVER['HTTP_HOST']);
		if($time < 0) $expired = '<b><font color=expired>'.$this->lang['out_time'].'</font></b>';
		elseif($time < 2*24*60*60) $expired = '<b> <span class="expired">'.$expired.'</span></b> <a href="http://'.$mydomain.'/giahan.php?url='.$link_acc.'">'.$this->lang['renewnow'].'</a>';
		elseif($time < 7*24*60*60) $expired = '<b><font color=red>'.$expired.'</font></b> <a href="http://'.$mydomain.'/giahan.php?url='.$link_acc.'">'.$this->lang['renewnow'].'</a>';
		//elseif($time < 2*24*60*60) $expired = '<b> <span class="expired">'.$expired.'</span></b> <a href="./login.php?go=renew">'.$this->lang['renewnow'].'</a>';
		//elseif($time < 7*24*60*60) $expired = '<b><font color=red>'.$expired.'</font></b> <a href="./login.php?go=renew">'.$this->lang['renewnow'].'</a>';
		printf($this->lang['notice'],$this->lang['dontshare'],Tools_get::convertmb($this->leftbw),$ip,count($this->jobs), $expired);

		//check hết hạn
		if($this->expired < time()+3*24*60*60 && strtolower($this->acc_type['type']) !== 'pro' && $this->info["logsmail"]["expired"] == false) {
			if((isset($_COOKIE["ck_logout"]) && time() - $_COOKIE["ck_logout"] > 3600*24) || !isset($_COOKIE["ck_logout"])) {
				setcookie('ck_logout',time(),time()+3600*24*365);
				die("<SCRIPT language='Javascript'>document.location.href ='./login.php?go=logout';</SCRIPT>");
			}
		}
	}


	function update_array($jobs, $update) {
		if(!is_array($update)) return $jobs;
		foreach($update as $key=>$value) {
			if(is_array($value)) {
				if(isset($jobs[$key])) $jobs[$key] = $this->update_array($jobs[$key], $update[$key]);
				elseif(is_array($jobs)) $jobs[$key] = $update[$key];
			}
			else{
				if(is_array($jobs)) $jobs[$key] = $update[$key];
			}
		}
		return $jobs;
	}

	function load_data($pathfile,$fulldata=true){
		if(!file_exists($pathfile)) return;
		$fileinfo_ext = $this->fileinfo_ext;
		$dir = opendir($pathfile);
		$lists = array();
		while ($file = readdir($dir)){
			if (substr($file,-strlen($fileinfo_ext)-1) == "." . $fileinfo_ext){
				$lists[] = $pathfile . $file;
			}
		}
		closedir($dir);
		$data = array();
		if (count($lists)){
			sort($lists);
			foreach ($lists as $file){
				$contentsfile = file_get_contents($file);
				$jobs_data = json_decode($contentsfile,true);	
				if (is_array($jobs_data)){
					$data = $this->update_array($data, $jobs_data);
				}
			}	
		}
		$tmp_old = json_encode($data);
		if($fulldata) return array($data, $lists, $tmp_old);
		else return $data;
	}

	function rand_filename($folder){
		$namedata = $timeload = explode(" ", microtime());
		$namedata = $namedata[1]*1000 + round($namedata[0]*1000);
		$filename = $folder.$namedata. ".dat";
		if (file_exists($filename)) $this->rand_filename($folder);
		return $filename;
	}

	function save_jobs(){
		if (!isset($this->jobs) || is_array($this->jobs)==false) die('error 01: not found data');
		### clean jobs ###
		$oldest = time() - $this->ttl*60;
		$delete = array();
		foreach ($this->jobs as $key=>$job) {
			if($key == 'clearfile') continue;
			if ($job['mtime'] < $oldest) {
				$delete[] = $key;
			}
		}
		foreach ($delete as $url) {
			unset($this->jobs[$url]);
		}
		### clean jobs ###
		$file_jobs = $this->rand_filename($this->fileinfo_dir.'/files/');
		$tmp = @json_encode($this->jobs);
		if($this->tmp_old !== $tmp) $this->tmp_old = $tmp;
		else return;

		$fh = fopen($file_jobs, 'w') or die('<CENTER><font color=red size=3>Could not open file ! Try to chmod the folder "<B>'.$this->fileinfo_dir.'</B>" to 777</font></CENTER>');
		fwrite($fh, $tmp);
		fclose($fh);
		@chmod($file_jobs, 0666);
		if (count($this->lists)) foreach ($this->lists as $file) if (file_exists($file)) @unlink($file);
		return true;
	}

	function load_info(){
		$this->info_data = @file_get_contents($this->fileinfo_dir."/".$this->fileinfo);
		$this->info = @json_decode($this->info_data, true);	
		if (!is_array($this->info)){
			$this->info = array();
			$this->info_data = 'vng';
		}
	}
	function save_info(){
		if (!isset($this->info) || is_array($this->info)==false) return;
		$tmp = json_encode($this->info);
		if ($tmp !== $this->info_data){
			$this->info_data = $tmp;
			$fh = fopen($this->fileinfo_dir."/".$this->fileinfo, 'w') 
			or die('<CENTER><font color=red size=3>Could not open file ! Try to chmod the folder "<B>'.$this->fileinfo_dir.'</B>" to 777</font></CENTER>');
			fwrite($fh, $this->info_data) 
			or die('<CENTER><font color=red size=3>Could not write file ! Try to chmod the folder "<B>'.$this->fileinfo_dir.'</B>" to 777</font></CENTER>');
			fclose($fh);
			@chmod($this->fileinfo_dir."/".$this->fileinfo, 0666);
			return true;	
		}
	}
	function load_bw(){
		$this->bw_data = @file_get_contents($this->fileinfo_dir."/bw.dat");
		$this->bw = @json_decode($this->bw_data, true);	
		if (!isset($this->bw) || !is_array($this->bw)){
			$this->bw = array();
			$this->bw_data = 'vng';
		}
		$bw = array();
		if(count($this->hosts) == 0) return;
		foreach($this->hosts as $host=>$value) {
			if(isset($this->bw[$host])) $bw[$host] = $this->bw[$host];
			else $bw[$host] = 0;
		}
		$this->bw = $bw;

	}

	function savefile($file,$data,$type='w+') {
		$fh = fopen($file, $type) 
		or die('<CENTER><font color=red size=3>Could not open file ! Try to chmod the file "<B>'.$file.'</B>" to 666</font></CENTER>');
		fwrite($fh, $data) 
		or die('<CENTER><font color=red size=3>Could not write file ! Try to chmod the file "<B>'.$file.'</B>" to 666</font></CENTER>');
		fclose($fh);
		@chmod($file, 0666);
	}

	function save_bw(){
		if (!isset($this->bw) || is_array($this->bw)==false) return;
		$tmp = json_encode($this->bw);
		if ($tmp !== $this->bw_data){
			$this->bw_data = $tmp;
			$fh = fopen($this->fileinfo_dir."/bw.dat", 'w') 
			or die('<CENTER><font color=red size=3>Could not open file ! Try to chmod the folder "<B>'.$this->fileinfo_dir.'</B>" to 777</font></CENTER>');
			fwrite($fh, $this->bw_data) 
			or die('<CENTER><font color=red size=3>Could not write file ! Try to chmod the folder "<B>'.$this->fileinfo_dir.'</B>" to 777</font></CENTER>');
			fclose($fh);
			@chmod($this->fileinfo_dir."/bw.dat", 0666);
			return true;	
		}
	}
	function get_load($i = 0){
		$load = array('0', '0', '0');
		if (@file_exists('/proc/loadavg')){
			if ($fh = @fopen('/proc/loadavg', 'r')){
				$data = @fread($fh, 15);
				@fclose($fh);
				$load = explode(' ', $data);
			}
		}
		else{
			if ($serverstats = @exec('uptime')){
				if (preg_match('/(?:averages)?\: ([0-9\.]+),?[\s]+([0-9\.]+),?[\s]+([0-9\.]+)/', $serverstats, $matches)){
					$load = array($matches[1], $matches[2], $matches[3]);
				}
			}
		}
		return $i==-1 ? $load : $load[$i];
	}

	function lookup_job($hash){
		//$this->load_jobs();
		foreach ($this->jobs as $key=>$job)
		{
			if ($job['hash'] == $hash)
			{
				$job['url'] = $key;
				return $job;
			}
		}
		return false;
	}

	function loadphim() {
		$phimdata = @file_get_contents($this->pathphim);
		$phim = @json_decode($phimdata, true);	
		if (!is_array($phim))$phim = array();
		$this->phim = $phim;
		return $phim;
	}
	function checklogin() {
		if(!isset($this->info["status"]) OR !isset($this->created) OR !isset($this->expired)) {
			die("<SCRIPT language='Javascript'>document.location.href ='./login.php?go=logout';</SCRIPT>");
		}
		elseif($this->info["status"] == "locked" ) {
			die("<SCRIPT language='Javascript'>document.location.href ='./login.php?go=lock';</SCRIPT>");
		}
		elseif($this->info["status"] == "expired" OR $this->expired < time()){
			die("<SCRIPT language='Javascript'>document.location.href ='./login.php?go=expired';</SCRIPT>");

		}

	}
	function cut_str($str, $left, $right)  {
		$str = substr ( stristr ( $str, $left ), strlen ( $left ) );
		$leftLen = strlen ( stristr ( $str, $right ) );
		$leftLen = $leftLen ? - ($leftLen) : strlen ( $str );
		$str = substr ( $str, 0, $leftLen );
		return $str;
	}
}
##################################### End class getinfo #######################################


##################################### Begin class stream_get ##################################
class stream_get extends getinfo {
	function __construct(){
		$this->stream_get();
	}

	function stream_get(){
		//include("limit.php");
		$this->config();
		if($this->Deny == true) return;
		//$this->load_jobs();
		list($this->jobs, $this->lists, $this->tmp_old) = $this->load_data($this->fileinfo_dir."/files/");
		$this->load_info();
		$this->loadphim();
		$this->CheckMBIP();
		$this->cookie = '';
		if (isset($_REQUEST['img'])) $this->showimg($_REQUEST['img']);
		if (isset($_COOKIE['owner'])) $this->owner = $_COOKIE['owner'];
		else{
			$this->owner = intval(rand()*10000);
			setcookie('owner', $this->owner, 0);	
		}
		$this->Checkbandwitdh();
		
	}
    function Checkbandwitdh(){
		//check gia hạn account
		if(!isset($this->info["logsmail"]["expired"])) $this->info["logsmail"]["expired"] = false;
		if($this->expired > time()+3*24*60*60 && strtolower($this->acc_type['type']) !== 'pro' && $this->info["logsmail"]["expired"] == true) {
			$this->info["logsmail"]["expired"] = false;
			$this->save_info();
		}
		if(isset($this->info["bandwitdh"]["time"]) && isset($this->info["bandwitdh"]["value"]) && isset($this->info["status"]))  {
			$lasttime = $this->info["bandwitdh"]["time"];
			$this->leftbw = $this->info["bandwitdh"]["value"];
			$datenow = date('z',time()) + 366*(date('Y',time()) - date('Y',$lasttime));
			if(strtolower($this->acc_type['type']) !== 'pro' && $this->info["status"] == "true") {
				if($datenow - date('z',$lasttime) > 0 AND isset($this->expired) AND $this->expired > time() ) {
					if (!is_numeric($this->leftbw)) $this->leftbw = $this->limitMBIP*1024*1024;
					elseif($datenow - date('z',$lasttime) >=2) $this->leftbw = $this->leftbw + $this->limitMBIP*1024*1024*2;
					elseif($datenow - date('z',$lasttime) == 1) $this->leftbw = $this->leftbw + $this->limitMBIP*1024*1024;
					if($this->leftbw > $this->maxbw*1024*1024) $this->leftbw = $this->maxbw*1024*1024;
					$this->info["bandwitdh"]["time"] = time();
					$this->info["bandwitdh"]["value"] = $this->leftbw;
					$this->save_info();

					# reset limit
					$this->load_bw();
					$bw = array();
					foreach($this->hosts as $host=>$value) {
						if(isset($this->bw[$host]))
							$bw[$host] = $this->hosts[$host]['bandwidth']*1024*1024*($datenow - date('z',$lasttime)) - $this->bw[$host];
						else $bw[$host] = 0;
						if($bw[$host] < 0)  $bw[$host] = abs($bw[$host]);
						else $bw[$host] = 0;
					}
					$this->bw = $bw;
					$this->save_bw();
					# reset limit

				}
			}
		}
		elseif (file_exists("info.backup.dat")) die(_notfilebw);
	}
    function CheckMBIP(){
		$this->countMBIP = 0;
		$this->totalMB = 0;
		$timedata =time();
		foreach ($this->jobs as $job){
			$this->totalMB = $this->totalMB + $job['msize'];

		}
	}
	function curl($url,$cookies,$post){
		$ch = @curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		if ($cookies) curl_setopt($ch, CURLOPT_COOKIE, $cookies);
		curl_setopt($ch, CURLOPT_USERAGENT, $this->UserAgent);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_REFERER,$url); 
		if ($post){
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
		}
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
		curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
		curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 60);
		$page = curl_exec( $ch);
		curl_close($ch); 
		return $page;
	}

	function mailreport($subject,$contents){
		$linklogin = str_replace(substr(strrchr($this->self, '/'), 1),"",$this->self);
		$post['subject'] = $subject;
		$post['contents'] = 
			"Thời gian lỗi: ".date( 'H:i:s- d.m.Y',time())."<BR/>
			Lỗi được tìm thấy từ tài khoản: ".$linklogin."<BR/>
			Mật khẩu: <B>".$this->SecureID."</B><BR>
			Mail: ".$this->email."<BR>
			Mobile: ".$this->mobile."
			".$contents;
		$data = $this->curl($this->linkreport,"secureid=".md5("test"),$post);
		//$data = $this->curl($this->linkmail,"vngcookie=".md5($this->passmail),$post);
	}
	function copyfile($link,$path) {
		if (!file_exists ($this->folderimg)) {
			mkdir($this->folderimg, 0777)  
			or die('<CENTER><font color=red size=4>Could not create folder! Try to chmod the folder "<B>'.$this->folderimg.'</B>" to 777</font></CENTER>');
		}
		$data = $this->curl($link,'','',0);	
		$handle = fopen($path, "w")
		or die('<CENTER><font color=red size=3>'.__LINE__.' could not open file! Try to chmod the file "<B>'.$path.'</B>" to 666</font></CENTER>');
		fwrite($handle, $data)
		or die('<CENTER><font color=red size=3>'.__LINE__.' could not write file! Try to chmod the file "<B>'.$path.'</B>" to 666</font></CENTER>');
		fclose($handle);
		return true;
	}

	function main(){
		$this->checklogin();
		$checklog = false;
		$url = false;
		krsort($this->info["logs"]);
		foreach($this->info["logs"] as $time => $iplog) {
			if(time() - $time < 24*60*60) {
				if(preg_match("/^(\d{1,3}\.\d{1,3}\.)/i",$_SERVER['REMOTE_ADDR'], $value)) $ip = trim($value[1]);
				else $ip = trim($_SERVER['REMOTE_ADDR']);
				if(stristr($iplog,$ip)) {
					$checklog = true;
					break;
				}
			}
			else break;
		}
		if($checklog == false) die("errorlogin");

		if ($this->get_load() > $this->max_load){
			echo '<center><b><i><font color=red>'.$this->lang['svhload'].'</font></i></b></center>';
			return;
		}
		if (isset($_POST['urllist'])) {
			$url = trim($_POST['urllist']);
			$url = str_replace("\r", "",  $url);
			$url = str_replace("\n", "",  $url);
			$url = str_replace("<", "",  $url);
			$url = str_replace(">", "",  $url);
		}
		$dlhtml = "";
		if(isset($_POST['download']) && $_POST['download']=='phim') {
			$dlhtml .= $this->get($url);
			if(stristr($dlhtml,'We do not support')) die ($this->lang['notf_film']);
			elseif(stristr($dlhtml,'title="click') || stristr($dlhtml,'id="errorlimit"')) die($dlhtml);
			elseif(stristr($dlhtml,'Kh&#244;ng th&#7875; get')) die($this->lang['max_film']);
			else die();
			//elseif(!stristr($dlhtml,'font-weight: bold;color:')) die('Phim không tồn tại.');
		}
		elseif(isset($_POST['download']) && ($_POST['download']=='subviet' || $_POST['download'] =='subeng')) {
			$dlhtml .= $this->get($url);
			if(stristr($dlhtml,'title="click')) die($dlhtml);
			elseif(stristr($dlhtml,'We do not support')) $dlhtml = $this->lang['find_sub'];
			elseif(stristr($dlhtml,'subscene.com') == true) {
				$sub = $dlhtml;
				$dlhtml = '<a href="'.$sub.'" style="font-weight: bold;color:blue; font-size:14px;" title="'.$this->lang['downsub'].'">'.($_POST['download']=='subviet'?$this->lang['subviet']:$this->lang['subeng']).'</a>';
				die($dlhtml);
			}
			//elseif(stristr($dlhtml,'We do not support')) die ('Không thể get được phụ đề. Vui lòng thử lại');
			if($_POST['download']=='subviet') $lang = '/vietnamese';
			else $lang = '/english';
			$filename = strtolower(str_replace(" ",'-',$this->phim[$url]['name']));
			$filename = str_replace('(','',$filename);
			$filename = str_replace(')','',$filename);
			$filename = str_replace(',','',$filename);
			$sub = 'http://subscene.com/subtitles/'.substr($filename,0,-5).$lang;
			$data = $this->curl($sub,'','');
			if(stristr($data,'<h1>Page Not Found</h1>')) {
				$sub = 'http://subscene.com/subtitles/'.$filename.$lang;
				$data = $this->curl($sub,'','');
			}
			
			if(stristr($data,'Subtitles for</h1>')) $dlhtml = '<a href="'.$sub.'" style="font-weight: bold;color:blue; font-size:14px;" title="'.$this->lang['downsub'].'">'.($_POST['download']=='subviet'?$this->lang['subviet']:$this->lang['subeng']).'</a>';
			else $dlhtml = $this->lang['find_sub'];
			die($dlhtml);
		}
		elseif (isset($url)&& strlen($url) > 10){
			if(substr($url,0,4)=='www.')$url = "http://".$url;
			$dlhtml .= $this->get($url);
		}
		else $dlhtml .=  "<b><a href=".$url." style='TEXT-DECORATION: none'><font color=red face=Arial size=2 id='Invalidlink'><s>".$url."</s></font></a> <img src=./../../../images/chk_error.png width='15' alt='errorlink'> <font color=#ffcc33><B>".$this->lang['errorlink']."</B></font><BR>";
		if (empty($url)==false)  echo $dlhtml;
	}
	function get($url){
		$url = trim($url);
		if (empty($url)) return;
		if(!isset($_POST['download'])) return;

		$type = array_keys($this->server);
		$sv_root = array_rand($this->sv_root, 1);
		$type[] = $sv_root;
		
		if($_POST['download']=='phim' || $_POST['download']=='subviet' || $_POST['download'] =='subeng')  {
			$hashphim = $url;
			$phim = $this->loadphim();
			if(isset($phim[$hashphim])) {
				$url = $phim[$hashphim]['movie'];
				$namemovies = $phim[$hashphim]['name'];
			}
			else die($this->lang['f5_press']);
			if($_POST['download']=='subviet'){
				$sub = str_replace(substr($url,-7),'',$url);
				if(isset($phim[$hashphim]['sub']['viet']) && $phim[$hashphim]['sub']['viet'] != false && stristr($phim[$hashphim]['sub']['viet'],'subscene.com') == true){
					return  $phim[$hashphim]['sub']['viet'];
				}
				elseif(isset($phim[$hashphim]['sub']['viet']) && $phim[$hashphim]['sub']['viet'] != false) $url = $phim[$hashphim]['sub']['viet'];
				elseif(Tools_get::size($sub.'.srt') >0 ) $url = $sub.'.srt';
				elseif(Tools_get::size($sub.'_VIE.srt') >0 ) $url = $sub.'_VIE.srt';
				else return;
			}
			elseif($_POST['download']=='subeng'){
				$sub = str_replace(substr($url,-7),'',$url);
				if(isset($phim[$hashphim]['sub']['anh']) && $phim[$hashphim]['sub']['anh'] != false && stristr($phim[$hashphim]['sub']['anh'],'subscene.com')){
					return  $phim[$hashphim]['sub']['anh'];
				}
				elseif(isset($phim[$hashphim]['sub']['anh']) && $phim[$hashphim]['sub']['anh'] != false) $url = $phim[$hashphim]['sub']['anh'];
				elseif(Tools_get::size($sub.'_ENG.srt') >0) $url = $sub.'_ENG.srt';
				else return;
				
			}
		}

		$dlhtml = "";
		$hash = md5($url);
		if($_POST['download'] =='phim')  $hash = 'phim_'.$hashphim;
		elseif($_POST['download'] =='subviet')  $hash = 'subviet_'.$hashphim;
		elseif($_POST['download'] =='subeng')  $hash = 'subeng_'.$hashphim;
		if ($this->leftbw <= 0 && isset($this->jobs[$hash])==false){
			$dlhtml = '<div id="errorlimit" align="center">'.$this->lang['outbw'].'</div>';
			return $dlhtml;
		}
		// Limit get tối đa 1 link = 4
		if(isset($this->jobs[$hash])==true && $this->jobs[$hash]['speed']> 4 && time() < $this->jobs[$hash]['mtime']+2*60*60) {
			if($_POST['download']=="down" || $_POST['download']=="phim" ) {
				$contents = "link get: $url <BR>Type: ".json_encode($type);
				$this->mailreport("Phát hiện $url get nhiều lần !",$contents);
			}
			$dlhtml .= "<b><a href=".$url." style='TEXT-DECORATION: none'><font color=#ff6600 face=Arial size=2 id='Invalidlink'>".$url."</font></a> <img src=./../../../images/chk_error.png width='15' alt='errorlink'> <font color=#ffcc33><B>".$this->lang['maxget'];
			die($dlhtml);
		}
		if(strpos($url,"filesonic")) $host = "filesonic.com";
		elseif(strpos($url,"wupload")) $host = "wupload.com";
		elseif(strpos($url,"rapidshare")) $host = "rapidshare.com";
		elseif(stristr($url,"k2share.cc")) $host = "keep2share.cc";
		elseif(stristr($url,"k2s.cc")) $host = "keep2share.cc";
		//elseif(stristr($url,'magnet:?xt=') || stristr($url,'.torrent')) $host = "torrent";
		elseif(stristr($url,'magnet:?xt=') || stristr($url,'.torrent')) {
			if(preg_match('%(http|https)\:\/\/torcache.net\/torrent\/(.*)\.torrent\?title\=(.*?)%U', $url, $matches)) {
				$hash = strtolower(trim($matches[2]));
				$name = strtolower(trim($matches[3]));
				$name = str_replace('[kat.cr]','',$name);
				$url = 'magnet:?xt=urn:btih:'.$hash.'&dn='.urlencode($name);
			}
			elseif(stristr($url,'.torrent')) {
				$data = @file_get_contents($this->infomagnet.'convert.php?url='.urlencode($url));
				$info = json_decode($data, true);
				if(!is_array($info)) die('error 1: Sorry, there was an error uploading your file.');
				if(isset($info['error']) && $info['error'] != 'no') die($info['error']);
				$url = $info['magnet'];
				$hash = $info['hash'];
			}
			elseif (preg_match('%magnet\:\?xt\=urn\:btih\:(.*)(\&dn\=)?%U', $url,$value)) $hash = strtolower(substr($url,20,40));
			elseif (preg_match('#^magnet\:\?xt\=urn\:btih\:(.*)#', $url,$value)) $hash = trim($value[1]);
			else die("can't get this file");
			$data = $this->curl($this->linkmagnet,"auth=".md5($this->passmagnet),'hash='.$hash);
			$page = json_decode($data, true);

			if(is_array($page) == true && isset($page['gate']) && isset($page['status'])) {
				 if(isset($page['link']) && stristr($page['link'],'http') &&  $page['status'] == 'ok') {
					$url = $page['link'];
					$schema = parse_url($url);
					$host = $schema['host'];
				 }
				 elseif($page['status'] == 'leeching') {
					$gateto = $page['gate'];
					$url = $page['magnet'];
					$host = "torrent";
				 }
				 else $host = "torrent";
			}
			else $host = "torrent";

		}
		else {
			$filesize = Tools_get::size($url);
			if($filesize > 500*1024) $host = 'dlink';
			else {
				$schema = parse_url($url);
				$host = $schema['host'];
			}
		}
		$host = str_replace("www.", "",  $host);

		# Edited by Kien
		//if($_POST['download'] == "mirror") {
			if($host == "oron.com" || $host == "rapidshare.com" || $host == "uploading.com" || $host == "letitbit.net" || $host == "vip-file.com" || $host == "shareflare.net" || $host == "ryushare.com" || $host == "filehaste.com" || $host == "hotfile.com" || $host == "filestay.com" || $host == "filemates.com" || $host == "shragle.com" || $host == "filehost.ws" || $host == "filerose.com" || $host == "cloudnator.com" || $host == "filereactor.com" || $host == "filejungle.com" || $host == "uploadstation.com" || $host == "fileserve.com" || $host == "wupload.com" || $host == "filesonic.com" || $host == "sharingmatrix.com" || $host == "megaupload.com" || $host == "megavideo.com" || $host == "megaporn.com" || $host == "uploadbox.com" || $host == "uploed1.com" || $host == "l1.to") {
				printf($this->lang['siteoff'],$host);
				exit;
			}
			if($host == "upstore.com1" || $host == "upstore.net1" || $host == "upstore1.com")
			{	printf($this->lang['baotri'],$host);
				exit;
			}
			if($host == "extabit.com" || $host == "extabit1.com"){
				printf($this->lang['extabit_1'],$host);
				exit;
			}
			if($host == "ryushare1.com" || $host == "oteupload1.com") {
				printf($this->lang['down_site'],$host);
				exit;
			}
			if($host == "oteupload.com" || $host == "oteupload1.com"){
				printf($this->lang['oteupload_1'],$host);
				exit;
			}
		//}
		//if($_POST['download'] == "mirror") {
			if($host == "downloadprovider.me" || $host == "usenet.nl" || $host == "usenet.net" || $host == "firstclass-download.com"){
				printf($this->lang['notsp_site'],$host);
				exit;
			}
		if(stristr($url,"getlinkvn.com") || stristr($url,"getlink.biz") || stristr($url,"cdn888.xyz") || stristr($url,"getlink.vn")) 
			die($this->lang['orig_pls']);
		//}
		//limit novafile voi acc pro
		
		if(strtolower($this->acc_type['type']) == 'pro') {
			$support_pre = @file_get_contents('http://getlink.vn/supportpre.txt');
			$list_pre = explode("\n", $support_pre);
			if(count($list_pre)>0) {
				foreach($list_pre as $sp_pre) {
					if(empty($sp_pre)) continue;
					if (stristr($sp_pre,$host)) {
						printf($this->lang['sitepre'],$host);
						exit;
					}
				}
			}
		}

		//if($host == "novafile.com")
		//	die("Thông báo: ".$host." chỉ hỗ trợ đối với tài khoản Getlink Premium. Bạn đang sử dụng tài khoản Getlink Pro." );
		# Edited by Kien

		# limit bandwidth for host
		$this->load_bw();
		if (isset($this->hosts[$host]) && $this->bw[$host] >= $this->hosts[$host]['bandwidth']*1024*1024 && isset($this->jobs[$hash])==false){
			printf($this->lang['max_bw_host'],Tools_get::convertmb($this->bw[$host]),Tools_get::convertmb($this->hosts[$host]['bandwidth']*1024*1024),$host);
			exit;
		}
		# limit bandwidth for host


		$this->group[] = $_COOKIE['network'];
		$fields = array(
				'type' => $type,
				'host' => $host,
				'download' => $_POST['download'],
				'group' => json_encode($this->group),
		);
		$data = $this->curl($this->linkgate,"auth=".md5($this->passgate),http_build_query($fields));
		//echo '<pre>';print_r($fields);echo $data;exit;
		
		if (stristr($data,'|') && $host == "torrent" && !isset($gateto)) {
			//save gate to Maget links manager
			$data2 = $this->curl($this->linkmagnet,"auth=".md5($this->passmagnet),'hash='.$hash.'&gate='.$data);

		}

	
		if (stristr($data,'|')) list($linkhost, $passhost, $server2) = explode('|', $data);
		elseif (stristr($data,'not support mirror')) die("not support mirror for ".$host);
		else {
			$contents = "link get: $url <BR>Type: ".json_encode($type)."<BR>Host: $host<BR>download: ".$_POST['download']."<BR>type=".json_encode($type)."&host=".$host."&download=".$_POST['download'];
			$this->mailreport("Không tìm thấy host phù hợp cho link $url !",$contents);
			printf($this->lang['notsv'],Tools_get::site_hash($url),$this->lang['mail_hotro']);
			return;
		}
		
		if(isset($linkhost)){
			$linklog = str_replace('index.php',"login.php",$this->self);
			$data = $this->curl($linkhost,"secureid=".md5($passhost),"urllist=".urlencode($url)."&server2=$server2&log=".urlencode($linklog)."&mail=".$this->email."&mobile=".$this->mobile);
			//echo "<textarea>".$data."</textarea>";exit;

			if(empty($data)==true) {
				$contents = "hostget: $linkhost <BR> server2=$server2 <BR> link get: $url <BR>Type: ".json_encode($type)."<BR>Host: $host<BR>download: ".$_POST['download']."<BR>urllist=$url&server2=$server2&log=".$linklog;
				$this->mailreport("Không load được $server2 !",$contents);
				printf($this->lang['cantjob'],$this->lang['mail_hotro']);
				return;
			}
			elseif(stristr($data,'Please enter Security ID')) {
				$contents = "hostget: $linkhost <BR> server2=$server2 <BR> link get: $url <BR>Type: ".json_encode($type)."<BR>Host: $host<BR>download: ".$_POST['download']."<BR>urllist=$url&server2=$server2&log=".$linklog;
				$this->mailreport("Sai mật khẩu login server !",$contents);
				printf($this->lang['cantjob'],$this->lang['mail_hotro']);
				return;
			}
			if(preg_match("/href='(.*?)' style='TEXT-DECORATION\: none' target='(.*?)'\> \<font color='#00CC00'\>(.*?)\<\/font\> \<font color='#FF66FF'\>\((.*?)\)\<\/font\>/i", $data, $content)){
				$tiam = time().rand(0,999);
				$URL = $content[1];
				$URL = str_replace('http://https','https',$URL);
				$URL = str_replace('http://http','http',$URL);
				/* - 16:58:15 - Sunday, 07 August 2016 [GMT+7]
				$type1 = json_encode($type);
				$type2 = $type;
				if(stristr($type1,'syd') && stristr($type1,'mel')) {
					$input = array("syd", "mel");
					$sv_key = array_rand($input, 1);
					$sv_main = $input[$sv_key];
					foreach($type2 as $key=>$val) if($val ==$sv_main) unset($type2[$key]);
					$URL =  str_replace('://us','://'.$sv_main,$URL);
				}
				elseif(stristr($type1,'syd')) {
					foreach($type2 as $key=>$val) if($val =='syd') unset($type2[$key]);
					$URL =  str_replace('://us','://syd',$URL);
				}
				elseif(stristr($type1,'mel')) {
					foreach($type2 as $key=>$val) if($val =='mel') unset($type2[$key]);
					$URL =  str_replace('://us','://mel',$URL);
				}
				*/
				//$target = $content[2];
				$filename = $content[3];
				$filesize = $content[4];
				if($_POST['download'] == "mirror" ) $dlhtml .=  "<b><a title='click here to download' href='$URL' style='TEXT-DECORATION: none' target='$tiam'> <font color='#00CC00'>".$filename."</font> <font color='#FF66FF'>($filesize)</font></a></b><BR>";
				else {
					//$sv_multi = array_rand($this->server, 1);
					$sv_multi = array_shift(array_keys($this->server)); //get the first key
					$dlhtml .=  "<div class='download_main'><b><a title='click here to download' href='$URL' style='TEXT-DECORATION: none' target='$tiam'> <font color='#00CC00'>".$filename."</font> <font color='#FF66FF'>($filesize)</font> | <span id='us' style='color:#ffff00'>(server US)</span></a></b></div>";
					$dlhtml .= 'link-multi-server';
					$dlhtml .="<div><b><a title='click here to download' href='".str_replace('://us','://'.$sv_multi,$URL)."' style='TEXT-DECORATION: none' target='$tiam'><font color='#00CC00'>".$filename."</font> <font color='#FF66FF'>($filesize)</font> | <span id='".$sv_multi."' style='color:#ffff00'>(".$this->server[$sv_multi].")</span></a>";

					$dlhtml .=  "</b></div>";
				}
				/*
			$svie = false;
			$seng = false;
			$sub = str_replace(substr($file[1],-4),'',$file[1]);
			if(Tools_get::size($sub.'.srt') >0 ) $svie = true;
			if(Tools_get::size($sub.'_VIE.srt') >0 ) $svie = true;
			if(Tools_get::size($sub.'_ENG.srt') >0 ) $svie = true;
				*/
			}
			else {
				$dlhtml .= $data;
				return $dlhtml;
			}
		}
		$msize = Tools_get::convert($filesize);
		if ($msize > ($this->leftbw+100*1024*1024) && isset($this->jobs[$hash])==false){
			$dlhtml = '<div id="errorlimit" align="center">'.$this->lang['outbw'].'</div>';
			return $dlhtml;
		}

		# limit bandwidth for host

		$this->load_bw();
		if (isset($this->hosts[$host]) && $this->bw[$host]+$msize >= $this->hosts[$host]['bandwidth']*1024*1024+100*1024*1024 && isset($this->jobs[$hash])==false){
			printf($this->lang['max_bw_host'],Tools_get::convertmb($this->bw[$host]),Tools_get::convertmb($this->hosts[$host]['bandwidth']*1024*1024),$host);
			return;
		}

		# limit bandwidth for host

		if(isset($URL) && $_POST['download'] != "mirror"){
			if ($hash == false) {
				printf($this->lang['cantjob'],$this->lang['mail_hotro']);
				return $dlhtml;
			}
			if(isset($this->jobs[$hash])==false || (isset($this->jobs[$hash])==true && time() > $this->jobs[$hash]['mtime']+24*60*60*2)){
				$this->load_info();
				$this->load_bw();
				$this->info["bandwitdh"]["value"] = $this->info["bandwitdh"]["value"] - $msize;
				if(isset($this->bw[$host])) $this->bw[$host] = $this->bw[$host] + $msize;
				$this->save_info();
				$this->save_bw();
				$speed = 1;
			}
			elseif((isset($this->jobs[$hash])==true && time() > $this->jobs[$hash]['mtime']+60*60*2)) $speed = 1;
			else $speed = $this->jobs[$hash]['speed']+1;
			$job = array(
				'hash'	=> substr(md5($hash), 0, 10),
				'path'	=> substr(md5(rand()), 0, 5),
				'filename'	=> isset($hashphim)?$namemovies:$filename,
				'size'	=> $filesize,
				'msize'	=> $msize,
				'mtime'	=> time(),
				'speed'	=> $speed,
				'url'	=> isset($hashphim)?$hashphim:$url,
				'owner'	=> $this->owner,
				'ip'	=> $_SERVER['REMOTE_ADDR'],
				'type'	=> 'direct',
				'directlink'	=> array(
					'url'	=> $URL,
						'cookies'=> $this->cookie,
					),
			);
			$this->jobs[$hash] = $job;
			$this->save_jobs();
			if($_POST['download'] == 'phim') {
				$dhtml = '<a href="'.$URL.'" style="font-weight: bold;color:#339900; font-size:16px;" title="'.$this->lang['downfilm'].'">'.$filename.' <font color = "red">('.$filesize.')</font></a>';
				if(isset($this->phim[$hashphim]['count'])) $this->phim[$hashphim]['count'] = $this->phim[$hashphim]['count'] + 1;
				else $this->phim[$hashphim]['count'] = 1;
				$file = $this->pathphim;
				$fh = fopen($file, 'w') 
				or die('<CENTER><font color=red size=3>Could not open file ! Try to chmod the file "<B>'.$file.'</B>" to 666</font></CENTER>');
				if(!is_writable($file)) { chmod($file, 0666); }
				fwrite($fh, json_encode($this->phim));
				fclose($fh);
				@chmod($file, 0666);

				return $dhtml;
			}
			elseif($_POST['download']=='subviet') {
				$dhtml = '<a href="'.$URL.'" style="font-weight: bold;color:blue; font-size:14px;" title="'.$this->lang['downsub'].'">'.$this->lang['subviet'].'</a>';
				return $dhtml;
			}
			elseif($_POST['download']=='subeng') {
				$dhtml = '<a href="'.$URL.'" style="font-weight: bold;color:blue; font-size:14px;" title="'.$this->lang['downsub'].'">'.$this->lang['subeng'].'</a>';
				return $dhtml;
			}
		}
		
		return $dlhtml;
	}

	function authcmp($field) {
		return function($a, $b) use ($field) {
			$av = isset($a[$field]) ? $a[$field] : '';
			$bv = isset($b[$field]) ? $b[$field] : '';
			return strcasecmp((string)$av, (string)$bv);
		};
	}
	function datecmp($field) {
		return function($a, $b) use ($field) {
			$av = isset($a[$field]) ? $a[$field] : 0;
			$bv = isset($b[$field]) ? $b[$field] : 0;
			if ($av == $bv) return 0;
			return ($av < $bv) ? 1 : -1; // desc
		};
	}
	function fulllist() {
		if (isset($_POST['clearfile'])) {
			$this->jobs['clearfile'] = time();
			$this->save_jobs();
		}
		if(!isset($this->jobs['clearfile'])) $this->jobs['clearfile'] = 0;
		$files = array();	
		foreach ($this->jobs as $key=>$job) {
			if(!isset($job['mtime']) || $job['mtime'] < $this->jobs['clearfile']) {
				continue;
			}
			if ($job['owner']!=$this->owner  && $this->privatef==true) continue;
			$files[$key] = $job;
			$files[$key]['hash'] = $key;
		}
		$compare = $this->datecmp('mtime'); 
		if (count($files)==0) { echo "<Center>".$this->lang['notfile']."<br/><a href='$this->self'> [".$this->lang['main']."] </a></center>"; return;}

		echo '<div style="overflow: auto; height: auto; max-height: 450px; width: 800px;"><table id="table_filelist" class="filelist" align="left" cellpadding="3" cellspacing="1" width="100%"><thead><tr class="flisttblhdr" valign="bottom"><td class="sorttable_alpha"><b>'.$this->lang['name'].'</b></td><td><b>'.$this->lang['Original'].'</b></td><td><b>'.$this->lang['Size'].'</b></td><td><b>'.$this->lang['Date'].'</b></td><td><B>IP</B></td></tr></thead><tbody>
		';

		$data = "";

		usort($files, $compare);
		foreach ($files as $file){
			$timeago = Tools_get::convert_time(time() - $file['mtime']). " ".$this->lang['ago'];
			if(time() - $file['mtime'] > 86400*8) $timeago = date('d/m/Y',$file['mtime']);

			if (strlen($file['filename']) > 80) $file['filename']= substr($file['filename'],0,70);
			if(stristr($file['url'],'http')) {
				$url = $file['url'];
				$hosting = substr(Tools_get::site_hash($file['url']),0,15);
			}
			elseif(stristr($file['url'],'magnet') || stristr($file['url'],'.torrent')) {
				$url = $file['url'];
				$hosting = 'torrent';
			}
			elseif(substr(strrchr($file['directlink']['url'], '.'), 1)=='srt') {
				$url = '?id=phim';
				$hosting = 'phụ đề';

			}
			else {
				$url = '?id=phim';
				$hosting = 'phim';
			}
			$data .= "
			<tr class='flistmouseoff' align='center'>
			<td><a href='".$file['directlink']['url']."' style='font-weight: bold; color: rgb(0, 0, 0);'>".$file['filename']."</a></td>
			<td><a href='$url' style='color: rgb(0, 0, 0);'>".$hosting."</a></td>
			<td>".$file['size']."</td>
			<td><font color=#000000>$timeago</font></center></td>
			<td><font color=#000000>".substr($file['ip'], 0, -3)."***</font></td></tr>";

		}
		echo $data;
		$totalall = Tools_get::convertmb($this->totalMB);
		$thislimitMBIP =	round($this->limitMBIP/1024,0);
		
		echo '</tbody><tbody><tr class="flisttblftr"><td>&nbsp;</td><td>'.$this->lang['Total'].':</td><td>'.$totalall.'</td><td></td><td>&nbsp;</td></tr></tbody></table>
		</div></form>';
		printf($this->lang['autodel'],Tools_get::convert_time($this->ttl*60));

		//Clear list files
		echo '	<form action="./?id=listfile" method="POST">
					<input input type="hidden" name="clearfile" value="1"/>
					<input type="submit" value="'.$this->lang['clear_list'].'"><BR>'.$this->lang['note_clear'].'
				</form><br>
				';
		//end clear

	}

	function showimg($hash){
		header("Content-type: image/jpeg");
		$path = $this->phim[$hash]['poster'];

		//$fname = $this->phim[$hash]['name'];
		if(isset($this->phim[$hash]['saveimg']) && $this->phim[$hash]['saveimg'] != false) {
			readfile($this->folderimg.$this->phim[$hash]['saveimg']);
			/*
			if(file_exists($this->folderimg.$this->phim[$hash]['saveimg'])) {
				echo $this->folderimg.$this->phim[$hash]['saveimg'];
				echo '<BR>';
				$image = imagecreatefromjpeg($this->folderimg.$this->phim[$hash]['saveimg']); 
				$color = imagecolorallocate($image, 68, 68, 68);
				imagestring($image, 4, 5, 2, "getlink.vn", $color); 
				imagejpeg($image);
			}
			else {
				$im = imagecreate(600, 30);
				$bg = imagecolorallocate($im, 255, 255, 255);
				$textcolor = imagecolorallocate($im, 0, 0, 255);
				imagestring($im, 5, 100, 0, 'Not found file '.$this->folderimg.$this->phim[$hash]['saveimg'], $textcolor);
				imagejpeg($im);
				imagedestroy($im);
			}
			*/

		}
		elseif(file_exists($this->folderimg.$hash.'.jpg')) {
			$image = imagecreatefromjpeg($this->folderimg.$hash.'.jpg'); 
			$color = imagecolorallocate($image, 68, 68, 68);
			imagestring($image, 4, 5, 2, "http://getlink.vn", $color); 
			imagejpeg($image);
		}
		else {
			$this->copyfile($path,$this->folderimg.$hash.'.jpg');
			echo $this->curl($path,'','',0);	
		}


		exit;

	}

	function showinfo($i,$files){
		$name = substr(strrchr($files['movie'], '/'), 1);
		$name = str_replace('_',' ',$name);
		$name = str_replace('%20',' ',$name);
		$name = str_replace('%28',' ',$name);
		$name = str_replace('%29',' ',$name);
		$gen = '';
		foreach($files['listgenre'] as $val) {
			$gen .= '<a href="./?id=phim&gen='.$val.'"><strong>'.(isset($this->gens[$val])?$this->gens[$val]:$val).'</strong></a>, ';
		}
		$info = '
		<div id="sticky'.$i.'" class="atip" style="width:'.(empty($i)? '700px':'450px').'">
			'.$this->lang['name_film'].': <b>'.$files['name'].'</b></br>
			'.((isset($files['timephim']))?$this->lang['Date'].': '.$files['timephim'].'<BR>':'').'
			'.$this->lang['name'].': <b>'.$name.'</b><br>
			'.$this->lang['Size'].': <b>'.Tools_get::convertmb($files['size']).'</b><br>
			'.$this->lang['rate_imdb'].': <b>'.$files['vote'].'</b><br>
			'.$this->lang['count_dl'].': <b>'.(isset($files['count'])?$files['count']:0).'</b><br>
			'.((isset($files['quality']) && empty($files['quality'])==false)?$this->lang['quality'].': <a href="./?id=phim&quality='.$files['quality'].'"><b>'.$files['quality'].'</b></a><br>':'').'
			'.$this->lang['release'].': <a href="./?id=phim&year='.date("Y",strtotime($files['year'])).'"><b>'.$files['year'].'</b></a><br>
			IMDB: <b><a href="'.$files['imdb'].'" target="'.$files['time'].'">'.$files['imdb'].'</b></a><br>
			'.$this->lang['type_f'].': <b>'.substr($gen,0,-2).'</b><br>
			<p align=justify>'.$files['note'].'</p><br><Br>
		</div>
		';
		return $info;
	}

	function listphim($type) {
		if(isset($_GET['phim'])) {
			$hash = trim($_GET['phim']);

			echo '<div class="al-pl">';
			if(isset($this->phim[$hash])) {
				echo '<div class="imgdl"><img src="http://img.getlinkvn.com/'.$hash.'.jpg"/></div>';
				echo $this->showinfo('',$this->phim[$hash]);
				if(isset($this->jobs['phim_'.$hash]))  {
					$data = '';
					$filename = substr(strrchr($this->jobs['phim_'.$hash]['directlink']['url'], '/'), 1);
					$data .= '<div id="phim'.$hash.'"><a href="'.$this->jobs['phim_'.$hash]['directlink']['url'].'" title="'.$this->lang['downfilm'].'" style="font-weight: bold;font-size:16px;color:green">'.$filename.' <font color = "red">('.$this->jobs['phim_'.$hash]['size'].')</font></a><br>
					<a href="javascript:void(0)" onclick="getphim(\''.$hash.'\');" title="'.$this->lang['f_reget1'].'" style="text-decoration: underline;">'.$this->lang['f_reget2'].'</a><br>
					</div>';
					if(isset($this->jobs['subviet_'.$hash]) && isset($this->jobs['subeng_'.$hash]))  {
						$data .= '<td><span id="subeng'.$hash.'"><a href="'.$this->jobs['subeng_'.$hash]['directlink']['url'].'" style="font-weight: bold;font-size:14px;color:blue">'.$this->lang['subeng'].'</a></span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span id="subviet'.$hash.'"><a href="'.$this->jobs['subviet_'.$hash]['directlink']['url'].'" style="font-weight: bold; font-size:14px;color:blue">'.$this->lang['subviet'].'</a></span></td>';
					}
					elseif(isset($this->jobs['subeng_'.$hash]))  {
						$data .= '<td><span id="subeng'.$hash.'"><a href="'.$this->jobs['subeng_'.$hash]['directlink']['url'].'" style="font-weight: bold; font-size:14px;color:blue">'.$this->lang['subeng'].'</a></span><span id="subviet'.$hash.'></span></td>';
					}
					elseif(isset($this->jobs['subviet_'.$hash]))  {
						$data .= '<td><span id="subeng'.$hash.'"></span><span id="subviet'.$hash.'><a href="'.$this->jobs['subviet_'.$hash]['directlink']['url'].'" style="font-weight: bold; font-size:14px;color:blue">'.$this->lang['subviet'].'</a></span></td>';
					}
					else {
						$data .= '<td><span id="subeng'.$hash.'"></span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span id="subviet'.$hash.'"></span></td>';

					}
					echo $data;

				}
				else {
					echo '<div id="phim'.$hash.'"><a href="javascript:void(0)" onclick="getphim(\''.$hash.'\');" title="'.$this->lang['downfilm'].'" style="font-weight: bold;font-size:16px;">'.$this->lang['downfilm'].' '.$this->phim[$hash]['name'].'</a></div>';
					echo '<div><span id="subeng'.$hash.'"></span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span id="subviet'.$hash.'"><span></div>';
				}
				echo '<BR><BR>';


			}
			else {
				echo '<br><br>'.$this->lang['not_f'].' <br><a href="javascript:history.back(1)">« '.$this->lang['back'].'</a><br><br></div>';
				return;
			}
			echo '</div>';
			
			foreach ($this->phim as $key=>$job) {
				$files[$key] = $job;
				$files[$key]['hash'] = $key;
				if(!isset($files[$key]['count'])) $files[$key]['count'] = 0;

				if(!stristr($files[$key]['name'],trim($this->phim[$hash]['name']))) unset($files[$key]);
			}
			if(count($files) == 0) return;
			echo '
			<!-- List new -->
			<div class="al-pl">
				<div class="title-main">
					<label class="ico-playlist"></label>
				</div>';
				echo '<ul class="list-al-pl">';
			$j = 0;
			$info = '';
			//echo '<pre>';
			//print_r($files);
			foreach($files as $i=>$file){
				$j++;
				echo '
				<li>
					<div class="poster" data-tooltip="stickynew'.$i.'">
						<a href="./?id=phim&phim='.$files[$i]['hash'].'" title="'.$this->lang['downfilm'].'"><img src="http://img.getlinkvn.com/'.$hash.'.jpg" style="max-height:180px; width:110px"/></a>
					</div>
					<h3>
						<a href="./?id=phim&phim='.$files[$i]['hash'].'" title="'.$this->lang['downfilm'].'">'.$files[$i]['name'].'</a><p>'.$this->lang['quality'].': '.$files[$i]['quality'].'<BR>'.$this->lang['Size'].': '.Tools_get::convertmb($files[$i]['size']).'<BR>'.$this->lang['count_dl'].': '.$files[$i]['count'].'<BR>Rate: '.$files[$i]['vote'].'</p>
					</h3>
				</li>';
				if($j == 6)  {
					echo '<br class="clr">';
					$j = 0;
				}
				$info .= $this->showinfo('new'.$i,$files[$i]);
			}
			echo '
					<br class="clr">
				</ul>
			</div>
			<!-- End List new -->';
			if(isset($info)) echo '
				<!--HTML for the tooltips-->
				<div id="mystickytooltip" class="stickytooltip">
					<div style="padding:5px">
						'.$info.'
					</div>
					<div class="stickystatus"></div>
				</div>
				<!--HTML for the tooltips-->';
			return;
		}
		if(isset($_GET['view']) && $_GET['view'] == 'request') { 
			include($this->fileinfo_dir."/info.php");
			
			echo '<div class="al-pl">
					<div class="title-main">
						<label class="ico-playlist">'.$this->lang['f_request'].'</label>
					</div>';
			echo '<div id="wait" style="width: 600px; padding:10px 0px 10px 20px;font-size:14px" align="center"><p align="justify">'.$this->lang['requestphim'].'</p></div>
				<div style="overflow: auto; height: auto; width: 500px;" id="contact">
				<form action="javascript:contact(document.getElementById(\'form_contact\'));" name="form_contact" id="form_contact">
				<table cellpadding="3" cellspacing="1" border="0" align="center">
					<tr>
						<td align="right">T&#7921; x&#432;ng :</td>
						<td>
							<select name="tuxung">
								<option value="anh">'.$this->lang['anh'].'</option>
								<option value="ch&#7883;">'.$this->lang['chi'].'</option>
								<option value="b&#225;c">'.$this->lang['bac'].'</option>
							</select>
						</td>
					</tr>
					<tr>
						<td align="right">'.$this->lang['fullname'].' *:</td>
						<td><input type="text" class="text" name="hovaten" size="30" value="'.$username.'"/></td>
					</tr>
					<tr>
						<td align="right">'.$this->lang['address'].'</td>
						<td><input type="text"  class="text" name="diachi" size="30" value="'.$address.'"/></td>
					</tr>
					<tr>
						<td align="right">'.$this->lang['mobile_sp'].'</td>
						<td><input type="text"  class="text" name="sodienthoai" size="30" value="'.$mobile.'"/></td>
					</tr>
					<tr>
						<td align="right">Email *:</td>
						<td>'.$email.'</td>
					</tr>
					<tr><td height="5px"></td></tr>
					<tr>
						<td align="right">'.$this->lang['sub'].' *:</td>
						<td><input type="text" class="text" name="tieude" size="60" value="yêu cầu phim"/></td>
					</tr>
					<tr>
						<td align="right" valign="top">'.$this->lang['content'].' *:</td>
						<td><textarea name="noidung" style="width:99%;height:100px;"></textarea></td>
					</tr>
					<tr>
						<td></td>
						<td align="left"><input type="submit" value="G&#7917;i" id="submit123"/></td>
					</tr>

				</table>
				</form><br><br></div>
			</div>';
			return;
		}
		$self = 'http://'.$_SERVER['HTTP_HOST'].isset($_SERVER['REQUEST_URI'])? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF'];
		$files = array();	
		$newfile = array();
		$title  = $this->lang['f_update'];
		foreach ($this->phim as $key=>$job) {
			$files[$key] = $job;
			$files[$key]['hash'] = $key;
			//if(strlen($files[$key]['year'])==4) $files[$key]['yearsec'] = strtotime('1-1-'.$files[$key]['year']);
			//else $files[$key]['yearsec'] = strtotime($files[$key]['year']);
			if(!isset($files[$key]['count'])) $files[$key]['count'] = 0;
			if(isset($_GET['search'])) {
				if(!stristr($files[$key]['name'],trim($_GET['search']))) unset($files[$key]);
			}
			elseif(isset($_GET['view']) && $type == 'down') {
				if(!isset($this->jobs['phim_'.$key])) unset($files[$key]);
				$title  = $this->lang['f_dl'];
			}
		}
		
		if(isset($_GET['view']) && $type == 'new') {
			$compare = $this->datecmp('year'); 
			usort($files, $compare);
			$title  = $this->lang['f_new'];
		}
		
		elseif(isset($_GET['view']) && $type == 'hot') {
			$compare = $this->datecmp('vote'); 
			usort($files, $compare);
			$title  = $this->lang['f_hot'];
		}
		elseif(isset($_GET['view']) && $type == 'dl') {
			$compare = $this->datecmp('count'); 
			usort($files, $compare);
			$title  = $this->lang['f_dlhot'];
		}
		else {
			$compare = $this->datecmp('time'); 
			usort($files, $compare);
		}
		if(isset($_GET['search'])) $title  = $this->lang['f_results'];
		elseif(isset($_GET['gen'])) {
			$gen = strtolower(trim($_GET['gen']));
			foreach($files as $key=>$phim) {
				if (in_array($gen, $phim['listgenre'])==true && $phim["status"] == 1) {
					$newfile[] = $phim;
				}
			}
			$files = $newfile;
			$title  = $this->lang['f_type'].': '.(isset($this->gens[$gen])?$this->gens[$gen]:$gen);
		}
		elseif(isset($_GET['quality'])) {
			$quality = trim($_GET['quality']);
			$title  = $this->lang['f_quality'].': '. $quality;
			foreach($files as $key=>$phim) {
				if (isset($phim['quality']) && empty($phim['quality'])==false && stristr($quality,$phim['quality']) && $phim["status"] == 1) {
					$newfile[] = $phim;
				}
			}
			$files = $newfile;
			$title  = $this->lang['f_quality'].': '. $quality;
		}
		elseif(isset($_GET['year'])) {
			$year = trim($_GET['year']);
			foreach($files as $key=>$phim) {
				if ($year == $phim['year'] && $phim["status"] == 1) {
					$newfile[] = $phim;
				}
			}
			$files = $newfile;
			$title  = $this->lang['f_year']. $year;
		}

		if(isset($_GET['page'])) {
			if (!is_numeric($_GET['page'])) $page = 0;
			else $page = trim($_GET['page']) - 1;
		}
		else $page = 0;
		$phim_per_page = 18;
		$totalphim = count($files);
		$totalpage = round($totalphim/$phim_per_page, 0);
		if ($totalpage*$phim_per_page < $totalphim) $totalpage = $totalpage+1;

		$trang = 'Trang: ';
		$end = 0;
		for ($h = 1 ; $h < $totalpage+1; $h++) {
			$end++;
			if(isset($_GET['page']) && $h == $_GET['page']) $pages = "<B><font color='red'>".$_GET['page']."</font></b>";
			elseif(isset($_GET['page'])==false && $h == 1)  $pages = "<B><font color='red'>1</font></b>";
			else $pages = $h;
			if(isset($_GET['year'])) $trang .= '&nbsp;<a href="./?id=phim&year='.$_GET['year'].'&page='.$h.'">['.$pages.']</a>&nbsp;';
			elseif(isset($_GET['quality'])) $trang .= '&nbsp;<a href="./?id=phim&quality='.$_GET['quality'].'&page='.$h.'">['.$pages.']</a>&nbsp;';
			elseif(isset($_GET['gen'])) $trang .= '&nbsp;<a href="./?id=phim&gen='.$_GET['gen'].'&page='.$h.'">['.$pages.']</a>&nbsp;';
			elseif($type == 'hot')  $trang .= '&nbsp;<a href="./?id=phim&view=hot&page='.$h.'">['.$pages.']</a>&nbsp;';
			elseif($type == 'new')   $trang .= '&nbsp;<a href="./?id=phim&view=new&page='.$h.'">['.$pages.']</a>&nbsp;';
			elseif($type == 'update')   $trang .= '&nbsp;<a href="./?id=phim&view=update&page='.$h.'">['.$pages.']</a>&nbsp;';
			elseif($type == 'dl')   $trang .= '&nbsp;<a href="./?id=phim&view=dl&page='.$h.'">['.$pages.']</a>&nbsp;';
			elseif($type == 'down')   $trang .= '&nbsp;<a href="./?id=phim&view=down&page='.$h.'">['.$pages.']</a>&nbsp;';
			elseif(isset($_GET['search']))   $trang .= '&nbsp;<a href="./?id=phim&search='.$_GET['search'].'&page='.$h.'">['.$pages.']</a>&nbsp;';
			if($end == "30") {
				$trang .=  "<BR>";
				$end = 0;
			}
		}
		if($totalphim == 0) {
			if(isset($_GET['search'])) echo $this->lang['f_notkey'];

			else echo '
			<div class="al-pl">
				<center><br><br>'.$this->lang['soon_up'].'<br><br></center>
			</div>
			';

			return;
		}
		if($type == 'main') {
			echo '
			<!-- List new -->
			<div class="al-pl">
				<div class="title-main">
					<label class="ico-playlist">'.$this->lang['f_update'].'</label>
					<a href="./?id=phim&view=update" class="more">'.$this->lang['f_list'].' »</a>
				</div>
				<ul class="list-al-pl">';
			if(count($files) < 12) $max = count($files);
			elseif(isset($_GET['phim'])) $max = 6;
			else $max = 12;
			$j = 0;
			$info = '';
			for($i = 0; $i <$max;$i++) {
				$j++;
				echo '
				<li>
					<div class="poster" data-tooltip="stickynew'.$i.'">
						<a href="./?id=phim&phim='.$files[$i]['hash'].'" title="'.$this->lang['downfilm'].'"><img src="http://img.getlinkvn.com/'.$files[$i]['hash'].'.jpg" style="max-height:180px; width:110px"/></a>
					</div>
					<h3>
						<a href="./?id=phim&phim='.$files[$i]['hash'].'" title="'.$this->lang['downfilm'].'">'.$files[$i]['name'].'</a><p>Lượt down: '.$files[$i]['count'].'<BR>Rate: '.$files[$i]['vote'].'</p>
					</h3>
				</li>';
				if($j == 6)  {
					echo '<br class="clr">';
					$j = 0;
				}
				$info .= $this->showinfo('new'.$i,$files[$i]);
			}
			echo '
					<br class="clr">
				</ul>
				<div class="title-main" align="right">
					<a href="./?id=phim&view=update" class="more">'.$this->lang['more'].' »</a>
				</div>	
				
			</div>
			<!-- End List new -->';

	
			$compare = $this->datecmp('count'); 
			usort($files, $compare);

			echo '
			<!-- List hot -->
			<div class="al-pl">
				<div class="title-main">
					<label class="ico-playlist">'.$this->lang['f_hot'].'</label>
					<a href="./?id=phim&view=dl&page=1" class="more">'.$this->lang['more'].' »</a>
				</div>
				<ul class="list-al-pl">';

			$j = 0;
			$h = 0;
			$year = date('Y') - 1;
			$max = count($files);
			for($i = 0; $i <$max;$i++) {
				if($files[$i]['count'] < $this->count_dl && $files[$i]['year'] < $year) continue;
				$j++;
				$h++;
				echo '
				<li>
					<div class="poster" data-tooltip="stickyhot'.$i.'">
						<a href="./?id=phim&phim='.$files[$i]['hash'].'" title="'.$this->lang['downfilm'].'"><img src="http://img.getlinkvn.com/'.$files[$i]['hash'].'.jpg" style="max-height:180px; width:110px"/></a>
					</div>
					<h3 id="phim'.$files[$i]['hash'].'">
						<a href="./?id=phim&phim='.$files[$i]['hash'].'" title="'.$this->lang['downfilm'].'">'.$files[$i]['name'].'</a><p>Lượt down: '.$files[$i]['count'].'<BR>Rate: '.$files[$i]['vote'].'</p>
					</h3>
				</li>';
				if($j == 6)  {
					echo '<br class="clr">';
					$j = 0;
				}
				$info .= $this->showinfo('hot'.$i,$files[$i]);
				if($h==18)break;
			}
			echo '
					<br class="clr">
				</ul>
				<div class="title-main" align="right">
					<a href="./?id=phim&view=dl&page=1" class="more">'.$this->lang['more'].' »</a>
				</div>	
			</div>
			<!-- End List hot -->';
		}
		else {
			echo '
			<!-- List new -->
			<div class="al-pl">
				<div class="title-main">
					<label class="ico-playlist">'.$title.'</label>
				</div>';
				echo $trang;
				echo '<ul class="list-al-pl">';
			$j = 0;
			$info = '';
			for ($i=$page*$phim_per_page; $i < $page*$phim_per_page + $phim_per_page; $i++){
				$j++;
				if(!isset($files[$i])) break;
				echo '
				<li>
					<div class="poster" data-tooltip="stickynew'.$i.'">
						<a href="./?id=phim&phim='.$files[$i]['hash'].'" title="'.$this->lang['downfilm'].'"><img src="http://img.getlinkvn.com/'.$files[$i]['hash'].'.jpg" style="max-height:180px; width:110px"/></a>
					</div>
					<h3>
						<a href="./?id=phim&phim='.$files[$i]['hash'].'" title="'.$this->lang['downfilm'].'">'.$files[$i]['name'].'</a><p>Lượt down: '.$files[$i]['count'].'<BR>Rate: '.$files[$i]['vote'].'</p>
					</h3>
				</li>';
				if($j == 6)  {
					echo '<br class="clr">';
					$j = 0;
				}
				$info .= $this->showinfo('new'.$i,$files[$i]);
			}
			echo '
					<br class="clr">
				</ul>
				<br>'.$trang.'<br><br>
			</div>
			<!-- End List new -->';
			
		}

		if(isset($info)) echo '
			<!--HTML for the tooltips-->
			<div id="mystickytooltip" class="stickytooltip">
				<div style="padding:5px">
					'.$info.'
				</div>
				<div class="stickystatus"></div>
			</div>
			<!--HTML for the tooltips-->';
	}
}
##################################### End class stream_get ###################################


##################################### Begin class Tools_get ###################################
class Tools_get extends getinfo {
	function site_hash($url){
		if(stristr($url,'magnet')) return 'magnet';
		//elseif(stristr($url,'.torrent')) return 'torrent';
		$schema = parse_url($url);
		$site = preg_replace("/(www.|.com|.net|.biz|.info|.org|.us|.vn|.jp|.fr|.in|.to)/","",$schema['host']);
		return $site;
	}
	function convert($filesize){
		$filesize = str_replace(",",".",$filesize);
		if(preg_match('/^([0-9]{1,7}+(\.[0-9]{1,2})?)/', $filesize,$value)){
			if(stristr($filesize,"TB"))		$value = $value[1]*1024*1024*1024*1024;
			elseif(stristr($filesize,"GB")) $value = $value[1]*1024*1024*1024;
			elseif(stristr($filesize,"MB")) $value = $value[1]*1024*1024;
			elseif(stristr($filesize,"KB")) $value = $value[1]*1024;
			else $value = $value[1];
		}
		else $value = 0;
		return round($value,0);
	}
	function convertmb($filesize){
		if (!is_numeric($filesize)) return $filesize;
		$soam = false;
		if($filesize<0){
			$filesize = abs($filesize);
			$soam = true;
		}
		if($filesize >= 1024*1024*1024*1024) $value = ($soam ? "-" : "").round($filesize/(1024*1024*1024*1024), 2)." TB";
		elseif($filesize >= 1024*1024*1024) $value = ($soam ? "-" : "").round($filesize/(1024*1024*1024), 2)." GB";
		elseif($filesize >= 1024*1024) $value = ($soam ? "-" : "").round($filesize/(1024*1024), 2)." MB";
		elseif($filesize >= 1024) $value = ($soam ? "-" : "").round($filesize/(1024), 2)." KB";
		else $value = ($soam ? "-" : "").$filesize." Bytes";
		return $value;
	}
	function convert_time($time){
		if($time >= 86400) $time = round($time/(60*24*60), 1)." ".$this->lang['days'];
		elseif(86400 > $time && $time >= 3600) $time = round($time/(60*60), 1)." giờ";
		elseif(3600 > $time && $time >= 60) $time = round($time/60, 1)." ".$this->lang['mins'];
		else $time = $time." ".$this->lang['sec'];

		return $time;
	}
	function size($link,$time=15){
		$link = str_replace(" ","%20",$link);
		$link = str_replace('&amp;','&',$link);
		/*
		$ch = @curl_init();
		curl_setopt($ch, CURLOPT_URL, $link);
		curl_setopt($ch, CURLOPT_HEADER, 1);
		curl_setopt($ch, CURLOPT_NOBODY, true);
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
		curl_setopt($ch, CURLOPT_USERAGENT, $this->UserAgent);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_REFERER,$link);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
		curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_TIMEOUT, $time); 
		curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $time);
		$page = curl_exec($ch);
		$info = curl_getinfo($ch);
		curl_close($ch); 
		//echo $page;print_r($info);exit;
		if($info['http_code'] == '200') $filesize = $info['download_content_length'];
		else $filesize = -1;
		return $filesize;
		*/

		$port = 80;
		$schema = parse_url(trim($link));
		$host= $schema['host'];
		$scheme = "http://";
		$gach = explode("/", $link);
		list($path1, $path)  = explode($gach[2], $link);
		if(isset($schema['port'])) $port = $schema['port'];
		elseif ($schema['scheme'] == 'https') {
			$scheme = "ssl://";
			$port = 443;
		}

		if ($scheme != "ssl://") {
			$scheme = "";
		}
		$hosts = $scheme . $host . ':' . $port;
		$fp = @stream_socket_client ($hosts, $errno, $errstr, 30);

		if (!$fp) $filesize = -1;
		else {
			$data = "GET {$path} HTTP/1.1\r\n";
			$data .= "User-Agent: ".$this->UserAgent."\r\n";
			$data .= "Host: {$host}\r\n";
			$data .= "Referer: {$link}\r\n";
			$data .= "Accept: */*\r\n";
			$data .= "Connection: Close\r\n\r\n";
			@stream_set_timeout($fp, 30);
			fputs($fp, $data);
			fflush($fp);

			$header = stream_get_line($fp, 1024);
			if(preg_match ('/^HTTP\/1\.(1|0) ([0-9]+) .*/i', $header, $responsecode)) {
				if ($responsecode[2] == 200) $filesize = trim ($this->cut_str ($header, "Content-Length:", "\n" ));
				else $filesize = -1;
			}
			else $filesize = -1;
		}
		//echo "<textarea>".$header ."</textarea>";exit;
		return $filesize;
	}

}
##################################### End class Tools_get #####################################

?>