diff options
Diffstat (limited to 'phpBB/includes/functions.php')
| -rw-r--r-- | phpBB/includes/functions.php | 279 | 
1 files changed, 42 insertions, 237 deletions
| diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 573df9e55d..949d33c566 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -64,135 +64,6 @@ function set_var(&$result, $var, $type, $multibyte = false)  }  /** -* Wrapper function of \phpbb\request\request::variable which exists for backwards compatability. -* See {@link \phpbb\request\request_interface::variable \phpbb\request\request_interface::variable} for -* documentation of this function's use. -* -* @deprecated -* @param	mixed			$var_name	The form variable's name from which data shall be retrieved. -* 										If the value is an array this may be an array of indizes which will give -* 										direct access to a value at any depth. E.g. if the value of "var" is array(1 => "a") -* 										then specifying array("var", 1) as the name will return "a". -* 										If you pass an instance of {@link \phpbb\request\request_interface phpbb_request_interface} -* 										as this parameter it will overwrite the current request class instance. If you do -* 										not do so, it will create its own instance (but leave superglobals enabled). -* @param	mixed			$default	A default value that is returned if the variable was not set. -* 										This function will always return a value of the same type as the default. -* @param	bool			$multibyte	If $default is a string this paramater has to be true if the variable may contain any UTF-8 characters -*										Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks -* @param	bool			$cookie		This param is mapped to \phpbb\request\request_interface::COOKIE as the last param for -* 										\phpbb\request\request_interface::variable for backwards compatability reasons. -* @param	\phpbb\request\request_interface|null|false	If an instance of \phpbb\request\request_interface is given the instance is stored in -*										a static variable and used for all further calls where this parameters is null. Until -*										the function is called with an instance it automatically creates a new \phpbb\request\request -*										instance on every call. By passing false this per-call instantiation can be restored -*										after having passed in a \phpbb\request\request_interface instance. -* -* @return	mixed	The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the -* 					the same as that of $default. If the variable is not set $default is returned. -*/ -function request_var($var_name, $default, $multibyte = false, $cookie = false, $request = null) -{ -	// This is all just an ugly hack to add "Dependency Injection" to a function -	// the only real code is the function call which maps this function to a method. -	static $static_request = null; - -	if ($request instanceof \phpbb\request\request_interface) -	{ -		$static_request = $request; - -		if (empty($var_name)) -		{ -			return; -		} -	} -	else if ($request === false) -	{ -		$static_request = null; - -		if (empty($var_name)) -		{ -			return; -		} -	} - -	$tmp_request = $static_request; - -	// no request class set, create a temporary one ourselves to keep backwards compatability -	if ($tmp_request === null) -	{ -		// false param: enable super globals, so the created request class does not -		// make super globals inaccessible everywhere outside this function. -		$tmp_request = new \phpbb\request\request(new \phpbb\request\type_cast_helper(), false); -	} - -	return $tmp_request->variable($var_name, $default, $multibyte, ($cookie) ? \phpbb\request\request_interface::COOKIE : \phpbb\request\request_interface::REQUEST); -} - -/** -* Sets a configuration option's value. -* -* Please note that this function does not update the is_dynamic value for -* an already existing config option. -* -* @param string $config_name   The configuration option's name -* @param string $config_value  New configuration value -* @param bool   $is_dynamic    Whether this variable should be cached (false) or -*                              if it changes too frequently (true) to be -*                              efficiently cached. -* -* @return null -* -* @deprecated -*/ -function set_config($config_name, $config_value, $is_dynamic = false, \phpbb\config\config $set_config = null) -{ -	static $config = null; - -	if ($set_config !== null) -	{ -		$config = $set_config; - -		if (empty($config_name)) -		{ -			return; -		} -	} - -	$config->set($config_name, $config_value, !$is_dynamic); -} - -/** -* Increments an integer config value directly in the database. -* -* @param string $config_name   The configuration option's name -* @param int    $increment     Amount to increment by -* @param bool   $is_dynamic    Whether this variable should be cached (false) or -*                              if it changes too frequently (true) to be -*                              efficiently cached. -* -* @return null -* -* @deprecated -*/ -function set_config_count($config_name, $increment, $is_dynamic = false, \phpbb\config\config $set_config = null) -{ -	static $config = null; - -	if ($set_config !== null) -	{ -		$config = $set_config; - -		if (empty($config_name)) -		{ -			return; -		} -	} - -	$config->increment($config_name, $increment, !$is_dynamic); -} - -/**  * Generates an alphanumeric random string of given length  *  * @return string @@ -235,8 +106,8 @@ function unique_id($extra = 'c')  	if ($dss_seeded !== true && ($config['rand_seed_last_update'] < time() - rand(1,10)))  	{ -		set_config('rand_seed_last_update', time(), true); -		set_config('rand_seed', $config['rand_seed'], true); +		$config->set('rand_seed_last_update', time(), false); +		$config->set('rand_seed', $config['rand_seed'], false);  		$dss_seeded = true;  	} @@ -376,8 +247,7 @@ function still_on_time($extra_time = 15)  {  	static $max_execution_time, $start_time; -	$time = explode(' ', microtime()); -	$current_time = $time[0] + $time[1]; +	$current_time = microtime(true);  	if (empty($max_execution_time))  	{ @@ -802,7 +672,7 @@ function phpbb_own_realpath($path)  	$max = sizeof($bits) - 1; -	// Check if we are able to resolve symlinks, Windows cannot. +	// Check if we are able to resolve symlinks, Windows (prior to Vista and Server 2008) cannot.  	$symlink_resolve = (function_exists('readlink')) ? true : false;  	foreach ($bits as $i => $bit) @@ -1192,7 +1062,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $  		if ($forum_id === false || !sizeof($forum_id))  		{  			// Mark all forums read (index page) - +			/* @var $phpbb_notifications \phpbb\notification\manager */  			$phpbb_notifications = $phpbb_container->get('notification_manager');  			// Mark all topic notifications read for this user @@ -1259,6 +1129,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $  			$forum_id = array($forum_id);  		} +		/* @var $phpbb_notifications \phpbb\notification\manager */  		$phpbb_notifications = $phpbb_container->get('notification_manager');  		$phpbb_notifications->mark_notifications_read_by_parent(array( @@ -1381,6 +1252,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $  			return;  		} +		/* @var $phpbb_notifications \phpbb\notification\manager */  		$phpbb_notifications = $phpbb_container->get('notification_manager');  		// Mark post notifications read for this user in this topic @@ -1680,7 +1552,7 @@ function get_complete_topic_tracking($forum_id, $topic_ids, $global_announce_lis  */  function get_unread_topics($user_id = false, $sql_extra = '', $sql_sort = '', $sql_limit = 1001, $sql_limit_offset = 0)  { -	global $config, $db, $user; +	global $config, $db, $user, $request;  	global $phpbb_dispatcher;  	$user_id = ($user_id === false) ? (int) $user->data['user_id'] : (int) $user_id; @@ -1759,7 +1631,7 @@ function get_unread_topics($user_id = false, $sql_extra = '', $sql_sort = '', $s  		if (empty($tracking_topics))  		{ -			$tracking_topics = request_var($config['cookie_name'] . '_track', '', false, true); +			$tracking_topics = $request->variable($config['cookie_name'] . '_track', '', false, \phpbb\request\request_interface::COOKIE);  			$tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();  		} @@ -1851,6 +1723,7 @@ function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_ti  	// Handle update of unapproved topics info.  	// Only update for moderators having m_approve permission for the forum. +	/* @var $phpbb_content_visibility \phpbb\content_visibility */  	$phpbb_content_visibility = $phpbb_container->get('content.visibility');  	// Check the forum for any left unread topics. @@ -2701,9 +2574,9 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo  	if ($check && $confirm)  	{ -		$user_id = request_var('confirm_uid', 0); -		$session_id = request_var('sess', ''); -		$confirm_key = request_var('confirm_key', ''); +		$user_id = $request->variable('confirm_uid', 0); +		$session_id = $request->variable('sess', ''); +		$confirm_key = $request->variable('confirm_key', '');  		if ($user_id != $user->data['user_id'] || $session_id != $user->session_id || !$confirm_key || !$user->data['user_last_confirm_key'] || $confirm_key != $user->data['user_last_confirm_key'])  		{ @@ -2745,7 +2618,7 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo  	);  	// If activation key already exist, we better do not re-use the key (something very strange is going on...) -	if (request_var('confirm_key', '')) +	if ($request->variable('confirm_key', ''))  	{  		// This should not occur, therefore we cancel the operation to safe the user  		return false; @@ -2801,7 +2674,7 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo  function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = false, $s_display = true)  {  	global $db, $user, $template, $auth, $phpEx, $phpbb_root_path, $config; -	global $request, $phpbb_container, $phpbb_dispatcher; +	global $request, $phpbb_container, $phpbb_dispatcher, $phpbb_log;  	$err = ''; @@ -2818,7 +2691,7 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa  		// anonymous/inactive users are never able to go to the ACP even if they have the relevant permissions  		if ($user->data['is_registered'])  		{ -			add_log('admin', 'LOG_ADMIN_AUTH_FAIL'); +			$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ADMIN_AUTH_FAIL');  		}  		trigger_error('NO_AUTH_ADMIN');  	} @@ -2828,13 +2701,13 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa  		// Get credential  		if ($admin)  		{ -			$credential = request_var('credential', ''); +			$credential = $request->variable('credential', '');  			if (strspn($credential, 'abcdef0123456789') !== strlen($credential) || strlen($credential) != 32)  			{  				if ($user->data['is_registered'])  				{ -					add_log('admin', 'LOG_ADMIN_AUTH_FAIL'); +					$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ADMIN_AUTH_FAIL');  				}  				trigger_error('NO_AUTH_ADMIN');  			} @@ -2846,7 +2719,7 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa  			$password	= $request->untrimmed_variable('password', '', true);  		} -		$username	= request_var('username', '', true); +		$username	= $request->variable('username', '', true);  		$autologin	= $request->is_set_post('autologin');  		$viewonline = (int) !$request->is_set_post('viewonline');  		$admin 		= ($admin) ? 1 : 0; @@ -2856,7 +2729,7 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa  		if ($admin && utf8_clean_string($username) != utf8_clean_string($user->data['username']))  		{  			// We log the attempt to use a different username... -			add_log('admin', 'LOG_ADMIN_AUTH_FAIL'); +			$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ADMIN_AUTH_FAIL');  			trigger_error('NO_AUTH_ADMIN_USER_DIFFER');  		} @@ -2869,7 +2742,7 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa  		{  			if ($result['status'] == LOGIN_SUCCESS)  			{ -				add_log('admin', 'LOG_ADMIN_AUTH_SUCCESS'); +				$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ADMIN_AUTH_SUCCESS');  			}  			else  			{ @@ -2877,7 +2750,7 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa  				// anonymous/inactive users are never able to go to the ACP even if they have the relevant permissions  				if ($user->data['is_registered'])  				{ -					add_log('admin', 'LOG_ADMIN_AUTH_FAIL'); +					$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ADMIN_AUTH_FAIL');  				}  			}  		} @@ -2885,7 +2758,7 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa  		// The result parameter is always an array, holding the relevant information...  		if ($result['status'] == LOGIN_SUCCESS)  		{ -			$redirect = request_var('redirect', "{$phpbb_root_path}index.$phpEx"); +			$redirect = $request->variable('redirect', "{$phpbb_root_path}index.$phpEx");  			/**  			* This event allows an extension to modify the redirection when a user successfully logs in @@ -2985,6 +2858,7 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa  		$s_hidden_fields['credential'] = $credential;  	} +	/* @var $provider_collection \phpbb\auth\provider_collection */  	$provider_collection = $phpbb_container->get('auth.provider_collection');  	$auth_provider = $provider_collection->get_provider(); @@ -3088,6 +2962,7 @@ function login_forum_box($forum_data)  		}  		$db->sql_freeresult($result); +		/* @var $passwords_manager \phpbb\passwords\manager */  		$passwords_manager = $phpbb_container->get('passwords.manager');  		if ($passwords_manager->check($password, $forum_data['forum_password'])) @@ -3244,52 +3119,6 @@ function parse_cfg_file($filename, $lines = false)  }  /** -* Add log entry -* -* @param	string	$mode				The mode defines which log_type is used and from which log the entry is retrieved -* @param	int		$forum_id			Mode 'mod' ONLY: forum id of the related item, NOT INCLUDED otherwise -* @param	int		$topic_id			Mode 'mod' ONLY: topic id of the related item, NOT INCLUDED otherwise -* @param	int		$reportee_id		Mode 'user' ONLY: user id of the reportee, NOT INCLUDED otherwise -* @param	string	$log_operation		Name of the operation -* @param	array	$additional_data	More arguments can be added, depending on the log_type -* -* @return	int|bool		Returns the log_id, if the entry was added to the database, false otherwise. -* -* @deprecated	Use $phpbb_log->add() instead -*/ -function add_log() -{ -	global $phpbb_log, $user; - -	$args = func_get_args(); -	$mode = array_shift($args); - -	// This looks kind of dirty, but add_log has some additional data before the log_operation -	$additional_data = array(); -	switch ($mode) -	{ -		case 'admin': -		case 'critical': -		break; -		case 'mod': -			$additional_data['forum_id'] = array_shift($args); -			$additional_data['topic_id'] = array_shift($args); -		break; -		case 'user': -			$additional_data['reportee_id'] = array_shift($args); -		break; -	} - -	$log_operation = array_shift($args); -	$additional_data = array_merge($additional_data, $args); - -	$user_id = (empty($user->data)) ? ANONYMOUS : $user->data['user_id']; -	$user_ip = (empty($user->ip)) ? '' : $user->ip; - -	return $phpbb_log->add($mode, $user_id, $user_ip, $log_operation, time(), $additional_data); -} - -/**  * Return a nicely formatted backtrace.  *  * Turns the array returned by debug_backtrace() into HTML markup. @@ -3690,38 +3519,12 @@ function phpbb_checkdnsrr($host, $type = 'MX')  		return (@gethostbyname($host_fqdn) == $host_fqdn) ? false : true;  	} -	// checkdnsrr() is available on Windows since PHP 5.3, -	// but until 5.3.3 it only works for MX records -	// See: http://bugs.php.net/bug.php?id=51844 - -	// Call checkdnsrr() if -	// we're looking for an MX record or -	// we're not on Windows or -	// we're running a PHP version where #51844 has been fixed - -	// checkdnsrr() supports AAAA since 5.0.0 -	// checkdnsrr() supports TXT since 5.2.4 -	if ( -		($type == 'MX' || DIRECTORY_SEPARATOR != '\\' || version_compare(PHP_VERSION, '5.3.3', '>=')) && -		($type != 'AAAA' || version_compare(PHP_VERSION, '5.0.0', '>=')) && -		($type != 'TXT' || version_compare(PHP_VERSION, '5.2.4', '>=')) && -		function_exists('checkdnsrr') -	) +	if (function_exists('checkdnsrr'))  	{  		return checkdnsrr($host_fqdn, $type);  	} -	// dns_get_record() is available since PHP 5; since PHP 5.3 also on Windows, -	// but on Windows it does not work reliable for AAAA records before PHP 5.3.1 - -	// Call dns_get_record() if -	// we're not looking for an AAAA record or -	// we're not on Windows or -	// we're running a PHP version where AAAA lookups work reliable -	if ( -		($type != 'AAAA' || DIRECTORY_SEPARATOR != '\\' || version_compare(PHP_VERSION, '5.3.1', '>=')) && -		function_exists('dns_get_record') -	) +	if (function_exists('dns_get_record'))  	{  		// dns_get_record() expects an integer as second parameter  		// We have to convert the string $type to the corresponding integer constant. @@ -3854,7 +3657,7 @@ function phpbb_checkdnsrr($host, $type = 'MX')  function msg_handler($errno, $msg_text, $errfile, $errline)  {  	global $cache, $db, $auth, $template, $config, $user, $request; -	global $phpEx, $phpbb_root_path, $msg_title, $msg_long_text; +	global $phpEx, $phpbb_root_path, $msg_title, $msg_long_text, $phpbb_log;  	// Do not display notices if we suppress them via @  	if (error_reporting() == 0 && $errno != E_USER_ERROR && $errno != E_USER_WARNING && $errno != E_USER_NOTICE) @@ -3868,11 +3671,6 @@ function msg_handler($errno, $msg_text, $errfile, $errline)  		$msg_text = $msg_long_text;  	} -	if (!defined('E_DEPRECATED')) -	{ -		define('E_DEPRECATED', 8192); -	} -  	switch ($errno)  	{  		case E_NOTICE: @@ -3895,7 +3693,7 @@ function msg_handler($errno, $msg_text, $errfile, $errline)  				// we are writing an image - the user won't see the debug, so let's place it in the log  				if (defined('IMAGE_OUTPUT') || defined('IN_CRON'))  				{ -					add_log('critical', 'LOG_IMAGE_GENERATION_ERROR', $errfile, $errline, $msg_text); +					$phpbb_log->add('critical', $user->data['user_id'], $user->ip, 'LOG_IMAGE_GENERATION_ERROR', false, array($errfile, $errline, $msg_text));  				}  				// echo '<br /><br />BACKTRACE<br />' . get_backtrace() . '<br />' . "\n";  			} @@ -3957,7 +3755,7 @@ function msg_handler($errno, $msg_text, $errfile, $errline)  			{  				// let's avoid loops  				$db->sql_return_on_error(true); -				add_log('critical', 'LOG_GENERAL_ERROR', $msg_title, $log_text); +				$phpbb_log->add('critical', $user->data['user_id'], $user->ip, 'LOG_GENERAL_ERROR', false, array($msg_title, $log_text));  				$db->sql_return_on_error(false);  			} @@ -4823,6 +4621,7 @@ function phpbb_get_avatar($row, $alt, $ignore_config = false)  		'height' => $row['avatar_height'],  	); +	/* @var $phpbb_avatar_manager \phpbb\avatar\manager */  	$phpbb_avatar_manager = $phpbb_container->get('avatar.manager');  	$driver = $phpbb_avatar_manager->get_driver($row['avatar_type'], $ignore_config);  	$html = ''; @@ -4951,8 +4750,8 @@ function page_header($page_title = '', $display_online_list = false, $item_id =  		if ($total_online_users > $config['record_online_users'])  		{ -			set_config('record_online_users', $total_online_users, true); -			set_config('record_online_date', time(), true); +			$config->set('record_online_users', $total_online_users, false); +			$config->set('record_online_date', time(), false);  		}  		$l_online_record = $user->lang('RECORD_ONLINE_USERS', (int) $config['record_online_users'], $user->format_date($config['record_online_date'], false, true)); @@ -4987,8 +4786,8 @@ function page_header($page_title = '', $display_online_list = false, $item_id =  		}  	} -	$forum_id = request_var('f', 0); -	$topic_id = request_var('t', 0); +	$forum_id = $request->variable('f', 0); +	$topic_id = $request->variable('t', 0);  	$s_feed_news = false; @@ -5008,6 +4807,7 @@ function page_header($page_title = '', $display_online_list = false, $item_id =  	// This path is sent with the base template paths in the assign_vars()  	// call below. We need to correct it in case we are accessing from a  	// controller because the web paths will be incorrect otherwise. +	/* @var $phpbb_path_helper \phpbb\path_helper */  	$phpbb_path_helper = $phpbb_container->get('path_helper');  	$corrected_path = $phpbb_path_helper->get_web_root_path();  	$web_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? $board_url : $corrected_path; @@ -5046,6 +4846,7 @@ function page_header($page_title = '', $display_online_list = false, $item_id =  	$notifications = false;  	if ($config['load_notifications'] && $user->data['user_id'] != ANONYMOUS && $user->data['user_type'] != USER_IGNORE)  	{ +		/* @var $phpbb_notifications \phpbb\notification\manager */  		$phpbb_notifications = $phpbb_container->get('notification_manager');  		$notifications = $phpbb_notifications->load_notifications(array( @@ -5059,6 +4860,8 @@ function page_header($page_title = '', $display_online_list = false, $item_id =  		}  	} +	/** @var \phpbb\controller\helper $controller_helper */ +	$controller_helper = $phpbb_container->get('controller.helper');  	$notification_mark_hash = generate_link_hash('mark_all_notifications_read');  	// The following assigns all _common_ variables that may be used at any point in a template. @@ -5112,7 +4915,7 @@ function page_header($page_title = '', $display_online_list = false, $item_id =  		'U_PROFILE'				=> append_sid("{$phpbb_root_path}ucp.$phpEx"),  		'U_USER_PROFILE'		=> get_username_string('profile', $user->data['user_id'], $user->data['username'], $user->data['user_colour']),  		'U_MODCP'				=> append_sid("{$phpbb_root_path}mcp.$phpEx", false, true, $user->session_id), -		'U_FAQ'					=> append_sid("{$phpbb_root_path}faq.$phpEx"), +		'U_FAQ'					=> $controller_helper->route('phpbb_help_controller', array('mode' => 'faq')),  		'U_SEARCH_SELF'			=> append_sid("{$phpbb_root_path}search.$phpEx", 'search_id=egosearch'),  		'U_SEARCH_NEW'			=> append_sid("{$phpbb_root_path}search.$phpEx", 'search_id=newposts'),  		'U_SEARCH_UNANSWERED'	=> append_sid("{$phpbb_root_path}search.$phpEx", 'search_id=unanswered'), @@ -5376,6 +5179,8 @@ function page_footer($run_cron = true, $display_template = true, $exit_handler =  	if ($call_cron)  	{  		global $phpbb_container; + +		/* @var $cron \phpbb\cron\manager */  		$cron = $phpbb_container->get('cron.manager');  		$task = $cron->find_one_ready_task(); | 
