Blame Extras/phpBB/3.0.4/includes/functions_display.php

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

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

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

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

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

' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '', '');
4c79b5
				}
4c79b5
4c79b5
				meta_refresh(3, $redirect_url);
4c79b5
4c79b5
				trigger_error($message);
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				$is_watching = 0;
4c79b5
			}
4c79b5
		}
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		if (isset($_GET['unwatch']) && $_GET['unwatch'] == $mode)
4c79b5
		{
4c79b5
			login_box();
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			$can_watch = 0;
4c79b5
			$is_watching = 0;
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	if ($can_watch)
4c79b5
	{
4c79b5
		$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"));
4c79b5
		$s_watching['title'] = $user->lang[(($is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)];
4c79b5
		$s_watching['is_watching'] = $is_watching;
4c79b5
	}
4c79b5
4c79b5
	return;
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* Get user rank title and image
4c79b5
*
4c79b5
* @param int $user_rank the current stored users rank id
4c79b5
* @param int $user_posts the users number of posts
4c79b5
* @param string &$rank_title the rank title will be stored here after execution
4c79b5
* @param string &$rank_img the rank image as full img tag is stored here after execution
4c79b5
* @param string &$rank_img_src the rank image source is stored here after execution
4c79b5
*
4c79b5
* 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
4c79b5
*/
4c79b5
function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank_img_src)
4c79b5
{
4c79b5
	global $ranks, $config, $phpbb_root_path;
4c79b5
4c79b5
	if (empty($ranks))
4c79b5
	{
4c79b5
		global $cache;
4c79b5
		$ranks = $cache->obtain_ranks();
4c79b5
	}
4c79b5
4c79b5
	if (!empty($user_rank))
4c79b5
	{
4c79b5
		$rank_title = (isset($ranks['special'][$user_rank]['rank_title'])) ? $ranks['special'][$user_rank]['rank_title'] : '';
4c79b5
		$rank_img = (!empty($ranks['special'][$user_rank]['rank_image'])) ? '' . $ranks['special'][$user_rank]['rank_title'] . '' : '';
4c79b5
		$rank_img_src = (!empty($ranks['special'][$user_rank]['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] : '';
4c79b5
	}
4c79b5
	else if ($user_posts !== false)
4c79b5
	{
4c79b5
		if (!empty($ranks['normal']))
4c79b5
		{
4c79b5
			foreach ($ranks['normal'] as $rank)
4c79b5
			{
4c79b5
				if ($user_posts >= $rank['rank_min'])
4c79b5
				{
4c79b5
					$rank_title = $rank['rank_title'];
4c79b5
					$rank_img = (!empty($rank['rank_image'])) ? '' . $rank['rank_title'] . '' : '';
4c79b5
					$rank_img_src = (!empty($rank['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image'] : '';
4c79b5
					break;
4c79b5
				}
4c79b5
			}
4c79b5
		}
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* Get user avatar
4c79b5
*
4c79b5
* @param string $avatar Users assigned avatar name
4c79b5
* @param int $avatar_type Type of avatar
4c79b5
* @param string $avatar_width Width of users avatar
4c79b5
* @param string $avatar_height Height of users avatar
4c79b5
* @param string $alt Optional language string for alt tag within image, can be a language key or text
4c79b5
*
4c79b5
* @return string Avatar image
4c79b5
*/
4c79b5
function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR')
4c79b5
{
4c79b5
	global $user, $config, $phpbb_root_path, $phpEx;
4c79b5
4c79b5
	if (empty($avatar) || !$avatar_type)
4c79b5
	{
4c79b5
		return '';
4c79b5
	}
4c79b5
4c79b5
	$avatar_img = '';
4c79b5
4c79b5
	switch ($avatar_type)
4c79b5
	{
4c79b5
		case AVATAR_UPLOAD:
4c79b5
			$avatar_img = $phpbb_root_path . "download/file.$phpEx?avatar=";
4c79b5
		break;
4c79b5
4c79b5
		case AVATAR_GALLERY:
4c79b5
			$avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
4c79b5
		break;
4c79b5
	}
4c79b5
4c79b5
	$avatar_img .= $avatar;
4c79b5
	return '' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '';
4c79b5
}
4c79b5
4c79b5
?>