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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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'] !== '---') ? $_POST['container'] : '';
  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. $T['Container'] = $Properties['Container'];
  250. $T['Archive'] = $Properties['Archive'];
  251. //******************************************************************************//
  252. //--------------- Autofill format and archive ----------------------------------//
  253. # Load FileList in lieu of $Tor object
  254. # todo: Format the output for $Validate->ParseExtensions()
  255. #var_dump($T['FileList']);
  256. # Disable the extension parser for edits
  257. # todo: Make this work with $T['FileList']
  258. if ($T['Container'] === 'Autofill'
  259. || $T['Archive'] === 'Autofill') {
  260. $Err = 'Extension parsing is only possible for new uploads';
  261. error($Err);
  262. }
  263. //******************************************************************************//
  264. //--------------- Start database stuff -----------------------------------------//
  265. $DBTorVals = [];
  266. $DB->query("
  267. SELECT Media, Container, Codec, Resolution, AudioFormat, Subbing, Language, Description, MediaInfo, Censored, Anonymous, Archive, Subber
  268. FROM torrents
  269. WHERE ID = $TorrentID");
  270. $DBTorVals = $DB->to_array(false, MYSQLI_ASSOC);
  271. $DBTorVals = $DBTorVals[0];
  272. $LogDetails = '';
  273. foreach ($DBTorVals as $Key => $Value) {
  274. $Value = "'$Value'";
  275. if ($Value != $T[$Key]) {
  276. if (!isset($T[$Key])) {
  277. continue;
  278. }
  279. if ((empty($Value) && empty($T[$Key])) || ($Value == "'0'" && $T[$Key] == "''")) {
  280. continue;
  281. }
  282. if ($LogDetails == '') {
  283. $LogDetails = "$Key: $Value -> ".$T[$Key];
  284. } else {
  285. $LogDetails = "$LogDetails, $Key: $Value -> ".$T[$Key];
  286. }
  287. }
  288. }
  289. $T['Censored'] = $Properties['Censored'];
  290. $T['Anonymous'] = $Properties['Anonymous'];
  291. // Update info for the torrent
  292. /*
  293. $SQL = "
  294. UPDATE torrents
  295. SET
  296. Media = $T[Media],
  297. Format = $T[Format],
  298. Encoding = $T[Encoding],
  299. RemasterYear = $T[RemasterYear],
  300. Remastered = $T[Remastered],
  301. RemasterTitle = $T[RemasterTitle],
  302. RemasterRecordLabel = $T[RemasterRecordLabel],
  303. RemasterCatalogueNumber = $T[RemasterCatalogueNumber],
  304. Scene = $T[Scene],";
  305. */
  306. $SQL = "
  307. UPDATE torrents
  308. SET
  309. Media = $T[Media],
  310. Container = $T[Container],
  311. Codec = $T[Codec],
  312. Resolution = $T[Resolution],
  313. AudioFormat = $T[AudioFormat],
  314. Subbing = $T[Subbing],
  315. Language = $T[Language],
  316. Subber = $T[Subber],
  317. Archive = $T[Archive],
  318. MediaInfo = $T[MediaInfo],
  319. Censored = $T[Censored],
  320. Anonymous = $T[Anonymous],";
  321. if (check_perms('torrents_freeleech')) {
  322. $SQL .= "FreeTorrent = $T[FreeLeech],";
  323. $SQL .= "FreeLeechType = $T[FreeLeechType],";
  324. }
  325. if (check_perms('users_mod')) {
  326. /*
  327. if ($T[Format] !== "'FLAC'") {
  328. $SQL .= "
  329. HasLog = '0',
  330. HasCue = '0',";
  331. } else {
  332. $SQL .= "
  333. HasLog = $T[HasLog],
  334. HasCue = $T[HasCue],";
  335. }
  336. */
  337. $DB->query("
  338. SELECT TorrentID
  339. FROM torrents_bad_tags
  340. WHERE TorrentID = '$TorrentID'");
  341. list($btID) = $DB->next_record();
  342. if (!$btID && $Properties['BadTags']) {
  343. $DB->query("
  344. INSERT INTO torrents_bad_tags
  345. VALUES ($TorrentID, $LoggedUser[ID], NOW())");
  346. }
  347. if ($btID && !$Properties['BadTags']) {
  348. $DB->query("
  349. DELETE FROM torrents_bad_tags
  350. WHERE TorrentID = '$TorrentID'");
  351. }
  352. $DB->query("
  353. SELECT TorrentID
  354. FROM torrents_bad_folders
  355. WHERE TorrentID = '$TorrentID'");
  356. list($bfID) = $DB->next_record();
  357. if (!$bfID && $Properties['BadFolders']) {
  358. $DB->query("
  359. INSERT INTO torrents_bad_folders
  360. VALUES ($TorrentID, $LoggedUser[ID], NOW())");
  361. }
  362. if ($bfID && !$Properties['BadFolders']) {
  363. $DB->query("
  364. DELETE FROM torrents_bad_folders
  365. WHERE TorrentID = '$TorrentID'");
  366. }
  367. $DB->query("
  368. SELECT TorrentID
  369. FROM torrents_bad_files
  370. WHERE TorrentID = '$TorrentID'");
  371. list($bfiID) = $DB->next_record();
  372. if (!$bfiID && $Properties['BadFiles']) {
  373. $DB->query("
  374. INSERT INTO torrents_bad_files
  375. VALUES ($TorrentID, $LoggedUser[ID], NOW())");
  376. }
  377. if ($bfiID && !$Properties['BadFiles']) {
  378. $DB->query("
  379. DELETE FROM torrents_bad_files
  380. WHERE TorrentID = '$TorrentID'");
  381. }
  382. $DB->query("
  383. SELECT TorrentID
  384. FROM library_contest
  385. WHERE TorrentID = '$TorrentID'");
  386. list($lbID) = $DB->next_record();
  387. if (!$lbID && $Properties['LibraryUpload'] && $Properties['LibraryPoints'] > 0) {
  388. $DB->query("
  389. SELECT UserID
  390. FROM torrents
  391. WHERE ID = $TorrentID");
  392. list($UploaderID) = $DB->next_record();
  393. $DB->query("
  394. INSERT INTO library_contest
  395. VALUES ($UploaderID, $TorrentID, $Properties[LibraryPoints])");
  396. }
  397. if ($lbID && !$Properties['LibraryUpload']) {
  398. $DB->query("
  399. DELETE FROM library_contest
  400. WHERE TorrentID = '$TorrentID'");
  401. }
  402. }
  403. $SQL .= "
  404. Description = $T[TorrentDescription]
  405. WHERE ID = $TorrentID";
  406. $DB->query($SQL);
  407. if (check_perms('torrents_freeleech') && $Properties['FreeLeech'] != $CurFreeLeech) {
  408. Torrents::freeleech_torrents($TorrentID, $Properties['FreeLeech'], $Properties['FreeLeechType']);
  409. }
  410. $DB->query("
  411. SELECT GroupID, Time
  412. FROM torrents
  413. WHERE ID = '$TorrentID'");
  414. list($GroupID, $Time) = $DB->next_record();
  415. // Competition
  416. if (strtotime($Time) > 1241352173) {
  417. if ($_POST['log_score'] === '100') {
  418. $DB->query("
  419. INSERT IGNORE into users_points (GroupID, UserID, Points)
  420. VALUES ('$GroupID', '$UserID', '1')");
  421. }
  422. }
  423. // End competiton
  424. $DB->query("
  425. SELECT Enabled
  426. FROM users_main
  427. WHERE ID = $UserID");
  428. list($Enabled) = $DB->next_record();
  429. $DB->query("
  430. SELECT Name
  431. FROM torrents_group
  432. WHERE ID = $GroupID");
  433. list($Name) = $DB->next_record(MYSQLI_NUM, false);
  434. Misc::write_log("Torrent $TorrentID ($Name) in group $GroupID was edited by ".$LoggedUser['Username']." ($LogDetails)"); // todo: This is probably broken
  435. Torrents::write_group_log($GroupID, $TorrentID, $LoggedUser['ID'], $LogDetails, 0);
  436. $Cache->delete_value("torrents_details_$GroupID");
  437. $Cache->delete_value("torrent_download_$TorrentID");
  438. Torrents::update_hash($GroupID);
  439. // All done!
  440. header("Location: torrents.php?id=$GroupID");