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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <?php
  2. declare(strict_types = 1);
  3. /**
  4. * Input validation
  5. */
  6. # User permissions
  7. authorize();
  8. if (!check_perms('site_edit_wiki')) {
  9. error(403);
  10. }
  11. # Variables for database input
  12. $user_id = (int) $LoggedUser['ID'];
  13. $group_id = (int) $_REQUEST['groupid'];
  14. Security::checkInt([$user_id, $group_id]);
  15. # If we're reverting to a previous revision
  16. if (!empty($_GET['action']) && $_GET['action'] === 'revert') {
  17. $revision_id = (int) $_GET['revisionid'];
  18. Security::checkInt($revision_id);
  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">
  24. <div class="header">
  25. <h2>
  26. Revert Confirm!
  27. </h2>
  28. </div>
  29. <div class="box">
  30. <form class="confirm_form" name="torrent_group" action="torrents.php" method="get">
  31. <input type="hidden" name="action" value="revert" />
  32. <input type="hidden" name="auth"
  33. value="<?=$LoggedUser['AuthKey']?>" />
  34. <input type="hidden" name="confirm" value="true" />
  35. <input type="hidden" name="groupid" value="<?=$group_id?>" />
  36. <input type="hidden" name="revisionid"
  37. value="<?=$revision_id?>" />
  38. <h3>
  39. You are attempting to revert to the revision
  40. <a
  41. href="torrents.php?id=<?=$group_id?>&amp;revisionid=<?=$revision_id?>"><?=$revision_id?></a>.
  42. </h3>
  43. <input type="submit" value="Confirm" />
  44. </form>
  45. </div>
  46. </div>
  47. <?php
  48. View::show_footer();
  49. error();
  50. }
  51. # With edit, the variables are passed with POST
  52. else {
  53. $description = $_POST['body'];
  54. $picture = $_POST['image'];
  55. if (($GroupInfo = $Cache->get_value('torrents_details_'.$group_id)) && !isset($GroupInfo[0][0])) {
  56. $GroupCategoryID = $GroupInfo[0]['category_id'];
  57. } else {
  58. $DB->query("
  59. SELECT
  60. `category_id`
  61. FROM
  62. `torrents_group`
  63. WHERE
  64. `id` = '$group_id'
  65. ");
  66. list($GroupCategoryID) = $DB->next_record();
  67. }
  68. // Trickery
  69. if (!preg_match("/^".IMAGE_REGEX."$/i", $picture)) {
  70. $picture = '';
  71. }
  72. ImageTools::blacklisted($picture);
  73. $Summary = db_string($_POST['summary']);
  74. }
  75. // Insert revision
  76. if (empty($revision_id)) { // edit
  77. $DB->prepare_query("
  78. INSERT INTO `wiki_torrents`(
  79. `PageID`,
  80. `Body`,
  81. `Image`,
  82. `UserID`,
  83. `Summary`,
  84. `Time`
  85. )
  86. VALUES(
  87. '$group_id',
  88. '$description',
  89. '$picture',
  90. '$user_id',
  91. '$Summary',
  92. NOW()
  93. )
  94. ");
  95. $DB->exec_prepared_query();
  96. } else { // revert
  97. $DB->query("
  98. SELECT
  99. `PageID`,
  100. `Body`,
  101. `Image`
  102. FROM
  103. `wiki_torrents`
  104. WHERE
  105. `RevisionID` = '$revision_id'
  106. ");
  107. list($PossibleGroupID, $Body, $Image) = $DB->next_record();
  108. if ($PossibleGroupID !== $group_id) {
  109. error(404);
  110. }
  111. $DB->query("
  112. INSERT INTO `wiki_torrents`(
  113. `PageID`,
  114. `Body`,
  115. `Image`,
  116. `UserID`,
  117. `Summary`,
  118. `Time`
  119. )
  120. SELECT
  121. '$group_id',
  122. `Body`,
  123. `Image`,
  124. '$user_id',
  125. 'Reverted to revision $revision_id',
  126. NOW()
  127. FROM
  128. `wiki_artists`
  129. WHERE
  130. `RevisionID` = '$revision_id'
  131. ");
  132. }
  133. $revision_id = $DB->inserted_id();
  134. $description = db_string($description);
  135. $picture = db_string($picture);
  136. // Update torrents table (technically, we don't need the revision_id column, but we can use it for a join which is nice and fast)
  137. $DB->query("
  138. UPDATE
  139. `torrents_group`
  140. SET
  141. `revision_id` = '$revision_id',
  142. `description` = '$description',
  143. `picture` = '$picture'
  144. WHERE
  145. `id` = '$group_id'
  146. ");
  147. // There we go, all done!
  148. $Cache->delete_value('torrents_details_'.$group_id);
  149. $Cache->delete_value('torrent_group_'.$group_id);
  150. $DB->query("
  151. SELECT
  152. `CollageID`
  153. FROM
  154. `collages_torrents`
  155. WHERE
  156. `GroupID` = '$group_id'
  157. ");
  158. if ($DB->has_results()) {
  159. while (list($CollageID) = $DB->next_record()) {
  160. $Cache->delete_value('collage_'.$CollageID);
  161. }
  162. }
  163. // Fix Recent Uploads/Downloads for image change
  164. $DB->query("
  165. SELECT DISTINCT
  166. `UserID`
  167. FROM
  168. `torrents` AS t
  169. LEFT JOIN `torrents_group` AS tg
  170. ON
  171. t.`GroupID` = tg.`id`
  172. WHERE
  173. tg.`id` = '$group_id'
  174. ");
  175. $user_ids = $DB->collect('UserID');
  176. foreach ($user_ids as $user_id) {
  177. $RecentUploads = $Cache->get_value('recent_uploads_'.$user_id);
  178. if (is_array($RecentUploads)) {
  179. foreach ($RecentUploads as $Key => $Recent) {
  180. if ($Recent['id'] === $group_id) {
  181. if ($Recent['picture'] !== $picture) {
  182. $Recent['picture'] = $picture;
  183. $Cache->begin_transaction('recent_uploads_'.$user_id);
  184. $Cache->update_row($Key, $Recent);
  185. $Cache->commit_transaction(0);
  186. }
  187. }
  188. }
  189. }
  190. }
  191. $DB->query("
  192. SELECT
  193. `ID`
  194. FROM
  195. `torrents`
  196. WHERE
  197. `GroupID` = '$group_id'
  198. ");
  199. if ($DB->has_results()) {
  200. $TorrentIDs = implode(',', $DB->collect('ID'));
  201. $DB->query("
  202. SELECT DISTINCT
  203. `uid`
  204. FROM
  205. `xbt_snatched`
  206. WHERE
  207. `fid` IN($TorrentIDs)
  208. ");
  209. $Snatchers = $DB->collect('uid');
  210. foreach ($Snatchers as $user_id) {
  211. $RecentSnatches = $Cache->get_value('recent_snatches_'.$user_id);
  212. if (is_array($RecentSnatches)) {
  213. foreach ($RecentSnatches as $Key => $Recent) {
  214. if ($Recent['id'] == $group_id) {
  215. if ($Recent['picture'] !== $picture) {
  216. $Recent['picture'] = $picture;
  217. $Cache->begin_transaction('recent_snatches_'.$user_id);
  218. $Cache->update_row($Key, $Recent);
  219. $Cache->commit_transaction(0);
  220. }
  221. }
  222. }
  223. }
  224. }
  225. }
  226. header("Location: torrents.php?id=$group_id");