sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
}
if ( !$row = $db->sql_fetchrow($result) )
{
message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
}
$forum_id = $row['forum_id'];
$topic_id = $row['topic_id'];
$post_time = $row['post_time'];
$topic_last_post_id = $row['topic_last_post_id'];
//END MOD Keep_unread_2
//
// Start session management
//
$userdata = session_pagestart($user_ip, $forum_id, $topic_id);
init_userprefs($userdata);
//
// End session management
//
//START MOD Keep_unread_2 * Keep topic unread from given post onwards
if ($mode == 'unread')
{
$board_config['tracking_unreads'][$topic_id] = $post_time-1; //testing for ">" only later on
write_cookies($userdata);
$message = $lang['keep_unread_done'] . '
' .
sprintf($lang['Click_return_forum'], '', ' ') . '
' .
sprintf($lang['Click_return_index'], '', ' ');
message_die(GENERAL_MESSAGE, $message);
}
$topic_last_read = topic_last_read($forum_id, $topic_id);
//END MOD Keep_unread_2
//
// Find topic id if user requested a newer
// or older topic
//
if ( isset($HTTP_GET_VARS['view']) && empty($HTTP_GET_VARS[POST_POST_URL]) )
{
if ( $HTTP_GET_VARS['view'] == 'newest' )
{ // read the first unread post in this topic
$sql = "SELECT p.post_id, t.topic_last_post_id
FROM (" . TOPICS_TABLE . " t
LEFT JOIN " . POSTS_TABLE . " p ON p.topic_id = t.topic_id AND p.post_time > $topic_last_read)
WHERE t.topic_id = $topic_id
AND t.topic_moved_id = 0
ORDER BY p.post_time";
if ( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Could not obtain newer/older topic information', '', __LINE__, __FILE__, $sql);
}
if ( !($row = $db->sql_fetchrow($result)) )
{
message_die(GENERAL_MESSAGE, 'No_new_posts_last_visit');
}
$post_id = empty($row['post_id']) ? $row['topic_last_post_id'] : $row['post_id'];
redirect(append_sid("./viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id", true));
}
else if ( $HTTP_GET_VARS['view'] == 'next' || $HTTP_GET_VARS['view'] == 'previous' )
{
$sql_condition = ( $HTTP_GET_VARS['view'] == 'next' ) ? '>' : '<';
$sql_ordering = ( $HTTP_GET_VARS['view'] == 'next' ) ? 'ASC' : 'DESC';
$sql = "SELECT t.topic_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";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Could not obtain newer/older topic information", '', __LINE__, __FILE__, $sql);
}
if ( $row = $db->sql_fetchrow($result) )
{
$topic_id = intval($row['topic_id']);
//MOD Keep_unread_2
redirect(append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id", true));
}
else
{
$message = ( $HTTP_GET_VARS['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.topic_vote, t.topic_last_post_id, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments ORDER BY p.post_id ASC";
$sql = "SELECT t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, t.topic_first_post_id, t.topic_last_post_id, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments" . $count_sql . "
FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f" . $join_sql_table . "
WHERE $join_sql
AND f.forum_id = t.forum_id
$order_sql";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Could not obtain topic information", '', __LINE__, __FILE__, $sql);
}
if ( !($forum_topic_data = $db->sql_fetchrow($result)) )
{
message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
}
$forum_id = intval($forum_topic_data['forum_id']);
// Start add - Topic in Who is online MOD
$topic_id = intval($forum_topic_data['topic_id']);
// End add - Topic in Who is online MOD
//MOD Keep_unread_2: session management already done above
//
// Start auth check
//
$is_auth = array();
$is_auth = auth(AUTH_ALL, $forum_id, $userdata, $forum_topic_data);
if( !$is_auth['auth_view'] || !$is_auth['auth_read'] )
{
if ( !$userdata['session_logged_in'] )
{
$redirect = ($post_id) ? POST_POST_URL . "=$post_id" : POST_TOPIC_URL . "=$topic_id";
$redirect .= ($start) ? "&start=$start" : '';
redirect(append_sid("login.$phpEx?redirect=viewtopic.$phpEx&$redirect", true));
}
$message = ( !$is_auth['auth_view'] ) ? $lang['Topic_post_not_exist'] : sprintf($lang['Sorry_auth_read'], $is_auth['auth_read_type']);
message_die(GENERAL_MESSAGE, $message);
}
//
// End auth check
//
$forum_name = $forum_topic_data['forum_name'];
$topic_title = $forum_topic_data['topic_title'];
$topic_id = intval($forum_topic_data['topic_id']);
$topic_time = $forum_topic_data['topic_time'];
if ($post_id)
{
$start = floor(($forum_topic_data['prev_posts'] - 1) / intval($board_config['posts_per_page'])) * intval($board_config['posts_per_page']);
}
//
// Getting current category info
//
$sql = "SELECT f.forum_id, f.cat_id, c.cat_id, c.cat_title
FROM " . FORUMS_TABLE . " f, " . CATEGORIES_TABLE . " c
WHERE f.forum_id = $forum_id
AND c.cat_id = f.cat_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Could not obtain category information", '', __LINE__, __FILE__, $sql);
}
$cat_data = $db->sql_fetchrow($result);
$cat_id = intval($cat_data['cat_id']);
$cat_title = $cat_data['cat_title'];
//Sig and Av ignore Toggling
if ($hide == 'hide')
{
$sql = "INSERT INTO " . HIDE_TABLE . " (user_id, hid_id) VALUES (" . $userdata[user_id] . ", " . $hidee_id . ")" ;
if ( !($db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error setting ignored sig and av', '', __LINE__, __FILE__, $sql);
}
}
else if ($hide == 'unhide')
{
$sql = "DELETE FROM " . HIDE_TABLE . " WHERE user_id = " . $userdata[user_id] . " && hid_id = " . $hidee_id;
if ( !($db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error unsetting ignored sig and av', '', __LINE__, __FILE__, $sql);
}
}
//
// Is user watching this thread?
//
if( $userdata['session_logged_in'] )
{
$can_watch_topic = TRUE;
$sql = "SELECT notify_status
FROM " . TOPICS_WATCH_TABLE . "
WHERE topic_id = $topic_id
AND user_id = " . $userdata['user_id'];
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Could not obtain topic watch information", '', __LINE__, __FILE__, $sql);
}
if ( $row = $db->sql_fetchrow($result) )
{
if ( isset($HTTP_GET_VARS['unwatch']) )
{
if ( $HTTP_GET_VARS['unwatch'] == 'topic' )
{
$is_watching_topic = 0;
$sql = "DELETE FROM " . TOPICS_WATCH_TABLE . "
WHERE topic_id = $topic_id
AND user_id = " . $userdata['user_id'];
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Could not delete topic watch information", '', __LINE__, __FILE__, $sql);
}
}
$template->assign_vars(array(
'META' => '')
);
$message = $lang['No_longer_watching'] . '
' . sprintf($lang['Click_return_topic'], '', '');
message_die(GENERAL_MESSAGE, $message);
}
else
{
$is_watching_topic = TRUE;
if ( $row['notify_status'] )
{
$sql = "UPDATE " . TOPICS_WATCH_TABLE . "
SET notify_status = 0
WHERE topic_id = $topic_id
AND user_id = " . $userdata['user_id'];
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Could not update topic watch information", '', __LINE__, __FILE__, $sql);
}
}
}
}
else
{
if ( isset($HTTP_GET_VARS['watch']) )
{
if ( $HTTP_GET_VARS['watch'] == 'topic' )
{
$is_watching_topic = TRUE;
$sql = "INSERT INTO " . TOPICS_WATCH_TABLE . " (user_id, topic_id, notify_status)
VALUES (" . $userdata['user_id'] . ", $topic_id, 0)";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Could not insert topic watch information", '', __LINE__, __FILE__, $sql);
}
}
$template->assign_vars(array(
'META' => '')
);
$message = $lang['You_are_watching'] . '
' . sprintf($lang['Click_return_topic'], '', '');
message_die(GENERAL_MESSAGE, $message);
}
else
{
$is_watching_topic = 0;
}
}
}
else
{
if ( isset($HTTP_GET_VARS['unwatch']) )
{
if ( $HTTP_GET_VARS['unwatch'] == 'topic' )
{
redirect(append_sid("login.$phpEx?redirect=viewtopic.$phpEx&" . POST_TOPIC_URL . "=$topic_id&unwatch=topic", true));
}
}
else
{
$can_watch_topic = 0;
$is_watching_topic = 0;
}
}
//
// 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
//
$previous_days = array(0, 1, 7, 14, 30, 90, 180, 364);
$previous_days_text = array($lang['All_Posts'], $lang['1_Day'], $lang['7_Days'], $lang['2_Weeks'], $lang['1_Month'], $lang['3_Months'], $lang['6_Months'], $lang['1_Year']);
if( !empty($HTTP_POST_VARS['postdays']) || !empty($HTTP_GET_VARS['postdays']) )
{
$post_days = ( !empty($HTTP_POST_VARS['postdays']) ) ? intval($HTTP_POST_VARS['postdays']) : intval($HTTP_GET_VARS['postdays']);
$min_post_time = time() - (intval($post_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";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Could not obtain limited topics count information", '', __LINE__, __FILE__, $sql);
}
$total_replies = ( $row = $db->sql_fetchrow($result) ) ? intval($row['num_posts']) : 0;
$limit_posts_time = "AND p.post_time >= $min_post_time ";
if ( !empty($HTTP_POST_VARS['postdays']))
{
$start = 0;
}
}
else
{
$total_replies = intval($forum_topic_data['topic_replies']) + 1;
$limit_posts_time = '';
$post_days = 0;
}
$select_post_days = '';
//
// Decide how to order the post display
//
if ( !empty($HTTP_POST_VARS['postorder']) || !empty($HTTP_GET_VARS['postorder']) )
{
$post_order = (!empty($HTTP_POST_VARS['postorder'])) ? htmlspecialchars($HTTP_POST_VARS['postorder']) : htmlspecialchars($HTTP_GET_VARS['postorder']);
$post_time_order = ($post_order == "asc") ? "ASC" : "DESC";
}
else
{
$post_order = 'asc';
$post_time_order = 'ASC';
}
$select_post_order = '';
//
// Go ahead and pull all data for this topic
//
$sql = "SELECT u.*, u.user_gender, u.user_custom_title, u.user_level, u.user_birthday, p.*, pt.post_text, pt.post_subject, pt.bbcode_uid, u.reputation, u.warnings, u.user_level
FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt
WHERE p.topic_id = $topic_id
$limit_posts_time
AND pt.post_id = p.post_id
AND u.user_id = p.poster_id
ORDER BY p.post_time $post_time_order
LIMIT $start, ".$board_config['posts_per_page'];
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Could not obtain post/user information.", '', __LINE__, __FILE__, $sql);
}
$postrow = array();
if ($row = $db->sql_fetchrow($result))
{
do
{
$postrow[] = $row;
}
while ($row = $db->sql_fetchrow($result));
$db->sql_freeresult($result);
$total_posts = count($postrow);
}
else
{
include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
sync('topic', $topic_id);
message_die(GENERAL_MESSAGE, $lang['No_posts_topic']);
}
$resync = FALSE;
if ($forum_topic_data['topic_replies'] + 1 < $start + count($postrow))
{
$resync = TRUE;
}
elseif ($start + $board_config['posts_per_page'] > $forum_topic_data['topic_replies'])
{
$row_id = intval($forum_topic_data['topic_replies']) % intval($board_config['posts_per_page']);
if ($postrow[$row_id]['post_id'] != $forum_topic_data['topic_last_post_id'] || $start + count($postrow) < $forum_topic_data['topic_replies'])
{
$resync = TRUE;
}
}
elseif (count($postrow) < $board_config['posts_per_page'])
{
$resync = TRUE;
}
if ($resync)
{
include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
sync('topic', $topic_id);
$result = $db->sql_query('SELECT COUNT(post_id) AS total FROM ' . POSTS_TABLE . ' WHERE topic_id = ' . $topic_id);
$row = $db->sql_fetchrow($result);
$total_replies = $row['total'];
}
$sql = "SELECT *
FROM " . RANKS_TABLE . "
ORDER BY rank_special, rank_min";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Could not obtain ranks information.", '', __LINE__, __FILE__, $sql);
}
$ranksrow = array();
while ( $row = $db->sql_fetchrow($result) )
{
$ranksrow[] = $row;
}
$db->sql_freeresult($result);
////////////democracy/////////////
//
// Get ban data
//
$sql = 'SELECT ban_userid
FROM ' . BANLIST_TABLE;
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Couldn't obtain banlist information", "", __LINE__, __FILE__, $sql);
}
while ( $row = $db->sql_fetchrow($result) )
{
$banned[$row['ban_userid']] = true;
}
/////////////////////////////////
//
// Define censored word matches
//
$orig_word = array();
$replacement_word = array();
obtain_word_list($orig_word, $replacement_word);
//
// Censor topic title
//
if ( count($orig_word) )
{
$topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
}
//
// Was a highlight request part of the URI?
//
$highlight_match = $highlight = '';
if (isset($HTTP_GET_VARS['highlight']))
{
// Split words and phrases
$words = explode(' ', trim(htmlspecialchars($HTTP_GET_VARS['highlight'])));
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($HTTP_GET_VARS['highlight']);
// Begin modification, maded by Yo mod
define(LOC_E, strtolower('ĺ'));
$highlight_match = str_replace(LOC_E, '['.LOC_E.',¨,¸]', $highlight_match);
// End modification, maded by Yo mod
$highlight_match = phpbb_rtrim($highlight_match, "\\");
}
//
// Post, reply and other URL generation for
// templating vars
//
$new_topic_url = append_sid("posting.$phpEx?mode=newtopic&" . POST_FORUM_URL . "=$forum_id");
$reply_topic_url = append_sid("posting.$phpEx?mode=reply&" . POST_TOPIC_URL . "=$topic_id");
$view_forum_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id");
$view_prev_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&view=previous");
$view_next_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&view=next");
$view_cat_url = append_sid("index.$phpEx?" . POST_CAT_URL . "=$cat_id");
//
// Mozilla navigation bar
//
$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
);
// özel ban by emrag
$userid = $userdata['user_id'];
$sql = "SELECT user_can_post
FROM " . USERS_TABLE . "
WHERE user_id = $userid";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_MESSAGE, 'Could not obtain user_can_post data');
}
$row = $db->sql_fetchrow($result);
$user_can_post = $row['user_can_post'];
if (!$user_can_post)
{
$post_info['forum_status'] = FORUM_LOCKED;
}
// özel ban by emrag
if(!$user_can_post)
{
$reply_img = $images['ban'];
$reply_alt = $lang['Ban'];
$post_img = $images['ban'];
$post_alt = $lang['Ban'];
}
else
{
$reply_img = ( $forum_topic_data['forum_status'] == FORUM_LOCKED || $forum_topic_data['topic_status'] == TOPIC_LOCKED ) ? $images['reply_locked'] : $images['reply_new'];
$reply_alt = ( $forum_topic_data['forum_status'] == FORUM_LOCKED || $forum_topic_data['topic_status'] == TOPIC_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'];
}
//
// Set a cookie for this topic
//
//START MOD Keep_unread_2 * $topic_last_read is known
//Reached the last post in a topic with unread posts
if ($topic_last_post_id == $postrow[($total_posts-1)]['post_id'])
{
//Read up to time of retrieval of this topic
$board_config['tracking_unreads'][$topic_id] = time();
}
//Reading a page, but not the last one, in a topic with new posts
elseif (isset($board_config['tracking_unreads'][$topic_id]))
{
//Set the highest of current topic_last_read and time of last post on page
$board_config['tracking_unreads'][$topic_id] = max($topic_last_read, $postrow[($total_posts-1)]['post_time']);
}
write_cookies($userdata); //Save
//END MOD Keep_unread_2
//
// Load templates
//
$template->set_filenames(array(
'body' => 'viewtopic_body.tpl')
);
// Begin Simple Subforums MOD
$all_forums = array();
make_jumpbox_ref('viewforum.'.$phpEx, $forum_id, $all_forums);
$parent_id = 0;
for( $i = 0; $i < count($all_forums); $i++ )
{
if( $all_forums[$i]['forum_id'] == $forum_id )
{
$parent_id = $all_forums[$i]['forum_parent'];
}
}
if( $parent_id )
{
for( $i = 0; $i < count($all_forums); $i++ )
{
if( $all_forums[$i]['forum_id'] == $parent_id )
{
$template->assign_vars(array(
'PARENT_FORUM' => 1,
'U_VIEW_PARENT_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL .'=' . $all_forums[$i]['forum_id']),
'PARENT_FORUM_NAME' => $all_forums[$i]['forum_name'],
));
}
}
}
// End Simple Subforums MOD
//
// Output page header
//
// Start add - Topic in Who is online MOD
define('SHOW_ONLINE', true);
// End add - Topic in Who is online MOD
$page_title = $lang['View_topic'] .' - ' . $topic_title;
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
//
// User authorisation levels output
//
$s_auth_can = ( ( $is_auth['auth_post'] ) ? $lang['Rules_post_can'] : $lang['Rules_post_cannot'] ) . '
';
$s_auth_can .= ( ( $is_auth['auth_reply'] ) ? $lang['Rules_reply_can'] : $lang['Rules_reply_cannot'] ) . '
';
$s_auth_can .= ( ( $is_auth['auth_edit'] ) ? $lang['Rules_edit_can'] : $lang['Rules_edit_cannot'] ) . '
';
$s_auth_can .= ( ( $is_auth['auth_delete'] ) ? $lang['Rules_delete_can'] : $lang['Rules_delete_cannot'] ) . '
';
$s_auth_can .= ( ( $is_auth['auth_vote'] ) ? $lang['Rules_vote_can'] : $lang['Rules_vote_cannot'] ) . '
';
$topic_mod = '';
if ( $is_auth['auth_mod'] )
{
$s_auth_can .= sprintf($lang['Rules_moderate'], "', '');
$topic_mod .= " ';
// [begin] Topics LifeTime
$template->assign_block_vars('switch_topic_mod', array());
$lifetime_time = array(0, 1*86400, 7*86400, 14*86400, 30*86400);
$lifetime_time_text = array($lang['Lifetime_now'], $lang['Lifetime_1_day'], $lang['Lifetime_7_days'], $lang['Lifetime_2_weeks'], $lang['Lifetime_1_month']);
$lifetime_select = '';
$sql = "SELECT * FROM " . TOPICS_LIFETIME_TABLE . " WHERE topic_id='$topic_id'";
$result = $db->sql_query($sql) or message_die(GENERAL_MESSAGE, 'Error getting lifetime data', '', __LINE__, __FILE__, $sql);
if ($db->sql_numrows($result))
{
$row = $db->sql_fetchrow($result);
$lifetime_expires = sprintf($lang['Lifetime_expires'], create_date($board_config['default_dateformat'], $row['topic_lifetime'], $board_config['board_timezone']));
$template->assign_block_vars('switch_topic_mod.switch_lifetime_expires', array());
$template->assign_vars(array('LIFETIME_EXPIRES' => $lifetime_expires));
}
// [end] Topics LifeTime
$topic_mod .= " ';
$topic_mod .= ( $forum_topic_data['topic_status'] == TOPIC_UNLOCKED ) ? " ' : " ';
$topic_mod .= " ';
// [begin] Mass Delete Posts (From Topic) Mod
$topic_mod .= " ';
$template->assign_block_vars('switch_topic_mod', array());
// [end] Mass Delete Posts (From Topic) Mod
//-- mod : merge -----------------------------------------------------------------------------------
//-- add
$topic_mod .= ' ';
//-- fin mod : merge -------------------------------------------------------------------------------
}
//
// Topic watch information
//
$s_watching_topic = '';
if ( $can_watch_topic )
{
if ( $is_watching_topic )
{
$s_watching_topic = "' . $lang['Stop_watching_topic'] . '';
$s_watching_topic_img = ( isset($images['topic_un_watch']) ) ? "' : '';
}
else
{
$s_watching_topic = "' . $lang['Start_watching_topic'] . '';
$s_watching_topic_img = ( isset($images['Topic_watch']) ) ? "' : '';
}
}
//
// 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("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&postdays=$post_days&postorder=$post_order&highlight=$highlight", $total_replies, $board_config['posts_per_page'], $start) : generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&postdays=$post_days&postorder=$post_order", $total_replies, $board_config['posts_per_page'], $start);
//
// Send vars to template
//
$template->assign_vars(array(
'FORUM_ID' => $forum_id,
'FORUM_NAME' => $forum_name,
'CAT_TITLE' => $cat_title,
'TOPIC_ID' => $topic_id,
'TOPIC_TITLE' => $topic_title,
'PAGINATION' => $pagination,
'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / intval($board_config['posts_per_page']) ) + 1 ), ceil( $total_replies / intval($board_config['posts_per_page']) )),
'POST_IMG' => $post_img,
'REPLY_IMG' => $reply_img,
'L_AUTHOR' => $lang['Author'],
'L_MESSAGE' => $lang['Message'],
'L_POSTED' => $lang['Posted'],
'L_POST_SUBJECT' => $lang['Post_subject'],
'L_VIEW_NEXT_TOPIC' => $lang['View_next_topic'],
'L_VIEW_PREVIOUS_TOPIC' => $lang['View_previous_topic'],
'L_POST_NEW_TOPIC' => $post_alt,
'L_POST_REPLY_TOPIC' => $reply_alt,
'L_BACK_TO_TOP' => $lang['Back_to_top'],
'L_DISPLAY_POSTS' => $lang['Display_posts'],
'L_LOCK_TOPIC' => $lang['Lock_topic'],
'L_UNLOCK_TOPIC' => $lang['Unlock_topic'],
'L_MOVE_TOPIC' => $lang['Move_topic'],
'L_SPLIT_TOPIC' => $lang['Split_topic'],
'L_DELETE_TOPIC' => $lang['Delete_topic'],
'L_GOTO_PAGE' => $lang['Goto_page'],
// [begin] Topics LifeTime
'L_LIFETIME' => $lang['Lifetime'],
'L_SET_LIFETIME' => $lang['Set_lifetime'],
'L_DELETE_LIFETIME' => $lang['Delete_lifetime'],
// [end] Topics LifeTime
// [begin] Mass Delete Posts (From Topic) Mod
'L_DELETE_POSTS' => $lang['Delete_posts'],
// [end] Mass Delete Posts (From Topic) Mod
'S_TOPIC_LINK' => POST_TOPIC_URL,
'S_SELECT_POST_DAYS' => $select_post_days,
'S_SELECT_POST_ORDER' => $select_post_order,
'S_POST_DAYS_ACTION' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $topic_id . "&start=$start"),
'S_AUTH_LIST' => $s_auth_can,
'S_TOPIC_ADMIN' => $topic_mod,
'S_WATCH_TOPIC' => $s_watching_topic,
'S_WATCH_TOPIC_IMG' => $s_watching_topic_img,
// [begin] Topics LifeTime
'S_SELECT_LIFETIME' => $lifetime_select,
'S_LIFETIME_ACTION' => "modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&mode=topics_lifetime&sid=" . $userdata['session_id'],
// [end] Topics LifeTime
// [begin] Mass Delete Posts (From Topic) Mod
'S_DELETE_POSTS_ACTION' => "modcp.$phpEx?" . POST_TOPIC_URL . "=$topic_id&mode=delete_posts&sid=" . $userdata['session_id'],
// [end] Mass Delete Posts (From Topic) Mod
'U_VIEW_TOPIC' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&start=$start&postdays=$post_days&postorder=$post_order&highlight=$highlight"),
'U_VIEW_FORUM' => $view_forum_url,
'U_VIEW_CAT' => $view_cat_url,
'U_VIEW_OLDER_TOPIC' => $view_prev_topic_url,
'U_VIEW_NEWER_TOPIC' => $view_next_topic_url,
'U_POST_NEW_TOPIC' => $new_topic_url,
'U_POST_REPLY_TOPIC' => $reply_topic_url)
);
//
// Does this topic contain a poll?
//
if ( !empty($forum_topic_data['topic_vote']) )
{
$s_hidden_fields = '';
$sql = "SELECT vd.vote_id, vd.vote_text, vd.vote_start, vd.vote_length, vr.vote_option_id, vr.vote_option_text, vr.vote_result
FROM " . VOTE_DESC_TABLE . " vd, " . VOTE_RESULTS_TABLE . " vr
WHERE vd.topic_id = $topic_id
AND vr.vote_id = vd.vote_id
ORDER BY vr.vote_option_id ASC";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Could not obtain vote data for this topic", '', __LINE__, __FILE__, $sql);
}
if ( $vote_info = $db->sql_fetchrowset($result) )
{
$db->sql_freeresult($result);
$vote_options = count($vote_info);
$vote_id = $vote_info[0]['vote_id'];
$vote_title = $vote_info[0]['vote_text'];
$sql = "SELECT vote_id
FROM " . VOTE_USERS_TABLE . "
WHERE vote_id = $vote_id
AND vote_user_id = " . intval($userdata['user_id']);
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Could not obtain user vote data for this topic", '', __LINE__, __FILE__, $sql);
}
$user_voted = ( $row = $db->sql_fetchrow($result) ) ? TRUE : 0;
$db->sql_freeresult($result);
if ( isset($HTTP_GET_VARS['vote']) || isset($HTTP_POST_VARS['vote']) )
{
$view_result = ( ( ( isset($HTTP_GET_VARS['vote']) ) ? $HTTP_GET_VARS['vote'] : $HTTP_POST_VARS['vote'] ) == 'viewresult' ) ? TRUE : 0;
}
else
{
$view_result = 0;
}
$poll_expired = ( $vote_info[0]['vote_length'] ) ? ( ( $vote_info[0]['vote_start'] + $vote_info[0]['vote_length'] < time() ) ? TRUE : 0 ) : 0;
if ( $user_voted || $view_result || $poll_expired || !$is_auth['auth_vote'] || $forum_topic_data['topic_status'] == TOPIC_LOCKED )
{
// Colour on Poll Results MOD, By Manipe (Begin)
$sql1 = "SELECT vote_option_id
FROM " . VOTE_USERS_TABLE . "
WHERE vote_user_id = '" . $userdata['user_id'] . "'
AND vote_id = '" . $vote_id . "'";
if ( !($result1 = $db->sql_query($sql1)) )
{
message_die(GENERAL_ERROR, 'Could not obtain user voted information', '', __LINE__, __FILE__, $sql);
}
$row1 = $db->sql_fetchrow($result1);
$voted_option_id = $row1['vote_option_id'];
$db->sql_freeresult($result1);
// Colour on Poll Results MOD, By Manipe (End)
$template->set_filenames(array(
'pollbox' => 'viewtopic_poll_result.tpl')
);
$vote_results_sum = 0;
for($i = 0; $i < $vote_options; $i++)
{
$vote_results_sum += $vote_info[$i]['vote_result'];
}
$vote_graphic = 0;
$vote_graphic_max = count($images['voting_graphic']);
for($i = 0; $i < $vote_options; $i++)
{
// Colour on Poll Results MOD, By Manipe (Begin)
$vote_percent = ( $vote_results_sum > 0 ) ? $vote_info[$i]['vote_result'] / $vote_results_sum : 0;
$vote_graphic_length = round($vote_percent * $board_config['vote_graphic_length']);
// Colour on Poll Results MOD, By Manipe (End)
if ( count($orig_word) )
{
$vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
}
// Colour on Poll Results MOD, By Manipe (Begin)
if ($voted_option_id == ($i+1)){
$vote_color = 'purple';
}
else{
if ( $vote_percent <= 0.3 ){
$vote_color = 'green';
}
else if ( ($vote_percent > 0.3) && ($vote_percent <= 0.6) ){
$vote_color = 'blue';
}
else if ( $vote_percent > 0.6 ){
$vote_color = 'red';
}
}
// Colour on Poll Results MOD, By Manipe (End)
$template->assign_block_vars("poll_option", array(
'POLL_OPTION_CAPTION' => $vote_info[$i]['vote_option_text'],
'POLL_OPTION_RESULT' => $vote_info[$i]['vote_result'],
'POLL_OPTION_PERCENT' => sprintf("%.1d%%", ($vote_percent * 100)),
// Colour on Poll Results MOD, By Manipe (Begin)
'POLL_OPTION_COLOR' => $vote_color,
// Colour on Poll Results MOD, By Manipe (End)
'POLL_OPTION_IMG' => $vote_graphic_img,
'POLL_OPTION_IMG_WIDTH' => $vote_graphic_length)
);
}
$template->assign_vars(array(
'L_TOTAL_VOTES' => $lang['Total_votes'],
'TOTAL_VOTES' => $vote_results_sum)
);
}
else
{
$template->set_filenames(array(
'pollbox' => 'viewtopic_poll_ballot.tpl')
);
for($i = 0; $i < $vote_options; $i++)
{
if ( count($orig_word) )
{
$vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
}
$template->assign_block_vars("poll_option", array(
'POLL_OPTION_ID' => $vote_info[$i]['vote_option_id'],
'POLL_OPTION_CAPTION' => $vote_info[$i]['vote_option_text'])
);
}
$template->assign_vars(array(
'L_SUBMIT_VOTE' => $lang['Submit_vote'],
'L_VIEW_RESULTS' => $lang['View_results'],
'U_VIEW_RESULTS' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&postdays=$post_days&postorder=$post_order&vote=viewresult"))
);
$s_hidden_fields = '';
}
if ( count($orig_word) )
{
$vote_title = preg_replace($orig_word, $replacement_word, $vote_title);
}
$s_hidden_fields .= '';
$template->assign_vars(array(
'POLL_QUESTION' => $vote_title,
'S_HIDDEN_FIELDS' => $s_hidden_fields,
'S_POLL_ACTION' => append_sid("posting.$phpEx?mode=vote&" . POST_TOPIC_URL . "=$topic_id"))
);
$template->assign_var_from_handle('POLL_DISPLAY', 'pollbox');
}
}
//
// Update the topic view counter
//
$sql = "UPDATE " . TOPICS_TABLE . "
SET topic_views = topic_views + 1
WHERE topic_id = $topic_id";
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Could not update topic views.", '', __LINE__, __FILE__, $sql);
}
// [begin] Extended Quick Reply Form mod
if ( ($is_auth['auth_reply'] && !(($forum_topic_data['forum_status'] == FORUM_LOCKED) || ($forum_topic_data['topic_status'] == TOPIC_LOCKED)) ) || ($userdata['user_level'] == ADMIN) || ($userdata['user_level'] == GLOBAL_MOD) )
{
$quick_reply = true;
}
else
{
$quick_reply = false;
}
// [end] Extended Quick Reply Form mod
// Start add - Show usergroups MOD
include($phpbb_root_path . 'includes/functions_usergroup.'.$phpEx);
// End add - Show usergroups MOD
//Get Sig and Av ignore settings
$sql = "SELECT hid_id FROM " . HIDE_TABLE . " WHERE user_id = " . $userdata[user_id];
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error retrieving ignored sig and av data', '', __LINE__, __FILE__, $sql);
}
$hid_ids = array();
while( $row = $db->sql_fetchrow($result) )
{
$hid_ids[$row['hid_id']] = true;
}
//
// Okay, let's do the loop, yeah come on baby let's do the loop
// and it goes like this ...
//
$user_id = $userdata['user_id'];
$counter = 0;
for($i = 0; $i < $total_posts; $i++)
{
$post_number = $i+$start;
$post_number = $post_number+1;
$post_id = $postrow[$i]['post_id'];
$poster_id = $postrow[$i]['user_id'];
if ( $user_id != ANONYMOUS )
{
$sql = "SELECT user_ignore
FROM " . IGNORE_TABLE . "
WHERE user_id = $user_id
AND user_ignore = $poster_id";
if( !$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Could not get data from ignore table', __LINE__, __FILE__, $sql);
}
$post_ignored = $db->sql_numrows($result);
}
else
{
$post_ignored = 0;
}
$counter++;
### note: normally, the user_id (member no.) starts with "2" (phpBB 2.0.4).
### if you want to start to count with "2" use the following code:
## $poster_uin = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Member_uin'] . ': '. $postrow[$i]['user_id'] : '';
### if you want to start to count with "1" add this line:
### (of course, you change "-1" to any other digit ("+292" or "2")... because if you
### delete an user the user_id will be still occupied
$poster_uin = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Member_uin'] . ': ' . sprintf($postrow[$i]['user_id']-1) : '';
$poster = ( $poster_id == ANONYMOUS ) ? $lang['Guest'] : $postrow[$i]['username'];
if (( $post_ignored > 0 ) && ( $poster_id != ANONYMOUS ) && ( $post_bypass != $postrow[$i]['post_id'] ) && ($postrow[$i]['user_level'] != ADMIN) && ($postrow[$i]['user_level'] != MOD) && ($postrow[$i]['user_level'] != GLOBAL_MOD))
{
$post_date = create_date($board_config['default_dateformat'], $postrow[$i]['post_time'], $board_config['board_timezone']);
//
// Define the little post icon
//
if ( $userdata['session_logged_in'] && $postrow[$i]['post_time'] > $userdata['user_lastvisit'] && $postrow[$i]['post_time'] > $topic_last_read )
{
$mini_post_img = $images['icon_minipost_new'];
$mini_post_alt = $lang['New_post'];
}
else
{
$mini_post_img = $images['icon_minipost'];
$mini_post_alt = $lang['Post'];
}
$message = $lang['Post_user_ignored'] . ' ' . sprintf($lang['Click_view_ignore'], '', '');
$ignore = '';
$poster_rank = '';
$rank_image = '';
$custom_title = '';
$poster_joined = '';
$poster_posts = '';
$poster_from = '';
$poster_avatar = '';
$poster_member = '';
$post_subject = '';
$user_sig = '';
$l_edited_by = '';
$mini_post_img = '';
$search_img = '';
$search = '';
$edit_img = '';
$edit = '';
$quote_img = '';
$quote = '';
$ip_img = '';
$ip = '';
$delpost_img = '';
$delpost = '';
$profile_img = '';
$profile = '';
$pm_img = '';
$pm = '';
$email_img = '';
$email = '';
$www_img = '';
$www = '';
$icq_status_img = '';
$icq_img = '';
$icq = '';
$aim_img = '';
$aim = '';
$msn_img = '';
$msn = '';
$yim_img = '';
$yim = '';
}
else
{
$post_date = create_date($board_config['default_dateformat'], $postrow[$i]['post_created'], $board_config['board_timezone']);
$poster_posts = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Posts'] . ': ' . $postrow[$i]['user_posts'] : '';
$poster_from = ( $postrow[$i]['user_from'] && $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Location'] . ': ' . $postrow[$i]['user_from'] : '';
$poster_joined = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Joined'] . ': ' . create_date($lang['DATE_FORMAT'], $postrow[$i]['user_regdate'], $board_config['board_timezone']) : '';
$poster_avatar = '';
if ( $postrow[$i]['user_avatar_type'] && $poster_id != ANONYMOUS && $postrow[$i]['user_allowavatar'] )
{
switch( $postrow[$i]['user_avatar_type'] )
{
case USER_AVATAR_UPLOAD:
$poster_avatar = ( $board_config['allow_avatar_upload'] ) ? '' : '';
break;
case USER_AVATAR_REMOTE:
$poster_avatar = ( $board_config['allow_avatar_remote'] ) ? '' : '';
break;
case USER_AVATAR_GALLERY:
$poster_avatar = ( $board_config['allow_avatar_local'] ) ? '' : '';
break;
}
}
if( $userdata['user_level'] == ADMIN)
{
$temp_url=append_sid('change_author.php?pid='.$postrow[$i]['post_id']);
$change_author_img = '';
$change_author = '' . $lang['change_author'] . '';
}
else
{
$change_author_img = '';
$change_author = '';
}
// Default avatar MOD, By Manipe (Begin)
if ((!$poster_avatar) && ($board_config['default_avatar_set'] != 3)){
if (($board_config['default_avatar_set'] == 0) && ($poster_id == -1) && ($board_config['default_avatar_guests_url'])){
$poster_avatar = '';
}
else if (($board_config['default_avatar_set'] == 1) && ($poster_id != -1) && ($board_config['default_avatar_users_url']) ){
$poster_avatar = '';
}
else if ($board_config['default_avatar_set'] == 2){
if (($poster_id == -1) && ($board_config['default_avatar_guests_url'])){
$poster_avatar = '';
}
else if (($poster_id != -1) && ($board_config['default_avatar_users_url'])){
$poster_avatar = '';
}
}
}
// Default avatar MOD, By Manipe (End)
//
//START MOD Keep_Unread_2 * Define the little post icon
//
if ( $postrow[$i]['post_time'] > $topic_last_read )
{
$mini_post_img = $images['icon_minipost_new'];
$mini_post_alt = $lang['New_post'];
}
else
{
$mini_post_img = $images['icon_minipost'];
$mini_post_alt = $lang['Post'];
}
//END MOD Keep_unread_2
$mini_post_url = append_sid("viewtopic.$phpEx?" . POST_POST_URL . '=' . $postrow[$i]['post_id']) . '#' . $postrow[$i]['post_id'];
//
// Generate ranks, set them to empty string initially.
//
$poster_rank = '';
$rank_image = '';
// [start] Birthday [Olympus style]
$poster_age = '';
$user_birthday = '';
// [end] Birthday [Olympus style]
// Start add - Gender MOD
$gender_image = '';
// End add - Gender MOD
///////////democracy////////////////
$user_warnings = '';
$user_reputation = '';
////////////////////////////////
if ( $postrow[$i]['user_id'] == ANONYMOUS )
{
} else if ( isset($userdata['user_birthday']) && isset($rankcfg[RANK_CFG_BIRTHDAY.',1']) && create_date('md', time(), $postrow[$i]['user_timezone']) == realdate('md',$postrow[$i]['user_birthday']) ) {
for($j = 0; $j < count($ranksrow); $j++)
{
if ( $rankcfg[RANK_CFG_BIRTHDAY.',1'] == $ranksrow[$j]['rank_id'] && $ranksrow[$j]['rank_special'] )
{
$poster_rank = $ranksrow[$j]['rank_title'];
$rank_image = ( $ranksrow[$j]['rank_image'] ) ? '
' : '';
}
}
}
else if ( $postrow[$i]['user_rank'] )
{
for($j = 0; $j < count($ranksrow); $j++)
{
if ( $postrow[$i]['user_rank'] == $ranksrow[$j]['rank_id'] && $ranksrow[$j]['rank_special'] )
{
$poster_rank = $ranksrow[$j]['rank_title'];
$rank_image = ( $ranksrow[$j]['rank_image'] ) ? '
' : '';
}
}
}
else
{
for($j = 0; $j < count($ranksrow); $j++)
{
if ( $postrow[$i]['user_posts'] >= $ranksrow[$j]['rank_min'] && !$ranksrow[$j]['rank_special'] && $ranksrow[$j]['rankset_id'] == $postrow[$i]['user_rankset_id'] )
{
$poster_rank = $ranksrow[$j]['rank_title'];
$rank_image = ( $ranksrow[$j]['rank_image'] ) ? '
' : '';
}
}
}
if ( !empty($postrow[$i]['user_custom_title']) )
{
switch( $board_config['custom_title_mode'] )
{
case CUSTOM_TITLE_MODE_INDEPENDENT:
$custom_title = $postrow[$i]['user_custom_title'] . '
';
break;
case CUSTOM_TITLE_MODE_REPLACE_RANK:
$poster_rank = $postrow[$i]['user_custom_title'];
break;
case CUSTOM_TITLE_MODE_REPLACE_BOTH:
$poster_rank = $postrow[$i]['user_custom_title'];
$rank_image = '';
break;
default:
break;
}
}
//
// Handle anon users posting with usernames
//
if ( $poster_id == ANONYMOUS && $postrow[$i]['post_username'] != '' )
{
$poster = $postrow[$i]['post_username'];
$poster_rank = $lang['Guest'];
}
$temp_url = '';
if ( $poster_id != ANONYMOUS )
{
if ($userdata['session_logged_in'])
{
$temp_url = append_sid("viewtopic.$phpEx?hide=hide&t=" . $postrow[$i]['topic_id'] . "&hidee_id=" . $postrow[$i]['user_id']);
$hide_img = '';
$hide = '' . $lang['Hide_sigav'] . '';
}
else
{
$temp_url = "";
$hide_img = "";
$hide = "";
}
////////////////////////democracy//////
if ( $board_config['reputation_enabled'] )
{
$thumb_up_img = '';
$thumb_dn_img = '';
$temp_url = "profile.$phpEx?mode=reputation&";
if ( $postrow[$i]['reputation'] > 0 || $postrow[$i]['warnings'] > 0)
{
$user_reputation = '' . $lang['Reputation'] . '' . ': ' . $postrow[$i]['reputation'];
}
else
{
$user_reputation = $lang['Reputation'] . ': ' . $postrow[$i]['reputation'];
}
if ( $postrow[$i]['user_id'] != $userdata['user_id'] && $userdata['user_id'] != ANONYMOUS )
{
$user_reputation .= ' ' . $thumb_up_img . ' ' . $thumb_dn_img . '' . '
';
}
$user_reputation .= '';
}
if ( $board_config['warnings_enabled'] )
{
$warnings = $postrow[$i]['warnings'];
if ( $banned[$postrow[$i]['user_id']] )
{
$user_ban = true;
$warnings = $warnings - 1;
}
else
{
$user_ban = false;
}
if ( $postrow[$i]['warnings'] > 0 )
{
$temp_url = append_sid("profile.$phpEx?mode=reputation&" . POST_USERS_URL . '=' . $postrow[$i]['user_id'] . '&m=0');
$user_warnings = '