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

/doweneed/forums/viewtopic.php

https://bitbucket.org/natis/masscap-main
PHP | 1249 lines | 927 code | 172 blank | 150 comment | 203 complexity | 7ad34754eedd88b956365e6021f6c71d MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /***************************************************************************
  3. * viewtopic.php
  4. * -------------------
  5. * begin : Saturday, Feb 13, 2001
  6. * copyright : (C) 2001 The phpBB Group
  7. * email : support@phpbb.com
  8. *
  9. * $Id: viewtopic.php,v 1.186.2.7 2002/07/22 13:12:23 psotfx Exp $
  10. *
  11. *
  12. ***************************************************************************/
  13. /***************************************************************************
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. ***************************************************************************/
  21. define('IN_PHPBB', true);
  22. $phpbb_root_path = './';
  23. include($phpbb_root_path . 'extension.inc');
  24. include($phpbb_root_path . 'common.'.$phpEx);
  25. include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
  26. //
  27. // Start initial var setup
  28. //
  29. if ( isset($HTTP_GET_VARS[POST_TOPIC_URL]) )
  30. {
  31. $topic_id = intval($HTTP_GET_VARS[POST_TOPIC_URL]);
  32. }
  33. else if ( isset($HTTP_GET_VARS['topic']) )
  34. {
  35. $topic_id = intval($HTTP_GET_VARS['topic']);
  36. }
  37. if ( isset($HTTP_GET_VARS[POST_POST_URL]))
  38. {
  39. $post_id = intval($HTTP_GET_VARS[POST_POST_URL]);
  40. }
  41. $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
  42. if ( !isset($topic_id) && !isset($post_id) )
  43. {
  44. message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
  45. }
  46. //
  47. // Find topic id if user requested a newer
  48. // or older topic
  49. //
  50. if ( isset($HTTP_GET_VARS['view']) && empty($HTTP_GET_VARS[POST_POST_URL]) )
  51. {
  52. if ( $HTTP_GET_VARS['view'] == 'newest' )
  53. {
  54. $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
  55. if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) )
  56. {
  57. $session_id = $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid'];
  58. if ( $session_id )
  59. {
  60. $sql = "SELECT p.post_id
  61. FROM " . POSTS_TABLE . " p, " . SESSIONS_TABLE . " s, " . USERS_TABLE . " u
  62. WHERE s.session_id = '$session_id'
  63. AND u.user_id = s.session_user_id
  64. AND p.topic_id = $topic_id
  65. AND p.post_time >= u.user_lastvisit
  66. ORDER BY p.post_time ASC
  67. LIMIT 1";
  68. if ( !($result = $db->sql_query($sql)) )
  69. {
  70. message_die(GENERAL_ERROR, 'Could not obtain newer/older topic information', '', __LINE__, __FILE__, $sql);
  71. }
  72. if ( !($row = $db->sql_fetchrow($result)) )
  73. {
  74. message_die(GENERAL_MESSAGE, 'No_new_posts_last_visit');
  75. }
  76. $post_id = $row['post_id'];
  77. header($header_location . append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id", true));
  78. exit;
  79. }
  80. }
  81. header($header_location . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id", true));
  82. exit;
  83. }
  84. else if ( $HTTP_GET_VARS['view'] == 'next' || $HTTP_GET_VARS['view'] == 'previous' )
  85. {
  86. $sql_condition = ( $HTTP_GET_VARS['view'] == 'next' ) ? '>' : '<';
  87. $sql_ordering = ( $HTTP_GET_VARS['view'] == 'next' ) ? 'ASC' : 'DESC';
  88. $sql = "SELECT t.topic_id
  89. FROM " . TOPICS_TABLE . " t, " . TOPICS_TABLE . " t2, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2
  90. WHERE t2.topic_id = $topic_id
  91. AND p2.post_id = t2.topic_last_post_id
  92. AND t.forum_id = t2.forum_id
  93. AND p.post_id = t.topic_last_post_id
  94. AND p.post_time $sql_condition p2.post_time
  95. AND p.topic_id = t.topic_id
  96. ORDER BY p.post_time $sql_ordering
  97. LIMIT 1";
  98. if ( !($result = $db->sql_query($sql)) )
  99. {
  100. message_die(GENERAL_ERROR, "Could not obtain newer/older topic information", '', __LINE__, __FILE__, $sql);
  101. }
  102. if ( $row = $db->sql_fetchrow($result) )
  103. {
  104. $topic_id = $row['topic_id'];
  105. }
  106. else
  107. {
  108. $message = ( $HTTP_GET_VARS['view'] == 'next' ) ? 'No_newer_topics' : 'No_older_topics';
  109. message_die(GENERAL_MESSAGE, $message);
  110. }
  111. }
  112. }
  113. //
  114. // This rather complex gaggle of code handles querying for topics but
  115. // also allows for direct linking to a post (and the calculation of which
  116. // page the post is on and the correct display of viewtopic)
  117. //
  118. $join_sql_table = ( !isset($post_id) ) ? '' : ", " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2 ";
  119. $join_sql = ( !isset($post_id) ) ? "t.topic_id = $topic_id" : "p.post_id = $post_id AND t.topic_id = p.topic_id AND p2.topic_id = p.topic_id AND p2.post_id <= $post_id";
  120. $count_sql = ( !isset($post_id) ) ? '' : ", COUNT(p2.post_id) AS prev_posts";
  121. $order_sql = ( !isset($post_id) ) ? '' : "GROUP BY p.post_id, t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, t.topic_last_post_id, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments ORDER BY p.post_id ASC";
  122. $sql = "SELECT t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, t.topic_last_post_id, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments" . $count_sql . "
  123. FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f" . $join_sql_table . "
  124. WHERE $join_sql
  125. AND f.forum_id = t.forum_id
  126. $order_sql";
  127. if ( !($result = $db->sql_query($sql)) )
  128. {
  129. message_die(GENERAL_ERROR, "Could not obtain topic information", '', __LINE__, __FILE__, $sql);
  130. }
  131. if ( !($forum_topic_data = $db->sql_fetchrow($result)) )
  132. {
  133. message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
  134. }
  135. $forum_id = $forum_topic_data['forum_id'];
  136. //
  137. // Start session management
  138. //
  139. $userdata = session_pagestart($user_ip, $forum_id);
  140. init_userprefs($userdata);
  141. //
  142. // End session management
  143. //
  144. //
  145. // Start auth check
  146. //
  147. $is_auth = array();
  148. $is_auth = auth(AUTH_ALL, $forum_id, $userdata, $forum_topic_data);
  149. if( !$is_auth['auth_view'] || !$is_auth['auth_read'] )
  150. {
  151. if ( !$userdata['session_logged_in'] )
  152. {
  153. $redirect = ( isset($post_id) ) ? POST_POST_URL . "=$post_id" : POST_TOPIC_URL . "=$topic_id";
  154. $redirect .= ( isset($start) ) ? "&start=$start" : '';
  155. $header_location = ( @preg_match("/Microsoft|WebSTAR|Xitami/", getenv("SERVER_SOFTWARE")) ) ? "Refresh: 0; URL=" : "Location: ";
  156. header($header_location . append_sid("login.$phpEx?redirect=viewtopic.$phpEx&$redirect", true));
  157. exit;
  158. }
  159. $message = ( !$is_auth['auth_view'] ) ? $lang['Topic_post_not_exist'] : sprintf($lang['Sorry_auth_read'], $is_auth['auth_read_type']);
  160. message_die(GENERAL_MESSAGE, $message);
  161. }
  162. //
  163. // End auth check
  164. //
  165. $forum_name = $forum_topic_data['forum_name'];
  166. $topic_title = $forum_topic_data['topic_title'];
  167. $topic_id = $forum_topic_data['topic_id'];
  168. $topic_time = $forum_topic_data['topic_time'];
  169. if ( !empty($post_id) )
  170. {
  171. $start = floor(($forum_topic_data['prev_posts'] - 1) / $board_config['posts_per_page']) * $board_config['posts_per_page'];
  172. }
  173. //
  174. // Is user watching this thread?
  175. //
  176. if( $userdata['session_logged_in'] )
  177. {
  178. $can_watch_topic = TRUE;
  179. $sql = "SELECT notify_status
  180. FROM " . TOPICS_WATCH_TABLE . "
  181. WHERE topic_id = $topic_id
  182. AND user_id = " . $userdata['user_id'];
  183. if ( !($result = $db->sql_query($sql)) )
  184. {
  185. message_die(GENERAL_ERROR, "Could not obtain topic watch information", '', __LINE__, __FILE__, $sql);
  186. }
  187. if ( $row = $db->sql_fetchrow($result) )
  188. {
  189. if ( isset($HTTP_GET_VARS['unwatch']) )
  190. {
  191. if ( $HTTP_GET_VARS['unwatch'] == 'topic' )
  192. {
  193. $is_watching_topic = 0;
  194. $sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
  195. $sql = "DELETE $sql_priority FROM " . TOPICS_WATCH_TABLE . "
  196. WHERE topic_id = $topic_id
  197. AND user_id = " . $userdata['user_id'];
  198. if ( !($result = $db->sql_query($sql)) )
  199. {
  200. message_die(GENERAL_ERROR, "Could not delete topic watch information", '', __LINE__, __FILE__, $sql);
  201. }
  202. }
  203. $template->assign_vars(array(
  204. 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">')
  205. );
  206. $message = $lang['No_longer_watching'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">', '</a>');
  207. message_die(GENERAL_MESSAGE, $message);
  208. }
  209. else
  210. {
  211. $is_watching_topic = TRUE;
  212. if ( $row['notify_status'] )
  213. {
  214. $sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
  215. $sql = "UPDATE $sql_priority " . TOPICS_WATCH_TABLE . "
  216. SET notify_status = 0
  217. WHERE topic_id = $topic_id
  218. AND user_id = " . $userdata['user_id'];
  219. if ( !($result = $db->sql_query($sql)) )
  220. {
  221. message_die(GENERAL_ERROR, "Could not update topic watch information", '', __LINE__, __FILE__, $sql);
  222. }
  223. }
  224. }
  225. }
  226. else
  227. {
  228. if ( isset($HTTP_GET_VARS['watch']) )
  229. {
  230. if ( $HTTP_GET_VARS['watch'] == 'topic' )
  231. {
  232. $is_watching_topic = TRUE;
  233. $sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
  234. $sql = "INSERT $sql_priority INTO " . TOPICS_WATCH_TABLE . " (user_id, topic_id, notify_status)
  235. VALUES (" . $userdata['user_id'] . ", $topic_id, 0)";
  236. if ( !($result = $db->sql_query($sql)) )
  237. {
  238. message_die(GENERAL_ERROR, "Could not insert topic watch information", '', __LINE__, __FILE__, $sql);
  239. }
  240. }
  241. $template->assign_vars(array(
  242. 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">')
  243. );
  244. $message = $lang['You_are_watching'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start") . '">', '</a>');
  245. message_die(GENERAL_MESSAGE, $message);
  246. }
  247. else
  248. {
  249. $is_watching_topic = 0;
  250. }
  251. }
  252. }
  253. else
  254. {
  255. if ( isset($HTTP_GET_VARS['unwatch']) )
  256. {
  257. if ( $HTTP_GET_VARS['unwatch'] == 'topic' )
  258. {
  259. $header_location = ( @preg_match("/Microsoft|WebSTAR|Xitami/", getenv("SERVER_SOFTWARE")) ) ? "Refresh: 0; URL=" : "Location: ";
  260. header($header_location . append_sid("login.$phpEx?redirect=viewtopic.$phpEx&" . POST_TOPIC_URL . "=$topic_id&unwatch=topic", true));
  261. exit;
  262. }
  263. }
  264. else
  265. {
  266. $can_watch_topic = 0;
  267. $is_watching_topic = 0;
  268. }
  269. }
  270. //
  271. // Generate a 'Show posts in previous x days' select box. If the postdays var is POSTed
  272. // then get it's value, find the number of topics with dates newer than it (to properly
  273. // handle pagination) and alter the main query
  274. //
  275. $previous_days = array(0, 1, 7, 14, 30, 90, 180, 364);
  276. $previous_days_text = array($lang['All_Posts'], $lang['1_Day'], $lang['7_Days'], $lang['2_Weeks'], $lang['1_Month'], $lang['3_Months'], $lang['6_Months'], $lang['1_Year']);
  277. if( !empty($HTTP_POST_VARS['postdays']) || !empty($HTTP_GET_VARS['postdays']) )
  278. {
  279. $post_days = ( !empty($HTTP_POST_VARS['postdays']) ) ? $HTTP_POST_VARS['postdays'] : $HTTP_GET_VARS['postdays'];
  280. $min_post_time = time() - ($post_days * 86400);
  281. $sql = "SELECT COUNT(p.post_id) AS num_posts
  282. FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
  283. WHERE t.topic_id = $topic_id
  284. AND p.topic_id = t.topic_id
  285. AND p.post_time >= $min_post_time";
  286. if ( !($result = $db->sql_query($sql)) )
  287. {
  288. message_die(GENERAL_ERROR, "Could not obtain limited topics count information", '', __LINE__, __FILE__, $sql);
  289. }
  290. $total_replies = ( $row = $db->sql_fetchrow($result) ) ? $row['num_posts'] : 0;
  291. $limit_posts_time = "AND p.post_time >= $min_post_time ";
  292. if ( !empty($HTTP_POST_VARS['postdays']))
  293. {
  294. $start = 0;
  295. }
  296. }
  297. else
  298. {
  299. $total_replies = $forum_topic_data['topic_replies'] + 1;
  300. $limit_posts_time = '';
  301. $post_days = 0;
  302. }
  303. $select_post_days = '<select name="postdays">';
  304. for($i = 0; $i < count($previous_days); $i++)
  305. {
  306. $selected = ($post_days == $previous_days[$i]) ? ' selected="selected"' : '';
  307. $select_post_days .= '<option value="' . $previous_days[$i] . '"' . $selected . '>' . $previous_days_text[$i] . '</option>';
  308. }
  309. $select_post_days .= '</select>';
  310. //
  311. // Decide how to order the post display
  312. //
  313. if ( !empty($HTTP_POST_VARS['postorder']) || !empty($HTTP_GET_VARS['postorder']) )
  314. {
  315. $post_order = (!empty($HTTP_POST_VARS['postorder'])) ? $HTTP_POST_VARS['postorder'] : $HTTP_GET_VARS['postorder'];
  316. $post_time_order = ($post_order == "asc") ? "ASC" : "DESC";
  317. }
  318. else
  319. {
  320. $post_order = 'asc';
  321. $post_time_order = 'ASC';
  322. }
  323. $select_post_order = '<select name="postorder">';
  324. if ( $post_time_order == 'ASC' )
  325. {
  326. $select_post_order .= '<option value="asc" selected="selected">' . $lang['Oldest_First'] . '</option><option value="desc">' . $lang['Newest_First'] . '</option>';
  327. }
  328. else
  329. {
  330. $select_post_order .= '<option value="asc">' . $lang['Oldest_First'] . '</option><option value="desc" selected="selected">' . $lang['Newest_First'] . '</option>';
  331. }
  332. $select_post_order .= '</select>';
  333. //
  334. // Go ahead and pull all data for this topic
  335. //
  336. $sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, p.*, pt.post_text, pt.post_subject, pt.bbcode_uid
  337. FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt
  338. WHERE p.topic_id = $topic_id
  339. $limit_posts_time
  340. AND pt.post_id = p.post_id
  341. AND u.user_id = p.poster_id
  342. ORDER BY p.post_time $post_time_order
  343. LIMIT $start, ".$board_config['posts_per_page'];
  344. if ( !($result = $db->sql_query($sql)) )
  345. {
  346. message_die(GENERAL_ERROR, "Could not obtain post/user information.", '', __LINE__, __FILE__, $sql);
  347. }
  348. if ( $row = $db->sql_fetchrow($result) )
  349. {
  350. $postrow = array();
  351. do
  352. {
  353. $postrow[] = $row;
  354. }
  355. while ( $row = $db->sql_fetchrow($result) );
  356. $db->sql_freeresult($result);
  357. $total_posts = count($postrow);
  358. }
  359. else
  360. {
  361. message_die(GENERAL_MESSAGE, $lang['No_posts_topic']);
  362. }
  363. $sql = "SELECT *
  364. FROM " . RANKS_TABLE . "
  365. ORDER BY rank_special, rank_min";
  366. if ( !($result = $db->sql_query($sql)) )
  367. {
  368. message_die(GENERAL_ERROR, "Could not obtain ranks information.", '', __LINE__, __FILE__, $sql);
  369. }
  370. $ranksrow = array();
  371. while ( $row = $db->sql_fetchrow($result) )
  372. {
  373. $ranksrow[] = $row;
  374. }
  375. $db->sql_freeresult($result);
  376. //
  377. // Define censored word matches
  378. //
  379. $orig_word = array();
  380. $replacement_word = array();
  381. obtain_word_list($orig_word, $replacement_word);
  382. //
  383. // Censor topic title
  384. //
  385. if ( count($orig_word) )
  386. {
  387. $topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
  388. }
  389. //
  390. // Was a highlight request part of the URI? Yes, this idea was
  391. // taken from vB but we did already have a highlighter in place
  392. // in search itself ... it's just been extended a bit!
  393. //
  394. if ( isset($HTTP_GET_VARS['highlight']) )
  395. {
  396. $highlight_match = array();
  397. //
  398. // Split words and phrases
  399. //
  400. $words = explode(' ', trim(urldecode($HTTP_GET_VARS['highlight'])));
  401. for($i = 0; $i < count($words); $i++)
  402. {
  403. if ( trim($words[$i]) != '' )
  404. {
  405. $highlight_match[] = '#\b(' . str_replace("*", "([\w]+)?", $words[$i]) . ')\b#is';
  406. }
  407. }
  408. $highlight_active = ( count($highlight_match) ) ? true : false;
  409. }
  410. else
  411. {
  412. $highlight_active = false;
  413. }
  414. //
  415. // Post, reply and other URL generation for
  416. // templating vars
  417. //
  418. $new_topic_url = append_sid("posting.$phpEx?mode=newtopic&amp;" . POST_FORUM_URL . "=$forum_id");
  419. $reply_topic_url = append_sid("posting.$phpEx?mode=reply&amp;" . POST_TOPIC_URL . "=$topic_id");
  420. $view_forum_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id");
  421. $view_prev_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;view=previous");
  422. $view_next_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;view=next");
  423. //
  424. // Mozilla navigation bar
  425. //
  426. $nav_links['prev'] = array(
  427. 'url' => $view_prev_topic_url,
  428. 'title' => $lang['View_previous_topic']
  429. );
  430. $nav_links['next'] = array(
  431. 'url' => $view_next_topic_url,
  432. 'title' => $lang['View_next_topic']
  433. );
  434. $nav_links['up'] = array(
  435. 'url' => $view_forum_url,
  436. 'title' => $forum_name
  437. );
  438. $reply_img = ( $forum_topic_data['forum_status'] == FORUM_LOCKED || $forum_topic_data['topic_status'] == TOPIC_LOCKED ) ? $images['reply_locked'] : $images['reply_new'];
  439. $reply_alt = ( $forum_topic_data['forum_status'] == FORUM_LOCKED || $forum_topic_data['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['Reply_to_topic'];
  440. $post_img = ( $forum_topic_data['forum_status'] == FORUM_LOCKED ) ? $images['post_locked'] : $images['post_new'];
  441. $post_alt = ( $forum_topic_data['forum_status'] == FORUM_LOCKED ) ? $lang['Forum_locked'] : $lang['Post_new_topic'];
  442. //
  443. // Set a cookie for this topic
  444. //
  445. if ( $userdata['session_logged_in'] )
  446. {
  447. $tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();
  448. $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();
  449. if ( !empty($tracking_topics[$topic_id]) && !empty($tracking_forums[$forum_id]) )
  450. {
  451. $topic_last_read = ( $tracking_topics[$topic_id] > $tracking_forums[$forum_id] ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
  452. }
  453. else if ( !empty($tracking_topics[$topic_id]) || !empty($tracking_forums[$forum_id]) )
  454. {
  455. $topic_last_read = ( !empty($tracking_topics[$topic_id]) ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
  456. }
  457. else
  458. {
  459. $topic_last_read = $userdata['user_lastvisit'];
  460. }
  461. if ( count($tracking_topics) >= 150 && empty($tracking_topics[$topic_id]) )
  462. {
  463. asort($tracking_topics);
  464. unset($tracking_topics[key($tracking_topics)]);
  465. }
  466. $tracking_topics[$topic_id] = time();
  467. setcookie($board_config['cookie_name'] . '_t', serialize($tracking_topics), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
  468. }
  469. //
  470. // Load templates
  471. //
  472. $template->set_filenames(array(
  473. 'body' => 'viewtopic_body.tpl')
  474. );
  475. make_jumpbox('viewforum.'.$phpEx, $forum_id);
  476. //
  477. // Output page header
  478. //
  479. $page_title = $lang['View_topic'] .' - ' . $topic_title;
  480. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  481. //
  482. // User authorisation levels output
  483. //
  484. $s_auth_can = ( ( $is_auth['auth_post'] ) ? $lang['Rules_post_can'] : $lang['Rules_post_cannot'] ) . '<br />';
  485. $s_auth_can .= ( ( $is_auth['auth_reply'] ) ? $lang['Rules_reply_can'] : $lang['Rules_reply_cannot'] ) . '<br />';
  486. $s_auth_can .= ( ( $is_auth['auth_edit'] ) ? $lang['Rules_edit_can'] : $lang['Rules_edit_cannot'] ) . '<br />';
  487. $s_auth_can .= ( ( $is_auth['auth_delete'] ) ? $lang['Rules_delete_can'] : $lang['Rules_delete_cannot'] ) . '<br />';
  488. $s_auth_can .= ( ( $is_auth['auth_vote'] ) ? $lang['Rules_vote_can'] : $lang['Rules_vote_cannot'] ) . '<br />';
  489. $topic_mod = '';
  490. if ( $is_auth['auth_mod'] )
  491. {
  492. $s_auth_can .= sprintf($lang['Rules_moderate'], '<a href="' . append_sid("modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a>');
  493. $topic_mod .= '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=delete") . '"><img src="' . $images['topic_mod_delete'] . '" alt="' . $lang['Delete_topic'] . '" title="' . $lang['Delete_topic'] . '" border="0" /></a>&nbsp;';
  494. $topic_mod .= '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=move"). '"><img src="' . $images['topic_mod_move'] . '" alt="' . $lang['Move_topic'] . '" title="' . $lang['Move_topic'] . '" border="0" /></a>&nbsp;';
  495. $topic_mod .= ( $forum_topic_data['topic_status'] == TOPIC_UNLOCKED ) ? '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=lock") . '"><img src="' . $images['topic_mod_lock'] . '" alt="' . $lang['Lock_topic'] . '" title="' . $lang['Lock_topic'] . '" border="0" /></a>&nbsp;' : '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=unlock") . '"><img src="' . $images['topic_mod_unlock'] . '" alt="' . $lang['Unlock_topic'] . '" title="' . $lang['Unlock_topic'] . '" border="0" /></a>&nbsp;';
  496. $topic_mod .= '<a href="' . append_sid("modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;mode=split") . '"><img src="' . $images['topic_mod_split'] . '" alt="' . $lang['Split_topic'] . '" title="' . $lang['Split_topic'] . '" border="0" /></a>&nbsp;';
  497. }
  498. //
  499. // Topic watch information
  500. //
  501. $s_watching_topic = '';
  502. if ( $can_watch_topic )
  503. {
  504. if ( $is_watching_topic )
  505. {
  506. $s_watching_topic = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;unwatch=topic&amp;start=$start") . '">' . $lang['Stop_watching_topic'] . '</a>';
  507. $s_watching_topic_img = ( isset($images['Topic_un_watch']) ) ? '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;unwatch=topic&amp;start=$start") . '"><img src="' . $images['Topic_un_watch'] . '" alt="' . $lang['Stop_watching_topic'] . '" title="' . $lang['Stop_watching_topic'] . '" border="0"></a>' : '';
  508. }
  509. else
  510. {
  511. $s_watching_topic = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;watch=topic&amp;start=$start") . '">' . $lang['Start_watching_topic'] . '</a>';
  512. $s_watching_topic_img = ( isset($images['Topic_watch']) ) ? '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;watch=topic&amp;start=$start") . '"><img src="' . $images['Topic_watch'] . '" alt="' . $lang['Stop_watching_topic'] . '" title="' . $lang['Start_watching_topic'] . '" border="0"></a>' : '';
  513. }
  514. }
  515. //
  516. // If we've got a hightlight set pass it on to pagination,
  517. // I get annoyed when I lose my highlight after the first page.
  518. //
  519. $pagination = ( $highlight_active ) ? generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;postdays=$post_days&amp;postorder=$post_order&amp;highlight=" . $HTTP_GET_VARS['highlight'], $total_replies, $board_config['posts_per_page'], $start) : generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;postdays=$post_days&amp;postorder=$post_order", $total_replies, $board_config['posts_per_page'], $start);
  520. //
  521. // Send vars to template
  522. //
  523. $template->assign_vars(array(
  524. 'FORUM_ID' => $forum_id,
  525. 'FORUM_NAME' => $forum_name,
  526. 'TOPIC_ID' => $topic_id,
  527. 'TOPIC_TITLE' => $topic_title,
  528. 'PAGINATION' => $pagination,
  529. 'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['posts_per_page'] ) + 1 ), ceil( $total_replies / $board_config['posts_per_page'] )),
  530. 'POST_IMG' => $post_img,
  531. 'REPLY_IMG' => $reply_img,
  532. 'L_AUTHOR' => $lang['Author'],
  533. 'L_MESSAGE' => $lang['Message'],
  534. 'L_POSTED' => $lang['Posted'],
  535. 'L_POST_SUBJECT' => $lang['Post_subject'],
  536. 'L_VIEW_NEXT_TOPIC' => $lang['View_next_topic'],
  537. 'L_VIEW_PREVIOUS_TOPIC' => $lang['View_previous_topic'],
  538. 'L_POST_NEW_TOPIC' => $post_alt,
  539. 'L_POST_REPLY_TOPIC' => $reply_alt,
  540. 'L_BACK_TO_TOP' => $lang['Back_to_top'],
  541. 'L_DISPLAY_POSTS' => $lang['Display_posts'],
  542. 'L_LOCK_TOPIC' => $lang['Lock_topic'],
  543. 'L_UNLOCK_TOPIC' => $lang['Unlock_topic'],
  544. 'L_MOVE_TOPIC' => $lang['Move_topic'],
  545. 'L_SPLIT_TOPIC' => $lang['Split_topic'],
  546. 'L_DELETE_TOPIC' => $lang['Delete_topic'],
  547. 'L_GOTO_PAGE' => $lang['Goto_page'],
  548. 'S_TOPIC_LINK' => POST_TOPIC_URL,
  549. 'S_SELECT_POST_DAYS' => $select_post_days,
  550. 'S_SELECT_POST_ORDER' => $select_post_order,
  551. 'S_POST_DAYS_ACTION' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $topic_id . "&amp;start=$start"),
  552. 'S_AUTH_LIST' => $s_auth_can,
  553. 'S_TOPIC_ADMIN' => $topic_mod,
  554. 'S_WATCH_TOPIC' => $s_watching_topic,
  555. 'U_VIEW_TOPIC' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start&amp;postdays=$post_days&amp;postorder=$post_order&amp;highlight=" . $HTTP_GET_VARS['highlight']),
  556. 'U_VIEW_FORUM' => $view_forum_url,
  557. 'U_VIEW_OLDER_TOPIC' => $view_prev_topic_url,
  558. 'U_VIEW_NEWER_TOPIC' => $view_next_topic_url,
  559. 'U_POST_NEW_TOPIC' => $new_topic_url,
  560. 'U_POST_REPLY_TOPIC' => $reply_topic_url)
  561. );
  562. //
  563. // Does this topic contain a poll?
  564. //
  565. if ( !empty($forum_topic_data['topic_vote']) )
  566. {
  567. $sql = "SELECT vd.vote_id, vd.vote_text, vd.vote_start, vd.vote_length, vr.vote_option_id, vr.vote_option_text, vr.vote_result
  568. FROM " . VOTE_DESC_TABLE . " vd, " . VOTE_RESULTS_TABLE . " vr
  569. WHERE vd.topic_id = $topic_id
  570. AND vr.vote_id = vd.vote_id
  571. ORDER BY vr.vote_option_id ASC";
  572. if ( !($result = $db->sql_query($sql)) )
  573. {
  574. message_die(GENERAL_ERROR, "Could not obtain vote data for this topic", '', __LINE__, __FILE__, $sql);
  575. }
  576. if ( $vote_info = $db->sql_fetchrowset($result) )
  577. {
  578. $db->sql_freeresult($result);
  579. $vote_options = count($vote_info);
  580. $vote_id = $vote_info[0]['vote_id'];
  581. $vote_title = $vote_info[0]['vote_text'];
  582. $sql = "SELECT vote_id
  583. FROM " . VOTE_USERS_TABLE . "
  584. WHERE vote_id = $vote_id
  585. AND vote_user_id = " . $userdata['user_id'];
  586. if ( !($result = $db->sql_query($sql)) )
  587. {
  588. message_die(GENERAL_ERROR, "Could not obtain user vote data for this topic", '', __LINE__, __FILE__, $sql);
  589. }
  590. $user_voted = ( $row = $db->sql_fetchrow($result) ) ? TRUE : 0;
  591. $db->sql_freeresult($result);
  592. if ( isset($HTTP_GET_VARS['vote']) || isset($HTTP_POST_VARS['vote']) )
  593. {
  594. $view_result = ( ( ( isset($HTTP_GET_VARS['vote']) ) ? $HTTP_GET_VARS['vote'] : $HTTP_POST_VARS['vote'] ) == 'viewresult' ) ? TRUE : 0;
  595. }
  596. else
  597. {
  598. $view_result = 0;
  599. }
  600. $poll_expired = ( $vote_info[0]['vote_length'] ) ? ( ( $vote_info[0]['vote_start'] + $vote_info[0]['vote_length'] < time() ) ? TRUE : 0 ) : 0;
  601. if ( $user_voted || $view_result || $poll_expired || !$is_auth['auth_vote'] || $forum_topic_data['topic_status'] == TOPIC_LOCKED )
  602. {
  603. $template->set_filenames(array(
  604. 'pollbox' => 'viewtopic_poll_result.tpl')
  605. );
  606. $vote_results_sum = 0;
  607. for($i = 0; $i < $vote_options; $i++)
  608. {
  609. $vote_results_sum += $vote_info[$i]['vote_result'];
  610. }
  611. $vote_graphic = 0;
  612. $vote_graphic_max = count($images['voting_graphic']);
  613. for($i = 0; $i < $vote_options; $i++)
  614. {
  615. $vote_percent = ( $vote_results_sum > 0 ) ? $vote_info[$i]['vote_result'] / $vote_results_sum : 0;
  616. $vote_graphic_length = round($vote_percent * $board_config['vote_graphic_length']);
  617. $vote_graphic_img = $images['voting_graphic'][$vote_graphic];
  618. $vote_graphic = ($vote_graphic < $vote_graphic_max - 1) ? $vote_graphic + 1 : 0;
  619. if ( count($orig_word) )
  620. {
  621. $vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
  622. }
  623. $template->assign_block_vars("poll_option", array(
  624. 'POLL_OPTION_CAPTION' => $vote_info[$i]['vote_option_text'],
  625. 'POLL_OPTION_RESULT' => $vote_info[$i]['vote_result'],
  626. 'POLL_OPTION_PERCENT' => sprintf("%.1d%%", ($vote_percent * 100)),
  627. 'POLL_OPTION_IMG' => $vote_graphic_img,
  628. 'POLL_OPTION_IMG_WIDTH' => $vote_graphic_length)
  629. );
  630. }
  631. $template->assign_vars(array(
  632. 'L_TOTAL_VOTES' => $lang['Total_votes'],
  633. 'TOTAL_VOTES' => $vote_results_sum)
  634. );
  635. }
  636. else
  637. {
  638. $template->set_filenames(array(
  639. 'pollbox' => 'viewtopic_poll_ballot.tpl')
  640. );
  641. for($i = 0; $i < $vote_options; $i++)
  642. {
  643. if ( count($orig_word) )
  644. {
  645. $vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
  646. }
  647. $template->assign_block_vars("poll_option", array(
  648. 'POLL_OPTION_ID' => $vote_info[$i]['vote_option_id'],
  649. 'POLL_OPTION_CAPTION' => $vote_info[$i]['vote_option_text'])
  650. );
  651. }
  652. $template->assign_vars(array(
  653. 'L_SUBMIT_VOTE' => $lang['Submit_vote'],
  654. 'L_VIEW_RESULTS' => $lang['View_results'],
  655. 'U_VIEW_RESULTS' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;postdays=$post_days&amp;postorder=$post_order&amp;vote=viewresult"))
  656. );
  657. $s_hidden_fields = '<input type="hidden" name="topic_id" value="' . $topic_id . '"><input type="hidden" name="mode" value="vote">';
  658. }
  659. if ( count($orig_word) )
  660. {
  661. $vote_title = preg_replace($orig_word, $replacement_word, $vote_title);
  662. }
  663. $template->assign_vars(array(
  664. 'POLL_QUESTION' => $vote_title,
  665. 'S_HIDDEN_FIELDS' => ( !empty($s_hidden_fields) ) ? $s_hidden_fields : '',
  666. 'S_POLL_ACTION' => append_sid("posting.$phpEx?" . POST_TOPIC_URL . "=$topic_id"))
  667. );
  668. $template->assign_var_from_handle('POLL_DISPLAY', 'pollbox');
  669. }
  670. }
  671. //
  672. // Update the topic view counter
  673. //
  674. $sql = "UPDATE " . TOPICS_TABLE . "
  675. SET topic_views = topic_views + 1
  676. WHERE topic_id = $topic_id";
  677. if ( !$db->sql_query($sql) )
  678. {
  679. message_die(GENERAL_ERROR, "Could not update topic views.", '', __LINE__, __FILE__, $sql);
  680. }
  681. //
  682. // Okay, let's do the loop, yeah come on baby let's do the loop
  683. // and it goes like this ...
  684. //
  685. for($i = 0; $i < $total_posts; $i++)
  686. {
  687. $poster_id = $postrow[$i]['user_id'];
  688. $poster = ( $poster_id == ANONYMOUS ) ? $lang['Guest'] : $postrow[$i]['username'];
  689. $post_date = create_date($board_config['default_dateformat'], $postrow[$i]['post_time'], $board_config['board_timezone']);
  690. $poster_posts = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Posts'] . ': ' . $postrow[$i]['user_posts'] : '';
  691. $poster_from = ( $postrow[$i]['user_from'] && $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Location'] . ': ' . $postrow[$i]['user_from'] : '';
  692. $poster_joined = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Joined'] . ': ' . create_date($lang['DATE_FORMAT'], $postrow[$i]['user_regdate'], $board_config['board_timezone']) : '';
  693. $poster_avatar = '';
  694. if ( $postrow[$i]['user_avatar_type'] && $poster_id != ANONYMOUS && $postrow[$i]['user_allowavatar'] )
  695. {
  696. switch( $postrow[$i]['user_avatar_type'] )
  697. {
  698. case USER_AVATAR_UPLOAD:
  699. $poster_avatar = ( $board_config['allow_avatar_upload'] ) ? '<img src="' . $board_config['avatar_path'] . '/' . $postrow[$i]['user_avatar'] . '" alt="" border="0" />' : '';
  700. break;
  701. case USER_AVATAR_REMOTE:
  702. $poster_avatar = ( $board_config['allow_avatar_remote'] ) ? '<img src="' . $postrow[$i]['user_avatar'] . '" alt="" border="0" />' : '';
  703. break;
  704. case USER_AVATAR_GALLERY:
  705. $poster_avatar = ( $board_config['allow_avatar_local'] ) ? '<img src="' . $board_config['avatar_gallery_path'] . '/' . $postrow[$i]['user_avatar'] . '" alt="" border="0" />' : '';
  706. break;
  707. }
  708. }
  709. //
  710. // Define the little post icon
  711. //
  712. if ( $userdata['session_logged_in'] && $postrow[$i]['post_time'] > $userdata['user_lastvisit'] && $postrow[$i]['post_time'] > $topic_last_read )
  713. {
  714. $mini_post_img = $images['icon_minipost_new'];
  715. $mini_post_alt = $lang['New_post'];
  716. }
  717. else
  718. {
  719. $mini_post_img = $images['icon_minipost'];
  720. $mini_post_alt = $lang['Post'];
  721. }
  722. $mini_post_url = append_sid("viewtopic.$phpEx?" . POST_POST_URL . '=' . $postrow[$i]['post_id']) . '#' . $postrow[$i]['post_id'];
  723. //
  724. // Generate ranks, set them to empty string initially.
  725. //
  726. $poster_rank = '';
  727. $rank_image = '';
  728. if ( $postrow[$i]['user_id'] == ANONYMOUS )
  729. {
  730. }
  731. else if ( $postrow[$i]['user_rank'] )
  732. {
  733. for($j = 0; $j < count($ranksrow); $j++)
  734. {
  735. if ( $postrow[$i]['user_rank'] == $ranksrow[$j]['rank_id'] && $ranksrow[$j]['rank_special'] )
  736. {
  737. $poster_rank = $ranksrow[$j]['rank_title'];
  738. $rank_image = ( $ranksrow[$j]['rank_image'] ) ? '<img src="' . $ranksrow[$j]['rank_image'] . '" alt="' . $poster_rank . '" title="' . $poster_rank . '" border="0" /><br />' : '';
  739. }
  740. }
  741. }
  742. else
  743. {
  744. for($j = 0; $j < count($ranksrow); $j++)
  745. {
  746. if ( $postrow[$i]['user_posts'] >= $ranksrow[$j]['rank_min'] && !$ranksrow[$j]['rank_special'] )
  747. {
  748. $poster_rank = $ranksrow[$j]['rank_title'];
  749. $rank_image = ( $ranksrow[$j]['rank_image'] ) ? '<img src="' . $ranksrow[$j]['rank_image'] . '" alt="' . $poster_rank . '" title="' . $poster_rank . '" border="0" /><br />' : '';
  750. }
  751. }
  752. }
  753. //
  754. // Handle anon users posting with usernames
  755. //
  756. if ( $poster_id == ANONYMOUS && $postrow[$i]['post_username'] != '' )
  757. {
  758. $poster = $postrow[$i]['post_username'];
  759. $poster_rank = $lang['Guest'];
  760. }
  761. $temp_url = '';
  762. if ( $poster_id != ANONYMOUS )
  763. {
  764. $temp_url = append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=$poster_id");
  765. $profile_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_profile'] . '" alt="' . $lang['Read_profile'] . '" title="' . $lang['Read_profile'] . '" border="0" /></a>';
  766. $profile = '<a href="' . $temp_url . '">' . $lang['Read_profile'] . '</a>';
  767. $temp_url = append_sid("privmsg.$phpEx?mode=post&amp;" . POST_USERS_URL . "=$poster_id");
  768. $pm_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_pm'] . '" alt="' . $lang['Send_private_message'] . '" title="' . $lang['Send_private_message'] . '" border="0" /></a>';
  769. $pm = '<a href="' . $temp_url . '">' . $lang['Send_private_message'] . '</a>';
  770. if ( !empty($postrow[$i]['user_viewemail']) || $is_auth['auth_mod'] )
  771. {
  772. $email_uri = ( $board_config['board_email_form'] ) ? append_sid("profile.$phpEx?mode=email&amp;" . POST_USERS_URL .'=' . $poster_id) : 'mailto:' . $postrow[$i]['user_email'];
  773. $email_img = '<a href="' . $email_uri . '"><img src="' . $images['icon_email'] . '" alt="' . $lang['Send_email'] . '" title="' . $lang['Send_email'] . '" border="0" /></a>';
  774. $email = '<a href="' . $email_uri . '">' . $lang['Send_email'] . '</a>';
  775. }
  776. else
  777. {
  778. $email_img = '';
  779. $email = '';
  780. }
  781. $www_img = ( $postrow[$i]['user_website'] ) ? '<a href="' . $postrow[$i]['user_website'] . '" target="_userwww"><img src="' . $images['icon_www'] . '" alt="' . $lang['Visit_website'] . '" title="' . $lang['Visit_website'] . '" border="0" /></a>' : '';
  782. $www = ( $postrow[$i]['user_website'] ) ? '<a href="' . $postrow[$i]['user_website'] . '" target="_userwww">' . $lang['Visit_website'] . '</a>' : '';
  783. if ( !empty($postrow[$i]['user_icq']) )
  784. {
  785. $icq_status_img = '<a href="http://wwp.icq.com/' . $postrow[$i]['user_icq'] . '#pager"><img src="http://web.icq.com/whitepages/online?icq=' . $postrow[$i]['user_icq'] . '&img=5" width="18" height="18" border="0" /></a>';
  786. $icq_img = '<a href="http://wwp.icq.com/scripts/search.dll?to=' . $postrow[$i]['user_icq'] . '"><img src="' . $images['icon_icq'] . '" alt="' . $lang['ICQ'] . '" title="' . $lang['ICQ'] . '" border="0" /></a>';
  787. $icq = '<a href="http://wwp.icq.com/scripts/search.dll?to=' . $postrow[$i]['user_icq'] . '">' . $lang['ICQ'] . '</a>';
  788. }
  789. else
  790. {
  791. $icq_status_img = '';
  792. $icq_img = '';
  793. $icq = '';
  794. }
  795. $aim_img = ( $postrow[$i]['user_aim'] ) ? '<a href="aim:goim?screenname=' . $postrow[$i]['user_aim'] . '&amp;message=Hello+Are+you+there?"><img src="' . $images['icon_aim'] . '" alt="' . $lang['AIM'] . '" title="' . $lang['AIM'] . '" border="0" /></a>' : '';
  796. $aim = ( $postrow[$i]['user_aim'] ) ? '<a href="aim:goim?screenname=' . $postrow[$i]['user_aim'] . '&amp;message=Hello+Are+you+there?">' . $lang['AIM'] . '</a>' : '';
  797. $temp_url = append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=$poster_id");
  798. $msn_img = ( $postrow[$i]['user_msnm'] ) ? '<a href="' . $temp_url . '"><img src="' . $images['icon_msnm'] . '" alt="' . $lang['MSNM'] . '" title="' . $lang['MSNM'] . '" border="0" /></a>' : '';
  799. $msn = ( $postrow[$i]['user_msnm'] ) ? '<a href="' . $temp_url . '">' . $lang['MSNM'] . '</a>' : '';
  800. $yim_img = ( $postrow[$i]['user_yim'] ) ? '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . $postrow[$i]['user_yim'] . '&amp;.src=pg"><img src="' . $images['icon_yim'] . '" alt="' . $lang['YIM'] . '" title="' . $lang['YIM'] . '" border="0" /></a>' : '';
  801. $yim = ( $postrow[$i]['user_yim'] ) ? '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . $postrow[$i]['user_yim'] . '&amp;.src=pg">' . $lang['YIM'] . '</a>' : '';
  802. }
  803. else
  804. {
  805. $profile_img = '';
  806. $profile = '';
  807. $pm_img = '';
  808. $pm = '';
  809. $email_img = '';
  810. $email = '';
  811. $www_img = '';
  812. $www = '';
  813. $icq_status_img = '';
  814. $icq_img = '';
  815. $icq = '';
  816. $aim_img = '';
  817. $aim = '';
  818. $msn_img = '';
  819. $msn = '';
  820. $yim_img = '';
  821. $yim = '';
  822. }
  823. $temp_url = append_sid("posting.$phpEx?mode=quote&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
  824. $quote_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_quote'] . '" alt="' . $lang['Reply_with_quote'] . '" title="' . $lang['Reply_with_quote'] . '" border="0" /></a>';
  825. $quote = '<a href="' . $temp_url . '">' . $lang['Reply_with_quote'] . '</a>';
  826. $temp_url = append_sid("search.$phpEx?search_author=" . urlencode($postrow[$i]['username']) . "&amp;showresults=posts");
  827. $search_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_search'] . '" alt="' . $lang['Search_user_posts'] . '" title="' . $lang['Search_user_posts'] . '" border="0" /></a>';
  828. $search = '<a href="' . $temp_url . '">' . $lang['Search_user_posts'] . '</a>';
  829. if ( ( $userdata['user_id'] == $poster_id && $is_auth['auth_edit'] ) || $is_auth['auth_mod'] )
  830. {
  831. $temp_url = append_sid("posting.$phpEx?mode=editpost&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
  832. $edit_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_edit'] . '" alt="' . $lang['Edit_delete_post'] . '" title="' . $lang['Edit_delete_post'] . '" border="0" /></a>';
  833. $edit = '<a href="' . $temp_url . '">' . $lang['Edit_delete_post'] . '</a>';
  834. }
  835. else
  836. {
  837. $edit_img = '';
  838. $edit = '';
  839. }
  840. if ( $is_auth['auth_mod'] )
  841. {
  842. $temp_url = append_sid("modcp.$phpEx?mode=ip&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id'] . "&amp;" . POST_TOPIC_URL . "=" . $topic_id);
  843. $ip_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_ip'] . '" alt="' . $lang['View_IP'] . '" title="' . $lang['View_IP'] . '" border="0" /></a>';
  844. $ip = '<a href="' . $temp_url . '">' . $lang['View_IP'] . '</a>';
  845. $temp_url = append_sid("posting.$phpEx?mode=delete&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
  846. $delpost_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_delpost'] . '" alt="' . $lang['Delete_post'] . '" title="' . $lang['Delete_post'] . '" border="0" /></a>';
  847. $delpost = '<a href="' . $temp_url . '">' . $lang['Delete_post'] . '</a>';
  848. }
  849. else
  850. {
  851. $ip_img = '';
  852. $ip = '';
  853. if ( $userdata['user_id'] == $poster_id && $is_auth['auth_delete'] && $forum_topic_data['topic_last_post_id'] == $postrow[$i]['post_id'] )
  854. {
  855. $temp_url = append_sid("posting.$phpEx?mode=delete&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
  856. $delpost_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_delpost'] . '" alt="' . $lang['Delete_post'] . '" title="' . $lang['Delete_post'] . '" border="0" /></a>';
  857. $delpost = '<a href="' . $temp_url . '">' . $lang['Delete_post'] . '</a>';
  858. }
  859. else
  860. {
  861. $delpost_img = '';
  862. $delpost = '';
  863. }
  864. }
  865. $post_subject = ( $postrow[$i]['post_subject'] != '' ) ? $postrow[$i]['post_subject'] : '';
  866. $message = $postrow[$i]['post_text'];
  867. $bbcode_uid = $postrow[$i]['bbcode_uid'];
  868. $user_sig = ( $postrow[$i]['enable_sig'] && $postrow[$i]['user_sig'] != '' && $board_config['allow_sig'] ) ? $postrow[$i]['user_sig'] : '';
  869. $user_sig_bbcode_uid = $postrow[$i]['user_sig_bbcode_uid'];
  870. //
  871. // Note! The order used for parsing the message _is_ important, moving things around could break any
  872. // output
  873. //
  874. //
  875. // If the board has HTML off but the post has HTML
  876. // on then we process it, else leave it alone
  877. //
  878. if ( !$board_config['allow_html'] )
  879. {
  880. if ( $user_sig != '' && $userdata['user_allowhtml'] )
  881. {
  882. $user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $user_sig);
  883. }
  884. if ( $postrow[$i]['enable_html'] )
  885. {
  886. $message = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $message);
  887. }
  888. }
  889. //
  890. // Parse message and/or sig for BBCode if reqd
  891. //
  892. if ( $board_config['allow_bbcode'] )
  893. {
  894. if ( $user_sig != '' && $user_sig_bbcode_uid != '' )
  895. {
  896. $user_sig = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($user_sig, $user_sig_bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $user_sig);
  897. }
  898. if ( $bbcode_uid != '' )
  899. {
  900. $message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $message);
  901. }
  902. }
  903. if ( $user_sig != '' )
  904. {
  905. $user_sig = make_clickable($user_sig);
  906. }
  907. $message = make_clickable($message);
  908. //
  909. // Highlight active words (primarily for search)
  910. //
  911. if ( $highlight_active )
  912. {
  913. if ( preg_match('/<.*>/', $message) )
  914. {
  915. $message = preg_replace($highlight_match, '<!-- #sh -->\1<!-- #eh -->', $message);
  916. $end_html = 0;
  917. $start_html = 1;
  918. $temp_message = '';
  919. $message = ' ' . $message . ' ';
  920. while( $start_html = strpos($message, '<', $start_html) )
  921. {
  922. $grab_length = $start_html - $end_html - 1;
  923. $temp_message .= substr($message, $end_html + 1, $grab_length);
  924. if ( $end_html = strpos($message, '>', $start_html) )
  925. {
  926. $length = $end_html - $start_html + 1;
  927. $hold_string = substr($message, $start_html, $length);
  928. if ( strrpos(' ' . $hold_string, '<') != 1 )
  929. {
  930. $end_html = $start_html + 1;
  931. $end_counter = 1;
  932. while ( $end_counter && $end_html < strlen($message) )
  933. {
  934. if ( substr($message, $end_html, 1) == '>' )
  935. {
  936. $end_counter--;
  937. }
  938. else if ( substr($message, $end_html, 1) == '<' )
  939. {
  940. $end_counter++;
  941. }
  942. $end_html++;
  943. }
  944. $length = $end_html - $start_html + 1;
  945. $hold_string = substr($message, $start_html, $length);
  946. $hold_string = str_replace('<!-- #sh -->', '', $hold_string);
  947. $hold_string = str_replace('<!-- #eh -->', '', $hold_string);
  948. }
  949. else if ( $hold_string == '<!-- #sh -->' )
  950. {
  951. $hold_string = str_replace('<!-- #sh -->', '<span style="color:#' . $theme['fontcolor3'] . '"><b>', $hold_string);
  952. }
  953. else if ( $hold_string == '<!-- #eh -->' )
  954. {
  955. $hold_string = str_replace('<!-- #eh -->', '</b></span>', $hold_string);
  956. }
  957. $temp_message .= $hold_string;
  958. $start_html += $length;
  959. }
  960. else
  961. {
  962. $start_html = strlen($message);
  963. }
  964. }
  965. $grab_length = strlen($message) - $end_html - 1;
  966. $temp_message .= substr($message, $end_html + 1, $grab_length);
  967. $message = trim($temp_message);
  968. }
  969. else
  970. {
  971. $message = preg_replace($highlight_match, '<span style="color:#' . $theme['fontcolor3'] . '"><b>\1</b></span>', $message);
  972. }
  973. }
  974. //
  975. // Replace naughty words
  976. //
  977. if ( count($orig_word) )
  978. {
  979. if ( $user_sig != '' )
  980. {
  981. $user_sig = preg_replace($orig_word, $replacement_word, $user_sig);
  982. }
  983. $post_subject = preg_replace($orig_word, $replacement_word, $post_subject);
  984. $message = preg_replace($orig_word, $replacement_word, $message);
  985. }
  986. //
  987. // Parse smilies
  988. //
  989. if ( $board_config['allow_smilies'] )
  990. {
  991. if ( $postrow[$i]['user_allowsmile'] && $user_sig != '' )
  992. {
  993. $user_sig = smilies_pass($user_sig);
  994. }
  995. if ( $postrow[$i]['enable_smilies'] )
  996. {
  997. $message = smilies_pass($message);
  998. }
  999. }
  1000. //
  1001. // Replace newlines (we use this rather than nl2br because
  1002. // till recently it wasn't XHTML compliant)
  1003. //
  1004. if ( $user_sig != '' )
  1005. {
  1006. $user_sig = '<br />_________________<br />' . str_replace("\n", "\n<br />\n", $user_sig);
  1007. }
  1008. $message = str_replace("\n", "\n<br />\n", $message);
  1009. //
  1010. // Editing information
  1011. //
  1012. if ( $postrow[$i]['post_edit_count'] )
  1013. {
  1014. $l_edit_time_total = ( $postrow[$i]['post_edit_count'] == 1 ) ? $lang['Edited_time_total'] : $lang['Edited_times_total'];
  1015. $l_edited_by = '<br /><br />' . sprintf($l_edit_time_total, $poster, create_date($board_config['default_dateformat'], $postrow[$i]['post_edit_time'], $board_config['board_timezone']), $postrow[$i]['post_edit_count']);
  1016. }
  1017. else
  1018. {
  1019. $l_edited_by = '';
  1020. }
  1021. //
  1022. // Again this will be handled by the templating
  1023. // code at some point
  1024. //
  1025. $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
  1026. $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
  1027. $template->assign_block_vars('postrow', array(
  1028. 'ROW_COLOR' => '#' . $row_color,
  1029. 'ROW_CLASS' => $row_class,
  1030. 'POSTER_NAME' => $poster,
  1031. 'POSTER_RANK' => $poster_rank,
  1032. 'RANK_IMAGE' => $rank_image,
  1033. 'POSTER_JOINED' => $poster_joined,
  1034. 'POSTER_POSTS' => $poster_posts,
  1035. 'POSTER_FROM' => $poster_from,
  1036. 'POSTER_AVATAR' => $poster_avatar,
  1037. 'POST_DATE' => $post_date,
  1038. 'POST_SUBJECT' => $post_subject,
  1039. 'MESSAGE' => $message,
  1040. 'SIGNATURE' => $user_sig,
  1041. 'EDITED_MESSAGE' => $l_edited_by,
  1042. 'MINI_POST_IMG' => $mini_post_img,
  1043. 'PROFILE_IMG' => $profile_img,
  1044. 'PROFILE' => $profile,
  1045. 'SEARCH_IMG' => $search_img,
  1046. 'SEARCH' => $search,
  1047. 'PM_IMG' => $pm_img,
  1048. 'PM' => $pm,
  1049. 'EMAIL_IMG' => $email_img,
  1050. 'EMAIL' => $email,
  1051. 'WWW_IMG' => $www_img,
  1052. 'WWW' => $www,
  1053. 'ICQ_STATUS_IMG' => $icq_status_img,
  1054. 'ICQ_IMG' => $icq_img,
  1055. 'ICQ' => $icq,
  1056. 'AIM_IMG' => $aim_img,
  1057. 'AIM' => $aim,
  1058. 'MSN_IMG' => $msn_img,
  1059. 'MSN' => $msn,
  1060. 'YIM_IMG' => $yim_img,
  1061. 'YIM' => $yim,
  1062. 'EDIT_IMG' => $edit_img,
  1063. 'EDIT' => $edit,
  1064. 'QUOTE_IMG' => $quote_img,
  1065. 'QUOTE' => $quote,
  1066. 'IP_IMG' => $ip_img,
  1067. 'IP' => $ip,
  1068. 'DELETE_IMG' => $delpost_img,
  1069. 'DELETE' => $delpost,
  1070. 'L_MINI_POST_ALT' => $mini_post_alt,
  1071. 'U_MINI_POST' => $mini_post_url,
  1072. 'U_POST_ID' => $postrow[$i]['post_id'])
  1073. );
  1074. }
  1075. $template->pparse('body');
  1076. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  1077. ?>