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.

takegroupedit.php 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. #declare(strict_types = 1);
  3. authorize();
  4. // Quick SQL injection check
  5. if (!$_REQUEST['groupid'] || !is_number($_REQUEST['groupid'])) {
  6. error(404);
  7. }
  8. if (!check_perms('site_edit_wiki')) {
  9. error(403);
  10. }
  11. // Variables for database input
  12. $UserID = $LoggedUser['ID'];
  13. $GroupID = $_REQUEST['groupid'];
  14. if (!empty($_GET['action']) && $_GET['action'] === 'revert') { // if we're reverting to a previous revision
  15. $RevisionID = $_GET['revisionid'];
  16. if (!is_number($RevisionID)) {
  17. error(400);
  18. }
  19. // To cite from merge: "Everything is legit, let's just confim they're not retarded"
  20. if (empty($_GET['confirm'])) {
  21. View::show_header(); ?>
  22. <!-- Start HTML -->
  23. <div class="center">
  24. <div class="header">
  25. <h2>Revert Confirm!</h2>
  26. </div>
  27. <div class="box pad">
  28. <form class="confirm_form" name="torrent_group" action="torrents.php" method="get">
  29. <input type="hidden" name="action" value="revert" />
  30. <input type="hidden" name="auth"
  31. value="<?=$LoggedUser['AuthKey']?>" />
  32. <input type="hidden" name="confirm" value="true" />
  33. <input type="hidden" name="groupid" value="<?=$GroupID?>" />
  34. <input type="hidden" name="revisionid"
  35. value="<?=$RevisionID?>" />
  36. <h3>You are attempting to revert to the revision <a
  37. href="torrents.php?id=<?=$GroupID?>&amp;revisionid=<?=$RevisionID?>"><?=$RevisionID?></a>.</h3>
  38. <input type="submit" value="Confirm" />
  39. </form>
  40. </div>
  41. </div>
  42. <?php
  43. View::show_footer();
  44. error();
  45. }
  46. } else { // with edit, the variables are passed with POST
  47. $Body = $_POST['body'];
  48. $Image = $_POST['image'];
  49. if (($GroupInfo = $Cache->get_value('torrents_details_'.$GroupID)) && !isset($GroupInfo[0][0])) {
  50. $GroupCategoryID = $GroupInfo[0]['CategoryID'];
  51. } else {
  52. $DB->query("
  53. SELECT CategoryID
  54. FROM torrents_group
  55. WHERE ID = '$GroupID'");
  56. list($GroupCategoryID) = $DB->next_record();
  57. }
  58. // Trickery
  59. if (!preg_match("/^".IMAGE_REGEX."$/i", $Image)) {
  60. $Image = '';
  61. }
  62. ImageTools::blacklisted($Image);
  63. $Summary = db_string($_POST['summary']);
  64. }
  65. // Insert revision
  66. if (empty($RevisionID)) { // edit
  67. $DB->query("
  68. INSERT INTO wiki_torrents
  69. (PageID, Body, Image, UserID, Summary, Time)
  70. VALUES
  71. ('$GroupID', '".db_string($Body)."', '".db_string($Image)."', '$UserID', '$Summary', NOW())");
  72. } else { // revert
  73. $DB->query("
  74. SELECT PageID, Body, Image
  75. FROM wiki_torrents
  76. WHERE RevisionID = '$RevisionID'");
  77. list($PossibleGroupID, $Body, $Image) = $DB->next_record();
  78. if ($PossibleGroupID != $GroupID) {
  79. error(404);
  80. }
  81. $DB->query("
  82. INSERT INTO wiki_torrents
  83. (PageID, Body, Image, UserID, Summary, Time)
  84. SELECT '$GroupID', Body, Image, '$UserID', 'Reverted to revision $RevisionID', NOW()
  85. FROM wiki_artists
  86. WHERE RevisionID = '$RevisionID'");
  87. }
  88. $RevisionID = $DB->inserted_id();
  89. $Body = db_string($Body);
  90. $Image = db_string($Image);
  91. // Update torrents table (technically, we don't need the RevisionID column, but we can use it for a join which is nice and fast)
  92. $DB->query("
  93. UPDATE torrents_group
  94. SET
  95. RevisionID = '$RevisionID',
  96. WikiBody = '$Body',
  97. WikiImage = '$Image'
  98. WHERE ID='$GroupID'");
  99. // There we go, all done!
  100. $Cache->delete_value('torrents_details_'.$GroupID);
  101. $Cache->delete_value('torrent_group_'.$GroupID);
  102. $DB->query("
  103. SELECT CollageID
  104. FROM collages_torrents
  105. WHERE GroupID = '$GroupID'");
  106. if ($DB->has_results()) {
  107. while (list($CollageID) = $DB->next_record()) {
  108. $Cache->delete_value('collage_'.$CollageID);
  109. }
  110. }
  111. //Fix Recent Uploads/Downloads for image change
  112. $DB->query("
  113. SELECT DISTINCT UserID
  114. FROM torrents AS t
  115. LEFT JOIN torrents_group AS tg ON t.GroupID=tg.ID
  116. WHERE tg.ID = $GroupID");
  117. $UserIDs = $DB->collect('UserID');
  118. foreach ($UserIDs as $UserID) {
  119. $RecentUploads = $Cache->get_value('recent_uploads_'.$UserID);
  120. if (is_array($RecentUploads)) {
  121. foreach ($RecentUploads as $Key => $Recent) {
  122. if ($Recent['ID'] == $GroupID) {
  123. if ($Recent['WikiImage'] != $Image) {
  124. $Recent['WikiImage'] = $Image;
  125. $Cache->begin_transaction('recent_uploads_'.$UserID);
  126. $Cache->update_row($Key, $Recent);
  127. $Cache->commit_transaction(0);
  128. }
  129. }
  130. }
  131. }
  132. }
  133. $DB->query("
  134. SELECT ID
  135. FROM torrents
  136. WHERE GroupID = $GroupID");
  137. if ($DB->has_results()) {
  138. $TorrentIDs = implode(',', $DB->collect('ID'));
  139. $DB->query("
  140. SELECT DISTINCT uid
  141. FROM xbt_snatched
  142. WHERE fid IN ($TorrentIDs)");
  143. $Snatchers = $DB->collect('uid');
  144. foreach ($Snatchers as $UserID) {
  145. $RecentSnatches = $Cache->get_value('recent_snatches_'.$UserID);
  146. if (is_array($RecentSnatches)) {
  147. foreach ($RecentSnatches as $Key => $Recent) {
  148. if ($Recent['ID'] == $GroupID) {
  149. if ($Recent['WikiImage'] != $Image) {
  150. $Recent['WikiImage'] = $Image;
  151. $Cache->begin_transaction('recent_snatches_'.$UserID);
  152. $Cache->update_row($Key, $Recent);
  153. $Cache->commit_transaction(0);
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }
  160. header("Location: torrents.php?id=$GroupID");