Code: Selecteer alles
$result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
while ($row = $db->sql_fetchrow($result))
{
$topic_list[] = (int) $row['topic_id'];
}
$db->sql_freeresult($result);
// For storing shadow topics
$shadow_topic_list = array();
if (sizeof($topic_list))
{
// SQL array for obtaining topics/stickies
$sql_array = array(
'SELECT' => $sql_array['SELECT'],
'FROM' => $sql_array['FROM'],
'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
'WHERE' => $db->sql_in_set('t.topic_id', $topic_list),
);
// If store_reverse, then first obtain topics, then stickies, else the other way around...
// Funnily enough you typically save one query if going from the last page to the middle (store_reverse) because
// the number of stickies are not known
$sql = $db->sql_build_query('SELECT', $sql_array);
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
if ($row['topic_status'] == ITEM_MOVED)
{
$shadow_topic_list[$row['topic_moved_id']] = $row['topic_id'];
}
$rowset[$row['topic_id']] = $row;
}
$db->sql_freeresult($result);
}
// If we have some shadow topics, update the rowset to reflect their topic information
if (sizeof($shadow_topic_list))
{
$sql = 'SELECT *
FROM ' . TOPICS_TABLE . '
WHERE ' . $db->sql_in_set('topic_id', array_keys($shadow_topic_list));
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$orig_topic_id = $shadow_topic_list[$row['topic_id']];
// If the shadow topic is already listed within the rowset (happens for active topics for example), then do not include it...
if (isset($rowset[$row['topic_id']]))
{
// We need to remove any trace regarding this topic. :)
unset($rowset[$orig_topic_id]);
unset($topic_list[array_search($orig_topic_id, $topic_list)]);
$topics_count--;
continue;
}
// Do not include those topics the user has no permission to access
if (!$auth->acl_get('f_read', $row['forum_id']))
{
// We need to remove any trace regarding this topic. :)
unset($rowset[$orig_topic_id]);
unset($topic_list[array_search($orig_topic_id, $topic_list)]);
$topics_count--;
continue;
}
// We want to retain some values
$row = array_merge($row, array(
'topic_moved_id' => $rowset[$orig_topic_id]['topic_moved_id'],
'topic_status' => $rowset[$orig_topic_id]['topic_status'],
'topic_type' => $rowset[$orig_topic_id]['topic_type'],
));
// Shadow topics are never reported
$row['topic_reported'] = 0;
$rowset[$orig_topic_id] = $row;
}
$db->sql_freeresult($result);
}
unset($shadow_topic_list);
// Ok, adjust topics count for active topics list
if ($s_display_active)
{
$topics_count = 1;
}
$template->assign_vars(array(
'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),
'PAGE_NUMBER' => on_page($topics_count, $config['topics_per_page'], $start),
'TOTAL_TOPICS' => ($s_display_active) ? false : (($topics_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $topics_count)))
);
$topic_list = ($store_reverse) ? array_merge($announcement_list, array_reverse($topic_list)) : array_merge($announcement_list, $topic_list);
$topic_tracking_info = $tracking_topics = array();
// Okay, lets dump out the page ...
if (sizeof($topic_list))
{
$mark_forum_read = true;
$mark_time_forum = 0;
// Active topics?
if ($s_display_active && sizeof($active_forum_ary))
{
// Generate topic forum list...
$topic_forum_list = array();
foreach ($rowset as $t_id => $row)
{
$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;
$topic_forum_list[$row['forum_id']]['topics'][] = $t_id;
}
if ($config['load_db_lastread'] && $user->data['is_registered'])
{
foreach ($topic_forum_list as $f_id => $topic_row)
{
$topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']), false);
}
}
else if ($config['load_anon_lastread'] || $user->data['is_registered'])
{
foreach ($topic_forum_list as $f_id => $topic_row)
{
$topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics'], false);
}
}
unset($topic_forum_list);
}
else
{
if ($config['load_db_lastread'] && $user->data['is_registered'])
{
$topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $rowset, array($forum_id => $forum_data['mark_time']), $global_announce_list);
$mark_time_forum = (!empty($forum_data['mark_time'])) ? $forum_data['mark_time'] : $user->data['user_lastmark'];
}
else if ($config['load_anon_lastread'] || $user->data['is_registered'])
{
$topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list, $global_announce_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;
}
$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'];
}
}
$s_type_switch = 0;
foreach ($topic_list as $topic_id)
{
$row = &$rowset[$topic_id];
// 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 = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
// Replies
$replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
if ($row['topic_status'] == ITEM_MOVED)
{
$topic_id = $row['topic_moved_id'];
$unread_topic = false;
}
else
{
$unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
}
// 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);
// Generate all the URIs ...
$view_topic_url_params = 'f=' . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . '&t=' . $topic_id;
$view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params);
$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&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&t=$topic_id", true, $user->session_id) : '';
// Send vars to template
$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']),
'PAGINATION' => topic_generate_pagination($replies, $view_topic_url),
'REPLIES' => $replies,
'VIEWS' => $row['topic_views'],
'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'),
'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt],
'TOPIC_FOLDER_IMG_WIDTH'=> $user->img($folder_img, '', false, '', 'width'),
'TOPIC_FOLDER_IMG_HEIGHT' => $user->img($folder_img, '', false, '', 'height'),
'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') : '',
'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' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&view=unread') . '#unread',
'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'],
'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_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=reports&f=' . $forum_id . '&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)
);
$s_type_switch = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
if ($unread_topic)
{
$mark_forum_read = false;
}
unset($rowset[$topic_id]);
}
}
// This is rather a fudge but it's the best I can think of without requiring information
// on all topics (as we do in 2.0.x). It looks for unread or new topics, if it doesn't find
// any it updates the forum last read cookie. This requires that the user visit the forum
// after reading a topic
if ($forum_data['forum_type'] == FORUM_POST && sizeof($topic_list) && $mark_forum_read)
{
update_forum_tracking_info($forum_id, $forum_data['forum_last_post_time'], false, $mark_time_forum);
}
page_footer();
?>