2011-03-28 14:21:28 +00:00
< ?
//******************************************************************************//
//--------------- Take upload --------------------------------------------------//
2013-02-07 08:00:47 +00:00
// This pages handles the backend of the torrent upload function. It checks //
// the data, and if it all validates, it builds the torrent file, then writes //
2011-03-28 14:21:28 +00:00
// the data to the database and the torrent to the disk. //
//******************************************************************************//
2013-03-13 08:00:43 +00:00
ini_set ( 'upload_max_filesize' , 2097152 );
ini_set ( 'max_file_uploads' , 100 );
2012-05-18 13:35:17 +00:00
define ( MAX_FILENAME_LENGTH , 180 );
2011-03-28 14:21:28 +00:00
include ( SERVER_ROOT . '/classes/class_validate.php' );
include ( SERVER_ROOT . '/classes/class_feed.php' );
include ( SERVER_ROOT . '/classes/class_text.php' );
include ( SERVER_ROOT . '/sections/torrents/functions.php' );
2012-06-18 08:00:14 +00:00
include ( SERVER_ROOT . '/classes/class_file_checker.php' );
2011-03-28 14:21:28 +00:00
enforce_login ();
authorize ();
$Validate = new VALIDATE ;
$Feed = new FEED ;
$Text = new TEXT ;
define ( 'QUERY_EXCEPTION' , true ); // Shut up debugging
//******************************************************************************//
//--------------- Set $Properties array ----------------------------------------//
2013-02-07 08:00:47 +00:00
// This is used if the form doesn't validate, and when the time comes to enter //
2011-03-28 14:21:28 +00:00
// it into the database. //
$Properties = array ();
$Type = $Categories [( int ) $_POST [ 'type' ]];
$TypeID = $_POST [ 'type' ] + 1 ;
2011-09-30 08:00:12 +00:00
$Properties [ 'CategoryName' ] = $Type ;
2011-03-28 14:21:28 +00:00
$Properties [ 'Title' ] = $_POST [ 'title' ];
$Properties [ 'Remastered' ] = ( isset ( $_POST [ 'remaster' ])) ? 1 : 0 ;
2013-04-15 08:00:54 +00:00
if ( $Properties [ 'Remastered' ] || isset ( $_POST [ 'unknown' ])) {
2011-03-28 14:21:28 +00:00
$Properties [ 'UnknownRelease' ] = ( isset ( $_POST [ 'unknown' ])) ? 1 : 0 ;
$Properties [ 'RemasterYear' ] = $_POST [ 'remaster_year' ];
$Properties [ 'RemasterTitle' ] = $_POST [ 'remaster_title' ];
$Properties [ 'RemasterRecordLabel' ] = $_POST [ 'remaster_record_label' ];
$Properties [ 'RemasterCatalogueNumber' ] = $_POST [ 'remaster_catalogue_number' ];
}
2013-04-15 08:00:54 +00:00
if ( ! $Properties [ 'Remastered' ] || $Properties [ 'UnknownRelease' ]) {
2011-03-28 14:21:28 +00:00
$Properties [ 'UnknownRelease' ] = 1 ;
$Properties [ 'RemasterYear' ] = '' ;
$Properties [ 'RemasterTitle' ] = '' ;
$Properties [ 'RemasterRecordLabel' ] = '' ;
$Properties [ 'RemasterCatalogueNumber' ] = '' ;
}
$Properties [ 'Year' ] = $_POST [ 'year' ];
$Properties [ 'RecordLabel' ] = $_POST [ 'record_label' ];
$Properties [ 'CatalogueNumber' ] = $_POST [ 'catalogue_number' ];
$Properties [ 'ReleaseType' ] = $_POST [ 'releasetype' ];
$Properties [ 'Scene' ] = ( isset ( $_POST [ 'scene' ])) ? 1 : 0 ;
$Properties [ 'Format' ] = $_POST [ 'format' ];
$Properties [ 'Media' ] = $_POST [ 'media' ];
$Properties [ 'Bitrate' ] = $_POST [ 'bitrate' ];
$Properties [ 'Encoding' ] = $_POST [ 'bitrate' ];
2012-03-08 08:00:24 +00:00
$Properties [ 'LibraryImage' ] = $_POST [ 'library_image' ];
$Properties [ 'MultiDisc' ] = $_POST [ 'multi_disc' ];
2011-03-28 14:21:28 +00:00
$Properties [ 'TagList' ] = $_POST [ 'tags' ];
$Properties [ 'Image' ] = $_POST [ 'image' ];
$Properties [ 'GroupDescription' ] = trim ( $_POST [ 'album_desc' ]);
2011-08-09 21:03:28 +00:00
if ( $_POST [ 'vanity_house' ] && check_perms ( 'torrents_edit_vanityhouse' ) ) {
$Properties [ 'VanityHouse' ] = 1 ;
} else {
$Properties [ 'VanityHouse' ] = 0 ;
}
2011-03-28 14:21:28 +00:00
$Properties [ 'TorrentDescription' ] = $_POST [ 'release_desc' ];
2013-04-15 08:00:54 +00:00
if ( $_POST [ 'album_desc' ]) {
2011-03-28 14:21:28 +00:00
$Properties [ 'GroupDescription' ] = trim ( $_POST [ 'album_desc' ]);
2013-04-20 08:01:01 +00:00
} elseif ( $_POST [ 'desc' ]) {
2011-03-28 14:21:28 +00:00
$Properties [ 'GroupDescription' ] = trim ( $_POST [ 'desc' ]);
}
$Properties [ 'GroupID' ] = $_POST [ 'groupid' ];
2013-04-15 08:00:54 +00:00
if ( empty ( $_POST [ 'artists' ])) {
2011-03-28 14:21:28 +00:00
$Err = " You didn't enter any artists " ;
} else {
$Artists = $_POST [ 'artists' ];
$Importance = $_POST [ 'importance' ];
}
$RequestID = $_POST [ 'requestid' ];
//******************************************************************************//
//--------------- Validate data in upload form ---------------------------------//
2012-01-27 08:00:19 +00:00
$Validate -> SetFields ( 'type' , '1' , 'inarray' , 'Please select a valid type.' , array ( 'inarray' => array_keys ( $Categories )));
2011-03-28 14:21:28 +00:00
switch ( $Type ) {
case 'Music' :
2013-04-15 08:00:54 +00:00
if ( ! $_POST [ 'groupid' ]) {
2011-03-28 14:21:28 +00:00
$Validate -> SetFields ( 'title' ,
'1' , 'string' , 'Title must be between 1 and 200 characters.' , array ( 'maxlength' => 200 , 'minlength' => 1 ));
$Validate -> SetFields ( 'year' ,
'1' , 'number' , 'The year of the original release must be entered.' , array ( 'length' => 40 ));
$Validate -> SetFields ( 'releasetype' ,
2012-01-27 08:00:19 +00:00
'1' , 'inarray' , 'Please select a valid release type.' , array ( 'inarray' => array_keys ( $ReleaseTypes )));
2011-03-28 14:21:28 +00:00
$Validate -> SetFields ( 'tags' ,
'1' , 'string' , 'You must enter at least one tag. Maximum length is 200 characters.' , array ( 'maxlength' => 200 , 'minlength' => 2 ));
$Validate -> SetFields ( 'record_label' ,
'0' , 'string' , 'Record label must be between 2 and 80 characters.' , array ( 'maxlength' => 80 , 'minlength' => 2 ));
$Validate -> SetFields ( 'catalogue_number' ,
'0' , 'string' , 'Catalogue Number must be between 2 and 80 characters.' , array ( 'maxlength' => 80 , 'minlength' => 2 ));
$Validate -> SetFields ( 'album_desc' ,
'1' , 'string' , 'The album description has a minimum length of 10 characters.' , array ( 'maxlength' => 1000000 , 'minlength' => 10 ));
2011-04-13 15:36:33 +00:00
if ( $Properties [ 'Media' ] == 'CD' && ! $Properties [ 'Remastered' ]) {
$Validate -> SetFields ( 'year' , '1' , 'number' , 'You have selected a year for an album that predates the media you say it was created on.' , array ( 'minlength' => 1982 ));
}
2011-03-28 14:21:28 +00:00
}
2013-04-20 08:01:01 +00:00
if ( $Properties [ 'Remastered' ] && ! $Properties [ 'UnknownRelease' ]) {
2011-03-28 14:21:28 +00:00
$Validate -> SetFields ( 'remaster_year' ,
'1' , 'number' , 'Year of remaster/re-issue must be entered.' );
} else {
$Validate -> SetFields ( 'remaster_year' ,
'0' , 'number' , 'Invalid remaster year.' );
}
2011-04-13 15:36:33 +00:00
if ( $Properties [ 'Media' ] == 'CD' && $Properties [ 'Remastered' ]) {
$Validate -> SetFields ( 'remaster_year' , '1' , 'number' , 'You have selected a year for an album that predates the media you say it was created on.' , array ( 'minlength' => 1982 ));
2011-03-28 14:21:28 +00:00
}
$Validate -> SetFields ( 'remaster_title' ,
'0' , 'string' , 'Remaster title must be between 2 and 80 characters.' , array ( 'maxlength' => 80 , 'minlength' => 2 ));
if ( $Properties [ 'RemasterTitle' ] == 'Original Release' ) {
$Validate -> SetFields ( 'remaster_title' , '0' , 'string' , '"Orginal Release" is not a valid remaster title.' );
}
$Validate -> SetFields ( 'remaster_record_label' ,
'0' , 'string' , 'Remaster record label must be between 2 and 80 characters.' , array ( 'maxlength' => 80 , 'minlength' => 2 ));
$Validate -> SetFields ( 'remaster_catalogue_number' ,
'0' , 'string' , 'Remaster catalogue number must be between 2 and 80 characters.' , array ( 'maxlength' => 80 , 'minlength' => 2 ));
$Validate -> SetFields ( 'format' ,
2012-01-27 08:00:19 +00:00
'1' , 'inarray' , 'Please select a valid format.' , array ( 'inarray' => $Formats ));
2011-03-28 14:21:28 +00:00
// Handle 'other' bitrates
2013-04-15 08:00:54 +00:00
if ( $Properties [ 'Encoding' ] == 'Other' ) {
2011-03-28 14:21:28 +00:00
if ( $Properties [ 'Format' ] == 'FLAC' ) {
$Validate -> SetFields ( 'bitrate' ,
'1' , 'string' , 'FLAC bitrate must be lossless.' , array ( 'regex' => '/Lossless/' ));
}
$Validate -> SetFields ( 'other_bitrate' ,
'1' , 'string' , 'You must enter the other bitrate (max length: 9 characters).' , array ( 'maxlength' => 9 ));
$enc = trim ( $_POST [ 'other_bitrate' ]);
2013-04-15 08:00:54 +00:00
if ( isset ( $_POST [ 'vbr' ])) { $enc .= ' (VBR)' ; }
2011-03-28 14:21:28 +00:00
$Properties [ 'Encoding' ] = $enc ;
$Properties [ 'Bitrate' ] = $enc ;
} else {
$Validate -> SetFields ( 'bitrate' ,
'1' , 'inarray' , 'You must choose a bitrate.' , array ( 'inarray' => $Bitrates ));
}
$Validate -> SetFields ( 'media' ,
2012-01-27 08:00:19 +00:00
'1' , 'inarray' , 'Please select a valid media.' , array ( 'inarray' => $Media ));
2011-03-28 14:21:28 +00:00
$Validate -> SetFields ( 'image' ,
'0' , 'link' , 'The image URL you entered was invalid.' , array ( 'maxlength' => 255 , 'minlength' => 12 ));
$Validate -> SetFields ( 'release_desc' ,
'0' , 'string' , 'The release description has a minimum length of 10 characters.' , array ( 'maxlength' => 1000000 , 'minlength' => 10 ));
$Validate -> SetFields ( 'groupid' , '0' , 'number' , 'Group ID was not numeric' );
break ;
case 'Audiobooks' :
case 'Comedy' :
$Validate -> SetFields ( 'title' ,
'1' , 'string' , 'Title must be between 2 and 200 characters.' , array ( 'maxlength' => 200 , 'minlength' => 2 ));
$Validate -> SetFields ( 'year' ,
'1' , 'number' , 'The year of the release must be entered.' );
$Validate -> SetFields ( 'format' ,
2012-01-27 08:00:19 +00:00
'1' , 'inarray' , 'Please select a valid format.' , array ( 'inarray' => $Formats ));
2011-03-28 14:21:28 +00:00
2013-04-15 08:00:54 +00:00
if ( $Properties [ 'Encoding' ] == 'Other' ) {
2011-03-28 14:21:28 +00:00
$Validate -> SetFields ( 'other_bitrate' ,
'1' , 'string' , 'You must enter the other bitrate (max length: 9 characters).' , array ( 'maxlength' => 9 ));
$enc = trim ( $_POST [ 'other_bitrate' ]);
2013-04-15 08:00:54 +00:00
if ( isset ( $_POST [ 'vbr' ])) { $enc .= ' (VBR)' ; }
2011-03-28 14:21:28 +00:00
$Properties [ 'Encoding' ] = $enc ;
$Properties [ 'Bitrate' ] = $enc ;
} else {
$Validate -> SetFields ( 'bitrate' ,
'1' , 'inarray' , 'You must choose a bitrate.' , array ( 'inarray' => $Bitrates ));
}
$Validate -> SetFields ( 'album_desc' ,
'1' , 'string' , 'You must enter a proper audiobook description.' , array ( 'maxlength' => 1000000 , 'minlength' => 10 ));
$Validate -> SetFields ( 'tags' ,
'1' , 'string' , 'You must enter at least one tag. Maximum length is 200 characters.' , array ( 'maxlength' => 200 , 'minlength' => 2 ));
$Validate -> SetFields ( 'release_desc' ,
'0' , 'string' , 'The release description has a minimum length of 10 characters.' , array ( 'maxlength' => 1000000 , 'minlength' => 10 ));
2012-02-17 08:00:18 +00:00
$Validate -> SetFields ( 'image' ,
'0' , 'link' , 'The image URL you entered was invalid.' , array ( 'maxlength' => 255 , 'minlength' => 12 ));
2011-03-28 14:21:28 +00:00
break ;
case 'Applications' :
case 'Comics' :
case 'E-Books' :
case 'E-Learning Videos' :
$Validate -> SetFields ( 'title' ,
'1' , 'string' , 'Title must be between 2 and 200 characters.' , array ( 'maxlength' => 200 , 'minlength' => 2 ));
$Validate -> SetFields ( 'tags' ,
'1' , 'string' , 'You must enter at least one tag. Maximum length is 200 characters.' , array ( 'maxlength' => 200 , 'minlength' => 2 ));
$Validate -> SetFields ( 'release_desc' ,
'0' , 'string' , 'The release description has a minimum length of 10 characters.' , array ( 'maxlength' => 1000000 , 'minlength' => 10 ));
2013-02-22 08:00:24 +00:00
2012-02-17 08:00:18 +00:00
$Validate -> SetFields ( 'image' ,
'0' , 'link' , 'The image URL you entered was invalid.' , array ( 'maxlength' => 255 , 'minlength' => 12 ));
2011-03-28 14:21:28 +00:00
break ;
}
$Validate -> SetFields ( 'rules' ,
'1' , 'require' , 'Your torrent must abide by the rules.' );
$Err = $Validate -> ValidateForm ( $_POST ); // Validate the form
$File = $_FILES [ 'file_input' ]; // This is our torrent file
$TorrentName = $File [ 'tmp_name' ];
if ( ! is_uploaded_file ( $TorrentName ) || ! filesize ( $TorrentName )) {
$Err = 'No torrent file uploaded, or file is empty.' ;
2013-04-15 08:00:54 +00:00
} elseif ( substr ( strtolower ( $File [ 'name' ]), strlen ( $File [ 'name' ]) - strlen ( '.torrent' )) !== '.torrent' ) {
2011-03-28 14:21:28 +00:00
$Err = " You seem to have put something other than a torrent file into the upload field. ( " . $File [ 'name' ] . " ). " ;
}
2013-04-15 08:00:54 +00:00
if ( $Type == 'Music' ) {
2012-11-14 08:00:19 +00:00
include ( SERVER_ROOT . '/sections/upload/get_extra_torrents.php' );
}
2011-03-28 14:21:28 +00:00
$LogScoreAverage = 0 ;
2013-04-15 08:00:54 +00:00
if ( ! $Err && $Properties [ 'Format' ] == 'FLAC' ) {
2011-03-28 14:21:28 +00:00
foreach ( $_FILES [ 'logfiles' ][ 'name' ] as $FileName ) {
2013-04-15 08:00:54 +00:00
if ( ! empty ( $FileName ) && substr ( strtolower ( $FileName ), strlen ( $FileName ) - strlen ( '.log' )) !== '.log' ) {
$Err = 'You seem to have put something other than an EAC or XLD log file into an upload field. (' . $FileName . ').' ;
2011-03-28 14:21:28 +00:00
break ;
}
}
//There is absolutely no point in checking the type of the file upload as its interpretation of the type is decided by the client.
2013-04-15 08:00:54 +00:00
/* foreach ( $_FILES [ 'logfiles' ][ 'type' ] as $FileType ) {
if ( ! empty ( $FileType ) && $FileType != " text/plain " && $FileType != " text/x-log " && $FileType != " application/octet-stream " && $FileType != " text/richtext " ) {
$Err = " You seem to have put something other than an EAC or XLD log file into an upload field. ( " . $FileType . " ) " ;
break ;
}
}
*/
2011-03-28 14:21:28 +00:00
}
//Multiple artists!
$LogName = '' ;
2013-04-15 08:00:54 +00:00
if ( empty ( $Properties [ 'GroupID' ]) && empty ( $ArtistForm ) && $Type == " Music " ) {
2011-03-28 14:21:28 +00:00
$MainArtistCount = 0 ;
$ArtistNames = array ();
$ArtistForm = array (
1 => array (),
2 => array (),
2011-11-20 08:00:18 +00:00
3 => array (),
4 => array (),
2011-11-22 08:00:17 +00:00
5 => array (),
6 => array ()
2011-03-28 14:21:28 +00:00
);
2013-04-24 08:00:23 +00:00
for ( $i = 0 , $il = count ( $Artists ); $i < $il ; $i ++ ) {
2013-04-15 08:00:54 +00:00
if ( trim ( $Artists [ $i ]) != '' ) {
if ( ! in_array ( $Artists [ $i ], trim ( $ArtistNames ))) {
2012-10-11 08:00:15 +00:00
$ArtistForm [ $Importance [ $i ]][] = array ( 'name' => Artists :: normalise_artist_name ( $Artists [ $i ]));
2013-04-15 08:00:54 +00:00
if ( $Importance [ $i ] == 1 ) {
2011-03-28 14:21:28 +00:00
$MainArtistCount ++ ;
}
$ArtistNames [] = trim ( $Artists [ $i ]);
}
}
}
2013-04-15 08:00:54 +00:00
if ( $MainArtistCount < 1 ) {
$Err = 'Please enter at least one main artist' ;
2011-03-28 14:21:28 +00:00
$ArtistForm = array ();
}
2012-10-11 08:00:15 +00:00
$LogName .= Artists :: display_artists ( $ArtistForm , false , true , false );
2013-04-15 08:00:54 +00:00
} elseif ( $Type == 'Music' && empty ( $ArtistForm )) {
2011-03-28 14:21:28 +00:00
$DB -> query ( " SELECT ta.ArtistID,aa.Name,ta.Importance FROM torrents_artists AS ta JOIN artists_alias AS aa ON ta.AliasID = aa.AliasID WHERE ta.GroupID = " . $Properties [ 'GroupID' ] . " ORDER BY ta.Importance ASC, aa.Name ASC; " );
2013-04-15 08:00:54 +00:00
while ( list ( $ArtistID , $ArtistName , $ArtistImportance ) = $DB -> next_record ( MYSQLI_BOTH , false )) {
2011-03-28 14:21:28 +00:00
$ArtistForm [ $ArtistImportance ][] = array ( 'id' => $ArtistID , 'name' => display_str ( $ArtistName ));
$ArtistsUnescaped [ $ArtistImportance ][] = array ( 'name' => $ArtistName );
}
2012-10-11 08:00:15 +00:00
$LogName .= Artists :: display_artists ( $ArtistsUnescaped , false , true , false );
2011-03-28 14:21:28 +00:00
}
2013-04-15 08:00:54 +00:00
if ( $Err ) { // Show the upload form, with the data the user entered
2011-03-28 14:21:28 +00:00
$UploadForm = $Type ;
include ( SERVER_ROOT . '/sections/upload/upload.php' );
die ();
}
2011-11-22 08:00:17 +00:00
// Strip out amazon's padding
$AmazonReg = '/(http:\/\/ecx.images-amazon.com\/images\/.+)(\._.*_\.jpg)/i' ;
$Matches = array ();
if ( preg_match ( $RegX , $Properties [ 'Image' ], $Matches )) {
$Properties [ 'Image' ] = $Matches [ 1 ] . '.jpg' ;
}
2013-02-25 21:16:55 +00:00
ImageTools :: blacklisted ( $Properties [ 'Image' ]);
2011-11-22 08:00:17 +00:00
2011-03-28 14:21:28 +00:00
//******************************************************************************//
//--------------- Make variables ready for database input ----------------------//
// Shorten and escape $Properties for database input
$T = array ();
foreach ( $Properties as $Key => $Value ) {
$T [ $Key ] = " ' " . db_string ( trim ( $Value )) . " ' " ;
2013-04-15 08:00:54 +00:00
if ( ! $T [ $Key ]) {
2011-03-28 14:21:28 +00:00
$T [ $Key ] = NULL ;
}
}
$SearchText = db_string ( trim ( $Properties [ 'Artist' ]) . ' ' . trim ( $Properties [ 'Title' ]) . ' ' . trim ( $Properties [ 'Year' ]));
//******************************************************************************//
//--------------- Generate torrent file ----------------------------------------//
2013-03-17 08:00:17 +00:00
$Tor = new BencodeTorrent ( $TorrentName , true );
2013-02-25 21:16:55 +00:00
$PublicTorrent = $Tor -> make_private (); // The torrent is now private.
$TorEnc = db_string ( $Tor -> encode ());
$InfoHash = pack ( 'H*' , $Tor -> info_hash ());
2011-03-28 14:21:28 +00:00
2013-02-25 21:16:55 +00:00
$DB -> query ( " SELECT ID FROM torrents WHERE info_hash=' " . db_string ( $InfoHash ) . " ' " );
if ( $DB -> record_count () > 0 ) {
list ( $ID ) = $DB -> next_record ();
$DB -> query ( " SELECT TorrentID FROM torrents_files WHERE TorrentID = " . $ID );
if ( $DB -> record_count () > 0 ) {
$Err = '<a href="torrents.php?torrentid=' . $ID . '">The exact same torrent file already exists on the site!</a>' ;
} else {
// A lost torrent
$DB -> query ( " INSERT INTO torrents_files (TorrentID, File) VALUES ( $ID , ' $TorEnc ') " );
$Err = '<a href="torrents.php?torrentid=' . $ID . '">Thank you for fixing this torrent</a>' ;
}
}
2011-03-28 14:21:28 +00:00
2013-02-25 21:16:55 +00:00
if ( isset ( $Tor -> Dec [ 'encrypted_files' ])) {
2013-02-16 08:00:57 +00:00
$Err = " This torrent contains an encrypted file list which is not supported here " ;
}
2011-03-28 14:21:28 +00:00
// File list and size
list ( $TotalSize , $FileList ) = $Tor -> file_list ();
2013-02-25 21:16:55 +00:00
$NumFiles = count ( $FileList );
$HasLog = 0 ;
$HasCue = 0 ;
2011-03-28 14:21:28 +00:00
$TmpFileList = array ();
2012-12-19 08:00:21 +00:00
$TooLongPaths = array ();
2013-02-25 21:16:55 +00:00
$DirName = isset ( $Tor -> Dec [ 'info' ][ 'files' ]) ? Format :: make_utf8 ( $Tor -> get_name ()) : " " ;
foreach ( $FileList as $File ) {
2011-03-28 14:21:28 +00:00
list ( $Size , $Name ) = $File ;
// add +log to encoding
2013-02-25 21:16:55 +00:00
if ( $T [ 'Encoding' ] == " 'Lossless' " && preg_match ( '/(?<!audiochecker)\.log$/i' , $Name )) {
$HasLog = 1 ;
2011-03-28 14:21:28 +00:00
}
// add +cue to encoding
2013-02-25 21:16:55 +00:00
if ( $T [ 'Encoding' ] == " 'Lossless' " && preg_match ( '/\.cue$/i' , $Name )) {
$HasCue = 1 ;
2011-03-28 14:21:28 +00:00
}
2013-02-25 21:16:55 +00:00
// Check file name and extension against blacklist/whitelist
2012-06-18 08:00:14 +00:00
check_file ( $Type , $Name );
2012-05-18 13:35:17 +00:00
// Make sure the filename is not too long
2013-02-25 21:16:55 +00:00
if ( mb_strlen ( $Name , 'UTF-8' ) + mb_strlen ( $DirName , 'UTF-8' ) + 1 > MAX_FILENAME_LENGTH ) {
2013-03-13 08:00:43 +00:00
$TooLongPaths [] = " $DirName / $Name " ;
2012-05-18 13:35:17 +00:00
}
2013-02-11 08:00:34 +00:00
// Add file info to array
$TmpFileList [] = Torrents :: filelist_format_file ( $File );
2011-03-28 14:21:28 +00:00
}
2013-02-25 21:16:55 +00:00
if ( count ( $TooLongPaths ) > 0 ) {
2013-03-13 08:00:43 +00:00
$Names = implode ( ' <br />' , $TooLongPaths );
$Err = " The torrent contained one or more files with too long a name:<br /> $Names " ;
2012-12-19 08:00:21 +00:00
}
2013-02-25 08:00:45 +00:00
$FilePath = db_string ( $DirName );
2013-02-11 08:00:34 +00:00
$FileString = db_string ( implode ( " \n " , $TmpFileList ));
2013-02-17 08:00:08 +00:00
$Debug -> set_flag ( 'upload: torrent decoded' );
2011-03-28 14:21:28 +00:00
2013-02-25 21:16:55 +00:00
if ( $Type == 'Music' ) {
2012-11-14 08:00:19 +00:00
include ( SERVER_ROOT . '/sections/upload/generate_extra_torrents.php' );
}
2011-03-28 14:21:28 +00:00
2013-02-25 21:16:55 +00:00
if ( ! empty ( $Err )) { // Show the upload form, with the data the user entered
$UploadForm = $Type ;
2011-03-28 14:21:28 +00:00
include ( SERVER_ROOT . '/sections/upload/upload.php' );
die ();
}
//******************************************************************************//
//--------------- Start database stuff -----------------------------------------//
$Body = $Properties [ 'GroupDescription' ];
// Trickery
2013-04-15 08:00:54 +00:00
if ( ! preg_match ( " /^ " . IMAGE_REGEX . " $ /i " , $Properties [ 'Image' ])) { $Properties [ 'Image' ] = '' ; $T [ 'Image' ] = " '' " ; }
2011-03-28 14:21:28 +00:00
2013-04-15 08:00:54 +00:00
if ( $Type == 'Music' ) {
2011-03-28 14:21:28 +00:00
// Does it belong in a group?
2013-04-15 08:00:54 +00:00
if ( $Properties [ 'GroupID' ]) {
2011-03-28 14:21:28 +00:00
$DB -> query ( "
SELECT
2013-04-15 08:00:54 +00:00
tg . id ,
tg . WikiImage ,
tg . WikiBody ,
tg . RevisionID ,
tg . Name ,
tg . Year ,
tg . ReleaseType ,
tg . TagList
2011-03-28 14:21:28 +00:00
FROM torrents_group AS tg
WHERE tg . id = " . $Properties['GroupID'] );
2013-04-15 08:00:54 +00:00
if ( $DB -> record_count () > 0 ) {
2012-08-30 08:00:17 +00:00
// Don't escape tg.Name. It's written directly to the log table
list ( $GroupID , $WikiImage , $WikiBody , $RevisionID , $Properties [ 'Title' ], $Properties [ 'Year' ], $Properties [ 'ReleaseType' ], $Properties [ 'TagList' ]) = $DB -> next_record ( MYSQLI_NUM , array ( 4 ));
2012-08-02 08:00:13 +00:00
$Properties [ 'TagList' ] = str_replace ( array ( " " , " . " , " _ " ), array ( " , " , " . " , " . " ), $Properties [ 'TagList' ]);
2013-04-20 08:01:01 +00:00
if ( ! $Properties [ 'Image' ] && $WikiImage ) {
2011-03-28 14:21:28 +00:00
$Properties [ 'Image' ] = $WikiImage ;
$T [ 'Image' ] = " ' " . db_string ( $WikiImage ) . " ' " ;
}
2013-04-20 08:01:01 +00:00
if ( strlen ( $WikiBody ) > strlen ( $Body )) {
2011-03-28 14:21:28 +00:00
$Body = $WikiBody ;
2013-04-15 08:00:54 +00:00
if ( ! $Properties [ 'Image' ] || $Properties [ 'Image' ] == $WikiImage ) {
2011-03-28 14:21:28 +00:00
$NoRevision = true ;
}
}
2012-10-11 08:00:15 +00:00
$Properties [ 'Artist' ] = Artists :: display_artists ( Artists :: get_artist ( $GroupID ), false , false );
2011-03-28 14:21:28 +00:00
}
}
2013-04-15 08:00:54 +00:00
if ( ! $GroupID ) {
foreach ( $ArtistForm as $Importance => $Artists ) {
foreach ( $Artists as $Num => $Artist ) {
2011-03-28 14:21:28 +00:00
$DB -> query ( "
SELECT
2013-04-15 08:00:54 +00:00
tg . id ,
tg . WikiImage ,
tg . WikiBody ,
tg . RevisionID
2011-03-28 14:21:28 +00:00
FROM torrents_group AS tg
2013-04-15 08:00:54 +00:00
LEFT JOIN torrents_artists AS ta ON ta . GroupID = tg . ID
LEFT JOIN artists_group AS ag ON ta . ArtistID = ag . ArtistID
2012-06-02 08:00:16 +00:00
WHERE ag . Name = '".db_string($Artist[' name '])."'
2013-04-15 08:00:54 +00:00
AND tg . Name = " . $T['Title'] . "
AND tg . ReleaseType = " . $T['ReleaseType'] . "
AND tg . Year = " . $T['Year'] );
2011-03-28 14:21:28 +00:00
2013-04-15 08:00:54 +00:00
if ( $DB -> record_count () > 0 ) {
2011-03-28 14:21:28 +00:00
list ( $GroupID , $WikiImage , $WikiBody , $RevisionID ) = $DB -> next_record ();
2013-04-15 08:00:54 +00:00
if ( ! $Properties [ 'Image' ] && $WikiImage ) {
2011-03-28 14:21:28 +00:00
$Properties [ 'Image' ] = $WikiImage ;
$T [ 'Image' ] = " ' " . db_string ( $WikiImage ) . " ' " ;
}
2013-04-20 08:01:01 +00:00
if ( strlen ( $WikiBody ) > strlen ( $Body )) {
2011-03-28 14:21:28 +00:00
$Body = $WikiBody ;
2013-04-15 08:00:54 +00:00
if ( ! $Properties [ 'Image' ] || $Properties [ 'Image' ] == $WikiImage ) {
2011-03-28 14:21:28 +00:00
$NoRevision = true ;
}
}
2012-10-11 08:00:15 +00:00
$ArtistForm = Artists :: get_artist ( $GroupID );
2011-03-28 14:21:28 +00:00
//This torrent belongs in a group
break ;
} else {
// The album hasn't been uploaded. Try to get the artist ids
$DB -> query ( "
SELECT
2013-04-15 08:00:54 +00:00
aa . ArtistID ,
aa . AliasID ,
aa . Name ,
aa . Redirect
2011-03-28 14:21:28 +00:00
FROM artists_alias AS aa
2012-06-02 08:00:16 +00:00
WHERE aa . Name = '".db_string($Artist[' name '])."' " );
2013-04-15 08:00:54 +00:00
if ( $DB -> record_count () > 0 ) {
while ( list ( $ArtistID , $AliasID , $AliasName , $Redirect ) = $DB -> next_record ( MYSQLI_NUM , false )) {
if ( ! strcasecmp ( $Artist [ 'name' ], $AliasName )) {
if ( $Redirect ) {
2012-05-18 13:35:17 +00:00
$AliasID = $Redirect ;
}
2012-06-13 08:00:16 +00:00
$ArtistForm [ $Importance ][ $Num ] = array ( 'id' => $ArtistID , 'aliasid' => $AliasID , 'name' => $AliasName );
2012-05-18 13:35:17 +00:00
break ;
}
2011-03-28 14:21:28 +00:00
}
}
}
}
}
}
}
//Needs to be here as it isn't set for add format until now
$LogName .= $Properties [ 'Title' ];
//For notifications--take note now whether it's a new group
$IsNewGroup = ! $GroupID ;
//----- Start inserts
2013-04-15 08:00:54 +00:00
if ( ! $GroupID && $Type == 'Music' ) {
2013-03-01 08:00:40 +00:00
//array to store which artists we have added already, to prevent adding an artist twice
$ArtistsAdded = array ();
2013-04-15 08:00:54 +00:00
foreach ( $ArtistForm as $Importance => $Artists ) {
foreach ( $Artists as $Num => $Artist ) {
if ( ! $Artist [ 'id' ]) {
if ( isset ( $ArtistsAdded [ strtolower ( $Artist [ 'name' ])])) {
2013-03-01 08:00:40 +00:00
$ArtistForm [ $Importance ][ $Num ] = $ArtistsAdded [ strtolower ( $Artist [ 'name' ])];
} else {
// Create artist
$DB -> query ( " INSERT INTO artists_group (Name) VALUES (' " . db_string ( $Artist [ 'name' ]) . " ') " );
$ArtistID = $DB -> inserted_id ();
2011-03-28 14:21:28 +00:00
2013-03-01 08:00:40 +00:00
$Cache -> increment ( 'stats_artist_count' );
2011-03-28 14:21:28 +00:00
2013-03-01 08:00:40 +00:00
$DB -> query ( " INSERT INTO artists_alias (ArtistID, Name) VALUES ( " . $ArtistID . " , ' " . db_string ( $Artist [ 'name' ]) . " ') " );
$AliasID = $DB -> inserted_id ();
2011-03-28 14:21:28 +00:00
2013-03-01 08:00:40 +00:00
$ArtistForm [ $Importance ][ $Num ] = array ( 'id' => $ArtistID , 'aliasid' => $AliasID , 'name' => $Artist [ 'name' ]);
$ArtistsAdded [ strtolower ( $Artist [ 'name' ])] = $ArtistForm [ $Importance ][ $Num ];
}
2011-03-28 14:21:28 +00:00
}
}
}
2013-03-01 08:00:40 +00:00
unset ( $ArtistsAdded );
2011-03-28 14:21:28 +00:00
}
2013-04-15 08:00:54 +00:00
if ( ! $GroupID ) {
2011-03-28 14:21:28 +00:00
// Create torrent group
$DB -> query ( "
INSERT INTO torrents_group
2011-08-09 21:03:28 +00:00
( ArtistID , CategoryID , Name , Year , RecordLabel , CatalogueNumber , Time , WikiBody , WikiImage , SearchText , ReleaseType , VanityHouse ) VALUES
( 0 , " . $TypeID . " , " . $T['Title'] . " , $T [ Year ], $T [ RecordLabel ], $T [ CatalogueNumber ], '".sqltime()."' , '".db_string($Body)."' , $T [ Image ], '$SearchText' , $T [ ReleaseType ], $T [ VanityHouse ]) " );
2011-03-28 14:21:28 +00:00
$GroupID = $DB -> inserted_id ();
2013-04-15 08:00:54 +00:00
if ( $Type == 'Music' ) {
foreach ( $ArtistForm as $Importance => $Artists ) {
foreach ( $Artists as $Num => $Artist ) {
2011-03-28 14:21:28 +00:00
$DB -> query ( " INSERT IGNORE INTO torrents_artists (GroupID, ArtistID, AliasID, UserID, Importance) VALUES ( " . $GroupID . " , " . $Artist [ 'id' ] . " , " . $Artist [ 'aliasid' ] . " , " . $LoggedUser [ 'ID' ] . " , ' " . $Importance . " ') " );
$Cache -> increment ( 'stats_album_count' );
}
}
}
$Cache -> increment ( 'stats_group_count' );
} else {
$DB -> query ( " UPDATE torrents_group SET
Time = '".sqltime()."'
WHERE ID = $GroupID " );
$Cache -> delete_value ( 'torrent_group_' . $GroupID );
$Cache -> delete_value ( 'torrents_details_' . $GroupID );
$Cache -> delete_value ( 'detail_files_' . $GroupID );
2013-04-15 08:00:54 +00:00
if ( $Type == 'Music' ) {
2012-02-22 08:00:31 +00:00
$DB -> query ( " SELECT ReleaseType FROM torrents_group WHERE ID=' $GroupID ' " );
list ( $Properties [ 'ReleaseType' ]) = $DB -> next_record ();
}
2011-03-28 14:21:28 +00:00
}
// Description
2013-04-15 08:00:54 +00:00
if ( ! $NoRevision ) {
2011-03-28 14:21:28 +00:00
$DB -> query ( "
INSERT INTO wiki_torrents
( PageID , Body , UserID , Summary , Time , Image ) VALUES
( $GroupID , $T [ GroupDescription ], $LoggedUser [ ID ], 'Uploaded new torrent' , '".sqltime()."' , $T [ Image ])
" );
$RevisionID = $DB -> inserted_id ();
// Revision ID
$DB -> query ( " UPDATE torrents_group SET RevisionID=' $RevisionID ' WHERE ID= $GroupID " );
}
// Tags
$Tags = explode ( ',' , $Properties [ 'TagList' ]);
2013-04-15 08:00:54 +00:00
if ( ! $Properties [ 'GroupID' ]) {
foreach ( $Tags as $Tag ) {
2012-10-11 08:00:15 +00:00
$Tag = Misc :: sanitize_tag ( $Tag );
2013-04-15 08:00:54 +00:00
if ( ! empty ( $Tag )) {
2012-10-11 08:00:15 +00:00
$Tag = Misc :: get_alias_tag ( $Tag );
2011-03-28 14:21:28 +00:00
$DB -> query ( " INSERT INTO tags
( Name , UserID ) VALUES
( '".$Tag."' , $LoggedUser [ ID ])
ON DUPLICATE KEY UPDATE Uses = Uses + 1 ;
" );
$TagID = $DB -> inserted_id ();
$DB -> query ( " INSERT INTO torrents_tags
( TagID , GroupID , UserID , PositiveVotes ) VALUES
( $TagID , $GroupID , $LoggedUser [ ID ], 10 )
ON DUPLICATE KEY UPDATE PositiveVotes = PositiveVotes + 1 ;
" );
}
}
}
// Use this section to control freeleeches
2012-12-26 08:00:54 +00:00
$T [ 'FreeLeech' ] = 0 ;
$T [ 'FreeLeechType' ] = 0 ;
2013-02-25 21:16:55 +00:00
$LogScore = ( $HasLog == 1 ? $LogScoreAverage : 0 );
2011-03-28 14:21:28 +00:00
// Torrent
$DB -> query ( "
INSERT INTO torrents
2013-02-22 08:00:24 +00:00
( GroupID , UserID , Media , Format , Encoding ,
Remastered , RemasterYear , RemasterTitle , RemasterRecordLabel , RemasterCatalogueNumber ,
Scene , HasLog , HasCue , info_hash , FileCount , FileList , FilePath , Size , Time ,
Description , LogScore , FreeTorrent , FreeLeechType )
2011-03-28 14:21:28 +00:00
VALUES
2013-02-25 21:16:55 +00:00
( $GroupID , $LoggedUser [ ID ], $T [ Media ], $T [ Format ], $T [ Encoding ], " .
" $T[Remastered] , $T[RemasterYear] , $T[RemasterTitle] , $T[RemasterRecordLabel] , $T[RemasterCatalogueNumber] , " .
" $T[Scene] , ' $HasLog ', ' $HasCue ', ' " . db_string ( $InfoHash ) . " ', $NumFiles , ' $FileString ', ' $FilePath ', " .
2013-02-28 08:00:29 +00:00
" $TotalSize , ' " . sqltime () . " ', $T[TorrentDescription] , $LogScore , ' $T[FreeLeech] ', ' $T[FreeLeechType] ') " );
2011-03-28 14:21:28 +00:00
$Cache -> increment ( 'stats_torrent_count' );
$TorrentID = $DB -> inserted_id ();
2012-10-11 08:00:15 +00:00
Tracker :: update_tracker ( 'add_torrent' , array ( 'id' => $TorrentID , 'info_hash' => rawurlencode ( $InfoHash ), 'freetorrent' => $T [ 'FreeLeech' ]));
2013-02-17 08:00:08 +00:00
$Debug -> set_flag ( 'upload: ocelot updated' );
2011-03-28 14:21:28 +00:00
//******************************************************************************//
//--------------- Write torrent file -------------------------------------------//
2013-02-25 21:16:55 +00:00
$DB -> query ( " INSERT INTO torrents_files (TorrentID, File) VALUES ( $TorrentID , ' $TorEnc ') " );
2012-10-11 08:00:15 +00:00
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 );
2011-03-28 14:21:28 +00:00
2012-10-11 08:00:15 +00:00
Torrents :: update_hash ( $GroupID );
2013-02-25 21:16:55 +00:00
$Debug -> set_flag ( 'upload: sphinx updated' );
2011-03-28 14:21:28 +00:00
2013-04-15 08:00:54 +00:00
if ( $Type == 'Music' ) {
2012-11-14 08:00:19 +00:00
include ( SERVER_ROOT . '/sections/upload/insert_extra_torrents.php' );
}
2011-03-28 14:21:28 +00:00
//******************************************************************************//
//--------------- 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 (' ;
2013-02-22 08:00:24 +00:00
foreach ( $LogScores as $LogKey => $LogScore ) {
$LogScores [ $LogKey ] = " $TorrentID , $LogScore ,1,0,0,NULL " ;
2011-03-28 14:21:28 +00:00
}
$LogQuery .= implode ( '),(' , $LogScores ) . ')' ;
$DB -> query ( $LogQuery );
$LogInDB = true ;
2012-10-02 08:00:20 +00:00
}
2011-03-28 14:21:28 +00:00
//******************************************************************************//
//--------------- Stupid Recent Uploads ----------------------------------------//
2013-04-15 08:00:54 +00:00
if ( trim ( $Properties [ 'Image' ]) != '' ) {
2011-03-28 14:21:28 +00:00
$RecentUploads = $Cache -> get_value ( 'recent_uploads_' . $UserID );
2013-04-15 08:00:54 +00:00
if ( is_array ( $RecentUploads )) {
2011-03-28 14:21:28 +00:00
do {
2013-04-15 08:00:54 +00:00
foreach ( $RecentUploads as $Item ) {
if ( $Item [ 'ID' ] == $GroupID ) {
break 2 ;
}
2011-03-28 14:21:28 +00:00
}
// Only reached if no matching GroupIDs in the cache already.
2013-04-15 08:00:54 +00:00
if ( count ( $RecentUploads ) == 5 ) {
2011-03-28 14:21:28 +00:00
array_pop ( $RecentUploads );
}
2012-10-11 08:00:15 +00:00
array_unshift ( $RecentUploads , array ( 'ID' => $GroupID , 'Name' => trim ( $Properties [ 'Title' ]), 'Artist' => Artists :: display_artists ( $ArtistForm , false , true ), 'WikiImage' => trim ( $Properties [ 'Image' ])));
2011-03-28 14:21:28 +00:00
$Cache -> cache_value ( 'recent_uploads_' . $UserID , $RecentUploads , 0 );
} while ( 0 );
}
}
2012-03-08 08:00:24 +00:00
//******************************************************************************//
//--------------- Contest ------------------------------------------------------//
2013-04-15 08:00:54 +00:00
if ( $Properties [ 'LibraryImage' ] != '' ) {
2013-02-22 08:00:24 +00:00
$DB -> query ( " INSERT INTO reportsv2 (ReporterID, TorrentID, Type, UserComment, Status, ReportedTime, Track, Image, ExtraID, Link)
2013-04-15 08:00:54 +00:00
VALUES ( 0 , " . $TorrentID . " , 'library' , '".db_string(($Properties[' MultiDisc '] ? ' Multi - disc ' : ' '))."' , 'New' , '".sqltime()."' , '' , '".db_string($Properties[' LibraryImage '])."' , '' , '' ) " );
2012-03-08 08:00:24 +00:00
}
2013-02-25 21:16:55 +00:00
//******************************************************************************//
//--------------- Post-processing ----------------------------------------------//
/* Because tracker updates and notifications can be slow , we ' re
* redirecting the user to the destination page and flushing the buffers
* to make it seem like the PHP process is working in the background .
*/
if ( $PublicTorrent ) {
View :: show_header ( " Warning " );
?>
< h1 > Warning </ h1 >
< p >< strong > Your torrent has been uploaded ; however , you must download your torrent from < a href = " torrents.php?id=<?= $GroupID ?> " > here </ a > because you didn ' t make your torrent using the " private " option .</ strong ></ p >
< ?
View :: show_footer ();
2013-04-15 08:00:54 +00:00
} elseif ( $RequestID ) {
2013-02-25 21:16:55 +00:00
header ( " Location: requests.php?action=takefill&requestid= " . $RequestID . " &torrentid= " . $TorrentID . " &auth= " . $LoggedUser [ 'AuthKey' ]);
} else {
header ( " Location: torrents.php?id= $GroupID " );
}
if ( function_exists ( 'fastcgi_finish_request' )) {
fastcgi_finish_request ();
} else {
ignore_user_abort ( true );
ob_flush ();
flush ();
ob_start (); // So we don't keep sending data to the client
}
2011-03-28 14:21:28 +00:00
//******************************************************************************//
//--------------- IRC announce and feeds ---------------------------------------//
2013-04-15 08:00:54 +00:00
$Announce = '' ;
2011-03-28 14:21:28 +00:00
2013-04-15 08:00:54 +00:00
if ( $Type == 'Music' ) {
$Announce .= Artists :: display_artists ( $ArtistForm , false );
}
2011-03-28 14:21:28 +00:00
$Announce .= trim ( $Properties [ 'Title' ]) . " " ;
2013-04-15 08:00:54 +00:00
if ( $Type == 'Music' ) {
2012-02-22 08:00:31 +00:00
$Announce .= '[' . trim ( $Properties [ 'Year' ]) . ']' ;
2013-04-15 08:00:54 +00:00
if (( $Type == 'Music' ) && ( $Properties [ 'ReleaseType' ] > 0 )) {
$Announce .= ' [' . $ReleaseTypes [ $Properties [ 'ReleaseType' ]] . ']' ;
}
$Announce .= ' - ' ;
2011-03-28 14:21:28 +00:00
$Announce .= trim ( $Properties [ 'Format' ]) . " / " . trim ( $Properties [ 'Bitrate' ]);
2013-04-15 08:00:54 +00:00
if ( $HasLog == 1 ) {
$Announce .= ' / Log' ;
}
if ( $LogInDB ) {
$Announce .= ' / ' . $LogScoreAverage . '%' ;
}
if ( $HasCue == 1 ) {
$Announce .= ' / Cue' ;
}
$Announce .= ' / ' . trim ( $Properties [ 'Media' ]);
if ( $Properties [ 'Scene' ] == '1' ) {
$Announce .= ' / Scene' ;
}
if ( $T [ 'FreeLeech' ] == '1' ) {
$Announce .= ' / Freeleech!' ;
}
2011-03-28 14:21:28 +00:00
}
$Title = $Announce ;
$AnnounceSSL = $Announce . " - https:// " . SSL_SITE_URL . " /torrents.php?id= $GroupID / https:// " . SSL_SITE_URL . " /torrents.php?action=download&id= $TorrentID " ;
2012-09-20 08:00:49 +00:00
$Announce .= " - https:// " . SSL_SITE_URL . " /torrents.php?id= $GroupID / https:// " . SSL_SITE_URL . " /torrents.php?action=download&id= $TorrentID " ;
2011-03-28 14:21:28 +00:00
$AnnounceSSL .= " - " . trim ( $Properties [ 'TagList' ]);
$Announce .= " - " . trim ( $Properties [ 'TagList' ]);
send_irc ( 'PRIVMSG #' . NONSSL_SITE_URL . '-announce :' . html_entity_decode ( $Announce ));
send_irc ( 'PRIVMSG #' . NONSSL_SITE_URL . '-announce-ssl :' . $AnnounceSSL );
//send_irc('PRIVMSG #'.NONSSL_SITE_URL.'-announce :'.html_entity_decode($Announce));
2013-02-17 08:00:08 +00:00
$Debug -> set_flag ( 'upload: announced on irc' );
2011-03-28 14:21:28 +00:00
// Manage notifications
$UsedFormatBitrates = array ();
2013-04-15 08:00:54 +00:00
if ( ! $IsNewGroup ) {
2011-03-28 14:21:28 +00:00
// maybe there are torrents in the same release as the new torrent. Let's find out (for notifications)
2013-02-04 08:00:13 +00:00
$GroupInfo = get_group_info ( $GroupID , true , 0 , false );
2011-03-28 14:21:28 +00:00
$ThisMedia = display_str ( $Properties [ 'Media' ]);
$ThisRemastered = display_str ( $Properties [ 'Remastered' ]);
$ThisRemasterYear = display_str ( $Properties [ 'RemasterYear' ]);
$ThisRemasterTitle = display_str ( $Properties [ 'RemasterTitle' ]);
$ThisRemasterRecordLabel = display_str ( $Properties [ 'RemasterRecordLabel' ]);
$ThisRemasterCatalogueNumber = display_str ( $Properties [ 'RemasterCatalogueNumber' ]);
2013-04-15 08:00:54 +00:00
foreach ( $GroupInfo [ 1 ] as $TorrentInfo ) {
2011-03-28 14:21:28 +00:00
if (( $TorrentInfo [ 'Media' ] == $ThisMedia )
2013-02-07 08:00:47 +00:00
&& ( $TorrentInfo [ 'Remastered' ] == $ThisRemastered )
&& ( $TorrentInfo [ 'RemasterYear' ] == ( int ) $ThisRemasterYear )
&& ( $TorrentInfo [ 'RemasterTitle' ] == $ThisRemasterTitle )
&& ( $TorrentInfo [ 'RemasterRecordLabel' ] == $ThisRemasterRecordLabel )
&& ( $TorrentInfo [ 'RemasterCatalogueNumber' ] == $ThisRemasterCatalogueNumber )
&& ( $TorrentInfo [ 'ID' ] != $TorrentID )) {
2011-03-28 14:21:28 +00:00
$UsedFormatBitrates [] = array ( 'format' => $TorrentInfo [ 'Format' ], 'bitrate' => $TorrentInfo [ 'Encoding' ]);
}
}
}
// For RSS
$Item = $Feed -> item ( $Title , $Text -> strip_bbcode ( $Body ), 'torrents.php?action=download&authkey=[[AUTHKEY]]&torrent_pass=[[PASSKEY]]&id=' . $TorrentID , $LoggedUser [ 'Username' ], 'torrents.php?id=' . $GroupID , trim ( $Properties [ 'TagList' ]));
//Notifications
$SQL = " SELECT unf.ID, unf.UserID, torrent_pass
FROM users_notify_filters AS unf
2013-04-15 08:00:54 +00:00
JOIN users_main AS um ON um . ID = unf . UserID
2011-03-28 14:21:28 +00:00
WHERE um . Enabled = '1' " ;
2013-04-15 08:00:54 +00:00
if ( empty ( $ArtistsUnescaped )) {
2011-03-28 14:21:28 +00:00
$ArtistsUnescaped = $ArtistForm ;
}
2013-04-15 08:00:54 +00:00
if ( ! empty ( $ArtistsUnescaped )) {
2011-03-28 14:21:28 +00:00
$ArtistNameList = array ();
$GuestArtistNameList = array ();
2013-04-15 08:00:54 +00:00
foreach ( $ArtistsUnescaped as $Importance => $Artists ) {
foreach ( $Artists as $Artist ) {
if ( $Importance == 1 || $Importance == 4 || $Importance == 5 || $Importance == 6 ) {
2012-06-02 08:00:16 +00:00
$ArtistNameList [] = " Artists LIKE '%| " . db_string ( str_replace ( '\\' , '\\\\' , $Artist [ 'name' ])) . " |%' " ;
2011-03-28 14:21:28 +00:00
} else {
2012-06-02 08:00:16 +00:00
$GuestArtistNameList [] = " Artists LIKE '%| " . db_string ( str_replace ( '\\' , '\\\\' , $Artist [ 'name' ])) . " |%' " ;
2011-03-28 14:21:28 +00:00
}
}
}
// Don't add notification if >2 main artists or if tracked artist isn't a main artist
2013-04-15 08:00:54 +00:00
if ( count ( $ArtistNameList ) > 2 || $Artist [ 'name' ] == 'Various Artists' ) {
2011-03-28 14:21:28 +00:00
$SQL .= " AND (ExcludeVA='0' AND ( " ;
$SQL .= implode ( " OR " , array_merge ( $ArtistNameList , $GuestArtistNameList ));
$SQL .= " OR Artists='')) AND ( " ;
} else {
$SQL .= " AND ( " ;
2013-04-15 08:00:54 +00:00
if ( ! empty ( $GuestArtistNameList )) {
2011-03-28 14:21:28 +00:00
$SQL .= " (ExcludeVA='0' AND ( " ;
$SQL .= implode ( " OR " , $GuestArtistNameList );
$SQL .= " )) OR " ;
}
$SQL .= implode ( " OR " , $ArtistNameList );
$SQL .= " OR Artists='') AND ( " ;
}
} else {
$SQL .= " AND (Artists='') AND ( " ;
}
reset ( $Tags );
$TagSQL = array ();
$NotTagSQL = array ();
2013-04-15 08:00:54 +00:00
foreach ( $Tags as $Tag ) {
2011-03-28 14:21:28 +00:00
$TagSQL [] = " Tags LIKE '%| " . db_string ( trim ( $Tag )) . " |%' " ;
$NotTagSQL [] = " NotTags LIKE '%| " . db_string ( trim ( $Tag )) . " |%' " ;
}
$TagSQL [] = " Tags='' " ;
$SQL .= implode ( ' OR ' , $TagSQL );
$SQL .= " ) AND !( " . implode ( ' OR ' , $NotTagSQL ) . " ) " ;
$SQL .= " AND (Categories LIKE '%| " . db_string ( trim ( $Type )) . " |%' OR Categories='') " ;
2013-04-15 08:00:54 +00:00
if ( $Properties [ 'ReleaseType' ]) {
2011-03-28 14:21:28 +00:00
$SQL .= " AND (ReleaseTypes LIKE '%| " . db_string ( trim ( $ReleaseTypes [ $Properties [ 'ReleaseType' ]])) . " |%' OR ReleaseTypes='') " ;
} else {
$SQL .= " AND (ReleaseTypes='') " ;
}
/*
Notify based on the following :
1. The torrent must match the formatbitrate filter on the notification
2. If they set NewGroupsOnly to 1 , it must also be the first torrent in the group to match the formatbitrate filter on the notification
*/
2013-04-15 08:00:54 +00:00
if ( $Properties [ 'Format' ]) {
2013-02-07 08:00:47 +00:00
$SQL .= " AND (Formats LIKE '%| " . db_string ( trim ( $Properties [ 'Format' ])) . " |%' OR Formats='') " ;
2011-03-28 14:21:28 +00:00
} else {
2013-02-07 08:00:47 +00:00
$SQL .= " AND (Formats='') " ;
2011-03-28 14:21:28 +00:00
}
2013-04-15 08:00:54 +00:00
if ( $_POST [ 'bitrate' ]) {
2013-02-07 08:00:47 +00:00
$SQL .= " AND (Encodings LIKE '%| " . db_string ( trim ( $_POST [ 'bitrate' ])) . " |%' OR Encodings='') " ;
2011-03-28 14:21:28 +00:00
} else {
2013-02-07 08:00:47 +00:00
$SQL .= " AND (Encodings='') " ;
2011-03-28 14:21:28 +00:00
}
2013-04-15 08:00:54 +00:00
if ( $Properties [ 'Media' ]) {
2013-02-07 08:00:47 +00:00
$SQL .= " AND (Media LIKE '%| " . db_string ( trim ( $Properties [ 'Media' ])) . " |%' OR Media='') " ;
2011-03-28 14:21:28 +00:00
} else {
2013-02-07 08:00:47 +00:00
$SQL .= " AND (Media='') " ;
2011-03-28 14:21:28 +00:00
}
// Either they aren't using NewGroupsOnly
$SQL .= " AND ((NewGroupsOnly = '0' " ;
// Or this is the first torrent in the group to match the formatbitrate filter
$SQL .= " ) OR ( NewGroupsOnly = '1' " ;
// Test the filter doesn't match any previous formatbitrate in the group
foreach ( $UsedFormatBitrates as $UsedFormatBitrate ) {
$FormatReq = " (Formats LIKE '%| " . db_string ( $UsedFormatBitrate [ 'format' ]) . " |%' OR Formats = '') " ;
$BitrateReq = " (Encodings LIKE '%| " . db_string ( $UsedFormatBitrate [ 'bitrate' ]) . " |%' OR Encodings = '') " ;
$SQL .= " AND (NOT( $FormatReq AND $BitrateReq )) " ;
}
2013-02-22 08:00:24 +00:00
2013-04-15 08:00:54 +00:00
$SQL .= '))' ;
2011-03-28 14:21:28 +00:00
2013-04-15 08:00:54 +00:00
if ( $Properties [ 'Year' ] && $Properties [ 'RemasterYear' ]) {
2011-03-28 14:21:28 +00:00
$SQL .= " AND ((' " . db_string ( trim ( $Properties [ 'Year' ])) . " ' BETWEEN FromYear AND ToYear)
OR ( '".db_string(trim($Properties[' RemasterYear ']))."' BETWEEN FromYear AND ToYear )
OR ( FromYear = 0 AND ToYear = 0 )) " ;
2013-04-15 08:00:54 +00:00
} elseif ( $Properties [ 'Year' ] || $Properties [ 'RemasterYear' ]) {
2011-03-28 14:21:28 +00:00
$SQL .= " AND ((' " . db_string ( trim ( Max ( $Properties [ 'Year' ], $Properties [ 'RemasterYear' ]))) . " ' BETWEEN FromYear AND ToYear)
OR ( FromYear = 0 AND ToYear = 0 )) " ;
} else {
$SQL .= " AND (FromYear=0 AND ToYear=0) " ;
}
$SQL .= " AND UserID != ' " . $LoggedUser [ 'ID' ] . " ' " ;
$DB -> query ( $SQL );
2013-02-17 08:00:08 +00:00
$Debug -> set_flag ( 'upload: notification query finished' );
2011-03-28 14:21:28 +00:00
2013-04-20 08:01:01 +00:00
if ( $DB -> record_count () > 0 ) {
2011-03-28 14:21:28 +00:00
$UserArray = $DB -> to_array ( 'UserID' );
$FilterArray = $DB -> to_array ( 'ID' );
2013-04-15 08:00:54 +00:00
$InsertSQL = 'INSERT IGNORE INTO users_notify_torrents (UserID, GroupID, TorrentID, FilterID) VALUES ' ;
2011-03-28 14:21:28 +00:00
$Rows = array ();
foreach ( $UserArray as $User ) {
list ( $FilterID , $UserID , $Passkey ) = $User ;
$Rows [] = " (' $UserID ', ' $GroupID ', ' $TorrentID ', ' $FilterID ') " ;
$Feed -> populate ( 'torrents_notify_' . $Passkey , $Item );
$Cache -> delete_value ( 'notifications_new_' . $UserID );
}
$InsertSQL .= implode ( ',' , $Rows );
$DB -> query ( $InsertSQL );
2013-02-17 08:00:08 +00:00
$Debug -> set_flag ( 'upload: notification inserts finished' );
2011-03-28 14:21:28 +00:00
foreach ( $FilterArray as $Filter ) {
list ( $FilterID , $UserID , $Passkey ) = $Filter ;
$Feed -> populate ( 'torrents_notify_' . $FilterID . '_' . $Passkey , $Item );
}
}
2012-02-08 08:00:20 +00:00
// RSS for bookmarks
$DB -> query ( " SELECT u.ID, u.torrent_pass
FROM users_main AS u
2013-04-15 08:00:54 +00:00
JOIN bookmarks_torrents AS b ON b . UserID = u . ID
2012-02-08 08:00:20 +00:00
WHERE b . GroupID = $GroupID " );
while ( list ( $UserID , $Passkey ) = $DB -> next_record ()) {
$Feed -> populate ( 'torrents_bookmarks_t_' . $Passkey , $Item );
}
2011-03-28 14:21:28 +00:00
$Feed -> populate ( 'torrents_all' , $Item );
2013-02-17 08:00:08 +00:00
$Debug -> set_flag ( 'upload: notifications handled' );
2013-04-20 08:01:01 +00:00
if ( $Type == 'Music' ) {
2011-03-28 14:21:28 +00:00
$Feed -> populate ( 'torrents_music' , $Item );
2013-04-15 08:00:54 +00:00
if ( $Properties [ 'Media' ] == 'Vinyl' ) {
$Feed -> populate ( 'torrents_vinyl' , $Item );
}
if ( $Properties [ 'Bitrate' ] == 'Lossless' ) {
$Feed -> populate ( 'torrents_lossless' , $Item );
}
if ( $Properties [ 'Bitrate' ] == '24bit Lossless' ) {
$Feed -> populate ( 'torrents_lossless24' , $Item );
}
if ( $Properties [ 'Format' ] == 'MP3' ) {
$Feed -> populate ( 'torrents_mp3' , $Item );
}
if ( $Properties [ 'Format' ] == 'FLAC' ) {
$Feed -> populate ( 'torrents_flac' , $Item );
}
}
if ( $Type == 'Applications' ) {
$Feed -> populate ( 'torrents_apps' , $Item );
}
if ( $Type == 'E-Books' ) {
$Feed -> populate ( 'torrents_ebooks' , $Item );
}
if ( $Type == 'Audiobooks' ) {
$Feed -> populate ( 'torrents_abooks' , $Item );
}
if ( $Type == 'E-Learning Videos' ) {
$Feed -> populate ( 'torrents_evids' , $Item );
}
if ( $Type == 'Comedy' ) {
$Feed -> populate ( 'torrents_comedy' , $Item );
}
if ( $Type == 'Comics' ) {
$Feed -> populate ( 'torrents_comics' , $Item );
}
2011-03-28 14:21:28 +00:00
// Clear Cache
$Cache -> delete ( 'torrents_details_' . $GroupID );