$Where = array();
if(!empty($_GET['advanced']) && check_perms('site_advanced_top10')) {
$Details = 'all';
$Limit = 10;
if($_GET['tags']) {
$Tags = explode(',', str_replace(".","_",trim($_GET['tags'])));
foreach ($Tags as $Tag) {
$Tag = preg_replace('/[^a-z0-9_]/', '', $Tag);
if($Tag != '') {
$Where[]="g.TagList REGEXP '[[:<:]]".db_string($Tag)."[[:>:]]'";
}
}
}
if($_GET['format']) {
if(in_array($_GET['format'], $Formats)) {
$Where[]="t.Format='".db_string($_GET['format'])."'";
}
}
} else {
// error out on invalid requests (before caching)
if(isset($_GET['details'])) {
if(in_array($_GET['details'], array('day','week','overall','snatched','data','seeded','month','year'))) {
$Details = $_GET['details'];
} else {
error(404);
}
} else {
$Details = 'all';
}
// defaults to 10 (duh)
$Limit = isset($_GET['limit']) ? intval($_GET['limit']) : 10;
$Limit = in_array($Limit, array(10, 100, 250)) ? $Limit : 10;
}
$Filtered = !empty($Where);
show_header('Top '.$Limit.' Torrents');
?>
Top =$Limit?> Torrents
if(check_perms('site_advanced_top10')) {
?>
}
// default setting to have them shown
$DisableFreeTorrentTop10 = (isset($LoggedUser['DisableFreeTorrentTop10']) ? $LoggedUser['DisableFreeTorrentTop10'] : 0);
// did they just toggle it?
if(isset($_GET['freeleech'])) {
// what did they choose?
$NewPref = ($_GET['freeleech'] == 'hide') ? 1 : 0;
// Pref id different
if ($NewPref != $DisableFreeTorrentTop10) {
$DisableFreeTorrentTop10 = $NewPref;
update_site_options($LoggedUser['ID'], array('DisableFreeTorrentTop10' => $DisableFreeTorrentTop10));
}
}
// Modify the Where query
if ($DisableFreeTorrentTop10) {
$Where[] = "t.FreeTorrent='0'";
}
// The link should say the opposite of the current setting
$FreeleechToggleName = ($DisableFreeTorrentTop10 ? 'show' : 'hide');
$FreeleechToggleQuery = get_url(array('freeleech'));
if (!empty($FreeleechToggleQuery))
$FreeleechToggleQuery .= '&';
$FreeleechToggleQuery .= 'freeleech=' . $FreeleechToggleName;
?>
$Where = implode(' AND ', $Where);
$WhereSum = (empty($Where)) ? '' : md5($Where);
$BaseQuery = "SELECT
t.ID,
g.ID,
g.Name,
g.CategoryID,
g.TagList,
t.Format,
t.Encoding,
t.Media,
t.Scene,
t.HasLog,
t.HasCue,
t.LogScore,
t.RemasterYear,
g.Year,
t.RemasterTitle,
t.Snatched,
t.Seeders,
t.Leechers,
((t.Size * t.Snatched) + (t.Size * 0.5 * t.Leechers)) AS Data,
g.ReleaseType
FROM torrents AS t
LEFT JOIN torrents_group AS g ON g.ID = t.GroupID ";
if($Details=='all' || $Details=='day') {
if (!$TopTorrentsActiveLastDay = $Cache->get_value('top10tor_day_'.$Limit.$WhereSum)) {
$DayAgo = time_minus(86400);
$Query = $BaseQuery.' WHERE t.Seeders>0 AND ';
if (!empty($Where)) { $Query .= $Where.' AND '; }
$Query .= "
t.Time>'$DayAgo'
ORDER BY (t.Seeders + t.Leechers) DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsActiveLastDay = $DB->to_array(false, MYSQLI_NUM);
$Cache->cache_value('top10tor_day_'.$Limit.$WhereSum,$TopTorrentsActiveLastDay,3600*2);
}
generate_torrent_table('Most Active Torrents Uploaded in the Past Day', 'day', $TopTorrentsActiveLastDay, $Limit);
}
if($Details=='all' || $Details=='week') {
if (!$TopTorrentsActiveLastWeek = $Cache->get_value('top10tor_week_'.$Limit.$WhereSum)) {
$WeekAgo = time_minus(604800);
$Query = $BaseQuery.' WHERE ';
if (!empty($Where)) { $Query .= $Where.' AND '; }
$Query .= "
t.Time>'$WeekAgo'
ORDER BY (t.Seeders + t.Leechers) DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsActiveLastWeek = $DB->to_array(false, MYSQLI_NUM);
$Cache->cache_value('top10tor_week_'.$Limit.$WhereSum,$TopTorrentsActiveLastWeek,3600*6);
}
generate_torrent_table('Most Active Torrents Uploaded in the Past Week', 'week', $TopTorrentsActiveLastWeek, $Limit);
}
if($Details=='all' || $Details=='month') {
if (!$TopTorrentsActiveLastMonth = $Cache->get_value('top10tor_month_'.$Limit.$WhereSum)) {
$Query = $BaseQuery.' WHERE ';
if (!empty($Where)) { $Query .= $Where.' AND '; }
$Query .= "
t.Time>'".sqltime()."' - INTERVAL 1 MONTH
ORDER BY (t.Seeders + t.Leechers) DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsActiveLastMonth = $DB->to_array(false, MYSQLI_NUM);
$Cache->cache_value('top10tor_month_'.$Limit.$WhereSum,$TopTorrentsActiveLastMonth,3600*6);
}
generate_torrent_table('Most Active Torrents Uploaded in the Past Month', 'month', $TopTorrentsActiveLastMonth, $Limit);
}
if($Details=='all' || $Details=='year') {
if (!$TopTorrentsActiveLastYear = $Cache->get_value('top10tor_year_'.$Limit.$WhereSum)) {
// IMPORTANT NOTE - we use WHERE t.Seeders>200 in order to speed up this query. You should remove it!
$Query = $BaseQuery.' WHERE ';
if ($Details=='all' && !$Filtered) {
$Query .= 't.Seeders>=200 AND ';
if (!empty($Where)) { $Query .= $Where.' AND '; }
}
elseif (!empty($Where)) { $Query .= $Where.' AND '; }
$Query .= "
t.Time>'".sqltime()."' - INTERVAL 1 YEAR
ORDER BY (t.Seeders + t.Leechers) DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsActiveLastYear = $DB->to_array(false, MYSQLI_NUM);
$Cache->cache_value('top10tor_year_'.$Limit.$WhereSum,$TopTorrentsActiveLastYear,3600*6);
}
generate_torrent_table('Most Active Torrents Uploaded in the Past Year', 'year', $TopTorrentsActiveLastYear, $Limit);
}
if($Details=='all' || $Details=='overall') {
if (!$TopTorrentsActiveAllTime = $Cache->get_value('top10tor_overall_'.$Limit.$WhereSum)) {
// IMPORTANT NOTE - we use WHERE t.Seeders>500 in order to speed up this query. You should remove it!
$Query = $BaseQuery;
if ($Details=='all' && !$Filtered) {
$Query .= " WHERE t.Seeders>=500 ";
if (!empty($Where)) { $Query .= ' AND '.$Where; }
}
elseif (!empty($Where)) { $Query .= ' WHERE '.$Where; }
$Query .= "
ORDER BY (t.Seeders + t.Leechers) DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsActiveAllTime = $DB->to_array(false, MYSQLI_NUM);
$Cache->cache_value('top10tor_overall_'.$Limit.$WhereSum,$TopTorrentsActiveAllTime,3600*6);
}
generate_torrent_table('Most Active Torrents of All Time', 'overall', $TopTorrentsActiveAllTime, $Limit);
}
if(($Details=='all' || $Details=='snatched') && !$Filtered) {
if (!$TopTorrentsSnatched = $Cache->get_value('top10tor_snatched_'.$Limit.$WhereSum)) {
$Query = $BaseQuery;
if (!empty($Where)) { $Query .= ' WHERE '.$Where; }
$Query .= "
ORDER BY t.Snatched DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsSnatched = $DB->to_array(false, MYSQLI_NUM);
$Cache->cache_value('top10tor_snatched_'.$Limit.$WhereSum,$TopTorrentsSnatched,3600*6);
}
generate_torrent_table('Most Snatched Torrents', 'snatched', $TopTorrentsSnatched, $Limit);
}
if(($Details=='all' || $Details=='data') && !$Filtered) {
if (!$TopTorrentsTransferred = $Cache->get_value('top10tor_data_'.$Limit.$WhereSum)) {
// IMPORTANT NOTE - we use WHERE t.Snatched>100 in order to speed up this query. You should remove it!
$Query = $BaseQuery;
if ($Details=='all') {
$Query .= " WHERE t.Snatched>=100 ";
if (!empty($Where)) { $Query .= ' AND '.$Where; }
}
$Query .= "
ORDER BY Data DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsTransferred = $DB->to_array(false, MYSQLI_NUM);
$Cache->cache_value('top10tor_data_'.$Limit.$WhereSum,$TopTorrentsTransferred,3600*6);
}
generate_torrent_table('Most Data Transferred Torrents', 'data', $TopTorrentsTransferred, $Limit);
}
if(($Details=='all' || $Details=='seeded') && !$Filtered) {
$TopTorrentsSeeded = $Cache->get_value('top10tor_seeded_'.$Limit.$WhereSum);
if ($TopTorrentsSeeded === FALSE) {
$Query = $BaseQuery;
if (!empty($Where)) { $Query .= ' WHERE '.$Where; }
$Query .= "
ORDER BY t.Seeders DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsSeeded = $DB->to_array(false, MYSQLI_NUM);
$Cache->cache_value('top10tor_seeded_'.$Limit.$WhereSum,$TopTorrentsSeeded,3600*6);
}
generate_torrent_table('Best Seeded Torrents', 'seeded', $TopTorrentsSeeded, $Limit);
}
?>
show_footer();
// generate a table based on data from most recent query to $DB
function generate_torrent_table($Caption, $Tag, $Details, $Limit) {
global $LoggedUser,$Categories,$Debug,$ReleaseTypes;
?>