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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. if ($RequestCatalogueNumber) {
  80. if (str_replace('-', '', strtolower($TorrentCatalogueNumber)) !== str_replace('-', '', strtolower($RequestCatalogueNumber))) {
  81. $Err = "This request requires the catalogue number $RequestCatalogueNumber";
  82. }
  83. }
  84. if ($RequestDLSiteID) {
  85. if (strtolower($TorrentDLSiteID) !== strtolower($RequestDLSiteID)) {
  86. $Err = "This request requires DLSite ID $RequestDLSiteID";
  87. }
  88. }
  89. }
  90. // Fill request
  91. if (!empty($Err)) {
  92. error($Err);
  93. }
  94. //We're all good! Fill!
  95. $DB->query("
  96. UPDATE requests
  97. SET FillerID = $FillerID,
  98. TorrentID = $TorrentID,
  99. TimeFilled = '".sqltime()."'
  100. WHERE ID = $RequestID");
  101. if ($CategoryName != 'Other') {
  102. $ArtistForm = Requests::get_artists($RequestID);
  103. $ArtistName = Artists::display_artists($ArtistForm, false, true);
  104. $FullName = $ArtistName.$Title;
  105. } else {
  106. $FullName = $Title;
  107. }
  108. $DB->query("
  109. SELECT UserID
  110. FROM requests_votes
  111. WHERE RequestID = $RequestID");
  112. $UserIDs = $DB->to_array();
  113. foreach ($UserIDs as $User) {
  114. list($VoterID) = $User;
  115. 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]');
  116. }
  117. if ($UploaderID != $FillerID) {
  118. 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]');
  119. }
  120. $RequestVotes = Requests::get_votes_array($RequestID);
  121. Misc::write_log("Request $RequestID ($FullName) was filled by user $FillerID ($FillerUsername) with the torrent $TorrentID for a ".Format::get_size($RequestVotes['TotalBounty']).' bounty.');
  122. // Give bounty
  123. $DB->query("
  124. UPDATE users_main
  125. SET Uploaded = (Uploaded + ".intval($RequestVotes['TotalBounty']*(1/4)).")
  126. WHERE ID = $FillerID");
  127. $DB->query("
  128. UPDATE users_main
  129. SET Uploaded = (Uploaded + ".intval($RequestVotes['TotalBounty']*(3/4)).")
  130. WHERE ID = $UploaderID");
  131. $Cache->delete_value("user_stats_$FillerID");
  132. $Cache->delete_value("request_$RequestID");
  133. if (isset($GroupID)) {
  134. $Cache->delete_value("requests_group_$GroupID");
  135. }
  136. $DB->query("
  137. SELECT ArtistID
  138. FROM requests_artists
  139. WHERE RequestID = $RequestID");
  140. $ArtistIDs = $DB->to_array();
  141. foreach ($ArtistIDs as $ArtistID) {
  142. $Cache->delete_value("artists_requests_".$ArtistID[0]);
  143. }
  144. Requests::update_sphinx_requests($RequestID);
  145. $SphQL = new SphinxqlQuery();
  146. $SphQL->raw_query("UPDATE requests, requests_delta SET torrentid = $TorrentID, fillerid = $FillerID WHERE id = $RequestID", false);
  147. header("Location: requests.php?action=view&id=$RequestID");
  148. ?>