Oppaitime'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.

take_fill.php 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?
  2. //******************************************************************************//
  3. //--------------- Fill a request -----------------------------------------------//
  4. $RequestID = $_REQUEST['requestid'];
  5. if (!is_number($RequestID)) {
  6. error(0);
  7. }
  8. authorize();
  9. //VALIDATION
  10. if (!empty($_GET['torrentid']) && is_number($_GET['torrentid'])) {
  11. $TorrentID = $_GET['torrentid'];
  12. } else {
  13. if (empty($_POST['link'])) {
  14. error('You forgot to supply a link to the filling torrent');
  15. } else {
  16. $Link = $_POST['link'];
  17. if (!preg_match('/'.TORRENT_REGEX.'/i', $Link, $Matches)) {
  18. error('Your link didn\'t seem to be a valid torrent link');
  19. } else {
  20. $TorrentID = $Matches[4];
  21. }
  22. }
  23. if (!$TorrentID || !is_number($TorrentID)) {
  24. error(404);
  25. }
  26. }
  27. //Torrent exists, check it's applicable
  28. $DB->query("
  29. SELECT
  30. t.UserID,
  31. t.Time,
  32. tg.CategoryID,
  33. tg.CatalogueNumber,
  34. tg.DLSiteID
  35. FROM torrents AS t
  36. LEFT JOIN torrents_group AS tg ON t.GroupID = tg.ID
  37. WHERE t.ID = $TorrentID
  38. LIMIT 1");
  39. if (!$DB->has_results()) {
  40. error(404);
  41. }
  42. list($UploaderID, $UploadTime, $TorrentCategoryID, $TorrentCatalogueNumber, $TorrentDLSiteID) = $DB->next_record();
  43. $FillerID = $LoggedUser['ID'];
  44. $FillerUsername = $LoggedUser['Username'];
  45. if (!empty($_POST['user']) && check_perms('site_moderate_requests')) {
  46. $FillerUsername = $_POST['user'];
  47. $DB->query("
  48. SELECT ID
  49. FROM users_main
  50. WHERE Username LIKE '".db_string($FillerUsername)."'");
  51. if (!$DB->has_results()) {
  52. $Err = 'No such user to fill for!';
  53. } else {
  54. list($FillerID) = $DB->next_record();
  55. }
  56. }
  57. if (time_ago($UploadTime) < 3600 && $UploaderID !== $FillerID && !check_perms('site_moderate_requests')) {
  58. $Err = 'There is a one hour grace period for new uploads to allow the torrent\'s uploader to fill the request.';
  59. }
  60. $DB->query("
  61. SELECT
  62. Title,
  63. UserID,
  64. TorrentID,
  65. CategoryID,
  66. CatalogueNumber,
  67. DLSiteID
  68. FROM requests
  69. WHERE ID = $RequestID");
  70. list($Title, $RequesterID, $OldTorrentID, $RequestCategoryID, $RequestCatalogueNumber, $RequestDLSiteID) = $DB->next_record();
  71. if (!empty($OldTorrentID)) {
  72. $Err = 'This request has already been filled.';
  73. }
  74. if ($RequestCategoryID !== '0' && $TorrentCategoryID !== $RequestCategoryID) {
  75. $Err = 'This torrent is of a different category than the request. If the request is actually miscategorized, please contact staff.';
  76. }
  77. $CategoryName = $Categories[$RequestCategoryID - 1];
  78. if ($CategoryName != 'Other') {
  79. //Commenting out as it's causing some issues with some users being unable to fill, unsure what it is, etc
  80. if ($RequestCatalogueNumber) {
  81. if ($TorrentCatalogueNumber !== $RequestCatalogueNumber) {
  82. $Err = "This request requires the catalogue number $RequestCatalogueNumber";
  83. }
  84. }
  85. if ($RequestDLSiteID) {
  86. if ($TorrentDLSiteID !== $RequestDLSiteID) {
  87. $Err = "This request requires DLSite ID $RequestDLSiteID";
  88. }
  89. }
  90. }
  91. // Fill request
  92. if (!empty($Err)) {
  93. error($Err);
  94. }
  95. //We're all good! Fill!
  96. $DB->query("
  97. UPDATE requests
  98. SET FillerID = $FillerID,
  99. TorrentID = $TorrentID,
  100. TimeFilled = '".sqltime()."'
  101. WHERE ID = $RequestID");
  102. if ($CategoryName != 'Other') {
  103. $ArtistForm = Requests::get_artists($RequestID);
  104. $ArtistName = Artists::display_artists($ArtistForm, false, true);
  105. $FullName = $ArtistName.$Title;
  106. } else {
  107. $FullName = $Title;
  108. }
  109. $DB->query("
  110. SELECT UserID
  111. FROM requests_votes
  112. WHERE RequestID = $RequestID");
  113. $UserIDs = $DB->to_array();
  114. foreach ($UserIDs as $User) {
  115. list($VoterID) = $User;
  116. Misc::send_pm($VoterID, 0, "The request \"$FullName\" has been filled", 'One of your requests&#8202;&mdash;&#8202;[url='.site_url()."requests.php?action=view&amp;id=$RequestID]$FullName".'[/url]&#8202;&mdash;&#8202;has been filled. You can view it here: [url]'.site_url()."torrents.php?torrentid=$TorrentID".'[/url]');
  117. }
  118. if ($UploaderID != $FillerID) {
  119. Misc::send_pm($UploaderID, 0, "The request \"$FullName\" has been filled with your torrent", 'The request&#8202;&mdash;&#8202;[url='.site_url()."requests.php?action=view&amp;id=$RequestID]$FullName".'[/url]&#8202;&mdash;&#8202;has been filled with a torrent you uploaded. You automatically received '.Format::get_size($RequestVotes['TotalBounty']*(3/4)).' of the total bounty. You can view the torrent you uploaded here: [url]'.site_url()."torrents.php?torrentid=$TorrentID".'[/url]');
  120. }
  121. $RequestVotes = Requests::get_votes_array($RequestID);
  122. Misc::write_log("Request $RequestID ($FullName) was filled by user $FillerID ($FillerUsername) with the torrent $TorrentID for a ".Format::get_size($RequestVotes['TotalBounty']).' bounty.');
  123. // Give bounty
  124. $DB->query("
  125. UPDATE users_main
  126. SET Uploaded = (Uploaded + ".intval($RequestVotes['TotalBounty']*(1/4)).")
  127. WHERE ID = $FillerID");
  128. $DB->query("
  129. UPDATE users_main
  130. SET Uploaded = (Uploaded + ".intval($RequestVotes['TotalBounty']*(3/4)).")
  131. WHERE ID = $UploaderID");
  132. $Cache->delete_value("user_stats_$FillerID");
  133. $Cache->delete_value("request_$RequestID");
  134. if (isset($GroupID)) {
  135. $Cache->delete_value("requests_group_$GroupID");
  136. }
  137. $DB->query("
  138. SELECT ArtistID
  139. FROM requests_artists
  140. WHERE RequestID = $RequestID");
  141. $ArtistIDs = $DB->to_array();
  142. foreach ($ArtistIDs as $ArtistID) {
  143. $Cache->delete_value("artists_requests_".$ArtistID[0]);
  144. }
  145. Requests::update_sphinx_requests($RequestID);
  146. $SphQL = new SphinxqlQuery();
  147. $SphQL->raw_query("UPDATE requests, requests_delta SET torrentid = $TorrentID, fillerid = $FillerID WHERE id = $RequestID", false);
  148. header("Location: requests.php?action=view&id=$RequestID");
  149. ?>