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.4KB

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