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

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