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.

screenshotedit.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?
  2. authorize();
  3. if (!$_POST['groupid'] || !is_number($_POST['groupid'])) {
  4. error(404);
  5. }
  6. $GroupID = $_POST['groupid'];
  7. if (!check_perms('torrents_edit') && !check_perms('screenshots_add') && !check_perms('screenshots_delete')) {
  8. $DB->query("
  9. SELECT UserID
  10. FROM torrents
  11. WHERE GroupID = ?", $GroupID);
  12. if (!in_array($LoggedUser['ID'], $DB->collect('UserID'))) {
  13. error(403);
  14. }
  15. }
  16. $Screenshots = $_POST['screenshots'] ?? [];
  17. $Screenshots = array_map("trim", $Screenshots);
  18. $Screenshots = array_filter($Screenshots, function($s) {
  19. return preg_match('/^'.IMAGE_REGEX.'$/i', $s);
  20. });
  21. $Screenshots = array_unique($Screenshots);
  22. if (count($Screenshots) > 10) {
  23. error("You cannot add more than 10 screenshots to a group");
  24. }
  25. $DB->query("
  26. SELECT UserID, Image
  27. FROM torrents_screenshots
  28. WHERE GroupID = ?", $GroupID);
  29. // $Old is an array of the form URL => UserID where UserID is the ID of the User who originally uploaded that image.
  30. $Old = [];
  31. if ($DB->has_results()) {
  32. while($S = $DB->next_record(MYSQLI_ASSOC)) {
  33. $Old[$S['Image']] = $S['UserID'];
  34. }
  35. }
  36. if (!empty($Old)) {
  37. $New = array_diff($Screenshots, array_keys($Old));
  38. $Deleted = array_diff(array_keys($Old), $Screenshots);
  39. } else {
  40. $New = $Screenshots;
  41. }
  42. // Deletion
  43. if (!empty($Deleted)) {
  44. if (check_perms('screenshots_delete') || check_perms('torrents_edit')) {
  45. $DeleteList = $Deleted;
  46. } else {
  47. $DeleteList = [];
  48. foreach ($Deleted as $S) {
  49. // If the user who submitted this request uploaded the image, add the image to the list.
  50. if ($Old[$S] == $LoggedUser['ID']) {
  51. $DeleteList[] = $S;
  52. } else {
  53. error(403);
  54. }
  55. }
  56. }
  57. if (!empty($DeleteList)) {
  58. $ScreenDel = '';
  59. $DB->prepare_query("DELETE FROM torrents_screenshots WHERE Image = ?", $ScreenDel);
  60. foreach ($DeleteList as $ScreenDel) {
  61. $DB->exec_prepared_query();
  62. }
  63. Torrents::write_group_log($GroupID, 0, $LoggedUser['ID'], "Deleted screenshot(s) ".implode(' , ', $DeleteList), 0);
  64. Misc::write_log("Screenshots ( ".implode(' , ', $DeleteList)." ) deleted from Torrent Group ".$GroupID." by ".$LoggedUser['Username']);
  65. }
  66. }
  67. // New screenshots
  68. if (!empty($New)) {
  69. $Screenshot = '';
  70. $DB->prepare_query("
  71. INSERT INTO torrents_screenshots
  72. (GroupID, UserID, Time, Image)
  73. VALUES
  74. (?, ?, NOW(), ?)",
  75. $GroupID, $LoggedUser['ID'], $Screenshot);
  76. foreach ($New as $Screenshot) {
  77. $DB->exec_prepared_query();
  78. }
  79. Torrents::write_group_log($GroupID, 0, $LoggedUser['ID'], "Added screenshot(s) ".implode(' , ', $New), 0);
  80. Misc::write_log("Screenshots ( ".implode(' , ', $New)." ) added to Torrent Group ".$GroupID." by ".$LoggedUser['Username']);
  81. }
  82. $Cache->delete_value("torrents_details_".$GroupID);
  83. header("Location: torrents.php?id=$GroupID");
  84. ?>