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

/moderate.php

https://github.com/Dratone/EveBB
PHP | 1005 lines | 710 code | 206 blank | 89 comment | 157 complexity | 15af4f97824a9edcac24d19e97953e8b MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * Copyright (C) 2008-2011 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. // This particular function doesn't require forum-based moderator access. It can be used
  11. // by all moderators and admins
  12. if (isset($_GET['get_host']))
  13. {
  14. if (!$pun_user['is_admmod'])
  15. message($lang_common['No permission']);
  16. // Is get_host an IP address or a post ID?
  17. if (@preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $_GET['get_host']) || @preg_match('/^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/', $_GET['get_host']))
  18. $ip = $_GET['get_host'];
  19. else
  20. {
  21. $get_host = intval($_GET['get_host']);
  22. if ($get_host < 1)
  23. message($lang_common['Bad request']);
  24. $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());
  25. if (!$db->num_rows($result))
  26. message($lang_common['Bad request']);
  27. $ip = $db->result($result);
  28. }
  29. // Load the misc.php language file
  30. require PUN_ROOT.'lang/'.$pun_user['language'].'/misc.php';
  31. message(sprintf($lang_misc['Host info 1'], $ip).'<br />'.sprintf($lang_misc['Host info 2'], @gethostbyaddr($ip)).'<br /><br /><a href="admin_users.php?show_users='.$ip.'">'.$lang_misc['Show more users'].'</a>');
  32. }
  33. // All other functions require moderator/admin access
  34. $fid = isset($_GET['fid']) ? intval($_GET['fid']) : 0;
  35. if ($fid < 1)
  36. message($lang_common['Bad request']);
  37. $result = $db->query('SELECT moderators FROM '.$db->prefix.'forums WHERE id='.$fid) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
  38. $moderators = $db->result($result);
  39. $mods_array = ($moderators != '') ? unserialize($moderators) : array();
  40. if ($pun_user['g_id'] != PUN_ADMIN && ($pun_user['g_moderator'] == '0' || !array_key_exists($pun_user['username'], $mods_array)))
  41. message($lang_common['No permission']);
  42. // Get topic/forum tracking data
  43. if (!$pun_user['is_guest'])
  44. $tracked_topics = get_tracked_topics();
  45. // Load the misc.php language file
  46. require PUN_ROOT.'lang/'.$pun_user['language'].'/misc.php';
  47. // All other topic moderation features require a topic ID in GET
  48. if (isset($_GET['tid']))
  49. {
  50. $tid = intval($_GET['tid']);
  51. if ($tid < 1)
  52. message($lang_common['Bad request']);
  53. // Fetch some info about the topic
  54. $result = $db->query('SELECT t.subject, t.num_replies, t.first_post_id, 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.'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());
  55. if (!$db->num_rows($result))
  56. message($lang_common['Bad request']);
  57. $cur_topic = $db->fetch_assoc($result);
  58. // Delete one or more posts
  59. if (isset($_POST['delete_posts']) || isset($_POST['delete_posts_comply']))
  60. {
  61. $posts = isset($_POST['posts']) ? $_POST['posts'] : array();
  62. if (empty($posts))
  63. message($lang_misc['No posts selected']);
  64. if (isset($_POST['delete_posts_comply']))
  65. {
  66. confirm_referrer('moderate.php');
  67. if (@preg_match('/[^0-9,]/', $posts))
  68. message($lang_common['Bad request']);
  69. // Verify that the post IDs are valid
  70. $result = $db->query('SELECT 1 FROM '.$db->prefix.'posts WHERE id IN('.$posts.') AND topic_id='.$tid) or error('Unable to check posts', __FILE__, __LINE__, $db->error());
  71. if ($db->num_rows($result) != substr_count($posts, ',') + 1)
  72. message($lang_common['Bad request']);
  73. //Attachment Mod Block Start
  74. foreach(explode(',',$posts) as $value)
  75. attach_delete_post($value);
  76. //Attachment Mod Block End
  77. // Delete the posts
  78. $db->query('DELETE FROM '.$db->prefix.'posts WHERE id IN('.$posts.')') or error('Unable to delete posts', __FILE__, __LINE__, $db->error());
  79. require PUN_ROOT.'include/search_idx.php';
  80. strip_search_index($posts);
  81. // Get last_post, last_post_id, and last_poster for the topic after deletion
  82. $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());
  83. $last_post = $db->fetch_assoc($result);
  84. // How many posts did we just delete?
  85. $num_posts_deleted = substr_count($posts, ',') + 1;
  86. // Update the topic
  87. $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());
  88. update_forum($fid);
  89. redirect('viewtopic.php?id='.$tid, $lang_misc['Delete posts redirect']);
  90. }
  91. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_misc['Moderate']);
  92. define('PUN_ACTIVE_PAGE', 'index');
  93. require PUN_ROOT.'header.php';
  94. ?>
  95. <div class="blockform">
  96. <h2><span><?php echo $lang_misc['Delete posts'] ?></span></h2>
  97. <div class="box">
  98. <form method="post" action="moderate.php?fid=<?php echo $fid ?>&amp;tid=<?php echo $tid ?>">
  99. <div class="inform">
  100. <fieldset>
  101. <legend><?php echo $lang_misc['Confirm delete legend'] ?></legend>
  102. <div class="infldset">
  103. <input type="hidden" name="posts" value="<?php echo implode(',', array_map('intval', array_keys($posts))) ?>" />
  104. <p><?php echo $lang_misc['Delete posts comply'] ?></p>
  105. </div>
  106. </fieldset>
  107. </div>
  108. <p class="buttons"><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>
  109. </form>
  110. </div>
  111. </div>
  112. <?php
  113. require PUN_ROOT.'footer.php';
  114. }
  115. else if (isset($_POST['split_posts']) || isset($_POST['split_posts_comply']))
  116. {
  117. $posts = isset($_POST['posts']) ? $_POST['posts'] : array();
  118. if (empty($posts))
  119. message($lang_misc['No posts selected']);
  120. if (isset($_POST['split_posts_comply']))
  121. {
  122. confirm_referrer('moderate.php');
  123. if (@preg_match('/[^0-9,]/', $posts))
  124. message($lang_common['Bad request']);
  125. $move_to_forum = isset($_POST['move_to_forum']) ? intval($_POST['move_to_forum']) : 0;
  126. if ($move_to_forum < 1)
  127. message($lang_common['Bad request']);
  128. // How many posts did we just split off?
  129. $num_posts_splitted = substr_count($posts, ',') + 1;
  130. // Verify that the post IDs are valid
  131. $result = $db->query('SELECT 1 FROM '.$db->prefix.'posts WHERE id IN('.$posts.') AND topic_id='.$tid) or error('Unable to check posts', __FILE__, __LINE__, $db->error());
  132. if ($db->num_rows($result) != $num_posts_splitted)
  133. message($lang_common['Bad request']);
  134. // Verify that the move to forum ID is valid
  135. $result = $db->query('SELECT 1 FROM '.$db->prefix.'forums AS f LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.group_id='.$pun_user['g_id'].' AND fp.forum_id='.$move_to_forum.') WHERE f.redirect_url IS NULL AND (fp.post_topics IS NULL OR fp.post_topics=1)') or error('Unable to fetch forum permissions', __FILE__, __LINE__, $db->error());
  136. if (!$db->num_rows($result))
  137. message($lang_common['Bad request']);
  138. // Load the post.php language file
  139. require PUN_ROOT.'lang/'.$pun_user['language'].'/post.php';
  140. // Check subject
  141. $new_subject = isset($_POST['new_subject']) ? pun_trim($_POST['new_subject']) : '';
  142. if ($new_subject == '')
  143. message($lang_post['No subject']);
  144. else if (pun_strlen($new_subject) > 70)
  145. message($lang_post['Too long subject']);
  146. // Get data from the new first post
  147. $result = $db->query('SELECT p.id, p.poster, p.posted FROM '.$db->prefix.'posts AS p WHERE id IN('.$posts.') ORDER BY p.id ASC LIMIT 1') or error('Unable to get first post', __FILE__, __LINE__, $db->error());
  148. $first_post_data = $db->fetch_assoc($result);
  149. // Create the new topic
  150. $db->query('INSERT INTO '.$db->prefix.'topics (poster, subject, posted, first_post_id, forum_id) VALUES (\''.$db->escape($first_post_data['poster']).'\', \''.$db->escape($new_subject).'\', '.$first_post_data['posted'].', '.$first_post_data['id'].', '.$move_to_forum.')') or error('Unable to create new topic', __FILE__, __LINE__, $db->error());
  151. $new_tid = $db->insert_id();
  152. // Move the posts to the new topic
  153. $db->query('UPDATE '.$db->prefix.'posts SET topic_id='.$new_tid.' WHERE id IN('.$posts.')') or error('Unable to move posts into new topic', __FILE__, __LINE__, $db->error());
  154. // Get last_post, last_post_id, and last_poster from the topic and update it
  155. $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());
  156. $last_post_data = $db->fetch_assoc($result);
  157. $db->query('UPDATE '.$db->prefix.'topics SET last_post='.$last_post_data['posted'].', last_post_id='.$last_post_data['id'].', last_poster=\''.$db->escape($last_post_data['poster']).'\', num_replies=num_replies-'.$num_posts_splitted.' WHERE id='.$tid) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
  158. // Get last_post, last_post_id, and last_poster from the new topic and update it
  159. $result = $db->query('SELECT id, poster, posted FROM '.$db->prefix.'posts WHERE topic_id='.$new_tid.' ORDER BY id DESC LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
  160. $last_post_data = $db->fetch_assoc($result);
  161. $db->query('UPDATE '.$db->prefix.'topics SET last_post='.$last_post_data['posted'].', last_post_id='.$last_post_data['id'].', last_poster=\''.$db->escape($last_post_data['poster']).'\', num_replies='.($num_posts_splitted-1).' WHERE id='.$new_tid) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
  162. update_forum($fid);
  163. update_forum($move_to_forum);
  164. redirect('viewtopic.php?id='.$new_tid, $lang_misc['Split posts redirect']);
  165. }
  166. $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.post_topics IS NULL OR fp.post_topics=1) AND f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position') or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
  167. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_misc['Moderate']);
  168. $focus_element = array('subject','new_subject');
  169. define('PUN_ACTIVE_PAGE', 'index');
  170. require PUN_ROOT.'header.php';
  171. ?>
  172. <div class="blockform">
  173. <h2><span><?php echo $lang_misc['Split posts'] ?></span></h2>
  174. <div class="box">
  175. <form id="subject" method="post" action="moderate.php?fid=<?php echo $fid ?>&amp;tid=<?php echo $tid ?>">
  176. <div class="inform">
  177. <fieldset>
  178. <legend><?php echo $lang_misc['Confirm split legend'] ?></legend>
  179. <div class="infldset">
  180. <input type="hidden" name="posts" value="<?php echo implode(',', array_map('intval', array_keys($posts))) ?>" />
  181. <label class="required"><strong><?php echo $lang_misc['New subject'] ?> <span><?php echo $lang_common['Required'] ?></span></strong><br /><input type="text" name="new_subject" size="80" maxlength="70" /><br /></label>
  182. <label><?php echo $lang_misc['Move to'] ?>
  183. <br /><select name="move_to_forum">
  184. <?php
  185. $cur_category = 0;
  186. while ($cur_forum = $db->fetch_assoc($result))
  187. {
  188. if ($cur_forum['cid'] != $cur_category) // A new category since last iteration?
  189. {
  190. if ($cur_category)
  191. echo "\t\t\t\t\t\t\t".'</optgroup>'."\n";
  192. echo "\t\t\t\t\t\t\t".'<optgroup label="'.pun_htmlspecialchars($cur_forum['cat_name']).'">'."\n";
  193. $cur_category = $cur_forum['cid'];
  194. }
  195. echo "\t\t\t\t\t\t\t\t".'<option value="'.$cur_forum['fid'].'"'.($fid == $cur_forum['fid'] ? ' selected="selected"' : '').'>'.pun_htmlspecialchars($cur_forum['forum_name']).'</option>'."\n";
  196. }
  197. ?>
  198. </optgroup>
  199. </select>
  200. <br /></label>
  201. <p><?php echo $lang_misc['Split posts comply'] ?></p>
  202. </div>
  203. </fieldset>
  204. </div>
  205. <p class="buttons"><input type="submit" name="split_posts_comply" value="<?php echo $lang_misc['Split'] ?>" /> <a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
  206. </form>
  207. </div>
  208. </div>
  209. <?php
  210. require PUN_ROOT.'footer.php';
  211. }
  212. // Show the moderate posts view
  213. // Load the viewtopic.php language file
  214. require PUN_ROOT.'lang/'.$pun_user['language'].'/topic.php';
  215. // Used to disable the Move and Delete buttons if there are no replies to this topic
  216. $button_status = ($cur_topic['num_replies'] == 0) ? ' disabled="disabled"' : '';
  217. // Determine the post offset (based on $_GET['p'])
  218. $num_pages = ceil(($cur_topic['num_replies'] + 1) / $pun_user['disp_posts']);
  219. $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : intval($_GET['p']);
  220. $start_from = $pun_user['disp_posts'] * ($p - 1);
  221. // Generate paging links
  222. $paging_links = '<span class="pages-label">'.$lang_common['Pages'].' </span>'.paginate($num_pages, $p, 'moderate.php?fid='.$fid.'&amp;tid='.$tid);
  223. if ($pun_config['o_censoring'] == '1')
  224. $cur_topic['subject'] = censor_words($cur_topic['subject']);
  225. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), pun_htmlspecialchars($cur_topic['forum_name']), pun_htmlspecialchars($cur_topic['subject']));
  226. define('PUN_ACTIVE_PAGE', 'index');
  227. require PUN_ROOT.'header.php';
  228. ?>
  229. <div class="linkst">
  230. <div class="inbox crumbsplus">
  231. <ul class="crumbs">
  232. <li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li>
  233. <li><span>»&#160;</span><a href="viewforum.php?id=<?php echo $fid ?>"><?php echo pun_htmlspecialchars($cur_topic['forum_name']) ?></a></li>
  234. <li><span>»&#160;</span><a href="viewtopic.php?id=<?php echo $tid ?>"><?php echo pun_htmlspecialchars($cur_topic['subject']) ?></a></li>
  235. <li><span>»&#160;</span><strong><?php echo $lang_misc['Moderate'] ?></strong></li>
  236. </ul>
  237. <div class="pagepost">
  238. <p class="pagelink conl"><?php echo $paging_links ?></p>
  239. </div>
  240. <div class="clearer"></div>
  241. </div>
  242. </div>
  243. <form method="post" action="moderate.php?fid=<?php echo $fid ?>&amp;tid=<?php echo $tid ?>">
  244. <?php
  245. require PUN_ROOT.'include/parser.php';
  246. $post_count = 0; // Keep track of post numbers
  247. // Retrieve a list of post IDs, LIMIT is (really) expensive so we only fetch the IDs here then later fetch the remaining data
  248. $result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id='.$tid.' ORDER BY id LIMIT '.$start_from.','.$pun_user['disp_posts']) or error('Unable to fetch post IDs', __FILE__, __LINE__, $db->error());
  249. $post_ids = array();
  250. for ($i = 0;$cur_post_id = $db->result($result, $i);$i++)
  251. $post_ids[] = $cur_post_id;
  252. // Retrieve the posts (and their respective poster)
  253. $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.id IN ('.implode(',', $post_ids).') ORDER BY p.id', true) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
  254. while ($cur_post = $db->fetch_assoc($result))
  255. {
  256. $post_count++;
  257. // If the poster is a registered user
  258. if ($cur_post['poster_id'] > 1)
  259. {
  260. if ($pun_user['g_view_users'] == '1')
  261. $poster = '<a href="profile.php?id='.$cur_post['poster_id'].'">'.pun_htmlspecialchars($cur_post['poster']).'</a>';
  262. else
  263. $poster = pun_htmlspecialchars($cur_post['poster']);
  264. // get_title() requires that an element 'username' be present in the array
  265. $cur_post['username'] = $cur_post['poster'];
  266. $user_title = get_title($cur_post);
  267. if ($pun_config['o_censoring'] == '1')
  268. $user_title = censor_words($user_title);
  269. }
  270. // If the poster is a guest (or a user that has been deleted)
  271. else
  272. {
  273. $poster = pun_htmlspecialchars($cur_post['poster']);
  274. $user_title = $lang_topic['Guest'];
  275. }
  276. // Perform the main parsing of the message (BBCode, smilies, censor words etc)
  277. $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
  278. ?>
  279. <div id="p<?php echo $cur_post['id'] ?>" class="blockpost<?php if($cur_post['id'] == $cur_topic['first_post_id']) echo ' firstpost' ?><?php echo ($post_count % 2 == 0) ? ' roweven' : ' rowodd' ?><?php if ($post_count == 1) echo ' blockpost1' ?>">
  280. <h2><span><span class="conr">#<?php echo ($start_from + $post_count) ?></span> <a href="viewtopic.php?pid=<?php echo $cur_post['id'].'#p'.$cur_post['id'] ?>"><?php echo format_time($cur_post['posted']) ?></a></span></h2>
  281. <div class="box">
  282. <div class="inbox">
  283. <div class="postbody">
  284. <div class="postleft">
  285. <dl>
  286. <dt><strong><?php echo $poster ?></strong></dt>
  287. <dd class="usertitle"><strong><?php echo $user_title ?></strong></dd>
  288. </dl>
  289. </div>
  290. <div class="postright">
  291. <h3 class="nosize"><?php echo $lang_common['Message'] ?></h3>
  292. <div class="postmsg">
  293. <?php echo $cur_post['message']."\n" ?>
  294. <?php if ($cur_post['edited'] != '') echo "\t\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"; ?>
  295. </div>
  296. </div>
  297. </div>
  298. </div>
  299. <div class="inbox">
  300. <div class="postfoot clearb">
  301. <div class="postfootright"><?php echo ($cur_post['id'] != $cur_topic['first_post_id']) ? '<p class="multidelete"><label><strong>'.$lang_misc['Select'].'</strong>&#160;<input type="checkbox" name="posts['.$cur_post['id'].']" value="1" /></label></p>' : '<p>'.$lang_misc['Cannot select first'].'</p>' ?></div>
  302. </div>
  303. </div>
  304. </div>
  305. </div>
  306. <?php
  307. }
  308. ?>
  309. <div class="postlinksb">
  310. <div class="inbox crumbsplus">
  311. <div class="pagepost">
  312. <p class="pagelink conl"><?php echo $paging_links ?></p>
  313. <p class="conr modbuttons"><input type="submit" name="split_posts" value="<?php echo $lang_misc['Split'] ?>"<?php echo $button_status ?> /> <input type="submit" name="delete_posts" value="<?php echo $lang_misc['Delete'] ?>"<?php echo $button_status ?> /></p>
  314. <div class="clearer"></div>
  315. </div>
  316. <ul class="crumbs">
  317. <li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li>
  318. <li><span>»&#160;</span><a href="viewforum.php?id=<?php echo $fid ?>"><?php echo pun_htmlspecialchars($cur_topic['forum_name']) ?></a></li>
  319. <li><span>»&#160;</span><a href="viewtopic.php?id=<?php echo $tid ?>"><?php echo pun_htmlspecialchars($cur_topic['subject']) ?></a></li>
  320. <li><span>»&#160;</span><strong><?php echo $lang_misc['Moderate'] ?></strong></li>
  321. </ul>
  322. <div class="clearer"></div>
  323. </div>
  324. </div>
  325. </form>
  326. <?php
  327. require PUN_ROOT.'footer.php';
  328. }
  329. // Move one or more topics
  330. if (isset($_REQUEST['move_topics']) || isset($_POST['move_topics_to']))
  331. {
  332. if (isset($_POST['move_topics_to']))
  333. {
  334. confirm_referrer('moderate.php');
  335. if (@preg_match('/[^0-9,]/', $_POST['topics']))
  336. message($lang_common['Bad request']);
  337. $topics = explode(',', $_POST['topics']);
  338. $move_to_forum = isset($_POST['move_to_forum']) ? intval($_POST['move_to_forum']) : 0;
  339. if (empty($topics) || $move_to_forum < 1)
  340. message($lang_common['Bad request']);
  341. // Verify that the topic IDs are valid
  342. $result = $db->query('SELECT 1 FROM '.$db->prefix.'topics WHERE id IN('.implode(',',$topics).') AND forum_id='.$fid) or error('Unable to check topics', __FILE__, __LINE__, $db->error());
  343. if ($db->num_rows($result) != count($topics))
  344. message($lang_common['Bad request']);
  345. // Verify that the move to forum ID is valid
  346. $result = $db->query('SELECT 1 FROM '.$db->prefix.'forums AS f LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.group_id='.$pun_user['g_id'].' AND fp.forum_id='.$move_to_forum.') WHERE f.redirect_url IS NULL AND (fp.post_topics IS NULL OR fp.post_topics=1)') or error('Unable to fetch forum permissions', __FILE__, __LINE__, $db->error());
  347. if (!$db->num_rows($result))
  348. message($lang_common['Bad request']);
  349. // Delete any redirect topics if there are any (only if we moved/copied the topic back to where it was once moved from)
  350. $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());
  351. // Move the topic(s)
  352. $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());
  353. // Should we create redirect topics?
  354. if (isset($_POST['with_redirect']))
  355. {
  356. foreach ($topics as $cur_topic)
  357. {
  358. // Fetch info for the redirect topic
  359. $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());
  360. $moved_to = $db->fetch_assoc($result);
  361. // Create the redirect topic
  362. $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());
  363. }
  364. }
  365. update_forum($fid); // Update the forum FROM which the topic was moved
  366. update_forum($move_to_forum); // Update the forum TO which the topic was moved
  367. $redirect_msg = (count($topics) > 1) ? $lang_misc['Move topics redirect'] : $lang_misc['Move topic redirect'];
  368. redirect('viewforum.php?id='.$move_to_forum, $redirect_msg);
  369. }
  370. if (isset($_POST['move_topics']))
  371. {
  372. $topics = isset($_POST['topics']) ? $_POST['topics'] : array();
  373. if (empty($topics))
  374. message($lang_misc['No topics selected']);
  375. $topics = implode(',', array_map('intval', array_keys($topics)));
  376. $action = 'multi';
  377. }
  378. else
  379. {
  380. $topics = intval($_GET['move_topics']);
  381. if ($topics < 1)
  382. message($lang_common['Bad request']);
  383. $action = 'single';
  384. }
  385. $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.post_topics IS NULL OR fp.post_topics=1) AND f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position') or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
  386. if ($db->num_rows($result) < 2)
  387. message($lang_misc['Nowhere to move']);
  388. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_misc['Moderate']);
  389. define('PUN_ACTIVE_PAGE', 'index');
  390. require PUN_ROOT.'header.php';
  391. ?>
  392. <div class="blockform">
  393. <h2><span><?php echo ($action == 'single') ? $lang_misc['Move topic'] : $lang_misc['Move topics'] ?></span></h2>
  394. <div class="box">
  395. <form method="post" action="moderate.php?fid=<?php echo $fid ?>">
  396. <div class="inform">
  397. <input type="hidden" name="topics" value="<?php echo $topics ?>" />
  398. <fieldset>
  399. <legend><?php echo $lang_misc['Move legend'] ?></legend>
  400. <div class="infldset">
  401. <label><?php echo $lang_misc['Move to'] ?>
  402. <br /><select name="move_to_forum">
  403. <?php
  404. $cur_category = 0;
  405. while ($cur_forum = $db->fetch_assoc($result))
  406. {
  407. if ($cur_forum['cid'] != $cur_category) // A new category since last iteration?
  408. {
  409. if ($cur_category)
  410. echo "\t\t\t\t\t\t\t".'</optgroup>'."\n";
  411. echo "\t\t\t\t\t\t\t".'<optgroup label="'.pun_htmlspecialchars($cur_forum['cat_name']).'">'."\n";
  412. $cur_category = $cur_forum['cid'];
  413. }
  414. if ($cur_forum['fid'] != $fid)
  415. echo "\t\t\t\t\t\t\t\t".'<option value="'.$cur_forum['fid'].'">'.pun_htmlspecialchars($cur_forum['forum_name']).'</option>'."\n";
  416. }
  417. ?>
  418. </optgroup>
  419. </select>
  420. <br /></label>
  421. <div class="rbox">
  422. <label><input type="checkbox" name="with_redirect" value="1"<?php if ($action == 'single') echo ' checked="checked"' ?> /><?php echo $lang_misc['Leave redirect'] ?><br /></label>
  423. </div>
  424. </div>
  425. </fieldset>
  426. </div>
  427. <p class="buttons"><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>
  428. </form>
  429. </div>
  430. </div>
  431. <?php
  432. require PUN_ROOT.'footer.php';
  433. }
  434. // Merge two or more topics
  435. else if (isset($_POST['merge_topics']) || isset($_POST['merge_topics_comply']))
  436. {
  437. if (isset($_POST['merge_topics_comply']))
  438. {
  439. confirm_referrer('moderate.php');
  440. if (@preg_match('/[^0-9,]/', $_POST['topics']))
  441. message($lang_common['Bad request']);
  442. $topics = explode(',', $_POST['topics']);
  443. if (count($topics) < 2)
  444. message($lang_misc['Not enough topics selected']);
  445. // Verify that the topic IDs are valid (moved topics can not be merged?)
  446. // $result = $db->query('SELECT 1 FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $topics).') AND moved_to IS NULL AND forum_id='.$fid) or error('Unable to check topics', __FILE__, __LINE__, $db->error());
  447. $result = $db->query('SELECT 1 FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $topics).') AND forum_id='.$fid) or error('Unable to check topics', __FILE__, __LINE__, $db->error());
  448. if ($db->num_rows($result) != count($topics))
  449. message($lang_common['Bad request']);
  450. // Fetch the topic that we're merging into
  451. $result = $db->query('SELECT MIN(t.id) FROM '.$db->prefix.'topics AS t WHERE t.id IN('.implode(',', $topics).')') or error('Unable to get topic', __FILE__, __LINE__, $db->error());
  452. $merge_to_tid = $db->result($result);
  453. // Make any redirect topics point to our new, merged topic
  454. $query = 'UPDATE '.$db->prefix.'topics SET moved_to='.$merge_to_tid.' WHERE moved_to IN('.implode(',', $topics).')';
  455. // Should we create redirect topics?
  456. if (isset($_POST['with_redirect']))
  457. $query .= ' OR (id IN('.implode(',', $topics).') AND id != '.$merge_to_tid.')';
  458. $db->query($query) or error('Unable to make redirection topics', __FILE__, __LINE__, $db->error());
  459. // Merge the posts into the topic
  460. $db->query('UPDATE '.$db->prefix.'posts SET topic_id='.$merge_to_tid.' WHERE topic_id IN('.implode(',', $topics).')') or error('Unable to merge the posts into the topic', __FILE__, __LINE__, $db->error());
  461. // Delete any subscriptions
  462. $db->query('DELETE FROM '.$db->prefix.'topic_subscriptions WHERE topic_id IN('.implode(',', $topics).') AND topic_id != '.$merge_to_tid) or error('Unable to delete subscriptions', __FILE__, __LINE__, $db->error());
  463. // Without redirection the old topics are removed
  464. if (!isset($_POST['with_redirect']))
  465. $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $topics).') AND id != '.$merge_to_tid) or error('Unable to delete old topics', __FILE__, __LINE__, $db->error());
  466. // Count number of replies in the topic
  467. $result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'posts WHERE topic_id='.$merge_to_tid) or error('Unable to fetch post count for topic', __FILE__, __LINE__, $db->error());
  468. $num_replies = $db->result($result, 0) - 1;
  469. // Get last_post, last_post_id and last_poster
  470. $result = $db->query('SELECT posted, id, poster FROM '.$db->prefix.'posts WHERE topic_id='.$merge_to_tid.' ORDER BY id DESC LIMIT 1') or error('Unable to get last post info', __FILE__, __LINE__, $db->error());
  471. list($last_post, $last_post_id, $last_poster) = $db->fetch_row($result);
  472. // Update topic
  473. $db->query('UPDATE '.$db->prefix.'topics SET num_replies='.$num_replies.', last_post='.$last_post.', last_post_id='.$last_post_id.', last_poster=\''.$db->escape($last_poster).'\' WHERE id='.$merge_to_tid) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
  474. // Update the forum FROM which the topic was moved and redirect
  475. update_forum($fid);
  476. redirect('viewforum.php?id='.$fid, $lang_misc['Merge topics redirect']);
  477. }
  478. $topics = isset($_POST['topics']) ? $_POST['topics'] : array();
  479. if (count($topics) < 2)
  480. message($lang_misc['Not enough topics selected']);
  481. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_misc['Moderate']);
  482. define('PUN_ACTIVE_PAGE', 'index');
  483. require PUN_ROOT.'header.php';
  484. ?>
  485. <div class="blockform">
  486. <h2><span><?php echo $lang_misc['Merge topics'] ?></span></h2>
  487. <div class="box">
  488. <form method="post" action="moderate.php?fid=<?php echo $fid ?>">
  489. <input type="hidden" name="topics" value="<?php echo implode(',', array_map('intval', array_keys($topics))) ?>" />
  490. <div class="inform">
  491. <fieldset>
  492. <legend><?php echo $lang_misc['Confirm merge legend'] ?></legend>
  493. <div class="infldset">
  494. <div class="rbox">
  495. <label><input type="checkbox" name="with_redirect" value="1" /><?php echo $lang_misc['Leave redirect'] ?><br /></label>
  496. </div>
  497. </div>
  498. </fieldset>
  499. </div>
  500. <p class="buttons"><input type="submit" name="merge_topics_comply" value="<?php echo $lang_misc['Merge'] ?>" /> <a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
  501. </form>
  502. </div>
  503. </div>
  504. <?php
  505. require PUN_ROOT.'footer.php';
  506. }
  507. // Delete one or more topics
  508. else if (isset($_POST['delete_topics']) || isset($_POST['delete_topics_comply']))
  509. {
  510. $topics = isset($_POST['topics']) ? $_POST['topics'] : array();
  511. if (empty($topics))
  512. message($lang_misc['No topics selected']);
  513. if (isset($_POST['delete_topics_comply']))
  514. {
  515. confirm_referrer('moderate.php');
  516. if (@preg_match('/[^0-9,]/', $topics))
  517. message($lang_common['Bad request']);
  518. require PUN_ROOT.'include/search_idx.php';
  519. // Verify that the topic IDs are valid
  520. $result = $db->query('SELECT 1 FROM '.$db->prefix.'topics WHERE id IN('.$topics.') AND forum_id='.$fid) or error('Unable to check topics', __FILE__, __LINE__, $db->error());
  521. if ($db->num_rows($result) != substr_count($topics, ',') + 1)
  522. message($lang_common['Bad request']);
  523. //Attachment Mod Block Start
  524. foreach(explode(',',$topics) as $value)
  525. attach_delete_thread($value);
  526. //Attachment Mod Block End
  527. // Delete the topics and any redirect topics
  528. $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());
  529. // Delete any subscriptions
  530. $db->query('DELETE FROM '.$db->prefix.'topic_subscriptions WHERE topic_id IN('.$topics.')') or error('Unable to delete subscriptions', __FILE__, __LINE__, $db->error());
  531. // Create a list of the post IDs in this topic and then strip the search index
  532. $result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id IN('.$topics.')') or error('Unable to fetch posts', __FILE__, __LINE__, $db->error());
  533. $post_ids = '';
  534. while ($row = $db->fetch_row($result))
  535. $post_ids .= ($post_ids != '') ? ','.$row[0] : $row[0];
  536. // We have to check that we actually have a list of post IDs since we could be deleting just a redirect topic
  537. if ($post_ids != '')
  538. strip_search_index($post_ids);
  539. // Delete posts
  540. $db->query('DELETE FROM '.$db->prefix.'posts WHERE topic_id IN('.$topics.')') or error('Unable to delete posts', __FILE__, __LINE__, $db->error());
  541. update_forum($fid);
  542. redirect('viewforum.php?id='.$fid, $lang_misc['Delete topics redirect']);
  543. }
  544. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_misc['Moderate']);
  545. define('PUN_ACTIVE_PAGE', 'index');
  546. require PUN_ROOT.'header.php';
  547. ?>
  548. <div class="blockform">
  549. <h2><span><?php echo $lang_misc['Delete topics'] ?></span></h2>
  550. <div class="box">
  551. <form method="post" action="moderate.php?fid=<?php echo $fid ?>">
  552. <input type="hidden" name="topics" value="<?php echo implode(',', array_map('intval', array_keys($topics))) ?>" />
  553. <div class="inform">
  554. <fieldset>
  555. <legend><?php echo $lang_misc['Confirm delete legend'] ?></legend>
  556. <div class="infldset">
  557. <p><?php echo $lang_misc['Delete topics comply'] ?></p>
  558. </div>
  559. </fieldset>
  560. </div>
  561. <p class="buttons"><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>
  562. </form>
  563. </div>
  564. </div>
  565. <?php
  566. require PUN_ROOT.'footer.php';
  567. }
  568. // Open or close one or more topics
  569. else if (isset($_REQUEST['open']) || isset($_REQUEST['close']))
  570. {
  571. $action = (isset($_REQUEST['open'])) ? 0 : 1;
  572. // There could be an array of topic IDs in $_POST
  573. if (isset($_POST['open']) || isset($_POST['close']))
  574. {
  575. confirm_referrer('moderate.php');
  576. $topics = isset($_POST['topics']) ? @array_map('intval', @array_keys($_POST['topics'])) : array();
  577. if (empty($topics))
  578. message($lang_misc['No topics selected']);
  579. $db->query('UPDATE '.$db->prefix.'topics SET closed='.$action.' WHERE id IN('.implode(',', $topics).') AND forum_id='.$fid) or error('Unable to close topics', __FILE__, __LINE__, $db->error());
  580. $redirect_msg = ($action) ? $lang_misc['Close topics redirect'] : $lang_misc['Open topics redirect'];
  581. redirect('moderate.php?fid='.$fid, $redirect_msg);
  582. }
  583. // Or just one in $_GET
  584. else
  585. {
  586. confirm_referrer('viewtopic.php');
  587. $topic_id = ($action) ? intval($_GET['close']) : intval($_GET['open']);
  588. if ($topic_id < 1)
  589. message($lang_common['Bad request']);
  590. $db->query('UPDATE '.$db->prefix.'topics SET closed='.$action.' WHERE id='.$topic_id.' AND forum_id='.$fid) or error('Unable to close topic', __FILE__, __LINE__, $db->error());
  591. $redirect_msg = ($action) ? $lang_misc['Close topic redirect'] : $lang_misc['Open topic redirect'];
  592. redirect('viewtopic.php?id='.$topic_id, $redirect_msg);
  593. }
  594. }
  595. // Stick a topic
  596. else if (isset($_GET['stick']))
  597. {
  598. confirm_referrer('viewtopic.php');
  599. $stick = intval($_GET['stick']);
  600. if ($stick < 1)
  601. message($lang_common['Bad request']);
  602. $db->query('UPDATE '.$db->prefix.'topics SET sticky=\'1\' WHERE id='.$stick.' AND forum_id='.$fid) or error('Unable to stick topic', __FILE__, __LINE__, $db->error());
  603. redirect('viewtopic.php?id='.$stick, $lang_misc['Stick topic redirect']);
  604. }
  605. // Unstick a topic
  606. else if (isset($_GET['unstick']))
  607. {
  608. confirm_referrer('viewtopic.php');
  609. $unstick = intval($_GET['unstick']);
  610. if ($unstick < 1)
  611. message($lang_common['Bad request']);
  612. $db->query('UPDATE '.$db->prefix.'topics SET sticky=\'0\' WHERE id='.$unstick.' AND forum_id='.$fid) or error('Unable to unstick topic', __FILE__, __LINE__, $db->error());
  613. redirect('viewtopic.php?id='.$unstick, $lang_misc['Unstick topic redirect']);
  614. }
  615. // No specific forum moderation action was specified in the query string, so we'll display the moderator forum
  616. // Load the viewforum.php language file
  617. require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';
  618. // Fetch some info about the forum
  619. $result = $db->query('SELECT f.forum_name, f.redirect_url, f.num_topics, f.sort_by 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());
  620. if (!$db->num_rows($result))
  621. message($lang_common['Bad request']);
  622. $cur_forum = $db->fetch_assoc($result);
  623. // Is this a redirect forum? In that case, abort!
  624. if ($cur_forum['redirect_url'] != '')
  625. message($lang_common['Bad request']);
  626. switch ($cur_forum['sort_by'])
  627. {
  628. case 0:
  629. $sort_by = 'last_post DESC';
  630. break;
  631. case 1:
  632. $sort_by = 'posted DESC';
  633. break;
  634. case 2:
  635. $sort_by = 'subject ASC';
  636. break;
  637. default:
  638. $sort_by = 'last_post DESC';
  639. break;
  640. }
  641. // Determine the topic offset (based on $_GET['p'])
  642. $num_pages = ceil($cur_forum['num_topics'] / $pun_user['disp_topics']);
  643. $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : intval($_GET['p']);
  644. $start_from = $pun_user['disp_topics'] * ($p - 1);
  645. // Generate paging links
  646. $paging_links = '<span class="pages-label">'.$lang_common['Pages'].' </span>'.paginate($num_pages, $p, 'moderate.php?fid='.$fid);
  647. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), pun_htmlspecialchars($cur_forum['forum_name']));
  648. define('PUN_ACTIVE_PAGE', 'index');
  649. require PUN_ROOT.'header.php';
  650. ?>
  651. <div class="linkst">
  652. <div class="inbox crumbsplus">
  653. <ul class="crumbs">
  654. <li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li>
  655. <li><span>»&#160;</span><a href="viewforum.php?id=<?php echo $fid ?>"><?php echo pun_htmlspecialchars($cur_forum['forum_name']) ?></a></li>
  656. <li><span>»&#160;</span><strong><?php echo $lang_misc['Moderate'] ?></strong></li>
  657. </ul>
  658. <div class="pagepost">
  659. <p class="pagelink conl"><?php echo $paging_links ?></p>
  660. </div>
  661. <div class="clearer"></div>
  662. </div>
  663. </div>
  664. <form method="post" action="moderate.php?fid=<?php echo $fid ?>">
  665. <div id="vf" class="blocktable">
  666. <h2><span><?php echo pun_htmlspecialchars($cur_forum['forum_name']) ?></span></h2>
  667. <div class="box">
  668. <div class="inbox">
  669. <table cellspacing="0">
  670. <thead>
  671. <tr>
  672. <th class="tcl" scope="col"><?php echo $lang_common['Topic'] ?></th>
  673. <th class="tc2" scope="col"><?php echo $lang_common['Replies'] ?></th>
  674. <?php if ($pun_config['o_topic_views'] == '1'): ?> <th class="tc3" scope="col"><?php echo $lang_forum['Views'] ?></th>
  675. <?php endif; ?> <th class="tcr"><?php echo $lang_common['Last post'] ?></th>
  676. <th class="tcmod" scope="col"><?php echo $lang_misc['Select'] ?></th>
  677. </tr>
  678. </thead>
  679. <tbody>
  680. <?php
  681. // Retrieve a list of topic IDs, LIMIT is (really) expensive so we only fetch the IDs here then later fetch the remaining data
  682. $result = $db->query('SELECT id FROM '.$db->prefix.'topics WHERE forum_id='.$fid.' ORDER BY sticky DESC, '.$sort_by.', id DESC LIMIT '.$start_from.', '.$pun_user['disp_topics']) or error('Unable to fetch topic IDs', __FILE__, __LINE__, $db->error());
  683. // If there are topics in this forum
  684. if ($db->num_rows($result))
  685. {
  686. $topic_ids = array();
  687. for ($i = 0;$cur_topic_id = $db->result($result, $i);$i++)
  688. $topic_ids[] = $cur_topic_id;
  689. // Select topics
  690. $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 id IN('.implode(',', $topic_ids).') ORDER BY sticky DESC, '.$sort_by.', id DESC') or error('Unable to fetch topic list for forum', __FILE__, __LINE__, $db->error());
  691. $button_status = '';
  692. $topic_count = 0;
  693. while ($cur_topic = $db->fetch_assoc($result))
  694. {
  695. ++$topic_count;
  696. $status_text = array();
  697. $item_status = ($topic_count % 2 == 0) ? 'roweven' : 'rowodd';
  698. $icon_type = 'icon';
  699. if ($cur_topic['moved_to'] == null)
  700. {
  701. $last_post = '<a href="viewtopic.php?pid='.$cur_topic['last_post_id'].'#p'.$cur_topic['last_post_id'].'">'.format_time($cur_topic['last_post']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['last_poster']).'</span>';
  702. $ghost_topic = false;
  703. }
  704. else
  705. {
  706. $last_post = '- - -';
  707. $ghost_topic = true;
  708. }
  709. if ($pun_config['o_censoring'] == '1')
  710. $cur_topic['subject'] = censor_words($cur_topic['subject']);
  711. if ($cur_topic['sticky'] == '1')
  712. {
  713. $item_status .= ' isticky';
  714. $status_text[] = '<span class="stickytext">'.$lang_forum['Sticky'].'</span>';
  715. }
  716. if ($cur_topic['moved_to'] != 0)
  717. {
  718. $subject = '<a href="viewtopic.php?id='.$cur_topic['moved_to'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>';
  719. $status_text[] = '<span class="movedtext">'.$lang_forum['Moved'].'</span>';
  720. $item_status .= ' imoved';
  721. }
  722. else if ($cur_topic['closed'] == '0')
  723. $subject = '<a href="viewtopic.php?id='.$cur_topic['id'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>';
  724. else
  725. {
  726. $subject = '<a href="viewtopic.php?id='.$cur_topic['id'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>';
  727. $status_text[] = '<span class="closedtext">'.$lang_forum['Closed'].'</span>';
  728. $item_status .= ' iclosed';
  729. }
  730. if (!$ghost_topic && $cur_topic['last_post'] > $pun_user['last_visit'] && (!isset($tracked_topics['topics'][$cur_topic['id']]) || $tracked_topics['topics'][$cur_topic['id']] < $cur_topic['last_post']) && (!isset($tracked_topics['forums'][$fid]) || $tracked_topics['forums'][$fid] < $cur_topic['last_post']))
  731. {
  732. $item_status .= ' inew';
  733. $icon_type = 'icon icon-new';
  734. $subject = '<strong>'.$subject.'</strong>';
  735. $subject_new_posts = '<span class="newtext">[ <a href="viewtopic.php?id='.$cur_topic['id'].'&amp;action=new" title="'.$lang_common['New posts info'].'">'.$lang_common['New posts'].'</a> ]</span>';
  736. }
  737. else
  738. $subject_new_posts = null;
  739. // Insert the status text before the subject
  740. $subject = implode(' ', $status_text).' '.$subject;
  741. $num_pages_topic = ceil(($cur_topic['num_replies'] + 1) / $pun_user['disp_posts']);
  742. if ($num_pages_topic > 1)
  743. $subject_multipage = '<span class="pagestext">[ '.paginate($num_pages_topic, -1, 'viewtopic.php?id='.$cur_topic['id']).' ]</span>';
  744. else
  745. $subject_multipage = null;
  746. // Should we show the "New posts" and/or the multipage links?
  747. if (!empty($subject_new_posts) || !empty($subject_multipage))
  748. {
  749. $subject .= !empty($subject_new_posts) ? ' '.$subject_new_posts : '';
  750. $subject .= !empty($subject_multipage) ? ' '.$subject_multipage : '';
  751. }
  752. ?>
  753. <tr class="<?php echo $item_status ?>">
  754. <td class="tcl">
  755. <div class="<?php echo $icon_type ?>"><div class="nosize"><?php echo forum_number_format($topic_count + $start_from) ?></div></div>
  756. <div class="tclcon">
  757. <div>
  758. <?php echo $subject."\n" ?>
  759. </div>
  760. </div>
  761. </td>
  762. <td class="tc2"><?php echo (!$ghost_topic) ? forum_number_format($cur_topic['num_replies']) : '-' ?></td>
  763. <?php if ($pun_config['o_topic_views'] == '1'): ?> <td class="tc3"><?php echo (!$ghost_topic) ? forum_number_format($cur_topic['num_views']) : '-' ?></td>
  764. <?php endif; ?> <td class="tcr"><?php echo $last_post ?></td>
  765. <td class="tcmod"><input type="checkbox" name="topics[<?php echo $cur_topic['id'] ?>]" value="1" /></td>
  766. </tr>
  767. <?php
  768. }
  769. }
  770. else
  771. {
  772. $colspan = ($pun_config['o_topic_views'] == '1') ? 5 : 4;
  773. $button_status = ' disabled="disabled"';
  774. echo "\t\t\t\t\t".'<tr><td class="tcl" colspan="'.$colspan.'">'.$lang_forum['Empty forum'].'</td></tr>'."\n";
  775. }
  776. ?>
  777. </tbody>
  778. </table>
  779. </div>
  780. </div>
  781. </div>
  782. <div class="linksb">
  783. <div class="inbox crumbsplus">
  784. <div class="pagepost">
  785. <p class="pagelink conl"><?php echo $paging_links ?></p>
  786. <p class="conr modbuttons"><input type="submit" name="move_topics" value="<?php echo $lang_misc['Move'] ?>"<?php echo $button_status ?> /> <input type="submit" name="delete_topics" value="<?php echo $lang_misc['Delete'] ?>"<?php echo $button_status ?> /> <input type="submit" name="merge_topics" value="<?php echo $lang_misc['Merge'] ?>"<?php echo $button_status ?> /> <input type="submit" name="open" value="<?php echo $lang_misc['Open'] ?>"<?php echo $button_status ?> /> <input type="submit" name="close" value="<?php echo $lang_misc['Close'] ?>"<?php echo $button_status ?> /></p>
  787. <div class="clearer"></div>
  788. </div>
  789. <ul class="crumbs">
  790. <li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li>
  791. <li><span>»&#160;</span><a href="viewforum.php?id=<?php echo $fid ?>"><?php echo pun_htmlspecialchars($cur_forum['forum_name']) ?></a></li>
  792. <li><span>»&#160;</span><strong><?php echo $lang_misc['Moderate'] ?></strong></li>
  793. </ul>
  794. <div class="clearer"></div>
  795. </div>
  796. </div>
  797. </form>
  798. <?php
  799. require PUN_ROOT.'footer.php';