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

/viewtopic.php

https://github.com/MightyGorgon/icy_phoenix
PHP | 2798 lines | 2348 code | 258 blank | 192 comment | 394 complexity | 009ac20086e3f4db5ca90a7a0f495fa3 MD5 | raw file
Possible License(s): AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. *
  12. * @Icy Phoenix is based on phpBB
  13. * @copyright (c) 2008 phpBB Group
  14. *
  15. */
  16. define('IN_TOPIC', true);
  17. // MG Cash MOD For IP - BEGIN
  18. define('IN_CASHMOD', true);
  19. define('CM_VIEWTOPIC', true);
  20. // MG Cash MOD For IP - END
  21. define('CT_SECLEVEL', 'MEDIUM');
  22. $ct_ignoregvar = array('');
  23. // Added to optimize memory for attachments
  24. define('ATTACH_DISPLAY', true);
  25. define('IN_ICYPHOENIX', true);
  26. if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
  27. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  28. include(IP_ROOT_PATH . 'common.' . PHP_EXT);
  29. include_once(IP_ROOT_PATH . 'includes/bbcode.' . PHP_EXT);
  30. include_once(IP_ROOT_PATH . ATTACH_MOD_PATH . 'includes/functions_delete.' . PHP_EXT);
  31. include_once(IP_ROOT_PATH . 'includes/functions_topics.' . PHP_EXT);
  32. include_once(IP_ROOT_PATH . 'includes/functions_calendar.' . PHP_EXT);
  33. include_once(IP_ROOT_PATH . 'includes/functions_users.' . PHP_EXT);
  34. include_once(IP_ROOT_PATH . 'includes/functions_profile.' . PHP_EXT);
  35. include_once(IP_ROOT_PATH . 'includes/functions_rate.' . PHP_EXT);
  36. // Event Registration - BEGIN
  37. include_once(IP_ROOT_PATH . 'includes/functions_events_reg.' . PHP_EXT);
  38. // Event Registration - END
  39. @include_once(IP_ROOT_PATH . 'includes/class_topics.' . PHP_EXT);
  40. $class_topics = new class_topics();
  41. // Init common vars: forum_id, topic_id, post_id, etc.
  42. $class_topics->var_init(true);
  43. // Start session management
  44. $user->session_begin();
  45. $auth->acl($user->data);
  46. $user->setup();
  47. // End session management
  48. setup_extra_lang(array('lang_rate'));
  49. $start = request_var('start', 0);
  50. $start = ($start < 0) ? 0 : $start;
  51. $page_number = request_var('page_number', 0);
  52. $page_number = ($page_number < 1) ? 0 : $page_number;
  53. $start = (empty($page_number) ? $start : (($page_number * $config['topics_per_page']) - $config['topics_per_page']));
  54. $sort_days_array = array(0, 1, 7, 14, 30, 90, 180, 365);
  55. $sort_days_lang_array = array(0 => $lang['ALL_POSTS'], 1 => $lang['1_DAY'], 7 => $lang['7_DAYS'], 14 => $lang['2_WEEKS'], 30 => $lang['1_MONTH'], 90 => $lang['3_MONTHS'], 180 => $lang['6_MONTHS'], 365 => $lang['1_YEAR']);
  56. $sort_key_array = array('t', 's', 'a');
  57. $sort_key_lang_array = array('t' => $lang['POST_TIME'], 's' => $lang['SUBJECT'], 'a' => $lang['AUTHOR']);
  58. // In Icy Phoenix we still prefer sorting by time instead by ID... it could lead to collateral problems I know...
  59. //$sort_key_sql_array = array('t' => 'p.post_id', 's' => 'p.post_subject', 'a' => 'u.username_clean');
  60. $sort_key_sql_array = array('t' => 'p.post_time', 's' => 'p.post_subject', 'a' => 'u.username_clean');
  61. $sort_dir_array = array('a', 'd');
  62. $sort_dir_lang_array = array('a' => $lang['ASCENDING'], 'd' => $lang['DESCENDING']);
  63. $sort_dir_sql_array = array('a' => 'ASC', 'd' => 'DESC');
  64. $default_sort_days = (!empty($user->data['user_post_show_days'])) ? $user->data['user_post_show_days'] : $sort_days_array[0];
  65. $default_sort_key = (!empty($user->data['user_post_sortby_type'])) ? $user->data['user_post_sortby_type'] : $sort_key_array[0];
  66. $default_sort_dir = (!empty($user->data['user_post_sortby_dir'])) ? $user->data['user_post_sortby_dir'] : $sort_dir_array[0];
  67. $sort_days = request_var('st', $default_sort_days);
  68. $sort_days = check_var_value($sort_days, $sort_days_array);
  69. $sort_key = request_var('sk', $default_sort_key);
  70. $sort_key = check_var_value($sort_key, $sort_key_array);
  71. $sort_key_sql = $sort_key_sql_array[$sort_key];
  72. $sort_dir = strtolower(request_var('sd', $default_sort_dir));
  73. $sort_dir = check_var_value($sort_dir, $sort_dir_array);
  74. $sort_dir_sql = $sort_dir_sql_array[$sort_dir];
  75. // only fetch post higher than a certain post_id. Maybe this should use post_time, as $sort_key_sql_array uses post_time
  76. $after_post_id = request_var('after_post_id', 0);
  77. // make sure we can't fetch negative indices. 0 = disabled
  78. $after_post_id = ($after_post_id < 0) ? 1 : $after_post_id;
  79. // Backward compatibility
  80. if (check_http_var_exists('postorder', true))
  81. {
  82. $sort_dir_array_old = array('asc', 'desc');
  83. $sort_dir = strtolower(request_var('postorder', $sort_dir_array_old[0]));
  84. $sort_dir = check_var_value($sort_dir, $sort_dir_array_old);
  85. $sort_dir = ($sort_dir == 'asc') ? 'a' : 'd';
  86. $sort_dir_sql = $sort_dir_sql_array[$sort_dir];
  87. }
  88. if (check_http_var_exists('postdays', true))
  89. {
  90. $sort_days = request_var('postdays', $default_sort_days);
  91. $sort_days = check_var_value($sort_days, $sort_days_array);
  92. }
  93. $vt_sort_append_array = array();
  94. if ($sort_days != $sort_days_array[0])
  95. {
  96. $vt_sort_append_array['st'] = $sort_days;
  97. }
  98. if ($sort_key != $sort_key_array[0])
  99. {
  100. $vt_sort_append_array['sk'] = $sort_key;
  101. }
  102. if ($sort_dir != $sort_dir_array[0])
  103. {
  104. $vt_sort_append_array['sd'] = $sort_dir;
  105. }
  106. $vt_sort_append = '';
  107. $vt_sort_append_red = '';
  108. if (!empty($vt_sort_append_array))
  109. {
  110. foreach ($vt_sort_append_array as $k => $v)
  111. {
  112. $vt_sort_append = '&amp;' . $k . '=' . $v;
  113. $vt_sort_append_red = '&' . $k . '=' . $v;
  114. }
  115. }
  116. $select_post_array = array('st' => 'sort_days', 'sk' => 'sort_key', 'sd' => 'sort_dir');
  117. $select_post_array_output = array();
  118. foreach ($select_post_array as $s_key => $s_name)
  119. {
  120. $select_post_array_output[$s_key] = '<select name="' . $s_key . '">';
  121. foreach (${$s_name . '_lang_array'} as $k => $v)
  122. {
  123. $selected = (${$s_name} == $k) ? ' selected="selected"' : '';
  124. $select_post_array_output[$s_key] .= '<option value="' . $k . '"' . $selected . '>' . $v . '</option>';
  125. }
  126. $select_post_array_output[$s_key] .= '</select>';
  127. ${'select_' . $s_name} = $select_post_array_output[$s_key];
  128. }
  129. $sid = request_var('sid', '');
  130. // Activity - BEGIN
  131. if (!empty($config['plugins']['activity']['enabled']))
  132. {
  133. include_once(IP_ROOT_PATH . PLUGINS_PATH . $config['plugins']['activity']['dir'] . 'common.' . PHP_EXT);
  134. $q = "SELECT * FROM " . INA_HOF;
  135. $r = $db->sql_query($q);
  136. $hof_data = $db->sql_fetchrowset($r);
  137. $db->sql_freeresult($r);
  138. }
  139. // Activity - END
  140. // Start initial var setup
  141. $kb_mode = false;
  142. $kb_mode_append = '';
  143. $kb_mode_append_red = '';
  144. $kb_mode_var = request_var('kb', '');
  145. if (($kb_mode_var == 'on') && ($user->data['bot_id'] == false))
  146. {
  147. $kb_mode = true;
  148. $kb_mode_append = '&amp;kb=on';
  149. $kb_mode_append_red = '&kb=on';
  150. }
  151. $download = request_get_var('download', '');
  152. if (empty($topic_id) && empty($post_id))
  153. {
  154. if (!defined('STATUS_404')) define('STATUS_404', true);
  155. message_die(GENERAL_MESSAGE, 'NO_TOPIC');
  156. }
  157. // Find topic id if user requested a newer or older topic
  158. $view = request_get_var('view', '');
  159. if (!empty($view) && empty($post_id))
  160. {
  161. if ($view == 'newest')
  162. {
  163. if (isset($_COOKIE[$config['cookie_name'] . '_sid']) || !empty($sid))
  164. {
  165. $session_id = isset($_COOKIE[$config['cookie_name'] . '_sid']) ? $_COOKIE[$config['cookie_name'] . '_sid'] : $sid;
  166. if (!preg_match('/^[A-Za-z0-9]*$/', $session_id))
  167. {
  168. $session_id = '';
  169. }
  170. if ($session_id)
  171. {
  172. $sql = "SELECT p.post_id
  173. FROM " . POSTS_TABLE . " p, " . SESSIONS_TABLE . " s, " . USERS_TABLE . " u
  174. WHERE s.session_id = '" . $db->sql_escape($session_id) . "'
  175. AND u.user_id = s.session_user_id
  176. AND p.topic_id = '" . $topic_id . "'
  177. AND p.post_time >= u.user_lastvisit
  178. ORDER BY p.post_time ASC
  179. LIMIT 1";
  180. $result = $db->sql_query($sql);
  181. /* UPI2DB REPLACE
  182. if (!($row = $db->sql_fetchrow($result)))
  183. {
  184. message_die(GENERAL_MESSAGE, 'No_new_posts_last_visit');
  185. }
  186. */
  187. // UPI2DB - BEGIN
  188. if (!($row = $db->sql_fetchrow($result)))
  189. {
  190. if ($topic_id > 0)
  191. {
  192. redirect(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . $kb_mode_append_red);
  193. }
  194. else
  195. {
  196. message_die(GENERAL_MESSAGE, 'No_new_posts_last_visit');
  197. }
  198. }
  199. // UPI2DB - END
  200. $post_id = $row['post_id'];
  201. $post_id_append = (!empty($post_id) ? (POST_POST_URL . '=' . $post_id) : '');
  202. $post_id_append_url = (!empty($post_id) ? ('#p' . $post_id) : '');
  203. $session_id_append = !empty($sid) ? ('sid=' . $session_id . '&') : '';
  204. redirect(append_sid(CMS_PAGE_VIEWTOPIC . '?' . $session_id_append . $kb_mode_append_red . $forum_id_append . '&' . $topic_id_append . '&' . $post_id_append . $post_id_append_url));
  205. }
  206. }
  207. redirect(append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . $kb_mode_append_red, true));
  208. }
  209. elseif (($view == 'next') || ($view == 'previous'))
  210. {
  211. $sql_condition = ($view == 'next') ? '>' : '<';
  212. $sql_ordering = ($view == 'next') ? 'ASC' : 'DESC';
  213. $sql = "SELECT t.topic_id, t.forum_id
  214. FROM " . TOPICS_TABLE . " t, " . TOPICS_TABLE . " t2
  215. WHERE
  216. t2.topic_id = '" . $topic_id . "'
  217. AND t.forum_id = t2.forum_id
  218. AND t.topic_moved_id = 0
  219. AND t.topic_last_post_id $sql_condition t2.topic_last_post_id
  220. ORDER BY t.topic_last_post_id $sql_ordering
  221. LIMIT 1";
  222. $result = $db->sql_query($sql);
  223. if ($row = $db->sql_fetchrow($result))
  224. {
  225. $forum_id = intval($row['forum_id']);
  226. $forum_id_append = (!empty($forum_id) ? (POST_FORUM_URL . '=' . $forum_id) : '');
  227. $topic_id = intval($row['topic_id']);
  228. $topic_id_append = (!empty($topic_id) ? (POST_TOPIC_URL . '=' . $topic_id) : '');
  229. redirect(append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . $kb_mode_append_red));
  230. }
  231. else
  232. {
  233. $message = ($view == 'next') ? 'No_newer_topics' : 'No_older_topics';
  234. message_die(GENERAL_MESSAGE, $message);
  235. }
  236. }
  237. }
  238. // This rather complex gaggle of code handles querying for topics but also allows for direct linking to a post (and the calculation of which page the post is on and the correct display of viewtopic)
  239. $join_sql_table = (!$post_id ? '' : (", " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2 "));
  240. $join_sql = (!$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));
  241. $count_sql = (!$post_id ? '' : (", COUNT(p2.post_id) AS prev_posts"));
  242. $order_sql = (!$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.poll_start, 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, f.auth_ban, f.auth_greencard, f.auth_bluecard ORDER BY p.post_id ASC"));
  243. // Let's try to query all fields for topics and forums... it should not require too much resources as we are querying only one row
  244. //$sql = "SELECT t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.poll_start, t.topic_last_post_id, t.topic_label_compiled, t.topic_first_post_id, t.topic_calendar_time, t.topic_calendar_duration, t.topic_reg, t.topic_similar_topics, f.forum_name, f.forum_status, f.forum_id, f.forum_similar_topics, f.forum_topic_views, f.forum_kb_mode, 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, f.auth_ban, f.auth_greencard, f.auth_bluecard" . $count_sql . "
  245. $sql = "SELECT t.*, f.*, u.*" . $count_sql . "
  246. FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f," . USERS_TABLE . " u" . $join_sql_table . "
  247. WHERE $join_sql
  248. AND f.forum_id = t.forum_id AND t.topic_poster = u.user_id
  249. $order_sql";
  250. attach_setup_viewtopic_auth($order_sql, $sql);
  251. $result = $db->sql_query($sql);
  252. if (!($forum_topic_data = $db->sql_fetchrow($result)))
  253. {
  254. if (!defined('STATUS_404')) define('STATUS_404', true);
  255. message_die(GENERAL_MESSAGE, 'NO_TOPIC');
  256. }
  257. $db->sql_freeresult($result);
  258. $forum_id = intval($forum_topic_data['forum_id']);
  259. $forum_id_append = (!empty($forum_id) ? (POST_FORUM_URL . '=' . $forum_id) : '');
  260. $topic_id = intval($forum_topic_data['topic_id']);
  261. $topic_id_append = (!empty($topic_id) ? (POST_TOPIC_URL . '=' . $topic_id) : '');
  262. $forum_name = get_object_lang(POST_FORUM_URL . $forum_id, 'name');
  263. $topic_time = $forum_topic_data['topic_time'];
  264. $topic_first_post_id = intval($forum_topic_data['topic_first_post_id']);
  265. $topic_calendar_time = intval($forum_topic_data['topic_calendar_time']);
  266. $topic_calendar_duration = intval($forum_topic_data['topic_calendar_duration']);
  267. $topic_title_data = $class_topics->generate_topic_title($topic_id, $forum_topic_data, 80);
  268. $topic_title = $topic_title_data['title'];
  269. $topic_title_clean = $topic_title_data['title_clean'];
  270. $topic_title_plain = $topic_title_data['title_plain'];
  271. $topic_title_label = $topic_title_data['title_label'];
  272. $topic_title_short = $topic_title_data['title_short'];
  273. // Topic poster information
  274. $topic_started = create_date_ip($lang['DATE_FORMAT_VF'], $forum_topic_data['topic_time'], $config['board_timezone'], true);
  275. $topic_username = colorize_username($forum_topic_data['user_id'], $forum_topic_data['username'], $forum_topic_data['user_color'], $forum_topic_data['user_active']);
  276. $topic_avatar_img = user_get_avatar($forum_topic_data['user_id'], $forum_topic_data['user_level'], $forum_topic_data['user_avatar'], $forum_topic_data['user_avatar_type'], $forum_topic_data['user_allowavatar']);
  277. $topic_user_from_flag = $forum_topic_data['user_from_flag'] ? '<img src="images/flags/' . $forum_topic_data['user_from_flag'] . '" alt="' . $forum_topic_data['user_from_flag'] . '" title="' . $forum_topic_data['user_from'] . '" />' : '';
  278. switch ($forum_topic_data['user_gender'])
  279. {
  280. case 1:
  281. $topic_user_gender_image = '<img src="' . $images['icon_minigender_male'] . '" alt="' . $lang['Gender']. ': ' . $lang['Male'] . '" title="' . $lang['Gender'] . ': ' . $lang['Male'] . '" />';
  282. break;
  283. case 2:
  284. $topic_user_gender_image = '<img src="' . $images['icon_minigender_female'] . '" alt="' . $lang['Gender']. ': ' . $lang['Female'] . '" title="' . $lang['Gender'] . ': ' . $lang['Female'] . '" />';
  285. break;
  286. default:
  287. $topic_user_gender_image = '';
  288. }
  289. $topic_user_joined = create_date($lang['JOINED_DATE_FORMAT'], $forum_topic_data['user_regdate'], $config['board_timezone']);
  290. $topic_user_posts = $forum_topic_data['user_posts'];
  291. $meta_content = array();
  292. $meta_content = $class_topics->meta_content_init($forum_topic_data, 'topic');
  293. $meta_content['post_id'] = (!empty($post_id) && (intval($post_id) > 0)) ? intval($post_id) : 0;
  294. $this_forum_auth_read = intval($forum_topic_data['auth_read']);
  295. if ($forum_topic_data['forum_kb_mode'])
  296. {
  297. if ($kb_mode_var == 'off')
  298. {
  299. $kb_mode = false;
  300. $kb_mode_append = '&amp;kb=off';
  301. $kb_mode_append_red = '&kb=off';
  302. }
  303. else
  304. {
  305. $kb_mode = true;
  306. $kb_mode_append = '&amp;kb=on';
  307. $kb_mode_append_red = '&kb=on';
  308. }
  309. }
  310. // Set or remove bookmark - BEGIN
  311. $setbm = request_var('setbm', '');
  312. $removebm = request_var('removebm', '');
  313. if ((!empty($setbm) || !empty($removebm)) && !$user->data['is_bot'])
  314. {
  315. $redirect = CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . $kb_mode_append_red . '&start=' . $start . $vt_sort_append_red . '&highlight=' . urlencode($_GET['highlight']);
  316. if ($user->data['session_logged_in'])
  317. {
  318. if (!empty($setbm))
  319. {
  320. set_bookmark($topic_id);
  321. }
  322. elseif (!empty($removebm))
  323. {
  324. remove_bookmark($topic_id);
  325. }
  326. }
  327. else
  328. {
  329. if (!empty($setbm))
  330. {
  331. $redirect .= '&setbm=true';
  332. }
  333. elseif (!empty($removebm))
  334. {
  335. $redirect .= '&removebm=true';
  336. }
  337. redirect(append_sid(CMS_PAGE_LOGIN . '?redirect=' . $redirect, true));
  338. }
  339. redirect(append_sid($redirect, true));
  340. }
  341. // Set or remove bookmark - END
  342. $cms_page['page_id'] = 'viewtopic';
  343. // Comment out page_nav because viewtopic has its own breadcrumbs...
  344. //$cms_page['page_nav'] = (!empty($cms_config_layouts[$cms_page['page_id']]['page_nav']) ? true : false);
  345. $cms_page['global_blocks'] = (!empty($cms_config_layouts[$cms_page['page_id']]['global_blocks']) ? true : false);
  346. $cms_auth_level = (isset($cms_config_layouts[$cms_page['page_id']]['view']) ? $cms_config_layouts[$cms_page['page_id']]['view'] : AUTH_ALL);
  347. check_page_auth($cms_page['page_id'], $cms_auth_level);
  348. if ($download)
  349. {
  350. @include(IP_ROOT_PATH . 'includes/topic_download.' . PHP_EXT);
  351. exit;
  352. }
  353. //Begin Lo-Fi Mod
  354. if (!empty($lofi))
  355. {
  356. $lang['Reply_with_quote'] = $lang['quote_lofi'] ;
  357. $lang['Edit_delete_post'] = $lang['edit_lofi'];
  358. $lang['View_IP'] = $lang['ip_lofi'];
  359. $lang['Delete_post'] = $lang['del_lofi'];
  360. $lang['Read_profile'] = $lang['profile_lofi'];
  361. $lang['Send_private_message'] = $lang['pm_lofi'];
  362. $lang['Send_email'] = $lang['email_lofi'];
  363. $lang['Visit_website'] = $lang['website_lofi'];
  364. $lang['ICQ'] = $lang['icq_lofi'];
  365. $lang['AIM'] = $lang['aim_lofi'];
  366. $lang['YIM'] = $lang['yim_lofi'];
  367. $lang['MSNM'] = $lang['msnm_lofi'];
  368. }
  369. //End Lo-Fi Mod
  370. // Force Topic Read - BEGIN
  371. $ftr_disabled = $config['ftr_disable'] ? true : false;
  372. if (!$ftr_disabled)
  373. {
  374. @include(IP_ROOT_PATH . 'includes/topic_ftr.' . PHP_EXT);
  375. }
  376. // Force Topic Read - END
  377. $similar_topics_enabled = false;
  378. if ($config['similar_topics'] && $forum_topic_data['forum_similar_topics'])
  379. {
  380. $similar_topics_enabled = true;
  381. }
  382. if ($similar_topics_enabled)
  383. {
  384. $similar_forums_auth = auth(AUTH_ALL, AUTH_LIST_ALL, $user->data);
  385. $similar_is_auth = $similar_forums_auth[$forum_id];
  386. }
  387. // Start auth check
  388. $is_auth = array();
  389. $is_auth = $tree['auth'][POST_FORUM_URL . $forum_id];
  390. if (!$is_auth['auth_read'])
  391. {
  392. if (!$user->data['session_logged_in'])
  393. {
  394. $redirect = $forum_id_append . '&' . $topic_id_append . $kb_mode_append_red;
  395. $redirect .= ($post_id) ? '&' . $post_id_append : '';
  396. $redirect .= ($start) ? '&start=' . $start : '';
  397. redirect(append_sid(CMS_PAGE_LOGIN . '?redirect=' . CMS_PAGE_VIEWTOPIC . '&' . $redirect, true));
  398. }
  399. $message = sprintf($lang['Sorry_auth_read'], $is_auth['auth_read_type']);
  400. message_die(GENERAL_MESSAGE, $message);
  401. }
  402. // End auth check
  403. // Who viewed a topic - BEGIN
  404. if (!$config['disable_topic_view'] && $forum_topic_data['forum_topic_views'])
  405. {
  406. $user_id = $user->data['user_id'];
  407. $sql = 'UPDATE ' . TOPIC_VIEW_TABLE . ' SET topic_id = "' . $topic_id . '", view_time = "' . time() . '", view_count = view_count + 1 WHERE topic_id=' . $topic_id . ' AND user_id = ' . $user_id;
  408. $db->sql_return_on_error(true);
  409. $result = $db->sql_query($sql);
  410. $db->sql_return_on_error(false);
  411. if (!$result || !$db->sql_affectedrows())
  412. {
  413. $sql = 'INSERT IGNORE INTO ' . TOPIC_VIEW_TABLE . ' (topic_id, user_id, view_time, view_count)
  414. VALUES (' . $topic_id . ', "' . $user_id . '", "' . time() . '", "1")';
  415. $db->sql_query($sql);
  416. }
  417. }
  418. // Who viewed a topic - END
  419. if (!empty($post_id))
  420. {
  421. $start = floor(($forum_topic_data['prev_posts'] - 1) / intval($config['posts_per_page'])) * intval($config['posts_per_page']);
  422. }
  423. // Is user watching this thread?
  424. if (!class_exists('class_notifications'))
  425. {
  426. include(IP_ROOT_PATH . 'includes/class_notifications.' . PHP_EXT);
  427. $class_notifications = new class_notifications();
  428. }
  429. $watch = request_var('watch', '');
  430. $unwatch = request_var('unwatch', '');
  431. if($user->data['session_logged_in'] && !$user->data['is_bot'])
  432. {
  433. $can_watch_topic = true;
  434. $sql = "SELECT notify_status
  435. FROM " . TOPICS_WATCH_TABLE . "
  436. WHERE topic_id = " . $topic_id . "
  437. AND user_id = " . $user->data['user_id'] . "
  438. LIMIT 1";
  439. $result = $db->sql_query($sql);
  440. if ($row = $db->sql_fetchrow($result))
  441. {
  442. if (!empty($unwatch))
  443. {
  444. if ($unwatch == 'topic')
  445. {
  446. $is_watching_topic = false;
  447. $class_notifications->delete_topic_watch($user->data['user_id'], $topic_id);
  448. }
  449. $redirect_url = append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&amp;' . $topic_id_append . '&amp;start=' . $start . $kb_mode_append);
  450. meta_refresh(3, $redirect_url);
  451. $message = $lang['No_longer_watching'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&amp;' . $topic_id_append . '&amp;start=' . $start . $kb_mode_append) . '">', '</a>');
  452. message_die(GENERAL_MESSAGE, $message);
  453. }
  454. else
  455. {
  456. $is_watching_topic = true;
  457. if ($row['notify_status'])
  458. {
  459. $class_notifications->update_topic_watch($user->data['user_id'], $topic_id, $forum_id, 0);
  460. }
  461. }
  462. }
  463. else
  464. {
  465. if (!empty($watch))
  466. {
  467. if ($watch == 'topic')
  468. {
  469. $is_watching_topic = true;
  470. $class_notifications->update_topic_watch($user->data['user_id'], $topic_id, $forum_id, 0);
  471. }
  472. $redirect_url = append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&amp;' . $topic_id_append . $kb_mode_append . '&amp;' . 'start=' . $start);
  473. meta_refresh(3, $redirect_url);
  474. $message = $lang['You_are_watching'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&amp;' . $topic_id_append . $kb_mode_append . '&amp;' . '&amp;start=' . $start) . '">', '</a>');
  475. message_die(GENERAL_MESSAGE, $message);
  476. }
  477. else
  478. {
  479. $is_watching_topic = false;
  480. }
  481. }
  482. }
  483. else
  484. {
  485. if ($unwatch == 'topic')
  486. {
  487. redirect(append_sid(CMS_PAGE_LOGIN . '?redirect=' . CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . $kb_mode_append_red . '&unwatch=topic', true));
  488. }
  489. else
  490. {
  491. $can_watch_topic = 0;
  492. $is_watching_topic = false;
  493. }
  494. }
  495. // Generate a 'Show posts in previous x days' select box. If the postdays var is POSTed then get it's value, find the number of topics with dates newer than it (to properly handle pagination) and alter the main query
  496. $limit_sql_insert = '';
  497. if(!empty($sort_days))
  498. {
  499. $start = 0;
  500. $min_post_time = time() - (intval($sort_days) * 86400);
  501. $sql = "SELECT COUNT(p.post_id) AS num_posts
  502. FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
  503. WHERE t.topic_id = " . $topic_id . "
  504. AND p.topic_id = t.topic_id
  505. AND p.post_time >= " . $min_post_time;
  506. $result = $db->sql_query($sql);
  507. $total_replies = ($row = $db->sql_fetchrow($result)) ? intval($row['num_posts']) : 0;
  508. $limit_posts_time = "AND p.post_time >= " . $min_post_time . " ";
  509. }
  510. elseif ($after_post_id > 0)
  511. {
  512. // TODO make it after_post_time?
  513. $limit_posts_time = "AND p.post_id > " . intval($after_post_id) . " ";
  514. $sort_days = 0;
  515. $total_replies = intval($forum_topic_data['topic_replies']) + 1;
  516. }
  517. else
  518. {
  519. $sort_days = 0;
  520. $total_replies = intval($forum_topic_data['topic_replies']) + 1;
  521. $limit_posts_time = '';
  522. $limit_sql_insert = $start . ', ';
  523. }
  524. $user_ids = array();
  525. $user_ids2 = array();
  526. if($user->data['session_logged_in'])
  527. {
  528. $user_ids[$user->data['user_id']] = $user->data['username'];
  529. }
  530. // Custom Profile Fields MOD
  531. $profile_data = get_fields('WHERE view_in_topic = ' . VIEW_IN_TOPIC . ' AND users_can_view = ' . ALLOW_VIEW);
  532. $profile_data_sql = get_udata_txt($profile_data, 'u.');
  533. // END Custom Profile Fields MOD
  534. // Similar Topics - BEGIN
  535. if ($similar_topics_enabled)
  536. {
  537. $similar_topics = get_similar_topics($similar_forums_auth, $topic_id, $topic_title_plain, $forum_topic_data['topic_similar_topics'], $forum_topic_data['topic_desc']);
  538. $count_similar = sizeof($similar_topics);
  539. // Switch again to false because we will show the box only if we have similar topics!
  540. $similar_topics_enabled = false;
  541. if ($count_similar > 0)
  542. {
  543. $similar_topics_enabled = true;
  544. }
  545. }
  546. // Similar Topics - END
  547. //if ($config['switch_poster_info_topic'] == true)
  548. // Use the above code if you want even guests to be shown the extra info
  549. if ($config['switch_poster_info_topic'] && $user->data['session_logged_in'] && !$user->data['is_bot'])
  550. {
  551. $parse_extra_user_info = true;
  552. // Query Styles
  553. $styles = $cache->obtain_styles(true);
  554. foreach ($styles as $k => $v)
  555. {
  556. $styles_list_id[] = $k;
  557. $styles_list_name[] = $v;
  558. }
  559. }
  560. else
  561. {
  562. $parse_extra_user_info = false;
  563. }
  564. // Activity - BEGIN
  565. if (!empty($config['plugins']['activity']['enabled']) && !$user->data['is_bot'])
  566. {
  567. $activity_sql = ', u.user_trophies, u.ina_char_name';
  568. }
  569. else
  570. {
  571. $activity_sql = '';
  572. }
  573. // Activity - END
  574. // Go ahead and pull all data for this topic
  575. // Self AUTH - BEGIN
  576. $self_sql_tables = (intval($is_auth['auth_read']) == AUTH_SELF) ? ', ' . USERS_TABLE . ' u2' : '';
  577. $self_sql = (intval($is_auth['auth_read']) == AUTH_SELF) ? " AND t.topic_poster = u2.user_id AND (u2.user_id = '" . $user->data['user_id'] . "' OR t.topic_type = '" . POST_GLOBAL_ANNOUNCE . "' OR t.topic_type = '" . POST_ANNOUNCE . "' OR t.topic_type = '" . POST_STICKY . "')" : '';
  578. // Self AUTH - END
  579. $user_sn_im_array = get_user_sn_im_array();
  580. $sn_im_sql = '';
  581. foreach ($user_sn_im_array as $k => $v)
  582. {
  583. $sn_im_sql .= ', u.' . $v['field'];
  584. }
  585. $sql = "SELECT u.username, u.user_id, u.user_active, u.user_mask, u.user_color, u.user_first_name, u.user_last_name, u.user_posts, u.user_from, u.user_from_flag, u.user_website, u.user_email, u.user_regdate, u.user_allow_viewemail, u.user_rank, u.user_rank2, u.user_rank3, u.user_rank4, u.user_rank5, u.user_sig, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, u.user_allow_viewonline, u.user_session_time, u.user_warnings, u.user_level, u.user_birthday, u.user_next_birthday_greeting, u.user_gender, u.user_personal_pics_count, u.user_style, u.user_lang" . $sn_im_sql . $activity_sql . $profile_data_sql . ", u.ct_miserable_user, p.*, t.topic_poster, t.topic_label_compiled
  586. FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . TOPICS_TABLE . " t" . $self_sql_tables . "
  587. WHERE p.topic_id = $topic_id
  588. AND t.topic_id = p.topic_id
  589. AND u.user_id = p.poster_id
  590. " . $limit_posts_time . "
  591. " . $self_sql . "
  592. ORDER BY " . $sort_key_sql . " " . $sort_dir_sql . "
  593. LIMIT " . $limit_sql_insert . $config['posts_per_page'];
  594. // MG Cash MOD For IP - BEGIN
  595. if (!empty($config['plugins']['cash']['enabled']))
  596. {
  597. $cm_viewtopic->generate_columns($template, $forum_id, $sql);
  598. }
  599. // MG Cash MOD For IP - END
  600. $result = $db->sql_query($sql);
  601. $postrow = array();
  602. if ($row = $db->sql_fetchrow($result))
  603. {
  604. do
  605. {
  606. if($row['user_id'] > 0)
  607. {
  608. $user_ids[$row['user_id']] = $row['username'];
  609. }
  610. $postrow[] = $row;
  611. }
  612. while ($row = $db->sql_fetchrow($result));
  613. $db->sql_freeresult($result);
  614. $total_posts = sizeof($postrow);
  615. }
  616. else
  617. {
  618. if (!class_exists('class_mcp')) include(IP_ROOT_PATH . 'includes/class_mcp.' . PHP_EXT);
  619. if (empty($class_mcp)) $class_mcp = new class_mcp();
  620. $class_mcp->sync('topic', $topic_id);
  621. message_die(GENERAL_MESSAGE, $lang['No_posts_topic']);
  622. }
  623. if (($total_posts == 1) && !empty($config['robots_index_topics_no_replies']))
  624. {
  625. define('ROBOTS_NOINDEX', true);
  626. }
  627. $resync = false;
  628. if (($forum_topic_data['topic_replies'] + 1) < ($start + sizeof($postrow)))
  629. {
  630. $resync = true;
  631. }
  632. elseif (($start + $config['posts_per_page']) > $forum_topic_data['topic_replies'])
  633. {
  634. $row_id = intval($forum_topic_data['topic_replies']) % intval($config['posts_per_page']);
  635. if ($postrow[$row_id]['post_id'] != $forum_topic_data['topic_last_post_id'] || $start + sizeof($postrow) < $forum_topic_data['topic_replies'])
  636. {
  637. $resync = true;
  638. }
  639. }
  640. elseif (sizeof($postrow) < $config['posts_per_page'])
  641. {
  642. $resync = true;
  643. }
  644. if ($resync)
  645. {
  646. if (!class_exists('class_mcp')) include(IP_ROOT_PATH . 'includes/class_mcp.' . PHP_EXT);
  647. if (empty($class_mcp)) $class_mcp = new class_mcp();
  648. $class_mcp->sync('topic', $topic_id);
  649. $sql = 'SELECT COUNT(post_id) AS total FROM ' . POSTS_TABLE . ' WHERE topic_id = ' . $topic_id;
  650. $result = $db->sql_query($sql);
  651. $row = $db->sql_fetchrow($result);
  652. $total_replies = $row['total'];
  653. }
  654. // Mighty Gorgon - Multiple Ranks - BEGIN
  655. $ranks_array = $cache->obtain_ranks(false);
  656. // Mighty Gorgon - Multiple Ranks - END
  657. // Was a highlight request part of the URI?
  658. $highlight_match = '';
  659. $highlight = '';
  660. $highlight_words = request_var('highlight', '');
  661. $highlight_words = htmlspecialchars_decode($highlight_words, ENT_COMPAT);
  662. if (!empty($highlight_words))
  663. {
  664. $highlight_words = addslashes(preg_replace('#[][\\/%():><{}`]#', ' ', $highlight_words));
  665. // Split words and phrases
  666. $words = explode(' ', trim(htmlspecialchars($highlight_words)));
  667. for($i = 0; $i < sizeof($words); $i++)
  668. {
  669. if (trim($words[$i]) != '')
  670. {
  671. $highlight_match .= (($highlight_match != '') ? '|' : '') . str_replace('*', '\w*', preg_quote($words[$i], '#'));
  672. }
  673. }
  674. unset($words);
  675. $highlight = urlencode($highlight_words);
  676. $highlight_match = rtrim($highlight_match, "\\");
  677. }
  678. // Post, reply and other URL generation for templating vars
  679. $new_topic_url = append_sid('posting.' . PHP_EXT . '?mode=newtopic&amp;' . $forum_id_append);
  680. $reply_topic_url = append_sid('posting.' . PHP_EXT . '?mode=reply&amp;' . $forum_id_append . '&amp;' . $topic_id_append);
  681. $view_forum_url = append_sid(CMS_PAGE_VIEWFORUM . '?' . POST_FORUM_URL . '=' . $forum_id . $kb_mode_append);
  682. $view_prev_topic_url = append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&amp;' . $topic_id_append . $kb_mode_append . '&amp;view=previous');
  683. $view_next_topic_url = append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&amp;' . $topic_id_append . $kb_mode_append . '&amp;view=next');
  684. // Mozilla navigation bar
  685. //SEO TOOLKIT BEGIN
  686. $nav_links['prev'] = array(
  687. 'url' => $view_prev_topic_url,
  688. 'title' => $lang['View_previous_topic']
  689. );
  690. $nav_links['next'] = array(
  691. 'url' => $view_next_topic_url,
  692. 'title' => $lang['View_next_topic']
  693. );
  694. $nav_links['up'] = array(
  695. 'url' => $view_forum_url,
  696. 'title' => $forum_name
  697. );
  698. //SEO TOOLKIT END
  699. $is_this_locked = (($forum_topic_data['forum_status'] == FORUM_LOCKED) || ($forum_topic_data['topic_status'] == TOPIC_LOCKED)) ? true : false;
  700. $reply_img = $is_this_locked ? $images['reply_locked'] : $images['reply_new'];
  701. $reply_alt = $is_this_locked ? $lang['Topic_locked'] : $lang['Reply_to_topic'];
  702. $post_img = ($forum_topic_data['forum_status'] == FORUM_LOCKED) ? $images['post_locked'] : $images['post_new'];
  703. $post_alt = ($forum_topic_data['forum_status'] == FORUM_LOCKED) ? $lang['Forum_locked'] : $lang['Post_new_topic'];
  704. if(!$user->data['session_logged_in'] || !$is_auth['auth_reply'] || ($is_this_locked && !$is_auth['auth_mod']) || $user->data['is_bot'])
  705. {
  706. $can_reply = false;
  707. }
  708. else
  709. {
  710. $can_reply = true;
  711. $template->assign_var('S_CAN_REPLY', true);
  712. }
  713. // Set a cookie for this topic
  714. if ($user->data['session_logged_in'] && !$user->data['is_bot'])
  715. {
  716. $tracking_forums = (isset($_COOKIE[$config['cookie_name'] . '_f'])) ? unserialize($_COOKIE[$config['cookie_name'] . '_f']) : array();
  717. $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_t'])) ? unserialize($_COOKIE[$config['cookie_name'] . '_t']) : array();
  718. if (!empty($tracking_topics[$topic_id]) && !empty($tracking_forums[$forum_id]))
  719. {
  720. $topic_last_read = ($tracking_topics[$topic_id] > $tracking_forums[$forum_id]) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
  721. }
  722. elseif (!empty($tracking_topics[$topic_id]) || !empty($tracking_forums[$forum_id]))
  723. {
  724. $topic_last_read = (!empty($tracking_topics[$topic_id])) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
  725. }
  726. else
  727. {
  728. $topic_last_read = $user->data['user_lastvisit'];
  729. }
  730. if ((sizeof($tracking_topics) >= 150) && empty($tracking_topics[$topic_id]))
  731. {
  732. asort($tracking_topics);
  733. unset($tracking_topics[key($tracking_topics)]);
  734. }
  735. $tracking_topics[$topic_id] = time();
  736. $user->set_cookie('t', serialize($tracking_topics), $user->cookie_expire);
  737. }
  738. // UPI2DB - BEGIN
  739. if($user->data['upi2db_access'])
  740. {
  741. $unread_new_posts = 0;
  742. $unread_edit_posts = 0;
  743. for($i = 0; $i < $total_posts; $i++)
  744. {
  745. if (sizeof($user->data['upi2db_unread'][$topic_id]['new_posts']) && in_array($postrow[$i]['post_id'], $user->data['upi2db_unread'][$topic_id]['new_posts']))
  746. {
  747. ++$unread_new_posts;
  748. }
  749. if (sizeof($user->data['upi2db_unread'][$topic_id]['edit_posts']) && in_array($postrow[$i]['post_id'], $user->data['upi2db_unread'][$topic_id]['edit_posts']))
  750. {
  751. ++$unread_edit_posts;
  752. }
  753. }
  754. }
  755. // UPI2DB - END
  756. $template_to_parse = ($kb_mode) ? 'viewtopic_kb_body.tpl' : 'viewtopic_body.tpl';
  757. // Needed for attachments... do not remove!
  758. $template->set_filenames(array('body' => $template_to_parse));
  759. make_jumpbox(CMS_PAGE_VIEWFORUM, $forum_id);
  760. // Output page header
  761. if ($config['display_viewonline'])
  762. {
  763. define('SHOW_ONLINE', true);
  764. }
  765. //$meta_content['page_title'] = $meta_content['forum_name'] . ' :: ' . $topic_title_plain;
  766. //$meta_content['page_title'] = str_replace(array('"'), array('\"'), htmlspecialchars_decode($topic_title_plain));
  767. $meta_content['page_title'] = $topic_title_plain;
  768. $meta_content['page_title_clean'] = $topic_title_plain;
  769. $template->assign_var('S_VIEW_TOPIC', true);
  770. if ($config['show_icons'] == true)
  771. {
  772. $template->assign_var('S_SHOW_ICONS', true);
  773. }
  774. else
  775. {
  776. $template->assign_var('S_SHOW_LINKS', true);
  777. }
  778. if ($similar_topics_enabled)
  779. {
  780. include(IP_ROOT_PATH . 'includes/similar_topics.' . PHP_EXT);
  781. }
  782. // User authorization levels output
  783. // Self AUTH - BEGIN
  784. $lang['Rules_reply_can'] = ((intval($is_auth['auth_reply']) == AUTH_SELF) ? $lang['Rules_reply_can_own'] : $lang['Rules_reply_can']);
  785. // Self AUTH - END
  786. $s_auth_can = ($is_auth['auth_post'] ? $lang['Rules_post_can'] : $lang['Rules_post_cannot']) . '<br />';
  787. $s_auth_can .= ($is_auth['auth_reply'] ? $lang['Rules_reply_can'] : $lang['Rules_reply_cannot']) . '<br />';
  788. $s_auth_can .= ($is_auth['auth_edit'] ? $lang['Rules_edit_can'] : $lang['Rules_edit_cannot']) . '<br />';
  789. $s_auth_can .= ($is_auth['auth_delete'] ? $lang['Rules_delete_can'] : $lang['Rules_delete_cannot']) . '<br />';
  790. $s_auth_can .= ($is_auth['auth_vote'] ? $lang['Rules_vote_can'] : $lang['Rules_vote_cannot']) . '<br />';
  791. if (intval($config['disable_attachments_mod']) == 0)
  792. {
  793. $s_auth_can .= ($is_auth['auth_attachments'] ? $lang['Rules_attach_can'] : $lang['Rules_attach_cannot']) . '<br />';
  794. $s_auth_can .= ($is_auth['auth_download'] ? $lang['Rules_download_can'] : $lang['Rules_download_cannot']) . '<br />';
  795. }
  796. $s_auth_can .= ($is_auth['auth_cal'] ? $lang['Rules_calendar_can'] : $lang['Rules_calendar_cannot']) . '<br />';
  797. $s_auth_can .= ($is_auth['auth_ban'] ? $lang['Rules_ban_can'] . '<br />' : '');
  798. $s_auth_can .= ($is_auth['auth_greencard'] ? $lang['Rules_greencard_can'] . '<br />' : '');
  799. $s_auth_can .= ($is_auth['auth_bluecard'] ? $lang['Rules_bluecard_can'] . '<br />' : '');
  800. //attach_build_auth_levels($is_auth, $s_auth_can);
  801. $topic_mod = '';
  802. $topic_mod_switch = false;
  803. if ($is_auth['auth_mod'])
  804. {
  805. $topic_mod_switch = true;
  806. $s_auth_can .= sprintf($lang['Rules_moderate'], '<a href="modcp.' . PHP_EXT . '?' . $forum_id_append . '&amp;sid=' . $user->data['session_id'] . '">', '</a>');
  807. // Full string to append as a reference for FORUM TOPIC POST (FTP)
  808. $full_ftp_append = (($forum_id_append == '') ? '' : ($forum_id_append . '&amp;')) . (($topic_id_append == '') ? '' : ($topic_id_append . '&amp;')) . (($post_id_append == '') ? '' : ($post_id_append . '&amp;'));
  809. if ($lofi)
  810. {
  811. if ($config['bin_forum'] != false)
  812. {
  813. $topic_mod .= '<a href="bin.' . PHP_EXT . '?' . $full_ftp_append . 'sid=' . $user->data['session_id'] . '" title="' . $lang['Move_bin'] . '">' . $lang['Move_bin'] . '</a>&nbsp;&bull;&nbsp;';
  814. }
  815. $topic_mod .= '<a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=delete&amp;sid=' . $user->data['session_id'] . '" title="' . $lang['Delete_topic'] . '">' . $lang['Delete_topic'] . '</a>&nbsp;&bull;&nbsp;';
  816. $topic_mod .= '<a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=move&amp;sid=' . $user->data['session_id'] . '" title="' . $lang['Move_topic'] . '">' . $lang['Move_topic'] . '</a>&nbsp;<br />';
  817. $topic_mod .= (($forum_topic_data['topic_status'] == TOPIC_UNLOCKED) ? '<a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=lock&amp;sid=' . $user->data['session_id'] . '" title="' . $lang['Lock_topic'] . '">' . $lang['Lock_topic'] . '</a>' : '<a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=unlock&amp;sid=' . $user->data['session_id'] . '" title="' . $lang['Unlock_topic'] . '">' . $lang['Unlock_topic'] . '</a>') . '&nbsp;&bull;&nbsp;';
  818. $topic_mod .= '<a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=split&amp;sid=' . $user->data['session_id'] . '" title="' . $lang['Split_topic'] . '">' . $lang['Split_topic'] . '</a>&nbsp;&bull;&nbsp;';
  819. $topic_mod .= '<a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=merge&amp;sid=' . $user->data['session_id'] . '" title="' . $lang['Merge_topic'] . '">' . $lang['Merge_topic'] . '</a>&nbsp;<br />';
  820. }
  821. else
  822. {
  823. if ($config['bin_forum'] != false)
  824. {
  825. $topic_mod .= '<span class="img-btn"><a href="bin.' . PHP_EXT . '?' . $full_ftp_append . 'sid=' . $user->data['session_id'] . '"><img src="' . $images['topic_mod_bin'] . '" alt="' . $lang['Move_bin'] . '" title="' . $lang['Move_bin'] . '" /></a></span>&nbsp;';
  826. }
  827. $topic_mod .= '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=delete&amp;sid=' . $user->data['session_id'] . '" ><img src="' . $images['topic_mod_delete'] . '" alt="' . $lang['Delete_topic'] . '" title="' . $lang['Delete_topic'] . '" /></a></span>&nbsp;';
  828. $topic_mod .= '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=move&amp;sid=' . $user->data['session_id'] . '"><img src="' . $images['topic_mod_move'] . '" alt="' . $lang['Move_topic'] . '" title="' . $lang['Move_topic'] . '" /></a></span>&nbsp;';
  829. $topic_mod .= ($forum_topic_data['topic_status'] == TOPIC_UNLOCKED) ? '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=lock&amp;sid=' . $user->data['session_id'] . '"><img src="' . $images['topic_mod_lock'] . '" alt="' . $lang['Lock_topic'] . '" title="' . $lang['Lock_topic'] . '" /></a></span>&nbsp;' : '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=unlock&amp;sid=' . $user->data['session_id'] . '"><img src="' . $images['topic_mod_unlock'] . '" alt="' . $lang['Unlock_topic'] . '" title="' . $lang['Unlock_topic'] . '" /></a></span>&nbsp;';
  830. $topic_mod .= '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=split&amp;sid=' . $user->data['session_id'] . '"><img src="' . $images['topic_mod_split'] . '" alt="' . $lang['Split_topic'] . '" title="' . $lang['Split_topic'] . '" /></a></span>&nbsp;';
  831. $topic_mod .= '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=merge&amp;sid=' . $user->data['session_id'] . '"><img src="' . $images['topic_mod_merge'] . '" alt="' . $lang['Merge_topic'] . '" title="' . $lang['Merge_topic'] . '" /></a></span>&nbsp;<br /><br />';
  832. $global_button = ($is_auth['auth_globalannounce']) ? '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=super_announce&amp;sid=' . $user->data['session_id'] . '"><img src="' . $images['gannounce_post'] . '" alt="' . $lang['Mod_CP_global'] . '" title="' . $lang['Mod_CP_global2'] . '" /></a></span>&nbsp;' : '';
  833. $announce_button = ($is_auth['auth_announce']) ? '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=announce&amp;sid=' . $user->data['session_id'] . '"><img src="' . $images['announce_post'] . '" alt="' . $lang['Mod_CP_announce'] . '" title="' . $lang['Mod_CP_announce2'] . '" /></a></span>&nbsp;' : '';
  834. $sticky_button = ($is_auth['auth_sticky']) ? '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=sticky&amp;sid=' . $user->data['session_id'] . '"><img src="' . $images['sticky_post'] . '" alt="' . $lang['Mod_CP_sticky'] . '" title="' . $lang['Mod_CP_sticky2'] . '" /></a></span>&nbsp;' : '';
  835. $normal_button = '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=normalize&amp;sid=' . $user->data['session_id'] . '"><img src="' . $images['normal_post'] . '" alt="' . $lang['Mod_CP_normal'] . '" title="' . $lang['Mod_CP_normal2'] . '" /></a></span>&nbsp;';
  836. $s_tmod_topic_global = false;
  837. $s_tmod_topic_announce = false;
  838. $s_tmod_topic_sticky = false;
  839. $s_tmod_topic_normal = false;
  840. switch($forum_topic_data['topic_type'])
  841. {
  842. case POST_NORMAL:
  843. $s_tmod_topic_normal = true;
  844. $topic_mod .= $global_button . $announce_button . $sticky_button;
  845. break;
  846. case POST_STICKY:
  847. $s_tmod_topic_sticky = true;
  848. $topic_mod .= $global_button . $announce_button . $normal_button;
  849. break;
  850. case POST_ANNOUNCE:
  851. $s_tmod_topic_announce = true;
  852. $topic_mod .= $global_button . $sticky_button . $normal_button;
  853. break;
  854. case POST_GLOBAL_ANNOUNCE:
  855. $s_tmod_topic_global = true;
  856. $topic_mod .= $announce_button . $sticky_button . $normal_button;
  857. break;
  858. }
  859. }
  860. }
  861. // Topics Labels - BEGIN
  862. //if (!(($user->data['user_level'] == 0) && ($user->data['user_id'] != $row['topic_poster'])))
  863. if ($is_auth['auth_edit'] || ($user->data['user_id'] == $row['topic_poster']))
  864. {
  865. $topics_labels_select = $class_topics->gen_topics_labels_select();
  866. $topic_labels_block = '<form action="modcp.' . PHP_EXT . '?sid=' . $user->data['session_id'] . '" method="post"><br /><br />';
  867. $topic_labels_block .= $topics_labels_select;
  868. $topic_labels_block .= '<input type="submit" name="label_edit" class="liteoption" value="' . $lang['TOPIC_LABEL'] . '"/>';
  869. $topic_labels_block .= '<input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '"/>';
  870. $topic_labels_block .= '<input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '"/>';
  871. $topic_labels_block .= '</form>';
  872. $topic_mod .= $topic_labels_block;
  873. }
  874. // Topics Labels - END
  875. $s_kb_mode_url = append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&amp;' . $topic_id_append . '&amp;kb=' . (!empty($kb_mode) ? 'off' : 'on') . '&amp;start=' . $start);
  876. $s_kb_mode_l = (!empty($kb_mode) ? $lang['KB_MODE_OFF'] : $lang['KB_MODE_ON']);
  877. $s_kb_mode = '<a href="' . $s_kb_mode_url . '">' . $s_kb_mode_l . '</a>';
  878. $s_kb_mode_img_tmp = (!empty($kb_mode) ? $images['topic_kb_off'] : $images['topic_kb_on']);
  879. $s_kb_mode_img = (!empty($s_kb_mode_img_tmp)) ? '<a href="' . $s_kb_mode_url . '"><img src="' . $s_kb_mode_img_tmp . '" alt="' . $s_kb_mode_l . '" title="' . $s_kb_mode_l . '" /></a>' : '';
  880. // Topic watch information
  881. $s_watching_topic = '';
  882. if ($can_watch_topic)
  883. {
  884. $s_watching_topic_url = append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&amp;' . $topic_id_append . $kb_mode_append . '&amp;' . (!empty($is_watching_topic) ? 'unwatch' : 'watch') . '=topic&amp;start=' . $start);
  885. $s_watching_topic_l = (!empty($is_watching_topic) ? $lang['Stop_watching_topic'] : $lang['Start_watching_topic']);
  886. $s_watching_topic = '<a href="' . $s_watching_topic_url . '">' . $s_watching_topic_l . '</a>';
  887. $s_watching_topic_img_tmp = (!empty($is_watching_topic) ? $images['topic_un_watch'] : $images['topic_watch']);
  888. $s_watching_topic_img = (!empty($s_watching_topic_img_tmp)) ? '<a href="' . $s_watching_topic_url . '"><img src="' . $s_watching_topic_img_tmp . '" alt="' . $s_watching_topic_l . '" title="' . $s_watching_topic_l . '" /></a>' : '';
  889. }
  890. // Bookmark information
  891. if ($user->data['session_logged_in'] && !$user->data['is_bot'])
  892. {
  893. $template->assign_block_vars('bookmark_state', array());
  894. // Send vars to template
  895. if (is_bookmark_set($topic_id))
  896. {
  897. $bookmark_img = $images['bookmark_remove'];
  898. $bm_action = '&amp;removebm=true';
  899. $set_rem_bookmark = $lang['Remove_Bookmark'];
  900. }
  901. else
  902. {
  903. $bookmark_img = $images['bookmark_add'];
  904. $bm_action = '&amp;setbm=true';
  905. $set_rem_bookmark = $lang['Set_Bookmark'];
  906. }
  907. $template->assign_vars(array(
  908. 'L_BOOKMARK_ACTION' => $set_rem_bookmark,
  909. 'IMG_BOOKMARK' => $bookmark_img,
  910. 'U_BOOKMARK_ACTION' => append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&amp;' . $topic_id_append . $kb_mode_append . '&amp;start=' . $start . $vt_sort_append . '&amp;highlight=' . urlencode($_GET['highlight']) . $bm_action)
  911. )
  912. );
  913. }
  914. // UPI2DB - BEGIN
  915. if($user->data['upi2db_access'])
  916. {
  917. //$mark_always_read = mark_always_read($forum_topic_data['topic_type'], $topic_id, $forum_id, 'viewforum', 'txt', $user->data['upi2db_unread']);
  918. $s_mark_ar = mark_always_read_vt_ip($forum_topic_data['topic_type'], $topic_id, $forum_id, 'txt', $user->data['upi2db_unread']);
  919. $s_mark_ar_img = mark_always_read_vt_ip($forum_topic_data['topic_type'], $topic_id, $forum_id, 'img', $user->data['upi2db_unread']);
  920. }
  921. else
  922. {
  923. $mark_always_read = '';
  924. $s_mark_ar = '';
  925. $s_mark_ar_img = '';
  926. }
  927. // UPI2DB - END
  928. if ($total_replies > (10 * $config['posts_per_page']))
  929. {
  930. $template->assign_var('S_EXTENDED_PAGINATION', true);
  931. }
  932. // If we've got a hightlight set pass it on to pagination,
  933. // I get annoyed when I lose my highlight after the first page.
  934. $pagination = ($highlight != '') ? generate_pagination(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&amp;' . $topic_id_append . $kb_mode_append . $vt_sort_append . '&amp;highlight=' . $highlight, $total_replies, $config['posts_per_page'], $start) : generate_pagination(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&amp;' . $topic_id_append . $kb_mode_append . $vt_sort_append, $total_replies, $config['posts_per_page'], $start);
  935. $current_page = get_page($total_replies, $config['posts_per_page'], $start);
  936. $watch_topic_url = 'topic_view_users.' . PHP_EXT . '?' . $forum_id_append . '&amp;' . $topic_id_append;
  937. $rules_bbcode = '';
  938. if ($forum_topic_data['forum_rules_in_viewtopic'])
  939. {
  940. //BBcode Parsing for Olympus rules Start
  941. $rules_bbcode = $forum_topic_data['forum_rules'];
  942. $bbcode->allow_html = true;
  943. $bbcode->allow_bbcode = true;
  944. $bbcode->allow_smilies = true;
  945. $rules_bbcode = $bbcode->parse($rules_bbcode);
  946. //BBcode Parsing for Olympus rules Start
  947. $template->assign_vars(array(
  948. 'S_FORUM_RULES' => true,
  949. 'S_FORUM_RULES_TITLE' => ($forum_topic_data['forum_rules_display_title']) ? true : false
  950. )
  951. );
  952. }
  953. $topic_viewed_link = '';
  954. if (empty($config['disable_topic_view']) && ($forum_topic_data['forum_topic_views'] == 1) && ($user->data['user_level'] == ADMIN))
  955. {
  956. $topic_viewed_link = append_sid('topic_view_users.' . PHP_EXT . '?' . $forum_id_append . '&amp;' . $topic_id_append);
  957. }
  958. if ($config['show_social_bookmarks'])
  959. {
  960. $template->assign_block_vars('social_bookmarks', array());
  961. }
  962. if ($config['display_tags_box'])
  963. {
  964. @include_once(IP_ROOT_PATH . 'includes/class_topics_tags.' . PHP_EXT);
  965. $class_topics_tags = new class_topics_tags();
  966. $topic_tags_links = $class_topics_tags->build_tags_list(array($topic_id));
  967. $template->assign_vars(array(
  968. 'S_TOPIC_TAGS' => true,
  969. 'TOPIC_TAGS' => $topic_tags_links,
  970. )
  971. );
  972. }
  973. if ($config['enable_featured_image'])
  974. {
  975. $template->assign_var('S_FEATURED_IMAGE', true);
  976. }
  977. $topic_title_enc = urlencode(ip_utf8_decode($topic_title_plain));
  978. $topic_title_enc_utf8 = urlencode($topic_title_plain);
  979. // URL Rewrite - BEGIN
  980. // Rewrite Social Bookmars URLs if any of URL Rewrite rules has been enabled
  981. // Forum ID and KB Mode removed from topic_url_enc to avoid compatibility problems with redirects in tell a friend
  982. if (($config['url_rw'] == true) || ($config['url_rw_guests'] == true))
  983. {
  984. $topic_url = create_server_url() . make_url_friendly($topic_title_plain) . '-vt' . $topic_id . '.html' . ($kb_mode ? ('?' . $kb_mode_append) : '');
  985. }
  986. else
  987. {
  988. $topic_url = create_server_url() . ip_build_url(CMS_PAGE_VIEWTOPIC, array($forum_id_append, $topic_id_append), false) . $kb_mode_append_red;
  989. }
  990. $topic_url_ltt = htmlspecialchars($topic_url);
  991. $topic_url_enc = urlencode(ip_utf8_decode($topic_url));
  992. $topic_url_enc_utf8 = urlencode($topic_url);
  993. // URL Rewrite - END
  994. $current_page = (floor($start / intval($config['posts_per_page'])) + 1);
  995. $max_page = ceil($total_replies / intval($config['posts_per_page']));
  996. $ajax_post_data = array(
  997. 'S_TOPIC_URL_AFTER' => append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . '&after_post_id='),
  998. 'L_WARN_NEW_POST' => $lang['Warn_new_post'],
  999. 'REFRESH_INTERVAL' => $config['auto_refresh_topic_interval'],
  1000. );
  1001. $template->assign_vars(array(
  1002. 'FORUM_ID' => $forum_id,
  1003. 'FORUM_ID_FULL' => POST_FORUM_URL . $forum_id,
  1004. 'FORUM_NAME' => $forum_name,
  1005. 'FORUM_RULES' => $rules_bbcode,
  1006. 'TOPIC_ID' => $topic_id,
  1007. 'TOPIC_ID_FULL' => POST_TOPIC_URL . $topic_id,
  1008. 'TOPIC_TITLE' => $topic_title,
  1009. 'TOPIC_TITLE_PLAIN' => $topic_title_plain,
  1010. 'TOPIC_TITLE_SHORT' => $topic_title_short,
  1011. 'TOPIC_TITLE_QR' => str_replace(array('"'), array('\"'), htmlspecialchars_decode($topic_title_plain)),
  1012. 'TOPIC_POSTED_TIME' => $topic_started,
  1013. 'TOPIC_AUTHOR_NAME' => $topic_username,
  1014. 'TOPIC_AUTHOR_AVATAR' => $topic_avatar_img,
  1015. 'TOPIC_AUTHOR_FROM' => $topic_user_from_flag,
  1016. 'TOPIC_AUTHOR_GENDER' => $topic_user_gender_image,
  1017. 'TOPIC_AUTHOR_JOINED' => $topic_user_joined,
  1018. 'TOPIC_AUTHOR_POSTS' => $topic_user_posts,
  1019. 'TOPIC_VIEWS' => $forum_topic_data['topic_views'],
  1020. 'TOPIC_REPLIES' => $forum_topic_data['topic_replies'],
  1021. 'PAGINATION' => $pagination,
  1022. 'CURRENT_PAGE_NUMBER' => $current_page,
  1023. 'MAX_PAGE_NUMBER' => $max_page,
  1024. 'IS_LAST_PAGE' => ($current_page == $max_page) ? 1 : 0,
  1025. 'PAGE_NUMBER' => sprintf($lang['Page_of'], $current_page, $max_page),
  1026. 'AJAX_POST_DATA' => json_encode($ajax_post_data),
  1027. 'POST_IMG' => $post_img,
  1028. 'REPLY_IMG' => $reply_img,
  1029. 'IS_LOCKED' => $is_this_locked,
  1030. 'TOPIC_TITLE_ENC' => $topic_title_enc,
  1031. 'TOPIC_TITLE_ENC_UTF8' => $topic_title_enc_utf8,
  1032. 'TOPIC_URL_ENC' => $topic_url_enc,
  1033. 'TOPIC_URL_ENC_UTF8' => $topic_url_enc_utf8,
  1034. 'TOPIC_URL_LTT' => $topic_url_ltt,
  1035. 'L_DOWNLOAD_POST' => $lang['Download_post'],
  1036. 'L_DOWNLOAD_TOPIC' => $lang['Download_topic'],
  1037. 'DOWNLOAD_TOPIC' => append_sid(CMS_PAGE_VIEWTOPIC . '?download=-1&amp;' . $forum_id_append . '&amp;' . $topic_id_append),
  1038. 'U_TELL' => append_sid('tellafriend.' . PHP_EXT . '?topic_title=' . $topic_title_enc . '&amp;topic_id=' . $topic_id),
  1039. 'L_PRINT' => $lang['Print_View'],
  1040. 'U_PRINT' => append_sid('printview.' . PHP_EXT . '?' . $forum_id_append . '&amp;' . $topic_id_append . '&amp;start=' . $start),
  1041. 'L_SHARE_TOPIC' => $lang['ShareThisTopic'],
  1042. 'L_REPLY_NEWS' => $lang['News_Reply'],
  1043. 'L_PRINT_NEWS' => $lang['News_Print'],
  1044. 'L_EMAIL_NEWS' => $lang['News_Email'],
  1045. 'MINIPOST_IMG' => $images['icon_minipost'],
  1046. 'IMG_FLOPPY' => $images['floppy2'],
  1047. 'IMG_REPLY' => $images['news_reply'],
  1048. 'IMG_RECENT_TOPICS' => $images['recent_topics'],
  1049. 'IMG_PRINT' => $images['printer_topic'],
  1050. 'IMG_VIEWED' => $images['topic_viewed'],
  1051. 'IMG_EMAIL' => $images['email_topic'],
  1052. 'IMG_LEFT' => $images['icon_previous'],
  1053. 'IMG_RIGHT' => $images['icon_nex…

Large files files are truncated, but you can click here to view the full file