function get_forum_func($xmlrpc_params)
{
    global $db, $auth, $user, $config, $mobiquo_config, $phpbb_home;
    $params = php_xmlrpc_decode($xmlrpc_params);
    $return_description = isset($params[0]) ? $params[0] : false;
    if (isset($params[1])) {
        $fid = intval($params[1]);
        $forum_filter = " WHERE f.parent_id = '{$fid}'";
        $root_forum_id = $fid;
    } else {
        $forum_filter = '';
        $root_forum_id = 0;
    }
    $user_watch_array = array();
    if ($user->data['is_registered']) {
        $sql = "SELECT notify_status,forum_id FROM " . FORUMS_WATCH_TABLE . " WHERE user_id = '" . $user->data['user_id'] . "'";
        $result_watch = $db->sql_query($sql);
        while ($row_watch = $db->sql_fetchrow($result_watch)) {
            if (isset($row_watch['notify_status']) && !is_null($row_watch['notify_status']) && $row_watch['notify_status'] !== '') {
                $user_watch_array[] = $row_watch['forum_id'];
            }
        }
    }
    $forum_rows = array();
    $forum_rows[$root_forum_id] = array('forum_id' => $root_forum_id, 'parent_id' => -1, 'child' => array());
    $forum_hide_forum_arr = !empty($mobiquo_config['hide_forum_id']) ? $mobiquo_config['hide_forum_id'] : array();
    $sql = 'SELECT f.*  FROM ' . FORUMS_TABLE . ' f ' . $forum_filter . '
            ORDER BY f.left_id ASC';
    $result = $db->sql_query($sql, 600);
    while ($row = $db->sql_fetchrow($result)) {
        $forum_id = $row['forum_id'];
        if ($row['forum_type'] == FORUM_CAT && $row['left_id'] + 1 == $row['right_id']) {
            // Non-postable forum with no subforums, don't display
            continue;
        }
        if (in_array($row['forum_id'], $forum_hide_forum_arr)) {
            continue;
        } elseif (in_array($row['parent_id'], $forum_hide_forum_arr)) {
            array_push($forum_hide_forum_arr, $row['forum_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) || isset($mobiquo_config['hide_forum_id']) && in_array($forum_id, $mobiquo_config['hide_forum_id'])) {
            // if the user does not have permissions to list this forum, skip everything until next branch
            $right_id = $row['right_id'];
            continue;
        }
        $row['unread_count'] = 0;
        if ($user->data['is_registered'] && ($config['email_enable'] || $config['jab_enable']) && $config['allow_forum_notify'] && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_subscribe', $forum_id)) {
            $row['can_subscribe'] = true;
            $row['is_subscribed'] = in_array($row['forum_id'], $user_watch_array) ? true : false;
        } else {
            $row['can_subscribe'] = false;
            $row['is_subscribed'] = false;
        }
        $forum_rows[$forum_id] = $row;
    }
    $db->sql_freeresult($result);
    $fids = array(-1);
    foreach ($forum_rows as $id => $value) {
        if (!in_array($value['parent_id'], $fids)) {
            unset($forum_rows[$id]);
        } else {
            if ($value['left_id'] > $value['right_id']) {
                unset($forum_rows[$id]);
            } else {
                $fids[] = $id;
            }
        }
    }
    while (empty($forum_rows[$root_forum_id]['child']) && count($forum_rows) > 1) {
        $current_parent_id = -1;
        $leaves_forum = array();
        foreach ($forum_rows as $row) {
            $row_parent_id = $row['parent_id'];
            if ($row_parent_id != $current_parent_id) {
                if (isset($leaves_forum[$row_parent_id])) {
                    $leaves_forum[$row_parent_id] = array();
                } else {
                    if (isset($leaves_forum[$forum_rows[$row_parent_id]['parent_id']])) {
                        $leaves_forum[$forum_rows[$row_parent_id]['parent_id']] = array();
                    }
                    $leaves_forum[$row_parent_id][] = $row['forum_id'];
                }
                $current_parent_id = $row_parent_id;
            } else {
                if ($row_parent_id == $current_parent_id) {
                    if (!empty($leaves_forum[$row_parent_id])) {
                        $leaves_forum[$row_parent_id][] = $row['forum_id'];
                    }
                }
            }
        }
        foreach ($leaves_forum as $node_forum_id => $leaves) {
            foreach ($leaves as $forum_id) {
                $forum =& $forum_rows[$forum_id];
                if (function_exists('get_unread_topics')) {
                    $unread_count = count(get_unread_topics(false, "AND t.forum_id = {$forum_id}"));
                } else {
                    $unread_count = count(tt_get_unread_topics(false, "AND t.forum_id = {$forum_id}"));
                }
                $forum['unread_count'] += $unread_count;
                if ($forum['unread_count']) {
                    $forum_rows[$forum['parent_id']]['unread_count'] += $forum['unread_count'];
                }
                $forum_type = $forum['forum_link'] ? 'link' : ($forum['forum_type'] != FORUM_POST ? 'category' : 'forum');
                if ($logo_icon_name = tp_get_forum_icon($forum_id, $forum_type, $forum['forum_status'], $forum['unread_count'])) {
                    $logo_url = $phpbb_home . $config['tapatalkdir'] . '/forum_icons/' . $logo_icon_name;
                } else {
                    if ($forum['forum_image']) {
                        if (preg_match('#^https?://#i', $forum['forum_image'])) {
                            $logo_url = $forum['forum_image'];
                        } else {
                            $logo_url = $phpbb_home . $forum['forum_image'];
                        }
                    } else {
                        $logo_url = '';
                    }
                }
                $xmlrpc_forum = array('forum_id' => new xmlrpcval($forum_id), 'forum_name' => new xmlrpcval(basic_clean($forum['forum_name']), 'base64'), 'parent_id' => new xmlrpcval($node_forum_id), 'logo_url' => new xmlrpcval($logo_url), 'url' => new xmlrpcval($forum['forum_link']));
                if ($forum['unread_count']) {
                    $xmlrpc_forum['unread_count'] = new xmlrpcval($forum['unread_count'], 'int');
                }
                if ($forum['unread_count']) {
                    $xmlrpc_forum['new_post'] = new xmlrpcval(true, 'boolean');
                }
                if ($forum['forum_password']) {
                    $xmlrpc_forum['is_protected'] = new xmlrpcval(true, 'boolean');
                }
                if (!empty($forum['can_subscribe'])) {
                    $xmlrpc_forum['can_subscribe'] = new xmlrpcval(true, 'boolean');
                } else {
                    $xmlrpc_forum['can_subscribe'] = new xmlrpcval(false, 'boolean');
                }
                if (!empty($forum['is_subscribed'])) {
                    $xmlrpc_forum['is_subscribed'] = new xmlrpcval(true, 'boolean');
                } else {
                    $xmlrpc_forum['is_subscribed'] = new xmlrpcval(false, 'boolean');
                }
                if ($forum['forum_type'] != FORUM_POST) {
                    $xmlrpc_forum['sub_only'] = new xmlrpcval(true, 'boolean');
                }
                if ($return_description) {
                    $description = smiley_text($forum['forum_desc'], true);
                    $description = generate_text_for_display($description, $forum['forum_desc_uid'], $forum['forum_desc_bitfield'], $forum['forum_desc_options']);
                    $description = preg_replace('/<br *?\\/?>/i', "\n", $description);
                    $xmlrpc_forum['description'] = new xmlrpcval(basic_clean($description), 'base64');
                }
                if (isset($forum['child'])) {
                    $xmlrpc_forum['child'] = new xmlrpcval($forum['child'], 'array');
                }
                $forum_rows[$node_forum_id]['child'][] = new xmlrpcval($xmlrpc_forum, 'struct');
                unset($forum_rows[$forum_id]);
            }
        }
    }
    $response = new xmlrpcval($forum_rows[$root_forum_id]['child'], 'array');
    return new xmlrpcresp($response);
}
/**
* 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);
    }
    // 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());
}
Example #3
0
				$l_search_title = $user->lang['SEARCH_UNREAD'];
				// force sorting
				$show_results = 'topics';
				$sort_key = 't';
				$sort_by_sql['t'] = 't.topic_last_post_time';
				$sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC');

				$sql_where = 'AND t.topic_moved_id = 0
					' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . '
					' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '');

				gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
				$s_sort_key = $s_sort_dir = $u_sort_param = $s_limit_days = '';

				$unread_list = array();
				$unread_list = get_unread_topics($user->data['user_id'], $sql_where, $sql_sort);

				if (!empty($unread_list))
				{
					$sql = 'SELECT t.topic_id
						FROM ' . TOPICS_TABLE . ' t
						WHERE ' . $db->sql_in_set('t.topic_id', array_keys($unread_list)) . "
						$sql_sort";
					$field = 'topic_id';
				}
			break;

			case 'newposts':
				$l_search_title = $user->lang['SEARCH_NEW'];
				// force sorting
				$show_results = (request_var('sr', 'topics') == 'posts') ? 'posts' : 'topics';
Example #4
0
	{
		if ($sql)
		{
			// Only return up to $total_matches_limit+1 ids (the last one will be removed later)
			$result = $db->sql_query_limit($sql, $total_matches_limit + 1);

			while ($row = $db->sql_fetchrow($result))
			{
				$id_ary[] = (int) $row[$field];
			}
			$db->sql_freeresult($result);
		}
		else if ($search_id == 'unreadposts')
		{
			// Only return up to $total_matches_limit+1 ids (the last one will be removed later)
			$id_ary = array_keys(get_unread_topics($user->data['user_id'], $sql_where, $sql_sort, $total_matches_limit + 1));
		}
		else
		{
			$search_id = '';
		}

		$total_match_count = sizeof($id_ary);
		if ($total_match_count)
		{
			// Limit the number to $total_matches_limit for pre-made searches
			if ($total_match_count > $total_matches_limit)
			{
				$found_more_search_matches = true;
				$total_match_count = $total_matches_limit;
			}
Example #5
0
 $total_match_count = 0;
 if ($search_id) {
     if ($sql) {
         // only return up to 1000 ids (the last one will be removed later)
         $result = $db->sql_query_limit($sql, 1001 - $start, $start);
         while ($row = $db->sql_fetchrow($result)) {
             $id_ary[] = (int) $row[$field];
         }
         $db->sql_freeresult($result);
         $total_match_count = sizeof($id_ary) + $start;
         $id_ary = array_slice($id_ary, 0, $per_page);
     } else {
         if ($search_id == 'unreadposts') {
             // tapatalk update
             if (function_exists('get_unread_topics')) {
                 $id_ary = array_keys(get_unread_topics($user->data['user_id'], $sql_where, $sql_sort, 1001 - $request_params[0], $request_params[0]));
             } else {
                 $id_ary = array_keys(tt_get_unread_topics($user->data['user_id'], $sql_where, $sql_sort, 1001 - $request_params[0], $request_params[0]));
             }
             $total_match_count = sizeof($id_ary) + $start;
             $id_ary = array_slice($id_ary, 0, $per_page);
         } else {
             $search_id = '';
         }
     }
 }
 sort($ex_fid_ary);
 sort($m_approve_fid_ary);
 sort($author_id_ary);
 if (!empty($search->search_query)) {
     // tapatalk change
Example #6
0
    /**
     * {@inheritdoc}
     */
    public function get_template_side($module_id)
    {
        if (!function_exists('phpbb_get_user_rank')) {
            include $this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext;
        }
        if ($this->user->data['is_registered']) {
            //
            // + new posts since last visit & you post number
            //
            $ex_fid_ary = array_unique(array_merge(array_keys($this->auth->acl_getf('!f_read', true)), array_keys($this->auth->acl_getf('!f_search', true))));
            if ($this->auth->acl_get('m_approve')) {
                $m_approve_fid_sql = '';
            } else {
                if ($this->auth->acl_getf_global('m_approve')) {
                    $m_approve_fid_ary = array_diff(array_keys($this->auth->acl_getf('!m_approve', true)), $ex_fid_ary);
                    $m_approve_fid_sql = ' AND (p.post_visibility = 1' . (sizeof($m_approve_fid_ary) ? ' OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) : '') . ')';
                } else {
                    $m_approve_fid_sql = ' AND p.post_visibility = 1';
                }
            }
            $sql = 'SELECT COUNT(DISTINCT t.topic_id) as total
						FROM ' . TOPICS_TABLE . ' t
						WHERE t.topic_last_post_time > ' . (int) $this->user->data['user_lastvisit'] . '
							AND t.topic_moved_id = 0
							' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . '
							' . (sizeof($ex_fid_ary) ? 'AND ' . $this->db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '');
            $result = $this->db->sql_query($sql, 600);
            $new_posts_count = (int) $this->db->sql_fetchfield('total');
            $this->db->sql_freeresult($result);
            // unread posts
            $sql_where = 'AND t.topic_moved_id = 0
							' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . '
							' . (sizeof($ex_fid_ary) ? 'AND ' . $this->db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '');
            $unread_list = get_unread_topics($this->user->data['user_id'], $sql_where, 'ORDER BY t.topic_id DESC');
            $unread_posts_count = sizeof($unread_list);
            // Get user avatar and rank
            $user_id = $this->user->data['user_id'];
            $username = $this->user->data['username'];
            $colour = $this->user->data['user_colour'];
            $avatar_img = phpbb_get_avatar(\phpbb\avatar\manager::clean_row($this->user->data, 'user'), 'USER_AVATAR');
            $rank_data = phpbb_get_user_rank($this->user->data, $this->user->data['user_posts']);
            // Assign specific vars
            $this->template->assign_vars(array('L_NEW_POSTS' => $this->user->lang['SEARCH_NEW'] . '&nbsp;(' . $new_posts_count . ')', 'L_SELF_POSTS' => $this->user->lang['SEARCH_SELF'] . '&nbsp;(' . $this->user->data['user_posts'] . ')', 'L_UNREAD_POSTS' => $this->user->lang['SEARCH_UNREAD'] . '&nbsp;(' . $unread_posts_count . ')', 'B3P_AVATAR_IMG' => $avatar_img, 'B3P_RANK_TITLE' => $rank_data['title'], 'B3P_RANK_IMG' => $rank_data['img'], 'RANK_IMG_SRC' => $rank_data['img_src'], 'USERNAME_FULL' => get_username_string('full', $user_id, $username, $colour), 'U_VIEW_PROFILE' => get_username_string('profile', $user_id, $username, $colour), 'U_NEW_POSTS' => append_sid("{$this->phpbb_root_path}search.{$this->php_ext}", 'search_id=newposts'), 'U_SELF_POSTS' => append_sid("{$this->phpbb_root_path}search.{$this->php_ext}", 'search_id=egosearch'), 'U_UNREAD_POSTS' => append_sid("{$this->phpbb_root_path}search.{$this->php_ext}", 'search_id=unreadposts'), 'U_UM_BOOKMARKS' => $this->config['allow_bookmarks'] ? append_sid("{$this->phpbb_root_path}ucp.{$this->php_ext}", 'i=main&amp;mode=bookmarks') : '', 'U_UM_MAIN_SUBSCRIBED' => append_sid("{$this->phpbb_root_path}ucp.{$this->php_ext}", 'i=main&amp;mode=subscribed'), 'U_UM_MCP' => $this->auth->acl_get('m_') || $this->auth->acl_getf_global('m_') ? append_sid("{$this->phpbb_root_path}mcp.{$this->php_ext}", 'i=main&amp;mode=front', true, $this->user->session_id) : '', 'S_DISPLAY_SUBSCRIPTIONS' => $this->config['allow_topic_notify'] || $this->config['allow_forum_notify'] ? true : false));
            return 'user_menu_side.html';
        } else {
            /*
             * Assign specific vars
             * Need to remove web root path as ucp.php will do the
             * redirect
             */
            $this->template->assign_vars(array('U_PORTAL_REDIRECT' => $this->path_helper->remove_web_root_path($this->controller_helper->route('board3_portal_controller')), 'S_DISPLAY_FULL_LOGIN' => true, 'S_AUTOLOGIN_ENABLED' => $this->config['allow_autologin'] ? true : false, 'S_LOGIN_ACTION' => append_sid("{$this->phpbb_root_path}ucp.{$this->php_ext}", 'mode=login'), 'S_SHOW_REGISTER' => $this->config['board3_user_menu_register_' . $module_id] ? true : false));
            return 'login_box_side.html';
        }
    }
Example #7
0
    public function display_recent_topics($tpl_loopname = 'recent_topics', $spec_forum_id = 0, $include_subforums = true)
    {
        $this->user->add_lang_ext('paybas/recenttopics', 'recenttopics');
        /**
         * Set some internal needed variables
         */
        $topics_per_page = $this->config['rt_number'];
        $num_pages = $this->config['rt_page_number'];
        $min_topic_level = $this->config['rt_min_topic_level'];
        $excluded_topics = $this->config['rt_anti_topics'];
        $display_parent_forums = $this->config['rt_parents'];
        $unread_only = $this->config['rt_unreadonly'];
        $sort_topics = $this->config['rt_sort_start_time'] ? 'topic_time' : 'topic_last_post_time';
        $persistent_display = $this->config['rt_persistent_display'];
        if ($persistent_display) {
            $this->template->assign_vars(array(strtoupper($tpl_loopname) . '_DISPLAY' => true));
        }
        $start = $this->request->variable($tpl_loopname . '_start', 0);
        $excluded_topic_ids = explode(', ', $excluded_topics);
        $total_limit = $topics_per_page * $num_pages;
        if (!function_exists('display_forums')) {
            include $this->root_path . 'includes/functions_display.' . $this->phpEx;
        }
        /**
         * Get the forums we take our topics from
         */
        // Get the allowed forums
        $forum_ary = array();
        $forum_read_ary = $this->auth->acl_getf('f_read');
        foreach ($forum_read_ary as $forum_id => $allowed) {
            if ($allowed['f_read']) {
                $forum_ary[] = (int) $forum_id;
            }
        }
        $forum_ids = array_unique($forum_ary);
        if (!sizeof($forum_ids)) {
            // No forums with f_read
            return;
        }
        $spec_forum_ary = array();
        if ($spec_forum_id) {
            // Only take a special-forum
            if (!$include_subforums) {
                if (!in_array($spec_forum_id, $forum_ids)) {
                    return;
                }
                $forum_ids = array();
                $sql = 'SELECT 1 as display_forum
					FROM ' . FORUMS_TABLE . '
					WHERE forum_id = ' . intval($spec_forum_id) . '
						AND forum_recent_topics = 1';
                $result = $this->db->sql_query_limit($sql, 1);
                $display_forum = (bool) $this->db->sql_fetchfield('display_forum');
                $this->db->sql_freeresult($result);
                if ($display_forum) {
                    $forum_ids = array($spec_forum_id);
                }
            } else {
                // ... and it's subforums
                $sql = 'SELECT f2.forum_id
					FROM ' . FORUMS_TABLE . ' f1
					LEFT JOIN ' . FORUMS_TABLE . " f2\n\t\t\t\t\t\tON (f2.left_id BETWEEN f1.left_id AND f1.right_id\n\t\t\t\t\t\t\tAND f2.forum_recent_topics = 1)\n\t\t\t\t\tWHERE f1.forum_id = {$spec_forum_id}\n\t\t\t\t\t\tAND f1.forum_recent_topics = 1\n\t\t\t\t\tORDER BY f2.left_id DESC";
                $result = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $spec_forum_ary[] = $row['forum_id'];
                }
                $this->db->sql_freeresult($result);
                $forum_ids = array_intersect($forum_ids, $spec_forum_ary);
                if (!sizeof($forum_ids)) {
                    return;
                }
            }
        } else {
            $sql = 'SELECT forum_id
				FROM ' . FORUMS_TABLE . '
				WHERE ' . $this->db->sql_in_set('forum_id', $forum_ids) . '
					AND forum_recent_topics = 1';
            $result = $this->db->sql_query($sql);
            $forum_ids = array();
            while ($row = $this->db->sql_fetchrow($result)) {
                $forum_ids[] = $row['forum_id'];
            }
            $this->db->sql_freeresult($result);
        }
        // No forums with f_read or recent topics enabled
        if (!sizeof($forum_ids)) {
            return;
        }
        // Remove duplicated ids
        $forum_ids = array_unique($forum_ids);
        $forums = $topic_list = array();
        $topics_count = 0;
        $obtain_icons = false;
        // Either use the phpBB core function to get unread topics, or the custom function for default behavior
        if ($unread_only && $this->user->data['user_id'] != ANONYMOUS) {
            // Get unread topics
            $sql_extra = ' AND ' . $this->db->sql_in_set('t.topic_id', $excluded_topic_ids, true);
            $sql_extra .= ' AND ' . $this->content_visibility->get_forums_visibility_sql('topic', $forum_ids, $table_alias = 't.');
            $unread_topics = get_unread_topics(false, $sql_extra, '', $total_limit);
            foreach ($unread_topics as $topic_id => $mark_time) {
                $topics_count++;
                if ($topics_count > $start && $topics_count <= $start + $topics_per_page) {
                    $topic_list[] = $topic_id;
                }
            }
        } else {
            // Get the allowed topics
            $sql_array = array('SELECT' => 't.forum_id, t.topic_id, t.topic_type, t.icon_id, tt.mark_time, ft.mark_time as f_mark_time', 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $this->user->data['user_id']), array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $this->user->data['user_id'])), 'WHERE' => $this->db->sql_in_set('t.topic_id', $excluded_topic_ids, true) . '
					AND t.topic_status <> ' . ITEM_MOVED . '
					AND ' . $this->content_visibility->get_forums_visibility_sql('topic', $forum_ids, $table_alias = 't.'), 'ORDER_BY' => 't.' . $sort_topics . ' DESC');
            // Check if we want all topics, or only stickies/announcements/globals
            if ($min_topic_level > 0) {
                $sql_array['WHERE'] .= ' AND t.topic_type >= ' . $min_topic_level;
            }
            /**
             * Event to modify the SQL query before the allowed topics list data is retrieved
             *
             * @event paybas.recenttopics.sql_pull_topics_list
             * @var    array    sql_array        The SQL array
             * @since 2.0.4
             */
            $vars = array('sql_array');
            extract($this->dispatcher->trigger_event('paybas.recenttopics.sql_pull_topics_list', compact($vars)));
            $sql = $this->db->sql_build_query('SELECT', $sql_array);
            $result = $this->db->sql_query_limit($sql, $total_limit);
            while ($row = $this->db->sql_fetchrow($result)) {
                $topics_count++;
                if ($topics_count > $start && $topics_count <= $start + $topics_per_page) {
                    $topic_list[] = $row['topic_id'];
                    $rowset[$row['topic_id']] = $row;
                    if (!isset($forums[$row['forum_id']]) && $this->user->data['is_registered'] && $this->config['load_db_lastread']) {
                        $forums[$row['forum_id']]['mark_time'] = $row['f_mark_time'];
                    }
                    $forums[$row['forum_id']]['topic_list'][] = $row['topic_id'];
                    $forums[$row['forum_id']]['rowset'][$row['topic_id']] =& $rowset[$row['topic_id']];
                    if ($row['icon_id'] && $this->auth->acl_get('f_icons', $row['forum_id'])) {
                        $obtain_icons = true;
                    }
                }
            }
            $this->db->sql_freeresult($result);
        }
        // No topics to display
        if (!sizeof($topic_list)) {
            return;
        }
        // Grab icons
        if ($obtain_icons) {
            $icons = $this->cache->obtain_icons();
        } else {
            $icons = array();
        }
        // Borrowed from search.php
        foreach ($forums as $forum_id => $forum) {
            if ($this->user->data['is_registered'] && $this->config['load_db_lastread']) {
                $topic_tracking_info[$forum_id] = get_topic_tracking($forum_id, $forum['topic_list'], $forum['rowset'], array($forum_id => $forum['mark_time']), $forum_id ? false : $forum['topic_list']);
            } else {
                if ($this->config['load_anon_lastread'] || $this->user->data['is_registered']) {
                    $tracking_topics = $this->request->variable($this->config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE);
                    $tracking_topics = $tracking_topics ? tracking_unserialize($tracking_topics) : array();
                    $topic_tracking_info[$forum_id] = get_complete_topic_tracking($forum_id, $forum['topic_list'], $forum_id ? false : $forum['topic_list']);
                    if (!$this->user->data['is_registered']) {
                        $this->user->data['user_lastmark'] = isset($tracking_topics['l']) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $this->config['board_startdate']) : 0;
                    }
                }
            }
        }
        // Now only pull the data of the requested topics
        $sql_array = array('SELECT' => 't.*, tp.topic_posted, f.forum_name', 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 't.topic_id = tp.topic_id AND tp.user_id = ' . $this->user->data['user_id']), array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id')), 'WHERE' => $this->db->sql_in_set('t.topic_id', $topic_list), 'ORDER_BY' => 't.' . $sort_topics . ' DESC');
        if ($display_parent_forums) {
            $sql_array['SELECT'] .= ', f.parent_id, f.forum_parents, f.left_id, f.right_id';
        }
        /**
         * Event to modify the SQL query before the topics data is retrieved
         *
         * @event paybas.recenttopics.sql_pull_topics_data
         * @var    array    sql_array        The SQL array
         * @since 2.0.0
         */
        $vars = array('sql_array');
        extract($this->dispatcher->trigger_event('paybas.recenttopics.sql_pull_topics_data', compact($vars)));
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query_limit($sql, $topics_per_page);
        $rowset = $topic_icons = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            $rowset[] = $row;
        }
        $this->db->sql_freeresult($result);
        // No topics returned by the DB
        if (!sizeof($rowset)) {
            return;
        }
        /**
         * Event to modify the topics list data before we start the display loop
         *
         * @event paybas.recenttopics.modify_topics_list
         * @var    array    topic_list        Array of all the topic IDs
         * @var    array    rowset            The full topics list array
         * @since 2.0.1
         */
        $vars = array('topic_list', 'rowset');
        extract($this->dispatcher->trigger_event('paybas.recenttopics.modify_topics_list', compact($vars)));
        foreach ($rowset as $row) {
            $topic_id = $row['topic_id'];
            $forum_id = $row['forum_id'];
            $s_type_switch_test = $row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL ? 1 : 0;
            //$replies = ($this->auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
            $replies = $this->content_visibility->get_count('topic_posts', $row, $forum_id) - 1;
            if ($unread_only) {
                topic_status($row, $replies, true, $folder_img, $folder_alt, $topic_type);
                $unread_topic = true;
            } else {
                topic_status($row, $replies, isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']] ? true : false, $folder_img, $folder_alt, $topic_type);
                $unread_topic = isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']] ? true : false;
            }
            $view_topic_url = append_sid("{$this->root_path}viewtopic.{$this->phpEx}", 'f=' . $forum_id . '&amp;t=' . $topic_id);
            $view_forum_url = append_sid("{$this->root_path}viewforum.{$this->phpEx}", 'f=' . $forum_id);
            $topic_unapproved = $row['topic_visibility'] == ITEM_UNAPPROVED && $this->auth->acl_get('m_approve', $forum_id);
            $posts_unapproved = $row['topic_visibility'] == ITEM_APPROVED && $row['topic_posts_unapproved'] && $this->auth->acl_get('m_approve', $forum_id);
            $u_mcp_queue = $topic_unapproved || $posts_unapproved ? append_sid("{$this->root_path}mcp.{$this->phpEx}", 'i=queue&amp;mode=' . ($topic_unapproved ? 'approve_details' : 'unapproved_posts') . "&amp;t={$topic_id}", true, $this->user->session_id) : '';
            $s_type_switch = $row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL ? 1 : 0;
            if (!empty($icons[$row['icon_id']])) {
                $topic_icons[] = $topic_id;
            }
            // Get folder img, topic status/type related information
            $folder_img = $folder_alt = $topic_type = '';
            topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
            $tpl_ary = array('FORUM_ID' => $forum_id, 'TOPIC_ID' => $topic_id, 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'FIRST_POST_TIME' => $this->user->format_date($row['topic_time']), 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']), 'LAST_POST_TIME' => $this->user->format_date($row['topic_last_post_time']), 'LAST_VIEW_TIME' => $this->user->format_date($row['topic_last_view_time']), 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'REPLIES' => $replies, 'VIEWS' => $row['topic_views'], 'TOPIC_TITLE' => censor_text($row['topic_title']), 'FORUM_NAME' => $row['forum_name'], 'TOPIC_TYPE' => $topic_type, 'TOPIC_IMG_STYLE' => $folder_img, 'TOPIC_FOLDER_IMG' => $this->user->img($folder_img, $folder_alt), 'TOPIC_FOLDER_IMG_ALT' => $this->user->lang[$folder_alt], 'TOPIC_ICON_IMG' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['img'] : '', 'TOPIC_ICON_IMG_WIDTH' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['width'] : '', 'TOPIC_ICON_IMG_HEIGHT' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['height'] : '', 'ATTACH_ICON_IMG' => $this->auth->acl_get('u_download') && $this->auth->acl_get('f_download', $forum_id) && $row['topic_attachment'] ? $this->user->img('icon_topic_attach', $this->user->lang['TOTAL_ATTACHMENTS']) : '', 'UNAPPROVED_IMG' => $topic_unapproved || $posts_unapproved ? $this->user->img('icon_topic_unapproved', $topic_unapproved ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', 'REPORTED_IMG' => $row['topic_reported'] && $this->auth->acl_get('m_report', $forum_id) ? $this->user->img('icon_topic_reported', 'TOPIC_REPORTED') : '', 'S_HAS_POLL' => $row['poll_start'] ? true : false, 'S_TOPIC_TYPE' => $row['topic_type'], 'S_USER_POSTED' => isset($row['topic_posted']) && $row['topic_posted'] ? true : false, 'S_UNREAD_TOPIC' => $unread_topic, 'S_TOPIC_REPORTED' => $row['topic_reported'] && $this->auth->acl_get('m_report', $forum_id) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, 'S_POST_ANNOUNCE' => $row['topic_type'] == POST_ANNOUNCE ? true : false, 'S_POST_GLOBAL' => $row['topic_type'] == POST_GLOBAL ? true : false, 'S_POST_STICKY' => $row['topic_type'] == POST_STICKY ? true : false, 'S_TOPIC_LOCKED' => $row['topic_status'] == ITEM_LOCKED ? true : false, 'S_TOPIC_MOVED' => $row['topic_status'] == ITEM_MOVED ? true : false, 'S_TOPIC_TYPE_SWITCH' => $s_type_switch == $s_type_switch_test ? -1 : $s_type_switch_test, 'U_NEWEST_POST' => $view_topic_url . '&amp;view=unread#unread', 'U_LAST_POST' => $view_topic_url . '&amp;p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'], 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'U_VIEW_TOPIC' => $view_topic_url, 'U_VIEW_FORUM' => $view_forum_url, 'U_MCP_REPORT' => append_sid("{$this->root_path}mcp.{$this->phpEx}", 'i=reports&amp;mode=reports&amp;f=' . $forum_id . '&amp;t=' . $topic_id, true, $this->user->session_id), 'U_MCP_QUEUE' => $u_mcp_queue);
            /**
             * Modify the topic data before it is assigned to the template
             *
             * @event paybas.recenttopics.modify_tpl_ary
             * @var    array    row            Array with topic data
             * @var    array    tpl_ary        Template block array with topic data
             * @since 2.0.0
             */
            $vars = array('row', 'tpl_ary');
            extract($this->dispatcher->trigger_event('paybas.recenttopics.modify_tpl_ary', compact($vars)));
            $this->template->assign_block_vars($tpl_loopname, $tpl_ary);
            $this->pagination->generate_template_pagination($view_topic_url, $tpl_loopname . '.pagination', 'start', $replies + 1, $this->config['posts_per_page'], 1, true, true);
            if ($display_parent_forums) {
                $forum_parents = get_forum_parents($row);
                foreach ($forum_parents as $parent_id => $data) {
                    $this->template->assign_block_vars($tpl_loopname . '.parent_forums', array('FORUM_ID' => $parent_id, 'FORUM_NAME' => $data[0], 'U_VIEW_FORUM' => append_sid("{$this->root_path}viewforum.{$this->phpEx}", 'f=' . $parent_id)));
                }
            }
        }
        // Get URL-parameters for pagination
        $url_params = explode('&', $this->user->page['query_string']);
        $append_params = false;
        foreach ($url_params as $param) {
            if (!$param) {
                continue;
            }
            if (strpos($param, '=') === false) {
                // Fix MSSTI Advanced BBCode MOD
                $append_params[$param] = '1';
                continue;
            }
            list($name, $value) = explode('=', $param);
            if ($name != $tpl_loopname . '_start') {
                $append_params[$name] = $value;
            }
        }
        $pagination_url = append_sid($this->root_path . $this->user->page['page_name'], $append_params);
        $this->pagination->generate_template_pagination($pagination_url, 'rt_pagination', $tpl_loopname . '_start', $topics_count, $topics_per_page, $start);
        $this->template->assign_vars(array('RT_SORT_START_TIME' => $sort_topics === 'topic_time' ? true : false, 'S_TOPIC_ICONS' => sizeof($topic_icons) ? true : false, 'NEWEST_POST_IMG' => $this->user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'LAST_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'POLL_IMG' => $this->user->img('icon_topic_poll', 'TOPIC_POLL'), strtoupper($tpl_loopname) . '_DISPLAY' => true));
    }
 /**
  * Get number of topics that have unread posts. Returns a negative number to signal error.
  */
 protected function get_unread_topics_count($limit, $exist_unread)
 {
     if (!$this->config['load_db_lastread'] || !$this->user->data['is_registered'] || $this->user->data['is_bot']) {
         return -1;
     }
     $unread_topics_count = 0;
     if (is_null($exist_unread) || $exist_unread && $limit > 1) {
         $forum_ids = array_unique(array_keys($this->auth->acl_getf('f_read')));
         if (sizeof($forum_ids)) {
             $sql_where = ' AND ' . $this->content_visibility->get_forums_visibility_sql('topic', $forum_ids, $table_alias = 't.');
             $sql_sort = '';
             $unread_topics_count = sizeof(get_unread_topics($this->user->data['user_id'], $sql_where, $sql_sort, $limit));
         }
     } else {
         $unread_topics_count = $exist_unread ? 1 : 0;
     }
     return $unread_topics_count;
 }
	public function get_template_side($module_id)
	{
		global $config, $template, $user, $auth, $db, $phpEx, $phpbb_root_path;

		if (!function_exists('display_forums'))
		{
			include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
		}

		if ($user->data['is_registered'])
		{
			//
			// + new posts since last visit & you post number
			//
			$ex_fid_ary = array_unique(array_merge(array_keys($auth->acl_getf('!f_read', true)), array_keys($auth->acl_getf('!f_search', true))));

			if ($auth->acl_get('m_approve'))
			{
				$m_approve_fid_ary = array(-1);
				$m_approve_fid_sql = '';
			}
			else if ($auth->acl_getf_global('m_approve'))
			{
				$m_approve_fid_ary = array_diff(array_keys($auth->acl_getf('!m_approve', true)), $ex_fid_ary);
				$m_approve_fid_sql = ' AND (p.post_approved = 1' . ((sizeof($m_approve_fid_ary)) ? ' OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) : '') . ')';
			}
			else
			{
				$m_approve_fid_ary = array();
				$m_approve_fid_sql = ' AND p.post_approved = 1';
			}

			$sql = 'SELECT COUNT(distinct t.topic_id) as total
						FROM ' . TOPICS_TABLE . ' t
						WHERE t.topic_last_post_time > ' . $user->data['user_lastvisit'] . '
							AND t.topic_moved_id = 0
							' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . '
							' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '');
			$result = $db->sql_query($sql);
			$new_posts_count = (int) $db->sql_fetchfield('total');
			$db->sql_freeresult($result);

			// unread posts
			$sql_where = 'AND t.topic_moved_id = 0
							' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . '
							' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '');
			$unread_list = array();
			$unread_list = get_unread_topics($user->data['user_id'], $sql_where, 'ORDER BY t.topic_id DESC');
			$unread_posts_count = sizeof($unread_list);


			// Get user avatar and rank
			$user_id = $user->data['user_id'];
			$username = $user->data['username'];
			$colour = $user->data['user_colour'];
			$avatar_img = get_user_avatar($user->data['user_avatar'], $user->data['user_avatar_type'], $user->data['user_avatar_width'], $user->data['user_avatar_height']);
			$rank_title = $rank_img = '';
			get_user_rank($user->data['user_rank'], $user->data['user_posts'], $rank_title, $rank_img, $rank_img_src);

			// Assign specific vars
			$template->assign_vars(array(
				'L_NEW_POSTS'	=> $user->lang['SEARCH_NEW'] . '&nbsp;(' . $new_posts_count . ')',
				'L_SELF_POSTS'	=> $user->lang['SEARCH_SELF'] . '&nbsp;(' . $user->data['user_posts'] . ')',
				'L_UNREAD_POSTS'=> $user->lang['SEARCH_UNREAD'] . '&nbsp;(' . $unread_posts_count . ')',

				'B3P_AVATAR_IMG'    => $avatar_img,
				'B3P_RANK_TITLE'    => $rank_title,
				'B3P_RANK_IMG'        => $rank_img,
				'RANK_IMG_SRC'    => $rank_img_src,

				'USERNAME_FULL'        => get_username_string('full', $user_id, $username, $colour),
				'U_VIEW_PROFILE'	=> get_username_string('profile', $user_id, $username, $colour),

				'U_NEW_POSTS'			=> append_sid("{$phpbb_root_path}search.$phpEx", 'search_id=newposts'),
				'U_SELF_POSTS'			=> append_sid("{$phpbb_root_path}search.$phpEx", 'search_id=egosearch'),
				'U_UNREAD_POSTS'		=> append_sid("{$phpbb_root_path}search.$phpEx", 'search_id=unreadposts'),
				'U_UM_BOOKMARKS'		=> ($config['allow_bookmarks']) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=main&amp;mode=bookmarks') : '',
				'U_UM_MAIN_SUBSCRIBED'	=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=main&amp;mode=subscribed'),
				'U_UM_MCP'				=> ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=front', true, $user->session_id) : '',
				'S_DISPLAY_SUBSCRIPTIONS' => ($config['allow_topic_notify'] || $config['allow_forum_notify']) ? true : false,
			));

			return 'user_menu_side.html';
		}
		else
		{
			// Assign specific vars
			$template->assign_vars(array(
				'U_PORTAL'				=> append_sid("{$phpbb_root_path}portal.$phpEx"),
				'S_DISPLAY_FULL_LOGIN'	=> true,
				'S_AUTOLOGIN_ENABLED'	=> ($config['allow_autologin']) ? true : false,
				'S_LOGIN_ACTION'		=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'),
				'S_SHOW_REGISTER'	=> ($config['board3_user_menu_register_' . $module_id]) ? true : false,
			));

			return 'login_box_side.html';
		}
	}
/**
* This code is only processed for the portal page in order to allow displaying
* of categories, it is not required for normal phpbb pages as the data is
* available in the data pool (globally)...
*
* The function simply reuses phpbb code but will be updated when block code is rewrittten as classes
* Will use dependency injection later
*/
function display_forums_categories()
{
    // A rewrite for phpBB3 display_forums code drastically reduced to provide categories block with data //
    global $db, $auth, $user, $template;
    global $phpbb_root_path, $phpEx, $config;
    $default_icon = $phpbb_root_path . 'ext/phpbbireland/portal/images/forum_icons/default.png';
    $forum_rows = $subforums = $forum_ids = $active_forum_ary = array();
    // $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
    $parent_id = $visible_forums = 0;
    $sql_from = '';
    $root_data = array('forum_id' => 0);
    $sql_where = '';
    $sql_array = array('SELECT' => 'f.*', 'FROM' => array(FORUMS_TABLE => 'f'), 'LEFT_JOIN' => array());
    $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);
    $branch_root_id = $root_data['forum_id'];
    $cnt = 0;
    // 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'];
        // 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;
        }
        // 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_id_unapproved_topics'] = $auth->acl_get('m_approve', $forum_id) && $row['forum_topics_approved'] != $row['forum_topics_approved'] ? $forum_id : 0;
        //$row['forum_topics'] = ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics'];
        $row['forum_topics'] = $auth->acl_get('m_approve', $forum_id) ? $row['forum_topics_approved'] : $row['forum_topics_approved'];
        if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_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_approved'] += $row['forum_posts_approved'];
                }
            }
        }
    }
    $db->sql_freeresult($result);
    // 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_ID' => $cnt, '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_IMAGE_SRC' => $row['forum_image'] ? $row['forum_image'] : $default_icon, '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 ? 'UNREAD_POSTS' : 'NO_UNREAD_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 = '';
        }
        $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_approved'] : '';
        $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['UNREAD_POSTS'] : $user->lang['NO_UNREAD_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_ID' => $cnt, '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_AUTH_READ' => $auth->acl_get('f_read', $row['forum_id']), '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, 'FORUM_IMAGE_SRC' => $row['forum_image'] ? $row['forum_image'] : $default_icon, '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, 'SUBFORUMS' => $s_subforums_list, 'U_VIEWFORUM' => $u_viewforum));
        // 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;
        $cnt++;
        //echo $cnt . ' ';
    }
    /*
    	As this code only affects the portal page category block, the option
    	to display 'categories only' is somewhat restricted, that is, it won't
    	affect the block when viewed on other phpbb pages...
    
    	The switch below is hard-coded atm but can be added to acp later...
    */
    $template->assign_vars(array('S_DISPLAY_CATS_ONLY' => false));
}
Example #11
0
 // show_results should not change after this
 $per_page = $show_results == 'posts' ? $config['posts_per_page'] : $config['topics_per_page'];
 $total_match_count = 0;
 if ($search_id) {
     if ($sql) {
         // only return up to 1000 ids (the last one will be removed later)
         $result = $db->sql_query_limit($sql, 1001 - $start, $start);
         while ($row = $db->sql_fetchrow($result)) {
             $id_ary[] = (int) $row[$field];
         }
         $db->sql_freeresult($result);
         $total_match_count = sizeof($id_ary) + $start;
         $id_ary = array_slice($id_ary, 0, $per_page);
     } else {
         if ($search_id == 'unreadposts') {
             $id_ary = array_keys(get_unread_topics($user->data['user_id'], $sql_where, $sql_sort, 1001 - $start, $start));
             $total_match_count = sizeof($id_ary) + $start;
             $id_ary = array_slice($id_ary, 0, $per_page);
         } else {
             $search_id = '';
         }
     }
 }
 // make sure that some arrays are always in the same order
 sort($ex_fid_ary);
 sort($m_approve_fid_ary);
 sort($author_id_ary);
 if (!empty($search->search_query)) {
     $total_match_count = $search->keyword_search($show_results, $search_fields, $search_terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page);
 } else {
     if (sizeof($author_id_ary)) {
Example #12
0
/**
 * Retrieve a set of topics and trim the names if necessary
 *
 * @param array $forum_id_ary
 * @param int $num_topics
 * @param int $num_chars
 * @return multitype:
 */
function fetch_topics($forum_id_ary, $num_topics, $num_chars)
{
    global $db, $cache, $user, $config, $auth, $template, $phpbb_root_path, $phpEx;
    //No authed forums, or desired number of topics is zero or less
    if (!sizeof($forum_id_ary) || $num_topics < 1) {
        return array();
    }
    $sql_arr = array('SELECT' => 't.*, tp.topic_posted, f.forum_name, f.parent_id, f.forum_parents, f.left_id, f.right_id ', 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 't.topic_id = tp.topic_id AND tp.user_id = ' . $user->data['user_id']), array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id')), 'WHERE' => ' topic_type <> ' . POST_GLOBAL . ' AND ' . $db->sql_in_set('t.forum_id', $forum_id_ary), 'ORDER_BY' => 't.topic_last_post_time DESC');
    $sql = $db->sql_build_query('SELECT', $sql_arr);
    $result = $db->sql_query_limit($sql, $num_topics);
    $row = $db->sql_fetchrowset($result);
    $db->sql_freeresult($result);
    /**
     * Get list of unread topics
     * @return array[int][int]		Topic ids as keys, mark_time of topic as value
     */
    $unreadlist = \get_unread_topics($user_id = false, $sql_extra = '', $sql_sort = '', $sql_limit = 1001, $sql_limit_offset = 0);
    $topics = array();
    $i = 0;
    foreach ($row as $topic) {
        // FORUM LINK
        $view_forum_url = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $topic['forum_id']);
        $topic_moderation = false;
        $posts_moderation = false;
        $u_mcp_queue = '';
        //is this topic not approved and does poster have moderation permission ?
        if (!$topic['topic_approved']) {
            if ($auth->acl_get('m_approve', $topic['forum_id'])) {
                $topic_moderation = true;
            }
        } else {
            //if this topic is approved, are there replies yet unapproved ?
            if ($topic['topic_replies'] < $topic['topic_replies_real']) {
                if ($auth->acl_get('m_approve', $topic['forum_id'])) {
                    $posts_moderation = true;
                }
            }
        }
        // build the moderation queue url
        $u_mcp_queue = $topic_moderation || $posts_moderation ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue&amp;mode=' . ($topic_moderation ? 'approve_details' : 'unapproved_posts') . '&amp;t=' . $topic['topic_id'], true, $user->session_id) : '';
        //count the number of replies to the topic
        $replies = $auth->acl_get('m_approve', $topic['forum_id']) ? $topic['topic_replies_real'] : $topic['topic_replies'];
        //build the folder names
        $folder = $folder_new = '';
        if ($topic['topic_status'] == ITEM_MOVED) {
            $topic_type = $user->lang['VIEW_TOPIC_MOVED'];
            $folder_img = 'topic_moved';
            $folder_alt = 'TOPIC_MOVED';
        } else {
            switch ($topic['topic_type']) {
                case POST_GLOBAL:
                    $topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
                    $folder = 'global_read';
                    $folder_new = 'global_unread';
                    break;
                case POST_ANNOUNCE:
                    $topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT'];
                    $folder = 'announce_read';
                    $folder_new = 'announce_unread';
                    break;
                case POST_STICKY:
                    $topic_type = $user->lang['VIEW_TOPIC_STICKY'];
                    $folder = 'sticky_read';
                    $folder_new = 'sticky_unread';
                    break;
                default:
                    $topic_type = '';
                    $folder = 'topic_read';
                    $folder_new = 'topic_unread';
                    // Hot topic threshold is for posts in a topic, which is replies + the first post. ;)
                    if ($config['hot_threshold'] && $replies + 1 >= $config['hot_threshold'] && $topic['topic_status'] != ITEM_LOCKED) {
                        $folder .= '_hot';
                        $folder_new .= '_hot';
                    }
                    break;
            }
            if ($topic['topic_status'] == ITEM_LOCKED) {
                $topic_type = $user->lang['VIEW_TOPIC_LOCKED'];
                $folder .= '_locked';
                $folder_new .= '_locked';
            }
            if (array_key_exists($topic['topic_id'], $unreadlist)) {
                $folder_img = $folder_new;
                $folder_alt = 'UNREAD_POSTS';
                $topic['unread'] = true;
            } else {
                $topic['unread'] = false;
                $folder_img = $folder;
                $folder_alt = $topic['topic_status'] == ITEM_LOCKED ? 'TOPIC_LOCKED' : 'NO_UNREAD_POSTS';
            }
            // Posted image?
            if (!empty($topic['topic_posted']) && $topic['topic_posted']) {
                $folder_img .= '_mine';
            }
        }
        if ($topic['poll_start'] && $topic['topic_status'] != ITEM_MOVED) {
            $topic_type = $user->lang['VIEW_TOPIC_POLL'];
        }
        // Trim the topic title and add ellipse
        if ($num_chars != 0 and strlen($topic['topic_title']) > $num_chars) {
            $topic['topic_title'] = substr($topic['topic_title'], 0, $num_chars) . '...';
        }
        $icons = array();
        if ($topic['icon_id'] && $auth->acl_get('f_icons', $topic['forum_id'])) {
            $icons = $cache->obtain_icons();
        }
        $attachmenticon = '';
        //can user download ?
        if ($auth->acl_get('u_download') && $auth->acl_get('f_download', $topic['forum_id'])) {
            //does post have attachments ?
            if ($topic['topic_attachment']) {
                $attachmenticon = $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']);
            }
        }
        $topics[$i]['topic_first_poster_colour'] = $topic['topic_first_poster_colour'];
        $topics[$i]['topic_first_poster_name'] = $topic['topic_first_poster_name'];
        $topics[$i]['topic_poster'] = $topic['topic_poster'];
        $topics[$i]['forum_id'] = $topic['forum_id'];
        $topics[$i]['post_id'] = $topic['topic_last_post_id'];
        $topics[$i]['post_unread'] = $topic['unread'];
        $topics[$i]['topic_id'] = $topic['topic_id'];
        $topics[$i]['topic_folder_img'] = $user->img($folder_img, $folder_alt);
        $topics[$i]['topic_folder_img_src'] = $user->img($folder_img, $folder_alt, false, '', 'src');
        $topics[$i]['topic_folder_img_alt'] = $user->lang[$folder_alt];
        $topics[$i]['topic_img'] = !empty($icons[$topic['icon_id']]) ? $icons[$topic['icon_id']]['img'] : '';
        $topics[$i]['topic_img_width'] = !empty($icons[$topic['icon_id']]) ? $icons[$topic['icon_id']]['width'] : '';
        $topics[$i]['topic_img_heigth'] = !empty($icons[$topic['icon_id']]) ? $icons[$topic['icon_id']]['height'] : '';
        $topics[$i]['topic_title'] = $topic['topic_title'];
        $topics[$i]['topic_last_post_id'] = $topic['topic_last_post_id'];
        $topics[$i]['topic_last_post_time'] = $user->format_date($topic['topic_last_post_time']);
        $topics[$i]['user_link'] = get_username_string('full', $topic['topic_last_poster_id'], $topic['topic_last_poster_name'], $topic['topic_last_poster_colour']);
        $topics[$i]['topic_unapproved'] = $topic_moderation;
        $topics[$i]['posts_unapproved'] = $posts_moderation;
        $topics[$i]['topic_reported'] = $topic['topic_reported'] && $auth->acl_get('m_report', $topic['forum_id']) ? true : false;
        $topics[$i]['unapproved_img'] = $topic_moderation || $posts_moderation ? $user->img('icon_topic_unapproved', $topic_moderation ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '';
        $topics[$i]['u_mcp_report'] = append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=reports&amp;mode=reports&amp;f=' . $topic['forum_id'] . '&amp;t=' . $topic['topic_id'], true, $user->session_id);
        $topics[$i]['u_mcp_queue'] = $u_mcp_queue;
        $topics[$i]['reported_img'] = $topic['topic_reported'] && $auth->acl_get('m_report', $topic['forum_id']) ? $user->img('icon_topic_reported', 'TOPIC_REPORTED') : '';
        $topics[$i]['view_forum_url'] = $view_forum_url;
        $topics[$i]['forum_name'] = $topic['forum_name'];
        $topics[$i]['attach_icon'] = $attachmenticon;
        $topics[$i]['forum_parents'] = \get_forum_parents($topic);
        $i++;
    }
    if (!empty($icons[$topic['icon_id']])) {
        $template->assign_vars(array('S_TOPIC_ICONS' => true));
    }
    return $topics;
}