BioTorrents.de’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 3.0KB

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