Guest User

viewtopic

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