/viewtopic.php
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
- <?php
- /**
- *
- * @package Icy Phoenix
- * @version $Id$
- * @copyright (c) 2008 Icy Phoenix
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- *
- */
- /**
- *
- * @Icy Phoenix is based on phpBB
- * @copyright (c) 2008 phpBB Group
- *
- */
- define('IN_TOPIC', true);
- // MG Cash MOD For IP - BEGIN
- define('IN_CASHMOD', true);
- define('CM_VIEWTOPIC', true);
- // MG Cash MOD For IP - END
- define('CT_SECLEVEL', 'MEDIUM');
- $ct_ignoregvar = array('');
- // Added to optimize memory for attachments
- define('ATTACH_DISPLAY', true);
- define('IN_ICYPHOENIX', true);
- if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
- if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
- include(IP_ROOT_PATH . 'common.' . PHP_EXT);
- include_once(IP_ROOT_PATH . 'includes/bbcode.' . PHP_EXT);
- include_once(IP_ROOT_PATH . ATTACH_MOD_PATH . 'includes/functions_delete.' . PHP_EXT);
- include_once(IP_ROOT_PATH . 'includes/functions_topics.' . PHP_EXT);
- include_once(IP_ROOT_PATH . 'includes/functions_calendar.' . PHP_EXT);
- include_once(IP_ROOT_PATH . 'includes/functions_users.' . PHP_EXT);
- include_once(IP_ROOT_PATH . 'includes/functions_profile.' . PHP_EXT);
- include_once(IP_ROOT_PATH . 'includes/functions_rate.' . PHP_EXT);
- // Event Registration - BEGIN
- include_once(IP_ROOT_PATH . 'includes/functions_events_reg.' . PHP_EXT);
- // Event Registration - END
- @include_once(IP_ROOT_PATH . 'includes/class_topics.' . PHP_EXT);
- $class_topics = new class_topics();
- // Init common vars: forum_id, topic_id, post_id, etc.
- $class_topics->var_init(true);
- // Start session management
- $user->session_begin();
- $auth->acl($user->data);
- $user->setup();
- // End session management
- setup_extra_lang(array('lang_rate'));
- $start = request_var('start', 0);
- $start = ($start < 0) ? 0 : $start;
- $page_number = request_var('page_number', 0);
- $page_number = ($page_number < 1) ? 0 : $page_number;
- $start = (empty($page_number) ? $start : (($page_number * $config['topics_per_page']) - $config['topics_per_page']));
- $sort_days_array = array(0, 1, 7, 14, 30, 90, 180, 365);
- $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']);
- $sort_key_array = array('t', 's', 'a');
- $sort_key_lang_array = array('t' => $lang['POST_TIME'], 's' => $lang['SUBJECT'], 'a' => $lang['AUTHOR']);
- // In Icy Phoenix we still prefer sorting by time instead by ID... it could lead to collateral problems I know...
- //$sort_key_sql_array = array('t' => 'p.post_id', 's' => 'p.post_subject', 'a' => 'u.username_clean');
- $sort_key_sql_array = array('t' => 'p.post_time', 's' => 'p.post_subject', 'a' => 'u.username_clean');
- $sort_dir_array = array('a', 'd');
- $sort_dir_lang_array = array('a' => $lang['ASCENDING'], 'd' => $lang['DESCENDING']);
- $sort_dir_sql_array = array('a' => 'ASC', 'd' => 'DESC');
- $default_sort_days = (!empty($user->data['user_post_show_days'])) ? $user->data['user_post_show_days'] : $sort_days_array[0];
- $default_sort_key = (!empty($user->data['user_post_sortby_type'])) ? $user->data['user_post_sortby_type'] : $sort_key_array[0];
- $default_sort_dir = (!empty($user->data['user_post_sortby_dir'])) ? $user->data['user_post_sortby_dir'] : $sort_dir_array[0];
- $sort_days = request_var('st', $default_sort_days);
- $sort_days = check_var_value($sort_days, $sort_days_array);
- $sort_key = request_var('sk', $default_sort_key);
- $sort_key = check_var_value($sort_key, $sort_key_array);
- $sort_key_sql = $sort_key_sql_array[$sort_key];
- $sort_dir = strtolower(request_var('sd', $default_sort_dir));
- $sort_dir = check_var_value($sort_dir, $sort_dir_array);
- $sort_dir_sql = $sort_dir_sql_array[$sort_dir];
- // only fetch post higher than a certain post_id. Maybe this should use post_time, as $sort_key_sql_array uses post_time
- $after_post_id = request_var('after_post_id', 0);
- // make sure we can't fetch negative indices. 0 = disabled
- $after_post_id = ($after_post_id < 0) ? 1 : $after_post_id;
- // Backward compatibility
- if (check_http_var_exists('postorder', true))
- {
- $sort_dir_array_old = array('asc', 'desc');
- $sort_dir = strtolower(request_var('postorder', $sort_dir_array_old[0]));
- $sort_dir = check_var_value($sort_dir, $sort_dir_array_old);
- $sort_dir = ($sort_dir == 'asc') ? 'a' : 'd';
- $sort_dir_sql = $sort_dir_sql_array[$sort_dir];
- }
- if (check_http_var_exists('postdays', true))
- {
- $sort_days = request_var('postdays', $default_sort_days);
- $sort_days = check_var_value($sort_days, $sort_days_array);
- }
- $vt_sort_append_array = array();
- if ($sort_days != $sort_days_array[0])
- {
- $vt_sort_append_array['st'] = $sort_days;
- }
- if ($sort_key != $sort_key_array[0])
- {
- $vt_sort_append_array['sk'] = $sort_key;
- }
- if ($sort_dir != $sort_dir_array[0])
- {
- $vt_sort_append_array['sd'] = $sort_dir;
- }
- $vt_sort_append = '';
- $vt_sort_append_red = '';
- if (!empty($vt_sort_append_array))
- {
- foreach ($vt_sort_append_array as $k => $v)
- {
- $vt_sort_append = '&' . $k . '=' . $v;
- $vt_sort_append_red = '&' . $k . '=' . $v;
- }
- }
- $select_post_array = array('st' => 'sort_days', 'sk' => 'sort_key', 'sd' => 'sort_dir');
- $select_post_array_output = array();
- foreach ($select_post_array as $s_key => $s_name)
- {
- $select_post_array_output[$s_key] = '<select name="' . $s_key . '">';
- foreach (${$s_name . '_lang_array'} as $k => $v)
- {
- $selected = (${$s_name} == $k) ? ' selected="selected"' : '';
- $select_post_array_output[$s_key] .= '<option value="' . $k . '"' . $selected . '>' . $v . '</option>';
- }
- $select_post_array_output[$s_key] .= '</select>';
- ${'select_' . $s_name} = $select_post_array_output[$s_key];
- }
- $sid = request_var('sid', '');
- // Activity - BEGIN
- if (!empty($config['plugins']['activity']['enabled']))
- {
- include_once(IP_ROOT_PATH . PLUGINS_PATH . $config['plugins']['activity']['dir'] . 'common.' . PHP_EXT);
- $q = "SELECT * FROM " . INA_HOF;
- $r = $db->sql_query($q);
- $hof_data = $db->sql_fetchrowset($r);
- $db->sql_freeresult($r);
- }
- // Activity - END
- // Start initial var setup
- $kb_mode = false;
- $kb_mode_append = '';
- $kb_mode_append_red = '';
- $kb_mode_var = request_var('kb', '');
- if (($kb_mode_var == 'on') && ($user->data['bot_id'] == false))
- {
- $kb_mode = true;
- $kb_mode_append = '&kb=on';
- $kb_mode_append_red = '&kb=on';
- }
- $download = request_get_var('download', '');
- if (empty($topic_id) && empty($post_id))
- {
- if (!defined('STATUS_404')) define('STATUS_404', true);
- message_die(GENERAL_MESSAGE, 'NO_TOPIC');
- }
- // Find topic id if user requested a newer or older topic
- $view = request_get_var('view', '');
- if (!empty($view) && empty($post_id))
- {
- if ($view == 'newest')
- {
- if (isset($_COOKIE[$config['cookie_name'] . '_sid']) || !empty($sid))
- {
- $session_id = isset($_COOKIE[$config['cookie_name'] . '_sid']) ? $_COOKIE[$config['cookie_name'] . '_sid'] : $sid;
- if (!preg_match('/^[A-Za-z0-9]*$/', $session_id))
- {
- $session_id = '';
- }
- if ($session_id)
- {
- $sql = "SELECT p.post_id
- FROM " . POSTS_TABLE . " p, " . SESSIONS_TABLE . " s, " . USERS_TABLE . " u
- WHERE s.session_id = '" . $db->sql_escape($session_id) . "'
- AND u.user_id = s.session_user_id
- AND p.topic_id = '" . $topic_id . "'
- AND p.post_time >= u.user_lastvisit
- ORDER BY p.post_time ASC
- LIMIT 1";
- $result = $db->sql_query($sql);
- /* UPI2DB REPLACE
- if (!($row = $db->sql_fetchrow($result)))
- {
- message_die(GENERAL_MESSAGE, 'No_new_posts_last_visit');
- }
- */
- // UPI2DB - BEGIN
- if (!($row = $db->sql_fetchrow($result)))
- {
- if ($topic_id > 0)
- {
- redirect(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . $kb_mode_append_red);
- }
- else
- {
- message_die(GENERAL_MESSAGE, 'No_new_posts_last_visit');
- }
- }
- // UPI2DB - END
- $post_id = $row['post_id'];
- $post_id_append = (!empty($post_id) ? (POST_POST_URL . '=' . $post_id) : '');
- $post_id_append_url = (!empty($post_id) ? ('#p' . $post_id) : '');
- $session_id_append = !empty($sid) ? ('sid=' . $session_id . '&') : '';
- 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));
- }
- }
- redirect(append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . $kb_mode_append_red, true));
- }
- elseif (($view == 'next') || ($view == 'previous'))
- {
- $sql_condition = ($view == 'next') ? '>' : '<';
- $sql_ordering = ($view == 'next') ? 'ASC' : 'DESC';
- $sql = "SELECT t.topic_id, t.forum_id
- FROM " . TOPICS_TABLE . " t, " . TOPICS_TABLE . " t2
- WHERE
- t2.topic_id = '" . $topic_id . "'
- AND t.forum_id = t2.forum_id
- AND t.topic_moved_id = 0
- AND t.topic_last_post_id $sql_condition t2.topic_last_post_id
- ORDER BY t.topic_last_post_id $sql_ordering
- LIMIT 1";
- $result = $db->sql_query($sql);
- if ($row = $db->sql_fetchrow($result))
- {
- $forum_id = intval($row['forum_id']);
- $forum_id_append = (!empty($forum_id) ? (POST_FORUM_URL . '=' . $forum_id) : '');
- $topic_id = intval($row['topic_id']);
- $topic_id_append = (!empty($topic_id) ? (POST_TOPIC_URL . '=' . $topic_id) : '');
- redirect(append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . $kb_mode_append_red));
- }
- else
- {
- $message = ($view == 'next') ? 'No_newer_topics' : 'No_older_topics';
- message_die(GENERAL_MESSAGE, $message);
- }
- }
- }
- // 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)
- $join_sql_table = (!$post_id ? '' : (", " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2 "));
- $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));
- $count_sql = (!$post_id ? '' : (", COUNT(p2.post_id) AS prev_posts"));
- $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"));
- // 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
- //$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 . "
- $sql = "SELECT t.*, f.*, u.*" . $count_sql . "
- FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f," . USERS_TABLE . " u" . $join_sql_table . "
- WHERE $join_sql
- AND f.forum_id = t.forum_id AND t.topic_poster = u.user_id
- $order_sql";
- attach_setup_viewtopic_auth($order_sql, $sql);
- $result = $db->sql_query($sql);
- if (!($forum_topic_data = $db->sql_fetchrow($result)))
- {
- if (!defined('STATUS_404')) define('STATUS_404', true);
- message_die(GENERAL_MESSAGE, 'NO_TOPIC');
- }
- $db->sql_freeresult($result);
- $forum_id = intval($forum_topic_data['forum_id']);
- $forum_id_append = (!empty($forum_id) ? (POST_FORUM_URL . '=' . $forum_id) : '');
- $topic_id = intval($forum_topic_data['topic_id']);
- $topic_id_append = (!empty($topic_id) ? (POST_TOPIC_URL . '=' . $topic_id) : '');
- $forum_name = get_object_lang(POST_FORUM_URL . $forum_id, 'name');
- $topic_time = $forum_topic_data['topic_time'];
- $topic_first_post_id = intval($forum_topic_data['topic_first_post_id']);
- $topic_calendar_time = intval($forum_topic_data['topic_calendar_time']);
- $topic_calendar_duration = intval($forum_topic_data['topic_calendar_duration']);
- $topic_title_data = $class_topics->generate_topic_title($topic_id, $forum_topic_data, 80);
- $topic_title = $topic_title_data['title'];
- $topic_title_clean = $topic_title_data['title_clean'];
- $topic_title_plain = $topic_title_data['title_plain'];
- $topic_title_label = $topic_title_data['title_label'];
- $topic_title_short = $topic_title_data['title_short'];
- // Topic poster information
- $topic_started = create_date_ip($lang['DATE_FORMAT_VF'], $forum_topic_data['topic_time'], $config['board_timezone'], true);
- $topic_username = colorize_username($forum_topic_data['user_id'], $forum_topic_data['username'], $forum_topic_data['user_color'], $forum_topic_data['user_active']);
- $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']);
- $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'] . '" />' : '';
- switch ($forum_topic_data['user_gender'])
- {
- case 1:
- $topic_user_gender_image = '<img src="' . $images['icon_minigender_male'] . '" alt="' . $lang['Gender']. ': ' . $lang['Male'] . '" title="' . $lang['Gender'] . ': ' . $lang['Male'] . '" />';
- break;
- case 2:
- $topic_user_gender_image = '<img src="' . $images['icon_minigender_female'] . '" alt="' . $lang['Gender']. ': ' . $lang['Female'] . '" title="' . $lang['Gender'] . ': ' . $lang['Female'] . '" />';
- break;
- default:
- $topic_user_gender_image = '';
- }
- $topic_user_joined = create_date($lang['JOINED_DATE_FORMAT'], $forum_topic_data['user_regdate'], $config['board_timezone']);
- $topic_user_posts = $forum_topic_data['user_posts'];
- $meta_content = array();
- $meta_content = $class_topics->meta_content_init($forum_topic_data, 'topic');
- $meta_content['post_id'] = (!empty($post_id) && (intval($post_id) > 0)) ? intval($post_id) : 0;
- $this_forum_auth_read = intval($forum_topic_data['auth_read']);
- if ($forum_topic_data['forum_kb_mode'])
- {
- if ($kb_mode_var == 'off')
- {
- $kb_mode = false;
- $kb_mode_append = '&kb=off';
- $kb_mode_append_red = '&kb=off';
- }
- else
- {
- $kb_mode = true;
- $kb_mode_append = '&kb=on';
- $kb_mode_append_red = '&kb=on';
- }
- }
- // Set or remove bookmark - BEGIN
- $setbm = request_var('setbm', '');
- $removebm = request_var('removebm', '');
- if ((!empty($setbm) || !empty($removebm)) && !$user->data['is_bot'])
- {
- $redirect = CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . $kb_mode_append_red . '&start=' . $start . $vt_sort_append_red . '&highlight=' . urlencode($_GET['highlight']);
- if ($user->data['session_logged_in'])
- {
- if (!empty($setbm))
- {
- set_bookmark($topic_id);
- }
- elseif (!empty($removebm))
- {
- remove_bookmark($topic_id);
- }
- }
- else
- {
- if (!empty($setbm))
- {
- $redirect .= '&setbm=true';
- }
- elseif (!empty($removebm))
- {
- $redirect .= '&removebm=true';
- }
- redirect(append_sid(CMS_PAGE_LOGIN . '?redirect=' . $redirect, true));
- }
- redirect(append_sid($redirect, true));
- }
- // Set or remove bookmark - END
- $cms_page['page_id'] = 'viewtopic';
- // Comment out page_nav because viewtopic has its own breadcrumbs...
- //$cms_page['page_nav'] = (!empty($cms_config_layouts[$cms_page['page_id']]['page_nav']) ? true : false);
- $cms_page['global_blocks'] = (!empty($cms_config_layouts[$cms_page['page_id']]['global_blocks']) ? true : false);
- $cms_auth_level = (isset($cms_config_layouts[$cms_page['page_id']]['view']) ? $cms_config_layouts[$cms_page['page_id']]['view'] : AUTH_ALL);
- check_page_auth($cms_page['page_id'], $cms_auth_level);
- if ($download)
- {
- @include(IP_ROOT_PATH . 'includes/topic_download.' . PHP_EXT);
- exit;
- }
- //Begin Lo-Fi Mod
- if (!empty($lofi))
- {
- $lang['Reply_with_quote'] = $lang['quote_lofi'] ;
- $lang['Edit_delete_post'] = $lang['edit_lofi'];
- $lang['View_IP'] = $lang['ip_lofi'];
- $lang['Delete_post'] = $lang['del_lofi'];
- $lang['Read_profile'] = $lang['profile_lofi'];
- $lang['Send_private_message'] = $lang['pm_lofi'];
- $lang['Send_email'] = $lang['email_lofi'];
- $lang['Visit_website'] = $lang['website_lofi'];
- $lang['ICQ'] = $lang['icq_lofi'];
- $lang['AIM'] = $lang['aim_lofi'];
- $lang['YIM'] = $lang['yim_lofi'];
- $lang['MSNM'] = $lang['msnm_lofi'];
- }
- //End Lo-Fi Mod
- // Force Topic Read - BEGIN
- $ftr_disabled = $config['ftr_disable'] ? true : false;
- if (!$ftr_disabled)
- {
- @include(IP_ROOT_PATH . 'includes/topic_ftr.' . PHP_EXT);
- }
- // Force Topic Read - END
- $similar_topics_enabled = false;
- if ($config['similar_topics'] && $forum_topic_data['forum_similar_topics'])
- {
- $similar_topics_enabled = true;
- }
- if ($similar_topics_enabled)
- {
- $similar_forums_auth = auth(AUTH_ALL, AUTH_LIST_ALL, $user->data);
- $similar_is_auth = $similar_forums_auth[$forum_id];
- }
- // Start auth check
- $is_auth = array();
- $is_auth = $tree['auth'][POST_FORUM_URL . $forum_id];
- if (!$is_auth['auth_read'])
- {
- if (!$user->data['session_logged_in'])
- {
- $redirect = $forum_id_append . '&' . $topic_id_append . $kb_mode_append_red;
- $redirect .= ($post_id) ? '&' . $post_id_append : '';
- $redirect .= ($start) ? '&start=' . $start : '';
- redirect(append_sid(CMS_PAGE_LOGIN . '?redirect=' . CMS_PAGE_VIEWTOPIC . '&' . $redirect, true));
- }
- $message = sprintf($lang['Sorry_auth_read'], $is_auth['auth_read_type']);
- message_die(GENERAL_MESSAGE, $message);
- }
- // End auth check
- // Who viewed a topic - BEGIN
- if (!$config['disable_topic_view'] && $forum_topic_data['forum_topic_views'])
- {
- $user_id = $user->data['user_id'];
- $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;
- $db->sql_return_on_error(true);
- $result = $db->sql_query($sql);
- $db->sql_return_on_error(false);
- if (!$result || !$db->sql_affectedrows())
- {
- $sql = 'INSERT IGNORE INTO ' . TOPIC_VIEW_TABLE . ' (topic_id, user_id, view_time, view_count)
- VALUES (' . $topic_id . ', "' . $user_id . '", "' . time() . '", "1")';
- $db->sql_query($sql);
- }
- }
- // Who viewed a topic - END
- if (!empty($post_id))
- {
- $start = floor(($forum_topic_data['prev_posts'] - 1) / intval($config['posts_per_page'])) * intval($config['posts_per_page']);
- }
- // Is user watching this thread?
- if (!class_exists('class_notifications'))
- {
- include(IP_ROOT_PATH . 'includes/class_notifications.' . PHP_EXT);
- $class_notifications = new class_notifications();
- }
- $watch = request_var('watch', '');
- $unwatch = request_var('unwatch', '');
- if($user->data['session_logged_in'] && !$user->data['is_bot'])
- {
- $can_watch_topic = true;
- $sql = "SELECT notify_status
- FROM " . TOPICS_WATCH_TABLE . "
- WHERE topic_id = " . $topic_id . "
- AND user_id = " . $user->data['user_id'] . "
- LIMIT 1";
- $result = $db->sql_query($sql);
- if ($row = $db->sql_fetchrow($result))
- {
- if (!empty($unwatch))
- {
- if ($unwatch == 'topic')
- {
- $is_watching_topic = false;
- $class_notifications->delete_topic_watch($user->data['user_id'], $topic_id);
- }
- $redirect_url = append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . '&start=' . $start . $kb_mode_append);
- meta_refresh(3, $redirect_url);
- $message = $lang['No_longer_watching'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . '&start=' . $start . $kb_mode_append) . '">', '</a>');
- message_die(GENERAL_MESSAGE, $message);
- }
- else
- {
- $is_watching_topic = true;
- if ($row['notify_status'])
- {
- $class_notifications->update_topic_watch($user->data['user_id'], $topic_id, $forum_id, 0);
- }
- }
- }
- else
- {
- if (!empty($watch))
- {
- if ($watch == 'topic')
- {
- $is_watching_topic = true;
- $class_notifications->update_topic_watch($user->data['user_id'], $topic_id, $forum_id, 0);
- }
- $redirect_url = append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . $kb_mode_append . '&' . 'start=' . $start);
- meta_refresh(3, $redirect_url);
- $message = $lang['You_are_watching'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . $kb_mode_append . '&' . '&start=' . $start) . '">', '</a>');
- message_die(GENERAL_MESSAGE, $message);
- }
- else
- {
- $is_watching_topic = false;
- }
- }
- }
- else
- {
- if ($unwatch == 'topic')
- {
- redirect(append_sid(CMS_PAGE_LOGIN . '?redirect=' . CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . $kb_mode_append_red . '&unwatch=topic', true));
- }
- else
- {
- $can_watch_topic = 0;
- $is_watching_topic = false;
- }
- }
- // 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
- $limit_sql_insert = '';
- if(!empty($sort_days))
- {
- $start = 0;
- $min_post_time = time() - (intval($sort_days) * 86400);
- $sql = "SELECT COUNT(p.post_id) AS num_posts
- FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
- WHERE t.topic_id = " . $topic_id . "
- AND p.topic_id = t.topic_id
- AND p.post_time >= " . $min_post_time;
- $result = $db->sql_query($sql);
- $total_replies = ($row = $db->sql_fetchrow($result)) ? intval($row['num_posts']) : 0;
- $limit_posts_time = "AND p.post_time >= " . $min_post_time . " ";
- }
- elseif ($after_post_id > 0)
- {
- // TODO make it after_post_time?
- $limit_posts_time = "AND p.post_id > " . intval($after_post_id) . " ";
- $sort_days = 0;
- $total_replies = intval($forum_topic_data['topic_replies']) + 1;
- }
- else
- {
- $sort_days = 0;
- $total_replies = intval($forum_topic_data['topic_replies']) + 1;
- $limit_posts_time = '';
- $limit_sql_insert = $start . ', ';
- }
- $user_ids = array();
- $user_ids2 = array();
- if($user->data['session_logged_in'])
- {
- $user_ids[$user->data['user_id']] = $user->data['username'];
- }
- // Custom Profile Fields MOD
- $profile_data = get_fields('WHERE view_in_topic = ' . VIEW_IN_TOPIC . ' AND users_can_view = ' . ALLOW_VIEW);
- $profile_data_sql = get_udata_txt($profile_data, 'u.');
- // END Custom Profile Fields MOD
- // Similar Topics - BEGIN
- if ($similar_topics_enabled)
- {
- $similar_topics = get_similar_topics($similar_forums_auth, $topic_id, $topic_title_plain, $forum_topic_data['topic_similar_topics'], $forum_topic_data['topic_desc']);
- $count_similar = sizeof($similar_topics);
- // Switch again to false because we will show the box only if we have similar topics!
- $similar_topics_enabled = false;
- if ($count_similar > 0)
- {
- $similar_topics_enabled = true;
- }
- }
- // Similar Topics - END
- //if ($config['switch_poster_info_topic'] == true)
- // Use the above code if you want even guests to be shown the extra info
- if ($config['switch_poster_info_topic'] && $user->data['session_logged_in'] && !$user->data['is_bot'])
- {
- $parse_extra_user_info = true;
- // Query Styles
- $styles = $cache->obtain_styles(true);
- foreach ($styles as $k => $v)
- {
- $styles_list_id[] = $k;
- $styles_list_name[] = $v;
- }
- }
- else
- {
- $parse_extra_user_info = false;
- }
- // Activity - BEGIN
- if (!empty($config['plugins']['activity']['enabled']) && !$user->data['is_bot'])
- {
- $activity_sql = ', u.user_trophies, u.ina_char_name';
- }
- else
- {
- $activity_sql = '';
- }
- // Activity - END
- // Go ahead and pull all data for this topic
- // Self AUTH - BEGIN
- $self_sql_tables = (intval($is_auth['auth_read']) == AUTH_SELF) ? ', ' . USERS_TABLE . ' u2' : '';
- $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 . "')" : '';
- // Self AUTH - END
- $user_sn_im_array = get_user_sn_im_array();
- $sn_im_sql = '';
- foreach ($user_sn_im_array as $k => $v)
- {
- $sn_im_sql .= ', u.' . $v['field'];
- }
- $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
- FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . TOPICS_TABLE . " t" . $self_sql_tables . "
- WHERE p.topic_id = $topic_id
- AND t.topic_id = p.topic_id
- AND u.user_id = p.poster_id
- " . $limit_posts_time . "
- " . $self_sql . "
- ORDER BY " . $sort_key_sql . " " . $sort_dir_sql . "
- LIMIT " . $limit_sql_insert . $config['posts_per_page'];
- // MG Cash MOD For IP - BEGIN
- if (!empty($config['plugins']['cash']['enabled']))
- {
- $cm_viewtopic->generate_columns($template, $forum_id, $sql);
- }
- // MG Cash MOD For IP - END
- $result = $db->sql_query($sql);
- $postrow = array();
- if ($row = $db->sql_fetchrow($result))
- {
- do
- {
- if($row['user_id'] > 0)
- {
- $user_ids[$row['user_id']] = $row['username'];
- }
- $postrow[] = $row;
- }
- while ($row = $db->sql_fetchrow($result));
- $db->sql_freeresult($result);
- $total_posts = sizeof($postrow);
- }
- else
- {
- if (!class_exists('class_mcp')) include(IP_ROOT_PATH . 'includes/class_mcp.' . PHP_EXT);
- if (empty($class_mcp)) $class_mcp = new class_mcp();
- $class_mcp->sync('topic', $topic_id);
- message_die(GENERAL_MESSAGE, $lang['No_posts_topic']);
- }
- if (($total_posts == 1) && !empty($config['robots_index_topics_no_replies']))
- {
- define('ROBOTS_NOINDEX', true);
- }
- $resync = false;
- if (($forum_topic_data['topic_replies'] + 1) < ($start + sizeof($postrow)))
- {
- $resync = true;
- }
- elseif (($start + $config['posts_per_page']) > $forum_topic_data['topic_replies'])
- {
- $row_id = intval($forum_topic_data['topic_replies']) % intval($config['posts_per_page']);
- if ($postrow[$row_id]['post_id'] != $forum_topic_data['topic_last_post_id'] || $start + sizeof($postrow) < $forum_topic_data['topic_replies'])
- {
- $resync = true;
- }
- }
- elseif (sizeof($postrow) < $config['posts_per_page'])
- {
- $resync = true;
- }
- if ($resync)
- {
- if (!class_exists('class_mcp')) include(IP_ROOT_PATH . 'includes/class_mcp.' . PHP_EXT);
- if (empty($class_mcp)) $class_mcp = new class_mcp();
- $class_mcp->sync('topic', $topic_id);
- $sql = 'SELECT COUNT(post_id) AS total FROM ' . POSTS_TABLE . ' WHERE topic_id = ' . $topic_id;
- $result = $db->sql_query($sql);
- $row = $db->sql_fetchrow($result);
- $total_replies = $row['total'];
- }
- // Mighty Gorgon - Multiple Ranks - BEGIN
- $ranks_array = $cache->obtain_ranks(false);
- // Mighty Gorgon - Multiple Ranks - END
- // Was a highlight request part of the URI?
- $highlight_match = '';
- $highlight = '';
- $highlight_words = request_var('highlight', '');
- $highlight_words = htmlspecialchars_decode($highlight_words, ENT_COMPAT);
- if (!empty($highlight_words))
- {
- $highlight_words = addslashes(preg_replace('#[][\\/%():><{}`]#', ' ', $highlight_words));
- // Split words and phrases
- $words = explode(' ', trim(htmlspecialchars($highlight_words)));
- for($i = 0; $i < sizeof($words); $i++)
- {
- if (trim($words[$i]) != '')
- {
- $highlight_match .= (($highlight_match != '') ? '|' : '') . str_replace('*', '\w*', preg_quote($words[$i], '#'));
- }
- }
- unset($words);
- $highlight = urlencode($highlight_words);
- $highlight_match = rtrim($highlight_match, "\\");
- }
- // Post, reply and other URL generation for templating vars
- $new_topic_url = append_sid('posting.' . PHP_EXT . '?mode=newtopic&' . $forum_id_append);
- $reply_topic_url = append_sid('posting.' . PHP_EXT . '?mode=reply&' . $forum_id_append . '&' . $topic_id_append);
- $view_forum_url = append_sid(CMS_PAGE_VIEWFORUM . '?' . POST_FORUM_URL . '=' . $forum_id . $kb_mode_append);
- $view_prev_topic_url = append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . $kb_mode_append . '&view=previous');
- $view_next_topic_url = append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . $kb_mode_append . '&view=next');
- // Mozilla navigation bar
- //SEO TOOLKIT BEGIN
- $nav_links['prev'] = array(
- 'url' => $view_prev_topic_url,
- 'title' => $lang['View_previous_topic']
- );
- $nav_links['next'] = array(
- 'url' => $view_next_topic_url,
- 'title' => $lang['View_next_topic']
- );
- $nav_links['up'] = array(
- 'url' => $view_forum_url,
- 'title' => $forum_name
- );
- //SEO TOOLKIT END
- $is_this_locked = (($forum_topic_data['forum_status'] == FORUM_LOCKED) || ($forum_topic_data['topic_status'] == TOPIC_LOCKED)) ? true : false;
- $reply_img = $is_this_locked ? $images['reply_locked'] : $images['reply_new'];
- $reply_alt = $is_this_locked ? $lang['Topic_locked'] : $lang['Reply_to_topic'];
- $post_img = ($forum_topic_data['forum_status'] == FORUM_LOCKED) ? $images['post_locked'] : $images['post_new'];
- $post_alt = ($forum_topic_data['forum_status'] == FORUM_LOCKED) ? $lang['Forum_locked'] : $lang['Post_new_topic'];
- if(!$user->data['session_logged_in'] || !$is_auth['auth_reply'] || ($is_this_locked && !$is_auth['auth_mod']) || $user->data['is_bot'])
- {
- $can_reply = false;
- }
- else
- {
- $can_reply = true;
- $template->assign_var('S_CAN_REPLY', true);
- }
- // Set a cookie for this topic
- if ($user->data['session_logged_in'] && !$user->data['is_bot'])
- {
- $tracking_forums = (isset($_COOKIE[$config['cookie_name'] . '_f'])) ? unserialize($_COOKIE[$config['cookie_name'] . '_f']) : array();
- $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_t'])) ? unserialize($_COOKIE[$config['cookie_name'] . '_t']) : array();
- if (!empty($tracking_topics[$topic_id]) && !empty($tracking_forums[$forum_id]))
- {
- $topic_last_read = ($tracking_topics[$topic_id] > $tracking_forums[$forum_id]) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
- }
- elseif (!empty($tracking_topics[$topic_id]) || !empty($tracking_forums[$forum_id]))
- {
- $topic_last_read = (!empty($tracking_topics[$topic_id])) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
- }
- else
- {
- $topic_last_read = $user->data['user_lastvisit'];
- }
- if ((sizeof($tracking_topics) >= 150) && empty($tracking_topics[$topic_id]))
- {
- asort($tracking_topics);
- unset($tracking_topics[key($tracking_topics)]);
- }
- $tracking_topics[$topic_id] = time();
- $user->set_cookie('t', serialize($tracking_topics), $user->cookie_expire);
- }
- // UPI2DB - BEGIN
- if($user->data['upi2db_access'])
- {
- $unread_new_posts = 0;
- $unread_edit_posts = 0;
- for($i = 0; $i < $total_posts; $i++)
- {
- if (sizeof($user->data['upi2db_unread'][$topic_id]['new_posts']) && in_array($postrow[$i]['post_id'], $user->data['upi2db_unread'][$topic_id]['new_posts']))
- {
- ++$unread_new_posts;
- }
- if (sizeof($user->data['upi2db_unread'][$topic_id]['edit_posts']) && in_array($postrow[$i]['post_id'], $user->data['upi2db_unread'][$topic_id]['edit_posts']))
- {
- ++$unread_edit_posts;
- }
- }
- }
- // UPI2DB - END
- $template_to_parse = ($kb_mode) ? 'viewtopic_kb_body.tpl' : 'viewtopic_body.tpl';
- // Needed for attachments... do not remove!
- $template->set_filenames(array('body' => $template_to_parse));
- make_jumpbox(CMS_PAGE_VIEWFORUM, $forum_id);
- // Output page header
- if ($config['display_viewonline'])
- {
- define('SHOW_ONLINE', true);
- }
- //$meta_content['page_title'] = $meta_content['forum_name'] . ' :: ' . $topic_title_plain;
- //$meta_content['page_title'] = str_replace(array('"'), array('\"'), htmlspecialchars_decode($topic_title_plain));
- $meta_content['page_title'] = $topic_title_plain;
- $meta_content['page_title_clean'] = $topic_title_plain;
- $template->assign_var('S_VIEW_TOPIC', true);
- if ($config['show_icons'] == true)
- {
- $template->assign_var('S_SHOW_ICONS', true);
- }
- else
- {
- $template->assign_var('S_SHOW_LINKS', true);
- }
- if ($similar_topics_enabled)
- {
- include(IP_ROOT_PATH . 'includes/similar_topics.' . PHP_EXT);
- }
- // User authorization levels output
- // Self AUTH - BEGIN
- $lang['Rules_reply_can'] = ((intval($is_auth['auth_reply']) == AUTH_SELF) ? $lang['Rules_reply_can_own'] : $lang['Rules_reply_can']);
- // Self AUTH - END
- $s_auth_can = ($is_auth['auth_post'] ? $lang['Rules_post_can'] : $lang['Rules_post_cannot']) . '<br />';
- $s_auth_can .= ($is_auth['auth_reply'] ? $lang['Rules_reply_can'] : $lang['Rules_reply_cannot']) . '<br />';
- $s_auth_can .= ($is_auth['auth_edit'] ? $lang['Rules_edit_can'] : $lang['Rules_edit_cannot']) . '<br />';
- $s_auth_can .= ($is_auth['auth_delete'] ? $lang['Rules_delete_can'] : $lang['Rules_delete_cannot']) . '<br />';
- $s_auth_can .= ($is_auth['auth_vote'] ? $lang['Rules_vote_can'] : $lang['Rules_vote_cannot']) . '<br />';
- if (intval($config['disable_attachments_mod']) == 0)
- {
- $s_auth_can .= ($is_auth['auth_attachments'] ? $lang['Rules_attach_can'] : $lang['Rules_attach_cannot']) . '<br />';
- $s_auth_can .= ($is_auth['auth_download'] ? $lang['Rules_download_can'] : $lang['Rules_download_cannot']) . '<br />';
- }
- $s_auth_can .= ($is_auth['auth_cal'] ? $lang['Rules_calendar_can'] : $lang['Rules_calendar_cannot']) . '<br />';
- $s_auth_can .= ($is_auth['auth_ban'] ? $lang['Rules_ban_can'] . '<br />' : '');
- $s_auth_can .= ($is_auth['auth_greencard'] ? $lang['Rules_greencard_can'] . '<br />' : '');
- $s_auth_can .= ($is_auth['auth_bluecard'] ? $lang['Rules_bluecard_can'] . '<br />' : '');
- //attach_build_auth_levels($is_auth, $s_auth_can);
- $topic_mod = '';
- $topic_mod_switch = false;
- if ($is_auth['auth_mod'])
- {
- $topic_mod_switch = true;
- $s_auth_can .= sprintf($lang['Rules_moderate'], '<a href="modcp.' . PHP_EXT . '?' . $forum_id_append . '&sid=' . $user->data['session_id'] . '">', '</a>');
- // Full string to append as a reference for FORUM TOPIC POST (FTP)
- $full_ftp_append = (($forum_id_append == '') ? '' : ($forum_id_append . '&')) . (($topic_id_append == '') ? '' : ($topic_id_append . '&')) . (($post_id_append == '') ? '' : ($post_id_append . '&'));
- if ($lofi)
- {
- if ($config['bin_forum'] != false)
- {
- $topic_mod .= '<a href="bin.' . PHP_EXT . '?' . $full_ftp_append . 'sid=' . $user->data['session_id'] . '" title="' . $lang['Move_bin'] . '">' . $lang['Move_bin'] . '</a> • ';
- }
- $topic_mod .= '<a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=delete&sid=' . $user->data['session_id'] . '" title="' . $lang['Delete_topic'] . '">' . $lang['Delete_topic'] . '</a> • ';
- $topic_mod .= '<a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=move&sid=' . $user->data['session_id'] . '" title="' . $lang['Move_topic'] . '">' . $lang['Move_topic'] . '</a> <br />';
- $topic_mod .= (($forum_topic_data['topic_status'] == TOPIC_UNLOCKED) ? '<a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=lock&sid=' . $user->data['session_id'] . '" title="' . $lang['Lock_topic'] . '">' . $lang['Lock_topic'] . '</a>' : '<a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=unlock&sid=' . $user->data['session_id'] . '" title="' . $lang['Unlock_topic'] . '">' . $lang['Unlock_topic'] . '</a>') . ' • ';
- $topic_mod .= '<a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=split&sid=' . $user->data['session_id'] . '" title="' . $lang['Split_topic'] . '">' . $lang['Split_topic'] . '</a> • ';
- $topic_mod .= '<a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=merge&sid=' . $user->data['session_id'] . '" title="' . $lang['Merge_topic'] . '">' . $lang['Merge_topic'] . '</a> <br />';
- }
- else
- {
- if ($config['bin_forum'] != false)
- {
- $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> ';
- }
- $topic_mod .= '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=delete&sid=' . $user->data['session_id'] . '" ><img src="' . $images['topic_mod_delete'] . '" alt="' . $lang['Delete_topic'] . '" title="' . $lang['Delete_topic'] . '" /></a></span> ';
- $topic_mod .= '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=move&sid=' . $user->data['session_id'] . '"><img src="' . $images['topic_mod_move'] . '" alt="' . $lang['Move_topic'] . '" title="' . $lang['Move_topic'] . '" /></a></span> ';
- $topic_mod .= ($forum_topic_data['topic_status'] == TOPIC_UNLOCKED) ? '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=lock&sid=' . $user->data['session_id'] . '"><img src="' . $images['topic_mod_lock'] . '" alt="' . $lang['Lock_topic'] . '" title="' . $lang['Lock_topic'] . '" /></a></span> ' : '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=unlock&sid=' . $user->data['session_id'] . '"><img src="' . $images['topic_mod_unlock'] . '" alt="' . $lang['Unlock_topic'] . '" title="' . $lang['Unlock_topic'] . '" /></a></span> ';
- $topic_mod .= '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=split&sid=' . $user->data['session_id'] . '"><img src="' . $images['topic_mod_split'] . '" alt="' . $lang['Split_topic'] . '" title="' . $lang['Split_topic'] . '" /></a></span> ';
- $topic_mod .= '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=merge&sid=' . $user->data['session_id'] . '"><img src="' . $images['topic_mod_merge'] . '" alt="' . $lang['Merge_topic'] . '" title="' . $lang['Merge_topic'] . '" /></a></span> <br /><br />';
- $global_button = ($is_auth['auth_globalannounce']) ? '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=super_announce&sid=' . $user->data['session_id'] . '"><img src="' . $images['gannounce_post'] . '" alt="' . $lang['Mod_CP_global'] . '" title="' . $lang['Mod_CP_global2'] . '" /></a></span> ' : '';
- $announce_button = ($is_auth['auth_announce']) ? '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=announce&sid=' . $user->data['session_id'] . '"><img src="' . $images['announce_post'] . '" alt="' . $lang['Mod_CP_announce'] . '" title="' . $lang['Mod_CP_announce2'] . '" /></a></span> ' : '';
- $sticky_button = ($is_auth['auth_sticky']) ? '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=sticky&sid=' . $user->data['session_id'] . '"><img src="' . $images['sticky_post'] . '" alt="' . $lang['Mod_CP_sticky'] . '" title="' . $lang['Mod_CP_sticky2'] . '" /></a></span> ' : '';
- $normal_button = '<span class="img-btn"><a href="modcp.' . PHP_EXT . '?' . $full_ftp_append . 'mode=normalize&sid=' . $user->data['session_id'] . '"><img src="' . $images['normal_post'] . '" alt="' . $lang['Mod_CP_normal'] . '" title="' . $lang['Mod_CP_normal2'] . '" /></a></span> ';
- $s_tmod_topic_global = false;
- $s_tmod_topic_announce = false;
- $s_tmod_topic_sticky = false;
- $s_tmod_topic_normal = false;
- switch($forum_topic_data['topic_type'])
- {
- case POST_NORMAL:
- $s_tmod_topic_normal = true;
- $topic_mod .= $global_button . $announce_button . $sticky_button;
- break;
- case POST_STICKY:
- $s_tmod_topic_sticky = true;
- $topic_mod .= $global_button . $announce_button . $normal_button;
- break;
- case POST_ANNOUNCE:
- $s_tmod_topic_announce = true;
- $topic_mod .= $global_button . $sticky_button . $normal_button;
- break;
- case POST_GLOBAL_ANNOUNCE:
- $s_tmod_topic_global = true;
- $topic_mod .= $announce_button . $sticky_button . $normal_button;
- break;
- }
- }
- }
- // Topics Labels - BEGIN
- //if (!(($user->data['user_level'] == 0) && ($user->data['user_id'] != $row['topic_poster'])))
- if ($is_auth['auth_edit'] || ($user->data['user_id'] == $row['topic_poster']))
- {
- $topics_labels_select = $class_topics->gen_topics_labels_select();
- $topic_labels_block = '<form action="modcp.' . PHP_EXT . '?sid=' . $user->data['session_id'] . '" method="post"><br /><br />';
- $topic_labels_block .= $topics_labels_select;
- $topic_labels_block .= '<input type="submit" name="label_edit" class="liteoption" value="' . $lang['TOPIC_LABEL'] . '"/>';
- $topic_labels_block .= '<input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '"/>';
- $topic_labels_block .= '<input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '"/>';
- $topic_labels_block .= '</form>';
- $topic_mod .= $topic_labels_block;
- }
- // Topics Labels - END
- $s_kb_mode_url = append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . '&kb=' . (!empty($kb_mode) ? 'off' : 'on') . '&start=' . $start);
- $s_kb_mode_l = (!empty($kb_mode) ? $lang['KB_MODE_OFF'] : $lang['KB_MODE_ON']);
- $s_kb_mode = '<a href="' . $s_kb_mode_url . '">' . $s_kb_mode_l . '</a>';
- $s_kb_mode_img_tmp = (!empty($kb_mode) ? $images['topic_kb_off'] : $images['topic_kb_on']);
- $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>' : '';
- // Topic watch information
- $s_watching_topic = '';
- if ($can_watch_topic)
- {
- $s_watching_topic_url = append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . $kb_mode_append . '&' . (!empty($is_watching_topic) ? 'unwatch' : 'watch') . '=topic&start=' . $start);
- $s_watching_topic_l = (!empty($is_watching_topic) ? $lang['Stop_watching_topic'] : $lang['Start_watching_topic']);
- $s_watching_topic = '<a href="' . $s_watching_topic_url . '">' . $s_watching_topic_l . '</a>';
- $s_watching_topic_img_tmp = (!empty($is_watching_topic) ? $images['topic_un_watch'] : $images['topic_watch']);
- $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>' : '';
- }
- // Bookmark information
- if ($user->data['session_logged_in'] && !$user->data['is_bot'])
- {
- $template->assign_block_vars('bookmark_state', array());
- // Send vars to template
- if (is_bookmark_set($topic_id))
- {
- $bookmark_img = $images['bookmark_remove'];
- $bm_action = '&removebm=true';
- $set_rem_bookmark = $lang['Remove_Bookmark'];
- }
- else
- {
- $bookmark_img = $images['bookmark_add'];
- $bm_action = '&setbm=true';
- $set_rem_bookmark = $lang['Set_Bookmark'];
- }
- $template->assign_vars(array(
- 'L_BOOKMARK_ACTION' => $set_rem_bookmark,
- 'IMG_BOOKMARK' => $bookmark_img,
- 'U_BOOKMARK_ACTION' => append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . $kb_mode_append . '&start=' . $start . $vt_sort_append . '&highlight=' . urlencode($_GET['highlight']) . $bm_action)
- )
- );
- }
- // UPI2DB - BEGIN
- if($user->data['upi2db_access'])
- {
- //$mark_always_read = mark_always_read($forum_topic_data['topic_type'], $topic_id, $forum_id, 'viewforum', 'txt', $user->data['upi2db_unread']);
- $s_mark_ar = mark_always_read_vt_ip($forum_topic_data['topic_type'], $topic_id, $forum_id, 'txt', $user->data['upi2db_unread']);
- $s_mark_ar_img = mark_always_read_vt_ip($forum_topic_data['topic_type'], $topic_id, $forum_id, 'img', $user->data['upi2db_unread']);
- }
- else
- {
- $mark_always_read = '';
- $s_mark_ar = '';
- $s_mark_ar_img = '';
- }
- // UPI2DB - END
- if ($total_replies > (10 * $config['posts_per_page']))
- {
- $template->assign_var('S_EXTENDED_PAGINATION', true);
- }
- // If we've got a hightlight set pass it on to pagination,
- // I get annoyed when I lose my highlight after the first page.
- $pagination = ($highlight != '') ? generate_pagination(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . $kb_mode_append . $vt_sort_append . '&highlight=' . $highlight, $total_replies, $config['posts_per_page'], $start) : generate_pagination(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . $kb_mode_append . $vt_sort_append, $total_replies, $config['posts_per_page'], $start);
- $current_page = get_page($total_replies, $config['posts_per_page'], $start);
- $watch_topic_url = 'topic_view_users.' . PHP_EXT . '?' . $forum_id_append . '&' . $topic_id_append;
- $rules_bbcode = '';
- if ($forum_topic_data['forum_rules_in_viewtopic'])
- {
- //BBcode Parsing for Olympus rules Start
- $rules_bbcode = $forum_topic_data['forum_rules'];
- $bbcode->allow_html = true;
- $bbcode->allow_bbcode = true;
- $bbcode->allow_smilies = true;
- $rules_bbcode = $bbcode->parse($rules_bbcode);
- //BBcode Parsing for Olympus rules Start
- $template->assign_vars(array(
- 'S_FORUM_RULES' => true,
- 'S_FORUM_RULES_TITLE' => ($forum_topic_data['forum_rules_display_title']) ? true : false
- )
- );
- }
- $topic_viewed_link = '';
- if (empty($config['disable_topic_view']) && ($forum_topic_data['forum_topic_views'] == 1) && ($user->data['user_level'] == ADMIN))
- {
- $topic_viewed_link = append_sid('topic_view_users.' . PHP_EXT . '?' . $forum_id_append . '&' . $topic_id_append);
- }
- if ($config['show_social_bookmarks'])
- {
- $template->assign_block_vars('social_bookmarks', array());
- }
- if ($config['display_tags_box'])
- {
- @include_once(IP_ROOT_PATH . 'includes/class_topics_tags.' . PHP_EXT);
- $class_topics_tags = new class_topics_tags();
- $topic_tags_links = $class_topics_tags->build_tags_list(array($topic_id));
- $template->assign_vars(array(
- 'S_TOPIC_TAGS' => true,
- 'TOPIC_TAGS' => $topic_tags_links,
- )
- );
- }
- if ($config['enable_featured_image'])
- {
- $template->assign_var('S_FEATURED_IMAGE', true);
- }
- $topic_title_enc = urlencode(ip_utf8_decode($topic_title_plain));
- $topic_title_enc_utf8 = urlencode($topic_title_plain);
- // URL Rewrite - BEGIN
- // Rewrite Social Bookmars URLs if any of URL Rewrite rules has been enabled
- // Forum ID and KB Mode removed from topic_url_enc to avoid compatibility problems with redirects in tell a friend
- if (($config['url_rw'] == true) || ($config['url_rw_guests'] == true))
- {
- $topic_url = create_server_url() . make_url_friendly($topic_title_plain) . '-vt' . $topic_id . '.html' . ($kb_mode ? ('?' . $kb_mode_append) : '');
- }
- else
- {
- $topic_url = create_server_url() . ip_build_url(CMS_PAGE_VIEWTOPIC, array($forum_id_append, $topic_id_append), false) . $kb_mode_append_red;
- }
- $topic_url_ltt = htmlspecialchars($topic_url);
- $topic_url_enc = urlencode(ip_utf8_decode($topic_url));
- $topic_url_enc_utf8 = urlencode($topic_url);
- // URL Rewrite - END
- $current_page = (floor($start / intval($config['posts_per_page'])) + 1);
- $max_page = ceil($total_replies / intval($config['posts_per_page']));
- $ajax_post_data = array(
- 'S_TOPIC_URL_AFTER' => append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&' . $topic_id_append . '&after_post_id='),
- 'L_WARN_NEW_POST' => $lang['Warn_new_post'],
- 'REFRESH_INTERVAL' => $config['auto_refresh_topic_interval'],
- );
- $template->assign_vars(array(
- 'FORUM_ID' => $forum_id,
- 'FORUM_ID_FULL' => POST_FORUM_URL . $forum_id,
- 'FORUM_NAME' => $forum_name,
- 'FORUM_RULES' => $rules_bbcode,
- 'TOPIC_ID' => $topic_id,
- 'TOPIC_ID_FULL' => POST_TOPIC_URL . $topic_id,
- 'TOPIC_TITLE' => $topic_title,
- 'TOPIC_TITLE_PLAIN' => $topic_title_plain,
- 'TOPIC_TITLE_SHORT' => $topic_title_short,
- 'TOPIC_TITLE_QR' => str_replace(array('"'), array('\"'), htmlspecialchars_decode($topic_title_plain)),
- 'TOPIC_POSTED_TIME' => $topic_started,
- 'TOPIC_AUTHOR_NAME' => $topic_username,
- 'TOPIC_AUTHOR_AVATAR' => $topic_avatar_img,
- 'TOPIC_AUTHOR_FROM' => $topic_user_from_flag,
- 'TOPIC_AUTHOR_GENDER' => $topic_user_gender_image,
- 'TOPIC_AUTHOR_JOINED' => $topic_user_joined,
- 'TOPIC_AUTHOR_POSTS' => $topic_user_posts,
- 'TOPIC_VIEWS' => $forum_topic_data['topic_views'],
- 'TOPIC_REPLIES' => $forum_topic_data['topic_replies'],
- 'PAGINATION' => $pagination,
- 'CURRENT_PAGE_NUMBER' => $current_page,
- 'MAX_PAGE_NUMBER' => $max_page,
- 'IS_LAST_PAGE' => ($current_page == $max_page) ? 1 : 0,
- 'PAGE_NUMBER' => sprintf($lang['Page_of'], $current_page, $max_page),
- 'AJAX_POST_DATA' => json_encode($ajax_post_data),
- 'POST_IMG' => $post_img,
- 'REPLY_IMG' => $reply_img,
- 'IS_LOCKED' => $is_this_locked,
- 'TOPIC_TITLE_ENC' => $topic_title_enc,
- 'TOPIC_TITLE_ENC_UTF8' => $topic_title_enc_utf8,
- 'TOPIC_URL_ENC' => $topic_url_enc,
- 'TOPIC_URL_ENC_UTF8' => $topic_url_enc_utf8,
- 'TOPIC_URL_LTT' => $topic_url_ltt,
- 'L_DOWNLOAD_POST' => $lang['Download_post'],
- 'L_DOWNLOAD_TOPIC' => $lang['Download_topic'],
- 'DOWNLOAD_TOPIC' => append_sid(CMS_PAGE_VIEWTOPIC . '?download=-1&' . $forum_id_append . '&' . $topic_id_append),
- 'U_TELL' => append_sid('tellafriend.' . PHP_EXT . '?topic_title=' . $topic_title_enc . '&topic_id=' . $topic_id),
- 'L_PRINT' => $lang['Print_View'],
- 'U_PRINT' => append_sid('printview.' . PHP_EXT . '?' . $forum_id_append . '&' . $topic_id_append . '&start=' . $start),
- 'L_SHARE_TOPIC' => $lang['ShareThisTopic'],
- 'L_REPLY_NEWS' => $lang['News_Reply'],
- 'L_PRINT_NEWS' => $lang['News_Print'],
- 'L_EMAIL_NEWS' => $lang['News_Email'],
- 'MINIPOST_IMG' => $images['icon_minipost'],
- 'IMG_FLOPPY' => $images['floppy2'],
- 'IMG_REPLY' => $images['news_reply'],
- 'IMG_RECENT_TOPICS' => $images['recent_topics'],
- 'IMG_PRINT' => $images['printer_topic'],
- 'IMG_VIEWED' => $images['topic_viewed'],
- 'IMG_EMAIL' => $images['email_topic'],
- 'IMG_LEFT' => $images['icon_previous'],
- 'IMG_RIGHT' => $images['icon_nex…
Large files files are truncated, but you can click here to view the full file