Example #1
0
$pagination = generate_pagination(append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&t={$topic_id}" . (strlen($u_sort_param) ? "&{$u_sort_param}" : '') . ($highlight_match ? "&hilit={$highlight}" : '')), $total_posts, $config['posts_per_page'], $start);
// Navigation links
generate_forum_nav($topic_data);
// Forum Rules
generate_forum_rules($topic_data);
// Moderators
$forum_moderators = array();
if ($config['load_moderators']) {
    get_moderators($forum_moderators, $forum_id);
}
// This is only used for print view so ...
$server_path = !$view ? $phpbb_root_path : generate_board_url() . '/';
// Replace naughty words in title
$topic_data['topic_title'] = censor_text($topic_data['topic_title']);
//global_announcements
global_announcements();
// Send vars to template
$template->assign_vars(array('FORUM_ID' => $forum_id, 'FORUM_NAME' => $topic_data['forum_name'], 'FORUM_DESC' => generate_text_for_display($topic_data['forum_desc'], $topic_data['forum_desc_uid'], $topic_data['forum_desc_bitfield'], $topic_data['forum_desc_options']), 'TOPIC_ID' => $topic_id, 'TOPIC_TITLE' => $topic_data['topic_title'], 'TOPIC_POSTER' => $topic_data['topic_poster'], 'TOPIC_AUTHOR_FULL' => get_username_string('full', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']), 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']), 'TOPIC_AUTHOR' => get_username_string('username', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']), 'PAGINATION' => $pagination, 'PAGE_NUMBER' => on_page($total_posts, $config['posts_per_page'], $start), 'TOTAL_POSTS' => $total_posts == 1 ? $user->lang['VIEW_TOPIC_POST'] : sprintf($user->lang['VIEW_TOPIC_POSTS'], $total_posts), 'U_MCP' => $auth->acl_get('m_', $forum_id) ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i=main&amp;mode=topic_view&amp;f={$forum_id}&amp;t={$topic_id}&amp;start={$start}" . (strlen($u_sort_param) ? "&amp;{$u_sort_param}" : ''), true, $user->session_id) : '', 'MODERATORS' => isset($forum_moderators[$forum_id]) && sizeof($forum_moderators[$forum_id]) ? implode(', ', $forum_moderators[$forum_id]) : '', 'POST_IMG' => $topic_data['forum_status'] == ITEM_LOCKED ? $user->img('button_topic_locked', 'FORUM_LOCKED') : $user->img('button_topic_new', 'POST_NEW_TOPIC'), 'QUOTE_IMG' => $user->img('icon_post_quote', 'REPLY_WITH_QUOTE'), 'REPLY_IMG' => $topic_data['forum_status'] == ITEM_LOCKED || $topic_data['topic_status'] == ITEM_LOCKED ? $user->img('button_topic_locked', 'TOPIC_LOCKED') : $user->img('button_topic_reply', 'REPLY_TO_TOPIC'), 'EDIT_IMG' => $user->img('icon_post_edit', 'EDIT_POST'), 'DELETE_IMG' => $user->img('icon_post_delete', 'DELETE_POST'), 'INFO_IMG' => $user->img('icon_post_info', 'VIEW_INFO'), 'PROFILE_IMG' => $user->img('icon_user_profile', 'READ_PROFILE'), 'SEARCH_IMG' => $user->img('icon_user_search', 'SEARCH_USER_POSTS'), 'PM_IMG' => $user->img('icon_contact_pm', 'SEND_PRIVATE_MESSAGE'), 'EMAIL_IMG' => $user->img('icon_contact_email', 'SEND_EMAIL'), 'WWW_IMG' => $user->img('icon_contact_www', 'VISIT_WEBSITE'), 'ICQ_IMG' => $user->img('icon_contact_icq', 'ICQ'), 'AIM_IMG' => $user->img('icon_contact_aim', 'AIM'), 'MSN_IMG' => $user->img('icon_contact_msnm', 'MSNM'), 'YIM_IMG' => $user->img('icon_contact_yahoo', 'YIM'), 'JABBER_IMG' => $user->img('icon_contact_jabber', 'JABBER'), 'REPORT_IMG' => $user->img('icon_post_report', 'REPORT_POST'), 'REPORTED_IMG' => $user->img('icon_topic_reported', 'POST_REPORTED'), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'POST_UNAPPROVED'), 'WARN_IMG' => $user->img('icon_user_warn', 'WARN_USER'), 'S_IS_LOCKED' => $topic_data['topic_status'] == ITEM_UNLOCKED && $topic_data['forum_status'] == ITEM_UNLOCKED ? false : true, 'S_SELECT_SORT_DIR' => $s_sort_dir, 'S_SELECT_SORT_KEY' => $s_sort_key, 'S_SELECT_SORT_DAYS' => $s_limit_days, 'S_SINGLE_MODERATOR' => !empty($forum_moderators[$forum_id]) && sizeof($forum_moderators[$forum_id]) > 1 ? false : true, 'S_TOPIC_ACTION' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&amp;t={$topic_id}&amp;start={$start}"), 'S_TOPIC_MOD' => $topic_mod != '' ? '<select name="action" id="quick-mod-select">' . $topic_mod . '</select>' : '', 'S_MOD_ACTION' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", "f={$forum_id}&amp;t={$topic_id}&amp;start={$start}&amp;quickmod=1&amp;redirect=" . urlencode(str_replace('&amp;', '&', $viewtopic_url)), true, $user->session_id), 'S_VIEWTOPIC' => true, 'S_DISPLAY_SEARCHBOX' => $auth->acl_get('u_search') && $auth->acl_get('f_search', $forum_id) && $config['load_search'] ? true : false, 'S_SEARCHBOX_ACTION' => append_sid("{$phpbb_root_path}search.{$phpEx}", 't=' . $topic_id), 'S_DISPLAY_POST_INFO' => $topic_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS) ? true : false, 'S_DISPLAY_REPLY_INFO' => $topic_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_reply', $forum_id) || $user->data['user_id'] == ANONYMOUS) ? true : false, 'S_ENABLE_FEEDS_TOPIC' => $config['feed_topic'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $topic_data['forum_options']) ? true : false, 'U_TOPIC' => "{$server_path}viewtopic.{$phpEx}?f={$forum_id}&amp;t={$topic_id}", 'U_FORUM' => $server_path, 'U_VIEW_TOPIC' => $viewtopic_url, 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id), 'U_VIEW_OLDER_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&amp;t={$topic_id}&amp;view=previous"), 'U_VIEW_NEWER_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&amp;t={$topic_id}&amp;view=next"), 'U_PRINT_TOPIC' => $auth->acl_get('f_print', $forum_id) ? $viewtopic_url . '&amp;view=print' : '', 'U_EMAIL_TOPIC' => $auth->acl_get('f_email', $forum_id) && $config['email_enable'] ? append_sid("{$phpbb_root_path}memberlist.{$phpEx}", "mode=email&amp;t={$topic_id}") : '', 'U_WATCH_TOPIC' => $s_watching_topic['link'], 'L_WATCH_TOPIC' => $s_watching_topic['title'], 'S_WATCHING_TOPIC' => $s_watching_topic['is_watching'], 'U_BOOKMARK_TOPIC' => $user->data['is_registered'] && $config['allow_bookmarks'] ? $viewtopic_url . '&amp;bookmark=1&amp;hash=' . generate_link_hash("topic_{$topic_id}") : '', 'L_BOOKMARK_TOPIC' => $user->data['is_registered'] && $config['allow_bookmarks'] && $topic_data['bookmarked'] ? $user->lang['BOOKMARK_TOPIC_REMOVE'] : $user->lang['BOOKMARK_TOPIC'], 'U_POST_NEW_TOPIC' => $auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS ? append_sid("{$phpbb_root_path}posting.{$phpEx}", "mode=post&amp;f={$forum_id}") : '', 'U_POST_REPLY_TOPIC' => $auth->acl_get('f_reply', $forum_id) || $user->data['user_id'] == ANONYMOUS ? append_sid("{$phpbb_root_path}posting.{$phpEx}", "mode=reply&amp;f={$forum_id}&amp;t={$topic_id}") : '', 'U_BUMP_TOPIC' => bump_topic_allowed($forum_id, $topic_data['topic_bumped'], $topic_data['topic_last_post_time'], $topic_data['topic_poster'], $topic_data['topic_last_poster_id']) ? append_sid("{$phpbb_root_path}posting.{$phpEx}", "mode=bump&amp;f={$forum_id}&amp;t={$topic_id}&amp;hash=" . generate_link_hash("topic_{$topic_id}")) : ''));
// Does this topic contain a poll?
if (!empty($topic_data['poll_start'])) {
    $sql = 'SELECT o.*, p.bbcode_bitfield, p.bbcode_uid
		FROM ' . POLL_OPTIONS_TABLE . ' o, ' . POSTS_TABLE . " p\n\t\tWHERE o.topic_id = {$topic_id}\n\t\t\tAND p.post_id = {$topic_data['topic_first_post_id']}\n\t\t\tAND p.topic_id = o.topic_id\n\t\tORDER BY o.poll_option_id";
    $result = $db->sql_query($sql);
    $poll_info = array();
    while ($row = $db->sql_fetchrow($result)) {
        $poll_info[] = $row;
    }
    $db->sql_freeresult($result);
    $cur_voted_id = array();
    if ($user->data['is_registered']) {
        $sql = 'SELECT poll_option_id
/**
* Display Forums
*/
function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
{
    global $db, $auth, $user, $template;
    global $phpbb_root_path, $phpEx, $config;
    $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
    $parent_id = $visible_forums = 0;
    $sql_from = '';
    // Mark forums read?
    $mark_read = request_var('mark', '');
    if ($mark_read == 'all') {
        $mark_read = '';
    }
    if (!$root_data) {
        if ($mark_read == 'forums') {
            $mark_read = 'all';
        }
        $root_data = array('forum_id' => 0);
        $sql_where = '';
    } else {
        $sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
    }
    // Display list of active topics for this category?
    $show_active = isset($root_data['forum_flags']) && $root_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS ? true : false;
    $sql_array = array('SELECT' => 'f.*', 'FROM' => array(FORUMS_TABLE => 'f'), 'LEFT_JOIN' => array());
    if ($config['load_db_lastread'] && $user->data['is_registered']) {
        $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');
        $sql_array['SELECT'] .= ', ft.mark_time';
    } else {
        if ($config['load_anon_lastread'] || $user->data['is_registered']) {
            $tracking_topics = isset($_COOKIE[$config['cookie_name'] . '_track']) ? STRIP ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track'] : '';
            $tracking_topics = $tracking_topics ? tracking_unserialize($tracking_topics) : array();
            if (!$user->data['is_registered']) {
                $user->data['user_lastmark'] = isset($tracking_topics['l']) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
            }
        }
    }
    if ($show_active) {
        $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_ACCESS_TABLE => 'fa'), 'ON' => "fa.forum_id = f.forum_id AND fa.session_id = '" . $db->sql_escape($user->session_id) . "'");
        $sql_array['SELECT'] .= ', fa.user_id';
    }
    $sql = $db->sql_build_query('SELECT', array('SELECT' => $sql_array['SELECT'], 'FROM' => $sql_array['FROM'], 'LEFT_JOIN' => $sql_array['LEFT_JOIN'], 'WHERE' => $sql_where, 'ORDER_BY' => 'f.left_id'));
    $result = $db->sql_query($sql);
    $forum_tracking_info = array();
    $branch_root_id = $root_data['forum_id'];
    // Check for unread global announcements (index page only)
    $ga_unread = false;
    if ($root_data['forum_id'] == 0) {
        $unread_ga_list = get_unread_topics($user->data['user_id'], 'AND t.forum_id = 0', '', 1);
        if (!empty($unread_ga_list)) {
            $ga_unread = true;
        }
    }
    while ($row = $db->sql_fetchrow($result)) {
        $forum_id = $row['forum_id'];
        // Mark forums read?
        if ($mark_read == 'forums' || $mark_read == 'all') {
            if ($auth->acl_get('f_list', $forum_id)) {
                $forum_ids[] = $forum_id;
                continue;
            }
        }
        // Category with no members
        if ($row['forum_type'] == FORUM_CAT && $row['left_id'] + 1 == $row['right_id']) {
            continue;
        }
        // Skip branch
        if (isset($right_id)) {
            if ($row['left_id'] < $right_id) {
                continue;
            }
            unset($right_id);
        }
        if (!$auth->acl_get('f_list', $forum_id)) {
            // if the user does not have permissions to list this forum, skip everything until next branch
            $right_id = $row['right_id'];
            continue;
        }
        $forum_ids[] = $forum_id;
        if ($config['load_db_lastread'] && $user->data['is_registered']) {
            $forum_tracking_info[$forum_id] = !empty($row['mark_time']) ? $row['mark_time'] : $user->data['user_lastmark'];
        } else {
            if ($config['load_anon_lastread'] || $user->data['is_registered']) {
                if (!$user->data['is_registered']) {
                    $user->data['user_lastmark'] = isset($tracking_topics['l']) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
                }
                $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'];
            }
        }
        // Count the difference of real to public topics, so we can display an information to moderators
        $row['forum_id_unapproved_topics'] = $auth->acl_get('m_approve', $forum_id) && $row['forum_topics_real'] != $row['forum_topics'] ? $forum_id : 0;
        $row['forum_topics'] = $auth->acl_get('m_approve', $forum_id) ? $row['forum_topics_real'] : $row['forum_topics'];
        // Display active topics from this forum?
        if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && $row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) {
            if (!isset($active_forum_ary['forum_topics'])) {
                $active_forum_ary['forum_topics'] = 0;
            }
            if (!isset($active_forum_ary['forum_posts'])) {
                $active_forum_ary['forum_posts'] = 0;
            }
            $active_forum_ary['forum_id'][] = $forum_id;
            $active_forum_ary['enable_icons'][] = $row['enable_icons'];
            $active_forum_ary['forum_topics'] += $row['forum_topics'];
            $active_forum_ary['forum_posts'] += $row['forum_posts'];
            // If this is a passworded forum we do not show active topics from it if the user is not authorised to view it...
            if ($row['forum_password'] && $row['user_id'] != $user->data['user_id']) {
                $active_forum_ary['exclude_forum_id'][] = $forum_id;
            }
        }
        //
        if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id) {
            if ($row['forum_type'] != FORUM_CAT) {
                $forum_ids_moderator[] = (int) $forum_id;
            }
            // Direct child of current branch
            $parent_id = $forum_id;
            $forum_rows[$forum_id] = $row;
            if ($row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id']) {
                $branch_root_id = $forum_id;
            }
            $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
            $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
        } else {
            if ($row['forum_type'] != FORUM_CAT) {
                $subforums[$parent_id][$forum_id]['display'] = $row['display_on_index'] ? true : false;
                $subforums[$parent_id][$forum_id]['name'] = $row['forum_name'];
                $subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
                $subforums[$parent_id][$forum_id]['children'] = array();
                if (isset($subforums[$parent_id][$row['parent_id']]) && !$row['display_on_index']) {
                    $subforums[$parent_id][$row['parent_id']]['children'][] = $forum_id;
                }
                if (!$forum_rows[$parent_id]['forum_id_unapproved_topics'] && $row['forum_id_unapproved_topics']) {
                    $forum_rows[$parent_id]['forum_id_unapproved_topics'] = $forum_id;
                }
                $forum_rows[$parent_id]['forum_topics'] += $row['forum_topics'];
                // Do not list redirects in LINK Forums as Posts.
                if ($row['forum_type'] != FORUM_LINK) {
                    $forum_rows[$parent_id]['forum_posts'] += $row['forum_posts'];
                }
                if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time']) {
                    $forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
                    $forum_rows[$parent_id]['forum_last_post_subject'] = $row['forum_last_post_subject'];
                    $forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
                    $forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
                    $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
                    $forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour'];
                    $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
                }
            }
        }
    }
    $db->sql_freeresult($result);
    // Handle marking posts
    if ($mark_read == 'forums' || $mark_read == 'all') {
        $redirect = build_url(array('mark', 'hash'));
        $token = request_var('hash', '');
        if (check_link_hash($token, 'global')) {
            if ($mark_read == 'all') {
                markread('all');
                $message = sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>');
            } else {
                // Add 0 to forums array to mark global announcements correctly
                $forum_ids[] = 0;
                markread('topics', $forum_ids);
                $message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
            }
            meta_refresh(3, $redirect);
            trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . $message);
        } else {
            $message = sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
            meta_refresh(3, $redirect);
            trigger_error($message);
        }
    }
    // Grab moderators ... if necessary
    if ($display_moderators) {
        if ($return_moderators) {
            $forum_ids_moderator[] = $root_data['forum_id'];
        }
        get_moderators($forum_moderators, $forum_ids_moderator);
    }
    //global_announcements
    global_announcements();
    // Used to tell whatever we have to create a dummy category or not.
    $last_catless = true;
    foreach ($forum_rows as $row) {
        // Empty category
        if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT) {
            $template->assign_block_vars('forumrow', array('S_IS_CAT' => true, 'FORUM_ID' => $row['forum_id'], 'FORUM_NAME' => $row['forum_name'], 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']), 'FORUM_FOLDER_IMG' => '', 'FORUM_FOLDER_IMG_SRC' => '', 'FORUM_IMAGE' => $row['forum_image'] ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang['FORUM_CAT'] . '" />' : '', 'FORUM_IMAGE_SRC' => $row['forum_image'] ? $phpbb_root_path . $row['forum_image'] : '', 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id'])));
            continue;
        }
        $visible_forums++;
        $forum_id = $row['forum_id'];
        $forum_unread = isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id] ? true : false;
        // Mark the first visible forum on index as unread if there's any unread global announcement
        if ($ga_unread && !empty($forum_ids_moderator) && $forum_id == $forum_ids_moderator[0]) {
            $forum_unread = true;
        }
        $folder_image = $folder_alt = $l_subforums = '';
        $subforums_list = array();
        // Generate list of subforums if we need to
        if (isset($subforums[$forum_id])) {
            foreach ($subforums[$forum_id] as $subforum_id => $subforum_row) {
                $subforum_unread = isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id] ? true : false;
                if (!$subforum_unread && !empty($subforum_row['children'])) {
                    foreach ($subforum_row['children'] as $child_id) {
                        if (isset($forum_tracking_info[$child_id]) && $subforums[$forum_id][$child_id]['orig_forum_last_post_time'] > $forum_tracking_info[$child_id]) {
                            // Once we found an unread child forum, we can drop out of this loop
                            $subforum_unread = true;
                            break;
                        }
                    }
                }
                if ($subforum_row['display'] && $subforum_row['name']) {
                    $subforums_list[] = array('link' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $subforum_id), 'name' => $subforum_row['name'], 'unread' => $subforum_unread);
                } else {
                    unset($subforums[$forum_id][$subforum_id]);
                }
                // If one subforum is unread the forum gets unread too...
                if ($subforum_unread) {
                    $forum_unread = true;
                }
            }
            $l_subforums = sizeof($subforums[$forum_id]) == 1 ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';
            $folder_image = $forum_unread ? 'forum_unread_subforum' : 'forum_read_subforum';
        } else {
            switch ($row['forum_type']) {
                case FORUM_POST:
                    $folder_image = $forum_unread ? 'forum_unread' : 'forum_read';
                    break;
                case FORUM_LINK:
                    $folder_image = 'forum_link';
                    break;
            }
        }
        // Which folder should we display?
        if ($row['forum_status'] == ITEM_LOCKED) {
            $folder_image = $forum_unread ? 'forum_unread_locked' : 'forum_read_locked';
            $folder_alt = 'FORUM_LOCKED';
        } else {
            $folder_alt = $forum_unread ? 'NEW_POSTS' : 'NO_NEW_POSTS';
        }
        // Create last post link information, if appropriate
        if ($row['forum_last_post_id']) {
            $last_post_subject = $row['forum_last_post_subject'];
            $last_post_time = $user->format_date($row['forum_last_post_time']);
            $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'];
        } else {
            $last_post_subject = $last_post_time = $last_post_url = '';
        }
        // Output moderator listing ... if applicable
        $l_moderator = $moderators_list = '';
        if ($display_moderators && !empty($forum_moderators[$forum_id])) {
            $l_moderator = sizeof($forum_moderators[$forum_id]) == 1 ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
            $moderators_list = implode(', ', $forum_moderators[$forum_id]);
        }
        $l_post_click_count = $row['forum_type'] == FORUM_LINK ? 'CLICKS' : 'POSTS';
        $post_click_count = $row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK ? $row['forum_posts'] : '';
        $s_subforums_list = array();
        foreach ($subforums_list as $subforum) {
            $s_subforums_list[] = '<a href="' . $subforum['link'] . '" class="subforum ' . ($subforum['unread'] ? 'unread' : 'read') . '" title="' . ($subforum['unread'] ? $user->lang['NEW_POSTS'] : $user->lang['NO_NEW_POSTS']) . '">' . $subforum['name'] . '</a>';
        }
        $s_subforums_list = (string) implode(', ', $s_subforums_list);
        $catless = $row['parent_id'] == $root_data['forum_id'] ? true : false;
        if ($row['forum_type'] != FORUM_LINK) {
            $u_viewforum = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id']);
        } else {
            // If the forum is a link and we count redirects we need to visit it
            // If the forum is having a password or no read access we do not expose the link, but instead handle it in viewforum
            if ($row['forum_flags'] & FORUM_FLAG_LINK_TRACK || $row['forum_password'] || !$auth->acl_get('f_read', $forum_id)) {
                $u_viewforum = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id']);
            } else {
                $u_viewforum = $row['forum_link'];
            }
        }
        $template->assign_block_vars('forumrow', array('S_IS_CAT' => false, 'S_NO_CAT' => $catless && !$last_catless, 'S_IS_LINK' => $row['forum_type'] == FORUM_LINK ? true : false, 'S_UNREAD_FORUM' => $forum_unread, 'S_LOCKED_FORUM' => $row['forum_status'] == ITEM_LOCKED ? true : false, 'S_LIST_SUBFORUMS' => $row['display_subforum_list'] ? true : false, 'S_SUBFORUMS' => sizeof($subforums_list) ? true : false, 'S_FEED_ENABLED' => $config['feed_forum'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $row['forum_options']) ? true : false, 'FORUM_ID' => $row['forum_id'], 'FORUM_NAME' => $row['forum_name'], 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']), 'TOPICS' => $row['forum_topics'], $l_post_click_count => $post_click_count, 'FORUM_FOLDER_IMG' => $user->img($folder_image, $folder_alt), 'FORUM_FOLDER_IMG_SRC' => $user->img($folder_image, $folder_alt, false, '', 'src'), 'FORUM_FOLDER_IMG_ALT' => isset($user->lang[$folder_alt]) ? $user->lang[$folder_alt] : '', 'FORUM_IMAGE' => $row['forum_image'] ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '', 'FORUM_IMAGE_SRC' => $row['forum_image'] ? $phpbb_root_path . $row['forum_image'] : '', 'LAST_POST_SUBJECT' => censor_text($last_post_subject), 'LAST_POST_TIME' => $last_post_time, 'LAST_POSTER' => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), 'LAST_POSTER_COLOUR' => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), 'LAST_POSTER_FULL' => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), 'MODERATORS' => $moderators_list, 'SUBFORUMS' => $s_subforums_list, 'L_SUBFORUM_STR' => $l_subforums, 'L_FORUM_FOLDER_ALT' => $folder_alt, 'L_MODERATOR_STR' => $l_moderator, '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']) : '', 'U_VIEWFORUM' => $u_viewforum, 'U_LAST_POSTER' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), 'U_LAST_POST' => $last_post_url));
        // Assign subforums loop for style authors
        foreach ($subforums_list as $subforum) {
            $template->assign_block_vars('forumrow.subforum', array('U_SUBFORUM' => $subforum['link'], 'SUBFORUM_NAME' => $subforum['name'], 'S_UNREAD' => $subforum['unread']));
        }
        $last_catless = $catless;
    }
    $template->assign_vars(array('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') : '', 'S_HAS_SUBFORUM' => $visible_forums ? true : false, 'L_SUBFORUM' => $visible_forums == 1 ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'], 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPICS_UNAPPROVED')));
    if ($return_moderators) {
        return array($active_forum_ary, $forum_moderators);
    }
    return array($active_forum_ary, array());
}