phpBB
Statistics
| Revision:

root / trunk / phpBB / viewforum.php

History | View | Annotate | Download (29.5 kB)

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