Gazelle/sections/top10/users.php

166 lines
5.8 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
// error out on invalid requests (before caching)
2013-05-01 08:00:16 +00:00
if (isset($_GET['details'])) {
if (in_array($_GET['details'],array('ul','dl','numul','uls','dls'))) {
2011-03-28 14:21:28 +00:00
$Details = $_GET['details'];
} else {
error(404);
}
} else {
$Details = 'all';
}
2012-10-11 08:00:15 +00:00
View::show_header('Top 10 Users');
2011-03-28 14:21:28 +00:00
?>
<div class="thin">
2012-08-19 08:00:19 +00:00
<div class="header">
<h2>Top 10 Users</h2>
2013-09-09 08:00:52 +00:00
<? Top10View::render_linkbox("users"); ?>
2011-03-28 14:21:28 +00:00
</div>
<?
// defaults to 10 (duh)
$Limit = isset($_GET['limit']) ? intval($_GET['limit']) : 10;
$Limit = in_array($Limit, array(10,100,250)) ? $Limit : 10;
2013-05-01 08:00:16 +00:00
$BaseQuery = "
SELECT
u.ID,
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-03-28 14:21:28 +00:00
FROM users_main AS u
2013-05-01 08:00:16 +00:00
JOIN users_info AS ui ON ui.UserID = u.ID
LEFT JOIN torrents AS t ON t.UserID=u.ID
2011-03-28 14:21:28 +00:00
WHERE u.Enabled='1'
2013-05-01 08:00:16 +00:00
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\"%'))
2011-03-28 14:21:28 +00:00
GROUP BY u.ID";
2013-05-01 08:00:16 +00:00
if ($Details == 'all' || $Details == 'ul') {
2011-03-28 14:21:28 +00:00
if (!$TopUserUploads = $Cache->get_value('topuser_ul_'.$Limit)) {
$DB->query("$BaseQuery ORDER BY u.Uploaded DESC LIMIT $Limit;");
$TopUserUploads = $DB->to_array();
2013-05-01 08:00:16 +00:00
$Cache->cache_value('topuser_ul_'.$Limit,$TopUserUploads, 3600 * 12);
2011-03-28 14:21:28 +00:00
}
generate_user_table('Uploaders', 'ul', $TopUserUploads, $Limit);
}
2013-05-01 08:00:16 +00:00
if ($Details == 'all' || $Details == 'dl') {
2011-03-28 14:21:28 +00:00
if (!$TopUserDownloads = $Cache->get_value('topuser_dl_'.$Limit)) {
$DB->query("$BaseQuery ORDER BY u.Downloaded DESC LIMIT $Limit;");
$TopUserDownloads = $DB->to_array();
2013-05-01 08:00:16 +00:00
$Cache->cache_value('topuser_dl_'.$Limit,$TopUserDownloads, 3600 * 12);
2011-03-28 14:21:28 +00:00
}
generate_user_table('Downloaders', 'dl', $TopUserDownloads, $Limit);
}
2013-02-12 08:00:08 +00:00
2013-05-01 08:00:16 +00:00
if ($Details == 'all' || $Details == 'numul') {
2011-03-28 14:21:28 +00:00
if (!$TopUserNumUploads = $Cache->get_value('topuser_numul_'.$Limit)) {
$DB->query("$BaseQuery ORDER BY NumUploads DESC LIMIT $Limit;");
$TopUserNumUploads = $DB->to_array();
2013-05-01 08:00:16 +00:00
$Cache->cache_value('topuser_numul_'.$Limit,$TopUserNumUploads, 3600 * 12);
2011-03-28 14:21:28 +00:00
}
generate_user_table('Torrents Uploaded', 'numul', $TopUserNumUploads, $Limit);
}
2013-05-01 08:00:16 +00:00
if ($Details == 'all' || $Details == 'uls') {
2011-03-28 14:21:28 +00:00
if (!$TopUserUploadSpeed = $Cache->get_value('topuser_ulspeed_'.$Limit)) {
$DB->query("$BaseQuery ORDER BY UpSpeed DESC LIMIT $Limit;");
$TopUserUploadSpeed = $DB->to_array();
2013-05-01 08:00:16 +00:00
$Cache->cache_value('topuser_ulspeed_'.$Limit,$TopUserUploadSpeed, 3600 * 12);
2011-03-28 14:21:28 +00:00
}
generate_user_table('Fastest Uploaders', 'uls', $TopUserUploadSpeed, $Limit);
}
2013-05-01 08:00:16 +00:00
if ($Details == 'all' || $Details == 'dls') {
2011-03-28 14:21:28 +00:00
if (!$TopUserDownloadSpeed = $Cache->get_value('topuser_dlspeed_'.$Limit)) {
$DB->query("$BaseQuery ORDER BY DownSpeed DESC LIMIT $Limit;");
$TopUserDownloadSpeed = $DB->to_array();
2013-05-01 08:00:16 +00:00
$Cache->cache_value('topuser_dlspeed_'.$Limit,$TopUserDownloadSpeed, 3600 * 12);
2011-03-28 14:21:28 +00:00
}
generate_user_table('Fastest Downloaders', 'dls', $TopUserDownloadSpeed, $Limit);
}
echo '</div>';
2012-10-11 08:00:15 +00:00
View::show_footer();
2011-03-28 14:21:28 +00:00
exit;
// generate a table based on data from most recent query to $DB
function generate_user_table($Caption, $Tag, $Details, $Limit) {
global $Time;
?>
<h3>Top <?=$Limit.' '.$Caption;?>
2013-02-12 08:00:08 +00:00
<small class="top10_quantity_links">
<?
2013-05-01 08:00:16 +00:00
switch ($Limit) {
2012-03-16 08:00:25 +00:00
case 100: ?>
2013-02-09 08:01:01 +00:00
- <a href="top10.php?type=users&amp;details=<?=$Tag?>" class="brackets">Top 10</a>
- <span class="brackets">Top 100</span>
- <a href="top10.php?type=users&amp;limit=250&amp;details=<?=$Tag?>" class="brackets">Top 250</a>
2012-03-16 08:00:25 +00:00
<? break;
case 250: ?>
2013-02-09 08:01:01 +00:00
- <a href="top10.php?type=users&amp;details=<?=$Tag?>" class="brackets">Top 10</a>
- <a href="top10.php?type=users&amp;limit=100&amp;details=<?=$Tag?>" class="brackets">Top 100</a>
- <span class="brackets">Top 250</span>
2012-03-16 08:00:25 +00:00
<? break;
default: ?>
2013-02-09 08:01:01 +00:00
- <span class="brackets">Top 10</span>
- <a href="top10.php?type=users&amp;limit=100&amp;details=<?=$Tag?>" class="brackets">Top 100</a>
- <a href="top10.php?type=users&amp;limit=250&amp;details=<?=$Tag?>" class="brackets">Top 250</a>
2012-03-16 08:00:25 +00:00
<? } ?>
2011-03-28 14:21:28 +00:00
</small>
</h3>
<table class="border">
<tr class="colhead">
<td class="center">Rank</td>
<td>User</td>
2013-03-09 08:00:18 +00:00
<td style="text-align: right;">Uploaded</td>
<td style="text-align: right;">UL speed</td>
<td style="text-align: right;">Downloaded</td>
<td style="text-align: right;">DL speed</td>
<td style="text-align: right;">Uploads</td>
<td style="text-align: right;">Ratio</td>
<td style="text-align: right;">Joined</td>
2011-03-28 14:21:28 +00:00
</tr>
<?
// in the unlikely event that query finds 0 rows...
2013-05-01 08:00:16 +00:00
if (empty($Details)) {
2011-03-28 14:21:28 +00:00
echo '
<tr class="rowb">
<td colspan="9" class="center">
Found no users matching the criteria
</td>
</tr>
</table><br />';
return;
}
$Rank = 0;
2013-05-01 08:00:16 +00:00
foreach ($Details as $Detail) {
2011-03-28 14:21:28 +00:00
$Rank++;
2013-05-01 08:00:16 +00:00
$Highlight = ($Rank % 2 ? 'a' : 'b');
2011-03-28 14:21:28 +00:00
?>
<tr class="row<?=$Highlight?>">
<td class="center"><?=$Rank?></td>
2012-10-11 08:00:15 +00:00
<td><?=Users::format_username($Detail['ID'], false, false, false)?></td>
2013-08-28 23:08:41 +00:00
<td class="number_column"><?=Format::get_size($Detail['Uploaded'])?></td>
<td class="number_column tooltip" title="Upload speed is reported in base 2 in bytes per second, not bits per second."><?=Format::get_size($Detail['UpSpeed'])?>/s</td>
<td class="number_column"><?=Format::get_size($Detail['Downloaded'])?></td>
<td class="number_column tooltip" title="Download speed is reported in base 2 in bytes per second, not bits per second."><?=Format::get_size($Detail['DownSpeed'])?>/s</td>
<td class="number_column"><?=number_format($Detail['NumUploads'])?></td>
<td class="number_column"><?=Format::get_ratio_html($Detail['Uploaded'], $Detail['Downloaded'])?></td>
<td class="number_column"><?=time_diff($Detail['JoinDate'])?></td>
2011-03-28 14:21:28 +00:00
</tr>
2013-08-28 23:08:41 +00:00
<? } ?>
2011-03-28 14:21:28 +00:00
</table><br />
<?
}
?>