All pastes #80664 Raw Edit

Something

public php v1 · immutable
·published 2006-07-06 18:02 UTC
rendered paste body
function display_forums($root_data = '', $display_moderators = true, $return_moderators = false){	global $db, $auth, $user, $template;	global $phpbb_root_path, $phpEx, $SID, $config;	$forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();	$parent_id = $visible_forums = 0;	$sql_from = $lastread_select = '';		// 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 = ' 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'] & 16) ? true : false;	if ($config['load_db_lastread'] && $user->data['is_registered'])	{		$sql_from = FORUMS_TABLE . ' f LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id)';		$lastread_select = ', ft.mark_time ';	}	else	{		$sql_from = FORUMS_TABLE . ' f ';		$lastread_select = $sql_lastread = '';		$tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array();		if (!$user->data['is_registered'])		{			$user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate'] : 0;		}	}	$sql = "SELECT f.* $lastread_select		FROM $sql_from		$sql_where		ORDER BY f.left_id";	$result = $db->sql_query($sql);	$forum_tracking_info = array();	$branch_root_id = $root_data['forum_id'];	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 (!$user->data['is_registered'])			{				$user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate'] : 0;			}			$forum_tracking_info[$forum_id] = (isset($tracking_topics['f'][$forum_id])) ? base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate'] : $user->data['user_lastmark'];		}		// Display active topics from this forum?		if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & 16))		{			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']	+= ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics'];			$active_forum_ary['forum_posts']	+= $row['forum_posts'];		}		//		if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id)		{			// Direct child of current branch			$parent_id = $forum_id;			$forum_rows[$forum_id] = $row;			if (!$row['parent_id'] && $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'];						$forum_rows[$parent_id]['forum_topics'] += ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $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_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_id_last_post'] = $forum_id;			}			else			{				$forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;			}		}		$forum_ids_moderator[$parent_id] = $forum_rows[$parent_id]['forum_id_last_post'];	}	$db->sql_freeresult($result);	// Handle marking posts	if ($mark_read == 'forums' || $mark_read == 'all')	{		$redirect = build_url('mark');		if ($mark_read == 'all')		{			markread('all');			$message = sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>');		}		else		{			markread('topics', $forum_ids);			$message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');		}				meta_refresh(3, $redirect);				$message = $user->lang['FORUMS_MARKED'] . '<br /><br />' . $message;		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);	}	foreach ($forum_rows as $row)	{		// Empty category		if (!$row['parent_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']),				'U_VIEWFORUM'		=>	"{$phpbb_root_path}viewforum.$phpEx$SID&amp;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;		$folder_image = $folder_alt = $subforums_list = $l_subforums = '';		// Generate list of subforums if we need to		if (isset($subforums[$forum_id]))		{			foreach ($subforums[$forum_id] as $subforum_id => $subforum_row)			{				// Update unread information if needed				if (!$forum_unread)				{					$forum_unread = (isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id]) ? true : false;				}				if ($subforum_row['display'] && $subforum_row['name'])				{					$subforums_list .= ($subforums_list == '') ? '' : ', ';					$subforums_list .= '<a href="' . $phpbb_root_path . "viewforum.$phpEx$SID&amp;f=$subforum_id\">{$subforum_row['name']}</a>";				}				else				{					unset($subforums[$forum_id][$subforum_id]);				}			}						$l_subforums = (sizeof($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';			$folder_image = ($forum_unread) ? 'sub_forum_new' : 'sub_forum';		}		else		{			switch ($row['forum_type'])			{				case FORUM_POST:					$folder_image = ($forum_unread) ? 'forum_new' : 'forum';				break;				case FORUM_LINK:					$folder_image = 'forum_link';				break;			}		}		// Which folder should we display?		if ($row['forum_status'] == ITEM_LOCKED)		{			$folder_image = 'forum_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_time = $user->format_date($row['forum_last_post_time']);			$last_poster = ($row['forum_last_poster_name'] != '') ? $row['forum_last_poster_name'] : $user->lang['GUEST'];			$last_poster_url = ($row['forum_last_poster_id'] == ANONYMOUS) ? '' : "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=viewprofile&amp;u={$row['forum_last_poster_id']}";			$last_post_url = "{$phpbb_root_path}viewtopic.$phpEx$SID&amp;f=" . $row['forum_id_last_post'] . '&amp;p=' . $row['forum_last_post_id'] . '#p' . $row['forum_last_post_id'];		}		else		{			$last_post_time = $last_poster = $last_poster_url = $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'] & 1) ? $row['forum_posts'] : '';		$template->assign_block_vars('forumrow', array(			'S_IS_CAT'			=> false,			'S_IS_LINK'			=> ($row['forum_type'] == FORUM_LINK) ? 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']),			'TOPICS'				=> $row['forum_topics'],			$l_post_click_count		=> $post_click_count,			'FORUM_FOLDER_IMG'		=> ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $folder_alt . '" />' : $user->img($folder_image, $folder_alt),			'FORUM_FOLDER_IMG_SRC'	=> ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : $user->img($folder_image, $folder_alt, false, '', 'src'),			'SUBFORUMS'				=> $subforums_list,			'LAST_POST_TIME'		=> $last_post_time,			'LAST_POSTER'			=> $last_poster,			'MODERATORS'			=> $moderators_list,			'L_SUBFORUM_STR'	=> $l_subforums,			'L_FORUM_FOLDER_ALT'=> $folder_alt,			'L_MODERATOR_STR'	=> $l_moderator,			'U_VIEWFORUM'		=> ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & 1) ? "{$phpbb_root_path}viewforum.$phpEx$SID&amp;f={$row['forum_id']}" : $row['forum_link'],			'U_LAST_POSTER'		=> $last_poster_url,			'U_LAST_POST'		=> $last_post_url,			)		);	}	$template->assign_vars(array(		'U_MARK_FORUMS'		=> "{$phpbb_root_path}viewforum.$phpEx$SID&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_post_latest', 'VIEW_LATEST_POST'),		)	);	if ($return_moderators)	{		return array($active_forum_ary, $forum_moderators);	}	return $active_forum_ary;}