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 $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
25 $parent_id = $visible_forums = 0;
29 $mark_read = request_var('mark', '');
31 if ($mark_read == 'all')
38 if ($mark_read == 'forums')
43 $root_data = array('forum_id' => 0);
48 $sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
51 // Display list of active topics for this category?
52 $show_active = (isset($root_data['forum_flags']) && ($root_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS
)) ?
true : false;
59 'LEFT_JOIN' => array(),
62 if (phpbb
::$config['load_db_lastread'] && phpbb
::$user->is_registered
)
64 $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE
=> 'ft'), 'ON' => 'ft.user_id = ' . phpbb
::$user->data
['user_id'] . ' AND ft.forum_id = f.forum_id');
65 $sql_array['SELECT'] .= ', ft.mark_time';
67 else if (phpbb
::$config['load_anon_lastread'] || phpbb
::$user->is_registered
)
69 $tracking_topics = request
::variable(phpbb
::$config['cookie_name'] . '_track', '', false, request
::COOKIE
);
70 $tracking_topics = ($tracking_topics) ?
tracking_unserialize($tracking_topics) : array();
72 if (!phpbb
::$user->is_registered
)
74 phpbb
::$user->data
['user_lastmark'] = (isset($tracking_topics['l'])) ?
(int) (base_convert($tracking_topics['l'], 36, 10) + phpbb
::$config['board_startdate']) : 0;
80 $sql_array['LEFT_JOIN'][] = array(
81 'FROM' => array(FORUMS_ACCESS_TABLE
=> 'fa'),
82 'ON' => "fa.forum_id = f.forum_id AND fa.session_id = '" . phpbb
::$db->sql_escape(phpbb
::$user->session_id
) . "'"
85 $sql_array['SELECT'] .= ', fa.user_id';
88 $sql = phpbb
::$db->sql_build_query('SELECT', array(
89 'SELECT' => $sql_array['SELECT'],
90 'FROM' => $sql_array['FROM'],
91 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
93 'WHERE' => $sql_where,
95 'ORDER_BY' => 'f.left_id',
98 $result = phpbb
::$db->sql_query($sql);
100 $forum_tracking_info = array();
101 $branch_root_id = $root_data['forum_id'];
102 while ($row = phpbb
::$db->sql_fetchrow($result))
104 $forum_id = $row['forum_id'];
107 if ($mark_read == 'forums' ||
$mark_read == 'all')
109 if (phpbb
::$acl->acl_get('f_list', $forum_id))
111 $forum_ids[] = $forum_id;
116 // Category with no members
117 if ($row['forum_type'] == FORUM_CAT
&& ($row['left_id'] +
1 == $row['right_id']))
123 if (isset($right_id))
125 if ($row['left_id'] < $right_id)
132 if (!phpbb
::$acl->acl_get('f_list', $forum_id))
134 // if the user does not have permissions to list this forum, skip everything until next branch
135 $right_id = $row['right_id'];
139 $forum_ids[] = $forum_id;
141 if (phpbb
::$config['load_db_lastread'] && phpbb
::$user->is_registered
)
143 $forum_tracking_info[$forum_id] = (!empty($row['mark_time'])) ?
$row['mark_time'] : phpbb
::$user->data
['user_lastmark'];
145 else if (phpbb
::$config['load_anon_lastread'] || phpbb
::$user->is_registered
)
147 if (!phpbb
::$user->is_registered
)
149 phpbb
::$user->data
['user_lastmark'] = (isset($tracking_topics['l'])) ?
(int) (base_convert($tracking_topics['l'], 36, 10) + phpbb
::$config['board_startdate']) : 0;
151 $forum_tracking_info[$forum_id] = (isset($tracking_topics['f'][$forum_id])) ?
(int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + phpbb
::$config['board_startdate']) : phpbb
::$user->data
['user_lastmark'];
154 $row['forum_topics'] = (phpbb
::$acl->acl_get('m_approve', $forum_id)) ?
$row['forum_topics_real'] : $row['forum_topics'];
156 // Display active topics from this forum?
157 if ($show_active && $row['forum_type'] == FORUM_POST
&& phpbb
::$acl->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS
))
159 if (!isset($active_forum_ary['forum_topics']))
161 $active_forum_ary['forum_topics'] = 0;
164 if (!isset($active_forum_ary['forum_posts']))
166 $active_forum_ary['forum_posts'] = 0;
169 $active_forum_ary['forum_id'][] = $forum_id;
170 $active_forum_ary['enable_icons'][] = $row['enable_icons'];
171 $active_forum_ary['forum_topics'] +
= $row['forum_topics'];
172 $active_forum_ary['forum_posts'] +
= $row['forum_posts'];
174 // If this is a passworded forum we do not show active topics from it if the user is not authorised to view it...
175 if ($row['forum_password'] && $row['user_id'] != phpbb
::$user->data
['user_id'])
177 $active_forum_ary['exclude_forum_id'][] = $forum_id;
182 if ($row['parent_id'] == $root_data['forum_id'] ||
$row['parent_id'] == $branch_root_id)
184 if ($row['forum_type'] != FORUM_CAT
)
186 $forum_ids_moderator[] = (int) $forum_id;
189 // Direct child of current branch
190 $parent_id = $forum_id;
191 $forum_rows[$forum_id] = $row;
193 if ($row['forum_type'] == FORUM_CAT
&& $row['parent_id'] == $root_data['forum_id'])
195 $branch_root_id = $forum_id;
197 $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
198 $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
200 else if ($row['forum_type'] != FORUM_CAT
)
202 $subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index']) ?
true : false;
203 $subforums[$parent_id][$forum_id]['name'] = $row['forum_name'];
204 $subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
205 $subforums[$parent_id][$forum_id]['children'] = array();
207 if (isset($subforums[$parent_id][$row['parent_id']]) && !$row['display_on_index'])
209 $subforums[$parent_id][$row['parent_id']]['children'][] = $forum_id;
212 $forum_rows[$parent_id]['forum_topics'] +
= $row['forum_topics'];
214 // Do not list redirects in LINK Forums as Posts.
215 if ($row['forum_type'] != FORUM_LINK
)
217 $forum_rows[$parent_id]['forum_posts'] +
= $row['forum_posts'];
220 if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time'])
222 $forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
223 $forum_rows[$parent_id]['forum_last_post_subject'] = $row['forum_last_post_subject'];
224 $forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
225 $forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
226 $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
227 $forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour'];
228 $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
232 phpbb
::$db->sql_freeresult($result);
234 // Handle marking posts
235 if ($mark_read == 'forums' ||
$mark_read == 'all')
237 $redirect = phpbb
::$url->build_url(array('mark', 'hash'));
238 $token = request_var('hash', '');
240 if (phpbb
::$security->check_link($token, 'global'))
242 if ($mark_read == 'all')
245 $message = phpbb
::$user->lang('RETURN_INDEX', '<a href="' . $redirect . '">', '</a>');
249 markread('topics', $forum_ids);
250 $message = phpbb
::$user->lang('RETURN_FORUM', '<a href="' . $redirect . '">', '</a>');
252 meta_refresh(3, $redirect);
253 trigger_error(phpbb
::$user->lang
['FORUMS_MARKED'] . '<br /><br />' . $message);
257 $message = phpbb
::$user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>');
258 phpbb
::$url->meta_refresh(3, $redirect);
259 trigger_error($message);
263 // Grab moderators ... if necessary
264 if ($display_moderators)
266 if ($return_moderators)
268 $forum_ids_moderator[] = $root_data['forum_id'];
270 get_moderators($forum_moderators, $forum_ids_moderator);
273 // Used to tell whatever we have to create a dummy category or not.
274 $last_catless = true;
275 foreach ($forum_rows as $row)
278 if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT
)
280 phpbb
::$template->assign_block_vars('forumrow', array(
282 'FORUM_ID' => $row['forum_id'],
283 'FORUM_NAME' => $row['forum_name'],
284 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
285 'FORUM_FOLDER_IMG' => '',
286 'FORUM_FOLDER_IMG_SRC' => '',
287 'FORUM_IMAGE' => ($row['forum_image']) ?
'<img src="' . PHPBB_ROOT_PATH
. $row['forum_image'] . '" alt="' . phpbb
::$user->lang
['FORUM_CAT'] . '" />' : '',
288 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? PHPBB_ROOT_PATH
. $row['forum_image'] : '',
289 'U_VIEWFORUM' => phpbb
::$url->append_sid('viewforum', 'f=' . $row['forum_id']),
296 $forum_id = $row['forum_id'];
298 $forum_unread = (isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id]) ?
true : false;
300 $folder_image = $folder_alt = $l_subforums = '';
301 $subforums_list = array();
303 // Generate list of subforums if we need to
304 if (isset($subforums[$forum_id]))
306 foreach ($subforums[$forum_id] as $subforum_id => $subforum_row)
308 $subforum_unread = (isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id]) ?
true : false;
310 if (!$subforum_unread && !empty($subforum_row['children']))
312 foreach ($subforum_row['children'] as $child_id)
314 if (isset($forum_tracking_info[$child_id]) && $subforums[$forum_id][$child_id]['orig_forum_last_post_time'] > $forum_tracking_info[$child_id])
316 // Once we found an unread child forum, we can drop out of this loop
317 $subforum_unread = true;
323 if ($subforum_row['display'] && $subforum_row['name'])
325 $subforums_list[] = array(
326 'link' => phpbb
::$url->append_sid('viewforum', 'f=' . $subforum_id),
327 'name' => $subforum_row['name'],
328 'unread' => $subforum_unread,
333 unset($subforums[$forum_id][$subforum_id]);
336 // If one subforum is unread the forum gets unread too...
337 if ($subforum_unread)
339 $forum_unread = true;
343 $folder_image = ($forum_unread) ?
'forum_unread_subforum' : 'forum_read_subforum';
347 switch ($row['forum_type'])
350 $folder_image = ($forum_unread) ?
'forum_unread' : 'forum_read';
354 $folder_image = 'forum_link';
359 // Which folder should we display?
360 if ($row['forum_status'] == ITEM_LOCKED
)
362 $folder_image = ($forum_unread) ?
'forum_unread_locked' : 'forum_read_locked';
363 $folder_alt = 'FORUM_LOCKED';
367 $folder_alt = ($forum_unread) ?
'NEW_POSTS' : 'NO_NEW_POSTS';
370 // Create last post link information, if appropriate
371 if ($row['forum_last_post_id'])
373 $last_post_subject = $row['forum_last_post_subject'];
374 $last_post_time = phpbb
::$user->format_date($row['forum_last_post_time']);
375 $last_post_url = phpbb
::$url->append_sid('viewtopic', 'f=' . $row['forum_id_last_post'] . '&p=' . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
379 $last_post_subject = $last_post_time = $last_post_url = '';
382 // Output moderator listing ... if applicable
383 $moderators_list = array();
384 if ($display_moderators && !empty($forum_moderators[$forum_id]))
386 $moderators_list = $forum_moderators[$forum_id];
389 $l_post_click_count = ($row['forum_type'] == FORUM_LINK
) ?
'CLICKS' : 'POSTS';
390 $post_click_count = ($row['forum_type'] != FORUM_LINK ||
$row['forum_flags'] & FORUM_FLAG_LINK_TRACK
) ?
$row['forum_posts'] : '';
392 $s_subforums_list = array();
393 foreach ($subforums_list as $subforum)
395 $s_subforums_list[] = '<a href="' . $subforum['link'] . '" class="subforum ' . (($subforum['unread']) ?
'unread' : 'read') . '" title="' . (($subforum['unread']) ? phpbb
::$user->lang
['NEW_POSTS'] : phpbb
::$user->lang
['NO_NEW_POSTS']) . '">' . $subforum['name'] . '</a>';
397 $s_subforums_list = (string) implode(', ', $s_subforums_list);
398 $catless = ($row['parent_id'] == $root_data['forum_id']) ?
true : false;
400 if ($row['forum_type'] != FORUM_LINK
)
402 $u_viewforum = phpbb
::$url->append_sid('viewforum', 'f=' . $row['forum_id']);
406 // If the forum is a link and we count redirects we need to visit it
407 // If the forum is having a password or no read access we do not expose the link, but instead handle it in viewforum
408 if (($row['forum_flags'] & FORUM_FLAG_LINK_TRACK
) ||
$row['forum_password'] ||
!phpbb
::$acl->acl_get('f_read', $forum_id))
410 $u_viewforum = phpbb
::$url->append_sid('viewforum', 'f=' . $row['forum_id']);
414 $u_viewforum = $row['forum_link'];
418 phpbb
::$template->assign_block_vars('forumrow', array(
420 'S_NO_CAT' => $catless && !$last_catless,
421 'S_IS_LINK' => ($row['forum_type'] == FORUM_LINK
) ?
true : false,
422 'S_UNREAD_FORUM' => $forum_unread,
423 'S_LOCKED_FORUM' => ($row['forum_status'] == ITEM_LOCKED
) ?
true : false,
424 'S_LIST_SUBFORUMS' => ($row['display_subforum_list']) ?
true : false,
425 'S_SUBFORUMS' => (sizeof($subforums_list)) ?
true : false,
427 'FORUM_ID' => $row['forum_id'],
428 'FORUM_NAME' => $row['forum_name'],
429 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
430 'TOPICS' => $row['forum_topics'],
431 $l_post_click_count => $post_click_count,
432 'FORUM_FOLDER_IMG' => phpbb
::$user->img($folder_image, $folder_alt),
433 'FORUM_FOLDER_IMG_SRC' => phpbb
::$user->img($folder_image, $folder_alt, 'src'),
434 'FORUM_FOLDER_IMG_ALT' => isset(phpbb
::$user->lang
[$folder_alt]) ? phpbb
::$user->lang
[$folder_alt] : '',
435 'FORUM_IMAGE' => ($row['forum_image']) ?
'<img src="' . PHPBB_ROOT_PATH
. $row['forum_image'] . '" alt="' . phpbb
::$user->lang
[$folder_alt] . '" />' : '',
436 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? PHPBB_ROOT_PATH
. $row['forum_image'] : '',
437 'LAST_POST_SUBJECT' => censor_text($last_post_subject),
438 'LAST_POST_TIME' => $last_post_time,
439 'LAST_POSTER' => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
440 'LAST_POSTER_COLOUR' => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
441 'LAST_POSTER_FULL' => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
442 'MODERATORS' => implode(', ', $moderators_list),
443 'SUBFORUMS' => $s_subforums_list,
445 'L_SUBFORUM_STR' => phpbb
::$user->lang('SUBFORUMS', sizeof($subforums_list)),
446 'L_FORUM_FOLDER_ALT' => $folder_alt,
447 'L_MODERATOR_STR' => phpbb
::$user->lang('MODERATORS', sizeof($moderators_list)),
449 'U_VIEWFORUM' => $u_viewforum,
450 'U_LAST_POSTER' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
451 'U_LAST_POST' => $last_post_url,
454 // Assign subforums loop for style authors
455 foreach ($subforums_list as $subforum)
457 phpbb
::$template->assign_block_vars('forumrow.subforum', array(
458 'U_SUBFORUM' => $subforum['link'],
459 'SUBFORUM_NAME' => $subforum['name'],
460 'S_UNREAD' => $subforum['unread'],
464 $last_catless = $catless;
467 phpbb
::$template->assign_vars(array(
468 'U_MARK_FORUMS' => (phpbb
::$user->is_registered || phpbb
::$config['load_anon_lastread']) ? phpbb
::$url->append_sid('viewforum', 'hash=' . generate_link_hash('global') . '&f=' . $root_data['forum_id'] . '&mark=forums') : '',
469 'S_HAS_SUBFORUM' => ($visible_forums) ?
true : false,
470 'L_SUBFORUM' => phpbb
::$user->lang('SUBFORUMS', $visible_forums),
471 'LAST_POST_IMG' => phpbb
::$user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
474 if ($return_moderators)
476 return array($active_forum_ary, $forum_moderators);
479 return array($active_forum_ary, array());
483 * Create forum rules for given forum
485 function generate_forum_rules(&$forum_data)
487 if (!$forum_data['forum_rules'] && !$forum_data['forum_rules_link'])
492 if ($forum_data['forum_rules'])
494 $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']);
497 phpbb
::$template->assign_vars(array(
498 'S_FORUM_RULES' => true,
499 'U_FORUM_RULES' => $forum_data['forum_rules_link'],
500 'FORUM_RULES' => $forum_data['forum_rules'],
505 * Create forum navigation links for given forum, create parent
506 * list if currently null, assign basic forum info to template
508 function generate_forum_nav(&$forum_data)
510 if (!phpbb
::$acl->acl_get('f_list', $forum_data['forum_id']))
516 $forum_parents = get_forum_parents($forum_data);
518 // Build navigation links
519 if (!empty($forum_parents))
521 foreach ($forum_parents as $parent_forum_id => $parent_data)
523 list($parent_name, $parent_type) = array_values($parent_data);
525 // Skip this parent if the user does not have the permission to view it
526 if (!phpbb
::$acl->acl_get('f_list', $parent_forum_id))
531 phpbb
::$template->assign_block_vars('navlinks', array(
532 'S_IS_CAT' => ($parent_type == FORUM_CAT
) ?
true : false,
533 'S_IS_LINK' => ($parent_type == FORUM_LINK
) ?
true : false,
534 'S_IS_POST' => ($parent_type == FORUM_POST
) ?
true : false,
535 'FORUM_NAME' => $parent_name,
536 'FORUM_ID' => $parent_forum_id,
537 'U_VIEW_FORUM' => phpbb
::$url->append_sid('viewforum', 'f=' . $parent_forum_id),
542 phpbb
::$template->assign_block_vars('navlinks', array(
543 'S_IS_CAT' => ($forum_data['forum_type'] == FORUM_CAT
) ?
true : false,
544 'S_IS_LINK' => ($forum_data['forum_type'] == FORUM_LINK
) ?
true : false,
545 'S_IS_POST' => ($forum_data['forum_type'] == FORUM_POST
) ?
true : false,
546 'FORUM_NAME' => $forum_data['forum_name'],
547 'FORUM_ID' => $forum_data['forum_id'],
548 'U_VIEW_FORUM' => phpbb
::$url->append_sid('viewforum', 'f=' . $forum_data['forum_id']),
551 phpbb
::$template->assign_vars(array(
552 'FORUM_ID' => $forum_data['forum_id'],
553 'FORUM_NAME' => $forum_data['forum_name'],
554 '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']),
561 * Returns forum parents as an array. Get them from forum_data if available, or update the database otherwise
563 function get_forum_parents(&$forum_data)
565 $forum_parents = array();
567 if ($forum_data['parent_id'] > 0)
569 if ($forum_data['forum_parents'] == '')
571 $sql = 'SELECT forum_id, forum_name, forum_type
572 FROM ' . FORUMS_TABLE
. '
573 WHERE left_id < ' . $forum_data['left_id'] . '
574 AND right_id > ' . $forum_data['right_id'] . '
575 ORDER BY left_id ASC';
576 $result = phpbb
::$db->sql_query($sql);
578 while ($row = phpbb
::$db->sql_fetchrow($result))
580 $forum_parents[$row['forum_id']] = array($row['forum_name'], (int) $row['forum_type']);
582 phpbb
::$db->sql_freeresult($result);
584 $forum_data['forum_parents'] = serialize($forum_parents);
586 $sql = 'UPDATE ' . FORUMS_TABLE
. "
587 SET forum_parents = '" . phpbb
::$db->sql_escape($forum_data['forum_parents']) . "'
588 WHERE parent_id = " . $forum_data['parent_id'];
589 phpbb
::$db->sql_query($sql);
593 $forum_parents = unserialize($forum_data['forum_parents']);
597 return $forum_parents;
601 * Generate topic pagination
603 function topic_generate_pagination($replies, $url)
605 // Make sure $per_page is a valid value
606 $per_page = (phpbb
::$config['posts_per_page'] <= 0) ?
1 : phpbb
::$config['posts_per_page'];
608 if (($replies +
1) > $per_page)
610 $total_pages = ceil(($replies +
1) / $per_page);
614 for ($j = 0; $j < $replies +
1; $j +
= $per_page)
616 $pagination .= '<a href="' . $url . '&start=' . $j . '">' . $times . '</a>';
617 if ($times == 1 && $total_pages > 5)
619 $pagination .= ' ... ';
621 // Display the last three pages
622 $times = $total_pages - 3;
623 $j +
= ($total_pages - 4) * $per_page;
625 else if ($times < $total_pages)
627 $pagination .= '<span class="page-sep">' . phpbb
::$user->lang
['COMMA_SEPARATOR'] . '</span>';
641 * Obtain list of moderators of each forum
643 function get_moderators(&$forum_moderators, $forum_id = false)
645 // Have we disabled the display of moderators? If so, then return
646 // from whence we came ...
647 if (!phpbb
::$config['load_moderators'])
654 if ($forum_id !== false)
656 if (!is_array($forum_id))
658 $forum_id = array($forum_id);
661 // If we don't have a forum then we can't have a moderator
662 if (!sizeof($forum_id))
667 $forum_sql = 'AND m.' . phpbb
::$db->sql_in_set('forum_id', $forum_id);
671 'SELECT' => 'm.*, u.user_colour, g.group_colour, g.group_type',
674 MODERATOR_CACHE_TABLE
=> 'm',
677 'LEFT_JOIN' => array(
679 'FROM' => array(USERS_TABLE
=> 'u'),
680 'ON' => 'm.user_id = u.user_id',
683 'FROM' => array(GROUPS_TABLE
=> 'g'),
684 'ON' => 'm.group_id = g.group_id',
688 'WHERE' => "m.display_on_index = 1 $forum_sql",
691 $sql = phpbb
::$db->sql_build_query('SELECT', $sql_array);
692 $result = phpbb
::$db->sql_query($sql, 3600);
694 while ($row = phpbb
::$db->sql_fetchrow($result))
696 if (!empty($row['user_id']))
698 $forum_moderators[$row['forum_id']][] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
702 $group_name = (($row['group_type'] == GROUP_SPECIAL
) ? phpbb
::$user->lang
['G_' . $row['group_name']] : $row['group_name']);
704 if (!phpbb
::$user->is_guest
&& !phpbb
::$acl->acl_get('u_viewprofile'))
706 $forum_moderators[$row['forum_id']][] = '<span' . (($row['group_colour']) ?
' style="color:#' . $row['group_colour'] . ';"' : '') . '>' . $group_name . '</span>';
710 $forum_moderators[$row['forum_id']][] = '<a' . (($row['group_colour']) ?
' style="color:#' . $row['group_colour'] . ';"' : '') . ' href="' . phpbb
::$url->append_sid('memberlist', 'mode=group&g=' . $row['group_id']) . '">' . $group_name . '</a>';
714 phpbb
::$db->sql_freeresult($result);
720 * User authorisation levels output
722 * @param string $mode Can be forum or topic. Not in use at the moment.
723 * @param int $forum_id The current forum the user is in.
724 * @param int $forum_status The forums status bit.
726 function gen_forum_auth_level($mode, $forum_id, $forum_status)
728 $locked = ($forum_status == ITEM_LOCKED
&& !phpbb
::$acl->acl_get('m_edit', $forum_id)) ?
true : false;
731 (phpbb
::$acl->acl_get('f_post', $forum_id) && !$locked) ? phpbb
::$user->lang
['RULES_POST_CAN'] : phpbb
::$user->lang
['RULES_POST_CANNOT'],
732 (phpbb
::$acl->acl_get('f_reply', $forum_id) && !$locked) ? phpbb
::$user->lang
['RULES_REPLY_CAN'] : phpbb
::$user->lang
['RULES_REPLY_CANNOT'],
733 (phpbb
::$user->is_registered
&& phpbb
::$acl->acl_gets('f_edit', 'm_edit', $forum_id) && !$locked) ? phpbb
::$user->lang
['RULES_EDIT_CAN'] : phpbb
::$user->lang
['RULES_EDIT_CANNOT'],
734 (phpbb
::$user->is_registered
&& phpbb
::$acl->acl_gets('f_delete', 'm_delete', $forum_id) && !$locked) ? phpbb
::$user->lang
['RULES_DELETE_CAN'] : phpbb
::$user->lang
['RULES_DELETE_CANNOT'],
737 if (phpbb
::$config['allow_attachments'])
739 $rules[] = (phpbb
::$acl->acl_get('f_attach', $forum_id) && phpbb
::$acl->acl_get('u_attach') && !$locked) ? phpbb
::$user->lang
['RULES_ATTACH_CAN'] : phpbb
::$user->lang
['RULES_ATTACH_CANNOT'];
742 foreach ($rules as $rule)
744 phpbb
::$template->assign_block_vars('rules', array('RULE' => $rule));
751 * Generate topic status
753 function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$folder_alt, &$topic_type)
755 $folder = $folder_new = '';
757 if ($topic_row['topic_status'] == ITEM_MOVED
)
759 $topic_type = phpbb
::$user->lang
['VIEW_TOPIC_MOVED'];
760 $folder_img = 'topic_moved';
761 $folder_alt = 'TOPIC_MOVED';
765 switch ($topic_row['topic_type'])
768 $topic_type = phpbb
::$user->lang
['VIEW_TOPIC_GLOBAL'];
769 $folder = 'global_read';
770 $folder_new = 'global_unread';
774 $topic_type = phpbb
::$user->lang
['VIEW_TOPIC_ANNOUNCEMENT'];
775 $folder = 'announce_read';
776 $folder_new = 'announce_unread';
780 $topic_type = phpbb
::$user->lang
['VIEW_TOPIC_STICKY'];
781 $folder = 'sticky_read';
782 $folder_new = 'sticky_unread';
787 $folder = 'topic_read';
788 $folder_new = 'topic_unread';
790 // Hot topic threshold is for posts in a topic, which is replies + the first post. ;)
791 if (phpbb
::$config['hot_threshold'] && ($replies +
1) >= phpbb
::$config['hot_threshold'] && $topic_row['topic_status'] != ITEM_LOCKED
)
794 $folder_new .= '_hot';
799 if ($topic_row['topic_status'] == ITEM_LOCKED
)
801 $topic_type = phpbb
::$user->lang
['VIEW_TOPIC_LOCKED'];
802 $folder .= '_locked';
803 $folder_new .= '_locked';
807 $folder_img = ($unread_topic) ?
$folder_new : $folder;
808 $folder_alt = ($unread_topic) ?
'NEW_POSTS' : (($topic_row['topic_status'] == ITEM_LOCKED
) ?
'TOPIC_LOCKED' : 'NO_NEW_POSTS');
811 if (!empty($topic_row['topic_posted']) && $topic_row['topic_posted'])
813 $folder_img .= '_mine';
817 if ($topic_row['poll_start'] && $topic_row['topic_status'] != ITEM_MOVED
)
819 $topic_type = phpbb
::$user->lang
['VIEW_TOPIC_POLL'];
824 * Assign/Build custom bbcodes for display in screens supporting using of bbcodes
825 * The custom bbcodes buttons will be placed within the template block 'custom_codes'
827 function display_custom_bbcodes()
829 // Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)
830 $num_predefined_bbcodes = 22;
832 $sql = 'SELECT bbcode_id, bbcode_tag, bbcode_helpline
833 FROM ' . BBCODES_TABLE
. '
834 WHERE display_on_posting = 1
835 ORDER BY bbcode_tag';
836 $result = phpbb
::$db->sql_query($sql);
839 while ($row = phpbb
::$db->sql_fetchrow($result))
841 // If the helpline is defined within the language file, we will use the localised version, else just use the database entry...
842 if (isset(phpbb
::$user->lang
[strtoupper($row['bbcode_helpline'])]))
844 $row['bbcode_helpline'] = phpbb
::$user->lang
[strtoupper($row['bbcode_helpline'])];
847 phpbb
::$template->assign_block_vars('custom_tags', array(
848 'BBCODE_NAME' => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'",
849 'BBCODE_ID' => $num_predefined_bbcodes +
($i * 2),
850 'BBCODE_TAG' => $row['bbcode_tag'],
851 'BBCODE_HELPLINE' => $row['bbcode_helpline'],
852 'A_BBCODE_HELPLINE' => str_replace(array('&', '"', "'", '<', '>'), array('&', '"', "\'", '<', '>'), $row['bbcode_helpline']),
857 phpbb
::$db->sql_freeresult($result);
863 function display_reasons($reason_id = 0)
866 FROM ' . REPORTS_REASONS_TABLE
. '
867 ORDER BY reason_order ASC';
868 $result = phpbb
::$db->sql_query($sql);
870 while ($row = phpbb
::$db->sql_fetchrow($result))
872 // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
873 if (isset(phpbb
::$user->lang
['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset(phpbb
::$user->lang
['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
875 $row['reason_description'] = phpbb
::$user->lang
['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
876 $row['reason_title'] = phpbb
::$user->lang
['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
879 phpbb
::$template->assign_block_vars('reason', array(
880 'ID' => $row['reason_id'],
881 'TITLE' => $row['reason_title'],
882 'DESCRIPTION' => $row['reason_description'],
883 'S_SELECTED' => ($row['reason_id'] == $reason_id) ?
true : false,
886 phpbb
::$db->sql_freeresult($result);
890 * Display user activity (action forum/topic)
892 function display_user_activity(&$userdata)
894 // Do not display user activity for users having more than 5000 posts...
895 if ($userdata['user_posts'] > 5000)
900 $forum_ary = array();
902 // Do not include those forums the user is not having read access to...
903 $forum_read_ary = phpbb
::$acl->acl_getf('!f_read');
905 foreach ($forum_read_ary as $forum_id => $not_allowed)
907 if ($not_allowed['f_read'])
909 $forum_ary[] = (int) $forum_id;
913 $forum_ary = array_unique($forum_ary);
914 $forum_sql = (sizeof($forum_ary)) ?
'AND ' . phpbb
::$db->sql_in_set('forum_id', $forum_ary, true) : '';
916 // Obtain active forum
917 $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts
918 FROM ' . POSTS_TABLE
. '
919 WHERE poster_id = ' . $userdata['user_id'] . "
920 AND post_postcount = 1
923 ORDER BY num_posts DESC";
924 $result = phpbb
::$db->sql_query_limit($sql, 1);
925 $active_f_row = phpbb
::$db->sql_fetchrow($result);
926 phpbb
::$db->sql_freeresult($result);
928 if (!empty($active_f_row))
930 $sql = 'SELECT forum_name
931 FROM ' . FORUMS_TABLE
. '
932 WHERE forum_id = ' . $active_f_row['forum_id'];
933 $result = phpbb
::$db->sql_query($sql, 3600);
934 $active_f_row['forum_name'] = (string) phpbb
::$db->sql_fetchfield('forum_name');
935 phpbb
::$db->sql_freeresult($result);
938 // Obtain active topic
939 $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts
940 FROM ' . POSTS_TABLE
. '
941 WHERE poster_id = ' . $userdata['user_id'] . "
942 AND post_postcount = 1
945 ORDER BY num_posts DESC";
946 $result = phpbb
::$db->sql_query_limit($sql, 1);
947 $active_t_row = phpbb
::$db->sql_fetchrow($result);
948 phpbb
::$db->sql_freeresult($result);
950 if (!empty($active_t_row))
952 $sql = 'SELECT topic_title
953 FROM ' . TOPICS_TABLE
. '
954 WHERE topic_id = ' . $active_t_row['topic_id'];
955 $result = phpbb
::$db->sql_query($sql);
956 $active_t_row['topic_title'] = (string) phpbb
::$db->sql_fetchfield('topic_title');
957 phpbb
::$db->sql_freeresult($result);
960 $userdata['active_t_row'] = $active_t_row;
961 $userdata['active_f_row'] = $active_f_row;
963 $active_f_name = $active_f_id = $active_f_count = $active_f_pct = '';
964 if (!empty($active_f_row['num_posts']))
966 $active_f_name = $active_f_row['forum_name'];
967 $active_f_id = $active_f_row['forum_id'];
968 $active_f_count = $active_f_row['num_posts'];
969 $active_f_pct = ($userdata['user_posts']) ?
($active_f_count / $userdata['user_posts']) * 100 : 0;
972 $active_t_name = $active_t_id = $active_t_count = $active_t_pct = '';
973 if (!empty($active_t_row['num_posts']))
975 $active_t_name = $active_t_row['topic_title'];
976 $active_t_id = $active_t_row['topic_id'];
977 $active_t_count = $active_t_row['num_posts'];
978 $active_t_pct = ($userdata['user_posts']) ?
($active_t_count / $userdata['user_posts']) * 100 : 0;
981 $l_active_pct = ($userdata['user_id'] != ANONYMOUS
&& $userdata['user_id'] == phpbb
::$user->data
['user_id']) ? phpbb
::$user->lang
['POST_PCT_ACTIVE_OWN'] : phpbb
::$user->lang
['POST_PCT_ACTIVE'];
983 phpbb
::$template->assign_vars(array(
984 'ACTIVE_FORUM' => $active_f_name,
985 'ACTIVE_FORUM_POSTS' => ($active_f_count == 1) ?
sprintf(phpbb
::$user->lang
['USER_POST'], 1) : sprintf(phpbb
::$user->lang
['USER_POSTS'], $active_f_count),
986 'ACTIVE_FORUM_PCT' => sprintf($l_active_pct, $active_f_pct),
987 'ACTIVE_TOPIC' => censor_text($active_t_name),
988 'ACTIVE_TOPIC_POSTS' => ($active_t_count == 1) ?
sprintf(phpbb
::$user->lang
['USER_POST'], 1) : sprintf(phpbb
::$user->lang
['USER_POSTS'], $active_t_count),
989 'ACTIVE_TOPIC_PCT' => sprintf($l_active_pct, $active_t_pct),
990 'U_ACTIVE_FORUM' => phpbb
::$url->append_sid('viewforum', 'f=' . $active_f_id),
991 'U_ACTIVE_TOPIC' => phpbb
::$url->append_sid('viewtopic', 't=' . $active_t_id),
992 'S_SHOW_ACTIVITY' => true,
997 * Topic and forum watching common code
999 function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, $notify_status = 'unset', $start = 0)
1003 $table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE
: TOPICS_WATCH_TABLE
;
1004 $where_sql = ($mode == 'forum') ?
'forum_id' : 'topic_id';
1005 $match_id = ($mode == 'forum') ?
$forum_id : $topic_id;
1006 $u_url = 'uid=' . phpbb
::$user->data
['user_id'];
1007 $u_url .= ($mode == 'forum') ?
'&f' : '&f=' . $forum_id . '&t';
1009 // Is user watching this thread?
1010 if ($user_id != ANONYMOUS
)
1014 if ($notify_status == 'unset')
1016 $sql = "SELECT notify_status
1018 WHERE $where_sql = $match_id
1019 AND user_id = $user_id";
1020 $result = phpbb
::$db->sql_query($sql);
1022 $notify_status = ($row = phpbb
::$db->sql_fetchrow($result)) ?
$row['notify_status'] : NULL;
1023 phpbb
::$db->sql_freeresult($result);
1026 if (!is_null($notify_status) && $notify_status !== '')
1029 if (phpbb_request
::is_set('unwatch', phpbb_request
::GET
))
1031 $uid = request_var('uid', 0);
1032 if ($uid != $user_id)
1034 $redirect_url = phpbb
::$url->append_sid("view$mode", "$u_url=$match_id&start=$start");
1035 $message = phpbb
::$user->lang
['ERR_UNWATCHING'] . '<br /><br />' . sprintf(phpbb
::$user->lang
['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1036 trigger_error($message);
1038 if (phpbb_request
::variable('unwatch', '', false, phpbb_request
::GET
) == $mode)
1042 $sql = 'DELETE FROM ' . $table_sql . "
1043 WHERE $where_sql = $match_id
1044 AND user_id = $user_id";
1045 phpbb
::$db->sql_query($sql);
1048 $redirect_url = phpbb
::$url->append_sid("view$mode", "$u_url=$match_id&start=$start");
1050 meta_refresh(3, $redirect_url);
1052 $message = phpbb
::$user->lang
['NOT_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf(phpbb
::$user->lang
['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1053 trigger_error($message);
1057 $is_watching = true;
1061 $sql = 'UPDATE ' . $table_sql . "
1062 SET notify_status = 0
1063 WHERE $where_sql = $match_id
1064 AND user_id = $user_id";
1065 phpbb
::$db->sql_query($sql);
1071 if (phpbb_request
::is_set('watch', phpbb_request
::GET
))
1073 $token = request_var('hash', '');
1074 $redirect_url = phpbb
::$url->append_sid("view$mode", "$u_url=$match_id&start=$start");
1076 if (phpbb_request
::variable('watch', '', false, phpbb_request
::GET
) == $mode && check_link_hash($token, "{$mode}_$match_id"))
1078 $is_watching = true;
1080 $sql = 'INSERT INTO ' . $table_sql . " (user_id, $where_sql, notify_status)
1081 VALUES ($user_id, $match_id, 0)";
1082 phpbb
::$db->sql_query($sql);
1083 $message = phpbb
::$user->lang
['ARE_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf(phpbb
::$user->lang
['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1087 $message = phpbb
::$user->lang
['ERR_WATCHING'] . '<br /><br />' . sprintf(phpbb
::$user->lang
['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1090 meta_refresh(3, $redirect_url);
1092 trigger_error($message);
1102 if (phpbb_request
::variable('unwatch', '', false, phpbb_request
::GET
) == $mode)
1115 $s_watching['link'] = phpbb
::$url->append_sid("view$mode", "$u_url=$match_id&" . (($is_watching) ?
'unwatch' : 'watch') . "=$mode&start=$start&hash=" . generate_link_hash("{$mode}_$match_id"));
1116 $s_watching['title'] = phpbb
::$user->lang
[(($is_watching) ?
'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)];
1117 $s_watching['is_watching'] = $is_watching;
1124 * Get user rank title and image
1126 * @param int $user_id the users user id
1127 * @param int $user_rank the current stored users rank id
1128 * @param int $user_posts the users number of posts
1129 * @param string &$rank_title the rank title will be stored here after execution
1130 * @param string &$rank_img the rank image as full img tag is stored here after execution
1131 * @param string &$rank_img_src the rank image source is stored here after execution
1134 function get_user_rank($user_id, $user_rank, $user_posts, &$rank_title, &$rank_img, &$rank_img_src)
1140 $ranks = phpbb_cache
::obtain_ranks();
1143 if (!empty($user_rank))
1145 $rank_title = (isset($ranks['special'][$user_rank]['rank_title'])) ?
$ranks['special'][$user_rank]['rank_title'] : '';
1146 $rank_img = (!empty($ranks['special'][$user_rank]['rank_image'])) ?
'<img src="' . PHPBB_ROOT_PATH
. phpbb
::$config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] . '" alt="' . $ranks['special'][$user_rank]['rank_title'] . '" title="' . $ranks['special'][$user_rank]['rank_title'] . '" />' : '';
1147 $rank_img_src = (!empty($ranks['special'][$user_rank]['rank_image'])) ? PHPBB_ROOT_PATH
. phpbb
::$config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] : '';
1149 else if ($user_id != ANONYMOUS
)
1151 if (!empty($ranks['normal']))
1153 foreach ($ranks['normal'] as $rank)
1155 if ($user_posts >= $rank['rank_min'])
1157 $rank_title = $rank['rank_title'];
1158 $rank_img = (!empty($rank['rank_image'])) ?
'<img src="' . PHPBB_ROOT_PATH
. phpbb
::$config['ranks_path'] . '/' . $rank['rank_image'] . '" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" />' : '';
1159 $rank_img_src = (!empty($rank['rank_image'])) ? PHPBB_ROOT_PATH
. phpbb
::$config['ranks_path'] . '/' . $rank['rank_image'] : '';
1170 * @param string $avatar Users assigned avatar name
1171 * @param int $avatar_type Type of avatar
1172 * @param string $avatar_width Width of users avatar
1173 * @param string $avatar_height Height of users avatar
1174 * @param string $alt Optional language string for alt tag within image, can be a language key or text
1176 * @return string Avatar image
1178 function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR')
1180 if (empty($avatar) ||
!$avatar_type)
1187 switch ($avatar_type)
1190 $avatar_img = PHPBB_ROOT_PATH
. 'download/file.' . PHP_EXT
. '?avatar=';
1193 case AVATAR_GALLERY
:
1194 $avatar_img = PHPBB_ROOT_PATH
. phpbb
::$config['avatar_gallery_path'] . '/';
1198 $avatar_img .= $avatar;
1199 return '<img src="' . (str_replace(' ', '%20', $avatar_img)) . '" width="' . $avatar_width . '" height="' . $avatar_height . '" alt="' . ((!empty(phpbb
::$user->lang
[$alt])) ? phpbb
::$user->lang
[$alt] : $alt) . '" />';