PageRenderTime 31ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/site/moderate.php

https://bitbucket.org/elifarley/netsukuku
PHP | 698 lines | 473 code | 153 blank | 72 comment | 101 complexity | aaa196447d5706b6e03a884174670c22 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /***********************************************************************
  3. Copyright (C) 2002-2005 Rickard Andersson (rickard@punbb.org)
  4. This file is part of PunBB.
  5. PunBB is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License as published
  7. by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. PunBB is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  16. MA 02111-1307 USA
  17. ************************************************************************/
  18. define('PUN_ROOT', './');
  19. require PUN_ROOT.'include/common.php';
  20. // This particular function doesn't require forum-based moderator access. It can be used
  21. // by all moderators and admins.
  22. if (isset($_GET['get_host']))
  23. {
  24. if ($pun_user['g_id'] > PUN_MOD)
  25. message($lang_common['No permission']);
  26. // Is get_host an IP address or a post ID?
  27. if (preg_match('/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/', $_GET['get_host']))
  28. $ip = $_GET['get_host'];
  29. else
  30. {
  31. $get_host = intval($_GET['get_host']);
  32. if ($get_host < 1)
  33. message($lang_common['Bad request']);
  34. $result = $db->query('SELECT poster_ip FROM '.$db->prefix.'posts WHERE id='.$get_host) or error('Unable to fetch post IP address', __FILE__, __LINE__, $db->error());
  35. if (!$db->num_rows($result))
  36. message($lang_common['Bad request']);
  37. $ip = $db->result($result);
  38. }
  39. message('The IP address is: '.$ip.'<br />The host name is: '.@gethostbyaddr($ip).'<br /><br /><a href="admin_users.php?show_users='.$ip.'">Show more users for this IP</a>');
  40. }
  41. // All other functions require moderator/admin access
  42. $fid = isset($_GET['fid']) ? intval($_GET['fid']) : 0;
  43. if ($fid < 1)
  44. message($lang_common['Bad request']);
  45. $result = $db->query('SELECT moderators FROM '.$db->prefix.'forums WHERE id='.$fid) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
  46. $moderators = $db->result($result);
  47. $mods_array = ($moderators != '') ? unserialize($moderators) : array();
  48. if ($pun_user['g_id'] != PUN_ADMIN && ($pun_user['g_id'] != PUN_MOD || !array_key_exists($pun_user['username'], $mods_array)))
  49. message($lang_common['No permission']);
  50. // Load the misc.php language file
  51. require PUN_ROOT.'lang/'.$pun_user['language'].'/misc.php';
  52. // All other topic moderation features require a topic id in GET
  53. if (isset($_GET['tid']))
  54. {
  55. $tid = intval($_GET['tid']);
  56. if ($tid < 1)
  57. message($lang_common['Bad request']);
  58. // Fetch some info about the topic
  59. $result = $db->query('SELECT t.subject, t.num_replies, f.id AS forum_id, forum_name FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'subscriptions AS s ON (t.id=s.topic_id AND s.user_id='.$pun_user['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 f.id='.$fid.' AND t.id='.$tid.' AND t.moved_to IS NULL') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
  60. if (!$db->num_rows($result))
  61. message($lang_common['Bad request']);
  62. $cur_topic = $db->fetch_assoc($result);
  63. // Delete one or more posts
  64. if (isset($_POST['delete_posts']) || isset($_POST['delete_posts_comply']))
  65. {
  66. $posts = $_POST['posts'];
  67. if (empty($posts))
  68. message($lang_misc['No posts selected']);
  69. if (isset($_POST['delete_posts_comply']))
  70. {
  71. confirm_referrer('moderate.php');
  72. if (preg_match('/[^0-9,]/', $posts))
  73. message($lang_common['Bad request']);
  74. // Delete the posts
  75. $db->query('DELETE FROM '.$db->prefix.'posts WHERE id IN('.$posts.')') or error('Unable to delete posts', __FILE__, __LINE__, $db->error());
  76. require PUN_ROOT.'include/search_idx.php';
  77. strip_search_index($posts);
  78. // Get last_post, last_post_id, and last_poster for the topic after deletion
  79. $result = $db->query('SELECT id, poster, posted FROM '.$db->prefix.'posts WHERE topic_id='.$tid.' ORDER BY id DESC LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
  80. $last_post = $db->fetch_assoc($result);
  81. // How many posts did we just delete?
  82. $num_posts_deleted = substr_count($posts, ',') + 1;
  83. // Update the topic
  84. $db->query('UPDATE '.$db->prefix.'topics SET last_post='.$last_post['posted'].', last_post_id='.$last_post['id'].', last_poster=\''.$db->escape($last_post['poster']).'\', num_replies=num_replies-'.$num_posts_deleted.' WHERE id='.$tid) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
  85. update_forum($fid);
  86. redirect('index.php?pag=forum&act=viewtopic&id='.$tid, $lang_misc['Delete posts redirect']);
  87. }
  88. $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_misc['Moderate'];
  89. require PUN_ROOT.'header.php';
  90. ?>
  91. <div class="blockform">
  92. <h2><span><?php echo $lang_misc['Delete posts'] ?></span></h2>
  93. <div class="box">
  94. <form method="post" action="index.php?pag=forum&amp;act=moderate&amp;fid=<?php echo $fid ?>&amp;tid=<?php echo $tid ?>">
  95. <div class="inform">
  96. <fieldset>
  97. <legend><?php echo $lang_misc['Confirm delete legend'] ?></legend>
  98. <div class="infldset">
  99. <input type="hidden" name="posts" value="<?php echo implode(',', array_keys($posts)) ?>" />
  100. <p><?php echo $lang_misc['Delete posts comply'] ?></p>
  101. </div>
  102. </fieldset>
  103. </div>
  104. <p><input type="submit" name="delete_posts_comply" value="<?php echo $lang_misc['Delete'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
  105. </form>
  106. </div>
  107. </div>
  108. <?php
  109. require PUN_ROOT.'footer.php';
  110. }
  111. // Show the delete multiple posts view
  112. // Load the viewtopic.php language file
  113. require PUN_ROOT.'lang/'.$pun_user['language'].'/topic.php';
  114. // Used to disable the Move and Delete buttons if there are no replies to this topic
  115. $button_status = ($cur_topic['num_replies'] == 0) ? ' disabled' : '';
  116. // Determine the post offset (based on $_GET['p'])
  117. $num_pages = ceil(($cur_topic['num_replies'] + 1) / $pun_user['disp_posts']);
  118. $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : $_GET['p'];
  119. $start_from = $pun_user['disp_posts'] * ($p - 1);
  120. // Generate paging links
  121. $paging_links = $lang_common['Pages'].': '.paginate($num_pages, $p, 'index.php?pag=forum&act=moderate&fid='.$fid.'&amp;tid='.$tid);
  122. if ($pun_config['o_censoring'] == '1')
  123. $cur_topic['subject'] = censor_words($cur_topic['subject']);
  124. $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$cur_topic['subject'];
  125. require PUN_ROOT.'header.php';
  126. ?>
  127. <div class="linkst">
  128. <div class="inbox">
  129. <p class="pagelink conl"><?php echo $paging_links ?></p>
  130. <ul><li><a href="index.php?pag=forum"><?php echo $lang_common['Index'] ?></a></li><li>&nbsp;&raquo;&nbsp;<a href="viewforum.php?id=<?php echo $fid ?>"><?php echo pun_htmlspecialchars($cur_topic['forum_name']) ?></a></li><li>&nbsp;&raquo;&nbsp;<?php echo pun_htmlspecialchars($cur_topic['subject']) ?></li></ul>
  131. <div class="clearer"></div>
  132. </div>
  133. </div>
  134. <form method="post" action="index.php?pag=forum&amp;act=moderate&amp;fid=<?php echo $fid ?>&amp;tid=<?php echo $tid ?>">
  135. <?php
  136. require PUN_ROOT.'include/parser.php';
  137. $bg_switch = true; // Used for switching background color in posts
  138. $post_count = 0; // Keep track of post numbers
  139. // Retrieve the posts (and their respective poster)
  140. $result = $db->query('SELECT u.title, u.num_posts, g.g_id, g.g_user_title, p.id, p.poster, p.poster_id, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id INNER JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE p.topic_id='.$tid.' ORDER BY p.id LIMIT '.$start_from.','.$pun_user['disp_posts'], true) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
  141. while ($cur_post = $db->fetch_assoc($result))
  142. {
  143. $post_count++;
  144. // If the poster is a registered user.
  145. if ($cur_post['poster_id'] > 1)
  146. {
  147. $poster = '<a href="profile.php?id='.$cur_post['poster_id'].'">'.pun_htmlspecialchars($cur_post['poster']).'</a>';
  148. // get_title() requires that an element 'username' be present in the array
  149. $cur_post['username'] = $cur_post['poster'];
  150. $user_title = get_title($cur_post);
  151. if ($pun_config['o_censoring'] == '1')
  152. $user_title = censor_words($user_title);
  153. }
  154. // If the poster is a guest (or a user that has been deleted)
  155. else
  156. {
  157. $poster = pun_htmlspecialchars($cur_post['poster']);
  158. $user_title = $lang_topic['Guest'];
  159. }
  160. // Switch the background color for every message.
  161. $bg_switch = ($bg_switch) ? $bg_switch = false : $bg_switch = true;
  162. $vtbg = ($bg_switch) ? ' roweven' : ' rowodd';
  163. // Perform the main parsing of the message (BBCode, smilies, censor words etc)
  164. $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
  165. ?>
  166. <div class="blockpost<?php echo $vtbg ?>">
  167. <a name="<?php echo $cur_post['id'] ?>"></a>
  168. <h2><span><span class="conr">#<?php echo ($start_from + $post_count) ?>&nbsp;</span><a href="index.php?pag=forum&amp;act=viewtopic&amp;pid=<?php echo $cur_post['id'].'#p'.$cur_post['id'] ?>"><?php echo format_time($cur_post['posted']) ?></a></span></h2>
  169. <div class="box">
  170. <div class="inbox">
  171. <div class="postleft">
  172. <dl>
  173. <dt><strong><?php echo $poster ?></strong></dt>
  174. <dd><strong><?php echo $user_title ?></strong></dd>
  175. </dl>
  176. </div>
  177. <div class="postright">
  178. <h3 class="nosize"><?php echo $lang_common['Message'] ?></h3>
  179. <div class="postmsg">
  180. <?php echo $cur_post['message']."\n" ?>
  181. <?php if ($cur_post['edited'] != '') echo "\t\t\t\t\t".'<p class="postedit"><em>'.$lang_topic['Last edit'].' '.pun_htmlspecialchars($cur_post['edited_by']).' ('.format_time($cur_post['edited']).')</em></p>'."\n"; ?>
  182. </div>
  183. <?php if ($start_from + $post_count > 1) echo '<p class="multidelete"><label><strong>'.$lang_misc['Select'].'</strong>&nbsp;&nbsp;<input type="checkbox" name="posts['.$cur_post['id'].']" value="1" /></label></p>'."\n" ?>
  184. </div>
  185. <div class="clearer"></div>
  186. </div>
  187. </div>
  188. </div>
  189. <?php
  190. }
  191. ?>
  192. <div class="postlinksb">
  193. <div class="inbox">
  194. <p class="pagelink conl"><?php echo $paging_links ?></p>
  195. <p class="conr"><input type="submit" name="delete_posts" value="<?php echo $lang_misc['Delete'] ?>"<?php echo $button_status ?> /></p>
  196. <div class="clearer"></div>
  197. </div>
  198. </div>
  199. </form>
  200. <?php
  201. require PUN_ROOT.'footer.php';
  202. }
  203. // Move one or more topics
  204. if (isset($_REQUEST['move_topics']) || isset($_POST['move_topics_to']))
  205. {
  206. if (isset($_POST['move_topics_to']))
  207. {
  208. confirm_referrer('moderate.php');
  209. if (preg_match('/[^0-9,]/', $_POST['topics']))
  210. message($lang_common['Bad request']);
  211. $topics = explode(',', $_POST['topics']);
  212. $move_to_forum = isset($_POST['move_to_forum']) ? intval($_POST['move_to_forum']) : 0;
  213. if (empty($topics) || $move_to_forum < 1)
  214. message($lang_common['Bad request']);
  215. // Delete any redirect topics if there are any (only if we moved/copied the topic back to where it where it was once moved from)
  216. $db->query('DELETE FROM '.$db->prefix.'topics WHERE forum_id='.$move_to_forum.' AND moved_to IN('.implode(',',$topics).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error());
  217. // Move the topic(s)
  218. $db->query('UPDATE '.$db->prefix.'topics SET forum_id='.$move_to_forum.' WHERE id IN('.implode(',',$topics).')') or error('Unable to move topics', __FILE__, __LINE__, $db->error());
  219. // Should we create redirect topics?
  220. if (isset($_POST['with_redirect']))
  221. {
  222. while (list(, $cur_topic) = @each($topics))
  223. {
  224. // Fetch info for the redirect topic
  225. $result = $db->query('SELECT poster, subject, posted, last_post FROM '.$db->prefix.'topics WHERE id='.$cur_topic) or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
  226. $moved_to = $db->fetch_assoc($result);
  227. // Create the redirect topic
  228. $db->query('INSERT INTO '.$db->prefix.'topics (poster, subject, posted, last_post, moved_to, forum_id) VALUES(\''.$db->escape($moved_to['poster']).'\', \''.$db->escape($moved_to['subject']).'\', '.$moved_to['posted'].', '.$moved_to['last_post'].', '.$cur_topic.', '.$fid.')') or error('Unable to create redirect topic', __FILE__, __LINE__, $db->error());
  229. }
  230. }
  231. update_forum($fid); // Update the forum FROM which the topic was moved
  232. update_forum($move_to_forum); // Update the forum TO which the topic was moved
  233. $redirect_msg = (count($topics) > 1) ? $lang_misc['Move topics redirect'] : $lang_misc['Move topic redirect'];
  234. redirect('index.php?pag=forum&act=viewforum&id='.$move_to_forum, $redirect_msg);
  235. }
  236. if (isset($_POST['move_topics']))
  237. {
  238. $topics = isset($_POST['topics']) ? $_POST['topics'] : array();
  239. if (empty($topics))
  240. message($lang_misc['No topics selected']);
  241. $topics = implode(',', array_keys($topics));
  242. $action = 'multi';
  243. }
  244. else
  245. {
  246. $topics = intval($_GET['move_topics']);
  247. if ($topics < 1)
  248. message($lang_common['Bad request']);
  249. $action = 'single';
  250. }
  251. $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Moderate';
  252. require PUN_ROOT.'header.php';
  253. ?>
  254. <div class="blockform">
  255. <h2><span><?php echo ($action == 'single') ? $lang_misc['Move topic'] : $lang_misc['Move topics'] ?></span></h2>
  256. <div class="box">
  257. <form method="post" action="index.php?pag=forum&amp;act=moderate&amp;fid=<?php echo $fid ?>">
  258. <div class="inform">
  259. <input type="hidden" name="topics" value="<?php echo $topics ?>" />
  260. <fieldset>
  261. <legend><?php echo $lang_misc['Move legend'] ?></legend>
  262. <div class="infldset">
  263. <label><?php echo $lang_misc['Move to'] ?>
  264. <br /><select name="move_to_forum">
  265. <?php
  266. $result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_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 f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position', true) or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
  267. $cur_category = 0;
  268. while ($cur_forum = $db->fetch_assoc($result))
  269. {
  270. if ($cur_forum['cid'] != $cur_category) // A new category since last iteration?
  271. {
  272. if ($cur_category)
  273. echo "\t\t\t\t\t\t\t".'</optgroup>'."\n";
  274. echo "\t\t\t\t\t\t\t".'<optgroup label="'.pun_htmlspecialchars($cur_forum['cat_name']).'">'."\n";
  275. $cur_category = $cur_forum['cid'];
  276. }
  277. if ($cur_forum['fid'] != $fid)
  278. echo "\t\t\t\t\t\t\t\t".'<option value="'.$cur_forum['fid'].'">'.pun_htmlspecialchars($cur_forum['forum_name']).'</option>'."\n";
  279. }
  280. ?>
  281. </optgroup>
  282. </select>
  283. <br /></label>
  284. <div class="rbox">
  285. <label><input type="checkbox" name="with_redirect" value="1"<?php if ($action == 'single') echo ' checked="checked"' ?> /><?php echo $lang_misc['Leave redirect'] ?><br /></label>
  286. </div>
  287. </div>
  288. </fieldset>
  289. </div>
  290. <p><input type="submit" name="move_topics_to" value="<?php echo $lang_misc['Move'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
  291. </form>
  292. </div>
  293. </div>
  294. <?php
  295. require PUN_ROOT.'footer.php';
  296. }
  297. // Delete one or more topics
  298. if (isset($_REQUEST['delete_topics']) || isset($_POST['delete_topics_comply']))
  299. {
  300. $topics = isset($_POST['topics']) ? $_POST['topics'] : array();
  301. if (empty($topics))
  302. message($lang_misc['No topics selected']);
  303. if (isset($_POST['delete_topics_comply']))
  304. {
  305. confirm_referrer('moderate.php');
  306. if (preg_match('/[^0-9,]/', $topics))
  307. message($lang_common['Bad request']);
  308. require PUN_ROOT.'include/search_idx.php';
  309. // Delete the topics and any redirect topics
  310. $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.$topics.') OR moved_to IN('.$topics.')') or error('Unable to delete topic', __FILE__, __LINE__, $db->error());
  311. // Delete any subscriptions
  312. $db->query('DELETE FROM '.$db->prefix.'subscriptions WHERE topic_id IN('.$topics.')') or error('Unable to delete subscriptions', __FILE__, __LINE__, $db->error());
  313. // Create a list of the post ID's in this topic and then strip the search index
  314. $result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id IN('.$topics.')') or error('Unable to fetch posts', __FILE__, __LINE__, $db->error());
  315. $post_ids = '';
  316. while ($row = $db->fetch_row($result))
  317. $post_ids .= ($post_ids != '') ? ','.$row[0] : $row[0];
  318. // We have to check that we actually have a list of post ID's since we could be deleting just a redirect topic
  319. if ($post_ids != '')
  320. strip_search_index($post_ids);
  321. // Delete posts
  322. $db->query('DELETE FROM '.$db->prefix.'posts WHERE topic_id IN('.$topics.')') or error('Unable to delete posts', __FILE__, __LINE__, $db->error());
  323. update_forum($fid);
  324. redirect('index.php?pag=forum&act=viewforum&id='.$fid, $lang_misc['Delete topics redirect']);
  325. }
  326. $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_misc['Moderate'];
  327. require PUN_ROOT.'header.php';
  328. ?>
  329. <div class="blockform">
  330. <h2><?php echo $lang_misc['Delete topics'] ?></h2>
  331. <div class="box">
  332. <form method="post" action="index.php?pag=forum&amp;act=moderate&amp;fid=<?php echo $fid ?>">
  333. <input type="hidden" name="topics" value="<?php echo implode(',', array_keys($topics)) ?>" />
  334. <div class="inform">
  335. <fieldset>
  336. <legend><?php echo $lang_misc['Confirm delete legend'] ?></legend>
  337. <div class="infldset">
  338. <p><?php echo $lang_misc['Delete topics comply'] ?></p>
  339. </div>
  340. </fieldset>
  341. </div>
  342. <p><input type="submit" name="delete_topics_comply" value="<?php echo $lang_misc['Delete'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
  343. </form>
  344. </div>
  345. </div>
  346. <?php
  347. require PUN_ROOT.'footer.php';
  348. }
  349. // Open or close one or more topics
  350. else if (isset($_REQUEST['open']) || isset($_REQUEST['close']))
  351. {
  352. $action = (isset($_REQUEST['open'])) ? 0 : 1;
  353. // There could be an array of topic ID's in $_POST
  354. if (isset($_POST['open']) || isset($_POST['close']))
  355. {
  356. confirm_referrer('moderate.php');
  357. $topics = isset($_POST['topics']) ? @array_map('intval', @array_keys($_POST['topics'])) : array();
  358. if (empty($topics))
  359. message($lang_misc['No topics selected']);
  360. $db->query('UPDATE '.$db->prefix.'topics SET closed='.$action.' WHERE id IN('.implode(',', $topics).')') or error('Unable to close topics', __FILE__, __LINE__, $db->error());
  361. $redirect_msg = ($action) ? $lang_misc['Close topics redirect'] : $lang_misc['Open topics redirect'];
  362. redirect('index.php?pag=forum&act=moderate&fid='.$fid, $redirect_msg);
  363. }
  364. // Or just one in $_GET
  365. else
  366. {
  367. confirm_referrer('viewtopic.php');
  368. $topic_id = ($action) ? intval($_GET['close']) : intval($_GET['open']);
  369. if ($topic_id < 1)
  370. message($lang_common['Bad request']);
  371. $db->query('UPDATE '.$db->prefix.'topics SET closed='.$action.' WHERE id='.$topic_id) or error('Unable to close topic', __FILE__, __LINE__, $db->error());
  372. $redirect_msg = ($action) ? $lang_misc['Close topic redirect'] : $lang_misc['Open topic redirect'];
  373. redirect('index.php?pag=forum&act=viewtopic&id='.$topic_id, $redirect_msg);
  374. }
  375. }
  376. // Stick a topic
  377. else if (isset($_GET['stick']))
  378. {
  379. confirm_referrer('viewtopic.php');
  380. $stick = intval($_GET['stick']);
  381. if ($stick < 1)
  382. message($lang_common['Bad request']);
  383. $db->query('UPDATE '.$db->prefix.'topics SET sticky=\'1\' WHERE id='.$stick) or error('Unable to stick topic', __FILE__, __LINE__, $db->error());
  384. redirect('index.php?pag=forum&act=viewtopic&id='.$stick, $lang_misc['Stick topic redirect']);
  385. }
  386. // Unstick a topic
  387. else if (isset($_GET['unstick']))
  388. {
  389. confirm_referrer('viewtopic.php');
  390. $unstick = intval($_GET['unstick']);
  391. if ($unstick < 1)
  392. message($lang_common['Bad request']);
  393. $db->query('UPDATE '.$db->prefix.'topics SET sticky=\'0\' WHERE id='.$unstick) or error('Unable to unstick topic', __FILE__, __LINE__, $db->error());
  394. redirect('index.php?pag=forum&act=viewtopic&id='.$unstick, $lang_misc['Unstick topic redirect']);
  395. }
  396. // No specific forum moderation action was specified in the query string, so we'll display the moderator forum
  397. // Load the viewforum.php language file
  398. require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';
  399. // Fetch some info about the forum
  400. $result = $db->query('SELECT f.forum_name, f.redirect_url, f.num_topics FROM '.$db->prefix.'forums AS f 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 f.id='.$fid) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
  401. if (!$db->num_rows($result))
  402. message($lang_common['Bad request']);
  403. $cur_forum = $db->fetch_assoc($result);
  404. // Is this a redirect forum? In that case, abort!
  405. if ($cur_forum['redirect_url'] != '')
  406. message($lang_common['Bad request']);
  407. $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.pun_htmlspecialchars($cur_forum['forum_name']);
  408. require PUN_ROOT.'header.php';
  409. // Determine the topic offset (based on $_GET['p'])
  410. $num_pages = ceil($cur_forum['num_topics'] / $pun_user['disp_topics']);
  411. $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : $_GET['p'];
  412. $start_from = $pun_user['disp_topics'] * ($p - 1);
  413. // Generate paging links
  414. $paging_links = $lang_common['Pages'].': '.paginate($num_pages, $p, 'index.php?pag=forum&act=moderate&fid='.$fid)
  415. ?>
  416. <div class="linkst">
  417. <div class="inbox">
  418. <p class="pagelink conl"><?php echo $paging_links ?></p>
  419. <ul><li><a href="index.php?pag=forum"><?php echo $lang_common['Index'] ?></a>&nbsp;</li><li>&raquo;&nbsp;<?php echo pun_htmlspecialchars($cur_forum['forum_name']) ?></li></ul>
  420. <div class="clearer"></div>
  421. </div>
  422. </div>
  423. <form method="post" action="index.php?pag=forum&amp;act=moderate&amp;fid=<?php echo $fid ?>">
  424. <div id="vf" class="blocktable">
  425. <h2><span><?php echo pun_htmlspecialchars($cur_forum['forum_name']) ?></span></h2>
  426. <div class="box">
  427. <div class="inbox">
  428. <table cellspacing="0">
  429. <thead>
  430. <tr>
  431. <th class="tcl" scope="col"><?php echo $lang_common['Topic'] ?></th>
  432. <th class="tc2" scope="col"><?php echo $lang_common['Replies'] ?></th>
  433. <th class="tc3" scope="col"><?php echo $lang_forum['Views'] ?></th>
  434. <th class="tcr"><?php echo $lang_common['Last post'] ?></th>
  435. <th class="tcmod" scope="col"><?php echo $lang_misc['Select'] ?></th>
  436. </tr>
  437. </thead>
  438. <tbody>
  439. <?php
  440. // Select topics
  441. $result = $db->query('SELECT id, poster, subject, posted, last_post, last_post_id, last_poster, num_views, num_replies, closed, sticky, moved_to FROM '.$db->prefix.'topics WHERE forum_id='.$fid.' ORDER BY sticky DESC, last_post DESC LIMIT '.$start_from.', '.$pun_user['disp_topics']) or error('Unable to fetch topic list for forum', __FILE__, __LINE__, $db->error());
  442. // If there are topics in this forum.
  443. if ($db->num_rows($result))
  444. {
  445. $button_status = '';
  446. while ($cur_topic = $db->fetch_assoc($result))
  447. {
  448. $icon_text = $lang_common['Normal icon'];
  449. $item_status = '';
  450. $icon_type = 'icon';
  451. if ($cur_topic['moved_to'] == null)
  452. {
  453. $last_post = '<a href="index.php?pag=forum&amp;act=viewtopic&amp;pid='.$cur_topic['last_post_id'].'#p'.$cur_topic['last_post_id'].'">'.format_time($cur_topic['last_post']).'</a> '.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['last_poster']);
  454. $ghost_topic = false;
  455. }
  456. else
  457. {
  458. $last_post = '&nbsp;';
  459. $ghost_topic = true;
  460. }
  461. if ($pun_config['o_censoring'] == '1')
  462. $cur_topic['subject'] = censor_words($cur_topic['subject']);
  463. if ($cur_topic['moved_to'] != 0)
  464. $subject = $lang_forum['Moved'].': <a href="index.php?pag=forum&amp;act=viewtopic&amp;id='.$cur_topic['moved_to'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>';
  465. else if ($cur_topic['closed'] == '0')
  466. $subject = '<a href="index.php?pag=forum&amp;act=viewtopic&amp;id='.$cur_topic['id'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span>'.$lang_common['by'].'&nbsp;'.pun_htmlspecialchars($cur_topic['poster']).'</span>';
  467. else
  468. {
  469. $subject = '<a href="index.php?pag=forum&amp;act=viewtopic&amp;id='.$cur_topic['id'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>';
  470. $icon_text = $lang_common['Closed icon'];
  471. $item_status = 'iclosed';
  472. }
  473. if ($cur_topic['last_post'] > $pun_user['last_visit'] && !$ghost_topic)
  474. {
  475. $icon_text .= ' '.$lang_common['New icon'];
  476. $item_status .= ' inew';
  477. $icon_type = 'icon inew';
  478. $subject = '<strong>'.$subject.'</strong>';
  479. $subject_new_posts = '<span class="newtext">[&nbsp;<a href="index.php?pag=forum&amp;act=viewtopic&amp;id='.$cur_topic['id'].'&amp;action=new" title="'.$lang_common['New posts info'].'">'.$lang_common['New posts'].'</a>&nbsp;]</span>';
  480. }
  481. else
  482. $subject_new_posts = null;
  483. // We won't display "the dot", but we add the spaces anyway
  484. if ($pun_config['o_show_dot'] == '1')
  485. $subject = '&nbsp;&nbsp;'.$subject;
  486. if ($cur_topic['sticky'] == '1')
  487. {
  488. $subject = '<span class="stickytext">'.$lang_forum['Sticky'].': </span>'.$subject;
  489. $item_status .= ' isticky';
  490. $icon_text .= ' '.$lang_forum['Sticky'];
  491. }
  492. $num_pages_topic = ceil(($cur_topic['num_replies'] + 1) / $pun_user['disp_posts']);
  493. if ($num_pages_topic > 1)
  494. $subject_multipage = '[ '.paginate($num_pages_topic, -1, 'index.php?pag=forum&act=viewtopic&id='.$cur_topic['id']).' ]';
  495. else
  496. $subject_multipage = null;
  497. // Should we show the "New posts" and/or the multipage links?
  498. if (!empty($subject_new_posts) || !empty($subject_multipage))
  499. {
  500. $subject .= '&nbsp; '.(!empty($subject_new_posts) ? $subject_new_posts : '');
  501. $subject .= !empty($subject_multipage) ? ' '.$subject_multipage : '';
  502. }
  503. ?>
  504. <tr<?php if ($item_status != '') echo ' class="'.trim($item_status).'"'; ?>>
  505. <td class="tcl">
  506. <div class="<?php echo $icon_type ?>"><div class="nosize"><?php echo trim($icon_text) ?></div></div>
  507. <div class="tclcon">
  508. <?php echo $subject."\n" ?>
  509. </div>
  510. </td>
  511. <td class="tc2"><?php echo (!$ghost_topic) ? $cur_topic['num_replies'] : '&nbsp;' ?></td>
  512. <td class="tc3"><?php echo (!$ghost_topic) ? $cur_topic['num_views'] : '&nbsp;' ?></td>
  513. <td class="tcr"><?php echo $last_post ?></td>
  514. <td class="tcmod"><input type="checkbox" name="topics[<?php echo $cur_topic['id'] ?>]" value="1" /></td>
  515. </tr>
  516. <?php
  517. }
  518. }
  519. else
  520. {
  521. $button_status = ' disabled';
  522. echo "\t\t\t\t\t".'<tr><td class="tcl" colspan="5">'.$lang_forum['Empty forum'].'</td></tr>'."\n";
  523. }
  524. ?>
  525. </tbody>
  526. </table>
  527. </div>
  528. </div>
  529. </div>
  530. <div class="linksb">
  531. <div class="inbox">
  532. <p class="pagelink conl"><?php echo $paging_links ?></p>
  533. <p class="conr"><input type="submit" name="move_topics" value="<?php echo $lang_misc['Move'] ?>"<?php echo $button_status ?> />&nbsp;&nbsp;<input type="submit" name="delete_topics" value="<?php echo $lang_misc['Delete'] ?>"<?php echo $button_status ?> />&nbsp;&nbsp;<input type="submit" name="open" value="<?php echo $lang_misc['Open'] ?>"<?php echo $button_status ?> />&nbsp;&nbsp;<input type="submit" name="close" value="<?php echo $lang_misc['Close'] ?>"<?php echo $button_status ?> /></p>
  534. <div class="clearer"></div>
  535. </div>
  536. </div>
  537. </form>
  538. <?php
  539. require PUN_ROOT.'footer.php';