Empty commit

This commit is contained in:
Git 2011-09-16 08:00:13 +00:00
parent e76769550f
commit c18eb15319
7 changed files with 460 additions and 2 deletions

View File

@ -926,6 +926,19 @@ CREATE TABLE `torrents_group` (
KEY `RevisionID` (`RevisionID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `torrents_groups_log` (
`ID` int(10) NOT NULL AUTO_INCREMENT,
`GroupID` int(10) NOT NULL,
`TorrentID` int(10) NOT NULL DEFAULT '0',
`UserID` int(10) NOT NULL,
`Info` mediumtext,
`Time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`ID`),
KEY `TorrentID` (`TorrentID`),
KEY `GroupID` (`GroupID`),
KEY `UserID` (`UserID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `torrents_logs_new` (
`LogID` int(10) NOT NULL AUTO_INCREMENT,
`TorrentID` int(10) NOT NULL DEFAULT '0',

View File

@ -36,6 +36,9 @@
case 'torrentgroup':
require('torrentgroup.php');
break;
case 'top10':
require(SERVER_ROOT.'/sections/ajax/top10/index.php');
break;
default:
// If they're screwing around with the query string
error(403);

View File

@ -0,0 +1,29 @@
<?
// Already done in /sections/ajax/index.php
//enforce_login();
if(!check_perms('site_top10')){
print json_encode(array('status' => 'failure'));
die();
}
if(empty($_GET['type']) || $_GET['type'] == 'torrents') {
include(SERVER_ROOT.'/sections/ajax/top10/torrents.php');
} else {
switch($_GET['type']) {
case 'users' :
include(SERVER_ROOT.'/sections/ajax/top10/users.php');
break;
case 'tags' :
include(SERVER_ROOT.'/sections/ajax/top10/tags.php');
break;
case 'history' :
include(SERVER_ROOT.'/sections/ajax/top10/history.php');
break;
default :
print json_encode(array('status' => 'failure'));
break;
}
}
?>

View File

@ -0,0 +1,106 @@
<?
authorize();
// error out on invalid requests (before caching)
if(isset($_GET['details'])) {
if(in_array($_GET['details'],array('ut','ur','v'))) {
$Details = $_GET['details'];
} else {
print json_encode(array('status' => 'failure'));
die();
}
} 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;
$OuterResults = array();
if ($Details == 'all' || $Details == 'ut') {
if (!$TopUsedTags = $Cache->get_value('topusedtag_'.$Limit)) {
$DB->query("SELECT
t.ID,
t.Name,
COUNT(tt.GroupID) AS Uses,
SUM(tt.PositiveVotes-1) AS PosVotes,
SUM(tt.NegativeVotes-1) AS NegVotes
FROM tags AS t
JOIN torrents_tags AS tt ON tt.TagID=t.ID
GROUP BY tt.TagID
ORDER BY Uses DESC
LIMIT $Limit");
$TopUsedTags = $DB->to_array();
$Cache->cache_value('topusedtag_'.$Limit,$TopUsedTags,3600*12);
}
$OuterResults[] = generate_tag_json('Most Used Torrent Tags', 'ut', $TopUsedTags, $Limit);
}
if ($Details == 'all' || $Details == 'ur') {
if (!$TopRequestTags = $Cache->get_value('toprequesttag_'.$Limit)) {
$DB->query("SELECT
t.ID,
t.Name,
COUNT(r.RequestID) AS Uses,
'',''
FROM tags AS t
JOIN requests_tags AS r ON r.TagID=t.ID
GROUP BY r.TagID
ORDER BY Uses DESC
LIMIT $Limit");
$TopRequestTags = $DB->to_array();
$Cache->cache_value('toprequesttag_'.$Limit,$TopRequestTags,3600*12);
}
$OuterResults[] = generate_tag_json('Most Used Request Tags', 'ur', $TopRequestTags, $Limit);
}
if ($Details == 'all' || $Details == 'v') {
if (!$TopVotedTags = $Cache->get_value('topvotedtag_'.$Limit)) {
$DB->query("SELECT
t.ID,
t.Name,
COUNT(tt.GroupID) AS Uses,
SUM(tt.PositiveVotes-1) AS PosVotes,
SUM(tt.NegativeVotes-1) AS NegVotes
FROM tags AS t
JOIN torrents_tags AS tt ON tt.TagID=t.ID
GROUP BY tt.TagID
ORDER BY PosVotes DESC
LIMIT $Limit");
$TopVotedTags = $DB->to_array();
$Cache->cache_value('topvotedtag_'.$Limit,$TopVotedTags,3600*12);
}
$OuterResults[] = generate_tag_json('Most Highly Voted Tags', 'v', $TopVotedTags, $Limit);
}
print
json_encode(
array(
'status' => 'success',
'response' => $OuterResults
)
);
function generate_tag_json($Caption, $Tag, $Details, $Limit) {
$results = array();
foreach ($Details as $Detail) {
$results[] = array(
'name' => $Detail['Name'],
'uses' => $Detail['Uses'],
'posVotes' => $Detail['PosVotes'],
'negVotes' => $Detail['NegVotes']
);
}
return array(
'caption' => $Caption,
'tag' => $Tag,
'limit' => $Limit,
'results' => $results
);
}

View File

@ -0,0 +1,190 @@
<?
authorize();
if(isset($_GET['details'])) {
if(in_array($_GET['details'], array('day','week','overall','snatched','data','seeded'))) {
$Details = $_GET['details'];
} else {
print json_encode(array('status' => 'failure'));
die();
}
} 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;
$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
FROM torrents AS t
LEFT JOIN torrents_group AS g ON g.ID = t.GroupID ";
$OuterResults = array();
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();
$Cache->cache_value('top10tor_day_'.$Limit.$WhereSum,$TopTorrentsActiveLastDay,3600*2);
}
$OuterResults[] = generate_torrent_json('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();
$Cache->cache_value('top10tor_week_'.$Limit.$WhereSum,$TopTorrentsActiveLastWeek,3600*6);
}
$OuterResults[] = generate_torrent_json('Most Active Torrents Uploaded in the Past Week', 'week', $TopTorrentsActiveLastWeek, $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 (!empty($Where)) { $Query .= ' WHERE '.$Where; }
elseif ($Details=='all') { $Query .= " WHERE t.Seeders>500 "; }
$Query .= "
ORDER BY (t.Seeders + t.Leechers) DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsActiveAllTime = $DB->to_array();
$Cache->cache_value('top10tor_overall_'.$Limit.$WhereSum,$TopTorrentsActiveAllTime,3600*6);
}
$OuterResults[] = generate_torrent_json('Most Active Torrents of All Time', 'overall', $TopTorrentsActiveAllTime, $Limit);
}
if(($Details == 'all' || $Details == 'snatched') && empty($Where)) {
if (!$TopTorrentsSnatched = $Cache->get_value('top10tor_snatched_'.$Limit.$WhereSum)) {
$Query = $BaseQuery;
$Query .= "
ORDER BY t.Snatched DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsSnatched = $DB->to_array();
$Cache->cache_value('top10tor_snatched_'.$Limit.$WhereSum,$TopTorrentsSnatched,3600*6);
}
$OuterResults[] = generate_torrent_json('Most Snatched Torrents', 'snatched', $TopTorrentsSnatched, $Limit);
}
if(($Details == 'all' || $Details == 'data') && empty($Where)) {
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 "; }
$Query .= "
ORDER BY Data DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsTransferred = $DB->to_array();
$Cache->cache_value('top10tor_data_'.$Limit.$WhereSum,$TopTorrentsTransferred,3600*6);
}
$OuterResults[] = generate_torrent_json('Most Data Transferred Torrents', 'data', $TopTorrentsTransferred, $Limit);
}
if(($Details == 'all' || $Details == 'seeded') && empty($Where)) {
if (!$TopTorrentsSeeded = $Cache->get_value('top10tor_seeded_'.$Limit.$WhereSum)) {
$Query = $BaseQuery."
ORDER BY t.Seeders DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsSeeded = $DB->to_array();
$Cache->cache_value('top10tor_seeded_'.$Limit.$WhereSum,$TopTorrentsSeeded,3600*6);
}
$OuterResults[] = generate_torrent_json('Best Seeded Torrents', 'seeded', $TopTorrentsSeeded, $Limit);
}
print
json_encode(
array(
'status' => 'success',
'response' => $OuterResults
)
);
function generate_torrent_json($Caption, $Tag, $Details, $Limit) {
global $LoggedUser,$Categories;
$results = array();
foreach ($Details as $Detail) {
list($TorrentID,$GroupID,$GroupName,$GroupCategoryID,$TorrentTags,
$Format,$Encoding,$Media,$Scene,$HasLog,$HasCue,$LogScore,$Year,$GroupYear,
$RemasterTitle,$Snatched,$Seeders,$Leechers,$Data) = $Detail;
$Artist = display_artists(get_artist($GroupID), false, true);
$TruncArtist = substr($Artist, 0, strlen($Artist)-3);
$TagList=array();
if($TorrentTags!='') {
$TorrentTags=explode(' ',$TorrentTags);
foreach ($TorrentTags as $TagKey => $TagName) {
$TagName = str_replace('_','.',$TagName);
$TagList[]=$TagName;
}
}
// Append to the existing array.
$results[] = array(
'torrentId' => $TorrentID,
'groupId' => $GroupID,
'artist' => $TruncArtist,
'groupYear' => $GroupYear,
'format' => $Format,
'encoding' => $Encoding,
'hasLog' => $HasLog,
'hasCue' => $HasCue,
'media' => $Media,
'scene' => $Scene,
'year' => $Year,
'tags' => $TagList,
'snatched' => $Snatched,
'seeders' => $Seeders,
'leechers' => $Leechers
);
}
return array(
'caption' => $Caption,
'tag' => $Tag,
'limit' => $Limit,
'results' => $results
);
}
?>

View File

@ -0,0 +1,114 @@
<?
authorize();
if(isset($_GET['details'])) {
if(in_array($_GET['details'],array('ul','dl','numul','uls','dls'))) {
$Details = $_GET['details'];
} else {
print json_encode(array('status' => 'failure'));
die();
}
} 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;
$BaseQuery = "SELECT
u.ID,
u.Username,
ui.JoinDate,
u.Uploaded,
u.Downloaded,
ABS(u.Uploaded-524288000) / (".time()." - UNIX_TIMESTAMP(ui.JoinDate)) AS UpSpeed,
u.Downloaded / (".time()." - UNIX_TIMESTAMP(ui.JoinDate)) AS DownSpeed,
COUNT(t.ID) AS NumUploads
FROM users_main AS u
JOIN users_info AS ui ON ui.UserID = u.ID
LEFT JOIN torrents AS t ON t.UserID=u.ID
WHERE u.Enabled='1'
AND Uploaded>'". 5*1024*1024*1024 ."'
AND Downloaded>'". 5*1024*1024*1024 ."'
AND (Paranoia IS NULL OR (Paranoia NOT LIKE '%\"uploaded\"%' AND Paranoia NOT LIKE '%\"downloaded\"%'))
GROUP BY u.ID";
$OuterResults = array();
if($Details == 'all' || $Details == 'ul') {
if (!$TopUserUploads = $Cache->get_value('topuser_ul_'.$Limit)) {
$DB->query("$BaseQuery ORDER BY u.Uploaded DESC LIMIT $Limit;");
$TopUserUploads = $DB->to_array();
$Cache->cache_value('topuser_ul_'.$Limit,$TopUserUploads,3600*12);
}
$OuterResults[] = generate_user_json('Uploaders', 'ul', $TopUserUploads, $Limit);
}
if($Details == 'all' || $Details == 'dl') {
if (!$TopUserDownloads = $Cache->get_value('topuser_dl_'.$Limit)) {
$DB->query("$BaseQuery ORDER BY u.Downloaded DESC LIMIT $Limit;");
$TopUserDownloads = $DB->to_array();
$Cache->cache_value('topuser_dl_'.$Limit,$TopUserDownloads,3600*12);
}
$OuterResults[] = generate_user_json('Downloaders', 'dl', $TopUserDownloads, $Limit);
}
if($Details == 'all' || $Details == 'numul') {
if (!$TopUserNumUploads = $Cache->get_value('topuser_numul_'.$Limit)) {
$DB->query("$BaseQuery ORDER BY NumUploads DESC LIMIT $Limit;");
$TopUserNumUploads = $DB->to_array();
$Cache->cache_value('topuser_numul_'.$Limit,$TopUserNumUploads,3600*12);
}
$OuterResults[] = generate_user_json('Torrents Uploaded', 'numul', $TopUserNumUploads, $Limit);
}
if($Details == 'all' || $Details == 'uls') {
if (!$TopUserUploadSpeed = $Cache->get_value('topuser_ulspeed_'.$Limit)) {
$DB->query("$BaseQuery ORDER BY UpSpeed DESC LIMIT $Limit;");
$TopUserUploadSpeed = $DB->to_array();
$Cache->cache_value('topuser_ulspeed_'.$Limit,$TopUserUploadSpeed,3600*12);
}
$OuterResults[] = generate_user_json('Fastest Uploaders', 'uls', $TopUserUploadSpeed, $Limit);
}
if($Details == 'all' || $Details == 'dls') {
if (!$TopUserDownloadSpeed = $Cache->get_value('topuser_dlspeed_'.$Limit)) {
$DB->query("$BaseQuery ORDER BY DownSpeed DESC LIMIT $Limit;");
$TopUserDownloadSpeed = $DB->to_array();
$Cache->cache_value('topuser_dlspeed_'.$Limit,$TopUserDownloadSpeed,3600*12);
}
$OuterResults[] = generate_user_json('Fastest Downloaders', 'dls', $TopUserDownloadSpeed, $Limit);
}
print
json_encode(
array(
'status' => 'success',
'response' => $OuterResults
)
);
function generate_user_json($Caption, $Tag, $Details, $Limit) {
$results = array();
foreach($Details as $Details) {
$results[] = array(
'id' => $Detail['ID'],
'username' => $Detail['Username'],
'uploaded' => $Detail['Uploaded'],
'upSpeed' => $Detail['UpSpeed'],
'downloaded' => $Detail['Downloaded'],
'downSpeed' => $Detail['DownSpeed'],
'numUploads' => $Detail['NumUploads'],
'joinDate' => $Detail['JoinDate']
);
}
return array(
'caption' => $Caption,
'tag' => $Tag,
'limit' => $Limit,
'results' => $results
);
}
?>

View File

@ -132,8 +132,11 @@
}
}
}
if($BitrateList && $BitrateList != "Any") {
if ($BitrateList === "Other") {
if ($Bitrate === "Lossless" || $Bitrate === "APS (VBR)" || $Bitrate === "V2 (VBR)" || $Bitrate === "V1 (VBR)" || $Bitrate === "256" || $Bitrate === "APX (VBR)" || $Bitrate === "V0 (VBR)" || $Bitrate === "q8.x (VBR)" || $Bitrate === "320" || $Bitrate === "24bit Lossless")
$Err = $Bitrate." is not allowed bitrate for this request";
} else if($BitrateList && $BitrateList != "Any") {
if(strpos($BitrateList, $Bitrate) === false) {
$Err = $Bitrate." is not an allowed bitrate for this request";
}