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

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