/** * Will freeleech / neutral leech / normalise a set of torrents * * @param array $TorrentIDs An array of torrent IDs to iterate over * @param int $FreeNeutral 0 = normal, 1 = fl, 2 = nl * @param int $FreeLeechType 0 = Unknown, 1 = Staff picks, 2 = Perma-FL (Toolbox, etc.), 3 = Vanity House */ public static function freeleech_torrents($TorrentIDs, $FreeNeutral = 1, $FreeLeechType = 0) { if (!is_array($TorrentIDs)) { $TorrentIDs = array($TorrentIDs); } $QueryID = G::$DB->get_query_id(); G::$DB->query("\n\t\t\tUPDATE torrents\n\t\t\tSET FreeTorrent = '{$FreeNeutral}', FreeLeechType = '{$FreeLeechType}'\n\t\t\tWHERE ID IN (" . implode(', ', $TorrentIDs) . ')'); G::$DB->query(' SELECT ID, GroupID, info_hash FROM torrents WHERE ID IN (' . implode(', ', $TorrentIDs) . ') ORDER BY GroupID ASC'); $Torrents = G::$DB->to_array(false, MYSQLI_NUM, false); $GroupIDs = G::$DB->collect('GroupID'); G::$DB->set_query_id($QueryID); foreach ($Torrents as $Torrent) { list($TorrentID, $GroupID, $InfoHash) = $Torrent; Tracker::update_tracker('update_torrent', array('info_hash' => rawurlencode($InfoHash), 'freetorrent' => $FreeNeutral)); G::$Cache->delete_value("torrent_download_{$TorrentID}"); Misc::write_log(G::$LoggedUser['Username'] . " marked torrent {$TorrentID} freeleech type {$FreeLeechType}!"); Torrents::write_group_log($GroupID, $TorrentID, G::$LoggedUser['ID'], "marked as freeleech type {$FreeLeechType}!", 0); } foreach ($GroupIDs as $GroupID) { Torrents::update_hash($GroupID); } }
</ul> <input type="submit" value="Confirm" /> </form> </div> </div> <?php View::show_footer(); } else { authorize(); $DB->query("\n\t\tUPDATE torrents\n\t\tSET\tGroupID = '{$GroupID}'\n\t\tWHERE ID = {$TorrentID}"); // Delete old torrent group if it's empty now $DB->query("\n\t\tSELECT COUNT(ID)\n\t\tFROM torrents\n\t\tWHERE GroupID = '{$OldGroupID}'"); list($TorrentsInGroup) = $DB->next_record(); if ($TorrentsInGroup == 0) { // TODO: votes etc! $DB->query("\n\t\t\tUPDATE comments\n\t\t\tSET PageID = '{$GroupID}'\n\t\t\tWHERE Page = 'torrents'\n\t\t\t\tAND PageID = '{$OldGroupID}'"); $Cache->delete_value("torrent_comments_{$GroupID}_catalogue_0"); $Cache->delete_value("torrent_comments_{$GroupID}"); Torrents::delete_group($OldGroupID); } else { Torrents::update_hash($OldGroupID); } Torrents::update_hash($GroupID); Misc::write_log("Torrent {$TorrentID} was edited by " . $LoggedUser['Username']); // TODO: this is probably broken Torrents::write_group_log($GroupID, 0, $LoggedUser['ID'], "merged group {$OldGroupID}", 0); $DB->query("\n\t\tUPDATE group_log\n\t\tSET GroupID = {$GroupID}\n\t\tWHERE GroupID = {$OldGroupID}"); $Cache->delete_value("torrents_details_{$GroupID}"); $Cache->delete_value("torrent_download_{$TorrentID}"); header("Location: torrents.php?id={$GroupID}"); }
<?php authorize(); $GroupID = $_POST['groupid']; $OldGroupID = $GroupID; $NewName = $_POST['name']; if (!$GroupID || !is_number($GroupID)) { error(404); } if (empty($NewName)) { error('Torrent groups must have a name'); } if (!check_perms('torrents_edit')) { error(403); } $DB->query("\n\tSELECT Name\n\tFROM torrents_group\n\tWHERE ID = {$GroupID}"); list($OldName) = $DB->next_record(MYSQLI_NUM, false); $DB->query("\n\tUPDATE torrents_group\n\tSET Name = '" . db_string($NewName) . "'\n\tWHERE ID = '{$GroupID}'"); $Cache->delete_value("torrents_details_{$GroupID}"); Torrents::update_hash($GroupID); Misc::write_log("Torrent Group {$GroupID} ({$OldName}) was renamed to \"{$NewName}\" from \"{$OldName}\" by " . $LoggedUser['Username']); Torrents::write_group_log($GroupID, 0, $LoggedUser['ID'], "renamed to \"{$NewName}\" from \"{$OldName}\"", 0); header("Location: torrents.php?id={$GroupID}");
} // End competiton $DB->query("\n\tSELECT LogScore\n\tFROM torrents\n\tWHERE ID = {$TorrentID}"); list($LogScore) = $DB->next_record(); if ($Properties['Trumpable'] == 1 && $LogScore == 100) { $DB->query("\n\t\tUPDATE torrents\n\t\tSET LogScore = 99\n\t\tWHERE ID = {$TorrentID}"); $Results = array(); $Results[] = 'The original uploader has chosen to allow this log to be deducted one point for using EAC v0.95., -1 point [1]'; $Details = db_string(serialize($Results)); $DB->query("\n\t\tUPDATE torrents_logs_new\n\t\tSET Score = 99, Details = '{$Details}'\n\t\tWHERE TorrentID = {$TorrentID}"); } $DB->query("\n\tSELECT Enabled\n\tFROM users_main\n\tWHERE ID = {$UserID}"); list($Enabled) = $DB->next_record(); if ($Properties['Trumpable'] == 0 && $LogScore == 99 && $Enabled == 1 && strtotime($Time) < 1284422400) { $DB->query("\n\t\tSELECT Log\n\t\tFROM torrents_logs_new\n\t\tWHERE TorrentID = {$TorrentID}"); list($Log) = $DB->next_record(); if (strpos($Log, 'EAC extraction') === 0) { $DB->query("\n\t\t\tUPDATE torrents\n\t\t\tSET LogScore = 100\n\t\t\tWHERE ID = {$TorrentID}"); $DB->query("\n\t\t\tUPDATE torrents_logs_new\n\t\t\tSET Score = 100, Details = ''\n\t\t\tWHERE TorrentID = {$TorrentID}"); } } $DB->query("\n\tSELECT Name\n\tFROM torrents_group\n\tWHERE ID = {$GroupID}"); list($Name) = $DB->next_record(MYSQLI_NUM, false); Misc::write_log("Torrent {$TorrentID} ({$Name}) in group {$GroupID} was edited by " . $LoggedUser['Username'] . " ({$LogDetails})"); // TODO: this is probably broken Torrents::write_group_log($GroupID, $TorrentID, $LoggedUser['ID'], $LogDetails, 0); $Cache->delete_value("torrents_details_{$GroupID}"); $Cache->delete_value("torrent_download_{$TorrentID}"); Torrents::update_hash($GroupID); // All done! header("Location: torrents.php?id={$GroupID}");
if (!strcasecmp($AliasName, $FoundAliasName)) { if ($Redirect) { $AliasID = $Redirect; } break; } } if (!$AliasID) { $AliasName = db_string($AliasName); $DB->query("\n\t\t\t\tINSERT INTO artists_group (Name)\n\t\t\t\tVALUES ('{$AliasName}')"); $ArtistID = $DB->inserted_id(); $DB->query("\n\t\t\t\tINSERT INTO artists_alias (ArtistID, Name)\n\t\t\t\tVALUES ('{$ArtistID}', '{$AliasName}')"); $AliasID = $DB->inserted_id(); } $DB->query("\n\t\t\tSELECT Name\n\t\t\tFROM artists_group\n\t\t\tWHERE ArtistID = {$ArtistID}"); list($ArtistName) = $DB->next_record(MYSQLI_NUM, false); $DB->query("\n\t\t\tINSERT IGNORE INTO torrents_artists\n\t\t\t\t(GroupID, ArtistID, AliasID, Importance, UserID)\n\t\t\tVALUES\n\t\t\t\t('{$GroupID}', '{$ArtistID}', '{$AliasID}', '{$Importance}', '{$UserID}')"); if ($DB->affected_rows()) { $Changed = true; Misc::write_log("Artist {$ArtistID} ({$ArtistName}) was added to the group {$GroupID} ({$GroupName}) as " . $ArtistTypes[$Importance] . ' by user ' . $LoggedUser['ID'] . ' (' . $LoggedUser['Username'] . ')'); Torrents::write_group_log($GroupID, 0, $LoggedUser['ID'], "added artist {$ArtistName} as " . $ArtistTypes[$Importance], 0); } } } if ($Changed) { $Cache->delete_value("torrents_details_{$GroupID}"); $Cache->delete_value("groups_artists_{$GroupID}"); // Delete group artist cache Torrents::update_hash($GroupID); } header('Location: ' . $_SERVER['HTTP_REFERER']);
} if ($Cache->get_value("torrent_{$TorrentID}_lock")) { error('Torrent cannot be deleted because the upload process is not completed yet. Please try again later.'); } $DB->query("\n\tSELECT\n\t\tt.UserID,\n\t\tt.GroupID,\n\t\tt.Size,\n\t\tt.info_hash,\n\t\ttg.Name,\n\t\tag.Name,\n\t\tt.Time,\n\t\tCOUNT(x.uid)\n\tFROM torrents AS t\n\t\tLEFT JOIN torrents_group AS tg ON tg.ID = t.GroupID\n\t\tLEFT JOIN artists_group AS ag ON ag.ArtistID = tg.ArtistID\n\t\tLEFT JOIN xbt_snatched AS x ON x.fid = t.ID\n\tWHERE t.ID = '{$TorrentID}'"); list($UserID, $GroupID, $Size, $InfoHash, $Name, $ArtistName, $Time, $Snatches) = $DB->next_record(MYSQLI_NUM, false); if (($LoggedUser['ID'] != $UserID || time_ago($Time) > 3600 * 24 * 7 || $Snatches > 4) && !check_perms('torrents_delete')) { error(403); } if ($ArtistName) { $Name = "{$ArtistName} - {$Name}"; } if (isset($_SESSION['logged_user']['multi_delete'])) { if ($_SESSION['logged_user']['multi_delete'] >= 3 && !check_perms('torrents_delete_fast')) { error('You have recently deleted 3 torrents. Please contact a staff member if you need to delete more.'); } $_SESSION['logged_user']['multi_delete']++; } else { $_SESSION['logged_user']['multi_delete'] = 1; } $InfoHash = unpack('H*', $InfoHash); Torrents::delete_torrent($TorrentID, $GroupID); Misc::write_log("Torrent {$TorrentID} ({$Name}) (" . number_format($Size / (1024 * 1024), 2) . ' MB) (' . strtoupper($InfoHash[1]) . ') was deleted by ' . $LoggedUser['Username'] . ': ' . $_POST['reason'] . ' ' . $_POST['extra']); Torrents::write_group_log($GroupID, $TorrentID, $LoggedUser['ID'], 'deleted torrent (' . number_format($Size / (1024 * 1024), 2) . ' MB, ' . strtoupper($InfoHash[1]) . ') for reason: ' . $_POST['reason'] . ' ' . $_POST['extra'], 0); View::show_header('Torrent deleted'); ?> <div class="thin"> <h3>Torrent was successfully deleted.</h3> </div> <?php View::show_footer();
$DB->query("\n\t\tSELECT CollageID\n\t\tFROM collages_torrents\n\t\tWHERE GroupID = '{$OldGroupID}'"); // Select all collages that contain edited group while (list($CollageID) = $DB->next_record()) { $DB->query("\n\t\t\tUPDATE IGNORE collages_torrents\n\t\t\tSET GroupID = '{$NewGroupID}'\n\t\t\tWHERE GroupID = '{$OldGroupID}'\n\t\t\t\tAND CollageID = '{$CollageID}'"); // Change collage group ID to new ID $DB->query("\n\t\t\tDELETE FROM collages_torrents\n\t\t\tWHERE GroupID = '{$OldGroupID}'\n\t\t\t\tAND CollageID = '{$CollageID}'"); $Cache->delete_value("collage_{$CollageID}"); } $Cache->delete_value("torrent_collages_{$NewGroupID}"); $Cache->delete_value("torrent_collages_personal_{$NewGroupID}"); // Requests $DB->query("\n\t\tSELECT ID\n\t\tFROM requests\n\t\tWHERE GroupID = '{$OldGroupID}'"); $Requests = $DB->collect('ID'); $DB->query("\n\t\tUPDATE requests\n\t\tSET GroupID = '{$NewGroupID}'\n\t\tWHERE GroupID = '{$OldGroupID}'"); foreach ($Requests as $RequestID) { $Cache->delete_value("request_{$RequestID}"); } $Cache->delete_value('requests_group_' . $NewGroupID); Torrents::delete_group($GroupID); Torrents::write_group_log($NewGroupID, 0, $LoggedUser['ID'], "Merged Group {$GroupID} ({$Name}) to {$NewGroupID} ({$NewName})", 0); $DB->query("\n\t\tUPDATE group_log\n\t\tSET GroupID = {$NewGroupID}\n\t\tWHERE GroupID = {$GroupID}"); $GroupID = $NewGroupID; $DB->query("\n\t\tSELECT ID\n\t\tFROM torrents\n\t\tWHERE GroupID = '{$OldGroupID}'"); while (list($TorrentID) = $DB->next_record()) { $Cache->delete_value("torrent_download_{$TorrentID}"); } $Cache->delete_value("torrents_details_{$GroupID}"); $Cache->delete_value("groups_artists_{$GroupID}"); Torrents::update_hash($GroupID); header("Location: torrents.php?id=" . $GroupID); }
$T['FreeLeechType'] = 0; $LogScore = $HasLog == 1 ? $LogScoreAverage : 0; // Torrent $DB->query("\n\tINSERT INTO torrents\n\t\t(GroupID, UserID, Media, Format, Encoding,\n\t\tRemastered, RemasterYear, RemasterTitle, RemasterRecordLabel, RemasterCatalogueNumber,\n\t\tScene, HasLog, HasCue, info_hash, FileCount, FileList, FilePath,\n\t\tSize, Time, Description, LogScore, FreeTorrent, FreeLeechType)\n\tVALUES\n\t\t({$GroupID}, {$LoggedUser['ID']}, {$T['Media']}, {$T['Format']}, {$T['Encoding']},\n\t\t{$T['Remastered']}, {$T['RemasterYear']}, {$T['RemasterTitle']}, {$T['RemasterRecordLabel']}, {$T['RemasterCatalogueNumber']},\n\t\t{$T['Scene']}, '{$HasLog}', '{$HasCue}', '" . db_string($InfoHash) . "', {$NumFiles}, '{$FileString}', '{$FilePath}',\n\t\t{$TotalSize}, '" . sqltime() . "', {$T['TorrentDescription']}, {$LogScore}, '{$T['FreeLeech']}', '{$T['FreeLeechType']}')"); $Cache->increment('stats_torrent_count'); $TorrentID = $DB->inserted_id(); Tracker::update_tracker('add_torrent', array('id' => $TorrentID, 'info_hash' => rawurlencode($InfoHash), 'freetorrent' => $T['FreeLeech'])); $Debug->set_flag('upload: ocelot updated'); // Prevent deletion of this torrent until the rest of the upload process is done // (expire the key after 10 minutes to prevent locking it for too long in case there's a fatal error below) $Cache->cache_value("torrent_{$TorrentID}_lock", true, 600); //******************************************************************************// //--------------- Write torrent file -------------------------------------------// $DB->query("\n\tINSERT INTO torrents_files (TorrentID, File)\n\tVALUES ({$TorrentID}, '{$TorEnc}')"); Misc::write_log("Torrent {$TorrentID} ({$LogName}) (" . number_format($TotalSize / (1024 * 1024), 2) . ' MB) was uploaded by ' . $LoggedUser['Username']); Torrents::write_group_log($GroupID, $TorrentID, $LoggedUser['ID'], 'uploaded (' . number_format($TotalSize / (1024 * 1024), 2) . ' MB)', 0); Torrents::update_hash($GroupID); $Debug->set_flag('upload: sphinx updated'); if ($Type == 'Music') { include SERVER_ROOT . '/sections/upload/insert_extra_torrents.php'; } //******************************************************************************// //--------------- Add the log scores to the DB ---------------------------------// if (!empty($LogScores) && $HasLog) { $LogQuery = ' INSERT INTO torrents_logs_new (TorrentID, Log, Details, NotEnglish, Score, Revision, Adjusted, AdjustedBy, AdjustmentReason) VALUES ('; foreach ($LogScores as $LogKey => $LogScore) { $LogScores[$LogKey] = "{$TorrentID}, {$LogScore}, 1, 0, 0, NULL"; }
error(404); } if (!check_perms('torrents_edit')) { error(403); } $DB->query("\n\tDELETE FROM torrents_artists\n\tWHERE GroupID = '{$GroupID}'\n\t\tAND ArtistID = '{$ArtistID}'\n\t\tAND Importance = '{$Importance}'"); $DB->query("\n\tSELECT Name\n\tFROM artists_group\n\tWHERE ArtistID = {$ArtistID}"); list($ArtistName) = $DB->next_record(MYSQLI_NUM, false); $DB->query("\n\tSELECT Name\n\tFROM torrents_group\n\tWHERE ID = {$GroupID}"); if (!$DB->has_results()) { error(404); } list($GroupName) = $DB->next_record(MYSQLI_NUM, false); // Get a count of how many groups or requests use this artist ID $DB->query("\n\tSELECT ag.ArtistID\n\tFROM artists_group AS ag\n\t\tLEFT JOIN requests_artists AS ra ON ag.ArtistID = ra.ArtistID\n\tWHERE ra.ArtistID IS NOT NULL\n\t\tAND ag.ArtistID = {$ArtistID}"); $ReqCount = $DB->record_count(); $DB->query("\n\tSELECT ag.ArtistID\n\tFROM artists_group AS ag\n\t\tLEFT JOIN torrents_artists AS ta ON ag.ArtistID = ta.ArtistID\n\tWHERE ta.ArtistID IS NOT NULL\n\t\tAND ag.ArtistID = {$ArtistID}"); $GroupCount = $DB->record_count(); if ($ReqCount + $GroupCount == 0) { // The only group to use this artist Artists::delete_artist($ArtistID); } $Cache->delete_value("torrents_details_{$GroupID}"); // Delete torrent group cache $Cache->delete_value("groups_artists_{$GroupID}"); // Delete group artist cache Misc::write_log('Artist (' . $ArtistTypes[$Importance] . ") {$ArtistID} ({$ArtistName}) was removed from the group {$GroupID} ({$GroupName}) by user " . $LoggedUser['ID'] . ' (' . $LoggedUser['Username'] . ')'); Torrents::write_group_log($GroupID, 0, $LoggedUser['ID'], "removed artist {$ArtistName} (" . $ArtistTypes[$Importance] . ')', 0); Torrents::update_hash($GroupID); $Cache->delete_value("artist_groups_{$ArtistID}"); header('Location: ' . $_SERVER['HTTP_REFERER']);
if (is_number($ArtistID) && is_number($Importance)) { $CleanArtists[] = array($Importance, $ArtistID); $ArtistIDs[] = $ArtistID; } } if (count($CleanArtists) > 0) { $ArtistsString = implode(',', $ArtistIDs); if ($_POST['manager_action'] == 'delete') { $DB->query("\n\t\t\tSELECT Name\n\t\t\tFROM torrents_group\n\t\t\tWHERE ID = '" . $_POST['groupid'] . "'"); list($GroupName) = $DB->next_record(); $DB->query("\n\t\t\tSELECT ArtistID, Name\n\t\t\tFROM artists_group\n\t\t\tWHERE ArtistID IN ({$ArtistsString})"); $ArtistNames = $DB->to_array('ArtistID', MYSQLI_ASSOC, false); foreach ($CleanArtists as $Artist) { list($Importance, $ArtistID) = $Artist; Misc::write_log('Artist (' . $ArtistTypes[$Importance] . ") {$ArtistID} (" . $ArtistNames[$ArtistID]['Name'] . ") was removed from the group " . $_POST['groupid'] . " ({$GroupName}) by user " . $LoggedUser['ID'] . ' (' . $LoggedUser['Username'] . ')'); Torrents::write_group_log($GroupID, 0, $LoggedUser['ID'], "Removed artist " . $ArtistNames[$ArtistID]['Name'] . " (" . $ArtistTypes[$Importance] . ")", 0); $DB->query("\n\t\t\t\tDELETE FROM torrents_artists\n\t\t\t\tWHERE GroupID = '{$GroupID}'\n\t\t\t\t\tAND ArtistID = '{$ArtistID}'\n\t\t\t\t\tAND Importance = '{$Importance}'"); $Cache->delete_value("artist_groups_{$ArtistID}"); } $DB->query("\n\t\t\tSELECT ArtistID\n\t\t\t\tFROM requests_artists\n\t\t\t\tWHERE ArtistID IN ({$ArtistsString})\n\t\t\tUNION\n\t\t\tSELECT ArtistID\n\t\t\t\tFROM torrents_artists\n\t\t\t\tWHERE ArtistID IN ({$ArtistsString})"); $Items = $DB->collect('ArtistID'); $EmptyArtists = array_diff($ArtistIDs, $Items); foreach ($EmptyArtists as $ArtistID) { Artists::delete_artist($ArtistID); } } else { $DB->query("\n\t\t\tUPDATE IGNORE torrents_artists\n\t\t\tSET Importance = '" . $_POST['importance'] . "'\n\t\t\tWHERE GroupID = '{$GroupID}'\n\t\t\t\tAND ArtistID IN ({$ArtistsString})"); } $Cache->delete_value("groups_artists_{$GroupID}"); Torrents::update_hash($GroupID); header("Location: torrents.php?id={$GroupID}");