diff options
Diffstat (limited to 'phpBB/phpbb')
| -rw-r--r-- | phpBB/phpbb/cache/driver/memcached.php | 134 | ||||
| -rw-r--r-- | phpBB/phpbb/db/migration/data/v31x/add_smtp_ssl_context_config_options.php | 32 | ||||
| -rw-r--r-- | phpBB/phpbb/extension/metadata_manager.php | 72 | 
3 files changed, 191 insertions, 47 deletions
| diff --git a/phpBB/phpbb/cache/driver/memcached.php b/phpBB/phpbb/cache/driver/memcached.php new file mode 100644 index 0000000000..105e763af4 --- /dev/null +++ b/phpBB/phpbb/cache/driver/memcached.php @@ -0,0 +1,134 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\cache\driver; + +if (!defined('PHPBB_ACM_MEMCACHED_PORT')) +{ +	define('PHPBB_ACM_MEMCACHED_PORT', 11211); +} + +if (!defined('PHPBB_ACM_MEMCACHED_COMPRESS')) +{ +	define('PHPBB_ACM_MEMCACHED_COMPRESS', true); +} + +if (!defined('PHPBB_ACM_MEMCACHED_HOST')) +{ +	define('PHPBB_ACM_MEMCACHED_HOST', 'localhost'); +} + +if (!defined('PHPBB_ACM_MEMCACHED')) +{ +	//can define multiple servers with host1/port1,host2/port2 format +	define('PHPBB_ACM_MEMCACHED', PHPBB_ACM_MEMCACHED_HOST . '/' . PHPBB_ACM_MEMCACHED_PORT); +} + +/** +* ACM for Memcached +*/ +class memcached extends \phpbb\cache\driver\memory +{ +	/** @var string Extension to use */ +	protected $extension = 'memcached'; + +	/** @var \Memcached Memcached class */ +	protected $memcached; + +	/** @var int Flags */ +	protected $flags = 0; + +	/** +	 * Memcached constructor +	 */ +	public function __construct() +	{ +		// Call the parent constructor +		parent::__construct(); + +		$this->memcached = new \Memcached(); +		$this->memcached->setOption(\Memcached::OPT_BINARY_PROTOCOL, true); +		// Memcached defaults to using compression, disable if we don't want +		// to use it +		if (!PHPBB_ACM_MEMCACHED_COMPRESS) +		{ +			$this->memcached->setOption(\Memcached::OPT_COMPRESSION, false); +		} + +		foreach (explode(',', PHPBB_ACM_MEMCACHE) as $u) +		{ +			$parts = explode('/', $u); +			$this->memcached->addServer(trim($parts[0]), trim($parts[1])); +		} +	} + +	/** +	* {@inheritDoc} +	*/ +	public function unload() +	{ +		parent::unload(); + +		unset($this->memcached); +	} + +	/** +	* {@inheritDoc} +	*/ +	public function purge() +	{ +		$this->memcached->flush(); + +		parent::purge(); +	} + +	/** +	* Fetch an item from the cache +	* +	* @param string $var Cache key +	* +	* @return mixed Cached data +	*/ +	protected function _read($var) +	{ +		return $this->memcached->get($this->key_prefix . $var); +	} + +	/** +	* Store data in the cache +	* +	* @param string $var Cache key +	* @param mixed $data Data to store +	* @param int $ttl Time-to-live of cached data +	* @return bool True if the operation succeeded +	*/ +	protected function _write($var, $data, $ttl = 2592000) +	{ +		if (!$this->memcached->replace($this->key_prefix . $var, $data, $ttl)) +		{ +			return $this->memcached->set($this->key_prefix . $var, $data, $ttl); +		} +		return true; +	} + +	/** +	* Remove an item from the cache +	* +	* @param string $var Cache key +	* @return bool True if the operation succeeded +	*/ +	protected function _delete($var) +	{ +		return $this->memcached->delete($this->key_prefix . $var); +	} +} diff --git a/phpBB/phpbb/db/migration/data/v31x/add_smtp_ssl_context_config_options.php b/phpBB/phpbb/db/migration/data/v31x/add_smtp_ssl_context_config_options.php new file mode 100644 index 0000000000..92051dc3ca --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v31x/add_smtp_ssl_context_config_options.php @@ -0,0 +1,32 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\db\migration\data\v31x; + +class add_smtp_ssl_context_config_options extends \phpbb\db\migration\migration +{ +	static public function depends_on() +	{ +		return array('\phpbb\db\migration\data\v31x\v3110'); +	} + +	public function update_data() +	{ +		return array( +			// See http://php.net/manual/en/context.ssl.php +			array('config.add', array('smtp_verify_peer', 1)), +			array('config.add', array('smtp_verify_peer_name', 1)), +			array('config.add', array('smtp_allow_self_signed', 0)), +		); +	} +} diff --git a/phpBB/phpbb/extension/metadata_manager.php b/phpBB/phpbb/extension/metadata_manager.php index 107907609b..0842c5d7ae 100644 --- a/phpBB/phpbb/extension/metadata_manager.php +++ b/phpBB/phpbb/extension/metadata_manager.php @@ -109,29 +109,18 @@ class metadata_manager  		{  			case 'all':  			default: -				// Validate the metadata -				if (!$this->validate()) -				{ -					return false; -				} - +				$this->validate();  				return $this->metadata;  			break;  			case 'version':  			case 'name': -				return ($this->validate($element)) ? $this->metadata[$element] : false; +				$this->validate($element); +				return $this->metadata[$element];  			break;  			case 'display-name': -				if (isset($this->metadata['extra']['display-name'])) -				{ -					return $this->metadata['extra']['display-name']; -				} -				else -				{ -					return ($this->validate('name')) ? $this->metadata['name'] : false; -				} +				return (isset($this->metadata['extra']['display-name'])) ? $this->metadata['extra']['display-name'] : $this->get_metadata('name');  			break;  		}  	} @@ -228,23 +217,8 @@ class metadata_manager  		switch ($name)  		{  			case 'all': -				$this->validate('display'); - -				if (!$this->validate_dir()) -				{ -					throw new \phpbb\extension\exception($this->user->lang('EXTENSION_DIR_INVALID')); -				} - -				if (!$this->validate_require_phpbb()) -				{ -					throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', 'soft-require')); -				} - -				if (!$this->validate_require_php()) -				{ -					throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', 'require php')); -				} -			break; +				$this->validate_enable(); +				// no break  			case 'display':  				foreach ($fields as $field => $data) @@ -301,40 +275,43 @@ class metadata_manager  	/**  	* This array handles the verification that this extension can be enabled on this board  	* -	* @return bool True if validation succeeded, False if failed +	* @return bool True if validation succeeded, throws an exception if invalid +	* @throws \phpbb\extension\exception  	*/  	public function validate_enable()  	{  		// Check for valid directory & phpBB, PHP versions -		if (!$this->validate_dir() || !$this->validate_require_phpbb() || !$this->validate_require_php()) -		{ -			return false; -		} - -		return true; +		return $this->validate_dir() && $this->validate_require_phpbb() && $this->validate_require_php();  	}  	/**  	* Validates the most basic directory structure to ensure it follows <vendor>/<ext> convention.  	* -	* @return boolean True when passes validation +	* @return boolean True when passes validation, throws an exception if invalid +	* @throws \phpbb\extension\exception  	*/  	public function validate_dir()  	{ -		return (substr_count($this->ext_name, '/') === 1 && $this->ext_name == $this->get_metadata('name')); +		if (substr_count($this->ext_name, '/') !== 1 || $this->ext_name != $this->get_metadata('name')) +		{ +			throw new \phpbb\extension\exception($this->user->lang('EXTENSION_DIR_INVALID')); +		} + +		return true;  	}  	/**  	* Validates the contents of the phpbb requirement field  	* -	* @return boolean True when passes validation +	* @return boolean True when passes validation, throws an exception if invalid +	* @throws \phpbb\extension\exception  	*/  	public function validate_require_phpbb()  	{  		if (!isset($this->metadata['extra']['soft-require']['phpbb/phpbb']))  		{ -			return false; +			throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', 'soft-require'));  		}  		return true; @@ -343,13 +320,14 @@ class metadata_manager  	/**  	* Validates the contents of the php requirement field  	* -	* @return boolean True when passes validation +	* @return boolean True when passes validation, throws an exception if invalid +	* @throws \phpbb\extension\exception  	*/  	public function validate_require_php()  	{  		if (!isset($this->metadata['require']['php']))  		{ -			return false; +			throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', 'require php'));  		}  		return true; @@ -372,10 +350,10 @@ class metadata_manager  			'META_LICENSE'		=> $this->metadata['license'],  			'META_REQUIRE_PHP'		=> (isset($this->metadata['require']['php'])) ? $this->metadata['require']['php'] : '', -			'META_REQUIRE_PHP_FAIL'	=> !$this->validate_require_php(), +			'META_REQUIRE_PHP_FAIL'	=> (isset($this->metadata['require']['php'])) ? false : true,  			'META_REQUIRE_PHPBB'		=> (isset($this->metadata['extra']['soft-require']['phpbb/phpbb'])) ? $this->metadata['extra']['soft-require']['phpbb/phpbb'] : '', -			'META_REQUIRE_PHPBB_FAIL'	=> !$this->validate_require_phpbb(), +			'META_REQUIRE_PHPBB_FAIL'	=> (isset($this->metadata['extra']['soft-require']['phpbb/phpbb'])) ? false : true,  			'META_DISPLAY_NAME'	=> (isset($this->metadata['extra']['display-name'])) ? $this->metadata['extra']['display-name'] : '',  		)); | 
