Gazelle/sections/ajax/top10/users.php

128 lines
3.7 KiB
PHP
Raw Normal View History

2011-09-16 08:00:13 +00:00
<?
2013-04-17 08:00:58 +00:00
if (isset($_GET['details'])) {
if (in_array($_GET['details'],array('ul','dl','numul','uls','dls'))) {
2011-09-16 08:00:13 +00:00
$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;
2013-04-17 08:00:58 +00:00
$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
2011-09-16 08:00:13 +00:00
FROM users_main AS u
2013-04-17 08:00:58 +00:00
JOIN users_info AS ui ON ui.UserID = u.ID
2013-10-30 08:01:19 +00:00
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 ."'
2013-04-17 08:00:58 +00:00
AND (Paranoia IS NULL OR (Paranoia NOT LIKE '%\"uploaded\"%' AND Paranoia NOT LIKE '%\"downloaded\"%'))
2011-09-16 08:00:13 +00:00
GROUP BY u.ID";
$OuterResults = array();
2013-04-17 08:00:58 +00:00
if ($Details == 'all' || $Details == 'ul') {
2013-10-30 08:01:19 +00:00
if (!$TopUserUploads = $Cache->get_value("topuser_ul_$Limit")) {
$DB->query("
$BaseQuery
ORDER BY u.Uploaded DESC
LIMIT $Limit;");
2011-09-16 08:00:13 +00:00
$TopUserUploads = $DB->to_array();
2013-10-30 08:01:19 +00:00
$Cache->cache_value("topuser_ul_$Limit", $TopUserUploads, 3600 * 12);
2011-09-16 08:00:13 +00:00
}
$OuterResults[] = generate_user_json('Uploaders', 'ul', $TopUserUploads, $Limit);
}
2013-04-17 08:00:58 +00:00
if ($Details == 'all' || $Details == 'dl') {
2013-10-30 08:01:19 +00:00
if (!$TopUserDownloads = $Cache->get_value("topuser_dl_$Limit")) {
$DB->query("
$BaseQuery
ORDER BY u.Downloaded DESC
LIMIT $Limit;");
2011-09-16 08:00:13 +00:00
$TopUserDownloads = $DB->to_array();
2013-10-30 08:01:19 +00:00
$Cache->cache_value("topuser_dl_$Limit", $TopUserDownloads, 3600 * 12);
2011-09-16 08:00:13 +00:00
}
$OuterResults[] = generate_user_json('Downloaders', 'dl', $TopUserDownloads, $Limit);
}
2013-04-17 08:00:58 +00:00
if ($Details == 'all' || $Details == 'numul') {
2013-10-30 08:01:19 +00:00
if (!$TopUserNumUploads = $Cache->get_value("topuser_numul_$Limit")) {
$DB->query("
$BaseQuery
ORDER BY NumUploads DESC
LIMIT $Limit;");
2011-09-16 08:00:13 +00:00
$TopUserNumUploads = $DB->to_array();
2013-10-30 08:01:19 +00:00
$Cache->cache_value("topuser_numul_$Limit", $TopUserNumUploads, 3600 * 12);
2011-09-16 08:00:13 +00:00
}
$OuterResults[] = generate_user_json('Torrents Uploaded', 'numul', $TopUserNumUploads, $Limit);
}
2013-04-17 08:00:58 +00:00
if ($Details == 'all' || $Details == 'uls') {
2013-10-30 08:01:19 +00:00
if (!$TopUserUploadSpeed = $Cache->get_value("topuser_ulspeed_$Limit")) {
$DB->query("
$BaseQuery
ORDER BY UpSpeed DESC
LIMIT $Limit;");
2011-09-16 08:00:13 +00:00
$TopUserUploadSpeed = $DB->to_array();
2013-10-30 08:01:19 +00:00
$Cache->cache_value("topuser_ulspeed_$Limit", $TopUserUploadSpeed, 3600 * 12);
2011-09-16 08:00:13 +00:00
}
$OuterResults[] = generate_user_json('Fastest Uploaders', 'uls', $TopUserUploadSpeed, $Limit);
}
2013-04-17 08:00:58 +00:00
if ($Details == 'all' || $Details == 'dls') {
2013-10-30 08:01:19 +00:00
if (!$TopUserDownloadSpeed = $Cache->get_value("topuser_dlspeed_$Limit")) {
$DB->query("
$BaseQuery
ORDER BY DownSpeed DESC
LIMIT $Limit;");
2011-09-16 08:00:13 +00:00
$TopUserDownloadSpeed = $DB->to_array();
2013-10-30 08:01:19 +00:00
$Cache->cache_value("topuser_dlspeed_$Limit", $TopUserDownloadSpeed, 3600 * 12);
2011-09-16 08:00:13 +00:00
}
$OuterResults[] = generate_user_json('Fastest Downloaders', 'dls', $TopUserDownloadSpeed, $Limit);
}
print
2013-04-17 08:00:58 +00:00
json_encode(
array(
'status' => 'success',
'response' => $OuterResults
)
);
2011-09-16 08:00:13 +00:00
function generate_user_json($Caption, $Tag, $Details, $Limit) {
$results = array();
2013-04-24 08:00:23 +00:00
foreach ($Details as $Detail) {
2011-09-16 08:00:13 +00:00
$results[] = array(
2013-10-30 08:01:19 +00:00
'id' => (int)$Detail['ID'],
2011-09-16 08:00:13 +00:00
'username' => $Detail['Username'],
2013-10-30 08:01:19 +00:00
'uploaded' => (float)$Detail['Uploaded'],
'upSpeed' => (float)$Detail['UpSpeed'],
'downloaded' => (float)$Detail['Downloaded'],
'downSpeed' => (float)$Detail['DownSpeed'],
'numUploads' => (int)$Detail['NumUploads'],
2011-09-16 08:00:13 +00:00
'joinDate' => $Detail['JoinDate']
);
}
return array(
'caption' => $Caption,
'tag' => $Tag,
2013-10-30 08:01:19 +00:00
'limit' => (int)$Limit,
2011-09-16 08:00:13 +00:00
'results' => $results
);
}
?>