BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

users.php 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. // Error out on invalid requests (before caching)
  3. if (isset($_GET['details'])) {
  4. if (in_array($_GET['details'], array('ul','dl','numul','uls','dls'))) {
  5. $Details = $_GET['details'];
  6. } else {
  7. error(404);
  8. }
  9. } else {
  10. $Details = 'all';
  11. }
  12. View::show_header('Top 10 Users');
  13. ?>
  14. <div>
  15. <div class="header">
  16. <h2>Top 10 Users</h2>
  17. <?php Top10View::render_linkbox("users"); ?>
  18. </div>
  19. <?php
  20. // Defaults to 10 (duh)
  21. $Limit = isset($_GET['limit']) ? intval($_GET['limit']) : 10;
  22. $Limit = in_array($Limit, array(10,100,250)) ? $Limit : 10;
  23. $BaseQuery = "
  24. SELECT
  25. u.ID,
  26. ui.JoinDate,
  27. u.Uploaded,
  28. u.Downloaded,
  29. ABS(u.Uploaded-524288000) / (".time()." - UNIX_TIMESTAMP(ui.JoinDate)) AS UpSpeed,
  30. u.Downloaded / (".time()." - UNIX_TIMESTAMP(ui.JoinDate)) AS DownSpeed,
  31. COUNT(t.ID) AS NumUploads
  32. FROM users_main AS u
  33. JOIN users_info AS ui ON ui.UserID = u.ID
  34. LEFT JOIN torrents AS t ON t.UserID=u.ID
  35. WHERE u.Enabled='1'
  36. AND Uploaded>='". 500*1024*1024 ."'
  37. AND Downloaded>='". 0 ."'
  38. AND u.ID > 2
  39. AND (Paranoia IS NULL OR (Paranoia NOT LIKE '%\"uploaded\"%' AND Paranoia NOT LIKE '%\"downloaded\"%'))
  40. GROUP BY u.ID";
  41. if ($Details == 'all' || $Details == 'ul') {
  42. if (!$TopUserUploads = $Cache->get_value('topuser_ul_'.$Limit)) {
  43. $DB->query("$BaseQuery ORDER BY u.Uploaded DESC LIMIT $Limit;");
  44. $TopUserUploads = $DB->to_array();
  45. $Cache->cache_value('topuser_ul_'.$Limit, $TopUserUploads, 3600 * 12);
  46. }
  47. generate_user_table('Uploaders', 'ul', $TopUserUploads, $Limit);
  48. }
  49. if ($Details == 'all' || $Details == 'dl') {
  50. if (!$TopUserDownloads = $Cache->get_value('topuser_dl_'.$Limit)) {
  51. $DB->query("$BaseQuery ORDER BY u.Downloaded DESC LIMIT $Limit;");
  52. $TopUserDownloads = $DB->to_array();
  53. $Cache->cache_value('topuser_dl_'.$Limit, $TopUserDownloads, 3600 * 12);
  54. }
  55. generate_user_table('Downloaders', 'dl', $TopUserDownloads, $Limit);
  56. }
  57. if ($Details == 'all' || $Details == 'numul') {
  58. if (!$TopUserNumUploads = $Cache->get_value('topuser_numul_'.$Limit)) {
  59. $DB->query("$BaseQuery ORDER BY NumUploads DESC LIMIT $Limit;");
  60. $TopUserNumUploads = $DB->to_array();
  61. $Cache->cache_value('topuser_numul_'.$Limit, $TopUserNumUploads, 3600 * 12);
  62. }
  63. generate_user_table('Torrents Uploaded', 'numul', $TopUserNumUploads, $Limit);
  64. }
  65. if ($Details == 'all' || $Details == 'uls') {
  66. if (!$TopUserUploadSpeed = $Cache->get_value('topuser_ulspeed_'.$Limit)) {
  67. $DB->query("$BaseQuery ORDER BY UpSpeed DESC LIMIT $Limit;");
  68. $TopUserUploadSpeed = $DB->to_array();
  69. $Cache->cache_value('topuser_ulspeed_'.$Limit, $TopUserUploadSpeed, 3600 * 12);
  70. }
  71. generate_user_table('Fastest Uploaders', 'uls', $TopUserUploadSpeed, $Limit);
  72. }
  73. if ($Details == 'all' || $Details == 'dls') {
  74. if (!$TopUserDownloadSpeed = $Cache->get_value('topuser_dlspeed_'.$Limit)) {
  75. $DB->query("$BaseQuery ORDER BY DownSpeed DESC LIMIT $Limit;");
  76. $TopUserDownloadSpeed = $DB->to_array();
  77. $Cache->cache_value('topuser_dlspeed_'.$Limit, $TopUserDownloadSpeed, 3600 * 12);
  78. }
  79. generate_user_table('Fastest Downloaders', 'dls', $TopUserDownloadSpeed, $Limit);
  80. }
  81. echo '</div>';
  82. View::show_footer();
  83. exit;
  84. // Generate a table based on data from most recent query to $DB
  85. function generate_user_table($Caption, $Tag, $Details, $Limit)
  86. {
  87. global $Time; ?>
  88. <h3>Top <?=$Limit.' '.$Caption; ?>
  89. <small class="top10_quantity_links">
  90. <?php
  91. switch ($Limit) {
  92. case 100: ?>
  93. &ndash; <a href="top10.php?type=users&amp;details=<?=$Tag?>"
  94. class="brackets">Top 10</a>
  95. &ndash; <span class="brackets">Top 100</span>
  96. &ndash; <a
  97. href="top10.php?type=users&amp;limit=250&amp;details=<?=$Tag?>"
  98. class="brackets">Top 250</a>
  99. <?php break;
  100. case 250: ?>
  101. &ndash; <a href="top10.php?type=users&amp;details=<?=$Tag?>"
  102. class="brackets">Top 10</a>
  103. &ndash; <a
  104. href="top10.php?type=users&amp;limit=100&amp;details=<?=$Tag?>"
  105. class="brackets">Top 100</a>
  106. &ndash; <span class="brackets">Top 250</span>
  107. <?php break;
  108. default: ?>
  109. &ndash; <span class="brackets">Top 10</span>
  110. &ndash; <a
  111. href="top10.php?type=users&amp;limit=100&amp;details=<?=$Tag?>"
  112. class="brackets">Top 100</a>
  113. &ndash; <a
  114. href="top10.php?type=users&amp;limit=250&amp;details=<?=$Tag?>"
  115. class="brackets">Top 250</a>
  116. <?php } ?>
  117. </small>
  118. </h3>
  119. <table class="border">
  120. <tr class="colhead">
  121. <td class="center">Rank</td>
  122. <td>User</td>
  123. <td style="text-align: right;">Uploaded</td>
  124. <td style="text-align: right;">UL speed</td>
  125. <td style="text-align: right;">Downloaded</td>
  126. <td style="text-align: right;">DL speed</td>
  127. <td style="text-align: right;">Uploads</td>
  128. <td style="text-align: right;">Ratio</td>
  129. <td style="text-align: right;">Joined</td>
  130. </tr>
  131. <?php
  132. // In the unlikely event that query finds 0 rows...
  133. if (empty($Details)) {
  134. echo '
  135. <tr class="row">
  136. <td colspan="9" class="center">
  137. Found no users matching the criteria
  138. </td>
  139. </tr>
  140. </table><br />';
  141. return;
  142. }
  143. $Rank = 0;
  144. foreach ($Details as $Detail) {
  145. $Rank++; ?>
  146. <tr class="row">
  147. <td class="center"><?=$Rank?>
  148. </td>
  149. <td><?=Users::format_username($Detail['ID'], false, false, false)?>
  150. </td>
  151. <td class="number_column"><?=Format::get_size($Detail['Uploaded'])?>
  152. </td>
  153. <td class="number_column tooltip"
  154. title="Upload speed is reported in base 2 in bytes per second, not bits per second."><?=Format::get_size($Detail['UpSpeed'])?>/s</td>
  155. <td class="number_column"><?=Format::get_size($Detail['Downloaded'])?>
  156. </td>
  157. <td class="number_column tooltip"
  158. title="Download speed is reported in base 2 in bytes per second, not bits per second."><?=Format::get_size($Detail['DownSpeed'])?>/s
  159. </td>
  160. <td class="number_column"><?=number_format($Detail['NumUploads'])?>
  161. </td>
  162. <td class="number_column"><?=Format::get_ratio_html($Detail['Uploaded'], $Detail['Downloaded'])?>
  163. </td>
  164. <td class="number_column"><?=time_diff($Detail['JoinDate'])?>
  165. </td>
  166. </tr>
  167. <?php
  168. } ?>
  169. </table><br />
  170. <?php
  171. }