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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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'])) ? 1 : 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. $T['Censored'] = $Properties['Censored'];
  199. //******************************************************************************//
  200. //--------------- Start database stuff -----------------------------------------//
  201. $DBTorVals = array();
  202. /*
  203. $DB->query("
  204. SELECT Media, Format, Encoding, RemasterYear, Remastered, RemasterTItle, RemasterRecordLabel, RemasterCatalogueNumber, Scene, Description
  205. FROM torrents
  206. WHERE ID = $TorrentID");
  207. */
  208. $DB->query("
  209. SELECT Media, Container, Codec, Resolution, AudioFormat, Subbing, Language, Description, MediaInfo, Censored, Archive, Subber
  210. FROM torrents
  211. WHERE ID = $TorrentID");
  212. $DBTorVals = $DB->to_array(false, MYSQLI_ASSOC);
  213. $DBTorVals = $DBTorVals[0];
  214. $LogDetails = '';
  215. foreach ($DBTorVals as $Key => $Value) {
  216. $Value = "'$Value'";
  217. if ($Value != $T[$Key]) {
  218. if (!isset($T[$Key])) {
  219. continue;
  220. }
  221. if ((empty($Value) && empty($T[$Key])) || ($Value == "'0'" && $T[$Key] == "''")) {
  222. continue;
  223. }
  224. if ($LogDetails == '') {
  225. $LogDetails = "$Key: $Value -> ".$T[$Key];
  226. } else {
  227. $LogDetails = "$LogDetails, $Key: $Value -> ".$T[$Key];
  228. }
  229. }
  230. }
  231. $T['Censored'] = $Properties['Censored'];
  232. // Update info for the torrent
  233. /*
  234. $SQL = "
  235. UPDATE torrents
  236. SET
  237. Media = $T[Media],
  238. Format = $T[Format],
  239. Encoding = $T[Encoding],
  240. RemasterYear = $T[RemasterYear],
  241. Remastered = $T[Remastered],
  242. RemasterTitle = $T[RemasterTitle],
  243. RemasterRecordLabel = $T[RemasterRecordLabel],
  244. RemasterCatalogueNumber = $T[RemasterCatalogueNumber],
  245. Scene = $T[Scene],";
  246. */
  247. $SQL = "
  248. UPDATE torrents
  249. SET
  250. Media = $T[Media],
  251. Container = $T[Container],
  252. Codec = $T[Codec],
  253. Resolution = $T[Resolution],
  254. AudioFormat = $T[AudioFormat],
  255. Subbing = $T[Subbing],
  256. Language = $T[Language],
  257. Subber = $T[Subber],
  258. Archive = $T[Archive],
  259. MediaInfo = $T[MediaInfo],
  260. Censored = $T[Censored],";
  261. if (check_perms('torrents_freeleech')) {
  262. $SQL .= "FreeTorrent = $T[FreeLeech],";
  263. $SQL .= "FreeLeechType = $T[FreeLeechType],";
  264. }
  265. if (check_perms('users_mod')) {
  266. /* if ($T[Format] != "'FLAC'") {
  267. $SQL .= "
  268. HasLog = '0',
  269. HasCue = '0',";
  270. } else {
  271. $SQL .= "
  272. HasLog = $T[HasLog],
  273. HasCue = $T[HasCue],";
  274. }
  275. */
  276. $DB->query("
  277. SELECT TorrentID
  278. FROM torrents_bad_tags
  279. WHERE TorrentID = '$TorrentID'");
  280. list($btID) = $DB->next_record();
  281. if (!$btID && $Properties['BadTags']) {
  282. $DB->query("
  283. INSERT INTO torrents_bad_tags
  284. VALUES ($TorrentID, $LoggedUser[ID], '".sqltime()."')");
  285. }
  286. if ($btID && !$Properties['BadTags']) {
  287. $DB->query("
  288. DELETE FROM torrents_bad_tags
  289. WHERE TorrentID = '$TorrentID'");
  290. }
  291. $DB->query("
  292. SELECT TorrentID
  293. FROM torrents_bad_folders
  294. WHERE TorrentID = '$TorrentID'");
  295. list($bfID) = $DB->next_record();
  296. if (!$bfID && $Properties['BadFolders']) {
  297. $DB->query("
  298. INSERT INTO torrents_bad_folders
  299. VALUES ($TorrentID, $LoggedUser[ID], '".sqltime()."')");
  300. }
  301. if ($bfID && !$Properties['BadFolders']) {
  302. $DB->query("
  303. DELETE FROM torrents_bad_folders
  304. WHERE TorrentID = '$TorrentID'");
  305. }
  306. $DB->query("
  307. SELECT TorrentID
  308. FROM torrents_bad_files
  309. WHERE TorrentID = '$TorrentID'");
  310. list($bfiID) = $DB->next_record();
  311. if (!$bfiID && $Properties['BadFiles']) {
  312. $DB->query("
  313. INSERT INTO torrents_bad_files
  314. VALUES ($TorrentID, $LoggedUser[ID], '".sqltime()."')");
  315. }
  316. if ($bfiID && !$Properties['BadFiles']) {
  317. $DB->query("
  318. DELETE FROM torrents_bad_files
  319. WHERE TorrentID = '$TorrentID'");
  320. }
  321. $DB->query("
  322. SELECT TorrentID
  323. FROM library_contest
  324. WHERE TorrentID = '$TorrentID'");
  325. list($lbID) = $DB->next_record();
  326. if (!$lbID && $Properties['LibraryUpload'] && $Properties['LibraryPoints'] > 0) {
  327. $DB->query("
  328. SELECT UserID
  329. FROM torrents
  330. WHERE ID = $TorrentID");
  331. list($UploaderID) = $DB->next_record();
  332. $DB->query("
  333. INSERT INTO library_contest
  334. VALUES ($UploaderID, $TorrentID, $Properties[LibraryPoints])");
  335. }
  336. if ($lbID && !$Properties['LibraryUpload']) {
  337. $DB->query("
  338. DELETE FROM library_contest
  339. WHERE TorrentID = '$TorrentID'");
  340. }
  341. }
  342. $SQL .= "
  343. Description = $T[TorrentDescription]
  344. WHERE ID = $TorrentID";
  345. $DB->query($SQL);
  346. if (check_perms('torrents_freeleech') && $Properties['FreeLeech'] != $CurFreeLeech) {
  347. Torrents::freeleech_torrents($TorrentID, $Properties['FreeLeech'], $Properties['FreeLeechType']);
  348. }
  349. $DB->query("
  350. SELECT GroupID, Time
  351. FROM torrents
  352. WHERE ID = '$TorrentID'");
  353. list($GroupID, $Time) = $DB->next_record();
  354. // Competition
  355. if (strtotime($Time) > 1241352173) {
  356. if ($_POST['log_score'] == '100') {
  357. $DB->query("
  358. INSERT IGNORE into users_points (GroupID, UserID, Points)
  359. VALUES ('$GroupID', '$UserID', '1')");
  360. }
  361. }
  362. // End competiton
  363. $DB->query("
  364. SELECT Enabled
  365. FROM users_main
  366. WHERE ID = $UserID");
  367. list($Enabled) = $DB->next_record();
  368. $DB->query("
  369. SELECT Name
  370. FROM torrents_group
  371. WHERE ID = $GroupID");
  372. list($Name) = $DB->next_record(MYSQLI_NUM, false);
  373. Misc::write_log("Torrent $TorrentID ($Name) in group $GroupID was edited by ".$LoggedUser['Username']." ($LogDetails)"); // TODO: this is probably broken
  374. Torrents::write_group_log($GroupID, $TorrentID, $LoggedUser['ID'], $LogDetails, 0);
  375. $Cache->delete_value("torrents_details_$GroupID");
  376. $Cache->delete_value("torrent_download_$TorrentID");
  377. Torrents::update_hash($GroupID);
  378. // All done!
  379. header("Location: torrents.php?id=$GroupID");
  380. ?>