PageRenderTime 35ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/forum/viewtopic.php

https://github.com/GreyTeardrop/socionicasys-forum
PHP | 2079 lines | 1562 code | 285 blank | 232 comment | 452 complexity | fbdeaf1f81801c86754227bde276e73c MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-3.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. *
  4. * @package phpBB3
  5. * @version $Id$
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. define('IN_PHPBB', true);
  14. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  15. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  16. include($phpbb_root_path . 'common.' . $phpEx);
  17. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  18. include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
  19. include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
  20. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  21. if (empty($_REQUEST['f'])) {
  22. $phpbb_seo->get_forum_id($session_forum_id);
  23. if ($session_forum_id > 0) {
  24. $_REQUEST['f'] = (int) $session_forum_id;
  25. }
  26. }
  27. if (!empty($_REQUEST['hilit'])) {
  28. $_REQUEST['hilit'] = rawurldecode($_REQUEST['hilit']);
  29. if (!$phpbb_seo->is_utf8($_REQUEST['hilit'])) {
  30. $_REQUEST['hilit'] = utf8_normalize_nfc(utf8_recode($_REQUEST['hilit'], 'iso-8859-1'));
  31. }
  32. }
  33. // www.phpBB-SEO.com SEO TOOLKIT END
  34. // Start session management
  35. $user->session_begin();
  36. $auth->acl($user->data);
  37. // Initial var setup
  38. $forum_id = request_var('f', 0);
  39. $topic_id = request_var('t', 0);
  40. $post_id = request_var('p', 0);
  41. $voted_id = request_var('vote_id', array('' => 0));
  42. $voted_id = (sizeof($voted_id) > 1) ? array_unique($voted_id) : $voted_id;
  43. $start = request_var('start', 0);
  44. $view = request_var('view', '');
  45. $default_sort_days = (!empty($user->data['user_post_show_days'])) ? $user->data['user_post_show_days'] : 0;
  46. $default_sort_key = (!empty($user->data['user_post_sortby_type'])) ? $user->data['user_post_sortby_type'] : 't';
  47. $default_sort_dir = (!empty($user->data['user_post_sortby_dir'])) ? $user->data['user_post_sortby_dir'] : 'a';
  48. $sort_days = request_var('st', $default_sort_days);
  49. $sort_key = request_var('sk', $default_sort_key);
  50. $sort_dir = request_var('sd', $default_sort_dir);
  51. $update = request_var('update', false);
  52. $s_can_vote = false;
  53. /**
  54. * @todo normalize?
  55. */
  56. $hilit_words = request_var('hilit', '', true);
  57. // Do we have a topic or post id?
  58. if (!$topic_id && !$post_id)
  59. {
  60. trigger_error('NO_TOPIC');
  61. }
  62. // Find topic id if user requested a newer or older topic
  63. if ($view && !$post_id)
  64. {
  65. if (!$forum_id)
  66. {
  67. $sql = 'SELECT forum_id
  68. FROM ' . TOPICS_TABLE . "
  69. WHERE topic_id = $topic_id";
  70. $result = $db->sql_query($sql);
  71. $forum_id = (int) $db->sql_fetchfield('forum_id');
  72. $db->sql_freeresult($result);
  73. if (!$forum_id)
  74. {
  75. trigger_error('NO_TOPIC');
  76. }
  77. }
  78. if ($view == 'unread')
  79. {
  80. // Get topic tracking info
  81. $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id);
  82. $topic_last_read = (isset($topic_tracking_info[$topic_id])) ? $topic_tracking_info[$topic_id] : 0;
  83. $sql = 'SELECT post_id, topic_id, forum_id
  84. FROM ' . POSTS_TABLE . "
  85. WHERE topic_id = $topic_id
  86. " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND post_approved = 1') . "
  87. AND post_time > $topic_last_read
  88. AND forum_id = $forum_id
  89. ORDER BY post_time ASC";
  90. $result = $db->sql_query_limit($sql, 1);
  91. $row = $db->sql_fetchrow($result);
  92. $db->sql_freeresult($result);
  93. if (!$row)
  94. {
  95. $sql = 'SELECT topic_last_post_id as post_id, topic_id, forum_id
  96. FROM ' . TOPICS_TABLE . '
  97. WHERE topic_id = ' . $topic_id;
  98. $result = $db->sql_query($sql);
  99. $row = $db->sql_fetchrow($result);
  100. $db->sql_freeresult($result);
  101. }
  102. if (!$row)
  103. {
  104. // Setup user environment so we can process lang string
  105. $user->setup('viewtopic');
  106. trigger_error('NO_TOPIC');
  107. }
  108. $post_id = $row['post_id'];
  109. $topic_id = $row['topic_id'];
  110. }
  111. else if ($view == 'next' || $view == 'previous')
  112. {
  113. $sql_condition = ($view == 'next') ? '>' : '<';
  114. $sql_ordering = ($view == 'next') ? 'ASC' : 'DESC';
  115. $sql = 'SELECT forum_id, topic_last_post_time
  116. FROM ' . TOPICS_TABLE . '
  117. WHERE topic_id = ' . $topic_id;
  118. $result = $db->sql_query($sql);
  119. $row = $db->sql_fetchrow($result);
  120. $db->sql_freeresult($result);
  121. if (!$row)
  122. {
  123. $user->setup('viewtopic');
  124. // OK, the topic doesn't exist. This error message is not helpful, but technically correct.
  125. trigger_error(($view == 'next') ? 'NO_NEWER_TOPICS' : 'NO_OLDER_TOPICS');
  126. }
  127. else
  128. {
  129. $sql = 'SELECT topic_id, forum_id
  130. FROM ' . TOPICS_TABLE . '
  131. WHERE forum_id = ' . $row['forum_id'] . "
  132. AND topic_moved_id = 0
  133. AND topic_last_post_time $sql_condition {$row['topic_last_post_time']}
  134. " . (($auth->acl_get('m_approve', $row['forum_id'])) ? '' : 'AND topic_approved = 1') . "
  135. ORDER BY topic_last_post_time $sql_ordering";
  136. $result = $db->sql_query_limit($sql, 1);
  137. $row = $db->sql_fetchrow($result);
  138. $db->sql_freeresult($result);
  139. if (!$row)
  140. {
  141. $user->setup('viewtopic');
  142. trigger_error(($view == 'next') ? 'NO_NEWER_TOPICS' : 'NO_OLDER_TOPICS');
  143. }
  144. else
  145. {
  146. $topic_id = $row['topic_id'];
  147. // Check for global announcement correctness?
  148. if (!$row['forum_id'] && !$forum_id)
  149. {
  150. trigger_error('NO_TOPIC');
  151. }
  152. else if ($row['forum_id'])
  153. {
  154. $forum_id = $row['forum_id'];
  155. }
  156. }
  157. }
  158. }
  159. // Check for global announcement correctness?
  160. if ((!isset($row) || !$row['forum_id']) && !$forum_id)
  161. {
  162. trigger_error('NO_TOPIC');
  163. }
  164. else if (isset($row) && $row['forum_id'])
  165. {
  166. $forum_id = $row['forum_id'];
  167. }
  168. }
  169. // This rather complex gaggle of code handles querying for topics but
  170. // also allows for direct linking to a post (and the calculation of which
  171. // page the post is on and the correct display of viewtopic)
  172. $sql_array = array(
  173. 'SELECT' => 't.*, f.*',
  174. 'FROM' => array(FORUMS_TABLE => 'f'),
  175. );
  176. // Firebird handles two columns of the same name a little differently, this
  177. // addresses that by forcing the forum_id to come from the forums table.
  178. if ($db->sql_layer === 'firebird')
  179. {
  180. $sql_array['SELECT'] = 'f.forum_id AS forum_id, ' . $sql_array['SELECT'];
  181. }
  182. // The FROM-Order is quite important here, else t.* columns can not be correctly bound.
  183. if ($post_id)
  184. {
  185. $sql_array['SELECT'] .= ', p.post_approved';
  186. $sql_array['FROM'][POSTS_TABLE] = 'p';
  187. }
  188. // Topics table need to be the last in the chain
  189. $sql_array['FROM'][TOPICS_TABLE] = 't';
  190. if ($user->data['is_registered'])
  191. {
  192. $sql_array['SELECT'] .= ', tw.notify_status';
  193. $sql_array['LEFT_JOIN'] = array();
  194. $sql_array['LEFT_JOIN'][] = array(
  195. 'FROM' => array(TOPICS_WATCH_TABLE => 'tw'),
  196. 'ON' => 'tw.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tw.topic_id'
  197. );
  198. if ($config['allow_bookmarks'])
  199. {
  200. $sql_array['SELECT'] .= ', bm.topic_id as bookmarked';
  201. $sql_array['LEFT_JOIN'][] = array(
  202. 'FROM' => array(BOOKMARKS_TABLE => 'bm'),
  203. 'ON' => 'bm.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = bm.topic_id'
  204. );
  205. }
  206. if ($config['load_db_lastread'])
  207. {
  208. $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as forum_mark_time';
  209. $sql_array['LEFT_JOIN'][] = array(
  210. 'FROM' => array(TOPICS_TRACK_TABLE => 'tt'),
  211. 'ON' => 'tt.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tt.topic_id'
  212. );
  213. $sql_array['LEFT_JOIN'][] = array(
  214. 'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
  215. 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND t.forum_id = ft.forum_id'
  216. );
  217. }
  218. }
  219. if (!$post_id)
  220. {
  221. $sql_array['WHERE'] = "t.topic_id = $topic_id";
  222. }
  223. else
  224. {
  225. $sql_array['WHERE'] = "p.post_id = $post_id AND t.topic_id = p.topic_id";
  226. }
  227. $sql_array['WHERE'] .= ' AND (f.forum_id = t.forum_id';
  228. if (!$forum_id)
  229. {
  230. // If it is a global announcement make sure to set the forum id to a postable forum
  231. $sql_array['WHERE'] .= ' OR (t.topic_type = ' . POST_GLOBAL . '
  232. AND f.forum_type = ' . FORUM_POST . ')';
  233. }
  234. else
  235. {
  236. $sql_array['WHERE'] .= ' OR (t.topic_type = ' . POST_GLOBAL . "
  237. AND f.forum_id = $forum_id)";
  238. }
  239. $sql_array['WHERE'] .= ')';
  240. // Join to forum table on topic forum_id unless topic forum_id is zero
  241. // whereupon we join on the forum_id passed as a parameter ... this
  242. // is done so navigation, forum name, etc. remain consistent with where
  243. // user clicked to view a global topic
  244. $sql = $db->sql_build_query('SELECT', $sql_array);
  245. $result = $db->sql_query($sql);
  246. $topic_data = $db->sql_fetchrow($result);
  247. $db->sql_freeresult($result);
  248. // link to unapproved post or incorrect link
  249. if (!$topic_data)
  250. {
  251. // If post_id was submitted, we try at least to display the topic as a last resort...
  252. if ($post_id && $topic_id)
  253. {
  254. redirect(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t=$topic_id" . (($forum_id) ? "&amp;f=$forum_id" : '')));
  255. }
  256. trigger_error('NO_TOPIC');
  257. }
  258. $forum_id = (int) $topic_data['forum_id'];
  259. // This is for determining where we are (page)
  260. if ($post_id)
  261. {
  262. // are we where we are supposed to be?
  263. if (!$topic_data['post_approved'] && !$auth->acl_get('m_approve', $topic_data['forum_id']))
  264. {
  265. // If post_id was submitted, we try at least to display the topic as a last resort...
  266. if ($topic_id)
  267. {
  268. redirect(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t=$topic_id" . (($forum_id) ? "&amp;f=$forum_id" : '')));
  269. }
  270. trigger_error('NO_TOPIC');
  271. }
  272. if ($post_id == $topic_data['topic_first_post_id'] || $post_id == $topic_data['topic_last_post_id'])
  273. {
  274. $check_sort = ($post_id == $topic_data['topic_first_post_id']) ? 'd' : 'a';
  275. if ($sort_dir == $check_sort)
  276. {
  277. $topic_data['prev_posts'] = ($auth->acl_get('m_approve', $forum_id)) ? $topic_data['topic_replies_real'] : $topic_data['topic_replies'];
  278. }
  279. else
  280. {
  281. $topic_data['prev_posts'] = 0;
  282. }
  283. }
  284. else
  285. {
  286. $sql = 'SELECT COUNT(p1.post_id) AS prev_posts
  287. FROM ' . POSTS_TABLE . ' p1, ' . POSTS_TABLE . " p2
  288. WHERE p1.topic_id = {$topic_data['topic_id']}
  289. AND p2.post_id = {$post_id}
  290. " . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p1.post_approved = 1' : '') . '
  291. AND ' . (($sort_dir == 'd') ? 'p1.post_time >= p2.post_time' : 'p1.post_time <= p2.post_time');
  292. $result = $db->sql_query($sql);
  293. $row = $db->sql_fetchrow($result);
  294. $db->sql_freeresult($result);
  295. $topic_data['prev_posts'] = $row['prev_posts'] - 1;
  296. }
  297. }
  298. $topic_id = (int) $topic_data['topic_id'];
  299. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  300. $phpbb_seo->set_url($topic_data['forum_name'], $forum_id, 'forum');
  301. if ($topic_data['topic_type'] == POST_GLOBAL) {
  302. // Let's make sure user will see global annoucements
  303. $auth->cache[$forum_id]['f_read'] = 1;
  304. $_parent = $phpbb_seo->seo_static['global_announce'];
  305. } else {
  306. $_parent = $phpbb_seo->seo_url['forum'][$forum_id];
  307. }
  308. if (!empty($phpbb_seo->seo_opt['sql_rewrite']) || !empty($topic_data['topic_url'])) {
  309. if ( !$phpbb_seo->check_url('topic', $topic_data['topic_url'], $_parent)) {
  310. if (!empty($topic_data['topic_url'])) {
  311. // Here we get rid of the seo delim (-t) and put it back even in simple mod
  312. // to be able to handle all cases at once
  313. $_url = preg_replace('`' . $phpbb_seo->seo_delim['topic'] . '$`i', '', $topic_data['topic_url']);
  314. $_title = $phpbb_seo->get_url_info('topic', $_url . $phpbb_seo->seo_delim['topic'] . $topic_id, 'title');
  315. } else {
  316. $_title = $phpbb_seo->modrtype > 2 ? censor_text($topic_data['topic_title']) : '';
  317. }
  318. unset($phpbb_seo->seo_url['topic'][$topic_id]);
  319. $topic_data['topic_url'] = $phpbb_seo->get_url_info('topic', $phpbb_seo->prepare_url( 'topic', $_title, $topic_id, $_parent, (( empty($_title) || ($_title == $phpbb_seo->seo_static['topic']) ) ? true : false) ), 'url');
  320. unset($phpbb_seo->seo_url['topic'][$topic_id]);
  321. if ($topic_data['topic_url']) {
  322. // Update the topic_url field for later re-use
  323. $sql = "UPDATE " . TOPICS_TABLE . " SET topic_url = '" . $db->sql_escape($topic_data['topic_url']) . "'
  324. WHERE topic_id = $topic_id";
  325. $db->sql_query($sql);
  326. }
  327. }
  328. } else {
  329. $topic_data['topic_url'] = '';
  330. }
  331. $phpbb_seo->prepare_iurl($topic_data, 'topic', $_parent);
  332. // www.phpBB-SEO.com SEO TOOLKIT END
  333. //
  334. $topic_replies = ($auth->acl_get('m_approve', $forum_id)) ? $topic_data['topic_replies_real'] : $topic_data['topic_replies'];
  335. // Check sticky/announcement time limit
  336. if (($topic_data['topic_type'] == POST_STICKY || $topic_data['topic_type'] == POST_ANNOUNCE) && $topic_data['topic_time_limit'] && ($topic_data['topic_time'] + $topic_data['topic_time_limit']) < time())
  337. {
  338. $sql = 'UPDATE ' . TOPICS_TABLE . '
  339. SET topic_type = ' . POST_NORMAL . ', topic_time_limit = 0
  340. WHERE topic_id = ' . $topic_id;
  341. $db->sql_query($sql);
  342. $topic_data['topic_type'] = POST_NORMAL;
  343. $topic_data['topic_time_limit'] = 0;
  344. }
  345. // Setup look and feel
  346. $user->setup('viewtopic', $topic_data['forum_style']);
  347. if (!$topic_data['topic_approved'] && !$auth->acl_get('m_approve', $forum_id))
  348. {
  349. trigger_error('NO_TOPIC');
  350. }
  351. // Start auth check
  352. if (!$auth->acl_get('f_read', $forum_id))
  353. {
  354. if ($user->data['user_id'] != ANONYMOUS)
  355. {
  356. trigger_error('SORRY_AUTH_READ');
  357. }
  358. login_box('', $user->lang['LOGIN_VIEWFORUM']);
  359. }
  360. // Forum is passworded ... check whether access has been granted to this
  361. // user this session, if not show login box
  362. if ($topic_data['forum_password'])
  363. {
  364. login_forum_box($topic_data);
  365. }
  366. // Redirect to login or to the correct post upon emailed notification links
  367. if (isset($_GET['e']))
  368. {
  369. $jump_to = request_var('e', 0);
  370. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  371. //$redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id");
  372. // www.phpBB-SEO.com SEO TOOLKIT END
  373. if ($user->data['user_id'] == ANONYMOUS)
  374. {
  375. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  376. login_box(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;p=$post_id&amp;e=$jump_to"), $user->lang['LOGIN_NOTIFY_TOPIC']);
  377. // www.phpBB-SEO.com SEO TOOLKIT END
  378. }
  379. if ($jump_to > 0)
  380. {
  381. // We direct the already logged in user to the correct post...
  382. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  383. redirect(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id" . ((!$post_id) ? "&amp;p=$jump_to" : "&amp;p=$post_id")) . "#p$jump_to");
  384. // www.phpBB-SEO.com SEO TOOLKIT END
  385. }
  386. }
  387. // What is start equal to?
  388. if ($post_id)
  389. {
  390. $start = floor(($topic_data['prev_posts']) / $config['posts_per_page']) * $config['posts_per_page'];
  391. }
  392. // Get topic tracking info
  393. if (!isset($topic_tracking_info))
  394. {
  395. $topic_tracking_info = array();
  396. // Get topic tracking info
  397. if ($config['load_db_lastread'] && $user->data['is_registered'])
  398. {
  399. $tmp_topic_data = array($topic_id => $topic_data);
  400. $topic_tracking_info = get_topic_tracking($forum_id, $topic_id, $tmp_topic_data, array($forum_id => $topic_data['forum_mark_time']));
  401. unset($tmp_topic_data);
  402. }
  403. else if ($config['load_anon_lastread'] || $user->data['is_registered'])
  404. {
  405. $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id);
  406. }
  407. }
  408. // Post ordering options
  409. $limit_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
  410. $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
  411. $sort_by_sql = array('a' => array('u.username_clean', 'p.post_id'), 't' => 'p.post_time', 's' => array('p.post_subject', 'p.post_id'));
  412. $join_user_sql = array('a' => true, 't' => false, 's' => false);
  413. $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
  414. gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param, $default_sort_days, $default_sort_key, $default_sort_dir);
  415. // Obtain correct post count and ordering SQL if user has
  416. // requested anything different
  417. if ($sort_days)
  418. {
  419. $min_post_time = time() - ($sort_days * 86400);
  420. $sql = 'SELECT COUNT(post_id) AS num_posts
  421. FROM ' . POSTS_TABLE . "
  422. WHERE topic_id = $topic_id
  423. AND post_time >= $min_post_time
  424. " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND post_approved = 1');
  425. $result = $db->sql_query($sql);
  426. $total_posts = (int) $db->sql_fetchfield('num_posts');
  427. $db->sql_freeresult($result);
  428. $limit_posts_time = "AND p.post_time >= $min_post_time ";
  429. if (isset($_POST['sort']))
  430. {
  431. $start = 0;
  432. }
  433. }
  434. else
  435. {
  436. $total_posts = $topic_replies + 1;
  437. $limit_posts_time = '';
  438. }
  439. // Was a highlight request part of the URI?
  440. $highlight_match = $highlight = '';
  441. if ($hilit_words)
  442. {
  443. foreach (explode(' ', trim($hilit_words)) as $word)
  444. {
  445. if (trim($word))
  446. {
  447. $word = str_replace('\*', '\w+?', preg_quote($word, '#'));
  448. $word = preg_replace('#(^|\s)\\\\w\*\?(\s|$)#', '$1\w+?$2', $word);
  449. $highlight_match .= (($highlight_match != '') ? '|' : '') . $word;
  450. }
  451. }
  452. $highlight = urlencode($hilit_words);
  453. }
  454. // Make sure $start is set to the last page if it exceeds the amount
  455. if ($start < 0 || $start >= $total_posts)
  456. {
  457. $start = ($start < 0) ? 0 : floor(($total_posts - 1) / $config['posts_per_page']) * $config['posts_per_page'];
  458. }
  459. // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> Zero dupe
  460. $phpbb_seo->seo_opt['zero_dupe']['start'] = $phpbb_seo->seo_chk_start( $start, $config['posts_per_page'] );
  461. // Changings for primehalo's Post Revision MOD
  462. $displ_history = request_var('display_history', false);
  463. $rem_history = request_var('remove_history', '');
  464. $conf_key = request_var('confirm_key', '');
  465. if (!empty($phpbb_seo->seo_opt['url_rewrite'])) {
  466. $phpbb_seo->seo_path['canonical'] = $phpbb_seo->drop_sid(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;start=$start"));
  467. }
  468. if ( $post_id && !$view && !$phpbb_seo->set_do_redir_post()) {
  469. $phpbb_seo->seo_opt['zero_dupe']['redir_def'] = array(
  470. 'p' => array('val' => $post_id, 'keep' => true, 'force' => true, 'hash' => "p$post_id"),
  471. 'hilit' => array('val' => (($highlight_match) ? $highlight : ''), 'keep' => !empty($highlight_match)),
  472. // Changings for primehalo's Post Revision MOD
  473. 'display_history' => array('val' => $displ_history, 'keep' => (boolean) ($displ_history == true)),
  474. 'remove_history' => array('val' => $rem_history, 'keep' => $rem_history),
  475. 'confirm_key' => array('val' => $conf_key, 'keep' => $conf_key),
  476. );
  477. } else {
  478. $seo_watch = request_var('watch', '');
  479. $seo_unwatch = request_var('unwatch', '');
  480. $seo_bookmark = request_var('bookmark', 0);
  481. $keep_watch = (boolean) ($seo_watch == 'topic' && $user->data['is_registered']);
  482. $keep_unwatch = (boolean) ($seo_unwatch == 'topic' && $user->data['is_registered']);
  483. $keep_hash = (boolean) ($keep_watch || $keep_unwatch || $seo_bookmark);
  484. $seo_uid = max(0, request_var('uid', 0));
  485. $phpbb_seo->seo_opt['zero_dupe']['redir_def'] = array(
  486. 'uid' => array('val' => $seo_uid, 'keep' => (boolean) ($keep_hash && $seo_uid)),
  487. 'f' => array('val' => $forum_id, 'keep' => true, 'force' => true),
  488. 't' => array('val' => $topic_id, 'keep' => true, 'force' => true, 'hash' => $post_id ? "p$post_id" : ''),
  489. // Changings for primehalo's Post Revision MOD
  490. 'p' => array('val' => $post_id, 'keep' => ((($post_id && $view == 'show') || $displ_history || !empty($rem_history) || !empty($conf_key)) ? true : false), 'hash' => "p$post_id"),
  491. 'display_history' => array('val' => $displ_history, 'keep' => (boolean) ($displ_history == true)),
  492. 'remove_history' => array('val' => $rem_history, 'keep' => $rem_history),
  493. 'confirm_key' => array('val' => $conf_key, 'keep' => $conf_key),
  494. 'watch' => array('val' => $seo_watch, 'keep' => $keep_watch),
  495. 'unwatch' => array('val' => $seo_unwatch, 'keep' => $keep_unwatch),
  496. 'bookmark' => array('val' => $seo_bookmark, 'keep' => (boolean) ($user->data['is_registered'] && $config['allow_bookmarks'] && $seo_bookmark)),
  497. 'start' => array('val' => $phpbb_seo->seo_opt['zero_dupe']['start'], 'keep' => true, 'force' => true),
  498. 'hash' => array('val' => request_var('hash', ''), 'keep' => $keep_hash),
  499. 'st' => array('val' => $sort_days, 'keep' => true),
  500. 'sk' => array('val' => $sort_key, 'keep' => true),
  501. 'sd' => array('val' => $sort_dir, 'keep' => true),
  502. 'view' => array('val' => $view, 'keep' => $view == 'print' ? (boolean) $auth->acl_get('f_print', $forum_id) : (($view == 'viewpoll' || $view == 'show') ? true : false)),
  503. 'hilit' => array('val' => (($highlight_match) ? $highlight : ''), 'keep' => (boolean) !(!$user->data['is_registered'] && $phpbb_seo->seo_opt['rem_hilit'])),
  504. );
  505. if ($phpbb_seo->seo_opt['zero_dupe']['redir_def']['bookmark']['keep']) { // Prevent unessecary redirections
  506. // Note : bookmark, watch and unwatch cases could just not be handled by the zero dupe (no redirect at all when used),
  507. // but the handling as well acts as a poweful security shield so, it's worth it ;)
  508. unset($phpbb_seo->seo_opt['zero_dupe']['redir_def']['start']);
  509. }
  510. }
  511. $phpbb_seo->seo_chk_dupe();
  512. // www.phpBB-SEO.com SEO TOOLKIT END -> Zero dupe
  513. // General Viewtopic URL for return links
  514. $viewtopic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id" . (($start == 0) ? '' : "&amp;start=$start") . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : '') . (($highlight_match) ? "&amp;hilit=$highlight" : ''));
  515. // Are we watching this topic?
  516. $s_watching_topic = array(
  517. 'link' => '',
  518. 'title' => '',
  519. 'is_watching' => false,
  520. );
  521. if (($config['email_enable'] || $config['jab_enable']) && $config['allow_topic_notify'] && $user->data['is_registered'])
  522. {
  523. watch_topic_forum('topic', $s_watching_topic, $user->data['user_id'], $forum_id, $topic_id, $topic_data['notify_status'], $start);
  524. // Reset forum notification if forum notify is set
  525. if ($config['allow_forum_notify'] && $auth->acl_get('f_subscribe', $forum_id))
  526. {
  527. $s_watching_forum = $s_watching_topic;
  528. watch_topic_forum('forum', $s_watching_forum, $user->data['user_id'], $forum_id, 0);
  529. }
  530. }
  531. // Bookmarks
  532. if ($config['allow_bookmarks'] && $user->data['is_registered'] && request_var('bookmark', 0))
  533. {
  534. if (check_link_hash(request_var('hash', ''), "topic_$topic_id"))
  535. {
  536. if (!$topic_data['bookmarked'])
  537. {
  538. $sql = 'INSERT INTO ' . BOOKMARKS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
  539. 'user_id' => $user->data['user_id'],
  540. 'topic_id' => $topic_id,
  541. ));
  542. $db->sql_query($sql);
  543. }
  544. else
  545. {
  546. $sql = 'DELETE FROM ' . BOOKMARKS_TABLE . "
  547. WHERE user_id = {$user->data['user_id']}
  548. AND topic_id = $topic_id";
  549. $db->sql_query($sql);
  550. }
  551. $message = (($topic_data['bookmarked']) ? $user->lang['BOOKMARK_REMOVED'] : $user->lang['BOOKMARK_ADDED']) . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $viewtopic_url . '">', '</a>');
  552. }
  553. else
  554. {
  555. $message = $user->lang['BOOKMARK_ERR'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $viewtopic_url . '">', '</a>');
  556. }
  557. meta_refresh(3, $viewtopic_url);
  558. trigger_error($message);
  559. }
  560. // Grab ranks
  561. $ranks = $cache->obtain_ranks();
  562. // Grab icons
  563. $icons = $cache->obtain_icons();
  564. // Grab extensions
  565. $extensions = array();
  566. if ($topic_data['topic_attachment'])
  567. {
  568. $extensions = $cache->obtain_attach_extensions($forum_id);
  569. }
  570. // Forum rules listing
  571. $s_forum_rules = '';
  572. gen_forum_auth_level('topic', $forum_id, $topic_data['forum_status']);
  573. // Quick mod tools
  574. $allow_change_type = ($auth->acl_get('m_', $forum_id) || ($user->data['is_registered'] && $user->data['user_id'] == $topic_data['topic_poster'])) ? true : false;
  575. $topic_mod = '';
  576. $topic_mod .= ($auth->acl_get('m_lock', $forum_id) || ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $topic_data['topic_poster'] && $topic_data['topic_status'] == ITEM_UNLOCKED)) ? (($topic_data['topic_status'] == ITEM_UNLOCKED) ? '<option value="lock">' . $user->lang['LOCK_TOPIC'] . '</option>' : '<option value="unlock">' . $user->lang['UNLOCK_TOPIC'] . '</option>') : '';
  577. $topic_mod .= ($auth->acl_get('m_delete', $forum_id)) ? '<option value="delete_topic">' . $user->lang['DELETE_TOPIC'] . '</option>' : '';
  578. $topic_mod .= ($auth->acl_get('m_move', $forum_id) && $topic_data['topic_status'] != ITEM_MOVED) ? '<option value="move">' . $user->lang['MOVE_TOPIC'] . '</option>' : '';
  579. $topic_mod .= ($auth->acl_get('m_split', $forum_id)) ? '<option value="split">' . $user->lang['SPLIT_TOPIC'] . '</option>' : '';
  580. $topic_mod .= ($auth->acl_get('m_merge', $forum_id)) ? '<option value="merge">' . $user->lang['MERGE_POSTS'] . '</option>' : '';
  581. $topic_mod .= ($auth->acl_get('m_merge', $forum_id)) ? '<option value="merge_topic">' . $user->lang['MERGE_TOPIC'] . '</option>' : '';
  582. $topic_mod .= ($auth->acl_get('m_move', $forum_id)) ? '<option value="fork">' . $user->lang['FORK_TOPIC'] . '</option>' : '';
  583. $topic_mod .= ($allow_change_type && $auth->acl_gets('f_sticky', 'f_announce', $forum_id) && $topic_data['topic_type'] != POST_NORMAL) ? '<option value="make_normal">' . $user->lang['MAKE_NORMAL'] . '</option>' : '';
  584. $topic_mod .= ($allow_change_type && $auth->acl_get('f_sticky', $forum_id) && $topic_data['topic_type'] != POST_STICKY) ? '<option value="make_sticky">' . $user->lang['MAKE_STICKY'] . '</option>' : '';
  585. $topic_mod .= ($allow_change_type && $auth->acl_get('f_announce', $forum_id) && $topic_data['topic_type'] != POST_ANNOUNCE) ? '<option value="make_announce">' . $user->lang['MAKE_ANNOUNCE'] . '</option>' : '';
  586. $topic_mod .= ($allow_change_type && $auth->acl_get('f_announce', $forum_id) && $topic_data['topic_type'] != POST_GLOBAL) ? '<option value="make_global">' . $user->lang['MAKE_GLOBAL'] . '</option>' : '';
  587. $topic_mod .= ($auth->acl_get('m_', $forum_id)) ? '<option value="topic_logs">' . $user->lang['VIEW_TOPIC_LOGS'] . '</option>' : '';
  588. // If we've got a hightlight set pass it on to pagination.
  589. $pagination = generate_pagination(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id" . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : '') . (($highlight_match) ? "&amp;hilit=$highlight" : '')), $total_posts, $config['posts_per_page'], $start);
  590. // Navigation links
  591. generate_forum_nav($topic_data);
  592. // Forum Rules
  593. generate_forum_rules($topic_data);
  594. // Moderators
  595. $forum_moderators = array();
  596. if ($config['load_moderators'])
  597. {
  598. get_moderators($forum_moderators, $forum_id);
  599. }
  600. // This is only used for print view so ...
  601. $server_path = (!$view) ? $phpbb_root_path : generate_board_url() . '/';
  602. // Replace naughty words in title
  603. $topic_data['topic_title'] = censor_text($topic_data['topic_title']);
  604. $s_search_hidden_fields = array(
  605. 't' => $topic_id,
  606. 'sf' => 'msgonly',
  607. );
  608. if ($_SID)
  609. {
  610. $s_search_hidden_fields['sid'] = $_SID;
  611. }
  612. //-- mod: Prime Trash Bin (Topics) ------------------------------------------//
  613. // Adjust the quickmod dropdown list if necessary.
  614. include ($phpbb_root_path . 'includes/prime_trash_bin_a.' . $phpEx);
  615. $topic_deleted = !empty($topic_data['topic_deleted_time']);
  616. if ($topic_deleted)
  617. {
  618. $topic_mod = fake_delete_alter_quickmod($topic_mod, $forum_id);
  619. }
  620. //-- end: Prime Trash Bin (Topics) ------------------------------------------//
  621. // Send vars to template
  622. $template->assign_vars(array(
  623. 'FORUM_ID' => $forum_id,
  624. 'FORUM_NAME' => $topic_data['forum_name'],
  625. 'FORUM_DESC' => generate_text_for_display($topic_data['forum_desc'], $topic_data['forum_desc_uid'], $topic_data['forum_desc_bitfield'], $topic_data['forum_desc_options']),
  626. 'TOPIC_ID' => $topic_id,
  627. 'TOPIC_TITLE' => $topic_data['topic_title'],
  628. 'TOPIC_POSTER' => $topic_data['topic_poster'],
  629. 'TOPIC_AUTHOR_FULL' => get_username_string('full', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']),
  630. 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']),
  631. 'TOPIC_AUTHOR' => get_username_string('username', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']),
  632. 'PAGINATION' => $pagination,
  633. 'PAGE_NUMBER' => on_page($total_posts, $config['posts_per_page'], $start),
  634. 'TOTAL_POSTS' => ($total_posts == 1) ? $user->lang['VIEW_TOPIC_POST'] : sprintf($user->lang['VIEW_TOPIC_POSTS'], $total_posts),
  635. 'U_MCP' => ($auth->acl_get('m_', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&amp;mode=topic_view&amp;f=$forum_id&amp;t=$topic_id" . (($start == 0) ? '' : "&amp;start=$start") . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : ''), true, $user->session_id) : '',
  636. 'MODERATORS' => (isset($forum_moderators[$forum_id]) && sizeof($forum_moderators[$forum_id])) ? implode(', ', $forum_moderators[$forum_id]) : '',
  637. 'POST_IMG' => ($topic_data['forum_status'] == ITEM_LOCKED) ? $user->img('button_topic_locked', 'FORUM_LOCKED') : $user->img('button_topic_new', 'POST_NEW_TOPIC'),
  638. 'QUOTE_IMG' => $user->img('icon_post_quote', 'REPLY_WITH_QUOTE'),
  639. 'REPLY_IMG' => ($topic_data['forum_status'] == ITEM_LOCKED || $topic_data['topic_status'] == ITEM_LOCKED) ? $user->img('button_topic_locked', 'TOPIC_LOCKED') : $user->img('button_topic_reply', 'REPLY_TO_TOPIC'),
  640. 'EDIT_IMG' => $user->img('icon_post_edit', 'EDIT_POST'),
  641. 'DELETE_IMG' => $user->img('icon_post_delete', 'DELETE_POST'),
  642. 'INFO_IMG' => $user->img('icon_post_info', 'VIEW_INFO'),
  643. 'PROFILE_IMG' => $user->img('icon_user_profile', 'READ_PROFILE'),
  644. 'SEARCH_IMG' => $user->img('icon_user_search', 'SEARCH_USER_POSTS'),
  645. 'PM_IMG' => $user->img('icon_contact_pm', 'SEND_PRIVATE_MESSAGE'),
  646. 'EMAIL_IMG' => $user->img('icon_contact_email', 'SEND_EMAIL'),
  647. 'WWW_IMG' => $user->img('icon_contact_www', 'VISIT_WEBSITE'),
  648. 'ICQ_IMG' => $user->img('icon_contact_icq', 'ICQ'),
  649. 'AIM_IMG' => $user->img('icon_contact_aim', 'AIM'),
  650. 'MSN_IMG' => $user->img('icon_contact_msnm', 'MSNM'),
  651. 'YIM_IMG' => $user->img('icon_contact_yahoo', 'YIM'),
  652. 'JABBER_IMG' => $user->img('icon_contact_jabber', 'JABBER') ,
  653. 'REPORT_IMG' => $user->img('icon_post_report', 'REPORT_POST'),
  654. 'REPORTED_IMG' => $user->img('icon_topic_reported', 'POST_REPORTED'),
  655. 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'POST_UNAPPROVED'),
  656. 'WARN_IMG' => $user->img('icon_user_warn', 'WARN_USER'),
  657. 'S_IS_LOCKED' => ($topic_data['topic_status'] == ITEM_UNLOCKED && $topic_data['forum_status'] == ITEM_UNLOCKED) ? false : true,
  658. 'S_SELECT_SORT_DIR' => $s_sort_dir,
  659. 'S_SELECT_SORT_KEY' => $s_sort_key,
  660. 'S_SELECT_SORT_DAYS' => $s_limit_days,
  661. 'S_SINGLE_MODERATOR' => (!empty($forum_moderators[$forum_id]) && sizeof($forum_moderators[$forum_id]) > 1) ? false : true,
  662. 'S_TOPIC_ACTION' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id" . (($start == 0) ? '' : "&amp;start=$start")),
  663. 'S_TOPIC_MOD' => ($topic_mod != '') ? '<select name="action" id="quick-mod-select">' . $topic_mod . '</select>' : '',
  664. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  665. 'S_MOD_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", "f=$forum_id&amp;t=$topic_id" . (($start == 0) ? '' : "&amp;start=$start") . "&amp;quickmod=1&amp;redirect=" . urlencode(str_replace('&amp;', '&', "{$phpbb_root_path}viewtopic.$phpEx?f=$forum_id&amp;t=$topic_id") . (($start == 0) ? '' : "&amp;start=$start") . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : '') . (($highlight_match) ? "&amp;hilit=$highlight" : '')), true, $user->session_id),
  666. // www.phpBB-SEO.com SEO TOOLKIT END
  667. 'S_VIEWTOPIC' => true,
  668. 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('u_search') && $auth->acl_get('f_search', $forum_id) && $config['load_search']) ? true : false,
  669. 'S_SEARCHBOX_ACTION' => append_sid("{$phpbb_root_path}search.$phpEx"),
  670. 'S_SEARCH_LOCAL_HIDDEN_FIELDS' => build_hidden_fields($s_search_hidden_fields),
  671. 'S_DISPLAY_POST_INFO' => ($topic_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
  672. 'S_DISPLAY_REPLY_INFO' => ($topic_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_reply', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
  673. 'S_ENABLE_FEEDS_TOPIC' => ($config['feed_topic'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $topic_data['forum_options'])) ? true : false,
  674. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  675. 'U_TOPIC' => !empty($phpbb_seo->seo_opt['url_rewrite']) ? $phpbb_seo->drop_sid($viewtopic_url) : "{$server_path}viewtopic.$phpEx?f=$forum_id&amp;t=$topic_id",
  676. // www.phpBB-SEO.com SEO TOOLKIT END
  677. 'U_FORUM' => $server_path,
  678. 'U_VIEW_TOPIC' => $viewtopic_url,
  679. 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
  680. 'U_VIEW_OLDER_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;view=previous"),
  681. 'U_VIEW_NEWER_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;view=next"),
  682. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  683. 'U_PRINT_TOPIC' => ($auth->acl_get('f_print', $forum_id)) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;start=$start" . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : '') . (($highlight_match) ? "&amp;hilit=$highlight" : '') . "&amp;view=print") : '',
  684. // www.phpBB-SEO.com SEO TOOLKIT END
  685. 'U_EMAIL_TOPIC' => ($auth->acl_get('f_email', $forum_id) && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=email&amp;t=$topic_id") : '',
  686. 'U_WATCH_TOPIC' => $s_watching_topic['link'],
  687. 'L_WATCH_TOPIC' => $s_watching_topic['title'],
  688. 'S_WATCHING_TOPIC' => $s_watching_topic['is_watching'],
  689. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  690. 'U_BOOKMARK_TOPIC' => ($user->data['is_registered'] && $config['allow_bookmarks']) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;bookmark=1&amp;hash=" . generate_link_hash("topic_$topic_id")) : '',
  691. // www.phpBB-SEO.com SEO TOOLKIT END
  692. 'L_BOOKMARK_TOPIC' => ($user->data['is_registered'] && $config['allow_bookmarks'] && $topic_data['bookmarked']) ? $user->lang['BOOKMARK_TOPIC_REMOVE'] : $user->lang['BOOKMARK_TOPIC'],
  693. 'U_POST_NEW_TOPIC' => ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=post&amp;f=$forum_id") : '',
  694. 'U_POST_REPLY_TOPIC' => ($auth->acl_get('f_reply', $forum_id) || $user->data['user_id'] == ANONYMOUS) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=reply&amp;f=$forum_id&amp;t=$topic_id") : '',
  695. 'U_BUMP_TOPIC' => (bump_topic_allowed($forum_id, $topic_data['topic_bumped'], $topic_data['topic_last_post_time'], $topic_data['topic_poster'], $topic_data['topic_last_poster_id'])) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=bump&amp;f=$forum_id&amp;t=$topic_id&amp;hash=" . generate_link_hash("topic_$topic_id")) : '')
  696. );
  697. // Does this topic contain a poll?
  698. if (!empty($topic_data['poll_start']))
  699. {
  700. $sql = 'SELECT o.*, p.bbcode_bitfield, p.bbcode_uid
  701. FROM ' . POLL_OPTIONS_TABLE . ' o, ' . POSTS_TABLE . " p
  702. WHERE o.topic_id = $topic_id
  703. AND p.post_id = {$topic_data['topic_first_post_id']}
  704. AND p.topic_id = o.topic_id
  705. ORDER BY o.poll_option_id";
  706. $result = $db->sql_query($sql);
  707. $poll_info = array();
  708. while ($row = $db->sql_fetchrow($result))
  709. {
  710. $poll_info[] = $row;
  711. }
  712. $db->sql_freeresult($result);
  713. $cur_voted_id = array();
  714. if ($user->data['is_registered'])
  715. {
  716. $sql = 'SELECT poll_option_id
  717. FROM ' . POLL_VOTES_TABLE . '
  718. WHERE topic_id = ' . $topic_id . '
  719. AND vote_user_id = ' . $user->data['user_id'];
  720. $result = $db->sql_query($sql);
  721. while ($row = $db->sql_fetchrow($result))
  722. {
  723. $cur_voted_id[] = $row['poll_option_id'];
  724. }
  725. $db->sql_freeresult($result);
  726. }
  727. else
  728. {
  729. // Cookie based guest tracking ... I don't like this but hum ho
  730. // it's oft requested. This relies on "nice" users who don't feel
  731. // the need to delete cookies to mess with results.
  732. if (isset($_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]))
  733. {
  734. $cur_voted_id = explode(',', $_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]);
  735. $cur_voted_id = array_map('intval', $cur_voted_id);
  736. }
  737. }
  738. // Can not vote at all if no vote permission
  739. $s_can_vote = ($auth->acl_get('f_vote', $forum_id) &&
  740. (($topic_data['poll_length'] != 0 && $topic_data['poll_start'] + $topic_data['poll_length'] > time()) || $topic_data['poll_length'] == 0) &&
  741. $topic_data['topic_status'] != ITEM_LOCKED &&
  742. $topic_data['forum_status'] != ITEM_LOCKED &&
  743. (!sizeof($cur_voted_id) ||
  744. ($auth->acl_get('f_votechg', $forum_id) && $topic_data['poll_vote_change']))) ? true : false;
  745. $s_display_results = (!$s_can_vote || ($s_can_vote && sizeof($cur_voted_id)) || $view == 'viewpoll') ? true : false;
  746. if ($update && $s_can_vote)
  747. {
  748. if (!sizeof($voted_id) || sizeof($voted_id) > $topic_data['poll_max_options'] || in_array(VOTE_CONVERTED, $cur_voted_id) || !check_form_key('posting'))
  749. {
  750. $redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id" . (($start == 0) ? '' : "&amp;start=$start"));
  751. meta_refresh(5, $redirect_url);
  752. if (!sizeof($voted_id))
  753. {
  754. $message = 'NO_VOTE_OPTION';
  755. }
  756. else if (sizeof($voted_id) > $topic_data['poll_max_options'])
  757. {
  758. $message = 'TOO_MANY_VOTE_OPTIONS';
  759. }
  760. else if (in_array(VOTE_CONVERTED, $cur_voted_id))
  761. {
  762. $message = 'VOTE_CONVERTED';
  763. }
  764. else
  765. {
  766. $message = 'FORM_INVALID';
  767. }
  768. $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
  769. trigger_error($message);
  770. }
  771. foreach ($voted_id as $option)
  772. {
  773. if (in_array($option, $cur_voted_id))
  774. {
  775. continue;
  776. }
  777. $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . '
  778. SET poll_option_total = poll_option_total + 1
  779. WHERE poll_option_id = ' . (int) $option . '
  780. AND topic_id = ' . (int) $topic_id;
  781. $db->sql_query($sql);
  782. if ($user->data['is_registered'])
  783. {
  784. $sql_ary = array(
  785. 'topic_id' => (int) $topic_id,
  786. 'poll_option_id' => (int) $option,
  787. 'vote_user_id' => (int) $user->data['user_id'],
  788. 'vote_user_ip' => (string) $user->ip,
  789. );
  790. $sql = 'INSERT INTO ' . POLL_VOTES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
  791. $db->sql_query($sql);
  792. }
  793. }
  794. foreach ($cur_voted_id as $option)
  795. {
  796. if (!in_array($option, $voted_id))
  797. {
  798. $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . '
  799. SET poll_option_total = poll_option_total - 1
  800. WHERE poll_option_id = ' . (int) $option . '
  801. AND topic_id = ' . (int) $topic_id;
  802. $db->sql_query($sql);
  803. if ($user->data['is_registered'])
  804. {
  805. $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . '
  806. WHERE topic_id = ' . (int) $topic_id . '
  807. AND poll_option_id = ' . (int) $option . '
  808. AND vote_user_id = ' . (int) $user->data['user_id'];
  809. $db->sql_query($sql);
  810. }
  811. }
  812. }
  813. if ($user->data['user_id'] == ANONYMOUS && !$user->data['is_bot'])
  814. {
  815. $user->set_cookie('poll_' . $topic_id, implode(',', $voted_id), time() + 31536000);
  816. }
  817. $sql = 'UPDATE ' . TOPICS_TABLE . '
  818. SET poll_last_vote = ' . time() . "
  819. WHERE topic_id = $topic_id";
  820. //, topic_last_post_time = ' . time() . " -- for bumping topics with new votes, ignore for now
  821. $db->sql_query($sql);
  822. $redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id" . (($start == 0) ? '' : "&amp;start=$start"));
  823. meta_refresh(5, $redirect_url);
  824. trigger_error($user->lang['VOTE_SUBMITTED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>'));
  825. }
  826. $poll_total = 0;
  827. foreach ($poll_info as $poll_option)
  828. {
  829. $poll_total += $poll_option['poll_option_total'];
  830. }
  831. if ($poll_info[0]['bbcode_bitfield'])
  832. {
  833. $poll_bbcode = new bbcode();
  834. }
  835. else
  836. {
  837. $poll_bbcode = false;
  838. }
  839. for ($i = 0, $size = sizeof($poll_info); $i < $size; $i++)
  840. {
  841. $poll_info[$i]['poll_option_text'] = censor_text($poll_info[$i]['poll_option_text']);
  842. if ($poll_bbcode !== false)
  843. {
  844. $poll_bbcode->bbcode_second_pass($poll_info[$i]['poll_option_text'], $poll_info[$i]['bbcode_uid'], $poll_option['bbcode_bitfield']);
  845. }
  846. $poll_info[$i]['poll_option_text'] = bbcode_nl2br($poll_info[$i]['poll_option_text']);
  847. $poll_info[$i]['poll_option_text'] = smiley_text($poll_info[$i]['poll_option_text']);
  848. }
  849. $topic_data['poll_title'] = censor_text($topic_data['poll_title']);
  850. if ($poll_bbcode !== false)
  851. {
  852. $poll_bbcode->bbcode_second_pass($topic_data['poll_title'], $poll_info[0]['bbcode_uid'], $poll_info[0]['bbcode_bitfield']);
  853. }
  854. $topic_data['poll_title'] = bbcode_nl2br($topic_data['poll_title']);
  855. $topic_data['poll_title'] = smiley_text($topic_data['poll_title']);
  856. unset($poll_bbcode);
  857. foreach ($poll_info as $poll_option)
  858. {
  859. $option_pct = ($poll_total > 0) ? $poll_option['poll_option_total'] / $poll_total : 0;
  860. $option_pct_txt = sprintf("%.1d%%", round($option_pct * 100));
  861. $template->assign_block_vars('poll_option', array(
  862. 'POLL_OPTION_ID' => $poll_option['poll_option_id'],
  863. 'POLL_OPTION_CAPTION' => $poll_option['poll_option_text'],
  864. 'POLL_OPTION_RESULT' => $poll_option['poll_option_total'],
  865. 'POLL_OPTION_PERCENT' => $option_pct_txt,
  866. 'POLL_OPTION_PCT' => round($option_pct * 100),
  867. 'POLL_OPTION_IMG' => $user->img('poll_center', $option_pct_txt, round($option_pct * 250)),
  868. 'POLL_OPTION_VOTED' => (in_array($poll_option['poll_option_id'], $cur_voted_id)) ? true : false)
  869. );
  870. }
  871. $poll_end = $topic_data['poll_length'] + $topic_data['poll_start'];
  872. $template->assign_vars(array(
  873. 'POLL_QUESTION' => $topic_data['poll_title'],
  874. 'TOTAL_VOTES' => $poll_total,
  875. 'POLL_LEFT_CAP_IMG' => $user->img('poll_left'),
  876. 'POLL_RIGHT_CAP_IMG'=> $user->img('poll_right'),
  877. 'L_MAX_VOTES' => ($topic_data['poll_max_options'] == 1) ? $user->lang['MAX_OPTION_SELECT'] : sprintf($user->lang['MAX_OPTIONS_SELECT'], $topic_data['poll_max_options']),
  878. 'L_POLL_LENGTH' => ($topic_data['poll_length']) ? sprintf($user->lang[($poll_end > time()) ? 'POLL_RUN_TILL' : 'POLL_ENDED_AT'], $user->format_date($poll_end)) : '',
  879. 'S_HAS_POLL' => true,
  880. 'S_CAN_VOTE' => $s_can_vote,
  881. 'S_DISPLAY_RESULTS' => $s_display_results,
  882. 'S_IS_MULTI_CHOICE' => ($topic_data['poll_max_options'] > 1) ? true : false,
  883. 'S_POLL_ACTION' => $viewtopic_url,
  884. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  885. 'U_VIEW_RESULTS' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;view=viewpoll") )
  886. // www.phpBB-SEO.com SEO TOOLKIT END
  887. );
  888. unset($poll_end, $poll_info, $voted_id);
  889. }
  890. // If the user is trying to reach the second half of the topic, fetch it starting from the end
  891. $store_reverse = false;
  892. $sql_limit = $config['posts_per_page'];
  893. $sql_sort_order = $direction = '';
  894. if ($start > $total_posts / 2)
  895. {
  896. $store_reverse = true;
  897. if ($start + $config['posts_per_page'] > $total_posts)
  898. {
  899. $sql_limit = min($config['posts_per_page'], max(1, $total_posts - $start));
  900. }
  901. // Select the sort order
  902. $direction = (($sort_dir == 'd') ? 'ASC' : 'DESC');
  903. $sql_start = max(0, $total_posts - $sql_limit - $start);
  904. }
  905. else
  906. {
  907. // Select the sort order
  908. $direction = (($sort_dir == 'd') ? 'DESC' : 'ASC');
  909. $sql_start = $start;
  910. }
  911. if (is_array($sort_by_sql[$sort_key]))
  912. {
  913. $sql_sort_order = implode(' ' . $direction . ', ', $sort_by_sql[$sort_key]) . ' ' . $direction;
  914. }
  915. else
  916. {
  917. $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . $direction;
  918. }
  919. // Container for user details, only process once
  920. $post_list = $user_cache = $id_cache = $attachments = $attach_list = $rowset = $update_count = $post_edit_list = array();
  921. $has_attachments = $display_notice = false;
  922. $bbcode_bitfield = '';
  923. $i = $i_total = 0;
  924. // Go ahead and pull all data for this topic
  925. $sql = 'SELECT p.post_id
  926. FROM ' . POSTS_TABLE . ' p' . (($join_user_sql[$sort_key]) ? ', ' . USERS_TABLE . ' u': '') . "
  927. WHERE p.topic_id = $topic_id
  928. " . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '') . "
  929. " . (($join_user_sql[$sort_key]) ? 'AND u.user_id = p.poster_id': '') . "
  930. $limit_posts_time
  931. ORDER BY $sql_sort_order";
  932. $result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
  933. $i = ($store_reverse) ? $sql_limit - 1 : 0;
  934. while ($row = $db->sql_fetchrow($result))
  935. {
  936. $post_list[$i] = (int) $row['post_id'];
  937. ($store_reverse) ? $i-- : $i++;
  938. }
  939. $db->sql_freeresult($result);
  940. //-- mod: Prime Trash Bin (Topics) ------------------------------------------//
  941. // Make it so no posts will show up if the topic has been deleted and
  942. // the user doesn't have the permissions to view the deleted content.
  943. if ($topic_deleted)
  944. {
  945. if (!auth_fake_delete('list', $forum_id)) // User can't view placeholder, so display "No Topic"
  946. {
  947. $post_list = array();
  948. }
  949. else if (!auth_fake_delete('view', $forum_id)) // User can view placeholder, but not the deleted posts
  950. {
  951. $post_list = array(0); //Needs an element or a "No Topic" message will be displayed
  952. }
  953. }
  954. //-- end: Prime Trash Bin (Topics) ------------------------------------------//
  955. if (!sizeof($post_list))
  956. {
  957. if ($sort_days)
  958. {
  959. trigger_error('NO_POSTS_TIME_FRAME');
  960. }
  961. else
  962. {
  963. trigger_error('NO_TOPIC');
  964. }
  965. }
  966. // Holding maximum post time for marking topic read
  967. // We need to grab it because we do reverse ordering sometimes
  968. $max_post_time = 0;
  969. //-- mod: Prime Post Revisions ----------------------------------------------//
  970. include($phpbb_root_path . 'includes/prime_post_revisions.' . $phpEx);
  971. $prime_post_revisions = new prime_post_revisions($post_list, $forum_id, $topic_id, $post_id);
  972. //-- end: Prime Post Revisions ----------------------------------------------//
  973. $sql = $db->sql_build_query('SELECT', array(
  974. 'SELECT' => 'u.*, z.friend, z.foe, p.*',
  975. 'FROM' => array(
  976. USERS_TABLE => 'u',
  977. POSTS_TABLE => 'p',
  978. ),
  979. 'LEFT_JOIN' => array(
  980. array(
  981. 'FROM' => array(ZEBRA_TABLE => 'z'),
  982. 'ON' => 'z.user_id = ' . $user->data['user_id'] . ' AND z.zebra_id = p.poster_id'
  983. )
  984. ),
  985. 'WHERE' => $db->sql_in_set('p.post_id', $post_list) . '
  986. AND u.user_id = p.poster_id'
  987. ));
  988. $result = $db->sql_query($sql);
  989. $now = getdate(time() + $user->timezone + $user->dst - date('Z'));
  990. //-- mod: Prime Post Revisions ----------------------------------------------//
  991. $prime_post_revisions->get_revision_info($post_list, $result, $viewtopic_url, $viewtopic_title);
  992. //-- end: Prime Post Revisions ----------------------------------------------//
  993. // Posts are stored in the $rowset array while $attach_list, $user_cache
  994. // and the global bbcode_bitfield are built
  995. while ($row = $db->sql_fetchrow($result))
  996. {
  997. //-- mod: Prime Trash Bin (Posts) -------------------------------------------//
  998. // If the post has been deleted, we need to check if the user is allowed to view the placeholder.
  999. if (!empty($row['post_deleted_time']) && !auth_fake_delete('list', $forum_id))
  1000. {
  1001. continue;
  1002. }
  1003. //-- end: Prime Trash Bin (Posts) -------------------------------------------//
  1004. //-- mod: Prime Post Revisions ----------------------------------------------//
  1005. $prime_post_revisions->merge_revision_info($post_list, $result, $row);
  1006. //-- end: Prime Post Revisions ----------------------------------------------//
  1007. // Set max_post_time
  1008. if ($row['post_time'] > $max_post_time)
  1009. {
  1010. $max_post_time = $row['post_time'];
  1011. }
  1012. $poster_id = (int) $row['poster_id'];
  1013. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  1014. $phpbb_seo->set_user_url( $row['username'], $poster_id );
  1015. // www.phpBB-SEO.com SEO TOOLKIT END
  1016. // Does post have an attachment? If so, add it to the list
  1017. if ($row['post_attachment'] && $config['allow_attachments'])
  1018. {
  1019. $attach_list[] = (int) $row['post_id'];
  1020. if ($row['post_approved'])
  1021. {
  1022. $has_attachments = true;
  1023. }
  1024. }
  1025. $rowset[$row['post_id']] = array(
  1026. 'hide_post' => ($row['foe'] && ($view != 'show' || $post_id != $row['post_id'])) ? true : false,
  1027. 'post_id' => $row['post_id'],
  1028. 'post_time' => $row['post_time'],
  1029. 'user_id' => $row['user_id'],
  1030. 'username' => $row['username'],
  1031. 'user_colour' => $row['user_colour'],
  1032. 'topic_id' => $row['topic_id'],
  1033. 'forum_id' => $row['forum_id'],
  1034. 'post_subject' => $row['post_subject'],
  1035. 'post_edit_count' => $row['post_edit_count'],
  1036. 'post_edit_time' => $row['post_edit_time'],
  1037. 'post_edit_reason' => $row['post_edit_reason'],
  1038. 'post_edit_user' => $row['post_edit_user'],
  1039. 'post_edit_locked' => $row['post_edit_locked'],
  1040. // Make sure the icon actually exists
  1041. 'icon_id' => (isset($icons[$row['icon_id']]['img'], $icons[$row['icon_id']]['height'], $icons[$row['icon_id']]['width'])) ? $row['icon_id'] : 0,
  1042. 'post_attachment' => $row['post_attachment'],
  1043. 'post_approved' => $row['post_approved'],
  1044. 'post_reported' => $row['post_reported'],
  1045. 'post_username' => $row['post_username'],
  1046. 'post_text' => $row['post_text'],
  1047. 'bbcode_uid' => $row['bbcode_uid'],
  1048. 'bbcode_bitfield' => $row['bbcode_bitfield'],
  1049. 'enable_smilies' => $row['enable_smilies'],
  1050. 'enable_sig' => $row['enable_sig'],
  1051. 'friend' => $row['friend'],
  1052. 'foe' => $row['foe'],
  1053. );
  1054. //-- mod: Prime Trash Bin (Posts) -------------------------------------------//
  1055. // This is where we make the deletion info available for when the script starts
  1056. // looping through each post to set the template variables. If we're viewing
  1057. // the post's revision history (another MOD), then don't hide the post's content.
  1058. if (!empty($row['post_deleted_time']) && empty($display_history))
  1059. {
  1060. $rowset[$row['post_id']]['post_deleted_from'] = $row['post_deleted_from'];
  1061. $rowset[$row['post_id']]['post_deleted_user'] = $row['post_deleted_user'];
  1062. $rowset[$row['post_id']]['post_deleted_time'] = $row['post_deleted_time'];
  1063. $rowset[$row['post_id']]['post_deleted_reason'] = censor_text($row['post_deleted_reason']);
  1064. // We don't want to display any info about previous edits.
  1065. $rowset[$row['post_id']]['post_edit_reason'] = '';
  1066. $rowset[$row['post_id']]['post_edit_count'] = 0;
  1067. }
  1068. //-- end: Prime Trash Bin (Posts) -------------------------------------------//
  1069. // Define the global bbcode bitfield, will be used to load bbcodes
  1070. $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
  1071. // Is a signature attached? Are we going to display it?
  1072. if ($row['enable_sig'] && $config['allow_sig'] && $user->optionget('viewsigs'))
  1073. {
  1074. $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['user_sig_bbcode_bitfield']);
  1075. }
  1076. // Cache various user specific data ... so we don't have to recompute
  1077. // this each time the same user appears on this page
  1078. if (!isset($user_cache[$poster_id]))
  1079. {
  1080. if ($poster_id == ANONYMOUS)
  1081. {
  1082. $user_cache[$poster_id] = array(
  1083. 'joined' => '',
  1084. 'posts' => '',
  1085. 'from' => '',
  1086. 'sig' => '',
  1087. 'sig_bbcode_uid' => '',
  1088. 'sig_bbcode_bitfield' => '',
  1089. 'online' => false,
  1090. 'avatar' => ($user->optionget('viewavatars')) ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'], $row['user_avatar_height']) : '',
  1091. 'rank_title' => '',
  1092. 'rank_image' => '',
  1093. 'rank_image_src' => '',
  1094. 'sig' => '',
  1095. 'profile' => '',
  1096. 'pm' => '',
  1097. 'email' => '',
  1098. 'www' => '',
  1099. 'icq_status_img' => '',
  1100. 'icq' => '',
  1101. 'aim' => '',
  1102. 'msn' => '',
  1103. 'yim' => '',
  1104. 'jabber' => '',
  1105. 'search' => '',
  1106. 'age' => '',
  1107. 'username' => $row['username'],
  1108. 'user_colour' => $row['user_colour'],
  1109. 'warnings' => 0,
  1110. 'allow_pm' => 0,
  1111. );
  1112. get_user_rank($row['user_rank'], false, $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']);
  1113. }
  1114. else
  1115. {
  1116. $user_sig = '';
  1117. // We add the signature to every posters entry because enable_sig is post dependant
  1118. if ($row['user_sig'] && $config['allow_sig'] && $user->optionget('viewsigs'))
  1119. {
  1120. $user_sig = $row['user_sig'];
  1121. }
  1122. $id_cache[] = $poster_id;
  1123. $user_cache[$poster_id] = array(
  1124. 'joined' => $user->format_date($row['user_regdate'], 'd.m.Y'),
  1125. 'posts' => $row['user_posts'],
  1126. 'warnings' => (isset($row['user_warnings'])) ? $row['user_warnings'] : 0,
  1127. 'from' => (!empty($row['user_from'])) ? $row['user_from'] : '',
  1128. 'sig' => $user_sig,
  1129. 'sig_bbcode_uid' => (!empty($row['user_sig_bbcode_uid'])) ? $row['user_sig_bbcode_uid'] : '',
  1130. 'sig_bbcode_bitfield' => (!empty($row['user_sig_bbcode_bitfield'])) ? $row['user_sig_bbcode_bitfield'] : '',
  1131. 'viewonline' => $row['user_allow_viewonline'],
  1132. 'allow_pm' => $row['user_allow_pm'],
  1133. 'avatar' => ($user->optionget('viewavatars')) ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'], $row['user_avatar_height']) : '',
  1134. 'age' => '',
  1135. 'rank_title' => '',
  1136. 'rank_image' => '',
  1137. 'rank_image_src' => '',
  1138. 'username' => $row['username'],
  1139. 'user_colour' => $row['user_colour'],
  1140. 'online' => false,
  1141. 'profile' => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=viewprofile&amp;u=$poster_id"),
  1142. 'www' => $row['user_website'],
  1143. 'aim' => ($row['user_aim'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=aim&amp;u=$poster_id") : '',
  1144. 'msn' => ($row['user_msnm'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=msnm&amp;u=$poster_id") : '',
  1145. 'yim' => ($row['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($row['user_yim']) . '&amp;.src=pg' : '',
  1146. 'jabber' => ($row['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=jabber&amp;u=$poster_id") : '',
  1147. 'search' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id=$poster_id&amp;sr=posts") : '',
  1148. 'author_full' => get_username_string('full', $poster_id, $row['username'], $row['user_colour']),
  1149. 'author_colour' => get_username_string('colour', $poster_id, $row['username'], $row['user_colour']),
  1150. 'author_username' => get_username_string('username', $poster_id, $row['username'], $row['user_colour']),
  1151. 'author_profile' => get_username_string('profile', $poster_id, $row['username'], $row['user_colour']),
  1152. );
  1153. get_user_rank($row['user_rank'], $row['user_posts'], $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']);
  1154. if ((!empty($row['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_email'))
  1155. {
  1156. $user_cache[$poster_id]['email'] = ($config['board_email_form'] && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=email&amp;u=$poster_id") : (($config['board_hide_emails'] && !$auth->acl_get('a_email')) ? '' : 'mailto:' . $row['user_email']);
  1157. }
  1158. else
  1159. {
  1160. $user_cache[$poster_id]['email'] = '';
  1161. }
  1162. if (!empty($row['user_icq']))
  1163. {
  1164. $user_cache[$poster_id]['icq'] = 'http://www.icq.com/people/' . urlencode($row['user_icq']) . '/';
  1165. $user_cache[$poster_id]['icq_status_img'] = '<img src="http://web.icq.com/whitepages/online?icq=' . $row['user_icq'] . '&amp;img=5" width="18" height="18" alt="" />';
  1166. }
  1167. else
  1168. {
  1169. $user_cache[$poster_id]['icq_status_img'] = '';
  1170. $user_cache[$poster_id]['icq'] = '';
  1171. }
  1172. if ($config['allow_birthdays'] && !empty($row['user_birthday']))
  1173. {
  1174. list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $row['user_birthday']));
  1175. if ($bday_year)
  1176. {
  1177. $diff = $now['mon'] - $bday_month;
  1178. if ($diff == 0)
  1179. {
  1180. $diff = ($now['mday'] - $bday_day < 0) ? 1 : 0;
  1181. }
  1182. else
  1183. {
  1184. $diff = ($diff < 0) ? 1 : 0;
  1185. }
  1186. $user_cache[$poster_id]['age'] = (int) ($now['year'] - $bday_year - $diff);
  1187. //-- mod: Prime Birthdate ---------------------------------------------------//
  1188. include($phpbb_root_path . 'includes/prime_birthdate.' . $phpEx);
  1189. $prime_birthdate->alter_user_cache($user_cache, $row);
  1190. //-- end: Prime Birthdate ---------------------------------------------------//
  1191. }
  1192. }
  1193. }
  1194. }
  1195. }
  1196. $db->sql_freeresult($result);
  1197. // Load custom profile fields
  1198. if ($config['load_cpf_viewtopic'])
  1199. {
  1200. if (!class_exists('custom_profile'))
  1201. {
  1202. include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
  1203. }
  1204. $cp = new custom_profile();
  1205. // Grab all profile fields from users in id cache for later use - similar to the poster cache
  1206. $profile_fields_tmp = $cp->generate_profile_fields_template('grab', $id_cache);
  1207. // filter out fields not to be displayed on viewtopic. Yes, it's a hack, but this shouldn't break any MODs.
  1208. $profile_fields_cache = array();
  1209. foreach ($profile_fields_tmp as $profile_user_id => $profile_fields)
  1210. {
  1211. $profile_fields_cache[$profile_user_id] = array();
  1212. foreach ($profile_fields as $used_ident => $profile_field)
  1213. {
  1214. if ($profile_field['data']['field_show_on_vt'])
  1215. {
  1216. $profile_fields_cache[$profile_user_id][$used_ident] = $profile_field;
  1217. }
  1218. }
  1219. }
  1220. unset($profile_fields_tmp);
  1221. }
  1222. // Generate online information for user
  1223. if ($config['load_onlinetrack'] && sizeof($id_cache))
  1224. {
  1225. $sql = 'SELECT session_user_id, MAX(session_time) as online_time, MIN(session_viewonline) AS viewonline
  1226. FROM ' . SESSIONS_TABLE . '
  1227. WHERE ' . $db->sql_in_set('session_user_id', $id_cache) . '
  1228. GROUP BY session_user_id';
  1229. $result = $db->sql_query($sql);
  1230. $update_time = $config['load_online_time'] * 60;
  1231. while ($row = $db->sql_fetchrow($result))
  1232. {
  1233. $user_cache[$row['session_user_id']]['online'] = (time() - $update_time < $row['online_time'] && (($row['viewonline']) || $auth->acl_get('u_viewonline'))) ? true : false;
  1234. }
  1235. $db->sql_freeresult($result);
  1236. }
  1237. unset($id_cache);
  1238. // Pull attachment data
  1239. if (sizeof($attach_list))
  1240. {
  1241. if ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id))
  1242. {
  1243. $sql = 'SELECT *
  1244. FROM ' . ATTACHMENTS_TABLE . '
  1245. WHERE ' . $db->sql_in_set('post_msg_id', $attach_list) . '
  1246. AND in_message = 0
  1247. ORDER BY filetime DESC, post_msg_id ASC';
  1248. $result = $db->sql_query($sql);
  1249. while ($row = $db->sql_fetchrow($result))
  1250. {
  1251. $attachments[$row['post_msg_id']][] = $row;
  1252. }
  1253. $db->sql_freeresult($result);
  1254. // No attachments exist, but post table thinks they do so go ahead and reset post_attach flags
  1255. if (!sizeof($attachments))
  1256. {
  1257. $sql = 'UPDATE ' . POSTS_TABLE . '
  1258. SET post_attachment = 0
  1259. WHERE ' . $db->sql_in_set('post_id', $attach_list);
  1260. $db->sql_query($sql);
  1261. // We need to update the topic indicator too if the complete topic is now without an attachment
  1262. if (sizeof($rowset) != $total_posts)
  1263. {
  1264. // Not all posts are displayed so we query the db to find if there's any attachment for this topic
  1265. $sql = 'SELECT a.post_msg_id as post_id
  1266. FROM ' . ATTACHMENTS_TABLE . ' a, ' . POSTS_TABLE . " p
  1267. WHERE p.topic_id = $topic_id
  1268. AND p.post_approved = 1
  1269. AND p.topic_id = a.topic_id";
  1270. $result = $db->sql_query_limit($sql, 1);
  1271. $row = $db->sql_fetchrow($result);
  1272. $db->sql_freeresult($result);
  1273. if (!$row)
  1274. {
  1275. $sql = 'UPDATE ' . TOPICS_TABLE . "
  1276. SET topic_attachment = 0
  1277. WHERE topic_id = $topic_id";
  1278. $db->sql_query($sql);
  1279. }
  1280. }
  1281. else
  1282. {
  1283. $sql = 'UPDATE ' . TOPICS_TABLE . "
  1284. SET topic_attachment = 0
  1285. WHERE topic_id = $topic_id";
  1286. $db->sql_query($sql);
  1287. }
  1288. }
  1289. else if ($has_attachments && !$topic_data['topic_attachment'])
  1290. {
  1291. // Topic has approved attachments but its flag is wrong
  1292. $sql = 'UPDATE ' . TOPICS_TABLE . "
  1293. SET topic_attachment = 1
  1294. WHERE topic_id = $topic_id";
  1295. $db->sql_query($sql);
  1296. $topic_data['topic_attachment'] = 1;
  1297. }
  1298. }
  1299. else
  1300. {
  1301. $display_notice = true;
  1302. }
  1303. }
  1304. // Instantiate BBCode if need be
  1305. if ($bbcode_bitfield !== '')
  1306. {
  1307. $bbcode = new bbcode(base64_encode($bbcode_bitfield));
  1308. }
  1309. $i_total = sizeof($rowset) - 1;
  1310. $prev_post_id = '';
  1311. $template->assign_vars(array(
  1312. 'S_NUM_POSTS' => sizeof($post_list))
  1313. );
  1314. // Check whether quick reply is enabled
  1315. $s_quick_reply = false;
  1316. if ($user->data['is_registered'] && $config['allow_quick_reply'] && ($topic_data['forum_flags'] & FORUM_FLAG_QUICK_REPLY) && $auth->acl_get('f_reply', $forum_id))
  1317. {
  1318. // Quick reply enabled forum
  1319. $s_quick_reply = (($topic_data['forum_status'] == ITEM_UNLOCKED && $topic_data['topic_status'] == ITEM_UNLOCKED) || $auth->acl_get('m_edit', $forum_id)) ? true : false;
  1320. }
  1321. // Output the posts
  1322. $first_unread = $post_unread = false;
  1323. for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i)
  1324. {
  1325. // A non-existing rowset only happens if there was no user present for the entered poster_id
  1326. // This could be a broken posts table.
  1327. if (!isset($rowset[$post_list[$i]]))
  1328. {
  1329. continue;
  1330. }
  1331. $row =& $rowset[$post_list[$i]];
  1332. $poster_id = $row['user_id'];
  1333. // End signature parsing, only if needed
  1334. if ($user_cache[$poster_id]['sig'] && $row['enable_sig'] && empty($user_cache[$poster_id]['sig_parsed']))
  1335. {
  1336. $user_cache[$poster_id]['sig'] = censor_text($user_cache[$poster_id]['sig']);
  1337. if ($user_cache[$poster_id]['sig_bbcode_bitfield'])
  1338. {
  1339. $bbcode->bbcode_second_pass($user_cache[$poster_id]['sig'], $user_cache[$poster_id]['sig_bbcode_uid'], $user_cache[$poster_id]['sig_bbcode_bitfield']);
  1340. }
  1341. $user_cache[$poster_id]['sig'] = bbcode_nl2br($user_cache[$poster_id]['sig']);
  1342. $user_cache[$poster_id]['sig'] = smiley_text($user_cache[$poster_id]['sig']);
  1343. $user_cache[$poster_id]['sig_parsed'] = true;
  1344. }
  1345. // Parse the message and subject
  1346. $message = censor_text($row['post_text']);
  1347. $decoded_message = false;
  1348. if ($s_quick_reply)
  1349. {
  1350. $decoded_message = $message;
  1351. decode_message($decoded_message, $row['bbcode_uid']);
  1352. $decoded_message = bbcode_nl2br($decoded_message);
  1353. }
  1354. // www.phpBB-SEO.com SEO TOOLKIT BEGIN - META
  1355. if ($i == 0) {
  1356. $m_kewrd = '';
  1357. $seo_meta->collect('description', $message);
  1358. if ($seo_meta->mconfig['topic_sql']) {
  1359. $common_sql = $seo_meta->mconfig['bypass_common'] ? '' : 'AND w.word_common = 0';
  1360. // collect keywords from all post in page
  1361. $post_id_sql = $db->sql_in_set('m.post_id', $post_list, false, true);
  1362. $sql = "SELECT w.word_text
  1363. FROM " . SEARCH_WORDMATCH_TABLE . " m, " . SEARCH_WORDLIST_TABLE . " w
  1364. WHERE $post_id_sql
  1365. AND w.word_id = m.word_id
  1366. $common_sql
  1367. ORDER BY w.word_count DESC";
  1368. $result = $db->sql_query_limit($sql, min(25, (int) $seo_meta->mconfig['keywordlimit']));
  1369. while ( $meta_row = $db->sql_fetchrow($result) ) {
  1370. $m_kewrd .= ' ' . $meta_row['word_text'];
  1371. }
  1372. $db->sql_freeresult($result);
  1373. }
  1374. $seo_meta->collect('keywords', $topic_data['topic_title'] . ' ' . $row['post_subject'] . ' ' . (!empty($m_kewrd) ? $m_kewrd : $seo_meta->meta['description']));
  1375. }
  1376. // www.phpBB-SEO.com SEO TOOLKIT END - META
  1377. // Second parse bbcode here
  1378. if ($row['bbcode_bitfield'])
  1379. {
  1380. $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
  1381. }
  1382. $message = bbcode_nl2br($message);
  1383. $message = smiley_text($message);
  1384. if (!empty($attachments[$row['post_id']]))
  1385. {
  1386. parse_attachments($forum_id, $message, $attachments[$row['post_id']], $update_count);
  1387. }
  1388. // Replace naughty words such as farty pants
  1389. $row['post_subject'] = censor_text($row['post_subject']);
  1390. // Highlight active words (primarily for search)
  1391. if ($highlight_match)
  1392. {
  1393. $message = preg_replace('#(?!<.*)(?<!\w)(' . $highlight_match . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">\1</span>', $message);
  1394. $row['post_subject'] = preg_replace('#(?!<.*)(?<!\w)(' . $highlight_match . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">\1</span>', $row['post_subject']);
  1395. }
  1396. //-- mod: Prime Post Revisions ----------------------------------------------//
  1397. $prime_post_revisions->set_edit_count($row);
  1398. //-- end: Prime Post Revisions ----------------------------------------------//
  1399. // Editing information
  1400. if (($row['post_edit_count'] && $config['display_last_edited']) || $row['post_edit_reason'])
  1401. {
  1402. // Get usernames for all following posts if not already stored
  1403. if (!sizeof($post_edit_list) && ($row['post_edit_reason'] || ($row['post_edit_user'] && !isset($user_cache[$row['post_edit_user']]))))
  1404. {
  1405. // Remove all post_ids already parsed (we do not have to check them)
  1406. $post_storage_list = (!$store_reverse) ? array_slice($post_list, $i) : array_slice(array_reverse($post_list), $i);
  1407. $sql = 'SELECT DISTINCT u.user_id, u.username, u.user_colour
  1408. FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
  1409. WHERE ' . $db->sql_in_set('p.post_id', $post_storage_list) . '
  1410. AND p.post_edit_count <> 0
  1411. AND p.post_edit_user <> 0
  1412. AND p.post_edit_user = u.user_id';
  1413. $result2 = $db->sql_query($sql);
  1414. while ($user_edit_row = $db->sql_fetchrow($result2))
  1415. {
  1416. $post_edit_list[$user_edit_row['user_id']] = $user_edit_row;
  1417. }
  1418. $db->sql_freeresult($result2);
  1419. unset($post_storage_list);
  1420. }
  1421. //-- mod: Prime Post Revisions ----------------------------------------------//
  1422. $prime_post_revisions->inject_user_data($row);
  1423. //-- end: Prime Post Revisions ----------------------------------------------//
  1424. $l_edit_time_total = ($row['post_edit_count'] == 1) ? $user->lang['EDITED_TIME_TOTAL'] : $user->lang['EDITED_TIMES_TOTAL'];
  1425. if ($row['post_edit_reason'])
  1426. {
  1427. // User having edited the post also being the post author?
  1428. if (!$row['post_edit_user'] || $row['post_edit_user'] == $poster_id)
  1429. {
  1430. $display_username = get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']);
  1431. }
  1432. else
  1433. {
  1434. $display_username = get_username_string('full', $row['post_edit_user'], $post_edit_list[$row['post_edit_user']]['username'], $post_edit_list[$row['post_edit_user']]['user_colour']);
  1435. }
  1436. $l_edited_by = sprintf($l_edit_time_total, $display_username, $user->format_date($row['post_edit_time'], false, true), $row['post_edit_count']);
  1437. }
  1438. else
  1439. {
  1440. if ($row['post_edit_user'] && !isset($user_cache[$row['post_edit_user']]))
  1441. {
  1442. $user_cache[$row['post_edit_user']] = $post_edit_list[$row['post_edit_user']];
  1443. }
  1444. // User having edited the post also being the post author?
  1445. if (!$row['post_edit_user'] || $row['post_edit_user'] == $poster_id)
  1446. {
  1447. $display_username = get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']);
  1448. }
  1449. else
  1450. {
  1451. $display_username = get_username_string('full', $row['post_edit_user'], $user_cache[$row['post_edit_user']]['username'], $user_cache[$row['post_edit_user']]['user_colour']);
  1452. }
  1453. $l_edited_by = sprintf($l_edit_time_total, $display_username, $user->format_date($row['post_edit_time'], false, true), $row['post_edit_count']);
  1454. }
  1455. }
  1456. else
  1457. {
  1458. $l_edited_by = '';
  1459. }
  1460. // Bump information
  1461. if ($topic_data['topic_bumped'] && $row['post_id'] == $topic_data['topic_last_post_id'] && isset($user_cache[$topic_data['topic_bumper']]) )
  1462. {
  1463. // It is safe to grab the username from the user cache array, we are at the last
  1464. // post and only the topic poster and last poster are allowed to bump.
  1465. // Admins and mods are bound to the above rules too...
  1466. $l_bumped_by = sprintf($user->lang['BUMPED_BY'], $user_cache[$topic_data['topic_bumper']]['username'], $user->format_date($topic_data['topic_last_post_time'], false, true));
  1467. }
  1468. else
  1469. {
  1470. $l_bumped_by = '';
  1471. }
  1472. $cp_row = array();
  1473. //
  1474. if ($config['load_cpf_viewtopic'])
  1475. {
  1476. $cp_row = (isset($profile_fields_cache[$poster_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$poster_id]) : array();
  1477. }
  1478. $post_unread = (isset($topic_tracking_info[$topic_id]) && $row['post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
  1479. $s_first_unread = false;
  1480. if (!$first_unread && $post_unread)
  1481. {
  1482. $s_first_unread = $first_unread = true;
  1483. }
  1484. $edit_allowed = ($user->data['is_registered'] && ($auth->acl_get('m_edit', $forum_id) || (
  1485. $user->data['user_id'] == $poster_id &&
  1486. $auth->acl_get('f_edit', $forum_id) &&
  1487. !$row['post_edit_locked'] &&
  1488. ($row['post_time'] > time() - ($config['edit_time'] * 60) || !$config['edit_time'])
  1489. )));
  1490. $delete_allowed = ($user->data['is_registered'] && ($auth->acl_get('m_delete', $forum_id) || (
  1491. $user->data['user_id'] == $poster_id &&
  1492. $auth->acl_get('f_delete', $forum_id) &&
  1493. $topic_data['topic_last_post_id'] == $row['post_id'] &&
  1494. ($row['post_time'] > time() - ($config['delete_time'] * 60) || !$config['delete_time']) &&
  1495. // we do not want to allow removal of the last post if a moderator locked it!
  1496. !$row['post_edit_locked']
  1497. )));
  1498. //
  1499. $postrow = array(
  1500. 'POST_AUTHOR_FULL' => ($poster_id != ANONYMOUS) ? $user_cache[$poster_id]['author_full'] : get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
  1501. 'POST_AUTHOR_COLOUR' => ($poster_id != ANONYMOUS) ? $user_cache[$poster_id]['author_colour'] : get_username_string('colour', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
  1502. 'POST_AUTHOR' => ($poster_id != ANONYMOUS) ? $user_cache[$poster_id]['author_username'] : get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
  1503. 'U_POST_AUTHOR' => ($poster_id != ANONYMOUS) ? $user_cache[$poster_id]['author_profile'] : get_username_string('profile', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
  1504. 'RANK_TITLE' => $user_cache[$poster_id]['rank_title'],
  1505. 'RANK_IMG' => $user_cache[$poster_id]['rank_image'],
  1506. 'RANK_IMG_SRC' => $user_cache[$poster_id]['rank_image_src'],
  1507. 'POSTER_JOINED' => $user_cache[$poster_id]['joined'],
  1508. 'POSTER_POSTS' => $user_cache[$poster_id]['posts'],
  1509. 'POSTER_FROM' => $user_cache[$poster_id]['from'],
  1510. 'POSTER_AVATAR' => $user_cache[$poster_id]['avatar'],
  1511. 'POSTER_WARNINGS' => $user_cache[$poster_id]['warnings'],
  1512. 'POSTER_AGE' => $user_cache[$poster_id]['age'],
  1513. 'POST_DATE' => $user->format_date($row['post_time'], false, ($view == 'print') ? true : false),
  1514. 'POST_SUBJECT' => $row['post_subject'],
  1515. 'MESSAGE' => $message,
  1516. 'DECODED_MESSAGE' => $decoded_message,
  1517. 'SIGNATURE' => ($row['enable_sig']) ? $user_cache[$poster_id]['sig'] : '',
  1518. 'EDITED_MESSAGE' => $l_edited_by,
  1519. 'EDIT_REASON' => $row['post_edit_reason'],
  1520. 'BUMPED_MESSAGE' => $l_bumped_by,
  1521. 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
  1522. 'POST_ICON_IMG' => ($topic_data['enable_icons'] && !empty($row['icon_id'])) ? $icons[$row['icon_id']]['img'] : '',
  1523. 'POST_ICON_IMG_WIDTH' => ($topic_data['enable_icons'] && !empty($row['icon_id'])) ? $icons[$row['icon_id']]['width'] : '',
  1524. 'POST_ICON_IMG_HEIGHT' => ($topic_data['enable_icons'] && !empty($row['icon_id'])) ? $icons[$row['icon_id']]['height'] : '',
  1525. 'ICQ_STATUS_IMG' => $user_cache[$poster_id]['icq_status_img'],
  1526. 'ONLINE_IMG' => ($poster_id == ANONYMOUS || !$config['load_onlinetrack']) ? '' : (($user_cache[$poster_id]['online']) ? $user->img('icon_user_online', 'ONLINE') : $user->img('icon_user_offline', 'OFFLINE')),
  1527. 'S_ONLINE' => ($poster_id == ANONYMOUS || !$config['load_onlinetrack']) ? false : (($user_cache[$poster_id]['online']) ? true : false),
  1528. 'U_EDIT' => ($edit_allowed) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=edit&amp;f=$forum_id&amp;p={$row['post_id']}") : '',
  1529. 'U_QUOTE' => ($auth->acl_get('f_reply', $forum_id)) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=quote&amp;f=$forum_id&amp;p={$row['post_id']}") : '',
  1530. 'U_INFO' => ($auth->acl_get('m_info', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&amp;mode=post_details&amp;f=$forum_id&amp;p=" . $row['post_id'], true, $user->session_id) : '',
  1531. 'U_DELETE' => ($delete_allowed) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=delete&amp;f=$forum_id&amp;p={$row['post_id']}") : '',
  1532. 'U_PROFILE' => $user_cache[$poster_id]['profile'],
  1533. 'U_SEARCH' => $user_cache[$poster_id]['search'],
  1534. 'U_PM' => ($poster_id != ANONYMOUS && $config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($user_cache[$poster_id]['allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=compose&amp;action=quotepost&amp;p=' . $row['post_id']) : '',
  1535. 'U_EMAIL' => $user_cache[$poster_id]['email'],
  1536. 'U_WWW' => $user_cache[$poster_id]['www'],
  1537. 'U_ICQ' => $user_cache[$poster_id]['icq'],
  1538. 'U_AIM' => $user_cache[$poster_id]['aim'],
  1539. 'U_MSN' => $user_cache[$poster_id]['msn'],
  1540. 'U_YIM' => $user_cache[$poster_id]['yim'],
  1541. 'U_JABBER' => $user_cache[$poster_id]['jabber'],
  1542. 'U_REPORT' => ($auth->acl_get('f_report', $forum_id)) ? append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&amp;p=' . $row['post_id']) : '',
  1543. 'U_MCP_REPORT' => ($auth->acl_get('m_report', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=report_details&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '',
  1544. 'U_MCP_APPROVE' => ($auth->acl_get('m_approve', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=approve_details&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '',
  1545. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  1546. // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe
  1547. 'U_MINI_POST' => !empty($phpbb_seo->seo_opt['no_dupe']['on']) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $topic_id . '&amp;f=' . $forum_id . '&amp;start=' . $start ) . '#p' . $row['post_id'] : append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['post_id'] . (($topic_data['topic_type'] == POST_GLOBAL) ? '&amp;f=' . $forum_id : '')) . '#p' . $row['post_id'],
  1548. // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe
  1549. // www.phpBB-SEO.com SEO TOOLKIT END
  1550. 'U_NEXT_POST_ID' => ($i < $i_total && isset($rowset[$post_list[$i + 1]])) ? $rowset[$post_list[$i + 1]]['post_id'] : '',
  1551. 'U_PREV_POST_ID' => $prev_post_id,
  1552. 'U_NOTES' => ($auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $poster_id, true, $user->session_id) : '',
  1553. 'U_WARN' => ($auth->acl_get('m_warn') && $poster_id != $user->data['user_id'] && $poster_id != ANONYMOUS) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&amp;mode=warn_post&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '',
  1554. 'POST_ID' => $row['post_id'],
  1555. 'POST_NUMBER' => $i + $start + 1,
  1556. 'POSTER_ID' => $poster_id,
  1557. 'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false,
  1558. 'S_POST_UNAPPROVED' => ($row['post_approved']) ? false : true,
  1559. 'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_report', $forum_id)) ? true : false,
  1560. 'S_DISPLAY_NOTICE' => $display_notice && $row['post_attachment'],
  1561. 'S_FRIEND' => ($row['friend']) ? true : false,
  1562. 'S_UNREAD_POST' => $post_unread,
  1563. 'S_FIRST_UNREAD' => $s_first_unread,
  1564. 'S_CUSTOM_FIELDS' => (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false,
  1565. 'S_TOPIC_POSTER' => ($topic_data['topic_poster'] == $poster_id) ? true : false,
  1566. 'S_IGNORE_POST' => ($row['hide_post']) ? true : false,
  1567. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  1568. 'L_IGNORE_POST' => ($row['hide_post']) ? sprintf($user->lang['POST_BY_FOE'], get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;p={$row['post_id']}&amp;view=show") . '#p' . $row['post_id'] . '">', '</a>') : '',
  1569. // www.phpBB-SEO.com SEO TOOLKIT END
  1570. );
  1571. //-- mod: Prime Post Revisions ----------------------------------------------//
  1572. $prime_post_revisions->update_postrow($post_list, $i, $rowset, $postrow);
  1573. //-- end: Prime Post Revisions ----------------------------------------------//
  1574. if (isset($cp_row['row']) && sizeof($cp_row['row']))
  1575. {
  1576. $postrow = array_merge($postrow, $cp_row['row']);
  1577. }
  1578. //-- mod: Prime Trash Bin (Posts) -------------------------------------------//
  1579. // Set up what we're going to display for the deleted message.
  1580. if (!empty($row['post_deleted_time']))
  1581. {
  1582. include ($phpbb_root_path . 'includes/prime_trash_bin_a.' . $phpEx);
  1583. set_stifled_post_template_vars($row, $message, $row['post_subject'], $postrow);
  1584. }
  1585. // If there is only one post, and the topic has been deleted, then only display the delete icon if user can permanently delete the topic.
  1586. if ($topic_data['topic_first_post_id'] == $topic_data['topic_last_post_id'] && $topic_data['topic_deleted_time'])
  1587. {
  1588. $postrow['U_DELETE'] = auth_fake_delete('delete', isset($topic_data['forum_id'])) ? $postrow['U_DELETE'] : '';
  1589. }
  1590. //-- end: Prime Trash Bin (Posts) -------------------------------------------//
  1591. // Dump vars into template
  1592. $template->assign_block_vars('postrow', $postrow);
  1593. if (!empty($cp_row['blockrow']))
  1594. {
  1595. foreach ($cp_row['blockrow'] as $field_data)
  1596. {
  1597. $template->assign_block_vars('postrow.custom_fields', $field_data);
  1598. }
  1599. }
  1600. // Display not already displayed Attachments for this post, we already parsed them. ;)
  1601. if (!empty($attachments[$row['post_id']]))
  1602. {
  1603. foreach ($attachments[$row['post_id']] as $attachment)
  1604. {
  1605. $template->assign_block_vars('postrow.attachment', array(
  1606. 'DISPLAY_ATTACHMENT' => $attachment)
  1607. );
  1608. }
  1609. }
  1610. $prev_post_id = $row['post_id'];
  1611. unset($rowset[$post_list[$i]]);
  1612. unset($attachments[$row['post_id']]);
  1613. }
  1614. unset($rowset, $user_cache);
  1615. // Update topic view and if necessary attachment view counters ... but only for humans and if this is the first 'page view'
  1616. if (isset($user->data['session_page']) && !$user->data['is_bot'] && (strpos($user->data['session_page'], '&t=' . $topic_id) === false || isset($user->data['session_created'])))
  1617. {
  1618. $sql = 'UPDATE ' . TOPICS_TABLE . '
  1619. SET topic_views = topic_views + 1, topic_last_view_time = ' . time() . "
  1620. WHERE topic_id = $topic_id";
  1621. $db->sql_query($sql);
  1622. // Update the attachment download counts
  1623. if (sizeof($update_count))
  1624. {
  1625. $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
  1626. SET download_count = download_count + 1
  1627. WHERE ' . $db->sql_in_set('attach_id', array_unique($update_count));
  1628. $db->sql_query($sql);
  1629. }
  1630. }
  1631. // Get last post time for all global announcements
  1632. // to keep proper forums tracking
  1633. if ($topic_data['topic_type'] == POST_GLOBAL)
  1634. {
  1635. $sql = 'SELECT topic_last_post_time as forum_last_post_time
  1636. FROM ' . TOPICS_TABLE . '
  1637. WHERE forum_id = 0
  1638. ORDER BY topic_last_post_time DESC';
  1639. $result = $db->sql_query_limit($sql, 1);
  1640. $topic_data['forum_last_post_time'] = (int) $db->sql_fetchfield('forum_last_post_time');
  1641. $db->sql_freeresult($result);
  1642. $sql = 'SELECT mark_time as forum_mark_time
  1643. FROM ' . FORUMS_TRACK_TABLE . '
  1644. WHERE forum_id = 0
  1645. AND user_id = ' . $user->data['user_id'];
  1646. $result = $db->sql_query($sql);
  1647. $topic_data['forum_mark_time'] = (int) $db->sql_fetchfield('forum_mark_time');
  1648. $db->sql_freeresult($result);
  1649. }
  1650. // Only mark topic if it's currently unread. Also make sure we do not set topic tracking back if earlier pages are viewed.
  1651. if (isset($topic_tracking_info[$topic_id]) && $topic_data['topic_last_post_time'] > $topic_tracking_info[$topic_id] && $max_post_time > $topic_tracking_info[$topic_id])
  1652. {
  1653. markread('topic', (($topic_data['topic_type'] == POST_GLOBAL) ? 0 : $forum_id), $topic_id, $max_post_time);
  1654. // Update forum info
  1655. $all_marked_read = update_forum_tracking_info((($topic_data['topic_type'] == POST_GLOBAL) ? 0 : $forum_id), $topic_data['forum_last_post_time'], (isset($topic_data['forum_mark_time'])) ? $topic_data['forum_mark_time'] : false, false);
  1656. }
  1657. else
  1658. {
  1659. $all_marked_read = true;
  1660. }
  1661. // If there are absolutely no more unread posts in this forum and unread posts shown, we can savely show the #unread link
  1662. if ($all_marked_read)
  1663. {
  1664. if ($post_unread)
  1665. {
  1666. $template->assign_vars(array(
  1667. 'U_VIEW_UNREAD_POST' => '#unread',
  1668. ));
  1669. }
  1670. else if (isset($topic_tracking_info[$topic_id]) && $topic_data['topic_last_post_time'] > $topic_tracking_info[$topic_id])
  1671. {
  1672. $template->assign_vars(array(
  1673. 'U_VIEW_UNREAD_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;view=unread") . '#unread',
  1674. ));
  1675. }
  1676. }
  1677. else if (!$all_marked_read)
  1678. {
  1679. $last_page = ((floor($start / $config['posts_per_page']) + 1) == max(ceil($total_posts / $config['posts_per_page']), 1)) ? true : false;
  1680. // What can happen is that we are at the last displayed page. If so, we also display the #unread link based in $post_unread
  1681. if ($last_page && $post_unread)
  1682. {
  1683. $template->assign_vars(array(
  1684. 'U_VIEW_UNREAD_POST' => '#unread',
  1685. ));
  1686. }
  1687. else if (!$last_page)
  1688. {
  1689. $template->assign_vars(array(
  1690. 'U_VIEW_UNREAD_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;view=unread") . '#unread',
  1691. ));
  1692. }
  1693. }
  1694. if ($s_can_vote || $s_quick_reply)
  1695. {
  1696. add_form_key('posting');
  1697. if ($s_quick_reply)
  1698. {
  1699. $user->add_lang(array('posting', 'mcp'));
  1700. $s_attach_sig = $config['allow_sig'] && $user->optionget('attachsig') && $auth->acl_get('f_sigs', $forum_id) && $auth->acl_get('u_sig');
  1701. $s_smilies = $config['allow_smilies'] && $user->optionget('smilies') && $auth->acl_get('f_smilies', $forum_id);
  1702. $s_bbcode = $config['allow_bbcode'] && $user->optionget('bbcode') && $auth->acl_get('f_bbcode', $forum_id);
  1703. $s_notify = $config['allow_topic_notify'] && ($user->data['user_notify'] || $s_watching_topic['is_watching']);
  1704. $s_url = $config['allow_post_links'];
  1705. $s_img = $s_bbcode && $auth->acl_get('f_img', $forum_id);
  1706. $s_flash = $s_bbcode && $auth->acl_get('f_flash', $forum_id) && $config['allow_post_flash'];
  1707. $s_topic_icons = false;
  1708. if ($topic_data['enable_icons'] && $auth->acl_get('f_icons', $forum_id))
  1709. {
  1710. $s_topic_icons = posting_gen_topic_icons('reply', $topic_data['icon_id']);
  1711. }
  1712. $qr_hidden_fields = array(
  1713. 'topic_cur_post_id' => (int) $topic_data['topic_last_post_id'],
  1714. 'lastclick' => (int) time(),
  1715. 'topic_id' => (int) $topic_data['topic_id'],
  1716. 'forum_id' => (int) $forum_id,
  1717. );
  1718. // Originally we use checkboxes and check with isset(), so we only provide them if they would be checked
  1719. (!$s_bbcode) ? $qr_hidden_fields['disable_bbcode'] = 1 : true;
  1720. (!$s_smilies) ? $qr_hidden_fields['disable_smilies'] = 1 : true;
  1721. (!$config['allow_post_links']) ? $qr_hidden_fields['disable_magic_url'] = 1 : true;
  1722. ($s_attach_sig) ? $qr_hidden_fields['attach_sig'] = 1 : true;
  1723. ($s_notify) ? $qr_hidden_fields['notify'] = 1 : true;
  1724. ($topic_data['topic_status'] == ITEM_LOCKED) ? $qr_hidden_fields['lock_topic'] = 1 : true;
  1725. $template->assign_vars(array(
  1726. 'L_ICON' => $user->lang['POST_ICON'],
  1727. 'L_MESSAGE_BODY_EXPLAIN' => (intval($config['max_post_chars'])) ? sprintf($user->lang['MESSAGE_BODY_EXPLAIN'], intval($config['max_post_chars'])) : '',
  1728. 'SUBJECT' => '',
  1729. 'BBCODE_STATUS' => ($s_bbcode) ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>'),
  1730. 'IMG_STATUS' => ($s_img) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
  1731. 'FLASH_STATUS' => ($s_flash) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
  1732. 'SMILIES_STATUS' => ($s_smilies) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
  1733. 'URL_STATUS' => ($s_bbcode && $s_url) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
  1734. 'U_QR_ACTION' => append_sid("{$phpbb_root_path}posting.$phpEx", "mode=reply&amp;f=$forum_id&amp;t=$topic_id"),
  1735. 'QR_HIDDEN_FIELDS' => build_hidden_fields($qr_hidden_fields),
  1736. 'S_QUICK_REPLY' => true,
  1737. 'S_SHOW_TOPIC_ICONS' => $s_topic_icons,
  1738. 'S_BBCODE_ALLOWED' => $s_bbcode,
  1739. 'S_SMILIES_ALLOWED' => $s_smilies,
  1740. 'S_LINKS_ALLOWED' => $s_url,
  1741. 'S_SAVE_ALLOWED' => ($auth->acl_get('u_savedrafts') && $user->data['is_registered']) ? true : false,
  1742. 'S_BBCODE_IMG' => $s_img,
  1743. 'S_BBCODE_URL' => $s_url,
  1744. 'S_BBCODE_FLASH' => $s_flash,
  1745. 'S_BBCODE_QUOTE' => true,
  1746. ));
  1747. // Build custom bbcodes array
  1748. display_custom_bbcodes();
  1749. // Generate smiley listing
  1750. generate_smilies('inline', $forum_id);
  1751. }
  1752. }
  1753. // now I have the urge to wash my hands :(
  1754. // We overwrite $_REQUEST['f'] if there is no forum specified
  1755. // to be able to display the correct online list.
  1756. // One downside is that the user currently viewing this topic/post is not taken into account.
  1757. if (empty($_REQUEST['f']))
  1758. {
  1759. $_REQUEST['f'] = $forum_id;
  1760. }
  1761. // We need to do the same with the topic_id. See #53025.
  1762. if (empty($_REQUEST['t']) && !empty($topic_id))
  1763. {
  1764. $_REQUEST['t'] = $topic_id;
  1765. }
  1766. // www.phpBB-SEO.com SEO TOOLKIT BEGIN - Related Topics
  1767. if (!empty($config['seo_related'])) {
  1768. require($phpbb_root_path . "phpbb_seo/phpbb_seo_related.$phpEx");
  1769. $seo_related = new seo_related();
  1770. $seo_related->get($topic_data, $forum_id);
  1771. }
  1772. //-- mod: Prime Post Revisions ----------------------------------------------//
  1773. $prime_post_revisions->assign_template_variables($viewtopic_url, $viewtopic_title);
  1774. //-- end: Prime Post Revisions ----------------------------------------------//
  1775. // www.phpBB-SEO.com SEO TOOLKIT END - Related Topics
  1776. //-- mod: Prime Trash Bin (Topics) ------------------------------------------//
  1777. if ($topic_deleted)
  1778. {
  1779. $template_vars = set_stifled_topic_template_vars($topic_data, $topic_data['topic_title'], ($blockname = true));
  1780. // This will become the page's title (in the browser's title bar).
  1781. $topic_data['topic_title'] = $template_vars['TOPIC_TITLE'];
  1782. }
  1783. //-- end: Prime Trash Bin (Topics) ------------------------------------------//
  1784. // Output the page
  1785. // www.phpBB-SEO.com SEO TOOLKIT BEGIN - TITLE
  1786. $extra_title = ($start > 0) ? ' - ' . $user->lang['Page'] . ( floor( ($start / $config['posts_per_page']) ) + 1 ) : '';
  1787. page_header($topic_data['topic_title'] . ' : ' . $topic_data['forum_name'] . $extra_title, true, $forum_id);
  1788. // www.phpBB-SEO.com SEO TOOLKIT END - TITLE
  1789. $template->set_filenames(array(
  1790. 'body' => ($view == 'print') ? 'viewtopic_print.html' : 'viewtopic_body.html')
  1791. );
  1792. make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"), $forum_id);
  1793. page_footer();
  1794. ?>