~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/php/phpBB3/viewforum.php

Port ivle.webapp.filesystem.{diff,svnlog}'s media to the new framework.

Show diffs side-by-side

added added

removed removed

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