Oppaitime'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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <?
  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['Format'] = $_POST['format'];
  33. $Properties['Media'] = $_POST['media'];
  34. $Properties['Bitrate'] = $_POST['bitrate'];
  35. $Properties['Encoding'] = $_POST['bitrate'];
  36. $Properties['Trumpable'] = (isset($_POST['make_trumpable'])) ? 1 : 0;
  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. if ($Remastered == '1' && !$RemasterYear && !check_perms('edit_unknowns')) {
  91. error(403);
  92. }
  93. */
  94. if ($Properties['UnknownRelease'] && !($Remastered == '1' && !$RemasterYear) && !check_perms('edit_unknowns')) {
  95. //It's Unknown now, and it wasn't before
  96. if ($LoggedUser['ID'] != $UserID) {
  97. //Hax
  98. die();
  99. }
  100. }
  101. $Validate->SetFields('type', '1', 'number', 'Not a valid type.', array('maxlength' => count($Categories), 'minlength' => 1));
  102. switch ($Type) {
  103. case 'Music':
  104. if (!empty($Properties['Remastered']) && !$Properties['UnknownRelease']) {
  105. $Validate->SetFields('remaster_year', '1', 'number', 'Year of remaster/re-issue must be entered.');
  106. } else {
  107. $Validate->SetFields('remaster_year', '0','number', 'Invalid remaster year.');
  108. }
  109. if (!empty($Properties['Remastered']) && !$Properties['UnknownRelease'] && $Properties['RemasterYear'] < 1982 && $Properties['Media'] == 'CD') {
  110. error('You have selected a year for an album that predates the medium you say it was created on.');
  111. header("Location: torrents.php?action=edit&id=$TorrentID");
  112. die();
  113. }
  114. $Validate->SetFields('remaster_title', '0', 'string', 'Remaster title must be between 2 and 80 characters.', array('maxlength' => 80, 'minlength' => 2));
  115. if ($Properties['RemasterTitle'] == 'Original Release') {
  116. error('"Original Release" is not a valid remaster title.');
  117. header("Location: torrents.php?action=edit&id=$TorrentID");
  118. die();
  119. }
  120. $Validate->SetFields('remaster_record_label', '0', 'string', 'Remaster record label must be between 2 and 80 characters.', array('maxlength' => 80, 'minlength' => 2));
  121. $Validate->SetFields('remaster_catalogue_number', '0', 'string', 'Remaster catalogue number must be between 2 and 80 characters.', array('maxlength' => 80, 'minlength' => 2));
  122. $Validate->SetFields('format', '1', 'inarray', 'Not a valid format.', array('inarray' => $Formats));
  123. $Validate->SetFields('bitrate', '1', 'inarray', 'You must choose a bitrate.', array('inarray' => $Bitrates));
  124. // Handle 'other' bitrates
  125. if ($Properties['Encoding'] == 'Other') {
  126. $Validate->SetFields('other_bitrate', '1', 'text', 'You must enter the other bitrate (max length: 9 characters).', array('maxlength' => 9));
  127. $enc = trim($_POST['other_bitrate']);
  128. if (isset($_POST['vbr'])) {
  129. $enc .= ' (VBR)';
  130. }
  131. $Properties['Encoding'] = $enc;
  132. $Properties['Bitrate'] = $enc;
  133. } else {
  134. $Validate->SetFields('bitrate', '1', 'inarray', 'You must choose a bitrate.', array('inarray' => $Bitrates));
  135. }
  136. $Validate->SetFields('media', '1', 'inarray', 'Not a valid media.', array('inarray' => $Media));
  137. $Validate->SetFields('release_desc', '0', 'string', 'Invalid release description.', array('maxlength' => 1000000, 'minlength' => 0));
  138. break;
  139. case 'Audiobooks':
  140. case 'Comedy':
  141. /*$Validate->SetFields('title', '1', 'string', 'Title must be between 2 and 300 characters.', array('maxlength' => 300, 'minlength' => 2));
  142. ^ this is commented out because there is no title field on these pages*/
  143. $Validate->SetFields('year', '1', 'number', 'The year of the release must be entered.');
  144. $Validate->SetFields('format', '1', 'inarray', 'Not a valid format.', array('inarray' => $Formats));
  145. $Validate->SetFields('bitrate', '1', 'inarray', 'You must choose a bitrate.', array('inarray' => $Bitrates));
  146. // Handle 'other' bitrates
  147. if ($Properties['Encoding'] == 'Other') {
  148. $Validate->SetFields('other_bitrate', '1', 'text', 'You must enter the other bitrate (max length: 9 characters).', array('maxlength' => 9));
  149. $enc = trim($_POST['other_bitrate']);
  150. if (isset($_POST['vbr'])) {
  151. $enc .= ' (VBR)';
  152. }
  153. $Properties['Encoding'] = $enc;
  154. $Properties['Bitrate'] = $enc;
  155. } else {
  156. $Validate->SetFields('bitrate', '1', 'inarray', 'You must choose a bitrate.', array('inarray' => $Bitrates));
  157. }
  158. $Validate->SetFields('release_desc', '0', 'string', 'The release description has a minimum length of 10 characters.', array('maxlength' => 1000000, 'minlength' => 10));
  159. break;
  160. case 'Applications':
  161. case 'Comics':
  162. case 'E-Books':
  163. case 'E-Learning Videos':
  164. /*$Validate->SetFields('title', '1', 'string', 'Title must be between 2 and 300 characters.', array('maxlength' => 300, 'minlength' => 2));
  165. ^ this is commented out because there is no title field on these pages*/
  166. break;
  167. }
  168. $Err = $Validate->ValidateForm($_POST); // Validate the form
  169. if ($Properties['Remastered'] && !$Properties['RemasterYear']) {
  170. //Unknown Edit!
  171. if ($LoggedUser['ID'] == $UserID || check_perms('edit_unknowns')) {
  172. //Fine!
  173. } else {
  174. $Err = "You may not edit someone else's upload to unknown release.";
  175. }
  176. }
  177. // Strip out Amazon's padding
  178. $AmazonReg = '/(http:\/\/ecx.images-amazon.com\/images\/.+)(\._.*_\.jpg)/i';
  179. $Matches = [];
  180. if (preg_match($RegX, $Properties['Image'], $Matches)) {
  181. $Properties['Image'] = $Matches[1].'.jpg';
  182. }
  183. ImageTools::blacklisted($Properties['Image']);
  184. if ($Err) { // Show the upload form, with the data the user entered
  185. if (check_perms('site_debug')) {
  186. die($Err);
  187. }
  188. error($Err);
  189. }
  190. //******************************************************************************//
  191. //--------------- Make variables ready for database input ----------------------//
  192. // Shorten and escape $Properties for database input
  193. $T = [];
  194. foreach ($Properties as $Key => $Value) {
  195. $T[$Key] = "'".db_string(trim($Value))."'";
  196. if (!$T[$Key]) {
  197. $T[$Key] = null;
  198. }
  199. }
  200. $T['Censored'] = $Properties['Censored'];
  201. $T['Anonymous'] = $Properties['Anonymous'];
  202. //******************************************************************************//
  203. //--------------- Start database stuff -----------------------------------------//
  204. $DBTorVals = [];
  205. $DB->query("
  206. SELECT Media, Container, Codec, Resolution, AudioFormat, Subbing, Language, Description, MediaInfo, Censored, Anonymous, Archive, Subber
  207. FROM torrents
  208. WHERE ID = $TorrentID");
  209. $DBTorVals = $DB->to_array(false, MYSQLI_ASSOC);
  210. $DBTorVals = $DBTorVals[0];
  211. $LogDetails = '';
  212. foreach ($DBTorVals as $Key => $Value) {
  213. $Value = "'$Value'";
  214. if ($Value != $T[$Key]) {
  215. if (!isset($T[$Key])) {
  216. continue;
  217. }
  218. if ((empty($Value) && empty($T[$Key])) || ($Value == "'0'" && $T[$Key] == "''")) {
  219. continue;
  220. }
  221. if ($LogDetails == '') {
  222. $LogDetails = "$Key: $Value -> ".$T[$Key];
  223. } else {
  224. $LogDetails = "$LogDetails, $Key: $Value -> ".$T[$Key];
  225. }
  226. }
  227. }
  228. $T['Censored'] = $Properties['Censored'];
  229. $T['Anonymous'] = $Properties['Anonymous'];
  230. // Update info for the torrent
  231. /*
  232. $SQL = "
  233. UPDATE torrents
  234. SET
  235. Media = $T[Media],
  236. Format = $T[Format],
  237. Encoding = $T[Encoding],
  238. RemasterYear = $T[RemasterYear],
  239. Remastered = $T[Remastered],
  240. RemasterTitle = $T[RemasterTitle],
  241. RemasterRecordLabel = $T[RemasterRecordLabel],
  242. RemasterCatalogueNumber = $T[RemasterCatalogueNumber],
  243. Scene = $T[Scene],";
  244. */
  245. $SQL = "
  246. UPDATE torrents
  247. SET
  248. Media = $T[Media],
  249. Container = $T[Container],
  250. Codec = $T[Codec],
  251. Resolution = $T[Resolution],
  252. AudioFormat = $T[AudioFormat],
  253. Subbing = $T[Subbing],
  254. Language = $T[Language],
  255. Subber = $T[Subber],
  256. Archive = $T[Archive],
  257. MediaInfo = $T[MediaInfo],
  258. Censored = $T[Censored],
  259. Anonymous = $T[Anonymous],";
  260. if (check_perms('torrents_freeleech')) {
  261. $SQL .= "FreeTorrent = $T[FreeLeech],";
  262. $SQL .= "FreeLeechType = $T[FreeLeechType],";
  263. }
  264. if (check_perms('users_mod')) {
  265. /* if ($T[Format] != "'FLAC'") {
  266. $SQL .= "
  267. HasLog = '0',
  268. HasCue = '0',";
  269. } else {
  270. $SQL .= "
  271. HasLog = $T[HasLog],
  272. HasCue = $T[HasCue],";
  273. }
  274. */
  275. $DB->query("
  276. SELECT TorrentID
  277. FROM torrents_bad_tags
  278. WHERE TorrentID = '$TorrentID'");
  279. list($btID) = $DB->next_record();
  280. if (!$btID && $Properties['BadTags']) {
  281. $DB->query("
  282. INSERT INTO torrents_bad_tags
  283. VALUES ($TorrentID, $LoggedUser[ID], NOW())");
  284. }
  285. if ($btID && !$Properties['BadTags']) {
  286. $DB->query("
  287. DELETE FROM torrents_bad_tags
  288. WHERE TorrentID = '$TorrentID'");
  289. }
  290. $DB->query("
  291. SELECT TorrentID
  292. FROM torrents_bad_folders
  293. WHERE TorrentID = '$TorrentID'");
  294. list($bfID) = $DB->next_record();
  295. if (!$bfID && $Properties['BadFolders']) {
  296. $DB->query("
  297. INSERT INTO torrents_bad_folders
  298. VALUES ($TorrentID, $LoggedUser[ID], NOW())");
  299. }
  300. if ($bfID && !$Properties['BadFolders']) {
  301. $DB->query("
  302. DELETE FROM torrents_bad_folders
  303. WHERE TorrentID = '$TorrentID'");
  304. }
  305. $DB->query("
  306. SELECT TorrentID
  307. FROM torrents_bad_files
  308. WHERE TorrentID = '$TorrentID'");
  309. list($bfiID) = $DB->next_record();
  310. if (!$bfiID && $Properties['BadFiles']) {
  311. $DB->query("
  312. INSERT INTO torrents_bad_files
  313. VALUES ($TorrentID, $LoggedUser[ID], NOW())");
  314. }
  315. if ($bfiID && !$Properties['BadFiles']) {
  316. $DB->query("
  317. DELETE FROM torrents_bad_files
  318. WHERE TorrentID = '$TorrentID'");
  319. }
  320. $DB->query("
  321. SELECT TorrentID
  322. FROM library_contest
  323. WHERE TorrentID = '$TorrentID'");
  324. list($lbID) = $DB->next_record();
  325. if (!$lbID && $Properties['LibraryUpload'] && $Properties['LibraryPoints'] > 0) {
  326. $DB->query("
  327. SELECT UserID
  328. FROM torrents
  329. WHERE ID = $TorrentID");
  330. list($UploaderID) = $DB->next_record();
  331. $DB->query("
  332. INSERT INTO library_contest
  333. VALUES ($UploaderID, $TorrentID, $Properties[LibraryPoints])");
  334. }
  335. if ($lbID && !$Properties['LibraryUpload']) {
  336. $DB->query("
  337. DELETE FROM library_contest
  338. WHERE TorrentID = '$TorrentID'");
  339. }
  340. }
  341. $SQL .= "
  342. Description = $T[TorrentDescription]
  343. WHERE ID = $TorrentID";
  344. $DB->query($SQL);
  345. if (check_perms('torrents_freeleech') && $Properties['FreeLeech'] != $CurFreeLeech) {
  346. Torrents::freeleech_torrents($TorrentID, $Properties['FreeLeech'], $Properties['FreeLeechType']);
  347. }
  348. $DB->query("
  349. SELECT GroupID, Time
  350. FROM torrents
  351. WHERE ID = '$TorrentID'");
  352. list($GroupID, $Time) = $DB->next_record();
  353. // Competition
  354. if (strtotime($Time) > 1241352173) {
  355. if ($_POST['log_score'] == '100') {
  356. $DB->query("
  357. INSERT IGNORE into users_points (GroupID, UserID, Points)
  358. VALUES ('$GroupID', '$UserID', '1')");
  359. }
  360. }
  361. // End competiton
  362. $DB->query("
  363. SELECT Enabled
  364. FROM users_main
  365. WHERE ID = $UserID");
  366. list($Enabled) = $DB->next_record();
  367. $DB->query("
  368. SELECT Name
  369. FROM torrents_group
  370. WHERE ID = $GroupID");
  371. list($Name) = $DB->next_record(MYSQLI_NUM, false);
  372. Misc::write_log("Torrent $TorrentID ($Name) in group $GroupID was edited by ".$LoggedUser['Username']." ($LogDetails)"); // TODO: this is probably broken
  373. Torrents::write_group_log($GroupID, $TorrentID, $LoggedUser['ID'], $LogDetails, 0);
  374. $Cache->delete_value("torrents_details_$GroupID");
  375. $Cache->delete_value("torrent_download_$TorrentID");
  376. Torrents::update_hash($GroupID);
  377. // All done!
  378. header("Location: torrents.php?id=$GroupID");
  379. ?>