PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/delete.php

https://github.com/Dratone/EveBB
PHP | 141 lines | 101 code | 28 blank | 12 comment | 21 complexity | a3549429ed353a6e7d213e33a7553a19 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * Copyright (C) 2008-2010 FluxBB
  4. * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
  5. * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
  6. */
  7. define('PUN_ROOT', dirname(__FILE__).'/');
  8. require PUN_ROOT.'include/common.php';
  9. require PUN_ROOT.'include/attach/attach_incl.php'; //Attachment Mod row, loads variables, functions and lang file
  10. if ($pun_user['g_read_board'] == '0')
  11. message($lang_common['No view']);
  12. $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
  13. if ($id < 1)
  14. message($lang_common['Bad request']);
  15. // Fetch some info about the post, the topic and the forum
  16. $result = $db->query('SELECT f.id AS fid, f.forum_name, f.moderators, f.redirect_url, fp.post_replies, fp.post_topics, t.id AS tid, t.subject, t.first_post_id, t.closed, p.posted, p.poster, p.poster_id, p.message, p.hide_smilies FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND p.id='.$id) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
  17. if (!$db->num_rows($result))
  18. message($lang_common['Bad request']);
  19. $cur_post = $db->fetch_assoc($result);
  20. if ($pun_config['o_censoring'] == '1')
  21. $cur_post['subject'] = censor_words($cur_post['subject']);
  22. // Sort out who the moderators are and if we are currently a moderator (or an admin)
  23. $mods_array = ($cur_post['moderators'] != '') ? unserialize($cur_post['moderators']) : array();
  24. $is_admmod = ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_moderator'] == '1' && array_key_exists($pun_user['username'], $mods_array))) ? true : false;
  25. $is_topic_post = ($id == $cur_post['first_post_id']) ? true : false;
  26. // Do we have permission to edit this post?
  27. if (($pun_user['g_delete_posts'] == '0' ||
  28. ($pun_user['g_delete_topics'] == '0' && $is_topic_post) ||
  29. $cur_post['poster_id'] != $pun_user['id'] ||
  30. $cur_post['closed'] == '1') &&
  31. !$is_admmod)
  32. message($lang_common['No permission']);
  33. // Load the delete.php language file
  34. require PUN_ROOT.'lang/'.$pun_user['language'].'/delete.php';
  35. if (isset($_POST['delete']))
  36. {
  37. if ($is_admmod)
  38. confirm_referrer('delete.php');
  39. require PUN_ROOT.'include/search_idx.php';
  40. if ($is_topic_post)
  41. {
  42. // Delete the topic and all of it's posts
  43. attach_delete_thread($cur_post['tid']); // Attachment Mod , delete the attachments in the whole thread (orphan check is checked in this function)
  44. delete_topic($cur_post['tid']);
  45. update_forum($cur_post['fid']);
  46. redirect('viewforum.php?id='.$cur_post['fid'], $lang_delete['Topic del redirect']);
  47. }
  48. else
  49. {
  50. // Delete just this one post
  51. attach_delete_post($id); // Attachment Mod , delete the attachments in this post (orphan check is checked in this function)
  52. delete_post($id, $cur_post['tid']);
  53. update_forum($cur_post['fid']);
  54. // Redirect towards the previous post
  55. $result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id='.$cur_post['tid'].' AND id < '.$id.' ORDER BY id DESC LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
  56. $post_id = $db->result($result);
  57. redirect('viewtopic.php?pid='.$post_id.'#p'.$post_id, $lang_delete['Post del redirect']);
  58. }
  59. }
  60. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_delete['Delete post']);
  61. define ('PUN_ACTIVE_PAGE', 'index');
  62. require PUN_ROOT.'header.php';
  63. require PUN_ROOT.'include/parser.php';
  64. $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
  65. ?>
  66. <div class="linkst">
  67. <div class="inbox">
  68. <ul class="crumbs">
  69. <li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li>
  70. <li><span>»&#160;</span><a href="viewforum.php?id=<?php echo $cur_post['fid'] ?>"><?php echo pun_htmlspecialchars($cur_post['forum_name']) ?></a></li>
  71. <li><span>»&#160;</span><a href="viewtopic.php?pid=<?php echo $id ?>#p<?php echo $id ?>"><?php echo pun_htmlspecialchars($cur_post['subject']) ?></a></li>
  72. <li><span>»&#160;</span><strong><?php echo $lang_delete['Delete post'] ?></strong></li>
  73. </ul>
  74. </div>
  75. </div>
  76. <div class="blockform">
  77. <h2><span><?php echo $lang_delete['Delete post'] ?></span></h2>
  78. <div class="box">
  79. <form method="post" action="delete.php?id=<?php echo $id ?>">
  80. <div class="inform">
  81. <div class="forminfo">
  82. <h3><span><?php printf($is_topic_post ? $lang_delete['Topic by'] : $lang_delete['Reply by'], '<strong>'.pun_htmlspecialchars($cur_post['poster']).'</strong>', format_time($cur_post['posted'])) ?></span></h3>
  83. <p><?php echo ($is_topic_post) ? '<strong>'.$lang_delete['Topic warning'].'</strong>' : '<strong>'.$lang_delete['Warning'].'</strong>' ?><br /><?php echo $lang_delete['Delete info'] ?></p>
  84. </div>
  85. </div>
  86. <p class="buttons"><input type="submit" name="delete" value="<?php echo $lang_delete['Delete'] ?>" /> <a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
  87. </form>
  88. </div>
  89. </div>
  90. <div id="postreview">
  91. <div class="blockpost">
  92. <div class="box">
  93. <div class="inbox">
  94. <div class="postbody">
  95. <div class="postleft">
  96. <dl>
  97. <dt><strong><?php echo pun_htmlspecialchars($cur_post['poster']) ?></strong></dt>
  98. <dd><span><?php echo format_time($cur_post['posted']) ?></span></dd>
  99. </dl>
  100. </div>
  101. <div class="postright">
  102. <div class="postmsg">
  103. <?php echo $cur_post['message']."\n" ?>
  104. </div>
  105. </div>
  106. </div>
  107. <div class="clearer"></div>
  108. </div>
  109. </div>
  110. </div>
  111. </div>
  112. <?php
  113. require PUN_ROOT.'footer.php';