2012-06-18 08:00:14 +00:00
< ? php
2013-02-25 21:16:55 +00:00
$ComicsExtensions = array_fill_keys ( array ( 'cbr' , 'cbz' , 'gif' , 'jpeg' , 'jpg' , 'pdf' , 'png' ), true );
$MusicExtensions = array_fill_keys (
array (
'ac3' , 'accurip' , 'azw3' , 'chm' , 'cue' , 'djv' , 'djvu' , 'doc' , 'dts' , 'epub' , 'ffp' ,
'flac' , 'gif' , 'htm' , 'html' , 'jpeg' , 'jpg' , 'lit' , 'log' , 'm3u' , 'm3u8' , 'm4a' , 'm4b' ,
'md5' , 'mobi' , 'mp3' , 'mp4' , 'nfo' , 'pdf' , 'pls' , 'png' , 'rtf' , 'sfv' , 'txt' ),
true );
$Keywords = array (
'ahashare.com' , 'demonoid.com' , 'demonoid.me' , 'djtunes.com' , 'h33t' , 'housexclusive.net' ,
'limetorrents.com' , 'mixesdb.com' , 'mixfiend.blogstop' , 'mixtapetorrent.blogspot' ,
'plixid.com' , 'reggaeme.com' , 'scc.nfo' , 'thepiratebay.org' , 'torrentday' );
2012-06-18 08:00:14 +00:00
function check_file ( $Type , $Name ) {
2013-02-25 21:16:55 +00:00
check_name ( $Name );
check_extensions ( $Type , $Name );
2012-06-18 08:00:14 +00:00
}
function check_name ( $Name ) {
2013-02-25 21:16:55 +00:00
global $Keywords ;
$NameLC = strtolower ( $Name );
foreach ( $Keywords as & $Value ) {
if ( strpos ( $NameLC , $Value ) !== false ) {
2012-06-18 08:00:14 +00:00
forbidden_error ( $Name );
2013-02-25 21:16:55 +00:00
}
2012-06-18 08:00:14 +00:00
}
2013-02-25 21:16:55 +00:00
if ( preg_match ( '/INCOMPLETE~\*/i' , $Name )) {
2012-06-18 08:00:14 +00:00
forbidden_error ( $Name );
}
2013-06-27 08:01:06 +00:00
/*
* These characters are invalid in NTFS on Windows systems :
* : ? / < > \ * | "
*
* TODO : Add " / " to the blacklist . Adding " / " to the blacklist causes problems with nested dirs , apparently .
*
* Only the following characters need to be escaped ( see the link below ) :
* \ - ^ ]
*
* http :// www . php . net / manual / en / regexp . reference . character - classes . php
*/
$AllBlockedChars = ' : ? < > \ * | " ' ;
if ( preg_match ( '/[\\:?<>*|"]/' , $Name , $Matches )) {
2013-06-26 08:01:00 +00:00
character_error ( $Matches [ 0 ], $AllBlockedChars );
2012-06-18 08:00:14 +00:00
}
}
function check_extensions ( $Type , $Name ) {
2013-02-25 21:16:55 +00:00
global $MusicExtensions , $ComicsExtensions ;
if ( $Type == 'Music' || $Type == 'Audiobooks' || $Type == 'Comedy' || $Type == 'E-Books' ) {
if ( ! isset ( $MusicExtensions [ get_file_extension ( $Name )])) {
2012-06-18 08:00:14 +00:00
invalid_error ( $Name );
2013-02-25 21:16:55 +00:00
}
2013-06-26 08:01:00 +00:00
} elseif ( $Type == 'Comics' ) {
2013-02-25 21:16:55 +00:00
if ( ! isset ( $ComicsExtensions [ get_file_extension ( $Name )])) {
2012-06-18 08:00:14 +00:00
invalid_error ( $Name );
2013-02-25 21:16:55 +00:00
}
}
2012-06-18 08:00:14 +00:00
}
2013-02-25 21:16:55 +00:00
function get_file_extension ( $FileName ) {
return strtolower ( substr ( strrchr ( $FileName , '.' ), 1 ));
2012-06-18 08:00:14 +00:00
}
function invalid_error ( $Name ) {
global $Err ;
2013-02-25 21:16:55 +00:00
$Err = 'The torrent contained one or more invalid files (' . display_str ( $Name ) . ')' ;
2012-06-18 08:00:14 +00:00
}
function forbidden_error ( $Name ) {
global $Err ;
2013-02-25 21:16:55 +00:00
$Err = 'The torrent contained one or more forbidden files (' . display_str ( $Name ) . ')' ;
2012-06-18 08:00:14 +00:00
}
2013-06-26 08:01:00 +00:00
function character_error ( $Character , $AllBlockedChars ) {
2013-02-25 21:16:55 +00:00
global $Err ;
2013-06-27 08:01:06 +00:00
$Err = " One or more of the files or folders in the torrent has a name that contains the forbidden character ' $Character '. Please rename the files as necessary and recreate the torrent.<br /><br /> \n Note: The complete list of characters that are disallowed are shown below:<br /> \n \t \t $AllBlockedChars " ;
2012-06-18 08:00:14 +00:00
}