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.

freeleechize.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. #declare(strict_types=1);
  3. $Cost = 2000;
  4. if (isset($_POST['torrent'])) {
  5. // Validation
  6. if (!empty($_GET['torrentid']) && is_number($_GET['torrentid'])) {
  7. $TorrentID = $_GET['torrentid'];
  8. } else {
  9. if (empty($_POST['torrent'])) {
  10. error('You forgot to supply a link to the torrent to freeleech');
  11. } else {
  12. $Link = $_POST['torrent'];
  13. if (!preg_match('/'.TORRENT_REGEX.'/i', $Link, $Matches)) {
  14. error('Your link didn\'t seem to be a valid torrent link');
  15. } else {
  16. $TorrentID = $Matches[4];
  17. }
  18. }
  19. if (!$TorrentID || !is_number($TorrentID)) {
  20. error(404);
  21. }
  22. }
  23. $UserID = $LoggedUser['ID'];
  24. // Make sure torrent exists
  25. $DB->prepared_query("
  26. SELECT FreeTorrent, FreeLeechType
  27. FROM torrents
  28. WHERE ID = $TorrentID");
  29. if ($DB->has_results()) {
  30. list($FreeTorrent, $FreeLeechType) = $DB->next_record();
  31. if ($FreeTorrent === 2) {
  32. error('Torrent is already neutral leech.');
  33. } elseif ($FreeTorrent === 1 && $FreeLeechType !== 3) {
  34. error('Torrent is already freeleech for another reason.');
  35. }
  36. } else {
  37. error('Torrent does not exist');
  38. }
  39. $DB->prepared_query("
  40. SELECT BonusPoints
  41. FROM users_main
  42. WHERE ID = $UserID");
  43. if ($DB->has_results()) {
  44. list($Points) = $DB->next_record();
  45. if ($Points >= $Cost) {
  46. $DB->prepared_query("
  47. SELECT TorrentID
  48. FROM shop_freeleeches
  49. WHERE TorrentID = $TorrentID");
  50. if ($DB->has_results()) {
  51. $DB->prepared_query("
  52. UPDATE shop_freeleeches
  53. SET ExpiryTime = ExpiryTime + INTERVAL 1 DAY
  54. WHERE TorrentID = $TorrentID");
  55. } else {
  56. $DB->prepared_query("
  57. INSERT INTO shop_freeleeches
  58. (TorrentID, ExpiryTime)
  59. VALUES($TorrentID, NOW() + INTERVAL 1 DAY)");
  60. Torrents::freeleech_torrents($TorrentID, 1, 3);
  61. }
  62. $DB->prepared_query("
  63. UPDATE users_main
  64. SET BonusPoints = BonusPoints - $Cost
  65. WHERE ID = $UserID");
  66. $DB->prepared_query("
  67. UPDATE users_info
  68. SET AdminComment = CONCAT('".sqltime()." - Made TorrentID $TorrentID freeleech for 24 more hours via the store\n\n', AdminComment)
  69. WHERE UserID = $UserID");
  70. $Cache->delete_value('user_info_heavy_'.$UserID);
  71. $Cache->delete_value('shop_freeleech_list');
  72. } else {
  73. error("Not enough points");
  74. }
  75. }
  76. View::show_header('Store'); ?>
  77. <div>
  78. <h2>Purchase Successful</h2>
  79. <div class="box">
  80. <p>
  81. You purchased 24 hours of freeleech for
  82. <a href="/torrents.php?torrentid=<?= $TorrentID ?>">this
  83. torrent</a>
  84. </p>
  85. <p>
  86. <a href="/store.php">Back to Store</a>
  87. </p>
  88. </div>
  89. </div>
  90. <?php
  91. View::show_footer();
  92. } else {
  93. View::show_header('Store'); ?>
  94. <div>
  95. <div class="box text-align: center;">
  96. <form action="store.php" method="POST">
  97. <input type="hidden" name="item" value="freeleechize">
  98. <strong>
  99. Enter the URL of the torrent you wish to make freeleech for 24 hours:
  100. </strong>
  101. <br />
  102. <input type="text" name="torrent" value="">
  103. <input type="submit">
  104. </form>
  105. <p>
  106. <a href="/store.php">Back to Store</a>
  107. </p>
  108. </div>
  109. </div>
  110. <?php
  111. View::show_footer();
  112. }