diff options
Diffstat (limited to 'phpBB/phpbb')
| -rw-r--r-- | phpBB/phpbb/extension/manager.php | 32 | ||||
| -rw-r--r-- | phpBB/phpbb/extension/metadata_manager.php | 66 | ||||
| -rw-r--r-- | phpBB/phpbb/profilefields/type/type_date.php | 2 | ||||
| -rw-r--r-- | phpBB/phpbb/request/request.php | 6 | ||||
| -rw-r--r-- | phpBB/phpbb/version_helper.php | 63 | 
5 files changed, 96 insertions, 73 deletions
diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php index 76f0e3558e..e7e5f83c23 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -149,10 +149,10 @@ class manager  	* Instantiates the metadata manager for the extension with the given name  	*  	* @param string $name The extension name -	* @param \phpbb\template\template $template The template manager +	* @param \phpbb\template\template $template The template manager or null  	* @return \phpbb\extension\metadata_manager Instance of the metadata manager  	*/ -	public function create_extension_metadata_manager($name, \phpbb\template\template $template) +	public function create_extension_metadata_manager($name, \phpbb\template\template $template = null)  	{  		return new \phpbb\extension\metadata_manager($name, $this->config, $this, $template, $this->user, $this->phpbb_root_path);  	} @@ -433,25 +433,11 @@ class manager  			if ($file_info->isFile() && $file_info->getFilename() == 'composer.json')  			{  				$ext_name = $iterator->getInnerIterator()->getSubPath(); -				$composer_file = $iterator->getPath() . '/composer.json'; - -				// Ignore the extension if there is no composer.json. -				if (!is_readable($composer_file) || !($ext_info = file_get_contents($composer_file))) -				{ -					continue; -				} - -				$ext_info = json_decode($ext_info, true);  				$ext_name = str_replace(DIRECTORY_SEPARATOR, '/', $ext_name); - -				// Ignore the extension if directory depth is not correct or if the directory structure -				// does not match the name value specified in composer.json. -				if (substr_count($ext_name, '/') !== 1 || !isset($ext_info['name']) || $ext_name != $ext_info['name']) +				if ($this->is_available($ext_name))  				{ -					continue; +					$available[$ext_name] = $this->phpbb_root_path . 'ext/' . $ext_name . '/';  				} - -				$available[$ext_name] = $this->phpbb_root_path . 'ext/' . $ext_name . '/';  			}  		}  		ksort($available); @@ -524,7 +510,15 @@ class manager  	*/  	public function is_available($name)  	{ -		return file_exists($this->get_extension_path($name, true)); +		$md_manager = $this->create_extension_metadata_manager($name); +		try +		{ +			return $md_manager->get_metadata('all') && $md_manager->validate_enable(); +		} +		catch (\phpbb\extension\exception $e) +		{ +			return false; +		}  	}  	/** diff --git a/phpBB/phpbb/extension/metadata_manager.php b/phpBB/phpbb/extension/metadata_manager.php index 0842c5d7ae..a09f07bed2 100644 --- a/phpBB/phpbb/extension/metadata_manager.php +++ b/phpBB/phpbb/extension/metadata_manager.php @@ -66,17 +66,18 @@ class metadata_manager  	*/  	protected $metadata_file; +	// @codingStandardsIgnoreStart  	/**  	* Creates the metadata manager  	*  	* @param string				$ext_name			Name (including vendor) of the extension  	* @param \phpbb\config\config		$config				phpBB Config instance  	* @param \phpbb\extension\manager	$extension_manager	An instance of the phpBB extension manager -	* @param \phpbb\template\template	$template			phpBB Template instance +	* @param \phpbb\template\template	$template			phpBB Template instance or null  	* @param \phpbb\user 		$user 				User instance  	* @param string				$phpbb_root_path	Path to the phpbb includes directory.  	*/ -	public function __construct($ext_name, \phpbb\config\config $config, \phpbb\extension\manager $extension_manager, \phpbb\template\template $template, \phpbb\user $user, $phpbb_root_path) +	public function __construct($ext_name, \phpbb\config\config $config, \phpbb\extension\manager $extension_manager, \phpbb\template\template $template = null, \phpbb\user $user, $phpbb_root_path)  	{  		$this->config = $config;  		$this->extension_manager = $extension_manager; @@ -88,6 +89,7 @@ class metadata_manager  		$this->metadata = array();  		$this->metadata_file = '';  	} +	// @codingStandardsIgnoreEnd  	/**  	* Processes and gets the metadata requested @@ -97,13 +99,11 @@ class metadata_manager  	*/  	public function get_metadata($element = 'all')  	{ -		$this->set_metadata_file(); - -		// Fetch the metadata -		$this->fetch_metadata(); - -		// Clean the metadata -		$this->clean_metadata_array(); +		// Fetch and clean the metadata if not done yet +		if ($this->metadata_file === '') +		{ +			$this->fetch_metadata_from_file(); +		}  		switch ($element)  		{ @@ -126,11 +126,11 @@ class metadata_manager  	}  	/** -	* Sets the filepath of the metadata file +	* Sets the path of the metadata file, gets its contents and cleans loaded file  	*  	* @throws \phpbb\extension\exception  	*/ -	private function set_metadata_file() +	private function fetch_metadata_from_file()  	{  		$ext_filepath = $this->extension_manager->get_extension_path($this->ext_name);  		$metadata_filepath = $this->phpbb_root_path . $ext_filepath . 'composer.json'; @@ -141,37 +141,19 @@ class metadata_manager  		{  			throw new \phpbb\extension\exception($this->user->lang('FILE_NOT_FOUND', $this->metadata_file));  		} -	} -	/** -	* Gets the contents of the composer.json file -	* -	* @return bool True if success, throws an exception on failure -	* @throws \phpbb\extension\exception -	*/ -	private function fetch_metadata() -	{ -		if (!file_exists($this->metadata_file)) +		if (!($file_contents = file_get_contents($this->metadata_file)))  		{ -			throw new \phpbb\extension\exception($this->user->lang('FILE_NOT_FOUND', $this->metadata_file)); +			throw new \phpbb\extension\exception($this->user->lang('FILE_CONTENT_ERR', $this->metadata_file));  		} -		else -		{ -			if (!($file_contents = file_get_contents($this->metadata_file))) -			{ -				throw new \phpbb\extension\exception($this->user->lang('FILE_CONTENT_ERR', $this->metadata_file)); -			} - -			if (($metadata = json_decode($file_contents, true)) === null) -			{ -				throw new \phpbb\extension\exception($this->user->lang('FILE_JSON_DECODE_ERR', $this->metadata_file)); -			} -			array_walk_recursive($metadata, array($this, 'sanitize_json')); -			$this->metadata = $metadata; - -			return true; +		if (($metadata = json_decode($file_contents, true)) === null) +		{ +			throw new \phpbb\extension\exception($this->user->lang('FILE_JSON_DECODE_ERR', $this->metadata_file));  		} + +		array_walk_recursive($metadata, array($this, 'sanitize_json')); +		$this->metadata = $metadata;  	}  	/** @@ -186,16 +168,6 @@ class metadata_manager  	}  	/** -	* This array handles the cleaning of the array -	* -	* @return array Contains the cleaned metadata array -	*/ -	private function clean_metadata_array() -	{ -		return $this->metadata; -	} - -	/**  	* Validate fields  	*  	* @param string $name  ("all" for display and enable validation diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 90ac9a6703..63a0c79a3d 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -264,7 +264,7 @@ class type_date extends type_base  		}  		$profile_row['s_year_options'] = '<option value="0"' . ((!$year) ? ' selected="selected"' : '') . '>--</option>'; -		for ($i = $now['year'] - 100; $i <= $now['year'] + 100; $i++) +		for ($i = 1901; $i <= $now['year'] + 50; $i++)  		{  			$profile_row['s_year_options'] .= '<option value="' . $i . '"' . (($i == $year) ? ' selected="selected"' : '') . ">$i</option>";  		} diff --git a/phpBB/phpbb/request/request.php b/phpBB/phpbb/request/request.php index 4cac6fbaea..00ff9064cb 100644 --- a/phpBB/phpbb/request/request.php +++ b/phpBB/phpbb/request/request.php @@ -169,12 +169,6 @@ class request implements \phpbb\request\request_interface  				$GLOBALS[$this->super_globals[$super_global]][$var_name] = $value;  			}  		} - -		if (!$this->super_globals_disabled()) -		{ -			unset($GLOBALS[$this->super_globals[$super_global]][$var_name]); -			$GLOBALS[$this->super_globals[$super_global]][$var_name] = $value; -		}  	}  	/** diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index b00f4f1d5f..9dc5a2e7c9 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -244,6 +244,69 @@ class version_helper  	}  	/** +	 * Gets the latest extension update for the current phpBB branch the user is on +	 * Will suggest versions from newer branches when EoL has been reached +	 * and/or version from newer branch is needed for having all known security +	 * issues fixed. +	 * +	 * @param bool $force_update Ignores cached data. Defaults to false. +	 * @param bool $force_cache Force the use of the cache. Override $force_update. +	 * @return array Version info or empty array if there are no updates +	 * @throws \RuntimeException +	 */ +	public function get_ext_update_on_branch($force_update = false, $force_cache = false) +	{ +		$versions = $this->get_versions_matching_stability($force_update, $force_cache); + +		$self = $this; +		$current_version = $this->current_version; + +		// Get current phpBB branch from version, e.g.: 3.2 +		preg_match('/^(\d+\.\d+).*$/', $this->config['version'], $matches); +		$current_branch = $matches[1]; + +		// Filter out any versions less than the current version +		$versions = array_filter($versions, function($data) use ($self, $current_version) { +			return $self->compare($data['current'], $current_version, '>='); +		}); + +		// Filter out any phpbb branches less than the current version +		$branches = array_filter(array_keys($versions), function($branch) use ($self, $current_branch) { +			return $self->compare($branch, $current_branch, '>='); +		}); +		if (!empty($branches)) +		{ +			$versions = array_intersect_key($versions, array_flip($branches)); +		} +		else +		{ +			// If branches are empty, it means the current phpBB branch is newer than any branch the +			// extension was validated against. Reverse sort the versions array so we get the newest +			// validated release available. +			krsort($versions); +		} + +		// Get the first available version from the previous list. +		$update_info = array_reduce($versions, function($value, $data) use ($self, $current_version) { +			if ($value === null && $self->compare($data['current'], $current_version, '>=')) +			{ +				if (!$data['eol'] && (!$data['security'] || $self->compare($data['security'], $data['current'], '<='))) +				{ +					return $self->compare($data['current'], $current_version, '>') ? $data : array(); +				} +				else +				{ +					return null; +				} +			} + +			return $value; +		}); + +		return $update_info === null ? array() : $update_info; +	} + +	/**  	* Obtains the latest version information  	*  	* @param bool $force_update Ignores cached data. Defaults to false.  | 
