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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  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. # todo: Associate containers with categories beforehand
  23. # It may have to happen structurally in config.php, e.g.,
  24. # $Categories = [
  25. # 'GazelleName' => [$Name, $Icon, $Description, $Containers],
  26. # ...
  27. # ];
  28. $Properties['FileTypes'] = [
  29. 'DNA' => $Containers,
  30. 'RNA' => $Containers,
  31. 'Proteins' => $ContainersProt,
  32. 'Imaging' => $ContainersGames,
  33. 'Extras' => $ContainersExtra
  34. ];
  35. $Properties['ArchiveTypes'] = [
  36. 'DNA' => $Archives,
  37. 'RNA' => $Archives,
  38. 'Proteins' => $Archives,
  39. 'Imaging' => $Archives,
  40. 'Extras' => $Archives
  41. ];
  42. $Properties['Remastered'] = (isset($_POST['remaster']))? 1 : 0;
  43. if ($Properties['Remastered']) {
  44. $Properties['UnknownRelease'] = (isset($_POST['unknown'])) ? 1 : 0;
  45. }
  46. if (!$Properties['Remastered']) {
  47. $Properties['UnknownRelease'] = 0;
  48. }
  49. $Properties['BadTags'] = (isset($_POST['bad_tags']))? 1 : 0;
  50. $Properties['BadFolders'] = (isset($_POST['bad_folders']))? 1 : 0;
  51. $Properties['BadFiles'] = (isset($_POST['bad_files'])) ? 1 : 0;
  52. $Properties['Trumpable'] = (isset($_POST['make_trumpable'])) ? 1 : 0;
  53. $Properties['Format'] = $_POST['format'];
  54. $Properties['Media'] = $_POST['media'];
  55. $Properties['Bitrate'] = $_POST['bitrate'];
  56. $Properties['Encoding'] = $_POST['bitrate'];
  57. $Properties['TorrentDescription'] = $_POST['release_desc'];
  58. $Properties['MediaInfo'] = $_POST['mediainfo'];
  59. $Properties['Name'] = $_POST['title'];
  60. $Properties['Container'] = $_POST['container'];
  61. $Properties['Codec'] = $_POST['codec'];
  62. $Properties['Resolution'] = $_POST['resolution'];
  63. $Properties['AudioFormat'] = $_POST['audioformat'];
  64. $Properties['Subbing'] = $_POST['sub'];
  65. $Properties['Language'] = $_POST['lang'];
  66. $Properties['Subber']= $_POST['subber'];
  67. $Properties['Censored'] = (isset($_POST['censored'])) ? '1' : '0';
  68. $Properties['Anonymous'] = (isset($_POST['anonymous'])) ? '1' : '0';
  69. $Properties['Archive'] = (isset($_POST['archive']) && $_POST['archive'] != '---') ? $_POST['archive'] : '';
  70. if ($_POST['album_desc']) {
  71. $Properties['GroupDescription'] = $_POST['album_desc'];
  72. }
  73. if (check_perms('torrents_freeleech')) {
  74. $Free = (int)$_POST['freeleech'];
  75. if (!in_array($Free, array(0, 1, 2))) {
  76. error(404);
  77. }
  78. $Properties['FreeLeech'] = $Free;
  79. if ($Free === 0) {
  80. $FreeType = 0;
  81. } else {
  82. $FreeType = (int)$_POST['freeleechtype'];
  83. if (!in_array($Free, array(0, 1, 2, 3))) {
  84. error(404);
  85. }
  86. }
  87. $Properties['FreeLeechType'] = $FreeType;
  88. }
  89. //******************************************************************************//
  90. //--------------- Validate data in edit form -----------------------------------//
  91. /*
  92. $DB->query("
  93. SELECT UserID, Remastered, RemasterYear, FreeTorrent
  94. FROM torrents
  95. WHERE ID = $TorrentID");
  96. */
  97. $DB->query("
  98. SELECT UserID, FreeTorrent
  99. FROM torrents
  100. WHERE ID = $TorrentID");
  101. if (!$DB->has_results()) {
  102. error(404);
  103. }
  104. // list($UserID, $Remastered, $RemasterYear, $CurFreeLeech) = $DB->next_record(MYSQLI_BOTH, false);
  105. list($UserID, $CurFreeLeech) = $DB->next_record(MYSQLI_BOTH, false);
  106. if ($LoggedUser['ID'] != $UserID && !check_perms('torrents_edit')) {
  107. error(403);
  108. }
  109. /* todo: Check strict equality and untangle features
  110. if ($Remastered === '1' && !$RemasterYear && !check_perms('edit_unknowns')) {
  111. error(403);
  112. }
  113. */
  114. if ($Properties['UnknownRelease'] && !($Remastered === '1' && !$RemasterYear) && !check_perms('edit_unknowns')) {
  115. // It's Unknown now, and it wasn't before
  116. if ($LoggedUser['ID'] !== $UserID) {
  117. // Hax
  118. die();
  119. }
  120. }
  121. $Validate->SetFields(
  122. 'type',
  123. '1',
  124. 'number',
  125. 'Not a valid type',
  126. array('maxlength' => count($Categories), 'minlength' => 1)
  127. );
  128. /* Ugh
  129. switch ($Type) {
  130. case 'Music':
  131. if (!empty($Properties['Remastered']) && !$Properties['UnknownRelease']) {
  132. $Validate->SetFields(
  133. 'remaster_year',
  134. '1',
  135. 'number',
  136. 'Year of remaster/re-issue must be entered'
  137. );
  138. } else {
  139. $Validate->SetFields(
  140. 'remaster_year',
  141. '0',
  142. 'number',
  143. 'Invalid remaster year'
  144. );
  145. }
  146. if (!empty($Properties['Remastered']) && !$Properties['UnknownRelease'] && $Properties['RemasterYear'] < 1982 && $Properties['Media'] === 'CD') {
  147. error('You have selected a year for an album that predates the medium you say it was created on');
  148. header("Location: torrents.php?action=edit&id=$TorrentID");
  149. die();
  150. }
  151. $Validate->SetFields(
  152. 'remaster_title',
  153. '0',
  154. 'string',
  155. 'Remaster title must be between 2 and 80 characters',
  156. array('maxlength' => 80, 'minlength' => 2)
  157. );
  158. if ($Properties['RemasterTitle'] === 'Original Release') {
  159. error('"Original Release" is not a valid remaster title');
  160. header("Location: torrents.php?action=edit&id=$TorrentID");
  161. die();
  162. }
  163. $Validate->SetFields(
  164. 'remaster_record_label',
  165. '0',
  166. 'string',
  167. 'Remaster record label must be between 2 and 80 characters',
  168. array('maxlength' => 80, 'minlength' => 2)
  169. );
  170. $Validate->SetFields(
  171. 'remaster_catalogue_number',
  172. '0',
  173. 'string',
  174. 'Remaster catalogue number must be between 2 and 80 characters',
  175. array('maxlength' => 80, 'minlength' => 2)
  176. );
  177. $Validate->SetFields(
  178. 'format',
  179. '1',
  180. 'inarray',
  181. 'Not a valid format',
  182. array('inarray' => $Formats)
  183. );
  184. $Validate->SetFields(
  185. 'bitrate',
  186. '1',
  187. 'inarray',
  188. 'You must choose a bitrate',
  189. array('inarray' => $Bitrates)
  190. );
  191. // Handle 'other' bitrates
  192. if ($Properties['Encoding'] === 'Other') {
  193. $Validate->SetFields(
  194. 'other_bitrate',
  195. '1',
  196. 'text',
  197. 'You must enter the other bitrate (max length: 9 characters)',
  198. array('maxlength' => 9)
  199. );
  200. $enc = trim($_POST['other_bitrate']);
  201. if (isset($_POST['vbr'])) {
  202. $enc .= ' (VBR)';
  203. }
  204. $Properties['Encoding'] = $enc;
  205. $Properties['Bitrate'] = $enc;
  206. } else {
  207. $Validate->SetFields(
  208. 'bitrate',
  209. '1',
  210. 'inarray',
  211. 'You must choose a bitrate',
  212. array('inarray' => $Bitrates)
  213. );
  214. }
  215. $Validate->SetFields(
  216. 'media',
  217. '1',
  218. 'inarray',
  219. 'Not a valid media',
  220. array('inarray' => $Media)
  221. );
  222. $Validate->SetFields(
  223. 'release_desc',
  224. '0',
  225. 'string',
  226. 'Invalid release description',
  227. array('maxlength' => 1000000, 'minlength' => 0)
  228. );
  229. break;
  230. default:
  231. break;
  232. }
  233. */
  234. $Err = $Validate->ValidateForm($_POST); // Validate the form
  235. if ($Properties['Remastered'] && !$Properties['RemasterYear']) {
  236. // Unknown Edit!
  237. if ($LoggedUser['ID'] === $UserID || check_perms('edit_unknowns')) {
  238. // Fine!
  239. } else {
  240. $Err = "You may not edit someone else's upload to unknown release";
  241. }
  242. }
  243. // Strip out Amazon's padding
  244. /*
  245. $AmazonReg = '/(http:\/\/ecx.images-amazon.com\/images\/.+)(\._.*_\.jpg)/i';
  246. $Matches = [];
  247. if (preg_match($RegX, $Properties['Image'], $Matches)) {
  248. $Properties['Image'] = $Matches[1].'.jpg';
  249. }
  250. ImageTools::blacklisted($Properties['Image']);
  251. */
  252. if ($Err) { // Show the upload form, with the data the user entered
  253. if (check_perms('site_debug')) {
  254. die($Err);
  255. }
  256. error($Err);
  257. }
  258. //******************************************************************************//
  259. //--------------- Make variables ready for database input ----------------------//
  260. // Shorten and escape $Properties for database input
  261. $T = [];
  262. foreach ($Properties as $Key => $Value) {
  263. $T[$Key] = "'".db_string(trim($Value))."'";
  264. if (!$T[$Key]) {
  265. $T[$Key] = null;
  266. }
  267. }
  268. $T['Censored'] = $Properties['Censored'];
  269. $T['Anonymous'] = $Properties['Anonymous'];
  270. //******************************************************************************//
  271. //--------------- Start database stuff -----------------------------------------//
  272. $DBTorVals = [];
  273. $DB->query("
  274. SELECT Media, Container, Codec, Resolution, AudioFormat, Subbing, Language, Description, MediaInfo, Censored, Anonymous, Archive, Subber
  275. FROM torrents
  276. WHERE ID = $TorrentID");
  277. $DBTorVals = $DB->to_array(false, MYSQLI_ASSOC);
  278. $DBTorVals = $DBTorVals[0];
  279. $LogDetails = '';
  280. foreach ($DBTorVals as $Key => $Value) {
  281. $Value = "'$Value'";
  282. if ($Value != $T[$Key]) {
  283. if (!isset($T[$Key])) {
  284. continue;
  285. }
  286. if ((empty($Value) && empty($T[$Key])) || ($Value == "'0'" && $T[$Key] == "''")) {
  287. continue;
  288. }
  289. if ($LogDetails == '') {
  290. $LogDetails = "$Key: $Value -> ".$T[$Key];
  291. } else {
  292. $LogDetails = "$LogDetails, $Key: $Value -> ".$T[$Key];
  293. }
  294. }
  295. }
  296. $T['Censored'] = $Properties['Censored'];
  297. $T['Anonymous'] = $Properties['Anonymous'];
  298. // Update info for the torrent
  299. /*
  300. $SQL = "
  301. UPDATE torrents
  302. SET
  303. Media = $T[Media],
  304. Format = $T[Format],
  305. Encoding = $T[Encoding],
  306. RemasterYear = $T[RemasterYear],
  307. Remastered = $T[Remastered],
  308. RemasterTitle = $T[RemasterTitle],
  309. RemasterRecordLabel = $T[RemasterRecordLabel],
  310. RemasterCatalogueNumber = $T[RemasterCatalogueNumber],
  311. Scene = $T[Scene],";
  312. */
  313. $SQL = "
  314. UPDATE torrents
  315. SET
  316. Media = $T[Media],
  317. Container = $T[Container],
  318. Codec = $T[Codec],
  319. Resolution = $T[Resolution],
  320. AudioFormat = $T[AudioFormat],
  321. Subbing = $T[Subbing],
  322. Language = $T[Language],
  323. Subber = $T[Subber],
  324. Archive = $T[Archive],
  325. MediaInfo = $T[MediaInfo],
  326. Censored = $T[Censored],
  327. Anonymous = $T[Anonymous],";
  328. if (check_perms('torrents_freeleech')) {
  329. $SQL .= "FreeTorrent = $T[FreeLeech],";
  330. $SQL .= "FreeLeechType = $T[FreeLeechType],";
  331. }
  332. if (check_perms('users_mod')) {
  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");