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.

file_checker.class.php 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. $ComicsExtensions = array_fill_keys(array('cbr', 'cbz', 'gif', 'jpeg', 'jpg', 'pdf', 'png'), true);
  3. $MusicExtensions = array_fill_keys(
  4. array(
  5. 'ac3', 'accurip', 'azw3', 'chm', 'cue', 'djv', 'djvu', 'doc', 'dts', 'epub', 'ffp',
  6. 'flac', 'gif', 'htm', 'html', 'jpeg', 'jpg', 'lit', 'log', 'm3u', 'm3u8', 'm4a', 'm4b',
  7. 'md5', 'mobi', 'mp3', 'mp4', 'nfo', 'pdf', 'pls', 'png', 'rtf', 'sfv', 'txt'),
  8. true
  9. );
  10. $Keywords = array(
  11. 'ahashare.com', 'demonoid.com', 'demonoid.me', 'djtunes.com', 'h33t', 'housexclusive.net',
  12. 'limetorrents.com', 'mixesdb.com', 'mixfiend.blogstop', 'mixtapetorrent.blogspot',
  13. 'plixid.com', 'reggaeme.com' , 'scc.nfo', 'thepiratebay.org', 'torrentday');
  14. function check_file($Type, $Name)
  15. {
  16. check_name($Name);
  17. check_extensions($Type, $Name);
  18. }
  19. function check_name($Name)
  20. {
  21. global $Keywords;
  22. $NameLC = strtolower($Name);
  23. foreach ($Keywords as &$Value) {
  24. if (strpos($NameLC, $Value) !== false) {
  25. forbidden_error($Name);
  26. }
  27. }
  28. if (preg_match('/INCOMPLETE~\*/i', $Name)) {
  29. forbidden_error($Name);
  30. }
  31. /*
  32. * These characters are invalid in NTFS on Windows systems:
  33. * : ? / < > \ * | "
  34. *
  35. * TODO: Add "/" to the blacklist. Adding "/" to the blacklist causes problems with nested dirs, apparently.
  36. *
  37. * Only the following characters need to be escaped (see the link below):
  38. * \ - ^ ]
  39. *
  40. * http://www.php.net/manual/en/regexp.reference.character-classes.php
  41. */
  42. $AllBlockedChars = ' : ? < > \ * | " ';
  43. if (preg_match('/[\\:?<>*|"]/', $Name, $Matches)) {
  44. character_error($Matches[0], $AllBlockedChars);
  45. }
  46. }
  47. function check_extensions($Type, $Name)
  48. {
  49. global $MusicExtensions, $ComicsExtensions;
  50. if ($Type == 'Music' || $Type == 'Audiobooks' || $Type == 'Comedy' || $Type == 'E-Books') {
  51. if (!isset($MusicExtensions[get_file_extension($Name)])) {
  52. invalid_error($Name);
  53. }
  54. } elseif ($Type == 'Comics') {
  55. if (!isset($ComicsExtensions[get_file_extension($Name)])) {
  56. invalid_error($Name);
  57. }
  58. }
  59. }
  60. function get_file_extension($FileName)
  61. {
  62. return strtolower(substr(strrchr($FileName, '.'), 1));
  63. }
  64. function invalid_error($Name)
  65. {
  66. global $Err;
  67. $Err = 'The torrent contained one or more invalid files (' . display_str($Name) . ')';
  68. }
  69. function forbidden_error($Name)
  70. {
  71. global $Err;
  72. $Err = 'The torrent contained one or more forbidden files (' . display_str($Name) . ')';
  73. }
  74. function character_error($Character, $AllBlockedChars)
  75. {
  76. global $Err;
  77. $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 />\nNote: The complete list of characters that are disallowed are shown below:<br />\n\t\t$AllBlockedChars";
  78. }