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 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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['Codec'] = $_POST['codec'];
  41. $Properties['Resolution'] = $_POST['resolution'];
  42. $Properties['AudioFormat'] = $_POST['audioformat'];
  43. $Properties['Subbing'] = $_POST['sub'];
  44. $Properties['Language'] = $_POST['lang'];
  45. $Properties['Subber']= $_POST['subber'];
  46. $Properties['Censored'] = (isset($_POST['censored'])) ? '1' : '0';
  47. $Properties['Anonymous'] = (isset($_POST['anonymous'])) ? '1' : '0';
  48. $Properties['Container'] = (isset($_POST['container']) && $_POST['container'] !== 'Autofill') ? $_POST['container'] : '';
  49. $Properties['Archive'] = (isset($_POST['archive']) && $_POST['archive'] !== 'Autofill') ? $_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. */
  159. $Validate->SetFields(
  160. 'format',
  161. '1',
  162. 'inarray',
  163. 'Not a valid format',
  164. array('inarray' => $Formats)
  165. );
  166. /*
  167. $Validate->SetFields(
  168. 'bitrate',
  169. '1',
  170. 'inarray',
  171. 'You must choose a bitrate',
  172. array('inarray' => $Bitrates)
  173. );
  174. // Handle 'other' bitrates
  175. if ($Properties['Encoding'] === 'Other') {
  176. $Validate->SetFields(
  177. 'other_bitrate',
  178. '1',
  179. 'text',
  180. 'You must enter the other bitrate (max length: 9 characters)',
  181. array('maxlength' => 9)
  182. );
  183. $enc = trim($_POST['other_bitrate']);
  184. if (isset($_POST['vbr'])) {
  185. $enc .= ' (VBR)';
  186. }
  187. $Properties['Encoding'] = $enc;
  188. $Properties['Bitrate'] = $enc;
  189. } else {
  190. $Validate->SetFields(
  191. 'bitrate',
  192. '1',
  193. 'inarray',
  194. 'You must choose a bitrate',
  195. array('inarray' => $Bitrates)
  196. );
  197. }
  198. */
  199. /* Broken 2020-03-10
  200. $Validate->SetFields(
  201. 'media',
  202. '1',
  203. 'inarray',
  204. 'Not a valid media',
  205. array('inarray' => $Media)
  206. );
  207. */
  208. /*
  209. $Validate->SetFields(
  210. 'release_desc',
  211. '0',
  212. 'string',
  213. 'Invalid release description',
  214. array('maxlength' => 1000000, 'minlength' => 0)
  215. );
  216. break;
  217. default:
  218. break;
  219. }
  220. */
  221. $Err = $Validate->ValidateForm($_POST); // Validate the form
  222. /*
  223. if ($Properties['Remastered'] && !$Properties['RemasterYear']) {
  224. // Unknown Edit!
  225. if ($LoggedUser['ID'] === $UserID || check_perms('edit_unknowns')) {
  226. // Fine!
  227. } else {
  228. $Err = "You may not edit someone else's upload to unknown release";
  229. }
  230. }
  231. */
  232. // Strip out Amazon's padding
  233. $AmazonReg = '/(http:\/\/ecx.images-amazon.com\/images\/.+)(\._.*_\.jpg)/i';
  234. $Matches = [];
  235. if (preg_match($RegX, $Properties['Image'], $Matches)) {
  236. $Properties['Image'] = $Matches[1].'.jpg';
  237. }
  238. ImageTools::blacklisted($Properties['Image']);
  239. if ($Err) { // Show the upload form, with the data the user entered
  240. if (check_perms('site_debug')) {
  241. die($Err);
  242. }
  243. error($Err);
  244. }
  245. //******************************************************************************//
  246. //--------------- Make variables ready for database input ----------------------//
  247. // Shorten and escape $Properties for database input
  248. $T = [];
  249. foreach ($Properties as $Key => $Value) {
  250. $T[$Key] = "'".db_string(trim($Value))."'";
  251. if (!$T[$Key]) {
  252. $T[$Key] = null;
  253. }
  254. }
  255. $T['Censored'] = $Properties['Censored'];
  256. $T['Anonymous'] = $Properties['Anonymous'];
  257. $T['Container'] = $Properties['Container'];
  258. $T['Archive'] = $Properties['Archive'];
  259. //******************************************************************************//
  260. //--------------- Autofill format and archive ----------------------------------//
  261. # Load FileList in lieu of $Tor object
  262. # todo: Format the output for $Validate->ParseExtensions()
  263. #var_dump($T['FileList']);
  264. # Disable the extension parser for edits
  265. # todo: Make this work with $T['FileList']
  266. if ($T['Container'] === 'Autofill'
  267. || $T['Archive'] === 'Autofill') {
  268. $Err = 'Extension parsing is only possible for new uploads';
  269. error($Err);
  270. }
  271. //******************************************************************************//
  272. //--------------- Start database stuff -----------------------------------------//
  273. $DBTorVals = [];
  274. $DB->query("
  275. SELECT Media, Container, Codec, Resolution, AudioFormat, Subbing, Language, Description, MediaInfo, Censored, Anonymous, Archive, Subber
  276. FROM torrents
  277. WHERE ID = $TorrentID");
  278. $DBTorVals = $DB->to_array(false, MYSQLI_ASSOC);
  279. $DBTorVals = $DBTorVals[0];
  280. $LogDetails = '';
  281. foreach ($DBTorVals as $Key => $Value) {
  282. $Value = "'$Value'";
  283. if ($Value !== $T[$Key]) {
  284. if (!isset($T[$Key])) {
  285. continue;
  286. }
  287. if ((empty($Value) && empty($T[$Key])) || ($Value === "'0'" && $T[$Key] === "''")) {
  288. continue;
  289. }
  290. if ($LogDetails === '') {
  291. $LogDetails = "$Key: $Value -> ".$T[$Key];
  292. } else {
  293. $LogDetails = "$LogDetails, $Key: $Value -> ".$T[$Key];
  294. }
  295. }
  296. }
  297. // Update info for the torrent
  298. /*
  299. $SQL = "
  300. UPDATE torrents
  301. SET
  302. Media = $T[Media],
  303. Format = $T[Format],
  304. Encoding = $T[Encoding],
  305. RemasterYear = $T[RemasterYear],
  306. Remastered = $T[Remastered],
  307. RemasterTitle = $T[RemasterTitle],
  308. RemasterRecordLabel = $T[RemasterRecordLabel],
  309. RemasterCatalogueNumber = $T[RemasterCatalogueNumber],
  310. Scene = $T[Scene],";
  311. */
  312. $SQL = "
  313. UPDATE torrents
  314. SET
  315. Media = $T[Media],
  316. Container = '$T[Container]',
  317. Codec = $T[Codec],
  318. Resolution = $T[Resolution],
  319. AudioFormat = $T[AudioFormat],
  320. Subbing = $T[Subbing],
  321. Language = $T[Language],
  322. Subber = $T[Subber],
  323. Archive = '$T[Archive]',
  324. MediaInfo = $T[MediaInfo],
  325. Censored = $T[Censored],
  326. Anonymous = $T[Anonymous],";
  327. if (check_perms('torrents_freeleech')) {
  328. $SQL .= "FreeTorrent = $T[FreeLeech],";
  329. $SQL .= "FreeLeechType = $T[FreeLeechType],";
  330. }
  331. if (check_perms('users_mod')) {
  332. /*
  333. if ($T[Format] !== "'FLAC'") {
  334. $SQL .= "
  335. HasLog = '0',
  336. HasCue = '0',";
  337. } else {
  338. $SQL .= "
  339. HasLog = $T[HasLog],
  340. HasCue = $T[HasCue],";
  341. }
  342. */
  343. $DB->query("
  344. SELECT TorrentID
  345. FROM torrents_bad_tags
  346. WHERE TorrentID = '$TorrentID'");
  347. list($btID) = $DB->next_record();
  348. if (!$btID && $Properties['BadTags']) {
  349. $DB->query("
  350. INSERT INTO torrents_bad_tags
  351. VALUES ($TorrentID, $LoggedUser[ID], NOW())");
  352. }
  353. if ($btID && !$Properties['BadTags']) {
  354. $DB->query("
  355. DELETE FROM torrents_bad_tags
  356. WHERE TorrentID = '$TorrentID'");
  357. }
  358. $DB->query("
  359. SELECT TorrentID
  360. FROM torrents_bad_folders
  361. WHERE TorrentID = '$TorrentID'");
  362. list($bfID) = $DB->next_record();
  363. if (!$bfID && $Properties['BadFolders']) {
  364. $DB->query("
  365. INSERT INTO torrents_bad_folders
  366. VALUES ($TorrentID, $LoggedUser[ID], NOW())");
  367. }
  368. if ($bfID && !$Properties['BadFolders']) {
  369. $DB->query("
  370. DELETE FROM torrents_bad_folders
  371. WHERE TorrentID = '$TorrentID'");
  372. }
  373. $DB->query("
  374. SELECT TorrentID
  375. FROM torrents_bad_files
  376. WHERE TorrentID = '$TorrentID'");
  377. list($bfiID) = $DB->next_record();
  378. if (!$bfiID && $Properties['BadFiles']) {
  379. $DB->query("
  380. INSERT INTO torrents_bad_files
  381. VALUES ($TorrentID, $LoggedUser[ID], NOW())");
  382. }
  383. if ($bfiID && !$Properties['BadFiles']) {
  384. $DB->query("
  385. DELETE FROM torrents_bad_files
  386. WHERE TorrentID = '$TorrentID'");
  387. }
  388. $DB->query("
  389. SELECT TorrentID
  390. FROM library_contest
  391. WHERE TorrentID = '$TorrentID'");
  392. list($lbID) = $DB->next_record();
  393. if (!$lbID && $Properties['LibraryUpload'] && $Properties['LibraryPoints'] > 0) {
  394. $DB->query("
  395. SELECT UserID
  396. FROM torrents
  397. WHERE ID = $TorrentID");
  398. list($UploaderID) = $DB->next_record();
  399. $DB->query("
  400. INSERT INTO library_contest
  401. VALUES ($UploaderID, $TorrentID, $Properties[LibraryPoints])");
  402. }
  403. if ($lbID && !$Properties['LibraryUpload']) {
  404. $DB->query("
  405. DELETE FROM library_contest
  406. WHERE TorrentID = '$TorrentID'");
  407. }
  408. }
  409. $SQL .= "
  410. Description = $T[TorrentDescription]
  411. WHERE ID = $TorrentID";
  412. $DB->query($SQL);
  413. if (check_perms('torrents_freeleech') && $Properties['FreeLeech'] != $CurFreeLeech) {
  414. Torrents::freeleech_torrents($TorrentID, $Properties['FreeLeech'], $Properties['FreeLeechType']);
  415. }
  416. $DB->query("
  417. SELECT GroupID, Time
  418. FROM torrents
  419. WHERE ID = '$TorrentID'");
  420. list($GroupID, $Time) = $DB->next_record();
  421. // Competition
  422. if (strtotime($Time) > 1241352173) {
  423. if ($_POST['log_score'] === '100') {
  424. $DB->query("
  425. INSERT IGNORE into users_points (GroupID, UserID, Points)
  426. VALUES ('$GroupID', '$UserID', '1')");
  427. }
  428. }
  429. // End competiton
  430. $DB->query("
  431. SELECT Enabled
  432. FROM users_main
  433. WHERE ID = $UserID");
  434. list($Enabled) = $DB->next_record();
  435. $DB->query("
  436. SELECT Name
  437. FROM torrents_group
  438. WHERE ID = $GroupID");
  439. list($Name) = $DB->next_record(MYSQLI_NUM, false);
  440. Misc::write_log("Torrent $TorrentID ($Name) in group $GroupID was edited by ".$LoggedUser['Username']." ($LogDetails)"); // todo: This is probably broken
  441. Torrents::write_group_log($GroupID, $TorrentID, $LoggedUser['ID'], $LogDetails, 0);
  442. $Cache->delete_value("torrents_details_$GroupID");
  443. $Cache->delete_value("torrent_download_$TorrentID");
  444. Torrents::update_hash($GroupID);
  445. // All done!
  446. header("Location: torrents.php?id=$GroupID");