diff options
Diffstat (limited to 'phpBB/includes/functions.php')
| -rw-r--r-- | phpBB/includes/functions.php | 163 | 
1 files changed, 105 insertions, 58 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 3402a618b0..21776693b0 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -289,7 +289,6 @@ function phpbb_gmgetdate($time = false)  * @param array	$allowed_units	only allow these units (data array indexes)  *  * @return mixed					data array if $string_only is false -* @author bantu  */  function get_formatted_filesize($value, $string_only = true, $allowed_units = false)  { @@ -463,7 +462,6 @@ function phpbb_version_compare($version1, $version2, $operator = null)  * @param int	$perms		Permissions to set  *  * @return bool	true on success, otherwise false -* @author faw, phpBB Limited  */  function phpbb_chmod($filename, $perms = CHMOD_READ)  { @@ -1031,7 +1029,7 @@ function phpbb_get_timezone_identifiers($selected_timezone)  			$validate_timezone = new DateTimeZone($selected_timezone);  			$timezones[] = $selected_timezone;  		} -		catch (Exception $e) +		catch (\Exception $e)  		{  		}  	} @@ -1061,7 +1059,7 @@ function phpbb_timezone_select($user, $default = '', $truncate = false)  		foreach ($unsorted_timezones as $timezone)  		{  			$tz = new DateTimeZone($timezone); -			$dt = new \phpbb\datetime($user, 'now', $tz); +			$dt = $user->create_datetime('now', $tz);  			$offset = $dt->getOffset();  			$current_time = $dt->format($user->lang['DATETIME_FORMAT'], true);  			$offset_string = phpbb_format_timezone_offset($offset); @@ -1146,12 +1144,12 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $  			// Mark all topic notifications read for this user  			$phpbb_notifications->mark_notifications_read(array( -				'topic', -				'quote', -				'bookmark', -				'post', -				'approve_topic', -				'approve_post', +				'notification.type.topic', +				'notification.type.quote', +				'notification.type.bookmark', +				'notification.type.post', +				'notification.type.approve_topic', +				'notification.type.approve_post',  			), false, $user->data['user_id'], $post_time);  			if ($config['load_db_lastread'] && $user->data['is_registered']) @@ -1211,8 +1209,8 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $  		$phpbb_notifications = $phpbb_container->get('notification_manager');  		$phpbb_notifications->mark_notifications_read_by_parent(array( -			'topic', -			'approve_topic', +			'notification.type.topic', +			'notification.type.approve_topic',  		), $forum_id, $user->data['user_id'], $post_time);  		// Mark all post/quote notifications read for this user in this forum @@ -1228,10 +1226,10 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $  		$db->sql_freeresult($result);  		$phpbb_notifications->mark_notifications_read_by_parent(array( -			'quote', -			'bookmark', -			'post', -			'approve_post', +			'notification.type.quote', +			'notification.type.bookmark', +			'notification.type.post', +			'notification.type.approve_post',  		), $topic_ids, $user->data['user_id'], $post_time);  		// Add 0 to forums array to mark global announcements correctly @@ -1334,15 +1332,15 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $  		// Mark post notifications read for this user in this topic  		$phpbb_notifications->mark_notifications_read(array( -			'topic', -			'approve_topic', +			'notification.type.topic', +			'notification.type.approve_topic',  		), $topic_id, $user->data['user_id'], $post_time);  		$phpbb_notifications->mark_notifications_read_by_parent(array( -			'quote', -			'bookmark', -			'post', -			'approve_post', +			'notification.type.quote', +			'notification.type.bookmark', +			'notification.type.post', +			'notification.type.approve_post',  		), $topic_id, $user->data['user_id'], $post_time);  		if ($config['load_db_lastread'] && $user->data['is_registered']) @@ -2210,7 +2208,7 @@ function generate_board_url($without_script_path = false)  */  function redirect($url, $return = false, $disable_cd_check = false)  { -	global $db, $cache, $config, $user, $phpbb_root_path, $phpbb_filesystem, $phpbb_path_helper, $phpEx; +	global $db, $cache, $config, $user, $phpbb_root_path, $phpbb_filesystem, $phpbb_path_helper, $phpEx, $phpbb_dispatcher;  	$failover_flag = false; @@ -2219,11 +2217,6 @@ function redirect($url, $return = false, $disable_cd_check = false)  		$user->add_lang('common');  	} -	if (!$return) -	{ -		garbage_collection(); -	} -  	// Make sure no &'s are in, this will break the redirect  	$url = str_replace('&', '&', $url); @@ -2298,10 +2291,26 @@ function redirect($url, $return = false, $disable_cd_check = false)  		trigger_error('INSECURE_REDIRECT', E_USER_ERROR);  	} +	/** +	* Execute code and/or overwrite redirect() +	* +	* @event core.functions.redirect +	* @var	string	url					The url +	* @var	bool	return				If true, do not redirect but return the sanitized URL. +	* @var	bool	disable_cd_check	If true, redirect() will redirect to an external domain. If false, the redirect point to the boards url if it does not match the current domain. +	* @since 3.1.0-RC3 +	*/ +	$vars = array('url', 'return', 'disable_cd_check'); +	extract($phpbb_dispatcher->trigger_event('core.functions.redirect', compact($vars))); +  	if ($return)  	{  		return $url;  	} +	else +	{ +		garbage_collection(); +	}  	// Redirect via an HTML form for PITA webservers  	if (@preg_match('#Microsoft|WebSTAR|Xitami#', getenv('SERVER_SOFTWARE'))) @@ -2529,7 +2538,7 @@ function check_link_hash($token, $link_name)  */  function add_form_key($form_name)  { -	global $config, $template, $user; +	global $config, $template, $user, $phpbb_dispatcher;  	$now = time();  	$token_sid = ($user->data['user_id'] == ANONYMOUS && !empty($config['form_token_sid_guests'])) ? $user->session_id : ''; @@ -2540,6 +2549,27 @@ function add_form_key($form_name)  		'form_token'	=> $token,  	)); +	/** +	* Perform additional actions on creation of the form token +	* +	* @event core.add_form_key +	* @var	string	form_name			The form name +	* @var	int		now					Current time timestamp +	* @var	string	s_fields			Generated hidden fields +	* @var	string	token				Form token +	* @var	string	token_sid			User session ID +	* +	* @since 3.1.0-RC3 +	*/ +	$vars = array( +		'form_name', +		'now', +		's_fields', +		'token', +		'token_sid', +	); +	extract($phpbb_dispatcher->trigger_event('core.add_form_key', compact($vars))); +  	$template->assign_vars(array(  		'S_FORM_TOKEN'	=> $s_fields,  	)); @@ -2719,11 +2749,6 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa  	global $db, $user, $template, $auth, $phpEx, $phpbb_root_path, $config;  	global $request, $phpbb_container; -	if (!class_exists('phpbb_captcha_factory', false)) -	{ -		include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx); -	} -  	$err = '';  	// Make sure user->setup() has been called @@ -2833,7 +2858,7 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa  		{  			case LOGIN_ERROR_ATTEMPTS: -				$captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']); +				$captcha = $phpbb_container->get('captcha.factory')->get_instance($config['captcha_plugin']);  				$captcha->init(CONFIRM_LOGIN);  				// $captcha->reset(); @@ -2945,7 +2970,7 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa  */  function login_forum_box($forum_data)  { -	global $db, $phpbb_container, $request, $template, $user; +	global $db, $phpbb_container, $request, $template, $user, $phpbb_dispatcher;  	$password = $request->variable('password', '', true); @@ -3006,6 +3031,17 @@ function login_forum_box($forum_data)  		$template->assign_var('LOGIN_ERROR', $user->lang['WRONG_PASSWORD']);  	} +	/** +	* Performing additional actions, load additional data on forum login +	* +	* @event core.login_forum_box +	* @var	array	forum_data		Array with forum data +	* @var	string	password		Password entered +	* @since 3.1.0-RC3 +	*/ +	$vars = array('forum_data', 'password'); +	extract($phpbb_dispatcher->trigger_event('core.login_forum_box', compact($vars))); +  	page_header($user->lang['LOGIN']);  	$template->assign_vars(array( @@ -3366,8 +3402,6 @@ function short_ipv6($ip, $length)  *  * @return mixed		false if specified address is not valid,  *					string otherwise -* -* @author bantu  */  function phpbb_ip_normalise($address)  { @@ -3396,8 +3430,6 @@ function phpbb_ip_normalise($address)  *  * @return mixed		false on failure,  *					string otherwise -* -* @author APTX  */  function phpbb_inet_ntop($in_addr)  { @@ -3467,8 +3499,6 @@ function phpbb_inet_ntop($in_addr)  *  * @return mixed		false if address is invalid,  *					in_addr representation of the given address otherwise (string) -* -* @author APTX  */  function phpbb_inet_pton($address)  { @@ -3548,8 +3578,6 @@ function phpbb_inet_pton($address)  *  * Since null can also be returned, you probably want to compare the result  * with === true or === false, -* -* @author bantu  */  function phpbb_checkdnsrr($host, $type = 'MX')  { @@ -4870,7 +4898,7 @@ function page_header($page_title = '', $display_online_list = false, $item_id =  		}  	} -	$dt = new \phpbb\datetime($user, 'now', $user->timezone); +	$dt = $user->create_datetime();  	$timezone_offset = 'GMT' . phpbb_format_timezone_offset($dt->getOffset());  	$timezone_name = $user->timezone->getName();  	if (isset($user->lang['timezones'][$timezone_name])) @@ -5030,6 +5058,20 @@ function page_header($page_title = '', $display_online_list = false, $item_id =  		'SITE_LOGO_IMG'			=> $user->img('site_logo'),  	)); +	// An array of http headers that phpbb will set. The following event may override these. +	$http_headers = array( +		// application/xhtml+xml not used because of IE +		'Content-type' => 'text/html; charset=UTF-8', +		'Cache-Control' => 'private, no-cache="set-cookie"', +		'Expires' => '0', +		'Pragma' => 'no-cache', +	); +	if (!empty($user->data['is_bot'])) +	{ +		// Let reverse proxies know we detected a bot. +		$http_headers['X-PHPBB-IS-BOT'] = 'yes'; +	} +  	/**  	* Execute code and/or overwrite _common_ template variables after they have been assigned.  	* @@ -5040,23 +5082,16 @@ function page_header($page_title = '', $display_online_list = false, $item_id =  	*									session item, e.g. forum for  	*									session_forum_id  	* @var	int		item_id				Restrict online users to item id +	* @var	array		http_headers			HTTP headers that should be set by phpbb  	*  	* @since 3.1.0-b3  	*/ -	$vars = array('page_title', 'display_online_list', 'item_id', 'item'); +	$vars = array('page_title', 'display_online_list', 'item_id', 'item', 'http_headers');  	extract($phpbb_dispatcher->trigger_event('core.page_header_after', compact($vars))); -	// application/xhtml+xml not used because of IE -	header('Content-type: text/html; charset=UTF-8'); - -	header('Cache-Control: private, no-cache="set-cookie"'); -	header('Expires: 0'); -	header('Pragma: no-cache'); - -	if (!empty($user->data['is_bot'])) +	foreach ($http_headers as $hname => $hval)  	{ -		// Let reverse proxies know we detected a bot. -		header('X-PHPBB-IS-BOT: yes'); +		header((string) $hname . ': ' . (string) $hval);  	}  	return; @@ -5084,9 +5119,10 @@ function phpbb_check_and_display_sql_report(\phpbb\request\request_interface $re  * @param \phpbb\config\config				$config		Config object  * @param \phpbb\auth\auth					$auth		Auth object  * @param \phpbb\user						$user		User object +* @param \phpbb\event\dispatcher_interface	$phpbb_dispatcher	Event dispatcher  * @return string  */ -function phpbb_generate_debug_output(phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\auth\auth $auth, \phpbb\user $user) +function phpbb_generate_debug_output(\phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\auth\auth $auth, \phpbb\user $user, \phpbb\event\dispatcher_interface $phpbb_dispatcher)  {  	$debug_info = array(); @@ -5125,6 +5161,17 @@ function phpbb_generate_debug_output(phpbb\db\driver\driver_interface $db, \phpb  		}  	} +	/** +	* Modify debug output information +	* +	* @event core.phpbb_generate_debug_output +	* @var	array	debug_info		Array of strings with debug information +	* +	* @since 3.1.0-RC3 +	*/ +	$vars = array('debug_info'); +	extract($phpbb_dispatcher->trigger_event('core.phpbb_generate_debug_output', compact($vars))); +  	return implode(' | ', $debug_info);  } @@ -5163,7 +5210,7 @@ function page_footer($run_cron = true, $display_template = true, $exit_handler =  	phpbb_check_and_display_sql_report($request, $auth, $db);  	$template->assign_vars(array( -		'DEBUG_OUTPUT'			=> phpbb_generate_debug_output($db, $config, $auth, $user), +		'DEBUG_OUTPUT'			=> phpbb_generate_debug_output($db, $config, $auth, $user, $phpbb_dispatcher),  		'TRANSLATION_INFO'		=> (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '',  		'CREDIT_LINE'			=> $user->lang('POWERED_BY', '<a href="https://www.phpbb.com/">phpBB</a>® Forum Software © phpBB Limited'),  | 
