BioTorrents.de’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.

takeedit.php 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <?php
  2. #declare(strict_types=1);
  3. //******************************************************************************//
  4. //--------------- Take edit ----------------------------------------------------//
  5. // This pages handles the backend of the 'edit torrent' function. It checks //
  6. // the data, and if it all validates, it edits the values in the database //
  7. // that correspond to the torrent in question. //
  8. //******************************************************************************//
  9. enforce_login();
  10. authorize();
  11. require_once SERVER_ROOT.'/classes/validate.class.php';
  12. $Validate = new VALIDATE;
  13. //******************************************************************************//
  14. //--------------- Set $Properties array ----------------------------------------//
  15. // This is used if the form doesn't validate, and when the time comes to enter //
  16. // it into the database. //
  17. //******************************************************************************//
  18. $Properties=[];
  19. $_POST['type'] = $_POST['type'] + 1;
  20. $TypeID = (int) $_POST['type'];
  21. $Type = $Categories[$TypeID-1];
  22. $TorrentID = (int) $_POST['torrentid'];
  23. /*
  24. $Properties['Remastered'] = (isset($_POST['remaster']))? 1 : 0;
  25. if ($Properties['Remastered']) {
  26. $Properties['UnknownRelease'] = (isset($_POST['unknown'])) ? 1 : 0;
  27. }
  28. if (!$Properties['Remastered']) {
  29. $Properties['UnknownRelease'] = 0;
  30. }
  31. */
  32. $Properties['BadTags'] = (isset($_POST['bad_tags']))? 1 : 0;
  33. $Properties['BadFolders'] = (isset($_POST['bad_folders']))? 1 : 0;
  34. $Properties['BadFiles'] = (isset($_POST['bad_files'])) ? 1 : 0;
  35. $Properties['Format'] = $_POST['format'];
  36. $Properties['Media'] = $_POST['media'];
  37. $Properties['Bitrate'] = $_POST['bitrate'];
  38. $Properties['Encoding'] = $_POST['bitrate'];
  39. $Properties['Trumpable'] = (isset($_POST['make_trumpable'])) ? 1 : 0;
  40. $Properties['TorrentDescription'] = $_POST['release_desc'];
  41. $Properties['Name'] = $_POST['title'];
  42. $Properties['Container'] = $_POST['container'];
  43. $Properties['Codec'] = $_POST['codec'];
  44. $Properties['Resolution'] = $_POST['resolution'];
  45. $Properties['Version'] = $_POST['version'];
  46. $Properties['Censored'] = (isset($_POST['censored'])) ? '1' : '0';
  47. $Properties['Anonymous'] = (isset($_POST['anonymous'])) ? '1' : '0';
  48. $Properties['Archive'] = (isset($_POST['archive']) && $_POST['archive'] != '---') ? $_POST['archive'] : '';
  49. if ($_POST['album_desc']) {
  50. $Properties['GroupDescription'] = $_POST['album_desc'];
  51. }
  52. if (check_perms('torrents_freeleech')) {
  53. $Free = (int) $_POST['freeleech'];
  54. if (!in_array($Free, array(0, 1, 2))) {
  55. error(404);
  56. }
  57. $Properties['FreeLeech'] = $Free;
  58. if ($Free == 0) {
  59. $FreeType = 0;
  60. } else {
  61. $FreeType = (int)$_POST['freeleechtype'];
  62. if (!in_array($Free, array(0, 1, 2, 3))) {
  63. error(404);
  64. }
  65. }
  66. $Properties['FreeLeechType'] = $FreeType;
  67. }
  68. //******************************************************************************//
  69. //--------------- Validate data in edit form -----------------------------------//
  70. /*
  71. $DB->query("
  72. SELECT UserID, Remastered, RemasterYear, FreeTorrent
  73. FROM torrents
  74. WHERE ID = $TorrentID");
  75. */
  76. $DB->query("
  77. SELECT UserID, FreeTorrent
  78. FROM torrents
  79. WHERE ID = $TorrentID");
  80. if (!$DB->has_results()) {
  81. error(404);
  82. }
  83. // list($UserID, $Remastered, $RemasterYear, $CurFreeLeech) = $DB->next_record(MYSQLI_BOTH, false);
  84. list($UserID, $CurFreeLeech) = $DB->next_record(MYSQLI_BOTH, false);
  85. if ($LoggedUser['ID'] != $UserID && !check_perms('torrents_edit')) {
  86. error(403);
  87. }
  88. /*
  89. if ($Remastered == '1' && !$RemasterYear && !check_perms('edit_unknowns')) {
  90. error(403);
  91. }
  92. */
  93. if ($Properties['UnknownRelease'] && !($Remastered == '1' && !$RemasterYear) && !check_perms('edit_unknowns')) {
  94. // It's Unknown now, and it wasn't before
  95. if ($LoggedUser['ID'] != $UserID) {
  96. // Hax
  97. error();
  98. }
  99. }
  100. $Validate->SetFields('type', '1', 'number', 'Not a valid type.', array('maxlength' => count($Categories), 'minlength' => 1));
  101. /*
  102. switch ($Type) {
  103. case 'Music':
  104. if (!empty($Properties['Remastered']) && !$Properties['UnknownRelease']) {
  105. $Validate->SetFields('remaster_year', '1', 'number', 'Year of remaster/re-issue must be entered.');
  106. } else {
  107. $Validate->SetFields('remaster_year', '0', 'number', 'Invalid remaster year.');
  108. }
  109. if (!empty($Properties['Remastered']) && !$Properties['UnknownRelease'] && $Properties['RemasterYear'] < 1982 && $Properties['Media'] == 'CD') {
  110. error('You have selected a year for an album that predates the medium you say it was created on.');
  111. header("Location: torrents.php?action=edit&id=$TorrentID");
  112. error();
  113. }
  114. $Validate->SetFields('remaster_title', '0', 'string', 'Remaster title must be between 2 and 80 characters.', array('maxlength' => 80, 'minlength' => 2));
  115. if ($Properties['RemasterTitle'] == 'Original Release') {
  116. error('"Original Release" is not a valid remaster title.');
  117. header("Location: torrents.php?action=edit&id=$TorrentID");
  118. error();
  119. }
  120. $Validate->SetFields('remaster_record_label', '0', 'string', 'Remaster record label must be between 2 and 80 characters.', array('maxlength' => 80, 'minlength' => 2));
  121. $Validate->SetFields('remaster_catalogue_number', '0', 'string', 'Remaster catalogue number must be between 2 and 80 characters.', array('maxlength' => 80, 'minlength' => 2));
  122. $Validate->SetFields('format', '1', 'inarray', 'Not a valid format.', array('inarray' => $Formats));
  123. $Validate->SetFields('bitrate', '1', 'inarray', 'You must choose a bitrate.', array('inarray' => $Bitrates));
  124. // Handle 'other' bitrates
  125. if ($Properties['Encoding'] == 'Other') {
  126. $Validate->SetFields('other_bitrate', '1', 'text', 'You must enter the other bitrate (max length: 9 characters).', array('maxlength' => 9));
  127. $enc = trim($_POST['other_bitrate']);
  128. if (isset($_POST['vbr'])) {
  129. $enc .= ' (VBR)';
  130. }
  131. $Properties['Encoding'] = $enc;
  132. $Properties['Bitrate'] = $enc;
  133. } else {
  134. $Validate->SetFields('bitrate', '1', 'inarray', 'You must choose a bitrate.', array('inarray' => $Bitrates));
  135. }
  136. $Validate->SetFields('media', '1', 'inarray', 'Not a valid media.', array('inarray' => $Media));
  137. $Validate->SetFields('release_desc', '0', 'string', 'Invalid release description.', array('maxlength' => 1000000, 'minlength' => 0));
  138. break;
  139. case 'Audiobooks':
  140. case 'Comedy':
  141. /*$Validate->SetFields('title', '1', 'string', 'Title must be between 2 and 300 characters.', array('maxlength' => 300, 'minlength' => 2));
  142. ^ this is commented out because there is no title field on these pages*
  143. $Validate->SetFields('year', '1', 'number', 'The year of the release must be entered.');
  144. $Validate->SetFields('format', '1', 'inarray', 'Not a valid format.', array('inarray' => $Formats));
  145. $Validate->SetFields('bitrate', '1', 'inarray', 'You must choose a bitrate.', array('inarray' => $Bitrates));
  146. // Handle 'other' bitrates
  147. if ($Properties['Encoding'] == 'Other') {
  148. $Validate->SetFields('other_bitrate', '1', 'text', 'You must enter the other bitrate (max length: 9 characters).', array('maxlength' => 9));
  149. $enc = trim($_POST['other_bitrate']);
  150. if (isset($_POST['vbr'])) {
  151. $enc .= ' (VBR)';
  152. }
  153. $Properties['Encoding'] = $enc;
  154. $Properties['Bitrate'] = $enc;
  155. } else {
  156. $Validate->SetFields('bitrate', '1', 'inarray', 'You must choose a bitrate.', array('inarray' => $Bitrates));
  157. }
  158. $Validate->SetFields('release_desc', '0', 'string', 'The release description has a minimum length of 10 characters.', array('maxlength' => 1000000, 'minlength' => 10));
  159. break;
  160. case 'Applications':
  161. case 'Comics':
  162. case 'E-Books':
  163. case 'E-Learning Videos':
  164. /*$Validate->SetFields('title', '1', 'string', 'Title must be between 2 and 300 characters.', array('maxlength' => 300, 'minlength' => 2));
  165. ^ this is commented out because there is no title field on these pages*
  166. break;
  167. }
  168. */
  169. $Err = $Validate->ValidateForm($_POST); // Validate the form
  170. if ($Properties['Remastered'] && !$Properties['RemasterYear']) {
  171. //Unknown Edit!
  172. if ($LoggedUser['ID'] == $UserID || check_perms('edit_unknowns')) {
  173. //Fine!
  174. } else {
  175. $Err = "You may not edit someone else's upload to unknown release.";
  176. }
  177. }
  178. // Strip out Amazon's padding
  179. $AmazonReg = '/(http:\/\/ecx.images-amazon.com\/images\/.+)(\._.*_\.jpg)/i';
  180. $Matches = [];
  181. if (preg_match($RegX, $Properties['Image'], $Matches)) {
  182. $Properties['Image'] = $Matches[1].'.jpg';
  183. }
  184. ImageTools::blacklisted($Properties['Image']);
  185. if ($Err) { // Show the upload form, with the data the user entered
  186. if (check_perms('site_debug')) {
  187. error($Err);
  188. }
  189. error($Err);
  190. }
  191. //******************************************************************************//
  192. //--------------- Make variables ready for database input ----------------------//
  193. // Shorten and escape $Properties for database input
  194. $T = [];
  195. foreach ($Properties as $Key => $Value) {
  196. $T[$Key] = "'".db_string(trim($Value))."'";
  197. if (!$T[$Key]) {
  198. $T[$Key] = null;
  199. }
  200. }
  201. $T['Censored'] = $Properties['Censored'];
  202. $T['Anonymous'] = $Properties['Anonymous'];
  203. //******************************************************************************//
  204. //--------------- Start database stuff -----------------------------------------//
  205. $DBTorVals = [];
  206. $DB->query("
  207. SELECT Media, Container, Codec, Resolution, Version, Description, Censored, Anonymous, Archive
  208. FROM torrents
  209. WHERE ID = $TorrentID");
  210. $DBTorVals = $DB->to_array(false, MYSQLI_ASSOC);
  211. $DBTorVals = $DBTorVals[0];
  212. $LogDetails = '';
  213. foreach ($DBTorVals as $Key => $Value) {
  214. $Value = "'$Value'";
  215. if ($Value != $T[$Key]) {
  216. if (!isset($T[$Key])) {
  217. continue;
  218. }
  219. if ((empty($Value) && empty($T[$Key])) || ($Value == "'0'" && $T[$Key] == "''")) {
  220. continue;
  221. }
  222. if ($LogDetails == '') {
  223. $LogDetails = "$Key: $Value -> ".$T[$Key];
  224. } else {
  225. $LogDetails = "$LogDetails, $Key: $Value -> ".$T[$Key];
  226. }
  227. }
  228. }
  229. $T['Censored'] = $Properties['Censored'];
  230. $T['Anonymous'] = $Properties['Anonymous'];
  231. // Update info for the torrent
  232. /*
  233. $SQL = "
  234. UPDATE torrents
  235. SET
  236. Media = $T[Media],
  237. Format = $T[Format],
  238. Encoding = $T[Encoding],
  239. RemasterYear = $T[RemasterYear],
  240. Remastered = $T[Remastered],
  241. RemasterTitle = $T[RemasterTitle],
  242. RemasterRecordLabel = $T[RemasterRecordLabel],
  243. RemasterCatalogueNumber = $T[RemasterCatalogueNumber],
  244. Scene = $T[Scene],";
  245. */
  246. $SQL = "
  247. UPDATE torrents
  248. SET
  249. Media = $T[Media],
  250. Container = $T[Container],
  251. Codec = $T[Codec],
  252. Resolution = $T[Resolution],
  253. Version = $T[Version],
  254. Archive = $T[Archive],
  255. Censored = $T[Censored],
  256. Anonymous = $T[Anonymous],";
  257. if (check_perms('torrents_freeleech')) {
  258. $SQL .= "FreeTorrent = $T[FreeLeech],";
  259. $SQL .= "FreeLeechType = $T[FreeLeechType],";
  260. }
  261. if (check_perms('users_mod')) {
  262. /* if ($T[Format] != "'FLAC'") {
  263. $SQL .= "
  264. HasLog = '0',
  265. HasCue = '0',";
  266. } else {
  267. $SQL .= "
  268. HasLog = $T[HasLog],
  269. HasCue = $T[HasCue],";
  270. }
  271. */
  272. $DB->query("
  273. SELECT TorrentID
  274. FROM torrents_bad_tags
  275. WHERE TorrentID = '$TorrentID'");
  276. list($btID) = $DB->next_record();
  277. if (!$btID && $Properties['BadTags']) {
  278. $DB->query("
  279. INSERT INTO torrents_bad_tags
  280. VALUES ($TorrentID, $LoggedUser[ID], NOW())");
  281. }
  282. if ($btID && !$Properties['BadTags']) {
  283. $DB->query("
  284. DELETE FROM torrents_bad_tags
  285. WHERE TorrentID = '$TorrentID'");
  286. }
  287. $DB->query("
  288. SELECT TorrentID
  289. FROM torrents_bad_folders
  290. WHERE TorrentID = '$TorrentID'");
  291. list($bfID) = $DB->next_record();
  292. if (!$bfID && $Properties['BadFolders']) {
  293. $DB->query("
  294. INSERT INTO torrents_bad_folders
  295. VALUES ($TorrentID, $LoggedUser[ID], NOW())");
  296. }
  297. if ($bfID && !$Properties['BadFolders']) {
  298. $DB->query("
  299. DELETE FROM torrents_bad_folders
  300. WHERE TorrentID = '$TorrentID'");
  301. }
  302. $DB->query("
  303. SELECT TorrentID
  304. FROM torrents_bad_files
  305. WHERE TorrentID = '$TorrentID'");
  306. list($bfiID) = $DB->next_record();
  307. if (!$bfiID && $Properties['BadFiles']) {
  308. $DB->query("
  309. INSERT INTO torrents_bad_files
  310. VALUES ($TorrentID, $LoggedUser[ID], NOW())");
  311. }
  312. if ($bfiID && !$Properties['BadFiles']) {
  313. $DB->query("
  314. DELETE FROM torrents_bad_files
  315. WHERE TorrentID = '$TorrentID'");
  316. }
  317. $DB->query("
  318. SELECT TorrentID
  319. FROM library_contest
  320. WHERE TorrentID = '$TorrentID'");
  321. list($lbID) = $DB->next_record();
  322. if (!$lbID && $Properties['LibraryUpload'] && $Properties['LibraryPoints'] > 0) {
  323. $DB->query("
  324. SELECT UserID
  325. FROM torrents
  326. WHERE ID = $TorrentID");
  327. list($UploaderID) = $DB->next_record();
  328. $DB->query("
  329. INSERT INTO library_contest
  330. VALUES ($UploaderID, $TorrentID, $Properties[LibraryPoints])");
  331. }
  332. if ($lbID && !$Properties['LibraryUpload']) {
  333. $DB->query("
  334. DELETE FROM library_contest
  335. WHERE TorrentID = '$TorrentID'");
  336. }
  337. }
  338. $SQL .= "
  339. Description = $T[TorrentDescription]
  340. WHERE ID = $TorrentID";
  341. $DB->query($SQL);
  342. if (check_perms('torrents_freeleech') && $Properties['FreeLeech'] != $CurFreeLeech) {
  343. Torrents::freeleech_torrents($TorrentID, $Properties['FreeLeech'], $Properties['FreeLeechType']);
  344. }
  345. $DB->query("
  346. SELECT GroupID, Time
  347. FROM torrents
  348. WHERE ID = '$TorrentID'");
  349. list($GroupID, $Time) = $DB->next_record();
  350. // Competition
  351. if (strtotime($Time) > 1241352173) {
  352. if ($_POST['log_score'] == '100') {
  353. $DB->query("
  354. INSERT IGNORE into users_points (GroupID, UserID, Points)
  355. VALUES ('$GroupID', '$UserID', '1')");
  356. }
  357. }
  358. // End competiton
  359. $DB->query("
  360. SELECT Enabled
  361. FROM users_main
  362. WHERE ID = $UserID");
  363. list($Enabled) = $DB->next_record();
  364. $DB->query("
  365. SELECT Name
  366. FROM torrents_group
  367. WHERE ID = $GroupID");
  368. list($Name) = $DB->next_record(MYSQLI_NUM, false);
  369. Misc::write_log("Torrent $TorrentID ($Name) in group $GroupID was edited by ".$LoggedUser['Username']." ($LogDetails)"); // TODO: this is probably broken
  370. Torrents::write_group_log($GroupID, $TorrentID, $LoggedUser['ID'], $LogDetails, 0);
  371. $Cache->delete_value("torrents_details_$GroupID");
  372. $Cache->delete_value("torrent_download_$TorrentID");
  373. Torrents::update_hash($GroupID);
  374. // All done!
  375. header("Location: torrents.php?id=$GroupID");