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

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