indvdum@0: session_begin(); indvdum@0: $auth->acl($user->data); indvdum@0: indvdum@0: // Start initial var setup indvdum@0: $forum_id = request_var('f', 0); indvdum@0: $mark_read = request_var('mark', ''); indvdum@0: $start = request_var('start', 0); indvdum@0: indvdum@0: $default_sort_days = (!empty($user->data['user_topic_show_days'])) ? $user->data['user_topic_show_days'] : 0; indvdum@0: $default_sort_key = (!empty($user->data['user_topic_sortby_type'])) ? $user->data['user_topic_sortby_type'] : 't'; indvdum@0: $default_sort_dir = (!empty($user->data['user_topic_sortby_dir'])) ? $user->data['user_topic_sortby_dir'] : 'd'; indvdum@0: indvdum@0: $sort_days = request_var('st', $default_sort_days); indvdum@0: $sort_key = request_var('sk', $default_sort_key); indvdum@0: $sort_dir = request_var('sd', $default_sort_dir); indvdum@0: indvdum@0: // Check if the user has actually sent a forum ID with his/her request indvdum@0: // If not give them a nice error page. indvdum@0: if (!$forum_id) indvdum@0: { indvdum@0: trigger_error('NO_FORUM'); indvdum@0: } indvdum@0: indvdum@0: $sql_from = FORUMS_TABLE . ' f'; indvdum@0: $lastread_select = ''; indvdum@0: indvdum@0: // Grab appropriate forum data indvdum@0: if ($config['load_db_lastread'] && $user->data['is_registered']) indvdum@0: { indvdum@0: $sql_from .= ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' indvdum@0: AND ft.forum_id = f.forum_id)'; indvdum@0: $lastread_select .= ', ft.mark_time'; indvdum@0: } indvdum@0: indvdum@0: if ($user->data['is_registered']) indvdum@0: { indvdum@0: $sql_from .= ' LEFT JOIN ' . FORUMS_WATCH_TABLE . ' fw ON (fw.forum_id = f.forum_id AND fw.user_id = ' . $user->data['user_id'] . ')'; indvdum@0: $lastread_select .= ', fw.notify_status'; indvdum@0: } indvdum@0: indvdum@0: $sql = "SELECT f.* $lastread_select indvdum@0: FROM $sql_from indvdum@0: WHERE f.forum_id = $forum_id"; indvdum@0: $result = $db->sql_query($sql); indvdum@0: $forum_data = $db->sql_fetchrow($result); indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: if (!$forum_data) indvdum@0: { indvdum@0: trigger_error('NO_FORUM'); indvdum@0: } indvdum@0: indvdum@0: indvdum@0: // Configure style, language, etc. indvdum@0: $user->setup('viewforum', $forum_data['forum_style']); indvdum@0: indvdum@0: // Redirect to login upon emailed notification links indvdum@0: if (isset($_GET['e']) && !$user->data['is_registered']) indvdum@0: { indvdum@0: login_box('', $user->lang['LOGIN_NOTIFY_FORUM']); indvdum@0: } indvdum@0: indvdum@0: // Permissions check indvdum@0: if (!$auth->acl_gets('f_list', 'f_read', $forum_id) || ($forum_data['forum_type'] == FORUM_LINK && $forum_data['forum_link'] && !$auth->acl_get('f_read', $forum_id))) indvdum@0: { indvdum@0: if ($user->data['user_id'] != ANONYMOUS) indvdum@0: { indvdum@0: trigger_error('SORRY_AUTH_READ'); indvdum@0: } indvdum@0: indvdum@0: login_box('', $user->lang['LOGIN_VIEWFORUM']); indvdum@0: } indvdum@0: indvdum@0: // Forum is passworded ... check whether access has been granted to this indvdum@0: // user this session, if not show login box indvdum@0: if ($forum_data['forum_password']) indvdum@0: { indvdum@0: login_forum_box($forum_data); indvdum@0: } indvdum@0: indvdum@0: // Is this forum a link? ... User got here either because the indvdum@0: // number of clicks is being tracked or they guessed the id indvdum@0: if ($forum_data['forum_type'] == FORUM_LINK && $forum_data['forum_link']) indvdum@0: { indvdum@0: // Does it have click tracking enabled? indvdum@0: if ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK) indvdum@0: { indvdum@0: $sql = 'UPDATE ' . FORUMS_TABLE . ' indvdum@0: SET forum_posts = forum_posts + 1 indvdum@0: WHERE forum_id = ' . $forum_id; indvdum@0: $db->sql_query($sql); indvdum@0: } indvdum@0: indvdum@0: // We redirect to the url. The third parameter indicates that external redirects are allowed. indvdum@0: redirect($forum_data['forum_link'], false, true); indvdum@0: return; indvdum@0: } indvdum@0: indvdum@0: // Build navigation links indvdum@0: generate_forum_nav($forum_data); indvdum@0: indvdum@0: // Forum Rules indvdum@0: if ($auth->acl_get('f_read', $forum_id)) indvdum@0: { indvdum@0: generate_forum_rules($forum_data); indvdum@0: } indvdum@0: indvdum@0: // Do we have subforums? indvdum@0: $active_forum_ary = $moderators = array(); indvdum@0: indvdum@0: if ($forum_data['left_id'] != $forum_data['right_id'] - 1) indvdum@0: { indvdum@0: list($active_forum_ary, $moderators) = display_forums($forum_data, $config['load_moderators'], $config['load_moderators']); indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $template->assign_var('S_HAS_SUBFORUM', false); indvdum@0: if ($config['load_moderators']) indvdum@0: { indvdum@0: get_moderators($moderators, $forum_id); indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: // Dump out the page header and load viewforum template indvdum@0: page_header($user->lang['VIEW_FORUM'] . ' - ' . $forum_data['forum_name'], true, $forum_id); indvdum@0: indvdum@0: $template->set_filenames(array( indvdum@0: 'body' => 'viewforum_body.html') indvdum@0: ); indvdum@0: indvdum@0: make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"), $forum_id); indvdum@0: indvdum@0: $template->assign_vars(array( indvdum@0: 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . (($start == 0) ? '' : "&start=$start")), indvdum@0: )); indvdum@0: indvdum@0: // Not postable forum or showing active topics? indvdum@0: if (!($forum_data['forum_type'] == FORUM_POST || (($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) && $forum_data['forum_type'] == FORUM_CAT))) indvdum@0: { indvdum@0: page_footer(); indvdum@0: } indvdum@0: indvdum@0: // Ok, if someone has only list-access, we only display the forum list. indvdum@0: // We also make this circumstance available to the template in case we want to display a notice. ;) indvdum@0: if (!$auth->acl_get('f_read', $forum_id)) indvdum@0: { indvdum@0: $template->assign_vars(array( indvdum@0: 'S_NO_READ_ACCESS' => true, indvdum@0: )); indvdum@0: indvdum@0: page_footer(); indvdum@0: } indvdum@0: indvdum@0: // Handle marking posts indvdum@0: if ($mark_read == 'topics') indvdum@0: { indvdum@0: $token = request_var('hash', ''); indvdum@0: if (check_link_hash($token, 'global')) indvdum@0: { indvdum@0: // Add 0 to forums array to mark global announcements correctly indvdum@0: markread('topics', array($forum_id, 0)); indvdum@0: } indvdum@0: $redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id); indvdum@0: meta_refresh(3, $redirect_url); indvdum@0: indvdum@0: trigger_error($user->lang['TOPICS_MARKED'] . '

' . sprintf($user->lang['RETURN_FORUM'], '', '')); indvdum@0: } indvdum@0: indvdum@0: // Is a forum specific topic count required? indvdum@0: if ($forum_data['forum_topics_per_page']) indvdum@0: { indvdum@0: $config['topics_per_page'] = $forum_data['forum_topics_per_page']; indvdum@0: } indvdum@0: indvdum@0: // Do the forum Prune thang - cron type job ... indvdum@0: if ($forum_data['prune_next'] < time() && $forum_data['enable_prune']) indvdum@0: { indvdum@0: $template->assign_var('RUN_CRON_TASK', 'cron'); indvdum@0: } indvdum@0: indvdum@0: // Forum rules and subscription info indvdum@0: $s_watching_forum = array( indvdum@0: 'link' => '', indvdum@0: 'title' => '', indvdum@0: 'is_watching' => false, indvdum@0: ); indvdum@0: indvdum@0: if (($config['email_enable'] || $config['jab_enable']) && $config['allow_forum_notify'] && $forum_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_subscribe', $forum_id) || $user->data['user_id'] == ANONYMOUS)) indvdum@0: { indvdum@0: $notify_status = (isset($forum_data['notify_status'])) ? $forum_data['notify_status'] : NULL; indvdum@0: watch_topic_forum('forum', $s_watching_forum, $user->data['user_id'], $forum_id, 0, $notify_status, $start, $forum_data['forum_name']); indvdum@0: } indvdum@0: indvdum@0: $s_forum_rules = ''; indvdum@0: gen_forum_auth_level('forum', $forum_id, $forum_data['forum_status']); indvdum@0: indvdum@0: // Topic ordering options indvdum@0: $limit_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); indvdum@0: indvdum@0: $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']); indvdum@0: $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'r' => 't.topic_replies', 's' => 't.topic_title', 'v' => 't.topic_views'); indvdum@0: indvdum@0: $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = ''; indvdum@0: gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param, $default_sort_days, $default_sort_key, $default_sort_dir); indvdum@0: indvdum@0: // Limit topics to certain time frame, obtain correct topic count indvdum@0: // global announcements must not be counted, normal announcements have to indvdum@0: // be counted, as forum_topics(_real) includes them indvdum@0: if ($sort_days) indvdum@0: { indvdum@0: $min_post_time = time() - ($sort_days * 86400); indvdum@0: indvdum@0: $sql = 'SELECT COUNT(topic_id) AS num_topics indvdum@0: FROM ' . TOPICS_TABLE . " indvdum@0: WHERE forum_id = $forum_id indvdum@0: AND ((topic_type <> " . POST_GLOBAL . " AND topic_last_post_time >= $min_post_time) indvdum@0: OR topic_type = " . POST_ANNOUNCE . ") indvdum@0: " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND topic_approved = 1'); indvdum@0: $result = $db->sql_query($sql); indvdum@0: $topics_count = (int) $db->sql_fetchfield('num_topics'); indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: if (isset($_POST['sort'])) indvdum@0: { indvdum@0: $start = 0; indvdum@0: } indvdum@0: $sql_limit_time = "AND t.topic_last_post_time >= $min_post_time"; indvdum@0: indvdum@0: // Make sure we have information about day selection ready indvdum@0: $template->assign_var('S_SORT_DAYS', true); indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $topics_count = ($auth->acl_get('m_approve', $forum_id)) ? $forum_data['forum_topics_real'] : $forum_data['forum_topics']; indvdum@0: $sql_limit_time = ''; indvdum@0: } indvdum@0: indvdum@0: // Make sure $start is set to the last page if it exceeds the amount indvdum@0: if ($start < 0 || $start > $topics_count) indvdum@0: { indvdum@0: $start = ($start < 0) ? 0 : floor(($topics_count - 1) / $config['topics_per_page']) * $config['topics_per_page']; indvdum@0: } indvdum@0: indvdum@0: // Basic pagewide vars indvdum@0: $post_alt = ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['FORUM_LOCKED'] : $user->lang['POST_NEW_TOPIC']; indvdum@0: indvdum@0: // Display active topics? indvdum@0: $s_display_active = ($forum_data['forum_type'] == FORUM_CAT && ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false; indvdum@0: indvdum@0: $s_search_hidden_fields = array('fid' => array($forum_id)); indvdum@0: if ($_SID) indvdum@0: { indvdum@0: $s_search_hidden_fields['sid'] = $_SID; indvdum@0: } indvdum@0: indvdum@0: if (!empty($_EXTRA_URL)) indvdum@0: { indvdum@0: foreach ($_EXTRA_URL as $url_param) indvdum@0: { indvdum@0: $url_param = explode('=', $url_param, 2); indvdum@0: $s_hidden_fields[$url_param[0]] = $url_param[1]; indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: $template->assign_vars(array( indvdum@0: 'MODERATORS' => (!empty($moderators[$forum_id])) ? implode(', ', $moderators[$forum_id]) : '', indvdum@0: indvdum@0: 'POST_IMG' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->img('button_topic_locked', $post_alt) : $user->img('button_topic_new', $post_alt), indvdum@0: 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), indvdum@0: 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'), indvdum@0: 'FOLDER_IMG' => $user->img('topic_read', 'NO_UNREAD_POSTS'), indvdum@0: 'FOLDER_UNREAD_IMG' => $user->img('topic_unread', 'UNREAD_POSTS'), indvdum@0: 'FOLDER_HOT_IMG' => $user->img('topic_read_hot', 'NO_UNREAD_POSTS_HOT'), indvdum@0: 'FOLDER_HOT_UNREAD_IMG' => $user->img('topic_unread_hot', 'UNREAD_POSTS_HOT'), indvdum@0: 'FOLDER_LOCKED_IMG' => $user->img('topic_read_locked', 'NO_UNREAD_POSTS_LOCKED'), indvdum@0: 'FOLDER_LOCKED_UNREAD_IMG' => $user->img('topic_unread_locked', 'UNREAD_POSTS_LOCKED'), indvdum@0: 'FOLDER_STICKY_IMG' => $user->img('sticky_read', 'POST_STICKY'), indvdum@0: 'FOLDER_STICKY_UNREAD_IMG' => $user->img('sticky_unread', 'POST_STICKY'), indvdum@0: 'FOLDER_ANNOUNCE_IMG' => $user->img('announce_read', 'POST_ANNOUNCEMENT'), indvdum@0: 'FOLDER_ANNOUNCE_UNREAD_IMG'=> $user->img('announce_unread', 'POST_ANNOUNCEMENT'), indvdum@0: 'FOLDER_MOVED_IMG' => $user->img('topic_moved', 'TOPIC_MOVED'), indvdum@0: 'REPORTED_IMG' => $user->img('icon_topic_reported', 'TOPIC_REPORTED'), indvdum@0: 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'), indvdum@0: 'GOTO_PAGE_IMG' => $user->img('icon_post_target', 'GOTO_PAGE'), indvdum@0: indvdum@0: 'L_NO_TOPICS' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['POST_FORUM_LOCKED'] : $user->lang['NO_TOPICS'], indvdum@0: indvdum@0: 'S_DISPLAY_POST_INFO' => ($forum_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false, indvdum@0: indvdum@0: 'S_IS_POSTABLE' => ($forum_data['forum_type'] == FORUM_POST) ? true : false, indvdum@0: 'S_USER_CAN_POST' => ($auth->acl_get('f_post', $forum_id)) ? true : false, indvdum@0: 'S_DISPLAY_ACTIVE' => $s_display_active, indvdum@0: 'S_SELECT_SORT_DIR' => $s_sort_dir, indvdum@0: 'S_SELECT_SORT_KEY' => $s_sort_key, indvdum@0: 'S_SELECT_SORT_DAYS' => $s_limit_days, indvdum@0: 'S_TOPIC_ICONS' => ($s_display_active && sizeof($active_forum_ary)) ? max($active_forum_ary['enable_icons']) : (($forum_data['enable_icons']) ? true : false), indvdum@0: 'S_WATCH_FORUM_LINK' => $s_watching_forum['link'], indvdum@0: 'S_WATCH_FORUM_TITLE' => $s_watching_forum['title'], indvdum@0: 'S_WATCHING_FORUM' => $s_watching_forum['is_watching'], indvdum@0: 'S_FORUM_ACTION' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . (($start == 0) ? '' : "&start=$start")), indvdum@0: 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('u_search') && $auth->acl_get('f_search', $forum_id) && $config['load_search']) ? true : false, indvdum@0: 'S_SEARCHBOX_ACTION' => append_sid("{$phpbb_root_path}search.$phpEx"), indvdum@0: 'S_SEARCH_LOCAL_HIDDEN_FIELDS' => build_hidden_fields($s_search_hidden_fields), indvdum@0: 'S_SINGLE_MODERATOR' => (!empty($moderators[$forum_id]) && sizeof($moderators[$forum_id]) > 1) ? false : true, indvdum@0: 'S_IS_LOCKED' => ($forum_data['forum_status'] == ITEM_LOCKED) ? true : false, indvdum@0: 'S_VIEWFORUM' => true, indvdum@0: indvdum@0: 'U_MCP' => ($auth->acl_get('m_', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "f=$forum_id&i=main&mode=forum_view", true, $user->session_id) : '', indvdum@0: 'U_POST_NEW_TOPIC' => ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS) ? append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=post&f=' . $forum_id) : '', indvdum@0: 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&$u_sort_param" : '') . (($start == 0) ? '' : "&start=$start")), indvdum@0: 'U_MARK_TOPICS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . "&f=$forum_id&mark=topics") : '', indvdum@0: )); indvdum@0: indvdum@0: // Grab icons indvdum@0: $icons = $cache->obtain_icons(); indvdum@0: indvdum@0: // Grab all topic data indvdum@0: $rowset = $announcement_list = $topic_list = $global_announce_list = array(); indvdum@0: indvdum@0: $sql_array = array( indvdum@0: 'SELECT' => 't.*', indvdum@0: 'FROM' => array( indvdum@0: TOPICS_TABLE => 't' indvdum@0: ), indvdum@0: 'LEFT_JOIN' => array(), indvdum@0: ); indvdum@0: indvdum@0: $sql_approved = ($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1'; indvdum@0: indvdum@0: if ($user->data['is_registered']) indvdum@0: { indvdum@0: if ($config['load_db_track']) indvdum@0: { indvdum@0: $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']); indvdum@0: $sql_array['SELECT'] .= ', tp.topic_posted'; indvdum@0: } indvdum@0: indvdum@0: if ($config['load_db_lastread']) indvdum@0: { indvdum@0: $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id']); indvdum@0: $sql_array['SELECT'] .= ', tt.mark_time'; indvdum@0: indvdum@0: if ($s_display_active && sizeof($active_forum_ary)) indvdum@0: { indvdum@0: $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id']); indvdum@0: $sql_array['SELECT'] .= ', ft.mark_time AS forum_mark_time'; indvdum@0: } indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: if ($forum_data['forum_type'] == FORUM_POST) indvdum@0: { indvdum@0: // Obtain announcements ... removed sort ordering, sort by time in all cases indvdum@0: $sql = $db->sql_build_query('SELECT', array( indvdum@0: 'SELECT' => $sql_array['SELECT'], indvdum@0: 'FROM' => $sql_array['FROM'], indvdum@0: 'LEFT_JOIN' => $sql_array['LEFT_JOIN'], indvdum@0: indvdum@0: 'WHERE' => 't.forum_id IN (' . $forum_id . ', 0) indvdum@0: AND t.topic_type IN (' . POST_ANNOUNCE . ', ' . POST_GLOBAL . ')', indvdum@0: indvdum@0: 'ORDER_BY' => 't.topic_time DESC', indvdum@0: )); indvdum@0: $result = $db->sql_query($sql); indvdum@0: indvdum@0: while ($row = $db->sql_fetchrow($result)) indvdum@0: { indvdum@0: if (!$row['topic_approved'] && !$auth->acl_get('m_approve', $row['forum_id'])) indvdum@0: { indvdum@0: // Do not display announcements that are waiting for approval. indvdum@0: continue; indvdum@0: } indvdum@0: indvdum@0: $rowset[$row['topic_id']] = $row; indvdum@0: $announcement_list[] = $row['topic_id']; indvdum@0: indvdum@0: if ($row['topic_type'] == POST_GLOBAL) indvdum@0: { indvdum@0: $global_announce_list[$row['topic_id']] = true; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $topics_count--; indvdum@0: } indvdum@0: } indvdum@0: $db->sql_freeresult($result); indvdum@0: } indvdum@0: indvdum@0: // If the user is trying to reach late pages, start searching from the end indvdum@0: $store_reverse = false; indvdum@0: $sql_limit = $config['topics_per_page']; indvdum@0: if ($start > $topics_count / 2) indvdum@0: { indvdum@0: $store_reverse = true; indvdum@0: indvdum@0: if ($start + $config['topics_per_page'] > $topics_count) indvdum@0: { indvdum@0: $sql_limit = min($config['topics_per_page'], max(1, $topics_count - $start)); indvdum@0: } indvdum@0: indvdum@0: // Select the sort order indvdum@0: $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC'); indvdum@0: $sql_start = max(0, $topics_count - $sql_limit - $start); indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: // Select the sort order indvdum@0: $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC'); indvdum@0: $sql_start = $start; indvdum@0: } indvdum@0: indvdum@0: if ($forum_data['forum_type'] == FORUM_POST || !sizeof($active_forum_ary)) indvdum@0: { indvdum@0: $sql_where = 't.forum_id = ' . $forum_id; indvdum@0: } indvdum@0: else if (empty($active_forum_ary['exclude_forum_id'])) indvdum@0: { indvdum@0: $sql_where = $db->sql_in_set('t.forum_id', $active_forum_ary['forum_id']); indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $get_forum_ids = array_diff($active_forum_ary['forum_id'], $active_forum_ary['exclude_forum_id']); indvdum@0: $sql_where = (sizeof($get_forum_ids)) ? $db->sql_in_set('t.forum_id', $get_forum_ids) : 't.forum_id = ' . $forum_id; indvdum@0: } indvdum@0: indvdum@0: // Grab just the sorted topic ids indvdum@0: $sql = 'SELECT t.topic_id indvdum@0: FROM ' . TOPICS_TABLE . " t indvdum@0: WHERE $sql_where indvdum@0: AND t.topic_type IN (" . POST_NORMAL . ', ' . POST_STICKY . ") indvdum@0: $sql_approved indvdum@0: $sql_limit_time indvdum@0: ORDER BY t.topic_type " . ((!$store_reverse) ? 'DESC' : 'ASC') . ', ' . $sql_sort_order; indvdum@0: $result = $db->sql_query_limit($sql, $sql_limit, $sql_start); indvdum@0: indvdum@0: while ($row = $db->sql_fetchrow($result)) indvdum@0: { indvdum@0: $topic_list[] = (int) $row['topic_id']; indvdum@0: } indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: // For storing shadow topics indvdum@0: $shadow_topic_list = array(); indvdum@0: indvdum@0: if (sizeof($topic_list)) indvdum@0: { indvdum@0: // SQL array for obtaining topics/stickies indvdum@0: $sql_array = array( indvdum@0: 'SELECT' => $sql_array['SELECT'], indvdum@0: 'FROM' => $sql_array['FROM'], indvdum@0: 'LEFT_JOIN' => $sql_array['LEFT_JOIN'], indvdum@0: indvdum@0: 'WHERE' => $db->sql_in_set('t.topic_id', $topic_list), indvdum@0: ); indvdum@0: indvdum@0: // If store_reverse, then first obtain topics, then stickies, else the other way around... indvdum@0: // Funnily enough you typically save one query if going from the last page to the middle (store_reverse) because indvdum@0: // the number of stickies are not known indvdum@0: $sql = $db->sql_build_query('SELECT', $sql_array); indvdum@0: $result = $db->sql_query($sql); indvdum@0: indvdum@0: while ($row = $db->sql_fetchrow($result)) indvdum@0: { indvdum@0: if ($row['topic_status'] == ITEM_MOVED) indvdum@0: { indvdum@0: $shadow_topic_list[$row['topic_moved_id']] = $row['topic_id']; indvdum@0: } indvdum@0: indvdum@0: $rowset[$row['topic_id']] = $row; indvdum@0: } indvdum@0: $db->sql_freeresult($result); indvdum@0: } indvdum@0: indvdum@0: // If we have some shadow topics, update the rowset to reflect their topic information indvdum@0: if (sizeof($shadow_topic_list)) indvdum@0: { indvdum@0: $sql = 'SELECT * indvdum@0: FROM ' . TOPICS_TABLE . ' indvdum@0: WHERE ' . $db->sql_in_set('topic_id', array_keys($shadow_topic_list)); indvdum@0: $result = $db->sql_query($sql); indvdum@0: indvdum@0: while ($row = $db->sql_fetchrow($result)) indvdum@0: { indvdum@0: $orig_topic_id = $shadow_topic_list[$row['topic_id']]; indvdum@0: indvdum@0: // If the shadow topic is already listed within the rowset (happens for active topics for example), then do not include it... indvdum@0: if (isset($rowset[$row['topic_id']])) indvdum@0: { indvdum@0: // We need to remove any trace regarding this topic. :) indvdum@0: unset($rowset[$orig_topic_id]); indvdum@0: unset($topic_list[array_search($orig_topic_id, $topic_list)]); indvdum@0: $topics_count--; indvdum@0: indvdum@0: continue; indvdum@0: } indvdum@0: indvdum@0: // Do not include those topics the user has no permission to access indvdum@0: if (!$auth->acl_get('f_read', $row['forum_id'])) indvdum@0: { indvdum@0: // We need to remove any trace regarding this topic. :) indvdum@0: unset($rowset[$orig_topic_id]); indvdum@0: unset($topic_list[array_search($orig_topic_id, $topic_list)]); indvdum@0: $topics_count--; indvdum@0: indvdum@0: continue; indvdum@0: } indvdum@0: indvdum@0: // We want to retain some values indvdum@0: $row = array_merge($row, array( indvdum@0: 'topic_moved_id' => $rowset[$orig_topic_id]['topic_moved_id'], indvdum@0: 'topic_status' => $rowset[$orig_topic_id]['topic_status'], indvdum@0: 'topic_type' => $rowset[$orig_topic_id]['topic_type'], indvdum@0: 'topic_title' => $rowset[$orig_topic_id]['topic_title'], indvdum@0: )); indvdum@0: indvdum@0: // Shadow topics are never reported indvdum@0: $row['topic_reported'] = 0; indvdum@0: indvdum@0: $rowset[$orig_topic_id] = $row; indvdum@0: } indvdum@0: $db->sql_freeresult($result); indvdum@0: } indvdum@0: unset($shadow_topic_list); indvdum@0: indvdum@0: // Ok, adjust topics count for active topics list indvdum@0: if ($s_display_active) indvdum@0: { indvdum@0: $topics_count = 1; indvdum@0: } indvdum@0: indvdum@0: // We need to readd the local announcements to the forums total topic count, otherwise the number is different from the one on the forum list indvdum@0: $total_topic_count = $topics_count + sizeof($announcement_list) - sizeof($global_announce_list); indvdum@0: indvdum@0: $template->assign_vars(array( indvdum@0: 'PAGINATION' => generate_pagination(append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&$u_sort_param" : '')), $topics_count, $config['topics_per_page'], $start), indvdum@0: 'PAGE_NUMBER' => on_page($topics_count, $config['topics_per_page'], $start), indvdum@0: 'TOTAL_TOPICS' => ($s_display_active) ? false : (($total_topic_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $total_topic_count))) indvdum@0: ); indvdum@0: indvdum@0: $topic_list = ($store_reverse) ? array_merge($announcement_list, array_reverse($topic_list)) : array_merge($announcement_list, $topic_list); indvdum@0: $topic_tracking_info = $tracking_topics = array(); indvdum@0: indvdum@0: // Okay, lets dump out the page ... indvdum@0: if (sizeof($topic_list)) indvdum@0: { indvdum@0: $mark_forum_read = true; indvdum@0: $mark_time_forum = 0; indvdum@0: indvdum@0: // Active topics? indvdum@0: if ($s_display_active && sizeof($active_forum_ary)) indvdum@0: { indvdum@0: // Generate topic forum list... indvdum@0: $topic_forum_list = array(); indvdum@0: foreach ($rowset as $t_id => $row) indvdum@0: { indvdum@0: $topic_forum_list[$row['forum_id']]['forum_mark_time'] = ($config['load_db_lastread'] && $user->data['is_registered'] && isset($row['forum_mark_time'])) ? $row['forum_mark_time'] : 0; indvdum@0: $topic_forum_list[$row['forum_id']]['topics'][] = $t_id; indvdum@0: } indvdum@0: indvdum@0: if ($config['load_db_lastread'] && $user->data['is_registered']) indvdum@0: { indvdum@0: foreach ($topic_forum_list as $f_id => $topic_row) indvdum@0: { indvdum@0: $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']), false); indvdum@0: } indvdum@0: } indvdum@0: else if ($config['load_anon_lastread'] || $user->data['is_registered']) indvdum@0: { indvdum@0: foreach ($topic_forum_list as $f_id => $topic_row) indvdum@0: { indvdum@0: $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics'], false); indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: unset($topic_forum_list); indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: if ($config['load_db_lastread'] && $user->data['is_registered']) indvdum@0: { indvdum@0: $topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $rowset, array($forum_id => $forum_data['mark_time']), $global_announce_list); indvdum@0: $mark_time_forum = (!empty($forum_data['mark_time'])) ? $forum_data['mark_time'] : $user->data['user_lastmark']; indvdum@0: } indvdum@0: else if ($config['load_anon_lastread'] || $user->data['is_registered']) indvdum@0: { indvdum@0: $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list, $global_announce_list); indvdum@0: indvdum@0: if (!$user->data['is_registered']) indvdum@0: { indvdum@0: $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0; indvdum@0: } indvdum@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']; indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: $s_type_switch = 0; indvdum@0: foreach ($topic_list as $topic_id) indvdum@0: { indvdum@0: $row = &$rowset[$topic_id]; indvdum@0: indvdum@0: $topic_forum_id = ($row['forum_id']) ? (int) $row['forum_id'] : $forum_id; indvdum@0: indvdum@0: // This will allow the style designer to output a different header indvdum@0: // or even separate the list of announcements from sticky and normal topics indvdum@0: $s_type_switch_test = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0; indvdum@0: indvdum@0: // Replies indvdum@0: $replies = ($auth->acl_get('m_approve', $topic_forum_id)) ? $row['topic_replies_real'] : $row['topic_replies']; indvdum@0: indvdum@0: if ($row['topic_status'] == ITEM_MOVED) indvdum@0: { indvdum@0: $topic_id = $row['topic_moved_id']; indvdum@0: $unread_topic = false; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false; indvdum@0: } indvdum@0: indvdum@0: // Get folder img, topic status/type related information indvdum@0: $folder_img = $folder_alt = $topic_type = ''; indvdum@0: topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type); indvdum@0: indvdum@0: // Generate all the URIs ... indvdum@0: $view_topic_url_params = 'f=' . $topic_forum_id . '&t=' . $topic_id; indvdum@0: $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params); indvdum@0: indvdum@0: $topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $topic_forum_id)) ? true : false; indvdum@0: $posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $topic_forum_id)) ? true : false; indvdum@0: $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&t=$topic_id", true, $user->session_id) : ''; indvdum@0: indvdum@0: // Send vars to template indvdum@0: $template->assign_block_vars('topicrow', array( indvdum@0: 'FORUM_ID' => $topic_forum_id, indvdum@0: 'TOPIC_ID' => $topic_id, indvdum@0: 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), indvdum@0: 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), indvdum@0: 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), indvdum@0: 'FIRST_POST_TIME' => $user->format_date($row['topic_time']), indvdum@0: 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']), indvdum@0: 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']), indvdum@0: 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']), indvdum@0: 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), indvdum@0: 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), indvdum@0: 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), indvdum@0: indvdum@0: 'PAGINATION' => topic_generate_pagination($replies, $view_topic_url), indvdum@0: 'REPLIES' => $replies, indvdum@0: 'VIEWS' => $row['topic_views'], indvdum@0: 'TOPIC_TITLE' => censor_text($row['topic_title']), indvdum@0: 'TOPIC_TYPE' => $topic_type, indvdum@0: indvdum@0: 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt), indvdum@0: 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'), indvdum@0: 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt], indvdum@0: 'TOPIC_FOLDER_IMG_WIDTH'=> $user->img($folder_img, '', false, '', 'width'), indvdum@0: 'TOPIC_FOLDER_IMG_HEIGHT' => $user->img($folder_img, '', false, '', 'height'), indvdum@0: indvdum@0: 'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '', indvdum@0: 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '', indvdum@0: 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '', indvdum@0: 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $topic_forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', indvdum@0: 'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', indvdum@0: indvdum@0: 'S_TOPIC_TYPE' => $row['topic_type'], indvdum@0: 'S_USER_POSTED' => (isset($row['topic_posted']) && $row['topic_posted']) ? true : false, indvdum@0: 'S_UNREAD_TOPIC' => $unread_topic, indvdum@0: 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $topic_forum_id)) ? true : false, indvdum@0: 'S_TOPIC_UNAPPROVED' => $topic_unapproved, indvdum@0: 'S_POSTS_UNAPPROVED' => $posts_unapproved, indvdum@0: 'S_HAS_POLL' => ($row['poll_start']) ? true : false, indvdum@0: 'S_POST_ANNOUNCE' => ($row['topic_type'] == POST_ANNOUNCE) ? true : false, indvdum@0: 'S_POST_GLOBAL' => ($row['topic_type'] == POST_GLOBAL) ? true : false, indvdum@0: 'S_POST_STICKY' => ($row['topic_type'] == POST_STICKY) ? true : false, indvdum@0: 'S_TOPIC_LOCKED' => ($row['topic_status'] == ITEM_LOCKED) ? true : false, indvdum@0: 'S_TOPIC_MOVED' => ($row['topic_status'] == ITEM_MOVED) ? true : false, indvdum@0: indvdum@0: 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&view=unread') . '#unread', indvdum@0: 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'], indvdum@0: 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), indvdum@0: 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), indvdum@0: 'U_VIEW_TOPIC' => $view_topic_url, indvdum@0: 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=reports&f=' . $topic_forum_id . '&t=' . $topic_id, true, $user->session_id), indvdum@0: 'U_MCP_QUEUE' => $u_mcp_queue, indvdum@0: indvdum@0: 'S_TOPIC_TYPE_SWITCH' => ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test) indvdum@0: ); indvdum@0: indvdum@0: $s_type_switch = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0; indvdum@0: indvdum@0: if ($unread_topic) indvdum@0: { indvdum@0: $mark_forum_read = false; indvdum@0: } indvdum@0: indvdum@0: unset($rowset[$topic_id]); indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: // This is rather a fudge but it's the best I can think of without requiring information indvdum@0: // on all topics (as we do in 2.0.x). It looks for unread or new topics, if it doesn't find indvdum@0: // any it updates the forum last read cookie. This requires that the user visit the forum indvdum@0: // after reading a topic indvdum@0: if ($forum_data['forum_type'] == FORUM_POST && sizeof($topic_list) && $mark_forum_read) indvdum@0: { indvdum@0: update_forum_tracking_info($forum_id, $forum_data['forum_last_post_time'], false, $mark_time_forum); indvdum@0: } indvdum@0: indvdum@0: page_footer(); indvdum@0: indvdum@0: ?>