sql_query($q);
$hof_data = $db->sql_fetchrowset($r);
#====
#==== Author: aUsTiN [austin@phpbb-amod.com] [http://phpbb-amod.com] === |
#==== End: ==== Activity Mod Plus ====================================== |
#======================================================================= |
// Cache Posts
// Here you can change the style of the CPS indicators
$CPS_Indicator = array(
'cached' => '•',
'not_cached' => '•',
'error' => '•',
'dont_cache' => '•',
'off_but_cached' => '•',
'off' => '•');
// Cache Posts
//
// Start initial var setup
//
$topic_id = $post_id = 0;
if ( isset($HTTP_GET_VARS[POST_TOPIC_URL]) )
{
$topic_id = intval($HTTP_GET_VARS[POST_TOPIC_URL]);
}
else if ( isset($HTTP_GET_VARS['topic']) )
{
$topic_id = intval($HTTP_GET_VARS['topic']);
}
if ( isset($HTTP_GET_VARS[POST_POST_URL]))
{
$post_id = intval($HTTP_GET_VARS[POST_POST_URL]);
}
$start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
$start = ($start < 0) ? 0 : $start;
$download = ( isset($HTTP_GET_VARS['download']) ) ? $HTTP_GET_VARS['download'] : '';
if (!$topic_id && !$post_id)
{
message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
}
//
// 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' )
{
if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) || isset($HTTP_GET_VARS['sid']) )
{
$session_id = isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) ? $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid'] : $HTTP_GET_VARS['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 = '$session_id'
AND u.user_id = s.session_user_id
AND p.topic_id = $topic_id
AND p.post_time >= u.user_lastvisit
AND p.post_draft = 0
ORDER BY p.post_time ASC
LIMIT 1";
// start mod save posts as drafts (and end mod too): added an AND constraint in the foregoing sql definition that post_draft be zero (i.e. that the post not just be a draft)
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 = $row['post_id'];
if (isset($HTTP_GET_VARS['sid']))
{
redirect("viewtopic.$phpEx?sid=$session_id&" . POST_POST_URL . "=$post_id#$post_id");
}
else
{
redirect("viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id");
}
}
}
redirect(append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_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
AND t.topic_last_post_id > 0
ORDER BY t.topic_last_post_id $sql_ordering
LIMIT 1";
// start mod save posts as drafts (and end mod too): added an AND constraint in the foregoing sql definition that last_post_id be greater than 0 (i.e. that the topic not just be a new draft topic not yet submitted)
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']);
}
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 AND p2.post_draft = 0";
// start mod save posts as drafts (and end too)...added constraint at end of previous line that post_draft be 0 (i.e. that the post not be a draft)
$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, f.min_posts_to_view, f.max_posts_to_view ORDER BY p.post_id ASC";
// start mod tabulated survey at topic head (and end too)...added reference to t.topic_survey in next line
// mod topic mod add to sql query
//mod topic description add to sql query
$sql = "SELECT t.topic_id, t.topic_title, t.topic_description, t.topic_descmod, t.topic_status,t.topic_noguest, t.topic_adminedit, t.topic_password, t.topic_pass_level, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, t.topic_first_post_id, t.topic_reg, t.topic_survey, t.topic_last_post_id, t.topic_cache_lock, 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.min_posts_to_view, f.max_posts_to_view" . $count_sql . "
FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f" . $join_sql_table . "
WHERE $join_sql
AND f.forum_id = t.forum_id
$order_sql";
//-- mod : calendar ------------------------------------------------------------
//-- add
$fields = array('f.auth_cal', 't.topic_first_post_id', 't.topic_calendar_time', 't.topic_calendar_duration');
$sql = preg_replace('/^SELECT /', 'SELECT ' . implode(', ', $fields) . ', ', $sql);
if ( $post_id )
{
$sql = preg_replace('/GROUP BY /', 'GROUP BY ' . implode(', ', $fields) . ', ', $sql);
}
//-- fin mod : calendar --------------------------------------------------------
attach_setup_viewtopic_auth($order_sql, $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 session management
//
$userdata = session_pagestart($user_ip, $forum_id);
init_userprefs($userdata);
//
// End session management
//
//-- mod : calendar ------------------------------------------------------------
//-- add
$user->set();
$calendar_api->set();
$calendar_front_title = new front_calendar();
//-- fin mod : calendar --------------------------------------------------------
if ( $download )
{
$sql_download = ( $download != -1 ) ? " AND p.post_id = " . intval($download) . " " : '';
$orig_word = array();
$replacement_word = array();
obtain_word_list($orig_word, $replacement_word);
$sql = "SELECT u.*, u.user_birthday, u.birthday_display, u.user_zodiac, u.user_rank_theme, u.user_custom_rank_status, u.user_custom_rank, p.*, pt.post_text, pt.post_subject, pt.bbcode_uid
FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt
WHERE p.topic_id = $topic_id
$sql_download
AND pt.post_id = p.post_id
AND u.user_id = p.poster_id
ORDER BY p.post_time ASC, p.post_id ASC";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Could not create download stream for post.", '', __LINE__, __FILE__, $sql);
}
$download_file = '';
$is_auth_read = array();
while ( $row = $db->sql_fetchrow($result) )
{
$is_auth_read = auth(AUTH_ALL, $row['forum_id'], $userdata);
$poster_id = $row['user_id'];
$poster = ( $poster_id == ANONYMOUS ) ? $lang['Guest'] : $row['username'];
$post_date = create_date($board_config['default_dateformat'], $row['post_time'], $board_config['board_timezone']);
$post_subject = ( $row['post_subject'] != '' ) ? $row['post_subject'] : '';
$bbcode_uid = $row['bbcode_uid'];
$message = $row['post_text'];
$message = strip_tags($message);
$message = preg_replace("/\[.*?:$bbcode_uid:?.*?\]/si", '', $message);
$message = preg_replace('/\[url\]|\[\/url\]/si', '', $message);
$message = preg_replace('/\:[0-9a-z\:]+\]/si', ']', $message);
$message = unprepare_message($message);
$message = preg_replace('/(/', '(', $message);
$message = preg_replace('/)/', ')', $message);
$message = preg_replace('/:/', ':', $message);
$message = preg_replace('/[/', '[', $message);
$message = preg_replace('/]/', ']', $message);
$message = preg_replace('/{/', '{', $message);
$message = preg_replace('/}/', '}', $message);
if (count($orig_word))
{
$post_subject = preg_replace($orig_word, $replacement_word, $post_subject);
$message = str_replace('\"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $message . '<'), 1, -1));
}
$break = "\n\r";
$line = '-----------------------------------';
$download_file .= $break.$line.$break.$poster.$break.$post_date.$break.$break.$post_subject.$break.$line.$break.$message.$break;
}
$disp_folder = ( $download == -1 ) ? 'Topic_'.$topic_id : 'Post_'.$download;
if (!$is_auth_read['auth_read'])
{
$download_file = sprintf($lang['Sorry_auth_read'], $is_auth_read['auth_read_type']);
$disp_folder = 'Download';
}
$filename = $board_config['sitename']."_".$disp_folder."_".date("Ymd",time()).".txt";
header('Content-Type: text/x-delimtext; name="'.$filename.'"');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Content-Transfer-Encoding: plain/text');
header('Content-Length: '.strlen($download_file));
print $download_file;
exit;
}
//
// 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
//
// BEGIN Forum Auth by Post Count 1.0.0 (www.phpBBDoctor.com)
if ( !(phpbbdoctor_post_count_auth($forum_topic_data['min_posts_to_view'], $forum_topic_data['max_posts_to_view'])) )
{
message_die(GENERAL_MESSAGE, $lang['Not_Authorised']);
}
// END Forum Auth by Post Count 1.0.0 (www.phpBBDoctor.com)
// Forum Icon Mod
$sql = "SELECT forum_icon
FROM " . FORUMS_TABLE . "
WHERE forum_id = $forum_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain forums information', '', __LINE__, __FILE__, $sql);
}
$forum_row = $db->sql_fetchrow($result);
$forum_icon = $forum_row['forum_icon'];
if ( isset($HTTP_GET_VARS['mode']) && $HTTP_GET_VARS['mode'] == 'breakdown' )
{
$gen_simple_header = TRUE;
if (!$topic_id)
{
message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
}
$sql = "SELECT u.user_id, u.username, COUNT(p.poster_id) AS total, MIN(p.post_time) AS first_post
FROM " . POSTS_TABLE . " AS p, " . USERS_TABLE . " AS u
WHERE topic_id = $topic_id
AND u.user_id = p.poster_id
AND u.user_id <> " . ANONYMOUS . "
GROUP BY u.user_id
UNION
SELECT " . ANONYMOUS . ", post_username AS username, COUNT(poster_id) AS total, MIN(post_time) AS first_post
FROM phpbb_posts
WHERE topic_id = $topic_id
AND poster_id = " . ANONYMOUS . "
GROUP BY post_username
ORDER BY total DESC, first_post ASC";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not breakdown topic', '', __LINE__, __FILE__, $sql);
}
$i = 0;
$total_posts = 0;
while ( $row = $db->sql_fetchrow($result) )
{
if ( $row['user_id'] != ANONYMOUS )
{
$temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . '=' . $row['user_id']);
$username = '' . $row['username'] . '';
}
else
{
$username = ( empty($row['username']) ) ? $lang['Guest'] : $row['username'];
}
$template->assign_block_vars('posterrow', array(
'ROW_CLASS' => ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'],
'USERNAME' => $username,
'POSTS' => $row['total'])
);
$total_posts+= $row['total'];
$i++;
}
$template->assign_vars(array(
'L_CLOSE_WINDOW' => $lang['Close_window'],
'L_WHO_POSTED' => $lang['Who_has_Posted'],
'L_TOTAL' => sprintf($lang['Posts_total'], $total_posts),
'L_USERNAME' => $lang['Username'],
'L_POSTS' => $lang['Posts'])
);
$page_title = $lang['Who_has_Posted'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
$template->set_filenames(array(
'body' => 'breakdown_popup.tpl')
);
$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
}
$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']);
}
// www.phpBB-SEO.com SEO TOOLKIT BEGIN
if ( !isset($phpbb_seo->seo_url['forum'][$forum_topic_data['forum_id']]) ) {
$phpbb_seo->seo_url['forum'][$forum_topic_data['forum_id']] = $phpbb_seo->format_url($forum_name, $phpbb_seo->seo_static['forum']);
}
// www.phpBB-SEO.com SEO TOOLKIT END
// www.phpBB-SEO.com SEO TOOLKIT BEGIN
$uri = $phpbb_seo->seo_req_uri();
$postorder_redir = empty($_POST['postorder']) && empty($_GET['postorder']);
if ($_GET['postorder'] == 'asc' || $_POST['postorder'] == 'asc' ) {
$postorder_redir = TRUE;
}
$phpbb_seo->seo_start( $start, $board_config['posts_per_page'] );
$phpbb_seo->page_url = $phpbb_seo->seo_static['topic'] . $topic_id . $phpbb_seo->start . $phpbb_seo->seo_ext['topic'];
$phpbb_seo->seo_cond(!$userdata['session_logged_in'] && ( strpos($uri, "sid=" ) !== FALSE ) );
if ( $phpbb_seo->do_redir || ( $postorder_redir && strpos($uri, 'watch=') === FALSE && strpos($uri, $phpbb_seo->page_url) === FALSE ) ) {
$phpbb_seo->seo_redirect( $phpbb_seo->seo_path['phpbb_url'] . $phpbb_seo->page_url . ( ( $post_id ) ? "#$post_id" : "" ) );
}
// www.phpBB-SEO.com SEO TOOLKIT END
//
// 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_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
$sql = "DELETE $sql_priority 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_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
$sql = "UPDATE $sql_priority " . 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_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
$sql = "INSERT $sql_priority 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
//
$valid = FALSE;
if( $userdata['session_logged_in'] ) {
$sql = "SELECT p.poster_id, p.topic_id
FROM " . POSTS_TABLE . " p
WHERE p.topic_id = $topic_id
AND p.poster_id = " . $userdata['user_id'];
$resultat = $db->sql_query($sql);
$valid = $db->sql_numrows($resultat) ? TRUE : FALSE;}
$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
AND p.post_draft = 0";
// start mod save posts as drafts (and end too)...added constraint at end of next line that post_draft be 0 (i.e. that the post not be a draft)
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
//
//-- mod : IP Country Flag II ------------------------------------------
// add , u.user_cf_iso3661_1 AND ,u.user_timezone AND , u.user_from_flag_cf_iso3661_1
$sql = "SELECT u.*, u.user_phoogle_map_center, u.user_phoogle_allow, u.user_phoogle_show_me, u.user_from_flag_cf_iso3661_1, u.user_timezone, u.user_cf_iso3661_1, u.user_myspace, u.ct_miserable_user, u.user_shouts, u.user_weblog, u.user_trophies, u.ina_char_name, p.*, pt.post_text, pt.post_subject, pt.bbcode_uid, ft.flag_name, u.user_reputation, pt.scribble_string
FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt, " . FLAG_TABLE . " ft
WHERE p.topic_id = $topic_id
$limit_posts_time
AND pt.post_id = p.post_id
AND u.user_id = p.poster_id
AND ft.flag_image = u.user_from_flag
AND p.post_draft = 0
ORDER BY p.post_time $post_time_order
LIMIT $start, ".$board_config['posts_per_page'];
//-- mod : browsers list -------------------------------------------------------
//-- add
$sql = str_replace('SELECT ', 'SELECT u.user_browser, ', $sql);
//-- fin mod : browsers list ---------------------------------------------------
//-- mod : rank color system ---------------------------------------------------
//-- add
$sql = str_replace('SELECT ', 'SELECT u.user_level, u.user_color, u.user_group_id, ', $sql);
//-- fin mod : rank color system -----------------------------------------------
$cm_viewtopic->generate_columns($template,$forum_id,$sql);
// start mod save posts as drafts (and end mod too)...note that I added AND p.post_draft = 0 in the forgoing $sql definition to assure that draft posts would not be displayed in viewtopic
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Could not obtain post/user information.", '', __LINE__, __FILE__, $sql);
}
//-- end mod : IP Country Flag II ----------------------------------------------
$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);
//
// 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);
}
//
// Word hightlighter with CrackerTracker Protection Engine
// Security System powered by http://www.cback.de
//
$highlight_match = $highlight = '';
if (isset($HTTP_GET_VARS['lighter']))
{
// 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']);
$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");
// www.phpBB-SEO.com SEO TOOLKIT BEGIN
if ($userdata['session_logged_in']) {
$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");
//
// 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']
);
}
// www.phpBB-SEO.com SEO TOOLKIT END
$nav_links['up'] = array(
'url' => $view_forum_url,
'title' => $forum_name
);
if ( $forum_topic_data['forum_status'] == FORUM_LOCKED || $forum_topic_data['topic_status'] == TOPIC_LOCKED )
{
$reply_img = ( !$is_auth['auth_mod'] ) ? $images['reply_locked'] : $images['reply_new'];
$reply_alt = ( !$is_auth['auth_mod'] ) ? $lang['Topic_locked'] : $lang['Reply_to_topic'];
$post_img = ( !$is_auth['auth_mod'] ) ? $images['post_locked'] : $images['post_new'];
$post_alt = ( !$is_auth['auth_mod'] ) ? $lang['Forum_locked'] : $lang['Post_new_topic'];
}
else
{
$reply_img = $images['reply_new'];
$reply_alt = $lang['Reply_to_topic'];
$post_img = $images['post_new'];
$post_alt = $lang['Post_new_topic'];
}
//
// Set a cookie for this topic
//
if ( $userdata['session_logged_in'] )
{
$tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();
$tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : 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];
}
else if ( !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 = $userdata['user_lastvisit'];
}
if ( count($tracking_topics) >= 150 && empty($tracking_topics[$topic_id]) )
{
asort($tracking_topics);
unset($tracking_topics[key($tracking_topics)]);
}
$tracking_topics[$topic_id] = time();
setcookie($board_config['cookie_name'] . '_t', serialize($tracking_topics), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
}
//
// Load templates
//
$template->set_filenames(array(
'body' => 'viewtopic_body.tpl')
);
$all_forums = array();
make_jumpbox_ref('viewforum.'.$phpEx, $forum_id, $all_forums);
$parent_id = 0;
for($i=0; $iassign_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'],
));
}
}
}
//
// Output page header
//
// www.phpBB-SEO.com SEO TOOLKIT BEGIN - TITLE
$extra_title = ($start != 0) ? ' - ' . $lang['Page'] . ( floor( ($start / $board_config['posts_per_page']) ) + 1 ) : '';
$page_title = "$forum_name : " . $topic_title . $extra_title;
// www.phpBB-SEO.com SEO TOOLKIT END - TITLE
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
//-- mod : toolbar -------------------------------------------------------------
//-- add
if ( $can_watch_topic )
{
$uw_parm = $is_watching_topic ? 'unwatch' : 'watch';
$tlbr_more = array(
'watch' => array('link_pgm' => 'viewtopic', 'link_parms' => array(POST_TOPIC_URL => intval($topic_id), $uw_parm => 'topic', 'start' => intval($start)), 'txt' => $is_watching_topic ? 'Stop_watching_topic' : 'Start_watching_topic', 'img' => $is_watching_topic ? 'tlbr_un_watch' : 'tlbr_watch'),
);
}
build_toolbar('viewtopic', $l_privmsgs_text, $s_privmsg_new, $forum_id, $tlbr_more);
//-- fin mod : toolbar ---------------------------------------------------------
// mod topic mod add
if ( ( ( $board_config['allow_tnologguest'] && $forum_topic_data['topic_noguest'] ) || $board_config['globalnoguestt'] ) && $userdata['user_id'] == ANONYMOUS )
{
// if this is a bot we let it through... people wanted this *shrugs*
if ( !user_is_bot( ) )
{
if ( $board_config['redirectnoguest'] )
{
redirect("login.$phpEx");
}
else
{
message_die ( GENERAL_MESSAGE, $lang['topic_noguest'] );
}
}
}
check_topicban ( $topic_id, TRUE );
$password = $forum_topic_data['topic_password'];
$pass_lvl = $forum_topic_data['topic_pass_level'];
$topic_logged = ( is_array( $userdata['log_topics'] ) ) ? array_search ( $forum_topic_data['topic_id'], $userdata['log_topics'] ) : FALSE;
$mod = FALSE;
if ( $pass_lvl == $userdata['user_level'] )
{
$mod = FALSE;
}
elseif ( $pass_lvl == USER && $userdata['user_level'] > USER )
{
$mod = TRUE;
}
if ( $userdata['user_level'] == ADMIN || !$board_config['enable_topicpass'] || ( $postrow[0]['user_id'] == ANONYMOUS && !$board_config['allow_guestpass'] ) )
{
$mod = TRUE;
}
if ( $topic_logged === FALSE && $password != '' && !$mod )
{
if ( !$board_config['allow_guesttlogin'] && $userdata['user_id'] == ANONYMOUS )
{
if ( $board_config['redirectnoguest'] )
{
redirect("login.$phpEx");
}else
{
message_die ( GENERAL_MESSAGE, $lang['guest_nologin'] );
}
}elseif ( !$userdata['user_allow_tlogin'] )
{
message_die ( GENERAL_MESSAGE, $lang['user_nologin'] );
}elseif ( !isset($HTTP_POST_VARS['topic_login'] ))
{
$template -> assign_vars ( array (
'L_LOGIN' => $lang['Login'],
'L_PASSWORD' => $lang['Password'],
'MESSAGE_TITLE' => $lang['Login'],
'MESSAGE_TEXT' => $lang['topic_login'],
'S_LOGIN_ACTION' => append_sid ( "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id" )
) );
$template -> set_filenames ( array (
'login' => 'topic_login.tpl'
) );
$template->pparse('login');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
break;
}else
{
$pass = md5 ( $HTTP_POST_VARS['topic_pass'] );
if ( $pass == $password )
{
$log_topics = $userdata['log_topics'];
$log_topics[count ( $log_topics ) + 1] = $topic_id;
//add this to session table
$sid = $userdata['session_id'];
$log_topics = implode ( ',', $log_topics );
$sql = "UPDATE " . SESSIONS_TABLE . " SET " .
"session_logged_topics='$log_topics' " .
"WHERE session_id='$sid' LIMIT 1";
$db -> sql_query ( $sql );
}else
{
message_die ( GENERAL_ERROR, $lang['wrong_tpass'] );
}
}
}elseif ( $topic_logged === FALSE && ( $mod || $password == '' ) )
{
$log_topics = $userdata['log_topics'];
$log_topics[count ( $log_topics ) + 1] = $topic_id;
//add this to session table
$sid = $userdata['session_id'];
$log_topics = implode ( ',', $log_topics );
$sql = "UPDATE " . SESSIONS_TABLE . " SET " .
"session_logged_topics='$log_topics' " .
"WHERE session_id='$sid' LIMIT 1";
$db -> sql_query ( $sql );
}
// mod topic mod end
//
// 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'] ) . '
';
//-- mod : calendar ------------------------------------------------------------
//-- add
$s_auth_can .= ( ( $is_auth['auth_cal'] ) ? $lang['Rules_calendar_can'] : $lang['Rules_calendar_cannot'] ) . '
';
//-- fin mod : calendar --------------------------------------------------------
// mod topic mod add
$pass = ( check_tauth ( $forum_row['auth_tpass'], 'auth_tpass', $forum_id ) && $userdata['user_allow_pass'] ) ? $lang['Rules_tpass_can']: $lang['Rules_tpass_cannot'];
$ban = ( check_tauth ( $forum_row['auth_tban'], 'auth_tban', $forum_id ) && $userdata['user_allow_tban'] ) ? $lang['Rules_tban_can']: $lang['Rules_tban_cannot'];
$noguest = ( check_tauth ( $forum_row['auth_tnoguest'], 'auth_tnoguest', $forum_id ) ) ? $lang['Rules_tnoguest_can']: $lang['Rules_tnoguest_cannot'];
$log = ( $userdata['user_allow_tlogin'] || ( $board_config['allow_guestlogin'] && $userdata['user_id'] == ANONYMOUS ) ) ? $lang['Rules_tlog_can']: $lang['Rules_tlog_cannot'];
$s_auth_can .= ( $board_config['enable_topicpass'] ) ? $pass . '
' : '';
$s_auth_can .= ( $board_config['enable_topicpass'] ) ? $log . '
' : '';
$s_auth_can .= ( $board_config['enable_topicban'] ) ? $ban . '
' : '';
$s_auth_can .= ( $board_config['allow_tnologguest'] ) ? $noguest . '
' : '';
// mod topic mod end
attach_build_auth_levels($is_auth, $s_auth_can);
$topic_mod = '';
// mod topic mod change arguments
if ( $is_auth['auth_mod'] && ( !$forum_topic_data['topic_adminedit'] || $userdata['user_level'] == ADMIN ))
{
$s_auth_can .= sprintf($lang['Rules_moderate'], "', '');
$topic_mod .= "
';
$topic_mod .= "
';
$topic_mod .= ( $forum_topic_data['topic_status'] == TOPIC_UNLOCKED ) ? "
' : "
';
$topic_mod .= "
';
$topic_mod .= "
';
$topic_mod .= ( $forum_topic_data['topic_type'] != 1 ) ? "
' : "
';
$topic_mod .= ( $forum_topic_data['topic_type'] != 2 ) ? "
' : "
';
include_once($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
$make_move_select = make_forum_select($topic_id.'_new_forum', $forum_id);
if (strpos($make_move_select, '