function get_subscribed_forum_func()
{
    global $config, $db, $user, $auth, $mobiquo_config, $phpbb_home;
    $user->setup('ucp');
    if (!$user->data['is_registered']) {
        trigger_error('LOGIN_EXPLAIN_UCP');
    }
    $forum_list = array();
    if ($config['allow_forum_notify']) {
        $forbidden_forums = $auth->acl_getf('!f_read', true);
        $forbidden_forums = array_unique(array_keys($forbidden_forums));
        if (isset($mobiquo_config['hide_forum_id'])) {
            $forbidden_forums = array_unique(array_merge($forbidden_forums, $mobiquo_config['hide_forum_id']));
        }
        $sql_array = array('SELECT' => 'f.*', 'FROM' => array(FORUMS_WATCH_TABLE => 'fw', FORUMS_TABLE => 'f'), 'WHERE' => 'fw.user_id = ' . $user->data['user_id'] . '
                AND f.forum_id = fw.forum_id
                AND ' . $db->sql_in_set('f.forum_id', $forbidden_forums, true, true), 'ORDER_BY' => 'left_id');
        if ($config['load_db_lastread']) {
            $sql_array['LEFT_JOIN'] = array(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 {
            $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();
        }
        $sql = $db->sql_build_query('SELECT', $sql_array);
        $result = $db->sql_query($sql);
        $forum_list = array();
        while ($row = $db->sql_fetchrow($result)) {
            $forum_id = $row['forum_id'];
            if ($config['load_db_lastread']) {
                $forum_check = !empty($row['mark_time']) ? $row['mark_time'] : $user->data['user_lastmark'];
            } else {
                $forum_check = isset($tracking_topics['f'][$forum_id]) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
            }
            $unread_forum = $row['forum_last_post_time'] > $forum_check ? true : false;
            $logo_url = '';
            if (file_exists("./forum_icons/{$forum_id}.png")) {
                $logo_url = $phpbb_home . $config['tapatalkdir'] . "/forum_icons/{$forum_id}.png";
            } else {
                if (file_exists("./forum_icons/{$forum_id}.jpg")) {
                    $logo_url = $phpbb_home . $config['tapatalkdir'] . "/forum_icons/{$forum_id}.jpg";
                } else {
                    if (file_exists("./forum_icons/default.png")) {
                        $logo_url = $phpbb_home . $config['tapatalkdir'] . "/forum_icons/default.png";
                    } else {
                        if ($row['forum_image']) {
                            $logo_url = $phpbb_home . $row['forum_image'];
                        }
                    }
                }
            }
            $xmlrpc_forum = new xmlrpcval(array('forum_id' => new xmlrpcval($forum_id), 'forum_name' => new xmlrpcval(html_entity_decode($row['forum_name']), 'base64'), 'icon_url' => new xmlrpcval($logo_url), 'is_protected' => new xmlrpcval($row['forum_password'] ? true : false, 'boolean'), 'sub_only' => new xmlrpcval($row['forum_type'] == FORUM_POST ? false : true, 'boolean'), 'new_post' => new xmlrpcval($unread_forum, 'boolean')), 'struct');
            $forum_list[] = $xmlrpc_forum;
        }
        $db->sql_freeresult($result);
    }
    $forum_num = count($forum_list);
    $response = new xmlrpcval(array('total_forums_num' => new xmlrpcval($forum_num, 'int'), 'forums' => new xmlrpcval($forum_list, 'array')), 'struct');
    return new xmlrpcresp($response);
}
예제 #2
0
				}

				if ($config['load_db_lastread'])
				{
					$sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.user_id = ' . $user->data['user_id'] . '
							AND t.topic_id = tt.topic_id)
						LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . '
							AND ft.forum_id = f.forum_id)';
					$sql_select .= ', tt.mark_time, ft.mark_time as f_mark_time';
				}
			}

			if ($config['load_anon_lastread'] || ($user->data['is_registered'] && !$config['load_db_lastread']))
			{
				$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();
			}

			$sql = "SELECT $sql_select
				FROM $sql_from
				WHERE $sql_where";
		}
		$sql .= ' ORDER BY ' . $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
		$result = $db->sql_query($sql);
		$result_topic_id = 0;

		$rowset = array();

		if ($show_results == 'topics')
		{
			$forums = $rowset = $shadow_topic_list = array();
예제 #3
0
/**
* 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());
}
예제 #4
0
/**
* get topic tracking info for news
* based on get_complete_tracking_info of phpBB3
* this should reduce the queries for the news and announcements block
*/
function get_portal_tracking_info($fetch_news)
{
    global $config, $request, $user;
    $last_read = $topic_ids = $forum_ids = $tracking_info = $rev_forum_ids = $user_lastmark = array();
    /**
     * group everything by the forum IDs
     */
    $count = $fetch_news['topic_count'];
    for ($i = 0; $i < $count; ++$i) {
        $tracking_info[$fetch_news[$i]['forum_id']][] = $fetch_news[$i]['topic_id'];
        $topic_ids[] = $fetch_news[$i]['topic_id'];
        $forum_ids[] = $fetch_news[$i]['forum_id'];
        $rev_forum_ids[$fetch_news[$i]['topic_id']] = $fetch_news[$i]['forum_id'];
        // the other way round also helps
    }
    foreach ($tracking_info as $forum_id => $current_forum) {
        if ($config['load_db_lastread'] && $user->data['is_registered']) {
            global $db;
            $mark_time = array();
            $sql = 'SELECT topic_id, mark_time
				FROM ' . TOPICS_TRACK_TABLE . '
				WHERE user_id =  ' . (int) $user->data['user_id'] . '
					AND ' . $db->sql_in_set('topic_id', $current_forum);
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                $last_read[$row['topic_id']] = $row['mark_time'];
            }
            $db->sql_freeresult($result);
            $current_forum = array_diff($current_forum, array_keys($last_read));
            if (sizeof($topic_ids)) {
                $sql = 'SELECT forum_id, mark_time
					FROM ' . FORUMS_TRACK_TABLE . '
					WHERE user_id =  ' . (int) $user->data['user_id'] . '
						AND ' . $db->sql_in_set('forum_id', $forum_ids);
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $mark_time[$row['forum_id']] = $row['mark_time'];
                }
                $db->sql_freeresult($result);
                // Set user last mark time
                foreach ($forum_ids as $current_forum_id) {
                    $user_lastmark[$current_forum_id] = isset($mark_time[$current_forum_id]) ? $mark_time[$current_forum_id] : $user->data['user_lastmark'];
                }
                // @todo: also check if $user_lastmark has been defined for this specific forum_id
                foreach ($topic_ids as $topic_id) {
                    if (!isset($last_read[$topic_id]) || isset($user_lastmark[$rev_forum_ids[$topic_id]]) && $user_lastmark[$rev_forum_ids[$topic_id]] > $last_read[$topic_id]) {
                        $last_read[$topic_id] = $user_lastmark[$rev_forum_ids[$topic_id]];
                    }
                }
            }
        } else {
            if ($config['load_anon_lastread'] || $user->data['is_registered']) {
                global $tracking_topics;
                if (!isset($tracking_topics) || !sizeof($tracking_topics)) {
                    if ($request->is_set($config['cookie_name'] . '_track', \phpbb\request\request_interface::COOKIE)) {
                        $tracking_topics = $request->variable($config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE);
                    } else {
                        $tracking_topics = '';
                    }
                    $tracking_topics = $tracking_topics ? tracking_unserialize($tracking_topics) : array();
                }
                if (!$user->data['is_registered']) {
                    $user_lastmark = isset($tracking_topics['l']) ? base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate'] : 0;
                } else {
                    $user_lastmark = $user->data['user_lastmark'];
                }
                foreach ($topic_ids as $topic_id) {
                    $topic_id36 = base_convert($topic_id, 10, 36);
                    if (isset($tracking_topics['t'][$topic_id36])) {
                        $last_read[$topic_id] = base_convert($tracking_topics['t'][$topic_id36], 36, 10) + $config['board_startdate'];
                    }
                }
                $topic_ids = array_diff($topic_ids, array_keys($last_read));
                if (sizeof($topic_ids)) {
                    $mark_time = array();
                    if (isset($tracking_topics['f'][$forum_id])) {
                        $mark_time[$forum_id] = base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate'];
                    }
                    $user_lastmark = isset($mark_time[$forum_id]) ? $mark_time[$forum_id] : $user_lastmark;
                    foreach ($topic_ids as $topic_id) {
                        $last_read[$topic_id] = $user_lastmark;
                    }
                }
            }
        }
    }
    return $last_read;
}
예제 #5
0
    function display_posts(&$master)
    {
        global $user, $template, $config, $phpEx, $db, $auth, $phpbb_root_path, $cache;
        static $bbcode;
        static $display_orders = array('first' => 't.topic_id', 'last' => 't.topic_last_post_time');
        global $phpbb_seo;
        // Usefull for multi bb topic & forum tracking
        // Leave default for single forum eg : '_track'
        $tracking_cookie_name = (defined('XLANG_AKEY') ? XLANG_AKEY : '') . '_track';
        $forum_read_auth =& $master->actions['auth_view_read'];
        // Specific options
        $display_file =& $master->call['display_file'];
        $display_user_info =& $master->call['display_user_info'];
        $display_user_link = !empty($master->call['display_user_link']) ? true : false;
        $display_user_link_key = $display_user_link ? 'full' : 'no_profile';
        $display_link =& $master->call['display_link'];
        $display_pagination =& $master->call['display_pagination'];
        $display_tracking =& $master->call['display_tracking'];
        $display_sig = !empty($master->call['display_sig']) ? (bool) ($config['allow_sig'] && $user->optionget('viewsigs')) : false;
        $display_order = isset($display_orders[$master->call['display_order']]) ? $display_orders[$master->call['display_order']] : $display_orders['first'];
        $display_post_buttons =& $master->call['display_post_buttons'];
        $display_sumarize =& $master->call['display_sumarize'];
        $limit_time_sql = !empty($master->call['limit_time']) ? ' AND t.topic_last_post_time > ' . ($user->time_now - $master->call['limit_time']) : '';
        $order_sql = @$master->call['sort'] == 'ASC' ? ' ASC' : ' DESC';
        if (!$display_tracking) {
            $load_db_lastread = $load_anon_lastread = false;
        } else {
            $load_db_lastread = (bool) ($config['load_db_lastread'] && $user->data['is_registered']);
            $load_anon_lastread = (bool) ($config['load_anon_lastread'] || $user->data['is_registered']);
        }
        // hanlde options
        $limit = $master->call['limit'] >= 1 ? (int) $master->call['limit'] : 5;
        $start =& $master->start;
        if (!$display_pagination || empty($display_file)) {
            $start = 0;
            $display_pagination = false;
        }
        $total_topics = 0;
        $topic_sql = $master->call['topic_sql'];
        $forum_sql = $master->call['forum_sql'];
        $s_global = $master->call['s_global'];
        $bbcode_bitfield = '';
        // Do some reset
        $topic_datas = $topic_ids = $forum_ids = $user_cache = $id_cache = $post_datas = $forum_datas = array();
        $forum_id = $master->call['forum_id'];
        $now = getdate(time() + $user->timezone + $user->dst - date('Z'));
        // Get The Data, first forums
        if (!$s_global && !$master->call['single_forum'] || $master->call['single_forum'] && empty($master->forum_datas[$master->call['forum_id']])) {
            $sql_array = array('SELECT' => 'f.*', 'FROM' => array(FORUMS_TABLE => 'f'), 'LEFT_JOIN' => array());
            if ($load_db_lastread) {
                $sql_array['SELECT'] .= ', ft.mark_time as forum_mark_time';
                $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['WHERE'] = $forum_sql ? str_replace('t.forum_id', 'f.forum_id', $forum_sql) : '';
            $sql = $db->sql_build_query('SELECT', $sql_array);
            unset($sql_array);
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                $forum_id = (int) $row['forum_id'];
                $forum_datas[$forum_id] = $row;
            }
            $db->sql_freeresult($result);
        }
        // Now the topics
        $sql_array = array('SELECT' => 't.*', 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array());
        if ($load_db_lastread) {
            $sql_array['SELECT'] .= ', tt.mark_time';
            $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.user_id = ' . $user->data['user_id'] . ' AND tt.topic_id = t.topic_id');
        } elseif ($load_anon_lastread && empty($master->tracking_topics)) {
            $master->tracking_topics = isset($_COOKIE[$config['cookie_name'] . $tracking_cookie_name]) ? STRIP ? stripslashes($_COOKIE[$config['cookie_name'] . $tracking_cookie_name]) : $_COOKIE[$config['cookie_name'] . $tracking_cookie_name] : '';
            $master->tracking_topics = $master->tracking_topics ? tracking_unserialize($master->tracking_topics) : array();
            if (!$user->data['is_registered']) {
                $user->data['user_lastmark'] = isset($master->tracking_topics['l']) ? (int) (base_convert($master->tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
            }
        }
        $sql_where = ($forum_sql ? $forum_sql : '') . $limit_time_sql;
        $sql_where .= $topic_sql ? ($sql_where ? ' AND ' : '') . $topic_sql : '';
        $sql_where .= ($sql_where ? ' AND ' : '') . 't.topic_status <> ' . ITEM_MOVED;
        if ($master->call['single_forum']) {
            $sql_where .= $auth->acl_get('m_approve', $master->call['forum_id']) ? '' : ' AND t.topic_approved = 1';
        } else {
            // only admins and global moderators will see un-approved topics
            // in the forum they have access to.
            $sql_where .= $auth->acl_gets('a_') || $auth->acl_getf_global('m_') ? '' : ' AND t.topic_approved = 1';
        }
        // obtain correct topic count if we display pagination
        if ($display_pagination) {
            $sql = "SELECT COUNT(t.topic_id) AS num_topics\n\t\t\t\tFROM " . TOPICS_TABLE . " t\n\t\t\t\tWHERE {$sql_where}";
            $result = $db->sql_query($sql);
            $total_topics = (int) $db->sql_fetchfield('num_topics');
            $db->sql_freeresult($result);
            // Make sure $start is set to the last page if it exceeds the amount
            if ($start < 0 || $start > $total_topics) {
                $start = $start < 0 ? 0 : floor(($total_topics - 1) / $limit) * $limit;
                // Since we've reached here, $start is not set proper, kill the dupe!
                $url = $display_file . $master->gym_master->html_add_start($start);
                $master->gym_master->seo_kill_dupes($url);
            }
        }
        $sql_array['WHERE'] = $sql_where;
        $sql_array['ORDER_BY'] = $display_order . $order_sql;
        $sql = $db->sql_build_query('SELECT', $sql_array);
        unset($sql_array);
        $result = $db->sql_query_limit($sql, $limit, $start);
        // First we parse the basic data
        while ($row = $db->sql_fetchrow($result)) {
            $forum_id = (int) $row['forum_id'];
            $topic_id = (int) $row['topic_id'];
            // Start with the forum
            if (!$s_global && empty($master->forum_datas[$forum_id])) {
                // www.phpBB-SEO.com SEO TOOLKIT BEGIN
                $phpbb_seo->set_url($forum_datas[$forum_id]['forum_name'], $forum_id, $phpbb_seo->seo_static['forum']);
                // www.phpBB-SEO.com SEO TOOLKIT END
                $master->forum_datas[$forum_id] = array_merge($forum_datas[$forum_id], array('forum_url' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", "f={$forum_id}"), 'm_approve' => $auth->acl_get('m_approve', $forum_id)));
                if ($load_db_lastread) {
                    $master->forum_tracking_info[$forum_id] = !empty($forum_datas[$forum_id]['forum_mark_time']) ? $forum_datas[$forum_id]['forum_mark_time'] : $user->data['user_lastmark'];
                } elseif ($load_anon_lastread) {
                    $master->forum_tracking_info[$forum_id] = isset($master->tracking_topics['f'][$forum_id]) ? (int) (base_convert($master->tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
                }
            }
            if (empty($master->forum_tracking_info[$forum_id])) {
                if ($load_db_lastread) {
                    $master->topic_tracking_info[$topic_id] = !empty($row['mark_time']) ? $row['mark_time'] : $user->data['user_lastmark'];
                } else {
                    if ($load_anon_lastread) {
                        $topic_id36 = base_convert($topic_id, 10, 36);
                        if (isset($master->tracking_topics['t'][$topic_id36])) {
                            $master->tracking_topics['t'][$topic_id] = base_convert($master->tracking_topics['t'][$topic_id36], 36, 10) + $config['board_startdate'];
                        }
                        $master->topic_tracking_info[$topic_id] = isset($master->tracking_topics['t'][$topic_id]) ? $master->tracking_topics['t'][$topic_id] : $user->data['user_lastmark'];
                    }
                }
            } else {
                $master->topic_tracking_info[$topic_id] = $master->forum_tracking_info[$forum_id];
            }
            // Topic post count
            $row['replies'] = !empty($master->forum_datas[$forum_id]['m_approve']) ? $row['topic_replies_real'] : $row['topic_replies'];
            $row['enable_icons'] = !empty($master->forum_datas[$forum_id]['enable_icons']);
            // www.phpBB-SEO.com SEO TOOLKIT BEGIN
            $phpbb_seo->prepare_iurl($row, 'topic', $row['topic_type'] == POST_GLOBAL ? $phpbb_seo->seo_static['global_announce'] : $phpbb_seo->seo_url['forum'][$forum_id]);
            // www.phpBB-SEO.com SEO TOOLKIT END
            $topic_datas[$forum_id][$topic_id] = $row;
            // @TODO deal with last post case ?
            $topic_ids[$topic_id] = $row['topic_first_post_id'];
            $forum_ids[$topic_id] = $forum_id;
        }
        $db->sql_freeresult($result);
        unset($forum_datas);
        // Let's go
        $has_result = false;
        if (!empty($topic_datas)) {
            $has_result = true;
            $bbcode_filter = false;
            if (!class_exists('bbcode')) {
                global $phpbb_root_path, $phpEx;
                include_once $phpbb_root_path . 'includes/bbcode.' . $phpEx;
            }
            $patterns = $replaces = array();
            if (!empty($master->module_config['html_msg_filters']['pattern'])) {
                $patterns = $master->module_config['html_msg_filters']['pattern'];
                $replaces = $master->module_config['html_msg_filters']['replace'];
                $bbcode_filter = true;
            }
            // Grab ranks
            $ranks = $cache->obtain_ranks();
            // Grab icons
            if (empty($master->icons)) {
                $master->icons = $cache->obtain_icons();
            }
            // Go ahead and pull all data for these topics
            $sql_array = array();
            $sql_array['SELECT'] = $sql_array['WHERE'] = '';
            if ($display_user_info) {
                $sql_array['SELECT'] = 'u.*, z.friend, z.foe, ';
                $sql_array['FROM'] = array(USERS_TABLE => 'u');
                $sql_array['LEFT_JOIN'] = array(array('FROM' => array(ZEBRA_TABLE => 'z'), 'ON' => 'z.user_id = ' . $user->data['user_id'] . ' AND z.zebra_id = p.poster_id'));
                $sql_array['WHERE'] = 'AND u.user_id = p.poster_id';
            }
            $sql_array['SELECT'] .= 'p.*';
            $sql_array['FROM'][POSTS_TABLE] = 'p';
            $sql_array['WHERE'] = $db->sql_in_set('p.post_id', $topic_ids) . $sql_array['WHERE'];
            $sql = $db->sql_build_query('SELECT', $sql_array);
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                $forum_id = (int) $row['forum_id'];
                $topic_id = (int) $row['topic_id'];
                // Define the global bbcode bitfield, will be used to load bbcodes
                $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
                // Only compute profile data if required
                if ($display_user_info) {
                    // www.phpBB-SEO.com SEO TOOLKIT BEGIN
                    $phpbb_seo->set_user_url($row['username'], $row['poster_id']);
                    // www.phpBB-SEO.com SEO TOOLKIT END
                    // Is a signature attached? Are we going to display it?
                    if ($display_sig && $row['enable_sig']) {
                        $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['user_sig_bbcode_bitfield']);
                    }
                } else {
                    // @TODO deal with last post case ?
                    $row['user_id'] = $row['poster_id'];
                    $row['username'] = $topic_datas[$forum_id][$topic_id]['topic_first_poster_name'];
                    $row['user_colour'] = $topic_datas[$forum_id][$topic_id]['topic_first_poster_colour'];
                }
                $poster_id = (int) $row['poster_id'];
                $post_datas[$forum_id][$topic_id] = array('hide_post' => false, 'post_id' => $row['post_id'], 'post_time' => $row['post_time'], 'user_id' => $row['user_id'], 'username' => $row['username'], 'user_colour' => $row['user_colour'], 'topic_id' => $row['topic_id'], 'forum_id' => $row['forum_id'], 'post_subject' => $row['post_subject'], 'post_edit_count' => $row['post_edit_count'], 'post_edit_time' => $row['post_edit_time'], 'post_edit_reason' => $row['post_edit_reason'], 'post_edit_user' => $row['post_edit_user'], 'icon_id' => isset($master->icons[$row['icon_id']]['img'], $master->icons[$row['icon_id']]['height'], $master->icons[$row['icon_id']]['width']) ? $row['icon_id'] : 0, 'post_attachment' => $row['post_attachment'], 'post_approved' => $row['post_approved'], 'post_reported' => $row['post_reported'], 'post_username' => $row['post_username'], 'post_text' => $row['post_text'], 'bbcode_uid' => $row['bbcode_uid'], 'bbcode_bitfield' => $row['bbcode_bitfield'], 'enable_smilies' => $row['enable_smilies'], 'enable_sig' => $row['enable_sig'], 'friend' => false, 'foe' => false);
                // Cache various user specific data ... so we don't have to recompute
                // this each time the same user appears on this page
                if (!isset($user_cache[$poster_id])) {
                    if ($poster_id == ANONYMOUS || !$display_user_info) {
                        $user_cache[$poster_id] = array('joined' => '', 'posts' => '', 'from' => '', 'sig' => '', 'sig_bbcode_uid' => '', 'sig_bbcode_bitfield' => '', 'online' => false, 'avatar' => '', 'rank_title' => '', 'rank_image' => '', 'rank_image_src' => '', 'profile' => '', 'pm' => '', 'email' => '', 'www' => '', 'icq_status_img' => '', 'icq' => '', 'aim' => '', 'msn' => '', 'yim' => '', 'jabber' => '', 'search' => '', 'age' => '', 'username' => $row['username'], 'user_colour' => $row['user_colour'], 'warnings' => 0, 'allow_pm' => 0);
                    } else {
                        $user_sig = '';
                        // We add the signature to every posters entry because enable_sig is post dependant
                        if ($display_sig && $row['user_sig']) {
                            $user_sig = $row['user_sig'];
                        }
                        $id_cache[] = $poster_id;
                        $user_cache[$poster_id] = array('joined' => $user->format_date($row['user_regdate']), 'posts' => $row['user_posts'], 'warnings' => isset($row['user_warnings']) ? $row['user_warnings'] : 0, 'from' => !empty($row['user_from']) ? $row['user_from'] : '', 'sig' => $user_sig, 'sig_bbcode_uid' => !empty($row['user_sig_bbcode_uid']) ? $row['user_sig_bbcode_uid'] : '', 'sig_bbcode_bitfield' => !empty($row['user_sig_bbcode_bitfield']) ? $row['user_sig_bbcode_bitfield'] : '', 'viewonline' => $row['user_allow_viewonline'], 'allow_pm' => $row['user_allow_pm'], 'avatar' => $user->optionget('viewavatars') ? $master->gym_master->get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'], $row['user_avatar_height']) : '', 'age' => '', 'rank_title' => '', 'rank_image' => '', 'rank_image_src' => '', 'username' => $row['username'], 'user_colour' => $row['user_colour'], 'online' => false, 'profile' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", "mode=viewprofile&amp;u={$poster_id}"), 'www' => $row['user_website'], 'aim' => $row['user_aim'] && $auth->acl_get('u_sendim') ? append_sid("{$phpbb_root_path}memberlist.{$phpEx}", "mode=contact&amp;action=aim&amp;u={$poster_id}") : '', 'msn' => $row['user_msnm'] && $auth->acl_get('u_sendim') ? append_sid("{$phpbb_root_path}memberlist.{$phpEx}", "mode=contact&amp;action=msnm&amp;u={$poster_id}") : '', 'yim' => $row['user_yim'] ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($row['user_yim']) . '&amp;.src=pg' : '', 'jabber' => $row['user_jabber'] && $auth->acl_get('u_sendim') ? append_sid("{$phpbb_root_path}memberlist.{$phpEx}", "mode=contact&amp;action=jabber&amp;u={$poster_id}") : '', 'search' => $auth->acl_get('u_search') ? append_sid("{$phpbb_root_path}search.{$phpEx}", "author_id={$poster_id}&amp;sr=posts") : '');
                        $master->gym_master->get_user_rank($row['user_rank'], $row['user_posts'], $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']);
                        if (!empty($row['user_allow_viewemail']) || $auth->acl_get('a_email')) {
                            $user_cache[$poster_id]['email'] = $config['board_email_form'] && $config['email_enable'] ? append_sid("{$phpbb_root_path}memberlist.{$phpEx}", "mode=email&amp;u={$poster_id}") : ($config['board_hide_emails'] && !$auth->acl_get('a_email') ? '' : 'mailto:' . $row['user_email']);
                        } else {
                            $user_cache[$poster_id]['email'] = '';
                        }
                        if (!empty($row['user_icq'])) {
                            $user_cache[$poster_id]['icq'] = 'http://www.icq.com/people/webmsg.php?to=' . $row['user_icq'];
                            $user_cache[$poster_id]['icq_status_img'] = '<img src="http://web.icq.com/whitepages/online?icq=' . $row['user_icq'] . '&amp;img=5" width="18" height="18" alt="" />';
                        } else {
                            $user_cache[$poster_id]['icq_status_img'] = '';
                            $user_cache[$poster_id]['icq'] = '';
                        }
                        if ($config['allow_birthdays'] && !empty($row['user_birthday'])) {
                            list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $row['user_birthday']));
                            if ($bday_year) {
                                $diff = $now['mon'] - $bday_month;
                                if ($diff == 0) {
                                    $diff = $now['mday'] - $bday_day < 0 ? 1 : 0;
                                } else {
                                    $diff = $diff < 0 ? 1 : 0;
                                }
                                $user_cache[$poster_id]['age'] = (int) ($now['year'] - $bday_year - $diff);
                            }
                        }
                    }
                    $user_cache[$poster_id]['post_author_full'] = get_username_string($display_user_link_key, $poster_id, $row['username'], $row['user_colour'], $row['post_username']);
                    $user_cache[$poster_id]['post_author_colour'] = get_username_string('colour', $poster_id, $row['username'], $row['user_colour'], $row['post_username']);
                    $user_cache[$poster_id]['post_author'] = get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username']);
                    $user_cache[$poster_id]['u_post_author'] = $display_user_link ? get_username_string('profile', $poster_id, $row['username'], $row['user_colour'], $row['post_username']) : '';
                }
            }
            $db->sql_freeresult($result);
            // Load custom profile fields
            if ($display_user_info && $config['load_cpf_viewtopic']) {
                include $phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx;
                $cp = new custom_profile();
                // Grab all profile fields from users in id cache for later use - similar to the poster cache
                $profile_fields_cache = $cp->generate_profile_fields_template('grab', $id_cache);
            }
            // Generate online information for user
            if (@$master->call['display_online'] && sizeof($id_cache)) {
                $sql = 'SELECT session_user_id, MAX(session_time) as online_time, MIN(session_viewonline) AS viewonline
					FROM ' . SESSIONS_TABLE . '
					WHERE ' . $db->sql_in_set('session_user_id', $id_cache) . '
					GROUP BY session_user_id';
                $result = $db->sql_query($sql);
                $update_time = $config['load_online_time'] * 60;
                while ($row = $db->sql_fetchrow($result)) {
                    $user_cache[$row['session_user_id']]['online'] = time() - $update_time < $row['online_time'] && ($row['viewonline'] || $auth->acl_get('u_viewonline')) ? true : false;
                }
                $db->sql_freeresult($result);
            }
            unset($id_cache);
            // Instantiate BBCode
            if (empty($bbcode)) {
                $bbcode = new bbcode(base64_encode($bbcode_bitfield));
            } else {
                $bbcode->bbcode(base64_encode($bbcode_bitfield));
            }
            $prev_post_id = '';
            // Parse messages
            foreach ($forum_ids as $topic_id => $forum_id) {
                if (!isset($post_datas[$forum_id][$topic_id])) {
                    continue;
                }
                $row =& $post_datas[$forum_id][$topic_id];
                $topic_data =& $topic_datas[$forum_id][$topic_id];
                $poster_id = (int) $row['user_id'];
                $l_edited_by = $l_bumped_by = '';
                $s_first_unread = false;
                // End signature parsing, only if needed
                if (@$user_cache[$poster_id]['sig'] && $row['enable_sig'] && empty($user_cache[$poster_id]['sig_parsed'])) {
                    $user_cache[$poster_id]['sig'] = censor_text($user_cache[$poster_id]['sig']);
                    if ($user_cache[$poster_id]['sig_bbcode_bitfield']) {
                        if ($bbcode_filter) {
                            $user_cache[$poster_id]['sig'] = preg_replace($patterns, $replaces, $user_cache[$poster_id]['sig']);
                        }
                        $bbcode->bbcode_second_pass($user_cache[$poster_id]['sig'], $user_cache[$poster_id]['sig_bbcode_uid'], $user_cache[$poster_id]['sig_bbcode_bitfield']);
                    }
                    $user_cache[$poster_id]['sig'] = bbcode_nl2br($user_cache[$poster_id]['sig']);
                    $user_cache[$poster_id]['sig'] = $master->gym_master->smiley_text($user_cache[$poster_id]['sig'], !$master->module_config['html_allow_smilies']);
                    $user_cache[$poster_id]['sig_parsed'] = true;
                } else {
                    // Remove sig
                    $user_cache[$poster_id]['sig'] = '';
                }
                // Parse the message and subject
                $message =& $row['post_text'];
                if ($bbcode_filter) {
                    $message = preg_replace($patterns, $replaces, $message);
                }
                if ($display_sumarize > 0) {
                    $message = $master->gym_master->summarize($message, $display_sumarize, $master->call['display_sumarize_method']);
                    // Clean broken tag at the end of the message
                    $message = preg_replace('`\\<[^\\<\\>]*$`i', ' ...', $message);
                    // Close broken bbcode tags requiring it, only quotes for now
                    $master->gym_master->close_bbcode_tags($message, $row['bbcode_uid']);
                }
                // Parse the message and subject
                $message = censor_text($message);
                // Second parse bbcode here
                if ($row['bbcode_bitfield']) {
                    $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
                }
                $message = bbcode_nl2br($message);
                $message = $master->gym_master->smiley_text($message, !$master->module_config['html_allow_smilies']);
                if ($display_sumarize > 0) {
                    // Clean up
                    static $find = array('`\\<\\!--[^\\<\\>]+--\\>`Ui', '`\\[\\/?[^\\]\\[]*\\]`Ui');
                    $message = preg_replace($find, '', $message);
                }
                // Replace naughty words such as farty pants
                $row['post_subject'] = censor_text(!empty($row['post_subject']) ? $row['post_subject'] : $topic_data['topic_title']);
                // custom profile fields
                $cp_row = array();
                if ($display_user_info && $config['load_cpf_viewtopic']) {
                    $cp_row = isset($profile_fields_cache[$poster_id]) ? $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$poster_id]) : array();
                }
                $post_unread = isset($topic_tracking_info[$topic_id]) && $row['post_time'] > $topic_tracking_info[$topic_id] ? true : false;
                // Generate all the URIs ...
                if (!$s_global && !isset($master->module_config['global_exclude_list'][$forum_id])) {
                    $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&amp;t={$topic_id}") . '#p' . $row['post_id'];
                    $view_forum_url = $master->forum_datas[$forum_id]['forum_url'];
                } else {
                    $view_topic_url = $view_forum_url = '';
                }
                $postrow = array('FORUM_NAME' => !$s_global ? $master->forum_datas[$forum_id]['forum_name'] : '', 'U_VIEW_FORUM' => $view_forum_url, 'VIEWS' => $topic_data['topic_views'], 'POST_DATE' => $user->format_date($row['post_time']), 'POST_SUBJECT' => $row['post_subject'], 'MESSAGE' => $message, 'EDITED_MESSAGE' => $l_edited_by, 'EDIT_REASON' => $row['post_edit_reason'], 'BUMPED_MESSAGE' => $l_bumped_by, 'MINI_POST_IMG' => $post_unread ? $user->img('icon_post_target_unread', 'NEW_POST') : $user->img('icon_post_target', 'POST'), 'POST_ICON_IMG' => $topic_data['enable_icons'] && !empty($row['icon_id']) ? $master->icons[$row['icon_id']]['img'] : '', 'POST_ICON_IMG_WIDTH' => $topic_data['enable_icons'] && !empty($row['icon_id']) ? $master->icons[$row['icon_id']]['width'] : '', 'POST_ICON_IMG_HEIGHT' => $topic_data['enable_icons'] && !empty($row['icon_id']) ? $master->icons[$row['icon_id']]['height'] : '', 'U_MCP_REPORT' => $auth->acl_get('m_report', $forum_id) ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=reports&amp;mode=report_details&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '', 'U_MCP_APPROVE' => $auth->acl_get('m_approve', $forum_id) ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue&amp;mode=approve_details&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '', 'U_MINI_POST' => $view_topic_url, 'U_NEWEST_POST' => $post_unread ? append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $forum_id . '&amp;t=' . $topic_id . '&amp;view=unread#unread') : '', 'POST_ID' => $row['post_id'], 'POSTER_ID' => $poster_id, 'S_HAS_ATTACHMENTS' => !empty($attachments[$row['post_id']]) ? true : false, 'S_POST_UNAPPROVED' => $row['post_approved'] ? false : true, 'S_POST_REPORTED' => $row['post_reported'] && $auth->acl_get('m_report', $forum_id) ? true : false, 'S_DISPLAY_NOTICE' => 0, 'S_FRIEND' => $row['friend'] ? true : false, 'S_UNREAD_POST' => $post_unread, 'S_CUSTOM_FIELDS' => isset($cp_row['row']) && sizeof($cp_row['row']) ? true : false, 'S_TOPIC_POSTER' => $topic_data['topic_poster'] == $poster_id ? true : false, 'S_IGNORE_POST' => $row['hide_post'] ? true : false, 'L_IGNORE_POST' => $row['hide_post'] ? sprintf($user->lang['POST_BY_FOE'], get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), '<a href="' . append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&amp;t={$topic_id}&amp;p={$row['post_id']}&amp;view=show") . '#p' . $row['post_id'] . '">', '</a>') : '', 'REPLIES' => $topic_datas[$forum_id][$topic_id]['replies']);
                if ($display_user_info) {
                    $postrow += array('POST_AUTHOR_FULL' => $user_cache[$poster_id]['post_author_full'], 'POST_AUTHOR_COLOUR' => $user_cache[$poster_id]['post_author_colour'], 'POST_AUTHOR' => $user_cache[$poster_id]['post_author'], 'U_POST_AUTHOR' => $user_cache[$poster_id]['u_post_author'], 'SIGNATURE' => $user_cache[$poster_id]['sig'], 'RANK_TITLE' => $user_cache[$poster_id]['rank_title'], 'RANK_IMG' => $user_cache[$poster_id]['rank_image'], 'RANK_IMG_SRC' => $user_cache[$poster_id]['rank_image_src'], 'POSTER_JOINED' => $user_cache[$poster_id]['joined'], 'POSTER_POSTS' => $user_cache[$poster_id]['posts'], 'POSTER_FROM' => $user_cache[$poster_id]['from'], 'POSTER_AVATAR' => $user_cache[$poster_id]['avatar'], 'POSTER_WARNINGS' => $user_cache[$poster_id]['warnings'], 'POSTER_AGE' => $user_cache[$poster_id]['age'], 'ICQ_STATUS_IMG' => $user_cache[$poster_id]['icq_status_img'], 'ONLINE_IMG' => $poster_id == ANONYMOUS || !$config['load_onlinetrack'] ? '' : ($user_cache[$poster_id]['online'] ? $user->img('icon_user_online', 'ONLINE') : $user->img('icon_user_offline', 'OFFLINE')), 'S_ONLINE' => $poster_id == ANONYMOUS || !$config['load_onlinetrack'] ? false : ($user_cache[$poster_id]['online'] ? true : false), 'U_PROFILE' => $user_cache[$poster_id]['profile'], 'U_SEARCH' => $user_cache[$poster_id]['search'], 'U_PM' => $poster_id != ANONYMOUS && $config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($user_cache[$poster_id]['allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=pm&amp;mode=compose&amp;action=quotepost&amp;p=' . $row['post_id']) : '', 'U_EMAIL' => $user_cache[$poster_id]['email'], 'U_WWW' => $user_cache[$poster_id]['www'], 'U_ICQ' => $user_cache[$poster_id]['icq'], 'U_AIM' => $user_cache[$poster_id]['aim'], 'U_MSN' => $user_cache[$poster_id]['msn'], 'U_YIM' => $user_cache[$poster_id]['yim'], 'U_JABBER' => $user_cache[$poster_id]['jabber']);
                }
                if ($display_post_buttons) {
                    $postrow += array('U_EDIT' => !$user->data['is_registered'] ? '' : ($user->data['user_id'] == $poster_id && $auth->acl_get('f_edit', $forum_id) && ($row['post_time'] > time() - $config['edit_time'] * 60 || !$config['edit_time']) || $auth->acl_get('m_edit', $forum_id) ? append_sid("{$phpbb_root_path}posting.{$phpEx}", "mode=edit&amp;f={$forum_id}&amp;p={$row['post_id']}") : ''), 'U_QUOTE' => $auth->acl_get('f_reply', $forum_id) ? append_sid("{$phpbb_root_path}posting.{$phpEx}", "mode=quote&amp;f={$forum_id}&amp;p={$row['post_id']}") : '', 'U_INFO' => $auth->acl_get('m_info', $forum_id) ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i=main&amp;mode=post_details&amp;f={$forum_id}&amp;p=" . $row['post_id'], true, $user->session_id) : '', 'U_DELETE' => !$user->data['is_registered'] ? '' : ($user->data['user_id'] == $poster_id && $auth->acl_get('f_delete', $forum_id) && $topic_data['topic_last_post_id'] == $row['post_id'] && ($row['post_time'] > time() - $config['edit_time'] * 60 || !$config['edit_time']) || $auth->acl_get('m_delete', $forum_id) ? append_sid("{$phpbb_root_path}posting.{$phpEx}", "mode=delete&amp;f={$forum_id}&amp;p={$row['post_id']}") : ''), 'U_REPORT' => $auth->acl_get('f_report', $forum_id) ? append_sid("{$phpbb_root_path}report.{$phpEx}", 'f=' . $forum_id . '&amp;p=' . $row['post_id']) : '', 'U_NOTES' => $auth->acl_getf_global('m_') ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=notes&amp;mode=user_notes&amp;u=' . $poster_id, true, $user->session_id) : '', 'U_WARN' => $auth->acl_get('m_warn') && $poster_id != $user->data['user_id'] && $poster_id != ANONYMOUS ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=warn&amp;mode=warn_post&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '');
                }
                if (isset($cp_row['row']) && sizeof($cp_row['row'])) {
                    $postrow = array_merge($postrow, $cp_row['row']);
                }
                // Dump vars into template
                $template->assign_block_vars('postrow', $postrow);
                if (!empty($cp_row['blockrow'])) {
                    foreach ($cp_row['blockrow'] as $field_data) {
                        $template->assign_block_vars('postrow.custom_fields', $field_data);
                    }
                }
                // Display not already displayed Attachments for this post, we already parsed them. ;)
                if (!empty($attachments[$row['post_id']])) {
                    foreach ($attachments[$row['post_id']] as $attachment) {
                        $template->assign_block_vars('postrow.attachment', array('DISPLAY_ATTACHMENT' => $attachment));
                    }
                }
                $prev_post_id = $row['post_id'];
                unset($topic_datas[$forum_id][$topic_id]);
            }
            unset($topic_datas, $user_cache);
        }
        $news_desc = false;
        $rules_info = array('forum_rules' => false, 'forum_rules_link' => false);
        // In case we are listing category's children
        if ($master->call['cat_forum']) {
            $forum_id = $master->call['cat_forum'];
        }
        if ($master->call['display_desc']) {
            $news_desc = !empty($master->module_config['html_site_desc']) ? $master->module_config['html_site_desc'] : '';
            if ($master->call['single_forum'] || $master->call['cat_forum']) {
                $news_desc = $master->generate_forum_info($master->forum_datas[$forum_id]);
            }
        }
        if ($master->call['display_rules'] && ($master->call['single_forum'] || $master->call['cat_forum'])) {
            $rules_info = $master->generate_forum_info($master->forum_datas[$forum_id], 'rules');
        }
        $tpl_vars = array('H1_POSTS' => $master->outputs['page_title'], 'DISPLAY_POSTS_H1' => $display_link, 'U_POSTS' => $display_link ? append_sid($display_file) : false, 'DISPLAY_USER_INFO' => $display_user_info, 'DISPLAY_POSTS' => $has_result, 'DISPLAY_POST_BUTTONS' => $display_post_buttons, 'NEWS_DESC' => $news_desc, 'NEWS_RULES' => $rules_info['forum_rules'], 'NEWS_RULES_LINK' => $rules_info['forum_rules_link'], 'REPORTED_IMG' => $user->img('icon_topic_reported', 'POST_REPORTED'), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'POST_UNAPPROVED'), 'T_ICONS_PATH' => "{$phpbb_root_path}{$config['icons_path']}/", 'NEWS_IMG_SRC' => $master->gym_master->path_config['gym_img_url'] . 'html_news.gif');
        if ($master->call['single_forum'] || $master->call['cat_forum']) {
            $tpl_vars += array('FORUM_MAP_URL' => $master->module_config['html_allow_cat_map'] ? append_sid($master->gym_master->html_build_url('html_forum_cat_map', $phpbb_seo->seo_url['forum'][$forum_id], $forum_id)) : '', 'FORUM_MAP' => sprintf($user->lang['HTML_MAP_OF'], $master->forum_datas[$forum_id]['forum_name']), 'FORUM_URL' => $master->forum_datas[$forum_id]['forum_url'], 'FORUM_NAME' => $master->forum_datas[$forum_id]['forum_name'], 'S_SINGLE_FORUM' => $master->call['cat_forum'] ? false : true);
        } else {
            $tpl_vars += array('FORUM_MAP' => sprintf($user->lang['HTML_MAP_OF'], $master->module_config['html_sitename']), 'FORUM_MAP_URL' => $master->module_config['html_allow_map'] ? append_sid($master->module_config['html_url'] . $master->url_settings['html_forum_map']) : '', 'FORUM_URL' => append_sid("{$phpbb_root_path}index.{$phpEx}"), 'FORUM_NAME' => $master->module_config['html_sitename']);
        }
        if ($display_user_info) {
            $tpl_vars += array('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'));
        }
        if ($display_post_buttons) {
            $tpl_vars += array('QUOTE_IMG' => $user->img('icon_post_quote', 'REPLY_WITH_QUOTE'), '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'), 'REPORT_IMG' => $user->img('icon_post_report', 'REPORT_POST'), 'WARN_IMG' => $user->img('icon_user_warn', 'WARN_USER'));
        }
        if ($display_pagination) {
            $l_total_topic_s = $total_topics == 0 ? 'TOTAL_TOPICS_ZERO' : 'TOTAL_TOPICS_OTHER';
            $tpl_vars += array('DISPLAY_PAGINATION' => generate_pagination(append_sid($display_file), $total_topics, $limit, $start), 'DISPLAY_PAGE_NUMBER' => on_page($total_topics, $limit, $start), 'DISPLAY_TOTAL_TOPICS' => sprintf($user->lang[$l_total_topic_s], $total_topics));
        }
        $template->assign_vars($tpl_vars);
        unset($tpl_vars);
    }
/**
* Check for read forums and update topic tracking info accordingly
*
* @param int $forum_id the forum id to check
* @param int $forum_last_post_time the forums last post time
* @param int $f_mark_time the forums last mark time if user is registered and load_db_lastread enabled
* @param int $mark_time_forum false if the mark time needs to be obtained, else the last users forum mark time
*
* @return true if complete forum got marked read, else false.
*/
function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_time = false, $mark_time_forum = false)
{
    global $db, $tracking_topics, $user, $config, $auth, $request, $phpbb_container;
    // Determine the users last forum mark time if not given.
    if ($mark_time_forum === false) {
        if ($config['load_db_lastread'] && $user->data['is_registered']) {
            $mark_time_forum = !empty($f_mark_time) ? $f_mark_time : $user->data['user_lastmark'];
        } else {
            if ($config['load_anon_lastread'] || $user->data['is_registered']) {
                $tracking_topics = $request->variable($config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE);
                $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;
                }
                $mark_time_forum = isset($tracking_topics['f'][$forum_id]) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
            }
        }
    }
    // Handle update of unapproved topics info.
    // Only update for moderators having m_approve permission for the forum.
    $phpbb_content_visibility = $phpbb_container->get('content.visibility');
    // Check the forum for any left unread topics.
    // If there are none, we mark the forum as read.
    if ($config['load_db_lastread'] && $user->data['is_registered']) {
        if ($mark_time_forum >= $forum_last_post_time) {
            // We do not need to mark read, this happened before. Therefore setting this to true
            $row = true;
        } else {
            $sql = 'SELECT t.forum_id
				FROM ' . TOPICS_TABLE . ' t
				LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt
					ON (tt.topic_id = t.topic_id
						AND tt.user_id = ' . $user->data['user_id'] . ')
				WHERE t.forum_id = ' . $forum_id . '
					AND t.topic_last_post_time > ' . $mark_time_forum . '
					AND t.topic_moved_id = 0
					AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.') . '
					AND (tt.topic_id IS NULL
						OR tt.mark_time < t.topic_last_post_time)';
            $result = $db->sql_query_limit($sql, 1);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
        }
    } else {
        if ($config['load_anon_lastread'] || $user->data['is_registered']) {
            // Get information from cookie
            $row = false;
            if (!isset($tracking_topics['tf'][$forum_id])) {
                // We do not need to mark read, this happened before. Therefore setting this to true
                $row = true;
            } else {
                $sql = 'SELECT t.topic_id
				FROM ' . TOPICS_TABLE . ' t
				WHERE t.forum_id = ' . $forum_id . '
					AND t.topic_last_post_time > ' . $mark_time_forum . '
					AND t.topic_moved_id = 0
					AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.');
                $result = $db->sql_query($sql);
                $check_forum = $tracking_topics['tf'][$forum_id];
                $unread = false;
                while ($row = $db->sql_fetchrow($result)) {
                    if (!isset($check_forum[base_convert($row['topic_id'], 10, 36)])) {
                        $unread = true;
                        break;
                    }
                }
                $db->sql_freeresult($result);
                $row = $unread;
            }
        } else {
            $row = true;
        }
    }
    if (!$row) {
        markread('topics', $forum_id);
        return true;
    }
    return false;
}
예제 #7
0
 /**
  * Get tracking data from cookie.
  */
 protected function get_track_cookie()
 {
     if ($this->grabbed_cookies == true || $this->user->data['is_registered']) {
         return;
     }
     $cookie = $this->request->variable($this->config['cookie_name'] . '_titania_track', '', false, true);
     if ($cookie) {
         $this->store = tracking_unserialize($cookie);
     }
     $this->grabbed_cookies = true;
 }
예제 #8
0
 function display_topics(&$master)
 {
     global $user, $template, $config, $phpEx, $db, $auth, $cache, $phpbb_root_path;
     static $display_orders = array('first' => 't.topic_id', 'last' => 't.topic_last_post_time');
     global $phpbb_seo;
     // Usefull for multi bb topic & forum tracking
     // Leave default for single forum eg : '_track'
     $tracking_cookie_name = (defined('XLANG_AKEY') ? XLANG_AKEY : '') . '_track';
     // Specific options
     $display_file =& $master->call['display_file'];
     $display_user_info =& $master->call['display_user_info'];
     $display_link =& $master->call['display_link'];
     $display_pagination =& $master->call['display_pagination'];
     $display_tracking =& $master->call['display_tracking'];
     $display_topic_status =& $master->call['display_topic_status'];
     $display_user_link = !empty($master->call['display_user_link']) ? true : false;
     $display_user_link_key = $display_user_link ? 'full' : 'no_profile';
     $display_last_post =& $master->call['display_last_post'];
     $display_order = isset($display_orders[$master->call['display_order']]) ? $display_orders[$master->call['display_order']] : $display_orders['first'];
     $limit_time_sql = !empty($master->call['limit_time']) ? ' AND t.topic_last_post_time > ' . ($user->time_now - $master->call['limit_time']) : '';
     $order_sql = @$master->call['sort'] == 'ASC' ? ' ASC' : ' DESC';
     if (!$display_tracking) {
         $load_db_lastread = $load_anon_lastread = false;
     } else {
         $load_db_lastread = (bool) ($config['load_db_lastread'] && $user->data['is_registered']);
         $load_anon_lastread = (bool) ($config['load_anon_lastread'] || $user->data['is_registered']);
     }
     // hanlde options
     $limit = $master->call['limit'] >= 1 ? (int) $master->call['limit'] : 5;
     $start =& $master->start;
     if (!$display_pagination || empty($display_file)) {
         $start = 0;
         $display_pagination = false;
     }
     $total_topics = 0;
     $topic_sql = $master->call['topic_sql'];
     $forum_sql = $master->call['forum_sql'];
     $s_global = $master->call['s_global'];
     // Do some reset
     $topic_datas = $topic_ids = $forum_ids = $user_cache = $id_cache = $post_datas = $forum_datas = array();
     $forum_id = $master->call['forum_id'];
     // Get The Data, first forums
     if (!$s_global && !$master->call['single_forum'] || $master->call['single_forum'] && empty($master->forum_datas[$master->call['forum_id']])) {
         $sql_array = array('SELECT' => 'f.*', 'FROM' => array(FORUMS_TABLE => 'f'), 'LEFT_JOIN' => array());
         if ($load_db_lastread) {
             $sql_array['SELECT'] .= ', ft.mark_time as forum_mark_time';
             $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['WHERE'] = $forum_sql ? str_replace('t.forum_id', 'f.forum_id', $forum_sql) : '';
         $sql = $db->sql_build_query('SELECT', $sql_array);
         unset($sql_array);
         $result = $db->sql_query($sql);
         while ($row = $db->sql_fetchrow($result)) {
             $forum_id = (int) $row['forum_id'];
             $forum_datas[$forum_id] = $row;
         }
         $db->sql_freeresult($result);
     }
     // Now the topics
     $sql_array = array('SELECT' => 't.*', 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array());
     if ($load_db_lastread) {
         $sql_array['SELECT'] .= ', tt.mark_time';
         $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.user_id = ' . $user->data['user_id'] . ' AND tt.topic_id = t.topic_id');
     } elseif ($load_anon_lastread && empty($master->tracking_topics)) {
         $master->tracking_topics = isset($_COOKIE[$config['cookie_name'] . $tracking_cookie_name]) ? STRIP ? stripslashes($_COOKIE[$config['cookie_name'] . $tracking_cookie_name]) : $_COOKIE[$config['cookie_name'] . $tracking_cookie_name] : '';
         $master->tracking_topics = $master->tracking_topics ? tracking_unserialize($master->tracking_topics) : array();
         if (!$user->data['is_registered']) {
             $user->data['user_lastmark'] = isset($master->tracking_topics['l']) ? (int) (base_convert($master->tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
         }
     }
     $sql_where = ($forum_sql ? $forum_sql : '') . $limit_time_sql;
     $sql_where .= $topic_sql ? ($sql_where ? ' AND ' : '') . $topic_sql : '';
     $sql_where .= ($sql_where ? ' AND ' : '') . 't.topic_status <> ' . ITEM_MOVED;
     if ($master->call['single_forum']) {
         $sql_where .= $auth->acl_get('m_approve', $master->call['forum_id']) ? '' : ' AND t.topic_approved = 1';
     } else {
         // only admins and global moderators will see un-approved topics
         // in the forum they have access to.
         $sql_where .= $auth->acl_gets('a_') || $auth->acl_getf_global('m_') ? '' : ' AND t.topic_approved = 1';
     }
     // obtain correct topic count if we display pagination
     if ($display_pagination) {
         $sql = "SELECT COUNT(t.topic_id) AS num_topics\n\t\t\t\tFROM " . TOPICS_TABLE . " t\n\t\t\t\tWHERE {$sql_where}";
         $result = $db->sql_query($sql);
         $total_topics = (int) $db->sql_fetchfield('num_topics');
         $db->sql_freeresult($result);
         // Make sure $start is set to the last page if it exceeds the amount
         if ($start < 0 || $start > $total_topics) {
             $start = $start < 0 ? 0 : floor(($total_topics - 1) / $limit) * $limit;
             // Since we've reached here, $start is not set proper, kill the dupe!
             $url = $display_file . $master->gym_master->html_add_start($start);
             $master->gym_master->seo_kill_dupes($url);
         }
     }
     $sql_array['WHERE'] = $sql_where;
     $sql_array['ORDER_BY'] = $display_order . $order_sql;
     $sql = $db->sql_build_query('SELECT', $sql_array);
     unset($sql_array);
     $result = $db->sql_query_limit($sql, $limit, $start);
     while ($row = $db->sql_fetchrow($result)) {
         $topic_id = (int) $row['topic_id'];
         $forum_id = (int) $row['forum_id'];
         // Start with the forum
         if (!$s_global && empty($master->forum_datas[$forum_id])) {
             // www.phpBB-SEO.com SEO TOOLKIT BEGIN
             $phpbb_seo->set_url($forum_datas[$forum_id]['forum_name'], $forum_id, 'forum');
             // www.phpBB-SEO.com SEO TOOLKIT END
             $master->forum_datas[$forum_id] = array_merge($forum_datas[$forum_id], array('forum_url' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", "f={$forum_id}"), 'm_approve' => $auth->acl_get('m_approve', $forum_id)));
             if ($load_db_lastread) {
                 $master->forum_tracking_info[$forum_id] = !empty($forum_datas[$forum_id]['forum_mark_time']) ? $forum_datas[$forum_id]['forum_mark_time'] : $user->data['user_lastmark'];
             } elseif ($load_anon_lastread) {
                 $master->forum_tracking_info[$forum_id] = isset($master->tracking_topics['f'][$forum_id]) ? (int) (base_convert($master->tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
             }
         }
         $topic_datas[$topic_id] = $row;
         $topic_ids[$topic_id] = $topic_id;
     }
     $db->sql_freeresult($result);
     // Let's go
     $has_result = false;
     if (!empty($topic_datas)) {
         $has_result = true;
         // Grab icons
         if (empty($master->icons)) {
             $master->icons = $cache->obtain_icons();
         }
         $s_type_switch = 0;
         $folder_alt = 'NO_NEW_POSTS';
         $topic_type = '';
         $folder_img = 'topic_read';
         $topic_folder_img = $user->img($folder_img, $folder_alt);
         $topic_folder_img_src = $user->img($folder_img, $folder_alt, false, '', 'src');
         foreach ($topic_ids as $topic_id) {
             $topic_id = (int) $topic_id;
             $row =& $topic_datas[$topic_id];
             $forum_id = (int) $row['forum_id'];
             if (empty($master->forum_tracking_info[$forum_id])) {
                 if ($load_db_lastread) {
                     $master->topic_tracking_info[$topic_id] = !empty($row['mark_time']) ? $row['mark_time'] : $user->data['user_lastmark'];
                 } else {
                     if ($load_anon_lastread) {
                         $topic_id36 = base_convert($topic_id, 10, 36);
                         if (isset($master->tracking_topics['t'][$topic_id36])) {
                             $master->tracking_topics['t'][$topic_id] = base_convert($master->tracking_topics['t'][$topic_id36], 36, 10) + $config['board_startdate'];
                         }
                         $master->topic_tracking_info[$topic_id] = isset($master->tracking_topics['t'][$topic_id]) ? $master->tracking_topics['t'][$topic_id] : $user->data['user_lastmark'];
                     }
                 }
             } else {
                 $master->topic_tracking_info[$topic_id] = $master->forum_tracking_info[$forum_id];
             }
             $row['topic_title'] = censor_text($row['topic_title']);
             // www.phpBB-SEO.com SEO TOOLKIT BEGIN
             $phpbb_seo->prepare_iurl($row, 'topic', $row['topic_type'] == POST_GLOBAL ? $phpbb_seo->seo_static['global_announce'] : $phpbb_seo->seo_url['forum'][$forum_id]);
             // www.phpBB-SEO.com SEO TOOLKIT END
             // This will allow the style designer to output a different header
             // or even separate the list of announcements from sticky and normal topics
             $s_type_switch_test = 0;
             // Replies
             $replies = !empty($master->forum_datas[$forum_id]['m_approve']) ? $row['topic_replies_real'] : $row['topic_replies'];
             $unread_topic = isset($master->topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $master->topic_tracking_info[$topic_id] ? true : false;
             // Get folder img, topic status/type related information
             if ($display_topic_status) {
                 $master->gym_master->topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
                 $topic_folder_img = $user->img($folder_img, $folder_alt);
                 $topic_folder_img_src = $user->img($folder_img, $folder_alt, false, '', 'src');
             }
             // Generate all the URIs ...
             $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&amp;t={$topic_id}");
             $view_forum_url = !$s_global ? $master->forum_datas[$forum_id]['forum_url'] : '';
             $topic_unapproved = !$row['topic_approved'] && $auth->acl_get('m_approve', $forum_id) ? true : false;
             $posts_unapproved = $row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $forum_id) ? true : false;
             $u_mcp_queue = $topic_unapproved || $posts_unapproved ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue&amp;mode=' . ($topic_unapproved ? 'approve_details' : 'unapproved_posts') . "&amp;t={$topic_id}", true, $user->session_id) : '';
             // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe
             if (!empty($phpbb_seo->seo_opt['no_dupe']['on'])) {
                 if ($replies + 1 > $phpbb_seo->seo_opt['topic_per_page']) {
                     $phpbb_seo->seo_opt['topic_last_page'][$topic_id] = floor($replies / $phpbb_seo->seo_opt['topic_per_page']) * $phpbb_seo->seo_opt['topic_per_page'];
                 }
             }
             // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe
             $tpl_data = array('FORUM_ID' => $forum_id, 'TOPIC_ID' => $topic_id, 'PAGINATION' => $master->call['display_topic_pagination'] ? $master->gym_master->topic_generate_pagination($replies, $view_topic_url) : '', 'REPLIES' => $replies, 'VIEWS' => $row['topic_views'], 'TOPIC_TITLE' => $row['topic_title'], 'FORUM_NAME' => !$s_global ? $master->forum_datas[$forum_id]['forum_name'] : '', 'TOPIC_TYPE' => $topic_type, 'TOPIC_FOLDER_IMG' => $topic_folder_img, 'TOPIC_FOLDER_IMG_SRC' => $topic_folder_img_src, 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt], 'TOPIC_ICON_IMG' => !empty($master->icons[$row['icon_id']]) ? $master->icons[$row['icon_id']]['img'] : '', 'TOPIC_ICON_IMG_WIDTH' => !empty($master->icons[$row['icon_id']]) ? $master->icons[$row['icon_id']]['width'] : '', 'TOPIC_ICON_IMG_HEIGHT' => !empty($master->icons[$row['icon_id']]) ? $master->icons[$row['icon_id']]['height'] : '', 'ATTACH_ICON_IMG' => $auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment'] ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', 'UNAPPROVED_IMG' => $topic_unapproved || $posts_unapproved ? $user->img('icon_topic_unapproved', $topic_unapproved ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', 'FIRST_POST_TIME' => $user->format_date($row['topic_time']), 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']), 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']), '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' => !empty($row['topic_reported']) && $auth->acl_get('m_report', $forum_id) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, 'S_HAS_POLL' => $row['poll_start'] ? true : false, '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, 'U_NEWEST_POST' => $unread_topic ? append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $forum_id . '&amp;t=' . $topic_id . '&amp;view=unread#unread') : '', 'U_VIEW_TOPIC' => $view_topic_url, 'U_VIEW_FORUM' => $view_forum_url, 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=reports&amp;mode=reports&amp;f=' . $forum_id . '&amp;t=' . $topic_id, true, $user->session_id), 'U_MCP_QUEUE' => $u_mcp_queue, 'S_TOPIC_TYPE_SWITCH' => $s_type_switch == $s_type_switch_test ? -1 : $s_type_switch_test);
             if ($display_last_post) {
                 $tpl_data += array('TOPIC_LAST_POST_TITLE' => !empty($row['topic_last_post_subject']) ? censor_text($row['topic_last_post_subject']) : $row['topic_title'], 'U_MINI_POST' => !empty($phpbb_seo->seo_opt['no_dupe']['on']) ? append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&amp;t={$topic_id}&amp;start=" . @intval($phpbb_seo->seo_opt['topic_last_page'][$topic_id])) . '#p' . $row['topic_last_post_id'] : append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'p=' . $row['topic_last_post_id'] . ($row['topic_type'] == POST_GLOBAL ? '&amp;f=' . $forum_id : '')) . '#p' . $row['topic_last_post_id']);
             }
             if ($display_user_info) {
                 $tpl_data += array('TOPIC_AUTHOR_FULL' => get_username_string($display_user_link_key, $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']), '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($display_user_link_key, $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'U_LAST_POST_AUTHOR' => $display_user_link ? get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']) : '', 'U_TOPIC_AUTHOR' => $display_user_link ? get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']) : '');
             }
             $template->assign_block_vars('topicrow', $tpl_data);
             unset($tpl_data);
             $s_type_switch = 0;
         }
         unset($topic_datas);
     }
     $map_desc = false;
     $rules_info = array('forum_rules' => false, 'forum_rules_link' => false);
     // In case we are listing category's children
     if ($master->call['cat_forum']) {
         $forum_id = $master->call['cat_forum'];
     }
     if ($master->call['display_desc']) {
         $map_desc = !empty($master->module_config['html_site_desc']) ? $master->module_config['html_site_desc'] : '';
         if ($master->call['single_forum'] || $master->call['cat_forum']) {
             $map_desc = $master->generate_forum_info($master->forum_datas[$forum_id]);
         }
     }
     if ($master->call['display_rules'] && ($master->call['single_forum'] || $master->call['cat_forum'])) {
         $rules_info = $master->generate_forum_info($master->forum_datas[$forum_id], 'rules');
     }
     $tpl_data = array('H1_TOPICS' => $master->outputs['page_title'], 'DISPLAY_TOPICS_H1' => $display_link, 'U_TOPICS' => $display_link ? append_sid($display_file) : false, 'DISPLAY_TOPICS' => $has_result, 'DISPLAY_LAST_POST' => $display_last_post, 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'MAP_DESC' => $map_desc, 'MAP_RULES' => $rules_info['forum_rules'], 'MAP_RULES_LINK' => $rules_info['forum_rules_link'], 'T_ICONS_PATH' => "{$phpbb_root_path}{$config['icons_path']}/", 'NEWS_IMG_SRC' => $master->gym_master->path_config['gym_img_url'] . 'html_news.gif');
     if ($master->call['single_forum'] || $master->call['cat_forum']) {
         $tpl_data += array('FORUM_NEWS' => sprintf($user->lang['HTML_NEWS_OF'], $master->forum_datas[$forum_id]['forum_name']), 'FORUM_NEWS_URL' => $master->module_config['html_allow_cat_news'] ? append_sid($master->gym_master->html_build_url('html_forum_cat_news', $phpbb_seo->seo_url['forum'][$forum_id], $forum_id)) : '', 'FORUM_URL' => $master->forum_datas[$forum_id]['forum_url'], 'FORUM_NAME' => $master->forum_datas[$forum_id]['forum_name'], 'S_SINGLE_FORUM' => $master->call['cat_forum'] ? false : true);
     } else {
         $tpl_data += array('FORUM_NEWS' => sprintf($user->lang['HTML_NEWS_OF'], $master->module_config['html_sitename']), 'FORUM_NEWS_URL' => $master->module_config['html_allow_news'] ? append_sid($master->module_config['html_url'] . $master->url_settings['html_forum_news']) : '', 'FORUM_URL' => append_sid("{$phpbb_root_path}index.{$phpEx}"), 'FORUM_NAME' => $master->module_config['html_sitename']);
     }
     $template->assign_vars($tpl_data);
     unset($tpl_data);
     if ($display_pagination) {
         $l_total_topic_s = $total_topics == 0 ? 'TOTAL_TOPICS_ZERO' : 'TOTAL_TOPICS_OTHER';
         $template->assign_vars(array('DISPLAY_PAGINATION' => generate_pagination(append_sid($display_file), $total_topics, $limit, $start), 'DISPLAY_PAGE_NUMBER' => on_page($total_topics, $limit, $start), 'DISPLAY_TOTAL_TOPICS' => sprintf($user->lang[$l_total_topic_s], $total_topics)));
     }
 }
예제 #9
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));
    }
예제 #10
0
    /**
     * Get similar topics by matching topic titles
     *
     * NOTE: Currently requires MySQL due to the use of FULLTEXT indexes
     * and MATCH and AGAINST and UNIX_TIMESTAMP. MySQL FULLTEXT has built-in
     * English ignore words. We use phpBB's ignore words for non-English
     * languages. We also remove any admin-defined special ignore words.
     *
     * @param	array	$topic_data	Array with topic data
     * @return 	null
     * @access	public
     */
    public function display_similar_topics($topic_data)
    {
        $topic_title = $this->clean_topic_title($topic_data['topic_title']);
        // If the cleaned up topic_title is empty, no need to continue
        if (empty($topic_title)) {
            return;
        }
        // Similar Topics query
        $sql_array = array('SELECT' => "f.forum_id, f.forum_name, t.*,\n\t\t\t\tMATCH (t.topic_title) AGAINST ('" . $this->db->sql_escape($topic_title) . "') AS score", 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id')), 'WHERE' => "MATCH (t.topic_title) AGAINST ('" . $this->db->sql_escape($topic_title) . "') >= 0.5\n\t\t\t\tAND t.topic_status <> " . ITEM_MOVED . '
				AND t.topic_visibility = ' . ITEM_APPROVED . '
				AND t.topic_time > (UNIX_TIMESTAMP() - ' . $this->config['similar_topics_time'] . ')
				AND t.topic_id <> ' . (int) $topic_data['topic_id']);
        // Add topic tracking data to the query (only if query caching is off)
        if ($this->user->data['is_registered'] && $this->config['load_db_lastread'] && !$this->config['similar_topics_cache']) {
            $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $this->user->data['user_id']);
            $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = f.forum_id AND ft.user_id = ' . $this->user->data['user_id']);
            $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as f_mark_time';
        } else {
            if ($this->config['load_anon_lastread'] || $this->user->data['is_registered']) {
                // Cookie based tracking copied from search.php
                $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();
            }
        }
        // We need to exclude passworded forums so we do not leak the topic title
        $passworded_forums = $this->user->get_passworded_forums();
        // See if the admin set this forum to only search a specific group of other forums, and include them
        if (!empty($topic_data['similar_topic_forums'])) {
            // Remove any passworded forums from this group of forums we will be searching
            $included_forums = array_diff(explode(',', $topic_data['similar_topic_forums']), $passworded_forums);
            // if there's nothing left to display (user has no access to the forums we want to search)
            if (empty($included_forums)) {
                return;
            }
            $sql_array['WHERE'] .= ' AND ' . $this->db->sql_in_set('f.forum_id', $included_forums);
        } else {
            if (!empty($this->config['similar_topics_ignore'])) {
                // Add passworded forums to the exlude array
                $excluded_forums = array_unique(array_merge(explode(',', $this->config['similar_topics_ignore']), $passworded_forums));
                $sql_array['WHERE'] .= ' AND ' . $this->db->sql_in_set('f.forum_id', $excluded_forums, true);
            } else {
                if (!empty($passworded_forums)) {
                    $sql_array['WHERE'] .= ' AND ' . $this->db->sql_in_set('f.forum_id', $passworded_forums, true);
                }
            }
        }
        /**
         * Event to modify the sql_array for similar topics
         *
         * @event vse.similartopics.get_topic_data
         * @var	array	sql_array	SQL array to get similar topics data
         * @since 1.3.0
         */
        $vars = array('sql_array');
        extract($this->dispatcher->trigger_event('vse.similartopics.get_topic_data', compact($vars)));
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query_limit($sql, $this->config['similar_topics_limit'], 0, $this->config['similar_topics_cache']);
        // Grab icons
        $icons = $this->cache->obtain_icons();
        $rowset = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            $similar_forum_id = (int) $row['forum_id'];
            $similar_topic_id = (int) $row['topic_id'];
            $rowset[$similar_topic_id] = $row;
            if ($this->auth->acl_get('f_read', $similar_forum_id)) {
                // Get topic tracking info
                if ($this->user->data['is_registered'] && $this->config['load_db_lastread'] && !$this->config['similar_topics_cache']) {
                    $topic_tracking_info = get_topic_tracking($similar_forum_id, $similar_topic_id, $rowset, array($similar_forum_id => $row['f_mark_time']));
                } else {
                    if ($this->config['load_anon_lastread'] || $this->user->data['is_registered']) {
                        $topic_tracking_info = get_complete_topic_tracking($similar_forum_id, $similar_topic_id);
                        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;
                        }
                    }
                }
                // Replies
                $replies = $this->content_visibility->get_count('topic_posts', $row, $similar_forum_id) - 1;
                // Get folder img, topic status/type related information
                $folder_img = $folder_alt = $topic_type = '';
                $unread_topic = isset($topic_tracking_info[$similar_topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$similar_topic_id] ? true : false;
                topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
                $topic_unapproved = $row['topic_visibility'] == ITEM_UNAPPROVED && $this->auth->acl_get('m_approve', $similar_forum_id) ? true : false;
                $posts_unapproved = $row['topic_visibility'] == ITEM_APPROVED && $row['topic_posts_unapproved'] && $this->auth->acl_get('m_approve', $similar_forum_id) ? true : false;
                //$topic_deleted = $row['topic_visibility'] == ITEM_DELETED;
                $u_mcp_queue = $topic_unapproved || $posts_unapproved ? append_sid("{$this->root_path}mcp.{$this->php_ext}", 'i=queue&amp;mode=' . ($topic_unapproved ? 'approve_details' : 'unapproved_posts') . "&amp;t={$similar_topic_id}", true, $this->user->session_id) : '';
                //$u_mcp_queue = (!$u_mcp_queue && $topic_deleted) ? append_sid("{$this->root_path}mcp.{$this->php_ext}", "i=queue&amp;mode=deleted_topics&amp;t=$similar_topic_id", true, $this->user->session_id) : $u_mcp_queue;
                $base_url = append_sid("{$this->root_path}viewtopic.{$this->php_ext}", 'f=' . $similar_forum_id . '&amp;t=' . $similar_topic_id);
                $topic_row = array('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_TIME' => $this->user->format_date($row['topic_last_post_time']), 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'TOPIC_REPLIES' => $replies, 'TOPIC_VIEWS' => $row['topic_views'], 'TOPIC_TITLE' => $row['topic_title'], 'FORUM_TITLE' => $row['forum_name'], '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', $similar_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') : '', 'S_UNREAD_TOPIC' => $unread_topic, 'S_TOPIC_REPORTED' => !empty($row['topic_reported']) && $this->auth->acl_get('m_report', $similar_forum_id) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, 'S_HAS_POLL' => $row['poll_start'] ? true : false, 'U_NEWEST_POST' => append_sid("{$this->root_path}viewtopic.{$this->php_ext}", 'f=' . $similar_forum_id . '&amp;t=' . $similar_topic_id . '&amp;view=unread') . '#unread', 'U_LAST_POST' => append_sid("{$this->root_path}viewtopic.{$this->php_ext}", 'f=' . $similar_forum_id . '&amp;t=' . $similar_topic_id . '&amp;p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'], 'U_VIEW_TOPIC' => append_sid("{$this->root_path}viewtopic.{$this->php_ext}", 'f=' . $similar_forum_id . '&amp;t=' . $similar_topic_id), 'U_VIEW_FORUM' => append_sid("{$this->root_path}viewforum.{$this->php_ext}", 'f=' . $similar_forum_id), 'U_MCP_REPORT' => append_sid("{$this->root_path}mcp.{$this->php_ext}", 'i=reports&amp;mode=reports&amp;f=' . $similar_forum_id . '&amp;t=' . $similar_topic_id, true, $this->user->session_id), 'U_MCP_QUEUE' => $u_mcp_queue);
                /**
                 * Event to modify the similar topics template block
                 *
                 * @event vse.similartopics.modify_topicrow
                 * @var	array	row			Array with similar topic data
                 * @var	array	topic_row	Template block array
                 * @since 1.3.0
                 */
                $vars = array('row', 'topic_row');
                extract($this->dispatcher->trigger_event('vse.similartopics.modify_topicrow', compact($vars)));
                $this->template->assign_block_vars('similar', $topic_row);
                $this->pagination->generate_template_pagination($base_url, 'similar.pagination', 'start', $replies + 1, $this->config['posts_per_page'], 1, true, true);
            }
        }
        $this->db->sql_freeresult($result);
        $this->user->add_lang_ext('vse/similartopics', 'similar_topics');
        $this->template->assign_vars(array('L_SIMILAR_TOPICS' => $this->user->lang('SIMILAR_TOPICS'), 'NEWEST_POST_IMG' => $this->user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'LAST_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'REPORTED_IMG' => $this->user->img('icon_topic_reported', 'TOPIC_REPORTED'), 'POLL_IMG' => $this->user->img('icon_topic_poll', 'TOPIC_POLL')));
    }
예제 #11
0
/**
* Display Forums
*/
function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
{
    global $db, $auth, $user, $template;
    global $phpbb_root_path, $phpEx, $config;
    global $request, $phpbb_dispatcher, $phpbb_container;
    $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->variable('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'];
    }
    // Handle marking everything read
    if ($mark_read == 'all') {
        $redirect = build_url(array('mark', 'hash', 'mark_time'));
        meta_refresh(3, $redirect);
        if (check_link_hash($request->variable('hash', ''), 'global')) {
            markread('all', false, false, $request->variable('mark_time', 0));
            if ($request->is_ajax()) {
                // Tell the ajax script what language vars and URL need to be replaced
                $data = array('NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'], 'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'], 'U_MARK_FORUMS' => $user->data['is_registered'] || $config['load_anon_lastread'] ? append_sid("{$phpbb_root_path}index.{$phpEx}", 'hash=' . generate_link_hash('global') . '&mark=forums&mark_time=' . time()) : '', 'MESSAGE_TITLE' => $user->lang['INFORMATION'], 'MESSAGE_TEXT' => $user->lang['FORUMS_MARKED']);
                $json_response = new \phpbb\json_response();
                $json_response->send($data);
            }
            trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>'));
        } else {
            trigger_error(sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
        }
    }
    // 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 = $request->variable($config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE);
            $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_ary = array('SELECT' => $sql_array['SELECT'], 'FROM' => $sql_array['FROM'], 'LEFT_JOIN' => $sql_array['LEFT_JOIN'], 'WHERE' => $sql_where, 'ORDER_BY' => 'f.left_id');
    /**
     * Event to modify the SQL query before the forum data is queried
     *
     * @event core.display_forums_modify_sql
     * @var	array	sql_ary		The SQL array to get the data of the forums
     * @since 3.1.0-a1
     */
    $vars = array('sql_ary');
    extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_sql', compact($vars)));
    $sql = $db->sql_build_query('SELECT', $sql_ary);
    $result = $db->sql_query($sql);
    $forum_tracking_info = $valid_categories = array();
    $branch_root_id = $root_data['forum_id'];
    /* @var $phpbb_content_visibility \phpbb\content_visibility */
    $phpbb_content_visibility = $phpbb_container->get('content.visibility');
    while ($row = $db->sql_fetchrow($result)) {
        /**
         * Event to modify the data set of a forum
         *
         * This event is triggered once per forum
         *
         * @event core.display_forums_modify_row
         * @var	int		branch_root_id	Last top-level forum
         * @var	array	row				The data of the forum
         * @since 3.1.0-a1
         */
        $vars = array('branch_root_id', 'row');
        extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_row', compact($vars)));
        $forum_id = $row['forum_id'];
        // Mark forums read?
        if ($mark_read == 'forums') {
            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;
        }
        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'];
            }
        }
        // Lets check whether there are unapproved topics/posts, so we can display an information to moderators
        $row['forum_id_unapproved_topics'] = $auth->acl_get('m_approve', $forum_id) && $row['forum_topics_unapproved'] ? $forum_id : 0;
        $row['forum_id_unapproved_posts'] = $auth->acl_get('m_approve', $forum_id) && $row['forum_posts_unapproved'] ? $forum_id : 0;
        $row['forum_posts'] = $phpbb_content_visibility->get_count('forum_posts', $row, $forum_id);
        $row['forum_topics'] = $phpbb_content_visibility->get_count('forum_topics', $row, $forum_id);
        // 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;
            }
        }
        // Fill list of categories with forums
        if (isset($forum_rows[$row['parent_id']])) {
            $valid_categories[$row['parent_id']] = true;
        }
        //
        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]['forum_password_last_post'] = $row['forum_password'];
            $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;
                }
                if (!$forum_rows[$parent_id]['forum_id_unapproved_posts'] && $row['forum_id_unapproved_posts']) {
                    $forum_rows[$parent_id]['forum_id_unapproved_posts'] = $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;
                    $forum_rows[$parent_id]['forum_password_last_post'] = $row['forum_password'];
                }
            }
        }
        /**
         * Event to modify the forum rows data set
         *
         * This event is triggered once per forum
         *
         * @event core.display_forums_modify_forum_rows
         * @var	array	forum_rows		Data array of all forums we display
         * @var	array	subforums		Data array of all subforums we display
         * @var	int		branch_root_id	Current top-level forum
         * @var	int		parent_id		Current parent forum
         * @var	array	row				The data of the forum
         * @since 3.1.0-a1
         */
        $vars = array('forum_rows', 'subforums', 'branch_root_id', 'parent_id', 'row');
        extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_forum_rows', compact($vars)));
    }
    $db->sql_freeresult($result);
    // Handle marking posts
    if ($mark_read == 'forums') {
        $redirect = build_url(array('mark', 'hash', 'mark_time'));
        $token = $request->variable('hash', '');
        if (check_link_hash($token, 'global')) {
            markread('topics', $forum_ids, false, $request->variable('mark_time', 0));
            $message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
            meta_refresh(3, $redirect);
            if ($request->is_ajax()) {
                // Tell the ajax script what language vars and URL need to be replaced
                $data = array('NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'], 'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'], 'U_MARK_FORUMS' => $user->data['is_registered'] || $config['load_anon_lastread'] ? append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'hash=' . generate_link_hash('global') . '&f=' . $root_data['forum_id'] . '&mark=forums&mark_time=' . time()) : '', 'MESSAGE_TITLE' => $user->lang['INFORMATION'], 'MESSAGE_TEXT' => $user->lang['FORUMS_MARKED']);
                $json_response = new \phpbb\json_response();
                $json_response->send($data);
            }
            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);
    }
    /**
     * Event to perform additional actions before the forum list is being generated
     *
     * @event core.display_forums_before
     * @var	array	active_forum_ary	Array with forum data to display active topics
     * @var	bool	display_moderators	Flag indicating if we display forum moderators
     * @var	array	forum_moderators	Array with forum moderators list
     * @var	array	forum_rows			Data array of all forums we display
     * @var	bool	return_moderators	Flag indicating if moderators list should be returned
     * @var	array	root_data			Array with the root forum data
     * @since 3.1.4-RC1
     */
    $vars = array('active_forum_ary', 'display_moderators', 'forum_moderators', 'forum_rows', 'return_moderators', 'root_data');
    extract($phpbb_dispatcher->trigger_event('core.display_forums_before', compact($vars)));
    // Used to tell whatever we have to create a dummy category or not.
    $last_catless = true;
    foreach ($forum_rows as $row) {
        // Category
        if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT) {
            // Do not display categories without any forums to display
            if (!isset($valid_categories[$row['forum_id']])) {
                continue;
            }
            $cat_row = 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']));
            /**
             * Modify the template data block of the 'category'
             *
             * This event is triggered once per 'category'
             *
             * @event core.display_forums_modify_category_template_vars
             * @var	array	cat_row			Template data of the 'category'
             * @var	bool	catless			The flag indicating whether the 'category' has a parent category
             * @var	bool	last_catless	The flag indicating whether the last forum had a parent category
             * @var	array	root_data		Array with the root forum data
             * @var	array	row				The data of the 'category'
             * @since 3.1.0-RC4
             */
            $vars = array('cat_row', 'catless', 'last_catless', 'root_data', 'row');
            extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_category_template_vars', compact($vars)));
            $template->assign_block_vars('forumrow', $cat_row);
            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;
        $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']) {
            if ($row['forum_password_last_post'] === '' && $auth->acl_get('f_read', $row['forum_id_last_post'])) {
                $last_post_subject = censor_text($row['forum_last_post_subject']);
                $last_post_subject_truncated = truncate_string($last_post_subject, 30, 255, false, $user->lang['ELLIPSIS']);
            } else {
                $last_post_subject = $last_post_subject_truncated = '';
            }
            $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 = $last_post_subject_truncated = '';
        }
        // 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($user->lang['COMMA_SEPARATOR'], $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 = $subforums_row = 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>';
            $subforums_row[] = array('U_SUBFORUM' => $subforum['link'], 'SUBFORUM_NAME' => $subforum['name'], 'S_UNREAD' => $subforum['unread']);
        }
        $s_subforums_list = (string) implode($user->lang['COMMA_SEPARATOR'], $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'];
            }
        }
        $forum_row = 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_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, 'S_DISPLAY_SUBJECT' => $last_post_subject !== '' && $config['display_last_subject'] ? true : false, 'S_FEED_ENABLED' => $config['feed_forum'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $row['forum_options']) && $row['forum_type'] == FORUM_POST ? 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_IMG_STYLE' => $folder_image, 'FORUM_FOLDER_IMG' => $user->img($folder_image, $folder_alt), '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' => $last_post_subject, 'LAST_POST_SUBJECT_TRUNCATED' => $last_post_subject_truncated, '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_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_UNAPPROVED_POSTS' => $row['forum_id_unapproved_posts'] ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue&amp;mode=unapproved_posts&amp;f=' . $row['forum_id_unapproved_posts']) : '', '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);
        /**
         * Modify the template data block of the forum
         *
         * This event is triggered once per forum
         *
         * @event core.display_forums_modify_template_vars
         * @var	array	forum_row		Template data of the forum
         * @var	array	row				The data of the forum
         * @var	array	subforums_row	Template data of subforums
         * @since 3.1.0-a1
         * @change 3.1.0-b5 Added var subforums_row
         */
        $vars = array('forum_row', 'row', 'subforums_row');
        extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_template_vars', compact($vars)));
        $template->assign_block_vars('forumrow', $forum_row);
        // Assign subforums loop for style authors
        $template->assign_block_vars_array('forumrow.subforum', $subforums_row);
        /**
         * Modify and/or assign additional template data for the forum
         * after forumrow loop has been assigned. This can be used
         * to create additional forumrow subloops in extensions.
         *
         * This event is triggered once per forum
         *
         * @event core.display_forums_add_template_data
         * @var	array	forum_row		Template data of the forum
         * @var	array	row				The data of the forum
         * @var	array	subforums_list	The data of subforums
         * @var	array	subforums_row	Template data of subforums
         * @var	bool	catless			The flag indicating whether a forum has a parent category
         * @since 3.1.0-b5
         */
        $vars = array('forum_row', 'row', 'subforums_list', 'subforums_row', 'catless');
        extract($phpbb_dispatcher->trigger_event('core.display_forums_add_template_data', compact($vars)));
        $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&amp;mark_time=' . time()) : '', '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'), 'UNAPPROVED_POST_IMG' => $user->img('icon_topic_unapproved', 'POSTS_UNAPPROVED_FORUM')));
    /**
     * Event to perform additional actions after the forum list has been generated
     *
     * @event core.display_forums_after
     * @var	array	active_forum_ary	Array with forum data to display active topics
     * @var	bool	display_moderators	Flag indicating if we display forum moderators
     * @var	array	forum_moderators	Array with forum moderators list
     * @var	array	forum_rows			Data array of all forums we display
     * @var	bool	return_moderators	Flag indicating if moderators list should be returned
     * @var	array	root_data			Array with the root forum data
     * @since 3.1.0-RC5
     */
    $vars = array('active_forum_ary', 'display_moderators', 'forum_moderators', 'forum_rows', 'return_moderators', 'root_data');
    extract($phpbb_dispatcher->trigger_event('core.display_forums_after', compact($vars)));
    if ($return_moderators) {
        return array($active_forum_ary, $forum_moderators);
    }
    return array($active_forum_ary, array());
}
예제 #12
0
 function display_forums(&$master)
 {
     global $user, $template, $config, $phpEx, $db, $auth, $cache, $phpbb_root_path;
     global $phpbb_seo;
     static $tpl = array('link' => '<a href="%1$s" title="%3$s">%2$s</a>', 'img' => '<img src="%1$s" alt="%2$s"/>');
     // Usefull for multi bb topic & forum tracking
     // Leave default for single forum eg : '_track'
     $tracking_cookie_name = (defined('XLANG_AKEY') ? XLANG_AKEY : '') . '_track';
     // Specific options
     $display_file =& $master->call['display_file'];
     $display_user_info =& $master->call['display_user_info'];
     $display_link =& $master->call['display_link'];
     $display_pagination =& $master->call['display_pagination'];
     $display_tracking =& $master->call['display_tracking'];
     $display_topic_status =& $master->call['display_topic_status'];
     $display_user_link = !empty($master->call['display_user_link']) ? true : false;
     $display_user_link_key = $display_user_link ? 'full' : 'no_profile';
     $display_last_post =& $master->call['display_last_post'];
     $forum_sql =& $master->call['forum_sql'];
     $forum_read_auth =& $master->actions['auth_view_read'];
     $forum_list_auth =& $master->actions['auth_view_list'];
     if (!$display_tracking) {
         $load_db_lastread = $load_anon_lastread = false;
     } else {
         $load_db_lastread = (bool) ($config['load_db_lastread'] && $user->data['is_registered']);
         $load_anon_lastread = (bool) ($config['load_anon_lastread'] || $user->data['is_registered']);
     }
     // Do some reset
     $forum_datas = $forum_ids = $sub_forums = array();
     $sql_array = array('SELECT' => 'f.*', 'FROM' => array(FORUMS_TABLE => 'f'), 'LEFT_JOIN' => array(), 'WHERE' => $forum_sql, 'ORDER_BY' => 'f.left_id ASC');
     // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe
     if (!empty($phpbb_seo->seo_opt['no_dupe']['on'])) {
         $sql_array['SELECT'] .= ', t.topic_id, t.topic_title, t.topic_replies, t.topic_replies_real, t.topic_status, t.topic_type, t.topic_moved_id' . (!empty($phpbb_seo->seo_opt['sql_rewrite']) ? ', t.topic_url ' : ' ');
         $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TABLE => 't'), 'ON' => "t.topic_last_post_id = f.forum_last_post_id");
     }
     // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe
     if ($load_db_lastread) {
         $sql_array['SELECT'] .= ', ft.mark_time as forum_mark_time';
         $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');
     } elseif ($load_anon_lastread && empty($master->tracking_topics)) {
         $master->tracking_topics = isset($_COOKIE[$config['cookie_name'] . $tracking_cookie_name]) ? STRIP ? stripslashes($_COOKIE[$config['cookie_name'] . $tracking_cookie_name]) : $_COOKIE[$config['cookie_name'] . $tracking_cookie_name] : '';
         $master->tracking_topics = $master->tracking_topics ? tracking_unserialize($master->tracking_topics) : array();
         if (!$user->data['is_registered']) {
             $user->data['user_lastmark'] = isset($master->tracking_topics['l']) ? (int) (base_convert($master->tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
         }
     }
     $right = 0;
     $level_store = array(0 => 0);
     $processed = array();
     $level = $last_level = 0;
     $html = $html_before = $html_after = '';
     $separator = ' &nbsp; ';
     $news_img = sprintf($tpl['img'], $master->gym_master->path_config['gym_img_url'] . 'html_news.gif', $user->lang['HTML_NEWS']);
     $map_img = sprintf($tpl['img'], $master->gym_master->path_config['gym_img_url'] . 'maps-icon.gif', $user->lang['HTML_MAP']);
     $subf_img = $user->img('subforum_read', 'NO_NEW_POSTS');
     $sql = $db->sql_build_query('SELECT', $sql_array);
     unset($sql_array);
     $result = $db->sql_query_limit($sql, 600);
     while ($row = $db->sql_fetchrow($result)) {
         $forum_id = (int) $row['forum_id'];
         //@TODO Find why in hell the above query could return more than one row per forum
         if (isset($processed[$forum_id])) {
             continue;
         }
         $processed[$forum_id] = $forum_id;
         $is_cat = $row['parent_id'] == 0 ? true : false;
         if (empty($master->forum_datas[$forum_id])) {
             // www.phpBB-SEO.com SEO TOOLKIT BEGIN
             $phpbb_seo->seo_url['forum'][$forum_id] = $phpbb_seo->set_url($row['forum_name'], $forum_id, $phpbb_seo->seo_static['forum']);
             // www.phpBB-SEO.com SEO TOOLKIT END
             $master->forum_datas[$forum_id] = array_merge($row, array('m_approve' => $auth->acl_get('m_approve', $forum_id), 'forum_name' => !empty($row['forum_name']) ? $row['forum_name'] : '', 'forum_status' => !empty($row['forum_status']) ? $row['forum_status'] : '', 'forum_last_post_time' => !empty($row['forum_last_post_time']) ? $row['forum_last_post_time'] : 0, 'enable_icons' => !empty($row['enable_icons']) ? $row['enable_icons'] : 0, 'forum_url' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", "f={$forum_id}")));
             if ($load_db_lastread) {
                 $master->forum_tracking_info[$forum_id] = !empty($row['forum_mark_time']) ? $row['forum_mark_time'] : $user->data['user_lastmark'];
             } elseif ($load_anon_lastread) {
                 $master->forum_tracking_info[$forum_id] = isset($master->tracking_topics['f'][$forum_id]) ? (int) (base_convert($master->tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
             }
         }
         $master->forum_datas[$forum_id]['forum_news_url'] = $master->forum_datas[$forum_id]['forum_map_url'] = '';
         if (!isset($root_forum_id)) {
             $root_forum_id = $forum_id;
             $sub_forums[$root_forum_id] = '';
         }
         $parent_id = (int) $row['parent_id'];
         if ($row['left_id'] < $right) {
             $level++;
             $level_store[$parent_id] = $level;
         } else {
             if ($row['left_id'] > $right + 1) {
                 if (isset($level_store[$parent_id])) {
                     $level = $level_store[$parent_id];
                 } else {
                     $level = 0;
                 }
             }
         }
         $right = (int) $row['right_id'];
         if ($level > 1) {
             // sub forums
             if ($level > $last_level) {
                 // going one or several level down
                 $diff = $level - $last_level;
                 $html_before = str_repeat("\n<ul><li>", $diff);
                 $html_after = "";
             }
             if ($level < $last_level) {
                 // Going one or several level up
                 $diff = $last_level - $level;
                 $html_before = str_repeat("</li></ul>\n", $diff) . "</li>\n<li>";
                 $html_after = "";
             }
             if ($level == $last_level) {
                 // Adding a link at the same level
                 $html_before = isset($forum_list_auth[$forum_id]) ? "</li>\n<li>" : '';
                 $html_after = "";
             }
             if ($display_tracking) {
                 $forum_unread = isset($master->forum_tracking_info[$forum_id]) && $master->forum_datas[$forum_id]['forum_last_post_time'] > $master->forum_tracking_info[$forum_id] ? true : false;
                 if ($forum_unread) {
                     $folder_image = 'subforum_unread';
                     $folder_alt = 'NEW_POSTS';
                 } else {
                     $folder_image = 'subforum_read';
                     $folder_alt = 'NO_NEW_POSTS';
                 }
                 $subf_img = $user->img($folder_image, $folder_alt);
             }
             $link = '';
             if (isset($forum_list_auth[$forum_id])) {
                 if (!empty($row['forum_topics']) && (isset($forum_read_auth[$forum_id]) || $is_cat)) {
                     if ($master->module_config['html_allow_cat_news']) {
                         $title = sprintf($user->lang['HTML_NEWS_OF'], $row['forum_name']);
                         $link = isset($forum_read_auth[$forum_id]) ? sprintf($tpl['link'], append_sid($master->module_config['html_url'] . $master->gym_master->html_build_url('html_forum_cat_news', $phpbb_seo->seo_url['forum'][$forum_id], $forum_id)), $news_img . ' ' . $title, $title) : $title;
                     }
                     if ($master->module_config['html_allow_cat_map']) {
                         $title = sprintf($user->lang['HTML_MAP_OF'], $row['forum_name']);
                         $link .= $separator . (isset($forum_read_auth[$forum_id]) ? sprintf($tpl['link'], append_sid($master->module_config['html_url'] . $master->gym_master->html_build_url('html_forum_cat_map', $phpbb_seo->seo_url['forum'][$forum_id], $forum_id)), $map_img . ' ' . $title, $title) : $title);
                     }
                 } else {
                     $title = $link = '<b>' . $row['forum_name'] . '</b>';
                 }
             }
             $sub_forums[$root_forum_id] .= $html_before . $link . $html_after;
         } else {
             $forum_datas[$forum_id] = array_merge(array('level' => $level), $row);
             $forum_ids[$forum_id] = $forum_id;
             if ($level < $last_level) {
                 // We went up in this root forum
                 $_level = $level > 0 ? 0 : 1;
                 $sub_forums[$root_forum_id] .= str_repeat("</li></ul>\n", $last_level - $level - $_level);
             }
             if ($level == 1) {
                 // next root forum
                 $root_forum_id = $forum_id;
                 $sub_forums[$root_forum_id] = '';
             }
         }
         $last_level = $level;
     }
     unset($processed);
     if (!empty($sub_forums[$root_forum_id]) && $last_level > 1) {
         // In case we need to close the last sub forum tag
         $sub_forums[$root_forum_id] .= str_repeat("</li></ul>\n", $last_level - 1);
     }
     $db->sql_freeresult($result);
     // Let's go
     $has_result = false;
     if (!empty($forum_datas)) {
         $has_result = true;
         // Grab icons
         if (empty($master->icons)) {
             $master->icons = $cache->obtain_icons();
         }
         $s_type_switch = 0;
         $last_catless = true;
         $root_data = array('forum_id' => 0);
         $s_is_cat = true;
         $level = 0;
         $folder_alt = 'NO_NEW_POSTS';
         $folder_image = 'forum_read';
         $forum_folder_img = $user->img($folder_image, $folder_alt);
         $forum_folder_img_src = $user->img($folder_image, $folder_alt, false, '', 'src');
         // Let's go
         foreach ($forum_ids as $forum_id) {
             $row =& $forum_datas[$forum_id];
             $catless = $row['level'] == 0 ? true : false;
             $is_cat = $row['parent_id'] == 0 ? true : false;
             if (!isset($forum_list_auth[$forum_id]) || $row['forum_type'] == FORUM_LINK) {
                 continue;
             }
             $forum_map_link = $forum_news_link = $forum_map_title = $forum_news_title = '';
             if (!empty($row['forum_topics']) && (isset($forum_read_auth[$forum_id]) || $is_cat)) {
                 if ($master->module_config['html_allow_cat_map']) {
                     $forum_map_title = sprintf($user->lang['HTML_MAP_OF'], $row['forum_name']);
                     $forum_map_link = sprintf($tpl['link'], append_sid($master->module_config['html_url'] . $master->gym_master->html_build_url('html_forum_cat_map', $phpbb_seo->seo_url['forum'][$forum_id], $forum_id)), $map_img . ' ' . $forum_map_title, $forum_map_title);
                 }
                 if ($master->module_config['html_allow_cat_news']) {
                     $forum_news_title = sprintf($user->lang['HTML_NEWS_OF'], $row['forum_name']);
                     $forum_news_link = sprintf($tpl['link'], append_sid($master->module_config['html_url'] . $master->gym_master->html_build_url('html_forum_cat_news', $phpbb_seo->seo_url['forum'][$forum_id], $forum_id)), $news_img . ' ' . $forum_news_title, $forum_news_title);
                 }
             } else {
                 $forum_news_title = $forum_news_link = '<b>' . $row['forum_name'] . '</b>';
                 $forum_news_link .= '<br/>';
             }
             $forum_unread = isset($master->forum_tracking_info[$forum_id]) && $master->forum_datas[$forum_id]['forum_last_post_time'] > $master->forum_tracking_info[$forum_id] ? true : false;
             if ($display_topic_status) {
                 // Which folder should we display?
                 $folder_alt = $forum_unread ? 'NEW_POSTS' : 'NO_NEW_POSTS';
                 if (!empty($sub_forums[$forum_id])) {
                     $folder_image = $forum_unread ? 'forum_unread_subforum' : 'forum_read_subforum';
                 } else {
                     if ($row['forum_status'] == ITEM_LOCKED) {
                         $folder_image = $forum_unread ? 'forum_unread_locked' : 'forum_read_locked';
                         $folder_alt = 'FORUM_LOCKED';
                     } else {
                         if ($row['forum_type'] == FORUM_POST) {
                             $folder_image = $forum_unread ? 'forum_unread' : 'forum_read';
                         } else {
                             $folder_image = 'forum_link';
                         }
                     }
                 }
                 $forum_folder_img = $user->img($folder_image, $folder_alt);
                 $forum_folder_img_src = $user->img($folder_image, $folder_alt, false, '', 'src');
             }
             $tpl_data = array('S_IS_CAT' => $is_cat, 'S_NO_CAT' => $catless && !$last_catless ? true : false, 'FORUM_ID' => $forum_id, 'FORUM_NAME' => $forum_map_title, 'FORUM_NEWS' => $forum_news_title, 'FORUM_MAP_LINK' => $forum_map_link, 'FORUM_NEWS_LINK' => $forum_news_link);
             if (!$is_cat) {
                 $tpl_data += array('FORUM_DESC' => $master->call['display_desc'] && !$is_cat ? $master->generate_forum_info($row) : '', 'FORUM_FOLDER_IMG' => $forum_folder_img, 'FORUM_FOLDER_IMG_SRC' => $forum_folder_img_src, 'FORUM_FOLDER_IMG_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'] : '', 'SUBFORUMS' => !empty($sub_forums[$forum_id]) ? $sub_forums[$forum_id] : '');
                 if ($display_last_post) {
                     // 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']);
                         if (!empty($phpbb_seo->seo_opt['no_dupe']['on']) && !empty($row['topic_id']) && !$row['forum_password']) {
                             if ($row['topic_status'] == ITEM_MOVED) {
                                 $row['topic_id'] = $row['topic_moved_id'];
                             }
                             $topic_id = (int) $row['topic_id'];
                             $row['topic_title'] = censor_text($row['topic_title']);
                             // www.phpBB-SEO.com SEO TOOLKIT BEGIN
                             $phpbb_seo->prepare_iurl($row, 'topic', $row['topic_type'] == POST_GLOBAL ? $phpbb_seo->seo_static['global_announce'] : $phpbb_seo->seo_url['forum'][$forum_id]);
                             // www.phpBB-SEO.com SEO TOOLKIT END
                             $last_post_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&amp;t={$topic_id}&amp;start=" . @intval($phpbb_seo->seo_opt['topic_last_page'][$topic_id])) . '#p' . $row['forum_last_post_id'];
                             $last_post_link = '<a href="' . append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&amp;t={$topic_id}") . '" title="' . $row['topic_title'] . ' : ' . $row['forum_name'] . '">' . $row['topic_title'] . '</a>';
                         } else {
                             $last_post_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&amp;p=" . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
                             $last_post_link = '';
                         }
                     } else {
                         $last_post_subject = $last_post_time = $last_post_url = $last_post_link = '';
                     }
                     $tpl_data += array('LAST_POST_SUBJECT' => censor_text($last_post_subject), 'LAST_POST_TIME' => $last_post_time, 'LAST_POST_LINK' => $last_post_link, 'U_LAST_POST' => $last_post_url);
                     if ($display_user_info) {
                         $tpl_data += array('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($display_user_link_key, $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']));
                     }
                 }
             }
             $template->assign_block_vars('forumrow', $tpl_data);
             $last_catless = $catless;
             unset($forum_datas[$forum_id]);
         }
     }
     $map_desc = false;
     if ($master->call['display_desc']) {
         $map_desc = !empty($master->module_config['html_site_desc']) ? $master->module_config['html_site_desc'] : '';
     }
     $template->assign_vars(array('H1_FORUMS' => $master->module_config['html_sitename'], 'DISPLAY_FORUMS_H1' => $display_link, 'U_FORUMS' => $display_link ? append_sid("{$phpbb_root_path}index.{$phpEx}") : false, 'FORUM_MAP_URL' => $master->module_config['html_allow_map'] ? append_sid($master->module_config['html_url'] . $master->url_settings['html_forum_map']) : '', 'FORUM_NEWS' => sprintf($user->lang['HTML_NEWS_OF'], $master->module_config['html_sitename']), 'NEWS_IMG_SRC' => $master->gym_master->path_config['gym_img_url'] . 'html_news.gif', 'FORUM_NEWS_URL' => $master->module_config['html_allow_news'] ? append_sid($master->module_config['html_url'] . $master->url_settings['html_forum_news']) : '', 'DISPLAY_FORUMS' => $has_result, 'DISPLAY_USER_INFO' => $display_user_info, 'DISPLAY_LAST_POST' => $display_last_post, 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'MAP_DESC' => $map_desc));
 }
function display_recent_topics($topics_per_page, $num_pages, $excluded_topics, $tpl_loopname = 'recenttopicrow', $spec_forum_id = 0, $include_subforums = true, $display_parent_forums = true)
{
    global $auth, $cache, $config, $db, $template, $user;
    global $phpbb_root_path, $phpEx;
    $user->add_lang('mods/info_acp_recenttopics');
    /**
     * Set some internal needed variables
     */
    $start = request_var($tpl_loopname . '_start', 0);
    $excluded_topic_ids = explode(', ', $excluded_topics);
    $total_limit = $topics_per_page * $num_pages;
    $ga_forum_id = 0;
    // Forum id we use for global announcements
    /**
     * Get the forums we take our topics from
     */
    // Get the allowed forums
    $forum_ary = array();
    $forum_read_ary = $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 = ' . $spec_forum_id . '
					AND forum_recent_topics = 1';
            $result = $db->sql_query_limit($sql, 1);
            $display_forum = (bool) $db->sql_fetchfield('display_forum');
            $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\tON (f2.left_id BETWEEN f1.left_id AND f1.right_id\n\t\t\t\t\t\tAND f2.forum_recent_topics = 1)\n\t\t\t\tWHERE f1.forum_id = {$spec_forum_id}\n\t\t\t\t\tAND f1.forum_recent_topics = 1\n\t\t\t\tORDER BY f2.left_id DESC";
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                $spec_forum_ary[] = $row['forum_id'];
            }
            $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 ' . $db->sql_in_set('forum_id', $forum_ids) . '
				AND forum_recent_topics = 1';
        $result = $db->sql_query($sql);
        $forum_ids = array();
        while ($row = $db->sql_fetchrow($result)) {
            $forum_ids[] = $row['forum_id'];
        }
        $db->sql_freeresult($result);
    }
    // No forums with f_read
    if (!sizeof($forum_ids)) {
        return;
    }
    // Moderator forums
    $m_approve_ids = array();
    $m_approve_ary = $auth->acl_getf('m_approve');
    foreach ($m_approve_ary as $forum_id => $allowed) {
        if ($allowed['m_approve'] && in_array($forum_id, $forum_ids)) {
            $m_approve_ids[] = (int) $forum_id;
        }
    }
    // Get the allowed topics
    $sql_query_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 = ' . $user->data['user_id']), array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id'])), 'WHERE' => '
			(
				(' . $db->sql_in_set('t.topic_id', $excluded_topic_ids, true) . '
					AND ' . $db->sql_in_set('t.forum_id', $forum_ids) . '
				)
				OR t.topic_type = ' . POST_GLOBAL . '
			)
			AND t.topic_status <> ' . ITEM_MOVED . '
			AND (' . $db->sql_in_set('t.forum_id', $m_approve_ids, false, true) . '
				OR t.topic_approved = 1)', 'ORDER_BY' => 't.topic_last_post_time DESC');
    // Is a soft delete MOD installed?
    if (file_exists("{$phpbb_root_path}includes/mods/soft_delete.{$phpEx}")) {
        $sql_query_array['WHERE'] .= ' AND topic_deleted = 0';
    }
    $sql = $db->sql_build_query('SELECT', $sql_query_array);
    $result = $db->sql_query_limit($sql, $total_limit);
    $forums = $ga_topic_ids = $topic_ids = array();
    $num_topics = 0;
    $obtain_icons = false;
    while ($row = $db->sql_fetchrow($result)) {
        $num_topics++;
        if ($num_topics > $start && $num_topics <= $start + $topics_per_page) {
            $topic_ids[] = $row['topic_id'];
            $rowset[$row['topic_id']] = $row;
            if (!isset($forums[$row['forum_id']]) && $user->data['is_registered'] && $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'] && $auth->acl_get('f_icons', $row['forum_id'])) {
                $obtain_icons = true;
            }
        }
    }
    $db->sql_freeresult($result);
    // No topics to display
    if (!sizeof($topic_ids)) {
        return;
    }
    // Grab icons
    if ($obtain_icons) {
        $icons = $cache->obtain_icons();
    } else {
        $icons = array();
    }
    // Borrowed from search.php
    foreach ($forums as $forum_id => $forum) {
        if ($user->data['is_registered'] && $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 ($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();
                $topic_tracking_info[$forum_id] = get_complete_topic_tracking($forum_id, $forum['topic_list'], $forum_id ? false : $forum['topic_list']);
                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;
                }
            }
        }
    }
    // Now only pull the data of the requested topics
    $sql_query_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 = ' . $user->data['user_id']), array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id')), 'WHERE' => $db->sql_in_set('t.topic_id', $topic_ids), 'ORDER_BY' => 't.topic_last_post_time DESC');
    if ($display_parent_forums) {
        $sql_query_array['SELECT'] .= ', f.parent_id, f.forum_parents, f.left_id, f.right_id';
    }
    $sql = $db->sql_build_query('SELECT', $sql_query_array);
    $result = $db->sql_query_limit($sql, $topics_per_page);
    $topic_icons = array();
    while ($row = $db->sql_fetchrow($result)) {
        $topic_id = $row['topic_id'];
        $forum_id = $row['forum_id'];
        // Cheat for Global Announcements on the unread-link: copied from search.php
        if (!$forum_id && !$ga_forum_id) {
            $sql2 = 'SELECT forum_id
				FROM ' . FORUMS_TABLE . '
				WHERE forum_type = ' . FORUM_POST . '
					AND ' . $db->sql_in_set('forum_id', $forum_ary, false, true);
            $result2 = $db->sql_query_limit($sql2, 1);
            $ga_forum_id = (int) $db->sql_fetchfield('forum_id');
            $db->sql_freeresult($result2);
            $forum_id = $ga_forum_id;
        } else {
            if (!$forum_id && $ga_forum_id) {
                $forum_id = $ga_forum_id;
            }
        }
        $s_type_switch_test = $row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL ? 1 : 0;
        $replies = $auth->acl_get('m_approve', $forum_id) ? $row['topic_replies_real'] : $row['topic_replies'];
        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("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $forum_id . '&amp;t=' . $topic_id);
        $view_forum_url = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id);
        $topic_unapproved = !$row['topic_approved'] && $auth->acl_get('m_approve', $forum_id) ? true : false;
        $posts_unapproved = $row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $forum_id) ? true : false;
        $u_mcp_queue = $topic_unapproved || $posts_unapproved ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue&amp;mode=' . ($topic_unapproved ? 'approve_details' : 'unapproved_posts') . "&amp;t={$topic_id}", true, $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;
        }
        $template->assign_block_vars($tpl_loopname, array('FORUM_ID' => $forum_id, 'TOPIC_ID' => $topic_id, 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'FIRST_POST_TIME' => $user->format_date($row['topic_time']), 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']), 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']), 'LAST_VIEW_TIME' => $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']), 'PAGINATION' => topic_generate_pagination($replies, $view_topic_url), 'REPLIES' => $replies, 'VIEWS' => $row['topic_views'], 'TOPIC_TITLE' => censor_text($row['topic_title']), 'FORUM_NAME' => $row['forum_name'], 'TOPIC_TYPE' => $topic_type, 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt), 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'), 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt], 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), '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' => $auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment'] ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', 'UNAPPROVED_IMG' => $topic_unapproved || $posts_unapproved ? $user->img('icon_topic_unapproved', $topic_unapproved ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', 'REPORTED_IMG' => $row['topic_reported'] && $auth->acl_get('m_report', $forum_id) ? $user->img('icon_topic_reported', 'TOPIC_REPORTED') : '', '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'] && $auth->acl_get('m_report', $forum_id) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, 'S_HAS_POLL' => $row['poll_start'] ? true : false, '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("{$phpbb_root_path}mcp.{$phpEx}", 'i=reports&amp;mode=reports&amp;f=' . $forum_id . '&amp;t=' . $topic_id, true, $user->session_id), 'U_MCP_QUEUE' => $u_mcp_queue));
        if ($display_parent_forums) {
            $forum_parents = get_forum_parents($row);
            foreach ($forum_parents as $parent_id => $data) {
                $template->assign_block_vars($tpl_loopname . '.parent_forums', array('FORUM_ID' => $parent_id, 'FORUM_NAME' => $data[0], 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $parent_id)));
            }
        }
    }
    $db->sql_freeresult($result);
    // Get URL-parameters for pagination
    $url_params = explode('&', $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;
        }
    }
    $template->assign_vars(array('S_TOPIC_ICONS' => sizeof($topic_icons) ? true : false, 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'), strtoupper($tpl_loopname) . '_DISPLAY' => true, strtoupper($tpl_loopname) . '_PAGE_NUMBER' => on_page($num_topics, $topics_per_page, $start), strtoupper($tpl_loopname) . '_PAGINATION' => recent_topics_generate_pagination(append_sid($phpbb_root_path . $user->page['page_name'], $append_params), $num_topics, $topics_per_page, $start, false, strtoupper($tpl_loopname), $tpl_loopname . '_start', $tpl_loopname)));
}
예제 #14
0
function tt_get_unread_topics($user_id = false, $sql_extra = '', $sql_sort = '', $sql_limit = 1001, $sql_limit_offset = 0)
{
    global $config, $db, $user;
    $user_id = $user_id === false ? (int) $user->data['user_id'] : (int) $user_id;
    // Data array we're going to return
    $unread_topics = array();
    if (empty($sql_sort)) {
        $sql_sort = 'ORDER BY t.topic_last_post_time DESC';
    }
    if ($config['load_db_lastread'] && $user->data['is_registered']) {
        // Get list of the unread topics
        $last_mark = (int) $user->data['user_lastmark'];
        $sql_array = array('SELECT' => 't.topic_id, t.topic_last_post_time, tt.mark_time as topic_mark_time, ft.mark_time as forum_mark_time', 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => "tt.user_id = {$user_id} AND t.topic_id = tt.topic_id"), array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => "ft.user_id = {$user_id} AND t.forum_id = ft.forum_id")), 'WHERE' => "\r\r\n                 t.topic_last_post_time > {$last_mark} AND\r\r\n                (\r\r\n                (tt.mark_time IS NOT NULL AND t.topic_last_post_time > tt.mark_time) OR\r\r\n                (tt.mark_time IS NULL AND ft.mark_time IS NOT NULL AND t.topic_last_post_time > ft.mark_time) OR\r\r\n                (tt.mark_time IS NULL AND ft.mark_time IS NULL)\r\r\n                )\r\r\n                {$sql_extra}\r\r\n                {$sql_sort}");
        $sql = $db->sql_build_query('SELECT', $sql_array);
        $result = $db->sql_query_limit($sql, $sql_limit, $sql_limit_offset);
        while ($row = $db->sql_fetchrow($result)) {
            $topic_id = (int) $row['topic_id'];
            $unread_topics[$topic_id] = $row['topic_mark_time'] ? (int) $row['topic_mark_time'] : ($row['forum_mark_time'] ? (int) $row['forum_mark_time'] : $last_mark);
        }
        $db->sql_freeresult($result);
    } else {
        if ($config['load_anon_lastread'] || $user->data['is_registered']) {
            global $tracking_topics;
            if (empty($tracking_topics)) {
                $tracking_topics = request_var($config['cookie_name'] . '_track', '', false, true);
                $tracking_topics = $tracking_topics ? tracking_unserialize($tracking_topics) : array();
            }
            if (!$user->data['is_registered']) {
                $user_lastmark = isset($tracking_topics['l']) ? base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate'] : 0;
            } else {
                $user_lastmark = (int) $user->data['user_lastmark'];
            }
            $sql = 'SELECT t.topic_id, t.forum_id, t.topic_last_post_time
            FROM ' . TOPICS_TABLE . ' t
            WHERE t.topic_last_post_time > ' . $user_lastmark . "\r\r\n            {$sql_extra}\r\r\n            {$sql_sort}";
            $result = $db->sql_query_limit($sql, $sql_limit, $sql_limit_offset);
            while ($row = $db->sql_fetchrow($result)) {
                $forum_id = (int) $row['forum_id'];
                $topic_id = (int) $row['topic_id'];
                $topic_id36 = base_convert($topic_id, 10, 36);
                if (isset($tracking_topics['t'][$topic_id36])) {
                    $last_read = base_convert($tracking_topics['t'][$topic_id36], 36, 10) + $config['board_startdate'];
                    if ($row['topic_last_post_time'] > $last_read) {
                        $unread_topics[$topic_id] = $last_read;
                    }
                } else {
                    if (isset($tracking_topics['f'][$forum_id])) {
                        $mark_time = base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate'];
                        if ($row['topic_last_post_time'] > $mark_time) {
                            $unread_topics[$topic_id] = $mark_time;
                        }
                    } else {
                        $unread_topics[$topic_id] = $user_lastmark;
                    }
                }
            }
            $db->sql_freeresult($result);
        }
    }
    return $unread_topics;
}
예제 #15
0
    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
        switch ($mode) {
            case 'front':
                $user->add_lang('memberlist');
                $sql_from = TOPICS_TABLE . ' t ';
                $sql_select = '';
                if ($config['load_db_track']) {
                    $sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.topic_id = t.topic_id
						AND tp.user_id = ' . $user->data['user_id'] . ')';
                    $sql_select .= ', tp.topic_posted';
                }
                if ($config['load_db_lastread']) {
                    $sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id
						AND tt.user_id = ' . $user->data['user_id'] . ')';
                    $sql_select .= ', tt.mark_time';
                }
                $topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
                $folder = 'global_read';
                $folder_new = 'global_unread';
                // Get cleaned up list... return only those forums not having the f_read permission
                $forum_ary = $auth->acl_getf('!f_read', true);
                $forum_ary = array_unique(array_keys($forum_ary));
                // Determine first forum the user is able to read into - for global announcement link
                $sql = 'SELECT forum_id
					FROM ' . FORUMS_TABLE . '
					WHERE forum_type = ' . FORUM_POST;
                if (sizeof($forum_ary)) {
                    $sql .= ' AND ' . $db->sql_in_set('forum_id', $forum_ary, true);
                }
                $result = $db->sql_query_limit($sql, 1);
                $g_forum_id = (int) $db->sql_fetchfield('forum_id');
                $db->sql_freeresult($result);
                $sql = "SELECT t.* {$sql_select}\n\t\t\t\t\tFROM {$sql_from}\n\t\t\t\t\tWHERE t.forum_id = 0\n\t\t\t\t\t\tAND t.topic_type = " . POST_GLOBAL . '
					ORDER BY t.topic_last_post_time DESC';
                $topic_list = $rowset = array();
                // If the user can't see any forums, he can't read any posts because fid of 0 is invalid
                if ($g_forum_id) {
                    $result = $db->sql_query($sql);
                    while ($row = $db->sql_fetchrow($result)) {
                        $topic_list[] = $row['topic_id'];
                        $rowset[$row['topic_id']] = $row;
                    }
                    $db->sql_freeresult($result);
                }
                $topic_tracking_info = array();
                if ($config['load_db_lastread']) {
                    $topic_tracking_info = get_topic_tracking(0, $topic_list, $rowset, false, $topic_list);
                } else {
                    $topic_tracking_info = get_complete_topic_tracking(0, $topic_list, $topic_list);
                }
                foreach ($topic_list as $topic_id) {
                    $row =& $rowset[$topic_id];
                    $forum_id = $row['forum_id'];
                    $topic_id = $row['topic_id'];
                    $unread_topic = isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id] ? true : false;
                    $folder_img = $unread_topic ? $folder_new : $folder;
                    $folder_alt = $unread_topic ? 'NEW_POSTS' : ($row['topic_status'] == ITEM_LOCKED ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS');
                    if ($row['topic_status'] == ITEM_LOCKED) {
                        $folder_img .= '_locked';
                    }
                    // Posted image?
                    if (!empty($row['topic_posted']) && $row['topic_posted']) {
                        $folder_img .= '_mine';
                    }
                    $template->assign_block_vars('topicrow', 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' => $user->format_date($row['topic_time']), 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']), 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']), 'LAST_VIEW_TIME' => $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']), 'TOPIC_TITLE' => censor_text($row['topic_title']), 'TOPIC_TYPE' => $topic_type, 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt), 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'), 'ATTACH_ICON_IMG' => $auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment'] ? $user->img('icon_topic_attach', '') : '', 'S_USER_POSTED' => !empty($row['topic_posted']) && $row['topic_posted'] ? true : false, 'S_UNREAD' => $unread_topic, 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$g_forum_id}&amp;t={$topic_id}&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_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$g_forum_id}&amp;t={$topic_id}&amp;view=unread") . '#unread', 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$g_forum_id}&amp;t={$topic_id}")));
                }
                if ($config['load_user_activity']) {
                    if (!function_exists('display_user_activity')) {
                        include_once $phpbb_root_path . 'includes/functions_display.' . $phpEx;
                    }
                    display_user_activity($user->data);
                }
                // Do the relevant calculations
                $memberdays = max(1, round((time() - $user->data['user_regdate']) / 86400));
                $posts_per_day = $user->data['user_posts'] / $memberdays;
                $percentage = $config['num_posts'] ? min(100, $user->data['user_posts'] / $config['num_posts'] * 100) : 0;
                $template->assign_vars(array('USER_COLOR' => !empty($user->data['user_colour']) ? $user->data['user_colour'] : '', 'JOINED' => $user->format_date($user->data['user_regdate']), 'VISITED' => empty($last_visit) ? ' - ' : $user->format_date($last_visit), 'WARNINGS' => $user->data['user_warnings'] ? $user->data['user_warnings'] : 0, 'POSTS' => $user->data['user_posts'] ? $user->data['user_posts'] : 0, 'POSTS_DAY' => sprintf($user->lang['POST_DAY'], $posts_per_day), 'POSTS_PCT' => sprintf($user->lang['POST_PCT'], $percentage), 'OCCUPATION' => !empty($row['user_occ']) ? $row['user_occ'] : '', 'INTERESTS' => !empty($row['user_interests']) ? $row['user_interests'] : '', 'U_SEARCH_USER' => $auth->acl_get('u_search') ? append_sid("{$phpbb_root_path}search.{$phpEx}", 'author_id=' . $user->data['user_id'] . '&amp;sr=posts') : ''));
                break;
            case 'subscribed':
                include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
                $user->add_lang('viewforum');
                add_form_key('ucp_front_subscribed');
                $unwatch = isset($_POST['unwatch']) ? true : false;
                if ($unwatch) {
                    if (check_form_key('ucp_front_subscribed')) {
                        $forums = array_keys(request_var('f', array(0 => 0)));
                        $topics = array_keys(request_var('t', array(0 => 0)));
                        $msg = '';
                        if (sizeof($forums) || sizeof($topics)) {
                            $l_unwatch = '';
                            if (sizeof($forums)) {
                                $sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . '
									WHERE ' . $db->sql_in_set('forum_id', $forums) . '
										AND user_id = ' . $user->data['user_id'];
                                $db->sql_query($sql);
                                $l_unwatch .= '_FORUMS';
                            }
                            if (sizeof($topics)) {
                                $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . '
									WHERE ' . $db->sql_in_set('topic_id', $topics) . '
										AND user_id = ' . $user->data['user_id'];
                                $db->sql_query($sql);
                                $l_unwatch .= '_TOPICS';
                            }
                            $msg = $user->lang['UNWATCHED' . $l_unwatch];
                        } else {
                            $msg = $user->lang['NO_WATCHED_SELECTED'];
                        }
                    } else {
                        $msg = $user->lang['FORM_INVALID'];
                    }
                    $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i={$id}&amp;mode=subscribed") . '">', '</a>');
                    meta_refresh(3, append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i={$id}&amp;mode=subscribed"));
                    trigger_error($message);
                }
                $forbidden_forums = array();
                if ($config['allow_forum_notify']) {
                    $forbidden_forums = $auth->acl_getf('!f_read', true);
                    $forbidden_forums = array_unique(array_keys($forbidden_forums));
                    $sql_array = array('SELECT' => 'f.*', 'FROM' => array(FORUMS_WATCH_TABLE => 'fw', FORUMS_TABLE => 'f'), 'WHERE' => 'fw.user_id = ' . $user->data['user_id'] . '
							AND f.forum_id = fw.forum_id
							AND ' . $db->sql_in_set('f.forum_id', $forbidden_forums, true, true), 'ORDER_BY' => 'left_id');
                    if ($config['load_db_lastread']) {
                        $sql_array['LEFT_JOIN'] = array(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 {
                        $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();
                    }
                    $sql = $db->sql_build_query('SELECT', $sql_array);
                    $result = $db->sql_query($sql);
                    while ($row = $db->sql_fetchrow($result)) {
                        $forum_id = $row['forum_id'];
                        if ($config['load_db_lastread']) {
                            $forum_check = !empty($row['mark_time']) ? $row['mark_time'] : $user->data['user_lastmark'];
                        } else {
                            $forum_check = isset($tracking_topics['f'][$forum_id]) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
                        }
                        $unread_forum = $row['forum_last_post_time'] > $forum_check ? true : false;
                        // Which folder should we display?
                        if ($row['forum_status'] == ITEM_LOCKED) {
                            $folder_image = $unread_forum ? 'forum_unread_locked' : 'forum_read_locked';
                            $folder_alt = 'FORUM_LOCKED';
                        } else {
                            $folder_image = $unread_forum ? 'forum_unread' : 'forum_read';
                            $folder_alt = $unread_forum ? 'NEW_POSTS' : 'NO_NEW_POSTS';
                        }
                        // Create last post link information, if appropriate
                        if ($row['forum_last_post_id']) {
                            $last_post_time = $user->format_date($row['forum_last_post_time']);
                            $last_post_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&amp;p=" . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
                        } else {
                            $last_post_time = $last_post_url = '';
                        }
                        $template->assign_block_vars('forumrow', array('FORUM_ID' => $forum_id, 'FORUM_FOLDER_IMG' => $user->img($folder_image, $folder_alt), 'FORUM_FOLDER_IMG_SRC' => $user->img($folder_image, $folder_alt, false, '', 'src'), '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'] : '', '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']), 'LAST_POST_SUBJECT' => $row['forum_last_post_subject'], 'LAST_POST_TIME' => $last_post_time, 'LAST_POST_AUTHOR' => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), 'U_LAST_POST_AUTHOR' => 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, 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id'])));
                    }
                    $db->sql_freeresult($result);
                }
                // Subscribed Topics
                if ($config['allow_topic_notify']) {
                    if (empty($forbidden_forums)) {
                        $forbidden_forums = $auth->acl_getf('!f_read', true);
                        $forbidden_forums = array_unique(array_keys($forbidden_forums));
                    }
                    $this->assign_topiclist('subscribed', $forbidden_forums);
                }
                $template->assign_vars(array('S_TOPIC_NOTIFY' => $config['allow_topic_notify'], 'S_FORUM_NOTIFY' => $config['allow_forum_notify']));
                break;
            case 'bookmarks':
                if (!$config['allow_bookmarks']) {
                    $template->assign_vars(array('S_NO_DISPLAY_BOOKMARKS' => true));
                    break;
                }
                include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
                $user->add_lang('viewforum');
                if (isset($_POST['unbookmark'])) {
                    $s_hidden_fields = array('unbookmark' => 1);
                    $topics = isset($_POST['t']) ? array_keys(request_var('t', array(0 => 0))) : array();
                    $url = $this->u_action;
                    if (!sizeof($topics)) {
                        trigger_error('NO_BOOKMARKS_SELECTED');
                    }
                    foreach ($topics as $topic_id) {
                        $s_hidden_fields['t'][$topic_id] = 1;
                    }
                    if (confirm_box(true)) {
                        $sql = 'DELETE FROM ' . BOOKMARKS_TABLE . '
							WHERE user_id = ' . $user->data['user_id'] . '
								AND ' . $db->sql_in_set('topic_id', $topics);
                        $db->sql_query($sql);
                        meta_refresh(3, $url);
                        $message = $user->lang['BOOKMARKS_REMOVED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $url . '">', '</a>');
                        trigger_error($message);
                    } else {
                        confirm_box(false, 'REMOVE_SELECTED_BOOKMARKS', build_hidden_fields($s_hidden_fields));
                    }
                }
                $forbidden_forums = $auth->acl_getf('!f_read', true);
                $forbidden_forums = array_unique(array_keys($forbidden_forums));
                $this->assign_topiclist('bookmarks', $forbidden_forums);
                break;
            case 'drafts':
                $pm_drafts = $this->p_master->p_name == 'pm' ? true : false;
                $template->assign_var('S_SHOW_DRAFTS', true);
                $user->add_lang('posting');
                $edit = isset($_REQUEST['edit']) ? true : false;
                $submit = isset($_POST['submit']) ? true : false;
                $draft_id = $edit ? intval($_REQUEST['edit']) : 0;
                $delete = isset($_POST['delete']) ? true : false;
                $s_hidden_fields = $edit ? '<input type="hidden" name="edit" value="' . $draft_id . '" />' : '';
                $draft_subject = $draft_message = '';
                add_form_key('ucp_draft');
                if ($delete) {
                    if (check_form_key('ucp_draft')) {
                        $drafts = array_keys(request_var('d', array(0 => 0)));
                        if (sizeof($drafts)) {
                            $sql = 'DELETE FROM ' . DRAFTS_TABLE . '
								WHERE ' . $db->sql_in_set('draft_id', $drafts) . '
									AND user_id = ' . $user->data['user_id'];
                            $db->sql_query($sql);
                        }
                        $msg = $user->lang['DRAFTS_DELETED'];
                        unset($drafts);
                    } else {
                        $msg = $user->lang['FORM_INVALID'];
                    }
                    $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
                    meta_refresh(3, $this->u_action);
                    trigger_error($message);
                }
                if ($submit && $edit) {
                    $draft_subject = utf8_normalize_nfc(request_var('subject', '', true));
                    $draft_message = utf8_normalize_nfc(request_var('message', '', true));
                    if (check_form_key('ucp_draft')) {
                        if ($draft_message && $draft_subject) {
                            $draft_row = array('draft_subject' => $draft_subject, 'draft_message' => $draft_message);
                            $sql = 'UPDATE ' . DRAFTS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $draft_row) . "\n\t\t\t\t\t\t\t\tWHERE draft_id = {$draft_id}\n\t\t\t\t\t\t\t\t\tAND user_id = " . $user->data['user_id'];
                            $db->sql_query($sql);
                            $message = $user->lang['DRAFT_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
                            meta_refresh(3, $this->u_action);
                            trigger_error($message);
                        } else {
                            $template->assign_var('ERROR', $draft_message == '' ? $user->lang['EMPTY_DRAFT'] : ($draft_subject == '' ? $user->lang['EMPTY_DRAFT_TITLE'] : ''));
                        }
                    } else {
                        $template->assign_var('ERROR', $user->lang['FORM_INVALID']);
                    }
                }
                if (!$pm_drafts) {
                    $sql = 'SELECT d.*, f.forum_name
						FROM ' . DRAFTS_TABLE . ' d, ' . FORUMS_TABLE . ' f
						WHERE d.user_id = ' . $user->data['user_id'] . ' ' . ($edit ? "AND d.draft_id = {$draft_id}" : '') . '
							AND f.forum_id = d.forum_id
						ORDER BY d.save_time DESC';
                } else {
                    $sql = 'SELECT * FROM ' . DRAFTS_TABLE . '
						WHERE user_id = ' . $user->data['user_id'] . ' ' . ($edit ? "AND draft_id = {$draft_id}" : '') . '
							AND forum_id = 0
							AND topic_id = 0
						ORDER BY save_time DESC';
                }
                $result = $db->sql_query($sql);
                $draftrows = $topic_ids = array();
                while ($row = $db->sql_fetchrow($result)) {
                    if ($row['topic_id']) {
                        $topic_ids[] = (int) $row['topic_id'];
                    }
                    $draftrows[] = $row;
                }
                $db->sql_freeresult($result);
                if (sizeof($topic_ids)) {
                    $sql = 'SELECT topic_id, forum_id, topic_title
						FROM ' . TOPICS_TABLE . '
						WHERE ' . $db->sql_in_set('topic_id', array_unique($topic_ids));
                    $result = $db->sql_query($sql);
                    while ($row = $db->sql_fetchrow($result)) {
                        $topic_rows[$row['topic_id']] = $row;
                    }
                    $db->sql_freeresult($result);
                }
                unset($topic_ids);
                $template->assign_var('S_EDIT_DRAFT', $edit);
                $row_count = 0;
                foreach ($draftrows as $draft) {
                    $link_topic = $link_forum = $link_pm = false;
                    $insert_url = $view_url = $title = '';
                    if (isset($topic_rows[$draft['topic_id']]) && $auth->acl_get('f_read', $topic_rows[$draft['topic_id']]['forum_id'])) {
                        $link_topic = true;
                        $view_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $topic_rows[$draft['topic_id']]['forum_id'] . '&amp;t=' . $draft['topic_id']);
                        $title = $topic_rows[$draft['topic_id']]['topic_title'];
                        $insert_url = append_sid("{$phpbb_root_path}posting.{$phpEx}", 'f=' . $topic_rows[$draft['topic_id']]['forum_id'] . '&amp;t=' . $draft['topic_id'] . '&amp;mode=reply&amp;d=' . $draft['draft_id']);
                    } else {
                        if ($auth->acl_get('f_read', $draft['forum_id'])) {
                            $link_forum = true;
                            $view_url = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $draft['forum_id']);
                            $title = $draft['forum_name'];
                            $insert_url = append_sid("{$phpbb_root_path}posting.{$phpEx}", 'f=' . $draft['forum_id'] . '&amp;mode=post&amp;d=' . $draft['draft_id']);
                        } else {
                            if ($pm_drafts) {
                                $link_pm = true;
                                $insert_url = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i={$id}&amp;mode=compose&amp;d=" . $draft['draft_id']);
                            }
                        }
                    }
                    $template_row = array('DATE' => $user->format_date($draft['save_time']), 'DRAFT_MESSAGE' => $submit ? $draft_message : $draft['draft_message'], 'DRAFT_SUBJECT' => $submit ? $draft_subject : $draft['draft_subject'], 'TITLE' => $title, 'DRAFT_ID' => $draft['draft_id'], 'FORUM_ID' => $draft['forum_id'], 'TOPIC_ID' => $draft['topic_id'], 'U_VIEW' => $view_url, 'U_VIEW_EDIT' => $this->u_action . '&amp;edit=' . $draft['draft_id'], 'U_INSERT' => $insert_url, 'S_LINK_TOPIC' => $link_topic, 'S_LINK_FORUM' => $link_forum, 'S_LINK_PM' => $link_pm, 'S_HIDDEN_FIELDS' => $s_hidden_fields);
                    $row_count++;
                    $edit ? $template->assign_vars($template_row) : $template->assign_block_vars('draftrow', $template_row);
                }
                if (!$edit) {
                    $template->assign_var('S_DRAFT_ROWS', $row_count);
                }
                break;
        }
        $template->assign_vars(array('L_TITLE' => $user->lang['UCP_MAIN_' . strtoupper($mode)], 'S_DISPLAY_MARK_ALL' => $mode == 'watched' || $mode == 'drafts' && !isset($_GET['edit']) ? true : false, 'S_HIDDEN_FIELDS' => isset($s_hidden_fields) ? $s_hidden_fields : '', 'S_UCP_ACTION' => $this->u_action, 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST')));
        // Set desired template
        $this->tpl_name = 'ucp_main_' . $mode;
        $this->page_title = 'UCP_MAIN_' . strtoupper($mode);
    }
예제 #16
0
 function last_topics($limit = 10)
 {
     global $db, $template, $user, $config, $phpEx, $phpbb_root_path, $phpbb_seo, $auth, $cache;
     // Usefull for multi bb topic & forum tracking
     // Leave default for single forum eg : '_track'
     $tracking_cookie_name = (defined('XLANG_AKEY') ? XLANG_AKEY : '') . '_track';
     $this->outputs['right_col_tpl'] = 'gym_sitemaps/last_topics_list.html';
     // wa can use start here since there are always more topics overall than in a single forum
     $start = $this->start ? $this->gym_master->chk_start($this->start, $limit) : 0;
     $template->assign_vars(array('LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST')));
     // Wee need to check auth here
     $this->module_config['last_topics_exclude_list'] = $this->gym_master->set_exclude_list($this->module_config['html_ltopic_exclude']);
     $forum_auth_ids = array_diff_assoc($this->module_auth['forum']['read_post'], $this->module_config['last_topics_exclude_list']);
     if (!empty($forum_auth_ids)) {
         $topic_sql_auth = $db->sql_in_set('t.forum_id', $forum_auth_ids, false, true);
         $template->assign_vars(array('NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST')));
         $display_tracking =& $this->call['display_tracking'];
         $display_user_info =& $this->call['display_user_info'];
         $display_topic_status =& $this->call['display_topic_status'];
         if (!$display_tracking) {
             $load_db_lastread = $load_anon_lastread = false;
         } else {
             $load_db_lastread = (bool) ($config['load_db_lastread'] && $user->data['is_registered']);
             $load_anon_lastread = (bool) ($config['load_anon_lastread'] || $user->data['is_registered']);
         }
         $template->assign_vars(array('LASTX_TOPICS_TITLE' => sprintf($user->lang['HTML_LASTX_TOPICS_TITLE'], $limit)));
         // Get The Data, first forums
         if (!empty($this->forum_datas)) {
             $f_id_done = array_keys($this->forum_datas);
             $f_id_done = array_combine($f_id_done, $f_id_done);
             unset($f_id_done[0]);
             $forum_query_ids = array_diff_assoc($forum_auth_ids, $f_id_done);
         } else {
             $forum_query_ids = $forum_auth_ids;
         }
         // Only get the required forums data
         if (!empty($forum_query_ids)) {
             $forum_sql_auth = $db->sql_in_set('f.forum_id', $forum_query_ids, false, true);
             $sql_array = array('SELECT' => 'f.*', 'FROM' => array(FORUMS_TABLE => 'f'), 'LEFT_JOIN' => array());
             if ($load_db_lastread) {
                 $sql_array['SELECT'] .= ', ft.mark_time as forum_mark_time';
                 $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['WHERE'] = $forum_sql_auth;
             $result = $db->sql_query($db->sql_build_query('SELECT', $sql_array));
             $all_forum_datas = $forum_datas = array();
             while ($row = $db->sql_fetchrow($result)) {
                 $forum_id = (int) $row['forum_id'];
                 $forum_datas[$forum_id] = $row;
             }
             $db->sql_freeresult($result);
         }
         // Now the topics
         $sql_array = array('SELECT' => 't.*', 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array());
         if ($display_user_info && $display_topic_status && $user->data['is_registered']) {
             $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . $user->data['user_id']);
             $sql_array['SELECT'] .= ', tp.topic_posted';
         }
         if ($load_db_lastread) {
             $sql_array['SELECT'] .= ', tt.mark_time';
             $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.user_id = ' . $user->data['user_id'] . ' AND tt.topic_id = t.topic_id');
         } elseif ($load_anon_lastread && empty($this->tracking_topics)) {
             $this->tracking_topics = isset($_COOKIE[$config['cookie_name'] . $tracking_cookie_name]) ? STRIP ? stripslashes($_COOKIE[$config['cookie_name'] . $tracking_cookie_name]) : $_COOKIE[$config['cookie_name'] . $tracking_cookie_name] : '';
             $this->tracking_topics = $this->tracking_topics ? tracking_unserialize($this->tracking_topics) : array();
             if (!$user->data['is_registered']) {
                 $user->data['user_lastmark'] = isset($this->tracking_topics['l']) ? (int) (base_convert($this->tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
             }
         }
         $sql_array['WHERE'] = "{$topic_sql_auth}\n\t\t\t\t\t\tAND t.topic_status <> " . ITEM_MOVED . ' AND t.topic_approved = 1';
         $sql_array['ORDER_BY'] = 'topic_last_post_time DESC';
         $result = $db->sql_query_limit($db->sql_build_query('SELECT', $sql_array), $limit, $start);
         while ($row = $db->sql_fetchrow($result)) {
             $topic_id = (int) $row['topic_id'];
             $forum_id = (int) $row['forum_id'];
             $all_forum_datas[$forum_id][$topic_id] = $row;
         }
         $db->sql_freeresult($result);
         // Grab icons
         if (empty($this->icons)) {
             $this->icons = $cache->obtain_icons();
         }
         $folder_alt = 'NO_NEW_POSTS';
         $topic_type = '';
         $folder_img = 'topic_read';
         $topic_folder_img = $user->img($folder_img, $folder_alt);
         $topic_folder_img_src = $user->img($folder_img, $folder_alt, false, '', 'src');
         foreach ($all_forum_datas as $forum_id => $topic_datas) {
             // Start with the forum
             $forum_id = (int) $forum_id;
             if (empty($this->forum_datas[$forum_id])) {
                 $row =& $forum_datas[$forum_id];
                 // www.phpBB-SEO.com SEO TOOLKIT BEGIN
                 $phpbb_seo->set_url($row['forum_name'], $forum_id, $phpbb_seo->seo_static['forum']);
                 // www.phpBB-SEO.com SEO TOOLKIT END
                 $this->forum_datas[$forum_id] = array_merge($row, array('forum_url' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", "f={$forum_id}"), 'm_approve' => $auth->acl_get('m_approve', $forum_id)));
                 if ($load_db_lastread) {
                     $this->forum_tracking_info[$forum_id] = !empty($row['forum_mark_time']) ? $row['forum_mark_time'] : $user->data['user_lastmark'];
                 } elseif ($load_anon_lastread) {
                     $this->forum_tracking_info[$forum_id] = isset($this->tracking_topics['f'][$forum_id]) ? (int) (base_convert($this->tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
                 }
             }
             $forum_unread = isset($this->forum_tracking_info[$forum_id]) && $this->forum_datas[$forum_id]['forum_last_post_time'] > $this->forum_tracking_info[$forum_id] ? true : false;
             $folder_image = $folder_alt = '';
             $folder_image = $forum_unread ? 'forum_unread' : 'forum_read';
             // Which folder should we display?
             if ($this->forum_datas[$forum_id]['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';
             }
             $template->assign_block_vars('last_forums', array('FORUM_NAME' => $this->forum_datas[$forum_id]['forum_name'], '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] : '', 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", "f={$forum_id}")));
             // Now the topics
             foreach ($topic_datas as $topic_id => $topic_data) {
                 $topic_id = (int) $topic_id;
                 if ($load_db_lastread) {
                     $this->topic_tracking_info[$topic_id] = !empty($topic_data['mark_time']) ? $topic_data['mark_time'] : $user->data['user_lastmark'];
                 } else {
                     if ($load_anon_lastread) {
                         $topic_id36 = base_convert($topic_id, 10, 36);
                         if (isset($this->tracking_topics['t'][$topic_id36])) {
                             $this->tracking_topics['t'][$topic_id] = base_convert($this->tracking_topics['t'][$topic_id36], 36, 10) + $config['board_startdate'];
                         }
                         $this->topic_tracking_info[$topic_id] = isset($this->tracking_topics['t'][$topic_id]) ? $this->tracking_topics['t'][$topic_id] : $user->data['user_lastmark'];
                     }
                 }
                 if (!empty($this->forum_tracking_info[$forum_id])) {
                     $this->topic_tracking_info[$topic_id] = $this->topic_tracking_info[$topic_id] > $this->forum_tracking_info[$forum_id] ? $this->topic_tracking_info[$topic_id] : $this->forum_tracking_info[$forum_id];
                 }
                 $topic_data['topic_title'] = censor_text($topic_data['topic_title']);
                 // www.phpBB-SEO.com SEO TOOLKIT BEGIN
                 $phpbb_seo->prepare_iurl($topic_data, 'topic', $topic_data['topic_type'] == POST_GLOBAL ? $this->seo_static['global_announce'] : $phpbb_seo->seo_url['forum'][$forum_id]);
                 // www.phpBB-SEO.com SEO TOOLKIT END
                 // Replies
                 $replies = $this->forum_datas[$forum_id]['m_approve'] ? $topic_data['topic_replies_real'] : $topic_data['topic_replies'];
                 $last_page = $replies + 1 > $config['posts_per_page'] ? floor($replies / $config['posts_per_page']) * $config['posts_per_page'] : 0;
                 $last_post_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&amp;t={$topic_id}" . ($last_page ? "&amp;start={$last_page}" : '')) . '#p' . $topic_data['topic_last_post_id'];
                 $unread_topic = isset($this->topic_tracking_info[$topic_id]) && $topic_data['topic_last_post_time'] > $this->topic_tracking_info[$topic_id] ? true : false;
                 // Get folder img, topic status/type related information
                 if ($display_topic_status) {
                     $this->gym_master->topic_status($topic_data, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
                     $topic_folder_img = $user->img($folder_img, $folder_alt);
                     $topic_folder_img_src = $user->img($folder_img, $folder_alt, false, '', 'src');
                 }
                 $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&amp;t={$topic_id}");
                 $template->assign_block_vars('last_forums.last_topics', array('TOPIC_TITLE' => $topic_data['topic_title'], 'PAGINATION' => $this->call['last_topic_pagination'] ? $this->gym_master->topic_generate_pagination($replies, $view_topic_url) : '', 'TOPIC_TYPE' => $topic_type, 'TOPIC_FOLDER_IMG' => $topic_folder_img, 'TOPIC_FOLDER_IMG_SRC' => $topic_folder_img_src, 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt], 'TOPIC_ICON_IMG' => !empty($this->icons[$topic_data['icon_id']]) ? $this->icons[$topic_data['icon_id']]['img'] : '', 'TOPIC_ICON_IMG_WIDTH' => !empty($this->icons[$topic_data['icon_id']]) ? $this->icons[$topic_data['icon_id']]['width'] : '', 'TOPIC_ICON_IMG_HEIGHT' => !empty($this->icons[$topic_data['icon_id']]) ? $this->icons[$topic_data['icon_id']]['height'] : '', 'U_NEWEST_POST' => $unread_topic ? append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $forum_id . '&amp;t=' . $topic_id . '&amp;view=unread#unread') : '', 'U_VIEW_TOPIC' => $view_topic_url, 'U_LAST_POST' => $last_post_url, 'S_UNREAD_TOPIC' => $unread_topic));
             }
         }
         unset($forum_datas, $all_forum_datas);
     }
 }
예제 #17
0
/**
* Check for read forums and update topic tracking info accordingly
*
* @param int $forum_id the forum id to check
* @param int $forum_last_post_time the forums last post time
* @param int $f_mark_time the forums last mark time if user is registered and load_db_lastread enabled
* @param int $mark_time_forum false if the mark time needs to be obtained, else the last users forum mark time
*
* @return true if complete forum got marked read, else false.
*/
function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_time = false, $mark_time_forum = false)
{
    global $db, $tracking_topics, $user, $config;
    // Determine the users last forum mark time if not given.
    if ($mark_time_forum === false) {
        if ($config['load_db_lastread'] && $user->data['is_registered']) {
            $mark_time_forum = !empty($f_mark_time) ? $f_mark_time : $user->data['user_lastmark'];
        } 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;
                }
                $mark_time_forum = isset($tracking_topics['f'][$forum_id]) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
            }
        }
    }
    // Check the forum for any left unread topics.
    // If there are none, we mark the forum as read.
    if ($config['load_db_lastread'] && $user->data['is_registered']) {
        if ($mark_time_forum >= $forum_last_post_time) {
            // We do not need to mark read, this happened before. Therefore setting this to true
            $row = true;
        } else {
            $sql = 'SELECT t.forum_id FROM ' . TOPICS_TABLE . ' t
				LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id'] . ')
				WHERE t.forum_id = ' . $forum_id . '
					AND t.topic_last_post_time > ' . $mark_time_forum . '
					AND t.topic_moved_id = 0
					AND (tt.topic_id IS NULL OR tt.mark_time < t.topic_last_post_time)
				GROUP BY t.forum_id';
            $result = $db->sql_query_limit($sql, 1);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
        }
    } else {
        if ($config['load_anon_lastread'] || $user->data['is_registered']) {
            // Get information from cookie
            $row = false;
            if (!isset($tracking_topics['tf'][$forum_id])) {
                // We do not need to mark read, this happened before. Therefore setting this to true
                $row = true;
            } else {
                $sql = 'SELECT topic_id
				FROM ' . TOPICS_TABLE . '
				WHERE forum_id = ' . $forum_id . '
					AND topic_last_post_time > ' . $mark_time_forum . '
					AND topic_moved_id = 0';
                $result = $db->sql_query($sql);
                $check_forum = $tracking_topics['tf'][$forum_id];
                $unread = false;
                while ($row = $db->sql_fetchrow($result)) {
                    if (!isset($check_forum[base_convert($row['topic_id'], 10, 36)])) {
                        $unread = true;
                        break;
                    }
                }
                $db->sql_freeresult($result);
                $row = $unread;
            }
        } else {
            $row = true;
        }
    }
    if (!$row) {
        markread('topics', $forum_id);
        return true;
    }
    return false;
}
예제 #18
0
/**
* get topic tracking info for news
* based on get_complete_tracking_info of phpBB3
* this should reduce the queries for the news and announcements block
*/
function get_portal_tracking_info($fetch_news)
{
	global $config, $user;

	$last_read = $topic_ids = $forum_ids = $tracking_info = $rev_forum_ids = array();

	/**
	* group everything by the forum IDs
	*/
	$count = $fetch_news['topic_count'];
	for ($i = 0; $i < $count; ++$i)
	{
		$tracking_info[$fetch_news[$i]['forum_id']][] = $fetch_news[$i]['topic_id'];
		$topic_ids[] = $fetch_news[$i]['topic_id'];
		$forum_ids[] = $fetch_news[$i]['forum_id'];
		$rev_forum_ids[$fetch_news[$i]['topic_id']] = $fetch_news[$i]['forum_id']; // the other way round also helps
	}

	foreach ($tracking_info as $forum_id => $current_forum)
	{
		if ($config['load_db_lastread'] && $user->data['is_registered'])
		{
			global $db;

			$mark_time = array();

			$sql = 'SELECT topic_id, mark_time
				FROM ' . TOPICS_TRACK_TABLE . "
				WHERE user_id = {$user->data['user_id']}
					AND " . $db->sql_in_set('topic_id', $current_forum);
			$result = $db->sql_query($sql);

			while ($row = $db->sql_fetchrow($result))
			{
				$last_read[$row['topic_id']] = $row['mark_time'];
			}
			$db->sql_freeresult($result);

			$current_forum = array_diff($current_forum, array_keys($last_read));

			if (sizeof($topic_ids))
			{
				$sql = 'SELECT forum_id, mark_time
					FROM ' . FORUMS_TRACK_TABLE . "
					WHERE user_id = {$user->data['user_id']}
						AND " . $db->sql_in_set('forum_id', $forum_ids);
				$result = $db->sql_query($sql);

				while ($row = $db->sql_fetchrow($result))
				{
					$mark_time[$row['forum_id']] = $row['mark_time'];
				}
				$db->sql_freeresult($result);

                // @todo: do not use $current_forum here as this is already used by the outside foreach
				foreach($forum_ids as $current_forum)
				{
					$user_lastmark[$current_forum] = (isset($mark_time[$current_forum])) ? $mark_time[$current_forum] : $user->data['user_lastmark'];
				}

                // @todo: also check if $user_lastmark has been defined for this specific forum_id
				foreach ($topic_ids as $topic_id)
				{
					$last_read[$topic_id] = (!isset($last_read[$topic_id]) || $user_lastmark[$rev_forum_ids[$topic_id]] > $last_read[$topic_id]) ? $user_lastmark[$rev_forum_ids[$topic_id]] : $last_read[$topic_id];
				}
			}
		}
		else if ($config['load_anon_lastread'] || $user->data['is_registered'])
		{
			global $tracking_topics;

			if (!isset($tracking_topics) || !sizeof($tracking_topics))
			{
				$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_lastmark = (isset($tracking_topics['l'])) ? base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate'] : 0;
			}
			else
			{
				$user_lastmark = $user->data['user_lastmark'];
			}

			foreach ($topic_ids as $topic_id)
			{
				$topic_id36 = base_convert($topic_id, 10, 36);

				if (isset($tracking_topics['t'][$topic_id36]))
				{
					$last_read[$topic_id] = base_convert($tracking_topics['t'][$topic_id36], 36, 10) + $config['board_startdate'];
				}
			}

			$topic_ids = array_diff($topic_ids, array_keys($last_read));

			if (sizeof($topic_ids))
			{
				$mark_time = array();

				if (isset($tracking_topics['f'][$forum_id]))
				{
					$mark_time[$forum_id] = base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate'];
				}

				$user_lastmark = (isset($mark_time[$forum_id])) ? $mark_time[$forum_id] : $user_lastmark;

				foreach ($topic_ids as $topic_id)
				{
					$last_read[$topic_id] = $user_lastmark;
				}
			}
		}
	}

	return $last_read;
}