5
* @version $Id: functions_display.php,v 1.168 2007/10/20 10:12:54 acydburn Exp $
6
* @copyright (c) 2005 phpBB Group
7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
14
if (!defined('IN_PHPBB'))
22
function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
24
global $db, $auth, $user, $template;
25
global $phpbb_root_path, $phpEx, $config;
27
$forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
28
$parent_id = $visible_forums = 0;
32
$mark_read = request_var('mark', '');
34
if ($mark_read == 'all')
41
if ($mark_read == 'forums')
46
$root_data = array('forum_id' => 0);
51
$sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
54
// Display list of active topics for this category?
55
$show_active = (isset($root_data['forum_flags']) && ($root_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
62
'LEFT_JOIN' => array(),
65
if ($config['load_db_lastread'] && $user->data['is_registered'])
67
$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');
68
$sql_array['SELECT'] .= ', ft.mark_time';
70
else if ($config['load_anon_lastread'] || $user->data['is_registered'])
72
$tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : '';
73
$tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
75
if (!$user->data['is_registered'])
77
$user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
83
$sql_array['LEFT_JOIN'][] = array(
84
'FROM' => array(FORUMS_ACCESS_TABLE => 'fa'),
85
'ON' => "fa.forum_id = f.forum_id AND fa.session_id = '" . $db->sql_escape($user->session_id) . "'"
88
$sql_array['SELECT'] .= ', fa.user_id';
91
$sql = $db->sql_build_query('SELECT', array(
92
'SELECT' => $sql_array['SELECT'],
93
'FROM' => $sql_array['FROM'],
94
'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
96
'WHERE' => $sql_where,
98
'ORDER_BY' => 'f.left_id',
101
$result = $db->sql_query($sql);
103
$forum_tracking_info = array();
104
$branch_root_id = $root_data['forum_id'];
105
while ($row = $db->sql_fetchrow($result))
107
$forum_id = $row['forum_id'];
110
if ($mark_read == 'forums' || $mark_read == 'all')
112
if ($auth->acl_get('f_list', $forum_id))
114
$forum_ids[] = $forum_id;
119
// Category with no members
120
if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
126
if (isset($right_id))
128
if ($row['left_id'] < $right_id)
135
if (!$auth->acl_get('f_list', $forum_id))
137
// if the user does not have permissions to list this forum, skip everything until next branch
138
$right_id = $row['right_id'];
142
$forum_ids[] = $forum_id;
144
if ($config['load_db_lastread'] && $user->data['is_registered'])
146
$forum_tracking_info[$forum_id] = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
148
else if ($config['load_anon_lastread'] || $user->data['is_registered'])
150
if (!$user->data['is_registered'])
152
$user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
154
$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'];
157
$row['forum_topics'] = ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics'];
159
// Display active topics from this forum?
160
if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS))
162
if (!isset($active_forum_ary['forum_topics']))
164
$active_forum_ary['forum_topics'] = 0;
167
if (!isset($active_forum_ary['forum_posts']))
169
$active_forum_ary['forum_posts'] = 0;
172
$active_forum_ary['forum_id'][] = $forum_id;
173
$active_forum_ary['enable_icons'][] = $row['enable_icons'];
174
$active_forum_ary['forum_topics'] += $row['forum_topics'];
175
$active_forum_ary['forum_posts'] += $row['forum_posts'];
177
// If this is a passworded forum we do not show active topics from it if the user is not authorised to view it...
178
if ($row['forum_password'] && $row['user_id'] != $user->data['user_id'])
180
$active_forum_ary['exclude_forum_id'][] = $forum_id;
185
if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id)
187
if ($row['forum_type'] != FORUM_CAT)
189
$forum_ids_moderator[] = (int) $forum_id;
192
// Direct child of current branch
193
$parent_id = $forum_id;
194
$forum_rows[$forum_id] = $row;
196
if ($row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id'])
198
$branch_root_id = $forum_id;
200
$forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
201
$forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
203
else if ($row['forum_type'] != FORUM_CAT)
205
$subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index']) ? true : false;
206
$subforums[$parent_id][$forum_id]['name'] = $row['forum_name'];
207
$subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
209
$forum_rows[$parent_id]['forum_topics'] += $row['forum_topics'];
211
// Do not list redirects in LINK Forums as Posts.
212
if ($row['forum_type'] != FORUM_LINK)
214
$forum_rows[$parent_id]['forum_posts'] += $row['forum_posts'];
217
if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time'])
219
$forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
220
$forum_rows[$parent_id]['forum_last_post_subject'] = $row['forum_last_post_subject'];
221
$forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
222
$forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
223
$forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
224
$forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour'];
225
$forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
229
$db->sql_freeresult($result);
231
// Handle marking posts
232
if ($mark_read == 'forums' || $mark_read == 'all')
234
$redirect = build_url('mark');
236
if ($mark_read == 'all')
240
$message = sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>');
244
markread('topics', $forum_ids);
246
$message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
249
meta_refresh(3, $redirect);
250
trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . $message);
253
// Grab moderators ... if necessary
254
if ($display_moderators)
256
if ($return_moderators)
258
$forum_ids_moderator[] = $root_data['forum_id'];
260
get_moderators($forum_moderators, $forum_ids_moderator);
263
// Used to tell whatever we have to create a dummy category or not.
264
$last_catless = true;
265
foreach ($forum_rows as $row)
268
if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT)
270
$template->assign_block_vars('forumrow', array(
272
'FORUM_ID' => $row['forum_id'],
273
'FORUM_NAME' => $row['forum_name'],
274
'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
275
'FORUM_FOLDER_IMG' => '',
276
'FORUM_FOLDER_IMG_SRC' => '',
277
'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang['FORUM_CAT'] . '" />' : '',
278
'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
279
'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
286
$forum_id = $row['forum_id'];
288
$forum_unread = (isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id]) ? true : false;
290
$folder_image = $folder_alt = $l_subforums = '';
291
$subforums_list = array();
293
// Generate list of subforums if we need to
294
if (isset($subforums[$forum_id]))
296
foreach ($subforums[$forum_id] as $subforum_id => $subforum_row)
298
$subforum_unread = (isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id]) ? true : false;
300
if ($subforum_row['display'] && $subforum_row['name'])
302
$subforums_list[] = array(
303
'link' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $subforum_id),
304
'name' => $subforum_row['name'],
305
'unread' => $subforum_unread,
310
unset($subforums[$forum_id][$subforum_id]);
313
// If one subforum is unread the forum gets unread too...
314
if ($subforum_unread)
316
$forum_unread = true;
320
$l_subforums = (sizeof($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';
321
$folder_image = ($forum_unread) ? 'forum_unread_subforum' : 'forum_read_subforum';
325
switch ($row['forum_type'])
328
$folder_image = ($forum_unread) ? 'forum_unread' : 'forum_read';
332
$folder_image = 'forum_link';
337
// Which folder should we display?
338
if ($row['forum_status'] == ITEM_LOCKED)
340
$folder_image = ($forum_unread) ? 'forum_unread_locked' : 'forum_read_locked';
341
$folder_alt = 'FORUM_LOCKED';
345
$folder_alt = ($forum_unread) ? 'NEW_POSTS' : 'NO_NEW_POSTS';
348
// Create last post link information, if appropriate
349
if ($row['forum_last_post_id'])
351
$last_post_subject = $row['forum_last_post_subject'];
352
$last_post_time = $user->format_date($row['forum_last_post_time']);
353
$last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&p=' . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
357
$last_post_subject = $last_post_time = $last_post_url = '';
360
// Output moderator listing ... if applicable
361
$l_moderator = $moderators_list = '';
362
if ($display_moderators && !empty($forum_moderators[$forum_id]))
364
$l_moderator = (sizeof($forum_moderators[$forum_id]) == 1) ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
365
$moderators_list = implode(', ', $forum_moderators[$forum_id]);
368
$l_post_click_count = ($row['forum_type'] == FORUM_LINK) ? 'CLICKS' : 'POSTS';
369
$post_click_count = ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? $row['forum_posts'] : '';
371
$s_subforums_list = array();
372
foreach ($subforums_list as $subforum)
374
$s_subforums_list[] = '<a href="' . $subforum['link'] . '" class="subforum ' . (($subforum['unread']) ? 'unread' : 'read') . '">' . $subforum['name'] . '</a>';
376
$s_subforums_list = (string) implode(', ', $s_subforums_list);
377
$catless = ($row['parent_id'] == $root_data['forum_id']) ? true : false;
379
if ($row['forum_type'] != FORUM_LINK)
381
$u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
385
// If the forum is a link and we count redirects we need to visit it
386
// If the forum is having a password or no read access we do not expose the link, but instead handle it in viewforum
387
if (($row['forum_flags'] & FORUM_FLAG_LINK_TRACK) || $row['forum_password'] || !$auth->acl_get('f_read', $forum_id))
389
$u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
393
$u_viewforum = $row['forum_link'];
397
$template->assign_block_vars('forumrow', array(
399
'S_NO_CAT' => $catless && !$last_catless,
400
'S_IS_LINK' => ($row['forum_type'] == FORUM_LINK) ? true : false,
401
'S_UNREAD_FORUM' => $forum_unread,
402
'S_LOCKED_FORUM' => ($row['forum_status'] == ITEM_LOCKED) ? true : false,
403
'S_SUBFORUMS' => (sizeof($subforums_list)) ? true : false,
405
'FORUM_ID' => $row['forum_id'],
406
'FORUM_NAME' => $row['forum_name'],
407
'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
408
'TOPICS' => $row['forum_topics'],
409
$l_post_click_count => $post_click_count,
410
'FORUM_FOLDER_IMG' => $user->img($folder_image, $folder_alt),
411
'FORUM_FOLDER_IMG_SRC' => $user->img($folder_image, $folder_alt, false, '', 'src'),
412
'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
413
'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
414
'LAST_POST_SUBJECT' => censor_text($last_post_subject),
415
'LAST_POST_TIME' => $last_post_time,
416
'LAST_POSTER' => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
417
'LAST_POSTER_COLOUR' => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
418
'LAST_POSTER_FULL' => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
419
'MODERATORS' => $moderators_list,
420
'SUBFORUMS' => $s_subforums_list,
422
'L_SUBFORUM_STR' => $l_subforums,
423
'L_FORUM_FOLDER_ALT' => $folder_alt,
424
'L_MODERATOR_STR' => $l_moderator,
426
'U_VIEWFORUM' => $u_viewforum,
427
'U_LAST_POSTER' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
428
'U_LAST_POST' => $last_post_url)
431
// Assign subforums loop for style authors
432
foreach ($subforums_list as $subforum)
434
$template->assign_block_vars('forumrow.subforum', array(
435
'U_SUBFORUM' => $subforum['link'],
436
'SUBFORUM_NAME' => $subforum['name'],
437
'S_UNREAD' => $subforum['unread'])
441
$last_catless = $catless;
444
$template->assign_vars(array(
445
'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $root_data['forum_id'] . '&mark=forums') : '',
446
'S_HAS_SUBFORUM' => ($visible_forums) ? true : false,
447
'L_SUBFORUM' => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'],
448
'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'))
451
if ($return_moderators)
453
return array($active_forum_ary, $forum_moderators);
456
return array($active_forum_ary, array());
460
* Create forum rules for given forum
462
function generate_forum_rules(&$forum_data)
464
if (!$forum_data['forum_rules'] && !$forum_data['forum_rules_link'])
469
global $template, $phpbb_root_path, $phpEx;
471
if ($forum_data['forum_rules'])
473
$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']);
476
$template->assign_vars(array(
477
'S_FORUM_RULES' => true,
478
'U_FORUM_RULES' => $forum_data['forum_rules_link'],
479
'FORUM_RULES' => $forum_data['forum_rules'])
484
* Create forum navigation links for given forum, create parent
485
* list if currently null, assign basic forum info to template
487
function generate_forum_nav(&$forum_data)
489
global $db, $user, $template, $auth;
490
global $phpEx, $phpbb_root_path;
492
if (!$auth->acl_get('f_list', $forum_data['forum_id']))
498
$forum_parents = get_forum_parents($forum_data);
500
// Build navigation links
501
if (!empty($forum_parents))
503
foreach ($forum_parents as $parent_forum_id => $parent_data)
505
list($parent_name, $parent_type) = array_values($parent_data);
507
// Skip this parent if the user does not have the permission to view it
508
if (!$auth->acl_get('f_list', $parent_forum_id))
513
$template->assign_block_vars('navlinks', array(
514
'S_IS_CAT' => ($parent_type == FORUM_CAT) ? true : false,
515
'S_IS_LINK' => ($parent_type == FORUM_LINK) ? true : false,
516
'S_IS_POST' => ($parent_type == FORUM_POST) ? true : false,
517
'FORUM_NAME' => $parent_name,
518
'FORUM_ID' => $parent_forum_id,
519
'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $parent_forum_id))
524
$template->assign_block_vars('navlinks', array(
525
'S_IS_CAT' => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
526
'S_IS_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
527
'S_IS_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
528
'FORUM_NAME' => $forum_data['forum_name'],
529
'FORUM_ID' => $forum_data['forum_id'],
530
'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_data['forum_id']))
533
$template->assign_vars(array(
534
'FORUM_ID' => $forum_data['forum_id'],
535
'FORUM_NAME' => $forum_data['forum_name'],
536
'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']))
543
* Returns forum parents as an array. Get them from forum_data if available, or update the database otherwise
545
function get_forum_parents(&$forum_data)
549
$forum_parents = array();
551
if ($forum_data['parent_id'] > 0)
553
if ($forum_data['forum_parents'] == '')
555
$sql = 'SELECT forum_id, forum_name, forum_type
556
FROM ' . FORUMS_TABLE . '
557
WHERE left_id < ' . $forum_data['left_id'] . '
558
AND right_id > ' . $forum_data['right_id'] . '
559
ORDER BY left_id ASC';
560
$result = $db->sql_query($sql);
562
while ($row = $db->sql_fetchrow($result))
564
$forum_parents[$row['forum_id']] = array($row['forum_name'], (int) $row['forum_type']);
566
$db->sql_freeresult($result);
568
$forum_data['forum_parents'] = serialize($forum_parents);
570
$sql = 'UPDATE ' . FORUMS_TABLE . "
571
SET forum_parents = '" . $db->sql_escape($forum_data['forum_parents']) . "'
572
WHERE parent_id = " . $forum_data['parent_id'];
573
$db->sql_query($sql);
577
$forum_parents = unserialize($forum_data['forum_parents']);
581
return $forum_parents;
585
* Generate topic pagination
587
function topic_generate_pagination($replies, $url)
589
global $config, $user;
591
// Make sure $per_page is a valid value
592
$per_page = ($config['posts_per_page'] <= 0) ? 1 : $config['posts_per_page'];
594
if (($replies + 1) > $per_page)
596
$total_pages = ceil(($replies + 1) / $per_page);
600
for ($j = 0; $j < $replies + 1; $j += $per_page)
602
$pagination .= '<a href="' . $url . '&start=' . $j . '">' . $times . '</a>';
603
if ($times == 1 && $total_pages > 5)
605
$pagination .= ' ... ';
607
// Display the last three pages
608
$times = $total_pages - 3;
609
$j += ($total_pages - 4) * $per_page;
611
else if ($times < $total_pages)
613
$pagination .= '<span class="page-sep">' . $user->lang['COMMA_SEPARATOR'] . '</span>';
627
* Obtain list of moderators of each forum
629
function get_moderators(&$forum_moderators, $forum_id = false)
631
global $config, $template, $db, $phpbb_root_path, $phpEx;
633
// Have we disabled the display of moderators? If so, then return
634
// from whence we came ...
635
if (!$config['load_moderators'])
642
if ($forum_id !== false)
644
if (!is_array($forum_id))
646
$forum_id = array($forum_id);
649
// If we don't have a forum then we can't have a moderator
650
if (!sizeof($forum_id))
655
$forum_sql = 'AND m.' . $db->sql_in_set('forum_id', $forum_id);
659
'SELECT' => 'm.*, u.user_colour, g.group_colour, g.group_type',
662
MODERATOR_CACHE_TABLE => 'm',
665
'LEFT_JOIN' => array(
667
'FROM' => array(USERS_TABLE => 'u'),
668
'ON' => 'm.user_id = u.user_id',
671
'FROM' => array(GROUPS_TABLE => 'g'),
672
'ON' => 'm.group_id = g.group_id',
676
'WHERE' => "m.display_on_index = 1 $forum_sql",
679
$sql = $db->sql_build_query('SELECT', $sql_array);
680
$result = $db->sql_query($sql, 3600);
682
while ($row = $db->sql_fetchrow($result))
684
if (!empty($row['user_id']))
686
$forum_moderators[$row['forum_id']][] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
690
$forum_moderators[$row['forum_id']][] = '<a' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . ' href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $row['group_id']) . '">' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</a>';
693
$db->sql_freeresult($result);
699
* User authorisation levels output
701
* @param string $mode Can be forum or topic. Not in use at the moment.
702
* @param int $forum_id The current forum the user is in.
703
* @param int $forum_status The forums status bit.
705
function gen_forum_auth_level($mode, $forum_id, $forum_status)
707
global $template, $auth, $user, $config;
709
$locked = ($forum_status == ITEM_LOCKED && !$auth->acl_get('m_edit', $forum_id)) ? true : false;
712
($auth->acl_get('f_post', $forum_id) && !$locked) ? $user->lang['RULES_POST_CAN'] : $user->lang['RULES_POST_CANNOT'],
713
($auth->acl_get('f_reply', $forum_id) && !$locked) ? $user->lang['RULES_REPLY_CAN'] : $user->lang['RULES_REPLY_CANNOT'],
714
($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id) && !$locked) ? $user->lang['RULES_EDIT_CAN'] : $user->lang['RULES_EDIT_CANNOT'],
715
($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'],
718
if ($config['allow_attachments'])
720
$rules[] = ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && !$locked) ? $user->lang['RULES_ATTACH_CAN'] : $user->lang['RULES_ATTACH_CANNOT'];
723
foreach ($rules as $rule)
725
$template->assign_block_vars('rules', array('RULE' => $rule));
732
* Generate topic status
734
function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$folder_alt, &$topic_type)
736
global $user, $config;
738
$folder = $folder_new = '';
740
if ($topic_row['topic_status'] == ITEM_MOVED)
742
$topic_type = $user->lang['VIEW_TOPIC_MOVED'];
743
$folder_img = 'topic_moved';
744
$folder_alt = 'TOPIC_MOVED';
748
switch ($topic_row['topic_type'])
751
$topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
752
$folder = 'global_read';
753
$folder_new = 'global_unread';
757
$topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT'];
758
$folder = 'announce_read';
759
$folder_new = 'announce_unread';
763
$topic_type = $user->lang['VIEW_TOPIC_STICKY'];
764
$folder = 'sticky_read';
765
$folder_new = 'sticky_unread';
770
$folder = 'topic_read';
771
$folder_new = 'topic_unread';
773
if ($config['hot_threshold'] && $replies >= $config['hot_threshold'] && $topic_row['topic_status'] != ITEM_LOCKED)
776
$folder_new .= '_hot';
781
if ($topic_row['topic_status'] == ITEM_LOCKED)
783
$topic_type = $user->lang['VIEW_TOPIC_LOCKED'];
784
$folder .= '_locked';
785
$folder_new .= '_locked';
789
$folder_img = ($unread_topic) ? $folder_new : $folder;
790
$folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($topic_row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS');
793
if (!empty($topic_row['topic_posted']) && $topic_row['topic_posted'])
795
$folder_img .= '_mine';
799
if ($topic_row['poll_start'] && $topic_row['topic_status'] != ITEM_MOVED)
801
$topic_type = $user->lang['VIEW_TOPIC_POLL'];
806
* Assign/Build custom bbcodes for display in screens supporting using of bbcodes
807
* The custom bbcodes buttons will be placed within the template block 'custom_codes'
809
function display_custom_bbcodes()
811
global $db, $template;
813
// Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)
814
$num_predefined_bbcodes = 22;
816
$sql = 'SELECT bbcode_id, bbcode_tag, bbcode_helpline
817
FROM ' . BBCODES_TABLE . '
818
WHERE display_on_posting = 1
819
ORDER BY bbcode_tag';
820
$result = $db->sql_query($sql);
823
while ($row = $db->sql_fetchrow($result))
825
$template->assign_block_vars('custom_tags', array(
826
'BBCODE_NAME' => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'",
827
'BBCODE_ID' => $num_predefined_bbcodes + ($i * 2),
828
'BBCODE_TAG' => $row['bbcode_tag'],
829
'BBCODE_HELPLINE' => $row['bbcode_helpline'],
830
'A_BBCODE_HELPLINE' => str_replace(array('&', '"', "'", '<', '>'), array('&', '"', "\'", '<', '>'), $row['bbcode_helpline']),
835
$db->sql_freeresult($result);
841
function display_reasons($reason_id = 0)
843
global $db, $user, $template;
846
FROM ' . REPORTS_REASONS_TABLE . '
847
ORDER BY reason_order ASC';
848
$result = $db->sql_query($sql);
850
while ($row = $db->sql_fetchrow($result))
852
// If the reason is defined within the language file, we will use the localized version, else just use the database entry...
853
if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
855
$row['reason_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
856
$row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
859
$template->assign_block_vars('reason', array(
860
'ID' => $row['reason_id'],
861
'TITLE' => $row['reason_title'],
862
'DESCRIPTION' => $row['reason_description'],
863
'S_SELECTED' => ($row['reason_id'] == $reason_id) ? true : false)
866
$db->sql_freeresult($result);
870
* Display user activity (action forum/topic)
872
function display_user_activity(&$userdata)
874
global $auth, $template, $db, $user;
875
global $phpbb_root_path, $phpEx;
877
// Do not display user activity for users having more than 5000 posts...
878
if ($userdata['user_posts'] > 5000)
883
$forum_ary = array();
885
// Do not include those forums the user is not having read access to...
886
$forum_read_ary = $auth->acl_getf('!f_read');
888
foreach ($forum_read_ary as $forum_id => $not_allowed)
890
if ($not_allowed['f_read'])
892
$forum_ary[] = (int) $forum_id;
896
$forum_ary = array_unique($forum_ary);
897
$forum_sql = (sizeof($forum_ary)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary, true) : '';
899
// Obtain active forum
900
$sql = 'SELECT forum_id, COUNT(post_id) AS num_posts
901
FROM ' . POSTS_TABLE . '
902
WHERE poster_id = ' . $userdata['user_id'] . "
903
AND post_postcount = 1
906
ORDER BY num_posts DESC";
907
$result = $db->sql_query_limit($sql, 1);
908
$active_f_row = $db->sql_fetchrow($result);
909
$db->sql_freeresult($result);
911
if (!empty($active_f_row))
913
$sql = 'SELECT forum_name
914
FROM ' . FORUMS_TABLE . '
915
WHERE forum_id = ' . $active_f_row['forum_id'];
916
$result = $db->sql_query($sql, 3600);
917
$active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name');
918
$db->sql_freeresult($result);
921
// Obtain active topic
922
$sql = 'SELECT topic_id, COUNT(post_id) AS num_posts
923
FROM ' . POSTS_TABLE . '
924
WHERE poster_id = ' . $userdata['user_id'] . "
925
AND post_postcount = 1
928
ORDER BY num_posts DESC";
929
$result = $db->sql_query_limit($sql, 1);
930
$active_t_row = $db->sql_fetchrow($result);
931
$db->sql_freeresult($result);
933
if (!empty($active_t_row))
935
$sql = 'SELECT topic_title
936
FROM ' . TOPICS_TABLE . '
937
WHERE topic_id = ' . $active_t_row['topic_id'];
938
$result = $db->sql_query($sql);
939
$active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title');
940
$db->sql_freeresult($result);
943
$userdata['active_t_row'] = $active_t_row;
944
$userdata['active_f_row'] = $active_f_row;
946
$active_f_name = $active_f_id = $active_f_count = $active_f_pct = '';
947
if (!empty($active_f_row['num_posts']))
949
$active_f_name = $active_f_row['forum_name'];
950
$active_f_id = $active_f_row['forum_id'];
951
$active_f_count = $active_f_row['num_posts'];
952
$active_f_pct = ($userdata['user_posts']) ? ($active_f_count / $userdata['user_posts']) * 100 : 0;
955
$active_t_name = $active_t_id = $active_t_count = $active_t_pct = '';
956
if (!empty($active_t_row['num_posts']))
958
$active_t_name = $active_t_row['topic_title'];
959
$active_t_id = $active_t_row['topic_id'];
960
$active_t_count = $active_t_row['num_posts'];
961
$active_t_pct = ($userdata['user_posts']) ? ($active_t_count / $userdata['user_posts']) * 100 : 0;
964
$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'];
966
$template->assign_vars(array(
967
'ACTIVE_FORUM' => $active_f_name,
968
'ACTIVE_FORUM_POSTS' => ($active_f_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_f_count),
969
'ACTIVE_FORUM_PCT' => sprintf($l_active_pct, $active_f_pct),
970
'ACTIVE_TOPIC' => censor_text($active_t_name),
971
'ACTIVE_TOPIC_POSTS' => ($active_t_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_t_count),
972
'ACTIVE_TOPIC_PCT' => sprintf($l_active_pct, $active_t_pct),
973
'U_ACTIVE_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $active_f_id),
974
'U_ACTIVE_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $active_t_id),
975
'S_SHOW_ACTIVITY' => true)
980
* Topic and forum watching common code
982
function watch_topic_forum($mode, &$s_watching, &$s_watching_img, $user_id, $forum_id, $topic_id, $notify_status = 'unset', $start = 0)
984
global $template, $db, $user, $phpEx, $start, $phpbb_root_path;
986
$table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE : TOPICS_WATCH_TABLE;
987
$where_sql = ($mode == 'forum') ? 'forum_id' : 'topic_id';
988
$match_id = ($mode == 'forum') ? $forum_id : $topic_id;
990
$u_url = ($mode == 'forum') ? 'f' : 'f=' . $forum_id . '&t';
992
// Is user watching this thread?
993
if ($user_id != ANONYMOUS)
997
if ($notify_status == 'unset')
999
$sql = "SELECT notify_status
1001
WHERE $where_sql = $match_id
1002
AND user_id = $user_id";
1003
$result = $db->sql_query($sql);
1005
$notify_status = ($row = $db->sql_fetchrow($result)) ? $row['notify_status'] : NULL;
1006
$db->sql_freeresult($result);
1009
if (!is_null($notify_status) && $notify_status !== '')
1011
if (isset($_GET['unwatch']))
1013
if ($_GET['unwatch'] == $mode)
1017
$sql = 'DELETE FROM ' . $table_sql . "
1018
WHERE $where_sql = $match_id
1019
AND user_id = $user_id";
1020
$db->sql_query($sql);
1023
$redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start");
1025
meta_refresh(3, $redirect_url);
1027
$message = $user->lang['NOT_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1028
trigger_error($message);
1032
$is_watching = true;
1036
$sql = 'UPDATE ' . $table_sql . "
1037
SET notify_status = 0
1038
WHERE $where_sql = $match_id
1039
AND user_id = $user_id";
1040
$db->sql_query($sql);
1046
if (isset($_GET['watch']))
1048
if ($_GET['watch'] == $mode)
1050
$is_watching = true;
1052
$sql = 'INSERT INTO ' . $table_sql . " (user_id, $where_sql, notify_status)
1053
VALUES ($user_id, $match_id, 0)";
1054
$db->sql_query($sql);
1057
$redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start");
1058
meta_refresh(3, $redirect_url);
1060
$message = $user->lang['ARE_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1061
trigger_error($message);
1071
if (isset($_GET['unwatch']) && $_GET['unwatch'] == $mode)
1084
$s_watching['link'] = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&" . (($is_watching) ? 'unwatch' : 'watch') . "=$mode&start=$start");
1085
$s_watching['title'] = $user->lang[(($is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)];
1086
$s_watching['is_watching'] = $is_watching;
1093
* Get user rank title and image
1095
* @param int $user_rank the current stored users rank id
1096
* @param int $user_posts the users number of posts
1097
* @param string &$rank_title the rank title will be stored here after execution
1098
* @param string &$rank_img the rank image as full img tag is stored here after execution
1099
* @param string &$rank_img_src the rank image source is stored here after execution
1102
function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank_img_src)
1104
global $ranks, $config;
1109
$ranks = $cache->obtain_ranks();
1112
if (!empty($user_rank))
1114
$rank_title = (isset($ranks['special'][$user_rank]['rank_title'])) ? $ranks['special'][$user_rank]['rank_title'] : '';
1115
$rank_img = (!empty($ranks['special'][$user_rank]['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] . '" alt="' . $ranks['special'][$user_rank]['rank_title'] . '" title="' . $ranks['special'][$user_rank]['rank_title'] . '" />' : '';
1116
$rank_img_src = (!empty($ranks['special'][$user_rank]['rank_image'])) ? $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] : '';
1120
if (!empty($ranks['normal']))
1122
foreach ($ranks['normal'] as $rank)
1124
if ($user_posts >= $rank['rank_min'])
1126
$rank_title = $rank['rank_title'];
1127
$rank_img = (!empty($rank['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $rank['rank_image'] . '" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" />' : '';
1128
$rank_img_src = (!empty($rank['rank_image'])) ? $config['ranks_path'] . '/' . $rank['rank_image'] : '';
1139
* @param string $avatar Users assigned avatar name
1140
* @param int $avatar_type Type of avatar
1141
* @param string $avatar_width Width of users avatar
1142
* @param string $avatar_height Height of users avatar
1143
* @param string $alt Optional language string for alt tag within image, can be a language key or text
1145
* @return string Avatar image
1147
function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR')
1149
global $user, $config, $phpbb_root_path, $phpEx;
1151
if (empty($avatar) || !$avatar_type)
1158
switch ($avatar_type)
1161
$avatar_img = $phpbb_root_path . "download/file.$phpEx?avatar=";
1164
case AVATAR_GALLERY:
1165
$avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
1169
$avatar_img .= $avatar;
1170
return '<img src="' . $avatar_img . '" width="' . $avatar_width . '" height="' . $avatar_height . '" alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
b'\\ No newline at end of file'