diff options
Diffstat (limited to 'phpBB/phpbb')
279 files changed, 5890 insertions, 2958 deletions
diff --git a/phpBB/phpbb/auth/auth.php b/phpBB/phpbb/auth/auth.php index 279959974d..b5cc675838 100644 --- a/phpBB/phpbb/auth/auth.php +++ b/phpBB/phpbb/auth/auth.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\auth; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * Permission/Auth class  * @package phpBB3  */ -class phpbb_auth +class auth  {  	var $acl = array();  	var $cache = array(); @@ -970,6 +972,18 @@ class phpbb_auth  				);  			} +			// If the auth provider wants us to link an empty account do so and redirect +			if ($login['status'] == LOGIN_SUCCESS_LINK_PROFILE) +			{ +				// If this status exists a fourth field is in the $login array called 'redirect_data' +				// This data is passed along as GET data to the next page allow the account to be linked + +				$params = array('mode' => 'login_link'); +				$url = append_sid($phpbb_root_path . 'ucp.' . $phpEx, array_merge($params, $login['redirect_data'])); + +				redirect($url); +			} +  			// If login succeeded, we will log the user in... else we pass the login array through...  			if ($login['status'] == LOGIN_SUCCESS)  			{ diff --git a/phpBB/phpbb/auth/provider/apache.php b/phpBB/phpbb/auth/provider/apache.php index 2e80436f78..5cbb63c4fc 100644 --- a/phpBB/phpbb/auth/provider/apache.php +++ b/phpBB/phpbb/auth/provider/apache.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\auth\provider; +  /**  * @ignore  */ @@ -20,19 +22,19 @@ if (!defined('IN_PHPBB'))   *   * @package auth   */ -class phpbb_auth_provider_apache extends phpbb_auth_provider_base +class apache extends \phpbb\auth\provider\base  {  	/**  	 * Apache Authentication Constructor  	 * -	 * @param 	phpbb_db_driver 	$db -	 * @param 	phpbb_config 		$config -	 * @param 	phpbb_request 		$request -	 * @param 	phpbb_user 			$user +	 * @param 	\phpbb\db\driver\driver 	$db +	 * @param 	\phpbb\config\config 		$config +	 * @param 	\phpbb\request\request 		$request +	 * @param 	\phpbb\user 			$user  	 * @param 	string 				$phpbb_root_path  	 * @param 	string 				$php_ext  	 */ -	public function __construct(phpbb_db_driver $db, phpbb_config $config, phpbb_request $request, phpbb_user $user, $phpbb_root_path, $php_ext) +	public function __construct(\phpbb\db\driver\driver $db, \phpbb\config\config $config, \phpbb\request\request $request, \phpbb\user $user, $phpbb_root_path, $php_ext)  	{  		$this->db = $db;  		$this->config = $config; @@ -47,7 +49,7 @@ class phpbb_auth_provider_apache extends phpbb_auth_provider_base  	 */  	public function init()  	{ -		if (!$this->request->is_set('PHP_AUTH_USER', phpbb_request_interface::SERVER) || $this->user->data['username'] !== htmlspecialchars_decode($this->request->server('PHP_AUTH_USER'))) +		if (!$this->request->is_set('PHP_AUTH_USER', \phpbb\request\request_interface::SERVER) || $this->user->data['username'] !== htmlspecialchars_decode($this->request->server('PHP_AUTH_USER')))  		{  			return $this->user->lang['APACHE_SETUP_BEFORE_USE'];  		} @@ -78,7 +80,7 @@ class phpbb_auth_provider_apache extends phpbb_auth_provider_base  			);  		} -		if (!$this->request->is_set('PHP_AUTH_USER', phpbb_request_interface::SERVER)) +		if (!$this->request->is_set('PHP_AUTH_USER', \phpbb\request\request_interface::SERVER))  		{  			return array(  				'status'		=> LOGIN_ERROR_EXTERNAL_AUTH, @@ -149,7 +151,7 @@ class phpbb_auth_provider_apache extends phpbb_auth_provider_base  	 */  	public function autologin()  	{ -		if (!$this->request->is_set('PHP_AUTH_USER', phpbb_request_interface::SERVER)) +		if (!$this->request->is_set('PHP_AUTH_USER', \phpbb\request\request_interface::SERVER))  		{  			return array();  		} @@ -241,7 +243,7 @@ class phpbb_auth_provider_apache extends phpbb_auth_provider_base  	public function validate_session($user)  	{  		// Check if PHP_AUTH_USER is set and handle this case -		if ($this->request->is_set('PHP_AUTH_USER', phpbb_request_interface::SERVER)) +		if ($this->request->is_set('PHP_AUTH_USER', \phpbb\request\request_interface::SERVER))  		{  			$php_auth_user = $this->request->server('PHP_AUTH_USER'); diff --git a/phpBB/phpbb/auth/provider/base.php b/phpBB/phpbb/auth/provider/base.php index 7eaf8bb2d3..2222d8c1b6 100644 --- a/phpBB/phpbb/auth/provider/base.php +++ b/phpBB/phpbb/auth/provider/base.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\auth\provider; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  *  * @package auth  */ -abstract class phpbb_auth_provider_base implements phpbb_auth_provider_interface +abstract class base implements \phpbb\auth\provider\provider_interface  {  	/**  	* {@inheritdoc} @@ -57,6 +59,22 @@ abstract class phpbb_auth_provider_base implements phpbb_auth_provider_interface  	/**  	* {@inheritdoc}  	*/ +	public function get_login_data() +	{ +		return; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_auth_link_data() +	{ +		return; +	} + +	/** +	* {@inheritdoc} +	*/  	public function logout($data, $new_session)  	{  		return; @@ -69,4 +87,28 @@ abstract class phpbb_auth_provider_base implements phpbb_auth_provider_interface  	{  		return;  	} + +	/** +	* {@inheritdoc} +	*/ +	public function login_link_has_necessary_data($login_link_data) +	{ +		return; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function link_account(array $link_data) +	{ +		return; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function unlink_account(array $link_data) +	{ +		return; +	}  } diff --git a/phpBB/phpbb/auth/provider/db.php b/phpBB/phpbb/auth/provider/db.php index 0934c56d9b..4654e49fb5 100644 --- a/phpBB/phpbb/auth/provider/db.php +++ b/phpBB/phpbb/auth/provider/db.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\auth\provider; +  /**  * @ignore  */ @@ -22,20 +24,20 @@ if (!defined('IN_PHPBB'))   *   * @package auth   */ -class phpbb_auth_provider_db extends phpbb_auth_provider_base +class db extends \phpbb\auth\provider\base  {  	/**  	 * Database Authentication Constructor  	 * -	 * @param	phpbb_db_driver	$db -	 * @param	phpbb_config 	$config -	 * @param	phpbb_request	$request -	 * @param	phpbb_user		$user +	 * @param	\phpbb\db\driver\driver	$db +	 * @param	\phpbb\config\config 	$config +	 * @param	\phpbb\request\request	$request +	 * @param	\phpbb\user		$user  	 * @param	string			$phpbb_root_path  	 * @param	string			$php_ext  	 */ -	public function __construct(phpbb_db_driver $db, phpbb_config $config, phpbb_request $request, phpbb_user $user, $phpbb_root_path, $php_ext) +	public function __construct(\phpbb\db\driver\driver $db, \phpbb\config\config $config, \phpbb\request\request $request, \phpbb\user $user, $phpbb_root_path, $php_ext)  	{  		$this->db = $db;  		$this->config = $config; @@ -149,7 +151,7 @@ class phpbb_auth_provider_db extends phpbb_auth_provider_base  				include ($this->phpbb_root_path . 'includes/captcha/captcha_factory.' . $this->php_ext);  			} -			$captcha = phpbb_captcha_factory::get_instance($this->config['captcha_plugin']); +			$captcha = \phpbb_captcha_factory::get_instance($this->config['captcha_plugin']);  			$captcha->init(CONFIRM_LOGIN);  			$vc_response = $captcha->validate($row);  			if ($vc_response) diff --git a/phpBB/phpbb/auth/provider/interface.php b/phpBB/phpbb/auth/provider/interface.php deleted file mode 100644 index 47043bc107..0000000000 --- a/phpBB/phpbb/auth/provider/interface.php +++ /dev/null @@ -1,105 +0,0 @@ -<?php -/** -* -* @package auth -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ - -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ -	exit; -} - -/** - * The interface authentication provider classes have to implement. - * - * @package auth - */ -interface phpbb_auth_provider_interface -{ -	/** -	 * Checks whether the user is currently identified to the authentication -	 * provider. -	 * Called in acp_board while setting authentication plugins. -	 * Changing to an authentication provider will not be permitted in acp_board -	 * if there is an error. -	 * -	 * @return 	boolean|string 	False if the user is identified, otherwise an -	 *							error message, or null if not implemented. -	 */ -	public function init(); - -	/** -	 * Performs login. -	 * -	 * @param	string	$username 	The name of the user being authenticated. -	 * @param	string	$password	The password of the user. -	 * @return	array	An associative array of the format: -	 *						array( -	 *							'status' => status constant -	 *							'error_msg' => string -	 *							'user_row' => array -	 *						) -	 */ -	public function login($username, $password); - -	/** -	 * Autologin function -	 * -	 * @return 	array|null	containing the user row, empty if no auto login -	 * 						should take place, or null if not impletmented. -	 */ -	public function autologin(); - -	/** -	 * This function is used to output any required fields in the authentication -	 * admin panel. It also defines any required configuration table fields. -	 * -	 * @return	array|null	Returns null if not implemented or an array of the -	 *						configuration fields of the provider. -	 */ -	public function acp(); - -	/** -	 * This function updates the template with variables related to the acp -	 * options with whatever configuraton values are passed to it as an array. -	 * It then returns the name of the acp file related to this authentication -	 * provider. -	 * @param	array	$new_config Contains the new configuration values that -	 *								have been set in acp_board. -	 * @return	array|null		Returns null if not implemented or an array with -	 *							the template file name and an array of the vars -	 *							that the template needs that must conform to the -	 *							following example: -	 *							array( -	 *								'TEMPLATE_FILE'	=> string, -	 *								'TEMPLATE_VARS'	=> array(...), -	 *							) -	 */ -	public function get_acp_template($new_config); - -	/** -	 * Performs additional actions during logout. -	 * -	 * @param 	array	$data			An array corresponding to -	 *									phpbb_session::data -	 * @param 	boolean	$new_session	True for a new session, false for no new -	 *									session. -	 */ -	public function logout($data, $new_session); - -	/** -	 * The session validation function checks whether the user is still logged -	 * into phpBB. -	 * -	 * @param 	array 	$user -	 * @return 	boolean	true if the given user is authenticated, false if the  -	 * 					session should be closed, or null if not implemented. -	 */ -	public function validate_session($user); -} diff --git a/phpBB/phpbb/auth/provider/ldap.php b/phpBB/phpbb/auth/provider/ldap.php index 0196529408..9d29789567 100644 --- a/phpBB/phpbb/auth/provider/ldap.php +++ b/phpBB/phpbb/auth/provider/ldap.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\auth\provider; +  /**  * @ignore  */ @@ -22,16 +24,16 @@ if (!defined('IN_PHPBB'))   *   * @package auth   */ -class phpbb_auth_provider_ldap extends phpbb_auth_provider_base +class ldap extends \phpbb\auth\provider\base  {  	/**  	 * LDAP Authentication Constructor  	 * -	 * @param 	phpbb_db_driver	$db -	 * @param 	phpbb_config	$config -	 * @param 	phpbb_user		$user +	 * @param 	\phpbb\db\driver\driver	$db +	 * @param 	\phpbb\config\config	$config +	 * @param 	\phpbb\user		$user  	 */ -	public function __construct(phpbb_db_driver $db, phpbb_config $config, phpbb_user $user) +	public function __construct(\phpbb\db\driver\driver $db, \phpbb\config\config $config, \phpbb\user $user)  	{  		$this->db = $db;  		$this->config = $config; diff --git a/phpBB/phpbb/auth/provider/oauth/oauth.php b/phpBB/phpbb/auth/provider/oauth/oauth.php new file mode 100644 index 0000000000..de81ac0d04 --- /dev/null +++ b/phpBB/phpbb/auth/provider/oauth/oauth.php @@ -0,0 +1,620 @@ +<?php +/** +* +* @package auth +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\auth\provider\oauth; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +use OAuth\Common\Consumer\Credentials; +use OAuth\Common\Http\Uri\Uri; + +/** +* OAuth authentication provider for phpBB3 +* +* @package auth +*/ +class oauth extends \phpbb\auth\provider\base +{ +	/** +	* Database driver +	* +	* @var \phpbb\db\driver\driver +	*/ +	protected $db; + +	/** +	* phpBB config +	* +	* @var \phpbb\config\config +	*/ +	protected $config; + +	/** +	* phpBB request object +	* +	* @var \phpbb\request\request_interface +	*/ +	protected $request; + +	/** +	* phpBB user +	* +	* @var \phpbb\user +	*/ +	protected $user; + +	/** +	* OAuth token table +	* +	* @var string +	*/ +	protected $auth_provider_oauth_token_storage_table; + +	/** +	* OAuth account association table +	* +	* @var string +	*/ +	protected $auth_provider_oauth_token_account_assoc; + +	/** +	* All OAuth service providers +	* +	* @var \phpbb\di\service_collection Contains \phpbb\auth\provider\oauth\service_interface +	*/ +	protected $service_providers; + +	/** +	* Users table +	* +	* @var string +	*/ +	protected $users_table; + +	/** +	* Cached current uri object +	* +	* @var \OAuth\Common\Http\Uri\UriInterface|null +	*/ +	protected $current_uri; + +	/** +	* phpBB root path +	* +	* @var string +	*/ +	protected $phpbb_root_path; + +	/** +	* PHP extenstion +	* +	* @var string +	*/ +	protected $php_ext; + +	/** +	* OAuth Authentication Constructor +	* +	* @param	\phpbb\db\driver\driver	$db +	* @param	\phpbb\config\config	$config +	* @param	\phpbb\request\request_interface	$request +	* @param	\phpbb\user		$user +	* @param	string			$auth_provider_oauth_token_storage_table +	* @param	string			$auth_provider_oauth_token_account_assoc +	* @param	\phpbb\di\service_collection	$service_providers Contains \phpbb\auth\provider\oauth\service_interface +	* @param	string			$users_table +	* @param	string			$phpbb_root_path +	* @param	string			$php_ext +	*/ +	public function __construct(\phpbb\db\driver\driver $db, \phpbb\config\config $config, \phpbb\request\request_interface $request, \phpbb\user $user, $auth_provider_oauth_token_storage_table, $auth_provider_oauth_token_account_assoc, \phpbb\di\service_collection $service_providers, $users_table, $phpbb_root_path, $php_ext) +	{ +		$this->db = $db; +		$this->config = $config; +		$this->request = $request; +		$this->user = $user; +		$this->auth_provider_oauth_token_storage_table = $auth_provider_oauth_token_storage_table; +		$this->auth_provider_oauth_token_account_assoc = $auth_provider_oauth_token_account_assoc; +		$this->service_providers = $service_providers; +		$this->users_table = $users_table; +		$this->phpbb_root_path = $phpbb_root_path; +		$this->php_ext = $php_ext; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function init() +	{ +		// This does not test whether or not the key and secret provided are valid. +		foreach ($this->service_providers as $service_provider) +		{ +			$credentials = $service_provider->get_service_credentials(); + +			if (($credentials['key'] && !$credentials['secret']) || (!$credentials['key'] && $credentials['secret'])) +			{ +				return $this->user->lang['AUTH_PROVIDER_OAUTH_ERROR_ELEMENT_MISSING']; +			} +		} +		return false; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function login($username, $password) +	{ +		// Temporary workaround for only having one authentication provider available +		if (!$this->request->is_set('oauth_service')) +		{ +			$provider = new \phpbb\auth\provider\db($this->db, $this->config, $this->request, $this->user, $this->phpbb_root_path, $this->php_ext); +			return $provider->login($username, $password); +		} + +		// Requst the name of the OAuth service +		$service_name_original = $this->request->variable('oauth_service', '', false); +		$service_name = 'auth.provider.oauth.service.' . strtolower($service_name_original); +		if ($service_name_original === '' || !array_key_exists($service_name, $this->service_providers)) +		{ +			return array( +				'status'		=> LOGIN_ERROR_EXTERNAL_AUTH, +				'error_msg'		=> 'LOGIN_ERROR_OAUTH_SERVICE_DOES_NOT_EXIST', +				'user_row'		=> array('user_id' => ANONYMOUS), +			); +		} + +		// Get the service credentials for the given service +		$service_credentials = $this->service_providers[$service_name]->get_service_credentials(); + +		$storage = new \phpbb\auth\provider\oauth\token_storage($this->db, $this->user, $this->auth_provider_oauth_token_storage_table); +		$query = 'mode=login&login=external&oauth_service=' . $service_name_original; +		$service = $this->get_service($service_name_original, $storage, $service_credentials, $this->service_providers[$service_name]->get_auth_scope(), $query); + +		if ($this->request->is_set('code', \phpbb\request\request_interface::GET)) +		{ +			$this->service_providers[$service_name]->set_external_service_provider($service); +			$unique_id = $this->service_providers[$service_name]->perform_auth_login(); + +			// Check to see if this provider is already assosciated with an account +			$data = array( +				'provider'	=> $service_name_original, +				'oauth_provider_id'	=> $unique_id +			); +			$sql = 'SELECT user_id FROM ' . $this->auth_provider_oauth_token_account_assoc . ' +				WHERE ' . $this->db->sql_build_array('SELECT', $data); +			$result = $this->db->sql_query($sql); +			$row = $this->db->sql_fetchrow($result); +			$this->db->sql_freeresult($result); + +			if (!$row) +			{ +				// The user does not yet exist, ask to link or create profile +				return array( +					'status'		=> LOGIN_SUCCESS_LINK_PROFILE, +					'error_msg'		=> 'LOGIN_OAUTH_ACCOUNT_NOT_LINKED', +					'user_row'		=> array(), +					'redirect_data'	=> array( +						'auth_provider'				=> 'oauth', +						'login_link_oauth_service'	=> $service_name_original, +					), +				); +			} + +			// Retrieve the user's account +			$sql = 'SELECT user_id, username, user_password, user_passchg, user_pass_convert, user_email, user_type, user_login_attempts +				FROM ' . $this->users_table . ' +					WHERE user_id = ' . (int) $row['user_id']; +			$result = $this->db->sql_query($sql); +			$row = $this->db->sql_fetchrow($result); +			$this->db->sql_freeresult($result); + +			if (!$row) +			{ +				throw new Exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_ENTRY'); +			} + +			// Update token storage to store the user_id +			$storage->set_user_id($row['user_id']); + +			// The user is now authenticated and can be logged in +			return array( +				'status'		=> LOGIN_SUCCESS, +				'error_msg'		=> false, +				'user_row'		=> $row, +			); +		} +		else +		{ +			$url = $service->getAuthorizationUri(); +			header('Location: ' . $url); +		} +	} + +	/** +	* Returns the cached current_uri object or creates and caches it if it is +	* not already created. In each case the query string is updated based on +	* the $query parameter. +	* +	* @param	string	$service_name	The name of the service +	* @param	string	$query			The query string of the current_uri +	*									used in redirects +	* @return	\OAuth\Common\Http\Uri\UriInterface +	*/ +	protected function get_current_uri($service_name, $query) +	{ +		if ($this->current_uri) +		{ +			$this->current_uri->setQuery($query); +			return $this->current_uri; +		} + +		$uri_factory = new \OAuth\Common\Http\Uri\UriFactory(); +		$current_uri = $uri_factory->createFromSuperGlobalArray($this->request->get_super_global(\phpbb\request\request_interface::SERVER)); +		$current_uri->setQuery($query); + +		$this->current_uri = $current_uri; +		return $current_uri; +	} + +	/** +	* Returns a new service object +	* +	* @param	string	$service_name			The name of the service +	* @param	\phpbb\auth\provider\oauth\token_storage $storage +	* @param	array	$service_credentials	{@see \phpbb\auth\provider\oauth\oauth::get_service_credentials} +	* @param	array	$scope					The scope of the request against +	*											the api. +	* @param	string	$query					The query string of the +	*											current_uri used in redirection +	* @return	\OAuth\Common\Service\ServiceInterface +	*/ +	protected function get_service($service_name, \phpbb\auth\provider\oauth\token_storage $storage, array $service_credentials, array $scopes = array(), $query) +	{ +		$current_uri = $this->get_current_uri($service_name, $query); + +		// Setup the credentials for the requests +		$credentials = new Credentials( +			$service_credentials['key'], +			$service_credentials['secret'], +			$current_uri->getAbsoluteUri() +		); + +		$service_factory = new \OAuth\ServiceFactory(); +		$service = $service_factory->createService($service_name, $credentials, $storage, $scopes); + +		if (!$service) +		{ +			throw new Exception('AUTH_PROVIDER_OAUTH_ERROR_SERVICE_NOT_CREATED'); +		} + +		return $service; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_login_data() +	{ +		$login_data = array( +			'TEMPLATE_FILE'		=> 'login_body_oauth.html', +			'BLOCK_VAR_NAME'	=> 'oauth', +			'BLOCK_VARS'		=> array(), +		); + +		foreach ($this->service_providers as $service_name => $service_provider) +		{ +			// Only include data if the credentials are set +			$credentials = $service_provider->get_service_credentials(); +			if ($credentials['key'] && $credentials['secret']) +			{ +				$actual_name = str_replace('auth.provider.oauth.service.', '', $service_name); +				$redirect_url = build_url(false) . '&login=external&oauth_service=' . $actual_name; +				$login_data['BLOCK_VARS'][$service_name] = array( +					'REDIRECT_URL'	=> redirect($redirect_url, true), +					'SERVICE_NAME'	=> $this->user->lang['AUTH_PROVIDER_OAUTH_SERVICE_' . strtoupper($actual_name)], +				); +			} +		} + +		return $login_data; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function acp() +	{ +		$ret = array(); + +		foreach ($this->service_providers as $service_name => $service_provider) +		{ +			$actual_name = str_replace('auth.provider.oauth.service.', '', $service_name); +			$ret[] = 'auth_oauth_' . $actual_name . '_key'; +			$ret[] = 'auth_oauth_' . $actual_name . '_secret'; +		} + +		return $ret; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_acp_template($new_config) +	{ +		$ret = array( +			'BLOCK_VAR_NAME'	=> 'oauth_services', +			'BLOCK_VARS'		=> array(), +			'TEMPLATE_FILE'		=> 'auth_provider_oauth.html', +			'TEMPLATE_VARS'		=> array(), +		); + +		foreach ($this->service_providers as $service_name => $service_provider) +		{ +			$actual_name = str_replace('auth.provider.oauth.service.', '', $service_name); +			$ret['BLOCK_VARS'][$actual_name] = array( +				'ACTUAL_NAME'	=> $this->user->lang['AUTH_PROVIDER_OAUTH_SERVICE_' . strtoupper($actual_name)], +				'KEY'			=> $new_config['auth_oauth_' . $actual_name . '_key'], +				'NAME'			=> $actual_name, +				'SECRET'		=> $new_config['auth_oauth_' . $actual_name . '_secret'], +			); +		} + +		return $ret; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function login_link_has_necessary_data($login_link_data) +	{ +		if (empty($login_link_data)) +		{ +			return 'LOGIN_LINK_NO_DATA_PROVIDED'; +		} + +		if (!array_key_exists('oauth_service', $login_link_data) || !$login_link_data['oauth_service'] || +			!array_key_exists('link_method', $login_link_data) || !$login_link_data['link_method']) +		{ +			return 'LOGIN_LINK_MISSING_DATA'; +		} + +		return null; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function link_account(array $link_data) +	{ +		// Check for a valid link method (auth_link or login_link) +		if (!array_key_exists('link_method', $link_data) || +			!in_array($link_data['link_method'], array( +				'auth_link', +				'login_link', +			))) +		{ +			return 'LOGIN_LINK_MISSING_DATA'; +		} + +		// We must have an oauth_service listed, check for it two ways +		if (!array_key_exists('oauth_service', $link_data) || !$link_data['oauth_service']) +		{ +			$link_data['oauth_service'] = $this->request->variable('oauth_service', ''); + +			if (!$link_data['oauth_service']) +			{ +				return 'LOGIN_LINK_MISSING_DATA'; +			} +		} + +		$service_name = 'auth.provider.oauth.service.' . strtolower($link_data['oauth_service']); +		if (!array_key_exists($service_name, $this->service_providers)) +		{ +			return 'LOGIN_ERROR_OAUTH_SERVICE_DOES_NOT_EXIST'; +		} + +		switch ($link_data['link_method']) +		{ +			case 'auth_link': +				return $this->link_account_auth_link($link_data, $service_name); +			case 'login_link': +				return $this->link_account_login_link($link_data, $service_name); +		} +	} + +	/** +	* Performs the account linking for login_link +	* +	* @param	array	$link_data		The same variable given to {@see \phpbb\auth\provider\provider_interface::link_account} +	* @param	string	$service_name	The name of the service being used in +	*									linking. +	* @return	string|null	Returns a language constant (string) if an error is +	*						encountered, or null on success. +	*/ +	protected function link_account_login_link(array $link_data, $service_name) +	{ +		$storage = new \phpbb\auth\provider\oauth\token_storage($this->db, $this->user, $this->auth_provider_oauth_token_storage_table); + +		// Check for an access token, they should have one +		if (!$storage->has_access_token_by_session($service_name)) +		{ +			return 'LOGIN_LINK_ERROR_OAUTH_NO_ACCESS_TOKEN'; +		} + +		// Prepare the query string +		$query = 'mode=login_link&login_link_oauth_service=' . strtolower($link_data['oauth_service']); + +		// Prepare for an authentication request +		$service_credentials = $this->service_providers[$service_name]->get_service_credentials(); +		$scopes = $this->service_providers[$service_name]->get_auth_scope(); +		$service = $this->get_service(strtolower($link_data['oauth_service']), $storage, $service_credentials, $scopes, $query); +		$this->service_providers[$service_name]->set_external_service_provider($service); + +		// The user has already authenticated successfully, request to authenticate again +		$unique_id = $this->service_providers[$service_name]->perform_token_auth(); + +		// Insert into table, they will be able to log in after this +		$data = array( +			'user_id'			=> $link_data['user_id'], +			'provider'			=> strtolower($link_data['oauth_service']), +			'oauth_provider_id'	=> $unique_id, +		); + +		$this->link_account_perform_link($data); +		// Update token storage to store the user_id +		$storage->set_user_id($link_data['user_id']); +	} + +	/** +	* Performs the account linking for auth_link +	* +	* @param	array	$link_data		The same variable given to {@see \phpbb\auth\provider\provider_interface::link_account} +	* @param	string	$service_name	The name of the service being used in +	*									linking. +	* @return	string|null	Returns a language constant (string) if an error is +	*						encountered, or null on success. +	*/ +	protected function link_account_auth_link(array $link_data, $service_name) +	{ +		$storage = new \phpbb\auth\provider\oauth\token_storage($this->db, $this->user, $this->auth_provider_oauth_token_storage_table); +		$query = 'i=ucp_auth_link&mode=auth_link&link=1&oauth_service=' . strtolower($link_data['oauth_service']); +		$service_credentials = $this->service_providers[$service_name]->get_service_credentials(); +		$scopes = $this->service_providers[$service_name]->get_auth_scope(); +		$service = $this->get_service(strtolower($link_data['oauth_service']), $storage, $service_credentials, $scopes, $query); + +		if ($this->request->is_set('code', \phpbb\request\request_interface::GET)) +		{ +			$this->service_providers[$service_name]->set_external_service_provider($service); +			$unique_id = $this->service_providers[$service_name]->perform_auth_login(); + +			// Insert into table, they will be able to log in after this +			$data = array( +				'user_id'			=> $this->user->data['user_id'], +				'provider'			=> strtolower($link_data['oauth_service']), +				'oauth_provider_id'	=> $unique_id, +			); + +			$this->link_account_perform_link($data); +		} +		else +		{ +			$url = $service->getAuthorizationUri(); +			header('Location: ' . $url); +		} +	} + +	/** +	* Performs the query that inserts an account link +	* +	* @param	array	$data	This array is passed to db->sql_build_array +	*/ +	protected function link_account_perform_link(array $data) +	{ +		$sql = 'INSERT INTO ' . $this->auth_provider_oauth_token_account_assoc . ' +			' . $this->db->sql_build_array('INSERT', $data); +		$this->db->sql_query($sql); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function logout($data, $new_session) +	{ +		// Clear all tokens belonging to the user +		$storage = new \phpbb\auth\provider\oauth\token_storage($this->db, $this->user, $this->auth_provider_oauth_token_storage_table); +		$storage->clearAllTokens(); + +		return; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_auth_link_data() +	{ +		$block_vars = array(); + +		// Get all external accounts tied to the current user +		$data = array( +			'user_id' => (int) $this->user->data['user_id'], +		); +		$sql = 'SELECT oauth_provider_id, provider FROM ' . $this->auth_provider_oauth_token_account_assoc . ' +			WHERE ' . $this->db->sql_build_array('SELECT', $data); +		$result = $this->db->sql_query($sql); +		$rows = $this->db->sql_fetchrowset($result); +		$this->db->sql_freeresult($result); + +		$oauth_user_ids = array(); + +		if ($rows !== false && sizeof($rows)) +		{ +			foreach ($rows as $row) +			{ +				$oauth_user_ids[$row['provider']] = $row['oauth_provider_id']; +			} +		} +		unset($rows); + +		foreach ($this->service_providers as $service_name => $service_provider) +		{ +			// Only include data if the credentials are set +			$credentials = $service_provider->get_service_credentials(); +			if ($credentials['key'] && $credentials['secret']) +			{ +				$actual_name = str_replace('auth.provider.oauth.service.', '', $service_name); + +				$block_vars[$service_name] = array( +					'HIDDEN_FIELDS'	=> array( +						'link'			=> (!isset($oauth_user_ids[$actual_name])), +						'oauth_service' => $actual_name, +					), + +					'SERVICE_NAME'	=> $this->user->lang['AUTH_PROVIDER_OAUTH_SERVICE_' . strtoupper($actual_name)], +					'UNIQUE_ID'		=> (isset($oauth_user_ids[$actual_name])) ? $oauth_user_ids[$actual_name] : null, +				); +			} +		} + +		return array( +			'BLOCK_VAR_NAME'	=> 'oauth', +			'BLOCK_VARS'		=> $block_vars, + +			'TEMPLATE_FILE'	=> 'ucp_auth_link_oauth.html', +		); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function unlink_account(array $link_data) +	{ +		if (!array_key_exists('oauth_service', $link_data) || !$link_data['oauth_service']) +		{ +			return 'LOGIN_LINK_MISSING_DATA'; +		} + +		// Remove the link +		$sql = 'DELETE FROM ' . $this->auth_provider_oauth_token_account_assoc . " +			WHERE provider = '" . $this->db->sql_escape($link_data['oauth_service']) . "' +				AND user_id = " . (int) $this->user->data['user_id']; +		$this->db->sql_query($sql); + +		// Clear all tokens belonging to the user on this servce +		$service_name = 'auth.provider.oauth.service.' . strtolower($link_data['oauth_service']); +		$storage = new \phpbb\auth\provider\oauth\token_storage($this->db, $this->user, $this->auth_provider_oauth_token_storage_table); +		$storage->clearToken($service_name); + +		return; +	} +} diff --git a/phpBB/phpbb/auth/provider/oauth/service/base.php b/phpBB/phpbb/auth/provider/oauth/service/base.php new file mode 100644 index 0000000000..61deb48695 --- /dev/null +++ b/phpBB/phpbb/auth/provider/oauth/service/base.php @@ -0,0 +1,57 @@ +<?php +/** +* +* @package auth +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\auth\provider\oauth\service; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +/** +* Base OAuth abstract class that all OAuth services should implement +* +* @package auth +*/ +abstract class base implements \phpbb\auth\provider\oauth\service\service_interface +{ +	/** +	* External OAuth service provider +	* +	* @var \OAuth\Common\Service\ServiceInterface +	*/ +	protected $service_provider; + +	/** +	* {@inheritdoc} +	*/ +	public function get_external_service_provider() +	{ +		return $this->service_provider; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_auth_scope() +	{ +		return array(); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function set_external_service_provider(\OAuth\Common\Service\ServiceInterface $service_provider) +	{ +		$this->service_provider = $service_provider; +	} +} diff --git a/phpBB/phpbb/auth/provider/oauth/service/bitly.php b/phpBB/phpbb/auth/provider/oauth/service/bitly.php new file mode 100644 index 0000000000..47cf7ee380 --- /dev/null +++ b/phpBB/phpbb/auth/provider/oauth/service/bitly.php @@ -0,0 +1,100 @@ +<?php +/** +* +* @package auth +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\auth\provider\oauth\service; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +/** +* Bitly OAuth service +* +* @package auth +*/ +class bitly extends \phpbb\auth\provider\oauth\service\base +{ +	/** +	* phpBB config +	* +	* @var \phpbb\config\config +	*/ +	protected $config; + +	/** +	* phpBB request +	* +	* @var \phpbb\request\request_interface +	*/ +	protected $request; + +	/** +	* Constructor +	* +	* @param	\phpbb\config\config				$config +	* @param	\phpbb\request\request_interface	$request +	*/ +	public function __construct(\phpbb\config\config $config, \phpbb\request\request_interface $request) +	{ +		$this->config = $config; +		$this->request = $request; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_service_credentials() +	{ +		return array( +			'key'		=> $this->config['auth_oauth_bitly_key'], +			'secret'	=> $this->config['auth_oauth_bitly_secret'], +		); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function perform_auth_login() +	{ +		if (!($this->service_provider instanceof \OAuth\OAuth2\Service\Bitly)) +		{ +			throw new \phpbb\auth\provider\oauth\service\exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE'); +		} + +		// This was a callback request from bitly, get the token +		$this->service_provider->requestAccessToken($this->request->variable('code', '')); + +		// Send a request with it +		$result = json_decode($this->service_provider->request('user/info'), true); + +		// Return the unique identifier returned from bitly +		return $result['data']['login']; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function perform_token_auth() +	{ +		if (!($this->service_provider instanceof \OAuth\OAuth2\Service\Bitly)) +		{ +			throw new \phpbb\auth\provider\oauth\service\exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE'); +		} + +		// Send a request with it +		$result = json_decode($this->service_provider->request('user/info'), true); + +		// Return the unique identifier returned from bitly +		return $result['data']['login']; +	} +} diff --git a/phpBB/phpbb/auth/provider/oauth/service/exception.php b/phpBB/phpbb/auth/provider/oauth/service/exception.php new file mode 100644 index 0000000000..23d3387951 --- /dev/null +++ b/phpBB/phpbb/auth/provider/oauth/service/exception.php @@ -0,0 +1,25 @@ +<?php +/** +* +* @package auth +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +/** +* OAuth service exception class +* +* @package auth +*/ +class phpbb_auth_provider_oauth_service_exception extends RuntimeException +{ +} diff --git a/phpBB/phpbb/auth/provider/oauth/service/facebook.php b/phpBB/phpbb/auth/provider/oauth/service/facebook.php new file mode 100644 index 0000000000..4a4eeba6d5 --- /dev/null +++ b/phpBB/phpbb/auth/provider/oauth/service/facebook.php @@ -0,0 +1,100 @@ +<?php +/** +* +* @package auth +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\auth\provider\oauth\service; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +/** +* Facebook OAuth service +* +* @package auth +*/ +class facebook extends base +{ +	/** +	* phpBB config +	* +	* @var phpbb\config\config +	*/ +	protected $config; + +	/** +	* phpBB request +	* +	* @var phpbb\request\request_interface +	*/ +	protected $request; + +	/** +	* Constructor +	* +	* @param	phpbb\config\config					$config +	* @param	phpbb\request\request_interface 	$request +	*/ +	public function __construct(\phpbb\config\config $config, \phpbb\request\request_interface $request) +	{ +		$this->config = $config; +		$this->request = $request; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_service_credentials() +	{ +		return array( +			'key'		=> $this->config['auth_oauth_facebook_key'], +			'secret'	=> $this->config['auth_oauth_facebook_secret'], +		); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function perform_auth_login() +	{ +		if (!($this->service_provider instanceof \OAuth\OAuth2\Service\Facebook)) +		{ +			throw new exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE'); +		} + +		// This was a callback request, get the token +		$this->service_provider->requestAccessToken($this->request->variable('code', '')); + +		// Send a request with it +		$result = json_decode($this->service_provider->request('/me'), true); + +		// Return the unique identifier +		return $result['id']; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function perform_token_auth() +	{ +		if (!($this->service_provider instanceof \OAuth\OAuth2\Service\Facebook)) +		{ +			throw new exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE'); +		} + +		// Send a request with it +		$result = json_decode($this->service_provider->request('/me'), true); + +		// Return the unique identifier +		return $result['id']; +	} +} diff --git a/phpBB/phpbb/auth/provider/oauth/service/google.php b/phpBB/phpbb/auth/provider/oauth/service/google.php new file mode 100644 index 0000000000..2449bbf523 --- /dev/null +++ b/phpBB/phpbb/auth/provider/oauth/service/google.php @@ -0,0 +1,111 @@ +<?php +/** +* +* @package auth +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\auth\provider\oauth\service; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +/** +* Google OAuth service +* +* @package auth +*/ +class google extends base +{ +	/** +	* phpBB config +	* +	* @var phpbb\config\config +	*/ +	protected $config; + +	/** +	* phpBB request +	* +	* @var phpbb\request\request_interface +	*/ +	protected $request; + +	/** +	* Constructor +	* +	* @param	phpbb\config\config					$config +	* @param	phpbb\request\request_interface 	$request +	*/ +	public function __construct(\phpbb\config\config $config, \phpbb\request\request_interface $request) +	{ +		$this->config = $config; +		$this->request = $request; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_auth_scope() +	{ +		return array( +			'userinfo_email', +			'userinfo_profile', +		); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_service_credentials() +	{ +		return array( +			'key'		=> $this->config['auth_oauth_google_key'], +			'secret'	=> $this->config['auth_oauth_google_secret'], +		); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function perform_auth_login() +	{ +		if (!($this->service_provider instanceof \OAuth\OAuth2\Service\Google)) +		{ +			throw new exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE'); +		} + +		// This was a callback request, get the token +		$this->service_provider->requestAccessToken($this->request->variable('code', '')); + +		// Send a request with it +		$result = json_decode($this->service_provider->request('https://www.googleapis.com/oauth2/v1/userinfo'), true); + +		// Return the unique identifier +		return $result['id']; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function perform_token_auth() +	{ +		if (!($this->service_provider instanceof \OAuth\OAuth2\Service\Google)) +		{ +			throw new exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE'); +		} + +		// Send a request with it +		$result = json_decode($this->service_provider->request('https://www.googleapis.com/oauth2/v1/userinfo'), true); + +		// Return the unique identifier +		return $result['id']; +	} +} diff --git a/phpBB/phpbb/auth/provider/oauth/service/service_interface.php b/phpBB/phpbb/auth/provider/oauth/service/service_interface.php new file mode 100644 index 0000000000..ab69fe6ef3 --- /dev/null +++ b/phpBB/phpbb/auth/provider/oauth/service/service_interface.php @@ -0,0 +1,79 @@ +<?php +/** +* +* @package auth +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\auth\provider\oauth\service; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +/** +* OAuth service interface +* +* @package auth +*/ +interface service_interface +{ +	/** +	* Returns an array of the scopes necessary for auth +	* +	* @return	array	An array of the required scopes +	*/ +	public function get_auth_scope(); + +	/** +	* Returns the external library service provider once it has been set +	* +	* @param	\OAuth\Common\Service\ServiceInterface|null +	*/ +	public function get_external_service_provider(); + +	/** +	* Returns an array containing the service credentials belonging to requested +	* service. +	* +	* @return	array	An array containing the 'key' and the 'secret' of the +	*					service in the form: +	*						array( +	*							'key'		=> string +	*							'secret'	=> string +	*						) +	*/ +	public function get_service_credentials(); + +	/** +	* Returns the results of the authentication in json format +	* +	* @throws	\phpbb\auth\provider\oauth\service\exception +	* @return	string	The unique identifier returned by the service provider +	*					that is used to authenticate the user with phpBB. +	*/ +	public function perform_auth_login(); + +	/** +	* Returns the results of the authentication in json format +	* Use this function when the user already has an access token +	* +	* @throws	\phpbb\auth\provider\oauth\service\exception +	* @return	string	The unique identifier returned by the service provider +	*					that is used to authenticate the user with phpBB. +	*/ +	public function perform_token_auth(); + +	/** +	* Sets the external library service provider +	* +	* @param	\OAuth\Common\Service\ServiceInterface	$service +	*/ +	public function set_external_service_provider(\OAuth\Common\Service\ServiceInterface $service_provider); +} diff --git a/phpBB/phpbb/auth/provider/oauth/token_storage.php b/phpBB/phpbb/auth/provider/oauth/token_storage.php new file mode 100644 index 0000000000..2ce0e32da3 --- /dev/null +++ b/phpBB/phpbb/auth/provider/oauth/token_storage.php @@ -0,0 +1,368 @@ +<?php +/** +* +* @package auth +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\auth\provider\oauth; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + + +use OAuth\OAuth1\Token\StdOAuth1Token; +use OAuth\Common\Token\TokenInterface; +use OAuth\Common\Storage\TokenStorageInterface; +use OAuth\Common\Storage\Exception\StorageException; +use OAuth\Common\Storage\Exception\TokenNotFoundException; + +/** +* OAuth storage wrapper for phpbb's cache +* +* @package auth +*/ +class token_storage implements TokenStorageInterface +{ +	/** +	* Cache driver. +	* +	* @var \phpbb\db\driver\driver +	*/ +	protected $db; + +	/** +	* phpBB user +	* +	* @var \phpbb\user +	*/ +	protected $user; + +	/** +	* OAuth token table +	* +	* @var string +	*/ +	protected $auth_provider_oauth_table; + +	/** +	* @var object|TokenInterface +	*/ +	protected $cachedToken; + +	/** +	* Creates token storage for phpBB. +	* +	* @param	\phpbb\db\driver\driver	$db +	* @param	\phpbb\user		$user +	* @param	string			$auth_provider_oauth_table +	*/ +	public function __construct(\phpbb\db\driver\driver $db, \phpbb\user $user, $auth_provider_oauth_table) +	{ +		$this->db = $db; +		$this->user = $user; +		$this->auth_provider_oauth_table = $auth_provider_oauth_table; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function retrieveAccessToken($service) +	{ +		$service = $this->get_service_name_for_db($service); + +		if ($this->cachedToken instanceOf TokenInterface) +		{ +			return $this->cachedToken; +		} + +		$data = array( +			'user_id'	=> (int) $this->user->data['user_id'], +			'provider'	=> $service, +		); + +		if ((int) $this->user->data['user_id'] === ANONYMOUS) +		{ +			$data['session_id']	= $this->user->data['session_id']; +		} + +		return $this->_retrieve_access_token($data); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function storeAccessToken($service, TokenInterface $token) +	{ +		$service = $this->get_service_name_for_db($service); + +		$this->cachedToken = $token; + +		$data = array( +			'user_id'		=> (int) $this->user->data['user_id'], +			'provider'		=> $service, +			'oauth_token'	=> $this->json_encode_token($token), +			'session_id'	=> $this->user->data['session_id'], +		); + +		$sql = 'INSERT INTO ' . $this->auth_provider_oauth_table . ' +			' . $this->db->sql_build_array('INSERT', $data); +		$this->db->sql_query($sql); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function hasAccessToken($service) +	{ +		$service = $this->get_service_name_for_db($service); + +		if ($this->cachedToken) { +			return true; +		} + +		$data = array( +			'user_id'	=> (int) $this->user->data['user_id'], +			'provider'	=> $service, +		); + +		if ((int) $this->user->data['user_id'] === ANONYMOUS) +		{ +			$data['session_id']	= $this->user->data['session_id']; +		} + +		return $this->_has_acess_token($data); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function clearToken($service) +	{ +		$service = $this->get_service_name_for_db($service); + +		$this->cachedToken = null; + +		$sql = 'DELETE FROM ' . $this->auth_provider_oauth_table . ' +			WHERE user_id = ' . (int) $this->user->data['user_id'] . " +				AND provider = '" . $this->db->sql_escape($service) . "'"; + +		if ((int) $this->user->data['user_id'] === ANONYMOUS) +		{ +			$sql .= " AND session_id = '" . $this->db->sql_escape($this->user->data['session_id']) . "'"; +		} + +		$this->db->sql_query($sql); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function clearAllTokens() +	{ +		$this->cachedToken = null; + +		$sql = 'DELETE FROM ' . $this->auth_provider_oauth_table . ' +			WHERE user_id = ' . (int) $this->user->data['user_id']; + +		if ((int) $this->user->data['user_id'] === ANONYMOUS) +		{ +			$sql .= " AND session_id = '" . $this->db->sql_escape($this->user->data['session_id']) . "'"; +		} + +		$this->db->sql_query($sql); +	} + +	/** +	* Updates the user_id field in the database assosciated with the token +	* +	* @param	int	$user_id +	*/ +	public function set_user_id($user_id) +	{ +		if (!$this->cachedToken) +		{ +			return; +		} + +		$sql = 'UPDATE ' . $this->auth_provider_oauth_table . ' +			SET ' . $this->db->sql_build_array('UPDATE', array( +					'user_id' => (int) $user_id +				)) . ' +				WHERE user_id = ' . (int) $this->user->data['user_id'] . " +					AND session_id = '" . $this->db->sql_escape($this->user->data['session_id']) . "'"; +		$this->db->sql_query($sql); +	} + +	/** +	* Checks to see if an access token exists solely by the session_id of the user +	* +	* @return	bool	true if they have token, false if they don't +	*/ +	public function has_access_token_by_session($service) +	{ +		$service = $this->get_service_name_for_db($service); + +		if ($this->cachedToken) +		{ +			return true; +		} + +		$data = array( +			'session_id'	=> $this->user->data['session_id'], +			'provider'		=> $service, +		); + +		return $this->_has_acess_token($data); +	} + +	/** +	* A helper function that performs the query for has access token functions +	* +	* @param	array	$data +	* @return	bool +	*/ +	protected function _has_acess_token($data) +	{ +		return (bool) $this->get_access_token_row($data); +	} + +	public function retrieve_access_token_by_session($service) +	{ +		$service = $this->get_service_name_for_db($service); + +		if ($this->cachedToken instanceOf TokenInterface) { +			return $this->cachedToken; +		} + +		$data = array( +			'session_id'	=> $this->user->data['session_id'], +			'provider'	=> $service, +		); + +		return $this->_retrieve_access_token($data); +	} + +	/** +	* A helper function that performs the query for retrieve access token functions +	* Also checks if the token is a valid token +	* +	* @param	array	$data +	* @return	mixed +	*/ +	protected function _retrieve_access_token($data) +	{ +		$row = $this->get_access_token_row($data); + +		if (!$row) +		{ +			throw new TokenNotFoundException('AUTH_PROVIDER_OAUTH_TOKEN_ERROR_NOT_STORED'); +		} + +		$token = $this->json_decode_token($row['oauth_token']); + +		// Ensure that the token was serialized/unserialized correctly +		if (!($token instanceof TokenInterface)) +		{ +			$this->clearToken(); +			throw new TokenNotFoundException('AUTH_PROVIDER_OAUTH_TOKEN_ERROR_INCORRECTLY_STORED'); +		} + +		$this->cachedToken = $token; +		return $token; +	} + +	/** +	* A helper function that performs the query for retrieving an access token +	* +	* @param	array	$data +	* @return	mixed +	*/ +	protected function get_access_token_row($data) +	{ +		$sql = 'SELECT oauth_token FROM ' . $this->auth_provider_oauth_table . ' +			WHERE ' . $this->db->sql_build_array('SELECT', $data); +		$result = $this->db->sql_query($sql); +		$row = $this->db->sql_fetchrow($result); +		$this->db->sql_freeresult($result); + +		return $row; +	} + +	public function json_encode_token(TokenInterface $token) +	{ +		$members = array( +			'accessToken'	=> $token->getAccessToken(), +			'endOfLife'		=> $token->getEndOfLife(), +			'extraParams'	=> $token->getExtraParams(), +			'refreshToken'	=> $token->getRefreshToken(), + +			'token_class'	=> get_class($token), +		); + +		// Handle additional data needed for OAuth1 tokens +		if ($token instanceof StdOAuth1Token) +		{ +			$members['requestToken']		= $token->getRequestToken(); +			$members['requestTokenSecret']	= $token->getRequestTokenSecret(); +			$members['accessTokenSecret']	= $token->getAccessTokenSecret(); +		} + +		return json_encode($members); +	} + +	public function json_decode_token($json) +	{ +		$token_data = json_decode($json, true); + +		if ($token_data === null) +		{ +			throw new TokenNotFoundException('AUTH_PROVIDER_OAUTH_TOKEN_ERROR_INCORRECTLY_STORED'); +		} + +		$token_class	= $token_data['token_class']; +		$access_token	= $token_data['accessToken']; +		$refresh_token	= $token_data['refreshToken']; +		$endOfLife		= $token_data['endOfLife']; +		$extra_params	= $token_data['extraParams']; + +		// Create the token +		$token = new $token_class($access_token, $refresh_token, TokenInterface::EOL_NEVER_EXPIRES, $extra_params); +		$token->setEndOfLife($endOfLife); + +		// Handle OAuth 1.0 specific elements +		if ($token instanceof StdOAuth1Token) +		{ +			$token->setRequestToken($token_data['requestToken']); +			$token->setRequestTokenSecret($token_data['requestTokenSecret']); +			$token->setAccessTokenSecret($token_data['accessTokenSecret']); +		} + +		return $token; +	} + +	/** +	* Returns the name of the service as it must be stored in the database. +	* +	* @param	string	$service	The name of the OAuth service +	* @return	string	The name of the OAuth service as it needs to be stored +	*					in the database. +	*/ +	protected function get_service_name_for_db($service) +	{ +		// Enforce the naming convention for oauth services +		if (strpos($service, 'auth.provider.oauth.service.') !== 0) +		{ +			$service = 'auth.provider.oauth.service.' . strtolower($service); +		} + +		return $service; +	} +} diff --git a/phpBB/phpbb/auth/provider/provider_interface.php b/phpBB/phpbb/auth/provider/provider_interface.php new file mode 100644 index 0000000000..1bb209c821 --- /dev/null +++ b/phpBB/phpbb/auth/provider/provider_interface.php @@ -0,0 +1,199 @@ +<?php +/** +* +* @package auth +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\auth\provider; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +/** + * The interface authentication provider classes have to implement. + * + * @package auth + */ +interface provider_interface +{ +	/** +	 * Checks whether the user is currently identified to the authentication +	 * provider. +	 * Called in acp_board while setting authentication plugins. +	 * Changing to an authentication provider will not be permitted in acp_board +	 * if there is an error. +	 * +	 * @return 	boolean|string 	False if the user is identified, otherwise an +	 *							error message, or null if not implemented. +	 */ +	public function init(); + +	/** +	 * Performs login. +	 * +	 * @param	string	$username 	The name of the user being authenticated. +	 * @param	string	$password	The password of the user. +	 * @return	array	An associative array of the format: +	 *						array( +	 *							'status' => status constant +	 *							'error_msg' => string +	 *							'user_row' => array +	 *						) +	 *					A fourth key of the array may be present: +	 *					'redirect_data'	This key is only used when 'status' is +	 *					equal to LOGIN_SUCCESS_LINK_PROFILE and its value is an +	 *					associative array that is turned into GET variables on +	 *					the redirect url. +	 */ +	public function login($username, $password); + +	/** +	 * Autologin function +	 * +	 * @return 	array|null	containing the user row, empty if no auto login +	 * 						should take place, or null if not impletmented. +	 */ +	public function autologin(); + +	/** +	 * This function is used to output any required fields in the authentication +	 * admin panel. It also defines any required configuration table fields. +	 * +	 * @return	array|null	Returns null if not implemented or an array of the +	 *						configuration fields of the provider. +	 */ +	public function acp(); + +	/** +	 * This function updates the template with variables related to the acp +	 * options with whatever configuraton values are passed to it as an array. +	 * It then returns the name of the acp file related to this authentication +	 * provider. +	 * @param	array	$new_config Contains the new configuration values that +	 *								have been set in acp_board. +	 * @return	array|null		Returns null if not implemented or an array with +	 *							the template file name and an array of the vars +	 *							that the template needs that must conform to the +	 *							following example: +	 *							array( +	 *								'TEMPLATE_FILE'	=> string, +	 *								'TEMPLATE_VARS'	=> array(...), +	 *							) +	 *							An optional third element may be added to this +	 *							array: 'BLOCK_VAR_NAME'. If this is present, +	 *							then its value should be a string that is used +	 *							to designate the name of the loop used in the +	 *							ACP template file. When this is present, an +	 *							additional key named 'BLOCK_VARS' is required. +	 *							This must be an array containing at least one +	 *							array of variables that will be assigned during +	 *							the loop in the template. An example of this is +	 *							presented below: +	 *							array( +	 *								'BLOCK_VAR_NAME'	=> string, +	 *								'BLOCK_VARS'		=> array( +	 *									'KEY IS UNIMPORTANT' => array(...), +	 *								), +	 *								'TEMPLATE_FILE'	=> string, +	 *								'TEMPLATE_VARS'	=> array(...), +	 *							) +	 */ +	public function get_acp_template($new_config); + +	/** +	* Returns an array of data necessary to build custom elements on the login +	* form. +	* +	* @return	array|null	If this function is not implemented on an auth +	*						provider then it returns null. If it is implemented +	*						it will return an array of up to four elements of +	*						which only 'TEMPLATE_FILE'. If 'BLOCK_VAR_NAME' is +	*						present then 'BLOCK_VARS' must also be present in +	*						the array. The fourth element 'VARS' is also +	*						optional. The array, with all four elements present +	*						looks like the following: +	*						array( +	*							'TEMPLATE_FILE'		=> string, +	*							'BLOCK_VAR_NAME'	=> string, +	*							'BLOCK_VARS'		=> array(...), +	*							'VARS'				=> array(...), +	*						) +	*/ +	public function get_login_data(); + +	/** +	 * Performs additional actions during logout. +	 * +	 * @param 	array	$data			An array corresponding to +	 *									\phpbb\session::data +	 * @param 	boolean	$new_session	True for a new session, false for no new +	 *									session. +	 */ +	public function logout($data, $new_session); + +	/** +	 * The session validation function checks whether the user is still logged +	 * into phpBB. +	 * +	 * @param 	array 	$user +	 * @return 	boolean	true if the given user is authenticated, false if the +	 * 					session should be closed, or null if not implemented. +	 */ +	public function validate_session($user); + +	/** +	* Checks to see if $login_link_data contains all information except for the +	* user_id of an account needed to successfully link an external account to +	* a forum account. +	* +	* @param	array	$link_data	Any data needed to link a phpBB account to +	*								an external account. +	* @return	string|null	Returns a string with a language constant if there +	*						is data missing or null if there is no error. +	*/ +	public function login_link_has_necessary_data($login_link_data); + +	/** +	* Links an external account to a phpBB account. +	* +	* @param	array	$link_data	Any data needed to link a phpBB account to +	*								an external account. +	*/ +	public function link_account(array $link_data); + +	/** +	* Returns an array of data necessary to build the ucp_auth_link page +	* +	* @return	array|null	If this function is not implemented on an auth +	*						provider then it returns null. If it is implemented +	*						it will return an array of up to four elements of +	*						which only 'TEMPLATE_FILE'. If 'BLOCK_VAR_NAME' is +	*						present then 'BLOCK_VARS' must also be present in +	*						the array. The fourth element 'VARS' is also +	*						optional. The array, with all four elements present +	*						looks like the following: +	*						array( +	*							'TEMPLATE_FILE'		=> string, +	*							'BLOCK_VAR_NAME'	=> string, +	*							'BLOCK_VARS'		=> array(...), +	*							'VARS'				=> array(...), +	*						) +	*/ +	public function get_auth_link_data(); + +	/** +	* Unlinks an external account from a phpBB account. +	* +	* @param	array	$link_data	Any data needed to unlink a phpBB account +	*								from a phpbb account. +	*/ +	public function unlink_account(array $link_data); +} diff --git a/phpBB/phpbb/avatar/driver/driver.php b/phpBB/phpbb/avatar/driver/driver.php index 29c58d4e62..0c54951cbd 100644 --- a/phpBB/phpbb/avatar/driver/driver.php +++ b/phpBB/phpbb/avatar/driver/driver.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\avatar\driver; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * Base class for avatar drivers  * @package phpBB3  */ -abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface +abstract class driver implements \phpbb\avatar\driver\driver_interface  {  	/**  	* Avatar driver name @@ -29,7 +31,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface  	/**  	* Current board configuration -	* @var phpbb_config +	* @var \phpbb\config\config  	*/  	protected $config; @@ -47,7 +49,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface  	/**  	* Cache driver -	* @var phpbb_cache_driver_interface +	* @var \phpbb\cache\driver\driver_interface  	*/  	protected $cache; @@ -69,13 +71,13 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface  	/**  	* Construct a driver object  	* -	* @param phpbb_config $config phpBB configuration -	* @param phpbb_request $request Request object +	* @param \phpbb\config\config $config phpBB configuration +	* @param \phpbb\request\request $request Request object  	* @param string $phpbb_root_path Path to the phpBB root  	* @param string $php_ext PHP file extension -	* @param phpbb_cache_driver_interface $cache Cache driver +	* @param \phpbb\cache\driver\driver_interface $cache Cache driver  	*/ -	public function __construct(phpbb_config $config, $phpbb_root_path, $php_ext, phpbb_cache_driver_interface $cache = null) +	public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\cache\driver\driver_interface $cache = null)  	{  		$this->config = $config;  		$this->phpbb_root_path = $phpbb_root_path; @@ -112,7 +114,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface  	*/  	public function get_template_name()  	{ -		$driver = preg_replace('#^phpbb_avatar_driver_#', '', get_class($this)); +		$driver = preg_replace('#^phpbb\\\\avatar\\\\driver\\\\#', '', get_class($this));  		$template = "ucp_avatar_options_$driver.html";  		return $template; diff --git a/phpBB/phpbb/avatar/driver/interface.php b/phpBB/phpbb/avatar/driver/driver_interface.php index 3d62969aef..d9540c19db 100644 --- a/phpBB/phpbb/avatar/driver/interface.php +++ b/phpBB/phpbb/avatar/driver/driver_interface.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\avatar\driver; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * Interface for avatar drivers  * @package phpBB3  */ -interface phpbb_avatar_driver_interface +interface driver_interface  {  	/**  	* Returns the name of the driver. @@ -32,7 +34,7 @@ interface phpbb_avatar_driver_interface  	* Get the avatar url and dimensions  	*  	* @param array	$row User data or group data that has been cleaned with -	*        phpbb_avatar_manager::clean_row +	*        \phpbb\avatar\manager::clean_row  	* @return array Avatar data, must have keys src, width and height, e.g.  	*        ['src' => '', 'width' => 0, 'height' => 0]  	*/ @@ -41,9 +43,9 @@ interface phpbb_avatar_driver_interface  	/**  	* Returns custom html if it is needed for displaying this avatar  	* -	* @param phpbb_user $user phpBB user object +	* @param \phpbb\user $user phpBB user object  	* @param array	$row User data or group data that has been cleaned with -	*        phpbb_avatar_manager::clean_row +	*        \phpbb\avatar\manager::clean_row  	* @param string $alt Alternate text for avatar image  	*  	* @return string HTML @@ -53,11 +55,11 @@ interface phpbb_avatar_driver_interface  	/**  	* Prepare form for changing the settings of this avatar  	* -	* @param phpbb_request $request Request object -	* @param phpbb_template	$template Template object -	* @param phpbb_user $user User object +	* @param \phpbb\request\request $request Request object +	* @param \phpbb\template\template	$template Template object +	* @param \phpbb\user $user User object  	* @param array	$row User data or group data that has been cleaned with -	*        phpbb_avatar_manager::clean_row +	*        \phpbb\avatar\manager::clean_row  	* @param array	&$error Reference to an error array that is filled by this  	*        function. Key values can either be a string with a language key or  	*        an array that will be passed to vsprintf() with the language key in @@ -70,7 +72,7 @@ interface phpbb_avatar_driver_interface  	/**  	* Prepare form for changing the acp settings of this avatar  	* -	* @param phpbb_user $user phpBB user object +	* @param \phpbb\user $user phpBB user object  	*  	* @return array Array of configuration options as consumed by acp_board.  	*        The setting for enabling/disabling the avatar will be handled by @@ -81,11 +83,11 @@ interface phpbb_avatar_driver_interface  	/**  	* Process form data  	* -	* @param phpbb_request $request Request object -	* @param phpbb_template	$template Template object -	* @param phpbb_user $user User object +	* @param \phpbb\request\request $request Request object +	* @param \phpbb\template\template	$template Template object +	* @param \phpbb\user $user User object  	* @param array	$row User data or group data that has been cleaned with -	*        phpbb_avatar_manager::clean_row +	*        \phpbb\avatar\manager::clean_row  	* @param array	&$error Reference to an error array that is filled by this  	*        function. Key values can either be a string with a language key or  	*        an array that will be passed to vsprintf() with the language key in @@ -100,7 +102,7 @@ interface phpbb_avatar_driver_interface  	* Delete avatar  	*  	* @param array $row User data or group data that has been cleaned with -	*        phpbb_avatar_manager::clean_row +	*        \phpbb\avatar\manager::clean_row  	*  	* @return bool True if avatar has been deleted or there is no need to delete,  	*        i.e. when the avatar is not hosted locally. diff --git a/phpBB/phpbb/avatar/driver/gravatar.php b/phpBB/phpbb/avatar/driver/gravatar.php index d559da1c0d..3ad783932e 100644 --- a/phpBB/phpbb/avatar/driver/gravatar.php +++ b/phpBB/phpbb/avatar/driver/gravatar.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\avatar\driver; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * Handles avatars hosted at gravatar.com  * @package phpBB3  */ -class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver +class gravatar extends \phpbb\avatar\driver\driver  {  	/**  	* The URL for the gravatar service diff --git a/phpBB/phpbb/avatar/driver/local.php b/phpBB/phpbb/avatar/driver/local.php index f4bcd4ce74..d779099c46 100644 --- a/phpBB/phpbb/avatar/driver/local.php +++ b/phpBB/phpbb/avatar/driver/local.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\avatar\driver; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * Handles avatars selected from the board gallery  * @package phpBB3  */ -class phpbb_avatar_driver_local extends phpbb_avatar_driver +class local extends \phpbb\avatar\driver\driver  {  	/**  	* @inheritdoc @@ -144,7 +146,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver  	* Get a list of avatars that are locally available  	* Results get cached for 24 hours (86400 seconds)  	* -	* @param phpbb_user $user User object +	* @param \phpbb\user $user User object  	*  	* @return array Array containing the locally available avatars  	*/ @@ -157,7 +159,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver  			$avatar_list = array();  			$path = $this->phpbb_root_path . $this->config['avatar_gallery_path']; -			$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS), RecursiveIteratorIterator::SELF_FIRST); +			$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS), \RecursiveIteratorIterator::SELF_FIRST);  			foreach ($iterator as $file_info)  			{  				$file_path = $file_info->getPath(); diff --git a/phpBB/phpbb/avatar/driver/remote.php b/phpBB/phpbb/avatar/driver/remote.php index 7da58107a1..1aa638dfe5 100644 --- a/phpBB/phpbb/avatar/driver/remote.php +++ b/phpBB/phpbb/avatar/driver/remote.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\avatar\driver; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * Handles avatars hosted remotely  * @package phpBB3  */ -class phpbb_avatar_driver_remote extends phpbb_avatar_driver +class remote extends \phpbb\avatar\driver\driver  {  	/**  	* @inheritdoc @@ -93,7 +95,7 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver  		// Make sure getimagesize works...  		if (function_exists('getimagesize'))  		{ -			if (($width <= 0 || $height <= 0) && (($image_data = getimagesize($url)) === false)) +			if (($width <= 0 || $height <= 0) && (($image_data = @getimagesize($url)) === false))  			{  				$error[] = 'UNABLE_GET_IMAGE_SIZE';  				return false; @@ -120,8 +122,8 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver  			include($this->phpbb_root_path . 'includes/functions_upload.' . $this->php_ext);  		} -		$types = fileupload::image_types(); -		$extension = strtolower(filespec::get_extension($url)); +		$types = \fileupload::image_types(); +		$extension = strtolower(\filespec::get_extension($url));  		if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]])))  		{ diff --git a/phpBB/phpbb/avatar/driver/upload.php b/phpBB/phpbb/avatar/driver/upload.php index 685ac4f349..377c9a0b04 100644 --- a/phpBB/phpbb/avatar/driver/upload.php +++ b/phpBB/phpbb/avatar/driver/upload.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\avatar\driver; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * Handles avatars uploaded to the board  * @package phpBB3  */ -class phpbb_avatar_driver_upload extends phpbb_avatar_driver +class upload extends \phpbb\avatar\driver\driver  {  	/**  	* @inheritdoc @@ -66,7 +68,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver  			include($this->phpbb_root_path . 'includes/functions_upload.' . $this->php_ext);  		} -		$upload = new fileupload('AVATAR_', $this->allowed_extensions, $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false)); +		$upload = new \fileupload('AVATAR_', $this->allowed_extensions, $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false));  		$url = $request->variable('avatar_upload_url', '');  		$upload_file = $request->file('avatar_upload_file'); diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 58d994c3c0..c28380a401 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\avatar; +  /**  * @ignore  */ @@ -18,11 +20,11 @@ if (!defined('IN_PHPBB'))  /**  * @package avatar  */ -class phpbb_avatar_manager +class manager  {  	/**  	* phpBB configuration -	* @var phpbb_config +	* @var \phpbb\config\config  	*/  	protected $config; @@ -59,11 +61,11 @@ class phpbb_avatar_manager  	/**  	* Construct an avatar manager object  	* -	* @param phpbb_config $config phpBB configuration +	* @param \phpbb\config\config $config phpBB configuration  	* @param array $avatar_drivers Avatar drivers passed via the service container  	* @param object $container Container object  	*/ -	public function __construct(phpbb_config $config, $avatar_drivers, $container) +	public function __construct(\phpbb\config\config $config, $avatar_drivers, $container)  	{  		$this->config = $config;  		$this->avatar_drivers = $avatar_drivers; @@ -194,7 +196,7 @@ class phpbb_avatar_manager  		$keys = array_keys($row);  		$values = array_values($row); -		$keys = array_map(array('phpbb_avatar_manager', 'strip_prefix'), $keys); +		$keys = array_map(array('\phpbb\avatar\manager', 'strip_prefix'), $keys);  		return array_combine($keys, $values);  	} @@ -220,7 +222,7 @@ class phpbb_avatar_manager  	*/  	static public function clean_driver_name($name)  	{ -		return str_replace('_', '.', $name); +		return str_replace(array('\\', '_'), '.', $name);  	}  	/** @@ -262,7 +264,7 @@ class phpbb_avatar_manager  		$config_name = $this->get_driver_config_name($driver);  		return array( -			'allow_avatar_' . $config_name	=> array('lang' => 'ALLOW_' . strtoupper($config_name),		'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => false), +			'allow_avatar_' . $config_name	=> array('lang' => 'ALLOW_' . strtoupper(str_replace('\\', '_', $config_name)),		'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => false),  		);  	} @@ -275,13 +277,13 @@ class phpbb_avatar_manager  	*/  	public function get_driver_config_name($driver)  	{ -		return preg_replace('#^phpbb_avatar_driver_#', '', get_class($driver)); +		return preg_replace('#^phpbb\\\\avatar\\\\driver\\\\#', '', get_class($driver));  	}  	/**  	* Replace "error" strings with their real, localized form  	* -	* @param phpbb_user phpBB User object +	* @param \phpbb\user phpBB User object  	* @param array	$error Array containing error strings  	*        Key values can either be a string with a language key or an array  	*        that will be passed to vsprintf() with the language key in the @@ -289,7 +291,7 @@ class phpbb_avatar_manager  	*  	* @return array Array containing the localized error strings  	*/ -	public function localize_errors(phpbb_user $user, $error) +	public function localize_errors(\phpbb\user $user, $error)  	{  		foreach ($error as $key => $lang)  		{ diff --git a/phpBB/phpbb/cache/driver/apc.php b/phpBB/phpbb/cache/driver/apc.php index 0516b669c8..ce72ec6134 100644 --- a/phpBB/phpbb/cache/driver/apc.php +++ b/phpBB/phpbb/cache/driver/apc.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cache\driver; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * ACM for APC  * @package acm  */ -class phpbb_cache_driver_apc extends phpbb_cache_driver_memory +class apc extends \phpbb\cache\driver\memory  {  	var $extension = 'apc'; diff --git a/phpBB/phpbb/cache/driver/base.php b/phpBB/phpbb/cache/driver/base.php index 32e04f813a..90185a00d2 100644 --- a/phpBB/phpbb/cache/driver/base.php +++ b/phpBB/phpbb/cache/driver/base.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cache\driver; +  /**  * @ignore  */ @@ -18,6 +20,6 @@ if (!defined('IN_PHPBB'))  /**  * @package acm  */ -abstract class phpbb_cache_driver_base implements phpbb_cache_driver_interface +abstract class base implements \phpbb\cache\driver\driver_interface  {  } diff --git a/phpBB/phpbb/cache/driver/interface.php b/phpBB/phpbb/cache/driver/driver_interface.php index 53f684d1c8..34c60b5935 100644 --- a/phpBB/phpbb/cache/driver/interface.php +++ b/phpBB/phpbb/cache/driver/driver_interface.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cache\driver; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  *  * @package acm  */ -interface phpbb_cache_driver_interface +interface driver_interface  {  	/**  	* Load global cache @@ -85,10 +87,10 @@ interface phpbb_cache_driver_interface  	* result to persistent storage. In other words, there is no need  	* to call save() afterwards.  	* -	* @param phpbb_db_driver $db	Database connection +	* @param \phpbb\db\driver\driver $db	Database connection  	* @param string $query			SQL query, should be used for generating storage key -	* @param mixed $query_result	The result from dbal::sql_query, to be passed to -	* 								dbal::sql_fetchrow to get all rows and store them +	* @param mixed $query_result	The result from \dbal::sql_query, to be passed to +	* 								\dbal::sql_fetchrow to get all rows and store them  	* 								in cache.  	* @param int $ttl				Time to live, after this timeout the query should  	*								expire from the cache. @@ -96,7 +98,7 @@ interface phpbb_cache_driver_interface  	* 								representing the query should be returned. Otherwise  	* 								the original $query_result should be returned.  	*/ -	public function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl); +	public function sql_save(\phpbb\db\driver\driver $db, $query, $query_result, $ttl);  	/**  	* Check if result for a given SQL query exists in cache. diff --git a/phpBB/phpbb/cache/driver/eaccelerator.php b/phpBB/phpbb/cache/driver/eaccelerator.php index 257b90c76e..72c0d77d02 100644 --- a/phpBB/phpbb/cache/driver/eaccelerator.php +++ b/phpBB/phpbb/cache/driver/eaccelerator.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cache\driver; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  * @package acm  * @todo Missing locks from destroy() talk with David  */ -class phpbb_cache_driver_eaccelerator extends phpbb_cache_driver_memory +class eaccelerator extends \phpbb\cache\driver\memory  {  	var $extension = 'eaccelerator';  	var $function = 'eaccelerator_get'; diff --git a/phpBB/phpbb/cache/driver/file.php b/phpBB/phpbb/cache/driver/file.php index 85decbe3e8..a64232400b 100644 --- a/phpBB/phpbb/cache/driver/file.php +++ b/phpBB/phpbb/cache/driver/file.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cache\driver; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * ACM File Based Caching  * @package acm  */ -class phpbb_cache_driver_file extends phpbb_cache_driver_base +class file extends \phpbb\cache\driver\base  {  	var $vars = array();  	var $var_expires = array(); @@ -205,28 +207,34 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base  	function purge()  	{  		// Purge all phpbb cache files -		$dir = @opendir($this->cache_dir); - -		if (!$dir) +		try +		{ +			$iterator = new \DirectoryIterator($this->cache_dir); +		} +		catch (Exception $e)  		{  			return;  		} -		while (($entry = readdir($dir)) !== false) +		foreach ($iterator as $fileInfo)  		{ -			if (strpos($entry, 'container_') !== 0 && -				strpos($entry, 'url_matcher') !== 0 && -				strpos($entry, 'sql_') !== 0 && -				strpos($entry, 'data_') !== 0 && -				strpos($entry, 'ctpl_') !== 0 && -				strpos($entry, 'tpl_') !== 0) +			if ($fileInfo->isDot())  			{  				continue;  			} - -			$this->remove_file($this->cache_dir . $entry); +			$filename = $fileInfo->getFilename(); +			if ($fileInfo->isDir()) +			{ +				$this->remove_dir($fileInfo->getPathname()); +			} +			elseif (strpos($filename, 'container_') === 0 || +				strpos($filename, 'url_matcher') === 0 || +				strpos($filename, 'sql_') === 0 || +				strpos($filename, 'data_') === 0) +			{ +				$this->remove_file($fileInfo->getPathname()); +			}  		} -		closedir($dir);  		unset($this->vars);  		unset($this->var_expires); @@ -242,6 +250,44 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base  	}  	/** +	* Remove directory +	* +	* @param string $dir Directory to remove +	* +	* @return null +	*/ +	protected function remove_dir($dir) +	{ +		try +		{ +			$iterator = new \DirectoryIterator($dir); +		} +		catch (Exception $e) +		{ +			return; +		} + +		foreach ($iterator as $fileInfo) +		{ +			if ($fileInfo->isDot()) +			{ +				continue; +			} + +			if ($fileInfo->isDir()) +			{ +				$this->remove_dir($fileInfo->getPathname()); +			} +			else +			{ +				$this->remove_file($fileInfo->getPathname()); +			} +		} + +		@rmdir($dir); +	} + +	/**  	* Destroy cache data  	*/  	function destroy($var_name, $table = '') @@ -369,7 +415,7 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base  	/**  	* {@inheritDoc}  	*/ -	function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl) +	function sql_save(\phpbb\db\driver\driver $db, $query, $query_result, $ttl)  	{  		// Remove extra spaces and tabs  		$query = preg_replace('/[\n\r\s\t]+/', ' ', $query); @@ -651,7 +697,7 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base  		$file = "{$this->cache_dir}$filename.$phpEx"; -		$lock = new phpbb_lock_flock($file); +		$lock = new \phpbb\lock\flock($file);  		$lock->acquire();  		if ($handle = @fopen($file, 'wb')) diff --git a/phpBB/phpbb/cache/driver/memcache.php b/phpBB/phpbb/cache/driver/memcache.php index 3fd16b23b0..84fe68ae49 100644 --- a/phpBB/phpbb/cache/driver/memcache.php +++ b/phpBB/phpbb/cache/driver/memcache.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cache\driver; +  /**  * @ignore  */ @@ -40,7 +42,7 @@ if (!defined('PHPBB_ACM_MEMCACHE'))  * ACM for Memcached  * @package acm  */ -class phpbb_cache_driver_memcache extends phpbb_cache_driver_memory +class memcache extends \phpbb\cache\driver\memory  {  	var $extension = 'memcache'; @@ -52,7 +54,7 @@ class phpbb_cache_driver_memcache extends phpbb_cache_driver_memory  		// Call the parent constructor  		parent::__construct(); -		$this->memcache = new Memcache; +		$this->memcache = new \Memcache;  		foreach(explode(',', PHPBB_ACM_MEMCACHE) as $u)  		{  			$parts = explode('/', $u); diff --git a/phpBB/phpbb/cache/driver/memory.php b/phpBB/phpbb/cache/driver/memory.php index f77a1df316..5a9861913f 100644 --- a/phpBB/phpbb/cache/driver/memory.php +++ b/phpBB/phpbb/cache/driver/memory.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cache\driver; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * ACM Abstract Memory Class  * @package acm  */ -abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base +abstract class memory extends \phpbb\cache\driver\base  {  	var $key_prefix; @@ -285,7 +287,7 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base  	/**  	* {@inheritDoc}  	*/ -	function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl) +	function sql_save(\phpbb\db\driver\driver $db, $query, $query_result, $ttl)  	{  		// Remove extra spaces and tabs  		$query = preg_replace('/[\n\r\s\t]+/', ' ', $query); diff --git a/phpBB/phpbb/cache/driver/null.php b/phpBB/phpbb/cache/driver/null.php index 2fadc27ba3..c03319ad61 100644 --- a/phpBB/phpbb/cache/driver/null.php +++ b/phpBB/phpbb/cache/driver/null.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cache\driver; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * ACM Null Caching  * @package acm  */ -class phpbb_cache_driver_null extends phpbb_cache_driver_base +class null extends \phpbb\cache\driver\base  {  	/**  	* Set cache path @@ -107,7 +109,7 @@ class phpbb_cache_driver_null extends phpbb_cache_driver_base  	/**  	* {@inheritDoc}  	*/ -	function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl) +	function sql_save(\phpbb\db\driver\driver $db, $query, $query_result, $ttl)  	{  		return $query_result;  	} diff --git a/phpBB/phpbb/cache/driver/redis.php b/phpBB/phpbb/cache/driver/redis.php index 960735b673..317d07428a 100644 --- a/phpBB/phpbb/cache/driver/redis.php +++ b/phpBB/phpbb/cache/driver/redis.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cache\driver; +  /**  * @ignore  */ @@ -33,7 +35,7 @@ if (!defined('PHPBB_ACM_REDIS_HOST'))  *  * @package acm  */ -class phpbb_cache_driver_redis extends phpbb_cache_driver_memory +class redis extends \phpbb\cache\driver\memory  {  	var $extension = 'redis'; @@ -56,7 +58,7 @@ class phpbb_cache_driver_redis extends phpbb_cache_driver_memory  		// Call the parent constructor  		parent::__construct(); -		$this->redis = new Redis(); +		$this->redis = new \Redis();  		$args = func_get_args();  		if (!empty($args)) @@ -83,8 +85,8 @@ class phpbb_cache_driver_redis extends phpbb_cache_driver_memory  			}  		} -		$this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); -		$this->redis->setOption(Redis::OPT_PREFIX, $this->key_prefix); +		$this->redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP); +		$this->redis->setOption(\Redis::OPT_PREFIX, $this->key_prefix);  		if (defined('PHPBB_ACM_REDIS_DB'))  		{ diff --git a/phpBB/phpbb/cache/driver/wincache.php b/phpBB/phpbb/cache/driver/wincache.php index 58f3b4a581..a0b24e4a1f 100644 --- a/phpBB/phpbb/cache/driver/wincache.php +++ b/phpBB/phpbb/cache/driver/wincache.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cache\driver; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * ACM for WinCache  * @package acm  */ -class phpbb_cache_driver_wincache extends phpbb_cache_driver_memory +class wincache extends \phpbb\cache\driver\memory  {  	var $extension = 'wincache'; diff --git a/phpBB/phpbb/cache/driver/xcache.php b/phpBB/phpbb/cache/driver/xcache.php index 06c5fafd97..fdcbf7e4b5 100644 --- a/phpBB/phpbb/cache/driver/xcache.php +++ b/phpBB/phpbb/cache/driver/xcache.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cache\driver; +  /**  * @ignore  */ @@ -24,7 +26,7 @@ if (!defined('IN_PHPBB'))  * - xcache.admin.enable_auth = off (or xcache.admin.user and xcache.admin.password set)  *  */ -class phpbb_cache_driver_xcache extends phpbb_cache_driver_memory +class xcache extends \phpbb\cache\driver\memory  {  	var $extension = 'XCache'; diff --git a/phpBB/phpbb/cache/service.php b/phpBB/phpbb/cache/service.php index 69c5e0fdd0..da8f4eb8d8 100644 --- a/phpBB/phpbb/cache/service.php +++ b/phpBB/phpbb/cache/service.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cache; +  /**  * @ignore  */ @@ -19,26 +21,26 @@ if (!defined('IN_PHPBB'))  * Class for grabbing/handling cached entries  * @package acm  */ -class phpbb_cache_service +class service  {  	/**  	* Cache driver.  	* -	* @var phpbb_cache_driver_interface +	* @var \phpbb\cache\driver\driver_interface  	*/  	protected $driver;  	/**  	* The config.  	* -	* @var phpbb_config +	* @var \phpbb\config\config  	*/  	protected $config;  	/**  	* Database connection.  	* -	* @var phpbb_db_driver +	* @var \phpbb\db\driver\driver  	*/  	protected $db; @@ -59,13 +61,13 @@ class phpbb_cache_service  	/**  	* Creates a cache service around a cache driver  	* -	* @param phpbb_cache_driver_interface $driver The cache driver -	* @param phpbb_config $config The config -	* @param phpbb_db_driver $db Database connection +	* @param \phpbb\cache\driver\driver_interface $driver The cache driver +	* @param \phpbb\config\config $config The config +	* @param \phpbb\db\driver\driver $db Database connection  	* @param string $phpbb_root_path Root path  	* @param string $php_ext PHP extension  	*/ -	public function __construct(phpbb_cache_driver_interface $driver, phpbb_config $config, phpbb_db_driver $db, $phpbb_root_path, $php_ext) +	public function __construct(\phpbb\cache\driver\driver_interface $driver, \phpbb\config\config $config, \phpbb\db\driver\driver $db, $phpbb_root_path, $php_ext)  	{  		$this->set_driver($driver);  		$this->config = $config; @@ -77,7 +79,7 @@ class phpbb_cache_service  	/**  	* Returns the cache driver used by this cache service.  	* -	* @return phpbb_cache_driver_interface The cache driver +	* @return \phpbb\cache\driver\driver_interface The cache driver  	*/  	public function get_driver()  	{ @@ -87,9 +89,9 @@ class phpbb_cache_service  	/**  	* Replaces the cache driver used by this cache service.  	* -	* @param phpbb_cache_driver_interface $driver The cache driver +	* @param \phpbb\cache\driver\driver_interface $driver The cache driver  	*/ -	public function set_driver(phpbb_cache_driver_interface $driver) +	public function set_driver(\phpbb\cache\driver\driver_interface $driver)  	{  		$this->driver = $driver;  	} diff --git a/phpBB/phpbb/class_loader.php b/phpBB/phpbb/class_loader.php index 02a2d584dc..769f28b4f1 100644 --- a/phpBB/phpbb/class_loader.php +++ b/phpBB/phpbb/class_loader.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb; +  /**  * @ignore  */ @@ -28,9 +30,9 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_class_loader +class class_loader  { -	private $prefix; +	private $namespace;  	private $path;  	private $php_ext;  	private $cache; @@ -44,17 +46,22 @@ class phpbb_class_loader  	private $cached_paths = array();  	/** -	* Creates a new phpbb_class_loader, which loads files with the given +	* Creates a new \phpbb\class_loader, which loads files with the given  	* file extension from the given path.  	* -	* @param string $prefix  Required class name prefix for files to be loaded +	* @param string $namespace Required namespace for files to be loaded  	* @param string $path    Directory to load files from  	* @param string $php_ext The file extension for PHP files -	* @param phpbb_cache_driver_interface $cache An implementation of the phpBB cache interface. +	* @param \phpbb\cache\driver\driver_interface $cache An implementation of the phpBB cache interface.  	*/ -	public function __construct($prefix, $path, $php_ext = 'php', phpbb_cache_driver_interface $cache = null) -	{ -		$this->prefix = $prefix; +	public function __construct($namespace, $path, $php_ext = 'php', \phpbb\cache\driver\driver_interface $cache = null) +    { +		if ($namespace[0] !== '\\') +		{ +			$namespace = '\\' . $namespace; +		} + +		$this->namespace = $namespace;  		$this->path = $path;  		$this->php_ext = $php_ext; @@ -66,13 +73,13 @@ class phpbb_class_loader  	* the class loader will resolve paths by checking for the existance of every  	* directory in the class name every time.  	* -	* @param phpbb_cache_driver_interface $cache An implementation of the phpBB cache interface. +	* @param \phpbb\cache\driver\driver_interface $cache An implementation of the phpBB cache interface.  	*/ -	public function set_cache(phpbb_cache_driver_interface $cache = null) +	public function set_cache(\phpbb\cache\driver\driver_interface $cache = null)  	{  		if ($cache)  		{ -			$this->cached_paths = $cache->get('class_loader_' . $this->prefix); +			$this->cached_paths = $cache->get('class_loader_' . str_replace('\\', '__', $this->namespace));  			if ($this->cached_paths === false)  			{ @@ -102,8 +109,9 @@ class phpbb_class_loader  	/**  	* Resolves a phpBB class name to a relative path which can be included.  	* -	* @param string       $class The class name to resolve, must have a phpbb_ -	*                            prefix +	* @param string       $class The class name to resolve, must be in the +	*                            namespace the loader was constructed with. +	*                            Has to begin with \  	* @return string|bool        A relative path to the file containing the  	*                            class or false if looking it up failed.  	*/ @@ -114,27 +122,12 @@ class phpbb_class_loader  			return $this->path . $this->cached_paths[$class] . '.' . $this->php_ext;  		} -		if (!preg_match('/^' . $this->prefix . '[a-zA-Z0-9_]+$/', $class)) +		if (!preg_match('/^' . preg_quote($this->namespace, '/') . '[a-zA-Z0-9_\\\\]+$/', $class))  		{  			return false;  		} -		$parts = explode('_', substr($class, strlen($this->prefix))); - -		$dirs = ''; - -		for ($i = 0, $n = sizeof($parts); $i < $n && is_dir($this->path . $dirs . $parts[$i]); $i++) -		{ -			$dirs .= $parts[$i] . '/'; -		} - -		// no file name left => use last dir name as file name -		if ($i == sizeof($parts)) -		{ -			$parts[] = $parts[$i - 1]; -		} - -		$relative_path = $dirs . implode(array_slice($parts, $i, sizeof($parts) - $i), '_'); +		$relative_path = str_replace('\\', '/', substr($class, strlen($this->namespace)));  		if (!file_exists($this->path . $relative_path . '.' . $this->php_ext))  		{ @@ -144,7 +137,7 @@ class phpbb_class_loader  		if ($this->cache)  		{  			$this->cached_paths[$class] = $relative_path; -			$this->cache->put('class_loader_' . $this->prefix, $this->cached_paths); +			$this->cache->put('class_loader_' . str_replace('\\', '__', $this->namespace), $this->cached_paths);  		}  		return $this->path . $relative_path . '.' . $this->php_ext; @@ -157,7 +150,8 @@ class phpbb_class_loader  	*/  	public function load_class($class)  	{ -		if (substr($class, 0, strlen($this->prefix)) === $this->prefix) +		$class = '\\' . $class; +		if (substr($class, 0, strlen($this->namespace)) === $this->namespace)  		{  			$path = $this->resolve_path($class); diff --git a/phpBB/phpbb/config/config.php b/phpBB/phpbb/config/config.php index 4b533dd55c..dc865df707 100644 --- a/phpBB/phpbb/config/config.php +++ b/phpBB/phpbb/config/config.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\config; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * Configuration container class  * @package phpBB3  */ -class phpbb_config implements ArrayAccess, IteratorAggregate, Countable +class config implements \ArrayAccess, \IteratorAggregate, \Countable  {  	/**  	* The configuration data @@ -44,7 +46,7 @@ class phpbb_config implements ArrayAccess, IteratorAggregate, Countable  	*/  	public function getIterator()  	{ -		return new ArrayIterator($this->config); +		return new \ArrayIterator($this->config);  	}  	/** @@ -90,7 +92,7 @@ class phpbb_config implements ArrayAccess, IteratorAggregate, Countable  	*/  	public function offsetUnset($key)  	{ -		trigger_error('Config values have to be deleted explicitly with the phpbb_config::delete($key) method.', E_USER_ERROR); +		trigger_error('Config values have to be deleted explicitly with the \phpbb\config\config::delete($key) method.', E_USER_ERROR);  	}  	/** diff --git a/phpBB/phpbb/config/db.php b/phpBB/phpbb/config/db.php index b18369a479..0a490af14f 100644 --- a/phpBB/phpbb/config/db.php +++ b/phpBB/phpbb/config/db.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\config; +  /**  * @ignore  */ @@ -19,17 +21,17 @@ if (!defined('IN_PHPBB'))  * Configuration container class  * @package phpBB3  */ -class phpbb_config_db extends phpbb_config +class db extends \phpbb\config\config  {  	/**  	* Cache instance -	* @var phpbb_cache_driver_interface +	* @var \phpbb\cache\driver\driver_interface  	*/  	protected $cache;  	/**  	* Database connection -	* @var phpbb_db_driver +	* @var \phpbb\db\driver\driver  	*/  	protected $db; @@ -42,11 +44,11 @@ class phpbb_config_db extends phpbb_config  	/**  	* Creates a configuration container with a default set of values  	* -	* @param phpbb_db_driver              $db    Database connection -	* @param phpbb_cache_driver_interface $cache Cache instance +	* @param \phpbb\db\driver\driver              $db    Database connection +	* @param \phpbb\cache\driver\driver_interface $cache Cache instance  	* @param string                       $table Configuration table name  	*/ -	public function __construct(phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $table) +	public function __construct(\phpbb\db\driver\driver $db, \phpbb\cache\driver\driver_interface $cache, $table)  	{  		$this->db = $db;  		$this->cache = $cache; diff --git a/phpBB/phpbb/config/db_text.php b/phpBB/phpbb/config/db_text.php index b365cb5c77..3ee3351e19 100644 --- a/phpBB/phpbb/config/db_text.php +++ b/phpBB/phpbb/config/db_text.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\config; +  /**  * @ignore  */ @@ -17,16 +19,16 @@ if (!defined('IN_PHPBB'))  /**  * Manages configuration options with an arbitrary length value stored in a TEXT -* column. In constrast to class phpbb_config_db, values are never cached and +* column. In constrast to class \phpbb\config\db, values are never cached and  * prefetched, but every get operation sends a query to the database.  *  * @package phpBB3  */ -class phpbb_config_db_text +class db_text  {  	/**  	* Database connection -	* @var phpbb_db_driver +	* @var \phpbb\db\driver\driver  	*/  	protected $db; @@ -37,10 +39,10 @@ class phpbb_config_db_text  	protected $table;  	/** -	* @param phpbb_db_driver $db        Database connection +	* @param \phpbb\db\driver\driver $db        Database connection  	* @param string          $table     Table name  	*/ -	public function __construct(phpbb_db_driver $db, $table) +	public function __construct(\phpbb\db\driver\driver $db, $table)  	{  		$this->db = $db;  		$this->table = $this->db->sql_escape($table); diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php index 4ad5f6793e..0b351bc9ec 100644 --- a/phpBB/phpbb/content_visibility.php +++ b/phpBB/phpbb/content_visibility.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb; +  /**  * @ignore  */ @@ -20,23 +22,23 @@ if (!defined('IN_PHPBB'))  * Handle fetching and setting the visibility for topics and posts  * @package phpbb  */ -class phpbb_content_visibility +class content_visibility  {  	/**  	* Database object -	* @var phpbb_db_driver +	* @var \phpbb\db\driver\driver  	*/  	protected $db;  	/**  	* User object -	* @var phpbb_user +	* @var \phpbb\user  	*/  	protected $user;  	/**  	* Auth object -	* @var phpbb_auth +	* @var \phpbb\auth\auth  	*/  	protected $auth; @@ -55,14 +57,14 @@ class phpbb_content_visibility  	/**  	* Constructor  	* -	* @param	phpbb_auth		$auth	Auth object -	* @param	phpbb_db_driver	$db		Database object -	* @param	phpbb_user		$user	User object +	* @param	\phpbb\auth\auth		$auth	Auth object +	* @param	\phpbb\db\driver\driver	$db		Database object +	* @param	\phpbb\user		$user	User object  	* @param	string		$phpbb_root_path	Root path  	* @param	string		$php_ext			PHP Extension  	* @return	null  	*/ -	public function __construct(phpbb_auth $auth, phpbb_db_driver $db, phpbb_user $user, $phpbb_root_path, $php_ext, $forums_table, $posts_table, $topics_table, $users_table) +	public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver $db, \phpbb\user $user, $phpbb_root_path, $php_ext, $forums_table, $posts_table, $topics_table, $users_table)  	{  		$this->auth = $auth;  		$this->db = $db; @@ -360,6 +362,11 @@ class phpbb_content_visibility  		// Sync the first/last topic information if needed  		if (!$is_starter && $is_latest)  		{ +			if (!function_exists('update_post_information')) +			{ +				include($this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext); +			} +  			// update_post_information can only update the last post info ...  			if ($topic_id)  			{ @@ -549,7 +556,7 @@ class phpbb_content_visibility  	*  	* @param $data			array	Contains information from the topics table about given topic  	* @param $sql_data		array	Populated with the SQL changes, may be empty at call time -	* @return void +	* @return null  	*/  	public function add_post_to_statistic($data, &$sql_data)  	{ @@ -570,7 +577,7 @@ class phpbb_content_visibility  	*  	* @param $data			array	Contains information from the topics table about given topic  	* @param $sql_data		array	Populated with the SQL changes, may be empty at call time -	* @return void +	* @return null  	*/  	public function remove_post_from_statistic($data, &$sql_data)  	{ @@ -592,7 +599,7 @@ class phpbb_content_visibility  	* @param $forum_id		int		Forum where the topic is found  	* @param $topic_row		array	Contains information from the topic, may be empty at call time  	* @param $sql_data		array	Populated with the SQL changes, may be empty at call time -	* @return void +	* @return null  	*/  	public function remove_topic_from_statistic($topic_id, $forum_id, &$topic_row, &$sql_data)  	{ diff --git a/phpBB/phpbb/controller/exception.php b/phpBB/phpbb/controller/exception.php index faa8b6b584..e8694b8bcf 100644 --- a/phpBB/phpbb/controller/exception.php +++ b/phpBB/phpbb/controller/exception.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\controller; +  /**  * @ignore  */ @@ -19,6 +21,6 @@ if (!defined('IN_PHPBB'))  * Controller exception class  * @package phpBB3  */ -class phpbb_controller_exception extends RuntimeException +class exception extends \RuntimeException  {  } diff --git a/phpBB/phpbb/controller/helper.php b/phpBB/phpbb/controller/helper.php index 74410ddfd1..07483a91eb 100644 --- a/phpBB/phpbb/controller/helper.php +++ b/phpBB/phpbb/controller/helper.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\controller; +  /**  * @ignore  */ @@ -21,21 +23,27 @@ use Symfony\Component\HttpFoundation\Response;  * Controller helper class, contains methods that do things for controllers  * @package phpBB3  */ -class phpbb_controller_helper +class helper  {  	/**  	* Template object -	* @var phpbb_template +	* @var \phpbb\template\template  	*/  	protected $template;  	/**  	* User object -	* @var phpbb_user +	* @var \phpbb\user  	*/  	protected $user;  	/** +	* config object +	* @var \phpbb\config\config +	*/ +	protected $config; + +	/**  	* phpBB root path  	* @var string  	*/ @@ -50,15 +58,17 @@ class phpbb_controller_helper  	/**  	* Constructor  	* -	* @param phpbb_template $template Template object -	* @param phpbb_user $user User object +	* @param \phpbb\template\template $template Template object +    * @param \phpbb\user $user User object +    * @param \phpbb\config\config $config Config object  	* @param string $phpbb_root_path phpBB root path  	* @param string $php_ext PHP extension  	*/ -	public function __construct(phpbb_template $template, phpbb_user $user, $phpbb_root_path, $php_ext) +	public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, $phpbb_root_path, $php_ext)  	{  		$this->template = $template;  		$this->user = $user; +		$this->config = $config;  		$this->phpbb_root_path = $phpbb_root_path;  		$this->php_ext = $php_ext;  	} @@ -102,22 +112,14 @@ class phpbb_controller_helper  			$route = substr($route, 0, $route_delim);  		} -		if (is_array($params) && !empty($params)) -		{ -			$params = array_merge(array( -				'controller' => $route, -			), $params); -		} -		else if (is_string($params) && $params) -		{ -			$params = 'controller=' . $route . (($is_amp) ? '&' : '&') . $params; -		} -		else +		// If enable_mod_rewrite is false, we need to include app.php +		$route_prefix = $this->phpbb_root_path; +		if (empty($this->config['enable_mod_rewrite']))  		{ -			$params = array('controller' => $route); +			$route_prefix .= 'app.' . $this->php_ext . '/';  		} -		return append_sid($this->phpbb_root_path . 'app.' . $this->php_ext . $route_params, $params, $is_amp, $session_id); +		return append_sid($route_prefix . "$route" . $route_params, $params, $is_amp, $session_id);  	}  	/** diff --git a/phpBB/phpbb/controller/provider.php b/phpBB/phpbb/controller/provider.php index b2a5b9f6b2..3aad08e3aa 100644 --- a/phpBB/phpbb/controller/provider.php +++ b/phpBB/phpbb/controller/provider.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\controller; +  /**  * @ignore  */ @@ -23,7 +25,7 @@ use Symfony\Component\Config\FileLocator;  * Controller interface  * @package phpBB3  */ -class phpbb_controller_provider +class provider  {  	/**  	* YAML file(s) containing route information @@ -48,7 +50,7 @@ class phpbb_controller_provider  	*  	* @return The current instance of this object for method chaining  	*/ -	public function import_paths_from_finder(phpbb_extension_finder $finder) +	public function import_paths_from_finder(\phpbb\extension\finder $finder)  	{  		// We hardcode the path to the core config directory  		// because the finder cannot find it diff --git a/phpBB/phpbb/controller/resolver.php b/phpBB/phpbb/controller/resolver.php index 95dfc8da8e..1cc8981105 100644 --- a/phpBB/phpbb/controller/resolver.php +++ b/phpBB/phpbb/controller/resolver.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\controller; +  /**  * @ignore  */ @@ -23,11 +25,11 @@ use Symfony\Component\HttpFoundation\Request;  * Controller manager class  * @package phpBB3  */ -class phpbb_controller_resolver implements ControllerResolverInterface +class resolver implements ControllerResolverInterface  {  	/**  	* User object -	* @var phpbb_user +	* @var \phpbb\user  	*/  	protected $user; @@ -38,23 +40,23 @@ class phpbb_controller_resolver implements ControllerResolverInterface  	protected $container;  	/** -	* phpbb_style object -	* @var phpbb_style +	* phpbb\template\template object +	* @var phpbb\template\template  	*/ -	protected $style; +	protected $template;  	/**  	* Construct method  	* -	* @param phpbb_user $user User Object +	* @param \phpbb\user $user User Object  	* @param ContainerInterface $container ContainerInterface object -	* @param phpbb_style $style +	* @param \phpbb\template\template $template  	*/ -	public function __construct(phpbb_user $user, ContainerInterface $container, phpbb_style $style = null) +	public function __construct(\phpbb\user $user, ContainerInterface $container, \phpbb\template\template $template = null)  	{  		$this->user = $user;  		$this->container = $container; -		$this->style = $style; +		$this->template = $template;  	}  	/** @@ -62,7 +64,7 @@ class phpbb_controller_resolver implements ControllerResolverInterface  	*  	* @param Symfony\Component\HttpFoundation\Request $request Symfony Request object  	* @return bool|Callable Callable or false -	* @throws phpbb_controller_exception +	* @throws \phpbb\controller\exception  	*/  	public function getController(Request $request)  	{ @@ -70,20 +72,20 @@ class phpbb_controller_resolver implements ControllerResolverInterface  		if (!$controller)  		{ -			throw new phpbb_controller_exception($this->user->lang['CONTROLLER_NOT_SPECIFIED']); +			throw new \phpbb\controller\exception($this->user->lang['CONTROLLER_NOT_SPECIFIED']);  		}  		// Require a method name along with the service name  		if (stripos($controller, ':') === false)  		{ -			throw new phpbb_controller_exception($this->user->lang['CONTROLLER_METHOD_NOT_SPECIFIED']); +			throw new \phpbb\controller\exception($this->user->lang['CONTROLLER_METHOD_NOT_SPECIFIED']);  		}  		list($service, $method) = explode(':', $controller);  		if (!$this->container->has($service))  		{ -			throw new phpbb_controller_exception($this->user->lang('CONTROLLER_SERVICE_UNDEFINED', $service)); +			throw new \phpbb\controller\exception($this->user->lang('CONTROLLER_SERVICE_UNDEFINED', $service));  		}  		$controller_object = $this->container->get($service); @@ -93,16 +95,16 @@ class phpbb_controller_resolver implements ControllerResolverInterface  		* the style paths for the extension (the ext author can change them  		* if necessary).  		*/ -		$controller_dir = explode('_', get_class($controller_object)); +		$controller_dir = explode('\\', get_class($controller_object)); -		// 0 phpbb, 1 ext, 2 vendor, 3 extension name, ... -		if (!is_null($this->style) && isset($controller_dir[3]) && $controller_dir[1] === 'ext') +		// 0 vendor, 1 extension name, ... +		if (!is_null($this->template) && isset($controller_dir[1]))  		{ -			$controller_style_dir = 'ext/' . $controller_dir[2] . '/' . $controller_dir[3] . '/styles'; +			$controller_style_dir = 'ext/' . $controller_dir[0] . '/' . $controller_dir[1] . '/styles';  			if (is_dir($controller_style_dir))  			{ -				$this->style->set_style(array($controller_style_dir, 'styles')); +				$this->template->set_style(array($controller_style_dir, 'styles'));  			}  		} @@ -118,13 +120,13 @@ class phpbb_controller_resolver implements ControllerResolverInterface  	* @param Symfony\Component\HttpFoundation\Request $request Symfony Request object  	* @param mixed $controller A callable (controller class, method)  	* @return bool False -	* @throws phpbb_controller_exception +	* @throws \phpbb\controller\exception  	*/  	public function getArguments(Request $request, $controller)  	{  		// At this point, $controller contains the object and method name  		list($object, $method) = $controller; -		$mirror = new ReflectionMethod($object, $method); +		$mirror = new \ReflectionMethod($object, $method);  		$arguments = array();  		$parameters = $mirror->getParameters(); @@ -145,7 +147,7 @@ class phpbb_controller_resolver implements ControllerResolverInterface  			}  			else  			{ -				throw new phpbb_controller_exception($this->user->lang('CONTROLLER_ARGUMENT_VALUE_MISSING', $param->getPosition() + 1, get_class($object) . ':' . $method, $param->name)); +				throw new \phpbb\controller\exception($this->user->lang('CONTROLLER_ARGUMENT_VALUE_MISSING', $param->getPosition() + 1, get_class($object) . ':' . $method, $param->name));  			}  		} diff --git a/phpBB/phpbb/cron/manager.php b/phpBB/phpbb/cron/manager.php index 84c9650830..f58ba64a3d 100644 --- a/phpBB/phpbb/cron/manager.php +++ b/phpBB/phpbb/cron/manager.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cron; +  /**  * @ignore  */ @@ -22,10 +24,10 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_cron_manager +class manager  {  	/** -	* Set of phpbb_cron_task_wrapper objects. +	* Set of \phpbb\cron\task\wrapper objects.  	* Array holding all tasks that have been found.  	*  	* @var array @@ -52,7 +54,7 @@ class phpbb_cron_manager  	* Loads tasks given by name, wraps them  	* and puts them into $this->tasks.  	* -	* @param array|Traversable $tasks		Array of instances of phpbb_cron_task +	* @param array|Traversable $tasks		Array of instances of \phpbb\cron\task\task  	*  	* @return null  	*/ @@ -71,7 +73,7 @@ class phpbb_cron_manager  	*  	* If no tasks are ready, null is returned.  	* -	* @return phpbb_cron_task_wrapper|null +	* @return \phpbb\cron\task\wrapper|null  	*/  	public function find_one_ready_task()  	{ @@ -88,7 +90,7 @@ class phpbb_cron_manager  	/**  	* Finds all tasks that are ready to run.  	* -	* @return array		List of tasks which are ready to run (wrapped in phpbb_cron_task_wrapper). +	* @return array		List of tasks which are ready to run (wrapped in \phpbb\cron\task\wrapper).  	*/  	public function find_all_ready_tasks()  	{ @@ -111,7 +113,7 @@ class phpbb_cron_manager  	* Web runner uses this method to resolve names to tasks.  	*  	* @param string				$name Name of the task to look up. -	* @return phpbb_cron_task	A task corresponding to the given name, or null. +	* @return \phpbb\cron\task\task	A task corresponding to the given name, or null.  	*/  	public function find_task($name)  	{ @@ -126,13 +128,13 @@ class phpbb_cron_manager  	}  	/** -	* Wraps a task inside an instance of phpbb_cron_task_wrapper. +	* Wraps a task inside an instance of \phpbb\cron\task\wrapper.  	* -	* @param  phpbb_cron_task 			$task The task. -	* @return phpbb_cron_task_wrapper	The wrapped task. +	* @param  \phpbb\cron\task\task 			$task The task. +	* @return \phpbb\cron\task\wrapper	The wrapped task.  	*/ -	public function wrap_task(phpbb_cron_task $task) +	public function wrap_task(\phpbb\cron\task\task $task)  	{ -		return new phpbb_cron_task_wrapper($task, $this->phpbb_root_path, $this->php_ext); +		return new \phpbb\cron\task\wrapper($task, $this->phpbb_root_path, $this->php_ext);  	}  } diff --git a/phpBB/phpbb/cron/task/base.php b/phpBB/phpbb/cron/task/base.php index 94a2f267b4..f30c9daf1b 100644 --- a/phpBB/phpbb/cron/task/base.php +++ b/phpBB/phpbb/cron/task/base.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cron\task; +  /**  * @ignore  */ @@ -26,7 +28,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -abstract class phpbb_cron_task_base implements phpbb_cron_task +abstract class base implements \phpbb\cron\task\task  {  	private $name; diff --git a/phpBB/phpbb/cron/task/core/prune_all_forums.php b/phpBB/phpbb/cron/task/core/prune_all_forums.php index 2c5d38cec0..8e3ef25ce6 100644 --- a/phpBB/phpbb/cron/task/core/prune_all_forums.php +++ b/phpBB/phpbb/cron/task/core/prune_all_forums.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cron\task\core; +  /**  * @ignore  */ @@ -24,7 +26,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base +class prune_all_forums extends \phpbb\cron\task\base  {  	protected $phpbb_root_path;  	protected $php_ext; @@ -36,10 +38,10 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base  	*  	* @param string $phpbb_root_path The root path  	* @param string $php_ext The PHP extension -	* @param phpbb_config $config The config -	* @param phpbb_db_driver $db The db connection +	* @param \phpbb\config\config $config The config +	* @param \phpbb\db\driver\driver $db The db connection  	*/ -	public function __construct($phpbb_root_path, $php_ext, phpbb_config $config, phpbb_db_driver $db) +	public function __construct($phpbb_root_path, $php_ext, \phpbb\config\config $config, \phpbb\db\driver\driver $db)  	{  		$this->phpbb_root_path = $phpbb_root_path;  		$this->php_ext = $php_ext; diff --git a/phpBB/phpbb/cron/task/core/prune_forum.php b/phpBB/phpbb/cron/task/core/prune_forum.php index e3c497f072..f14ab7b702 100644 --- a/phpBB/phpbb/cron/task/core/prune_forum.php +++ b/phpBB/phpbb/cron/task/core/prune_forum.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cron\task\core; +  /**  * @ignore  */ @@ -24,7 +26,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements phpbb_cron_task_parametrized +class prune_forum extends \phpbb\cron\task\base implements \phpbb\cron\task\parametrized  {  	protected $phpbb_root_path;  	protected $php_ext; @@ -46,10 +48,10 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p  	*  	* @param string $phpbb_root_path The root path  	* @param string $php_ext The PHP extension -	* @param phpbb_config $config The config -	* @param phpbb_db_driver $db The db connection +	* @param \phpbb\config\config $config The config +	* @param \phpbb\db\driver\driver $db The db connection  	*/ -	public function __construct($phpbb_root_path, $php_ext, phpbb_config $config, phpbb_db_driver $db) +	public function __construct($phpbb_root_path, $php_ext, \phpbb\config\config $config, \phpbb\db\driver\driver $db)  	{  		$this->phpbb_root_path = $phpbb_root_path;  		$this->php_ext = $php_ext; @@ -132,15 +134,15 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p  	/**  	* Parses parameters found in $request, which is an instance of -	* phpbb_request_interface. +	* \phpbb\request\request_interface.  	*  	* It is expected to have a key f whose value is id of the forum to be pruned.  	* -	* @param phpbb_request_interface $request Request object. +	* @param \phpbb\request\request_interface $request Request object.  	*  	* @return null  	*/ -	public function parse_parameters(phpbb_request_interface $request) +	public function parse_parameters(\phpbb\request\request_interface $request)  	{  		$this->forum_data = null;  		if ($request->is_set('f')) diff --git a/phpBB/phpbb/cron/task/core/prune_notifications.php b/phpBB/phpbb/cron/task/core/prune_notifications.php new file mode 100644 index 0000000000..296c0ae64f --- /dev/null +++ b/phpBB/phpbb/cron/task/core/prune_notifications.php @@ -0,0 +1,65 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +/** +* Prune notifications cron task. +* +* @package phpBB3 +*/ +class phpbb_cron_task_core_prune_notifications extends phpbb_cron_task_base +{ +	protected $config; +	protected $notification_manager; + +	/** +	* Constructor. +	* +	* @param phpbb_config $config The config +	* @param phpbb_notification_manager $notification_manager Notification manager +	*/ +	public function __construct(phpbb_config $config, phpbb_notification_manager $notification_manager) +	{ +		$this->config = $config; +		$this->notification_manager = $notification_manager; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function run() +	{ +		// time minus expire days in seconds +		$timestamp = time() - ($this->config['read_notification_expire_days'] * 60 * 60 * 24); +		$this->notification_manager->prune_notifications($timestamp); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function is_runnable() +	{ +		return (bool) $this->config['read_notification_expire_days']; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function should_run() +	{ +		return $this->config['read_notification_last_gc'] < time() - $this->config['read_notification_gc']; +	} +} diff --git a/phpBB/phpbb/cron/task/core/queue.php b/phpBB/phpbb/cron/task/core/queue.php index 732f9c6bea..cb13df86df 100644 --- a/phpBB/phpbb/cron/task/core/queue.php +++ b/phpBB/phpbb/cron/task/core/queue.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cron\task\core; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_cron_task_core_queue extends phpbb_cron_task_base +class queue extends \phpbb\cron\task\base  {  	protected $phpbb_root_path;  	protected $php_ext; @@ -31,9 +33,9 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base  	*  	* @param string $phpbb_root_path The root path  	* @param string $php_ext The PHP extension -	* @param phpbb_config $config The config +	* @param \phpbb\config\config $config The config  	*/ -	public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) +	public function __construct($phpbb_root_path, $php_ext, \phpbb\config\config $config)  	{  		$this->phpbb_root_path = $phpbb_root_path;  		$this->php_ext = $php_ext; @@ -51,7 +53,7 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base  		{  			include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext);  		} -		$queue = new queue(); +		$queue = new \queue();  		$queue->process();  	} diff --git a/phpBB/phpbb/cron/task/core/tidy_cache.php b/phpBB/phpbb/cron/task/core/tidy_cache.php index 16a45dae7c..021d5fd8a3 100644 --- a/phpBB/phpbb/cron/task/core/tidy_cache.php +++ b/phpBB/phpbb/cron/task/core/tidy_cache.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cron\task\core; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base +class tidy_cache extends \phpbb\cron\task\base  {  	protected $config;  	protected $cache; @@ -28,10 +30,10 @@ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base  	/**  	* Constructor.  	* -	* @param phpbb_config $config The config -	* @param phpbb_cache_driver_interface $cache The cache driver +	* @param \phpbb\config\config $config The config +	* @param \phpbb\cache\driver\driver_interface $cache The cache driver  	*/ -	public function __construct(phpbb_config $config, phpbb_cache_driver_interface $cache) +	public function __construct(\phpbb\config\config $config, \phpbb\cache\driver\driver_interface $cache)  	{  		$this->config = $config;  		$this->cache = $cache; diff --git a/phpBB/phpbb/cron/task/core/tidy_database.php b/phpBB/phpbb/cron/task/core/tidy_database.php index b882e7b500..d03cba1d86 100644 --- a/phpBB/phpbb/cron/task/core/tidy_database.php +++ b/phpBB/phpbb/cron/task/core/tidy_database.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cron\task\core; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base +class tidy_database extends \phpbb\cron\task\base  {  	protected $phpbb_root_path;  	protected $php_ext; @@ -31,9 +33,9 @@ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base  	*  	* @param string $phpbb_root_path The root path  	* @param string $php_ext The PHP extension -	* @param phpbb_config $config The config +	* @param \phpbb\config\config $config The config  	*/ -	public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) +	public function __construct($phpbb_root_path, $php_ext, \phpbb\config\config $config)  	{  		$this->phpbb_root_path = $phpbb_root_path;  		$this->php_ext = $php_ext; diff --git a/phpBB/phpbb/cron/task/core/tidy_search.php b/phpBB/phpbb/cron/task/core/tidy_search.php index a3d5b7dbd2..ebd0d86cbc 100644 --- a/phpBB/phpbb/cron/task/core/tidy_search.php +++ b/phpBB/phpbb/cron/task/core/tidy_search.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cron\task\core; +  /**  * @ignore  */ @@ -22,7 +24,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base +class tidy_search extends \phpbb\cron\task\base  {  	protected $phpbb_root_path;  	protected $php_ext; @@ -36,12 +38,12 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base  	*  	* @param string $phpbb_root_path The root path  	* @param string $php_ext The PHP extension -	* @param phpbb_auth $auth The auth -	* @param phpbb_config $config The config -	* @param phpbb_db_driver $db The db connection -	* @param phpbb_user $user The user +	* @param \phpbb\auth\auth $auth The auth +	* @param \phpbb\config\config $config The config +	* @param \phpbb\db\driver\driver $db The db connection +	* @param \phpbb\user $user The user  	*/ -	public function __construct($phpbb_root_path, $php_ext, phpbb_auth $auth, phpbb_config $config, phpbb_db_driver $db, phpbb_user $user) +	public function __construct($phpbb_root_path, $php_ext, \phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\db\driver\driver $db, \phpbb\user $user)  	{  		$this->phpbb_root_path = $phpbb_root_path;  		$this->php_ext = $php_ext; diff --git a/phpBB/phpbb/cron/task/core/tidy_sessions.php b/phpBB/phpbb/cron/task/core/tidy_sessions.php index 95f55235c9..5df019ae46 100644 --- a/phpBB/phpbb/cron/task/core/tidy_sessions.php +++ b/phpBB/phpbb/cron/task/core/tidy_sessions.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cron\task\core; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base +class tidy_sessions extends \phpbb\cron\task\base  {  	protected $config;  	protected $user; @@ -28,10 +30,10 @@ class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base  	/**  	* Constructor.  	* -	* @param phpbb_config $config The config -	* @param phpbb_user $user The user +	* @param \phpbb\config\config $config The config +	* @param \phpbb\user $user The user  	*/ -	public function __construct(phpbb_config $config, phpbb_user $user) +	public function __construct(\phpbb\config\config $config, \phpbb\user $user)  	{  		$this->config = $config;  		$this->user = $user; diff --git a/phpBB/phpbb/cron/task/core/tidy_warnings.php b/phpBB/phpbb/cron/task/core/tidy_warnings.php index 2a7798e56e..1cc0abbe88 100644 --- a/phpBB/phpbb/cron/task/core/tidy_warnings.php +++ b/phpBB/phpbb/cron/task/core/tidy_warnings.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cron\task\core; +  /**  * @ignore  */ @@ -22,7 +24,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base +class tidy_warnings extends \phpbb\cron\task\base  {  	protected $phpbb_root_path;  	protected $php_ext; @@ -33,9 +35,9 @@ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base  	*  	* @param string $phpbb_root_path The root path  	* @param string $php_ext The PHP extension -	* @param phpbb_config $config The config +	* @param \phpbb\config\config $config The config  	*/ -	public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) +	public function __construct($phpbb_root_path, $php_ext, \phpbb\config\config $config)  	{  		$this->phpbb_root_path = $phpbb_root_path;  		$this->php_ext = $php_ext; diff --git a/phpBB/phpbb/cron/task/parametrized.php b/phpBB/phpbb/cron/task/parametrized.php index 5f0e46eafc..1d2f449c58 100644 --- a/phpBB/phpbb/cron/task/parametrized.php +++ b/phpBB/phpbb/cron/task/parametrized.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cron\task; +  /**  * @ignore  */ @@ -26,7 +28,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -interface phpbb_cron_task_parametrized extends phpbb_cron_task +interface parametrized extends \phpbb\cron\task\task  {  	/**  	* Returns parameters of this cron task as an array. @@ -39,14 +41,14 @@ interface phpbb_cron_task_parametrized extends phpbb_cron_task  	/**  	* Parses parameters found in $request, which is an instance of -	* phpbb_request_interface. +	* \phpbb\request\request_interface.  	*  	* $request contains user input and must not be trusted.  	* Cron task must validate all data before using it.  	* -	* @param phpbb_request_interface $request Request object. +	* @param \phpbb\request\request_interface $request Request object.  	*  	* @return null  	*/ -	public function parse_parameters(phpbb_request_interface $request); +	public function parse_parameters(\phpbb\request\request_interface $request);  } diff --git a/phpBB/phpbb/cron/task/task.php b/phpBB/phpbb/cron/task/task.php index 2d585df96d..84218c4fc9 100644 --- a/phpBB/phpbb/cron/task/task.php +++ b/phpBB/phpbb/cron/task/task.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cron\task; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * Cron task interface  * @package phpBB3  */ -interface phpbb_cron_task +interface task  {  	/**  	* Returns the name of the task. diff --git a/phpBB/phpbb/cron/task/wrapper.php b/phpBB/phpbb/cron/task/wrapper.php index 386fb5b383..aa015966c6 100644 --- a/phpBB/phpbb/cron/task/wrapper.php +++ b/phpBB/phpbb/cron/task/wrapper.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\cron\task; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_cron_task_wrapper +class wrapper  {  	protected $task;  	protected $phpbb_root_path; @@ -32,9 +34,9 @@ class phpbb_cron_task_wrapper  	*  	* Wraps a task $task, which must implement cron_task interface.  	* -	* @param phpbb_cron_task $task The cron task to wrap. +	* @param \phpbb\cron\task\task $task The cron task to wrap.  	*/ -	public function __construct(phpbb_cron_task $task, $phpbb_root_path, $php_ext) +	public function __construct(\phpbb\cron\task\task $task, $phpbb_root_path, $php_ext)  	{  		$this->task = $task;  		$this->phpbb_root_path = $phpbb_root_path; @@ -51,7 +53,7 @@ class phpbb_cron_task_wrapper  	*/  	public function is_parametrized()  	{ -		return $this->task instanceof phpbb_cron_task_parametrized; +		return $this->task instanceof \phpbb\cron\task\parametrized;  	}  	/** diff --git a/phpBB/phpbb/datetime.php b/phpBB/phpbb/datetime.php index 3c6d4971b9..84b13202af 100644 --- a/phpBB/phpbb/datetime.php +++ b/phpBB/phpbb/datetime.php @@ -6,11 +6,13 @@  * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2  */ +namespace phpbb; +  /**  * phpBB custom extensions to the PHP DateTime class  * This handles the relative formats phpBB employs  */ -class phpbb_datetime extends DateTime +class datetime extends \DateTime  {  	/**  	* String used to wrap the date segment which should be replaced by today/tomorrow/yesterday @@ -28,14 +30,14 @@ class phpbb_datetime extends DateTime  	static protected $format_cache = array();  	/** -	* Constructs a new instance of phpbb_datetime, expanded to include an argument to inject +	* Constructs a new instance of \phpbb\datetime, expanded to include an argument to inject  	* the user context and modify the timezone to the users selected timezone if one is not set.  	*  	* @param string $time String in a format accepted by strtotime().  	* @param DateTimeZone $timezone Time zone of the time.  	* @param user User object for context.  	*/ -	public function __construct($user, $time = 'now', DateTimeZone $timezone = null) +	public function __construct($user, $time = 'now', \DateTimeZone $timezone = null)  	{  		$this->user	= $user;  		$timezone	= $timezone ?: $this->user->timezone; diff --git a/phpBB/phpbb/db/driver/driver.php b/phpBB/phpbb/db/driver/driver.php index 08c966c07a..53d39e9127 100644 --- a/phpBB/phpbb/db/driver/driver.php +++ b/phpBB/phpbb/db/driver/driver.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\db\driver; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * Database Abstraction Layer  * @package dbal  */ -class phpbb_db_driver +class driver  {  	var $db_connect_id;  	var $query_result; @@ -82,7 +84,7 @@ class phpbb_db_driver  		// Fill default sql layer based on the class being called.  		// This can be changed by the specified layer itself later if needed. -		$this->sql_layer = substr(get_class($this), strlen('phpbb_db_driver_')); +		$this->sql_layer = substr(get_class($this), strlen('phpbb\db\driver\\'));  		// Do not change this please! This variable is used to easy the use of it - and is hardcoded.  		$this->any_char = chr(0) . '%'; diff --git a/phpBB/phpbb/db/driver/firebird.php b/phpBB/phpbb/db/driver/firebird.php index 787c28b812..2df5eaf369 100644 --- a/phpBB/phpbb/db/driver/firebird.php +++ b/phpBB/phpbb/db/driver/firebird.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\db\driver; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  * Minimum Requirement is Firebird 2.1  * @package dbal  */ -class phpbb_db_driver_firebird extends phpbb_db_driver +class firebird extends \phpbb\db\driver\driver  {  	var $last_query_text = '';  	var $service_handle = false; diff --git a/phpBB/phpbb/db/driver/mssql.php b/phpBB/phpbb/db/driver/mssql.php index 89c2c2351b..4d2cd287da 100644 --- a/phpBB/phpbb/db/driver/mssql.php +++ b/phpBB/phpbb/db/driver/mssql.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\db\driver; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  * Minimum Requirement is MSSQL 2000+  * @package dbal  */ -class phpbb_db_driver_mssql extends phpbb_db_driver +class mssql extends \phpbb\db\driver\driver  {  	var $connect_error = ''; diff --git a/phpBB/phpbb/db/driver/mssql_base.php b/phpBB/phpbb/db/driver/mssql_base.php index 56c111c871..57c4e0f1fd 100644 --- a/phpBB/phpbb/db/driver/mssql_base.php +++ b/phpBB/phpbb/db/driver/mssql_base.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\db\driver; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * MSSQL Database Base Abstraction Layer  * @package dbal   */ -abstract class phpbb_db_driver_mssql_base extends phpbb_db_driver +abstract class mssql_base extends \phpbb\db\driver\driver  {  	/**  	* {@inheritDoc} diff --git a/phpBB/phpbb/db/driver/mssql_odbc.php b/phpBB/phpbb/db/driver/mssql_odbc.php index a1d1a5d5dd..9db34a69fb 100644 --- a/phpBB/phpbb/db/driver/mssql_odbc.php +++ b/phpBB/phpbb/db/driver/mssql_odbc.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\db\driver; +  /**  * @ignore  */ @@ -26,7 +28,7 @@ if (!defined('IN_PHPBB'))  *  * @package dbal  */ -class phpbb_db_driver_mssql_odbc extends phpbb_db_driver_mssql_base +class mssql_odbc extends \phpbb\db\driver\mssql_base  {  	var $last_query_text = '';  	var $connect_error = ''; diff --git a/phpBB/phpbb/db/driver/mssqlnative.php b/phpBB/phpbb/db/driver/mssqlnative.php index 28fc88298a..e6002fe1a3 100644 --- a/phpBB/phpbb/db/driver/mssqlnative.php +++ b/phpBB/phpbb/db/driver/mssqlnative.php @@ -11,6 +11,8 @@  *  */ +namespace phpbb\db\driver; +  /**  * @ignore  */ @@ -56,7 +58,7 @@ class result_mssqlnative  		{  			if (is_array($value))  			{ -				$obj->$key = new stdClass(); +				$obj->$key = new \stdClass();  				array_to_obj($value, $obj->$key);  			}  			else @@ -191,7 +193,7 @@ class result_mssqlnative  /**  * @package dbal  */ -class phpbb_db_driver_mssqlnative extends phpbb_db_driver_mssql_base +class mssqlnative extends \phpbb\db\driver\mssql_base  {  	var $m_insert_id = NULL;  	var $last_query_text = ''; diff --git a/phpBB/phpbb/db/driver/mysql.php b/phpBB/phpbb/db/driver/mysql.php index f3744ac09d..c76126763d 100644 --- a/phpBB/phpbb/db/driver/mysql.php +++ b/phpBB/phpbb/db/driver/mysql.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\db\driver; +  /**  * @ignore  */ @@ -24,7 +26,7 @@ if (!defined('IN_PHPBB'))  * MySQL 5.0+  * @package dbal  */ -class phpbb_db_driver_mysql extends phpbb_db_driver_mysql_base +class mysql extends \phpbb\db\driver\mysql_base  {  	var $multi_insert = true;  	var $connect_error = ''; diff --git a/phpBB/phpbb/db/driver/mysql_base.php b/phpBB/phpbb/db/driver/mysql_base.php index ba44ea61aa..8f2f66674b 100644 --- a/phpBB/phpbb/db/driver/mysql_base.php +++ b/phpBB/phpbb/db/driver/mysql_base.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\db\driver; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * Abstract MySQL Database Base Abstraction Layer  * @package dbal  */ -abstract class phpbb_db_driver_mysql_base extends phpbb_db_driver +abstract class mysql_base extends \phpbb\db\driver\driver  {  	/**  	* {@inheritDoc} diff --git a/phpBB/phpbb/db/driver/mysqli.php b/phpBB/phpbb/db/driver/mysqli.php index 0f7a73ee6e..4d0e43b464 100644 --- a/phpBB/phpbb/db/driver/mysqli.php +++ b/phpBB/phpbb/db/driver/mysqli.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\db\driver; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  * MySQL 4.1+ or MySQL 5.0+  * @package dbal  */ -class phpbb_db_driver_mysqli extends phpbb_db_driver_mysql_base +class mysqli extends \phpbb\db\driver\mysql_base  {  	var $multi_insert = true;  	var $connect_error = ''; diff --git a/phpBB/phpbb/db/driver/oracle.php b/phpBB/phpbb/db/driver/oracle.php index e21e07055d..5dfab21455 100644 --- a/phpBB/phpbb/db/driver/oracle.php +++ b/phpBB/phpbb/db/driver/oracle.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\db\driver; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * Oracle Database Abstraction Layer  * @package dbal  */ -class phpbb_db_driver_oracle extends phpbb_db_driver +class oracle extends \phpbb\db\driver\driver  {  	var $last_query_text = '';  	var $connect_error = ''; diff --git a/phpBB/phpbb/db/driver/postgres.php b/phpBB/phpbb/db/driver/postgres.php index 14854d179d..7a98b90c73 100644 --- a/phpBB/phpbb/db/driver/postgres.php +++ b/phpBB/phpbb/db/driver/postgres.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\db\driver; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  * Minimum Requirement is Version 7.3+  * @package dbal  */ -class phpbb_db_driver_postgres extends phpbb_db_driver +class postgres extends \phpbb\db\driver\driver  {  	var $last_query_text = '';  	var $connect_error = ''; @@ -84,7 +86,7 @@ class phpbb_db_driver_postgres extends phpbb_db_driver  				$this->connect_error = 'pg_pconnect function does not exist, is pgsql extension installed?';  				return $this->sql_error('');  			} -			$collector = new phpbb_error_collector; +			$collector = new \phpbb\error_collector;  			$collector->install();  			$this->db_connect_id = (!$new_link) ? @pg_pconnect($connect_string) : @pg_pconnect($connect_string, PGSQL_CONNECT_FORCE_NEW);  		} @@ -95,7 +97,7 @@ class phpbb_db_driver_postgres extends phpbb_db_driver  				$this->connect_error = 'pg_connect function does not exist, is pgsql extension installed?';  				return $this->sql_error('');  			} -			$collector = new phpbb_error_collector; +			$collector = new \phpbb\error_collector;  			$collector->install();  			$this->db_connect_id = (!$new_link) ? @pg_connect($connect_string) : @pg_connect($connect_string, PGSQL_CONNECT_FORCE_NEW);  		} diff --git a/phpBB/phpbb/db/driver/sqlite.php b/phpBB/phpbb/db/driver/sqlite.php index 7188f0daa2..a548fd2618 100644 --- a/phpBB/phpbb/db/driver/sqlite.php +++ b/phpBB/phpbb/db/driver/sqlite.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\db\driver; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  * Minimum Requirement: 2.8.2+  * @package dbal  */ -class phpbb_db_driver_sqlite extends phpbb_db_driver +class sqlite extends \phpbb\db\driver\driver  {  	var $connect_error = ''; diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_10_rc2.php b/phpBB/phpbb/db/migration/data/30x/3_0_10_rc2.php deleted file mode 100644 index b14b3b00aa..0000000000 --- a/phpBB/phpbb/db/migration/data/30x/3_0_10_rc2.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php -/** -* -* @package migration -* @copyright (c) 2012 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 -* -*/ - -class phpbb_db_migration_data_30x_3_0_10_rc2 extends phpbb_db_migration -{ -	public function effectively_installed() -	{ -		return version_compare($this->config['version'], '3.0.10-rc2', '>='); -	} - -	static public function depends_on() -	{ -		return array('phpbb_db_migration_data_30x_3_0_10_rc1'); -	} - -	public function update_data() -	{ -		return array( -			array('config.update', array('version', '3.0.10-rc2')), -		); -	} -} diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_10_rc3.php b/phpBB/phpbb/db/migration/data/30x/3_0_10_rc3.php deleted file mode 100644 index 473057d65d..0000000000 --- a/phpBB/phpbb/db/migration/data/30x/3_0_10_rc3.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php -/** -* -* @package migration -* @copyright (c) 2012 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 -* -*/ - -class phpbb_db_migration_data_30x_3_0_10_rc3 extends phpbb_db_migration -{ -	public function effectively_installed() -	{ -		return version_compare($this->config['version'], '3.0.10-rc3', '>='); -	} - -	static public function depends_on() -	{ -		return array('phpbb_db_migration_data_30x_3_0_10_rc2'); -	} - -	public function update_data() -	{ -		return array( -			array('config.update', array('version', '3.0.10-rc3')), -		); -	} -} diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_6_rc2.php b/phpBB/phpbb/db/migration/data/30x/3_0_6_rc2.php deleted file mode 100644 index a939dbd489..0000000000 --- a/phpBB/phpbb/db/migration/data/30x/3_0_6_rc2.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php -/** -* -* @package migration -* @copyright (c) 2012 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 -* -*/ - -class phpbb_db_migration_data_30x_3_0_6_rc2 extends phpbb_db_migration -{ -	public function effectively_installed() -	{ -		return version_compare($this->config['version'], '3.0.6-rc2', '>='); -	} - -	static public function depends_on() -	{ -		return array('phpbb_db_migration_data_30x_3_0_6_rc1'); -	} - -	public function update_data() -	{ -		return array( -			array('config.update', array('version', '3.0.6-rc2')), -		); -	} -} diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_6_rc4.php b/phpBB/phpbb/db/migration/data/30x/3_0_6_rc4.php deleted file mode 100644 index fc2923f99b..0000000000 --- a/phpBB/phpbb/db/migration/data/30x/3_0_6_rc4.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php -/** -* -* @package migration -* @copyright (c) 2012 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 -* -*/ - -class phpbb_db_migration_data_30x_3_0_6_rc4 extends phpbb_db_migration -{ -	public function effectively_installed() -	{ -		return version_compare($this->config['version'], '3.0.6-rc4', '>='); -	} - -	static public function depends_on() -	{ -		return array('phpbb_db_migration_data_30x_3_0_6_rc3'); -	} - -	public function update_data() -	{ -		return array( -			array('config.update', array('version', '3.0.6-rc4')), -		); -	} -} diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_9_rc2.php b/phpBB/phpbb/db/migration/data/30x/3_0_9_rc2.php deleted file mode 100644 index c0e662aa45..0000000000 --- a/phpBB/phpbb/db/migration/data/30x/3_0_9_rc2.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php -/** -* -* @package migration -* @copyright (c) 2012 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 -* -*/ - -class phpbb_db_migration_data_30x_3_0_9_rc2 extends phpbb_db_migration -{ -	public function effectively_installed() -	{ -		return version_compare($this->config['version'], '3.0.9-rc2', '>='); -	} - -	static public function depends_on() -	{ -		return array('phpbb_db_migration_data_30x_3_0_9_rc1'); -	} - -	public function update_data() -	{ -		return array( -			array('config.update', array('version', '3.0.9-rc2')), -		); -	} -} diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_9_rc3.php b/phpBB/phpbb/db/migration/data/30x/3_0_9_rc3.php deleted file mode 100644 index d6d1f14b2e..0000000000 --- a/phpBB/phpbb/db/migration/data/30x/3_0_9_rc3.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php -/** -* -* @package migration -* @copyright (c) 2012 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 -* -*/ - -class phpbb_db_migration_data_30x_3_0_9_rc3 extends phpbb_db_migration -{ -	public function effectively_installed() -	{ -		return version_compare($this->config['version'], '3.0.9-rc3', '>='); -	} - -	static public function depends_on() -	{ -		return array('phpbb_db_migration_data_30x_3_0_9_rc2'); -	} - -	public function update_data() -	{ -		return array( -			array('config.update', array('version', '3.0.9-rc3')), -		); -	} -} diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_9_rc4.php b/phpBB/phpbb/db/migration/data/30x/3_0_9_rc4.php deleted file mode 100644 index e673249343..0000000000 --- a/phpBB/phpbb/db/migration/data/30x/3_0_9_rc4.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php -/** -* -* @package migration -* @copyright (c) 2012 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 -* -*/ - -class phpbb_db_migration_data_30x_3_0_9_rc4 extends phpbb_db_migration -{ -	public function effectively_installed() -	{ -		return version_compare($this->config['version'], '3.0.9-rc4', '>='); -	} - -	static public function depends_on() -	{ -		return array('phpbb_db_migration_data_30x_3_0_9_rc3'); -	} - -	public function update_data() -	{ -		return array( -			array('config.update', array('version', '3.0.9-rc4')), -		); -	} -} diff --git a/phpBB/phpbb/db/migration/data/30x/local_url_bbcode.php b/phpBB/phpbb/db/migration/data/v30x/local_url_bbcode.php index f324b8880d..5e6ba90336 100644 --- a/phpBB/phpbb/db/migration/data/30x/local_url_bbcode.php +++ b/phpBB/phpbb/db/migration/data/v30x/local_url_bbcode.php @@ -7,11 +7,13 @@  *  */ -class phpbb_db_migration_data_30x_local_url_bbcode extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class local_url_bbcode extends \phpbb\db\migration\migration  {  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_12_rc1'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_12_rc1');  	}  	public function update_data() @@ -44,7 +46,7 @@ class phpbb_db_migration_data_30x_local_url_bbcode extends phpbb_db_migration  			$bbcode_match = $row['bbcode_match'];  			$bbcode_tpl = $row['bbcode_tpl']; -			$acp_bbcodes = new acp_bbcodes(); +			$acp_bbcodes = new \acp_bbcodes();  			$sql_ary = $acp_bbcodes->build_regexp($bbcode_match, $bbcode_tpl);  			$sql = 'UPDATE ' . BBCODES_TABLE . ' diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_1.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_1.php index c996a0138a..aed0f2784b 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_1.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_1.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_1 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_1 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.1', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.1', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_1_rc1'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_1_rc1');  	}  	public function update_data() diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_10.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_10.php index 122f93d6b4..305309c3bd 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_10.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_10.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_10 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_10 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.10', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.10', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_10_rc3'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_10_rc3');  	}  	public function update_data() diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_10_rc1.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_10_rc1.php index 0ed05812dc..fb50d67fb5 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_10_rc1.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_10_rc1.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_10_rc1 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_10_rc1 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.10-rc1', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.10-RC1', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_9'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_9');  	}  	public function update_data() @@ -24,7 +26,7 @@ class phpbb_db_migration_data_30x_3_0_10_rc1 extends phpbb_db_migration  		return array(  			array('config.add', array('email_max_chunk_size', 50)), -			array('config.update', array('version', '3.0.10-rc1')), +			array('config.update', array('version', '3.0.10-RC1')),  		);  	}  } diff --git a/phpBB/phpbb/db/migration/data/v30x/release_3_0_10_rc2.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_10_rc2.php new file mode 100644 index 0000000000..63ba1e8fc2 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_10_rc2.php @@ -0,0 +1,30 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +namespace phpbb\db\migration\data\v30x; + +class release_3_0_10_rc2 extends \phpbb\db\migration\migration +{ +	public function effectively_installed() +	{ +		return phpbb_version_compare($this->config['version'], '3.0.10-RC2', '>='); +	} + +	static public function depends_on() +	{ +		return array('\phpbb\db\migration\data\v30x\release_3_0_10_rc1'); +	} + +	public function update_data() +	{ +		return array( +			array('config.update', array('version', '3.0.10-RC2')), +		); +	} +} diff --git a/phpBB/phpbb/db/migration/data/v30x/release_3_0_10_rc3.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_10_rc3.php new file mode 100644 index 0000000000..7055063032 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_10_rc3.php @@ -0,0 +1,30 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +namespace phpbb\db\migration\data\v30x; + +class release_3_0_10_rc3 extends \phpbb\db\migration\migration +{ +	public function effectively_installed() +	{ +		return phpbb_version_compare($this->config['version'], '3.0.10-RC3', '>='); +	} + +	static public function depends_on() +	{ +		return array('\phpbb\db\migration\data\v30x\release_3_0_10_rc2'); +	} + +	public function update_data() +	{ +		return array( +			array('config.update', array('version', '3.0.10-RC3')), +		); +	} +} diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_11.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_11.php index e063c699cc..1246597efb 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_11.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_11.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_11 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_11 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.11', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.11', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_11_rc2'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_11_rc2');  	}  	public function update_data() diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_11_rc1.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_11_rc1.php index dddfc0e0e7..7e284235e1 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_11_rc1.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_11_rc1.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_11_rc1 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_11_rc1 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.11-rc1', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.11-RC1', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_10'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_10');  	}  	public function update_data() @@ -25,7 +27,7 @@ class phpbb_db_migration_data_30x_3_0_11_rc1 extends phpbb_db_migration  			array('custom', array(array(&$this, 'cleanup_deactivated_styles'))),  			array('custom', array(array(&$this, 'delete_orphan_private_messages'))), -			array('config.update', array('version', '3.0.11-rc1')), +			array('config.update', array('version', '3.0.11-RC1')),  		);  	} diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_11_rc2.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_11_rc2.php index fac8523e8c..017038855d 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_11_rc2.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_11_rc2.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_11_rc2 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_11_rc2 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.11-rc2', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.11-RC2', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_11_rc1'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_11_rc1');  	}  	public function update_schema() @@ -44,7 +46,7 @@ class phpbb_db_migration_data_30x_3_0_11_rc2 extends phpbb_db_migration  	public function update_data()  	{  		return array( -			array('config.update', array('version', '3.0.11-rc2')), +			array('config.update', array('version', '3.0.11-RC2')),  		);  	}  } diff --git a/phpBB/phpbb/db/migration/data/v30x/release_3_0_12.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_12.php new file mode 100644 index 0000000000..5a2d569724 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_12.php @@ -0,0 +1,33 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +namespace phpbb\db\migration\data\v30x; + +class release_3_0_12 extends \phpbb\db\migration\migration +{ +	public function effectively_installed() +	{ +		return phpbb_version_compare($this->config['version'], '3.0.12', '>=') && phpbb_version_compare($this->config['version'], '3.1.0-dev', '<'); +	} + +	static public function depends_on() +	{ +		return array('\phpbb\db\migration\data\v30x\release_3_0_12_rc3'); +	} + +	public function update_data() +	{ +		return array( +			array('if', array( +				phpbb_version_compare($this->config['version'], '3.0.12', '<'), +				array('config.update', array('version', '3.0.12')), +			)), +		); +	} +} diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_12_rc1.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_12_rc1.php index 6a31a51201..35a3015959 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_12_rc1.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_12_rc1.php @@ -7,18 +7,20 @@  *  */ +namespace phpbb\db\migration\data\v30x; +  /** @todo DROP LOGIN_ATTEMPT_TABLE.attempt_id in 3.0.12-RC1 **/ -class phpbb_db_migration_data_30x_3_0_12_rc1 extends phpbb_db_migration +class release_3_0_12_rc1 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.12-rc1', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.12-RC1', '>=');  	} - 	static public function depends_on() +	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_11'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_11');  	}  	public function update_data() @@ -28,7 +30,7 @@ class phpbb_db_migration_data_30x_3_0_12_rc1 extends phpbb_db_migration  			array('custom', array(array(&$this, 'update_bots'))),  			array('custom', array(array(&$this, 'disable_bots_from_receiving_pms'))), -			array('config.update', array('version', '3.0.12-rc1')), +			array('config.update', array('version', '3.0.12-RC1')),  		);  	} @@ -108,7 +110,7 @@ class phpbb_db_migration_data_30x_3_0_12_rc1 extends phpbb_db_migration  						WHERE user_id = $bot_user_id";  					$this->sql_query($sql); -					user_delete('remove', $bot_user_id); +					user_delete('retain', $bot_user_id);  				}  				else  				{ diff --git a/phpBB/phpbb/db/migration/data/v30x/release_3_0_12_rc2.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_12_rc2.php new file mode 100644 index 0000000000..3edb578fc8 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_12_rc2.php @@ -0,0 +1,33 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +namespace phpbb\db\migration\data\v30x; + +class release_3_0_12_rc2 extends \phpbb\db\migration\migration +{ +	public function effectively_installed() +	{ +		return phpbb_version_compare($this->config['version'], '3.0.12-RC2', '>=') && phpbb_version_compare($this->config['version'], '3.1.0-dev', '<'); +	} + +	static public function depends_on() +	{ +		return array('\phpbb\db\migration\data\v30x\release_3_0_12_rc1'); +	} + +	public function update_data() +	{ +		return array( +			array('if', array( +				phpbb_version_compare($this->config['version'], '3.0.12-RC2', '<'), +				array('config.update', array('version', '3.0.12-RC2')), +			)), +		); +	} +} diff --git a/phpBB/phpbb/db/migration/data/v30x/release_3_0_12_rc3.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_12_rc3.php new file mode 100644 index 0000000000..510693a5b7 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_12_rc3.php @@ -0,0 +1,33 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +namespace phpbb\db\migration\data\v30x; + +class release_3_0_12_rc3 extends \phpbb\db\migration\migration +{ +	public function effectively_installed() +	{ +		return phpbb_version_compare($this->config['version'], '3.0.12-RC3', '>=') && phpbb_version_compare($this->config['version'], '3.1.0-dev', '<'); +	} + +	static public function depends_on() +	{ +		return array('\phpbb\db\migration\data\v30x\release_3_0_12_rc2'); +	} + +	public function update_data() +	{ +		return array( +			array('if', array( +				phpbb_version_compare($this->config['version'], '3.0.12-RC3', '<'), +				array('config.update', array('version', '3.0.12-RC3')), +			)), +		); +	} +} diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_1_rc1.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_1_rc1.php index 562ccf077c..862276528d 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_1_rc1.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_1_rc1.php @@ -7,11 +7,13 @@  *  */ -class phpbb_db_migration_data_30x_3_0_1_rc1 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_1_rc1 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.1-rc1', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.1-RC1', '>=');  	}  	public function update_schema() @@ -74,7 +76,7 @@ class phpbb_db_migration_data_30x_3_0_1_rc1 extends phpbb_db_migration  			array('custom', array(array(&$this, 'fix_unset_last_view_time'))),  			array('custom', array(array(&$this, 'reset_smiley_size'))), -			array('config.update', array('version', '3.0.1-rc1')), +			array('config.update', array('version', '3.0.1-RC1')),  		);  	} diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_2.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_2.php index eed5acef82..7e2a08590e 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_2.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_2.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_2 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_2 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.2', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.2', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_2_rc2'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_2_rc2');  	}  	public function update_data() diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_2_rc1.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_2_rc1.php index a960e90765..7a856383e2 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_2_rc1.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_2_rc1.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_2_rc1 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_2_rc1 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.2-rc1', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.2-RC1', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_1'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_1');  	}  	public function update_data() @@ -26,7 +28,7 @@ class phpbb_db_migration_data_30x_3_0_2_rc1 extends phpbb_db_migration  			array('config.add', array('check_attachment_content', '1')),  			array('config.add', array('mime_triggers', 'body|head|html|img|plaintext|a href|pre|script|table|title')), -			array('config.update', array('version', '3.0.2-rc1')), +			array('config.update', array('version', '3.0.2-RC1')),  		);  	}  } diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_2_rc2.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_2_rc2.php index 8917dfea77..61562575eb 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_2_rc2.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_2_rc2.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_2_rc2 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_2_rc2 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.2-rc2', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.2-RC2', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_2_rc1'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_2_rc1');  	}  	public function update_schema() @@ -74,7 +76,7 @@ class phpbb_db_migration_data_30x_3_0_2_rc2 extends phpbb_db_migration  	public function update_data()  	{  		return array( -			array('config.update', array('version', '3.0.2-rc2')), +			array('config.update', array('version', '3.0.2-RC2')),  		);  	}  } diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_3.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_3.php index 8984cf7b76..b2adbeaa43 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_3.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_3.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_3 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_3 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.3', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.3', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_3_rc1'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_3_rc1');  	}  	public function update_data() diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_3_rc1.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_3_rc1.php index 4b102e1a2e..57bd59bba3 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_3_rc1.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_3_rc1.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_3_rc1 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_3_rc1 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.3-rc1', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.3-RC1', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_2'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_2');  	}  	public function update_schema() @@ -60,7 +62,7 @@ class phpbb_db_migration_data_30x_3_0_3_rc1 extends phpbb_db_migration  			array('permission.add', array('u_masspm_group', true, 'u_masspm')),  			array('custom', array(array(&$this, 'correct_acp_email_permissions'))), -			array('config.update', array('version', '3.0.3-rc1')), +			array('config.update', array('version', '3.0.3-RC1')),  		);  	} diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_4.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_4.php index 9a0c132e78..5d6140393b 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_4.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_4.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_4 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_4 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.4', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.4', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_4_rc1'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_4_rc1');  	}  	public function update_data() diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_4_rc1.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_4_rc1.php index 8ad75a557b..a8af4dd76c 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_4_rc1.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_4_rc1.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_4_rc1 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_4_rc1 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.4-rc1', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.4-RC1', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_3'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_3');  	}  	public function update_schema() @@ -76,13 +78,13 @@ class phpbb_db_migration_data_30x_3_0_4_rc1 extends phpbb_db_migration  		return array(  			array('custom', array(array(&$this, 'update_custom_profile_fields'))), -			array('config.update', array('version', '3.0.4-rc1')), +			array('config.update', array('version', '3.0.4-RC1')),  		);  	}  	public function update_custom_profile_fields()  	{ -		// Update the Custom Profile Fields based on previous settings to the new format +		// Update the Custom Profile Fields based on previous settings to the new \format  		$sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide  				FROM ' . PROFILE_FIELDS_TABLE;  		$result = $this->db->sql_query($sql); diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_5.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_5.php index 16d2dee457..7bbe7ffed9 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_5.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_5.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_5 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_5 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.5', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.5', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_5_rc1part2'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_5_rc1part2');  	}  	public function update_data() diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_5_rc1.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_5_rc1.php index ea17cc1e31..ffe2c6a44d 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_5_rc1.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_5_rc1.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_5_rc1 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_5_rc1 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.5-rc1', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.5-RC1', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_4'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_4');  	}  	public function update_schema() diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_5_rc1part2.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_5_rc1part2.php index 8538347b1a..04b14b5189 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_5_rc1part2.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_5_rc1part2.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_5_rc1part2 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_5_rc1part2 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.5-rc1', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.5-RC1', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_5_rc1'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_5_rc1');  	}  	public function update_schema() @@ -36,7 +38,7 @@ class phpbb_db_migration_data_30x_3_0_5_rc1part2 extends phpbb_db_migration  	public function update_data()  	{  		return array( -			array('config.update', array('version', '3.0.5-rc1')), +			array('config.update', array('version', '3.0.5-RC1')),  		);  	}  } diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_6.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_6.php index bb651dc7cd..85ea2e9d20 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_6.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_6.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_6 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_6 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.6', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.6', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_6_rc4'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_6_rc4');  	}  	public function update_data() diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_6_rc1.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_6_rc1.php index 38c282ebf0..87d5e490f8 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_6_rc1.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_6_rc1.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_6_rc1 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_6_rc1 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.6-rc1', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.6-RC1', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_5'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_5');  	}  	public function update_schema() @@ -185,7 +187,7 @@ class phpbb_db_migration_data_30x_3_0_6_rc1 extends phpbb_db_migration  			array('custom', array(array(&$this, 'add_newly_registered_group'))),  			array('custom', array(array(&$this, 'set_user_options_default'))), -			array('config.update', array('version', '3.0.6-rc1')), +			array('config.update', array('version', '3.0.6-RC1')),  		);  	} @@ -318,7 +320,7 @@ class phpbb_db_migration_data_30x_3_0_6_rc1 extends phpbb_db_migration  		// Clear permissions...  		include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext); -		$auth_admin = new auth_admin(); +		$auth_admin = new \auth_admin();  		$auth_admin->acl_clear_prefetch();  	}  } diff --git a/phpBB/phpbb/db/migration/data/v30x/release_3_0_6_rc2.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_6_rc2.php new file mode 100644 index 0000000000..7a0ef28601 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_6_rc2.php @@ -0,0 +1,30 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +namespace phpbb\db\migration\data\v30x; + +class release_3_0_6_rc2 extends \phpbb\db\migration\migration +{ +	public function effectively_installed() +	{ +		return phpbb_version_compare($this->config['version'], '3.0.6-RC2', '>='); +	} + +	static public function depends_on() +	{ +		return array('\phpbb\db\migration\data\v30x\release_3_0_6_rc1'); +	} + +	public function update_data() +	{ +		return array( +			array('config.update', array('version', '3.0.6-RC2')), +		); +	} +} diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_6_rc3.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_6_rc3.php index b3f09d8ab8..73a1fe9e6a 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_6_rc3.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_6_rc3.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_6_rc3 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_6_rc3 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.6-rc3', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.6-RC3', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_6_rc2'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_6_rc2');  	}  	public function update_data() @@ -24,13 +26,13 @@ class phpbb_db_migration_data_30x_3_0_6_rc3 extends phpbb_db_migration  		return array(  			array('custom', array(array(&$this, 'update_cp_fields'))), -			array('config.update', array('version', '3.0.6-rc3')), +			array('config.update', array('version', '3.0.6-RC3')),  		);  	}  	public function update_cp_fields()  	{ -		// Update the Custom Profile Fields based on previous settings to the new format +		// Update the Custom Profile Fields based on previous settings to the new \format  		$sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . '  			SET field_show_on_vt = 1  			WHERE field_hide = 0 diff --git a/phpBB/phpbb/db/migration/data/v30x/release_3_0_6_rc4.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_6_rc4.php new file mode 100644 index 0000000000..b6e5be2c2f --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_6_rc4.php @@ -0,0 +1,30 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +namespace phpbb\db\migration\data\v30x; + +class release_3_0_6_rc4 extends \phpbb\db\migration\migration +{ +	public function effectively_installed() +	{ +		return phpbb_version_compare($this->config['version'], '3.0.6-RC4', '>='); +	} + +	static public function depends_on() +	{ +		return array('\phpbb\db\migration\data\v30x\release_3_0_6_rc3'); +	} + +	public function update_data() +	{ +		return array( +			array('config.update', array('version', '3.0.6-RC4')), +		); +	} +} diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_7.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_7.php index 9ff2e9e4ab..2b0da30bc6 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_7.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_7.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_7 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_7 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.7', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.7', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_7_rc2'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_7_rc2');  	}  	public function update_data() diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_7_pl1.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_7_pl1.php index c9cc9d19ac..3547ee77e1 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_7_pl1.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_7_pl1.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_7_pl1 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_7_pl1 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.7-pl1', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.7-pl1', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_7'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_7');  	}  	public function update_data() diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_7_rc1.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_7_rc1.php index ffebf66f2d..de4d772808 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_7_rc1.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_7_rc1.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_7_rc1 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_7_rc1 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.7-rc1', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.7-RC1', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_6'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_6');  	}  	public function update_schema() @@ -62,7 +64,7 @@ class phpbb_db_migration_data_30x_3_0_7_rc1 extends phpbb_db_migration  			array('config.add', array('feed_topics_active', $this->config['feed_overall_topics'])),  			array('custom', array(array(&$this, 'delete_text_templates'))), -			array('config.update', array('version', '3.0.7-rc1')), +			array('config.update', array('version', '3.0.7-RC1')),  		);  	} diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_7_rc2.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_7_rc2.php index 55bc2bc679..800803a753 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_7_rc2.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_7_rc2.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_7_rc2 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_7_rc2 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.7-rc2', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.7-RC2', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_7_rc1'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_7_rc1');  	}  	public function update_data() @@ -24,7 +26,7 @@ class phpbb_db_migration_data_30x_3_0_7_rc2 extends phpbb_db_migration  		return array(  			array('custom', array(array(&$this, 'update_email_hash'))), -			array('config.update', array('version', '3.0.7-rc2')), +			array('config.update', array('version', '3.0.7-RC2')),  		);  	} diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_8.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_8.php index 8998ef9627..6c8b1df6fc 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_8.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_8.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_8 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_8 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.8', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.8', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_8_rc1'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_8_rc1');  	}  	public function update_data() diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_8_rc1.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_8_rc1.php index aeff35333e..1a14e5c961 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_8_rc1.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_8_rc1.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_8_rc1 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_8_rc1 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.8-rc1', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.8-RC1', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_7_pl1'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_7_pl1');  	}  	public function update_data() @@ -38,7 +40,7 @@ class phpbb_db_migration_data_30x_3_0_8_rc1 extends phpbb_db_migration  			array('config.update_if_equals', array(600, 'queue_interval', 60)),  			array('config.update_if_equals', array(50, 'email_package_size', 20)), -			array('config.update', array('version', '3.0.8-rc1')), +			array('config.update', array('version', '3.0.8-RC1')),  		);  	} diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_9.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_9.php index d5269ea6f0..9af2fce971 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_9.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_9.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_9 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_9 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.9', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.9', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_9_rc4'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_9_rc4');  	}  	public function update_data() diff --git a/phpBB/phpbb/db/migration/data/30x/3_0_9_rc1.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_9_rc1.php index 4c345b429b..3fb790bc0d 100644 --- a/phpBB/phpbb/db/migration/data/30x/3_0_9_rc1.php +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_9_rc1.php @@ -7,16 +7,18 @@  *  */ -class phpbb_db_migration_data_30x_3_0_9_rc1 extends phpbb_db_migration +namespace phpbb\db\migration\data\v30x; + +class release_3_0_9_rc1 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ -		return version_compare($this->config['version'], '3.0.9-rc1', '>='); +		return phpbb_version_compare($this->config['version'], '3.0.9-RC1', '>=');  	}  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_8'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_8');  	}  	public function update_schema() @@ -74,7 +76,7 @@ class phpbb_db_migration_data_30x_3_0_9_rc1 extends phpbb_db_migration  			array('custom', array(array(&$this, 'update_file_extension_group_names'))),  			array('custom', array(array(&$this, 'fix_firebird_qa_captcha'))), -			array('config.update', array('version', '3.0.9-rc1')), +			array('config.update', array('version', '3.0.9-RC1')),  		);  	} diff --git a/phpBB/phpbb/db/migration/data/v30x/release_3_0_9_rc2.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_9_rc2.php new file mode 100644 index 0000000000..cd79d24ade --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_9_rc2.php @@ -0,0 +1,30 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +namespace phpbb\db\migration\data\v30x; + +class release_3_0_9_rc2 extends \phpbb\db\migration\migration +{ +	public function effectively_installed() +	{ +		return phpbb_version_compare($this->config['version'], '3.0.9-RC2', '>='); +	} + +	static public function depends_on() +	{ +		return array('\phpbb\db\migration\data\v30x\release_3_0_9_rc1'); +	} + +	public function update_data() +	{ +		return array( +			array('config.update', array('version', '3.0.9-RC2')), +		); +	} +} diff --git a/phpBB/phpbb/db/migration/data/v30x/release_3_0_9_rc3.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_9_rc3.php new file mode 100644 index 0000000000..7e59b8f9e8 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_9_rc3.php @@ -0,0 +1,30 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +namespace phpbb\db\migration\data\v30x; + +class release_3_0_9_rc3 extends \phpbb\db\migration\migration +{ +	public function effectively_installed() +	{ +		return phpbb_version_compare($this->config['version'], '3.0.9-RC3', '>='); +	} + +	static public function depends_on() +	{ +		return array('\phpbb\db\migration\data\v30x\release_3_0_9_rc2'); +	} + +	public function update_data() +	{ +		return array( +			array('config.update', array('version', '3.0.9-RC3')), +		); +	} +} diff --git a/phpBB/phpbb/db/migration/data/v30x/release_3_0_9_rc4.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_9_rc4.php new file mode 100644 index 0000000000..e71d9defa6 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_9_rc4.php @@ -0,0 +1,30 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +namespace phpbb\db\migration\data\v30x; + +class release_3_0_9_rc4 extends \phpbb\db\migration\migration +{ +	public function effectively_installed() +	{ +		return phpbb_version_compare($this->config['version'], '3.0.9-RC4', '>='); +	} + +	static public function depends_on() +	{ +		return array('\phpbb\db\migration\data\v30x\release_3_0_9_rc3'); +	} + +	public function update_data() +	{ +		return array( +			array('config.update', array('version', '3.0.9-RC4')), +		); +	} +} diff --git a/phpBB/phpbb/db/migration/data/v310/acp_style_components_module.php b/phpBB/phpbb/db/migration/data/v310/acp_style_components_module.php new file mode 100644 index 0000000000..9f168f4fd6 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/acp_style_components_module.php @@ -0,0 +1,42 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\db\migration\data\v310; + +class acp_style_components_module extends \phpbb\db\migration\migration +{ +	public function effectively_installed() +	{ +		$sql = 'SELECT module_id +			FROM ' . MODULES_TABLE . " +			WHERE module_class = 'acp' +				AND module_langname = 'ACP_STYLE_COMPONENTS'"; +		$result = $this->db->sql_query($sql); +		$module_id = $this->db->sql_fetchfield('module_id'); +		$this->db->sql_freeresult($result); + +		return $module_id == false; +	} + +	static public function depends_on() +	{ +		return array('\phpbb\db\migration\data\v310\dev'); +	} + +	public function update_data() +	{ +		return array( +			array('module.remove', array( +				'acp', +				false, +				'ACP_STYLE_COMPONENTS', +			)), +		); +	} +} diff --git a/phpBB/phpbb/db/migration/data/v310/allow_cdn.php b/phpBB/phpbb/db/migration/data/v310/allow_cdn.php new file mode 100644 index 0000000000..aa471df6e7 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/allow_cdn.php @@ -0,0 +1,33 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +namespace phpbb\db\migration\data\v310; + +class allow_cdn extends \phpbb\db\migration\migration +{ +	public function effectively_installed() +	{ +		return isset($this->config['allow_cdn']); +	} + +	static public function depends_on() +	{ +		return array( +			'\phpbb\db\migration\data\v310\jquery_update', +		); +	} + +	public function update_data() +	{ +		return array( +			array('config.add', array('allow_cdn', (int) $this->config['load_jquery_cdn'])), +			array('config.remove', array('load_jquery_cdn')), +		); +	} +} diff --git a/phpBB/phpbb/db/migration/data/v310/auth_provider_oauth.php b/phpBB/phpbb/db/migration/data/v310/auth_provider_oauth.php new file mode 100644 index 0000000000..971a7e8504 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/auth_provider_oauth.php @@ -0,0 +1,73 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +namespace phpbb\db\migration\data\v310; + +class auth_provider_oauth extends \phpbb\db\migration\migration +{ +	public function effectively_installed() +	{ +		return $this->db_tools->sql_table_exists($this->table_prefix . 'auth_provider_oauth'); +	} + +	public function update_schema() +	{ +		return array( +			'add_tables'	=> array( +				$this->table_prefix . 'oauth_tokens'	=> array( +					'COLUMNS' => array( +						'user_id'			=> array('UINT', 0), // phpbb_users.user_id +						'session_id'		=> array('CHAR:32', ''), // phpbb_sessions.session_id used only when user_id not set +						'provider'			=> array('VCHAR', ''), // Name of the OAuth provider +						'oauth_token'		=> array('MTEXT', ''), // Serialized token +					), +					'KEYS' => array( +						'user_id'			=> array('INDEX', 'user_id'), +						'provider'			=> array('INDEX', 'provider'), +					), +				), +				$this->table_prefix . 'oauth_accounts'	=> array( +					'COLUMNS' => array( +						'user_id'			=> array('UINT', 0), +						'provider'			=> array('VCHAR', ''), +						'oauth_provider_id'	=> array('TEXT_UNI', ''), +					), +					'PRIMARY_KEY' => array( +						'user_id', +						'provider', +					), +				), +			), +		); +	} + +	public function revert_schema() +	{ +		return array( +			'drop_tables'	=> array( +				$this->table_prefix . 'oauth_tokens', +				$this->table_prefix . 'oauth_accounts', +			), +		); +	} + +	public function update_data() +	{ +		return array( +			array('module.add', array( +				'ucp', +				'UCP_PROFILE', +				array( +					'module_basename'	=> 'ucp_auth_link', +					'modes'				=> array('auth_link'), +				), +			)), +		); +	} +} diff --git a/phpBB/phpbb/db/migration/data/310/avatars.php b/phpBB/phpbb/db/migration/data/v310/avatars.php index 79547337f7..80ce606f29 100644 --- a/phpBB/phpbb/db/migration/data/310/avatars.php +++ b/phpBB/phpbb/db/migration/data/v310/avatars.php @@ -7,7 +7,9 @@  *  */ -class phpbb_db_migration_data_310_avatars extends phpbb_db_migration +namespace phpbb\db\migration\data\v310; + +class avatars extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ @@ -16,7 +18,7 @@ class phpbb_db_migration_data_310_avatars extends phpbb_db_migration  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_11'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_11');  	}  	public function update_schema() diff --git a/phpBB/phpbb/db/migration/data/310/boardindex.php b/phpBB/phpbb/db/migration/data/v310/boardindex.php index 965e32c15c..27492f2d0d 100644 --- a/phpBB/phpbb/db/migration/data/310/boardindex.php +++ b/phpBB/phpbb/db/migration/data/v310/boardindex.php @@ -7,7 +7,9 @@  *  */ -class phpbb_db_migration_data_310_boardindex extends phpbb_db_migration +namespace phpbb\db\migration\data\v310; + +class boardindex extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ diff --git a/phpBB/phpbb/db/migration/data/310/config_db_text.php b/phpBB/phpbb/db/migration/data/v310/config_db_text.php index 89f211adda..1a7ee7a9a6 100644 --- a/phpBB/phpbb/db/migration/data/310/config_db_text.php +++ b/phpBB/phpbb/db/migration/data/v310/config_db_text.php @@ -7,7 +7,9 @@  *  */ -class phpbb_db_migration_data_310_config_db_text extends phpbb_db_migration +namespace phpbb\db\migration\data\v310; + +class config_db_text extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ @@ -16,7 +18,7 @@ class phpbb_db_migration_data_310_config_db_text extends phpbb_db_migration  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_11'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_11');  	}  	public function update_schema() diff --git a/phpBB/phpbb/db/migration/data/310/dev.php b/phpBB/phpbb/db/migration/data/v310/dev.php index 0fc2950987..c1db883616 100644 --- a/phpBB/phpbb/db/migration/data/310/dev.php +++ b/phpBB/phpbb/db/migration/data/v310/dev.php @@ -7,7 +7,9 @@  *  */ -class phpbb_db_migration_data_310_dev extends phpbb_db_migration +namespace phpbb\db\migration\data\v310; + +class dev extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ @@ -17,10 +19,10 @@ class phpbb_db_migration_data_310_dev extends phpbb_db_migration  	static public function depends_on()  	{  		return array( -			'phpbb_db_migration_data_310_extensions', -			'phpbb_db_migration_data_310_style_update_p2', -			'phpbb_db_migration_data_310_timezone_p2', -			'phpbb_db_migration_data_310_reported_posts_display', +			'\phpbb\db\migration\data\v310\extensions', +			'\phpbb\db\migration\data\v310\style_update_p2', +			'\phpbb\db\migration\data\v310\timezone_p2', +			'\phpbb\db\migration\data\v310\reported_posts_display',  		);  	} @@ -206,7 +208,7 @@ class phpbb_db_migration_data_310_dev extends phpbb_db_migration  		{  			include($this->phpbb_root_path . 'includes/functions_acp.' . $this->php_ext);  		} -		$module_manager = new acp_modules(); +		$module_manager = new \acp_modules();  		$module_manager->module_class = 'acp';  		$module_manager->move_module($language_module_id, $language_management_module_id);  	} diff --git a/phpBB/phpbb/db/migration/data/310/extensions.php b/phpBB/phpbb/db/migration/data/v310/extensions.php index 6a9caa1cfc..d8b38dbc9e 100644 --- a/phpBB/phpbb/db/migration/data/310/extensions.php +++ b/phpBB/phpbb/db/migration/data/v310/extensions.php @@ -7,7 +7,9 @@  *  */ -class phpbb_db_migration_data_310_extensions extends phpbb_db_migration +namespace phpbb\db\migration\data\v310; + +class extensions extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ @@ -16,7 +18,7 @@ class phpbb_db_migration_data_310_extensions extends phpbb_db_migration  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_11'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_11');  	}  	public function update_schema() diff --git a/phpBB/phpbb/db/migration/data/310/forgot_password.php b/phpBB/phpbb/db/migration/data/v310/forgot_password.php index a553e51f35..814093caa9 100644 --- a/phpBB/phpbb/db/migration/data/310/forgot_password.php +++ b/phpBB/phpbb/db/migration/data/v310/forgot_password.php @@ -7,7 +7,9 @@  *  */ -class phpbb_db_migration_data_310_forgot_password extends phpbb_db_migration +namespace phpbb\db\migration\data\v310; + +class forgot_password extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ @@ -16,7 +18,7 @@ class phpbb_db_migration_data_310_forgot_password extends phpbb_db_migration  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_11'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_11');  	}  	public function update_data() diff --git a/phpBB/phpbb/db/migration/data/310/jquery_update.php b/phpBB/phpbb/db/migration/data/v310/jquery_update.php index dc49f74fcb..bd2de2b4d4 100644 --- a/phpBB/phpbb/db/migration/data/310/jquery_update.php +++ b/phpBB/phpbb/db/migration/data/v310/jquery_update.php @@ -7,7 +7,9 @@  *  */ -class phpbb_db_migration_data_310_jquery_update extends phpbb_db_migration +namespace phpbb\db\migration\data\v310; + +class jquery_update extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ @@ -17,7 +19,7 @@ class phpbb_db_migration_data_310_jquery_update extends phpbb_db_migration  	static public function depends_on()  	{  		return array( -			'phpbb_db_migration_data_310_dev', +			'\phpbb\db\migration\data\v310\dev',  		);  	} diff --git a/phpBB/phpbb/db/migration/data/v310/mod_rewrite.php b/phpBB/phpbb/db/migration/data/v310/mod_rewrite.php new file mode 100644 index 0000000000..ffb790b135 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/mod_rewrite.php @@ -0,0 +1,27 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +namespace phpbb\db\migration\data\v310; + +class mod_rewrite extends \phpbb\db\migration\migration +{ +	static public function depends_on() +	{ +		return array( +			'\phpbb\db\migration\data\v310\dev', +		); +	} + +	public function update_data() +	{ +		return array( +			array('config.add', array('enable_mod_rewrite', '0')), +		); +	} +} diff --git a/phpBB/phpbb/db/migration/data/v310/namespaces.php b/phpBB/phpbb/db/migration/data/v310/namespaces.php new file mode 100644 index 0000000000..f74ecbd874 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/namespaces.php @@ -0,0 +1,30 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +namespace phpbb\db\migration\data\v310; + +class namespaces extends \phpbb\db\migration\migration +{ +	static public function depends_on() +	{ +		return array( +			'\phpbb\db\migration\data\v310\dev', +		); +	} + +	public function update_data() +	{ +		return array( +			array('if', array( +				(preg_match('#^phpbb_search_#', $this->config['search_type'])), +				array('config.update', array('search_type', str_replace('phpbb_search_', '\\phpbb\\search\\', $this->config['search_type']))), +			)), +		); +	} +} diff --git a/phpBB/phpbb/db/migration/data/310/notification_options_reconvert.php b/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php index d994d7ec5f..4195623618 100644 --- a/phpBB/phpbb/db/migration/data/310/notification_options_reconvert.php +++ b/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php @@ -7,45 +7,56 @@  *  */ -class phpbb_db_migration_data_310_notification_options_reconvert extends phpbb_db_migration +namespace phpbb\db\migration\data\v310; + +class notification_options_reconvert extends \phpbb\db\migration\migration  {  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_310_notifications_schema_fix'); +		return array('\phpbb\db\migration\data\v310\notifications_schema_fix');  	}  	public function update_data()  	{  		return array( +			array('custom', array(array($this, 'purge_notifications'))),  			array('custom', array(array($this, 'convert_notifications'))),  		);  	} -	public function convert_notifications() +	public function purge_notifications() +	{ +		$sql = 'DELETE FROM ' . $this->table_prefix . 'user_notifications'; +		$this->sql_query($sql); +	} + +	public function convert_notifications($start)  	{ -		$insert_table = $this->table_prefix . 'user_notifications'; -		$insert_buffer = new phpbb_db_sql_insert_buffer($this->db, $insert_table); +		$insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $this->table_prefix . 'user_notifications'); -		$this->perform_conversion($insert_buffer, $insert_table); +		return $this->perform_conversion($insert_buffer, $start);  	}  	/**  	* Perform the conversion (separate for testability)  	* -	* @param phpbb_db_sql_insert_buffer $insert_buffer -	* @param string $insert_table +	* @param \phpbb\db\sql_insert_buffer		$insert_buffer +	* @param int			$start		Start of staggering step +	* @return		mixed		int start of the next step, null if the end was reached  	*/ -	public function perform_conversion(phpbb_db_sql_insert_buffer $insert_buffer, $insert_table) +	public function perform_conversion(\phpbb\db\sql_insert_buffer $insert_buffer, $start)  	{ -		$sql = 'DELETE FROM ' . $insert_table; -		$this->db->sql_query($sql); +		$limit = 250; +		$converted_users = 0;  		$sql = 'SELECT user_id, user_notify_type, user_notify_pm -			FROM ' . USERS_TABLE; -		$result = $this->db->sql_query($sql); +			FROM ' . $this->table_prefix . 'users +			ORDER BY user_id'; +		$result = $this->db->sql_query_limit($sql, $limit, $start);  		while ($row = $this->db->sql_fetchrow($result))  		{ +			$converted_users++;  			$notification_methods = array();  			// In-board notification @@ -89,18 +100,26 @@ class phpbb_db_migration_data_310_notification_options_reconvert extends phpbb_d  		$this->db->sql_freeresult($result);  		$insert_buffer->flush(); + +		if ($converted_users < $limit) +		{ +			// No more users left, we are done... +			return; +		} + +		return $start + $limit;  	}  	/**  	* Insert method rows to DB  	* -	* @param phpbb_db_sql_insert_buffer $insert_buffer +	* @param \phpbb\db\sql_insert_buffer $insert_buffer  	* @param string $item_type  	* @param int $item_id  	* @param int $user_id  	* @param string $methods  	*/ -	protected function add_method_rows(phpbb_db_sql_insert_buffer $insert_buffer, $item_type, $item_id, $user_id, array $methods) +	protected function add_method_rows(\phpbb\db\sql_insert_buffer $insert_buffer, $item_type, $item_id, $user_id, array $methods)  	{  		$row_base = array(  			'item_type'		=> $item_type, diff --git a/phpBB/phpbb/db/migration/data/310/notifications.php b/phpBB/phpbb/db/migration/data/v310/notifications.php index 17c939d95a..10f1392094 100644 --- a/phpBB/phpbb/db/migration/data/310/notifications.php +++ b/phpBB/phpbb/db/migration/data/v310/notifications.php @@ -7,7 +7,9 @@  *  */ -class phpbb_db_migration_data_310_notifications extends phpbb_db_migration +namespace phpbb\db\migration\data\v310; + +class notifications extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ @@ -16,7 +18,7 @@ class phpbb_db_migration_data_310_notifications extends phpbb_db_migration  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_310_dev'); +		return array('\phpbb\db\migration\data\v310\dev');  	}  	public function update_schema() diff --git a/phpBB/phpbb/db/migration/data/v310/notifications_cron.php b/phpBB/phpbb/db/migration/data/v310/notifications_cron.php new file mode 100644 index 0000000000..d5fa9c58a5 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/notifications_cron.php @@ -0,0 +1,27 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\db\migration\data\v310; + +class notifications_cron extends \phpbb\db\migration\migration +{ +	static public function depends_on() +	{ +		return array('\phpbb\db\migration\data\v310\notifications'); +	} + +	public function update_data() +	{ +		return array( +			array('config.add', array('read_notification_expire_days', 30)), +			array('config.add', array('read_notification_last_gc', 0)), // last run +			array('config.add', array('read_notification_gc', (60 * 60 * 24))), // seconds between run; 1 day +		); +	} +} diff --git a/phpBB/phpbb/db/migration/data/310/notifications_schema_fix.php b/phpBB/phpbb/db/migration/data/v310/notifications_schema_fix.php index 27e63e10d0..8ed626d8a6 100644 --- a/phpBB/phpbb/db/migration/data/310/notifications_schema_fix.php +++ b/phpBB/phpbb/db/migration/data/v310/notifications_schema_fix.php @@ -7,11 +7,13 @@  *  */ -class phpbb_db_migration_data_310_notifications_schema_fix extends phpbb_db_migration +namespace phpbb\db\migration\data\v310; + +class notifications_schema_fix extends \phpbb\db\migration\migration  {  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_310_notifications'); +		return array('\phpbb\db\migration\data\v310\notifications');  	}  	public function update_schema() diff --git a/phpBB/phpbb/db/migration/data/310/reported_posts_display.php b/phpBB/phpbb/db/migration/data/v310/reported_posts_display.php index 80a0a0e43f..56b7a0916c 100644 --- a/phpBB/phpbb/db/migration/data/310/reported_posts_display.php +++ b/phpBB/phpbb/db/migration/data/v310/reported_posts_display.php @@ -7,7 +7,9 @@  *  */ -class phpbb_db_migration_data_310_reported_posts_display extends phpbb_db_migration +namespace phpbb\db\migration\data\v310; + +class reported_posts_display extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ @@ -16,7 +18,7 @@ class phpbb_db_migration_data_310_reported_posts_display extends phpbb_db_migrat  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_11'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_11');  	}  	public function update_schema() diff --git a/phpBB/phpbb/db/migration/data/310/signature_module_auth.php b/phpBB/phpbb/db/migration/data/v310/signature_module_auth.php index e4fbb27bcb..6da1cb8009 100644 --- a/phpBB/phpbb/db/migration/data/310/signature_module_auth.php +++ b/phpBB/phpbb/db/migration/data/v310/signature_module_auth.php @@ -7,7 +7,9 @@  *  */ -class phpbb_db_migration_data_310_signature_module_auth extends phpbb_db_migration +namespace phpbb\db\migration\data\v310; + +class signature_module_auth extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ @@ -17,7 +19,7 @@ class phpbb_db_migration_data_310_signature_module_auth extends phpbb_db_migrati  				AND module_basename = 'ucp_profile'  				AND module_mode = 'signature'";  		$result = $this->db->sql_query($sql); -		$module_auth = $this->db_sql_fetchfield('module_auth'); +		$module_auth = $this->db->sql_fetchfield('module_auth');  		$this->db->sql_freeresult($result);  		return $module_auth === 'acl_u_sig' || $module_auth === false; @@ -25,7 +27,7 @@ class phpbb_db_migration_data_310_signature_module_auth extends phpbb_db_migrati  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_31x_dev'); +		return array('\phpbb\db\migration\data\v310\dev');  	}  	public function update_data() diff --git a/phpBB/phpbb/db/migration/data/v310/softdelete_mcp_modules.php b/phpBB/phpbb/db/migration/data/v310/softdelete_mcp_modules.php new file mode 100644 index 0000000000..d1a31815b2 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/softdelete_mcp_modules.php @@ -0,0 +1,57 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +namespace phpbb\db\migration\data\v310; + +class softdelete_mcp_modules extends \phpbb\db\migration\migration +{ +	public function effectively_installed() +	{ +		$sql = 'SELECT module_id +			FROM ' . MODULES_TABLE . " +			WHERE module_class = 'mcp' +				AND module_basename = 'mcp_queue' +				AND module_mode = 'deleted_topics'"; +		$result = $this->db->sql_query($sql); +		$module_id = $this->db->sql_fetchfield('module_id'); +		$this->db->sql_freeresult($result); + +		return $module_id !== false; +	} + +	static public function depends_on() +	{ +		return array( +			'\phpbb\db\migration\data\v310\dev', +			'\phpbb\db\migration\data\v310\softdelete_p2', +		); +	} + +	public function update_data() +	{ +		return array( +			array('module.add', array( +				'mcp', +				'MCP_QUEUE', +				array( +					'module_basename'	=> 'mcp_queue', +					'modes'				=> array('deleted_topics'), +				), +			)), +			array('module.add', array( +				'mcp', +				'MCP_QUEUE', +				array( +					'module_basename'	=> 'mcp_queue', +					'modes'				=> array('deleted_posts'), +				), +			)), +		); +	} +} diff --git a/phpBB/phpbb/db/migration/data/310/softdelete_p1.php b/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php index 84f8eebd4a..f080c78c50 100644 --- a/phpBB/phpbb/db/migration/data/310/softdelete_p1.php +++ b/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php @@ -7,7 +7,9 @@  *  */ -class phpbb_db_migration_data_310_softdelete_p1 extends phpbb_db_migration +namespace phpbb\db\migration\data\v310; + +class softdelete_p1 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ @@ -16,7 +18,7 @@ class phpbb_db_migration_data_310_softdelete_p1 extends phpbb_db_migration  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_310_dev'); +		return array('\phpbb\db\migration\data\v310\dev');  	}  	public function update_schema() @@ -99,7 +101,8 @@ class phpbb_db_migration_data_310_softdelete_p1 extends phpbb_db_migration  		return array(  			array('custom', array(array($this, 'update_post_visibility'))),  			array('custom', array(array($this, 'update_topic_visibility'))), -			array('custom', array(array($this, 'update_topic_forum_counts'))), +			array('custom', array(array($this, 'update_topics_post_counts'))), +			array('custom', array(array($this, 'update_forums_topic_and_post_counts'))),  			array('permission.add', array('f_softdelete', false)),  			array('permission.add', array('m_softdelete', false)), @@ -120,28 +123,43 @@ class phpbb_db_migration_data_310_softdelete_p1 extends phpbb_db_migration  		$this->sql_query($sql);  	} -	public function update_topic_forum_counts() +	public function update_topics_post_counts()  	{ +		/* +		* Using sql_case here to avoid "BIGINT UNSIGNED value is out of range" errors. +		* As we update all topics in 2 queries, one broken topic would stop the conversion +		* for all topics and the surpressed error will cause the admin to not even notice it. +		*/  		$sql = 'UPDATE ' . $this->table_prefix . 'topics  			SET topic_posts_approved = topic_replies + 1, -				topic_posts_unapproved = topic_replies_real - topic_replies +				topic_posts_unapproved = ' . $this->db->sql_case('topic_replies_real > topic_replies', 'topic_replies_real - topic_replies', '0') . '  			WHERE topic_visibility = ' . ITEM_APPROVED;  		$this->sql_query($sql);  		$sql = 'UPDATE ' . $this->table_prefix . 'topics  			SET topic_posts_approved = 0, -				topic_posts_unapproved = (topic_replies_real - topic_replies) + 1 +				topic_posts_unapproved = (' . $this->db->sql_case('topic_replies_real > topic_replies', 'topic_replies_real - topic_replies', '0') . ') + 1  			WHERE topic_visibility = ' . ITEM_UNAPPROVED;  		$this->sql_query($sql); +	} + +	public function update_forums_topic_and_post_counts($start) +	{ +		$start = (int) $start; +		$limit = 10; +		$converted_forums = 0;  		$sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS sum_topics, SUM(topic_posts_approved) AS sum_posts_approved, SUM(topic_posts_unapproved) AS sum_posts_unapproved  			FROM ' . $this->table_prefix . 'topics -			GROUP BY forum_id, topic_visibility'; -		$result = $this->db->sql_query($sql); +			GROUP BY forum_id, topic_visibility +			ORDER BY forum_id, topic_visibility'; +		$result = $this->db->sql_query_limit($sql, $limit, $start);  		$update_forums = array();  		while ($row = $this->db->sql_fetchrow($result))  		{ +			$converted_forums++; +  			$forum_id = (int) $row['forum_id'];  			if (!isset($update_forums[$forum_id]))  			{ @@ -167,5 +185,14 @@ class phpbb_db_migration_data_310_softdelete_p1 extends phpbb_db_migration  				WHERE forum_id = ' . $forum_id;  			$this->sql_query($sql);  		} + +		if ($converted_forums < $limit) +		{ +			// There are no more topics, we are done +			return; +		} + +		// There are still more topics to query, return the next start value +		return $start + $limit;  	}  } diff --git a/phpBB/phpbb/db/migration/data/310/softdelete_p2.php b/phpBB/phpbb/db/migration/data/v310/softdelete_p2.php index 7320a2c2bf..0c32e474f4 100644 --- a/phpBB/phpbb/db/migration/data/310/softdelete_p2.php +++ b/phpBB/phpbb/db/migration/data/v310/softdelete_p2.php @@ -7,7 +7,9 @@  *  */ -class phpbb_db_migration_data_310_softdelete_p2 extends phpbb_db_migration +namespace phpbb\db\migration\data\v310; + +class softdelete_p2 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ @@ -17,8 +19,8 @@ class phpbb_db_migration_data_310_softdelete_p2 extends phpbb_db_migration  	static public function depends_on()  	{  		return array( -			'phpbb_db_migration_data_310_dev', -			'phpbb_db_migration_data_310_softdelete_p1', +			'\phpbb\db\migration\data\v310\dev', +			'\phpbb\db\migration\data\v310\softdelete_p1',  		);  	} diff --git a/phpBB/phpbb/db/migration/data/310/style_update_p1.php b/phpBB/phpbb/db/migration/data/v310/style_update_p1.php index d43537559d..26f1046287 100644 --- a/phpBB/phpbb/db/migration/data/310/style_update_p1.php +++ b/phpBB/phpbb/db/migration/data/v310/style_update_p1.php @@ -7,7 +7,9 @@  *  */ -class phpbb_db_migration_data_310_style_update_p1 extends phpbb_db_migration +namespace phpbb\db\migration\data\v310; + +class style_update_p1 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ @@ -16,7 +18,7 @@ class phpbb_db_migration_data_310_style_update_p1 extends phpbb_db_migration  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_11'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_11');  	}  	public function update_schema() @@ -59,7 +61,7 @@ class phpbb_db_migration_data_310_style_update_p1 extends phpbb_db_migration  		// Get list of valid 3.1 styles  		$available_styles = array('prosilver'); -		$iterator = new DirectoryIterator($this->phpbb_root_path . 'styles'); +		$iterator = new \DirectoryIterator($this->phpbb_root_path . 'styles');  		$skip_dirs = array('.', '..', 'prosilver');  		foreach ($iterator as $fileinfo)  		{ diff --git a/phpBB/phpbb/db/migration/data/310/style_update_p2.php b/phpBB/phpbb/db/migration/data/v310/style_update_p2.php index 7b10518a66..202a8409fb 100644 --- a/phpBB/phpbb/db/migration/data/310/style_update_p2.php +++ b/phpBB/phpbb/db/migration/data/v310/style_update_p2.php @@ -7,7 +7,9 @@  *  */ -class phpbb_db_migration_data_310_style_update_p2 extends phpbb_db_migration +namespace phpbb\db\migration\data\v310; + +class style_update_p2 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ @@ -16,7 +18,7 @@ class phpbb_db_migration_data_310_style_update_p2 extends phpbb_db_migration  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_310_style_update_p1'); +		return array('\phpbb\db\migration\data\v310\style_update_p1');  	}  	public function update_schema() diff --git a/phpBB/phpbb/db/migration/data/310/teampage.php b/phpBB/phpbb/db/migration/data/v310/teampage.php index 4e77da17b7..80cc4be1c0 100644 --- a/phpBB/phpbb/db/migration/data/310/teampage.php +++ b/phpBB/phpbb/db/migration/data/v310/teampage.php @@ -7,7 +7,9 @@  *  */ -class phpbb_db_migration_data_310_teampage extends phpbb_db_migration +namespace phpbb\db\migration\data\v310; + +class teampage extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ @@ -16,7 +18,7 @@ class phpbb_db_migration_data_310_teampage extends phpbb_db_migration  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_310_dev'); +		return array('\phpbb\db\migration\data\v310\dev');  	}  	public function update_schema() diff --git a/phpBB/phpbb/db/migration/data/310/timezone.php b/phpBB/phpbb/db/migration/data/v310/timezone.php index 6e50cbe45f..dd0c6a2093 100644 --- a/phpBB/phpbb/db/migration/data/310/timezone.php +++ b/phpBB/phpbb/db/migration/data/v310/timezone.php @@ -7,7 +7,9 @@  *  */ -class phpbb_db_migration_data_310_timezone extends phpbb_db_migration +namespace phpbb\db\migration\data\v310; + +class timezone extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ @@ -16,7 +18,7 @@ class phpbb_db_migration_data_310_timezone extends phpbb_db_migration  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_30x_3_0_11'); +		return array('\phpbb\db\migration\data\v30x\release_3_0_11');  	}  	public function update_schema() diff --git a/phpBB/phpbb/db/migration/data/310/timezone_p2.php b/phpBB/phpbb/db/migration/data/v310/timezone_p2.php index 113b979e4f..1066ab8571 100644 --- a/phpBB/phpbb/db/migration/data/310/timezone_p2.php +++ b/phpBB/phpbb/db/migration/data/v310/timezone_p2.php @@ -7,7 +7,9 @@  *  */ -class phpbb_db_migration_data_310_timezone_p2 extends phpbb_db_migration +namespace phpbb\db\migration\data\v310; + +class timezone_p2 extends \phpbb\db\migration\migration  {  	public function effectively_installed()  	{ @@ -16,7 +18,7 @@ class phpbb_db_migration_data_310_timezone_p2 extends phpbb_db_migration  	static public function depends_on()  	{ -		return array('phpbb_db_migration_data_310_timezone'); +		return array('\phpbb\db\migration\data\v310\timezone');  	}  	public function update_schema() diff --git a/phpBB/phpbb/db/migration/exception.php b/phpBB/phpbb/db/migration/exception.php index e84330dd71..58e29b5218 100644 --- a/phpBB/phpbb/db/migration/exception.php +++ b/phpBB/phpbb/db/migration/exception.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\db\migration; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  *  * @package db  */ -class phpbb_db_migration_exception extends \Exception +class exception extends \Exception  {  	/**  	* Extra parameters sent to exception to aid in debugging @@ -64,12 +66,12 @@ class phpbb_db_migration_exception extends \Exception  	}  	/** -	* Get localised message (with $user->lang())  -	*  -	* @param phpbb_user $user +	* Get localised message (with $user->lang()) +	* +	* @param \phpbb\user $user  	* @return string  	*/ -	public function getLocalisedMessage(phpbb_user $user) +	public function getLocalisedMessage(\phpbb\user $user)  	{  		$parameters = $this->getParameters();  		array_unshift($parameters, $this->getMessage()); diff --git a/phpBB/phpbb/db/migration/migration.php b/phpBB/phpbb/db/migration/migration.php index 0ffa96fd14..aff3837279 100644 --- a/phpBB/phpbb/db/migration/migration.php +++ b/phpBB/phpbb/db/migration/migration.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\db\migration; +  /**  * @ignore  */ @@ -24,15 +26,15 @@ if (!defined('IN_PHPBB'))  *  * @package db  */ -abstract class phpbb_db_migration +abstract class migration  { -	/** @var phpbb_config */ +	/** @var \phpbb\config\config */  	protected $config; -	/** @var phpbb_db_driver */ +	/** @var \phpbb\db\driver\driver */  	protected $db; -	/** @var phpbb_db_tools */ +	/** @var \phpbb\db\tools */  	protected $db_tools;  	/** @var string */ @@ -53,14 +55,14 @@ abstract class phpbb_db_migration  	/**  	* Constructor  	* -	* @param phpbb_config $config -	* @param phpbb_db_driver $db -	* @param phpbb_db_tools $db_tools +	* @param \phpbb\config\config $config +	* @param \phpbb\db\driver\driver $db +	* @param \phpbb\db\tools $db_tools  	* @param string $phpbb_root_path  	* @param string $php_ext  	* @param string $table_prefix  	*/ -	public function __construct(phpbb_config $config, phpbb_db_driver $db, phpbb_db_tools $db_tools, $phpbb_root_path, $php_ext, $table_prefix) +	public function __construct(\phpbb\config\config $config, \phpbb\db\driver\driver $db, \phpbb\db\tools $db_tools, $phpbb_root_path, $php_ext, $table_prefix)  	{  		$this->config = $config;  		$this->db = $db; diff --git a/phpBB/phpbb/db/migration/tool/config.php b/phpBB/phpbb/db/migration/tool/config.php index 0b626bf455..f2149dc59a 100644 --- a/phpBB/phpbb/db/migration/tool/config.php +++ b/phpBB/phpbb/db/migration/tool/config.php @@ -7,22 +7,24 @@  *  */ +namespace phpbb\db\migration\tool; +  /**  * Migration config tool  *  * @package db  */ -class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interface +class config implements \phpbb\db\migration\tool\tool_interface  { -	/** @var phpbb_config */ +	/** @var \phpbb\config\config */  	protected $config;  	/**  	* Constructor  	* -	* @param phpbb_config $config +	* @param \phpbb\config\config $config  	*/ -	public function __construct(phpbb_config $config) +	public function __construct(\phpbb\config\config $config)  	{  		$this->config = $config;  	} @@ -67,7 +69,7 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac  	{  		if (!isset($this->config[$config_name]))  		{ -			throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); +			throw new \phpbb\db\migration\exception('CONFIG_NOT_EXIST', $config_name);  		}  		$this->config->set($config_name, $config_value); @@ -88,7 +90,7 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac  	{  		if (!isset($this->config[$config_name]))  		{ -			throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); +			throw new \phpbb\db\migration\exception('CONFIG_NOT_EXIST', $config_name);  		}  		$this->config->set_atomic($config_name, $compare, $config_value); diff --git a/phpBB/phpbb/db/migration/tool/module.php b/phpBB/phpbb/db/migration/tool/module.php index ac4d2c9bd7..3e39d87c04 100644 --- a/phpBB/phpbb/db/migration/tool/module.php +++ b/phpBB/phpbb/db/migration/tool/module.php @@ -7,20 +7,22 @@  *  */ +namespace phpbb\db\migration\tool; +  /**  * Migration module management tool  *  * @package db  */ -class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interface +class module implements \phpbb\db\migration\tool\tool_interface  { -	/** @var phpbb_cache_service */ +	/** @var \phpbb\cache\service */  	protected $cache;  	/** @var dbal */  	protected $db; -	/** @var phpbb_user */ +	/** @var \phpbb\user */  	protected $user;  	/** @var string */ @@ -35,14 +37,14 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac  	/**  	* Constructor  	* -	* @param phpbb_db_driver $db +	* @param \phpbb\db\driver\driver $db  	* @param mixed $cache -	* @param phpbb_user $user +	* @param \phpbb\user $user  	* @param string $phpbb_root_path  	* @param string $php_ext  	* @param string $modules_table  	*/ -	public function __construct(phpbb_db_driver $db, phpbb_cache_service $cache, phpbb_user $user, $phpbb_root_path, $php_ext, $modules_table) +	public function __construct(\phpbb\db\driver\driver $db, \phpbb\cache\service $cache, \phpbb\user $user, $phpbb_root_path, $php_ext, $modules_table)  	{  		$this->db = $db;  		$this->cache = $cache; @@ -133,7 +135,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac  	*  	* @param string $class The module class(acp|mcp|ucp)  	* @param int|string $parent The parent module_id|module_langname (0 for no parent) -	* @param array $data an array of the data on the new module. +	* @param array $data an array of the data on the new \module.  	* 	This can be setup in two different ways.  	*	1. The "manual" way.  For inserting a category or one at a time.  	*		It will be merged with the base array shown a bit below, @@ -180,9 +182,6 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac  		{  			// The "automatic" way  			$basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; -			$basename = str_replace(array('/', '\\'), '', $basename); -			$class = str_replace(array('/', '\\'), '', $class); -  			$module = $this->get_module_info($class, $basename);  			$result = ''; @@ -221,14 +220,14 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac  			if (!$module_id)  			{ -				throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', $parent); +				throw new \phpbb\db\migration\exception('MODULE_NOT_EXIST', $parent);  			}  			$parent = $data['parent_id'] = $module_id;  		}  		else if (!$this->exists($class, false, $parent))  		{ -			throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', $parent); +			throw new \phpbb\db\migration\exception('MODULE_NOT_EXIST', $parent);  		}  		if ($this->exists($class, $parent, $data['module_langname'])) @@ -241,7 +240,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac  			include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext);  			$this->user->add_lang('acp/modules');  		} -		$acp_modules = new acp_modules(); +		$acp_modules = new \acp_modules();  		$module_data = array(  			'module_enabled'	=> (isset($data['module_enabled'])) ? $data['module_enabled'] : 1, @@ -259,7 +258,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac  		if (is_string($result))  		{  			// Error -			throw new phpbb_db_migration_exception('MODULE_ERROR', $result); +			throw new \phpbb\db\migration\exception('MODULE_ERROR', $result);  		}  		else  		{ @@ -347,13 +346,11 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac  			// Failed.  			if (!isset($module['module_basename']))  			{ -				throw new phpbb_db_migration_exception('MODULE_NOT_EXIST'); +				throw new \phpbb\db\migration\exception('MODULE_NOT_EXIST');  			}  			// Automatic method -			$basename = str_replace(array('/', '\\'), '', $module['module_basename']); -			$class = str_replace(array('/', '\\'), '', $class); - +			$basename = $module['module_basename'];  			$module_info = $this->get_module_info($class, $basename);  			foreach ($module_info['modes'] as $mode => $info) @@ -433,7 +430,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac  				include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext);  				$this->user->add_lang('acp/modules');  			} -			$acp_modules = new acp_modules(); +			$acp_modules = new \acp_modules();  			$acp_modules->module_class = $class;  			foreach ($module_ids as $module_id) @@ -476,7 +473,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac  	}  	/** -	* Wrapper for acp_modules::get_module_infos() +	* Wrapper for \acp_modules::get_module_infos()  	*  	* @param string $class Module Class  	* @param string $basename Module Basename @@ -488,12 +485,12 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac  		{  			include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext);  		} -		$acp_modules = new acp_modules(); +		$acp_modules = new \acp_modules();  		$module = $acp_modules->get_module_infos($basename, $class, true);  		if (empty($module))  		{ -			throw new phpbb_db_migration_exception('MODULE_INFO_FILE_NOT_EXIST', $class, $basename); +			throw new \phpbb\db\migration\exception('MODULE_INFO_FILE_NOT_EXIST', $class, $basename);  		}  		return array_pop($module); diff --git a/phpBB/phpbb/db/migration/tool/permission.php b/phpBB/phpbb/db/migration/tool/permission.php index 2f09c0ac72..fd2de9c8fb 100644 --- a/phpBB/phpbb/db/migration/tool/permission.php +++ b/phpBB/phpbb/db/migration/tool/permission.php @@ -7,17 +7,19 @@  *  */ +namespace phpbb\db\migration\tool; +  /**  * Migration permission management tool  *  * @package db  */ -class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_interface +class permission implements \phpbb\db\migration\tool\tool_interface  { -	/** @var phpbb_auth */ +	/** @var \phpbb\auth\auth */  	protected $auth; -	/** @var phpbb_cache_service */ +	/** @var \phpbb\cache\service */  	protected $cache;  	/** @var dbal */ @@ -32,13 +34,13 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte  	/**  	* Constructor  	* -	* @param phpbb_db_driver $db +	* @param \phpbb\db\driver\driver $db  	* @param mixed $cache -	* @param phpbb_auth $auth +	* @param \phpbb\auth\auth $auth  	* @param string $phpbb_root_path  	* @param string $php_ext  	*/ -	public function __construct(phpbb_db_driver $db, phpbb_cache_service $cache, phpbb_auth $auth, $phpbb_root_path, $php_ext) +	public function __construct(\phpbb\db\driver\driver $db, \phpbb\cache\service $cache, \phpbb\auth\auth $auth, $phpbb_root_path, $php_ext)  	{  		$this->db = $db;  		$this->cache = $cache; @@ -117,7 +119,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte  		{  			include($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext);  		} -		$auth_admin = new auth_admin(); +		$auth_admin = new \auth_admin();  		// We have to add a check to see if the !$global (if global, local, and if local, global) permission already exists.  If it does, acl_add_option currently has a bug which would break the ACL system, so we are having a work-around here.  		if ($this->exists($auth_option, !$global)) @@ -290,7 +292,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte  		if (!$role_id)  		{ -			throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $old_role_name); +			throw new \phpbb\db\migration\exception('ROLE_NOT_EXIST', $old_role_name);  		}  		$sql = 'UPDATE ' . ACL_ROLES_TABLE . " @@ -380,7 +382,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte  				if (!$role_id)  				{ -					throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $name); +					throw new \phpbb\db\migration\exception('ROLE_NOT_EXIST', $name);  				}  				$sql = 'SELECT auth_option_id, auth_setting @@ -403,7 +405,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte  				if (!$group_id)  				{ -					throw new phpbb_db_migration_exception('GROUP_NOT_EXIST', $name); +					throw new \phpbb\db\migration\exception('GROUP_NOT_EXIST', $name);  				}  				// If the group has a role set for them we will add the requested permissions to that role. @@ -523,7 +525,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte  				if (!$role_id)  				{ -					throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $name); +					throw new \phpbb\db\migration\exception('ROLE_NOT_EXIST', $name);  				}  				$sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' @@ -540,7 +542,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte  				if (!$group_id)  				{ -					throw new phpbb_db_migration_exception('GROUP_NOT_EXIST', $name); +					throw new \phpbb\db\migration\exception('GROUP_NOT_EXIST', $name);  				}  				// If the group has a role set for them we will remove the requested permissions from that role. diff --git a/phpBB/phpbb/db/migration/tool/interface.php b/phpBB/phpbb/db/migration/tool/tool_interface.php index ced53b2023..e7b89d8858 100644 --- a/phpBB/phpbb/db/migration/tool/interface.php +++ b/phpBB/phpbb/db/migration/tool/tool_interface.php @@ -7,12 +7,14 @@  *  */ +namespace phpbb\db\migration\tool; +  /**  * Migration tool interface  *  * @package db  */ -interface phpbb_db_migration_tool_interface +interface tool_interface  {  	/**  	* Retrieve a short name used for commands in migrations. diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php index ca3ffc8043..47e1406043 100644 --- a/phpBB/phpbb/db/migrator.php +++ b/phpBB/phpbb/db/migrator.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\db; +  /**  * @ignore  */ @@ -20,15 +22,15 @@ if (!defined('IN_PHPBB'))  *  * @package db  */ -class phpbb_db_migrator +class migrator  { -	/** @var phpbb_config */ +	/** @var \phpbb\config\config */  	protected $config; -	/** @var phpbb_db_driver */ +	/** @var \phpbb\db\driver\driver */  	protected $db; -	/** @var phpbb_db_tools */ +	/** @var \phpbb\db\tools */  	protected $db_tools;  	/** @var string */ @@ -71,7 +73,7 @@ class phpbb_db_migrator  	/**  	* Constructor of the database migrator  	*/ -	public function __construct(phpbb_config $config, phpbb_db_driver $db, phpbb_db_tools $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) +	public function __construct(\phpbb\config\config $config, \phpbb\db\driver\driver $db, \phpbb\db\tools $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools)  	{  		$this->config = $config;  		$this->db = $db; @@ -190,6 +192,11 @@ class phpbb_db_migrator  		foreach ($state['migration_depends_on'] as $depend)  		{ +			if ($this->unfulfillable($depend) !== false) +			{ +				throw new \phpbb\db\migration\exception('MIGRATION_NOT_FULFILLABLE', $name, $depend); +			} +  			if (!isset($this->migration_state[$depend]) ||  				!$this->migration_state[$depend]['migration_schema_done'] ||  				!$this->migration_state[$depend]['migration_data_done']) @@ -202,11 +209,12 @@ class phpbb_db_migrator  			'name'	=> $name,  			'class'	=> $migration,  			'state'	=> $state, +			'task'	=> '',  		);  		if (!isset($this->migration_state[$name]))  		{ -			if ($migration->effectively_installed()) +			if ($state['migration_start_time'] == 0 && $migration->effectively_installed())  			{  				$state = array(  					'migration_depends_on'	=> $migration->depends_on(), @@ -225,8 +233,11 @@ class phpbb_db_migrator  			}  		} +		$this->set_migration_state($name, $state); +  		if (!$state['migration_schema_done'])  		{ +			$this->last_run_migration['task'] = 'apply_schema_changes';  			$this->apply_schema_changes($migration->update_schema());  			$state['migration_schema_done'] = true;  		} @@ -234,13 +245,14 @@ class phpbb_db_migrator  		{  			try  			{ +				$this->last_run_migration['task'] = 'process_data_step';  				$result = $this->process_data_step($migration->update_data(), $state['migration_data_state']);  				$state['migration_data_state'] = ($result === true) ? '' : $result;  				$state['migration_data_done'] = ($result === true);  				$state['migration_end_time'] = ($result === true) ? time() : 0;  			} -			catch (phpbb_db_migration_exception $e) +			catch (\phpbb\db\migration\exception $e)  			{  				// Revert the schema changes  				$this->revert($name); @@ -304,6 +316,7 @@ class phpbb_db_migrator  		$this->last_run_migration = array(  			'name'	=> $name,  			'class'	=> $migration, +			'task'	=> '',  		);  		if ($state['migration_data_done']) @@ -398,7 +411,7 @@ class phpbb_db_migrator  					));  				}  			} -			catch (phpbb_db_migration_exception $e) +			catch (\phpbb\db\migration\exception $e)  			{  				// We should try rolling back here  				foreach ($steps as $reverse_step_identifier => $reverse_step) @@ -474,12 +487,12 @@ class phpbb_db_migrator  			case 'if':  				if (!isset($parameters[0]))  				{ -					throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_MISSING_CONDITION', $step); +					throw new \phpbb\db\migration\exception('MIGRATION_INVALID_DATA_MISSING_CONDITION', $step);  				}  				if (!isset($parameters[1]))  				{ -					throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_MISSING_STEP', $step); +					throw new \phpbb\db\migration\exception('MIGRATION_INVALID_DATA_MISSING_STEP', $step);  				}  				$condition = $parameters[0]; @@ -496,7 +509,7 @@ class phpbb_db_migrator  			case 'custom':  				if (!is_callable($parameters[0]))  				{ -					throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_CUSTOM_NOT_CALLABLE', $step); +					throw new \phpbb\db\migration\exception('MIGRATION_INVALID_DATA_CUSTOM_NOT_CALLABLE', $step);  				}  				return array( @@ -508,17 +521,17 @@ class phpbb_db_migrator  			default:  				if (!$method)  				{ -					throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_UNKNOWN_TYPE', $step); +					throw new \phpbb\db\migration\exception('MIGRATION_INVALID_DATA_UNKNOWN_TYPE', $step);  				}  				if (!isset($this->tools[$class]))  				{ -					throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_UNDEFINED_TOOL', $step); +					throw new \phpbb\db\migration\exception('MIGRATION_INVALID_DATA_UNDEFINED_TOOL', $step);  				}  				if (!method_exists(get_class($this->tools[$class]), $method))  				{ -					throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_UNDEFINED_METHOD', $step); +					throw new \phpbb\db\migration\exception('MIGRATION_INVALID_DATA_UNDEFINED_METHOD', $step);  				}  				// Attempt to reverse operations @@ -622,6 +635,7 @@ class phpbb_db_migrator  				{  					continue;  				} +  				return false;  			} @@ -656,7 +670,7 @@ class phpbb_db_migrator  	* Helper to get a migration  	*  	* @param string $name Name of the migration -	* @return phpbb_db_migration +	* @return \phpbb\db\migration\migration  	*/  	protected function get_migration($name)  	{ @@ -694,7 +708,7 @@ class phpbb_db_migrator  	/**  	* Load migration data files from a directory  	* -	* @param phpbb_extension_finder $finder +	* @param \phpbb\extension\finder $finder  	* @param string $path Path to migration data files  	* @param bool $check_fulfillable If TRUE (default), we will check  	* 	if all of the migrations are fulfillable after loading them. @@ -703,11 +717,11 @@ class phpbb_db_migrator  	* 	with the last call to prevent throwing errors unnecessarily).  	* @return array Array of migration names  	*/ -	public function load_migrations(phpbb_extension_finder $finder, $path, $check_fulfillable = true) +	public function load_migrations(\phpbb\extension\finder $finder, $path, $check_fulfillable = true)  	{  		if (!is_dir($path))  		{ -			throw new phpbb_db_migration_exception('DIRECTORY INVALID', $path); +			throw new \phpbb\db\migration\exception('DIRECTORY INVALID', $path);  		}  		$migrations = array(); @@ -736,7 +750,7 @@ class phpbb_db_migrator  				$unfulfillable = $this->unfulfillable($name);  				if ($unfulfillable !== false)  				{ -					throw new phpbb_db_migration_exception('MIGRATION_NOT_FULFILLABLE', $name, $unfulfillable); +					throw new \phpbb\db\migration\exception('MIGRATION_NOT_FULFILLABLE', $name, $unfulfillable);  				}  			}  		} diff --git a/phpBB/phpbb/db/sql_insert_buffer.php b/phpBB/phpbb/db/sql_insert_buffer.php index c18f908429..7bbd213bdc 100644 --- a/phpBB/phpbb/db/sql_insert_buffer.php +++ b/phpBB/phpbb/db/sql_insert_buffer.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\db; +  /**  * @ignore  */ @@ -38,7 +40,7 @@ if (!defined('IN_PHPBB'))  *  * Usage:  * <code> -*	$buffer = new phpbb_db_sql_insert_buffer($db, 'test_table', 1234); +*	$buffer = new \phpbb\db\sql_insert_buffer($db, 'test_table', 1234);  *  *	while (do_stuff())  *	{ @@ -53,9 +55,9 @@ if (!defined('IN_PHPBB'))  *  * @package dbal  */ -class phpbb_db_sql_insert_buffer +class sql_insert_buffer  { -	/** @var phpbb_db_driver */ +	/** @var \phpbb\db\driver\driver */  	protected $db;  	/** @var string */ @@ -68,11 +70,11 @@ class phpbb_db_sql_insert_buffer  	protected $buffer = array();  	/** -	* @param phpbb_db_driver $db +	* @param \phpbb\db\driver\driver $db  	* @param string          $table_name  	* @param int             $max_buffered_rows  	*/ -	public function __construct(phpbb_db_driver $db, $table_name, $max_buffered_rows = 500) +	public function __construct(\phpbb\db\driver\driver $db, $table_name, $max_buffered_rows = 500)  	{  		$this->db = $db;  		$this->table_name = $table_name; diff --git a/phpBB/phpbb/db/tools.php b/phpBB/phpbb/db/tools.php index 492284ffcd..1f156fbb04 100644 --- a/phpBB/phpbb/db/tools.php +++ b/phpBB/phpbb/db/tools.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\db; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  *  * @package dbal  */ -class phpbb_db_tools +class tools  {  	/**  	* Current sql layer @@ -37,247 +39,257 @@ class phpbb_db_tools  	* The Column types for every database we support  	* @var array  	*/ -	var $dbms_type_map = array( -		'mysql_41'	=> array( -			'INT:'		=> 'int(%d)', -			'BINT'		=> 'bigint(20)', -			'UINT'		=> 'mediumint(8) UNSIGNED', -			'UINT:'		=> 'int(%d) UNSIGNED', -			'TINT:'		=> 'tinyint(%d)', -			'USINT'		=> 'smallint(4) UNSIGNED', -			'BOOL'		=> 'tinyint(1) UNSIGNED', -			'VCHAR'		=> 'varchar(255)', -			'VCHAR:'	=> 'varchar(%d)', -			'CHAR:'		=> 'char(%d)', -			'XSTEXT'	=> 'text', -			'XSTEXT_UNI'=> 'varchar(100)', -			'STEXT'		=> 'text', -			'STEXT_UNI'	=> 'varchar(255)', -			'TEXT'		=> 'text', -			'TEXT_UNI'	=> 'text', -			'MTEXT'		=> 'mediumtext', -			'MTEXT_UNI'	=> 'mediumtext', -			'TIMESTAMP'	=> 'int(11) UNSIGNED', -			'DECIMAL'	=> 'decimal(5,2)', -			'DECIMAL:'	=> 'decimal(%d,2)', -			'PDECIMAL'	=> 'decimal(6,3)', -			'PDECIMAL:'	=> 'decimal(%d,3)', -			'VCHAR_UNI'	=> 'varchar(255)', -			'VCHAR_UNI:'=> 'varchar(%d)', -			'VCHAR_CI'	=> 'varchar(255)', -			'VARBINARY'	=> 'varbinary(255)', -		), - -		'mysql_40'	=> array( -			'INT:'		=> 'int(%d)', -			'BINT'		=> 'bigint(20)', -			'UINT'		=> 'mediumint(8) UNSIGNED', -			'UINT:'		=> 'int(%d) UNSIGNED', -			'TINT:'		=> 'tinyint(%d)', -			'USINT'		=> 'smallint(4) UNSIGNED', -			'BOOL'		=> 'tinyint(1) UNSIGNED', -			'VCHAR'		=> 'varbinary(255)', -			'VCHAR:'	=> 'varbinary(%d)', -			'CHAR:'		=> 'binary(%d)', -			'XSTEXT'	=> 'blob', -			'XSTEXT_UNI'=> 'blob', -			'STEXT'		=> 'blob', -			'STEXT_UNI'	=> 'blob', -			'TEXT'		=> 'blob', -			'TEXT_UNI'	=> 'blob', -			'MTEXT'		=> 'mediumblob', -			'MTEXT_UNI'	=> 'mediumblob', -			'TIMESTAMP'	=> 'int(11) UNSIGNED', -			'DECIMAL'	=> 'decimal(5,2)', -			'DECIMAL:'	=> 'decimal(%d,2)', -			'PDECIMAL'	=> 'decimal(6,3)', -			'PDECIMAL:'	=> 'decimal(%d,3)', -			'VCHAR_UNI'	=> 'blob', -			'VCHAR_UNI:'=> array('varbinary(%d)', 'limit' => array('mult', 3, 255, 'blob')), -			'VCHAR_CI'	=> 'blob', -			'VARBINARY'	=> 'varbinary(255)', -		), - -		'firebird'	=> array( -			'INT:'		=> 'INTEGER', -			'BINT'		=> 'DOUBLE PRECISION', -			'UINT'		=> 'INTEGER', -			'UINT:'		=> 'INTEGER', -			'TINT:'		=> 'INTEGER', -			'USINT'		=> 'INTEGER', -			'BOOL'		=> 'INTEGER', -			'VCHAR'		=> 'VARCHAR(255) CHARACTER SET NONE', -			'VCHAR:'	=> 'VARCHAR(%d) CHARACTER SET NONE', -			'CHAR:'		=> 'CHAR(%d) CHARACTER SET NONE', -			'XSTEXT'	=> 'BLOB SUB_TYPE TEXT CHARACTER SET NONE', -			'STEXT'		=> 'BLOB SUB_TYPE TEXT CHARACTER SET NONE', -			'TEXT'		=> 'BLOB SUB_TYPE TEXT CHARACTER SET NONE', -			'MTEXT'		=> 'BLOB SUB_TYPE TEXT CHARACTER SET NONE', -			'XSTEXT_UNI'=> 'VARCHAR(100) CHARACTER SET UTF8', -			'STEXT_UNI'	=> 'VARCHAR(255) CHARACTER SET UTF8', -			'TEXT_UNI'	=> 'BLOB SUB_TYPE TEXT CHARACTER SET UTF8', -			'MTEXT_UNI'	=> 'BLOB SUB_TYPE TEXT CHARACTER SET UTF8', -			'TIMESTAMP'	=> 'INTEGER', -			'DECIMAL'	=> 'DOUBLE PRECISION', -			'DECIMAL:'	=> 'DOUBLE PRECISION', -			'PDECIMAL'	=> 'DOUBLE PRECISION', -			'PDECIMAL:'	=> 'DOUBLE PRECISION', -			'VCHAR_UNI'	=> 'VARCHAR(255) CHARACTER SET UTF8', -			'VCHAR_UNI:'=> 'VARCHAR(%d) CHARACTER SET UTF8', -			'VCHAR_CI'	=> 'VARCHAR(255) CHARACTER SET UTF8', -			'VARBINARY'	=> 'CHAR(255) CHARACTER SET NONE', -		), - -		'mssql'		=> array( -			'INT:'		=> '[int]', -			'BINT'		=> '[float]', -			'UINT'		=> '[int]', -			'UINT:'		=> '[int]', -			'TINT:'		=> '[int]', -			'USINT'		=> '[int]', -			'BOOL'		=> '[int]', -			'VCHAR'		=> '[varchar] (255)', -			'VCHAR:'	=> '[varchar] (%d)', -			'CHAR:'		=> '[char] (%d)', -			'XSTEXT'	=> '[varchar] (1000)', -			'STEXT'		=> '[varchar] (3000)', -			'TEXT'		=> '[varchar] (8000)', -			'MTEXT'		=> '[text]', -			'XSTEXT_UNI'=> '[varchar] (100)', -			'STEXT_UNI'	=> '[varchar] (255)', -			'TEXT_UNI'	=> '[varchar] (4000)', -			'MTEXT_UNI'	=> '[text]', -			'TIMESTAMP'	=> '[int]', -			'DECIMAL'	=> '[float]', -			'DECIMAL:'	=> '[float]', -			'PDECIMAL'	=> '[float]', -			'PDECIMAL:'	=> '[float]', -			'VCHAR_UNI'	=> '[varchar] (255)', -			'VCHAR_UNI:'=> '[varchar] (%d)', -			'VCHAR_CI'	=> '[varchar] (255)', -			'VARBINARY'	=> '[varchar] (255)', -		), - -		'mssqlnative'	=> array( -			'INT:'		=> '[int]', -			'BINT'		=> '[float]', -			'UINT'		=> '[int]', -			'UINT:'		=> '[int]', -			'TINT:'		=> '[int]', -			'USINT'		=> '[int]', -			'BOOL'		=> '[int]', -			'VCHAR'		=> '[varchar] (255)', -			'VCHAR:'	=> '[varchar] (%d)', -			'CHAR:'		=> '[char] (%d)', -			'XSTEXT'	=> '[varchar] (1000)', -			'STEXT'		=> '[varchar] (3000)', -			'TEXT'		=> '[varchar] (8000)', -			'MTEXT'		=> '[text]', -			'XSTEXT_UNI'=> '[varchar] (100)', -			'STEXT_UNI'	=> '[varchar] (255)', -			'TEXT_UNI'	=> '[varchar] (4000)', -			'MTEXT_UNI'	=> '[text]', -			'TIMESTAMP'	=> '[int]', -			'DECIMAL'	=> '[float]', -			'DECIMAL:'	=> '[float]', -			'PDECIMAL'	=> '[float]', -			'PDECIMAL:'	=> '[float]', -			'VCHAR_UNI'	=> '[varchar] (255)', -			'VCHAR_UNI:'=> '[varchar] (%d)', -			'VCHAR_CI'	=> '[varchar] (255)', -			'VARBINARY'	=> '[varchar] (255)', -		), - -		'oracle'	=> array( -			'INT:'		=> 'number(%d)', -			'BINT'		=> 'number(20)', -			'UINT'		=> 'number(8)', -			'UINT:'		=> 'number(%d)', -			'TINT:'		=> 'number(%d)', -			'USINT'		=> 'number(4)', -			'BOOL'		=> 'number(1)', -			'VCHAR'		=> 'varchar2(255)', -			'VCHAR:'	=> 'varchar2(%d)', -			'CHAR:'		=> 'char(%d)', -			'XSTEXT'	=> 'varchar2(1000)', -			'STEXT'		=> 'varchar2(3000)', -			'TEXT'		=> 'clob', -			'MTEXT'		=> 'clob', -			'XSTEXT_UNI'=> 'varchar2(300)', -			'STEXT_UNI'	=> 'varchar2(765)', -			'TEXT_UNI'	=> 'clob', -			'MTEXT_UNI'	=> 'clob', -			'TIMESTAMP'	=> 'number(11)', -			'DECIMAL'	=> 'number(5, 2)', -			'DECIMAL:'	=> 'number(%d, 2)', -			'PDECIMAL'	=> 'number(6, 3)', -			'PDECIMAL:'	=> 'number(%d, 3)', -			'VCHAR_UNI'	=> 'varchar2(765)', -			'VCHAR_UNI:'=> array('varchar2(%d)', 'limit' => array('mult', 3, 765, 'clob')), -			'VCHAR_CI'	=> 'varchar2(255)', -			'VARBINARY'	=> 'raw(255)', -		), - -		'sqlite'	=> array( -			'INT:'		=> 'int(%d)', -			'BINT'		=> 'bigint(20)', -			'UINT'		=> 'INTEGER UNSIGNED', //'mediumint(8) UNSIGNED', -			'UINT:'		=> 'INTEGER UNSIGNED', // 'int(%d) UNSIGNED', -			'TINT:'		=> 'tinyint(%d)', -			'USINT'		=> 'INTEGER UNSIGNED', //'mediumint(4) UNSIGNED', -			'BOOL'		=> 'INTEGER UNSIGNED', //'tinyint(1) UNSIGNED', -			'VCHAR'		=> 'varchar(255)', -			'VCHAR:'	=> 'varchar(%d)', -			'CHAR:'		=> 'char(%d)', -			'XSTEXT'	=> 'text(65535)', -			'STEXT'		=> 'text(65535)', -			'TEXT'		=> 'text(65535)', -			'MTEXT'		=> 'mediumtext(16777215)', -			'XSTEXT_UNI'=> 'text(65535)', -			'STEXT_UNI'	=> 'text(65535)', -			'TEXT_UNI'	=> 'text(65535)', -			'MTEXT_UNI'	=> 'mediumtext(16777215)', -			'TIMESTAMP'	=> 'INTEGER UNSIGNED', //'int(11) UNSIGNED', -			'DECIMAL'	=> 'decimal(5,2)', -			'DECIMAL:'	=> 'decimal(%d,2)', -			'PDECIMAL'	=> 'decimal(6,3)', -			'PDECIMAL:'	=> 'decimal(%d,3)', -			'VCHAR_UNI'	=> 'varchar(255)', -			'VCHAR_UNI:'=> 'varchar(%d)', -			'VCHAR_CI'	=> 'varchar(255)', -			'VARBINARY'	=> 'blob', -		), - -		'postgres'	=> array( -			'INT:'		=> 'INT4', -			'BINT'		=> 'INT8', -			'UINT'		=> 'INT4', // unsigned -			'UINT:'		=> 'INT4', // unsigned -			'USINT'		=> 'INT2', // unsigned -			'BOOL'		=> 'INT2', // unsigned -			'TINT:'		=> 'INT2', -			'VCHAR'		=> 'varchar(255)', -			'VCHAR:'	=> 'varchar(%d)', -			'CHAR:'		=> 'char(%d)', -			'XSTEXT'	=> 'varchar(1000)', -			'STEXT'		=> 'varchar(3000)', -			'TEXT'		=> 'varchar(8000)', -			'MTEXT'		=> 'TEXT', -			'XSTEXT_UNI'=> 'varchar(100)', -			'STEXT_UNI'	=> 'varchar(255)', -			'TEXT_UNI'	=> 'varchar(4000)', -			'MTEXT_UNI'	=> 'TEXT', -			'TIMESTAMP'	=> 'INT4', // unsigned -			'DECIMAL'	=> 'decimal(5,2)', -			'DECIMAL:'	=> 'decimal(%d,2)', -			'PDECIMAL'	=> 'decimal(6,3)', -			'PDECIMAL:'	=> 'decimal(%d,3)', -			'VCHAR_UNI'	=> 'varchar(255)', -			'VCHAR_UNI:'=> 'varchar(%d)', -			'VCHAR_CI'	=> 'varchar_ci', -			'VARBINARY'	=> 'bytea', -		), -	); +	var $dbms_type_map = array(); + +	/** +	* Get the column types for every database we support +	* +	* @return array +	*/ +	public static function get_dbms_type_map() +	{ +		return array( +			'mysql_41'	=> array( +				'INT:'		=> 'int(%d)', +				'BINT'		=> 'bigint(20)', +				'UINT'		=> 'mediumint(8) UNSIGNED', +				'UINT:'		=> 'int(%d) UNSIGNED', +				'TINT:'		=> 'tinyint(%d)', +				'USINT'		=> 'smallint(4) UNSIGNED', +				'BOOL'		=> 'tinyint(1) UNSIGNED', +				'VCHAR'		=> 'varchar(255)', +				'VCHAR:'	=> 'varchar(%d)', +				'CHAR:'		=> 'char(%d)', +				'XSTEXT'	=> 'text', +				'XSTEXT_UNI'=> 'varchar(100)', +				'STEXT'		=> 'text', +				'STEXT_UNI'	=> 'varchar(255)', +				'TEXT'		=> 'text', +				'TEXT_UNI'	=> 'text', +				'MTEXT'		=> 'mediumtext', +				'MTEXT_UNI'	=> 'mediumtext', +				'TIMESTAMP'	=> 'int(11) UNSIGNED', +				'DECIMAL'	=> 'decimal(5,2)', +				'DECIMAL:'	=> 'decimal(%d,2)', +				'PDECIMAL'	=> 'decimal(6,3)', +				'PDECIMAL:'	=> 'decimal(%d,3)', +				'VCHAR_UNI'	=> 'varchar(255)', +				'VCHAR_UNI:'=> 'varchar(%d)', +				'VCHAR_CI'	=> 'varchar(255)', +				'VARBINARY'	=> 'varbinary(255)', +			), + +			'mysql_40'	=> array( +				'INT:'		=> 'int(%d)', +				'BINT'		=> 'bigint(20)', +				'UINT'		=> 'mediumint(8) UNSIGNED', +				'UINT:'		=> 'int(%d) UNSIGNED', +				'TINT:'		=> 'tinyint(%d)', +				'USINT'		=> 'smallint(4) UNSIGNED', +				'BOOL'		=> 'tinyint(1) UNSIGNED', +				'VCHAR'		=> 'varbinary(255)', +				'VCHAR:'	=> 'varbinary(%d)', +				'CHAR:'		=> 'binary(%d)', +				'XSTEXT'	=> 'blob', +				'XSTEXT_UNI'=> 'blob', +				'STEXT'		=> 'blob', +				'STEXT_UNI'	=> 'blob', +				'TEXT'		=> 'blob', +				'TEXT_UNI'	=> 'blob', +				'MTEXT'		=> 'mediumblob', +				'MTEXT_UNI'	=> 'mediumblob', +				'TIMESTAMP'	=> 'int(11) UNSIGNED', +				'DECIMAL'	=> 'decimal(5,2)', +				'DECIMAL:'	=> 'decimal(%d,2)', +				'PDECIMAL'	=> 'decimal(6,3)', +				'PDECIMAL:'	=> 'decimal(%d,3)', +				'VCHAR_UNI'	=> 'blob', +				'VCHAR_UNI:'=> array('varbinary(%d)', 'limit' => array('mult', 3, 255, 'blob')), +				'VCHAR_CI'	=> 'blob', +				'VARBINARY'	=> 'varbinary(255)', +			), + +			'firebird'	=> array( +				'INT:'		=> 'INTEGER', +				'BINT'		=> 'DOUBLE PRECISION', +				'UINT'		=> 'INTEGER', +				'UINT:'		=> 'INTEGER', +				'TINT:'		=> 'INTEGER', +				'USINT'		=> 'INTEGER', +				'BOOL'		=> 'INTEGER', +				'VCHAR'		=> 'VARCHAR(255) CHARACTER SET NONE', +				'VCHAR:'	=> 'VARCHAR(%d) CHARACTER SET NONE', +				'CHAR:'		=> 'CHAR(%d) CHARACTER SET NONE', +				'XSTEXT'	=> 'BLOB SUB_TYPE TEXT CHARACTER SET NONE', +				'STEXT'		=> 'BLOB SUB_TYPE TEXT CHARACTER SET NONE', +				'TEXT'		=> 'BLOB SUB_TYPE TEXT CHARACTER SET NONE', +				'MTEXT'		=> 'BLOB SUB_TYPE TEXT CHARACTER SET NONE', +				'XSTEXT_UNI'=> 'VARCHAR(100) CHARACTER SET UTF8', +				'STEXT_UNI'	=> 'VARCHAR(255) CHARACTER SET UTF8', +				'TEXT_UNI'	=> 'BLOB SUB_TYPE TEXT CHARACTER SET UTF8', +				'MTEXT_UNI'	=> 'BLOB SUB_TYPE TEXT CHARACTER SET UTF8', +				'TIMESTAMP'	=> 'INTEGER', +				'DECIMAL'	=> 'DOUBLE PRECISION', +				'DECIMAL:'	=> 'DOUBLE PRECISION', +				'PDECIMAL'	=> 'DOUBLE PRECISION', +				'PDECIMAL:'	=> 'DOUBLE PRECISION', +				'VCHAR_UNI'	=> 'VARCHAR(255) CHARACTER SET UTF8', +				'VCHAR_UNI:'=> 'VARCHAR(%d) CHARACTER SET UTF8', +				'VCHAR_CI'	=> 'VARCHAR(255) CHARACTER SET UTF8', +				'VARBINARY'	=> 'CHAR(255) CHARACTER SET NONE', +			), + +			'mssql'		=> array( +				'INT:'		=> '[int]', +				'BINT'		=> '[float]', +				'UINT'		=> '[int]', +				'UINT:'		=> '[int]', +				'TINT:'		=> '[int]', +				'USINT'		=> '[int]', +				'BOOL'		=> '[int]', +				'VCHAR'		=> '[varchar] (255)', +				'VCHAR:'	=> '[varchar] (%d)', +				'CHAR:'		=> '[char] (%d)', +				'XSTEXT'	=> '[varchar] (1000)', +				'STEXT'		=> '[varchar] (3000)', +				'TEXT'		=> '[varchar] (8000)', +				'MTEXT'		=> '[text]', +				'XSTEXT_UNI'=> '[varchar] (100)', +				'STEXT_UNI'	=> '[varchar] (255)', +				'TEXT_UNI'	=> '[varchar] (4000)', +				'MTEXT_UNI'	=> '[text]', +				'TIMESTAMP'	=> '[int]', +				'DECIMAL'	=> '[float]', +				'DECIMAL:'	=> '[float]', +				'PDECIMAL'	=> '[float]', +				'PDECIMAL:'	=> '[float]', +				'VCHAR_UNI'	=> '[varchar] (255)', +				'VCHAR_UNI:'=> '[varchar] (%d)', +				'VCHAR_CI'	=> '[varchar] (255)', +				'VARBINARY'	=> '[varchar] (255)', +			), + +			'mssqlnative'	=> array( +				'INT:'		=> '[int]', +				'BINT'		=> '[float]', +				'UINT'		=> '[int]', +				'UINT:'		=> '[int]', +				'TINT:'		=> '[int]', +				'USINT'		=> '[int]', +				'BOOL'		=> '[int]', +				'VCHAR'		=> '[varchar] (255)', +				'VCHAR:'	=> '[varchar] (%d)', +				'CHAR:'		=> '[char] (%d)', +				'XSTEXT'	=> '[varchar] (1000)', +				'STEXT'		=> '[varchar] (3000)', +				'TEXT'		=> '[varchar] (8000)', +				'MTEXT'		=> '[text]', +				'XSTEXT_UNI'=> '[varchar] (100)', +				'STEXT_UNI'	=> '[varchar] (255)', +				'TEXT_UNI'	=> '[varchar] (4000)', +				'MTEXT_UNI'	=> '[text]', +				'TIMESTAMP'	=> '[int]', +				'DECIMAL'	=> '[float]', +				'DECIMAL:'	=> '[float]', +				'PDECIMAL'	=> '[float]', +				'PDECIMAL:'	=> '[float]', +				'VCHAR_UNI'	=> '[varchar] (255)', +				'VCHAR_UNI:'=> '[varchar] (%d)', +				'VCHAR_CI'	=> '[varchar] (255)', +				'VARBINARY'	=> '[varchar] (255)', +			), + +			'oracle'	=> array( +				'INT:'		=> 'number(%d)', +				'BINT'		=> 'number(20)', +				'UINT'		=> 'number(8)', +				'UINT:'		=> 'number(%d)', +				'TINT:'		=> 'number(%d)', +				'USINT'		=> 'number(4)', +				'BOOL'		=> 'number(1)', +				'VCHAR'		=> 'varchar2(255)', +				'VCHAR:'	=> 'varchar2(%d)', +				'CHAR:'		=> 'char(%d)', +				'XSTEXT'	=> 'varchar2(1000)', +				'STEXT'		=> 'varchar2(3000)', +				'TEXT'		=> 'clob', +				'MTEXT'		=> 'clob', +				'XSTEXT_UNI'=> 'varchar2(300)', +				'STEXT_UNI'	=> 'varchar2(765)', +				'TEXT_UNI'	=> 'clob', +				'MTEXT_UNI'	=> 'clob', +				'TIMESTAMP'	=> 'number(11)', +				'DECIMAL'	=> 'number(5, 2)', +				'DECIMAL:'	=> 'number(%d, 2)', +				'PDECIMAL'	=> 'number(6, 3)', +				'PDECIMAL:'	=> 'number(%d, 3)', +				'VCHAR_UNI'	=> 'varchar2(765)', +				'VCHAR_UNI:'=> array('varchar2(%d)', 'limit' => array('mult', 3, 765, 'clob')), +				'VCHAR_CI'	=> 'varchar2(255)', +				'VARBINARY'	=> 'raw(255)', +			), + +			'sqlite'	=> array( +				'INT:'		=> 'int(%d)', +				'BINT'		=> 'bigint(20)', +				'UINT'		=> 'INTEGER UNSIGNED', //'mediumint(8) UNSIGNED', +				'UINT:'		=> 'INTEGER UNSIGNED', // 'int(%d) UNSIGNED', +				'TINT:'		=> 'tinyint(%d)', +				'USINT'		=> 'INTEGER UNSIGNED', //'mediumint(4) UNSIGNED', +				'BOOL'		=> 'INTEGER UNSIGNED', //'tinyint(1) UNSIGNED', +				'VCHAR'		=> 'varchar(255)', +				'VCHAR:'	=> 'varchar(%d)', +				'CHAR:'		=> 'char(%d)', +				'XSTEXT'	=> 'text(65535)', +				'STEXT'		=> 'text(65535)', +				'TEXT'		=> 'text(65535)', +				'MTEXT'		=> 'mediumtext(16777215)', +				'XSTEXT_UNI'=> 'text(65535)', +				'STEXT_UNI'	=> 'text(65535)', +				'TEXT_UNI'	=> 'text(65535)', +				'MTEXT_UNI'	=> 'mediumtext(16777215)', +				'TIMESTAMP'	=> 'INTEGER UNSIGNED', //'int(11) UNSIGNED', +				'DECIMAL'	=> 'decimal(5,2)', +				'DECIMAL:'	=> 'decimal(%d,2)', +				'PDECIMAL'	=> 'decimal(6,3)', +				'PDECIMAL:'	=> 'decimal(%d,3)', +				'VCHAR_UNI'	=> 'varchar(255)', +				'VCHAR_UNI:'=> 'varchar(%d)', +				'VCHAR_CI'	=> 'varchar(255)', +				'VARBINARY'	=> 'blob', +			), + +			'postgres'	=> array( +				'INT:'		=> 'INT4', +				'BINT'		=> 'INT8', +				'UINT'		=> 'INT4', // unsigned +				'UINT:'		=> 'INT4', // unsigned +				'USINT'		=> 'INT2', // unsigned +				'BOOL'		=> 'INT2', // unsigned +				'TINT:'		=> 'INT2', +				'VCHAR'		=> 'varchar(255)', +				'VCHAR:'	=> 'varchar(%d)', +				'CHAR:'		=> 'char(%d)', +				'XSTEXT'	=> 'varchar(1000)', +				'STEXT'		=> 'varchar(3000)', +				'TEXT'		=> 'varchar(8000)', +				'MTEXT'		=> 'TEXT', +				'XSTEXT_UNI'=> 'varchar(100)', +				'STEXT_UNI'	=> 'varchar(255)', +				'TEXT_UNI'	=> 'varchar(4000)', +				'MTEXT_UNI'	=> 'TEXT', +				'TIMESTAMP'	=> 'INT4', // unsigned +				'DECIMAL'	=> 'decimal(5,2)', +				'DECIMAL:'	=> 'decimal(%d,2)', +				'PDECIMAL'	=> 'decimal(6,3)', +				'PDECIMAL:'	=> 'decimal(%d,3)', +				'VCHAR_UNI'	=> 'varchar(255)', +				'VCHAR_UNI:'=> 'varchar(%d)', +				'VCHAR_CI'	=> 'varchar_ci', +				'VARBINARY'	=> 'bytea', +			), +		); +	}  	/**  	* A list of types being unsigned for better reference in some db's @@ -300,14 +312,16 @@ class phpbb_db_tools  	/**  	* Constructor. Set DB Object and set {@link $return_statements return_statements}.  	* -	* @param phpbb_db_driver	$db					Database connection +	* @param \phpbb\db\driver\driver	$db					Database connection  	* @param bool		$return_statements	True if only statements should be returned and no SQL being executed  	*/ -	public function __construct(phpbb_db_driver $db, $return_statements = false) +	public function __construct(\phpbb\db\driver\driver $db, $return_statements = false)  	{  		$this->db = $db;  		$this->return_statements = $return_statements; +		$this->dbms_type_map = self::get_dbms_type_map(); +  		// Determine mapping database type  		switch ($this->db->sql_layer)  		{ diff --git a/phpBB/phpbb/di/extension/config.php b/phpBB/phpbb/di/extension/config.php index 6c272a6588..85b374a3ca 100644 --- a/phpBB/phpbb/di/extension/config.php +++ b/phpBB/phpbb/di/extension/config.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\di\extension; +  /**  * @ignore  */ @@ -23,7 +25,7 @@ use Symfony\Component\Config\FileLocator;  /**  * Container config extension  */ -class phpbb_di_extension_config extends Extension +class config extends Extension  {  	public function __construct($config_file)  	{ @@ -76,7 +78,7 @@ class phpbb_di_extension_config extends Extension  	{  		if (preg_match('#^[a-z]+$#', $acm_type))  		{ -			return 'phpbb_cache_driver_'.$acm_type; +			return '\\phpbb\cache\driver\\'.$acm_type;  		}  		return $acm_type; diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index 9c36ba2fc4..1f6b700973 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\di\extension; +  /**  * @ignore  */ @@ -23,22 +25,22 @@ use Symfony\Component\Config\FileLocator;  /**  * Container core extension  */ -class phpbb_di_extension_core extends Extension +class core extends Extension  {  	/** -	* phpBB Root path +	* Config path  	* @var string  	*/ -	protected $root_path; +	protected $config_path;  	/**  	* Constructor  	* -	* @param string $root_path Root path +	* @param string $config_path Config path  	*/ -	public function __construct($root_path) +	public function __construct($config_path)  	{ -		$this->root_path = $root_path; +		$this->config_path = $config_path;  	}  	/** @@ -51,7 +53,7 @@ class phpbb_di_extension_core extends Extension  	*/  	public function load(array $config, ContainerBuilder $container)  	{ -		$loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($this->root_path . 'config'))); +		$loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($this->config_path)));  		$loader->load('services.yml');  	} diff --git a/phpBB/phpbb/di/extension/ext.php b/phpBB/phpbb/di/extension/ext.php index 7d9b433751..cf623a7c87 100644 --- a/phpBB/phpbb/di/extension/ext.php +++ b/phpBB/phpbb/di/extension/ext.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\di\extension; +  /**  * @ignore  */ @@ -23,7 +25,7 @@ use Symfony\Component\Config\FileLocator;  /**  * Container ext extension  */ -class phpbb_di_extension_ext extends Extension +class ext extends Extension  {  	protected $paths = array(); diff --git a/phpBB/phpbb/di/pass/collection_pass.php b/phpBB/phpbb/di/pass/collection_pass.php index 63a5c7dfc4..ffc5a41f6d 100644 --- a/phpBB/phpbb/di/pass/collection_pass.php +++ b/phpBB/phpbb/di/pass/collection_pass.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\di\pass; +  /**  * @ignore  */ @@ -23,7 +25,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;  * the services tagged with the appropriate name defined in the collection's  * service_collection tag.  */ -class phpbb_di_pass_collection_pass implements CompilerPassInterface +class collection_pass implements CompilerPassInterface  {  	/**  	* Modify the container before it is passed to the rest of the code diff --git a/phpBB/phpbb/di/pass/kernel_pass.php b/phpBB/phpbb/di/pass/kernel_pass.php index a701ebcfa6..6a9124ad78 100644 --- a/phpBB/phpbb/di/pass/kernel_pass.php +++ b/phpBB/phpbb/di/pass/kernel_pass.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\di\pass; +  /**  * @ignore  */ @@ -18,7 +20,7 @@ if (!defined('IN_PHPBB'))  use Symfony\Component\DependencyInjection\ContainerBuilder;  use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -class phpbb_di_pass_kernel_pass implements CompilerPassInterface +class kernel_pass implements CompilerPassInterface  {  	/**  	* Modify the container before it is passed to the rest of the code @@ -38,12 +40,12 @@ class phpbb_di_pass_kernel_pass implements CompilerPassInterface  				if (!isset($event['event']))  				{ -					throw new InvalidArgumentException(sprintf('Service "%1$s" must define the "event" attribute on "kernel.event_listener" tags.', $id)); +					throw new \InvalidArgumentException(sprintf('Service "%1$s" must define the "event" attribute on "kernel.event_listener" tags.', $id));  				}  				if (!isset($event['method']))  				{ -					throw new InvalidArgumentException(sprintf('Service "%1$s" must define the "method" attribute on "kernel.event_listener" tags.', $id)); +					throw new \InvalidArgumentException(sprintf('Service "%1$s" must define the "method" attribute on "kernel.event_listener" tags.', $id));  				}  				$definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority)); @@ -55,11 +57,11 @@ class phpbb_di_pass_kernel_pass implements CompilerPassInterface  			// We must assume that the class value has been correctly filled, even if the service is created by a factory  			$class = $container->getDefinition($id)->getClass(); -			$refClass = new ReflectionClass($class); +			$refClass = new \ReflectionClass($class);  			$interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface';  			if (!$refClass->implementsInterface($interface))  			{ -				throw new InvalidArgumentException(sprintf('Service "%1$s" must implement interface "%2$s".', $id, $interface)); +				throw new \InvalidArgumentException(sprintf('Service "%1$s" must implement interface "%2$s".', $id, $interface));  			}  			$definition->addMethodCall('addSubscriberService', array($id, $class)); diff --git a/phpBB/phpbb/di/service_collection.php b/phpBB/phpbb/di/service_collection.php index 880cb46d4d..fccdd77071 100644 --- a/phpBB/phpbb/di/service_collection.php +++ b/phpBB/phpbb/di/service_collection.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\di; +  /**  * @ignore  */ @@ -22,7 +24,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;  *  * @package phpBB3  */ -class phpbb_di_service_collection extends ArrayObject +class service_collection extends \ArrayObject  {  	/**  	* Constructor diff --git a/phpBB/phpbb/error_collector.php b/phpBB/phpbb/error_collector.php index 358da747b8..9b3216e32f 100644 --- a/phpBB/phpbb/error_collector.php +++ b/phpBB/phpbb/error_collector.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb; +  /**  * @ignore  */ @@ -15,11 +17,11 @@ if (!defined('IN_PHPBB'))  	exit;  } -class phpbb_error_collector +class error_collector  {  	var $errors; -	function phpbb_error_collector() +	function __construct()  	{  		$this->errors = array();  	} diff --git a/phpBB/phpbb/event/data.php b/phpBB/phpbb/event/data.php index 70718ff0ae..3481023b74 100644 --- a/phpBB/phpbb/event/data.php +++ b/phpBB/phpbb/event/data.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\event; +  /**  * @ignore  */ @@ -17,7 +19,7 @@ if (!defined('IN_PHPBB'))  use Symfony\Component\EventDispatcher\Event; -class phpbb_event_data extends Event implements ArrayAccess +class data extends Event implements \ArrayAccess  {      private $data; diff --git a/phpBB/phpbb/event/dispatcher.php b/phpBB/phpbb/event/dispatcher.php index 4f637ce3bb..cc3733692e 100644 --- a/phpBB/phpbb/event/dispatcher.php +++ b/phpBB/phpbb/event/dispatcher.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\event; +  /**  * @ignore  */ @@ -31,11 +33,11 @@ use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;  *     extract($phpbb_dispatcher->trigger_event('core.index', compact($vars)));  *  */ -class phpbb_event_dispatcher extends ContainerAwareEventDispatcher +class dispatcher extends ContainerAwareEventDispatcher  {  	public function trigger_event($eventName, $data = array())  	{ -		$event = new phpbb_event_data($data); +		$event = new \phpbb\event\data($data);  		$this->dispatch($eventName, $event);  		return $event->get_data_filtered(array_keys($data));  	} diff --git a/phpBB/phpbb/event/extension_subscriber_loader.php b/phpBB/phpbb/event/extension_subscriber_loader.php index d933b943d7..ab50a589fe 100644 --- a/phpBB/phpbb/event/extension_subscriber_loader.php +++ b/phpBB/phpbb/event/extension_subscriber_loader.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\event; +  /**  * @ignore  */ @@ -17,12 +19,12 @@ if (!defined('IN_PHPBB'))  use Symfony\Component\EventDispatcher\EventDispatcherInterface; -class phpbb_event_extension_subscriber_loader +class extension_subscriber_loader  {  	private $dispatcher;  	private $extension_manager; -	public function __construct(EventDispatcherInterface $dispatcher, phpbb_extension_manager $extension_manager) +	public function __construct(EventDispatcherInterface $dispatcher, \phpbb\extension\manager $extension_manager)  	{  		$this->dispatcher = $dispatcher;  		$this->extension_manager = $extension_manager; @@ -33,7 +35,6 @@ class phpbb_event_extension_subscriber_loader  		$finder = $this->extension_manager->get_finder();  		$subscriber_classes = $finder  			->extension_directory('/event') -			->suffix('listener')  			->core_path('event/')  			->get_classes(); diff --git a/phpBB/phpbb/event/kernel_exception_subscriber.php b/phpBB/phpbb/event/kernel_exception_subscriber.php index f90989a74c..09103680e8 100644 --- a/phpBB/phpbb/event/kernel_exception_subscriber.php +++ b/phpBB/phpbb/event/kernel_exception_subscriber.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\event; +  /**  * @ignore  */ @@ -21,27 +23,27 @@ use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;  use Symfony\Component\HttpKernel\Exception\HttpException;  use Symfony\Component\HttpFoundation\Response; -class phpbb_event_kernel_exception_subscriber implements EventSubscriberInterface +class kernel_exception_subscriber implements EventSubscriberInterface  {  	/**  	* Template object -	* @var phpbb_template +	* @var \phpbb\template\template  	*/  	protected $template;  	/**  	* User object -	* @var phpbb_user +	* @var \phpbb\user  	*/  	protected $user;  	/**  	* Construct method  	* -	* @param phpbb_template $template Template object -	* @param phpbb_user $user User object +	* @param \phpbb\template\template $template Template object +	* @param \phpbb\user $user User object  	*/ -	public function __construct(phpbb_template $template, phpbb_user $user) +	public function __construct(\phpbb\template\template $template, \phpbb\user $user)  	{  		$this->template = $template;  		$this->user = $user; diff --git a/phpBB/phpbb/event/kernel_request_subscriber.php b/phpBB/phpbb/event/kernel_request_subscriber.php index afb8464f80..a629dd8440 100644 --- a/phpBB/phpbb/event/kernel_request_subscriber.php +++ b/phpBB/phpbb/event/kernel_request_subscriber.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\event; +  /**  * @ignore  */ @@ -21,11 +23,11 @@ use Symfony\Component\HttpKernel\Event\GetResponseEvent;  use Symfony\Component\HttpKernel\EventListener\RouterListener;  use Symfony\Component\Routing\RequestContext; -class phpbb_event_kernel_request_subscriber implements EventSubscriberInterface +class kernel_request_subscriber implements EventSubscriberInterface  {  	/**  	* Extension finder object -	* @var phpbb_extension_finder +	* @var \phpbb\extension\finder  	*/  	protected $finder; @@ -44,11 +46,11 @@ class phpbb_event_kernel_request_subscriber implements EventSubscriberInterface  	/**  	* Construct method  	* -	* @param phpbb_extension_finder $finder Extension finder object +	* @param \phpbb\extension\finder $finder Extension finder object  	* @param string $root_path Root path  	* @param string $php_ext PHP extension  	*/ -	public function __construct(phpbb_extension_finder $finder, $root_path, $php_ext) +	public function __construct(\phpbb\extension\finder $finder, $root_path, $php_ext)  	{  		$this->finder = $finder;  		$this->root_path = $root_path; diff --git a/phpBB/phpbb/event/kernel_terminate_subscriber.php b/phpBB/phpbb/event/kernel_terminate_subscriber.php index 1eaf890e42..de441da102 100644 --- a/phpBB/phpbb/event/kernel_terminate_subscriber.php +++ b/phpBB/phpbb/event/kernel_terminate_subscriber.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\event; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;  use Symfony\Component\HttpKernel\KernelEvents;  use Symfony\Component\HttpKernel\Event\PostResponseEvent; -class phpbb_event_kernel_terminate_subscriber implements EventSubscriberInterface +class kernel_terminate_subscriber implements EventSubscriberInterface  {  	/**  	* This listener is run when the KernelEvents::TERMINATE event is triggered diff --git a/phpBB/phpbb/extension/base.php b/phpBB/phpbb/extension/base.php index c4462b64d8..a529cc7961 100644 --- a/phpBB/phpbb/extension/base.php +++ b/phpBB/phpbb/extension/base.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\extension; +  /**  * @ignore  */ @@ -22,15 +24,15 @@ use Symfony\Component\DependencyInjection\ContainerInterface;  *  * @package extension  */ -class phpbb_extension_base implements phpbb_extension_interface +class base implements \phpbb\extension\extension_interface  {  	/** @var ContainerInterface */  	protected $container; -	/** @var phpbb_extension_finder */ +	/** @var \phpbb\extension\finder */  	protected $finder; -	/** @var phpbb_db_migrator */ +	/** @var \phpbb\db\migrator */  	protected $migrator;  	/** @var string */ @@ -43,11 +45,11 @@ class phpbb_extension_base implements phpbb_extension_interface  	* Constructor  	*  	* @param ContainerInterface $container Container object -	* @param phpbb_extension_finder $extension_finder +	* @param \phpbb\extension\finder $extension_finder  	* @param string $extension_name Name of this extension (from ext.manager)  	* @param string $extension_path Relative path to this extension  	*/ -	public function __construct(ContainerInterface $container, phpbb_extension_finder $extension_finder, phpbb_db_migrator $migrator, $extension_name, $extension_path) +	public function __construct(ContainerInterface $container, \phpbb\extension\finder $extension_finder, \phpbb\db\migrator $migrator, $extension_name, $extension_path)  	{  		$this->container = $container;  		$this->extension_finder = $extension_finder; diff --git a/phpBB/phpbb/extension/exception.php b/phpBB/phpbb/extension/exception.php index e08a8912ea..e2ba647878 100644 --- a/phpBB/phpbb/extension/exception.php +++ b/phpBB/phpbb/extension/exception.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\extension; +  /**  * @ignore  */ @@ -18,7 +20,7 @@ if (!defined('IN_PHPBB'))  /**   * Exception class for metadata   */ -class phpbb_extension_exception extends UnexpectedValueException +class exception extends \UnexpectedValueException  {  	public function __toString()  	{ diff --git a/phpBB/phpbb/extension/interface.php b/phpBB/phpbb/extension/extension_interface.php index 7b36a12bf6..1e5f546dc5 100644 --- a/phpBB/phpbb/extension/interface.php +++ b/phpBB/phpbb/extension/extension_interface.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\extension; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  *  * @package extension  */ -interface phpbb_extension_interface +interface extension_interface  {  	/**  	* enable_step is executed on enabling an extension until it returns false. diff --git a/phpBB/phpbb/extension/finder.php b/phpBB/phpbb/extension/finder.php index 155a41cda5..e787919588 100644 --- a/phpBB/phpbb/extension/finder.php +++ b/phpBB/phpbb/extension/finder.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\extension; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  *  * @package extension  */ -class phpbb_extension_finder +class finder  {  	protected $extension_manager;  	protected $filesystem; @@ -52,17 +54,17 @@ class phpbb_extension_finder  	/**  	* Creates a new finder instance with its dependencies  	* -	* @param phpbb_extension_manager $extension_manager An extension manager +	* @param \phpbb\extension\manager $extension_manager An extension manager  	*            instance that provides the finder with a list of active  	*            extensions and their locations -	* @param phpbb_filesystem $filesystem Filesystem instance +	* @param \phpbb\filesystem $filesystem Filesystem instance  	* @param string $phpbb_root_path Path to the phpbb root directory -	* @param phpbb_cache_driver_interface $cache A cache instance or null +	* @param \phpbb\cache\driver\driver_interface $cache A cache instance or null  	* @param string $php_ext php file extension  	* @param string $cache_name The name of the cache variable, defaults to  	*                           _ext_finder  	*/ -	public function __construct(phpbb_extension_manager $extension_manager, phpbb_filesystem $filesystem, $phpbb_root_path = '', phpbb_cache_driver_interface $cache = null, $php_ext = 'php', $cache_name = '_ext_finder') +	public function __construct(\phpbb\extension\manager $extension_manager, \phpbb\filesystem $filesystem, $phpbb_root_path = '', \phpbb\cache\driver\driver_interface $cache = null, $php_ext = 'php', $cache_name = '_ext_finder')  	{  		$this->extension_manager = $extension_manager;  		$this->filesystem = $filesystem; @@ -88,7 +90,7 @@ class phpbb_extension_finder  	* Sets a core path to be searched in addition to extensions  	*  	* @param string $core_path The path relative to phpbb_root_path -	* @return phpbb_extension_finder This object for chaining calls +	* @return \phpbb\extension\finder This object for chaining calls  	*/  	public function core_path($core_path)  	{ @@ -104,7 +106,7 @@ class phpbb_extension_finder  	* file extension is automatically added to suffixes.  	*  	* @param string $suffix A filename suffix -	* @return phpbb_extension_finder This object for chaining calls +	* @return \phpbb\extension\finder This object for chaining calls  	*/  	public function suffix($suffix)  	{ @@ -121,7 +123,7 @@ class phpbb_extension_finder  	* file extension is automatically added to suffixes.  	*  	* @param string $extension_suffix A filename suffix -	* @return phpbb_extension_finder This object for chaining calls +	* @return \phpbb\extension\finder This object for chaining calls  	*/  	public function extension_suffix($extension_suffix)  	{ @@ -137,7 +139,7 @@ class phpbb_extension_finder  	* file extension is automatically added to suffixes.  	*  	* @param string $core_suffix A filename suffix -	* @return phpbb_extension_finder This object for chaining calls +	* @return \phpbb\extension\finder This object for chaining calls  	*/  	public function core_suffix($core_suffix)  	{ @@ -149,7 +151,7 @@ class phpbb_extension_finder  	* Sets the prefix all files found in extensions and core must match  	*  	* @param string $prefix A filename prefix -	* @return phpbb_extension_finder This object for chaining calls +	* @return \phpbb\extension\finder This object for chaining calls  	*/  	public function prefix($prefix)  	{ @@ -162,7 +164,7 @@ class phpbb_extension_finder  	* Sets a prefix all files found in extensions must match  	*  	* @param string $extension_prefix A filename prefix -	* @return phpbb_extension_finder This object for chaining calls +	* @return \phpbb\extension\finder This object for chaining calls  	*/  	public function extension_prefix($extension_prefix)  	{ @@ -174,7 +176,7 @@ class phpbb_extension_finder  	* Sets a prefix all files found in the core path must match  	*  	* @param string $core_prefix A filename prefix -	* @return phpbb_extension_finder This object for chaining calls +	* @return \phpbb\extension\finder This object for chaining calls  	*/  	public function core_prefix($core_prefix)  	{ @@ -189,7 +191,7 @@ class phpbb_extension_finder  	* the current directory.  	*  	* @param string $directory -	* @return phpbb_extension_finder This object for chaining calls +	* @return \phpbb\extension\finder This object for chaining calls  	*/  	public function directory($directory)  	{ @@ -202,7 +204,7 @@ class phpbb_extension_finder  	* Sets a directory all files found in extensions must be contained in  	*  	* @param string $extension_directory -	* @return phpbb_extension_finder This object for chaining calls +	* @return \phpbb\extension\finder This object for chaining calls  	*/  	public function extension_directory($extension_directory)  	{ @@ -214,7 +216,7 @@ class phpbb_extension_finder  	* Sets a directory all files found in the core path must be contained in  	*  	* @param string $core_directory -	* @return phpbb_extension_finder This object for chaining calls +	* @return \phpbb\extension\finder This object for chaining calls  	*/  	public function core_directory($core_directory)  	{ @@ -275,9 +277,17 @@ class phpbb_extension_finder  		$classes = array();  		foreach ($files as $file => $ext_name)  		{ -			$file = preg_replace('#^(phpbb|includes)/#', '', $file); - -			$classes[] = 'phpbb_' . str_replace('/', '_', substr($file, 0, -strlen('.' . $this->php_ext))); +			$class = substr($file, 0, -strlen('.' . $this->php_ext)); +			if ($ext_name === '/' && preg_match('#^includes/#', $file)) +			{ +				$class = preg_replace('#^includes/#', '', $class); +				$classes[] = 'phpbb_' . str_replace('/', '_', $class); +			} +			else +			{ +				$class = preg_replace('#^ext/#', '', $class); +				$classes[] = '\\' . str_replace('/', '\\', $class); +			}  		}  		return $classes;  	} @@ -473,7 +483,7 @@ class phpbb_extension_finder  			}  			$directory_pattern = '#' . $directory_pattern . '#'; -			$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); +			$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST);  			foreach ($iterator as $file_info)  			{  				$filename = $file_info->getFilename(); diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php index 4451049d04..ce6d7e05c8 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\extension; +  /**  * @ignore  */ @@ -22,7 +24,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;  *  * @package extension  */ -class phpbb_extension_manager +class manager  {  	/** @var ContainerInterface */  	protected $container; @@ -40,16 +42,16 @@ class phpbb_extension_manager  	* Creates a manager and loads information from database  	*  	* @param ContainerInterface $container A container -	* @param phpbb_db_driver $db A database connection -	* @param phpbb_config $config phpbb_config -	* @param phpbb_filesystem $filesystem +	* @param \phpbb\db\driver\driver $db A database connection +	* @param \phpbb\config\config $config \phpbb\config\config +	* @param \phpbb\filesystem $filesystem  	* @param string $extension_table The name of the table holding extensions  	* @param string $phpbb_root_path Path to the phpbb includes directory.  	* @param string $php_ext php file extension -	* @param phpbb_cache_driver_interface $cache A cache instance or null +	* @param \phpbb\cache\driver\driver_interface $cache A cache instance or null  	* @param string $cache_name The name of the cache variable, defaults to _ext  	*/ -	public function __construct(ContainerInterface $container, phpbb_db_driver $db, phpbb_config $config, phpbb_filesystem $filesystem, $extension_table, $phpbb_root_path, $php_ext = 'php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') +	public function __construct(ContainerInterface $container, \phpbb\db\driver\driver $db, \phpbb\config\config $config, \phpbb\filesystem $filesystem, $extension_table, $phpbb_root_path, $php_ext = 'php', \phpbb\cache\driver\driver_interface $cache = null, $cache_name = '_ext')  	{  		$this->container = $container;  		$this->phpbb_root_path = $phpbb_root_path; @@ -126,12 +128,12 @@ class phpbb_extension_manager  	* Instantiates the extension meta class for the extension with the given name  	*  	* @param string $name The extension name -	* @return phpbb_extension_interface Instance of the extension meta class or -	*                     phpbb_extension_base if the class does not exist +	* @return \phpbb\extension\extension_interface Instance of the extension meta class or +	*                     \phpbb\extension\base if the class does not exist  	*/  	public function get_extension($name)  	{ -		$extension_class_name = 'phpbb_ext_' . str_replace('/', '_', $name) . '_ext'; +		$extension_class_name = str_replace('/', '\\', $name) . '\\ext';  		$migrator = $this->container->get('migrator'); @@ -141,7 +143,7 @@ class phpbb_extension_manager  		}  		else  		{ -			return new phpbb_extension_base($this->container, $this->get_finder(), $migrator, $name, $this->get_extension_path($name, true)); +			return new \phpbb\extension\base($this->container, $this->get_finder(), $migrator, $name, $this->get_extension_path($name, true));  		}  	} @@ -150,11 +152,11 @@ class phpbb_extension_manager  	*  	* @param string $name The extension name  	* @param string $template The template manager -	* @return phpbb_extension_metadata_manager Instance of the metadata manager +	* @return \phpbb\extension\metadata_manager Instance of the metadata manager  	*/ -	public function create_extension_metadata_manager($name, phpbb_template $template) +	public function create_extension_metadata_manager($name, \phpbb\template\template $template)  	{ -		return new phpbb_extension_metadata_manager($name, $this->config, $this, $template, $this->phpbb_root_path); +		return new \phpbb\extension\metadata_manager($name, $this->config, $this, $template, $this->phpbb_root_path);  	}  	/** @@ -403,9 +405,9 @@ class phpbb_extension_manager  			return $available;  		} -		$iterator = new RecursiveIteratorIterator( -			new RecursiveDirectoryIterator($this->phpbb_root_path . 'ext/', FilesystemIterator::NEW_CURRENT_AND_KEY | FilesystemIterator::FOLLOW_SYMLINKS), -			RecursiveIteratorIterator::SELF_FIRST); +		$iterator = new \RecursiveIteratorIterator( +			new \RecursiveDirectoryIterator($this->phpbb_root_path . 'ext/', \FilesystemIterator::NEW_CURRENT_AND_KEY | \FilesystemIterator::FOLLOW_SYMLINKS), +			\RecursiveIteratorIterator::SELF_FIRST);  		foreach ($iterator as $file_info)  		{  			if ($file_info->isFile() && $file_info->getFilename() == 'ext.' . $this->php_ext) @@ -502,12 +504,12 @@ class phpbb_extension_manager  	}  	/** -	* Instantiates a phpbb_extension_finder. +	* Instantiates a \phpbb\extension\finder.  	* -	* @return phpbb_extension_finder An extension finder instance +	* @return \phpbb\extension\finder An extension finder instance  	*/  	public function get_finder()  	{ -		return new phpbb_extension_finder($this, $this->filesystem, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder'); +		return new \phpbb\extension\finder($this, $this->filesystem, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder');  	}  } diff --git a/phpBB/phpbb/extension/metadata_manager.php b/phpBB/phpbb/extension/metadata_manager.php index 14b77c085b..19c6288e96 100644 --- a/phpBB/phpbb/extension/metadata_manager.php +++ b/phpBB/phpbb/extension/metadata_manager.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\extension; +  /**  * @ignore  */ @@ -20,23 +22,23 @@ if (!defined('IN_PHPBB'))  *  * @package extension  */ -class phpbb_extension_metadata_manager +class metadata_manager  {  	/**  	* phpBB Config instance -	* @var phpbb_config +	* @var \phpbb\config\config  	*/  	protected $config;  	/**  	* phpBB Extension Manager -	* @var phpbb_extension_manager +	* @var \phpbb\extension\manager  	*/  	protected $extension_manager;  	/**  	* phpBB Template instance -	* @var phpbb_template +	* @var \phpbb\template\template  	*/  	protected $template; @@ -68,12 +70,12 @@ class phpbb_extension_metadata_manager  	* Creates the metadata manager  	*  	* @param string				$ext_name			Name (including vendor) of the extension -	* @param phpbb_config		$config				phpBB Config instance -	* @param phpbb_extension_manager	$extension_manager An instance of the phpBBb extension manager -	* @param phpbb_template		$template			phpBB Template instance +	* @param \phpbb\config\config		$config				phpBB Config instance +	* @param \phpbb\extension\manager	$extension_manager An instance of the phpBBb extension manager +	* @param \phpbb\template\template		$template			phpBB Template instance  	* @param string				$phpbb_root_path	Path to the phpbb includes directory.  	*/ -	public function __construct($ext_name, phpbb_config $config, phpbb_extension_manager $extension_manager, phpbb_template $template, $phpbb_root_path) +	public function __construct($ext_name, \phpbb\config\config $config, \phpbb\extension\manager $extension_manager, \phpbb\template\template $template, $phpbb_root_path)  	{  		$this->config = $config;  		$this->extension_manager = $extension_manager; @@ -145,7 +147,7 @@ class phpbb_extension_metadata_manager  		if (!file_exists($this->metadata_file))  		{ -    		throw new phpbb_extension_exception('The required file does not exist: ' . $this->metadata_file); +    		throw new \phpbb\extension\exception('The required file does not exist: ' . $this->metadata_file);  		}  	} @@ -158,18 +160,18 @@ class phpbb_extension_metadata_manager  	{  		if (!file_exists($this->metadata_file))  		{ -			throw new phpbb_extension_exception('The required file does not exist: ' . $this->metadata_file); +			throw new \phpbb\extension\exception('The required file does not exist: ' . $this->metadata_file);  		}  		else  		{  			if (!($file_contents = file_get_contents($this->metadata_file)))  			{ -    			throw new phpbb_extension_exception('file_get_contents failed on ' . $this->metadata_file); +    			throw new \phpbb\extension\exception('file_get_contents failed on ' . $this->metadata_file);  			}  			if (($metadata = json_decode($file_contents, true)) === NULL)  			{ -    			throw new phpbb_extension_exception('json_decode failed on ' . $this->metadata_file); +    			throw new \phpbb\extension\exception('json_decode failed on ' . $this->metadata_file);  			}  			$this->metadata = $metadata; @@ -201,7 +203,7 @@ class phpbb_extension_metadata_manager      	// Basic fields      	$fields = array(      		'name'		=> '#^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$#', -    		'type'		=> '#^phpbb3-extension$#', +    		'type'		=> '#^phpbb-extension$#',      		'licence'	=> '#.+#',      		'version'	=> '#.+#',      	); @@ -228,12 +230,12 @@ class phpbb_extension_metadata_manager      			{      				if (!isset($this->metadata[$name]))      				{ -    					throw new phpbb_extension_exception("Required meta field '$name' has not been set."); +    					throw new \phpbb\extension\exception("Required meta field '$name' has not been set.");  					}  					if (!preg_match($fields[$name], $this->metadata[$name]))  					{ -    					throw new phpbb_extension_exception("Meta field '$name' is invalid."); +    					throw new \phpbb\extension\exception("Meta field '$name' is invalid.");  					}  				}  			break; @@ -251,14 +253,14 @@ class phpbb_extension_metadata_manager  	{  		if (empty($this->metadata['authors']))  		{ -    		throw new phpbb_extension_exception("Required meta field 'authors' has not been set."); +    		throw new \phpbb\extension\exception("Required meta field 'authors' has not been set.");  		}  		foreach ($this->metadata['authors'] as $author)  		{  			if (!isset($author['name']))  			{ -    			throw new phpbb_extension_exception("Required meta field 'author name' has not been set."); +    			throw new \phpbb\extension\exception("Required meta field 'author name' has not been set.");  			}  		} @@ -289,12 +291,12 @@ class phpbb_extension_metadata_manager  	 */  	public function validate_require_phpbb()  	{ -		if (!isset($this->metadata['require']['phpbb'])) +		if (!isset($this->metadata['require']['phpbb/phpbb']))  		{ -			return true; +			return false;  		} -		return $this->_validate_version($this->metadata['require']['phpbb'], $this->config['version']); +		return true;  	}  	/** @@ -306,10 +308,10 @@ class phpbb_extension_metadata_manager  	{  		if (!isset($this->metadata['require']['php']))  		{ -			return true; +			return false;  		} -		return $this->_validate_version($this->metadata['require']['php'], phpversion()); +		return true;  	}  	/** @@ -352,7 +354,7 @@ class phpbb_extension_metadata_manager  			'META_REQUIRE_PHP'		=> (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '',  			'META_REQUIRE_PHP_FAIL'	=> !$this->validate_require_php(), -			'META_REQUIRE_PHPBB'		=> (isset($this->metadata['require']['phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb']) : '', +			'META_REQUIRE_PHPBB'		=> (isset($this->metadata['require']['phpbb/phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb/phpbb']) : '',  			'META_REQUIRE_PHPBB_FAIL'	=> !$this->validate_require_phpbb(),  			'META_DISPLAY_NAME'	=> (isset($this->metadata['extra']['display-name'])) ? htmlspecialchars($this->metadata['extra']['display-name']) : '', diff --git a/phpBB/phpbb/extension/provider.php b/phpBB/phpbb/extension/provider.php index 45b55e5cab..c2a264d311 100644 --- a/phpBB/phpbb/extension/provider.php +++ b/phpBB/phpbb/extension/provider.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\extension; +  /**  * @ignore  */ @@ -28,7 +30,7 @@ if (!defined('IN_PHPBB'))  *  * @package extension  */ -abstract class phpbb_extension_provider implements IteratorAggregate +abstract class provider implements \IteratorAggregate  {  	/**  	* Array holding all found items @@ -38,16 +40,16 @@ abstract class phpbb_extension_provider implements IteratorAggregate  	/**  	* An extension manager to search for items in extensions -	* @var phpbb_extension_manager +	* @var \phpbb\extension\manager  	*/  	protected $extension_manager;  	/**  	* Constructor. Loads all available items.  	* -	* @param phpbb_extension_manager $extension_manager phpBB extension manager +	* @param \phpbb\extension\manager $extension_manager phpBB extension manager  	*/ -	public function __construct(phpbb_extension_manager $extension_manager) +	public function __construct(\phpbb\extension\manager $extension_manager)  	{  		$this->extension_manager = $extension_manager;  	} @@ -71,6 +73,6 @@ abstract class phpbb_extension_provider implements IteratorAggregate  			$this->items = $this->find();  		} -		return new ArrayIterator($this->items); +		return new \ArrayIterator($this->items);  	}  } diff --git a/phpBB/phpbb/feed/base.php b/phpBB/phpbb/feed/base.php index 296d830932..de7dd41df4 100644 --- a/phpBB/phpbb/feed/base.php +++ b/phpBB/phpbb/feed/base.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\feed; +  /**  * @ignore  */ @@ -20,27 +22,27 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -abstract class phpbb_feed_base +abstract class base  {  	/**  	* Feed helper object -	* @var phpbb_feed_helper +	* @var \phpbb\feed\helper  	*/  	protected $helper; -	/** @var phpbb_config */ +	/** @var \phpbb\config\config */  	protected $config; -	/** @var phpbb_db_driver */ +	/** @var \phpbb\db\driver\driver */  	protected $db; -	/** @var phpbb_cache_driver_interface */ +	/** @var \phpbb\cache\driver\driver_interface */  	protected $cache; -	/** @var phpbb_user */ +	/** @var \phpbb\user */  	protected $user; -	/** @var phpbb_auth */ +	/** @var \phpbb\auth\auth */  	protected $auth;  	/** @var string */ @@ -74,17 +76,17 @@ abstract class phpbb_feed_base  	/**  	* Constructor  	* -	* @param phpbb_feed_helper $helper Feed helper -	* @param phpbb_config		$config		Config object -	* @param phpbb_db_driver	$db			Database connection -	* @param phpbb_cache_driver_interface	$cache			Cache object -	* @param phpbb_user			$user		User object -	* @param phpbb_auth			$auth		Auth object -	* @param phpbb_content_visibility	$content_visibility		Auth object +	* @param \phpbb\feed\helper $helper Feed helper +	* @param \phpbb\config\config		$config		Config object +	* @param \phpbb\db\driver\driver	$db			Database connection +	* @param \phpbb\cache\driver\driver_interface	$cache			Cache object +	* @param \phpbb\user			$user		User object +	* @param \phpbb\auth\auth			$auth		Auth object +	* @param \phpbb\content_visibility	$content_visibility		Auth object  	* @param string				$phpEx		php file extension  	* @return	null  	*/ -	function __construct(phpbb_feed_helper $helper, phpbb_config $config, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, phpbb_user $user, phpbb_auth $auth, phpbb_content_visibility $content_visibility, $phpEx) +	function __construct(\phpbb\feed\helper $helper, \phpbb\config\config $config, \phpbb\db\driver\driver $db, \phpbb\cache\driver\driver_interface $cache, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\content_visibility $content_visibility, $phpEx)  	{  		$this->config = $config;  		$this->helper = $helper; diff --git a/phpBB/phpbb/feed/factory.php b/phpBB/phpbb/feed/factory.php index 63a1eb8ef0..e011b0e3a9 100644 --- a/phpBB/phpbb/feed/factory.php +++ b/phpBB/phpbb/feed/factory.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\feed; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * Factory class to return correct object  * @package phpBB3  */ -class phpbb_feed_factory +class factory  {  	/**  	* Service container object @@ -27,21 +29,21 @@ class phpbb_feed_factory  	*/  	protected $container; -	/** @var phpbb_config */ +	/** @var \phpbb\config\config */  	protected $config; -	/** @var phpbb_db_driver */ +	/** @var \phpbb\db\driver\driver */  	protected $db;  	/**  	* Constructor  	*  	* @param objec				$container	Container object -	* @param phpbb_config		$config		Config object -	* @param phpbb_db_driver	$db			Database connection +	* @param \phpbb\config\config		$config		Config object +	* @param \phpbb\db\driver\driver	$db			Database connection  	* @return	null  	*/ -	public function __construct($container, phpbb_config $config, phpbb_db_driver $db) +	public function __construct($container, \phpbb\config\config $config, \phpbb\db\driver\driver $db)  	{  		$this->container = $container;  		$this->config = $config; diff --git a/phpBB/phpbb/feed/forum.php b/phpBB/phpbb/feed/forum.php index b5f0dd0f8f..83066d2d25 100644 --- a/phpBB/phpbb/feed/forum.php +++ b/phpBB/phpbb/feed/forum.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\feed; +  /**  * @ignore  */ @@ -23,7 +25,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_feed_forum extends phpbb_feed_post_base +class forum extends \phpbb\feed\post_base  {  	var $forum_id		= 0;  	var $forum_data		= array(); @@ -32,9 +34,9 @@ class phpbb_feed_forum extends phpbb_feed_post_base  	* Set the Forum ID  	*  	* @param int	$forum_id			Forum ID -	* @return	phpbb_feed_forum +	* @return	\phpbb\feed\forum  	*/ -	public function set_forum_id($topic_id) +	public function set_forum_id($forum_id)  	{  		$this->forum_id = (int) $forum_id; diff --git a/phpBB/phpbb/feed/forums.php b/phpBB/phpbb/feed/forums.php index 409097a9f3..6be1c68da8 100644 --- a/phpBB/phpbb/feed/forums.php +++ b/phpBB/phpbb/feed/forums.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\feed; +  /**  * @ignore  */ @@ -23,7 +25,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_feed_forums extends phpbb_feed_base +class forums extends \phpbb\feed\base  {  	var $num_items	= 0; diff --git a/phpBB/phpbb/feed/helper.php b/phpBB/phpbb/feed/helper.php index 93330aa2ad..cf8328bd5e 100644 --- a/phpBB/phpbb/feed/helper.php +++ b/phpBB/phpbb/feed/helper.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\feed; +  /**  * @ignore  */ @@ -19,12 +21,12 @@ if (!defined('IN_PHPBB'))  * Class with some helpful functions used in feeds  * @package phpBB3  */ -class phpbb_feed_helper +class helper  { -	/** @var phpbb_config */ +	/** @var \phpbb\config\config */  	protected $config; -	/** @var phpbb_user */ +	/** @var \phpbb\user */  	protected $user;  	/** @var string */ @@ -33,12 +35,12 @@ class phpbb_feed_helper  	/**  	* Constructor  	* -	* @param	phpbb_config	$config		Config object -	* @param	phpbb_user		$user		User object +	* @param	\phpbb\config\config	$config		Config object +	* @param	\phpbb\user		$user		User object  	* @param	string	$phpbb_root_path	Root path  	* @return	null  	*/ -	public function __construct(phpbb_config $config, phpbb_user $user, $phpbb_root_path) +	public function __construct(\phpbb\config\config $config, \phpbb\user $user, $phpbb_root_path)  	{  		$this->config = $config;  		$this->user = $user; diff --git a/phpBB/phpbb/feed/news.php b/phpBB/phpbb/feed/news.php index f2d45b5165..20017a3248 100644 --- a/phpBB/phpbb/feed/news.php +++ b/phpBB/phpbb/feed/news.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\feed; +  /**  * @ignore  */ @@ -23,7 +25,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_feed_news extends phpbb_feed_topic_base +class news extends \phpbb\feed\topic_base  {  	function get_news_forums()  	{ diff --git a/phpBB/phpbb/feed/overall.php b/phpBB/phpbb/feed/overall.php index 869df7cde0..8ee1f092ab 100644 --- a/phpBB/phpbb/feed/overall.php +++ b/phpBB/phpbb/feed/overall.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\feed; +  /**  * @ignore  */ @@ -23,7 +25,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_feed_overall extends phpbb_feed_post_base +class overall extends \phpbb\feed\post_base  {  	function get_sql()  	{ @@ -72,7 +74,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base  				),  			),  			'WHERE'		=> $this->db->sql_in_set('p.topic_id', $topic_ids) . ' -							AND ' . $this->content_visibility->get_visibility_sql('post', array(), 'p.') . ' +							AND ' . $this->content_visibility->get_forums_visibility_sql('post', $forum_ids, 'p.') . '  							AND p.post_time >= ' . $min_post_time . '  							AND u.user_id = p.poster_id',  			'ORDER_BY'	=> 'p.post_time DESC', diff --git a/phpBB/phpbb/feed/post_base.php b/phpBB/phpbb/feed/post_base.php index 1f4cb4b5ef..5588ecadb0 100644 --- a/phpBB/phpbb/feed/post_base.php +++ b/phpBB/phpbb/feed/post_base.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\feed; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -abstract class phpbb_feed_post_base extends phpbb_feed_base +abstract class post_base extends \phpbb\feed\base  {  	var $num_items = 'feed_limit_post'; diff --git a/phpBB/phpbb/feed/topic.php b/phpBB/phpbb/feed/topic.php index 36f958ac60..1eeb4fbe94 100644 --- a/phpBB/phpbb/feed/topic.php +++ b/phpBB/phpbb/feed/topic.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\feed; +  /**  * @ignore  */ @@ -22,7 +24,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_feed_topic extends phpbb_feed_post_base +class topic extends \phpbb\feed\post_base  {  	var $topic_id		= 0;  	var $forum_id		= 0; @@ -32,7 +34,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base  	* Set the Topic ID  	*  	* @param int	$topic_id			Topic ID -	* @return	phpbb_feed_topic +	* @return	\phpbb\feed\topic  	*/  	public function set_topic_id($topic_id)  	{ @@ -43,7 +45,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base  	function open()  	{ -		$sql = 'SELECT f.forum_options, f.forum_password, t.topic_id, t.forum_id, t.topic_visibility, t.topic_title, t.topic_time, t.topic_views, t.topic_replies, t.topic_type +		$sql = 'SELECT f.forum_options, f.forum_password, t.topic_id, t.forum_id, t.topic_visibility, t.topic_title, t.topic_time, t.topic_views, t.topic_posts_approved, t.topic_type  			FROM ' . TOPICS_TABLE . ' t  			LEFT JOIN ' . FORUMS_TABLE . ' f  				ON (f.forum_id = t.forum_id) @@ -60,7 +62,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base  		$this->forum_id = (int) $this->topic_data['forum_id'];  		// Make sure topic is either approved or user authed -		if (!$this->topic_data['topic_approved'] && !$this->auth->acl_get('m_approve', $this->forum_id)) +		if ($this->topic_data['topic_visibility'] != ITEM_APPROVED && !$this->auth->acl_get('m_approve', $this->forum_id))  		{  			trigger_error('SORRY_AUTH_READ');  		} diff --git a/phpBB/phpbb/feed/topic_base.php b/phpBB/phpbb/feed/topic_base.php index b104a46631..f05be9223e 100644 --- a/phpBB/phpbb/feed/topic_base.php +++ b/phpBB/phpbb/feed/topic_base.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\feed; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -abstract class phpbb_feed_topic_base extends phpbb_feed_base +abstract class topic_base extends \phpbb\feed\base  {  	var $num_items = 'feed_limit_topic'; diff --git a/phpBB/phpbb/feed/topics.php b/phpBB/phpbb/feed/topics.php index 31f5177773..d70195c87b 100644 --- a/phpBB/phpbb/feed/topics.php +++ b/phpBB/phpbb/feed/topics.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\feed; +  /**  * @ignore  */ @@ -23,7 +25,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_feed_topics extends phpbb_feed_topic_base +class topics extends \phpbb\feed\topic_base  {  	function get_sql()  	{ diff --git a/phpBB/phpbb/feed/topics_active.php b/phpBB/phpbb/feed/topics_active.php index 249dd1d66a..c6f46d67e6 100644 --- a/phpBB/phpbb/feed/topics_active.php +++ b/phpBB/phpbb/feed/topics_active.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\feed; +  /**  * @ignore  */ @@ -24,7 +26,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_feed_topics_active extends phpbb_feed_topic_base +class topics_active extends \phpbb\feed\topic_base  {  	var $sort_days = 7; diff --git a/phpBB/phpbb/filesystem.php b/phpBB/phpbb/filesystem.php index 27cab48fb0..dbfaebe0fa 100644 --- a/phpBB/phpbb/filesystem.php +++ b/phpBB/phpbb/filesystem.php @@ -6,6 +6,9 @@  * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2  *  */ + +namespace phpbb; +  /**  * @ignore  */ @@ -18,7 +21,7 @@ if (!defined('IN_PHPBB'))  * A class with various functions that are related to paths, files and the filesystem  * @package phpBB3  */ -class phpbb_filesystem +class filesystem  {  	/**  	* Eliminates useless . and .. components from specified path. diff --git a/phpBB/phpbb/groupposition/exception.php b/phpBB/phpbb/groupposition/exception.php index e4ff09c703..3a8d92dbc7 100644 --- a/phpBB/phpbb/groupposition/exception.php +++ b/phpBB/phpbb/groupposition/exception.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\groupposition; +  /**  * @ignore  */ @@ -18,6 +20,6 @@ if (!defined('IN_PHPBB'))  /**  * @package groupposition  */ -class phpbb_groupposition_exception extends \Exception +class exception extends \Exception  {  } diff --git a/phpBB/phpbb/groupposition/interface.php b/phpBB/phpbb/groupposition/groupposition_interface.php index eacc04e1a4..a568785185 100644 --- a/phpBB/phpbb/groupposition/interface.php +++ b/phpBB/phpbb/groupposition/groupposition_interface.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\groupposition; +  /**  * @ignore  */ @@ -22,7 +24,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -interface phpbb_groupposition_interface +interface groupposition_interface  {  	/**  	* Returns the value for a given group, if the group exists. @@ -32,7 +34,7 @@ interface phpbb_groupposition_interface  	public function get_group_value($group_id);  	/** -	* Get number of groups displayed  +	* Get number of groups displayed  	*  	* @return	int		value of the last item displayed  	*/ diff --git a/phpBB/phpbb/groupposition/legend.php b/phpBB/phpbb/groupposition/legend.php index 7fddadde99..9a1ef3d1d0 100644 --- a/phpBB/phpbb/groupposition/legend.php +++ b/phpBB/phpbb/groupposition/legend.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\groupposition; +  /**  * @ignore  */ @@ -23,7 +25,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_groupposition_legend implements phpbb_groupposition_interface +class legend implements \phpbb\groupposition\groupposition_interface  {  	/**  	* Group is not displayed @@ -32,23 +34,23 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface  	/**  	* Database object -	* @var phpbb_db_driver +	* @var \phpbb\db\driver\driver  	*/  	protected $db;  	/**  	* User object -	* @var phpbb_user +	* @var \phpbb\user  	*/  	protected $user;  	/**  	* Constructor  	* -	* @param phpbb_db_driver	$db		Database object -	* @param phpbb_user			$user	User object +	* @param \phpbb\db\driver\driver	$db		Database object +	* @param \phpbb\user			$user	User object  	*/ -	public function __construct(phpbb_db_driver $db, phpbb_user $user) +	public function __construct(\phpbb\db\driver\driver $db, \phpbb\user $user)  	{  		$this->db = $db;  		$this->user = $user; @@ -71,7 +73,7 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface  		if ($current_value === false)  		{  			// Group not found. -			throw new phpbb_groupposition_exception('NO_GROUP'); +			throw new \phpbb\groupposition\exception('NO_GROUP');  		}  		return (int) $current_value; diff --git a/phpBB/phpbb/groupposition/teampage.php b/phpBB/phpbb/groupposition/teampage.php index 7c758199e7..4e8228eb58 100644 --- a/phpBB/phpbb/groupposition/teampage.php +++ b/phpBB/phpbb/groupposition/teampage.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\groupposition; +  /**  * @ignore  */ @@ -22,7 +24,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_groupposition_teampage implements phpbb_groupposition_interface +class teampage implements \phpbb\groupposition\groupposition_interface  {  	/**  	* Group is not displayed @@ -36,30 +38,30 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface  	/**  	* Database object -	* @var phpbb_db_driver +	* @var \phpbb\db\driver\driver  	*/  	protected $db;  	/**  	* User object -	* @var phpbb_user +	* @var \phpbb\user  	*/  	protected $user;  	/**  	* Cache object -	* @var phpbb_cache_driver_interface +	* @var \phpbb\cache\driver\driver_interface  	*/  	protected $cache;  	/**  	* Constructor  	* -	* @param phpbb_db_driver				$db		Database object -	* @param phpbb_user						$user	User object -	* @param phpbb_cache_driver_interface	$cache	Cache object +	* @param \phpbb\db\driver\driver				$db		Database object +	* @param \phpbb\user						$user	User object +	* @param \phpbb\cache\driver\driver_interface	$cache	Cache object  	*/ -	public function __construct(phpbb_db_driver $db, phpbb_user $user, phpbb_cache_driver_interface $cache) +	public function __construct(\phpbb\db\driver\driver $db, \phpbb\user $user, \phpbb\cache\driver\driver_interface $cache)  	{  		$this->db = $db;  		$this->user = $user; @@ -86,7 +88,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface  		if ($row === false)  		{  			// Group not found. -			throw new phpbb_groupposition_exception('NO_GROUP'); +			throw new \phpbb\groupposition\exception('NO_GROUP');  		}  		return (int) $row['teampage_position']; @@ -113,7 +115,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface  		if ($row === false)  		{  			// Group not found. -			throw new phpbb_groupposition_exception('NO_GROUP'); +			throw new \phpbb\groupposition\exception('NO_GROUP');  		}  		return $row; @@ -137,7 +139,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface  		if ($current_value === false)  		{  			// Group not found. -			throw new phpbb_groupposition_exception('NO_GROUP'); +			throw new \phpbb\groupposition\exception('NO_GROUP');  		}  		return (int) $current_value; @@ -161,7 +163,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface  		if ($row === false)  		{  			// Group not found. -			throw new phpbb_groupposition_exception('NO_GROUP'); +			throw new \phpbb\groupposition\exception('NO_GROUP');  		}  		return $row; diff --git a/phpBB/phpbb/hook/finder.php b/phpBB/phpbb/hook/finder.php index 7b0412f733..d5eb1f8186 100644 --- a/phpBB/phpbb/hook/finder.php +++ b/phpBB/phpbb/hook/finder.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\hook; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_hook_finder +class finder  {  	protected $phpbb_root_path;  	protected $cache; @@ -31,9 +33,9 @@ class phpbb_hook_finder  	*  	* @param string $phpbb_root_path Path to the phpbb root directory  	* @param string $php_ext php file extension -	* @param phpbb_cache_driver_interface $cache A cache instance or null +	* @param \phpbb\cache\driver\driver_interface $cache A cache instance or null  	*/ -	public function __construct($phpbb_root_path, $php_ext, phpbb_cache_driver_interface $cache = null) +	public function __construct($phpbb_root_path, $php_ext, \phpbb\cache\driver\driver_interface $cache = null)  	{  		$this->phpbb_root_path = $phpbb_root_path;  		$this->cache = $cache; diff --git a/phpBB/phpbb/json_response.php b/phpBB/phpbb/json_response.php index 5dd904da09..fe532fc9d4 100644 --- a/phpBB/phpbb/json_response.php +++ b/phpBB/phpbb/json_response.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * JSON class  * @package phpBB3  */ -class phpbb_json_response +class json_response  {  	/**  	 * Send the data to the client and exit the script. diff --git a/phpBB/phpbb/lock/db.php b/phpBB/phpbb/lock/db.php index 5cc0821aa0..3e15727c12 100644 --- a/phpBB/phpbb/lock/db.php +++ b/phpBB/phpbb/lock/db.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\lock; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * Database locking class  * @package phpBB3  */ -class phpbb_lock_db +class db  {  	/**  	* Name of the config variable this lock uses @@ -42,13 +44,13 @@ class phpbb_lock_db  	/**  	* The phpBB configuration -	* @var phpbb_config +	* @var \phpbb\config\config  	*/  	private $config;  	/**  	* A database connection -	* @var phpbb_db_driver +	* @var \phpbb\db\driver\driver  	*/  	private $db; @@ -59,9 +61,9 @@ class phpbb_lock_db  	*  	* @param	string	$config_name	A config variable to be used for locking  	* @param	array	$config			The phpBB configuration -	* @param	phpbb_db_driver	$db				A database connection +	* @param	\phpbb\db\driver\driver	$db				A database connection  	*/ -	public function __construct($config_name, phpbb_config $config, phpbb_db_driver $db) +	public function __construct($config_name, \phpbb\config\config $config, \phpbb\db\driver\driver $db)  	{  		$this->config_name = $config_name;  		$this->config = $config; diff --git a/phpBB/phpbb/lock/flock.php b/phpBB/phpbb/lock/flock.php index 17de0847c0..2a36a853ee 100644 --- a/phpBB/phpbb/lock/flock.php +++ b/phpBB/phpbb/lock/flock.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\lock; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * File locking class  * @package phpBB3  */ -class phpbb_lock_flock +class flock  {  	/**  	* Path to the file to which access is controlled diff --git a/phpBB/phpbb/log/log.php b/phpBB/phpbb/log/log.php index 7a26858348..7f4e52ed39 100644 --- a/phpBB/phpbb/log/log.php +++ b/phpBB/phpbb/log/log.php @@ -1,12 +1,14 @@  <?php  /**  * -* @package phpbb_log +* @package \phpbb\log\log  * @copyright (c) 2012 phpBB Group  * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2  *  */ +namespace phpbb\log; +  /**  * @ignore  */ @@ -18,9 +20,9 @@ if (!defined('IN_PHPBB'))  /**  * This class is used to add entries into the log table.  * -* @package phpbb_log +* @package \phpbb\log\log  */ -class phpbb_log implements phpbb_log_interface +class log implements \phpbb\log\log_interface  {  	/**  	* If set, administrative user profile links will be returned and messages @@ -56,19 +58,19 @@ class phpbb_log implements phpbb_log_interface  	/**  	* Database object -	* @var phpbb_db_driver +	* @var \phpbb\db\driver\driver  	*/  	protected $db;  	/**  	* User object -	* @var phpbb_user +	* @var \phpbb\user  	*/  	protected $user;  	/**  	* Auth object -	* @var phpbb_auth +	* @var \phpbb\auth\auth  	*/  	protected $auth; @@ -99,9 +101,9 @@ class phpbb_log implements phpbb_log_interface  	/**  	* Constructor  	* -	* @param	phpbb_db_driver	$db		Database object -	* @param	phpbb_user		$user	User object -	* @param	phpbb_auth		$auth	Auth object +	* @param	\phpbb\db\driver\driver	$db		Database object +	* @param	\phpbb\user		$user	User object +	* @param	\phpbb\auth\auth		$auth	Auth object  	* @param	phpbb_dispatcher	$phpbb_dispatcher	Event dispatcher  	* @param	string		$phpbb_root_path		Root path  	* @param	string		$relative_admin_path	Relative admin root path @@ -123,7 +125,7 @@ class phpbb_log implements phpbb_log_interface  		/*  		* IN_ADMIN is set after the session is created,  		* so we need to take ADMIN_START into account as well, otherwise -		* it will not work for the phpbb_log object we create in common.php +		* it will not work for the \phpbb\log\log object we create in common.php  		*/  		$this->set_is_admin((defined('ADMIN_START') && ADMIN_START) || (defined('IN_ADMIN') && IN_ADMIN));  		$this->enable(); diff --git a/phpBB/phpbb/log/interface.php b/phpBB/phpbb/log/log_interface.php index 3b459c9bdf..427d30015d 100644 --- a/phpBB/phpbb/log/interface.php +++ b/phpBB/phpbb/log/log_interface.php @@ -1,12 +1,14 @@  <?php  /**  * -* @package phpbb_log +* @package \phpbb\log\log  * @copyright (c) 2012 phpBB Group  * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2  *  */ +namespace phpbb\log; +  /**  * @ignore  */ @@ -18,9 +20,9 @@ if (!defined('IN_PHPBB'))  /**  * The interface for the log-system.  * -* @package phpbb_log +* @package \phpbb\log\log  */ -interface phpbb_log_interface +interface log_interface  {  	/**  	* This function returns the state of the log system. diff --git a/phpBB/phpbb/log/null.php b/phpBB/phpbb/log/null.php new file mode 100644 index 0000000000..2ef69926ee --- /dev/null +++ b/phpBB/phpbb/log/null.php @@ -0,0 +1,80 @@ +<?php +/** +* +* @package phpbb_log +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\log; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +/** +* Null logger +* +* @package phpbb_log +*/ +class null implements log_interface +{ +	/** +	* {@inheritdoc} +	*/ +	public function is_enabled($type = '') +	{ +		return false; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function disable($type = '') +	{ +	} + +	/** +	* {@inheritdoc} +	*/ +	public function enable($type = '') +	{ +	} + +	/** +	* {@inheritdoc} +	*/ +	public function add($mode, $user_id, $log_ip, $log_operation, $log_time = false, $additional_data = array()) +	{ +		return false; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_logs($mode, $count_logs = true, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $log_time = 0, $sort_by = 'l.log_time DESC', $keywords = '') +	{ +		return array(); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_log_count() +	{ +		return 0; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_valid_offset() +	{ +		return 0; +	} +} diff --git a/phpBB/phpbb/notification/exception.php b/phpBB/phpbb/notification/exception.php index a52d6fdc57..275fb3b542 100644 --- a/phpBB/phpbb/notification/exception.php +++ b/phpBB/phpbb/notification/exception.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  *  * @package notifications  */ -class phpbb_notification_exception extends \Exception +class exception extends \Exception  {  	public function __toString()  	{ diff --git a/phpBB/phpbb/notification/manager.php b/phpBB/phpbb/notification/manager.php index 97833710c0..c42c84fb1f 100644 --- a/phpBB/phpbb/notification/manager.php +++ b/phpBB/phpbb/notification/manager.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * Notifications service class  * @package notifications  */ -class phpbb_notification_manager +class manager  {  	/** @var array */  	protected $notification_types; @@ -30,16 +32,16 @@ class phpbb_notification_manager  	/** @var ContainerBuilder */  	protected $phpbb_container; -	/** @var phpbb_user_loader */ +	/** @var \phpbb\user_loader */  	protected $user_loader; -	/** @var phpbb_db_driver */ +	/** @var \phpbb\db\driver\driver */  	protected $db; -	/** @var phpbb_cache_service */ +	/** @var \phpbb\cache\service */  	protected $cache; -	/** @var phpbb_user */ +	/** @var \phpbb\user */  	protected $user;  	/** @var string */ @@ -59,21 +61,21 @@ class phpbb_notification_manager  	/**  	* Notification Constructor -	*  +	*  	* @param array $notification_types  	* @param array $notification_methods  	* @param ContainerBuilder $phpbb_container -	* @param phpbb_user_loader $user_loader -	* @param phpbb_db_driver $db -	* @param phpbb_user $user +	* @param \phpbb\user_loader $user_loader +	* @param \phpbb\db\driver\driver $db +	* @param \phpbb\user $user  	* @param string $phpbb_root_path  	* @param string $php_ext  	* @param string $notification_types_table  	* @param string $notifications_table  	* @param string $user_notifications_table -	* @return phpbb_notification_manager +	* @return \phpbb\notification\manager  	*/ -	public function __construct($notification_types, $notification_methods, $phpbb_container, phpbb_user_loader $user_loader, phpbb_db_driver $db, phpbb_cache_service $cache, $user, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table) +	public function __construct($notification_types, $notification_methods, $phpbb_container, \phpbb\user_loader $user_loader, \phpbb\db\driver\driver $db, \phpbb\cache\service $cache, $user, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table)  	{  		$this->notification_types = $notification_types;  		$this->notification_methods = $notification_methods; @@ -402,7 +404,7 @@ class phpbb_notification_manager  		$pre_create_data = $notification->pre_create_insert_array($data, $notify_users);  		unset($notification); -		$insert_buffer = new phpbb_db_sql_insert_buffer($this->db, $this->notifications_table); +		$insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $this->notifications_table);  		// Go through each user so we can insert a row in the DB and then notify them by their desired means  		foreach ($notify_users as $user => $methods) @@ -490,15 +492,15 @@ class phpbb_notification_manager  	*  	* @param string|array $notification_type_name Type identifier or array of item types (only acceptable if the $item_id is identical for the specified types)  	* @param int|array $item_id Identifier within the type (or array of ids) -	* @param array $data Data specific for this type that will be updated +	* @param mixed $parent_id Parent identifier within the type (or array of ids), used in combination with item_id if specified (Default: false; not checked)  	*/ -	public function delete_notifications($notification_type_name, $item_id) +	public function delete_notifications($notification_type_name, $item_id, $parent_id = false)  	{  		if (is_array($notification_type_name))  		{  			foreach ($notification_type_name as $type)  			{ -				$this->delete_notifications($type, $item_id); +				$this->delete_notifications($type, $item_id, $parent_id);  			}  			return; @@ -508,7 +510,8 @@ class phpbb_notification_manager  		$sql = 'DELETE FROM ' . $this->notifications_table . '  			WHERE notification_type_id = ' . (int) $notification_type_id . ' -				AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id); +				AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) . +				(($parent_id !== false) ? ' AND ' . ((is_array($parent_id) ? $this->db->sql_in_set('item_parent_id', $parent_id) : 'item_parent_id = ' . (int) $parent_id)) : '');  		$this->db->sql_query($sql);  	} @@ -525,7 +528,7 @@ class phpbb_notification_manager  		{  			$type = $this->get_item_type_class($type_name); -			if ($type instanceof phpbb_notification_type_interface && $type->is_available()) +			if ($type instanceof \phpbb\notification\type\type_interface && $type->is_available())  			{  				$options = array_merge(array(  					'id'		=> $type->get_type(), @@ -561,7 +564,7 @@ class phpbb_notification_manager  		{  			$method = $this->get_method_class($method_name); -			if ($method instanceof phpbb_notification_method_interface && $method->is_available()) +			if ($method instanceof \phpbb\notification\method\method_interface && $method->is_available())  			{  				$subscription_methods[$method_name] = array(  					'id'		=> $method->get_type(), @@ -796,11 +799,13 @@ class phpbb_notification_manager  	* Delete all notifications older than a certain time  	*  	* @param int $timestamp Unix timestamp to delete all notifications that were created before +	* @param bool $only_unread True (default) to only prune read notifications  	*/ -	public function prune_notifications($timestamp) +	public function prune_notifications($timestamp, $only_read = true)  	{  		$sql = 'DELETE FROM ' . $this->notifications_table . ' -			WHERE notification_time < ' . (int) $timestamp; +			WHERE notification_time < ' . (int) $timestamp . +				(($only_read) ? ' AND notification_read = 1' : '');  		$this->db->sql_query($sql);  	} @@ -834,12 +839,12 @@ class phpbb_notification_manager  	protected function load_object($object_name)  	{  		$object = $this->phpbb_container->get($object_name); -		 +  		if (method_exists($object, 'set_notification_manager'))  		{  			$object->set_notification_manager($this);  		} -		 +  		return $object;  	} @@ -873,7 +878,7 @@ class phpbb_notification_manager  		{  			if (!isset($this->notification_types[$notification_type_name]) && !isset($this->notification_types['notification.type.' . $notification_type_name]))  			{ -				throw new phpbb_notification_exception($this->user->lang('NOTIFICATION_TYPE_NOT_EXIST', $notification_type_name)); +				throw new \phpbb\notification\exception($this->user->lang('NOTIFICATION_TYPE_NOT_EXIST', $notification_type_name));  			}  			$sql = 'INSERT INTO ' . $this->notification_types_table . ' ' . $this->db->sql_build_array('INSERT', array( diff --git a/phpBB/phpbb/notification/method/base.php b/phpBB/phpbb/notification/method/base.php index b633956d01..327f964424 100644 --- a/phpBB/phpbb/notification/method/base.php +++ b/phpBB/phpbb/notification/method/base.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\method; +  /**  * @ignore  */ @@ -19,33 +21,33 @@ if (!defined('IN_PHPBB'))  * Base notifications method class  * @package notifications  */ -abstract class phpbb_notification_method_base implements phpbb_notification_method_interface +abstract class base implements \phpbb\notification\method\method_interface  { -	/** @var phpbb_notification_manager */ +	/** @var \phpbb\notification\manager */  	protected $notification_manager; -	/** @var phpbb_user_loader */ +	/** @var \phpbb\user_loader */  	protected $user_loader; -	/** @var phpbb_db_driver */ +	/** @var \phpbb\db\driver\driver */  	protected $db; -	/** @var phpbb_cache_driver_interface */ +	/** @var \phpbb\cache\driver\driver_interface */  	protected $cache; -	/** @var phpbb_template */ +	/** @var \phpbb\template\template */  	protected $template; -	/** @var phpbb_extension_manager */ +	/** @var \phpbb\extension\manager */  	protected $extension_manager; -	/** @var phpbb_user */ +	/** @var \phpbb\user */  	protected $user; -	/** @var phpbb_auth */ +	/** @var \phpbb\auth\auth */  	protected $auth; -	/** @var phpbb_config */ +	/** @var \phpbb\config\config */  	protected $config;  	/** @var string */ @@ -64,17 +66,17 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth  	/**  	* Notification Method Base Constructor  	*  -	* @param phpbb_user_loader $user_loader -	* @param phpbb_db_driver $db -	* @param phpbb_cache_driver_interface $cache -	* @param phpbb_user $user -	* @param phpbb_auth $auth -	* @param phpbb_config $config +	* @param \phpbb\user_loader $user_loader +	* @param \phpbb\db\driver\driver $db +	* @param \phpbb\cache\driver\driver_interface $cache +	* @param \phpbb\user $user +	* @param \phpbb\auth\auth $auth +	* @param \phpbb\config\config $config  	* @param string $phpbb_root_path  	* @param string $php_ext -	* @return phpbb_notification_method_base +	* @return \phpbb\notification\method\base  	*/ -	public function __construct(phpbb_user_loader $user_loader, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) +	public function __construct(\phpbb\user_loader $user_loader, \phpbb\db\driver\driver $db, \phpbb\cache\driver\driver_interface $cache, $user, \phpbb\auth\auth $auth, \phpbb\config\config $config, $phpbb_root_path, $php_ext)  	{  		$this->user_loader = $user_loader;  		$this->db = $db; @@ -89,9 +91,9 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth  	/**  	* Set notification manager (required)  	*  -	* @param phpbb_notification_manager $notification_manager +	* @param \phpbb\notification\manager $notification_manager  	*/ -	public function set_notification_manager(phpbb_notification_manager $notification_manager) +	public function set_notification_manager(\phpbb\notification\manager $notification_manager)  	{  		$this->notification_manager = $notification_manager;  	} @@ -99,9 +101,9 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth  	/**  	* Add a notification to the queue  	* -	* @param phpbb_notification_type_interface $notification +	* @param \phpbb\notification\type\type_interface $notification  	*/ -	public function add_to_queue(phpbb_notification_type_interface $notification) +	public function add_to_queue(\phpbb\notification\type\type_interface $notification)  	{  		$this->queue[] = $notification;  	} diff --git a/phpBB/phpbb/notification/method/email.php b/phpBB/phpbb/notification/method/email.php index 571b0ec656..b761eb5a28 100644 --- a/phpBB/phpbb/notification/method/email.php +++ b/phpBB/phpbb/notification/method/email.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\method; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  *  * @package notifications  */ -class phpbb_notification_method_email extends phpbb_notification_method_messenger_base +class email extends \phpbb\notification\method\messenger_base  {  	/**  	* Get notification method name diff --git a/phpBB/phpbb/notification/method/jabber.php b/phpBB/phpbb/notification/method/jabber.php index d3b756d020..6ec21bb735 100644 --- a/phpBB/phpbb/notification/method/jabber.php +++ b/phpBB/phpbb/notification/method/jabber.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\method; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  *  * @package notifications  */ -class phpbb_notification_method_jabber extends phpbb_notification_method_messenger_base +class jabber extends \phpbb\notification\method\messenger_base  {  	/**  	* Get notification method name diff --git a/phpBB/phpbb/notification/method/messenger_base.php b/phpBB/phpbb/notification/method/messenger_base.php index 4966aa94bc..b1b30f29b7 100644 --- a/phpBB/phpbb/notification/method/messenger_base.php +++ b/phpBB/phpbb/notification/method/messenger_base.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\method; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  *  * @package notifications  */ -abstract class phpbb_notification_method_messenger_base extends phpbb_notification_method_base +abstract class messenger_base extends \phpbb\notification\method\base  {  	/**  	* Notify using phpBB messenger @@ -60,7 +62,7 @@ abstract class phpbb_notification_method_messenger_base extends phpbb_notificati  		{  			include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext);  		} -		$messenger = new messenger(); +		$messenger = new \messenger();  		$board_url = generate_board_url();  		// Time to go through the queue and send emails diff --git a/phpBB/phpbb/notification/method/interface.php b/phpBB/phpbb/notification/method/method_interface.php index ef875942cc..0131a8bde0 100644 --- a/phpBB/phpbb/notification/method/interface.php +++ b/phpBB/phpbb/notification/method/method_interface.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\method; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * Base notifications method interface  * @package notifications  */ -interface phpbb_notification_method_interface +interface method_interface  {  	/**  	* Get notification method name @@ -37,9 +39,9 @@ interface phpbb_notification_method_interface  	/**  	* Add a notification to the queue  	* -	* @param phpbb_notification_type_interface $notification +	* @param \phpbb\notification\type\type_interface $notification  	*/ -	public function add_to_queue(phpbb_notification_type_interface $notification); +	public function add_to_queue(\phpbb\notification\type\type_interface $notification);  	/**  	* Parse the queue and notify the users diff --git a/phpBB/phpbb/notification/type/approve_post.php b/phpBB/phpbb/notification/type/approve_post.php index 1a30781c35..cf4ec57989 100644 --- a/phpBB/phpbb/notification/type/approve_post.php +++ b/phpBB/phpbb/notification/type/approve_post.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\type; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  *  * @package notifications  */ -class phpbb_notification_type_approve_post extends phpbb_notification_type_post +class approve_post extends \phpbb\notification\type\post  {  	/**  	* Get notification type name diff --git a/phpBB/phpbb/notification/type/approve_topic.php b/phpBB/phpbb/notification/type/approve_topic.php index e728e9ac30..ca5bb67754 100644 --- a/phpBB/phpbb/notification/type/approve_topic.php +++ b/phpBB/phpbb/notification/type/approve_topic.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\type; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  *  * @package notifications  */ -class phpbb_notification_type_approve_topic extends phpbb_notification_type_topic +class approve_topic extends \phpbb\notification\type\topic  {  	/**  	* Get notification type name diff --git a/phpBB/phpbb/notification/type/base.php b/phpBB/phpbb/notification/type/base.php index 46517f1c9b..3c44468bb8 100644 --- a/phpBB/phpbb/notification/type/base.php +++ b/phpBB/phpbb/notification/type/base.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\type; +  /**  * @ignore  */ @@ -19,30 +21,30 @@ if (!defined('IN_PHPBB'))  * Base notifications class  * @package notifications  */ -abstract class phpbb_notification_type_base implements phpbb_notification_type_interface +abstract class base implements \phpbb\notification\type\type_interface  { -	/** @var phpbb_notification_manager */ +	/** @var \phpbb\notification\manager */  	protected $notification_manager; -	/** @var phpbb_user_loader */ +	/** @var \phpbb\user_loader */  	protected $user_loader; -	/** @var phpbb_db_driver */ +	/** @var \phpbb\db\driver\driver */  	protected $db; -	/** @var phpbb_cache_driver_interface */ +	/** @var \phpbb\cache\driver\driver_interface */  	protected $cache; -	/** @var phpbb_template */ +	/** @var \phpbb\template\template */  	protected $template; -	/** @var phpbb_user */ +	/** @var \phpbb\user */  	protected $user; -	/** @var phpbb_auth */ +	/** @var \phpbb\auth\auth */  	protected $auth; -	/** @var phpbb_config */ +	/** @var \phpbb\config\config */  	protected $config;  	/** @var string */ @@ -93,21 +95,21 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i  	/**  	* Notification Type Base Constructor -	*  -	* @param phpbb_user_loader $user_loader -	* @param phpbb_db_driver $db -	* @param phpbb_cache_driver_interface $cache -	* @param phpbb_user $user -	* @param phpbb_auth $auth -	* @param phpbb_config $config +	* +	* @param \phpbb\user_loader $user_loader +	* @param \phpbb\db\driver\driver $db +	* @param \phpbb\cache\driver\driver_interface $cache +	* @param \phpbb\user $user +	* @param \phpbb\auth\auth $auth +	* @param \phpbb\config\config $config  	* @param string $phpbb_root_path  	* @param string $php_ext  	* @param string $notification_types_table  	* @param string $notifications_table  	* @param string $user_notifications_table -	* @return phpbb_notification_type_base +	* @return \phpbb\notification\type\base  	*/ -	public function __construct(phpbb_user_loader $user_loader, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table) +	public function __construct(\phpbb\user_loader $user_loader, \phpbb\db\driver\driver $db, \phpbb\cache\driver\driver_interface $cache, $user, \phpbb\auth\auth $auth, \phpbb\config\config $config, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table)  	{  		$this->user_loader = $user_loader;  		$this->db = $db; @@ -126,10 +128,10 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i  	/**  	* Set notification manager (required) -	*  -	* @param phpbb_notification_manager $notification_manager +	* +	* @param \phpbb\notification\manager $notification_manager  	*/ -	public function set_notification_manager(phpbb_notification_manager $notification_manager) +	public function set_notification_manager(\phpbb\notification\manager $notification_manager)  	{  		$this->notification_manager = $notification_manager; @@ -150,7 +152,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i  	/**  	* Magic method to get data from this notification -	*  +	*  	* @param mixed $name  	* @return mixed  	*/ @@ -162,7 +164,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i  	/**  	* Magic method to set data on this notification -	*  +	*  	* @param mixed $name  	* @return null  	*/ @@ -174,9 +176,9 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i  	/**  	* Magic method to get a string of this notification -	*  +	*  	* Primarily for testing -	*  +	*  	* @param string $name  	* @return mixed  	*/ @@ -283,7 +285,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i  	/**  	* Prepare to output the notification to the template -	*  +	*  	* @return array Template variables  	*/  	public function prepare_for_display() @@ -331,7 +333,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i  	/**  	* Get the user's avatar (fall back) -	*  +	*  	* @return string  	*/  	public function get_avatar() @@ -341,7 +343,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i  	/**  	* Get the special items to load (fall back) -	*  +	*  	* @return array  	*/  	public function get_load_special() @@ -359,7 +361,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i  	/**  	* Is available (fall back) -	*  +	*  	* @return bool  	*/  	public function is_available() @@ -369,7 +371,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i  	/**  	* Pre create insert array function (fall back) -	*  +	*  	* @return array  	*/  	public function pre_create_insert_array($type_data, $notify_users) diff --git a/phpBB/phpbb/notification/type/bookmark.php b/phpBB/phpbb/notification/type/bookmark.php index ae2e75d3eb..50ea7380af 100644 --- a/phpBB/phpbb/notification/type/bookmark.php +++ b/phpBB/phpbb/notification/type/bookmark.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\type; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  *  * @package notifications  */ -class phpbb_notification_type_bookmark extends phpbb_notification_type_post +class bookmark extends \phpbb\notification\type\post  {  	/**  	* Get notification type name diff --git a/phpBB/phpbb/notification/type/disapprove_post.php b/phpBB/phpbb/notification/type/disapprove_post.php index 951c7e0254..0c9162ec5c 100644 --- a/phpBB/phpbb/notification/type/disapprove_post.php +++ b/phpBB/phpbb/notification/type/disapprove_post.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\type; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  *  * @package notifications  */ -class phpbb_notification_type_disapprove_post extends phpbb_notification_type_approve_post +class disapprove_post extends \phpbb\notification\type\approve_post  {  	/**  	* Get notification type name diff --git a/phpBB/phpbb/notification/type/disapprove_topic.php b/phpBB/phpbb/notification/type/disapprove_topic.php index 038e528797..dde6f83ec4 100644 --- a/phpBB/phpbb/notification/type/disapprove_topic.php +++ b/phpBB/phpbb/notification/type/disapprove_topic.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\type; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  *  * @package notifications  */ -class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_approve_topic +class disapprove_topic extends \phpbb\notification\type\approve_topic  {  	/**  	* Get notification type name diff --git a/phpBB/phpbb/notification/type/group_request.php b/phpBB/phpbb/notification/type/group_request.php new file mode 100644 index 0000000000..1768a8fffa --- /dev/null +++ b/phpBB/phpbb/notification/type/group_request.php @@ -0,0 +1,165 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\notification\type; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +class group_request extends \phpbb\notification\type\base +{ +	/** +	* {@inheritdoc} +	*/ +	public function get_type() +	{ +		return 'group_request'; +	} + +	/** +	* {@inheritdoc} +	*/ +	public static $notification_option = array( +		'lang'	=> 'NOTIFICATION_TYPE_GROUP_REQUEST', +	); + +	/** +	* {@inheritdoc} +	*/ +	public function is_available() +	{ +		// Leader of any groups? +		$sql = 'SELECT group_id +			FROM ' . USER_GROUP_TABLE . ' +			WHERE user_id = ' . (int) $this->user->data['user_id'] . ' +				AND group_leader = 1'; +		$result = $this->db->sql_query_limit($sql, 1); +		$row = $this->db->sql_fetchrow($result); +		$this->db->sql_freeresult($result); + +		return (!empty($row)) ? true : false; +	} + +	/** +	* {@inheritdoc} +	*/ +	public static function get_item_id($group) +	{ +		return (int) $group['user_id']; +	} + +	/** +	* {@inheritdoc} +	*/ +	public static function get_item_parent_id($group) +	{ +		// Group id is the parent +		return (int) $group['group_id']; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function find_users_for_notification($group, $options = array()) +	{ +		$options = array_merge(array( +			'ignore_users'		=> array(), +		), $options); + +		$sql = 'SELECT user_id +			FROM ' . USER_GROUP_TABLE . ' +			WHERE group_leader = 1 +				AND group_id = ' . (int) $group['group_id']; +		$result = $this->db->sql_query($sql); + +		$user_ids = array(); +		while ($row = $this->db->sql_fetchrow($result)) +		{ +			$user_ids[] = (int) $row['user_id']; +		} +		$this->db->sql_freeresult($result); + +		$this->user_loader->load_users($user_ids); + +		return $this->check_user_notification_options($user_ids, $options); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_avatar() +	{ +		return $this->user_loader->get_avatar($this->item_id); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_title() +	{ +		$username = $this->user_loader->get_username($this->item_id, 'no_profile'); + +		return $this->user->lang('NOTIFICATION_GROUP_REQUEST', $username, $this->get_data('group_name')); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_email_template() +	{ +		return 'group_request'; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_email_template_variables() +	{ +		$user_data = $this->user_loader->get_user($this->item_id); + +		return array( +			'GROUP_NAME'		   		=> htmlspecialchars_decode($this->get_data('group_name')), +			'REQUEST_USERNAME' 	   		=> htmlspecialchars_decode($user_data['username']), + +			'U_PENDING'			  		=> generate_board_url() . "/ucp.{$this->php_ext}?i=groups&mode=manage&action=list&g={$this->item_parent_id}", +			'U_GROUP'					=> generate_board_url() . "/memberlist.{$this->php_ext}?mode=group&g={$this->item_parent_id}", +		); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_url() +	{ +		return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=groups&mode=manage&action=list&g={$this->item_parent_id}"); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function users_to_query() +	{ +		return array($this->item_id); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function create_insert_array($group, $pre_create_data = array()) +	{ +		$this->set_data('group_name', $group['group_name']); + +		return parent::create_insert_array($group, $pre_create_data); +	} +} diff --git a/phpBB/phpbb/notification/type/group_request_approved.php b/phpBB/phpbb/notification/type/group_request_approved.php new file mode 100644 index 0000000000..be4a902acd --- /dev/null +++ b/phpBB/phpbb/notification/type/group_request_approved.php @@ -0,0 +1,120 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\notification\type; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +class group_request_approved extends \phpbb\notification\type\base +{ +	/** +	* {@inheritdoc} +	*/ +	public function get_type() +	{ +		return 'group_request_approved'; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function is_available() +	{ +		return false; +	} + +	/** +	* {@inheritdoc} +	*/ +	public static function get_item_id($group) +	{ +		return (int) $group['group_id']; +	} + +	/** +	* {@inheritdoc} +	*/ +	public static function get_item_parent_id($group) +	{ +		return 0; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function find_users_for_notification($group, $options = array()) +	{ +		$users = array(); + +		$group['user_ids'] = (!is_array($group['user_ids'])) ? array($group['user_ids']) : $group['user_ids']; + +		foreach ($group['user_ids'] as $user_id) +		{ +			$users[$user_id] = array(''); +		} + +		return $users; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_title() +	{ +		return $this->user->lang('NOTIFICATION_GROUP_REQUEST_APPROVED', $this->get_data('group_name')); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_url() +	{ +		return append_sid($this->phpbb_root_path . 'memberlist.' . $this->php_ext, "mode=group&g={$this->item_id}"); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function create_insert_array($group, $pre_create_data = array()) +	{ +		$this->set_data('group_name', $group['group_name']); + +		return parent::create_insert_array($group, $pre_create_data); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function users_to_query() +	{ +		return array(); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_email_template() +	{ +		return false; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_email_template_variables() +	{ +		return array(); +	} +} diff --git a/phpBB/phpbb/notification/type/pm.php b/phpBB/phpbb/notification/type/pm.php index b3db7ad5ad..bed0807b0f 100644 --- a/phpBB/phpbb/notification/type/pm.php +++ b/phpBB/phpbb/notification/type/pm.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\type; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  *  * @package notifications  */ -class phpbb_notification_type_pm extends phpbb_notification_type_base +class pm extends \phpbb\notification\type\base  {  	/**  	* Get notification type name diff --git a/phpBB/phpbb/notification/type/post.php b/phpBB/phpbb/notification/type/post.php index 9207fd866e..fe50e7f172 100644 --- a/phpBB/phpbb/notification/type/post.php +++ b/phpBB/phpbb/notification/type/post.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\type; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  *  * @package notifications  */ -class phpbb_notification_type_post extends phpbb_notification_type_base +class post extends \phpbb\notification\type\base  {  	/**  	* Get notification type name diff --git a/phpBB/phpbb/notification/type/post_in_queue.php b/phpBB/phpbb/notification/type/post_in_queue.php index bc4b15cdc3..f05ed1ce9a 100644 --- a/phpBB/phpbb/notification/type/post_in_queue.php +++ b/phpBB/phpbb/notification/type/post_in_queue.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\type; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  *  * @package notifications  */ -class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post +class post_in_queue extends \phpbb\notification\type\post  {  	/**  	* Get notification type name diff --git a/phpBB/phpbb/notification/type/quote.php b/phpBB/phpbb/notification/type/quote.php index 0ed13f36fb..8fb433990e 100644 --- a/phpBB/phpbb/notification/type/quote.php +++ b/phpBB/phpbb/notification/type/quote.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\type; +  /**  * @ignore  */ @@ -17,11 +19,11 @@ if (!defined('IN_PHPBB'))  /**  * Post quoting notifications class -* This class handles notifications for quoting users in a post +* This class handles notifying users when they have been quoted in a post  *  * @package notifications  */ -class phpbb_notification_type_quote extends phpbb_notification_type_post +class quote extends \phpbb\notification\type\post  {  	/**  	* Get notification type name diff --git a/phpBB/phpbb/notification/type/report_pm.php b/phpBB/phpbb/notification/type/report_pm.php index 3fa73bab41..13330e2932 100644 --- a/phpBB/phpbb/notification/type/report_pm.php +++ b/phpBB/phpbb/notification/type/report_pm.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\type; +  /**  * @ignore  */ @@ -16,12 +18,12 @@ if (!defined('IN_PHPBB'))  }  /** -* Private message reproted notifications class +* Private message reported notifications class  * This class handles notifications for private messages when they are reported  *  * @package notifications  */ -class phpbb_notification_type_report_pm extends phpbb_notification_type_pm +class report_pm extends \phpbb\notification\type\pm  {  	/**  	* Get notification type name diff --git a/phpBB/phpbb/notification/type/report_pm_closed.php b/phpBB/phpbb/notification/type/report_pm_closed.php index 63dfa92064..2e4a1ceb30 100644 --- a/phpBB/phpbb/notification/type/report_pm_closed.php +++ b/phpBB/phpbb/notification/type/report_pm_closed.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\type; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  *  * @package notifications  */ -class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_pm +class report_pm_closed extends \phpbb\notification\type\pm  {  	/**  	* Get notification type name diff --git a/phpBB/phpbb/notification/type/report_post.php b/phpBB/phpbb/notification/type/report_post.php index de5c54a291..c2dad6f1bb 100644 --- a/phpBB/phpbb/notification/type/report_post.php +++ b/phpBB/phpbb/notification/type/report_post.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\type; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  *  * @package notifications  */ -class phpbb_notification_type_report_post extends phpbb_notification_type_post_in_queue +class report_post extends \phpbb\notification\type\post_in_queue  {  	/**  	* Get notification type name diff --git a/phpBB/phpbb/notification/type/report_post_closed.php b/phpBB/phpbb/notification/type/report_post_closed.php index 3916cd8db7..270ccf0a1a 100644 --- a/phpBB/phpbb/notification/type/report_post_closed.php +++ b/phpBB/phpbb/notification/type/report_post_closed.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\type; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  *  * @package notifications  */ -class phpbb_notification_type_report_post_closed extends phpbb_notification_type_post +class report_post_closed extends \phpbb\notification\type\post  {  	/**  	* Get notification type name diff --git a/phpBB/phpbb/notification/type/topic.php b/phpBB/phpbb/notification/type/topic.php index 22436d3fb1..8db02f610b 100644 --- a/phpBB/phpbb/notification/type/topic.php +++ b/phpBB/phpbb/notification/type/topic.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\type; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  *  * @package notifications  */ -class phpbb_notification_type_topic extends phpbb_notification_type_base +class topic extends \phpbb\notification\type\base  {  	/**  	* Get notification type name diff --git a/phpBB/phpbb/notification/type/topic_in_queue.php b/phpBB/phpbb/notification/type/topic_in_queue.php index f735e10c00..056651bc53 100644 --- a/phpBB/phpbb/notification/type/topic_in_queue.php +++ b/phpBB/phpbb/notification/type/topic_in_queue.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\type; +  /**  * @ignore  */ @@ -21,7 +23,7 @@ if (!defined('IN_PHPBB'))  *  * @package notifications  */ -class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_topic +class topic_in_queue extends \phpbb\notification\type\topic  {  	/**  	* Get notification type name diff --git a/phpBB/phpbb/notification/type/interface.php b/phpBB/phpbb/notification/type/type_interface.php index a40fdafd09..cfc6cd461e 100644 --- a/phpBB/phpbb/notification/type/interface.php +++ b/phpBB/phpbb/notification/type/type_interface.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\notification\type; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * Base notifications interface  * @package notifications  */ -interface phpbb_notification_type_interface +interface type_interface  {  	/**  	* Get notification type name @@ -27,7 +29,7 @@ interface phpbb_notification_type_interface  	* @return string  	*/  	public function get_type(); -	 +  	/**  	* Set initial data from the database  	* diff --git a/phpBB/phpbb/path_helper.php b/phpBB/phpbb/path_helper.php new file mode 100644 index 0000000000..b2ed11a927 --- /dev/null +++ b/phpBB/phpbb/path_helper.php @@ -0,0 +1,175 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +/** +* A class with various functions that are related to paths, files and the filesystem +* @package phpBB3 +*/ +class path_helper +{ +	/** @var \phpbb\symfony_request */ +	protected $symfony_request; + +	/** @var \phpbb\filesystem */ +	protected $filesystem; + +	/** @var string */ +	protected $phpbb_root_path; + +	/** @var string */ +	protected $adm_relative_path; + +	/** @var string */ +	protected $php_ext; + +	/** @var string */ +	protected $web_root_path; + +	/** +	* Constructor +	* +	* @param \phpbb\symfony_request $symfony_request +	* @param \phpbb\filesystem $filesystem +	* @param string $phpbb_root_path Relative path to phpBB root +	* @param string $php_ext PHP extension (php) +	*/ +	public function __construct(\phpbb\symfony_request $symfony_request, \phpbb\filesystem $filesystem, $phpbb_root_path, $php_ext, $adm_relative_path = null) +	{ +		$this->symfony_request = $symfony_request; +		$this->filesystem = $filesystem; +		$this->phpbb_root_path = $phpbb_root_path; +		$this->php_ext = $php_ext; +		$this->adm_relative_path = $adm_relative_path; +	} + +	/** +	* Get the phpBB root path +	* +	* @return string +	*/ +	public function get_phpbb_root_path() +	{ +		return $this->phpbb_root_path; +	} + +	/** +	* Get the adm root path +	* +	* @return string +	*/ +	public function get_adm_relative_path() +	{ +		return $this->adm_relative_path; +	} + +	/** +	* Get the php extension +	* +	* @return string +	*/ +	public function get_php_ext() +	{ +		return $this->php_ext; +	} + +	/** +	* Update a path to the correct relative root path +	* +	* This replaces $phpbb_root_path . some_url with +	*	get_web_root_path() . some_url OR if $phpbb_root_path +	*	is not at the beginning of $path, just prepends the +	*	web root path +	* +	* @param string $path The path to be updated +	* @return string +	*/ +	public function update_web_root_path($path) +	{ +		$web_root_path = $this->get_web_root_path($this->symfony_request); + +		if (strpos($path, $this->phpbb_root_path) === 0) +		{ +			$path = substr($path, strlen($this->phpbb_root_path)); +		} + +		return $web_root_path . $path; +	} + +	/** +	* Get a relative root path from the current URL +	* +	* @return string +	*/ +	public function get_web_root_path() +	{ +		if ($this->symfony_request === null) +		{ +			return $this->phpbb_root_path; +		} + +		if (null !== $this->web_root_path) +		{ +			return $this->web_root_path; +		} + +		// Path info (e.g. /foo/bar) +		$path_info = $this->filesystem->clean_path($this->symfony_request->getPathInfo()); + +		// Full request URI (e.g. phpBB/app.php/foo/bar) +		$request_uri = $this->symfony_request->getRequestUri(); + +		// Script name URI (e.g. phpBB/app.php) +		$script_name = $this->symfony_request->getScriptName(); + +		/* +		* If the path info is empty (single /), then we're not using +		*	a route like app.php/foo/bar +		*/ +		if ($path_info === '/') +		{ +			return $this->web_root_path = $this->phpbb_root_path; +		} + +		// How many corrections might we need? +		$corrections = substr_count($path_info, '/'); + +		/* +		* If the script name (e.g. phpBB/app.php) exists in the +		*	requestUri (e.g. phpBB/app.php/foo/template), then we +		*	are have a non-rewritten URL. +		*/ +		if (strpos($request_uri, $script_name) === 0) +		{ +			/* +			* Append ../ to the end of the phpbb_root_path as many times +			*	as / exists in path_info +			*/ +			return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $corrections); +		} + +		/* +		* If we're here it means we're at a re-written path, so we must +		*	correct the relative path for web URLs. We must append ../ +		*	to the end of the root path as many times as / exists in path_info +		*	less one time (because the script, e.g. /app.php, doesn't exist in +		*	the URL) +		*/ +		return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $corrections - 1); +	} +} diff --git a/phpBB/phpbb/permissions.php b/phpBB/phpbb/permissions.php new file mode 100644 index 0000000000..d0405471bc --- /dev/null +++ b/phpBB/phpbb/permissions.php @@ -0,0 +1,342 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb; + +/** +* DO NOT CHANGE +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +class permissions +{ +	/** +	* Event dispatcher object +	* @var \phpbb\event\dispatcher +	*/ +	protected $dispatcher; + +	/** +	* User object +	* @var \phpbb\user +	*/ +	protected $user; + +	/** +	* Constructor +	* +	* @param	\phpbb\event\dispatcher	$phpbb_dispatcher	Event dispatcher +	* @param	\phpbb\user				$user				User Object +	* @return	null +	*/ +	public function __construct(\phpbb\event\dispatcher $phpbb_dispatcher, \phpbb\user $user) +	{ +		$this->dispatcher = $phpbb_dispatcher; +		$this->user = $user; + +		$categories = $this->categories; +		$types = $this->types; +		$permissions = $this->permissions; + +		/** +		* Allows to specify additional permission categories, types and permissions +		* +		* @event core.permissions +		* @var	array	types			Array with permission types (a_, u_, m_, etc.) +		* @var	array	categories		Array with permission categories (pm, post, settings, misc, etc.) +		* @var	array	permissions		Array with permissions. Each Permission has the following layout: +		*		'<type><permission>' => array( +		*			'lang'	=> 'Language Key with a Short description', // Optional, if not set, +		*						// the permissions identifier '<type><permission>' is used with +		*						// all uppercase. +		*			'cat'	=> 'Identifier of the category, the permission should be displayed in', +		*		), +		*		Example: +		*		'u_viewprofile' => array( +		*			'lang'	=> 'ACL_U_VIEWPROFILE', +		*			'cat'	=> 'profile', +		*		), +		* @since 3.1-A1 +		*/ +		$vars = array('types', 'categories', 'permissions'); +		extract($phpbb_dispatcher->trigger_event('core.permissions', compact($vars))); + +		$this->categories = $categories; +		$this->types = $types; +		$this->permissions = $permissions; +	} + +	/** +	* Returns an array with all the permission categories (pm, post, settings, misc, etc.) +	* +	* @return	array	Layout: cat-identifier => Language key +	*/ +	public function get_categories() +	{ +		return $this->categories; +	} + +	/** +	* Returns the language string of a permission category +	* +	* @param	string	$category	Identifier of the category +	* @return	string		Language string +	*/ +	public function get_category_lang($category) +	{ +		return $this->user->lang($this->categories[$category]); +	} + +	/** +	* Returns an array with all the permission types (a_, u_, m_, etc.) +	* +	* @return	array	Layout: type-identifier => Language key +	*/ +	public function get_types() +	{ +		return $this->types; +	} + +	/** +	* Returns the language string of a permission type +	* +	* @param	string	$type	Identifier of the type +	* @param	mixed	$scope	Scope of the type (should be 'global', 'local' or false) +	* @return	string	Language string +	*/ +	public function get_type_lang($type, $scope = false) +	{ +		if ($scope && isset($this->types[$scope][$type])) +		{ +			$lang_key = $this->types[$scope][$type]; +		} +		else if (isset($this->types[$type])) +		{ +			$lang_key = $this->types[$type]; +		} +		else +		{ +			$lang_key = 'ACL_TYPE_' . strtoupper(($scope) ? $scope . '_' . $type : $type); +		} + +		return $this->user->lang($lang_key); +	} + +	/** +	* Returns an array with all the permissions. +	* Each Permission has the following layout: +	*	'<type><permission>' => array( +	*		'lang'	=> 'Language Key with a Short description', // Optional, if not set, +	*					// the permissions identifier '<type><permission>' is used with +	*					// all uppercase. +	*		'cat'	=> 'Identifier of the category, the permission should be displayed in', +	*	), +	*	Example: +	*	'u_viewprofile' => array( +	*		'lang'	=> 'ACL_U_VIEWPROFILE', +	*		'cat'	=> 'profile', +	*	), +	* +	* @return	array +	*/ +	public function get_permissions() +	{ +		return $this->permissions; +	} + +	/** +	* Returns the category of a permission +	* +	* @param	string	$permission	Identifier of the permission +	* @return	string		Returns the category identifier of the permission +	*/ +	public function get_permission_category($permission) +	{ +		return (isset($this->permissions[$permission]['cat'])) ? $this->permissions[$permission]['cat'] : 'misc'; +	} + +	/** +	* Returns the language string of a permission +	* +	* @param	string	$permission	Identifier of the permission +	* @return	string	Language string +	*/ +	public function get_permission_lang($permission) +	{ +		return (isset($this->permissions[$permission]['lang'])) ? $this->user->lang($this->permissions[$permission]['lang']) : $this->user->lang('ACL_' . strtoupper($permission)); +	} + +	protected $types = array( +		'u_'			=> 'ACL_TYPE_U_', +		'a_'			=> 'ACL_TYPE_A_', +		'm_'			=> 'ACL_TYPE_M_', +		'f_'			=> 'ACL_TYPE_F_', +		'global'		=> array( +			'm_'			=> 'ACL_TYPE_GLOBAL_M_', +		), +	); + +	protected $categories = array( +		'actions'		=> 'ACL_CAT_ACTIONS', +		'content'		=> 'ACL_CAT_CONTENT', +		'forums'		=> 'ACL_CAT_FORUMS', +		'misc'			=> 'ACL_CAT_MISC', +		'permissions'	=> 'ACL_CAT_PERMISSIONS', +		'pm'			=> 'ACL_CAT_PM', +		'polls'			=> 'ACL_CAT_POLLS', +		'post'			=> 'ACL_CAT_POST', +		'post_actions'	=> 'ACL_CAT_POST_ACTIONS', +		'posting'		=> 'ACL_CAT_POSTING', +		'profile'		=> 'ACL_CAT_PROFILE', +		'settings'		=> 'ACL_CAT_SETTINGS', +		'topic_actions'	=> 'ACL_CAT_TOPIC_ACTIONS', +		'user_group'	=> 'ACL_CAT_USER_GROUP', +	); + +	protected $permissions = array( +		// User Permissions +		'u_viewprofile'	=> array('lang' => 'ACL_U_VIEWPROFILE', 'cat' => 'profile'), +		'u_chgname'		=> array('lang' => 'ACL_U_CHGNAME', 'cat' => 'profile'), +		'u_chgpasswd'	=> array('lang' => 'ACL_U_CHGPASSWD', 'cat' => 'profile'), +		'u_chgemail'	=> array('lang' => 'ACL_U_CHGEMAIL', 'cat' => 'profile'), +		'u_chgavatar'	=> array('lang' => 'ACL_U_CHGAVATAR', 'cat' => 'profile'), +		'u_chggrp'		=> array('lang' => 'ACL_U_CHGGRP', 'cat' => 'profile'), +		'u_chgprofileinfo'	=> array('lang' => 'ACL_U_CHGPROFILEINFO', 'cat' => 'profile'), + +		'u_attach'		=> array('lang' => 'ACL_U_ATTACH', 'cat' => 'post'), +		'u_download'	=> array('lang' => 'ACL_U_DOWNLOAD', 'cat' => 'post'), +		'u_savedrafts'	=> array('lang' => 'ACL_U_SAVEDRAFTS', 'cat' => 'post'), +		'u_chgcensors'	=> array('lang' => 'ACL_U_CHGCENSORS', 'cat' => 'post'), +		'u_sig'			=> array('lang' => 'ACL_U_SIG', 'cat' => 'post'), + +		'u_sendpm'		=> array('lang' => 'ACL_U_SENDPM', 'cat' => 'pm'), +		'u_masspm'		=> array('lang' => 'ACL_U_MASSPM', 'cat' => 'pm'), +		'u_masspm_group'=> array('lang' => 'ACL_U_MASSPM_GROUP', 'cat' => 'pm'), +		'u_readpm'		=> array('lang' => 'ACL_U_READPM', 'cat' => 'pm'), +		'u_pm_edit'		=> array('lang' => 'ACL_U_PM_EDIT', 'cat' => 'pm'), +		'u_pm_delete'	=> array('lang' => 'ACL_U_PM_DELETE', 'cat' => 'pm'), +		'u_pm_forward'	=> array('lang' => 'ACL_U_PM_FORWARD', 'cat' => 'pm'), +		'u_pm_emailpm'	=> array('lang' => 'ACL_U_PM_EMAILPM', 'cat' => 'pm'), +		'u_pm_printpm'	=> array('lang' => 'ACL_U_PM_PRINTPM', 'cat' => 'pm'), +		'u_pm_attach'	=> array('lang' => 'ACL_U_PM_ATTACH', 'cat' => 'pm'), +		'u_pm_download'	=> array('lang' => 'ACL_U_PM_DOWNLOAD', 'cat' => 'pm'), +		'u_pm_bbcode'	=> array('lang' => 'ACL_U_PM_BBCODE', 'cat' => 'pm'), +		'u_pm_smilies'	=> array('lang' => 'ACL_U_PM_SMILIES', 'cat' => 'pm'), +		'u_pm_img'		=> array('lang' => 'ACL_U_PM_IMG', 'cat' => 'pm'), +		'u_pm_flash'	=> array('lang' => 'ACL_U_PM_FLASH', 'cat' => 'pm'), + +		'u_sendemail'	=> array('lang' => 'ACL_U_SENDEMAIL', 'cat' => 'misc'), +		'u_sendim'		=> array('lang' => 'ACL_U_SENDIM', 'cat' => 'misc'), +		'u_ignoreflood'	=> array('lang' => 'ACL_U_IGNOREFLOOD', 'cat' => 'misc'), +		'u_hideonline'	=> array('lang' => 'ACL_U_HIDEONLINE', 'cat' => 'misc'), +		'u_viewonline'	=> array('lang' => 'ACL_U_VIEWONLINE', 'cat' => 'misc'), +		'u_search'		=> array('lang' => 'ACL_U_SEARCH', 'cat' => 'misc'), + +		// Forum Permissions +		'f_list'		=> array('lang' => 'ACL_F_LIST', 'cat' => 'actions'), +		'f_read'		=> array('lang' => 'ACL_F_READ', 'cat' => 'actions'), +		'f_search'		=> array('lang' => 'ACL_F_SEARCH', 'cat' => 'actions'), +		'f_subscribe'	=> array('lang' => 'ACL_F_SUBSCRIBE', 'cat' => 'actions'), +		'f_print'		=> array('lang' => 'ACL_F_PRINT', 'cat' => 'actions'), +		'f_email'		=> array('lang' => 'ACL_F_EMAIL', 'cat' => 'actions'), +		'f_bump'		=> array('lang' => 'ACL_F_BUMP', 'cat' => 'actions'), +		'f_user_lock'	=> array('lang' => 'ACL_F_USER_LOCK', 'cat' => 'actions'), +		'f_download'	=> array('lang' => 'ACL_F_DOWNLOAD', 'cat' => 'actions'), +		'f_report'		=> array('lang' => 'ACL_F_REPORT', 'cat' => 'actions'), + +		'f_post'		=> array('lang' => 'ACL_F_POST', 'cat' => 'post'), +		'f_sticky'		=> array('lang' => 'ACL_F_STICKY', 'cat' => 'post'), +		'f_announce'	=> array('lang' => 'ACL_F_ANNOUNCE', 'cat' => 'post'), +		'f_reply'		=> array('lang' => 'ACL_F_REPLY', 'cat' => 'post'), +		'f_edit'		=> array('lang' => 'ACL_F_EDIT', 'cat' => 'post'), +		'f_delete'		=> array('lang' => 'ACL_F_DELETE', 'cat' => 'post'), +		'f_ignoreflood' => array('lang' => 'ACL_F_IGNOREFLOOD', 'cat' => 'post'), +		'f_postcount'	=> array('lang' => 'ACL_F_POSTCOUNT', 'cat' => 'post'), +		'f_noapprove'	=> array('lang' => 'ACL_F_NOAPPROVE', 'cat' => 'post'), + +		'f_attach'		=> array('lang' => 'ACL_F_ATTACH', 'cat' => 'content'), +		'f_icons'		=> array('lang' => 'ACL_F_ICONS', 'cat' => 'content'), +		'f_bbcode'		=> array('lang' => 'ACL_F_BBCODE', 'cat' => 'content'), +		'f_flash'		=> array('lang' => 'ACL_F_FLASH', 'cat' => 'content'), +		'f_img'			=> array('lang' => 'ACL_F_IMG', 'cat' => 'content'), +		'f_sigs'		=> array('lang' => 'ACL_F_SIGS', 'cat' => 'content'), +		'f_smilies'		=> array('lang' => 'ACL_F_SMILIES', 'cat' => 'content'), + +		'f_poll'		=> array('lang' => 'ACL_F_POLL', 'cat' => 'polls'), +		'f_vote'		=> array('lang' => 'ACL_F_VOTE', 'cat' => 'polls'), +		'f_votechg'		=> array('lang' => 'ACL_F_VOTECHG', 'cat' => 'polls'), + +		// Moderator Permissions +		'm_edit'		=> array('lang' => 'ACL_M_EDIT', 'cat' => 'post_actions'), +		'm_delete'		=> array('lang' => 'ACL_M_DELETE', 'cat' => 'post_actions'), +		'm_approve'		=> array('lang' => 'ACL_M_APPROVE', 'cat' => 'post_actions'), +		'm_report'		=> array('lang' => 'ACL_M_REPORT', 'cat' => 'post_actions'), +		'm_chgposter'	=> array('lang' => 'ACL_M_CHGPOSTER', 'cat' => 'post_actions'), + +		'm_move'	=> array('lang' => 'ACL_M_MOVE', 'cat' => 'topic_actions'), +		'm_lock'	=> array('lang' => 'ACL_M_LOCK', 'cat' => 'topic_actions'), +		'm_split'	=> array('lang' => 'ACL_M_SPLIT', 'cat' => 'topic_actions'), +		'm_merge'	=> array('lang' => 'ACL_M_MERGE', 'cat' => 'topic_actions'), + +		'm_info'	=> array('lang' => 'ACL_M_INFO', 'cat' => 'misc'), +		'm_warn'	=> array('lang' => 'ACL_M_WARN', 'cat' => 'misc'), +		'm_ban'		=> array('lang' => 'ACL_M_BAN', 'cat' => 'misc'), + +		// Admin Permissions +		'a_board'		=> array('lang' => 'ACL_A_BOARD', 'cat' => 'settings'), +		'a_server'		=> array('lang' => 'ACL_A_SERVER', 'cat' => 'settings'), +		'a_jabber'		=> array('lang' => 'ACL_A_JABBER', 'cat' => 'settings'), +		'a_phpinfo'		=> array('lang' => 'ACL_A_PHPINFO', 'cat' => 'settings'), + +		'a_forum'		=> array('lang' => 'ACL_A_FORUM', 'cat' => 'forums'), +		'a_forumadd'	=> array('lang' => 'ACL_A_FORUMADD', 'cat' => 'forums'), +		'a_forumdel'	=> array('lang' => 'ACL_A_FORUMDEL', 'cat' => 'forums'), +		'a_prune'		=> array('lang' => 'ACL_A_PRUNE', 'cat' => 'forums'), + +		'a_icons'		=> array('lang' => 'ACL_A_ICONS', 'cat' => 'posting'), +		'a_words'		=> array('lang' => 'ACL_A_WORDS', 'cat' => 'posting'), +		'a_bbcode'		=> array('lang' => 'ACL_A_BBCODE', 'cat' => 'posting'), +		'a_attach'		=> array('lang' => 'ACL_A_ATTACH', 'cat' => 'posting'), + +		'a_user'		=> array('lang' => 'ACL_A_USER', 'cat' => 'user_group'), +		'a_userdel'		=> array('lang' => 'ACL_A_USERDEL', 'cat' => 'user_group'), +		'a_group'		=> array('lang' => 'ACL_A_GROUP', 'cat' => 'user_group'), +		'a_groupadd'	=> array('lang' => 'ACL_A_GROUPADD', 'cat' => 'user_group'), +		'a_groupdel'	=> array('lang' => 'ACL_A_GROUPDEL', 'cat' => 'user_group'), +		'a_ranks'		=> array('lang' => 'ACL_A_RANKS', 'cat' => 'user_group'), +		'a_profile'		=> array('lang' => 'ACL_A_PROFILE', 'cat' => 'user_group'), +		'a_names'		=> array('lang' => 'ACL_A_NAMES', 'cat' => 'user_group'), +		'a_ban'			=> array('lang' => 'ACL_A_BAN', 'cat' => 'user_group'), + +		'a_viewauth'	=> array('lang' => 'ACL_A_VIEWAUTH', 'cat' => 'permissions'), +		'a_authgroups'	=> array('lang' => 'ACL_A_AUTHGROUPS', 'cat' => 'permissions'), +		'a_authusers'	=> array('lang' => 'ACL_A_AUTHUSERS', 'cat' => 'permissions'), +		'a_fauth'		=> array('lang' => 'ACL_A_FAUTH', 'cat' => 'permissions'), +		'a_mauth'		=> array('lang' => 'ACL_A_MAUTH', 'cat' => 'permissions'), +		'a_aauth'		=> array('lang' => 'ACL_A_AAUTH', 'cat' => 'permissions'), +		'a_uauth'		=> array('lang' => 'ACL_A_UAUTH', 'cat' => 'permissions'), +		'a_roles'		=> array('lang' => 'ACL_A_ROLES', 'cat' => 'permissions'), +		'a_switchperm'	=> array('lang' => 'ACL_A_SWITCHPERM', 'cat' => 'permissions'), + +		'a_styles'		=> array('lang' => 'ACL_A_STYLES', 'cat' => 'misc'), +		'a_extensions'	=> array('lang' => 'ACL_A_EXTENSIONS', 'cat' => 'misc'), +		'a_viewlogs'	=> array('lang' => 'ACL_A_VIEWLOGS', 'cat' => 'misc'), +		'a_clearlogs'	=> array('lang' => 'ACL_A_CLEARLOGS', 'cat' => 'misc'), +		'a_modules'		=> array('lang' => 'ACL_A_MODULES', 'cat' => 'misc'), +		'a_language'	=> array('lang' => 'ACL_A_LANGUAGE', 'cat' => 'misc'), +		'a_email'		=> array('lang' => 'ACL_A_EMAIL', 'cat' => 'misc'), +		'a_bots'		=> array('lang' => 'ACL_A_BOTS', 'cat' => 'misc'), +		'a_reasons'		=> array('lang' => 'ACL_A_REASONS', 'cat' => 'misc'), +		'a_backup'		=> array('lang' => 'ACL_A_BACKUP', 'cat' => 'misc'), +		'a_search'		=> array('lang' => 'ACL_A_SEARCH', 'cat' => 'misc'), +	); +} diff --git a/phpBB/phpbb/php/ini.php b/phpBB/phpbb/php/ini.php index 17e8c54a57..8767091aba 100644 --- a/phpBB/phpbb/php/ini.php +++ b/phpBB/phpbb/php/ini.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\php; +  /**  * @ignore  */ @@ -22,7 +24,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB  */ -class phpbb_php_ini +class ini  {  	/**  	* Simple wrapper for ini_get() diff --git a/phpBB/phpbb/request/deactivated_super_global.php b/phpBB/phpbb/request/deactivated_super_global.php index cc05847ec7..8f39960477 100644 --- a/phpBB/phpbb/request/deactivated_super_global.php +++ b/phpBB/phpbb/request/deactivated_super_global.php @@ -1,12 +1,14 @@  <?php  /**  * -* @package phpbb_request +* @package \phpbb\request\request  * @copyright (c) 2010 phpBB Group  * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2  *  */ +namespace phpbb\request; +  /**  * @ignore  */ @@ -19,9 +21,9 @@ if (!defined('IN_PHPBB'))  * Replacement for a superglobal (like $_GET or $_POST) which calls  * trigger_error on all operations but isset, overloads the [] operator with SPL.  * -* @package phpbb_request +* @package \phpbb\request\request  */ -class phpbb_request_deactivated_super_global implements ArrayAccess, Countable, IteratorAggregate +class deactivated_super_global implements \ArrayAccess, \Countable, \IteratorAggregate  {  	/**  	* @var	string	Holds the name of the superglobal this is replacing. @@ -29,23 +31,23 @@ class phpbb_request_deactivated_super_global implements ArrayAccess, Countable,  	private $name;  	/** -	* @var	phpbb_request_interface::POST|GET|REQUEST|COOKIE	Super global constant. +	* @var	\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE	Super global constant.  	*/  	private $super_global;  	/** -	* @var	phpbb_request_interface	The request class instance holding the actual request data. +	* @var	\phpbb\request\request_interface	The request class instance holding the actual request data.  	*/  	private $request;  	/**  	* Constructor generates an error message fitting the super global to be used within the other functions.  	* -	* @param	phpbb_request_interface	$request	A request class instance holding the real super global data. +	* @param	\phpbb\request\request_interface	$request	A request class instance holding the real super global data.  	* @param	string					$name		Name of the super global this is a replacement for - e.g. '_GET'. -	* @param	phpbb_request_interface::POST|GET|REQUEST|COOKIE	$super_global	The variable's super global constant. +	* @param	\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE	$super_global	The variable's super global constant.  	*/ -	public function __construct(phpbb_request_interface $request, $name, $super_global) +	public function __construct(\phpbb\request\request_interface $request, $name, $super_global)  	{  		$this->request = $request;  		$this->name = $name; @@ -84,7 +86,7 @@ class phpbb_request_deactivated_super_global implements ArrayAccess, Countable,  	}  	/**#@+ -	* Part of the ArrayAccess implementation, will always result in a FATAL error. +	* Part of the \ArrayAccess implementation, will always result in a FATAL error.  	*/  	public function offsetGet($offset)  	{ @@ -103,7 +105,7 @@ class phpbb_request_deactivated_super_global implements ArrayAccess, Countable,  	/**#@-*/  	/** -	* Part of the Countable implementation, will always result in a FATAL error +	* Part of the \Countable implementation, will always result in a FATAL error  	*/  	public function count()  	{ diff --git a/phpBB/phpbb/request/request.php b/phpBB/phpbb/request/request.php index ae3c526d89..1c388b3c73 100644 --- a/phpBB/phpbb/request/request.php +++ b/phpBB/phpbb/request/request.php @@ -1,12 +1,14 @@  <?php  /**  * -* @package phpbb_request +* @package \phpbb\request\request  * @copyright (c) 2010 phpBB Group  * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2  *  */ +namespace phpbb\request; +  /**  * @ignore  */ @@ -21,20 +23,20 @@ if (!defined('IN_PHPBB'))  * It provides a method to disable access to input data through super globals.  * This should force MOD authors to read about data validation.  * -* @package phpbb_request +* @package \phpbb\request\request  */ -class phpbb_request implements phpbb_request_interface +class request implements \phpbb\request\request_interface  {  	/**  	* @var	array	The names of super global variables that this class should protect if super globals are disabled.  	*/  	protected $super_globals = array( -		phpbb_request_interface::POST => '_POST', -		phpbb_request_interface::GET => '_GET', -		phpbb_request_interface::REQUEST => '_REQUEST', -		phpbb_request_interface::COOKIE => '_COOKIE', -		phpbb_request_interface::SERVER => '_SERVER', -		phpbb_request_interface::FILES => '_FILES', +		\phpbb\request\request_interface::POST => '_POST', +		\phpbb\request\request_interface::GET => '_GET', +		\phpbb\request\request_interface::REQUEST => '_REQUEST', +		\phpbb\request\request_interface::COOKIE => '_COOKIE', +		\phpbb\request\request_interface::SERVER => '_SERVER', +		\phpbb\request\request_interface::FILES => '_FILES',  	);  	/** @@ -53,15 +55,15 @@ class phpbb_request implements phpbb_request_interface  	protected $input;  	/** -	* @var	phpbb_request_type_cast_helper_interface	An instance of a type cast helper providing convenience methods for type conversions. +	* @var	\phpbb\request\type_cast_helper_interface	An instance of a type cast helper providing convenience methods for type conversions.  	*/  	protected $type_cast_helper;  	/**  	* Initialises the request class, that means it stores all input data in {@link $input input} -	* and then calls {@link phpbb_request_deactivated_super_global phpbb_request_deactivated_super_global} +	* and then calls {@link \phpbb\request\deactivated_super_global \phpbb\request\deactivated_super_global}  	*/ -	public function __construct(phpbb_request_type_cast_helper_interface $type_cast_helper = null, $disable_super_globals = true) +	public function __construct(\phpbb\request\type_cast_helper_interface $type_cast_helper = null, $disable_super_globals = true)  	{  		if ($type_cast_helper)  		{ @@ -69,7 +71,7 @@ class phpbb_request implements phpbb_request_interface  		}  		else  		{ -			$this->type_cast_helper = new phpbb_request_type_cast_helper(); +			$this->type_cast_helper = new \phpbb\request\type_cast_helper();  		}  		foreach ($this->super_globals as $const => $super_global) @@ -78,8 +80,8 @@ class phpbb_request implements phpbb_request_interface  		}  		// simulate request_order = GP -		$this->original_request = $this->input[phpbb_request_interface::REQUEST]; -		$this->input[phpbb_request_interface::REQUEST] = $this->input[phpbb_request_interface::POST] + $this->input[phpbb_request_interface::GET]; +		$this->original_request = $this->input[\phpbb\request\request_interface::REQUEST]; +		$this->input[\phpbb\request\request_interface::REQUEST] = $this->input[\phpbb\request\request_interface::POST] + $this->input[\phpbb\request\request_interface::GET];  		if ($disable_super_globals)  		{ @@ -99,7 +101,7 @@ class phpbb_request implements phpbb_request_interface  	/**  	* Disables access of super globals specified in $super_globals. -	* This is achieved by overwriting the super globals with instances of {@link phpbb_request_deactivated_super_global phpbb_request_deactivated_super_global} +	* This is achieved by overwriting the super globals with instances of {@link \phpbb\request\deactivated_super_global \phpbb\request\deactivated_super_global}  	*/  	public function disable_super_globals()  	{ @@ -108,7 +110,7 @@ class phpbb_request implements phpbb_request_interface  			foreach ($this->super_globals as $const => $super_global)  			{  				unset($GLOBALS[$super_global]); -				$GLOBALS[$super_global] = new phpbb_request_deactivated_super_global($this, $super_global, $const); +				$GLOBALS[$super_global] = new \phpbb\request\deactivated_super_global($this, $super_global, $const);  			}  			$this->super_globals_disabled = true; @@ -144,10 +146,10 @@ class phpbb_request implements phpbb_request_interface  	* @param	string	$var_name	The name of the variable that shall be overwritten  	* @param	mixed	$value		The value which the variable shall contain.  	* 								If this is null the variable will be unset. -	* @param	phpbb_request_interface::POST|GET|REQUEST|COOKIE	$super_global +	* @param	\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE	$super_global  	* 								Specifies which super global shall be changed  	*/ -	public function overwrite($var_name, $value, $super_global = phpbb_request_interface::REQUEST) +	public function overwrite($var_name, $value, $super_global = \phpbb\request\request_interface::REQUEST)  	{  		if (!isset($this->super_globals[$super_global]))  		{ @@ -193,13 +195,13 @@ class phpbb_request implements phpbb_request_interface  	* 										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	phpbb_request_interface::POST|GET|REQUEST|COOKIE	$super_global +	* @param	\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE	$super_global  	* 										Specifies which super global should be used  	*  	* @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.  	*/ -	public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST) +	public function variable($var_name, $default, $multibyte = false, $super_global = \phpbb\request\request_interface::REQUEST)  	{  		return $this->_variable($var_name, $default, $multibyte, $super_global, true);  	} @@ -217,13 +219,13 @@ class phpbb_request implements phpbb_request_interface  	* 										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	phpbb_request_interface::POST|GET|REQUEST|COOKIE	$super_global +	* @param	\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE	$super_global  	* 										Specifies which super global should be used  	*  	* @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.  	*/ -	public function untrimmed_variable($var_name, $default, $multibyte, $super_global = phpbb_request_interface::REQUEST) +	public function untrimmed_variable($var_name, $default, $multibyte, $super_global = \phpbb\request\request_interface::REQUEST)  	{  		return $this->_variable($var_name, $default, $multibyte, $super_global, false);  	} @@ -234,8 +236,8 @@ class phpbb_request implements phpbb_request_interface  	* Also fall back to getenv(), some CGI setups may need it (probably not, but  	* whatever).  	* -	* @param	string|array	$var_name		See phpbb_request_interface::variable -	* @param	mixed			$Default		See phpbb_request_interface::variable +	* @param	string|array	$var_name		See \phpbb\request\request_interface::variable +	* @param	mixed			$Default		See \phpbb\request\request_interface::variable  	*  	* @return	mixed	The server variable value.  	*/ @@ -243,9 +245,9 @@ class phpbb_request implements phpbb_request_interface  	{  		$multibyte = true; -		if ($this->is_set($var_name, phpbb_request_interface::SERVER)) +		if ($this->is_set($var_name, \phpbb\request\request_interface::SERVER))  		{ -			return $this->variable($var_name, $default, $multibyte, phpbb_request_interface::SERVER); +			return $this->variable($var_name, $default, $multibyte, \phpbb\request\request_interface::SERVER);  		}  		else  		{ @@ -259,7 +261,7 @@ class phpbb_request implements phpbb_request_interface  	* Shortcut method to retrieve the value of client HTTP headers.  	*  	* @param	string|array	$header_name	The name of the header to retrieve. -	* @param	mixed			$default		See phpbb_request_interface::variable +	* @param	mixed			$default		See \phpbb\request\request_interface::variable  	*  	* @return	mixed	The header value.  	*/ @@ -279,7 +281,7 @@ class phpbb_request implements phpbb_request_interface  	*/  	public function file($form_name)  	{ -		return $this->variable($form_name, array('name' => 'none'), false, phpbb_request_interface::FILES); +		return $this->variable($form_name, array('name' => 'none'), false, \phpbb\request\request_interface::FILES);  	}  	/** @@ -294,7 +296,7 @@ class phpbb_request implements phpbb_request_interface  	*/  	public function is_set_post($name)  	{ -		return $this->is_set($name, phpbb_request_interface::POST); +		return $this->is_set($name, \phpbb\request\request_interface::POST);  	}  	/** @@ -302,12 +304,12 @@ class phpbb_request implements phpbb_request_interface  	* arrays.  	*  	* @param	string	$var	Name of the variable -	* @param	phpbb_request_interface::POST|GET|REQUEST|COOKIE	$super_global +	* @param	\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE	$super_global  	*							Specifies the super global which shall be checked  	*  	* @return	bool			True if the variable was sent as input  	*/ -	public function is_set($var, $super_global = phpbb_request_interface::REQUEST) +	public function is_set($var, $super_global = \phpbb\request\request_interface::REQUEST)  	{  		return isset($this->input[$super_global][$var]);  	} @@ -335,13 +337,13 @@ class phpbb_request implements phpbb_request_interface  	/**  	* Returns all variable names for a given super global  	* -	* @param	phpbb_request_interface::POST|GET|REQUEST|COOKIE	$super_global +	* @param	\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE	$super_global  	*					The super global from which names shall be taken  	*  	* @return	array	All variable names that are set for the super global.  	*					Pay attention when using these, they are unsanitised!  	*/ -	public function variable_names($super_global = phpbb_request_interface::REQUEST) +	public function variable_names($super_global = \phpbb\request\request_interface::REQUEST)  	{  		if (!isset($this->input[$super_global]))  		{ @@ -362,14 +364,14 @@ class phpbb_request implements phpbb_request_interface  	* 										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	phpbb_request_interface::POST|GET|REQUEST|COOKIE	$super_global +	* @param	\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE	$super_global  	* 										Specifies which super global should be used  	* @param	bool			$trim		Indicates whether trim() should be applied to string values.  	*  	* @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.  	*/ -	protected function _variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST, $trim = true) +	protected function _variable($var_name, $default, $multibyte = false, $super_global = \phpbb\request\request_interface::REQUEST, $trim = true)  	{  		$path = false; @@ -412,4 +414,12 @@ class phpbb_request implements phpbb_request_interface  		return $var;  	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_super_global($super_global = \phpbb\request\request_interface::REQUEST) +	{ +		return $this->input[$super_global]; +	}  } diff --git a/phpBB/phpbb/request/interface.php b/phpBB/phpbb/request/request_interface.php index 741db35917..cd949147f7 100644 --- a/phpBB/phpbb/request/interface.php +++ b/phpBB/phpbb/request/request_interface.php @@ -1,12 +1,14 @@  <?php  /**  * -* @package phpbb_request +* @package \phpbb\request\request  * @copyright (c) 2010 phpBB Group  * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2  *  */ +namespace phpbb\request; +  /**  * @ignore  */ @@ -18,9 +20,9 @@ if (!defined('IN_PHPBB'))  /**  * An interface through which all application input can be accessed.  * -* @package phpbb_request +* @package \phpbb\request\request  */ -interface phpbb_request_interface +interface request_interface  {  	/**#@+  	* Constant identifying the super global with the same name. @@ -43,10 +45,10 @@ interface phpbb_request_interface  	* @param	string	$var_name	The name of the variable that shall be overwritten  	* @param	mixed	$value		The value which the variable shall contain.  	* 								If this is null the variable will be unset. -	* @param	phpbb_request_interface::POST|GET|REQUEST|COOKIE	$super_global +	* @param	\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE	$super_global  	* 								Specifies which super global shall be changed  	*/ -	public function overwrite($var_name, $value, $super_global = phpbb_request_interface::REQUEST); +	public function overwrite($var_name, $value, $super_global = \phpbb\request\request_interface::REQUEST);  	/**  	* Central type safe input handling function. @@ -60,19 +62,19 @@ interface phpbb_request_interface  	* 										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	phpbb_request_interface::POST|GET|REQUEST|COOKIE	$super_global +	* @param	\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE	$super_global  	* 										Specifies which super global should be used  	*  	* @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.  	*/ -	public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST); +	public function variable($var_name, $default, $multibyte = false, $super_global = \phpbb\request\request_interface::REQUEST);  	/**  	* Shortcut method to retrieve SERVER variables.  	* -	* @param	string|array	$var_name		See phpbb_request_interface::variable -	* @param	mixed			$default		See phpbb_request_interface::variable +	* @param	string|array	$var_name		See \phpbb\request\request_interface::variable +	* @param	mixed			$default		See \phpbb\request\request_interface::variable  	*  	* @return	mixed	The server variable value.  	*/ @@ -82,7 +84,7 @@ interface phpbb_request_interface  	* Shortcut method to retrieve the value of client HTTP headers.  	*  	* @param	string|array	$header_name	The name of the header to retrieve. -	* @param	mixed			$default		See phpbb_request_interface::variable +	* @param	mixed			$default		See \phpbb\request\request_interface::variable  	*  	* @return	mixed	The header value.  	*/ @@ -105,12 +107,12 @@ interface phpbb_request_interface  	* arrays.  	*  	* @param	string	$var	Name of the variable -	* @param	phpbb_request_interface::POST|GET|REQUEST|COOKIE	$super_global +	* @param	\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE	$super_global  	*							Specifies the super global which shall be checked  	*  	* @return	bool			True if the variable was sent as input  	*/ -	public function is_set($var, $super_global = phpbb_request_interface::REQUEST); +	public function is_set($var, $super_global = \phpbb\request\request_interface::REQUEST);  	/**  	* Checks whether the current request is an AJAX request (XMLHttpRequest) @@ -129,11 +131,21 @@ interface phpbb_request_interface  	/**  	* Returns all variable names for a given super global  	* -	* @param	phpbb_request_interface::POST|GET|REQUEST|COOKIE	$super_global +	* @param	\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE	$super_global  	*					The super global from which names shall be taken  	*  	* @return	array	All variable names that are set for the super global.  	*					Pay attention when using these, they are unsanitised!  	*/ -	public function variable_names($super_global = phpbb_request_interface::REQUEST); +	public function variable_names($super_global = \phpbb\request\request_interface::REQUEST); + +	/** +	* Returns the original array of the requested super global +	* +	* @param	\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE	$super_global +	*					The super global which will be returned +	* +	* @return	array	The original array of the requested super global. +	*/ +	public function get_super_global($super_global = \phpbb\request\request_interface::REQUEST);  } diff --git a/phpBB/phpbb/request/type_cast_helper.php b/phpBB/phpbb/request/type_cast_helper.php index 1a5274ed14..262aff73c1 100644 --- a/phpBB/phpbb/request/type_cast_helper.php +++ b/phpBB/phpbb/request/type_cast_helper.php @@ -1,12 +1,14 @@  <?php  /**  * -* @package phpbb_request +* @package \phpbb\request\request  * @copyright (c) 2010 phpBB Group  * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2  *  */ +namespace phpbb\request; +  /**  * @ignore  */ @@ -18,9 +20,9 @@ if (!defined('IN_PHPBB'))  /**  * A helper class that provides convenience methods for type casting.  * -* @package phpbb_request +* @package \phpbb\request\request  */ -class phpbb_request_type_cast_helper implements phpbb_request_type_cast_helper_interface +class type_cast_helper implements \phpbb\request\type_cast_helper_interface  {  	/** diff --git a/phpBB/phpbb/request/type_cast_helper_interface.php b/phpBB/phpbb/request/type_cast_helper_interface.php index 3920d16fc7..e8195c352e 100644 --- a/phpBB/phpbb/request/type_cast_helper_interface.php +++ b/phpBB/phpbb/request/type_cast_helper_interface.php @@ -1,12 +1,14 @@  <?php  /**  * -* @package phpbb_request +* @package \phpbb\request\request  * @copyright (c) 2010 phpBB Group  * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2  *  */ +namespace phpbb\request; +  /**  * @ignore  */ @@ -18,9 +20,9 @@ if (!defined('IN_PHPBB'))  /**  * An interface for type cast operations.  * -* @package phpbb_request +* @package \phpbb\request\request  */ -interface phpbb_request_type_cast_helper_interface +interface type_cast_helper_interface  {  	/**  	* Recursively applies addslashes to a variable. diff --git a/phpBB/phpbb/search/base.php b/phpBB/phpbb/search/base.php index 914cef9167..f2f982c31b 100644 --- a/phpBB/phpbb/search/base.php +++ b/phpBB/phpbb/search/base.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\search; +  /**  * @ignore  */ @@ -23,12 +25,12 @@ define('SEARCH_RESULT_IN_CACHE', 1);  define('SEARCH_RESULT_INCOMPLETE', 2);  /** -* phpbb_search_base +* \phpbb\search\base  * optional base class for search plugins providing simple caching based on ACM  * and functions to retrieve ignore_words and synonyms  * @package search  */ -class phpbb_search_base +class base  {  	var $ignore_words = array();  	var $match_synonym = array(); diff --git a/phpBB/phpbb/search/fulltext_mysql.php b/phpBB/phpbb/search/fulltext_mysql.php index a1e1b089b9..50d2d2577f 100644 --- a/phpBB/phpbb/search/fulltext_mysql.php +++ b/phpBB/phpbb/search/fulltext_mysql.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\search; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  * Fulltext search for MySQL  * @package search  */ -class phpbb_search_fulltext_mysql extends phpbb_search_base +class fulltext_mysql extends \phpbb\search\base  {  	/**  	 * Associative array holding index stats @@ -36,19 +38,19 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base  	/**  	 * Config object -	 * @var phpbb_config +	 * @var \phpbb\config\config  	 */  	protected $config; -	 +  	/**  	 * Database connection -	 * @var phpbb_db_driver +	 * @var \phpbb\db\driver\driver  	 */  	protected $db; -	 +  	/**  	 * User object -	 * @var phpbb_user +	 * @var \phpbb\user  	 */  	protected $user; @@ -74,7 +76,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base  	/**  	 * Constructor -	 * Creates a new phpbb_search_fulltext_mysql, which is used as a search backend +	 * Creates a new \phpbb\search\fulltext_mysql, which is used as a search backend  	 *  	 * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false  	 */ diff --git a/phpBB/phpbb/search/fulltext_native.php b/phpBB/phpbb/search/fulltext_native.php index 730c3a6c2d..33326f2882 100644 --- a/phpBB/phpbb/search/fulltext_native.php +++ b/phpBB/phpbb/search/fulltext_native.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\search; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  * phpBB's own db driven fulltext search, version 2  * @package search  */ -class phpbb_search_fulltext_native extends phpbb_search_base +class fulltext_native extends \phpbb\search\base  {  	/**  	 * Associative array holding index stats @@ -80,19 +82,19 @@ class phpbb_search_fulltext_native extends phpbb_search_base  	/**  	 * Config object -	 * @var phpbb_config +	 * @var \phpbb\config\config  	 */  	protected $config;  	/**  	 * Database connection -	 * @var phpbb_db_driver +	 * @var \phpbb\db\driver\driver  	 */  	protected $db;  	/**  	 * User object -	 * @var phpbb_user +	 * @var \phpbb\user  	 */  	protected $user; @@ -1556,7 +1558,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base  	* @param	string	$encoding		Text encoding  	* @return	string					Cleaned up text, only alphanumeric chars are left  	* -	* @todo normalizer::cleanup being able to be used? +	* @todo \normalizer::cleanup being able to be used?  	*/  	protected function cleanup($text, $allowed_chars = null, $encoding = 'utf-8')  	{ @@ -1588,7 +1590,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base  		* If we use it more widely, an instance of that class should be held in a  		* a global variable instead  		*/ -		utf_normalizer::nfc($text); +		\utf_normalizer::nfc($text);  		/**  		* The first thing we do is: diff --git a/phpBB/phpbb/search/fulltext_postgres.php b/phpBB/phpbb/search/fulltext_postgres.php index 6b4b310f2e..756034103e 100644 --- a/phpBB/phpbb/search/fulltext_postgres.php +++ b/phpBB/phpbb/search/fulltext_postgres.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\search; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  * Fulltext search for PostgreSQL  * @package search  */ -class phpbb_search_fulltext_postgres extends phpbb_search_base +class fulltext_postgres extends \phpbb\search\base  {  	/**  	 * Associative array holding index stats @@ -61,19 +63,19 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base  	/**  	 * Config object -	 * @var phpbb_config +	 * @var \phpbb\config\config  	 */  	protected $config;  	/**  	 * Database connection -	 * @var phpbb_db_driver +	 * @var \phpbb\db\driver\driver  	 */  	protected $db;  	/**  	 * User object -	 * @var phpbb_user +	 * @var \phpbb\user  	 */  	protected $user; @@ -99,7 +101,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base  	/**  	 * Constructor -	 * Creates a new phpbb_search_fulltext_postgres, which is used as a search backend +	 * Creates a new \phpbb\search\fulltext_postgres, which is used as a search backend  	 *  	 * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false  	 */ diff --git a/phpBB/phpbb/search/fulltext_sphinx.php b/phpBB/phpbb/search/fulltext_sphinx.php index 4f3f852664..cb76d58f49 100644 --- a/phpBB/phpbb/search/fulltext_sphinx.php +++ b/phpBB/phpbb/search/fulltext_sphinx.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\search; +  /**  */  if (!defined('IN_PHPBB')) @@ -26,7 +28,7 @@ define('SPHINX_CONNECT_WAIT_TIME', 300);  * Fulltext search based on the sphinx search deamon  * @package search  */ -class phpbb_search_fulltext_sphinx +class fulltext_sphinx  {  	/**  	 * Associative array holding index stats @@ -73,25 +75,25 @@ class phpbb_search_fulltext_sphinx  	/**  	 * Auth object -	 * @var phpbb_auth +	 * @var \phpbb\auth\auth  	 */  	protected $auth;  	/**  	 * Config object -	 * @var phpbb_config +	 * @var \phpbb\config\config  	 */  	protected $config;  	/**  	 * Database connection -	 * @var phpbb_db_driver +	 * @var \phpbb\db\driver\driver  	 */  	protected $db;  	/**  	 * Database Tools object -	 * @var phpbb_db_tools +	 * @var \phpbb\db\tools  	 */  	protected $db_tools; @@ -103,7 +105,7 @@ class phpbb_search_fulltext_sphinx  	/**  	 * User object -	 * @var phpbb_user +	 * @var \phpbb\user  	 */  	protected $user; @@ -122,7 +124,7 @@ class phpbb_search_fulltext_sphinx  	/**  	 * Constructor -	 * Creates a new phpbb_search_fulltext_postgres, which is used as a search backend +	 * Creates a new \phpbb\search\fulltext_postgres, which is used as a search backend  	 *  	 * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false  	 */ @@ -135,8 +137,8 @@ class phpbb_search_fulltext_sphinx  		$this->db = $db;  		$this->auth = $auth; -		// Initialize phpbb_db_tools object -		$this->db_tools = new phpbb_db_tools($this->db); +		// Initialize \phpbb\db\tools object +		$this->db_tools = new \phpbb\db\tools($this->db);  		if(!$this->config['fulltext_sphinx_id'])  		{ @@ -151,7 +153,7 @@ class phpbb_search_fulltext_sphinx  		}  		// Initialize sphinx client -		$this->sphinx = new SphinxClient(); +		$this->sphinx = new \SphinxClient();  		$this->sphinx->SetServer(($this->config['fulltext_sphinx_host'] ? $this->config['fulltext_sphinx_host'] : 'localhost'), ($this->config['fulltext_sphinx_port'] ? (int) $this->config['fulltext_sphinx_port'] : 9312)); @@ -250,7 +252,7 @@ class phpbb_search_fulltext_sphinx  		/* Now that we're sure everything was entered correctly,  		generate a config for the index. We use a config value  		fulltext_sphinx_id for this, as it should be unique. */ -		$config_object = new phpbb_search_sphinx_config($this->config_file_data); +		$config_object = new \phpbb\search\sphinx\config($this->config_file_data);  		$config_data = array(  			'source source_phpbb_' . $this->id . '_main' => array(  				array('type',						$this->dbtype . ' # mysql or pgsql'), diff --git a/phpBB/phpbb/search/sphinx/config.php b/phpBB/phpbb/search/sphinx/config.php index f1864f0c8c..262d6008cc 100644 --- a/phpBB/phpbb/search/sphinx/config.php +++ b/phpBB/phpbb/search/sphinx/config.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\search\sphinx; +  /**  * @ignore  */ @@ -16,12 +18,12 @@ if (!defined('IN_PHPBB'))  }  /** -* phpbb_search_sphinx_config +* \phpbb\search\sphinx\config  * An object representing the sphinx configuration  * Can read it from file and write it back out after modification  * @package search  */ -class phpbb_search_sphinx_config +class config  {  	private $sections = array(); @@ -44,7 +46,7 @@ class phpbb_search_sphinx_config  	* Get a section object by its name  	*  	* @param	string 								$name	The name of the section that shall be returned -	* @return	phpbb_search_sphinx_config_section			The section object or null if none was found +	* @return	\phpbb\search\sphinx\config_section			The section object or null if none was found  	*  	* @access	public  	*/ @@ -53,7 +55,7 @@ class phpbb_search_sphinx_config  		for ($i = 0, $size = sizeof($this->sections); $i < $size; $i++)  		{  			// Make sure this is really a section object and not a comment -			if (($this->sections[$i] instanceof phpbb_search_sphinx_config_section) && $this->sections[$i]->get_name() == $name) +			if (($this->sections[$i] instanceof \phpbb\search\sphinx\config_section) && $this->sections[$i]->get_name() == $name)  			{  				return $this->sections[$i];  			} @@ -64,13 +66,13 @@ class phpbb_search_sphinx_config  	* Appends a new empty section to the end of the config  	*  	* @param	string								$name	The name for the new section -	* @return	phpbb_search_sphinx_config_section			The newly created section object +	* @return	\phpbb\search\sphinx\config_section			The newly created section object  	*  	* @access	public  	*/  	function add_section($name)  	{ -		$this->sections[] = new phpbb_search_sphinx_config_section($name, ''); +		$this->sections[] = new \phpbb\search\sphinx\config_section($name, '');  		return $this->sections[sizeof($this->sections) - 1];  	} @@ -109,7 +111,7 @@ class phpbb_search_sphinx_config  				// that way they're not deleted when reassembling the file from the sections  				if (!$line || $line[0] == '#')  				{ -					$this->sections[] = new phpbb_search_sphinx_config_comment($config_file[$i]); +					$this->sections[] = new \phpbb\search\sphinx\config_comment($config_file[$i]);  					continue;  				}  				else @@ -143,7 +145,7 @@ class phpbb_search_sphinx_config  					// And then we create the new section object  					$section_name = trim($section_name); -					$section = new phpbb_search_sphinx_config_section($section_name, $section_name_comment); +					$section = new \phpbb\search\sphinx\config_section($section_name, $section_name_comment);  				}  			}  			else @@ -158,10 +160,10 @@ class phpbb_search_sphinx_config  					// of this section so they're not deleted on reassembly  					if (!$line || $line[0] == '#')  					{ -						$section->add_variable(new phpbb_search_sphinx_config_comment($config_file[$i])); +						$section->add_variable(new \phpbb\search\sphinx\config_comment($config_file[$i]));  						continue;  					} -	 +  					// As long as we haven't yet actually found an opening bracket for this section  					// we treat everything as comments so it's not deleted either  					if (!$found_opening_bracket) @@ -174,13 +176,13 @@ class phpbb_search_sphinx_config  						}  						else  						{ -							$section->add_variable(new phpbb_search_sphinx_config_comment($config_file[$i])); +							$section->add_variable(new \phpbb\search\sphinx\config_comment($config_file[$i]));  							continue;  						}  					}  				} -				// If we did not find a comment in this line or still add to the previous  +				// If we did not find a comment in this line or still add to the previous  				// line's value ...  				if ($line || $in_value)  				{ @@ -239,16 +241,16 @@ class phpbb_search_sphinx_config  						}  					} -					// If a name and an equal sign were found then we have append a  +					// If a name and an equal sign were found then we have append a  					// new variable object to the section  					if ($name && $found_assignment)  					{ -						$section->add_variable(new phpbb_search_sphinx_config_variable(trim($name), trim($value), ($end_section) ? '' : $comment)); +						$section->add_variable(new \phpbb\search\sphinx\config_variable(trim($name), trim($value), ($end_section) ? '' : $comment));  						continue;  					}  					/* If we found a closing curly bracket this section has been completed -					and we can append it to the section list and continue with looking for  +					and we can append it to the section list and continue with looking for  					the next section */  					if ($end_section)  					{ @@ -262,7 +264,7 @@ class phpbb_search_sphinx_config  				// If we did not find anything meaningful up to here, then just treat it  				// as a comment  				$comment = ($skip_first) ? "\t" . substr(ltrim($config_file[$i]), 1) : $config_file[$i]; -				$section->add_variable(new phpbb_search_sphinx_config_comment($comment)); +				$section->add_variable(new \phpbb\search\sphinx\config_comment($comment));  			}  		} diff --git a/phpBB/phpbb/search/sphinx/config_comment.php b/phpBB/phpbb/search/sphinx/config_comment.php index 7f695dbf0c..77a943377d 100644 --- a/phpBB/phpbb/search/sphinx/config_comment.php +++ b/phpBB/phpbb/search/sphinx/config_comment.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\search\sphinx; +  /**  * @ignore  */ @@ -16,10 +18,10 @@ if (!defined('IN_PHPBB'))  }  /** -* phpbb_search_sphinx_config_comment +* \phpbb\search\sphinx\config_comment  * Represents a comment inside the sphinx configuration  */ -class phpbb_search_sphinx_config_comment +class config_comment  {  	private $exact_string; diff --git a/phpBB/phpbb/search/sphinx/config_section.php b/phpBB/phpbb/search/sphinx/config_section.php index 79c9c8563d..730abf011e 100644 --- a/phpBB/phpbb/search/sphinx/config_section.php +++ b/phpBB/phpbb/search/sphinx/config_section.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\search\sphinx; +  /**  * @ignore  */ @@ -16,10 +18,10 @@ if (!defined('IN_PHPBB'))  }  /** -* phpbb_search_sphinx_config_section +* \phpbb\search\sphinx\config_section  * Represents a single section inside the sphinx configuration  */ -class phpbb_search_sphinx_config_section +class config_section  {  	private $name;  	private $comment; @@ -45,7 +47,7 @@ class phpbb_search_sphinx_config_section  	/**  	* Add a variable object to the list of variables in this section  	* -	* @param	phpbb_search_sphinx_config_variable	$variable	The variable object +	* @param	\phpbb\search\sphinx\config_variable	$variable	The variable object  	*  	* @access	public  	*/ @@ -82,7 +84,7 @@ class phpbb_search_sphinx_config_section  	* Get a variable object by its name  	*  	* @param	string 								$name	The name of the variable that shall be returned -	* @return	phpbb_search_sphinx_config_section			The first variable object from this section with the +	* @return	\phpbb\search\sphinx\config_section			The first variable object from this section with the  	*														given name or null if none was found  	*  	* @access	public @@ -92,7 +94,7 @@ class phpbb_search_sphinx_config_section  		for ($i = 0, $size = sizeof($this->variables); $i < $size; $i++)  		{  			// Make sure this is a variable object and not a comment -			if (($this->variables[$i] instanceof phpbb_search_sphinx_config_variable) && $this->variables[$i]->get_name() == $name) +			if (($this->variables[$i] instanceof \phpbb\search\sphinx\config_variable) && $this->variables[$i]->get_name() == $name)  			{  				return $this->variables[$i];  			} @@ -111,7 +113,7 @@ class phpbb_search_sphinx_config_section  		for ($i = 0, $size = sizeof($this->variables); $i < $size; $i++)  		{  			// Make sure this is a variable object and not a comment -			if (($this->variables[$i] instanceof phpbb_search_sphinx_config_variable) && $this->variables[$i]->get_name() == $name) +			if (($this->variables[$i] instanceof \phpbb\search\sphinx\config_variable) && $this->variables[$i]->get_name() == $name)  			{  				array_splice($this->variables, $i, 1);  				$i--; @@ -124,13 +126,13 @@ class phpbb_search_sphinx_config_section  	*  	* @param	string								$name	The name for the new variable  	* @param	string								$value	The value for the new variable -	* @return	phpbb_search_sphinx_config_variable			Variable object that was created +	* @return	\phpbb\search\sphinx\config_variable			Variable object that was created  	*  	* @access	public  	*/  	function create_variable($name, $value)  	{ -		$this->variables[] = new phpbb_search_sphinx_config_variable($name, $value, ''); +		$this->variables[] = new \phpbb\search\sphinx\config_variable($name, $value, '');  		return $this->variables[sizeof($this->variables) - 1];  	} diff --git a/phpBB/phpbb/search/sphinx/config_variable.php b/phpBB/phpbb/search/sphinx/config_variable.php index 2c1d35a49c..c8f40bfb5f 100644 --- a/phpBB/phpbb/search/sphinx/config_variable.php +++ b/phpBB/phpbb/search/sphinx/config_variable.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\search\sphinx; +  /**  * @ignore  */ @@ -16,10 +18,10 @@ if (!defined('IN_PHPBB'))  }  /** -* phpbb_search_sphinx_config_variable +* \phpbb\search\sphinx\config_variable  * Represents a single variable inside the sphinx configuration  */ -class phpbb_search_sphinx_config_variable +class config_variable  {  	private $name;  	private $value; diff --git a/phpBB/phpbb/session.php b/phpBB/phpbb/session.php index e0585b1523..5e4380bfc8 100644 --- a/phpBB/phpbb/session.php +++ b/phpBB/phpbb/session.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb; +  /**  * @ignore  */ @@ -19,7 +21,7 @@ if (!defined('IN_PHPBB'))  * Session class  * @package phpBB3  */ -class phpbb_session +class session  {  	var $cookie_data = array();  	var $page = array(); @@ -40,13 +42,13 @@ class phpbb_session  	*/  	static function extract_current_page($root_path)  	{ -		global $request; +		global $request, $symfony_request, $phpbb_filesystem;  		$page_array = array();  		// First of all, get the request uri... -		$script_name = htmlspecialchars_decode($request->server('PHP_SELF')); -		$args = explode('&', htmlspecialchars_decode($request->server('QUERY_STRING'))); +		$script_name = $symfony_request->getScriptName(); +		$args = explode('&', $symfony_request->getQueryString());  		// If we are unable to get the script name we use REQUEST_URI as a failover and note it within the page array for easier support...  		if (!$script_name) @@ -87,6 +89,12 @@ class phpbb_session  		$page_name = (substr($script_name, -1, 1) == '/') ? '' : basename($script_name);  		$page_name = urlencode(htmlspecialchars($page_name)); +		$symfony_request_path = $phpbb_filesystem->clean_path($symfony_request->getPathInfo()); +		if ($symfony_request_path !== '/') +		{ +			$page_name .= $symfony_request_path; +		} +  		// current directory within the phpBB root (for example: adm)  		$root_dirs = explode('/', str_replace('\\', '/', phpbb_realpath($root_path)));  		$page_dirs = explode('/', str_replace('\\', '/', phpbb_realpath('./'))); @@ -103,10 +111,14 @@ class phpbb_session  		}  		// Current page from phpBB root (for example: adm/index.php?i=10&b=2) -		$page = (($page_dir) ? $page_dir . '/' : '') . $page_name . (($query_string) ? "?$query_string" : ''); +		$page = (($page_dir) ? $page_dir . '/' : '') . $page_name; +		if ($query_string) +		{ +			$page .= '?' . $query_string; +		}  		// The script path from the webroot to the current directory (for example: /phpBB3/adm/) : always prefixed with / and ends in / -		$script_path = trim(str_replace('\\', '/', dirname($script_name))); +		$script_path = $symfony_request->getBasePath();  		// The script path from the webroot to the phpBB root (for example: /phpBB3/)  		$script_dirs = explode('/', $script_path); @@ -243,7 +255,7 @@ class phpbb_session  			$this->forwarded_for = '';  		} -		if ($request->is_set($config['cookie_name'] . '_sid', phpbb_request_interface::COOKIE) || $request->is_set($config['cookie_name'] . '_u', phpbb_request_interface::COOKIE)) +		if ($request->is_set($config['cookie_name'] . '_sid', \phpbb\request\request_interface::COOKIE) || $request->is_set($config['cookie_name'] . '_u', \phpbb\request\request_interface::COOKIE))  		{  			$this->cookie_data['u'] = request_var($config['cookie_name'] . '_u', 0, false, true);  			$this->cookie_data['k'] = request_var($config['cookie_name'] . '_k', '', false, true); @@ -405,9 +417,9 @@ class phpbb_session  					$provider = $phpbb_container->get('auth.provider.' . $method); -					if (!($provider instanceof phpbb_auth_provider_interface)) +					if (!($provider instanceof \phpbb\auth\provider\provider_interface))  					{ -						throw new \RuntimeException($provider . ' must implement phpbb_auth_provider_interface'); +						throw new \RuntimeException($provider . ' must implement \phpbb\auth\provider\provider_interface');  					}  					$ret = $provider->validate_session($this->data); @@ -1022,7 +1034,8 @@ class phpbb_session  			{  				include($phpbb_root_path . "includes/captcha/captcha_factory." . $phpEx);  			} -			phpbb_captcha_factory::garbage_collect($config['captcha_plugin']); +			$captcha_factory = new \phpbb_captcha_factory(); +			$captcha_factory->garbage_collect($config['captcha_plugin']);  			$sql = 'DELETE FROM ' . LOGIN_ATTEMPT_TABLE . '  				WHERE attempt_time < ' . (time() - (int) $config['ip_login_limit_time']); diff --git a/phpBB/phpbb/style/extension_path_provider.php b/phpBB/phpbb/style/extension_path_provider.php deleted file mode 100644 index ec1d85f821..0000000000 --- a/phpBB/phpbb/style/extension_path_provider.php +++ /dev/null @@ -1,137 +0,0 @@ -<?php -/** -* -* @package phpBB3 -* @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ - -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ -	exit; -} - -/** -* Provides a style resource locator with core style paths and extension style paths -* -* Finds installed style paths and makes them available to the resource locator. -* -* @package phpBB3 -*/ -class phpbb_style_extension_path_provider extends phpbb_extension_provider implements phpbb_style_path_provider_interface -{ -	/** -	* Optional prefix for style paths searched within extensions. -	* -	* Empty by default. Relative to the extension directory. As an example, it -	* could be adm/ for admin style. -	* -	* @var string -	*/ -	protected $ext_dir_prefix = ''; - -	/** -	* A provider of paths to be searched for styles -	* @var phpbb_style_path_provider -	*/ -	protected $base_path_provider; - -	/** @var string */ -	protected $phpbb_root_path; - -	/** -	* Constructor stores extension manager -	* -	* @param phpbb_extension_manager $extension_manager phpBB extension manager -	* @param phpbb_style_path_provider $base_path_provider A simple path provider -	*            to provide paths to be located in extensions -	* @param string		$phpbb_root_path	phpBB root path -	*/ -	public function __construct(phpbb_extension_manager $extension_manager, phpbb_style_path_provider $base_path_provider, $phpbb_root_path) -	{ -		parent::__construct($extension_manager); -		$this->base_path_provider = $base_path_provider; -		$this->phpbb_root_path = $phpbb_root_path; -	} - -	/** -	* Sets a prefix for style paths searched within extensions. -	* -	* The prefix is inserted between the extension's path e.g. ext/foo/ and -	* the looked up style path, e.g. styles/bar/. So it should not have a -	* leading slash, but should have a trailing slash. -	* -	* @param string $ext_dir_prefix The prefix including trailing slash -	* @return null -	*/ -	public function set_ext_dir_prefix($ext_dir_prefix) -	{ -		$this->ext_dir_prefix = $ext_dir_prefix; -	} - -	/** -	* Finds style paths using the extension manager -	* -	* Locates a path (e.g. styles/prosilver/) in all active extensions. -	* Then appends the core style paths based in the current working -	* directory. -	* -	* @return array     List of style paths -	*/ -	public function find() -	{ -		$directories = array(); - -		$finder = $this->extension_manager->get_finder(); -		foreach ($this->base_path_provider as $key => $paths) -		{ -			if ($key == 'style') -			{ -				foreach ($paths as $path) -				{ -					$directories['style'][] = $path; -					if ($path && !phpbb_is_absolute($path)) -					{ -						// Remove phpBB root path from the style path, -						// so the finder is able to find extension styles, -						// when the root path is not ./ -						if (strpos($path, $this->phpbb_root_path) === 0) -						{ -							$path = substr($path, strlen($this->phpbb_root_path)); -						} - -						$result = $finder->directory('/' . $this->ext_dir_prefix . $path) -							->get_directories(true, false, true); -						foreach ($result as $ext => $ext_path) -						{ -							// Make sure $ext_path has no ending slash -							if (substr($ext_path, -1) === '/') -							{ -								$ext_path = substr($ext_path, 0, -1); -							} -							$directories[$ext][] = $ext_path; -						} -					} -				} -			} -		} - -		return $directories; -	} - -	/** -	* Overwrites the current style paths -	* -	* @param array $styles An array of style paths. The first element is the main style. -	* @return null -	*/ -	public function set_styles(array $styles) -	{ -		$this->base_path_provider->set_styles($styles); -		$this->items = null; -	} -} diff --git a/phpBB/phpbb/style/path_provider.php b/phpBB/phpbb/style/path_provider.php deleted file mode 100644 index 731d682e88..0000000000 --- a/phpBB/phpbb/style/path_provider.php +++ /dev/null @@ -1,62 +0,0 @@ -<?php -/** -* -* @package phpBB3 -* @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ - -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ -	exit; -} - -/** -* Provides a style resource locator with paths -* -* Finds installed style paths and makes them available to the resource locator. -* -* @package phpBB3 -*/ -class phpbb_style_path_provider implements IteratorAggregate, phpbb_style_path_provider_interface -{ -	protected $paths = array(); - -	/** -	* Ignores the extension dir prefix -	* -	* @param string $ext_dir_prefix The prefix including trailing slash -	* @return null -	*/ -	public function set_ext_dir_prefix($ext_dir_prefix) -	{ -	} - -	/** -	* Overwrites the current style paths -	* -	* The first element of the passed styles map, is considered the main -	* style. -	* -	* @param array $styles An array of style paths. The first element is the main style. -	* @return null -	*/ -	public function set_styles(array $styles) -	{ -		$this->paths = array('style' => $styles); -	} - -	/** -	* Retrieve an iterator over all style paths -	* -	* @return ArrayIterator An iterator for the array of style paths -	*/ -	public function getIterator() -	{ -		return new ArrayIterator($this->paths); -	} -} diff --git a/phpBB/phpbb/style/path_provider_interface.php b/phpBB/phpbb/style/path_provider_interface.php deleted file mode 100644 index 1a6153a4d3..0000000000 --- a/phpBB/phpbb/style/path_provider_interface.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php -/** -* -* @package phpBB3 -* @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ - -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ -	exit; -} - -/** -* Provides a style resource locator with paths -* -* Finds installed style paths and makes them available to the resource locator. -* -* @package phpBB3 -*/ -interface phpbb_style_path_provider_interface extends Traversable -{ -	/** -	* Defines a prefix to use for style paths in extensions -	* -	* @param string $ext_dir_prefix The prefix including trailing slash -	* @return null -	*/ -	public function set_ext_dir_prefix($ext_dir_prefix); - -	/** -	* Overwrites the current style paths -	* -	* @param array $styles An array of style paths. The first element is the main style. -	* @return null -	*/ -	public function set_styles(array $styles); -} diff --git a/phpBB/phpbb/style/resource_locator.php b/phpBB/phpbb/style/resource_locator.php deleted file mode 100644 index 4cf767c062..0000000000 --- a/phpBB/phpbb/style/resource_locator.php +++ /dev/null @@ -1,348 +0,0 @@ -<?php -/** -* -* @package phpBB3 -* @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ - -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ -	exit; -} - - -/** -* Style resource locator.  -* Maintains mapping from template handles to source template file paths. -* Locates style files: resources (such as .js and .css files) and templates. -* -* Style resource locator is aware of styles tree, and can return actual -* filesystem paths (i.e., the "child" style or the "parent" styles) -* depending on what files exist. -* -* Root paths stored in locator are paths to style directories. Templates are -* stored in subdirectory that $template_path points to. -* -* @package phpBB3 -*/ -class phpbb_style_resource_locator implements phpbb_template_locator -{ -	/** -	* Paths to style directories. -	* @var array -	*/ -	private $roots = array(); - -	/** -	* Location of templates directory within style directories. -	* Must have trailing slash. Empty if templates are stored in root -	* style directory, such as admin control panel templates. -	* @var string -	*/ -	private $template_path; - -	/** -	* Map from root index to handles to source template file paths. -	* Normally it only contains paths for handles that are used -	* (or are likely to be used) by the page being rendered and not -	* all templates that exist on the filesystem. -	* @var array -	*/ -	private $files = array(); - -	/** -	* Map from handles to source template file names. -	* Covers the same data as $files property but maps to basenames -	* instead of paths. -	* @var array -	*/ -	private $filenames = array(); - -	/** -	* Constructor. -	* -	* Sets default template path to template/. -	*/ -	public function __construct() -	{ -		$this->set_default_template_path(); -	} - -	/** -	* Sets the list of style paths -	* -	* These paths will be searched for style files in the provided order. -	* Paths may be outside of phpBB, but templates loaded from these paths -	* will still be cached. -	* -	* @param array $style_paths An array of paths to style directories -	* @return null -	*/ -	public function set_paths($style_paths) -	{ -		$this->roots = array(); -		$this->files = array(); -		$this->filenames = array(); - -		foreach ($style_paths as $key => $paths) -		{ -			foreach ($paths as $path) -			{ -				// Make sure $path has no ending slash -				if (substr($path, -1) === '/') -				{ -					$path = substr($path, 0, -1); -				} -				$this->roots[$key][] = $path; -			} -		} -	} - -	/** -	* Sets the location of templates directory within style directories. -	* -	* The location must be a relative path, with a trailing slash. -	* Typically it is one directory level deep, e.g. "template/". -	* -	* @param string $template_path Relative path to templates directory within style directories -	* @return null -	*/ -	public function set_template_path($template_path) -	{ -		$this->template_path = $template_path; -	} - -	/** -	* Sets the location of templates directory within style directories -	* to the default, which is "template/". -	* -	* @return null -	*/ -	public function set_default_template_path() -	{ -		$this->template_path = 'template/'; -	} - -	/** -	* {@inheritDoc} -	*/ -	public function set_filenames(array $filename_array) -	{ -		foreach ($filename_array as $handle => $filename) -		{ -			if (empty($filename)) -			{ -				trigger_error("style resource locator: set_filenames: Empty filename specified for $handle", E_USER_ERROR); -			} - -			$this->filename[$handle] = $filename; - -			foreach ($this->roots as $root_key => $root_paths) -			{ -				foreach ($root_paths as $root_index => $root) -				{ -					$this->files[$root_key][$root_index][$handle] = $root . '/' . $this->template_path . $filename; -				} -			} -		} -	} - -	/** -	* {@inheritDoc} -	*/ -	public function get_filename_for_handle($handle) -	{ -		if (!isset($this->filename[$handle])) -		{ -			trigger_error("style resource locator: get_filename_for_handle: No file specified for handle $handle", E_USER_ERROR); -		} -		return $this->filename[$handle]; -	} - -	/** -	* {@inheritDoc} -	*/ -	public function get_virtual_source_file_for_handle($handle) -	{ -		// If we don't have a file assigned to this handle, die. -		if (!isset($this->files['style'][0][$handle])) -		{ -			trigger_error("style resource locator: No file specified for handle $handle", E_USER_ERROR); -		} - -		$source_file = $this->files['style'][0][$handle]; -		return $source_file; -	} - -	/** -	* {@inheritDoc} -	*/ -	public function get_source_file_for_handle($handle, $find_all = false) -	{ -		// If we don't have a file assigned to this handle, die. -		if (!isset($this->files['style'][0][$handle])) -		{ -			trigger_error("style resource locator: No file specified for handle $handle", E_USER_ERROR); -		} - -		// locate a source file that exists -		$source_file = $this->files['style'][0][$handle]; -		$tried = $source_file; -		$found = false; -		$found_all = array(); -		foreach ($this->roots as $root_key => $root_paths) -		{ -			foreach ($root_paths as $root_index => $root) -			{ -				$source_file = $this->files[$root_key][$root_index][$handle]; -				$tried .= ', ' . $source_file; -				if (file_exists($source_file)) -				{ -					$found = true; -					break; -				} -			} -			if ($found) -			{ -				if ($find_all) -				{ -					$found_all[] = $source_file; -					$found = false; -				} -				else -				{ -					break; -				} -			} -		} - -		// search failed -		if (!$found && !$find_all) -		{ -			trigger_error("style resource locator: File for handle $handle does not exist. Could not find: $tried", E_USER_ERROR); -		} - -		return ($find_all) ? $found_all : $source_file; -	} - -	/** -	* {@inheritDoc} -	*/ -	public function get_first_file_location($files, $return_default = false, $return_full_path = true) -	{ -		// set default value -		$default_result = false; - -		// check all available paths -		foreach ($this->roots as $root_paths) -		{ -			foreach ($root_paths as $path) -			{ -				// check all files -				foreach ($files as $filename) -				{ -					$source_file = $path . '/' . $filename; -					if (file_exists($source_file)) -					{ -						return ($return_full_path) ? $source_file : $filename; -					} - -					// assign first file as result if $return_default is true -					if ($return_default && $default_result === false) -					{ -						$default_result = $source_file; -					} -				} -			} -		} - -		// search failed -		return $default_result; -	} - -	/** -	* Obtains filesystem path for a template file. -	* -	* The simplest use is specifying a single template file as a string -	* in the first argument. This template file should be a basename -	* of a template file in the selected style, or its parent styles -	* if template inheritance is being utilized. -	* -	* Note: "selected style" is whatever style the style resource locator -	* is configured for. -	* -	* The return value then will be a path, relative to the current -	* directory or absolute, to the template file in the selected style -	* or its closest parent. -	* -	* If the selected style does not have the template file being searched, -	* (and if inheritance is involved, none of the parents have it either), -	* false will be returned. -	* -	* Specifying true for $return_default will cause the function to -	* return the first path which was checked for existence in the event -	* that the template file was not found, instead of false. -	* This is the path in the selected style itself, not any of its -	* parents. -	* -	* $files can be given an array of templates instead of a single -	* template. When given an array, the function will try to resolve -	* each template in the array to a path, and will return the first -	* path that exists, or false if none exist. -	* -	* If $files is an array and template inheritance is involved, first -	* each of the files will be checked in the selected style, then each -	* of the files will be checked in the immediate parent, and so on. -	* -	* If $return_full_path is false, then instead of returning a usable -	* path (when the template is found) only the template's basename -	* will be returned. This can be used to check which of the templates -	* specified in $files exists. Naturally more than one template must -	* be given in $files. -	* -	* This function works identically to get_first_file_location except -	* it operates on a list of templates, not files. Practically speaking, -	* the templates given in the first argument first are prepended with -	* the template path (property in this class), then given to -	* get_first_file_location for the rest of the processing. -	* -	* Templates given to this function can be relative paths for templates -	* located in subdirectories of the template directories. The paths -	* should be relative to the templates directory (template/ by default). -	* -	* @param string or array $files List of templates to locate. If there is only -	*				one template, $files can be a string to make code easier to read. -	* @param bool $return_default Determines what to return if template does not -	*				exist. If true, function will return location where template is -	*				supposed to be. If false, function will return false. -	* @param bool $return_full_path If true, function will return full path -	*				to template. If false, function will return template file name. -	*				This parameter can be used to check which one of set of template -	*				files is available. -	* @return string or boolean Source template path if template exists or $return_default is -	*				true. False if template does not exist and $return_default is false -	*/ -	public function get_first_template_location($templates, $return_default = false, $return_full_path = true) -	{ -		// add template path prefix -		$files = array(); -		if (is_string($templates)) -		{ -			$files[] = $this->template_path . $templates; -		} -		else -		{ -			foreach ($templates as $template) -			{ -				$files[] = $this->template_path . $template; -			} -		} - -		return $this->get_first_file_location($files, $return_default, $return_full_path); -	} -} diff --git a/phpBB/phpbb/style/style.php b/phpBB/phpbb/style/style.php deleted file mode 100644 index 034f518091..0000000000 --- a/phpBB/phpbb/style/style.php +++ /dev/null @@ -1,241 +0,0 @@ -<?php -/** -* -* @package phpBB3 -* @copyright (c) 2005 phpBB Group, sections (c) 2001 ispi of Lincoln Inc -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ - -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ -	exit; -} - -/** -* Base Style class. -* @package phpBB3 -*/ -class phpbb_style -{ -	/** -	* Template class. -	* Handles everything related to templates. -	* @var phpbb_template -	*/ -	private $template; - -	/** -	* phpBB root path -	* @var string -	*/ -	private $phpbb_root_path; - -	/** -	* PHP file extension -	* @var string -	*/ -	private $php_ext; - -	/** -	* phpBB config instance -	* @var phpbb_config -	*/ -	private $config; - -	/** -	* Current user -	* @var phpbb_user -	*/ -	private $user; - -	/** -	* Style resource locator -	* @var phpbb_style_resource_locator -	*/ -	private $locator; - -	/** -	* Style path provider -	* @var phpbb_style_path_provider -	*/ -	private $provider; - -	/** -	* Constructor. -	* -	* @param string $phpbb_root_path phpBB root path -	* @param user $user current user -	* @param phpbb_style_resource_locator $locator style resource locator -	* @param phpbb_style_path_provider $provider style path provider -	* @param phpbb_template $template template -	*/ -	public function __construct($phpbb_root_path, $php_ext, $config, $user, phpbb_style_resource_locator $locator, phpbb_style_path_provider_interface $provider, phpbb_template $template) -	{ -		$this->phpbb_root_path = $phpbb_root_path; -		$this->php_ext = $php_ext; -		$this->config = $config; -		$this->user = $user; -		$this->locator = $locator; -		$this->provider = $provider; -		$this->template = $template; -	} - -	/** -	* Get the style tree of the style preferred by the current user -	* -	* @return array Style tree, most specific first -	*/ -	public function get_user_style() -	{ -		$style_list = array( -			$this->user->style['style_path'], -		); - -		if ($this->user->style['style_parent_id']) -		{ -			$style_list = array_merge($style_list, array_reverse(explode('/', $this->user->style['style_parent_tree']))); -		} - -		return $style_list; -	} - -	/** -	* Set style location based on (current) user's chosen style. -	* -	* @param array $style_directories The directories to add style paths for -	* 	E.g. array('ext/foo/bar/styles', 'styles') -	* 	Default: array('styles') (phpBB's style directory) -	* @return bool true -	*/ -	public function set_style($style_directories = array('styles')) -	{ -		$this->names = $this->get_user_style(); - -		$paths = array(); -		foreach ($style_directories as $directory) -		{ -			foreach ($this->names as $name) -			{ -				$path = $this->get_style_path($name, $directory); - -				if (is_dir($path)) -				{ -					$paths[] = $path; -				} -			} -		} - -		$this->provider->set_styles($paths); -		$this->locator->set_paths($this->provider); - -		$new_paths = array(); -		foreach ($paths as $path) -		{ -			$new_paths[] = $path . '/template/'; -		} - -		$this->template->set_style_names($this->names, $new_paths, ($style_directories === array('styles'))); - -		return true; -	} - -	/** -	* Set custom style location (able to use directory outside of phpBB). -	* -	* Note: Templates are still compiled to phpBB's cache directory. -	* -	* @param string $name Name of style, used for cache prefix. Examples: "admin", "prosilver" -	* @param array or string $paths Array of style paths, relative to current root directory -	* @param array $names Array of names of templates in inheritance tree order, used by extensions. If empty, $name will be used. -	* @param string $template_path Path to templates, relative to style directory. False if path should be set to default (templates/). -	* @return bool true -	*/ -	public function set_custom_style($name, $paths, $names = array(), $template_path = false) -	{ -		if (is_string($paths)) -		{ -			$paths = array($paths); -		} - -		if (empty($names)) -		{ -			$names = array($name); -		} -		$this->names = $names; - -		$this->provider->set_styles($paths); -		$this->locator->set_paths($this->provider); - -		if ($template_path !== false) -		{ -			$this->locator->set_template_path($template_path); -		} - -		$new_paths = array(); -		foreach ($paths as $path) -		{ -			$new_paths[] = $path . '/' . (($template_path !== false) ? $template_path : 'template/'); -		} - -		$this->template->set_style_names($names, $new_paths); - -		return true; -	} - -	/** -	* Get location of style directory for specific style_path -	* -	* @param string $path Style path, such as "prosilver" -	* @param string $style_base_directory The base directory the style is in -	* 	E.g. 'styles', 'ext/foo/bar/styles' -	* 	Default: 'styles' -	* @return string Path to style directory, relative to current path -	*/ -	public function get_style_path($path, $style_base_directory = 'styles') -	{ -		return $this->phpbb_root_path . trim($style_base_directory, '/') . '/' . $path; -	} - -	/** -	* Defines a prefix to use for style paths in extensions -	* -	* @param string $ext_dir_prefix The prefix including trailing slash -	* @return null -	*/ -	public function set_ext_dir_prefix($ext_dir_prefix) -	{ -		$this->provider->set_ext_dir_prefix($ext_dir_prefix); -	} - -	/** -	* Locates source file path, accounting for styles tree and verifying that -	* the path exists. -	* -	* @param string or array $files List of files to locate. If there is only -	*				one file, $files can be a string to make code easier to read. -	* @param bool $return_default Determines what to return if file does not -	*				exist. If true, function will return location where file is -	*				supposed to be. If false, function will return false. -	* @param bool $return_full_path If true, function will return full path -	*				to file. If false, function will return file name. This -	*				parameter can be used to check which one of set of files -	*				is available. -	* @return string or boolean Source file path if file exists or $return_default is -	*				true. False if file does not exist and $return_default is false -	*/ -	public function locate($files, $return_default = false, $return_full_path = true) -	{ -		// convert string to array -		if (is_string($files)) -		{ -			$files = array($files); -		} - -		// use resource locator to find files -		return $this->locator->get_first_file_location($files, $return_default, $return_full_path); -	} -} diff --git a/phpBB/phpbb/symfony_request.php b/phpBB/phpbb/symfony_request.php new file mode 100644 index 0000000000..92784c213b --- /dev/null +++ b/phpBB/phpbb/symfony_request.php @@ -0,0 +1,48 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb; + +use Symfony\Component\HttpFoundation\Request; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +class symfony_request extends Request +{ +	/** +	* Constructor +	* +	* @param phpbb\request\request_interface $phpbb_request +	*/ +	public function __construct(\phpbb\request\request_interface $phpbb_request) +	{ +		// This function is meant to sanitize the global input arrays +		$sanitizer = function(&$value, $key) { +			$type_cast_helper = new \phpbb\request\type_cast_helper(); +			$type_cast_helper->set_var($value, $value, gettype($value), true); +		}; + +		$get_parameters = $phpbb_request->get_super_global(\phpbb\request\request_interface::GET); +		$post_parameters = $phpbb_request->get_super_global(\phpbb\request\request_interface::POST); +		$server_parameters = $phpbb_request->get_super_global(\phpbb\request\request_interface::SERVER); +		$files_parameters = $phpbb_request->get_super_global(\phpbb\request\request_interface::FILES); +		$cookie_parameters = $phpbb_request->get_super_global(\phpbb\request\request_interface::COOKIE); + +		array_walk_recursive($get_parameters, $sanitizer); +		array_walk_recursive($post_parameters, $sanitizer); + +		parent::__construct($get_parameters, $post_parameters, array(), $cookie_parameters, $files_parameters, $server_parameters); +	} +} diff --git a/phpBB/phpbb/template/asset.php b/phpBB/phpbb/template/asset.php index 7c322cd971..27564bf347 100644 --- a/phpBB/phpbb/template/asset.php +++ b/phpBB/phpbb/template/asset.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template; +  /**  * @ignore  */ @@ -15,17 +17,22 @@ if (!defined('IN_PHPBB'))  	exit;  } -class phpbb_template_asset +class asset  {  	protected $components = array(); +	/** @var \phpbb\path_helper **/ +	protected $path_helper; +  	/**  	* Constructor  	*  	* @param string $url URL  	*/ -	public function __construct($url) +	public function __construct($url, \phpbb\path_helper $path_helper)  	{ +		$this->path_helper = $path_helper; +  		$this->set_url($url);  	} @@ -112,7 +119,7 @@ class phpbb_template_asset  	*/  	public function get_url()  	{ -		return $this->join_url($this->components); +		return $this->path_helper->update_web_root_path($this->join_url($this->components));  	}  	/** diff --git a/phpBB/phpbb/template/base.php b/phpBB/phpbb/template/base.php new file mode 100644 index 0000000000..86868707f0 --- /dev/null +++ b/phpBB/phpbb/template/base.php @@ -0,0 +1,150 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\template; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +abstract class base implements template +{ +	/** +	* Template context. +	* Stores template data used during template rendering. +	* +	* @var \phpbb\template\context +	*/ +	protected $context; + +	/** +	* Array of filenames assigned to set_filenames +	* +	* @var array +	*/ +	protected $filenames = array(); + +	/** +	* {@inheritdoc} +	*/ +	public function set_filenames(array $filename_array) +	{ +		$this->filenames = array_merge($this->filenames, $filename_array); + +		return $this; +	} + +	/** +	* Get a filename from the handle +	* +	* @param string $handle +	* @return string +	*/ +	protected function get_filename_from_handle($handle) +	{ +		return (isset($this->filenames[$handle])) ? $this->filenames[$handle] : $handle; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function destroy() +	{ +		$this->context->clear(); + +		return $this; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function destroy_block_vars($blockname) +	{ +		$this->context->destroy_block_vars($blockname); + +		return $this; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function assign_vars(array $vararray) +	{ +		foreach ($vararray as $key => $val) +		{ +			$this->assign_var($key, $val); +		} + +		return $this; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function assign_var($varname, $varval) +	{ +		$this->context->assign_var($varname, $varval); + +		return $this; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function append_var($varname, $varval) +	{ +		$this->context->append_var($varname, $varval); + +		return $this; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function assign_block_vars($blockname, array $vararray) +	{ +		$this->context->assign_block_vars($blockname, $vararray); + +		return $this; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert') +	{ +		return $this->context->alter_block_array($blockname, $vararray, $key, $mode); +	} + +	/** +	* Calls hook if any is defined. +	* +	* @param string $handle Template handle being displayed. +	* @param string $method Method name of the caller. +	*/ +	protected function call_hook($handle, $method) +	{ +		global $phpbb_hook; + +		if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, $method), $handle, $this)) +		{ +			if ($phpbb_hook->hook_return(array(__CLASS__, $method))) +			{ +				$result = $phpbb_hook->hook_return_result(array(__CLASS__, $method)); +				return array($result); +			} +		} + +		return false; +	} +} diff --git a/phpBB/phpbb/template/context.php b/phpBB/phpbb/template/context.php index c5ce7422b9..24234c1e4a 100644 --- a/phpBB/phpbb/template/context.php +++ b/phpBB/phpbb/template/context.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template; +  /**  * @ignore  */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_template_context +class context  {  	/**  	* variable that holds all the data we'll be substituting into @@ -86,7 +88,7 @@ class phpbb_template_context  	* Returns a reference to template data array.  	*  	* This function is public so that template renderer may invoke it. -	* Users should alter template variables via functions in phpbb_template. +	* Users should alter template variables via functions in \phpbb\template\template.  	*  	* Note: modifying returned array will affect data stored in the context.  	* @@ -223,7 +225,7 @@ class phpbb_template_context  	* @param	string	$mode		Mode to execute (valid modes are 'insert' and 'change')  	*  	*	If insert, the vararray is inserted at the given position (position counting from zero). -	*	If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new value). +	*	If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new \value).  	*  	* Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array)  	* and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars) diff --git a/phpBB/phpbb/template/locator.php b/phpBB/phpbb/template/locator.php deleted file mode 100644 index f6fd20bcc2..0000000000 --- a/phpBB/phpbb/template/locator.php +++ /dev/null @@ -1,163 +0,0 @@ -<?php -/** -* -* @package phpBB3 -* @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ - -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ -	exit; -} - - -/** -* Resource locator interface. -* -* Objects implementing this interface maintain mapping from template handles -* to source template file paths and locate templates. -* -* Locates style files. -* -* Resource locator is aware of styles tree, and can return actual -* filesystem paths (i.e., the "child" style or the "parent" styles) -* depending on what files exist. -* -* Root paths stored in locator are paths to style directories. Templates are -* stored in subdirectory that $template_path points to. -* -* @package phpBB3 -*/ -interface phpbb_template_locator -{ -	/** -	* Sets the template filenames for handles. $filename_array -	* should be a hash of handle => filename pairs. -	* -	* @param array $filename_array Should be a hash of handle => filename pairs. -	*/ -	public function set_filenames(array $filename_array); - -	/** -	* Determines the filename for a template handle. -	* -	* The filename comes from array used in a set_filenames call, -	* which should have been performed prior to invoking this function. -	* Return value is a file basename (without path). -	* -	* @param $handle string Template handle -	* @return string Filename corresponding to the template handle -	*/ -	public function get_filename_for_handle($handle); - -	/** -	* Determines the source file path for a template handle without -	* regard for styles tree. -	* -	* This function returns the path in "primary" style directory -	* corresponding to the given template handle. That path may or -	* may not actually exist on the filesystem. Because this function -	* does not perform stat calls to determine whether the path it -	* returns actually exists, it is faster than get_source_file_for_handle. -	* -	* Use get_source_file_for_handle to obtain the actual path that is -	* guaranteed to exist (which might come from the parent style -	* directory if primary style has parent styles). -	* -	* This function will trigger an error if the handle was never -	* associated with a template file via set_filenames. -	* -	* @param $handle string Template handle -	* @return string Path to source file path in primary style directory -	*/ -	public function get_virtual_source_file_for_handle($handle); - -	/** -	* Determines the source file path for a template handle, accounting -	* for styles tree and verifying that the path exists. -	* -	* This function returns the actual path that may be compiled for -	* the specified template handle. It will trigger an error if -	* the template handle was never associated with a template path -	* via set_filenames or if the template file does not exist on the -	* filesystem. -	* -	* Use get_virtual_source_file_for_handle to just resolve a template -	* handle to a path without any filesystem or styles tree checks. -	* -	* @param string $handle Template handle (i.e. "friendly" template name) -	* @param bool $find_all If true, each root path will be checked and function -	*				will return array of files instead of string and will not -	*				trigger a error if template does not exist -	* @return string Source file path -	*/ -	public function get_source_file_for_handle($handle, $find_all = false); - -	/** -	* Obtains a complete filesystem path for a file in a style. -	* -	* This function traverses the style tree (selected style and -	* its parents in order, if inheritance is being used) and finds -	* the first file on the filesystem matching specified relative path, -	* or the first of the specified paths if more than one path is given. -	* -	* This function can be used to determine filesystem path of any -	* file under any style, with the consequence being that complete -	* relative to the style directory path must be provided as an argument. -	* -	* In particular, this function can be used to locate templates -	* and javascript files. -	* -	* For locating templates get_first_template_location should be used -	* as it prepends the configured template path to the template basename. -	* -	* Note: "selected style" is whatever style the style resource locator -	* is configured for. -	* -	* The return value then will be a path, relative to the current -	* directory or absolute, to the first existing file in the selected -	* style or its closest parent. -	* -	* If the selected style does not have the file being searched, -	* (and if inheritance is involved, none of the parents have it either), -	* false will be returned. -	* -	* Multiple files can be specified, in which case the first file in -	* the list that can be found on the filesystem is returned. -	* -	* If multiple files are specified and inheritance is involved, -	* first each of the specified files is checked in the selected style, -	* then each of the specified files is checked in the immediate parent, -	* etc. -	* -	* Specifying true for $return_default will cause the function to -	* return the first path which was checked for existence in the event -	* that the template file was not found, instead of false. -	* This is always a path in the selected style itself, not any of its -	* parents. -	* -	* If $return_full_path is false, then instead of returning a usable -	* path (when the file is found) the file's path relative to the style -	* directory will be returned. This is the same path as was given to -	* the function as a parameter. This can be used to check which of the -	* files specified in $files exists. Naturally this requires passing -	* more than one file in $files. -	* -	* @param array $files List of files to locate. -	* @param bool $return_default Determines what to return if file does not -	*				exist. If true, function will return location where file is -	*				supposed to be. If false, function will return false. -	* @param bool $return_full_path If true, function will return full path -	*				to file. If false, function will return file name. This -	*				parameter can be used to check which one of set of files -	*				is available. -	* @return string or boolean Source file path if file exists or $return_default is -	*				true. False if file does not exist and $return_default is false -	*/ -	public function get_first_file_location($files, $return_default = false, $return_full_path = true); -} diff --git a/phpBB/phpbb/template/template.php b/phpBB/phpbb/template/template.php index 89a01e924d..cf38bba522 100644 --- a/phpBB/phpbb/template/template.php +++ b/phpBB/phpbb/template/template.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template; +  /**  * @ignore  */ @@ -15,13 +17,13 @@ if (!defined('IN_PHPBB'))  	exit;  } -interface phpbb_template +interface template  {  	/**  	* Clear the cache  	* -	* @return phpbb_template +	* @return \phpbb\template\template  	*/  	public function clear_cache(); @@ -29,24 +31,42 @@ interface phpbb_template  	* Sets the template filenames for handles.  	*  	* @param array $filename_array Should be a hash of handle => filename pairs. -	* @return phpbb_template $this +	* @return \phpbb\template\template $this  	*/  	public function set_filenames(array $filename_array);  	/** -	* Sets the style names/paths corresponding to style hierarchy being compiled -	* and/or rendered. +	* Get the style tree of the style preferred by the current user +	* +	* @return array Style tree, most specific first +	*/ +	public function get_user_style(); + +	/** +	* Set style location based on (current) user's chosen style. +	* +	* @param array $style_directories The directories to add style paths for +	* 	E.g. array('ext/foo/bar/styles', 'styles') +	* 	Default: array('styles') (phpBB's style directory) +	* @return \phpbb\template\template $this +	*/ +	public function set_style($style_directories = array('styles')); + +	/** +	* Set custom style location (able to use directory outside of phpBB). +	* +	* Note: Templates are still compiled to phpBB's cache directory.  	* -	* @param array $style_names List of style names in inheritance tree order -	* @param array $style_paths List of style paths in inheritance tree order -	* @return phpbb_template $this +	* @param string|array $names Array of names or string of name of template(s) in inheritance tree order, used by extensions. +	* @param string|array or string $paths Array of style paths, relative to current root directory +	* @return \phpbb\template\template $this  	*/ -	public function set_style_names(array $style_names, array $style_paths); +	public function set_custom_style($names, $paths);  	/**  	* Clears all variables and blocks assigned to this template.  	* -	* @return phpbb_template $this +	* @return \phpbb\template\template $this  	*/  	public function destroy(); @@ -54,7 +74,7 @@ interface phpbb_template  	* Reset/empty complete block  	*  	* @param string $blockname Name of block to destroy -	* @return phpbb_template $this +	* @return \phpbb\template\template $this  	*/  	public function destroy_block_vars($blockname); @@ -66,7 +86,7 @@ interface phpbb_template  	* This function calls hooks.  	*  	* @param string $handle Handle to display -	* @return phpbb_template $this +	* @return \phpbb\template\template $this  	*/  	public function display($handle); @@ -77,7 +97,7 @@ interface phpbb_template  	* @param string $handle Handle to operate on  	* @param string $template_var Template variable to assign compiled handle to  	* @param bool $return_content If true return compiled handle, otherwise assign to $template_var -	* @return phpbb_template|string if $return_content is true return string of the compiled handle, otherwise return $this +	* @return \phpbb\template\template|string if $return_content is true return string of the compiled handle, otherwise return $this  	*/  	public function assign_display($handle, $template_var = '', $return_content = true); @@ -85,7 +105,7 @@ interface phpbb_template  	* Assign key variable pairs from an array  	*  	* @param array $vararray A hash of variable name => value pairs -	* @return phpbb_template $this +	* @return \phpbb\template\template $this  	*/  	public function assign_vars(array $vararray); @@ -96,7 +116,7 @@ interface phpbb_template  	*  	* @param string $varname Variable name  	* @param string $varval Value to assign to variable -	* @return phpbb_template $this +	* @return \phpbb\template\template $this  	*/  	public function assign_var($varname, $varval); @@ -107,7 +127,7 @@ interface phpbb_template  	*  	* @param string $varname Variable name  	* @param string $varval Value to append to variable -	* @return phpbb_template $this +	* @return \phpbb\template\template $this  	*/  	public function append_var($varname, $varval); @@ -115,7 +135,7 @@ interface phpbb_template  	* Assign key variable pairs from an array to a specified block  	* @param string $blockname Name of block to assign $vararray to  	* @param array $vararray A hash of variable name => value pairs -	* @return phpbb_template $this +	* @return \phpbb\template\template $this  	*/  	public function assign_block_vars($blockname, array $vararray); @@ -139,7 +159,7 @@ interface phpbb_template  	* @param	string	$mode		Mode to execute (valid modes are 'insert' and 'change')  	*  	*	If insert, the vararray is inserted at the given position (position counting from zero). -	*	If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new value). +	*	If change, the current block gets merged with the vararray (resulting in new \key/value pairs be added and existing keys be replaced by the new \value).  	*  	* Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array)  	* and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars) diff --git a/phpBB/phpbb/template/twig/definition.php b/phpBB/phpbb/template/twig/definition.php index 6557b209eb..2490a43f81 100644 --- a/phpBB/phpbb/template/twig/definition.php +++ b/phpBB/phpbb/template/twig/definition.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template\twig; +  /**  * @ignore  */ @@ -18,7 +20,7 @@ if (!defined('IN_PHPBB'))  /**  * This class holds all DEFINE variables from the current page load  */ -class phpbb_template_twig_definition +class definition  {  	/** @var array **/  	protected $definitions = array(); @@ -39,7 +41,7 @@ class phpbb_template_twig_definition  	*  	* @param string $name  	* @param mixed $value -	* @return phpbb_template_twig_definition +	* @return \phpbb\template\twig\definition  	*/  	public function set($name, $value)  	{ @@ -53,7 +55,7 @@ class phpbb_template_twig_definition  	*  	* @param string $name  	* @param string $value -	* @return phpbb_template_twig_definition +	* @return \phpbb\template\twig\definition  	*/  	public function append($name, $value)  	{ diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index b60cd72325..a6c0e476f0 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template\twig; +  /**  * @ignore  */ @@ -15,34 +17,44 @@ if (!defined('IN_PHPBB'))  	exit;  } -class phpbb_template_twig_environment extends Twig_Environment +class environment extends \Twig_Environment  {  	/** @var array */  	protected $phpbb_extensions; -	/** @var phpbb_config */ +	/** @var \phpbb\config\config */  	protected $phpbb_config; +	/** @var \phpbb\path_helper */ +	protected $phpbb_path_helper; +  	/** @var string */  	protected $phpbb_root_path; +	/** @var string */ +	protected $web_root_path; +  	/** @var array **/  	protected $namespace_look_up_order = array('__main__');  	/**  	* Constructor  	* -	* @param phpbb_config $phpbb_config +	* @param \phpbb\config\config $phpbb_config  	* @param array $phpbb_extensions Array of enabled extensions (name => path) +	* @param \phpbb\path_helper  	* @param string $phpbb_root_path  	* @param Twig_LoaderInterface $loader  	* @param array $options Array of options to pass to Twig  	*/ -	public function __construct($phpbb_config, $phpbb_extensions, $phpbb_root_path, Twig_LoaderInterface $loader = null, $options = array()) +	public function __construct($phpbb_config, $phpbb_extensions, \phpbb\path_helper $path_helper, \Twig_LoaderInterface $loader = null, $options = array())  	{  		$this->phpbb_config = $phpbb_config;  		$this->phpbb_extensions = $phpbb_extensions; -		$this->phpbb_root_path = $phpbb_root_path; + +		$this->phpbb_path_helper = $path_helper; +		$this->phpbb_root_path = $this->phpbb_path_helper->get_phpbb_root_path(); +		$this->web_root_path = $this->phpbb_path_helper->get_web_root_path();  		return parent::__construct($loader, $options);  	} @@ -62,7 +74,7 @@ class phpbb_template_twig_environment extends Twig_Environment  	/**  	* Get phpBB config  	* -	* @return phpbb_config +	* @return \phpbb\config\config  	*/  	public function get_phpbb_config()  	{ @@ -80,6 +92,26 @@ class phpbb_template_twig_environment extends Twig_Environment  	}  	/** +	* Get the web root path +	* +	* @return string +	*/ +	public function get_web_root_path() +	{ +		return $this->web_root_path; +	} + +	/** +	* Get the phpbb path helper object +	* +	* @return \phpbb\path_helper +	*/ +	public function get_path_helper() +	{ +		return $this->phpbb_path_helper; +	} + +	/**  	* Get the namespace look up order  	*  	* @return array @@ -124,7 +156,7 @@ class phpbb_template_twig_environment extends Twig_Environment  					return parent::loadTemplate('@' . $namespace . '/' . $name, $index);  				} -				catch (Twig_Error_Loader $e) +				catch (\Twig_Error_Loader $e)  				{  				}  			} @@ -137,4 +169,39 @@ class phpbb_template_twig_environment extends Twig_Environment  			return parent::loadTemplate($name, $index);  		}  	} + +	/** +	 * Finds a template by name. +	 * +	 * @param string  $name  The template name +	 * @return string +	 */ +	public function findTemplate($name) +	{ +		if (strpos($name, '@') === false) +		{ +			foreach ($this->getNamespaceLookUpOrder() as $namespace) +			{ +				try +				{ +					if ($namespace === '__main__') +					{ +						return parent::getLoader()->getCacheKey($name); +					} + +					return parent::getLoader()->getCacheKey('@' . $namespace . '/' . $name); +				} +				catch (Twig_Error_Loader $e) +				{ +				} +			} + +			// We were unable to load any templates +			throw $e; +		} +		else +		{ +			return parent::getLoader()->getCacheKey($name); +		} +	}  } diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index c279726434..1ddb97369e 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template\twig; +  /**  * @ignore  */ @@ -15,22 +17,22 @@ if (!defined('IN_PHPBB'))  	exit;  } -class phpbb_template_twig_extension extends Twig_Extension +class extension extends \Twig_Extension  { -	/** @var phpbb_template_context */ +	/** @var \phpbb\template\context */  	protected $context; -	/** @var phpbb_user */ +	/** @var \phpbb\user */  	protected $user;  	/**  	* Constructor  	* -	* @param phpbb_template_context $context -	* @param phpbb_user $user -	* @return phpbb_template_twig_extension +	* @param \phpbb\template\context $context +	* @param \phpbb\user $user +	* @return \phpbb\template\twig\extension  	*/ -	public function __construct(phpbb_template_context $context, $user) +	public function __construct(\phpbb\template\context $context, $user)  	{  		$this->context = $context;  		$this->user = $user; @@ -54,13 +56,13 @@ class phpbb_template_twig_extension extends Twig_Extension  	public function getTokenParsers()  	{  		return array( -			new phpbb_template_twig_tokenparser_define, -			new phpbb_template_twig_tokenparser_include, -			new phpbb_template_twig_tokenparser_includejs, -			new phpbb_template_twig_tokenparser_includecss, -			new phpbb_template_twig_tokenparser_event, -			new phpbb_template_twig_tokenparser_includephp, -			new phpbb_template_twig_tokenparser_php, +			new \phpbb\template\twig\tokenparser\defineparser, +			new \phpbb\template\twig\tokenparser\includeparser, +			new \phpbb\template\twig\tokenparser\includejs, +			new \phpbb\template\twig\tokenparser\includecss, +			new \phpbb\template\twig\tokenparser\event, +			new \phpbb\template\twig\tokenparser\includephp, +			new \phpbb\template\twig\tokenparser\php,  		);  	} @@ -72,8 +74,8 @@ class phpbb_template_twig_extension extends Twig_Extension      public function getFilters()      {  		return array( -			new Twig_SimpleFilter('subset', array($this, 'loop_subset'), array('needs_environment' => true)), -			new Twig_SimpleFilter('addslashes', 'addslashes'), +			new \Twig_SimpleFilter('subset', array($this, 'loop_subset'), array('needs_environment' => true)), +			new \Twig_SimpleFilter('addslashes', 'addslashes'),  		);      } @@ -85,7 +87,7 @@ class phpbb_template_twig_extension extends Twig_Extension      public function getFunctions()      {  		return array( -			new Twig_SimpleFunction('lang', array($this, 'lang')), +			new \Twig_SimpleFunction('lang', array($this, 'lang')),  		);  	} @@ -102,26 +104,26 @@ class phpbb_template_twig_extension extends Twig_Extension  			),  			array(  				// precedence settings are copied from similar operators in Twig core extension -				'||' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), -				'&&' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), +				'||' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), +				'&&' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), -				'eq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), +				'eq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), -				'ne' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), -				'neq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), -				'<>' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), +				'ne' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), +				'neq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), +				'<>' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), -				'===' => array('precedence' => 20, 'class' => 'phpbb_template_twig_node_expression_binary_equalequal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), -				'!==' => array('precedence' => 20, 'class' => 'phpbb_template_twig_node_expression_binary_notequalequal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), +				'===' => array('precedence' => 20, 'class' => '\phpbb\template\twig\node\expression\binary\equalequal', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), +				'!==' => array('precedence' => 20, 'class' => '\phpbb\template\twig\node\expression\binary\notequalequal', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), -				'gt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Greater', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), -				'gte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), -				'ge' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), -				'lt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Less', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), -				'lte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), -				'le' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), +				'gt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Greater', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), +				'gte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), +				'ge' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), +				'lt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Less', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), +				'lte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), +				'le' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), -				'mod' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mod', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), +				'mod' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mod', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),  			),  		);      } @@ -137,7 +139,7 @@ class phpbb_template_twig_extension extends Twig_Extension  	 *  	 * @return mixed The sliced variable  	 */ -	function loop_subset(Twig_Environment $env, $item, $start, $end = null, $preserveKeys = false) +	function loop_subset(\Twig_Environment $env, $item, $start, $end = null, $preserveKeys = false)  	{  		// We do almost the same thing as Twig's slice (array_slice), except when $end is positive  		if ($end >= 1) diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index 46412ad048..d832fbf84e 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template\twig; +  /**  * @ignore  */ @@ -15,7 +17,7 @@ if (!defined('IN_PHPBB'))  	exit;  } -class phpbb_template_twig_lexer extends Twig_Lexer +class lexer extends \Twig_Lexer  {  	public function tokenize($code, $filename = null)  	{ @@ -75,7 +77,7 @@ class phpbb_template_twig_lexer extends Twig_Lexer  		// Fix tokens that may have inline variables (e.g. <!-- DEFINE $TEST = '{FOO}')  		$code = $this->fix_inline_variable_tokens(array( -			'DEFINE.+=', +			'DEFINE \$[a-zA-Z0-9_]+ =',  			'INCLUDE',  			'INCLUDEPHP',  			'INCLUDEJS', @@ -126,10 +128,14 @@ class phpbb_template_twig_lexer extends Twig_Lexer  	{  		$callback = function($matches)  		{ -			// Remove any quotes that may have been used in different implementations -			// E.g. DEFINE $TEST = 'blah' vs INCLUDE foo -			// Replace {} with start/end to parse variables (' ~ TEST ~ '.html) -			$matches[2] = str_replace(array('"', "'", '{', '}'), array('', '', "' ~ ", " ~ '"), $matches[2]); +			// Remove matching quotes at the beginning/end if a statement; +			// E.g. 'asdf'"' -> asdf'" +			// E.g. "asdf'"" -> asdf'" +			// E.g. 'asdf'" -> 'asdf'" +			$matches[2] = preg_replace('#^([\'"])?(.*?)\1$#', '$2', $matches[2]); + +			// Replace template variables with start/end to parse variables (' ~ TEST ~ '.html) +			$matches[2] = preg_replace('#{([a-zA-Z0-9_\.$]+)}#', "'~ \$1 ~'", $matches[2]);  			// Surround the matches in single quotes ('' ~ TEST ~ '.html')  			return "<!-- {$matches[1]} '{$matches[2]}' -->"; @@ -157,6 +163,9 @@ class phpbb_template_twig_lexer extends Twig_Lexer  			$subset = trim(substr($matches[2], 1, -1)); // Remove parenthesis  			$body = $matches[3]; +			// Replace <!-- BEGINELSE --> +			$body = str_replace('<!-- BEGINELSE -->', '{% else %}', $body); +  			// Is the designer wanting to call another loop in a loop?  			// <!-- BEGIN loop -->  			// <!-- BEGIN !loop2 --> @@ -187,25 +196,20 @@ class phpbb_template_twig_lexer extends Twig_Lexer  			// Recursive...fix any child nodes  			$body = $parent_class->fix_begin_tokens($body, $parent_nodes); -			// Rename loopname vars (to prevent collisions, loop children are named (loop name)_loop_element) -			$body = str_replace($name . '.', $name . '_loop_element.', $body); -  			// Need the parent variable name  			array_pop($parent_nodes); -			$parent = (!empty($parent_nodes)) ? end($parent_nodes) . '_loop_element.' : ''; +			$parent = (!empty($parent_nodes)) ? end($parent_nodes) . '.' : '';  			if ($subset !== '')  			{  				$subset = '|subset(' . $subset . ')';  			} -			// Turn into a Twig for loop, using (loop name)_loop_element for each child -			return "{% for {$name}_loop_element in {$parent}{$name}{$subset} %}{$body}{% endfor %}"; +			$parent = ($parent) ?: 'loops.'; +			// Turn into a Twig for loop +			return "{% for {$name} in {$parent}{$name}{$subset} %}{$body}{% endfor %}";  		}; -		// Replace <!-- BEGINELSE --> correctly, only needs to be done once -		$code = str_replace('<!-- BEGINELSE -->', '{% else %}', $code); -  		return preg_replace_callback('#<!-- BEGIN ([!a-zA-Z0-9_]+)(\([0-9,\-]+\))? -->(.+?)<!-- END \1 -->#s', $callback, $code);  	} @@ -217,21 +221,28 @@ class phpbb_template_twig_lexer extends Twig_Lexer  	*/  	protected function fix_if_tokens($code)  	{ +		// Replace ELSE IF with ELSEIF +		$code = preg_replace('#<!-- ELSE IF (.+?) -->#', '<!-- ELSEIF $1 -->', $code); + +		// Replace our "div by" with Twig's divisibleby (Twig does not like test names with spaces) +		$code = preg_replace('# div by ([0-9]+)#', ' divisibleby($1)', $code); +  		$callback = function($matches)  		{ +			$inner = $matches[2];  			// Replace $TEST with definition.TEST -			$matches[1] = preg_replace('#\s\$([a-zA-Z_0-9]+)#', ' definition.$1', $matches[1]); +			$inner = preg_replace('#(\s\(*!?)\$([a-zA-Z_0-9]+)#', '$1definition.$2', $inner); -			// Replace .test with test|length -			$matches[1] = preg_replace('#\s\.([a-zA-Z_0-9\.]+)#', ' $1|length', $matches[1]); +			// Replace .foo with loops.foo|length +			$inner = preg_replace('#(\s\(*!?)\.([a-zA-Z_0-9]+)([^a-zA-Z_0-9\.])#', '$1loops.$2|length$3', $inner); -			return '<!-- IF' . $matches[1] . '-->'; -		}; +			// Replace .foo.bar with foo.bar|length +			$inner = preg_replace('#(\s\(*!?)\.([a-zA-Z_0-9\.]+)([^a-zA-Z_0-9\.])#', '$1$2|length$3', $inner); -		// Replace our "div by" with Twig's divisibleby (Twig does not like test names with spaces) -		$code = preg_replace('# div by ([0-9]+)#', ' divisibleby($1)', $code); +			return "<!-- {$matches[1]}IF{$inner}-->"; +		}; -		return preg_replace_callback('#<!-- IF((.*)[\s][\$|\.|!]([^\s]+)(.*))-->#', $callback, $code); +		return preg_replace_callback('#<!-- (ELSE)?IF((.*?) \(*!?[\$|\.]([^\s]+)(.*?))-->#', $callback, $code);  	}  	/** @@ -255,10 +266,10 @@ class phpbb_template_twig_lexer extends Twig_Lexer  		*/  		// Replace <!-- DEFINE $NAME with {% DEFINE definition.NAME -		$code = preg_replace('#<!-- DEFINE \$(.*)-->#', '{% DEFINE $1 %}', $code); +		$code = preg_replace('#<!-- DEFINE \$(.*?) -->#', '{% DEFINE $1 %}', $code);  		// Changing UNDEFINE NAME to DEFINE NAME = null to save from creating an extra token parser/node -		$code = preg_replace('#<!-- UNDEFINE \$(.*)-->#', '{% DEFINE $1= null %}', $code); +		$code = preg_replace('#<!-- UNDEFINE \$(.*?)-->#', '{% DEFINE $1= null %}', $code);  		// Replace all of our variables, {$VARNAME}, with Twig style, {{ definition.VARNAME }}  		$code = preg_replace('#{\$([a-zA-Z0-9_\.]+)}#', '{{ definition.$1 }}', $code); diff --git a/phpBB/phpbb/template/twig/loader.php b/phpBB/phpbb/template/twig/loader.php new file mode 100644 index 0000000000..910061dc0f --- /dev/null +++ b/phpBB/phpbb/template/twig/loader.php @@ -0,0 +1,152 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\template\twig; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +/** +* Twig Template loader +* @package phpBB3 +*/ +class loader extends \Twig_Loader_Filesystem +{ +	protected $safe_directories = array(); + +	/** +	* Set safe directories +	* +	* @param array $directories Array of directories that are safe (empty to clear) +	* @return Twig_Loader_Filesystem +	*/ +	public function setSafeDirectories($directories = array()) +	{ +		$this->safe_directories = array(); + +		if (!empty($directories)) +		{ +			foreach ($directories as $directory) +			{ +				$this->addSafeDirectory($directory); +			} +		} + +		return $this; +	} + +	/** +	* Add safe directory +	* +	* @param string $directory Directory that should be added +	* @return Twig_Loader_Filesystem +	*/ +	public function addSafeDirectory($directory) +	{ +		$directory = phpbb_realpath($directory); + +		if ($directory !== false) +		{ +			$this->safe_directories[] = $directory; +		} + +		return $this; +	} + +	/** +	* Get current safe directories +	* +	* @return array +	*/ +	public function getSafeDirectories() +	{ +		return $this->safe_directories; +	} + +	/** +	* Override for parent::validateName() +	* +	* This is done because we added support for safe directories, and when Twig +	*	findTemplate() is called, validateName() is called first, which would +	*	always throw an exception if the file is outside of the configured +	*	template directories. +	*/ +	protected function validateName($name) +	{ +		return; +	} + +	/** +	* Find the template +	* +	* Override for Twig_Loader_Filesystem::findTemplate to add support +	*	for loading from safe directories. +	*/ +	protected function findTemplate($name) +	{ +		$name = (string) $name; + +		// normalize name +		$name = preg_replace('#/{2,}#', '/', strtr($name, '\\', '/')); + +		// If this is in the cache we can skip the entire process below +		//	as it should have already been validated +		if (isset($this->cache[$name])) { +			return $this->cache[$name]; +		} + +		// First, find the template name. The override above of validateName +		//	causes the validateName process to be skipped for this call +		$file = parent::findTemplate($name); + +		try +		{ +			// Try validating the name (which may throw an exception) +			parent::validateName($name); +		} +		catch (Twig_Error_Loader $e) +		{ +			if (strpos($e->getRawMessage(), 'Looks like you try to load a template outside configured directories') === 0) +			{ +				// Ok, so outside of the configured template directories, we +				//	can now check if we're within a "safe" directory + +				// Find the real path of the directory the file is in +				$directory = phpbb_realpath(dirname($file)); + +				if ($directory === false) +				{ +					// Some sort of error finding the actual path, must throw the exception +					throw $e; +				} + +				foreach ($this->safe_directories as $safe_directory) +				{ +					if (strpos($directory, $safe_directory) === 0) +					{ +						// The directory being loaded is below a directory +						// that is "safe". We're good to load it! +						return $file; +					} +				} +			} + +			// Not within any safe directories +			throw $e; +		} + +		// No exception from validateName, safe to load. +		return $file; +	} +} diff --git a/phpBB/phpbb/template/twig/node/define.php b/phpBB/phpbb/template/twig/node/definenode.php index fcb19cc773..ec084d0f7d 100644 --- a/phpBB/phpbb/template/twig/node/define.php +++ b/phpBB/phpbb/template/twig/node/definenode.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template\twig\node; +  /**  * @ignore  */ @@ -16,9 +18,9 @@ if (!defined('IN_PHPBB'))  } -class phpbb_template_twig_node_define extends Twig_Node +class definenode extends \Twig_Node  { -	public function __construct($capture, Twig_NodeInterface $name, Twig_NodeInterface $value, $lineno, $tag = null) +	public function __construct($capture, \Twig_NodeInterface $name, \Twig_NodeInterface $value, $lineno, $tag = null)  	{  		parent::__construct(array('name' => $name, 'value' => $value), array('capture' => $capture, 'safe' => false), $lineno, $tag);  	} @@ -28,7 +30,7 @@ class phpbb_template_twig_node_define extends Twig_Node  	 *  	 * @param Twig_Compiler A Twig_Compiler instance  	 */ -	public function compile(Twig_Compiler $compiler) +	public function compile(\Twig_Compiler $compiler)  	{  		$compiler->addDebugInfo($this); @@ -38,7 +40,7 @@ class phpbb_template_twig_node_define extends Twig_Node  				->subcompile($this->getNode('value'))  			; -			$compiler->write("\$value = ('' === \$value = ob_get_clean()) ? '' : new Twig_Markup(\$value, \$this->env->getCharset());\n"); +			$compiler->write("\$value = ('' === \$value = ob_get_clean()) ? '' : new \Twig_Markup(\$value, \$this->env->getCharset());\n");  		}  		else  		{ diff --git a/phpBB/phpbb/template/twig/node/event.php b/phpBB/phpbb/template/twig/node/event.php index 971dea14fa..202db775ee 100644 --- a/phpBB/phpbb/template/twig/node/event.php +++ b/phpBB/phpbb/template/twig/node/event.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template\twig\node; +  /**  * @ignore  */ @@ -16,12 +18,18 @@ if (!defined('IN_PHPBB'))  } -class phpbb_template_twig_node_event extends Twig_Node +class event extends \Twig_Node  { +	/** +	 * The subdirectory in which all template listener files must be placed +	 * @var string +	 */ +	protected $listener_directory = 'event/'; +  	/** @var Twig_Environment */  	protected $environment; -	public function __construct(Twig_Node_Expression $expr, phpbb_template_twig_environment $environment, $lineno, $tag = null) +	public function __construct(\Twig_Node_Expression $expr, \phpbb\template\twig\environment $environment, $lineno, $tag = null)  	{  		$this->environment = $environment; @@ -33,11 +41,11 @@ class phpbb_template_twig_node_event extends Twig_Node  	 *  	 * @param Twig_Compiler A Twig_Compiler instance  	 */ -	public function compile(Twig_Compiler $compiler) +	public function compile(\Twig_Compiler $compiler)  	{  		$compiler->addDebugInfo($this); -		$location = $this->getNode('expr')->getAttribute('name'); +		$location = $this->listener_directory . $this->getNode('expr')->getAttribute('name');  		foreach ($this->environment->get_phpbb_extensions() as $ext_namespace => $ext_path)  		{ diff --git a/phpBB/phpbb/template/twig/node/expression/binary/equalequal.php b/phpBB/phpbb/template/twig/node/expression/binary/equalequal.php index 8ec2069114..48d8b814b8 100644 --- a/phpBB/phpbb/template/twig/node/expression/binary/equalequal.php +++ b/phpBB/phpbb/template/twig/node/expression/binary/equalequal.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template\twig\node\expression\binary; +  /**  * @ignore  */ @@ -16,9 +18,9 @@ if (!defined('IN_PHPBB'))  } -class phpbb_template_twig_node_expression_binary_equalequal extends Twig_Node_Expression_Binary +class equalequal extends \Twig_Node_Expression_Binary  { -	public function operator(Twig_Compiler $compiler) +	public function operator(\Twig_Compiler $compiler)  	{  		return $compiler->raw('===');  	} diff --git a/phpBB/phpbb/template/twig/node/expression/binary/notequalequal.php b/phpBB/phpbb/template/twig/node/expression/binary/notequalequal.php index 96f32c502e..87585dfb4c 100644 --- a/phpBB/phpbb/template/twig/node/expression/binary/notequalequal.php +++ b/phpBB/phpbb/template/twig/node/expression/binary/notequalequal.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template\twig\node\expression\binary; +  /**  * @ignore  */ @@ -16,9 +18,9 @@ if (!defined('IN_PHPBB'))  } -class phpbb_template_twig_node_expression_binary_notequalequal extends Twig_Node_Expression_Binary +class notequalequal extends \Twig_Node_Expression_Binary  { -	public function operator(Twig_Compiler $compiler) +	public function operator(\Twig_Compiler $compiler)  	{  		return $compiler->raw('!==');  	} diff --git a/phpBB/phpbb/template/twig/node/includeasset.php b/phpBB/phpbb/template/twig/node/includeasset.php index 990b1c984f..f6c9dc9c58 100644 --- a/phpBB/phpbb/template/twig/node/includeasset.php +++ b/phpBB/phpbb/template/twig/node/includeasset.php @@ -7,12 +7,14 @@  *  */ -class phpbb_template_twig_node_includeasset extends Twig_Node +namespace phpbb\template\twig\node; + +abstract class includeasset extends \Twig_Node  {  	/** @var Twig_Environment */  	protected $environment; -	public function __construct(Twig_Node_Expression $expr, phpbb_template_twig_environment $environment, $lineno, $tag = null) +	public function __construct(\Twig_Node_Expression $expr, \phpbb\template\twig\environment $environment, $lineno, $tag = null)  	{  		$this->environment = $environment; @@ -23,7 +25,7 @@ class phpbb_template_twig_node_includeasset extends Twig_Node  	 *  	 * @param Twig_Compiler A Twig_Compiler instance  	 */ -	public function compile(Twig_Compiler $compiler) +	public function compile(\Twig_Compiler $compiler)  	{  		$compiler->addDebugInfo($this); @@ -33,17 +35,17 @@ class phpbb_template_twig_node_includeasset extends Twig_Node  			->write("\$asset_file = ")  			->subcompile($this->getNode('expr'))  			->raw(";\n") -			->write("\$asset = new phpbb_template_asset(\$asset_file);\n") +			->write("\$asset = new \phpbb\\template\\asset(\$asset_file, \$this->getEnvironment()->get_path_helper());\n")  			->write("if (substr(\$asset_file, 0, 2) !== './' && \$asset->is_relative()) {\n")  			->indent()  				->write("\$asset_path = \$asset->get_path();")  				->write("\$local_file = \$this->getEnvironment()->get_phpbb_root_path() . \$asset_path;\n")  				->write("if (!file_exists(\$local_file)) {\n")  				->indent() -					->write("\$local_file = \$this->getEnvironment()->getLoader()->getCacheKey(\$asset_path);\n") +					->write("\$local_file = \$this->getEnvironment()->findTemplate(\$asset_path);\n")  					->write("\$asset->set_path(\$local_file, true);\n")  				->outdent() -				->write("\$asset->add_assets_version({$config['assets_version']});\n") +				->write("\$asset->add_assets_version('{$config['assets_version']}');\n")  				->write("\$asset_file = \$asset->get_url();\n")  				->write("}\n")  			->outdent() @@ -57,4 +59,19 @@ class phpbb_template_twig_node_includeasset extends Twig_Node  			->raw("\n');\n")  		;  	} + +	/** +	* Get the definition name +	* +	* @return string (e.g. 'SCRIPTS') +	*/ +	abstract public function get_definition_name(); + +	/** +	* Append the output code for the asset +	* +	* @param Twig_Compiler A Twig_Compiler instance +	* @return null +	*/ +	abstract protected function append_asset(\Twig_Compiler $compiler);  } diff --git a/phpBB/phpbb/template/twig/node/includecss.php b/phpBB/phpbb/template/twig/node/includecss.php index 01fda44aad..deb279fa4a 100644 --- a/phpBB/phpbb/template/twig/node/includecss.php +++ b/phpBB/phpbb/template/twig/node/includecss.php @@ -7,19 +7,22 @@  *  */ -class phpbb_template_twig_node_includecss extends phpbb_template_twig_node_includeasset +namespace phpbb\template\twig\node; + +class includecss extends \phpbb\template\twig\node\includeasset  { +	/** +	* {@inheritdoc} +	*/  	public function get_definition_name()  	{  		return 'STYLESHEETS';  	}  	/** -	 * Compiles the node to PHP. -	 * -	 * @param Twig_Compiler A Twig_Compiler instance -	 */ -	public function append_asset(Twig_Compiler $compiler) +	* {@inheritdoc} +	*/ +	public function append_asset(\Twig_Compiler $compiler)  	{  		$compiler  			->raw("<link href=\"' . ") diff --git a/phpBB/phpbb/template/twig/node/includejs.php b/phpBB/phpbb/template/twig/node/includejs.php index fdf2bea3ed..696b640eac 100644 --- a/phpBB/phpbb/template/twig/node/includejs.php +++ b/phpBB/phpbb/template/twig/node/includejs.php @@ -7,19 +7,22 @@  *  */ -class phpbb_template_twig_node_includejs extends phpbb_template_twig_node_includeasset +namespace phpbb\template\twig\node; + +class includejs extends \phpbb\template\twig\node\includeasset  { +	/** +	* {@inheritdoc} +	*/  	public function get_definition_name()  	{  		return 'SCRIPTS';  	}  	/** -	 * Compiles the node to PHP. -	 * -	 * @param Twig_Compiler A Twig_Compiler instance -	 */ -	protected function append_asset(Twig_Compiler $compiler) +	* {@inheritdoc} +	*/ +	protected function append_asset(\Twig_Compiler $compiler)  	{  		$config = $this->environment->get_phpbb_config(); diff --git a/phpBB/phpbb/template/twig/node/include.php b/phpBB/phpbb/template/twig/node/includenode.php index 5c6ae1bbcf..77fe7f3acb 100644 --- a/phpBB/phpbb/template/twig/node/include.php +++ b/phpBB/phpbb/template/twig/node/includenode.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template\twig\node; +  /**  * @ignore  */ @@ -16,14 +18,14 @@ if (!defined('IN_PHPBB'))  } -class phpbb_template_twig_node_include extends Twig_Node_Include +class includenode extends \Twig_Node_Include  {  	/**  	 * Compiles the node to PHP.  	 *  	 * @param Twig_Compiler A Twig_Compiler instance  	 */ -	public function compile(Twig_Compiler $compiler) +	public function compile(\Twig_Compiler $compiler)  	{  		$compiler->addDebugInfo($this); diff --git a/phpBB/phpbb/template/twig/node/includephp.php b/phpBB/phpbb/template/twig/node/includephp.php index dbe54f0e1a..4024cf0cc8 100644 --- a/phpBB/phpbb/template/twig/node/includephp.php +++ b/phpBB/phpbb/template/twig/node/includephp.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template\twig\node; +  /**  * @ignore  */ @@ -16,12 +18,12 @@ if (!defined('IN_PHPBB'))  } -class phpbb_template_twig_node_includephp extends Twig_Node +class includephp extends \Twig_Node  {  	/** @var Twig_Environment */  	protected $environment; -	public function __construct(Twig_Node_Expression $expr, phpbb_template_twig_environment $environment, $ignoreMissing = false, $lineno, $tag = null) +	public function __construct(\Twig_Node_Expression $expr, \phpbb\template\twig\environment $environment, $ignoreMissing = false, $lineno, $tag = null)  	{  		$this->environment = $environment; @@ -33,7 +35,7 @@ class phpbb_template_twig_node_includephp extends Twig_Node  	 *  	 * @param Twig_Compiler A Twig_Compiler instance  	 */ -	public function compile(Twig_Compiler $compiler) +	public function compile(\Twig_Compiler $compiler)  	{  		$compiler->addDebugInfo($this); @@ -80,7 +82,7 @@ class phpbb_template_twig_node_includephp extends Twig_Node  		if ($this->getAttribute('ignore_missing')) {  			$compiler  				->outdent() -				->write("} catch (Twig_Error_Loader \$e) {\n") +				->write("} catch (\Twig_Error_Loader \$e) {\n")  				->indent()  				->write("// ignore missing template\n")  				->outdent() diff --git a/phpBB/phpbb/template/twig/node/php.php b/phpBB/phpbb/template/twig/node/php.php index c11539ea7f..b37759303d 100644 --- a/phpBB/phpbb/template/twig/node/php.php +++ b/phpBB/phpbb/template/twig/node/php.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template\twig\node; +  /**  * @ignore  */ @@ -16,12 +18,12 @@ if (!defined('IN_PHPBB'))  } -class phpbb_template_twig_node_php extends Twig_Node +class php extends \Twig_Node  {  	/** @var Twig_Environment */  	protected $environment; -	public function __construct(Twig_Node_Text $text, phpbb_template_twig_environment $environment, $lineno, $tag = null) +	public function __construct(\Twig_Node_Text $text, \phpbb\template\twig\environment $environment, $lineno, $tag = null)  	{  		$this->environment = $environment; @@ -33,7 +35,7 @@ class phpbb_template_twig_node_php extends Twig_Node  	 *  	 * @param Twig_Compiler A Twig_Compiler instance  	 */ -	public function compile(Twig_Compiler $compiler) +	public function compile(\Twig_Compiler $compiler)  	{  		$compiler->addDebugInfo($this); diff --git a/phpBB/phpbb/template/twig/tokenparser/define.php b/phpBB/phpbb/template/twig/tokenparser/defineparser.php index 4ea15388c4..688afec191 100644 --- a/phpBB/phpbb/template/twig/tokenparser/define.php +++ b/phpBB/phpbb/template/twig/tokenparser/defineparser.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template\twig\tokenparser; +  /**  * @ignore  */ @@ -16,7 +18,7 @@ if (!defined('IN_PHPBB'))  } -class phpbb_template_twig_tokenparser_define extends Twig_TokenParser +class defineparser extends \Twig_TokenParser  {  	/**  	 * Parses a token and returns a node. @@ -25,31 +27,31 @@ class phpbb_template_twig_tokenparser_define extends Twig_TokenParser  	 *  	 * @return Twig_NodeInterface A Twig_NodeInterface instance  	 */ -	public function parse(Twig_Token $token) +	public function parse(\Twig_Token $token)  	{  		$lineno = $token->getLine();  		$stream = $this->parser->getStream();  		$name = $this->parser->getExpressionParser()->parseExpression();  		$capture = false; -		if ($stream->test(Twig_Token::OPERATOR_TYPE, '=')) { +		if ($stream->test(\Twig_Token::OPERATOR_TYPE, '=')) {  			$stream->next();  			$value = $this->parser->getExpressionParser()->parseExpression(); -			$stream->expect(Twig_Token::BLOCK_END_TYPE); +			$stream->expect(\Twig_Token::BLOCK_END_TYPE);  		} else {  			$capture = true; -			$stream->expect(Twig_Token::BLOCK_END_TYPE); +			$stream->expect(\Twig_Token::BLOCK_END_TYPE);  			$value = $this->parser->subparse(array($this, 'decideBlockEnd'), true); -			$stream->expect(Twig_Token::BLOCK_END_TYPE); +			$stream->expect(\Twig_Token::BLOCK_END_TYPE);  		} -		return new phpbb_template_twig_node_define($capture, $name, $value, $lineno, $this->getTag()); +		return new \phpbb\template\twig\node\definenode($capture, $name, $value, $lineno, $this->getTag());  	} -	public function decideBlockEnd(Twig_Token $token) +	public function decideBlockEnd(\Twig_Token $token)  	{  		return $token->test('ENDDEFINE');  	} diff --git a/phpBB/phpbb/template/twig/tokenparser/event.php b/phpBB/phpbb/template/twig/tokenparser/event.php index e4dddd6dcc..7cf4000909 100644 --- a/phpBB/phpbb/template/twig/tokenparser/event.php +++ b/phpBB/phpbb/template/twig/tokenparser/event.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template\twig\tokenparser; +  /**  * @ignore  */ @@ -16,7 +18,7 @@ if (!defined('IN_PHPBB'))  } -class phpbb_template_twig_tokenparser_event extends Twig_TokenParser +class event extends \Twig_TokenParser  {  	/**  	 * Parses a token and returns a node. @@ -25,14 +27,14 @@ class phpbb_template_twig_tokenparser_event extends Twig_TokenParser  	 *  	 * @return Twig_NodeInterface A Twig_NodeInterface instance  	 */ -	public function parse(Twig_Token $token) +	public function parse(\Twig_Token $token)  	{  		$expr = $this->parser->getExpressionParser()->parseExpression();  		$stream = $this->parser->getStream(); -		$stream->expect(Twig_Token::BLOCK_END_TYPE); +		$stream->expect(\Twig_Token::BLOCK_END_TYPE); -		return new phpbb_template_twig_node_event($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag()); +		return new \phpbb\template\twig\node\event($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());  	}  	/** diff --git a/phpBB/phpbb/template/twig/tokenparser/includecss.php b/phpBB/phpbb/template/twig/tokenparser/includecss.php index 6c24dda647..7bf4c610b1 100644 --- a/phpBB/phpbb/template/twig/tokenparser/includecss.php +++ b/phpBB/phpbb/template/twig/tokenparser/includecss.php @@ -7,7 +7,9 @@  *  */ -class phpbb_template_twig_tokenparser_includecss extends Twig_TokenParser +namespace phpbb\template\twig\tokenparser; + +class includecss extends \Twig_TokenParser  {  	/**  	 * Parses a token and returns a node. @@ -16,14 +18,14 @@ class phpbb_template_twig_tokenparser_includecss extends Twig_TokenParser  	 *  	 * @return Twig_NodeInterface A Twig_NodeInterface instance  	 */ -	public function parse(Twig_Token $token) +	public function parse(\Twig_Token $token)  	{  		$expr = $this->parser->getExpressionParser()->parseExpression();  		$stream = $this->parser->getStream(); -		$stream->expect(Twig_Token::BLOCK_END_TYPE); +		$stream->expect(\Twig_Token::BLOCK_END_TYPE); -		return new phpbb_template_twig_node_includecss($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag()); +		return new \phpbb\template\twig\node\includecss($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());  	}  	/** diff --git a/phpBB/phpbb/template/twig/tokenparser/includejs.php b/phpBB/phpbb/template/twig/tokenparser/includejs.php index b02b2f89ba..30a99f3279 100644 --- a/phpBB/phpbb/template/twig/tokenparser/includejs.php +++ b/phpBB/phpbb/template/twig/tokenparser/includejs.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template\twig\tokenparser; +  /**  * @ignore  */ @@ -16,7 +18,7 @@ if (!defined('IN_PHPBB'))  } -class phpbb_template_twig_tokenparser_includejs extends Twig_TokenParser +class includejs extends \Twig_TokenParser  {  	/**  	 * Parses a token and returns a node. @@ -25,14 +27,14 @@ class phpbb_template_twig_tokenparser_includejs extends Twig_TokenParser  	 *  	 * @return Twig_NodeInterface A Twig_NodeInterface instance  	 */ -	public function parse(Twig_Token $token) +	public function parse(\Twig_Token $token)  	{  		$expr = $this->parser->getExpressionParser()->parseExpression();  		$stream = $this->parser->getStream(); -		$stream->expect(Twig_Token::BLOCK_END_TYPE); +		$stream->expect(\Twig_Token::BLOCK_END_TYPE); -		return new phpbb_template_twig_node_includejs($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag()); +		return new \phpbb\template\twig\node\includejs($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());  	}  	/** diff --git a/phpBB/phpbb/template/twig/tokenparser/include.php b/phpBB/phpbb/template/twig/tokenparser/includeparser.php index 520f9fd1a0..715c0ec84d 100644 --- a/phpBB/phpbb/template/twig/tokenparser/include.php +++ b/phpBB/phpbb/template/twig/tokenparser/includeparser.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template\twig\tokenparser; +  /**  * @ignore  */ @@ -16,7 +18,7 @@ if (!defined('IN_PHPBB'))  } -class phpbb_template_twig_tokenparser_include extends Twig_TokenParser_Include +class includeparser extends \Twig_TokenParser_Include  {  	/**  	 * Parses a token and returns a node. @@ -25,13 +27,13 @@ class phpbb_template_twig_tokenparser_include extends Twig_TokenParser_Include  	 *  	 * @return Twig_NodeInterface A Twig_NodeInterface instance  	 */ -	public function parse(Twig_Token $token) +	public function parse(\Twig_Token $token)  	{  		$expr = $this->parser->getExpressionParser()->parseExpression();  		list($variables, $only, $ignoreMissing) = $this->parseArguments(); -		return new phpbb_template_twig_node_include($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); +		return new \phpbb\template\twig\node\includenode($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());  	}  	/** diff --git a/phpBB/phpbb/template/twig/tokenparser/includephp.php b/phpBB/phpbb/template/twig/tokenparser/includephp.php index 13fe6de8a6..d906837590 100644 --- a/phpBB/phpbb/template/twig/tokenparser/includephp.php +++ b/phpBB/phpbb/template/twig/tokenparser/includephp.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template\twig\tokenparser; +  /**  * @ignore  */ @@ -16,7 +18,7 @@ if (!defined('IN_PHPBB'))  } -class phpbb_template_twig_tokenparser_includephp extends Twig_TokenParser +class includephp extends \Twig_TokenParser  {  	/**  	 * Parses a token and returns a node. @@ -25,23 +27,23 @@ class phpbb_template_twig_tokenparser_includephp extends Twig_TokenParser  	 *  	 * @return Twig_NodeInterface A Twig_NodeInterface instance  	 */ -	public function parse(Twig_Token $token) +	public function parse(\Twig_Token $token)  	{  		$expr = $this->parser->getExpressionParser()->parseExpression();  		$stream = $this->parser->getStream();  		$ignoreMissing = false; -		if ($stream->test(Twig_Token::NAME_TYPE, 'ignore')) { +		if ($stream->test(\Twig_Token::NAME_TYPE, 'ignore')) {  			$stream->next(); -			$stream->expect(Twig_Token::NAME_TYPE, 'missing'); +			$stream->expect(\Twig_Token::NAME_TYPE, 'missing');  			$ignoreMissing = true;  		} -		$stream->expect(Twig_Token::BLOCK_END_TYPE); +		$stream->expect(\Twig_Token::BLOCK_END_TYPE); -		return new phpbb_template_twig_node_includephp($expr, $this->parser->getEnvironment(), $ignoreMissing, $token->getLine(), $this->getTag()); +		return new \phpbb\template\twig\node\includephp($expr, $this->parser->getEnvironment(), $ignoreMissing, $token->getLine(), $this->getTag());  	}  	/** diff --git a/phpBB/phpbb/template/twig/tokenparser/php.php b/phpBB/phpbb/template/twig/tokenparser/php.php index 197980a59a..e4f70fb9b1 100644 --- a/phpBB/phpbb/template/twig/tokenparser/php.php +++ b/phpBB/phpbb/template/twig/tokenparser/php.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template\twig\tokenparser; +  /**  * @ignore  */ @@ -16,7 +18,7 @@ if (!defined('IN_PHPBB'))  } -class phpbb_template_twig_tokenparser_php extends Twig_TokenParser +class php extends \Twig_TokenParser  {  	/**  	 * Parses a token and returns a node. @@ -25,20 +27,20 @@ class phpbb_template_twig_tokenparser_php extends Twig_TokenParser  	 *  	 * @return Twig_NodeInterface A Twig_NodeInterface instance  	 */ -	public function parse(Twig_Token $token) +	public function parse(\Twig_Token $token)  	{  		$stream = $this->parser->getStream(); -		$stream->expect(Twig_Token::BLOCK_END_TYPE); +		$stream->expect(\Twig_Token::BLOCK_END_TYPE);  		$body = $this->parser->subparse(array($this, 'decideEnd'), true); -		$stream->expect(Twig_Token::BLOCK_END_TYPE); +		$stream->expect(\Twig_Token::BLOCK_END_TYPE); -		return new phpbb_template_twig_node_php($body, $this->parser->getEnvironment(), $token->getLine(), $this->getTag()); +		return new \phpbb\template\twig\node\php($body, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());  	} -	public function decideEnd(Twig_Token $token) +	public function decideEnd(\Twig_Token $token)  	{  		return $token->test('ENDPHP');  	} diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index 92a37d1634..9df9310427 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\template\twig; +  /**  * @ignore  */ @@ -19,16 +21,9 @@ if (!defined('IN_PHPBB'))  * Twig Template class.  * @package phpBB3  */ -class phpbb_template_twig implements phpbb_template +class twig extends \phpbb\template\base  {  	/** -	* Template context. -	* Stores template data used during template rendering. -	* @var phpbb_template_context -	*/ -	protected $context; - -	/**  	* Path of the cache directory for the template  	*  	* Cannot be changed during runtime. @@ -38,16 +33,16 @@ class phpbb_template_twig implements phpbb_template  	private $cachepath = '';  	/** -	* phpBB root path -	* @var string +	* phpBB path helper +	* @var \phpbb\path_helper  	*/ -	protected $phpbb_root_path; +	protected $path_helper;  	/** -	* adm relative path +	* phpBB root path  	* @var string  	*/ -	protected $adm_relative_path; +	protected $phpbb_root_path;  	/**  	* PHP file extension @@ -57,34 +52,24 @@ class phpbb_template_twig implements phpbb_template  	/**  	* phpBB config instance -	* @var phpbb_config +	* @var \phpbb\config\config  	*/  	protected $config;  	/**  	* Current user -	* @var phpbb_user +	* @var \phpbb\user  	*/  	protected $user;  	/**  	* Extension manager.  	* -	* @var phpbb_extension_manager +	* @var \phpbb\extension\manager  	*/  	protected $extension_manager;  	/** -	* Name of the style that the template being compiled and/or rendered -	* belongs to, and its parents, in inheritance tree order. -	* -	* Used to invoke style-specific template events. -	* -	* @var array -	*/ -	protected $style_names; - -	/**  	* Twig Environment  	*  	* @var Twig_Environment @@ -92,42 +77,33 @@ class phpbb_template_twig implements phpbb_template  	protected $twig;  	/** -	* Array of filenames assigned to set_filenames -	* -	* @var array -	*/ -	protected $filenames = array(); - -	/**  	* Constructor.  	* -	* @param string $phpbb_root_path phpBB root path -	* @param string $php_ext php extension (typically 'php') -	* @param phpbb_config $config -	* @param phpbb_user $user -	* @param phpbb_template_context $context template context -	* @param phpbb_extension_manager $extension_manager extension manager, if null then template events will not be invoked -	* @param string $adm_relative_path relative path to adm directory +	* @param \phpbb\path_helper $path_helper +	* @param \phpbb\config\config $config +	* @param \phpbb\user $user +	* @param \phpbb\template\context $context template context +	* @param \phpbb\extension\manager $extension_manager extension manager, if null then template events will not be invoked  	*/ -	public function __construct($phpbb_root_path, $php_ext, $config, $user, phpbb_template_context $context, phpbb_extension_manager $extension_manager = null, $adm_relative_path = null) +	public function __construct(\phpbb\path_helper $path_helper, $config, $user, \phpbb\template\context $context, \phpbb\extension\manager $extension_manager = null)  	{ -		$this->phpbb_root_path = $phpbb_root_path; -		$this->adm_relative_path = $adm_relative_path; -		$this->php_ext = $php_ext; +		$this->path_helper = $path_helper; +		$this->phpbb_root_path = $path_helper->get_phpbb_root_path(); +		$this->php_ext = $path_helper->get_php_ext();  		$this->config = $config;  		$this->user = $user;  		$this->context = $context;  		$this->extension_manager = $extension_manager; -		$this->cachepath = $phpbb_root_path . 'cache/twig/'; +		$this->cachepath = $this->phpbb_root_path . 'cache/twig/';  		// Initiate the loader, __main__ namespace paths will be setup later in set_style_names() -		$loader = new Twig_Loader_Filesystem(''); +		$loader = new \phpbb\template\twig\loader(''); -		$this->twig = new phpbb_template_twig_environment( +		$this->twig = new \phpbb\template\twig\environment(  			$this->config,  			($this->extension_manager) ? $this->extension_manager->all_enabled() : array(), -			$this->phpbb_root_path, +			$this->path_helper,  			$loader,  			array(  				'cache'			=> (defined('IN_INSTALL')) ? false : $this->cachepath, @@ -138,21 +114,27 @@ class phpbb_template_twig implements phpbb_template  		);  		$this->twig->addExtension( -			new phpbb_template_twig_extension( +			new \phpbb\template\twig\extension(  				$this->context,  				$this->user  			)  		); -		$lexer = new phpbb_template_twig_lexer($this->twig); +		$lexer = new \phpbb\template\twig\lexer($this->twig);  		$this->twig->setLexer($lexer); + +		// Add admin namespace +		if ($this->path_helper->get_adm_relative_path() !== null && is_dir($this->phpbb_root_path . $this->path_helper->get_adm_relative_path() . 'style/')) +		{ +			$this->twig->getLoader()->setPaths($this->phpbb_root_path . $this->path_helper->get_adm_relative_path() . 'style/', 'admin'); +		}  	}  	/**  	* Clear the cache  	* -	* @return phpbb_template +	* @return \phpbb\template\template  	*/  	public function clear_cache()  	{ @@ -165,51 +147,94 @@ class phpbb_template_twig implements phpbb_template  	}  	/** -	* Sets the template filenames for handles. +	* Get the style tree of the style preferred by the current user  	* -	* @param array $filename_array Should be a hash of handle => filename pairs. -	* @return phpbb_template $this +	* @return array Style tree, most specific first  	*/ -	public function set_filenames(array $filename_array) +	public function get_user_style()  	{ -		$this->filenames = array_merge($this->filenames, $filename_array); +		$style_list = array( +			$this->user->style['style_path'], +		); -		return $this; +		if ($this->user->style['style_parent_id']) +		{ +			$style_list = array_merge($style_list, array_reverse(explode('/', $this->user->style['style_parent_tree']))); +		} + +		return $style_list;  	}  	/** -	* Sets the style names/paths corresponding to style hierarchy being compiled -	* and/or rendered. +	* Set style location based on (current) user's chosen style.  	* -	* @param array $style_names List of style names in inheritance tree order -	* @param array $style_paths List of style paths in inheritance tree order -	* @param bool $is_core True if the style names are the "core" styles for this page load -	* 	Core means the main phpBB template files -	* @return phpbb_template $this +	* @param array $style_directories The directories to add style paths for +	* 	E.g. array('ext/foo/bar/styles', 'styles') +	* 	Default: array('styles') (phpBB's style directory) +	* @return \phpbb\template\template $this  	*/ -	public function set_style_names(array $style_names, array $style_paths, $is_core = false) +	public function set_style($style_directories = array('styles'))  	{ -		$this->style_names = $style_names; +		if ($style_directories !== array('styles') && $this->twig->getLoader()->getPaths('core') === array()) +		{ +			// We should set up the core styles path since not already setup +			$this->set_style(); +		} -		// Set as __main__ namespace -		$this->twig->getLoader()->setPaths($style_paths); +		$names = $this->get_user_style(); -		// Core style namespace from phpbb_style::set_style() -		if ($is_core) +		$paths = array(); +		foreach ($style_directories as $directory)  		{ -			$this->twig->getLoader()->setPaths($style_paths, 'core'); +			foreach ($names as $name) +			{ +				$path = $this->phpbb_root_path . trim($directory, '/') . "/{$name}/"; +				$template_path = $path . 'template/'; + +				if (is_dir($template_path)) +				{ +					// Add the base style directory as a safe directory +					$this->twig->getLoader()->addSafeDirectory($path); + +					$paths[] = $template_path; +				} +			}  		} -		// Add admin namespace -		if (is_dir($this->phpbb_root_path . $this->adm_relative_path . 'style/')) +		// If we're setting up the main phpBB styles directory and the core +		// namespace isn't setup yet, we will set it up now +		if ($style_directories === array('styles') && $this->twig->getLoader()->getPaths('core') === array())  		{ -			$this->twig->getLoader()->setPaths($this->phpbb_root_path . $this->adm_relative_path . 'style/', 'admin'); +			// Set up the core style paths namespace +			$this->twig->getLoader()->setPaths($paths, 'core');  		} +		$this->set_custom_style($names, $paths); + +		return $this; +	} + +	/** +	* Set custom style location (able to use directory outside of phpBB). +	* +	* Note: Templates are still compiled to phpBB's cache directory. +	* +	* @param string|array $names Array of names or string of name of template(s) in inheritance tree order, used by extensions. +	* @param string|array or string $paths Array of style paths, relative to current root directory +	* @return phpbb_template $this +	*/ +	public function set_custom_style($names, $paths) +	{ +		$paths = (is_string($paths)) ? array($paths) : $paths; +		$names = (is_string($names)) ? array($names) : $names; + +		// Set as __main__ namespace +		$this->twig->getLoader()->setPaths($paths); +  		// Add all namespaces for all extensions -		if ($this->extension_manager instanceof phpbb_extension_manager) +		if ($this->extension_manager instanceof \phpbb\extension\manager)  		{ -			$style_names[] = 'all'; +			$names[] = 'all';  			foreach ($this->extension_manager->all_enabled() as $ext_namespace => $ext_path)  			{ @@ -217,13 +242,17 @@ class phpbb_template_twig implements phpbb_template  				$namespace = str_replace('/', '_', $ext_namespace);  				$paths = array(); -				foreach ($style_names as $style_name) +				foreach ($names as $style_name)  				{ -					$ext_style_path = $ext_path . 'styles/' . $style_name . '/template'; +					$ext_style_path = $ext_path . 'styles/' . $style_name . '/'; +					$ext_style_template_path = $ext_style_path . 'template/'; -					if (is_dir($ext_style_path)) +					if (is_dir($ext_style_template_path))  					{ -						$paths[] = $ext_style_path; +						// Add the base style directory as a safe directory +						$this->twig->getLoader()->addSafeDirectory($ext_style_path); + +						$paths[] = $ext_style_template_path;  					}  				} @@ -235,31 +264,6 @@ class phpbb_template_twig implements phpbb_template  	}  	/** -	* Clears all variables and blocks assigned to this template. -	* -	* @return phpbb_template $this -	*/ -	public function destroy() -	{ -		$this->context = array(); - -		return $this; -	} - -	/** -	* Reset/empty complete block -	* -	* @param string $blockname Name of block to destroy -	* @return phpbb_template $this -	*/ -	public function destroy_block_vars($blockname) -	{ -		$this->context->destroy_block_vars($blockname); - -		return $this; -	} - -	/**  	* Display a template for provided handle.  	*  	* The template will be loaded and compiled, if necessary, first. @@ -267,7 +271,7 @@ class phpbb_template_twig implements phpbb_template  	* This function calls hooks.  	*  	* @param string $handle Handle to display -	* @return phpbb_template $this +	* @return \phpbb\template\template $this  	*/  	public function display($handle)  	{ @@ -283,35 +287,13 @@ class phpbb_template_twig implements phpbb_template  	}  	/** -	* Calls hook if any is defined. -	* -	* @param string $handle Template handle being displayed. -	* @param string $method Method name of the caller. -	*/ -	protected function call_hook($handle, $method) -	{ -		global $phpbb_hook; - -		if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, $method), $handle, $this)) -		{ -			if ($phpbb_hook->hook_return(array(__CLASS__, $method))) -			{ -				$result = $phpbb_hook->hook_return_result(array(__CLASS__, $method)); -				return array($result); -			} -		} - -		return false; -	} - -	/**  	* Display the handle and assign the output to a template variable  	* or return the compiled result.  	*  	* @param string $handle Handle to operate on  	* @param string $template_var Template variable to assign compiled handle to  	* @param bool $return_content If true return compiled handle, otherwise assign to $template_var -	* @return phpbb_template|string if $return_content is true return string of the compiled handle, otherwise return $this +	* @return \phpbb\template\template|string if $return_content is true return string of the compiled handle, otherwise return $this  	*/  	public function assign_display($handle, $template_var = '', $return_content = true)  	{ @@ -326,134 +308,30 @@ class phpbb_template_twig implements phpbb_template  	}  	/** -	* Assign key variable pairs from an array -	* -	* @param array $vararray A hash of variable name => value pairs -	* @return phpbb_template $this -	*/ -	public function assign_vars(array $vararray) -	{ -		foreach ($vararray as $key => $val) -		{ -			$this->assign_var($key, $val); -		} - -		return $this; -	} - -	/** -	* Assign a single scalar value to a single key. -	* -	* Value can be a string, an integer or a boolean. -	* -	* @param string $varname Variable name -	* @param string $varval Value to assign to variable -	* @return phpbb_template $this -	*/ -	public function assign_var($varname, $varval) -	{ -		$this->context->assign_var($varname, $varval); - -		return $this; -	} - -	/** -	* Append text to the string value stored in a key. -	* -	* Text is appended using the string concatenation operator (.). -	* -	* @param string $varname Variable name -	* @param string $varval Value to append to variable -	* @return phpbb_template $this -	*/ -	public function append_var($varname, $varval) -	{ -		$this->context->append_var($varname, $varval); - -		return $this; -	} - -	/** -	* Assign key variable pairs from an array to a specified block -	* @param string $blockname Name of block to assign $vararray to -	* @param array $vararray A hash of variable name => value pairs -	* @return phpbb_template $this -	*/ -	public function assign_block_vars($blockname, array $vararray) -	{ -		$this->context->assign_block_vars($blockname, $vararray); - -		return $this; -	} - -	/** -	* Change already assigned key variable pair (one-dimensional - single loop entry) -	* -	* An example of how to use this function: -	* {@example alter_block_array.php} -	* -	* @param	string	$blockname	the blockname, for example 'loop' -	* @param	array	$vararray	the var array to insert/add or merge -	* @param	mixed	$key		Key to search for -	* -	* array: KEY => VALUE [the key/value pair to search for within the loop to determine the correct position] -	* -	* int: Position [the position to change or insert at directly given] -	* -	* If key is false the position is set to 0 -	* If key is true the position is set to the last entry -	* -	* @param	string	$mode		Mode to execute (valid modes are 'insert' and 'change') -	* -	*	If insert, the vararray is inserted at the given position (position counting from zero). -	*	If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new value). -	* -	* Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array) -	* and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars) -	* -	* @return bool false on error, true on success -	*/ -	public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert') -	{ -		return $this->context->alter_block_array($blockname, $vararray, $key, $mode); -	} - -	/**  	* Get template vars in a format Twig will use (from the context)  	*  	* @return array  	*/ -	public function get_template_vars() +	protected function get_template_vars()  	{  		$context_vars = $this->context->get_data_ref();  		$vars = array_merge(  			$context_vars['.'][0], // To get normal vars -			$context_vars, // To get loops  			array( -				'definition'	=> new phpbb_template_twig_definition(), +				'definition'	=> new \phpbb\template\twig\definition(),  				'user'			=> $this->user, +				'loops'			=> $context_vars, // To get loops  			)  		);  		// cleanup -		unset($vars['.']); +		unset($vars['loops']['.']);  		return $vars;  	}  	/** -	* Get a filename from the handle -	* -	* @param string $handle -	* @return string -	*/ -	protected function get_filename_from_handle($handle) -	{ -		return (isset($this->filenames[$handle])) ? $this->filenames[$handle] : $handle; -	} - -	/**  	* Get path to template for handle (required for BBCode parser)  	*  	* @return string diff --git a/phpBB/phpbb/tree/nestedset.php b/phpBB/phpbb/tree/nestedset.php index 4d851a87a8..171dae4d14 100644 --- a/phpBB/phpbb/tree/nestedset.php +++ b/phpBB/phpbb/tree/nestedset.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\tree; +  /**  * @ignore  */ @@ -15,12 +17,12 @@ if (!defined('IN_PHPBB'))  	exit;  } -abstract class phpbb_tree_nestedset implements phpbb_tree_interface +abstract class nestedset implements \phpbb\tree\tree_interface  { -	/** @var phpbb_db_driver */ +	/** @var \phpbb\db\driver\driver */  	protected $db; -	/** @var phpbb_lock_db */ +	/** @var \phpbb\lock\db */  	protected $lock;  	/** @var string */ @@ -58,15 +60,15 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface  	/**  	* Construct  	* -	* @param phpbb_db_driver	$db		Database connection -	* @param phpbb_lock_db		$lock	Lock class used to lock the table when moving forums around +	* @param \phpbb\db\driver\driver	$db		Database connection +	* @param \phpbb\lock\db		$lock	Lock class used to lock the table when moving forums around  	* @param string			$table_name			Table name  	* @param string			$message_prefix		Prefix for the messages thrown by exceptions  	* @param string			$sql_where			Additional SQL restrictions for the queries  	* @param array			$item_basic_data	Array with basic item data that is stored in item_parents  	* @param array			$columns			Array with column names to overwrite  	*/ -	public function __construct(phpbb_db_driver $db, phpbb_lock_db $lock, $table_name, $message_prefix = '', $sql_where = '', $item_basic_data = array(), $columns = array()) +	public function __construct(\phpbb\db\driver\driver $db, \phpbb\lock\db $lock, $table_name, $message_prefix = '', $sql_where = '', $item_basic_data = array(), $columns = array())  	{  		$this->db = $db;  		$this->lock = $lock; @@ -116,7 +118,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface  		if (!$this->lock->acquire())  		{ -			throw new RuntimeException($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); +			throw new \RuntimeException($this->message_prefix . 'LOCK_FAILED_ACQUIRE');  		}  		return true; @@ -184,7 +186,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface  		$item_id = (int) $item_id;  		if (!$item_id)  		{ -			throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); +			throw new \OutOfBoundsException($this->message_prefix . 'INVALID_ITEM');  		}  		$items = $this->get_subtree_data($item_id); @@ -192,7 +194,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface  		if (empty($items) || !isset($items[$item_id]))  		{ -			throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); +			throw new \OutOfBoundsException($this->message_prefix . 'INVALID_ITEM');  		}  		$this->remove_subset($item_ids, $items[$item_id]); @@ -242,7 +244,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface  		if (!$item)  		{  			$this->lock->release(); -			throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); +			throw new \OutOfBoundsException($this->message_prefix . 'INVALID_ITEM');  		}  		/** @@ -364,7 +366,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface  		if (!$current_parent_id)  		{ -			throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); +			throw new \OutOfBoundsException($this->message_prefix . 'INVALID_ITEM');  		}  		$this->acquire_lock(); @@ -373,7 +375,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface  		if (!isset($item_data[$current_parent_id]))  		{  			$this->lock->release(); -			throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); +			throw new \OutOfBoundsException($this->message_prefix . 'INVALID_ITEM');  		}  		$current_parent = $item_data[$current_parent_id]; @@ -389,7 +391,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface  		if (in_array($new_parent_id, $move_items))  		{  			$this->lock->release(); -			throw new OutOfBoundsException($this->message_prefix . 'INVALID_PARENT'); +			throw new \OutOfBoundsException($this->message_prefix . 'INVALID_PARENT');  		}  		$diff = sizeof($move_items) * 2; @@ -413,7 +415,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface  			{  				$this->db->sql_transaction('rollback');  				$this->lock->release(); -				throw new OutOfBoundsException($this->message_prefix . 'INVALID_PARENT'); +				throw new \OutOfBoundsException($this->message_prefix . 'INVALID_PARENT');  			}  			$new_right_id = $this->prepare_adding_subset($move_items, $new_parent, true); @@ -470,7 +472,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface  		if (!$item_id)  		{ -			throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); +			throw new \OutOfBoundsException($this->message_prefix . 'INVALID_ITEM');  		}  		$this->acquire_lock(); @@ -479,7 +481,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface  		if (!isset($item_data[$item_id]))  		{  			$this->lock->release(); -			throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); +			throw new \OutOfBoundsException($this->message_prefix . 'INVALID_ITEM');  		}  		$item = $item_data[$item_id]; @@ -488,7 +490,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface  		if (in_array($new_parent_id, $move_items))  		{  			$this->lock->release(); -			throw new OutOfBoundsException($this->message_prefix . 'INVALID_PARENT'); +			throw new \OutOfBoundsException($this->message_prefix . 'INVALID_PARENT');  		}  		$diff = sizeof($move_items) * 2; @@ -512,7 +514,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface  			{  				$this->db->sql_transaction('rollback');  				$this->lock->release(); -				throw new OutOfBoundsException($this->message_prefix . 'INVALID_PARENT'); +				throw new \OutOfBoundsException($this->message_prefix . 'INVALID_PARENT');  			}  			$new_right_id = $this->prepare_adding_subset($move_items, $new_parent, true); diff --git a/phpBB/phpbb/tree/nestedset_forum.php b/phpBB/phpbb/tree/nestedset_forum.php index ff09ef55d0..2fee5b097e 100644 --- a/phpBB/phpbb/tree/nestedset_forum.php +++ b/phpBB/phpbb/tree/nestedset_forum.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\tree; +  /**  * @ignore  */ @@ -15,16 +17,16 @@ if (!defined('IN_PHPBB'))  	exit;  } -class phpbb_tree_nestedset_forum extends phpbb_tree_nestedset +class nestedset_forum extends \phpbb\tree\nestedset  {  	/**  	* Construct  	* -	* @param phpbb_db_driver	$db		Database connection -	* @param phpbb_lock_db		$lock	Lock class used to lock the table when moving forums around +	* @param \phpbb\db\driver\driver	$db		Database connection +	* @param \phpbb\lock\db		$lock	Lock class used to lock the table when moving forums around  	* @param string				$table_name		Table name  	*/ -	public function __construct(phpbb_db_driver $db, phpbb_lock_db $lock, $table_name) +	public function __construct(\phpbb\db\driver\driver $db, \phpbb\lock\db $lock, $table_name)  	{  		parent::__construct(  			$db, diff --git a/phpBB/phpbb/tree/interface.php b/phpBB/phpbb/tree/tree_interface.php index cc8aab2115..162c1e5e29 100644 --- a/phpBB/phpbb/tree/interface.php +++ b/phpBB/phpbb/tree/tree_interface.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb\tree; +  /**  * @ignore  */ @@ -15,7 +17,7 @@ if (!defined('IN_PHPBB'))  	exit;  } -interface phpbb_tree_interface +interface tree_interface  {  	/**  	* Inserts an item into the database table and into the tree. @@ -79,7 +81,7 @@ interface phpbb_tree_interface  	/**  	* Change parent item  	* -	* Moves the item to the bottom of the new parent's list of children +	* Moves the item to the bottom of the new \parent's list of children  	*  	* @param int	$item_id			The item to be moved  	* @param int	$new_parent_id		The new parent item diff --git a/phpBB/phpbb/user.php b/phpBB/phpbb/user.php index 5530fe3f03..f97cc94d40 100644 --- a/phpBB/phpbb/user.php +++ b/phpBB/phpbb/user.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb; +  /**  * @ignore  */ @@ -23,7 +25,7 @@ if (!defined('IN_PHPBB'))  *  * @package phpBB3  */ -class phpbb_user extends phpbb_session +class user extends \phpbb\session  {  	var $lang = array();  	var $help = array(); @@ -75,7 +77,7 @@ class phpbb_user extends phpbb_session  	*/  	function setup($lang_set = false, $style_id = false)  	{ -		global $db, $phpbb_style, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache; +		global $db, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache;  		global $phpbb_dispatcher;  		if ($this->data['user_id'] != ANONYMOUS) @@ -128,6 +130,7 @@ class phpbb_user extends phpbb_session  		}  		$user_data = $this->data; +		$lang_set_ext = array();  		/**  		* Event to load language files and modify user data on every page @@ -139,10 +142,18 @@ class phpbb_user extends phpbb_session  		* @var	string	user_timezone		User's timezone, should be one of  		*							http://www.php.net/manual/en/timezones.php  		* @var	mixed	lang_set			String or array of language files +		* @var	array	lang_set_ext		Array containing entries of format +		* 					array( +		* 						'ext_name' => (string) [extension name], +		* 						'lang_set' => (string|array) [language files], +		* 					) +		* 					For performance reasons, only load translations +		* 					that are absolutely needed globally using this +		* 					event. Use local events otherwise.  		* @var	mixed	style_id			Style we are going to display  		* @since 3.1-A1  		*/ -		$vars = array('user_data', 'user_lang_name', 'user_date_format', 'user_timezone', 'lang_set', 'style_id'); +		$vars = array('user_data', 'user_lang_name', 'user_date_format', 'user_timezone', 'lang_set', 'lang_set_ext', 'style_id');  		extract($phpbb_dispatcher->trigger_event('core.user_setup', compact($vars)));  		$this->data = $user_data; @@ -151,12 +162,12 @@ class phpbb_user extends phpbb_session  		try  		{ -			$this->timezone = new DateTimeZone($user_timezone); +			$this->timezone = new \DateTimeZone($user_timezone);  		} -		catch (Exception $e) +		catch (\Exception $e)  		{  			// If the timezone the user has selected is invalid, we fall back to UTC. -			$this->timezone = new DateTimeZone('UTC'); +			$this->timezone = new \DateTimeZone('UTC');  		}  		// We include common language file here to not load it every time a custom language file is included @@ -173,6 +184,12 @@ class phpbb_user extends phpbb_session  		$this->add_lang($lang_set);  		unset($lang_set); +		foreach ($lang_set_ext as $ext_lang_pair) +		{ +			$this->add_lang_ext($ext_lang_pair['ext_name'], $ext_lang_pair['lang_set']); +		} +		unset($lang_set_ext); +  		$style_request = request_var('style', 0);  		if ($style_request && $auth->acl_get('a_styles') && !defined('ADMIN_START'))  		{ @@ -236,7 +253,7 @@ class phpbb_user extends phpbb_session  			}  		} -		$phpbb_style->set_style(); +		$template->set_style();  		$this->img_lang = $this->lang_name; @@ -590,6 +607,13 @@ class phpbb_user extends phpbb_session  				$language_filename = $lang_path . $this->lang_name . '/' . $filename . '.' . $phpEx;  			} +			// If we are in install, try to use the updated version, when available +			$install_language_filename = str_replace('language/', 'install/update/new/language/', $language_filename); +			if (defined('IN_INSTALL') && file_exists($install_language_filename)) +			{ +				$language_filename = $install_language_filename; +			} +  			if (!file_exists($language_filename))  			{  				global $config; @@ -649,27 +673,27 @@ class phpbb_user extends phpbb_session  		if (!isset($utc))  		{ -			$utc = new DateTimeZone('UTC'); +			$utc = new \DateTimeZone('UTC');  		} -		$time = new phpbb_datetime($this, "@$gmepoch", $utc); +		$time = new \phpbb\datetime($this, "@$gmepoch", $utc);  		$time->setTimezone($this->timezone);  		return $time->format($format, $forcedate);  	}  	/** -	* Create a phpbb_datetime object in the context of the current user +	* Create a \phpbb\datetime object in the context of the current user  	*  	* @since 3.1  	* @param string $time String in a format accepted by strtotime().  	* @param DateTimeZone $timezone Time zone of the time. -	* @return phpbb_datetime Date time object linked to the current users locale +	* @return \phpbb\datetime Date time object linked to the current users locale  	*/ -	public function create_datetime($time = 'now', DateTimeZone $timezone = null) +	public function create_datetime($time = 'now', \DateTimeZone $timezone = null)  	{  		$timezone = $timezone ?: $this->timezone; -		return new phpbb_datetime($this, $time, $timezone); +		return new \phpbb\datetime($this, $time, $timezone);  	}  	/** @@ -680,10 +704,10 @@ class phpbb_user extends phpbb_session  	* @param	DateTimeZone	$timezone	Timezone of the date/time, falls back to timezone of current user  	* @return	int			Returns the unix timestamp  	*/ -	public function get_timestamp_from_format($format, $time, DateTimeZone $timezone = null) +	public function get_timestamp_from_format($format, $time, \DateTimeZone $timezone = null)  	{  		$timezone = $timezone ?: $this->timezone; -		$date = DateTime::createFromFormat($format, $time, $timezone); +		$date = \DateTime::createFromFormat($format, $time, $timezone);  		return ($date !== false) ? $date->format('U') : false;  	} diff --git a/phpBB/phpbb/user_loader.php b/phpBB/phpbb/user_loader.php index 37bf9648c1..78620ab1b9 100644 --- a/phpBB/phpbb/user_loader.php +++ b/phpBB/phpbb/user_loader.php @@ -7,6 +7,8 @@  *  */ +namespace phpbb; +  /**  */  if (!defined('IN_PHPBB')) @@ -22,9 +24,9 @@ if (!defined('IN_PHPBB'))  * have to query the same user multiple times in  * different services.  */ -class phpbb_user_loader +class user_loader  { -	/** @var phpbb_db_driver */ +	/** @var \phpbb\db\driver\driver */  	protected $db = null;  	/** @var string */ @@ -46,12 +48,12 @@ class phpbb_user_loader  	/**  	* User loader constructor  	* -	* @param phpbb_db_driver $db A database connection +	* @param \phpbb\db\driver\driver $db A database connection  	* @param string $phpbb_root_path Path to the phpbb includes directory.  	* @param string $php_ext php file extension  	* @param string $users_table The name of the database table (phpbb_users)  	*/ -	public function __construct(phpbb_db_driver $db, $phpbb_root_path, $php_ext, $users_table) +	public function __construct(\phpbb\db\driver\driver $db, $phpbb_root_path, $php_ext, $users_table)  	{  		$this->db = $db;  | 
