Gazelle/sections/requests/takefill.php

210 lines
6.5 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
//******************************************************************************//
//--------------- Fill a request -----------------------------------------------//
$RequestID = $_REQUEST['requestid'];
2013-04-15 08:00:54 +00:00
if (!is_number($RequestID)) {
2011-03-28 14:21:28 +00:00
error(0);
}
authorize();
//VALIDATION
2013-04-15 08:00:54 +00:00
if (!empty($_GET['torrentid']) && is_number($_GET['torrentid'])) {
2011-03-28 14:21:28 +00:00
$TorrentID = $_GET['torrentid'];
} else {
2013-04-15 08:00:54 +00:00
if (empty($_POST['link'])) {
2013-06-11 08:01:24 +00:00
error('You forgot to supply a link to the filling torrent');
2011-03-28 14:21:28 +00:00
} else {
$Link = $_POST['link'];
2013-06-11 08:01:24 +00:00
if (!preg_match('/'.TORRENT_REGEX.'/i', $Link, $Matches)) {
error('Your link didn\'t seem to be a valid torrent link');
2011-03-28 14:21:28 +00:00
} else {
2013-06-11 08:01:24 +00:00
$TorrentID = $Matches[4];
2011-03-28 14:21:28 +00:00
}
}
2013-04-15 08:00:54 +00:00
if (!$TorrentID || !is_number($TorrentID)) {
2011-03-28 14:21:28 +00:00
error(404);
}
}
//Torrent exists, check it's applicable
2013-04-21 08:00:52 +00:00
$DB->query("
2013-05-29 08:00:51 +00:00
SELECT
t.UserID,
2013-04-21 08:00:52 +00:00
t.Time,
tg.ReleaseType,
t.Encoding,
t.Format,
t.Media,
t.HasLog,
t.HasCue,
t.LogScore,
tg.CategoryID,
IF(t.Remastered = '1', t.RemasterCatalogueNumber, tg.CatalogueNumber)
FROM torrents AS t
LEFT JOIN torrents_group AS tg ON t.GroupID=tg.ID
2013-05-29 08:00:51 +00:00
WHERE t.ID = $TorrentID
2013-04-21 08:00:52 +00:00
LIMIT 1");
2011-03-28 14:21:28 +00:00
2013-04-15 08:00:54 +00:00
if ($DB->record_count() < 1) {
2011-03-28 14:21:28 +00:00
error(404);
}
list($UploaderID, $UploadTime, $TorrentReleaseType, $Bitrate, $Format, $Media, $HasLog, $HasCue, $LogScore, $TorrentCategoryID, $TorrentCatalogueNumber) = $DB->next_record();
$FillerID = $LoggedUser['ID'];
$FillerUsername = $LoggedUser['Username'];
2013-04-15 08:00:54 +00:00
if (!empty($_POST['user']) && check_perms('site_moderate_requests')) {
2011-03-28 14:21:28 +00:00
$FillerUsername = $_POST['user'];
$DB->query("SELECT ID FROM users_main WHERE Username LIKE '".db_string($FillerUsername)."'");
2013-04-15 08:00:54 +00:00
if ($DB->record_count() < 1) {
2013-04-21 08:00:52 +00:00
$Err = 'No such user to fill for!';
2011-03-28 14:21:28 +00:00
} else {
list($FillerID) = $DB->next_record();
}
}
2013-04-15 08:00:54 +00:00
if (time_ago($UploadTime) < 3600 && $UploaderID != $FillerID && !check_perms('site_moderate_requests')) {
2013-05-19 08:01:02 +00:00
$Err = 'There is a one hour grace period for new uploads to allow the torrent\'s uploader to fill the request.';
2011-03-28 14:21:28 +00:00
}
2013-04-21 08:00:52 +00:00
$DB->query("
SELECT
2011-08-29 08:00:08 +00:00
Title,
2011-03-28 14:21:28 +00:00
UserID,
TorrentID,
CategoryID,
ReleaseType,
CatalogueNumber,
BitrateList,
FormatList,
MediaList,
2011-08-29 08:00:08 +00:00
LogCue
FROM requests
2011-03-28 14:21:28 +00:00
WHERE ID = ".$RequestID);
2011-08-29 08:00:08 +00:00
list($Title, $RequesterID, $OldTorrentID, $RequestCategoryID, $RequestReleaseType, $RequestCatalogueNumber, $BitrateList, $FormatList, $MediaList, $LogCue) = $DB->next_record();
2011-03-28 14:21:28 +00:00
2013-04-15 08:00:54 +00:00
if (!empty($OldTorrentID)) {
$Err = 'This request has already been filled.';
2011-03-28 14:21:28 +00:00
}
2013-04-15 08:00:54 +00:00
if ($RequestCategoryID != 0 && $TorrentCategoryID != $RequestCategoryID) {
$Err = 'This torrent is of a different category than the request. If the request is actually miscategorized, please contact staff.';
2011-03-28 14:21:28 +00:00
}
$CategoryName = $Categories[$RequestCategoryID - 1];
2013-04-15 08:00:54 +00:00
if ($CategoryName == 'Music') {
2011-03-28 14:21:28 +00:00
//Commenting out as it's causing some issues with some users being unable to fill, unsure what it is, etc
2013-04-15 08:00:54 +00:00
/*if ($RequestCatalogueNumber) {
if ($TorrentCatalogueNumber != $RequestCatalogueNumber) {
$Err = "This request requires the catalogue number $RequestCatalogueNumber";
2011-03-28 14:21:28 +00:00
}
}*/
2013-05-30 08:00:30 +00:00
//WEB has no ripping log. Ditto Vinyl - Actually ditto everything but CD
2013-05-14 08:00:34 +00:00
//$WEBOverride = ((strpos($MediaList, 'WEB') !== false) && $Media == "WEB");
2013-04-15 08:00:54 +00:00
//$VinylOverride = ((strpos($MediaList, 'Vinyl') !== false) && $Media == "Vinyl");
//if ($Format == 'FLAC' && $LogCue && !$WEBOverride && !$VinylOverride) {
if ($Format == 'FLAC' && $LogCue && $Media == 'CD') {
if (strpos($LogCue, 'Log') && !$HasLog) {
$Err = 'This request requires a log.';
2011-03-28 14:21:28 +00:00
}
/*
* Removed due to rule 2.2.15.6 rendering some requests unfillable
*/
2013-04-15 08:00:54 +00:00
//if (strpos($LogCue, "Cue") && !$HasCue) {
2012-09-09 08:00:26 +00:00
// $Err = "This request requires a cue.";
2011-03-28 14:21:28 +00:00
//}
2013-02-19 08:00:30 +00:00
2013-04-15 08:00:54 +00:00
if (strpos($LogCue, '%')) {
preg_match('/\d+/', $LogCue, $Matches);
if ((int) $LogScore < (int) $Matches[0]) {
$Err = 'This torrent\'s log score is too low.';
2011-03-28 14:21:28 +00:00
}
}
}
2011-09-16 08:00:13 +00:00
2013-04-15 08:00:54 +00:00
if ($BitrateList === 'Other') {
if ($Bitrate === 'Lossless' || $Bitrate === 'APS (VBR)' || $Bitrate === 'V2 (VBR)' || $Bitrate === 'V1 (VBR)' || $Bitrate === '256' || $Bitrate === 'APX (VBR)' || $Bitrate === 'V0 (VBR)' || $Bitrate === 'q8.x (VBR)' || $Bitrate === '320' || $Bitrate === '24bit Lossless')
$Err = "$Bitrate is not an allowed bitrate for this request.";
} elseif ($BitrateList && $BitrateList != 'Any') {
if (strpos($BitrateList, $Bitrate) === false) {
$Err = "$Bitrate is not an allowed bitrate for this request.";
2011-03-28 14:21:28 +00:00
}
}
2013-04-15 08:00:54 +00:00
if ($FormatList && $FormatList != "Any") {
if (strpos($FormatList, $Format) === false) {
$Err = "$Format is not an allowed format for this request.";
2011-03-28 14:21:28 +00:00
}
}
2013-04-15 08:00:54 +00:00
if ($MediaList && $MediaList != "Any") {
if (strpos($MediaList, $Media) === false) {
$Err = "$Media is not allowed media for this request.";
2011-03-28 14:21:28 +00:00
}
}
}
// Fill request
2013-04-15 08:00:54 +00:00
if (!empty($Err)) {
2011-03-28 14:21:28 +00:00
error($Err);
}
//We're all good! Fill!
2013-04-21 08:00:52 +00:00
$DB->query("
UPDATE requests
SET FillerID = $FillerID,
TorrentID = $TorrentID,
TimeFilled = '".sqltime()."'
WHERE ID = $RequestID");
2011-03-28 14:21:28 +00:00
2013-04-15 08:00:54 +00:00
if ($CategoryName == 'Music') {
2013-05-13 08:00:33 +00:00
$ArtistForm = Requests::get_artists($RequestID);
2012-10-11 08:00:15 +00:00
$ArtistName = Artists::display_artists($ArtistForm, false, true);
2011-03-28 14:21:28 +00:00
$FullName = $ArtistName.$Title;
} else {
$FullName = $Title;
}
2013-04-15 08:00:54 +00:00
$DB->query("SELECT UserID FROM requests_votes WHERE RequestID = $RequestID");
2011-03-28 14:21:28 +00:00
$UserIDs = $DB->to_array();
foreach ($UserIDs as $User) {
list($VoterID) = $User;
2013-06-15 08:00:45 +00:00
Misc::send_pm($VoterID, 0, "The request \"$FullName\" has been filled", 'One of your requests&#8202;&mdash;&#8202;[url=https://'.SSL_SITE_URL.'/requests.php?action=view&amp;id='.$RequestID.']'.$FullName.'[/url]&#8202;&mdash;&#8202;has been filled. You can view it here: [url]https://'.SSL_SITE_URL.'/torrents.php?torrentid='.$TorrentID.'[/url]');
2011-03-28 14:21:28 +00:00
}
2013-05-13 08:00:33 +00:00
$RequestVotes = Requests::get_votes_array($RequestID);
2013-05-19 08:01:02 +00:00
Misc::write_log("Request $RequestID ($FullName) was filled by user $FillerID ($FillerUsername) with the torrent $TorrentID for a ".Format::get_size($RequestVotes['TotalBounty']).' bounty.');
2011-03-28 14:21:28 +00:00
// Give bounty
2013-05-14 08:00:34 +00:00
$DB->query("
UPDATE users_main
SET Uploaded = (Uploaded + ".$RequestVotes['TotalBounty'].")
WHERE ID = $FillerID");
2011-03-28 14:21:28 +00:00
$Cache->delete_value('user_stats_'.$FillerID);
$Cache->delete_value('request_'.$RequestID);
2012-02-05 08:00:20 +00:00
if ($GroupID) {
$Cache->delete_value('requests_group_'.$GroupID);
}
2011-03-28 14:21:28 +00:00
2013-04-15 08:00:54 +00:00
$DB->query("SELECT ArtistID FROM requests_artists WHERE RequestID = $RequestID");
2011-03-28 14:21:28 +00:00
$ArtistIDs = $DB->to_array();
2013-04-15 08:00:54 +00:00
foreach ($ArtistIDs as $ArtistID) {
$Cache->delete_value("artists_requests_$ArtistID");
2011-03-28 14:21:28 +00:00
}
$SS->UpdateAttributes('requests', array('torrentid','fillerid'), array($RequestID => array((int)$TorrentID,(int)$FillerID)));
2012-10-11 08:00:15 +00:00
Requests::update_sphinx_requests($RequestID);
2011-03-28 14:21:28 +00:00
header('Location: requests.php?action=view&id='.$RequestID);
?>