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.

takegroupedit.php 5.0KB

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