diff options
Diffstat (limited to 'phpBB/includes/functions_display.php')
| -rw-r--r-- | phpBB/includes/functions_display.php | 539 | 
1 files changed, 348 insertions, 191 deletions
| diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index ee7048638d..e663ac90c5 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -2,9 +2,8 @@  /**  *  * @package phpBB3 -* @version $Id$  * @copyright (c) 2005 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2  *  */ @@ -23,6 +22,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod  {  	global $db, $auth, $user, $template;  	global $phpbb_root_path, $phpEx, $config; +	global $request, $phpbb_dispatcher, $phpbb_container;  	$forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();  	$parent_id = $visible_forums = 0; @@ -54,12 +54,26 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod  	// Handle marking everything read  	if ($mark_read == 'all')  	{ -		$redirect = build_url(array('mark', 'hash')); +		$redirect = build_url(array('mark', 'hash', 'mark_time'));  		meta_refresh(3, $redirect);  		if (check_link_hash(request_var('hash', ''), 'global'))  		{ -			markread('all'); +			markread('all', false, false, request_var('mark_time', 0)); + +			if ($request->is_ajax()) +			{ +				// Tell the ajax script what language vars and URL need to be replaced +				$data = array( +					'NO_UNREAD_POSTS'	=> $user->lang['NO_UNREAD_POSTS'], +					'UNREAD_POSTS'		=> $user->lang['UNREAD_POSTS'], +					'U_MARK_FORUMS'		=> ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}index.$phpEx", 'hash=' . generate_link_hash('global') . '&mark=forums&mark_time=' . time()) : '', +					'MESSAGE_TITLE'		=> $user->lang['INFORMATION'], +					'MESSAGE_TEXT'		=> $user->lang['FORUMS_MARKED'] +				); +				$json_response = new \phpbb\json_response(); +				$json_response->send($data); +			}  			trigger_error(  				$user->lang['FORUMS_MARKED'] . '<br /><br />' . @@ -90,7 +104,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod  	}  	else if ($config['load_anon_lastread'] || $user->data['is_registered'])  	{ -		$tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : ''; +		$tracking_topics = $request->variable($config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE);  		$tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();  		if (!$user->data['is_registered']) @@ -109,7 +123,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod  		$sql_array['SELECT'] .= ', fa.user_id';  	} -	$sql = $db->sql_build_query('SELECT', array( +	$sql_ary = array(  		'SELECT'	=> $sql_array['SELECT'],  		'FROM'		=> $sql_array['FROM'],  		'LEFT_JOIN'	=> $sql_array['LEFT_JOIN'], @@ -117,27 +131,41 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod  		'WHERE'		=> $sql_where,  		'ORDER_BY'	=> 'f.left_id', -	)); +	); +	/** +	* Event to modify the SQL query before the forum data is queried +	* +	* @event core.display_forums_modify_sql +	* @var	array	sql_ary		The SQL array to get the data of the forums +	* @since 3.1-A1 +	*/ +	$vars = array('sql_ary'); +	extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_sql', compact($vars))); + +	$sql = $db->sql_build_query('SELECT', $sql_ary);  	$result = $db->sql_query($sql);  	$forum_tracking_info = array();  	$branch_root_id = $root_data['forum_id']; -	// Check for unread global announcements (index page only) -	$ga_unread = false; -	if ($root_data['forum_id'] == 0) -	{ -		$unread_ga_list = get_unread_topics($user->data['user_id'], 'AND t.forum_id = 0', '', 1); - -		if (!empty($unread_ga_list)) -		{ -			$ga_unread = true; -		} -	} +	$phpbb_content_visibility = $phpbb_container->get('content.visibility');  	while ($row = $db->sql_fetchrow($result))  	{ +		/** +		* Event to modify the data set of a forum +		* +		* This event is triggered once per forum +		* +		* @event core.display_forums_modify_row +		* @var	int		branch_root_id	Last top-level forum +		* @var	array	row				The data of the forum +		* @since 3.1-A1 +		*/ +		$vars = array('branch_root_id', 'row'); +		extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_row', compact($vars))); +  		$forum_id = $row['forum_id'];  		// Mark forums read? @@ -187,9 +215,11 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod  			$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'];  		} -		// Count the difference of real to public topics, so we can display an information to moderators -		$row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && ($row['forum_topics_real'] != $row['forum_topics'])) ? $forum_id : 0; -		$row['forum_topics'] = ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics']; +		// Lets check whether there are unapproved topics/posts, so we can display an information to moderators +		$row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && $row['forum_topics_unapproved']) ? $forum_id : 0; +		$row['forum_id_unapproved_posts'] = ($auth->acl_get('m_approve', $forum_id) && $row['forum_posts_unapproved']) ? $forum_id : 0; +		$row['forum_posts'] = $phpbb_content_visibility->get_count('forum_posts', $row, $forum_id); +		$row['forum_topics'] = $phpbb_content_visibility->get_count('forum_topics', $row, $forum_id);  		// Display active topics from this forum?  		if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) @@ -252,6 +282,11 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod  				$forum_rows[$parent_id]['forum_id_unapproved_topics'] = $forum_id;  			} +			if (!$forum_rows[$parent_id]['forum_id_unapproved_posts'] && $row['forum_id_unapproved_posts']) +			{ +				$forum_rows[$parent_id]['forum_id_unapproved_posts'] = $forum_id; +			} +  			$forum_rows[$parent_id]['forum_topics'] += $row['forum_topics'];  			// Do not list redirects in LINK Forums as Posts. @@ -271,21 +306,50 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod  				$forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;  			}  		} + +		/** +		* Event to modify the forum rows data set +		* +		* This event is triggered once per forum +		* +		* @event core.display_forums_modify_forum_rows +		* @var	array	forum_rows		Data array of all forums we display +		* @var	array	subforums		Data array of all subforums we display +		* @var	int		branch_root_id	Current top-level forum +		* @var	int		parent_id		Current parent forum +		* @var	array	row				The data of the forum +		* @since 3.1-A1 +		*/ +		$vars = array('forum_rows', 'subforums', 'branch_root_id', 'parent_id', 'row'); +		extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_forum_rows', compact($vars)));  	}  	$db->sql_freeresult($result);  	// Handle marking posts  	if ($mark_read == 'forums')  	{ -		$redirect = build_url(array('mark', 'hash')); +		$redirect = build_url(array('mark', 'hash', 'mark_time'));  		$token = request_var('hash', '');  		if (check_link_hash($token, 'global'))  		{ -			// Add 0 to forums array to mark global announcements correctly -			$forum_ids[] = 0; -			markread('topics', $forum_ids); +			markread('topics', $forum_ids, false, request_var('mark_time', 0));  			$message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');  			meta_refresh(3, $redirect); + +			if ($request->is_ajax()) +			{ +				// Tell the ajax script what language vars and URL need to be replaced +				$data = array( +					'NO_UNREAD_POSTS'	=> $user->lang['NO_UNREAD_POSTS'], +					'UNREAD_POSTS'		=> $user->lang['UNREAD_POSTS'], +					'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&mark_time=' . time()) : '', +					'MESSAGE_TITLE'		=> $user->lang['INFORMATION'], +					'MESSAGE_TEXT'		=> $user->lang['FORUMS_MARKED'] +				); +				$json_response = new \phpbb\json_response(); +				$json_response->send($data); +			} +  			trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . $message);  		}  		else @@ -334,12 +398,6 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod  		$forum_unread = (isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id]) ? true : false; -		// Mark the first visible forum on index as unread if there's any unread global announcement -		if ($ga_unread && !empty($forum_ids_moderator) && $forum_id == $forum_ids_moderator[0]) -		{ -			$forum_unread = true; -		} -  		$folder_image = $folder_alt = $l_subforums = '';  		$subforums_list = array(); @@ -415,12 +473,13 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod  		if ($row['forum_last_post_id'])  		{  			$last_post_subject = $row['forum_last_post_subject']; +			$last_post_subject_truncated = truncate_string(censor_text($last_post_subject), 30, 255, false, $user->lang['ELLIPSIS']);  			$last_post_time = $user->format_date($row['forum_last_post_time']);  			$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'];  		}  		else  		{ -			$last_post_subject = $last_post_time = $last_post_url = ''; +			$last_post_subject = $last_post_time = $last_post_url = $last_post_subject_truncated = '';  		}  		// Output moderator listing ... if applicable @@ -428,7 +487,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod  		if ($display_moderators && !empty($forum_moderators[$forum_id]))  		{  			$l_moderator = (sizeof($forum_moderators[$forum_id]) == 1) ? $user->lang['MODERATOR'] : $user->lang['MODERATORS']; -			$moderators_list = implode(', ', $forum_moderators[$forum_id]); +			$moderators_list = implode($user->lang['COMMA_SEPARATOR'], $forum_moderators[$forum_id]);  		}  		$l_post_click_count = ($row['forum_type'] == FORUM_LINK) ? 'CLICKS' : 'POSTS'; @@ -439,7 +498,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod  		{  			$s_subforums_list[] = '<a href="' . $subforum['link'] . '" class="subforum ' . (($subforum['unread']) ? 'unread' : 'read') . '" title="' . (($subforum['unread']) ? $user->lang['UNREAD_POSTS'] : $user->lang['NO_UNREAD_POSTS']) . '">' . $subforum['name'] . '</a>';  		} -		$s_subforums_list = (string) implode(', ', $s_subforums_list); +		$s_subforums_list = (string) implode($user->lang['COMMA_SEPARATOR'], $s_subforums_list);  		$catless = ($row['parent_id'] == $root_data['forum_id']) ? true : false;  		if ($row['forum_type'] != FORUM_LINK) @@ -460,7 +519,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod  			}  		} -		$template->assign_block_vars('forumrow', array( +		$forum_row = array(  			'S_IS_CAT'			=> false,  			'S_NO_CAT'			=> $catless && !$last_catless,  			'S_IS_LINK'			=> ($row['forum_type'] == FORUM_LINK) ? true : false, @@ -469,6 +528,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod  			'S_LOCKED_FORUM'	=> ($row['forum_status'] == ITEM_LOCKED) ? true : false,  			'S_LIST_SUBFORUMS'	=> ($row['display_subforum_list']) ? true : false,  			'S_SUBFORUMS'		=> (sizeof($subforums_list)) ? true : false, +			'S_DISPLAY_SUBJECT'	=>	($last_post_subject && $config['display_last_subject'] && !$row['forum_password'] && $auth->acl_get('f_read', $row['forum_id'])) ? true : false,  			'S_FEED_ENABLED'	=> ($config['feed_forum'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $row['forum_options']) && $row['forum_type'] == FORUM_POST) ? true : false,  			'FORUM_ID'				=> $row['forum_id'], @@ -476,12 +536,13 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod  			'FORUM_DESC'			=> generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),  			'TOPICS'				=> $row['forum_topics'],  			$l_post_click_count		=> $post_click_count, +			'FORUM_IMG_STYLE'		=> $folder_image,  			'FORUM_FOLDER_IMG'		=> $user->img($folder_image, $folder_alt), -			'FORUM_FOLDER_IMG_SRC'	=> $user->img($folder_image, $folder_alt, false, '', 'src'),  			'FORUM_FOLDER_IMG_ALT'	=> isset($user->lang[$folder_alt]) ? $user->lang[$folder_alt] : '',  			'FORUM_IMAGE'			=> ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',  			'FORUM_IMAGE_SRC'		=> ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '', -			'LAST_POST_SUBJECT'		=> censor_text($last_post_subject), +			'LAST_POST_SUBJECT'		=> (!$row['forum_password'] && $auth->acl_get('f_read', $row['forum_id'])) ? censor_text($last_post_subject) : "", +			'LAST_POST_SUBJECT_TRUNCATED'	=> (!$row['forum_password'] && $auth->acl_get('f_read', $row['forum_id'])) ? $last_post_subject_truncated : "",  			'LAST_POST_TIME'		=> $last_post_time,  			'LAST_POSTER'			=> get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),  			'LAST_POSTER_COLOUR'	=> get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), @@ -493,11 +554,27 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod  			'L_MODERATOR_STR'		=> $l_moderator,  			'U_UNAPPROVED_TOPICS'	=> ($row['forum_id_unapproved_topics']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=unapproved_topics&f=' . $row['forum_id_unapproved_topics']) : '', +			'U_UNAPPROVED_POSTS'	=> ($row['forum_id_unapproved_posts']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=unapproved_posts&f=' . $row['forum_id_unapproved_posts']) : '',  			'U_VIEWFORUM'		=> $u_viewforum,  			'U_LAST_POSTER'		=> get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), -			'U_LAST_POST'		=> $last_post_url) +			'U_LAST_POST'		=> $last_post_url,  		); +		/** +		* Modify the template data block of the forum +		* +		* This event is triggered once per forum +		* +		* @event core.display_forums_modify_template_vars +		* @var	array	forum_row		Template data of the forum +		* @var	array	row				The data of the forum +		* @since 3.1-A1 +		*/ +		$vars = array('forum_row', 'row'); +		extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_template_vars', compact($vars))); + +		$template->assign_block_vars('forumrow', $forum_row); +  		// Assign subforums loop for style authors  		foreach ($subforums_list as $subforum)  		{ @@ -512,11 +589,12 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod  	}  	$template->assign_vars(array( -		'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') : '', +		'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&mark_time=' . time()) : '',  		'S_HAS_SUBFORUM'	=> ($visible_forums) ? true : false,  		'L_SUBFORUM'		=> ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'],  		'LAST_POST_IMG'		=> $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),  		'UNAPPROVED_IMG'	=> $user->img('icon_topic_unapproved', 'TOPICS_UNAPPROVED'), +		'UNAPPROVED_POST_IMG'	=> $user->img('icon_topic_unapproved', 'POSTS_UNAPPROVED'),  	));  	if ($return_moderators) @@ -655,48 +733,6 @@ function get_forum_parents(&$forum_data)  }  /** -* Generate topic pagination -*/ -function topic_generate_pagination($replies, $url) -{ -	global $config, $user; - -	// Make sure $per_page is a valid value -	$per_page = ($config['posts_per_page'] <= 0) ? 1 : $config['posts_per_page']; - -	if (($replies + 1) > $per_page) -	{ -		$total_pages = ceil(($replies + 1) / $per_page); -		$pagination = ''; - -		$times = 1; -		for ($j = 0; $j < $replies + 1; $j += $per_page) -		{ -			$pagination .= '<a href="' . $url . ($j == 0 ? '' : '&start=' . $j) . '">' . $times . '</a>'; -			if ($times == 1 && $total_pages > 5) -			{ -				$pagination .= '<span class="page-dots"> ... </span>'; - -				// Display the last three pages -				$times = $total_pages - 3; -				$j += ($total_pages - 4) * $per_page; -			} -			else if ($times < $total_pages) -			{ -				$pagination .= '<span class="page-sep">' . $user->lang['COMMA_SEPARATOR'] . '</span>'; -			} -			$times++; -		} -	} -	else -	{ -		$pagination = ''; -	} - -	return $pagination; -} - -/**  * Obtain list of moderators of each forum  */  function get_moderators(&$forum_moderators, $forum_id = false) @@ -790,7 +826,7 @@ function gen_forum_auth_level($mode, $forum_id, $forum_status)  		($auth->acl_get('f_post', $forum_id) && !$locked) ? $user->lang['RULES_POST_CAN'] : $user->lang['RULES_POST_CANNOT'],  		($auth->acl_get('f_reply', $forum_id) && !$locked) ? $user->lang['RULES_REPLY_CAN'] : $user->lang['RULES_REPLY_CANNOT'],  		($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id) && !$locked) ? $user->lang['RULES_EDIT_CAN'] : $user->lang['RULES_EDIT_CANNOT'], -		($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'], +		($user->data['is_registered'] && ($auth->acl_gets('f_delete', 'm_delete', $forum_id) || $auth->acl_gets('f_softdelete', 'm_softdelete', $forum_id)) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'],  	);  	if ($config['allow_attachments']) @@ -883,20 +919,35 @@ function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$fold  /**  * Assign/Build custom bbcodes for display in screens supporting using of bbcodes -* The custom bbcodes buttons will be placed within the template block 'custom_codes' +* The custom bbcodes buttons will be placed within the template block 'custom_tags'  */  function display_custom_bbcodes()  { -	global $db, $template, $user; +	global $db, $template, $user, $phpbb_dispatcher;  	// Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)  	$num_predefined_bbcodes = 22; -	$sql = 'SELECT bbcode_id, bbcode_tag, bbcode_helpline -		FROM ' . BBCODES_TABLE . ' -		WHERE display_on_posting = 1 -		ORDER BY bbcode_tag'; -	$result = $db->sql_query($sql); +	$sql_ary = array( +		'SELECT'	=> 'b.bbcode_id, b.bbcode_tag, b.bbcode_helpline', +		'FROM'		=> array(BBCODES_TABLE => 'b'), +		'WHERE'		=> 'b.display_on_posting = 1', +		'ORDER_BY'	=> 'b.bbcode_tag', +	); + +	/** +	* Event to modify the SQL query before custom bbcode data is queried +	* +	* @event core.display_custom_bbcodes_modify_sql +	* @var	array	sql_ary					The SQL array to get the bbcode data +	* @var	int		num_predefined_bbcodes	The number of predefined core bbcodes +	*										(multiplied by factor of 2) +	* @since 3.1.0-a3 +	*/ +	$vars = array('sql_ary', 'num_predefined_bbcodes'); +	extract($phpbb_dispatcher->trigger_event('core.display_custom_bbcodes_modify_sql', compact($vars))); + +	$result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));  	$i = 0;  	while ($row = $db->sql_fetchrow($result)) @@ -907,17 +958,40 @@ function display_custom_bbcodes()  			$row['bbcode_helpline'] = $user->lang[strtoupper($row['bbcode_helpline'])];  		} -		$template->assign_block_vars('custom_tags', array( +		$custom_tags = array(  			'BBCODE_NAME'		=> "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'",  			'BBCODE_ID'			=> $num_predefined_bbcodes + ($i * 2),  			'BBCODE_TAG'		=> $row['bbcode_tag'],  			'BBCODE_HELPLINE'	=> $row['bbcode_helpline'],  			'A_BBCODE_HELPLINE'	=> str_replace(array('&', '"', "'", '<', '>'), array('&', '"', "\'", '<', '>'), $row['bbcode_helpline']), -		)); +		); + +		/** +		* Event to modify the template data block of a custom bbcode +		* +		* This event is triggered once per bbcode +		* +		* @event core.display_custom_bbcodes_modify_row +		* @var	array	custom_tags		Template data of the bbcode +		* @var	array	row				The data of the bbcode +		* @since 3.1-A1 +		*/ +		$vars = array('custom_tags', 'row'); +		extract($phpbb_dispatcher->trigger_event('core.display_custom_bbcodes_modify_row', compact($vars))); + +		$template->assign_block_vars('custom_tags', $custom_tags);  		$i++;  	}  	$db->sql_freeresult($result); + +	/** +	* Display custom bbcodes +	* +	* @event core.display_custom_bbcodes +	* @since 3.1-A1 +	*/ +	$phpbb_dispatcher->dispatch('core.display_custom_bbcodes');  }  /** @@ -957,7 +1031,7 @@ function display_reasons($reason_id = 0)  function display_user_activity(&$userdata)  {  	global $auth, $template, $db, $user; -	global $phpbb_root_path, $phpEx; +	global $phpbb_root_path, $phpEx, $phpbb_container;  	// Do not display user activity for users having more than 5000 posts...  	if ($userdata['user_posts'] > 5000) @@ -967,73 +1041,65 @@ function display_user_activity(&$userdata)  	$forum_ary = array(); -	// Do not include those forums the user is not having read access to... -	$forum_read_ary = $auth->acl_getf('!f_read'); - -	foreach ($forum_read_ary as $forum_id => $not_allowed) +	$forum_read_ary = $auth->acl_getf('f_read'); +	foreach ($forum_read_ary as $forum_id => $allowed)  	{ -		if ($not_allowed['f_read']) +		if ($allowed['f_read'])  		{  			$forum_ary[] = (int) $forum_id;  		}  	} -	$forum_ary = array_unique($forum_ary); -	$forum_sql = (sizeof($forum_ary)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary, true) : ''; - -	$fid_m_approve = $auth->acl_getf('m_approve', true); -	$sql_m_approve = (!empty($fid_m_approve)) ? 'OR ' . $db->sql_in_set('forum_id', array_keys($fid_m_approve)) : ''; - -	// Obtain active forum -	$sql = 'SELECT forum_id, COUNT(post_id) AS num_posts -		FROM ' . POSTS_TABLE . ' -		WHERE poster_id = ' . $userdata['user_id'] . " -			AND post_postcount = 1 -			AND (post_approved = 1 -				$sql_m_approve) -			$forum_sql -		GROUP BY forum_id -		ORDER BY num_posts DESC"; -	$result = $db->sql_query_limit($sql, 1); -	$active_f_row = $db->sql_fetchrow($result); -	$db->sql_freeresult($result); +	$forum_ary = array_diff($forum_ary, $user->get_passworded_forums()); -	if (!empty($active_f_row)) +	$active_f_row = $active_t_row = array(); +	if (!empty($forum_ary))  	{ -		$sql = 'SELECT forum_name -			FROM ' . FORUMS_TABLE . ' -			WHERE forum_id = ' . $active_f_row['forum_id']; -		$result = $db->sql_query($sql, 3600); -		$active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name'); +		$phpbb_content_visibility = $phpbb_container->get('content.visibility'); + +		// Obtain active forum +		$sql = 'SELECT forum_id, COUNT(post_id) AS num_posts +			FROM ' . POSTS_TABLE . ' +			WHERE poster_id = ' . $userdata['user_id'] . ' +				AND post_postcount = 1 +				AND ' . $phpbb_content_visibility->get_forums_visibility_sql('post', $forum_ary) . ' +			GROUP BY forum_id +			ORDER BY num_posts DESC'; +		$result = $db->sql_query_limit($sql, 1); +		$active_f_row = $db->sql_fetchrow($result);  		$db->sql_freeresult($result); -	} -	// Obtain active topic -	// We need to exclude passworded forums here so we do not leak the topic title -	$forum_ary_topic = array_unique(array_merge($forum_ary, $user->get_passworded_forums())); -	$forum_sql_topic = (!empty($forum_ary_topic)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary_topic, true) : ''; - -	$sql = 'SELECT topic_id, COUNT(post_id) AS num_posts -		FROM ' . POSTS_TABLE . ' -		WHERE poster_id = ' . $userdata['user_id'] . " -			AND post_postcount = 1 -			AND (post_approved = 1 -				$sql_m_approve) -			$forum_sql_topic -		GROUP BY topic_id -		ORDER BY num_posts DESC"; -	$result = $db->sql_query_limit($sql, 1); -	$active_t_row = $db->sql_fetchrow($result); -	$db->sql_freeresult($result); +		if (!empty($active_f_row)) +		{ +			$sql = 'SELECT forum_name +				FROM ' . FORUMS_TABLE . ' +				WHERE forum_id = ' . $active_f_row['forum_id']; +			$result = $db->sql_query($sql, 3600); +			$active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name'); +			$db->sql_freeresult($result); +		} -	if (!empty($active_t_row)) -	{ -		$sql = 'SELECT topic_title -			FROM ' . TOPICS_TABLE . ' -			WHERE topic_id = ' . $active_t_row['topic_id']; -		$result = $db->sql_query($sql); -		$active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title'); +		// Obtain active topic +		$sql = 'SELECT topic_id, COUNT(post_id) AS num_posts +			FROM ' . POSTS_TABLE . ' +			WHERE poster_id = ' . $userdata['user_id'] . ' +				AND post_postcount = 1 +				AND ' . $phpbb_content_visibility->get_forums_visibility_sql('post', $forum_ary) . ' +			GROUP BY topic_id +			ORDER BY num_posts DESC'; +		$result = $db->sql_query_limit($sql, 1); +		$active_t_row = $db->sql_fetchrow($result);  		$db->sql_freeresult($result); + +		if (!empty($active_t_row)) +		{ +			$sql = 'SELECT topic_title +				FROM ' . TOPICS_TABLE . ' +				WHERE topic_id = ' . $active_t_row['topic_id']; +			$result = $db->sql_query($sql); +			$active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title'); +			$db->sql_freeresult($result); +		}  	}  	$userdata['active_t_row'] = $active_t_row; @@ -1061,10 +1127,10 @@ function display_user_activity(&$userdata)  	$template->assign_vars(array(  		'ACTIVE_FORUM'			=> $active_f_name, -		'ACTIVE_FORUM_POSTS'	=> ($active_f_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_f_count), +		'ACTIVE_FORUM_POSTS'	=> $user->lang('USER_POSTS', (int) $active_f_count),  		'ACTIVE_FORUM_PCT'		=> sprintf($l_active_pct, $active_f_pct),  		'ACTIVE_TOPIC'			=> censor_text($active_t_name), -		'ACTIVE_TOPIC_POSTS'	=> ($active_t_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_t_count), +		'ACTIVE_TOPIC_POSTS'	=> $user->lang('USER_POSTS', (int) $active_t_count),  		'ACTIVE_TOPIC_PCT'		=> sprintf($l_active_pct, $active_t_pct),  		'U_ACTIVE_FORUM'		=> append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $active_f_id),  		'U_ACTIVE_TOPIC'		=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $active_t_id), @@ -1078,6 +1144,7 @@ function display_user_activity(&$userdata)  function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, $notify_status = 'unset', $start = 0, $item_title = '')  {  	global $template, $db, $user, $phpEx, $start, $phpbb_root_path; +	global $request;  	$table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE : TOPICS_WATCH_TABLE;  	$where_sql = ($mode == 'forum') ? 'forum_id' : 'topic_id'; @@ -1105,7 +1172,6 @@ function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id,  		if (!is_null($notify_status) && $notify_status !== '')  		{ -  			if (isset($_GET['unwatch']))  			{  				$uid = request_var('uid', 0); @@ -1113,10 +1179,15 @@ function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id,  				if ($token && check_link_hash($token, "{$mode}_$match_id") || confirm_box(true))  				{ -					if ($uid != $user_id || $_GET['unwatch'] != $mode) +					if ($uid != $user_id || $request->variable('unwatch', '', false, \phpbb\request\request_interface::GET) != $mode)  					{  						$redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start"); -						$message = $user->lang['ERR_UNWATCHING'] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>'); +						$message = $user->lang['ERR_UNWATCHING']; + +						if (!$request->is_ajax()) +						{ +							$message .= '<br /><br />' . $user->lang('RETURN_' . strtoupper($mode), '<a href="' . $redirect_url . '">', '</a>'); +						}  						trigger_error($message);  					} @@ -1126,8 +1197,12 @@ function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id,  					$db->sql_query($sql);  					$redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start"); -					$message = $user->lang['NOT_WATCHING_' . strtoupper($mode)] . '<br /><br />'; -					$message .= sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>'); +					$message = $user->lang['NOT_WATCHING_' . strtoupper($mode)]; + +					if (!$request->is_ajax()) +					{ +						$message .= '<br /><br />' . $user->lang('RETURN_' . strtoupper($mode), '<a href="' . $redirect_url . '">', '</a>'); +					}  					meta_refresh(3, $redirect_url);  					trigger_error($message);  				} @@ -1178,10 +1253,15 @@ function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id,  				if ($token && check_link_hash($token, "{$mode}_$match_id") || confirm_box(true))  				{ -					if ($uid != $user_id || $_GET['watch'] != $mode) +					if ($uid != $user_id || $request->variable('watch', '', false, \phpbb\request\request_interface::GET) != $mode)  					{  						$redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start"); -						$message = $user->lang['ERR_WATCHING'] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>'); +						$message = $user->lang['ERR_WATCHING']; + +						if (!$request->is_ajax()) +						{ +							$message .= '<br /><br />' . $user->lang('RETURN_' . strtoupper($mode), '<a href="' . $redirect_url . '">', '</a>'); +						}  						trigger_error($message);  					} @@ -1192,7 +1272,12 @@ function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id,  					$db->sql_query($sql);  					$redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start"); -					$message = $user->lang['ARE_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>'); +					$message = $user->lang['ARE_WATCHING_' . strtoupper($mode)]; + +					if (!$request->is_ajax()) +					{ +						$message .= '<br /><br />' . $user->lang('RETURN_' . strtoupper($mode), '<a href="' . $redirect_url . '">', '</a>'); +					}  					meta_refresh(3, $redirect_url);  					trigger_error($message);  				} @@ -1221,7 +1306,8 @@ function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id,  	}  	else  	{ -		if ((isset($_GET['unwatch']) && $_GET['unwatch'] == $mode) || (isset($_GET['watch']) && $_GET['watch'] == $mode)) +		if ((isset($_GET['unwatch']) && $request->variable('unwatch', '', false, \phpbb\request\request_interface::GET) == $mode) || +			(isset($_GET['watch']) && $request->variable('watch', '', false, \phpbb\request\request_interface::GET) == $mode))  		{  			login_box();  		} @@ -1235,7 +1321,9 @@ function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id,  	if ($can_watch)  	{  		$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")); +		$s_watching['link_toggle'] = 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"));  		$s_watching['title'] = $user->lang[(($is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)]; +		$s_watching['title_toggle'] = $user->lang[((!$is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)];  		$s_watching['is_watching'] = $is_watching;  	} @@ -1290,54 +1378,123 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank  /**  * Get user avatar  * -* @param string $avatar Users assigned avatar name -* @param int $avatar_type Type of avatar -* @param string $avatar_width Width of users avatar -* @param string $avatar_height Height of users avatar +* @param array $user_row Row from the users table +* @param string $alt Optional language string for alt tag within image, can be a language key or text +* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP +* +* @return string Avatar html +*/ +function phpbb_get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false) +{ +	$row = \phpbb\avatar\manager::clean_row($user_row, 'user'); +	return phpbb_get_avatar($row, $alt, $ignore_config); +} + +/** +* Get group avatar +* +* @param array $group_row Row from the groups table +* @param string $alt Optional language string for alt tag within image, can be a language key or text +* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP +* +* @return string Avatar html +*/ +function phpbb_get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = false) +{ +	$row = \phpbb\avatar\manager::clean_row($user_row, 'group'); +	return phpbb_get_avatar($row, $alt, $ignore_config); +} + +/** +* Get avatar +* +* @param array $row Row cleaned by \phpbb\avatar\driver\driver::clean_row  * @param string $alt Optional language string for alt tag within image, can be a language key or text  * @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP  * -* @return string Avatar image +* @return string Avatar html  */ -function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false) +function phpbb_get_avatar($row, $alt, $ignore_config = false)  { -	global $user, $config, $phpbb_root_path, $phpEx; +	global $user, $config, $cache, $phpbb_root_path, $phpEx; +	global $request; +	global $phpbb_container; -	if (empty($avatar) || !$avatar_type || (!$config['allow_avatar'] && !$ignore_config)) +	if (!$config['allow_avatar'] && !$ignore_config)  	{  		return '';  	} -	$avatar_img = ''; +	$avatar_data = array( +		'src' => $row['avatar'], +		'width' => $row['avatar_width'], +		'height' => $row['avatar_height'], +	); + +	$phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); +	$driver = $phpbb_avatar_manager->get_driver($row['avatar_type'], $ignore_config); +	$html = ''; -	switch ($avatar_type) +	if ($driver)  	{ -		case AVATAR_UPLOAD: -			if (!$config['allow_avatar_upload'] && !$ignore_config) -			{ -				return ''; -			} -			$avatar_img = $phpbb_root_path . "download/file.$phpEx?avatar="; -		break; +		$html = $driver->get_custom_html($user, $row, $alt); +		if (!empty($html)) +		{ +			return $html; +		} -		case AVATAR_GALLERY: -			if (!$config['allow_avatar_local'] && !$ignore_config) -			{ -				return ''; -			} -			$avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/'; -		break; +		$avatar_data = $driver->get_data($row, $ignore_config); +	} +	else +	{ +		$avatar_data['src'] = ''; +	} -		case AVATAR_REMOTE: -			if (!$config['allow_avatar_remote'] && !$ignore_config) -			{ -				return ''; -			} -		break; +	if (!empty($avatar_data['src'])) +	{ +		$html = '<img src="' . $avatar_data['src'] . '" ' . +			($avatar_data['width'] ? ('width="' . $avatar_data['width'] . '" ') : '') . +			($avatar_data['height'] ? ('height="' . $avatar_data['height'] . '" ') : '') . +			'alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';  	} -	$avatar_img .= $avatar; -	return '<img src="' . (str_replace(' ', '%20', $avatar_img)) . '" width="' . $avatar_width . '" height="' . $avatar_height . '" alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />'; +	return $html;  } -?>
\ No newline at end of file +/** +* Generate a list of archive types available for compressing attachments +* +* @param string $param_key Either topic_id or post_id +* @param string $param_val The value of the topic or post id +* @param string $phpbb_root_path The root path of the phpBB installation +* @param string $phpEx The PHP extension +* +* @return array Array containing the link and the type of compression +*/ +function phpbb_gen_download_links($param_key, $param_val, $phpbb_root_path, $phpEx) +{ +	if (!class_exists('compress')) +	{ +		require $phpbb_root_path . 'includes/functions_compress.' . $phpEx; +	} + +	$methods = compress::methods(); +	// Sort by preferred type. +	$methods = array_intersect(array('.zip', '.tar.bz2', '.tar.gz', '.tar'), $methods); +	$links = array(); + +	foreach ($methods as $method) +	{ +		$exploded = explode('.', $method); +		$type = array_pop($exploded); +		$params = array('archive' => $method); +		$params[$param_key] = $param_val; + +		$links[] = array( +			'LINK' => append_sid("{$phpbb_root_path}download/file.$phpEx", $params), +			'TYPE' => $type, +		); +	} + +	return $links; +} | 
