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

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