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.

community_stats.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. #declare(strict_types=1);
  3. if (!isset($_GET['userid']) || !is_number($_GET['userid'])) {
  4. json_die('failure');
  5. }
  6. $UserID = $_GET['userid'];
  7. $CommStats = array(
  8. 'leeching' => false,
  9. 'seeding' => false,
  10. 'snatched' => false,
  11. 'usnatched' => false,
  12. 'downloaded' => false,
  13. 'udownloaded' => false,
  14. 'seedingperc' => false,
  15. );
  16. $User = Users::user_info($UserID);
  17. function check_paranoia_here($Setting)
  18. {
  19. global $User;
  20. return check_paranoia($Setting, $User['Paranoia'], $User['Class'], $User['ID']);
  21. }
  22. if (check_paranoia_here('seeding+') || check_paranoia_here('leeching+')) {
  23. $DB->query("
  24. SELECT IF(remaining = 0, 'Seeding', 'Leeching') AS Type, COUNT(x.uid)
  25. FROM xbt_files_users AS x
  26. INNER JOIN torrents AS t ON t.ID = x.fid
  27. WHERE x.uid = '$UserID'
  28. AND x.active = 1
  29. GROUP BY Type");
  30. $PeerCount = $DB->to_array(0, MYSQLI_NUM, false);
  31. if (check_paranoia('seeding+')) {
  32. $Seeding = isset($PeerCount['Seeding']) ? $PeerCount['Seeding'][1] : 0;
  33. $CommStats['seeding'] = number_format($Seeding);
  34. }
  35. if (check_paranoia('leeching+')) {
  36. $CommStats['leeching'] = isset($PeerCount['Leeching']) ? number_format($PeerCount['Leeching'][1]) : 0;
  37. }
  38. }
  39. if (check_paranoia_here('snatched+')) {
  40. $DB->query("
  41. SELECT COUNT(x.uid), COUNT(DISTINCT x.fid)
  42. FROM xbt_snatched AS x
  43. INNER JOIN torrents AS t ON t.ID = x.fid
  44. WHERE x.uid = '$UserID'");
  45. list($Snatched, $UniqueSnatched) = $DB->next_record(MYSQLI_NUM, false);
  46. $CommStats['snatched'] = number_format($Snatched);
  47. if (check_perms('site_view_torrent_snatchlist', $User['Class'])) {
  48. $CommStats['usnatched'] = number_format($UniqueSnatched);
  49. }
  50. if (check_paranoia_here('seeding+') && check_paranoia_here('snatched+') && $UniqueSnatched > 0) {
  51. $CommStats['seedingperc'] = 100 * min(1, round($Seeding / $UniqueSnatched, 2));
  52. }
  53. }
  54. if (check_perms('site_view_torrent_snatchlist', $Class)) {
  55. $DB->query("
  56. SELECT COUNT(ud.UserID), COUNT(DISTINCT ud.TorrentID)
  57. FROM users_downloads AS ud
  58. JOIN torrents AS t ON t.ID = ud.TorrentID
  59. WHERE ud.UserID = '$UserID'");
  60. list($NumDownloads, $UniqueDownloads) = $DB->next_record(MYSQLI_NUM, false);
  61. $CommStats['downloaded'] = number_format($NumDownloads);
  62. $CommStats['udownloaded'] = number_format($UniqueDownloads);
  63. }
  64. json_die('success', $CommStats);