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 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. #declare(strict_types=1);
  3. # todo: Go through line by line
  4. if (isset($_GET['details'])) {
  5. if (in_array($_GET['details'], array('ul','dl','numul','uls','dls'))) {
  6. $Details = $_GET['details'];
  7. } else {
  8. echo json_encode(array('status' => 'failure'));
  9. error();
  10. }
  11. } else {
  12. $Details = 'all';
  13. }
  14. // Defaults to 10 (duh)
  15. $Limit = isset($_GET['limit']) ? intval($_GET['limit']) : 10;
  16. $Limit = in_array($Limit, array(10,100,250)) ? $Limit : 10;
  17. $BaseQuery = "
  18. SELECT
  19. u.ID,
  20. u.Username,
  21. ui.JoinDate,
  22. u.Uploaded,
  23. u.Downloaded,
  24. ABS(u.Uploaded-524288000) / (".time()." - UNIX_TIMESTAMP(ui.JoinDate)) AS UpSpeed,
  25. u.Downloaded / (".time()." - UNIX_TIMESTAMP(ui.JoinDate)) AS DownSpeed,
  26. COUNT(t.ID) AS NumUploads
  27. FROM users_main AS u
  28. JOIN users_info AS ui ON ui.UserID = u.ID
  29. LEFT JOIN torrents AS t ON t.UserID = u.ID
  30. WHERE u.Enabled = '1'
  31. AND Uploaded > '". 5 * 1024 * 1024 * 1024 ."'
  32. AND Downloaded > '". 5 * 1024 * 1024 * 1024 ."'
  33. AND (Paranoia IS NULL OR (Paranoia NOT LIKE '%\"uploaded\"%' AND Paranoia NOT LIKE '%\"downloaded\"%'))
  34. GROUP BY u.ID";
  35. $OuterResults = [];
  36. if ($Details == 'all' || $Details == 'ul') {
  37. if (!$TopUserUploads = $Cache->get_value("topuser_ul_$Limit")) {
  38. $DB->query("
  39. $BaseQuery
  40. ORDER BY u.Uploaded DESC
  41. LIMIT $Limit;");
  42. $TopUserUploads = $DB->to_array();
  43. $Cache->cache_value("topuser_ul_$Limit", $TopUserUploads, 3600 * 12);
  44. }
  45. $OuterResults[] = generate_user_json('Uploaders', 'ul', $TopUserUploads, $Limit);
  46. }
  47. if ($Details == 'all' || $Details == 'dl') {
  48. if (!$TopUserDownloads = $Cache->get_value("topuser_dl_$Limit")) {
  49. $DB->query("
  50. $BaseQuery
  51. ORDER BY u.Downloaded DESC
  52. LIMIT $Limit;");
  53. $TopUserDownloads = $DB->to_array();
  54. $Cache->cache_value("topuser_dl_$Limit", $TopUserDownloads, 3600 * 12);
  55. }
  56. $OuterResults[] = generate_user_json('Downloaders', 'dl', $TopUserDownloads, $Limit);
  57. }
  58. if ($Details == 'all' || $Details == 'numul') {
  59. if (!$TopUserNumUploads = $Cache->get_value("topuser_numul_$Limit")) {
  60. $DB->query("
  61. $BaseQuery
  62. ORDER BY NumUploads DESC
  63. LIMIT $Limit;");
  64. $TopUserNumUploads = $DB->to_array();
  65. $Cache->cache_value("topuser_numul_$Limit", $TopUserNumUploads, 3600 * 12);
  66. }
  67. $OuterResults[] = generate_user_json('Torrents Uploaded', 'numul', $TopUserNumUploads, $Limit);
  68. }
  69. if ($Details == 'all' || $Details == 'uls') {
  70. if (!$TopUserUploadSpeed = $Cache->get_value("topuser_ulspeed_$Limit")) {
  71. $DB->query("
  72. $BaseQuery
  73. ORDER BY UpSpeed DESC
  74. LIMIT $Limit;");
  75. $TopUserUploadSpeed = $DB->to_array();
  76. $Cache->cache_value("topuser_ulspeed_$Limit", $TopUserUploadSpeed, 3600 * 12);
  77. }
  78. $OuterResults[] = generate_user_json('Fastest Uploaders', 'uls', $TopUserUploadSpeed, $Limit);
  79. }
  80. if ($Details == 'all' || $Details == 'dls') {
  81. if (!$TopUserDownloadSpeed = $Cache->get_value("topuser_dlspeed_$Limit")) {
  82. $DB->query("
  83. $BaseQuery
  84. ORDER BY DownSpeed DESC
  85. LIMIT $Limit;");
  86. $TopUserDownloadSpeed = $DB->to_array();
  87. $Cache->cache_value("topuser_dlspeed_$Limit", $TopUserDownloadSpeed, 3600 * 12);
  88. }
  89. $OuterResults[] = generate_user_json('Fastest Downloaders', 'dls', $TopUserDownloadSpeed, $Limit);
  90. }
  91. print
  92. json_encode(
  93. array(
  94. 'status' => 'success',
  95. 'response' => $OuterResults
  96. )
  97. );
  98. function generate_user_json($Caption, $Tag, $Details, $Limit)
  99. {
  100. $results = [];
  101. foreach ($Details as $Detail) {
  102. $results[] = array(
  103. 'id' => (int)$Detail['ID'],
  104. 'username' => $Detail['Username'],
  105. 'uploaded' => (float)$Detail['Uploaded'],
  106. 'upSpeed' => (float)$Detail['UpSpeed'],
  107. 'downloaded' => (float)$Detail['Downloaded'],
  108. 'downSpeed' => (float)$Detail['DownSpeed'],
  109. 'numUploads' => (int)$Detail['NumUploads'],
  110. 'joinDate' => $Detail['JoinDate']
  111. );
  112. }
  113. return array(
  114. 'caption' => $Caption,
  115. 'tag' => $Tag,
  116. 'limit' => (int)$Limit,
  117. 'results' => $results
  118. );
  119. }