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.

takeedit.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?
  2. authorize();
  3. /*********************************************************************\
  4. //--------------Take Post--------------------------------------------//
  5. The page that handles the backend of the 'edit post' function.
  6. $_GET['action'] must be "takeedit" for this page to work.
  7. It will be accompanied with:
  8. $_POST['post'] - the ID of the post
  9. $_POST['body']
  10. \*********************************************************************/
  11. // Quick SQL injection check
  12. if (!$_POST['post'] || !is_number($_POST['post']) || !is_number($_POST['key'])) {
  13. error(0, true);
  14. }
  15. // End injection check
  16. if ($LoggedUser['DisablePosting']) {
  17. error('Your posting privileges have been removed.');
  18. }
  19. // Variables for database input
  20. $UserID = $LoggedUser['ID'];
  21. $Body = $_POST['body']; //Don't URL Decode
  22. $PostID = $_POST['post'];
  23. $Key = $_POST['key'];
  24. $SQLTime = sqltime();
  25. $DoPM = isset($_POST['pm']) ? $_POST['pm'] : 0;
  26. // Mainly
  27. $DB->query("
  28. SELECT
  29. p.Body,
  30. p.AuthorID,
  31. p.TopicID,
  32. t.IsLocked,
  33. t.ForumID,
  34. f.MinClassWrite,
  35. CEIL((
  36. SELECT COUNT(p2.ID)
  37. FROM forums_posts AS p2
  38. WHERE p2.TopicID = p.TopicID
  39. AND p2.ID <= '$PostID'
  40. ) / ".POSTS_PER_PAGE."
  41. ) AS Page
  42. FROM forums_posts AS p
  43. JOIN forums_topics AS t ON p.TopicID = t.ID
  44. JOIN forums AS f ON t.ForumID = f.ID
  45. WHERE p.ID = '$PostID'");
  46. list($OldBody, $AuthorID, $TopicID, $IsLocked, $ForumID, $MinClassWrite, $Page) = $DB->next_record();
  47. // Make sure they aren't trying to edit posts they shouldn't
  48. if (!Forums::check_forumperm($ForumID, 'Write') || ($IsLocked && !check_perms('site_moderate_forums'))) {
  49. error('Either the thread is locked, or you lack the permission to edit this post.', true);
  50. }
  51. if ($UserID != $AuthorID && !check_perms('site_moderate_forums')) {
  52. error(403,true);
  53. }
  54. if ($LoggedUser['DisablePosting']) {
  55. error('Your posting privileges have been removed.', true);
  56. }
  57. if (!$DB->has_results()) {
  58. error(404, true);
  59. }
  60. // Send a PM to the user to notify them of the edit
  61. if ($UserID != $AuthorID && $DoPM) {
  62. $PMSubject = "Your post #$PostID has been edited";
  63. $PMurl = site_url()."forums.php?action=viewthread&postid=$PostID#post$PostID";
  64. $ProfLink = '[url='.site_url()."user.php?id=$UserID]".$LoggedUser['Username'].'[/url]';
  65. $PMBody = "One of your posts has been edited by $ProfLink: [url]{$PMurl}[/url]";
  66. Misc::send_pm($AuthorID, 0, $PMSubject, $PMBody);
  67. }
  68. // Perform the update
  69. $DB->query("
  70. UPDATE forums_posts
  71. SET
  72. Body = '" . db_string($Body) . "',
  73. EditedUserID = '$UserID',
  74. EditedTime = '$SQLTime'
  75. WHERE ID = '$PostID'");
  76. $CatalogueID = floor((POSTS_PER_PAGE * $Page - POSTS_PER_PAGE) / THREAD_CATALOGUE);
  77. $Cache->begin_transaction("thread_$TopicID"."_catalogue_$CatalogueID");
  78. if ($Cache->MemcacheDBArray[$Key]['ID'] != $PostID) {
  79. $Cache->cancel_transaction();
  80. $Cache->delete_value("thread_$TopicID"."_catalogue_$CatalogueID"); //just clear the cache for would be cache-screwer-uppers
  81. } else {
  82. $Cache->update_row($Key, array(
  83. 'ID'=>$Cache->MemcacheDBArray[$Key]['ID'],
  84. 'AuthorID'=>$Cache->MemcacheDBArray[$Key]['AuthorID'],
  85. 'AddedTime'=>$Cache->MemcacheDBArray[$Key]['AddedTime'],
  86. 'Body'=>$Body, //Don't url decode.
  87. 'EditedUserID'=>$LoggedUser['ID'],
  88. 'EditedTime'=>$SQLTime,
  89. 'Username'=>$LoggedUser['Username']
  90. ));
  91. $Cache->commit_transaction(3600 * 24 * 5);
  92. }
  93. $ThreadInfo = Forums::get_thread_info($TopicID);
  94. if ($ThreadInfo === null) {
  95. error(404);
  96. }
  97. if ($ThreadInfo['StickyPostID'] == $PostID) {
  98. $ThreadInfo['StickyPost']['Body'] = $Body;
  99. $ThreadInfo['StickyPost']['EditedUserID'] = $LoggedUser['ID'];
  100. $ThreadInfo['StickyPost']['EditedTime'] = $SQLTime;
  101. $Cache->cache_value("thread_$TopicID".'_info', $ThreadInfo, 0);
  102. }
  103. $DB->query("
  104. INSERT INTO comments_edits
  105. (Page, PostID, EditUser, EditTime, Body)
  106. VALUES
  107. ('forums', $PostID, $UserID, '$SQLTime', '".db_string($OldBody)."')");
  108. $Cache->delete_value("forums_edits_$PostID");
  109. // This gets sent to the browser, which echoes it in place of the old body
  110. echo Text::full_format($Body);
  111. ?>
  112. <br /><br /><div class="last_edited">Last edited by <a href="user.php?id=<?=$LoggedUser['ID']?>"><?=$LoggedUser['Username']?></a> Just now</div>