diff options
Diffstat (limited to 'phpBB/includes/functions_acp.php')
| -rw-r--r-- | phpBB/includes/functions_acp.php | 173 | 
1 files changed, 103 insertions, 70 deletions
| diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index cb44ed2794..3f64bc19f9 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package acp -* @copyright (c) 2005 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ @@ -20,7 +24,7 @@ if (!defined('IN_PHPBB'))  */  function adm_page_header($page_title)  { -	global $config, $db, $user, $template; +	global $config, $user, $template;  	global $phpbb_root_path, $phpbb_admin_path, $phpEx, $SID, $_SID;  	global $phpbb_dispatcher; @@ -41,7 +45,7 @@ function adm_page_header($page_title)  	* @var	string	page_title			Page title  	* @var	bool	adm_page_header_override	Shall we return instead of  	*									running the rest of adm_page_header() -	* @since 3.1-A1 +	* @since 3.1.0-a1  	*/  	$vars = array('page_title', 'adm_page_header_override');  	extract($phpbb_dispatcher->trigger_event('core.adm_page_header', compact($vars))); @@ -103,12 +107,30 @@ function adm_page_header($page_title)  		'S_CONTENT_FLOW_END'	=> ($user->lang['DIRECTION'] == 'ltr') ? 'right' : 'left',  	)); -	// application/xhtml+xml not used because of IE -	header('Content-type: text/html; charset=UTF-8'); +	// 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' => gmdate('D, d M Y H:i:s', time()) . ' GMT', +	); -	header('Cache-Control: private, no-cache="set-cookie"'); -	header('Expires: 0'); -	header('Pragma: no-cache'); +	/** +	* Execute code and/or overwrite _common_ template variables after they have been assigned. +	* +	* @event core.adm_page_header_after +	* @var	string	page_title			Page title +	* @var	array	http_headers			HTTP headers that should be set by phpbb +	* +	* @since 3.1.0-RC3 +	*/ +	$vars = array('page_title', 'http_headers'); +	extract($phpbb_dispatcher->trigger_event('core.adm_page_header_after', compact($vars))); + +	foreach ($http_headers as $hname => $hval) +	{ +		header((string) $hname . ': ' . (string) $hval); +	}  	return;  } @@ -118,8 +140,8 @@ function adm_page_header($page_title)  */  function adm_page_footer($copyright_html = true)  { -	global $db, $config, $template, $user, $auth, $cache; -	global $starttime, $phpbb_root_path, $phpbb_admin_path, $phpEx; +	global $db, $config, $template, $user, $auth; +	global $phpbb_root_path;  	global $request, $phpbb_dispatcher;  	// A listener can set this variable to `true` when it overrides this function @@ -132,7 +154,7 @@ function adm_page_footer($copyright_html = true)  	* @var	bool	copyright_html			Shall we display the copyright?  	* @var	bool	adm_page_footer_override	Shall we return instead of  	*									running the rest of adm_page_footer() -	* @since 3.1-A1 +	* @since 3.1.0-a1  	*/  	$vars = array('copyright_html', 'adm_page_footer_override');  	extract($phpbb_dispatcher->trigger_event('core.adm_page_footer', compact($vars))); @@ -142,41 +164,16 @@ function adm_page_footer($copyright_html = true)  		return;  	} -	// Output page creation time -	if (defined('DEBUG')) -	{ -		$mtime = explode(' ', microtime()); -		$totaltime = $mtime[0] + $mtime[1] - $starttime; - -		if ($request->variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG') && method_exists($db, 'sql_report')) -		{ -			$db->sql_report('display'); -		} - -		$debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress']) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime); +	$user->update_session_infos(); -		if ($auth->acl_get('a_') && defined('DEBUG')) -		{ -			if (function_exists('memory_get_peak_usage')) -			{ -				if ($memory_usage = memory_get_peak_usage()) -				{ -					$memory_usage = get_formatted_filesize($memory_usage); - -					$debug_output .= ' | Peak Memory Usage: ' . $memory_usage; -				} -			} - -			$debug_output .= ' | <a href="' . build_url() . '&explain=1">Explain</a>'; -		} -	} +	phpbb_check_and_display_sql_report($request, $auth, $db);  	$template->assign_vars(array( -		'DEBUG_OUTPUT'		=> (defined('DEBUG')) ? $debug_output : '', +		'DEBUG_OUTPUT'		=> phpbb_generate_debug_output($db, $config, $auth, $user, $phpbb_dispatcher),  		'TRANSLATION_INFO'	=> (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '',  		'S_COPYRIGHT_HTML'	=> $copyright_html, -		'CREDIT_LINE'		=> $user->lang('POWERED_BY', '<a href="https://www.phpbb.com/">phpBB</a>® Forum Software © phpBB Group'), -		'T_JQUERY_LINK'		=> !empty($config['allow_cdn']) && !empty($config['load_jquery_url']) ? $config['load_jquery_url'] : "{$phpbb_root_path}assets/javascript/jquery.js", +		'CREDIT_LINE'		=> $user->lang('POWERED_BY', '<a href="https://www.phpbb.com/">phpBB</a>® Forum Software © phpBB Limited'), +		'T_JQUERY_LINK'		=> !empty($config['allow_cdn']) && !empty($config['load_jquery_url']) ? $config['load_jquery_url'] : "{$phpbb_root_path}assets/javascript/jquery.min.js",  		'S_ALLOW_CDN'		=> !empty($config['allow_cdn']),  		'VERSION'			=> $config['version'])  	); @@ -235,7 +232,7 @@ function h_radio($name, $input_ary, $input_default = false, $id = false, $key =  /**  * Build configuration template for acp configuration pages  */ -function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars) +function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)  {  	global $user, $module, $phpbb_dispatcher; @@ -243,15 +240,20 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)  	$name = 'config[' . $config_key . ']';  	// Make sure there is no notice printed out for non-existent config options (we simply set them) -	if (!isset($new[$config_key])) +	if (!isset($new_ary[$config_key]))  	{ -		$new[$config_key] = ''; +		$new_ary[$config_key] = '';  	}  	switch ($tpl_type[0])  	{ -		case 'text':  		case 'password': +			if ($new_ary[$config_key] !== '') +			{ +				// replace passwords with asterixes +				$new_ary[$config_key] = '********'; +			} +		case 'text':  		case 'url':  		case 'email':  		case 'color': @@ -263,16 +265,15 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)  		case 'range':  		case 'search':  		case 'tel': -		case 'url':  		case 'week':  			$size = (int) $tpl_type[1];  			$maxlength = (int) $tpl_type[2]; -			$tpl = '<input id="' . $key . '" type="' . $tpl_type[0] . '"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="' . $name . '" value="' . $new[$config_key] . '"' . (($tpl_type[0] === 'password') ?  ' autocomplete="off"' : '') . ' />'; +			$tpl = '<input id="' . $key . '" type="' . $tpl_type[0] . '"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="' . $name . '" value="' . $new_ary[$config_key] . '"' . (($tpl_type[0] === 'password') ?  ' autocomplete="off"' : '') . ' />';  		break;  		case 'number': -			$min = $max = $maxlength = ''; +			$max = $maxlength = '';  			$min = ( isset($tpl_type[1]) ) ? (int) $tpl_type[1] : false;  			if ( isset($tpl_type[2]) )  			{ @@ -280,11 +281,11 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)  				$maxlength = strlen( (string) $max );  			} -			$tpl = '<input id="' . $key . '" type="number" maxlength="' . (( $maxlength != '' ) ? $maxlength : 255) . '"' . (( $min != '' ) ? ' min="' . $min . '"' : '') . (( $max != '' ) ? ' max="' . $max . '"' : '') . ' name="' . $name . '" value="' . $new[$config_key] . '" />'; +			$tpl = '<input id="' . $key . '" type="number" maxlength="' . (( $maxlength != '' ) ? $maxlength : 255) . '"' . (( $min != '' ) ? ' min="' . $min . '"' : '') . (( $max != '' ) ? ' max="' . $max . '"' : '') . ' name="' . $name . '" value="' . $new_ary[$config_key] . '" />';  		break;  		case 'dimension': -			$min = $max = $maxlength = $size = ''; +			$max = $maxlength = $size = '';  			$min = (int) $tpl_type[1]; @@ -294,19 +295,19 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)  				$size = $maxlength = strlen( (string) $max );  			} -			$tpl = '<input id="' . $key . '" type="number"' . (( $size != '' ) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength != '') ? $maxlength : 255) . '"' . (( $min !== '' ) ? ' min="' . $min . '"' : '') . (( $max != '' ) ? ' max="' . $max . '"' : '') . ' name="config[' . $config_key . '_width]" value="' . $new[$config_key . '_width'] . '" /> x <input type="number"' . (( $size != '' ) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength != '') ? $maxlength : 255) . '"' . (( $min !== '' ) ? ' min="' . $min . '"' : '') . (( $max != '' ) ? ' max="' . $max . '"' : '') . ' name="config[' . $config_key . '_height]" value="' . $new[$config_key . '_height'] . '" />'; +			$tpl = '<input id="' . $key . '" type="number"' . (( $size != '' ) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength != '') ? $maxlength : 255) . '"' . (( $min !== '' ) ? ' min="' . $min . '"' : '') . (( $max != '' ) ? ' max="' . $max . '"' : '') . ' name="config[' . $config_key . '_width]" value="' . $new_ary[$config_key . '_width'] . '" /> x <input type="number"' . (( $size != '' ) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength != '') ? $maxlength : 255) . '"' . (( $min !== '' ) ? ' min="' . $min . '"' : '') . (( $max != '' ) ? ' max="' . $max . '"' : '') . ' name="config[' . $config_key . '_height]" value="' . $new_ary[$config_key . '_height'] . '" />';  		break;  		case 'textarea':  			$rows = (int) $tpl_type[1];  			$cols = (int) $tpl_type[2]; -			$tpl = '<textarea id="' . $key . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . $new[$config_key] . '</textarea>'; +			$tpl = '<textarea id="' . $key . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . $new_ary[$config_key] . '</textarea>';  		break;  		case 'radio': -			$key_yes	= ($new[$config_key]) ? ' checked="checked"' : ''; -			$key_no		= (!$new[$config_key]) ? ' checked="checked"' : ''; +			$key_yes	= ($new_ary[$config_key]) ? ' checked="checked"' : ''; +			$key_no		= (!$new_ary[$config_key]) ? ' checked="checked"' : '';  			$tpl_type_cond = explode('_', $tpl_type[1]);  			$type_no = ($tpl_type_cond[0] == 'disabled' || $tpl_type_cond[0] == 'enabled') ? false : true; @@ -320,8 +321,6 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)  		case 'select':  		case 'custom': -			$return = ''; -  			if (isset($vars['method']))  			{  				$call = array($module->module, $vars['method']); @@ -343,7 +342,7 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)  					switch ($value)  					{  						case '{CONFIG_VALUE}': -							$value = $new[$config_key]; +							$value = $new_ary[$config_key];  						break;  						case '{KEY}': @@ -356,7 +355,7 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)  			}  			else  			{ -				$args = array($new[$config_key], $key); +				$args = array($new_ary[$config_key], $key);  			}  			$return = call_user_func_array($call, $args); @@ -364,8 +363,9 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)  			if ($tpl_type[0] == 'select')  			{  				$size = (isset($tpl_type[1])) ? (int) $tpl_type[1] : 1; +				$data_toggle = (!empty($tpl_type[2])) ? ' data-togglable-settings="true"' : ''; -				$tpl = '<select id="' . $key . '" name="' . $name . '"' . (($size > 1) ? ' size="' . $size . '"' : '') . '>' . $return . '</select>'; +				$tpl = '<select id="' . $key . '" name="' . $name . '"' . (($size > 1) ? ' size="' . $size . '"' : '') . $data_toggle . '>' . $return . '</select>';  			}  			else  			{ @@ -383,6 +383,7 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)  		$tpl .= $vars['append'];  	} +	$new = $new_ary;  	/**  	* Overwrite the html code we display for the config value  	* @@ -396,10 +397,12 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)  	* @var	string	name		Should be used for the name attribute  	* @var	array	vars		Array with the options for the config  	* @var	string	tpl			The resulting html code we display -	* @since 3.1-A1 +	* @since 3.1.0-a1  	*/  	$vars = array('tpl_type', 'key', 'new', 'name', 'vars', 'tpl');  	extract($phpbb_dispatcher->trigger_event('core.build_config_template', compact($vars))); +	$new_ary = $new; +	unset($new);  	return $tpl;  } @@ -410,7 +413,7 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)  */  function validate_config_vars($config_vars, &$cfg_array, &$error)  { -	global $phpbb_root_path, $user, $phpbb_dispatcher; +	global $phpbb_root_path, $user, $phpbb_dispatcher, $phpbb_filesystem;  	$type	= 0;  	$min	= 1; @@ -555,6 +558,9 @@ function validate_config_vars($config_vars, &$cfg_array, &$error)  				$cfg_array[$config_name] = trim($destination); +			// Absolute file path +			case 'absolute_path': +			case 'absolute_path_writable':  			// Path being relative (still prefixed by phpbb_root_path), but with the ability to escape the root dir...  			case 'path':  			case 'wpath': @@ -573,20 +579,22 @@ function validate_config_vars($config_vars, &$cfg_array, &$error)  					break;  				} -				if (!file_exists($phpbb_root_path . $cfg_array[$config_name])) +				$path = in_array($config_definition['validate'], array('wpath', 'path', 'rpath', 'rwpath')) ? $phpbb_root_path . $cfg_array[$config_name] : $cfg_array[$config_name]; + +				if (!file_exists($path))  				{  					$error[] = sprintf($user->lang['DIRECTORY_DOES_NOT_EXIST'], $cfg_array[$config_name]);  				} -				if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !is_dir($phpbb_root_path . $cfg_array[$config_name])) +				if (file_exists($path) && !is_dir($path))  				{  					$error[] = sprintf($user->lang['DIRECTORY_NOT_DIR'], $cfg_array[$config_name]);  				}  				// Check if the path is writable -				if ($config_definition['validate'] == 'wpath' || $config_definition['validate'] == 'rwpath') +				if ($config_definition['validate'] == 'wpath' || $config_definition['validate'] == 'rwpath' || $config_definition['validate'] === 'absolute_path_writable')  				{ -					if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !phpbb_is_writable($phpbb_root_path . $cfg_array[$config_name])) +					if (file_exists($path) && !$phpbb_filesystem->is_writable($path))  					{  						$error[] = sprintf($user->lang['DIRECTORY_NOT_WRITABLE'], $cfg_array[$config_name]);  					} @@ -606,7 +614,7 @@ function validate_config_vars($config_vars, &$cfg_array, &$error)  				* @var	array	error		Array of errors, the errors should  				*							be strings only, language keys are  				*							not replaced afterwards -				* @since 3.1-A1 +				* @since 3.1.0-a1  				*/  				$vars = array('cfg_array', 'config_name', 'config_definition', 'error');  				extract($phpbb_dispatcher->trigger_event('core.validate_config_variable', compact($vars))); @@ -642,8 +650,6 @@ function validate_range($value_ary, &$error)  	foreach ($value_ary as $value)  	{  		$column = explode(':', $value['column_type']); -		$max = $min = 0; -		$type = 0;  		if (!isset($column_types[$column[0]]))  		{  			continue; @@ -678,3 +684,30 @@ function validate_range($value_ary, &$error)  		}  	}  } + +/** +* Inserts new config display_vars into an exisiting display_vars array +* at the given position. +* +* @param array $display_vars An array of existing config display vars +* @param array $add_config_vars An array of new config display vars +* @param array $where Where to place the new config vars, +*              before or after an exisiting config, as an array +*              of the form: array('after' => 'config_name') or +*              array('before' => 'config_name'). +* @return array The array of config display vars +*/ +function phpbb_insert_config_array($display_vars, $add_config_vars, $where) +{ +	if (is_array($where) && array_key_exists(current($where), $display_vars)) +	{ +		$position = array_search(current($where), array_keys($display_vars)) + ((key($where) == 'before') ? 0 : 1); +		$display_vars = array_merge( +			array_slice($display_vars, 0, $position), +			$add_config_vars, +			array_slice($display_vars, $position) +		); +	} + +	return $display_vars; +} | 
