viewforum.php
author indvdum (gotoindvdum[at]gmail[dot]com)
Fri, 09 Mar 2012 16:11:37 +0400
changeset 12 898199d067e7
parent 0 ceef6d64c21d
permissions -rw-r--r--
Ignoring cache
indvdum@0
     1
<?php
indvdum@0
     2
/**
indvdum@0
     3
*
indvdum@0
     4
* @package phpBB3
indvdum@0
     5
* @version $Id$
indvdum@0
     6
* @copyright (c) 2005 phpBB Group
indvdum@0
     7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
indvdum@0
     8
*
indvdum@0
     9
*/
indvdum@0
    10
indvdum@0
    11
/**
indvdum@0
    12
* @ignore
indvdum@0
    13
*/
indvdum@0
    14
define('IN_PHPBB', true);
indvdum@0
    15
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
indvdum@0
    16
$phpEx = substr(strrchr(__FILE__, '.'), 1);
indvdum@0
    17
include($phpbb_root_path . 'common.' . $phpEx);
indvdum@0
    18
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
indvdum@0
    19
indvdum@0
    20
// Start session
indvdum@0
    21
$user->session_begin();
indvdum@0
    22
$auth->acl($user->data);
indvdum@0
    23
indvdum@0
    24
// Start initial var setup
indvdum@0
    25
$forum_id	= request_var('f', 0);
indvdum@0
    26
$mark_read	= request_var('mark', '');
indvdum@0
    27
$start		= request_var('start', 0);
indvdum@0
    28
indvdum@0
    29
$default_sort_days	= (!empty($user->data['user_topic_show_days'])) ? $user->data['user_topic_show_days'] : 0;
indvdum@0
    30
$default_sort_key	= (!empty($user->data['user_topic_sortby_type'])) ? $user->data['user_topic_sortby_type'] : 't';
indvdum@0
    31
$default_sort_dir	= (!empty($user->data['user_topic_sortby_dir'])) ? $user->data['user_topic_sortby_dir'] : 'd';
indvdum@0
    32
indvdum@0
    33
$sort_days	= request_var('st', $default_sort_days);
indvdum@0
    34
$sort_key	= request_var('sk', $default_sort_key);
indvdum@0
    35
$sort_dir	= request_var('sd', $default_sort_dir);
indvdum@0
    36
indvdum@0
    37
// Check if the user has actually sent a forum ID with his/her request
indvdum@0
    38
// If not give them a nice error page.
indvdum@0
    39
if (!$forum_id)
indvdum@0
    40
{
indvdum@0
    41
	trigger_error('NO_FORUM');
indvdum@0
    42
}
indvdum@0
    43
indvdum@0
    44
$sql_from = FORUMS_TABLE . ' f';
indvdum@0
    45
$lastread_select = '';
indvdum@0
    46
indvdum@0
    47
// Grab appropriate forum data
indvdum@0
    48
if ($config['load_db_lastread'] && $user->data['is_registered'])
indvdum@0
    49
{
indvdum@0
    50
	$sql_from .= ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . '
indvdum@0
    51
		AND ft.forum_id = f.forum_id)';
indvdum@0
    52
	$lastread_select .= ', ft.mark_time';
indvdum@0
    53
}
indvdum@0
    54
indvdum@0
    55
if ($user->data['is_registered'])
indvdum@0
    56
{
indvdum@0
    57
	$sql_from .= ' LEFT JOIN ' . FORUMS_WATCH_TABLE . ' fw ON (fw.forum_id = f.forum_id AND fw.user_id = ' . $user->data['user_id'] . ')';
indvdum@0
    58
	$lastread_select .= ', fw.notify_status';
indvdum@0
    59
}
indvdum@0
    60
indvdum@0
    61
$sql = "SELECT f.* $lastread_select
indvdum@0
    62
	FROM $sql_from
indvdum@0
    63
	WHERE f.forum_id = $forum_id";
indvdum@0
    64
$result = $db->sql_query($sql);
indvdum@0
    65
$forum_data = $db->sql_fetchrow($result);
indvdum@0
    66
$db->sql_freeresult($result);
indvdum@0
    67
indvdum@0
    68
if (!$forum_data)
indvdum@0
    69
{
indvdum@0
    70
	trigger_error('NO_FORUM');
indvdum@0
    71
}
indvdum@0
    72
indvdum@0
    73
indvdum@0
    74
// Configure style, language, etc.
indvdum@0
    75
$user->setup('viewforum', $forum_data['forum_style']);
indvdum@0
    76
indvdum@0
    77
// Redirect to login upon emailed notification links
indvdum@0
    78
if (isset($_GET['e']) && !$user->data['is_registered'])
indvdum@0
    79
{
indvdum@0
    80
	login_box('', $user->lang['LOGIN_NOTIFY_FORUM']);
indvdum@0
    81
}
indvdum@0
    82
indvdum@0
    83
// Permissions check
indvdum@0
    84
if (!$auth->acl_gets('f_list', 'f_read', $forum_id) || ($forum_data['forum_type'] == FORUM_LINK && $forum_data['forum_link'] && !$auth->acl_get('f_read', $forum_id)))
indvdum@0
    85
{
indvdum@0
    86
	if ($user->data['user_id'] != ANONYMOUS)
indvdum@0
    87
	{
indvdum@0
    88
		trigger_error('SORRY_AUTH_READ');
indvdum@0
    89
	}
indvdum@0
    90
indvdum@0
    91
	login_box('', $user->lang['LOGIN_VIEWFORUM']);
indvdum@0
    92
}
indvdum@0
    93
indvdum@0
    94
// Forum is passworded ... check whether access has been granted to this
indvdum@0
    95
// user this session, if not show login box
indvdum@0
    96
if ($forum_data['forum_password'])
indvdum@0
    97
{
indvdum@0
    98
	login_forum_box($forum_data);
indvdum@0
    99
}
indvdum@0
   100
indvdum@0
   101
// Is this forum a link? ... User got here either because the
indvdum@0
   102
// number of clicks is being tracked or they guessed the id
indvdum@0
   103
if ($forum_data['forum_type'] == FORUM_LINK && $forum_data['forum_link'])
indvdum@0
   104
{
indvdum@0
   105
	// Does it have click tracking enabled?
indvdum@0
   106
	if ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK)
indvdum@0
   107
	{
indvdum@0
   108
		$sql = 'UPDATE ' . FORUMS_TABLE . '
indvdum@0
   109
			SET forum_posts = forum_posts + 1
indvdum@0
   110
			WHERE forum_id = ' . $forum_id;
indvdum@0
   111
		$db->sql_query($sql);
indvdum@0
   112
	}
indvdum@0
   113
indvdum@0
   114
	// We redirect to the url. The third parameter indicates that external redirects are allowed.
indvdum@0
   115
	redirect($forum_data['forum_link'], false, true);
indvdum@0
   116
	return;
indvdum@0
   117
}
indvdum@0
   118
indvdum@0
   119
// Build navigation links
indvdum@0
   120
generate_forum_nav($forum_data);
indvdum@0
   121
indvdum@0
   122
// Forum Rules
indvdum@0
   123
if ($auth->acl_get('f_read', $forum_id))
indvdum@0
   124
{
indvdum@0
   125
	generate_forum_rules($forum_data);
indvdum@0
   126
}
indvdum@0
   127
indvdum@0
   128
// Do we have subforums?
indvdum@0
   129
$active_forum_ary = $moderators = array();
indvdum@0
   130
indvdum@0
   131
if ($forum_data['left_id'] != $forum_data['right_id'] - 1)
indvdum@0
   132
{
indvdum@0
   133
	list($active_forum_ary, $moderators) = display_forums($forum_data, $config['load_moderators'], $config['load_moderators']);
indvdum@0
   134
}
indvdum@0
   135
else
indvdum@0
   136
{
indvdum@0
   137
	$template->assign_var('S_HAS_SUBFORUM', false);
indvdum@0
   138
	if ($config['load_moderators'])
indvdum@0
   139
	{
indvdum@0
   140
		get_moderators($moderators, $forum_id);
indvdum@0
   141
	}
indvdum@0
   142
}
indvdum@0
   143
indvdum@0
   144
// Dump out the page header and load viewforum template
indvdum@0
   145
page_header($user->lang['VIEW_FORUM'] . ' - ' . $forum_data['forum_name'], true, $forum_id);
indvdum@0
   146
indvdum@0
   147
$template->set_filenames(array(
indvdum@0
   148
	'body' => 'viewforum_body.html')
indvdum@0
   149
);
indvdum@0
   150
indvdum@0
   151
make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"), $forum_id);
indvdum@0
   152
indvdum@0
   153
$template->assign_vars(array(
indvdum@0
   154
	'U_VIEW_FORUM'			=> append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . (($start == 0) ? '' : "&amp;start=$start")),
indvdum@0
   155
));
indvdum@0
   156
indvdum@0
   157
// Not postable forum or showing active topics?
indvdum@0
   158
if (!($forum_data['forum_type'] == FORUM_POST || (($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) && $forum_data['forum_type'] == FORUM_CAT)))
indvdum@0
   159
{
indvdum@0
   160
	page_footer();
indvdum@0
   161
}
indvdum@0
   162
indvdum@0
   163
// Ok, if someone has only list-access, we only display the forum list.
indvdum@0
   164
// We also make this circumstance available to the template in case we want to display a notice. ;)
indvdum@0
   165
if (!$auth->acl_get('f_read', $forum_id))
indvdum@0
   166
{
indvdum@0
   167
	$template->assign_vars(array(
indvdum@0
   168
		'S_NO_READ_ACCESS'		=> true,
indvdum@0
   169
	));
indvdum@0
   170
indvdum@0
   171
	page_footer();
indvdum@0
   172
}
indvdum@0
   173
indvdum@0
   174
// Handle marking posts
indvdum@0
   175
if ($mark_read == 'topics')
indvdum@0
   176
{
indvdum@0
   177
	$token = request_var('hash', '');
indvdum@0
   178
	if (check_link_hash($token, 'global'))
indvdum@0
   179
	{
indvdum@0
   180
		// Add 0 to forums array to mark global announcements correctly
indvdum@0
   181
		markread('topics', array($forum_id, 0));
indvdum@0
   182
	}
indvdum@0
   183
	$redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
indvdum@0
   184
	meta_refresh(3, $redirect_url);
indvdum@0
   185
indvdum@0
   186
	trigger_error($user->lang['TOPICS_MARKED'] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>'));
indvdum@0
   187
}
indvdum@0
   188
indvdum@0
   189
// Is a forum specific topic count required?
indvdum@0
   190
if ($forum_data['forum_topics_per_page'])
indvdum@0
   191
{
indvdum@0
   192
	$config['topics_per_page'] = $forum_data['forum_topics_per_page'];
indvdum@0
   193
}
indvdum@0
   194
indvdum@0
   195
// Do the forum Prune thang - cron type job ...
indvdum@0
   196
if ($forum_data['prune_next'] < time() && $forum_data['enable_prune'])
indvdum@0
   197
{
indvdum@0
   198
	$template->assign_var('RUN_CRON_TASK', '<img src="' . append_sid($phpbb_root_path . 'cron.' . $phpEx, 'cron_type=prune_forum&amp;f=' . $forum_id) . '" alt="cron" width="1" height="1" />');
indvdum@0
   199
}
indvdum@0
   200
indvdum@0
   201
// Forum rules and subscription info
indvdum@0
   202
$s_watching_forum = array(
indvdum@0
   203
	'link'			=> '',
indvdum@0
   204
	'title'			=> '',
indvdum@0
   205
	'is_watching'	=> false,
indvdum@0
   206
);
indvdum@0
   207
indvdum@0
   208
if (($config['email_enable'] || $config['jab_enable']) && $config['allow_forum_notify'] && $forum_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_subscribe', $forum_id) || $user->data['user_id'] == ANONYMOUS))
indvdum@0
   209
{
indvdum@0
   210
	$notify_status = (isset($forum_data['notify_status'])) ? $forum_data['notify_status'] : NULL;
indvdum@0
   211
	watch_topic_forum('forum', $s_watching_forum, $user->data['user_id'], $forum_id, 0, $notify_status, $start, $forum_data['forum_name']);
indvdum@0
   212
}
indvdum@0
   213
indvdum@0
   214
$s_forum_rules = '';
indvdum@0
   215
gen_forum_auth_level('forum', $forum_id, $forum_data['forum_status']);
indvdum@0
   216
indvdum@0
   217
// Topic ordering options
indvdum@0
   218
$limit_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
indvdum@0
   219
indvdum@0
   220
$sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
indvdum@0
   221
$sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'r' => 't.topic_replies', 's' => 't.topic_title', 'v' => 't.topic_views');
indvdum@0
   222
indvdum@0
   223
$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
indvdum@0
   224
gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param, $default_sort_days, $default_sort_key, $default_sort_dir);
indvdum@0
   225
indvdum@0
   226
// Limit topics to certain time frame, obtain correct topic count
indvdum@0
   227
// global announcements must not be counted, normal announcements have to
indvdum@0
   228
// be counted, as forum_topics(_real) includes them
indvdum@0
   229
if ($sort_days)
indvdum@0
   230
{
indvdum@0
   231
	$min_post_time = time() - ($sort_days * 86400);
indvdum@0
   232
indvdum@0
   233
	$sql = 'SELECT COUNT(topic_id) AS num_topics
indvdum@0
   234
		FROM ' . TOPICS_TABLE . "
indvdum@0
   235
		WHERE forum_id = $forum_id
indvdum@0
   236
			AND ((topic_type <> " . POST_GLOBAL . " AND topic_last_post_time >= $min_post_time)
indvdum@0
   237
				OR topic_type = " . POST_ANNOUNCE . ")
indvdum@0
   238
		" . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND topic_approved = 1');
indvdum@0
   239
	$result = $db->sql_query($sql);
indvdum@0
   240
	$topics_count = (int) $db->sql_fetchfield('num_topics');
indvdum@0
   241
	$db->sql_freeresult($result);
indvdum@0
   242
indvdum@0
   243
	if (isset($_POST['sort']))
indvdum@0
   244
	{
indvdum@0
   245
		$start = 0;
indvdum@0
   246
	}
indvdum@0
   247
	$sql_limit_time = "AND t.topic_last_post_time >= $min_post_time";
indvdum@0
   248
indvdum@0
   249
	// Make sure we have information about day selection ready
indvdum@0
   250
	$template->assign_var('S_SORT_DAYS', true);
indvdum@0
   251
}
indvdum@0
   252
else
indvdum@0
   253
{
indvdum@0
   254
	$topics_count = ($auth->acl_get('m_approve', $forum_id)) ? $forum_data['forum_topics_real'] : $forum_data['forum_topics'];
indvdum@0
   255
	$sql_limit_time = '';
indvdum@0
   256
}
indvdum@0
   257
indvdum@0
   258
// Make sure $start is set to the last page if it exceeds the amount
indvdum@0
   259
if ($start < 0 || $start > $topics_count)
indvdum@0
   260
{
indvdum@0
   261
	$start = ($start < 0) ? 0 : floor(($topics_count - 1) / $config['topics_per_page']) * $config['topics_per_page'];
indvdum@0
   262
}
indvdum@0
   263
indvdum@0
   264
// Basic pagewide vars
indvdum@0
   265
$post_alt = ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['FORUM_LOCKED'] : $user->lang['POST_NEW_TOPIC'];
indvdum@0
   266
indvdum@0
   267
// Display active topics?
indvdum@0
   268
$s_display_active = ($forum_data['forum_type'] == FORUM_CAT && ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
indvdum@0
   269
indvdum@0
   270
$s_search_hidden_fields = array('fid' => array($forum_id));
indvdum@0
   271
if ($_SID)
indvdum@0
   272
{
indvdum@0
   273
	$s_search_hidden_fields['sid'] = $_SID;
indvdum@0
   274
}
indvdum@0
   275
indvdum@0
   276
if (!empty($_EXTRA_URL))
indvdum@0
   277
{
indvdum@0
   278
	foreach ($_EXTRA_URL as $url_param)
indvdum@0
   279
	{
indvdum@0
   280
		$url_param = explode('=', $url_param, 2);
indvdum@0
   281
		$s_hidden_fields[$url_param[0]] = $url_param[1];
indvdum@0
   282
	}
indvdum@0
   283
}
indvdum@0
   284
indvdum@0
   285
$template->assign_vars(array(
indvdum@0
   286
	'MODERATORS'	=> (!empty($moderators[$forum_id])) ? implode(', ', $moderators[$forum_id]) : '',
indvdum@0
   287
indvdum@0
   288
	'POST_IMG'					=> ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->img('button_topic_locked', $post_alt) : $user->img('button_topic_new', $post_alt),
indvdum@0
   289
	'NEWEST_POST_IMG'			=> $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
indvdum@0
   290
	'LAST_POST_IMG'				=> $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
indvdum@0
   291
	'FOLDER_IMG'				=> $user->img('topic_read', 'NO_UNREAD_POSTS'),
indvdum@0
   292
	'FOLDER_UNREAD_IMG'			=> $user->img('topic_unread', 'UNREAD_POSTS'),
indvdum@0
   293
	'FOLDER_HOT_IMG'			=> $user->img('topic_read_hot', 'NO_UNREAD_POSTS_HOT'),
indvdum@0
   294
	'FOLDER_HOT_UNREAD_IMG'		=> $user->img('topic_unread_hot', 'UNREAD_POSTS_HOT'),
indvdum@0
   295
	'FOLDER_LOCKED_IMG'			=> $user->img('topic_read_locked', 'NO_UNREAD_POSTS_LOCKED'),
indvdum@0
   296
	'FOLDER_LOCKED_UNREAD_IMG'	=> $user->img('topic_unread_locked', 'UNREAD_POSTS_LOCKED'),
indvdum@0
   297
	'FOLDER_STICKY_IMG'			=> $user->img('sticky_read', 'POST_STICKY'),
indvdum@0
   298
	'FOLDER_STICKY_UNREAD_IMG'	=> $user->img('sticky_unread', 'POST_STICKY'),
indvdum@0
   299
	'FOLDER_ANNOUNCE_IMG'		=> $user->img('announce_read', 'POST_ANNOUNCEMENT'),
indvdum@0
   300
	'FOLDER_ANNOUNCE_UNREAD_IMG'=> $user->img('announce_unread', 'POST_ANNOUNCEMENT'),
indvdum@0
   301
	'FOLDER_MOVED_IMG'			=> $user->img('topic_moved', 'TOPIC_MOVED'),
indvdum@0
   302
	'REPORTED_IMG'				=> $user->img('icon_topic_reported', 'TOPIC_REPORTED'),
indvdum@0
   303
	'UNAPPROVED_IMG'			=> $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'),
indvdum@0
   304
	'GOTO_PAGE_IMG'				=> $user->img('icon_post_target', 'GOTO_PAGE'),
indvdum@0
   305
indvdum@0
   306
	'L_NO_TOPICS' 			=> ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['POST_FORUM_LOCKED'] : $user->lang['NO_TOPICS'],
indvdum@0
   307
indvdum@0
   308
	'S_DISPLAY_POST_INFO'	=> ($forum_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
indvdum@0
   309
indvdum@0
   310
	'S_IS_POSTABLE'			=> ($forum_data['forum_type'] == FORUM_POST) ? true : false,
indvdum@0
   311
	'S_USER_CAN_POST'		=> ($auth->acl_get('f_post', $forum_id)) ? true : false,
indvdum@0
   312
	'S_DISPLAY_ACTIVE'		=> $s_display_active,
indvdum@0
   313
	'S_SELECT_SORT_DIR'		=> $s_sort_dir,
indvdum@0
   314
	'S_SELECT_SORT_KEY'		=> $s_sort_key,
indvdum@0
   315
	'S_SELECT_SORT_DAYS'	=> $s_limit_days,
indvdum@0
   316
	'S_TOPIC_ICONS'			=> ($s_display_active && sizeof($active_forum_ary)) ? max($active_forum_ary['enable_icons']) : (($forum_data['enable_icons']) ? true : false),
indvdum@0
   317
	'S_WATCH_FORUM_LINK'	=> $s_watching_forum['link'],
indvdum@0
   318
	'S_WATCH_FORUM_TITLE'	=> $s_watching_forum['title'],
indvdum@0
   319
	'S_WATCHING_FORUM'		=> $s_watching_forum['is_watching'],
indvdum@0
   320
	'S_FORUM_ACTION'		=> append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . (($start == 0) ? '' : "&amp;start=$start")),
indvdum@0
   321
	'S_DISPLAY_SEARCHBOX'	=> ($auth->acl_get('u_search') && $auth->acl_get('f_search', $forum_id) && $config['load_search']) ? true : false,
indvdum@0
   322
	'S_SEARCHBOX_ACTION'	=> append_sid("{$phpbb_root_path}search.$phpEx"),
indvdum@0
   323
	'S_SEARCH_LOCAL_HIDDEN_FIELDS'	=> build_hidden_fields($s_search_hidden_fields),
indvdum@0
   324
	'S_SINGLE_MODERATOR'	=> (!empty($moderators[$forum_id]) && sizeof($moderators[$forum_id]) > 1) ? false : true,
indvdum@0
   325
	'S_IS_LOCKED'			=> ($forum_data['forum_status'] == ITEM_LOCKED) ? true : false,
indvdum@0
   326
	'S_VIEWFORUM'			=> true,
indvdum@0
   327
indvdum@0
   328
	'U_MCP'				=> ($auth->acl_get('m_', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "f=$forum_id&amp;i=main&amp;mode=forum_view", true, $user->session_id) : '',
indvdum@0
   329
	'U_POST_NEW_TOPIC'	=> ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS) ? append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=post&amp;f=' . $forum_id) : '',
indvdum@0
   330
	'U_VIEW_FORUM'		=> append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : '') . (($start == 0) ? '' : "&amp;start=$start")),
indvdum@0
   331
	'U_MARK_TOPICS'		=> ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . "&amp;f=$forum_id&amp;mark=topics") : '',
indvdum@0
   332
));
indvdum@0
   333
indvdum@0
   334
// Grab icons
indvdum@0
   335
$icons = $cache->obtain_icons();
indvdum@0
   336
indvdum@0
   337
// Grab all topic data
indvdum@0
   338
$rowset = $announcement_list = $topic_list = $global_announce_list = array();
indvdum@0
   339
indvdum@0
   340
$sql_array = array(
indvdum@0
   341
	'SELECT'	=> 't.*',
indvdum@0
   342
	'FROM'		=> array(
indvdum@0
   343
		TOPICS_TABLE		=> 't'
indvdum@0
   344
	),
indvdum@0
   345
	'LEFT_JOIN'	=> array(),
indvdum@0
   346
);
indvdum@0
   347
indvdum@0
   348
$sql_approved = ($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1';
indvdum@0
   349
indvdum@0
   350
if ($user->data['is_registered'])
indvdum@0
   351
{
indvdum@0
   352
	if ($config['load_db_track'])
indvdum@0
   353
	{
indvdum@0
   354
		$sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . $user->data['user_id']);
indvdum@0
   355
		$sql_array['SELECT'] .= ', tp.topic_posted';
indvdum@0
   356
	}
indvdum@0
   357
indvdum@0
   358
	if ($config['load_db_lastread'])
indvdum@0
   359
	{
indvdum@0
   360
		$sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id']);
indvdum@0
   361
		$sql_array['SELECT'] .= ', tt.mark_time';
indvdum@0
   362
indvdum@0
   363
		if ($s_display_active && sizeof($active_forum_ary))
indvdum@0
   364
		{
indvdum@0
   365
			$sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id']);
indvdum@0
   366
			$sql_array['SELECT'] .= ', ft.mark_time AS forum_mark_time';
indvdum@0
   367
		}
indvdum@0
   368
	}
indvdum@0
   369
}
indvdum@0
   370
indvdum@0
   371
if ($forum_data['forum_type'] == FORUM_POST)
indvdum@0
   372
{
indvdum@0
   373
	// Obtain announcements ... removed sort ordering, sort by time in all cases
indvdum@0
   374
	$sql = $db->sql_build_query('SELECT', array(
indvdum@0
   375
		'SELECT'	=> $sql_array['SELECT'],
indvdum@0
   376
		'FROM'		=> $sql_array['FROM'],
indvdum@0
   377
		'LEFT_JOIN'	=> $sql_array['LEFT_JOIN'],
indvdum@0
   378
indvdum@0
   379
		'WHERE'		=> 't.forum_id IN (' . $forum_id . ', 0)
indvdum@0
   380
			AND t.topic_type IN (' . POST_ANNOUNCE . ', ' . POST_GLOBAL . ')',
indvdum@0
   381
indvdum@0
   382
		'ORDER_BY'	=> 't.topic_time DESC',
indvdum@0
   383
	));
indvdum@0
   384
	$result = $db->sql_query($sql);
indvdum@0
   385
indvdum@0
   386
	while ($row = $db->sql_fetchrow($result))
indvdum@0
   387
	{
indvdum@0
   388
		if (!$row['topic_approved'] && !$auth->acl_get('m_approve', $row['forum_id']))
indvdum@0
   389
		{
indvdum@0
   390
			// Do not display announcements that are waiting for approval.
indvdum@0
   391
			continue;
indvdum@0
   392
		}
indvdum@0
   393
indvdum@0
   394
		$rowset[$row['topic_id']] = $row;
indvdum@0
   395
		$announcement_list[] = $row['topic_id'];
indvdum@0
   396
indvdum@0
   397
		if ($row['topic_type'] == POST_GLOBAL)
indvdum@0
   398
		{
indvdum@0
   399
			$global_announce_list[$row['topic_id']] = true;
indvdum@0
   400
		}
indvdum@0
   401
		else
indvdum@0
   402
		{
indvdum@0
   403
			$topics_count--;
indvdum@0
   404
		}
indvdum@0
   405
	}
indvdum@0
   406
	$db->sql_freeresult($result);
indvdum@0
   407
}
indvdum@0
   408
indvdum@0
   409
// If the user is trying to reach late pages, start searching from the end
indvdum@0
   410
$store_reverse = false;
indvdum@0
   411
$sql_limit = $config['topics_per_page'];
indvdum@0
   412
if ($start > $topics_count / 2)
indvdum@0
   413
{
indvdum@0
   414
	$store_reverse = true;
indvdum@0
   415
indvdum@0
   416
	if ($start + $config['topics_per_page'] > $topics_count)
indvdum@0
   417
	{
indvdum@0
   418
		$sql_limit = min($config['topics_per_page'], max(1, $topics_count - $start));
indvdum@0
   419
	}
indvdum@0
   420
indvdum@0
   421
	// Select the sort order
indvdum@0
   422
	$sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
indvdum@0
   423
	$sql_start = max(0, $topics_count - $sql_limit - $start);
indvdum@0
   424
}
indvdum@0
   425
else
indvdum@0
   426
{
indvdum@0
   427
	// Select the sort order
indvdum@0
   428
	$sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
indvdum@0
   429
	$sql_start = $start;
indvdum@0
   430
}
indvdum@0
   431
indvdum@0
   432
if ($forum_data['forum_type'] == FORUM_POST || !sizeof($active_forum_ary))
indvdum@0
   433
{
indvdum@0
   434
	$sql_where = 't.forum_id = ' . $forum_id;
indvdum@0
   435
}
indvdum@0
   436
else if (empty($active_forum_ary['exclude_forum_id']))
indvdum@0
   437
{
indvdum@0
   438
	$sql_where = $db->sql_in_set('t.forum_id', $active_forum_ary['forum_id']);
indvdum@0
   439
}
indvdum@0
   440
else
indvdum@0
   441
{
indvdum@0
   442
	$get_forum_ids = array_diff($active_forum_ary['forum_id'], $active_forum_ary['exclude_forum_id']);
indvdum@0
   443
	$sql_where = (sizeof($get_forum_ids)) ? $db->sql_in_set('t.forum_id', $get_forum_ids) : 't.forum_id = ' . $forum_id;
indvdum@0
   444
}
indvdum@0
   445
indvdum@0
   446
// Grab just the sorted topic ids
indvdum@0
   447
$sql = 'SELECT t.topic_id
indvdum@0
   448
	FROM ' . TOPICS_TABLE . " t
indvdum@0
   449
	WHERE $sql_where
indvdum@0
   450
		AND t.topic_type IN (" . POST_NORMAL . ', ' . POST_STICKY . ")
indvdum@0
   451
		$sql_approved
indvdum@0
   452
		$sql_limit_time
indvdum@0
   453
	ORDER BY t.topic_type " . ((!$store_reverse) ? 'DESC' : 'ASC') . ', ' . $sql_sort_order;
indvdum@0
   454
$result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
indvdum@0
   455
indvdum@0
   456
while ($row = $db->sql_fetchrow($result))
indvdum@0
   457
{
indvdum@0
   458
	$topic_list[] = (int) $row['topic_id'];
indvdum@0
   459
}
indvdum@0
   460
$db->sql_freeresult($result);
indvdum@0
   461
indvdum@0
   462
// For storing shadow topics
indvdum@0
   463
$shadow_topic_list = array();
indvdum@0
   464
indvdum@0
   465
if (sizeof($topic_list))
indvdum@0
   466
{
indvdum@0
   467
	// SQL array for obtaining topics/stickies
indvdum@0
   468
	$sql_array = array(
indvdum@0
   469
		'SELECT'		=> $sql_array['SELECT'],
indvdum@0
   470
		'FROM'			=> $sql_array['FROM'],
indvdum@0
   471
		'LEFT_JOIN'		=> $sql_array['LEFT_JOIN'],
indvdum@0
   472
indvdum@0
   473
		'WHERE'			=> $db->sql_in_set('t.topic_id', $topic_list),
indvdum@0
   474
	);
indvdum@0
   475
indvdum@0
   476
	// If store_reverse, then first obtain topics, then stickies, else the other way around...
indvdum@0
   477
	// Funnily enough you typically save one query if going from the last page to the middle (store_reverse) because
indvdum@0
   478
	// the number of stickies are not known
indvdum@0
   479
	$sql = $db->sql_build_query('SELECT', $sql_array);
indvdum@0
   480
	$result = $db->sql_query($sql);
indvdum@0
   481
indvdum@0
   482
	while ($row = $db->sql_fetchrow($result))
indvdum@0
   483
	{
indvdum@0
   484
		if ($row['topic_status'] == ITEM_MOVED)
indvdum@0
   485
		{
indvdum@0
   486
			$shadow_topic_list[$row['topic_moved_id']] = $row['topic_id'];
indvdum@0
   487
		}
indvdum@0
   488
indvdum@0
   489
		$rowset[$row['topic_id']] = $row;
indvdum@0
   490
	}
indvdum@0
   491
	$db->sql_freeresult($result);
indvdum@0
   492
}
indvdum@0
   493
indvdum@0
   494
// If we have some shadow topics, update the rowset to reflect their topic information
indvdum@0
   495
if (sizeof($shadow_topic_list))
indvdum@0
   496
{
indvdum@0
   497
	$sql = 'SELECT *
indvdum@0
   498
		FROM ' . TOPICS_TABLE . '
indvdum@0
   499
		WHERE ' . $db->sql_in_set('topic_id', array_keys($shadow_topic_list));
indvdum@0
   500
	$result = $db->sql_query($sql);
indvdum@0
   501
indvdum@0
   502
	while ($row = $db->sql_fetchrow($result))
indvdum@0
   503
	{
indvdum@0
   504
		$orig_topic_id = $shadow_topic_list[$row['topic_id']];
indvdum@0
   505
indvdum@0
   506
		// If the shadow topic is already listed within the rowset (happens for active topics for example), then do not include it...
indvdum@0
   507
		if (isset($rowset[$row['topic_id']]))
indvdum@0
   508
		{
indvdum@0
   509
			// We need to remove any trace regarding this topic. :)
indvdum@0
   510
			unset($rowset[$orig_topic_id]);
indvdum@0
   511
			unset($topic_list[array_search($orig_topic_id, $topic_list)]);
indvdum@0
   512
			$topics_count--;
indvdum@0
   513
indvdum@0
   514
			continue;
indvdum@0
   515
		}
indvdum@0
   516
indvdum@0
   517
		// Do not include those topics the user has no permission to access
indvdum@0
   518
		if (!$auth->acl_get('f_read', $row['forum_id']))
indvdum@0
   519
		{
indvdum@0
   520
			// We need to remove any trace regarding this topic. :)
indvdum@0
   521
			unset($rowset[$orig_topic_id]);
indvdum@0
   522
			unset($topic_list[array_search($orig_topic_id, $topic_list)]);
indvdum@0
   523
			$topics_count--;
indvdum@0
   524
indvdum@0
   525
			continue;
indvdum@0
   526
		}
indvdum@0
   527
indvdum@0
   528
		// We want to retain some values
indvdum@0
   529
		$row = array_merge($row, array(
indvdum@0
   530
			'topic_moved_id'	=> $rowset[$orig_topic_id]['topic_moved_id'],
indvdum@0
   531
			'topic_status'		=> $rowset[$orig_topic_id]['topic_status'],
indvdum@0
   532
			'topic_type'		=> $rowset[$orig_topic_id]['topic_type'],
indvdum@0
   533
			'topic_title'		=> $rowset[$orig_topic_id]['topic_title'],
indvdum@0
   534
		));
indvdum@0
   535
indvdum@0
   536
		// Shadow topics are never reported
indvdum@0
   537
		$row['topic_reported'] = 0;
indvdum@0
   538
indvdum@0
   539
		$rowset[$orig_topic_id] = $row;
indvdum@0
   540
	}
indvdum@0
   541
	$db->sql_freeresult($result);
indvdum@0
   542
}
indvdum@0
   543
unset($shadow_topic_list);
indvdum@0
   544
indvdum@0
   545
// Ok, adjust topics count for active topics list
indvdum@0
   546
if ($s_display_active)
indvdum@0
   547
{
indvdum@0
   548
	$topics_count = 1;
indvdum@0
   549
}
indvdum@0
   550
indvdum@0
   551
// We need to readd the local announcements to the forums total topic count, otherwise the number is different from the one on the forum list
indvdum@0
   552
$total_topic_count = $topics_count + sizeof($announcement_list) - sizeof($global_announce_list);
indvdum@0
   553
indvdum@0
   554
$template->assign_vars(array(
indvdum@0
   555
	'PAGINATION'	=> generate_pagination(append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : '')), $topics_count, $config['topics_per_page'], $start),
indvdum@0
   556
	'PAGE_NUMBER'	=> on_page($topics_count, $config['topics_per_page'], $start),
indvdum@0
   557
	'TOTAL_TOPICS'	=> ($s_display_active) ? false : (($total_topic_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $total_topic_count)))
indvdum@0
   558
);
indvdum@0
   559
indvdum@0
   560
$topic_list = ($store_reverse) ? array_merge($announcement_list, array_reverse($topic_list)) : array_merge($announcement_list, $topic_list);
indvdum@0
   561
$topic_tracking_info = $tracking_topics = array();
indvdum@0
   562
indvdum@0
   563
// Okay, lets dump out the page ...
indvdum@0
   564
if (sizeof($topic_list))
indvdum@0
   565
{
indvdum@0
   566
	$mark_forum_read = true;
indvdum@0
   567
	$mark_time_forum = 0;
indvdum@0
   568
indvdum@0
   569
	// Active topics?
indvdum@0
   570
	if ($s_display_active && sizeof($active_forum_ary))
indvdum@0
   571
	{
indvdum@0
   572
		// Generate topic forum list...
indvdum@0
   573
		$topic_forum_list = array();
indvdum@0
   574
		foreach ($rowset as $t_id => $row)
indvdum@0
   575
		{
indvdum@0
   576
			$topic_forum_list[$row['forum_id']]['forum_mark_time'] = ($config['load_db_lastread'] && $user->data['is_registered'] && isset($row['forum_mark_time'])) ? $row['forum_mark_time'] : 0;
indvdum@0
   577
			$topic_forum_list[$row['forum_id']]['topics'][] = $t_id;
indvdum@0
   578
		}
indvdum@0
   579
indvdum@0
   580
		if ($config['load_db_lastread'] && $user->data['is_registered'])
indvdum@0
   581
		{
indvdum@0
   582
			foreach ($topic_forum_list as $f_id => $topic_row)
indvdum@0
   583
			{
indvdum@0
   584
				$topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']), false);
indvdum@0
   585
			}
indvdum@0
   586
		}
indvdum@0
   587
		else if ($config['load_anon_lastread'] || $user->data['is_registered'])
indvdum@0
   588
		{
indvdum@0
   589
			foreach ($topic_forum_list as $f_id => $topic_row)
indvdum@0
   590
			{
indvdum@0
   591
				$topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics'], false);
indvdum@0
   592
			}
indvdum@0
   593
		}
indvdum@0
   594
indvdum@0
   595
		unset($topic_forum_list);
indvdum@0
   596
	}
indvdum@0
   597
	else
indvdum@0
   598
	{
indvdum@0
   599
		if ($config['load_db_lastread'] && $user->data['is_registered'])
indvdum@0
   600
		{
indvdum@0
   601
			$topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $rowset, array($forum_id => $forum_data['mark_time']), $global_announce_list);
indvdum@0
   602
			$mark_time_forum = (!empty($forum_data['mark_time'])) ? $forum_data['mark_time'] : $user->data['user_lastmark'];
indvdum@0
   603
		}
indvdum@0
   604
		else if ($config['load_anon_lastread'] || $user->data['is_registered'])
indvdum@0
   605
		{
indvdum@0
   606
			$topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list, $global_announce_list);
indvdum@0
   607
indvdum@0
   608
			if (!$user->data['is_registered'])
indvdum@0
   609
			{
indvdum@0
   610
				$user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
indvdum@0
   611
			}
indvdum@0
   612
			$mark_time_forum = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
indvdum@0
   613
		}
indvdum@0
   614
	}
indvdum@0
   615
indvdum@0
   616
	$s_type_switch = 0;
indvdum@0
   617
	foreach ($topic_list as $topic_id)
indvdum@0
   618
	{
indvdum@0
   619
		$row = &$rowset[$topic_id];
indvdum@0
   620
indvdum@0
   621
		$topic_forum_id = ($row['forum_id']) ? (int) $row['forum_id'] : $forum_id;
indvdum@0
   622
indvdum@0
   623
		// This will allow the style designer to output a different header
indvdum@0
   624
		// or even separate the list of announcements from sticky and normal topics
indvdum@0
   625
		$s_type_switch_test = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
indvdum@0
   626
indvdum@0
   627
		// Replies
indvdum@0
   628
		$replies = ($auth->acl_get('m_approve', $topic_forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
indvdum@0
   629
indvdum@0
   630
		if ($row['topic_status'] == ITEM_MOVED)
indvdum@0
   631
		{
indvdum@0
   632
			$topic_id = $row['topic_moved_id'];
indvdum@0
   633
			$unread_topic = false;
indvdum@0
   634
		}
indvdum@0
   635
		else
indvdum@0
   636
		{
indvdum@0
   637
			$unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
indvdum@0
   638
		}
indvdum@0
   639
indvdum@0
   640
		// Get folder img, topic status/type related information
indvdum@0
   641
		$folder_img = $folder_alt = $topic_type = '';
indvdum@0
   642
		topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
indvdum@0
   643
indvdum@0
   644
		// Generate all the URIs ...
indvdum@0
   645
		$view_topic_url_params = 'f=' . $topic_forum_id . '&amp;t=' . $topic_id;
indvdum@0
   646
		$view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params);
indvdum@0
   647
indvdum@0
   648
		$topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $topic_forum_id)) ? true : false;
indvdum@0
   649
		$posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $topic_forum_id)) ? true : false;
indvdum@0
   650
		$u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&amp;t=$topic_id", true, $user->session_id) : '';
indvdum@0
   651
indvdum@0
   652
		// Send vars to template
indvdum@0
   653
		$template->assign_block_vars('topicrow', array(
indvdum@0
   654
			'FORUM_ID'					=> $topic_forum_id,
indvdum@0
   655
			'TOPIC_ID'					=> $topic_id,
indvdum@0
   656
			'TOPIC_AUTHOR'				=> get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
indvdum@0
   657
			'TOPIC_AUTHOR_COLOUR'		=> get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
indvdum@0
   658
			'TOPIC_AUTHOR_FULL'			=> get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
indvdum@0
   659
			'FIRST_POST_TIME'			=> $user->format_date($row['topic_time']),
indvdum@0
   660
			'LAST_POST_SUBJECT'			=> censor_text($row['topic_last_post_subject']),
indvdum@0
   661
			'LAST_POST_TIME'			=> $user->format_date($row['topic_last_post_time']),
indvdum@0
   662
			'LAST_VIEW_TIME'			=> $user->format_date($row['topic_last_view_time']),
indvdum@0
   663
			'LAST_POST_AUTHOR'			=> get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
indvdum@0
   664
			'LAST_POST_AUTHOR_COLOUR'	=> get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
indvdum@0
   665
			'LAST_POST_AUTHOR_FULL'		=> get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
indvdum@0
   666
indvdum@0
   667
			'PAGINATION'		=> topic_generate_pagination($replies, $view_topic_url),
indvdum@0
   668
			'REPLIES'			=> $replies,
indvdum@0
   669
			'VIEWS'				=> $row['topic_views'],
indvdum@0
   670
			'TOPIC_TITLE'		=> censor_text($row['topic_title']),
indvdum@0
   671
			'TOPIC_TYPE'		=> $topic_type,
indvdum@0
   672
indvdum@0
   673
			'TOPIC_FOLDER_IMG'		=> $user->img($folder_img, $folder_alt),
indvdum@0
   674
			'TOPIC_FOLDER_IMG_SRC'	=> $user->img($folder_img, $folder_alt, false, '', 'src'),
indvdum@0
   675
			'TOPIC_FOLDER_IMG_ALT'	=> $user->lang[$folder_alt],
indvdum@0
   676
			'TOPIC_FOLDER_IMG_WIDTH'=> $user->img($folder_img, '', false, '', 'width'),
indvdum@0
   677
			'TOPIC_FOLDER_IMG_HEIGHT'	=> $user->img($folder_img, '', false, '', 'height'),
indvdum@0
   678
indvdum@0
   679
			'TOPIC_ICON_IMG'		=> (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
indvdum@0
   680
			'TOPIC_ICON_IMG_WIDTH'	=> (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
indvdum@0
   681
			'TOPIC_ICON_IMG_HEIGHT'	=> (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
indvdum@0
   682
			'ATTACH_ICON_IMG'		=> ($auth->acl_get('u_download') && $auth->acl_get('f_download', $topic_forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
indvdum@0
   683
			'UNAPPROVED_IMG'		=> ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
indvdum@0
   684
indvdum@0
   685
			'S_TOPIC_TYPE'			=> $row['topic_type'],
indvdum@0
   686
			'S_USER_POSTED'			=> (isset($row['topic_posted']) && $row['topic_posted']) ? true : false,
indvdum@0
   687
			'S_UNREAD_TOPIC'		=> $unread_topic,
indvdum@0
   688
			'S_TOPIC_REPORTED'		=> (!empty($row['topic_reported']) && $auth->acl_get('m_report', $topic_forum_id)) ? true : false,
indvdum@0
   689
			'S_TOPIC_UNAPPROVED'	=> $topic_unapproved,
indvdum@0
   690
			'S_POSTS_UNAPPROVED'	=> $posts_unapproved,
indvdum@0
   691
			'S_HAS_POLL'			=> ($row['poll_start']) ? true : false,
indvdum@0
   692
			'S_POST_ANNOUNCE'		=> ($row['topic_type'] == POST_ANNOUNCE) ? true : false,
indvdum@0
   693
			'S_POST_GLOBAL'			=> ($row['topic_type'] == POST_GLOBAL) ? true : false,
indvdum@0
   694
			'S_POST_STICKY'			=> ($row['topic_type'] == POST_STICKY) ? true : false,
indvdum@0
   695
			'S_TOPIC_LOCKED'		=> ($row['topic_status'] == ITEM_LOCKED) ? true : false,
indvdum@0
   696
			'S_TOPIC_MOVED'			=> ($row['topic_status'] == ITEM_MOVED) ? true : false,
indvdum@0
   697
indvdum@0
   698
			'U_NEWEST_POST'			=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;view=unread') . '#unread',
indvdum@0
   699
			'U_LAST_POST'			=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
indvdum@0
   700
			'U_LAST_POST_AUTHOR'	=> get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
indvdum@0
   701
			'U_TOPIC_AUTHOR'		=> get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
indvdum@0
   702
			'U_VIEW_TOPIC'			=> $view_topic_url,
indvdum@0
   703
			'U_MCP_REPORT'			=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=reports&amp;f=' . $topic_forum_id . '&amp;t=' . $topic_id, true, $user->session_id),
indvdum@0
   704
			'U_MCP_QUEUE'			=> $u_mcp_queue,
indvdum@0
   705
indvdum@0
   706
			'S_TOPIC_TYPE_SWITCH'	=> ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test)
indvdum@0
   707
		);
indvdum@0
   708
indvdum@0
   709
		$s_type_switch = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
indvdum@0
   710
indvdum@0
   711
		if ($unread_topic)
indvdum@0
   712
		{
indvdum@0
   713
			$mark_forum_read = false;
indvdum@0
   714
		}
indvdum@0
   715
indvdum@0
   716
		unset($rowset[$topic_id]);
indvdum@0
   717
	}
indvdum@0
   718
}
indvdum@0
   719
indvdum@0
   720
// This is rather a fudge but it's the best I can think of without requiring information
indvdum@0
   721
// on all topics (as we do in 2.0.x). It looks for unread or new topics, if it doesn't find
indvdum@0
   722
// any it updates the forum last read cookie. This requires that the user visit the forum
indvdum@0
   723
// after reading a topic
indvdum@0
   724
if ($forum_data['forum_type'] == FORUM_POST && sizeof($topic_list) && $mark_forum_read)
indvdum@0
   725
{
indvdum@0
   726
	update_forum_tracking_info($forum_id, $forum_data['forum_last_post_time'], false, $mark_time_forum);
indvdum@0
   727
}
indvdum@0
   728
indvdum@0
   729
page_footer();
indvdum@0
   730
indvdum@0
   731
?>