Contributing back some bug fixes
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.

bonus_points.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?
  2. //------------------------ Update Bonus Points -------------------------//
  3. function bytesToGiB($bytes) {
  4. if ($bytes > 1048576) {
  5. $GiB = $bytes / 1073741824;
  6. } else {
  7. $GiB = 0;
  8. }
  9. return $GiB;
  10. }
  11. function calculateBP() {
  12. global $DB;
  13. global $Cache;
  14. $getUsers = $DB->query("SELECT DISTINCT(uid) AS uid FROM xbt_files_users");
  15. if ($DB->has_results()) {
  16. $users = array();
  17. while ($result = $DB->next_record()) {
  18. $users[] = $result['uid'];
  19. }
  20. foreach($users as $UserID) {
  21. $DB->query("
  22. SELECT t.Size,
  23. t.Seeders,
  24. (us.SeedTime/60/60/24) AS days
  25. FROM xbt_files_users AS x
  26. LEFT JOIN torrents AS t ON t.ID=x.fid
  27. LEFT JOIN users_seedtime AS us ON x.fid=us.TorrentID AND x.uid=us.UserID
  28. WHERE x.uid = $UserID AND x.active=1");
  29. $totalBP = 0;
  30. while ($torrent = $DB->next_record()) {
  31. $points = bytesToGiB($torrent['Size']) * ( 0.25 + ( 0.6 * log(1+$torrent['days']) / pow($torrent['Seeders'],0.6) ) );
  32. $totalBP = $totalBP + $points;
  33. }
  34. if ($totalBP > 0) {
  35. $DB->query("SELECT BonusPoints, BPDems FROM users_main WHERE ID=$UserID");
  36. list($BonusPoints, $BPDems) = $DB->next_record();
  37. $OldBP = (float) $BonusPoints.'.'.$BPDems;
  38. $NewBP = $OldBP + $totalBP;
  39. $NewDems = $NewBP - floor($NewBP);
  40. $NewBP = $NewBP - $NewDems;
  41. $NewDems = (int) substr($NewDems, 2);
  42. $DB->query("
  43. UPDATE users_main
  44. SET BonusPoints = $NewBP, BPDems = $NewDems
  45. WHERE ID=$UserID");
  46. }
  47. $Cache->delete_value('user_info_heavy_'.$UserID);
  48. }
  49. }
  50. }
  51. calculateBP();
  52. ?>