View Single Post
  #1  
Old 6th January 2013, 02:49
sharpie sharpie is offline
Senior Member
 
Join Date: Apr 2012
United Kingdom
Posts: 17
Default ajax browse help please
can anyone help me please im trying to add torrent new tags so when a new torrent gets uploaded it says new, to this ajax browse but not having any success

Code:
<?php
require_once("include/bittorrent.php");
if(eregi(basename(__FILE__),$_SERVER['REQUEST_URI'])){
	print("<h2>You know you're not allowed to look directly at scripts.. so stop trying to peak</h2>");
	die();
}

//	==	TheHippy Ajax Browse Class 2010
//
//	==	
class browseTorrents extends db {

	// $active statuses are 1=active only, 2=dead only, 3=active and dead
	public function getTorrentList($cats_id=0,$active=3,$page=1,$stext=0)
	{
		$cats = genrelist();
		$cattotal = count($cats);
		$output	=	"";
              $perpage = "25";
		$offset = ($page - 1) * $perpage;
		$where	=	"";
		$ccase	=	"";
		if($cats_id != "0"){
			$where	=	" WHERE ";
				$ccase	.=	"`torrents`.`category`='" . urlencode($cats_id) . "'";
		}
		if($stext	!= "0"){
			if($where == " WHERE "){
				$ccase	.=	" AND `torrents`.`name` LIKE '%" . htmlspecialchars($stext) . "%'";
			} else {
				$where = " WHERE ";
				$ccase	.=	"`torrents`.`name` LIKE '%" . htmlspecialchars($stext) . "%'";
			}
		}
		switch($active)
		{
			case 1:
			if($where == " WHERE "){
				$ccase	.=	" AND `torrents`.`visible`='yes'";
			} else {
				$where = " WHERE ";
				$ccase	.=	"`torrents`.`visible`='yes'";
			}
			break;
			case 2:
			if($where == " WHERE "){
				$ccase	.=	" AND `torrents`.`visible`='no'";
			} else {
				$where = " WHERE ";
				$ccase	.=	"`torrents`.`visible`='no'";
			}
			break;
			case 3:
			break;
		}

		//	=	This counts the total torrents for pagination
		$sql2	=	"SELECT `torrents`.`id`, `torrents`.`name` AS `torrentname`, `torrents`.`filename`, `torrents`.`description`,`torrents`.`category`, `torrents`.`size`, `torrents`.`added`, `torrents`.`type`, `torrents`.`numfiles`, `torrents`.`comments`, `torrents`.`views`, `torrents`.`hits`, `torrents`.`times_completed`, `torrents`.`leechers`, `torrents`.`seeders`, `torrents`.`owner`, `users`.`username`,`users`.`privacy`, `users`.`id` AS `user_id`, `categories`.`name` FROM `torrents` LEFT JOIN `users` ON `users`.`id`=`torrents`.`owner` LEFT JOIN `categories` ON `categories`.`id`=`torrents`.`category` " . $where . $ccase . "";
		$gettotals	=	$this->query($sql2);
		$totalt		=	$this->rows;
		$maxpage	=	ceil($totalt/$perpage);
		$npage	=	array();
		//	=	This makes the pagination
		if($page > 1){
				$pagefirst	=	"document.getElementById('page').value='1';";
				$npage[]	=	" <span class=\"ajaxclicker\" onmousedown=\"$pagefirst\" onclick=\"doBrowse();\">&laquo; First Page</span> ";
				$pagel		=	"document.getElementById('page').value='$maxpage';";
				$lastpage	=	"<span class=\"ajaxclicker\" onmousedown=\"$pagel\" onclick=\"doBrowse();\">" . $maxpage . "</span>";
				$pageback	=	$page-1;
				$pageba		=	"document.getElementById('page').value='$pageback';";
				$npage[]	=	" <span class=\"ajaxclicker\" onmousedown=\"$pageba\" onclick=\"doBrowse();\"><img title=Back border='0' src=\"pic/prevpager.png\"/></span> ";
			if($page < $maxpage){
				$pageforr	=	$page+1;
				$pagefor	=	"document.getElementById('page').value='$pageforr';";
				$npage[]	=	" <span class=\"ajaxclicker\" onmousedown=\"$pagefor\" onclick=\"doBrowse();\"><img title='page $page' border='0' src=\"pic/nextpager.png\"/></span> ";
				$pagelast	=	"document.getElementById('page').value='$maxpage';";
				$npage[]	=	" <span class=\"ajaxclicker\" onmousedown=\"$pagelast\" onclick=\"doBrowse();\">Last Page &raquo;</span> ";
				$pagel		=	"document.getElementById('page').value='$maxpage';";
				$lastpage	=	"<span class=\"ajaxclicker\" onmousedown=\"$pagel\" onclick=\"doBrowse();\">" . $maxpage . "</span>";
			}	
		}
		if($maxpage > 1){
		if($page == 1){
			$pageforr	=	$page+1;
			$pagefor	=	"document.getElementById('page').value='$pageforr';";
			$npage[]	=	" <span class=\"ajaxclicker\" onmousedown=\"$pagefor\" onclick=\"doBrowse();\"><img title='Page $page' border='0' src=\"pic/nextpager.png\"/></span> ";
			$pagelast	=	"document.getElementById('page').value='$maxpage';";
			$npage[]	=	" <span class=\"ajaxclicker\" onmousedown=\"$pagelast\" onclick=\"doBrowse();\">Last Page &raquo;</span>";
		}
		}
			$output		.=	"<span class=\"ajaxclicker\"  onclick=\"doBrowse();\"><b>Refresh Table</b></span>";
			$output		.=	"<br><div  border=\"0\" style=\"text-align:center;\"><span id=\"totalrecords\">Total Torrents found: $totalt</span>";
			foreach($npage as $key=>$val) {
				$output	.=	$val;
			}
		$output		.=	"</div>";
		//	=	This makes the actual query to populate the table of results

		$sql	=	"SELECT `torrents`.`id`, `torrents`.`name` AS `torrentname`, `torrents`.`filename`, `torrents`.`ori_descr`, torrents.free,`torrents`.`category`, torrents.10days, categories.name AS cat_name, categories.image AS cat_pic, `torrents`.`size`, `torrents`.`added`, `torrents`.`type`, `torrents`.`numfiles`, `torrents`.`comments`, `torrents`.`views`, `torrents`.`hits`, `torrents`.`times_completed`, `torrents`.`leechers`, `torrents`.`seeders`, `torrents`.`owner`, `users`.`username`,`users`.`privacy`, `users`.`id` AS `user_id`, `categories`.`name`,users.class as owner_class FROM `torrents` LEFT JOIN `users` ON `users`.`id`=`torrents`.`owner` LEFT JOIN `categories` ON `categories`.`id`=`torrents`.`category` " . $where . $ccase . " ORDER BY `torrents`.`id` DESC LIMIT $offset,$perpage";
		$tors	=	$this->query($sql);
		$total	=	$this->rows;

		//	= Start building what'll be displayed in the users browser
		if($this->rows > 0){
		$output	.=	"<br />\n";
		$output	.=	"<table border=\"0\" align=\"center\" class=\"row3\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";
		$output	.=	"	<tr>\n";
		$output	.=	"		<td class=\"colhead\" align=\"center\">Genre</td>\n";
		$output	.=	"		<td class=\"colhead\" align=\"center\">Name</td>\n";
		$output	.=	"		<td class=\"colhead\" width=\"8%\" align=\"center\">Added</td>\n";
		$output	.=	"		<td class=\"colhead\" align=\"center\"><img border='0' src='pic/comments.png' alt='Comments' title='Comments' /></td>\n";
		$output	.=	"		<td class=\"colhead\" width=\"8%\" align=\"center\">Size</td>\n";
		$output	.=	"		<td class=\"colhead\" align=\"center\"><img border='0' src='pic/snatched.png' alt='Snatches' title='Snatches' /></td>\n";
		$output	.=	"		<td class=\"colhead\" align=\"center\"><img border='0' src='pic/seeders.png' alt='Seeders' title='Seeders' /></td>\n";
		$output	.=	"		<td class=\"colhead\" align=\"center\"><img border='0' src='pic/leechers.png' alt='Leechers' title='Leechers' /></td>\n";
		$output	.=	"		<td class=\"colhead\" align=\"center\">Upped&nbsp;by</td>\n";
		$output	.=	"	</tr>\n";
			while($tor	=	mysql_fetch_array($tors)){
/*				$ttl = (28*24) - floor((time() - $tor["added"]) / 3600);						
				if ($ttl == 1){
					$ttl .= "<br />Hour"; 
				} else { 
					$ttl .= "<br />Hours";
				}
*/

				$leecha		=	"";
				$leechb		=	"";
				$seeda		=	"";
				$seedb		=	"";
				if($tor['leechers'] > 0){
					$leecha	=	"<strong><a href=\"details.php?id=" . $tor['id'] . "&dllist=1#leechers\"><font color=green>";	
					$leechb	=	"</a></strong></font>";
				}
				if($tor['seeders'] > 0){
					$seeda	=	"<strong><a href=\"details.php?id=" . $tor['id'] . "&dllist=1#seeders\"><font color=green>";	
					$seedb	=	"</a></strong></font>";
				}
				if($tor['comments'] >= 1){
					$com1	=	"<strong><a href=\"details.php?id=" . $tor['id'] . "&page=0#startcomments\"><font color=green>";	
					$com2	=	"</a></strong></font>";
				}

        $thisisfrees = ($tor[free]=="yes" ? "<img  align=right src=pic/freedownload.gif title='This torrent is freeleech so only upload counts!'>" : "");
        $doubleuptag = ($tor["10days"]=="yes" ? "<img align=right src='pic/2xup.png' alt='x2' title='This torrent is x2 upload'>" : "");      
$dispname = htmlspecialchars($tor["torrentname"]);
$dispname1 = htmlspecialchars($tor["ori_descr"]);
if (get_user_class() >= UC_VIP){
$dl = ("<a align=right href=\"download.php/" . $tor['id'] . "/" . rawurlencode($tor["filename"]) . "\"><img align=right src=pic/blank.gif class=dl border=0 title='Download $dispname' alt=Download></a>");
}        $added = "" . get_elapsed_times(sql_timestamp_to_unix_timestamp($tor["added"])) . " ago";
				$detaila	=	"<strong><a title=\"$dispname1\" href=\"details.php?id=" . $tor['id'] . "\">";
				$detailb	=	"</a></strong>";
				$filesa		=	"<strong><a href=\"filelist.php?id=" . $tor['id'] . "\">";
				$filesb		=	"</a></strong>";
				$ownera		=	"<strong><a href=\"" . $tor['username'] . ".usr\"><font color=\"".get_user_class_color($tor["owner_class"])."\">";
				$ownerb		=	"</a></strong></font>";
				$catega		=	"<span ><span>";
				$categb		=	"</span></span>";
				$downla		=	"<a href=\"download.php?torrent=" . $tor['id'] . "\">";
				$downlb		=	"</a>";	
				$output	.=	"	<tr class=browse>";
				$output	.=	"		<td align=\"left\"><img border=\"0\" src=\"pic/categorypics/" . $tor["cat_pic"] . "\" title=\"" . $tor["cat_name"] . "\" /></td>\n";
                            $output	.=	"		<td align=\"left\"><b>". $detaila . $tor['torrentname'] . $detailb ."$dl $thisisfrees $doubleuptag</b></a>\n";
				$output	.=	"		<td align=\"center\">$added</td>\n";
//				$output	.=	"		<td align=\"center\">" . $ttl . "</td>\n";
				$output	.=	"		<td align=\"center\"><a href=\"details.php?id=" . $tor['id'] . "&page=0#startcomments\">" . $tor['comments'] . "</a></td>\n";
				$output	.=	"		<td align=\"center\">" . str_replace(" ", " ", mksize($tor["size"])) . "</td>\n";
				$output	.=	"		<td align=\"center\"><a href=viewsnatches.php?id=$tor[id]>" . $tor['times_completed'] . "</a></td>\n";
				$output	.=	"		<td align=\"center\"><b><font color=red>" . $seeda . $tor['seeders'] . $seedb . "</td></font>\n";
				$output	.=	"		<td align=\"center\"><b><font color=red>" . $leecha . $tor['leechers'] . $leechb . "</td></font></b>\n";
				$output	.=	"		<td align=\"center\">" . $ownera . $tor['username'] . $ownerb . "</td>\n";
				$output	.=	"	</tr>";
			}
		$output	.=	"</table>\n";
		} else {
			$output.=	"<h2>Sorry: There are no torrents that match your criteria, try amending your options.</h2>";	
		}
			$output		.=	"<br /><div style=\"text-align:center;\"><span id=\"totalrecords\">Total Torrents found: $totalt</span>";
			foreach($npage as $key=>$val) {
				$output	.=	$val;
			}
			$output		.=	"</div>";
			// = Amend with your website address below...
			//$output.=	"<br /><span class=\"linktopage\"><strong>Link to this page: </strong>https://gettorrents.org/browse.php?cat_id=" . $cats_id . "&active=" . $active . "&page=" . $page . "&search=" . $stext . "</span>";
		return $output;
	}
}
?>
Reply With Quote