Blame Identity/Webenv/App/phpBB/3.0.4/includes/functions_display.php

f2e824
f2e824
/**
f2e824
*
f2e824
* @package phpBB3
f2e824
* @version $Id: functions_display.php 9082 2008-11-22 20:26:09Z acydburn $
f2e824
* @copyright (c) 2005 phpBB Group
f2e824
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
f2e824
*
f2e824
*/
f2e824
f2e824
/**
f2e824
* @ignore
f2e824
*/
f2e824
if (!defined('IN_PHPBB'))
f2e824
{
f2e824
	exit;
f2e824
}
f2e824
f2e824
/**
f2e824
* Display Forums
f2e824
*/
f2e824
function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
f2e824
{
f2e824
	global $db, $auth, $user, $template;
f2e824
	global $phpbb_root_path, $phpEx, $config;
f2e824
f2e824
	$forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
f2e824
	$parent_id = $visible_forums = 0;
f2e824
	$sql_from = '';
f2e824
f2e824
	// Mark forums read?
f2e824
	$mark_read = request_var('mark', '');
f2e824
f2e824
	if ($mark_read == 'all')
f2e824
	{
f2e824
		$mark_read = '';
f2e824
	}
f2e824
f2e824
	if (!$root_data)
f2e824
	{
f2e824
		if ($mark_read == 'forums')
f2e824
		{
f2e824
			$mark_read = 'all';
f2e824
		}
f2e824
f2e824
		$root_data = array('forum_id' => 0);
f2e824
		$sql_where = '';
f2e824
	}
f2e824
	else
f2e824
	{
f2e824
		$sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
f2e824
	}
f2e824
f2e824
	// Display list of active topics for this category?
f2e824
	$show_active = (isset($root_data['forum_flags']) && ($root_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
f2e824
f2e824
	$sql_array = array(
f2e824
		'SELECT'	=> 'f.*',
f2e824
		'FROM'		=> array(
f2e824
			FORUMS_TABLE		=> 'f'
f2e824
		),
f2e824
		'LEFT_JOIN'	=> array(),
f2e824
	);
f2e824
f2e824
	if ($config['load_db_lastread'] && $user->data['is_registered'])
f2e824
	{
f2e824
		$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');
f2e824
		$sql_array['SELECT'] .= ', ft.mark_time';
f2e824
	}
f2e824
	else if ($config['load_anon_lastread'] || $user->data['is_registered'])
f2e824
	{
f2e824
		$tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : '';
f2e824
		$tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
f2e824
f2e824
		if (!$user->data['is_registered'])
f2e824
		{
f2e824
			$user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
f2e824
		}
f2e824
	}
f2e824
f2e824
	if ($show_active)
f2e824
	{
f2e824
		$sql_array['LEFT_JOIN'][] = array(
f2e824
			'FROM'	=> array(FORUMS_ACCESS_TABLE => 'fa'),
f2e824
			'ON'	=> "fa.forum_id = f.forum_id AND fa.session_id = '" . $db->sql_escape($user->session_id) . "'"
f2e824
		);
f2e824
f2e824
		$sql_array['SELECT'] .= ', fa.user_id';
f2e824
	}
f2e824
f2e824
	$sql = $db->sql_build_query('SELECT', array(
f2e824
		'SELECT'	=> $sql_array['SELECT'],
f2e824
		'FROM'		=> $sql_array['FROM'],
f2e824
		'LEFT_JOIN'	=> $sql_array['LEFT_JOIN'],
f2e824
f2e824
		'WHERE'		=> $sql_where,
f2e824
f2e824
		'ORDER_BY'	=> 'f.left_id',
f2e824
	));
f2e824
f2e824
	$result = $db->sql_query($sql);
f2e824
f2e824
	$forum_tracking_info = array();
f2e824
	$branch_root_id = $root_data['forum_id'];
f2e824
	while ($row = $db->sql_fetchrow($result))
f2e824
	{
f2e824
		$forum_id = $row['forum_id'];
f2e824
f2e824
		// Mark forums read?
f2e824
		if ($mark_read == 'forums' || $mark_read == 'all')
f2e824
		{
f2e824
			if ($auth->acl_get('f_list', $forum_id))
f2e824
			{
f2e824
				$forum_ids[] = $forum_id;
f2e824
				continue;
f2e824
			}
f2e824
		}
f2e824
f2e824
		// Category with no members
f2e824
		if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
f2e824
		{
f2e824
			continue;
f2e824
		}
f2e824
f2e824
		// Skip branch
f2e824
		if (isset($right_id))
f2e824
		{
f2e824
			if ($row['left_id'] < $right_id)
f2e824
			{
f2e824
				continue;
f2e824
			}
f2e824
			unset($right_id);
f2e824
		}
f2e824
f2e824
		if (!$auth->acl_get('f_list', $forum_id))
f2e824
		{
f2e824
			// if the user does not have permissions to list this forum, skip everything until next branch
f2e824
			$right_id = $row['right_id'];
f2e824
			continue;
f2e824
		}
f2e824
f2e824
		$forum_ids[] = $forum_id;
f2e824
f2e824
		if ($config['load_db_lastread'] && $user->data['is_registered'])
f2e824
		{
f2e824
			$forum_tracking_info[$forum_id] = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
f2e824
		}
f2e824
		else if ($config['load_anon_lastread'] || $user->data['is_registered'])
f2e824
		{
f2e824
			if (!$user->data['is_registered'])
f2e824
			{
f2e824
				$user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
f2e824
			}
f2e824
			$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'];
f2e824
		}
f2e824
f2e824
		$row['forum_topics'] = ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics'];
f2e824
f2e824
		// Display active topics from this forum?
f2e824
		if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS))
f2e824
		{
f2e824
			if (!isset($active_forum_ary['forum_topics']))
f2e824
			{
f2e824
				$active_forum_ary['forum_topics'] = 0;
f2e824
			}
f2e824
f2e824
			if (!isset($active_forum_ary['forum_posts']))
f2e824
			{
f2e824
				$active_forum_ary['forum_posts'] = 0;
f2e824
			}
f2e824
f2e824
			$active_forum_ary['forum_id'][]		= $forum_id;
f2e824
			$active_forum_ary['enable_icons'][]	= $row['enable_icons'];
f2e824
			$active_forum_ary['forum_topics']	+= $row['forum_topics'];
f2e824
			$active_forum_ary['forum_posts']	+= $row['forum_posts'];
f2e824
f2e824
			// If this is a passworded forum we do not show active topics from it if the user is not authorised to view it...
f2e824
			if ($row['forum_password'] && $row['user_id'] != $user->data['user_id'])
f2e824
			{
f2e824
				$active_forum_ary['exclude_forum_id'][] = $forum_id;
f2e824
			}
f2e824
		}
f2e824
f2e824
		//
f2e824
		if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id)
f2e824
		{
f2e824
			if ($row['forum_type'] != FORUM_CAT)
f2e824
			{
f2e824
				$forum_ids_moderator[] = (int) $forum_id;
f2e824
			}
f2e824
f2e824
			// Direct child of current branch
f2e824
			$parent_id = $forum_id;
f2e824
			$forum_rows[$forum_id] = $row;
f2e824
f2e824
			if ($row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id'])
f2e824
			{
f2e824
				$branch_root_id = $forum_id;
f2e824
			}
f2e824
			$forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
f2e824
			$forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
f2e824
		}
f2e824
		else if ($row['forum_type'] != FORUM_CAT)
f2e824
		{
f2e824
			$subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index']) ? true : false;
f2e824
			$subforums[$parent_id][$forum_id]['name'] = $row['forum_name'];
f2e824
			$subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
f2e824
			$subforums[$parent_id][$forum_id]['children'] = array();
f2e824
f2e824
			if (isset($subforums[$parent_id][$row['parent_id']]) && !$row['display_on_index'])
f2e824
			{
f2e824
				$subforums[$parent_id][$row['parent_id']]['children'][] = $forum_id;
f2e824
			}
f2e824
f2e824
			$forum_rows[$parent_id]['forum_topics'] += $row['forum_topics'];
f2e824
f2e824
			// Do not list redirects in LINK Forums as Posts.
f2e824
			if ($row['forum_type'] != FORUM_LINK)
f2e824
			{
f2e824
				$forum_rows[$parent_id]['forum_posts'] += $row['forum_posts'];
f2e824
			}
f2e824
f2e824
			if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time'])
f2e824
			{
f2e824
				$forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
f2e824
				$forum_rows[$parent_id]['forum_last_post_subject'] = $row['forum_last_post_subject'];
f2e824
				$forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
f2e824
				$forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
f2e824
				$forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
f2e824
				$forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour'];
f2e824
				$forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
f2e824
			}
f2e824
		}
f2e824
	}
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	// Handle marking posts
f2e824
	if ($mark_read == 'forums' || $mark_read == 'all')
f2e824
	{
f2e824
		$redirect = build_url('mark', 'hash');
f2e824
		$token = request_var('hash', '');
f2e824
		if (check_link_hash($token, 'global'))
f2e824
		{
f2e824
			if ($mark_read == 'all')
f2e824
			{
f2e824
				markread('all');
f2e824
				$message = sprintf($user->lang['RETURN_INDEX'], '', '');
f2e824
			}
f2e824
			else
f2e824
			{
f2e824
				markread('topics', $forum_ids);
f2e824
				$message = sprintf($user->lang['RETURN_FORUM'], '', '');
f2e824
			}
f2e824
			meta_refresh(3, $redirect);
f2e824
			trigger_error($user->lang['FORUMS_MARKED'] . '

' . $message);
f2e824
		}
f2e824
		else
f2e824
		{
f2e824
			$message = sprintf($user->lang['RETURN_PAGE'], '', '');
f2e824
			meta_refresh(3, $redirect);
f2e824
			trigger_error($message);
f2e824
		}
f2e824
f2e824
	}
f2e824
f2e824
	// Grab moderators ... if necessary
f2e824
	if ($display_moderators)
f2e824
	{
f2e824
		if ($return_moderators)
f2e824
		{
f2e824
			$forum_ids_moderator[] = $root_data['forum_id'];
f2e824
		}
f2e824
		get_moderators($forum_moderators, $forum_ids_moderator);
f2e824
	}
f2e824
f2e824
	// Used to tell whatever we have to create a dummy category or not.
f2e824
	$last_catless = true;
f2e824
	foreach ($forum_rows as $row)
f2e824
	{
f2e824
		// Empty category
f2e824
		if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT)
f2e824
		{
f2e824
			$template->assign_block_vars('forumrow', array(
f2e824
				'S_IS_CAT'				=> true,
f2e824
				'FORUM_ID'				=> $row['forum_id'],
f2e824
				'FORUM_NAME'			=> $row['forum_name'],
f2e824
				'FORUM_DESC'			=> generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
f2e824
				'FORUM_FOLDER_IMG'		=> '',
f2e824
				'FORUM_FOLDER_IMG_SRC'	=> '',
f2e824
				'FORUM_IMAGE'			=> ($row['forum_image']) ? '' . $user->lang['FORUM_CAT'] . '' : '',
f2e824
				'FORUM_IMAGE_SRC'		=> ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
f2e824
				'U_VIEWFORUM'			=> append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
f2e824
			);
f2e824
f2e824
			continue;
f2e824
		}
f2e824
f2e824
		$visible_forums++;
f2e824
		$forum_id = $row['forum_id'];
f2e824
f2e824
		$forum_unread = (isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id]) ? true : false;
f2e824
f2e824
		$folder_image = $folder_alt = $l_subforums = '';
f2e824
		$subforums_list = array();
f2e824
f2e824
		// Generate list of subforums if we need to
f2e824
		if (isset($subforums[$forum_id]))
f2e824
		{
f2e824
			foreach ($subforums[$forum_id] as $subforum_id => $subforum_row)
f2e824
			{
f2e824
				$subforum_unread = (isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id]) ? true : false;
f2e824
f2e824
				if (!$subforum_unread && !empty($subforum_row['children']))
f2e824
				{
f2e824
					foreach ($subforum_row['children'] as $child_id)
f2e824
					{
f2e824
						if (isset($forum_tracking_info[$child_id]) && $subforums[$forum_id][$child_id]['orig_forum_last_post_time'] > $forum_tracking_info[$child_id])
f2e824
						{
f2e824
							// Once we found an unread child forum, we can drop out of this loop
f2e824
							$subforum_unread = true;
f2e824
							break;
f2e824
						}
f2e824
					}
f2e824
				}
f2e824
f2e824
				if ($subforum_row['display'] && $subforum_row['name'])
f2e824
				{
f2e824
					$subforums_list[] = array(
f2e824
						'link'		=> append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $subforum_id),
f2e824
						'name'		=> $subforum_row['name'],
f2e824
						'unread'	=> $subforum_unread,
f2e824
					);
f2e824
				}
f2e824
				else
f2e824
				{
f2e824
					unset($subforums[$forum_id][$subforum_id]);
f2e824
				}
f2e824
f2e824
				// If one subforum is unread the forum gets unread too...
f2e824
				if ($subforum_unread)
f2e824
				{
f2e824
					$forum_unread = true;
f2e824
				}
f2e824
			}
f2e824
f2e824
			$l_subforums = (sizeof($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';
f2e824
			$folder_image = ($forum_unread) ? 'forum_unread_subforum' : 'forum_read_subforum';
f2e824
		}
f2e824
		else
f2e824
		{
f2e824
			switch ($row['forum_type'])
f2e824
			{
f2e824
				case FORUM_POST:
f2e824
					$folder_image = ($forum_unread) ? 'forum_unread' : 'forum_read';
f2e824
				break;
f2e824
f2e824
				case FORUM_LINK:
f2e824
					$folder_image = 'forum_link';
f2e824
				break;
f2e824
			}
f2e824
		}
f2e824
f2e824
		// Which folder should we display?
f2e824
		if ($row['forum_status'] == ITEM_LOCKED)
f2e824
		{
f2e824
			$folder_image = ($forum_unread) ? 'forum_unread_locked' : 'forum_read_locked';
f2e824
			$folder_alt = 'FORUM_LOCKED';
f2e824
		}
f2e824
		else
f2e824
		{
f2e824
			$folder_alt = ($forum_unread) ? 'NEW_POSTS' : 'NO_NEW_POSTS';
f2e824
		}
f2e824
f2e824
		// Create last post link information, if appropriate
f2e824
		if ($row['forum_last_post_id'])
f2e824
		{
f2e824
			$last_post_subject = $row['forum_last_post_subject'];
f2e824
			$last_post_time = $user->format_date($row['forum_last_post_time']);
f2e824
			$last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&p=' . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
f2e824
		}
f2e824
		else
f2e824
		{
f2e824
			$last_post_subject = $last_post_time = $last_post_url = '';
f2e824
		}
f2e824
f2e824
		// Output moderator listing ... if applicable
f2e824
		$l_moderator = $moderators_list = '';
f2e824
		if ($display_moderators && !empty($forum_moderators[$forum_id]))
f2e824
		{
f2e824
			$l_moderator = (sizeof($forum_moderators[$forum_id]) == 1) ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
f2e824
			$moderators_list = implode(', ', $forum_moderators[$forum_id]);
f2e824
		}
f2e824
f2e824
		$l_post_click_count = ($row['forum_type'] == FORUM_LINK) ? 'CLICKS' : 'POSTS';
f2e824
		$post_click_count = ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? $row['forum_posts'] : '';
f2e824
f2e824
		$s_subforums_list = array();
f2e824
		foreach ($subforums_list as $subforum)
f2e824
		{
f2e824
			$s_subforums_list[] = '' . $subforum['name'] . '';
f2e824
		}
f2e824
		$s_subforums_list = (string) implode(', ', $s_subforums_list);
f2e824
		$catless = ($row['parent_id'] == $root_data['forum_id']) ? true : false;
f2e824
f2e824
		if ($row['forum_type'] != FORUM_LINK)
f2e824
		{
f2e824
			$u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
f2e824
		}
f2e824
		else
f2e824
		{
f2e824
			// If the forum is a link and we count redirects we need to visit it
f2e824
			// If the forum is having a password or no read access we do not expose the link, but instead handle it in viewforum
f2e824
			if (($row['forum_flags'] & FORUM_FLAG_LINK_TRACK) || $row['forum_password'] || !$auth->acl_get('f_read', $forum_id))
f2e824
			{
f2e824
				$u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
f2e824
			}
f2e824
			else
f2e824
			{
f2e824
				$u_viewforum = $row['forum_link'];
f2e824
			}
f2e824
		}
f2e824
f2e824
		$template->assign_block_vars('forumrow', array(
f2e824
			'S_IS_CAT'			=> false,
f2e824
			'S_NO_CAT'			=> $catless && !$last_catless,
f2e824
			'S_IS_LINK'			=> ($row['forum_type'] == FORUM_LINK) ? true : false,
f2e824
			'S_UNREAD_FORUM'	=> $forum_unread,
f2e824
			'S_LOCKED_FORUM'	=> ($row['forum_status'] == ITEM_LOCKED) ? true : false,
f2e824
			'S_LIST_SUBFORUMS'	=> ($row['display_subforum_list']) ? true : false,
f2e824
			'S_SUBFORUMS'		=> (sizeof($subforums_list)) ? true : false,
f2e824
f2e824
			'FORUM_ID'				=> $row['forum_id'],
f2e824
			'FORUM_NAME'			=> $row['forum_name'],
f2e824
			'FORUM_DESC'			=> generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
f2e824
			'TOPICS'				=> $row['forum_topics'],
f2e824
			$l_post_click_count		=> $post_click_count,
f2e824
			'FORUM_FOLDER_IMG'		=> $user->img($folder_image, $folder_alt),
f2e824
			'FORUM_FOLDER_IMG_SRC'	=> $user->img($folder_image, $folder_alt, false, '', 'src'),
f2e824
			'FORUM_FOLDER_IMG_ALT'	=> isset($user->lang[$folder_alt]) ? $user->lang[$folder_alt] : '',
f2e824
			'FORUM_IMAGE'			=> ($row['forum_image']) ? '' . $user->lang[$folder_alt] . '' : '',
f2e824
			'FORUM_IMAGE_SRC'		=> ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
f2e824
			'LAST_POST_SUBJECT'		=> censor_text($last_post_subject),
f2e824
			'LAST_POST_TIME'		=> $last_post_time,
f2e824
			'LAST_POSTER'			=> get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
f2e824
			'LAST_POSTER_COLOUR'	=> get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
f2e824
			'LAST_POSTER_FULL'		=> get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
f2e824
			'MODERATORS'			=> $moderators_list,
f2e824
			'SUBFORUMS'				=> $s_subforums_list,
f2e824
f2e824
			'L_SUBFORUM_STR'		=> $l_subforums,
f2e824
			'L_FORUM_FOLDER_ALT'	=> $folder_alt,
f2e824
			'L_MODERATOR_STR'		=> $l_moderator,
f2e824
f2e824
			'U_VIEWFORUM'		=> $u_viewforum,
f2e824
			'U_LAST_POSTER'		=> get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
f2e824
			'U_LAST_POST'		=> $last_post_url)
f2e824
		);
f2e824
f2e824
		// Assign subforums loop for style authors
f2e824
		foreach ($subforums_list as $subforum)
f2e824
		{
f2e824
			$template->assign_block_vars('forumrow.subforum', array(
f2e824
				'U_SUBFORUM'	=> $subforum['link'],
f2e824
				'SUBFORUM_NAME'	=> $subforum['name'],
f2e824
				'S_UNREAD'		=> $subforum['unread'])
f2e824
			);
f2e824
		}
f2e824
f2e824
		$last_catless = $catless;
f2e824
	}
f2e824
f2e824
	$template->assign_vars(array(
f2e824
		'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') : '',
f2e824
		'S_HAS_SUBFORUM'	=> ($visible_forums) ? true : false,
f2e824
		'L_SUBFORUM'		=> ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'],
f2e824
		'LAST_POST_IMG'		=> $user->img('icon_topic_latest', 'VIEW_LATEST_POST'))
f2e824
	);
f2e824
f2e824
	if ($return_moderators)
f2e824
	{
f2e824
		return array($active_forum_ary, $forum_moderators);
f2e824
	}
f2e824
f2e824
	return array($active_forum_ary, array());
f2e824
}
f2e824
f2e824
/**
f2e824
* Create forum rules for given forum
f2e824
*/
f2e824
function generate_forum_rules(&$forum_data)
f2e824
{
f2e824
	if (!$forum_data['forum_rules'] && !$forum_data['forum_rules_link'])
f2e824
	{
f2e824
		return;
f2e824
	}
f2e824
f2e824
	global $template, $phpbb_root_path, $phpEx;
f2e824
f2e824
	if ($forum_data['forum_rules'])
f2e824
	{
f2e824
		$forum_data['forum_rules'] = generate_text_for_display($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options']);
f2e824
	}
f2e824
f2e824
	$template->assign_vars(array(
f2e824
		'S_FORUM_RULES'	=> true,
f2e824
		'U_FORUM_RULES'	=> $forum_data['forum_rules_link'],
f2e824
		'FORUM_RULES'	=> $forum_data['forum_rules'])
f2e824
	);
f2e824
}
f2e824
f2e824
/**
f2e824
* Create forum navigation links for given forum, create parent
f2e824
* list if currently null, assign basic forum info to template
f2e824
*/
f2e824
function generate_forum_nav(&$forum_data)
f2e824
{
f2e824
	global $db, $user, $template, $auth;
f2e824
	global $phpEx, $phpbb_root_path;
f2e824
f2e824
	if (!$auth->acl_get('f_list', $forum_data['forum_id']))
f2e824
	{
f2e824
		return;
f2e824
	}
f2e824
f2e824
	// Get forum parents
f2e824
	$forum_parents = get_forum_parents($forum_data);
f2e824
f2e824
	// Build navigation links
f2e824
	if (!empty($forum_parents))
f2e824
	{
f2e824
		foreach ($forum_parents as $parent_forum_id => $parent_data)
f2e824
		{
f2e824
			list($parent_name, $parent_type) = array_values($parent_data);
f2e824
f2e824
			// Skip this parent if the user does not have the permission to view it
f2e824
			if (!$auth->acl_get('f_list', $parent_forum_id))
f2e824
			{
f2e824
				continue;
f2e824
			}
f2e824
f2e824
			$template->assign_block_vars('navlinks', array(
f2e824
				'S_IS_CAT'		=> ($parent_type == FORUM_CAT) ? true : false,
f2e824
				'S_IS_LINK'		=> ($parent_type == FORUM_LINK) ? true : false,
f2e824
				'S_IS_POST'		=> ($parent_type == FORUM_POST) ? true : false,
f2e824
				'FORUM_NAME'	=> $parent_name,
f2e824
				'FORUM_ID'		=> $parent_forum_id,
f2e824
				'U_VIEW_FORUM'	=> append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $parent_forum_id))
f2e824
			);
f2e824
		}
f2e824
	}
f2e824
f2e824
	$template->assign_block_vars('navlinks', array(
f2e824
		'S_IS_CAT'		=> ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
f2e824
		'S_IS_LINK'		=> ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
f2e824
		'S_IS_POST'		=> ($forum_data['forum_type'] == FORUM_POST) ? true : false,
f2e824
		'FORUM_NAME'	=> $forum_data['forum_name'],
f2e824
		'FORUM_ID'		=> $forum_data['forum_id'],
f2e824
		'U_VIEW_FORUM'	=> append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_data['forum_id']))
f2e824
	);
f2e824
f2e824
	$template->assign_vars(array(
f2e824
		'FORUM_ID' 		=> $forum_data['forum_id'],
f2e824
		'FORUM_NAME'	=> $forum_data['forum_name'],
f2e824
		'FORUM_DESC'	=> generate_text_for_display($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options']))
f2e824
	);
f2e824
f2e824
	return;
f2e824
}
f2e824
f2e824
/**
f2e824
* Returns forum parents as an array. Get them from forum_data if available, or update the database otherwise
f2e824
*/
f2e824
function get_forum_parents(&$forum_data)
f2e824
{
f2e824
	global $db;
f2e824
f2e824
	$forum_parents = array();
f2e824
f2e824
	if ($forum_data['parent_id'] > 0)
f2e824
	{
f2e824
		if ($forum_data['forum_parents'] == '')
f2e824
		{
f2e824
			$sql = 'SELECT forum_id, forum_name, forum_type
f2e824
				FROM ' . FORUMS_TABLE . '
f2e824
				WHERE left_id < ' . $forum_data['left_id'] . '
f2e824
					AND right_id > ' . $forum_data['right_id'] . '
f2e824
				ORDER BY left_id ASC';
f2e824
			$result = $db->sql_query($sql);
f2e824
f2e824
			while ($row = $db->sql_fetchrow($result))
f2e824
			{
f2e824
				$forum_parents[$row['forum_id']] = array($row['forum_name'], (int) $row['forum_type']);
f2e824
			}
f2e824
			$db->sql_freeresult($result);
f2e824
f2e824
			$forum_data['forum_parents'] = serialize($forum_parents);
f2e824
f2e824
			$sql = 'UPDATE ' . FORUMS_TABLE . "
f2e824
				SET forum_parents = '" . $db->sql_escape($forum_data['forum_parents']) . "'
f2e824
				WHERE parent_id = " . $forum_data['parent_id'];
f2e824
			$db->sql_query($sql);
f2e824
		}
f2e824
		else
f2e824
		{
f2e824
			$forum_parents = unserialize($forum_data['forum_parents']);
f2e824
		}
f2e824
	}
f2e824
f2e824
	return $forum_parents;
f2e824
}
f2e824
f2e824
/**
f2e824
* Generate topic pagination
f2e824
*/
f2e824
function topic_generate_pagination($replies, $url)
f2e824
{
f2e824
	global $config, $user;
f2e824
f2e824
	// Make sure $per_page is a valid value
f2e824
	$per_page = ($config['posts_per_page'] <= 0) ? 1 : $config['posts_per_page'];
f2e824
f2e824
	if (($replies + 1) > $per_page)
f2e824
	{
f2e824
		$total_pages = ceil(($replies + 1) / $per_page);
f2e824
		$pagination = '';
f2e824
f2e824
		$times = 1;
f2e824
		for ($j = 0; $j < $replies + 1; $j += $per_page)
f2e824
		{
f2e824
			$pagination .= '' . $times . '';
f2e824
			if ($times == 1 && $total_pages > 5)
f2e824
			{
f2e824
				$pagination .= ' ... ';
f2e824
f2e824
				// Display the last three pages
f2e824
				$times = $total_pages - 3;
f2e824
				$j += ($total_pages - 4) * $per_page;
f2e824
			}
f2e824
			else if ($times < $total_pages)
f2e824
			{
f2e824
				$pagination .= '' . $user->lang['COMMA_SEPARATOR'] . '';
f2e824
			}
f2e824
			$times++;
f2e824
		}
f2e824
	}
f2e824
	else
f2e824
	{
f2e824
		$pagination = '';
f2e824
	}
f2e824
f2e824
	return $pagination;
f2e824
}
f2e824
f2e824
/**
f2e824
* Obtain list of moderators of each forum
f2e824
*/
f2e824
function get_moderators(&$forum_moderators, $forum_id = false)
f2e824
{
f2e824
	global $config, $template, $db, $phpbb_root_path, $phpEx, $user, $auth;
f2e824
f2e824
	// Have we disabled the display of moderators? If so, then return
f2e824
	// from whence we came ...
f2e824
	if (!$config['load_moderators'])
f2e824
	{
f2e824
		return;
f2e824
	}
f2e824
f2e824
	$forum_sql = '';
f2e824
f2e824
	if ($forum_id !== false)
f2e824
	{
f2e824
		if (!is_array($forum_id))
f2e824
		{
f2e824
			$forum_id = array($forum_id);
f2e824
		}
f2e824
f2e824
		// If we don't have a forum then we can't have a moderator
f2e824
		if (!sizeof($forum_id))
f2e824
		{
f2e824
			return;
f2e824
		}
f2e824
f2e824
		$forum_sql = 'AND m.' . $db->sql_in_set('forum_id', $forum_id);
f2e824
	}
f2e824
f2e824
	$sql_array = array(
f2e824
		'SELECT'	=> 'm.*, u.user_colour, g.group_colour, g.group_type',
f2e824
f2e824
		'FROM'		=> array(
f2e824
			MODERATOR_CACHE_TABLE	=> 'm',
f2e824
		),
f2e824
f2e824
		'LEFT_JOIN'	=> array(
f2e824
			array(
f2e824
				'FROM'	=> array(USERS_TABLE => 'u'),
f2e824
				'ON'	=> 'm.user_id = u.user_id',
f2e824
			),
f2e824
			array(
f2e824
				'FROM'	=> array(GROUPS_TABLE => 'g'),
f2e824
				'ON'	=> 'm.group_id = g.group_id',
f2e824
			),
f2e824
		),
f2e824
f2e824
		'WHERE'		=> "m.display_on_index = 1 $forum_sql",
f2e824
	);
f2e824
f2e824
	$sql = $db->sql_build_query('SELECT', $sql_array);
f2e824
	$result = $db->sql_query($sql, 3600);
f2e824
f2e824
	while ($row = $db->sql_fetchrow($result))
f2e824
	{
f2e824
		if (!empty($row['user_id']))
f2e824
		{
f2e824
			$forum_moderators[$row['forum_id']][] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
f2e824
		}
f2e824
		else
f2e824
		{
f2e824
			$group_name = (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']);
f2e824
f2e824
			if ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_viewprofile'))
f2e824
			{
f2e824
				$forum_moderators[$row['forum_id']][] = '<span' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . '>' . $group_name . '';
f2e824
			}
f2e824
			else
f2e824
			{
f2e824
				$forum_moderators[$row['forum_id']][] = '<a' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . ' href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $row['group_id']) . '">' . $group_name . '';
f2e824
			}
f2e824
		}
f2e824
	}
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	return;
f2e824
}
f2e824
f2e824
/**
f2e824
* User authorisation levels output
f2e824
*
f2e824
* @param	string	$mode			Can be forum or topic. Not in use at the moment.
f2e824
* @param	int		$forum_id		The current forum the user is in.
f2e824
* @param	int		$forum_status	The forums status bit.
f2e824
*/
f2e824
function gen_forum_auth_level($mode, $forum_id, $forum_status)
f2e824
{
f2e824
	global $template, $auth, $user, $config;
f2e824
f2e824
	$locked = ($forum_status == ITEM_LOCKED && !$auth->acl_get('m_edit', $forum_id)) ? true : false;
f2e824
f2e824
	$rules = array(
f2e824
		($auth->acl_get('f_post', $forum_id) && !$locked) ? $user->lang['RULES_POST_CAN'] : $user->lang['RULES_POST_CANNOT'],
f2e824
		($auth->acl_get('f_reply', $forum_id) && !$locked) ? $user->lang['RULES_REPLY_CAN'] : $user->lang['RULES_REPLY_CANNOT'],
f2e824
		($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id) && !$locked) ? $user->lang['RULES_EDIT_CAN'] : $user->lang['RULES_EDIT_CANNOT'],
f2e824
		($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'],
f2e824
	);
f2e824
f2e824
	if ($config['allow_attachments'])
f2e824
	{
f2e824
		$rules[] = ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && !$locked) ? $user->lang['RULES_ATTACH_CAN'] : $user->lang['RULES_ATTACH_CANNOT'];
f2e824
	}
f2e824
f2e824
	foreach ($rules as $rule)
f2e824
	{
f2e824
		$template->assign_block_vars('rules', array('RULE' => $rule));
f2e824
	}
f2e824
f2e824
	return;
f2e824
}
f2e824
f2e824
/**
f2e824
* Generate topic status
f2e824
*/
f2e824
function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$folder_alt, &$topic_type)
f2e824
{
f2e824
	global $user, $config;
f2e824
f2e824
	$folder = $folder_new = '';
f2e824
f2e824
	if ($topic_row['topic_status'] == ITEM_MOVED)
f2e824
	{
f2e824
		$topic_type = $user->lang['VIEW_TOPIC_MOVED'];
f2e824
		$folder_img = 'topic_moved';
f2e824
		$folder_alt = 'TOPIC_MOVED';
f2e824
	}
f2e824
	else
f2e824
	{
f2e824
		switch ($topic_row['topic_type'])
f2e824
		{
f2e824
			case POST_GLOBAL:
f2e824
				$topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
f2e824
				$folder = 'global_read';
f2e824
				$folder_new = 'global_unread';
f2e824
			break;
f2e824
f2e824
			case POST_ANNOUNCE:
f2e824
				$topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT'];
f2e824
				$folder = 'announce_read';
f2e824
				$folder_new = 'announce_unread';
f2e824
			break;
f2e824
f2e824
			case POST_STICKY:
f2e824
				$topic_type = $user->lang['VIEW_TOPIC_STICKY'];
f2e824
				$folder = 'sticky_read';
f2e824
				$folder_new = 'sticky_unread';
f2e824
			break;
f2e824
f2e824
			default:
f2e824
				$topic_type = '';
f2e824
				$folder = 'topic_read';
f2e824
				$folder_new = 'topic_unread';
f2e824
f2e824
				// Hot topic threshold is for posts in a topic, which is replies + the first post. ;)
f2e824
				if ($config['hot_threshold'] && ($replies + 1) >= $config['hot_threshold'] && $topic_row['topic_status'] != ITEM_LOCKED)
f2e824
				{
f2e824
					$folder .= '_hot';
f2e824
					$folder_new .= '_hot';
f2e824
				}
f2e824
			break;
f2e824
		}
f2e824
f2e824
		if ($topic_row['topic_status'] == ITEM_LOCKED)
f2e824
		{
f2e824
			$topic_type = $user->lang['VIEW_TOPIC_LOCKED'];
f2e824
			$folder .= '_locked';
f2e824
			$folder_new .= '_locked';
f2e824
		}
f2e824
f2e824
f2e824
		$folder_img = ($unread_topic) ? $folder_new : $folder;
f2e824
		$folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($topic_row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS');
f2e824
f2e824
		// Posted image?
f2e824
		if (!empty($topic_row['topic_posted']) && $topic_row['topic_posted'])
f2e824
		{
f2e824
			$folder_img .= '_mine';
f2e824
		}
f2e824
	}
f2e824
f2e824
	if ($topic_row['poll_start'] && $topic_row['topic_status'] != ITEM_MOVED)
f2e824
	{
f2e824
		$topic_type = $user->lang['VIEW_TOPIC_POLL'];
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* Assign/Build custom bbcodes for display in screens supporting using of bbcodes
f2e824
* The custom bbcodes buttons will be placed within the template block 'custom_codes'
f2e824
*/
f2e824
function display_custom_bbcodes()
f2e824
{
f2e824
	global $db, $template;
f2e824
f2e824
	// Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)
f2e824
	$num_predefined_bbcodes = 22;
f2e824
f2e824
	$sql = 'SELECT bbcode_id, bbcode_tag, bbcode_helpline
f2e824
		FROM ' . BBCODES_TABLE . '
f2e824
		WHERE display_on_posting = 1
f2e824
		ORDER BY bbcode_tag';
f2e824
	$result = $db->sql_query($sql);
f2e824
f2e824
	$i = 0;
f2e824
	while ($row = $db->sql_fetchrow($result))
f2e824
	{
f2e824
		$template->assign_block_vars('custom_tags', array(
f2e824
			'BBCODE_NAME'		=> "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'",
f2e824
			'BBCODE_ID'			=> $num_predefined_bbcodes + ($i * 2),
f2e824
			'BBCODE_TAG'		=> $row['bbcode_tag'],
f2e824
			'BBCODE_HELPLINE'	=> $row['bbcode_helpline'],
f2e824
			'A_BBCODE_HELPLINE'	=> str_replace(array('&', '"', "'", '<', '>'), array('&', '"', "\'", '<', '>'), $row['bbcode_helpline']),
f2e824
		));
f2e824
f2e824
		$i++;
f2e824
	}
f2e824
	$db->sql_freeresult($result);
f2e824
}
f2e824
f2e824
/**
f2e824
* Display reasons
f2e824
*/
f2e824
function display_reasons($reason_id = 0)
f2e824
{
f2e824
	global $db, $user, $template;
f2e824
f2e824
	$sql = 'SELECT *
f2e824
		FROM ' . REPORTS_REASONS_TABLE . '
f2e824
		ORDER BY reason_order ASC';
f2e824
	$result = $db->sql_query($sql);
f2e824
f2e824
	while ($row = $db->sql_fetchrow($result))
f2e824
	{
f2e824
		// If the reason is defined within the language file, we will use the localized version, else just use the database entry...
f2e824
		if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
f2e824
		{
f2e824
			$row['reason_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
f2e824
			$row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
f2e824
		}
f2e824
f2e824
		$template->assign_block_vars('reason', array(
f2e824
			'ID'			=> $row['reason_id'],
f2e824
			'TITLE'			=> $row['reason_title'],
f2e824
			'DESCRIPTION'	=> $row['reason_description'],
f2e824
			'S_SELECTED'	=> ($row['reason_id'] == $reason_id) ? true : false)
f2e824
		);
f2e824
	}
f2e824
	$db->sql_freeresult($result);
f2e824
}
f2e824
f2e824
/**
f2e824
* Display user activity (action forum/topic)
f2e824
*/
f2e824
function display_user_activity(&$userdata)
f2e824
{
f2e824
	global $auth, $template, $db, $user;
f2e824
	global $phpbb_root_path, $phpEx;
f2e824
f2e824
	// Do not display user activity for users having more than 5000 posts...
f2e824
	if ($userdata['user_posts'] > 5000)
f2e824
	{
f2e824
		return;
f2e824
	}
f2e824
f2e824
	$forum_ary = array();
f2e824
f2e824
	// Do not include those forums the user is not having read access to...
f2e824
	$forum_read_ary = $auth->acl_getf('!f_read');
f2e824
f2e824
	foreach ($forum_read_ary as $forum_id => $not_allowed)
f2e824
	{
f2e824
		if ($not_allowed['f_read'])
f2e824
		{
f2e824
			$forum_ary[] = (int) $forum_id;
f2e824
		}
f2e824
	}
f2e824
f2e824
	$forum_ary = array_unique($forum_ary);
f2e824
	$forum_sql = (sizeof($forum_ary)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary, true) : '';
f2e824
f2e824
	// Obtain active forum
f2e824
	$sql = 'SELECT forum_id, COUNT(post_id) AS num_posts
f2e824
		FROM ' . POSTS_TABLE . '
f2e824
		WHERE poster_id = ' . $userdata['user_id'] . "
f2e824
			AND post_postcount = 1
f2e824
			$forum_sql
f2e824
		GROUP BY forum_id
f2e824
		ORDER BY num_posts DESC";
f2e824
	$result = $db->sql_query_limit($sql, 1);
f2e824
	$active_f_row = $db->sql_fetchrow($result);
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	if (!empty($active_f_row))
f2e824
	{
f2e824
		$sql = 'SELECT forum_name
f2e824
			FROM ' . FORUMS_TABLE . '
f2e824
			WHERE forum_id = ' . $active_f_row['forum_id'];
f2e824
		$result = $db->sql_query($sql, 3600);
f2e824
		$active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name');
f2e824
		$db->sql_freeresult($result);
f2e824
	}
f2e824
f2e824
	// Obtain active topic
f2e824
	$sql = 'SELECT topic_id, COUNT(post_id) AS num_posts
f2e824
		FROM ' . POSTS_TABLE . '
f2e824
		WHERE poster_id = ' . $userdata['user_id'] . "
f2e824
			AND post_postcount = 1
f2e824
			$forum_sql
f2e824
		GROUP BY topic_id
f2e824
		ORDER BY num_posts DESC";
f2e824
	$result = $db->sql_query_limit($sql, 1);
f2e824
	$active_t_row = $db->sql_fetchrow($result);
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	if (!empty($active_t_row))
f2e824
	{
f2e824
		$sql = 'SELECT topic_title
f2e824
			FROM ' . TOPICS_TABLE . '
f2e824
			WHERE topic_id = ' . $active_t_row['topic_id'];
f2e824
		$result = $db->sql_query($sql);
f2e824
		$active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title');
f2e824
		$db->sql_freeresult($result);
f2e824
	}
f2e824
f2e824
	$userdata['active_t_row'] = $active_t_row;
f2e824
	$userdata['active_f_row'] = $active_f_row;
f2e824
f2e824
	$active_f_name = $active_f_id = $active_f_count = $active_f_pct = '';
f2e824
	if (!empty($active_f_row['num_posts']))
f2e824
	{
f2e824
		$active_f_name = $active_f_row['forum_name'];
f2e824
		$active_f_id = $active_f_row['forum_id'];
f2e824
		$active_f_count = $active_f_row['num_posts'];
f2e824
		$active_f_pct = ($userdata['user_posts']) ? ($active_f_count / $userdata['user_posts']) * 100 : 0;
f2e824
	}
f2e824
f2e824
	$active_t_name = $active_t_id = $active_t_count = $active_t_pct = '';
f2e824
	if (!empty($active_t_row['num_posts']))
f2e824
	{
f2e824
		$active_t_name = $active_t_row['topic_title'];
f2e824
		$active_t_id = $active_t_row['topic_id'];
f2e824
		$active_t_count = $active_t_row['num_posts'];
f2e824
		$active_t_pct = ($userdata['user_posts']) ? ($active_t_count / $userdata['user_posts']) * 100 : 0;
f2e824
	}
f2e824
f2e824
	$l_active_pct = ($userdata['user_id'] != ANONYMOUS && $userdata['user_id'] == $user->data['user_id']) ? $user->lang['POST_PCT_ACTIVE_OWN'] : $user->lang['POST_PCT_ACTIVE'];
f2e824
f2e824
	$template->assign_vars(array(
f2e824
		'ACTIVE_FORUM'			=> $active_f_name,
f2e824
		'ACTIVE_FORUM_POSTS'	=> ($active_f_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_f_count),
f2e824
		'ACTIVE_FORUM_PCT'		=> sprintf($l_active_pct, $active_f_pct),
f2e824
		'ACTIVE_TOPIC'			=> censor_text($active_t_name),
f2e824
		'ACTIVE_TOPIC_POSTS'	=> ($active_t_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_t_count),
f2e824
		'ACTIVE_TOPIC_PCT'		=> sprintf($l_active_pct, $active_t_pct),
f2e824
		'U_ACTIVE_FORUM'		=> append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $active_f_id),
f2e824
		'U_ACTIVE_TOPIC'		=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $active_t_id),
f2e824
		'S_SHOW_ACTIVITY'		=> true)
f2e824
	);
f2e824
}
f2e824
f2e824
/**
f2e824
* Topic and forum watching common code
f2e824
*/
f2e824
function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, $notify_status = 'unset', $start = 0)
f2e824
{
f2e824
	global $template, $db, $user, $phpEx, $start, $phpbb_root_path;
f2e824
f2e824
	$table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE : TOPICS_WATCH_TABLE;
f2e824
	$where_sql = ($mode == 'forum') ? 'forum_id' : 'topic_id';
f2e824
	$match_id = ($mode == 'forum') ? $forum_id : $topic_id;
f2e824
	$u_url = "uid={$user->data['user_id']}";
f2e824
	$u_url .= ($mode == 'forum') ? '&f' : '&f=' . $forum_id . '&t';
f2e824
f2e824
	// Is user watching this thread?
f2e824
	if ($user_id != ANONYMOUS)
f2e824
	{
f2e824
		$can_watch = true;
f2e824
f2e824
		if ($notify_status == 'unset')
f2e824
		{
f2e824
			$sql = "SELECT notify_status
f2e824
				FROM $table_sql
f2e824
				WHERE $where_sql = $match_id
f2e824
					AND user_id = $user_id";
f2e824
			$result = $db->sql_query($sql);
f2e824
f2e824
			$notify_status = ($row = $db->sql_fetchrow($result)) ? $row['notify_status'] : NULL;
f2e824
			$db->sql_freeresult($result);
f2e824
		}
f2e824
f2e824
		if (!is_null($notify_status) && $notify_status !== '')
f2e824
		{
f2e824
f2e824
			if (isset($_GET['unwatch']))
f2e824
			{
f2e824
				$uid = request_var('uid', 0);
f2e824
				if ($uid != $user_id)
f2e824
				{
f2e824
					$redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start");
f2e824
					$message = $user->lang['ERR_UNWATCHING'] . '

' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '', '');
f2e824
					trigger_error($message);
f2e824
				}
f2e824
				if ($_GET['unwatch'] == $mode)
f2e824
				{
f2e824
					$is_watching = 0;
f2e824
f2e824
					$sql = 'DELETE FROM ' . $table_sql . "
f2e824
						WHERE $where_sql = $match_id
f2e824
							AND user_id = $user_id";
f2e824
					$db->sql_query($sql);
f2e824
				}
f2e824
f2e824
				$redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start");
f2e824
f2e824
				meta_refresh(3, $redirect_url);
f2e824
f2e824
				$message = $user->lang['NOT_WATCHING_' . strtoupper($mode)] . '

' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '', '');
f2e824
				trigger_error($message);
f2e824
			}
f2e824
			else
f2e824
			{
f2e824
				$is_watching = true;
f2e824
f2e824
				if ($notify_status)
f2e824
				{
f2e824
					$sql = 'UPDATE ' . $table_sql . "
f2e824
						SET notify_status = 0
f2e824
						WHERE $where_sql = $match_id
f2e824
							AND user_id = $user_id";
f2e824
					$db->sql_query($sql);
f2e824
				}
f2e824
			}
f2e824
		}
f2e824
		else
f2e824
		{
f2e824
			if (isset($_GET['watch']))
f2e824
			{
f2e824
				$token = request_var('hash', '');
f2e824
				$redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start");
f2e824
f2e824
				if ($_GET['watch'] == $mode && check_link_hash($token, "{$mode}_$match_id"))
f2e824
				{
f2e824
					$is_watching = true;
f2e824
f2e824
					$sql = 'INSERT INTO ' . $table_sql . " (user_id, $where_sql, notify_status)
f2e824
						VALUES ($user_id, $match_id, 0)";
f2e824
					$db->sql_query($sql);
f2e824
					$message = $user->lang['ARE_WATCHING_' . strtoupper($mode)] . '

' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '', '');
f2e824
				}
f2e824
				else
f2e824
				{
f2e824
					$message = $user->lang['ERR_WATCHING'] . '

' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '', '');
f2e824
				}
f2e824
f2e824
				meta_refresh(3, $redirect_url);
f2e824
f2e824
				trigger_error($message);
f2e824
			}
f2e824
			else
f2e824
			{
f2e824
				$is_watching = 0;
f2e824
			}
f2e824
		}
f2e824
	}
f2e824
	else
f2e824
	{
f2e824
		if (isset($_GET['unwatch']) && $_GET['unwatch'] == $mode)
f2e824
		{
f2e824
			login_box();
f2e824
		}
f2e824
		else
f2e824
		{
f2e824
			$can_watch = 0;
f2e824
			$is_watching = 0;
f2e824
		}
f2e824
	}
f2e824
f2e824
	if ($can_watch)
f2e824
	{
f2e824
		$s_watching['link'] = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&" . (($is_watching) ? 'unwatch' : 'watch') . "=$mode&start=$start&hash=" . generate_link_hash("{$mode}_$match_id"));
f2e824
		$s_watching['title'] = $user->lang[(($is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)];
f2e824
		$s_watching['is_watching'] = $is_watching;
f2e824
	}
f2e824
f2e824
	return;
f2e824
}
f2e824
f2e824
/**
f2e824
* Get user rank title and image
f2e824
*
f2e824
* @param int $user_rank the current stored users rank id
f2e824
* @param int $user_posts the users number of posts
f2e824
* @param string &$rank_title the rank title will be stored here after execution
f2e824
* @param string &$rank_img the rank image as full img tag is stored here after execution
f2e824
* @param string &$rank_img_src the rank image source is stored here after execution
f2e824
*
f2e824
* Note: since we do not want to break backwards-compatibility, this function will only properly assign ranks to guests if you call it for them with user_posts == false
f2e824
*/
f2e824
function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank_img_src)
f2e824
{
f2e824
	global $ranks, $config, $phpbb_root_path;
f2e824
f2e824
	if (empty($ranks))
f2e824
	{
f2e824
		global $cache;
f2e824
		$ranks = $cache->obtain_ranks();
f2e824
	}
f2e824
f2e824
	if (!empty($user_rank))
f2e824
	{
f2e824
		$rank_title = (isset($ranks['special'][$user_rank]['rank_title'])) ? $ranks['special'][$user_rank]['rank_title'] : '';
f2e824
		$rank_img = (!empty($ranks['special'][$user_rank]['rank_image'])) ? '' . $ranks['special'][$user_rank]['rank_title'] . '' : '';
f2e824
		$rank_img_src = (!empty($ranks['special'][$user_rank]['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] : '';
f2e824
	}
f2e824
	else if ($user_posts !== false)
f2e824
	{
f2e824
		if (!empty($ranks['normal']))
f2e824
		{
f2e824
			foreach ($ranks['normal'] as $rank)
f2e824
			{
f2e824
				if ($user_posts >= $rank['rank_min'])
f2e824
				{
f2e824
					$rank_title = $rank['rank_title'];
f2e824
					$rank_img = (!empty($rank['rank_image'])) ? '' . $rank['rank_title'] . '' : '';
f2e824
					$rank_img_src = (!empty($rank['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image'] : '';
f2e824
					break;
f2e824
				}
f2e824
			}
f2e824
		}
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* Get user avatar
f2e824
*
f2e824
* @param string $avatar Users assigned avatar name
f2e824
* @param int $avatar_type Type of avatar
f2e824
* @param string $avatar_width Width of users avatar
f2e824
* @param string $avatar_height Height of users avatar
f2e824
* @param string $alt Optional language string for alt tag within image, can be a language key or text
f2e824
*
f2e824
* @return string Avatar image
f2e824
*/
f2e824
function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR')
f2e824
{
f2e824
	global $user, $config, $phpbb_root_path, $phpEx;
f2e824
f2e824
	if (empty($avatar) || !$avatar_type)
f2e824
	{
f2e824
		return '';
f2e824
	}
f2e824
f2e824
	$avatar_img = '';
f2e824
f2e824
	switch ($avatar_type)
f2e824
	{
f2e824
		case AVATAR_UPLOAD:
f2e824
			$avatar_img = $phpbb_root_path . "download/file.$phpEx?avatar=";
f2e824
		break;
f2e824
f2e824
		case AVATAR_GALLERY:
f2e824
			$avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
f2e824
		break;
f2e824
	}
f2e824
f2e824
	$avatar_img .= $avatar;
f2e824
	return '' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '';
f2e824
}
f2e824
f2e824
?>