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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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. $TypeID = (int)$_POST['type'];
  19. $Type = $Categories[$TypeID-1];
  20. $TorrentID = (int)$_POST['torrentid'];
  21. $Properties['Remastered'] = (isset($_POST['remaster']))? 1 : 0;
  22. if ($Properties['Remastered']) {
  23. $Properties['UnknownRelease'] = (isset($_POST['unknown'])) ? 1 : 0;
  24. }
  25. if (!$Properties['Remastered']) {
  26. $Properties['UnknownRelease'] = 0;
  27. }
  28. $Properties['BadTags'] = (isset($_POST['bad_tags']))? 1 : 0;
  29. $Properties['BadFolders'] = (isset($_POST['bad_folders']))? 1 : 0;
  30. $Properties['BadFiles'] = (isset($_POST['bad_files'])) ? 1 : 0;
  31. $Properties['Format'] = $_POST['format'];
  32. $Properties['Media'] = $_POST['media'];
  33. $Properties['Bitrate'] = $_POST['bitrate'];
  34. $Properties['Encoding'] = $_POST['bitrate'];
  35. $Properties['Trumpable'] = (isset($_POST['make_trumpable'])) ? 1 : 0;
  36. $Properties['TorrentDescription'] = $_POST['release_desc'];
  37. $Properties['MediaInfo'] = $_POST['mediainfo'];
  38. $Properties['Name'] = $_POST['title'];
  39. $Properties['Container'] = $_POST['container'];
  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'])) ? $_POST['censored'] : 0;
  47. $Properties['Archive'] = (isset($_POST['archive']) && $_POST['archive'] != '---') ? $_POST['archive'] : '';
  48. if ($_POST['album_desc']) {
  49. $Properties['GroupDescription'] = $_POST['album_desc'];
  50. }
  51. if (check_perms('torrents_freeleech')) {
  52. $Free = (int)$_POST['freeleech'];
  53. if (!in_array($Free, array(0, 1, 2))) {
  54. error(404);
  55. }
  56. $Properties['FreeLeech'] = $Free;
  57. if ($Free == 0) {
  58. $FreeType = 0;
  59. } else {
  60. $FreeType = (int)$_POST['freeleechtype'];
  61. if (!in_array($Free, array(0, 1, 2, 3))) {
  62. error(404);
  63. }
  64. }
  65. $Properties['FreeLeechType'] = $FreeType;
  66. }
  67. //******************************************************************************//
  68. //--------------- Validate data in edit form -----------------------------------//
  69. /*
  70. $DB->query("
  71. SELECT UserID, Remastered, RemasterYear, FreeTorrent
  72. FROM torrents
  73. WHERE ID = $TorrentID");
  74. */
  75. $DB->query("
  76. SELECT UserID, FreeTorrent
  77. FROM torrents
  78. WHERE ID = $TorrentID");
  79. if (!$DB->has_results()) {
  80. error(404);
  81. }
  82. // list($UserID, $Remastered, $RemasterYear, $CurFreeLeech) = $DB->next_record(MYSQLI_BOTH, false);
  83. list($UserID, $CurFreeLeech) = $DB->next_record(MYSQLI_BOTH, false);
  84. if ($LoggedUser['ID'] != $UserID && !check_perms('torrents_edit')) {
  85. error(403);
  86. }
  87. /*
  88. if ($Remastered == '1' && !$RemasterYear && !check_perms('edit_unknowns')) {
  89. error(403);
  90. }
  91. */
  92. if ($Properties['UnknownRelease'] && !($Remastered == '1' && !$RemasterYear) && !check_perms('edit_unknowns')) {
  93. //It's Unknown now, and it wasn't before
  94. if ($LoggedUser['ID'] != $UserID) {
  95. //Hax
  96. die();
  97. }
  98. }
  99. $Validate->SetFields('type', '1', 'number', 'Not a valid type.', array('maxlength' => count($Categories), 'minlength' => 1));
  100. switch ($Type) {
  101. case 'Music':
  102. if (!empty($Properties['Remastered']) && !$Properties['UnknownRelease']) {
  103. $Validate->SetFields('remaster_year', '1', 'number', 'Year of remaster/re-issue must be entered.');
  104. } else {
  105. $Validate->SetFields('remaster_year', '0','number', 'Invalid remaster year.');
  106. }
  107. if (!empty($Properties['Remastered']) && !$Properties['UnknownRelease'] && $Properties['RemasterYear'] < 1982 && $Properties['Media'] == 'CD') {
  108. error('You have selected a year for an album that predates the medium you say it was created on.');
  109. header("Location: torrents.php?action=edit&id=$TorrentID");
  110. die();
  111. }
  112. $Validate->SetFields('remaster_title', '0', 'string', 'Remaster title must be between 2 and 80 characters.', array('maxlength' => 80, 'minlength' => 2));
  113. if ($Properties['RemasterTitle'] == 'Original Release') {
  114. error('"Original Release" is not a valid remaster title.');
  115. header("Location: torrents.php?action=edit&id=$TorrentID");
  116. die();
  117. }
  118. $Validate->SetFields('remaster_record_label', '0', 'string', 'Remaster record label must be between 2 and 80 characters.', array('maxlength' => 80, 'minlength' => 2));
  119. $Validate->SetFields('remaster_catalogue_number', '0', 'string', 'Remaster catalogue number must be between 2 and 80 characters.', array('maxlength' => 80, 'minlength' => 2));
  120. $Validate->SetFields('format', '1', 'inarray', 'Not a valid format.', array('inarray' => $Formats));
  121. $Validate->SetFields('bitrate', '1', 'inarray', 'You must choose a bitrate.', array('inarray' => $Bitrates));
  122. // Handle 'other' bitrates
  123. if ($Properties['Encoding'] == 'Other') {
  124. $Validate->SetFields('other_bitrate', '1', 'text', 'You must enter the other bitrate (max length: 9 characters).', array('maxlength' => 9));
  125. $enc = trim($_POST['other_bitrate']);
  126. if (isset($_POST['vbr'])) {
  127. $enc .= ' (VBR)';
  128. }
  129. $Properties['Encoding'] = $enc;
  130. $Properties['Bitrate'] = $enc;
  131. } else {
  132. $Validate->SetFields('bitrate', '1', 'inarray', 'You must choose a bitrate.', array('inarray' => $Bitrates));
  133. }
  134. $Validate->SetFields('media', '1', 'inarray', 'Not a valid media.', array('inarray' => $Media));
  135. $Validate->SetFields('release_desc', '0', 'string', 'Invalid release description.', array('maxlength' => 1000000, 'minlength' => 0));
  136. break;
  137. case 'Audiobooks':
  138. case 'Comedy':
  139. /*$Validate->SetFields('title', '1', 'string', 'Title must be between 2 and 300 characters.', array('maxlength' => 300, 'minlength' => 2));
  140. ^ this is commented out because there is no title field on these pages*/
  141. $Validate->SetFields('year', '1', 'number', 'The year of the release must be entered.');
  142. $Validate->SetFields('format', '1', 'inarray', 'Not a valid format.', array('inarray' => $Formats));
  143. $Validate->SetFields('bitrate', '1', 'inarray', 'You must choose a bitrate.', array('inarray' => $Bitrates));
  144. // Handle 'other' bitrates
  145. if ($Properties['Encoding'] == 'Other') {
  146. $Validate->SetFields('other_bitrate', '1', 'text', 'You must enter the other bitrate (max length: 9 characters).', array('maxlength' => 9));
  147. $enc = trim($_POST['other_bitrate']);
  148. if (isset($_POST['vbr'])) {
  149. $enc .= ' (VBR)';
  150. }
  151. $Properties['Encoding'] = $enc;
  152. $Properties['Bitrate'] = $enc;
  153. } else {
  154. $Validate->SetFields('bitrate', '1', 'inarray', 'You must choose a bitrate.', array('inarray' => $Bitrates));
  155. }
  156. $Validate->SetFields('release_desc', '0', 'string', 'The release description has a minimum length of 10 characters.', array('maxlength' => 1000000, 'minlength' => 10));
  157. break;
  158. case 'Applications':
  159. case 'Comics':
  160. case 'E-Books':
  161. case 'E-Learning Videos':
  162. /*$Validate->SetFields('title', '1', 'string', 'Title must be between 2 and 300 characters.', array('maxlength' => 300, 'minlength' => 2));
  163. ^ this is commented out because there is no title field on these pages*/
  164. break;
  165. }
  166. $Err = $Validate->ValidateForm($_POST); // Validate the form
  167. if ($Properties['Remastered'] && !$Properties['RemasterYear']) {
  168. //Unknown Edit!
  169. if ($LoggedUser['ID'] == $UserID || check_perms('edit_unknowns')) {
  170. //Fine!
  171. } else {
  172. $Err = "You may not edit someone else's upload to unknown release.";
  173. }
  174. }
  175. // Strip out Amazon's padding
  176. $AmazonReg = '/(http:\/\/ecx.images-amazon.com\/images\/.+)(\._.*_\.jpg)/i';
  177. $Matches = array();
  178. if (preg_match($RegX, $Properties['Image'], $Matches)) {
  179. $Properties['Image'] = $Matches[1].'.jpg';
  180. }
  181. ImageTools::blacklisted($Properties['Image']);
  182. if ($Err) { // Show the upload form, with the data the user entered
  183. if (check_perms('site_debug')) {
  184. die($Err);
  185. }
  186. error($Err);
  187. }
  188. //******************************************************************************//
  189. //--------------- Make variables ready for database input ----------------------//
  190. // Shorten and escape $Properties for database input
  191. $T = array();
  192. foreach ($Properties as $Key => $Value) {
  193. $T[$Key] = "'".db_string(trim($Value))."'";
  194. if (!$T[$Key]) {
  195. $T[$Key] = null;
  196. }
  197. }
  198. //******************************************************************************//
  199. //--------------- Start database stuff -----------------------------------------//
  200. $DBTorVals = array();
  201. /*
  202. $DB->query("
  203. SELECT Media, Format, Encoding, RemasterYear, Remastered, RemasterTItle, RemasterRecordLabel, RemasterCatalogueNumber, Scene, Description
  204. FROM torrents
  205. WHERE ID = $TorrentID");
  206. */
  207. $DB->query("
  208. SELECT Media, Container, Codec, Resolution, AudioFormat, Subbing, Language, Description, MediaInfo, Censored, Archive, Subber
  209. FROM torrents
  210. WHERE ID = $TorrentID");
  211. $DBTorVals = $DB->to_array(false, MYSQLI_ASSOC);
  212. $DBTorVals = $DBTorVals[0];
  213. $LogDetails = '';
  214. foreach ($DBTorVals as $Key => $Value) {
  215. $Value = "'$Value'";
  216. if ($Value != $T[$Key]) {
  217. if (!isset($T[$Key])) {
  218. continue;
  219. }
  220. if ((empty($Value) && empty($T[$Key])) || ($Value == "'0'" && $T[$Key] == "''")) {
  221. continue;
  222. }
  223. if ($LogDetails == '') {
  224. $LogDetails = "$Key: $Value -> ".$T[$Key];
  225. } else {
  226. $LogDetails = "$LogDetails, $Key: $Value -> ".$T[$Key];
  227. }
  228. }
  229. }
  230. $T['Censored'] = $Properties['Censored'];
  231. // Update info for the torrent
  232. /*
  233. $SQL = "
  234. UPDATE torrents
  235. SET
  236. Media = $T[Media],
  237. Format = $T[Format],
  238. Encoding = $T[Encoding],
  239. RemasterYear = $T[RemasterYear],
  240. Remastered = $T[Remastered],
  241. RemasterTitle = $T[RemasterTitle],
  242. RemasterRecordLabel = $T[RemasterRecordLabel],
  243. RemasterCatalogueNumber = $T[RemasterCatalogueNumber],
  244. Scene = $T[Scene],";
  245. */
  246. $SQL = "
  247. UPDATE torrents
  248. SET
  249. Media = $T[Media],
  250. Container = $T[Container],
  251. Codec = $T[Codec],
  252. Resolution = $T[Resolution],
  253. AudioFormat = $T[AudioFormat],
  254. Subbing = $T[Subbing],
  255. Language = $T[Language],
  256. Subber = $T[Subber],
  257. Archive = $T[Archive],
  258. MediaInfo = $T[MediaInfo],
  259. Censored = $T[Censored],";
  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], '".sqltime()."')");
  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], '".sqltime()."')");
  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], '".sqltime()."')");
  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. ?>