phpBB
Statistics
| Revision:

root / trunk / phpBB / includes / functions_display.php

History | View | Annotate | Download (42.6 kB)

1
<?php
2
/**
3
*
4
* @package phpBB3
5
* @copyright (c) 2005 phpBB Group
6
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
*
8
*/
9
10
/**
11
* @ignore
12
*/
13
if (!defined('IN_PHPBB'))
14
{
15
        exit;
16
}
17
18
/**
19
* Display Forums
20
*/
21
function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
22
{
23
        global $db, $auth, $user, $template;
24
        global $phpbb_root_path, $phpEx, $config;
25
        global $request;
26
27
        $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
28
        $parent_id = $visible_forums = 0;
29
        $sql_from = '';
30
31
        // Mark forums read?
32
        $mark_read = request_var('mark', '');
33
34
        if ($mark_read == 'all')
35
        {
36
                $mark_read = '';
37
        }
38
39
        if (!$root_data)
40
        {
41
                if ($mark_read == 'forums')
42
                {
43
                        $mark_read = 'all';
44
                }
45
46
                $root_data = array('forum_id' => 0);
47
                $sql_where = '';
48
        }
49
        else
50
        {
51
                $sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
52
        }
53
54
        // Handle marking everything read
55
        if ($mark_read == 'all')
56
        {
57
                $redirect = build_url(array('mark', 'hash'));
58
                meta_refresh(3, $redirect);
59
60
                if (check_link_hash(request_var('hash', ''), 'global'))
61
                {
62
                        markread('all');
63
64
                        trigger_error(
65
                                $user->lang['FORUMS_MARKED'] . '<br /><br />' .
66
                                sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>')
67
                        );
68
                }
69
                else
70
                {
71
                        trigger_error(sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
72
                }
73
        }
74
75
        // Display list of active topics for this category?
76
        $show_active = (isset($root_data['forum_flags']) && ($root_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
77
78
        $sql_array = array(
79
                'SELECT'        => 'f.*',
80
                'FROM'                => array(
81
                        FORUMS_TABLE                => 'f'
82
                ),
83
                'LEFT_JOIN'        => array(),
84
        );
85
86
        if ($config['load_db_lastread'] && $user->data['is_registered'])
87
        {
88
                $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id');
89
                $sql_array['SELECT'] .= ', ft.mark_time';
90
        }
91
        else if ($config['load_anon_lastread'] || $user->data['is_registered'])
92
        {
93
                $tracking_topics = $request->variable($config['cookie_name'] . '_track', '', true, phpbb_request_interface::COOKIE);
94
                $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
95
96
                if (!$user->data['is_registered'])
97
                {
98
                        $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
99
                }
100
        }
101
102
        if ($show_active)
103
        {
104
                $sql_array['LEFT_JOIN'][] = array(
105
                        'FROM'        => array(FORUMS_ACCESS_TABLE => 'fa'),
106
                        'ON'        => "fa.forum_id = f.forum_id AND fa.session_id = '" . $db->sql_escape($user->session_id) . "'"
107
                );
108
109
                $sql_array['SELECT'] .= ', fa.user_id';
110
        }
111
112
        $sql_ary = array(
113
                'SELECT'        => $sql_array['SELECT'],
114
                'FROM'                => $sql_array['FROM'],
115
                'LEFT_JOIN'        => $sql_array['LEFT_JOIN'],
116
117
                'WHERE'                => $sql_where,
118
119
                'ORDER_BY'        => 'f.left_id',
120
        );
121
122
        $sql = $db->sql_build_query('SELECT', $sql_ary);
123
        $result = $db->sql_query($sql);
124
125
        $forum_tracking_info = array();
126
        $branch_root_id = $root_data['forum_id'];
127
128
        while ($row = $db->sql_fetchrow($result))
129
        {
130
                $forum_id = $row['forum_id'];
131
132
                // Mark forums read?
133
                if ($mark_read == 'forums')
134
                {
135
                        if ($auth->acl_get('f_list', $forum_id))
136
                        {
137
                                $forum_ids[] = $forum_id;
138
                        }
139
140
                        continue;
141
                }
142
143
                // Category with no members
144
                if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
145
                {
146
                        continue;
147
                }
148
149
                // Skip branch
150
                if (isset($right_id))
151
                {
152
                        if ($row['left_id'] < $right_id)
153
                        {
154
                                continue;
155
                        }
156
                        unset($right_id);
157
                }
158
159
                if (!$auth->acl_get('f_list', $forum_id))
160
                {
161
                        // if the user does not have permissions to list this forum, skip everything until next branch
162
                        $right_id = $row['right_id'];
163
                        continue;
164
                }
165
166
                if ($config['load_db_lastread'] && $user->data['is_registered'])
167
                {
168
                        $forum_tracking_info[$forum_id] = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
169
                }
170
                else if ($config['load_anon_lastread'] || $user->data['is_registered'])
171
                {
172
                        if (!$user->data['is_registered'])
173
                        {
174
                                $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
175
                        }
176
                        $forum_tracking_info[$forum_id] = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
177
                }
178
179
                // Count the difference of real to public topics, so we can display an information to moderators
180
                $row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && ($row['forum_topics_real'] != $row['forum_topics'])) ? $forum_id : 0;
181
                $row['forum_topics'] = ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics'];
182
183
                // Display active topics from this forum?
184
                if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS))
185
                {
186
                        if (!isset($active_forum_ary['forum_topics']))
187
                        {
188
                                $active_forum_ary['forum_topics'] = 0;
189
                        }
190
191
                        if (!isset($active_forum_ary['forum_posts']))
192
                        {
193
                                $active_forum_ary['forum_posts'] = 0;
194
                        }
195
196
                        $active_forum_ary['forum_id'][]                = $forum_id;
197
                        $active_forum_ary['enable_icons'][]        = $row['enable_icons'];
198
                        $active_forum_ary['forum_topics']        += $row['forum_topics'];
199
                        $active_forum_ary['forum_posts']        += $row['forum_posts'];
200
201
                        // If this is a passworded forum we do not show active topics from it if the user is not authorised to view it...
202
                        if ($row['forum_password'] && $row['user_id'] != $user->data['user_id'])
203
                        {
204
                                $active_forum_ary['exclude_forum_id'][] = $forum_id;
205
                        }
206
                }
207
208
                //
209
                if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id)
210
                {
211
                        if ($row['forum_type'] != FORUM_CAT)
212
                        {
213
                                $forum_ids_moderator[] = (int) $forum_id;
214
                        }
215
216
                        // Direct child of current branch
217
                        $parent_id = $forum_id;
218
                        $forum_rows[$forum_id] = $row;
219
220
                        if ($row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id'])
221
                        {
222
                                $branch_root_id = $forum_id;
223
                        }
224
                        $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
225
                        $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
226
                }
227
                else if ($row['forum_type'] != FORUM_CAT)
228
                {
229
                        $subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index']) ? true : false;
230
                        $subforums[$parent_id][$forum_id]['name'] = $row['forum_name'];
231
                        $subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
232
                        $subforums[$parent_id][$forum_id]['children'] = array();
233
234
                        if (isset($subforums[$parent_id][$row['parent_id']]) && !$row['display_on_index'])
235
                        {
236
                                $subforums[$parent_id][$row['parent_id']]['children'][] = $forum_id;
237
                        }
238
239
                        if (!$forum_rows[$parent_id]['forum_id_unapproved_topics'] && $row['forum_id_unapproved_topics'])
240
                        {
241
                                $forum_rows[$parent_id]['forum_id_unapproved_topics'] = $forum_id;
242
                        }
243
244
                        $forum_rows[$parent_id]['forum_topics'] += $row['forum_topics'];
245
246
                        // Do not list redirects in LINK Forums as Posts.
247
                        if ($row['forum_type'] != FORUM_LINK)
248
                        {
249
                                $forum_rows[$parent_id]['forum_posts'] += $row['forum_posts'];
250
                        }
251
252
                        if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time'])
253
                        {
254
                                $forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
255
                                $forum_rows[$parent_id]['forum_last_post_subject'] = $row['forum_last_post_subject'];
256
                                $forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
257
                                $forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
258
                                $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
259
                                $forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour'];
260
                                $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
261
                        }
262
                }
263
        }
264
        $db->sql_freeresult($result);
265
266
        // Handle marking posts
267
        if ($mark_read == 'forums')
268
        {
269
                $redirect = build_url(array('mark', 'hash'));
270
                $token = request_var('hash', '');
271
                if (check_link_hash($token, 'global'))
272
                {
273
                        markread('topics', $forum_ids);
274
                        $message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
275
                        meta_refresh(3, $redirect);
276
                        trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . $message);
277
                }
278
                else
279
                {
280
                        $message = sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
281
                        meta_refresh(3, $redirect);
282
                        trigger_error($message);
283
                }
284
285
        }
286
287
        // Grab moderators ... if necessary
288
        if ($display_moderators)
289
        {
290
                if ($return_moderators)
291
                {
292
                        $forum_ids_moderator[] = $root_data['forum_id'];
293
                }
294
                get_moderators($forum_moderators, $forum_ids_moderator);
295
        }
296
297
        // Used to tell whatever we have to create a dummy category or not.
298
        $last_catless = true;
299
        foreach ($forum_rows as $row)
300
        {
301
                // Empty category
302
                if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT)
303
                {
304
                        $template->assign_block_vars('forumrow', array(
305
                                'S_IS_CAT'                                => true,
306
                                'FORUM_ID'                                => $row['forum_id'],
307
                                'FORUM_NAME'                        => $row['forum_name'],
308
                                'FORUM_DESC'                        => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
309
                                'FORUM_FOLDER_IMG'                => '',
310
                                'FORUM_FOLDER_IMG_SRC'        => '',
311
                                'FORUM_IMAGE'                        => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang['FORUM_CAT'] . '" />' : '',
312
                                'FORUM_IMAGE_SRC'                => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
313
                                'U_VIEWFORUM'                        => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
314
                        );
315
316
                        continue;
317
                }
318
319
                $visible_forums++;
320
                $forum_id = $row['forum_id'];
321
322
                $forum_unread = (isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id]) ? true : false;
323
324
                $folder_image = $folder_alt = $l_subforums = '';
325
                $subforums_list = array();
326
327
                // Generate list of subforums if we need to
328
                if (isset($subforums[$forum_id]))
329
                {
330
                        foreach ($subforums[$forum_id] as $subforum_id => $subforum_row)
331
                        {
332
                                $subforum_unread = (isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id]) ? true : false;
333
334
                                if (!$subforum_unread && !empty($subforum_row['children']))
335
                                {
336
                                        foreach ($subforum_row['children'] as $child_id)
337
                                        {
338
                                                if (isset($forum_tracking_info[$child_id]) && $subforums[$forum_id][$child_id]['orig_forum_last_post_time'] > $forum_tracking_info[$child_id])
339
                                                {
340
                                                        // Once we found an unread child forum, we can drop out of this loop
341
                                                        $subforum_unread = true;
342
                                                        break;
343
                                                }
344
                                        }
345
                                }
346
347
                                if ($subforum_row['display'] && $subforum_row['name'])
348
                                {
349
                                        $subforums_list[] = array(
350
                                                'link'                => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $subforum_id),
351
                                                'name'                => $subforum_row['name'],
352
                                                'unread'        => $subforum_unread,
353
                                        );
354
                                }
355
                                else
356
                                {
357
                                        unset($subforums[$forum_id][$subforum_id]);
358
                                }
359
360
                                // If one subforum is unread the forum gets unread too...
361
                                if ($subforum_unread)
362
                                {
363
                                        $forum_unread = true;
364
                                }
365
                        }
366
367
                        $l_subforums = (sizeof($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';
368
                        $folder_image = ($forum_unread) ? 'forum_unread_subforum' : 'forum_read_subforum';
369
                }
370
                else
371
                {
372
                        switch ($row['forum_type'])
373
                        {
374
                                case FORUM_POST:
375
                                        $folder_image = ($forum_unread) ? 'forum_unread' : 'forum_read';
376
                                break;
377
378
                                case FORUM_LINK:
379
                                        $folder_image = 'forum_link';
380
                                break;
381
                        }
382
                }
383
384
                // Which folder should we display?
385
                if ($row['forum_status'] == ITEM_LOCKED)
386
                {
387
                        $folder_image = ($forum_unread) ? 'forum_unread_locked' : 'forum_read_locked';
388
                        $folder_alt = 'FORUM_LOCKED';
389
                }
390
                else
391
                {
392
                        $folder_alt = ($forum_unread) ? 'UNREAD_POSTS' : 'NO_UNREAD_POSTS';
393
                }
394
395
                // Create last post link information, if appropriate
396
                if ($row['forum_last_post_id'])
397
                {
398
                        $last_post_subject = $row['forum_last_post_subject'];
399
                        $last_post_time = $user->format_date($row['forum_last_post_time']);
400
                        $last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&amp;p=' . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
401
                }
402
                else
403
                {
404
                        $last_post_subject = $last_post_time = $last_post_url = '';
405
                }
406
407
                // Output moderator listing ... if applicable
408
                $l_moderator = $moderators_list = '';
409
                if ($display_moderators && !empty($forum_moderators[$forum_id]))
410
                {
411
                        $l_moderator = (sizeof($forum_moderators[$forum_id]) == 1) ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
412
                        $moderators_list = implode(', ', $forum_moderators[$forum_id]);
413
                }
414
415
                $l_post_click_count = ($row['forum_type'] == FORUM_LINK) ? 'CLICKS' : 'POSTS';
416
                $post_click_count = ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? $row['forum_posts'] : '';
417
418
                $s_subforums_list = array();
419
                foreach ($subforums_list as $subforum)
420
                {
421
                        $s_subforums_list[] = '<a href="' . $subforum['link'] . '" class="subforum ' . (($subforum['unread']) ? 'unread' : 'read') . '" title="' . (($subforum['unread']) ? $user->lang['UNREAD_POSTS'] : $user->lang['NO_UNREAD_POSTS']) . '">' . $subforum['name'] . '</a>';
422
                }
423
                $s_subforums_list = (string) implode(', ', $s_subforums_list);
424
                $catless = ($row['parent_id'] == $root_data['forum_id']) ? true : false;
425
426
                if ($row['forum_type'] != FORUM_LINK)
427
                {
428
                        $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
429
                }
430
                else
431
                {
432
                        // If the forum is a link and we count redirects we need to visit it
433
                        // If the forum is having a password or no read access we do not expose the link, but instead handle it in viewforum
434
                        if (($row['forum_flags'] & FORUM_FLAG_LINK_TRACK) || $row['forum_password'] || !$auth->acl_get('f_read', $forum_id))
435
                        {
436
                                $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
437
                        }
438
                        else
439
                        {
440
                                $u_viewforum = $row['forum_link'];
441
                        }
442
                }
443
444
                $template->assign_block_vars('forumrow', array(
445
                        'S_IS_CAT'                        => false,
446
                        'S_NO_CAT'                        => $catless && !$last_catless,
447
                        'S_IS_LINK'                        => ($row['forum_type'] == FORUM_LINK) ? true : false,
448
                        'S_UNREAD_FORUM'        => $forum_unread,
449
                        'S_AUTH_READ'                => $auth->acl_get('f_read', $row['forum_id']),
450
                        'S_LOCKED_FORUM'        => ($row['forum_status'] == ITEM_LOCKED) ? true : false,
451
                        'S_LIST_SUBFORUMS'        => ($row['display_subforum_list']) ? true : false,
452
                        'S_SUBFORUMS'                => (sizeof($subforums_list)) ? true : false,
453
                        'S_FEED_ENABLED'        => ($config['feed_forum'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $row['forum_options']) && $row['forum_type'] == FORUM_POST) ? true : false,
454
455
                        'FORUM_ID'                                => $row['forum_id'],
456
                        'FORUM_NAME'                        => $row['forum_name'],
457
                        'FORUM_DESC'                        => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
458
                        'TOPICS'                                => $row['forum_topics'],
459
                        $l_post_click_count                => $post_click_count,
460
                        'FORUM_IMG_STYLE'                => $folder_image,
461
                        'FORUM_FOLDER_IMG'                => $user->img($folder_image, $folder_alt),
462
                        'FORUM_FOLDER_IMG_ALT'        => isset($user->lang[$folder_alt]) ? $user->lang[$folder_alt] : '',
463
                        'FORUM_IMAGE'                        => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
464
                        'FORUM_IMAGE_SRC'                => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
465
                        'LAST_POST_SUBJECT'                => censor_text($last_post_subject),
466
                        'LAST_POST_TIME'                => $last_post_time,
467
                        'LAST_POSTER'                        => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
468
                        'LAST_POSTER_COLOUR'        => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
469
                        'LAST_POSTER_FULL'                => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
470
                        'MODERATORS'                        => $moderators_list,
471
                        'SUBFORUMS'                                => $s_subforums_list,
472
473
                        'L_SUBFORUM_STR'                => $l_subforums,
474
                        'L_MODERATOR_STR'                => $l_moderator,
475
476
                        'U_UNAPPROVED_TOPICS'        => ($row['forum_id_unapproved_topics']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=unapproved_topics&amp;f=' . $row['forum_id_unapproved_topics']) : '',
477
                        'U_VIEWFORUM'                => $u_viewforum,
478
                        'U_LAST_POSTER'                => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
479
                        'U_LAST_POST'                => $last_post_url)
480
                );
481
482
                // Assign subforums loop for style authors
483
                foreach ($subforums_list as $subforum)
484
                {
485
                        $template->assign_block_vars('forumrow.subforum', array(
486
                                'U_SUBFORUM'        => $subforum['link'],
487
                                'SUBFORUM_NAME'        => $subforum['name'],
488
                                'S_UNREAD'                => $subforum['unread'])
489
                        );
490
                }
491
492
                $last_catless = $catless;
493
        }
494
495
        $template->assign_vars(array(
496
                'U_MARK_FORUMS'                => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . '&amp;f=' . $root_data['forum_id'] . '&amp;mark=forums') : '',
497
                'S_HAS_SUBFORUM'        => ($visible_forums) ? true : false,
498
                'L_SUBFORUM'                => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'],
499
                'LAST_POST_IMG'                => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
500
                'UNAPPROVED_IMG'        => $user->img('icon_topic_unapproved', 'TOPICS_UNAPPROVED'),
501
        ));
502
503
        if ($return_moderators)
504
        {
505
                return array($active_forum_ary, $forum_moderators);
506
        }
507
508
        return array($active_forum_ary, array());
509
}
510
511
/**
512
* Create forum rules for given forum
513
*/
514
function generate_forum_rules(&$forum_data)
515
{
516
        if (!$forum_data['forum_rules'] && !$forum_data['forum_rules_link'])
517
        {
518
                return;
519
        }
520
521
        global $template, $phpbb_root_path, $phpEx;
522
523
        if ($forum_data['forum_rules'])
524
        {
525
                $forum_data['forum_rules'] = generate_text_for_display($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options']);
526
        }
527
528
        $template->assign_vars(array(
529
                'S_FORUM_RULES'        => true,
530
                'U_FORUM_RULES'        => $forum_data['forum_rules_link'],
531
                'FORUM_RULES'        => $forum_data['forum_rules'])
532
        );
533
}
534
535
/**
536
* Create forum navigation links for given forum, create parent
537
* list if currently null, assign basic forum info to template
538
*/
539
function generate_forum_nav(&$forum_data)
540
{
541
        global $db, $user, $template, $auth, $config;
542
        global $phpEx, $phpbb_root_path;
543
544
        if (!$auth->acl_get('f_list', $forum_data['forum_id']))
545
        {
546
                return;
547
        }
548
549
        // Get forum parents
550
        $forum_parents = get_forum_parents($forum_data);
551
552
        // Build navigation links
553
        if (!empty($forum_parents))
554
        {
555
                foreach ($forum_parents as $parent_forum_id => $parent_data)
556
                {
557
                        list($parent_name, $parent_type) = array_values($parent_data);
558
559
                        // Skip this parent if the user does not have the permission to view it
560
                        if (!$auth->acl_get('f_list', $parent_forum_id))
561
                        {
562
                                continue;
563
                        }
564
565
                        $template->assign_block_vars('navlinks', array(
566
                                'S_IS_CAT'                => ($parent_type == FORUM_CAT) ? true : false,
567
                                'S_IS_LINK'                => ($parent_type == FORUM_LINK) ? true : false,
568
                                'S_IS_POST'                => ($parent_type == FORUM_POST) ? true : false,
569
                                'FORUM_NAME'        => $parent_name,
570
                                'FORUM_ID'                => $parent_forum_id,
571
                                'U_VIEW_FORUM'        => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $parent_forum_id))
572
                        );
573
                }
574
        }
575
576
        $template->assign_block_vars('navlinks', array(
577
                'S_IS_CAT'                => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
578
                'S_IS_LINK'                => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
579
                'S_IS_POST'                => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
580
                'FORUM_NAME'        => $forum_data['forum_name'],
581
                'FORUM_ID'                => $forum_data['forum_id'],
582
                'U_VIEW_FORUM'        => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_data['forum_id']))
583
        );
584
585
        $template->assign_vars(array(
586
                'FORUM_ID'                 => $forum_data['forum_id'],
587
                'FORUM_NAME'        => $forum_data['forum_name'],
588
                'FORUM_DESC'        => generate_text_for_display($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options']),
589
590
                'S_ENABLE_FEEDS_FORUM'        => ($config['feed_forum'] && $forum_data['forum_type'] == FORUM_POST && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $forum_data['forum_options'])) ? true : false,
591
        ));
592
593
        return;
594
}
595
596
/**
597
* Returns forum parents as an array. Get them from forum_data if available, or update the database otherwise
598
*/
599
function get_forum_parents(&$forum_data)
600
{
601
        global $db;
602
603
        $forum_parents = array();
604
605
        if ($forum_data['parent_id'] > 0)
606
        {
607
                if ($forum_data['forum_parents'] == '')
608
                {
609
                        $sql = 'SELECT forum_id, forum_name, forum_type
610
                                FROM ' . FORUMS_TABLE . '
611
                                WHERE left_id < ' . $forum_data['left_id'] . '
612
                                        AND right_id > ' . $forum_data['right_id'] . '
613
                                ORDER BY left_id ASC';
614
                        $result = $db->sql_query($sql);
615
616
                        while ($row = $db->sql_fetchrow($result))
617
                        {
618
                                $forum_parents[$row['forum_id']] = array($row['forum_name'], (int) $row['forum_type']);
619
                        }
620
                        $db->sql_freeresult($result);
621
622
                        $forum_data['forum_parents'] = serialize($forum_parents);
623
624
                        $sql = 'UPDATE ' . FORUMS_TABLE . "
625
                                SET forum_parents = '" . $db->sql_escape($forum_data['forum_parents']) . "'
626
                                WHERE parent_id = " . $forum_data['parent_id'];
627
                        $db->sql_query($sql);
628
                }
629
                else
630
                {
631
                        $forum_parents = unserialize($forum_data['forum_parents']);
632
                }
633
        }
634
635
        return $forum_parents;
636
}
637
638
/**
639
* Generate topic pagination
640
*/
641
function topic_generate_pagination($replies, $url)
642
{
643
        global $config, $user;
644
645
        // Make sure $per_page is a valid value
646
        $per_page = ($config['posts_per_page'] <= 0) ? 1 : $config['posts_per_page'];
647
648
        if (($replies + 1) > $per_page)
649
        {
650
                $total_pages = ceil(($replies + 1) / $per_page);
651
                $pagination = '';
652
653
                $times = 1;
654
                for ($j = 0; $j < $replies + 1; $j += $per_page)
655
                {
656
                        $pagination .= '<a href="' . $url . ($j == 0 ? '' : '&amp;start=' . $j) . '">' . $times . '</a>';
657
                        if ($times == 1 && $total_pages > 5)
658
                        {
659
                                $pagination .= '<span class="page-dots"> ... </span>';
660
661
                                // Display the last three pages
662
                                $times = $total_pages - 3;
663
                                $j += ($total_pages - 4) * $per_page;
664
                        }
665
                        else if ($times < $total_pages)
666
                        {
667
                                $pagination .= '<span class="page-sep">' . $user->lang['COMMA_SEPARATOR'] . '</span>';
668
                        }
669
                        $times++;
670
                }
671
        }
672
        else
673
        {
674
                $pagination = '';
675
        }
676
677
        return $pagination;
678
}
679
680
/**
681
* Obtain list of moderators of each forum
682
*/
683
function get_moderators(&$forum_moderators, $forum_id = false)
684
{
685
        global $config, $template, $db, $phpbb_root_path, $phpEx, $user, $auth;
686
687
        $forum_id_ary = array();
688
689
        if ($forum_id !== false)
690
        {
691
                if (!is_array($forum_id))
692
                {
693
                        $forum_id = array($forum_id);
694
                }
695
696
                // Exchange key/value pair to be able to faster check for the forum id existence
697
                $forum_id_ary = array_flip($forum_id);
698
        }
699
700
        $sql_array = array(
701
                'SELECT'        => 'm.*, u.user_colour, g.group_colour, g.group_type',
702
703
                'FROM'                => array(
704
                        MODERATOR_CACHE_TABLE        => 'm',
705
                ),
706
707
                'LEFT_JOIN'        => array(
708
                        array(
709
                                'FROM'        => array(USERS_TABLE => 'u'),
710
                                'ON'        => 'm.user_id = u.user_id',
711
                        ),
712
                        array(
713
                                'FROM'        => array(GROUPS_TABLE => 'g'),
714
                                'ON'        => 'm.group_id = g.group_id',
715
                        ),
716
                ),
717
718
                'WHERE'                => 'm.display_on_index = 1',
719
        );
720
721
        // We query every forum here because for caching we should not have any parameter.
722
        $sql = $db->sql_build_query('SELECT', $sql_array);
723
        $result = $db->sql_query($sql, 3600);
724
725
        while ($row = $db->sql_fetchrow($result))
726
        {
727
                $f_id = (int) $row['forum_id'];
728
729
                if (!isset($forum_id_ary[$f_id]))
730
                {
731
                        continue;
732
                }
733
734
                if (!empty($row['user_id']))
735
                {
736
                        $forum_moderators[$f_id][] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
737
                }
738
                else
739
                {
740
                        $group_name = (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']);
741
742
                        if ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_viewprofile'))
743
                        {
744
                                $forum_moderators[$f_id][] = '<span' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . '>' . $group_name . '</span>';
745
                        }
746
                        else
747
                        {
748
                                $forum_moderators[$f_id][] = '<a' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . ' href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id']) . '">' . $group_name . '</a>';
749
                        }
750
                }
751
        }
752
        $db->sql_freeresult($result);
753
754
        return;
755
}
756
757
/**
758
* User authorisation levels output
759
*
760
* @param        string        $mode                        Can be forum or topic. Not in use at the moment.
761
* @param        int                $forum_id                The current forum the user is in.
762
* @param        int                $forum_status        The forums status bit.
763
*/
764
function gen_forum_auth_level($mode, $forum_id, $forum_status)
765
{
766
        global $template, $auth, $user, $config;
767
768
        $locked = ($forum_status == ITEM_LOCKED && !$auth->acl_get('m_edit', $forum_id)) ? true : false;
769
770
        $rules = array(
771
                ($auth->acl_get('f_post', $forum_id) && !$locked) ? $user->lang['RULES_POST_CAN'] : $user->lang['RULES_POST_CANNOT'],
772
                ($auth->acl_get('f_reply', $forum_id) && !$locked) ? $user->lang['RULES_REPLY_CAN'] : $user->lang['RULES_REPLY_CANNOT'],
773
                ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id) && !$locked) ? $user->lang['RULES_EDIT_CAN'] : $user->lang['RULES_EDIT_CANNOT'],
774
                ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'],
775
        );
776
777
        if ($config['allow_attachments'])
778
        {
779
                $rules[] = ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && !$locked) ? $user->lang['RULES_ATTACH_CAN'] : $user->lang['RULES_ATTACH_CANNOT'];
780
        }
781
782
        foreach ($rules as $rule)
783
        {
784
                $template->assign_block_vars('rules', array('RULE' => $rule));
785
        }
786
787
        return;
788
}
789
790
/**
791
* Generate topic status
792
*/
793
function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$folder_alt, &$topic_type)
794
{
795
        global $user, $config;
796
797
        $folder = $folder_new = '';
798
799
        if ($topic_row['topic_status'] == ITEM_MOVED)
800
        {
801
                $topic_type = $user->lang['VIEW_TOPIC_MOVED'];
802
                $folder_img = 'topic_moved';
803
                $folder_alt = 'TOPIC_MOVED';
804
        }
805
        else
806
        {
807
                switch ($topic_row['topic_type'])
808
                {
809
                        case POST_GLOBAL:
810
                                $topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
811
                                $folder = 'global_read';
812
                                $folder_new = 'global_unread';
813
                        break;
814
815
                        case POST_ANNOUNCE:
816
                                $topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT'];
817
                                $folder = 'announce_read';
818
                                $folder_new = 'announce_unread';
819
                        break;
820
821
                        case POST_STICKY:
822
                                $topic_type = $user->lang['VIEW_TOPIC_STICKY'];
823
                                $folder = 'sticky_read';
824
                                $folder_new = 'sticky_unread';
825
                        break;
826
827
                        default:
828
                                $topic_type = '';
829
                                $folder = 'topic_read';
830
                                $folder_new = 'topic_unread';
831
832
                                // Hot topic threshold is for posts in a topic, which is replies + the first post. ;)
833
                                if ($config['hot_threshold'] && ($replies + 1) >= $config['hot_threshold'] && $topic_row['topic_status'] != ITEM_LOCKED)
834
                                {
835
                                        $folder .= '_hot';
836
                                        $folder_new .= '_hot';
837
                                }
838
                        break;
839
                }
840
841
                if ($topic_row['topic_status'] == ITEM_LOCKED)
842
                {
843
                        $topic_type = $user->lang['VIEW_TOPIC_LOCKED'];
844
                        $folder .= '_locked';
845
                        $folder_new .= '_locked';
846
                }
847
848
849
                $folder_img = ($unread_topic) ? $folder_new : $folder;
850
                $folder_alt = ($unread_topic) ? 'UNREAD_POSTS' : (($topic_row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_UNREAD_POSTS');
851
852
                // Posted image?
853
                if (!empty($topic_row['topic_posted']) && $topic_row['topic_posted'])
854
                {
855
                        $folder_img .= '_mine';
856
                }
857
        }
858
859
        if ($topic_row['poll_start'] && $topic_row['topic_status'] != ITEM_MOVED)
860
        {
861
                $topic_type = $user->lang['VIEW_TOPIC_POLL'];
862
        }
863
}
864
865
/**
866
* Assign/Build custom bbcodes for display in screens supporting using of bbcodes
867
* The custom bbcodes buttons will be placed within the template block 'custom_codes'
868
*/
869
function display_custom_bbcodes()
870
{
871
        global $db, $template, $user;
872
873
        // Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)
874
        $num_predefined_bbcodes = 22;
875
876
        $sql = 'SELECT bbcode_id, bbcode_tag, bbcode_helpline
877
                FROM ' . BBCODES_TABLE . '
878
                WHERE display_on_posting = 1
879
                ORDER BY bbcode_tag';
880
        $result = $db->sql_query($sql);
881
882
        $i = 0;
883
        while ($row = $db->sql_fetchrow($result))
884
        {
885
                // If the helpline is defined within the language file, we will use the localised version, else just use the database entry...
886
                if (isset($user->lang[strtoupper($row['bbcode_helpline'])]))
887
                {
888
                        $row['bbcode_helpline'] = $user->lang[strtoupper($row['bbcode_helpline'])];
889
                }
890
891
                $template->assign_block_vars('custom_tags', array(
892
                        'BBCODE_NAME'                => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'",
893
                        'BBCODE_ID'                        => $num_predefined_bbcodes + ($i * 2),
894
                        'BBCODE_TAG'                => $row['bbcode_tag'],
895
                        'BBCODE_HELPLINE'        => $row['bbcode_helpline'],
896
                        'A_BBCODE_HELPLINE'        => str_replace(array('&amp;', '&quot;', "'", '&lt;', '&gt;'), array('&', '"', "\'", '<', '>'), $row['bbcode_helpline']),
897
                ));
898
899
                $i++;
900
        }
901
        $db->sql_freeresult($result);
902
}
903
904
/**
905
* Display reasons
906
*/
907
function display_reasons($reason_id = 0)
908
{
909
        global $db, $user, $template;
910
911
        $sql = 'SELECT *
912
                FROM ' . REPORTS_REASONS_TABLE . '
913
                ORDER BY reason_order ASC';
914
        $result = $db->sql_query($sql);
915
916
        while ($row = $db->sql_fetchrow($result))
917
        {
918
                // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
919
                if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
920
                {
921
                        $row['reason_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
922
                        $row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
923
                }
924
925
                $template->assign_block_vars('reason', array(
926
                        'ID'                        => $row['reason_id'],
927
                        'TITLE'                        => $row['reason_title'],
928
                        'DESCRIPTION'        => $row['reason_description'],
929
                        'S_SELECTED'        => ($row['reason_id'] == $reason_id) ? true : false)
930
                );
931
        }
932
        $db->sql_freeresult($result);
933
}
934
935
/**
936
* Display user activity (action forum/topic)
937
*/
938
function display_user_activity(&$userdata)
939
{
940
        global $auth, $template, $db, $user;
941
        global $phpbb_root_path, $phpEx;
942
943
        // Do not display user activity for users having more than 5000 posts...
944
        if ($userdata['user_posts'] > 5000)
945
        {
946
                return;
947
        }
948
949
        $forum_ary = array();
950
951
        // Do not include those forums the user is not having read access to...
952
        $forum_read_ary = $auth->acl_getf('!f_read');
953
954
        foreach ($forum_read_ary as $forum_id => $not_allowed)
955
        {
956
                if ($not_allowed['f_read'])
957
                {
958
                        $forum_ary[] = (int) $forum_id;
959
                }
960
        }
961
962
        $forum_ary = array_unique($forum_ary);
963
        $forum_sql = (sizeof($forum_ary)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary, true) : '';
964
965
        $fid_m_approve = $auth->acl_getf('m_approve', true);
966
        $sql_m_approve = (!empty($fid_m_approve)) ? 'OR ' . $db->sql_in_set('forum_id', array_keys($fid_m_approve)) : '';
967
968
        // Obtain active forum
969
        $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts
970
                FROM ' . POSTS_TABLE . '
971
                WHERE poster_id = ' . $userdata['user_id'] . "
972
                        AND post_postcount = 1
973
                        AND (post_approved = 1
974
                                $sql_m_approve)
975
                        $forum_sql
976
                GROUP BY forum_id
977
                ORDER BY num_posts DESC";
978
        $result = $db->sql_query_limit($sql, 1);
979
        $active_f_row = $db->sql_fetchrow($result);
980
        $db->sql_freeresult($result);
981
982
        if (!empty($active_f_row))
983
        {
984
                $sql = 'SELECT forum_name
985
                        FROM ' . FORUMS_TABLE . '
986
                        WHERE forum_id = ' . $active_f_row['forum_id'];
987
                $result = $db->sql_query($sql, 3600);
988
                $active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name');
989
                $db->sql_freeresult($result);
990
        }
991
992
        // Obtain active topic
993
        // We need to exclude passworded forums here so we do not leak the topic title
994
        $forum_ary_topic = array_unique(array_merge($forum_ary, $user->get_passworded_forums()));
995
        $forum_sql_topic = (!empty($forum_ary_topic)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary_topic, true) : '';
996
997
        $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts
998
                FROM ' . POSTS_TABLE . '
999
                WHERE poster_id = ' . $userdata['user_id'] . "
1000
                        AND post_postcount = 1
1001
                        AND (post_approved = 1
1002
                                $sql_m_approve)
1003
                        $forum_sql_topic
1004
                GROUP BY topic_id
1005
                ORDER BY num_posts DESC";
1006
        $result = $db->sql_query_limit($sql, 1);
1007
        $active_t_row = $db->sql_fetchrow($result);
1008
        $db->sql_freeresult($result);
1009
1010
        if (!empty($active_t_row))
1011
        {
1012
                $sql = 'SELECT topic_title
1013
                        FROM ' . TOPICS_TABLE . '
1014
                        WHERE topic_id = ' . $active_t_row['topic_id'];
1015
                $result = $db->sql_query($sql);
1016
                $active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title');
1017
                $db->sql_freeresult($result);
1018
        }
1019
1020
        $userdata['active_t_row'] = $active_t_row;
1021
        $userdata['active_f_row'] = $active_f_row;
1022
1023
        $active_f_name = $active_f_id = $active_f_count = $active_f_pct = '';
1024
        if (!empty($active_f_row['num_posts']))
1025
        {
1026
                $active_f_name = $active_f_row['forum_name'];
1027
                $active_f_id = $active_f_row['forum_id'];
1028
                $active_f_count = $active_f_row['num_posts'];
1029
                $active_f_pct = ($userdata['user_posts']) ? ($active_f_count / $userdata['user_posts']) * 100 : 0;
1030
        }
1031
1032
        $active_t_name = $active_t_id = $active_t_count = $active_t_pct = '';
1033
        if (!empty($active_t_row['num_posts']))
1034
        {
1035
                $active_t_name = $active_t_row['topic_title'];
1036
                $active_t_id = $active_t_row['topic_id'];
1037
                $active_t_count = $active_t_row['num_posts'];
1038
                $active_t_pct = ($userdata['user_posts']) ? ($active_t_count / $userdata['user_posts']) * 100 : 0;
1039
        }
1040
1041
        $l_active_pct = ($userdata['user_id'] != ANONYMOUS && $userdata['user_id'] == $user->data['user_id']) ? $user->lang['POST_PCT_ACTIVE_OWN'] : $user->lang['POST_PCT_ACTIVE'];
1042
1043
        $template->assign_vars(array(
1044
                'ACTIVE_FORUM'                        => $active_f_name,
1045
                'ACTIVE_FORUM_POSTS'        => $user->lang('USER_POSTS', (int) $active_f_count),
1046
                'ACTIVE_FORUM_PCT'                => sprintf($l_active_pct, $active_f_pct),
1047
                'ACTIVE_TOPIC'                        => censor_text($active_t_name),
1048
                'ACTIVE_TOPIC_POSTS'        => $user->lang('USER_POSTS', (int) $active_t_count),
1049
                'ACTIVE_TOPIC_PCT'                => sprintf($l_active_pct, $active_t_pct),
1050
                'U_ACTIVE_FORUM'                => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $active_f_id),
1051
                'U_ACTIVE_TOPIC'                => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $active_t_id),
1052
                'S_SHOW_ACTIVITY'                => true)
1053
        );
1054
}
1055
1056
/**
1057
* Topic and forum watching common code
1058
*/
1059
function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, $notify_status = 'unset', $start = 0, $item_title = '')
1060
{
1061
        global $template, $db, $user, $phpEx, $start, $phpbb_root_path;
1062
        global $request;
1063
1064
        $table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE : TOPICS_WATCH_TABLE;
1065
        $where_sql = ($mode == 'forum') ? 'forum_id' : 'topic_id';
1066
        $match_id = ($mode == 'forum') ? $forum_id : $topic_id;
1067
        $u_url = "uid={$user->data['user_id']}";
1068
        $u_url .= ($mode == 'forum') ? '&amp;f' : '&amp;f=' . $forum_id . '&amp;t';
1069
        $is_watching = 0;
1070
1071
        // Is user watching this thread?
1072
        if ($user_id != ANONYMOUS)
1073
        {
1074
                $can_watch = true;
1075
1076
                if ($notify_status == 'unset')
1077
                {
1078
                        $sql = "SELECT notify_status
1079
                                FROM $table_sql
1080
                                WHERE $where_sql = $match_id
1081
                                        AND user_id = $user_id";
1082
                        $result = $db->sql_query($sql);
1083
1084
                        $notify_status = ($row = $db->sql_fetchrow($result)) ? $row['notify_status'] : NULL;
1085
                        $db->sql_freeresult($result);
1086
                }
1087
1088
                if (!is_null($notify_status) && $notify_status !== '')
1089
                {
1090
                        if (isset($_GET['unwatch']))
1091
                        {
1092
                                $uid = request_var('uid', 0);
1093
                                $token = request_var('hash', '');
1094
1095
                                if ($token && check_link_hash($token, "{$mode}_$match_id") || confirm_box(true))
1096
                                {
1097
                                        if ($uid != $user_id || $request->variable('unwatch', '', false, phpbb_request_interface::GET) != $mode)
1098
                                        {
1099
                                                $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
1100
                                                $message = $user->lang['ERR_UNWATCHING'] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1101
                                                trigger_error($message);
1102
                                        }
1103
1104
                                        $sql = 'DELETE FROM ' . $table_sql . "
1105
                                                WHERE $where_sql = $match_id
1106
                                                        AND user_id = $user_id";
1107
                                        $db->sql_query($sql);
1108
1109
                                        $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
1110
                                        $message = $user->lang['NOT_WATCHING_' . strtoupper($mode)] . '<br /><br />';
1111
                                        $message .= sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1112
                                        meta_refresh(3, $redirect_url);
1113
                                        trigger_error($message);
1114
                                }
1115
                                else
1116
                                {
1117
                                        $s_hidden_fields = array(
1118
                                                'uid'                => $user->data['user_id'],
1119
                                                'unwatch'        => $mode,
1120
                                                'start'                => $start,
1121
                                                'f'                        => $forum_id,
1122
                                        );
1123
                                        if ($mode != 'forum')
1124
                                        {
1125
                                                $s_hidden_fields['t'] = $topic_id;
1126
                                        }
1127
1128
                                        if ($item_title == '')
1129
                                        {
1130
                                                $confirm_box_message = 'UNWATCH_' . strtoupper($mode);
1131
                                        }
1132
                                        else
1133
                                        {
1134
                                                $confirm_box_message = $user->lang('UNWATCH_' . strtoupper($mode) . '_DETAILED', $item_title);
1135
                                        }
1136
                                        confirm_box(false, $confirm_box_message, build_hidden_fields($s_hidden_fields));
1137
                                }
1138
                        }
1139
                        else
1140
                        {
1141
                                $is_watching = true;
1142
1143
                                if ($notify_status != NOTIFY_YES)
1144
                                {
1145
                                        $sql = 'UPDATE ' . $table_sql . "
1146
                                                SET notify_status = " . NOTIFY_YES . "
1147
                                                WHERE $where_sql = $match_id
1148
                                                        AND user_id = $user_id";
1149
                                        $db->sql_query($sql);
1150
                                }
1151
                        }
1152
                }
1153
                else
1154
                {
1155
                        if (isset($_GET['watch']))
1156
                        {
1157
                                $uid = request_var('uid', 0);
1158
                                $token = request_var('hash', '');
1159
1160
                                if ($token && check_link_hash($token, "{$mode}_$match_id") || confirm_box(true))
1161
                                {
1162
                                        if ($uid != $user_id || $request->variable('watch', '', false, phpbb_request_interface::GET) != $mode)
1163
                                        {
1164
                                                $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
1165
                                                $message = $user->lang['ERR_WATCHING'] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1166
                                                trigger_error($message);
1167
                                        }
1168
1169
                                        $is_watching = true;
1170
1171
                                        $sql = 'INSERT INTO ' . $table_sql . " (user_id, $where_sql, notify_status)
1172
                                                VALUES ($user_id, $match_id, " . NOTIFY_YES . ')';
1173
                                        $db->sql_query($sql);
1174
1175
                                        $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
1176
                                        $message = $user->lang['ARE_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1177
                                        meta_refresh(3, $redirect_url);
1178
                                        trigger_error($message);
1179
                                }
1180
                                else
1181
                                {
1182
                                        $s_hidden_fields = array(
1183
                                                'uid'                => $user->data['user_id'],
1184
                                                'watch'                => $mode,
1185
                                                'start'                => $start,
1186
                                                'f'                        => $forum_id,
1187
                                        );
1188
                                        if ($mode != 'forum')
1189
                                        {
1190
                                                $s_hidden_fields['t'] = $topic_id;
1191
                                        }
1192
1193
                                        $confirm_box_message = (($item_title == '') ? 'WATCH_' . strtoupper($mode) : $user->lang('WATCH_' . strtoupper($mode) . '_DETAILED', $item_title));
1194
                                        confirm_box(false, $confirm_box_message, build_hidden_fields($s_hidden_fields));
1195
                                }
1196
                        }
1197
                        else
1198
                        {
1199
                                $is_watching = 0;
1200
                        }
1201
                }
1202
        }
1203
        else
1204
        {
1205
                if ((isset($_GET['unwatch']) && $request->variable('unwatch', '', false, phpbb_request_interface::GET) == $mode) ||
1206
                        (isset($_GET['watch']) && $request->variable('watch', '', false, phpbb_request_interface::GET) == $mode))
1207
                {
1208
                        login_box();
1209
                }
1210
                else
1211
                {
1212
                        $can_watch = 0;
1213
                        $is_watching = 0;
1214
                }
1215
        }
1216
1217
        if ($can_watch)
1218
        {
1219
                $s_watching['link'] = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;" . (($is_watching) ? 'unwatch' : 'watch') . "=$mode&amp;start=$start&amp;hash=" . generate_link_hash("{$mode}_$match_id"));
1220
                $s_watching['title'] = $user->lang[(($is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)];
1221
                $s_watching['is_watching'] = $is_watching;
1222
        }
1223
1224
        return;
1225
}
1226
1227
/**
1228
* Get user rank title and image
1229
*
1230
* @param int $user_rank the current stored users rank id
1231
* @param int $user_posts the users number of posts
1232
* @param string &$rank_title the rank title will be stored here after execution
1233
* @param string &$rank_img the rank image as full img tag is stored here after execution
1234
* @param string &$rank_img_src the rank image source is stored here after execution
1235
*
1236
* Note: since we do not want to break backwards-compatibility, this function will only properly assign ranks to guests if you call it for them with user_posts == false
1237
*/
1238
function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank_img_src)
1239
{
1240
        global $ranks, $config, $phpbb_root_path;
1241
1242
        if (empty($ranks))
1243
        {
1244
                global $cache;
1245
                $ranks = $cache->obtain_ranks();
1246
        }
1247
1248
        if (!empty($user_rank))
1249
        {
1250
                $rank_title = (isset($ranks['special'][$user_rank]['rank_title'])) ? $ranks['special'][$user_rank]['rank_title'] : '';
1251
                $rank_img = (!empty($ranks['special'][$user_rank]['rank_image'])) ? '<img src="' . $phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] . '" alt="' . $ranks['special'][$user_rank]['rank_title'] . '" title="' . $ranks['special'][$user_rank]['rank_title'] . '" />' : '';
1252
                $rank_img_src = (!empty($ranks['special'][$user_rank]['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] : '';
1253
        }
1254
        else if ($user_posts !== false)
1255
        {
1256
                if (!empty($ranks['normal']))
1257
                {
1258
                        foreach ($ranks['normal'] as $rank)
1259
                        {
1260
                                if ($user_posts >= $rank['rank_min'])
1261
                                {
1262
                                        $rank_title = $rank['rank_title'];
1263
                                        $rank_img = (!empty($rank['rank_image'])) ? '<img src="' . $phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image'] . '" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" />' : '';
1264
                                        $rank_img_src = (!empty($rank['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image'] : '';
1265
                                        break;
1266
                                }
1267
                        }
1268
                }
1269
        }
1270
}
1271
1272
/**
1273
* Get user avatar
1274
*
1275
* @param string $avatar Users assigned avatar name
1276
* @param int $avatar_type Type of avatar
1277
* @param string $avatar_width Width of users avatar
1278
* @param string $avatar_height Height of users avatar
1279
* @param string $alt Optional language string for alt tag within image, can be a language key or text
1280
* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP
1281
*
1282
* @return string Avatar image
1283
*/
1284
function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false)
1285
{
1286
        global $user, $config, $phpbb_root_path, $phpEx;
1287
1288
        if (empty($avatar) || !$avatar_type || (!$config['allow_avatar'] && !$ignore_config))
1289
        {
1290
                return '';
1291
        }
1292
1293
        $avatar_img = '';
1294
1295
        switch ($avatar_type)
1296
        {
1297
                case AVATAR_UPLOAD:
1298
                        if (!$config['allow_avatar_upload'] && !$ignore_config)
1299
                        {
1300
                                return '';
1301
                        }
1302
                        $avatar_img = $phpbb_root_path . "download/file.$phpEx?avatar=";
1303
                break;
1304
1305
                case AVATAR_GALLERY:
1306
                        if (!$config['allow_avatar_local'] && !$ignore_config)
1307
                        {
1308
                                return '';
1309
                        }
1310
                        $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
1311
                break;
1312
1313
                case AVATAR_REMOTE:
1314
                        if (!$config['allow_avatar_remote'] && !$ignore_config)
1315
                        {
1316
                                return '';
1317
                        }
1318
                break;
1319
        }
1320
1321
        $avatar_img .= $avatar;
1322
        return '<img src="' . (str_replace(' ', '%20', $avatar_img)) . '" width="' . $avatar_width . '" height="' . $avatar_height . '" alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
1323
}