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.

badges.php 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. declare(strict_types=1);
  3. $ENV = ENV::go();
  4. $GiB = 1024*1024*1024;
  5. $ModifiedIDs = [];
  6. // Download badges
  7. foreach ($ENV->AUTOMATED_BADGE_IDS->DL as $DL => $Badge) {
  8. $DB->query("
  9. SELECT ID
  10. FROM users_main
  11. WHERE Downloaded >= ".($DL*$GiB)."
  12. AND ID NOT IN (SELECT UserID FROM users_badges WHERE BadgeID = $Badge)");
  13. if ($DB->has_results()) {
  14. $IDs = $DB->collect('ID');
  15. foreach ($IDs as $ID) {
  16. if (Badges::award_badge($ID, $Badge)) {
  17. Misc::send_pm($ID, 0, 'You have received a badge!', "You have received a badge for downloading ".$DL."GiB of data.\n\nIt can be enabled from your user settings.");
  18. }
  19. }
  20. $ModifiedIDs = array_merge($ModifiedIDs, $IDs);
  21. }
  22. }
  23. // Upload badges
  24. foreach ($ENV->AUTOMATED_BADGE_IDS->UL as $UL => $Badge) {
  25. $DB->query("
  26. SELECT ID
  27. FROM users_main
  28. WHERE Uploaded >= ".($UL*$GiB)."
  29. AND ID NOT IN (SELECT UserID FROM users_badges WHERE BadgeID = $Badge)");
  30. if ($DB->has_results()) {
  31. $IDs = $DB->collect('ID');
  32. foreach ($IDs as $ID) {
  33. if (Badges::award_badge($ID, $Badge)) {
  34. Misc::send_pm($ID, 0, 'You have received a badge!', "You have received a badge for uploading ".$UL."GiB of data.\n\nIt can be enabled from your user settings.");
  35. }
  36. }
  37. $ModifiedIDs = array_merge($ModifiedIDs, $IDs);
  38. }
  39. }
  40. // Tag badges
  41. /*
  42. foreach ($ENV->AUTOMATED_BADGE_IDS->Tags as $Tag => $Badge) {
  43. $DB->query("
  44. SELECT DISTINCT x.uid
  45. FROM xbt_snatched AS x
  46. JOIN torrents AS t ON t.ID = x.fid
  47. JOIN torrents_group AS tg ON t.GroupID = tg.ID
  48. WHERE tg.TagList LIKE '%" . $Tag . "%'");
  49. if ($DB->has_results()) {
  50. $IDs = $DB->collect('uid');
  51. foreach ($IDs as $ID) {
  52. if (Badges::award_badge($ID, $Badge)) {
  53. Misc::send_pm($ID, 0, 'You have recieved a badge!', "You have received a badge for mysterious reasons.\n\nIt can be enabled from your user settings.");
  54. }
  55. }
  56. $ModifiedIDs = array_merge($ModifiedIDs, $IDs);
  57. }
  58. }
  59. */
  60. foreach (array_unique($ModifiedIDs) as $ID) {
  61. $Cache->delete_value('user_badges_'.$ID);
  62. }