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

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