phpBB

Code Changes

File: phpbb/extension/metadata_manager.php

  Unmodified   Added   Modified   Removed
Line 29Line 29
	* @var \phpbb\extension\manager
*/
protected $extension_manager;

	* @var \phpbb\extension\manager
*/
protected $extension_manager;


/**
* phpBB Template instance
* @var \phpbb\template\template
*/
protected $template;

/**
* phpBB User instance
* @var \phpbb\user
*/
protected $user;

 

/**
* phpBB root path


/**
* phpBB root path

Line 72Line 60
	* @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 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\user $user User instance

 
	* @param string				$phpbb_root_path	Path to the phpbb includes directory.
*/

	* @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_root_path)

	{
$this->config = $config;
$this->extension_manager = $extension_manager;

	{
$this->config = $config;
$this->extension_manager = $extension_manager;

		$this->template = $template;
$this->user = $user;

 
		$this->phpbb_root_path = $phpbb_root_path;

$this->ext_name = $ext_name;

		$this->phpbb_root_path = $phpbb_root_path;

$this->ext_name = $ext_name;

Line 118Line 102
				return $this->metadata;
break;


				return $this->metadata;
break;


 
			case 'version':

			case 'name':

			case 'name':

				return ($this->validate('name')) ? $this->metadata['name'] : false;

				return ($this->validate($element)) ? $this->metadata[$element] : false;

			break;

case 'display-name':

			break;

case 'display-name':

Line 149Line 134

if (!file_exists($this->metadata_file))
{


if (!file_exists($this->metadata_file))
{

			throw new \phpbb\extension\exception($this->user->lang('FILE_NOT_FOUND', $this->metadata_file));

			throw new \phpbb\extension\exception('FILE_NOT_FOUND', array($this->metadata_file));

		}
}


		}
}


Line 163Line 148
	{
if (!file_exists($this->metadata_file))
{

	{
if (!file_exists($this->metadata_file))
{

			throw new \phpbb\extension\exception($this->user->lang('FILE_NOT_FOUND', $this->metadata_file));

			throw new \phpbb\extension\exception('FILE_NOT_FOUND', array($this->metadata_file));

		}
else
{
if (!($file_contents = file_get_contents($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));

				throw new \phpbb\extension\exception('FILE_CONTENT_ERR', array($this->metadata_file));

			}

if (($metadata = json_decode($file_contents, true)) === null)
{

			}

if (($metadata = json_decode($file_contents, true)) === null)
{

				throw new \phpbb\extension\exception($this->user->lang('FILE_JSON_DECODE_ERR', $this->metadata_file));

				throw new \phpbb\extension\exception('FILE_JSON_DECODE_ERR', array($this->metadata_file));

			}


			}


 
			array_walk_recursive($metadata, array($this, 'sanitize_json'));

			$this->metadata = $metadata;

return true;
}

			$this->metadata = $metadata;

return true;
}

 
	}

/**
* Sanitize input from JSON array using htmlspecialchars()
*
* @param mixed $value Value of array row
* @param string $key Key of array row
*/
public function sanitize_json(&$value, $key)
{
$value = htmlspecialchars($value);

	}

/**

	}

/**

Line 234Line 231
				{
if (!isset($this->metadata[$name]))
{

				{
if (!isset($this->metadata[$name]))
{

						throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', $name));

						throw new \phpbb\extension\exception('META_FIELD_NOT_SET', array($name));

					}

if (!preg_match($fields[$name], $this->metadata[$name]))
{

					}

if (!preg_match($fields[$name], $this->metadata[$name]))
{

						throw new \phpbb\extension\exception($this->user->lang('META_FIELD_INVALID', $name));

						throw new \phpbb\extension\exception('META_FIELD_INVALID', array($name));

					}
}
break;

					}
}
break;

Line 258Line 255
	{
if (empty($this->metadata['authors']))
{

	{
if (empty($this->metadata['authors']))
{

			throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', 'authors'));

			throw new \phpbb\extension\exception('META_FIELD_NOT_SET', array('authors'));

		}

foreach ($this->metadata['authors'] as $author)
{
if (!isset($author['name']))
{

		}

foreach ($this->metadata['authors'] as $author)
{
if (!isset($author['name']))
{

				throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', 'author name'));

				throw new \phpbb\extension\exception('META_FIELD_NOT_SET', array('author name'));

			}
}


			}
}


Line 332Line 329
	/**
* Outputs the metadata into the template
*

	/**
* Outputs the metadata into the template
*

	* @return null

	* @param \phpbb\template\template	$template	phpBB Template instance

	*/

	*/

	public function output_template_data()

	public function output_template_data(\phpbb\template\template $template)

	{

	{

		$this->template->assign_vars(array(
'META_NAME' => htmlspecialchars($this->metadata['name']),
'META_TYPE' => htmlspecialchars($this->metadata['type']),
'META_DESCRIPTION' => (isset($this->metadata['description'])) ? htmlspecialchars($this->metadata['description']) : '',

		$template->assign_vars(array(
'META_NAME' => $this->metadata['name'],
'META_TYPE' => $this->metadata['type'],
'META_DESCRIPTION' => (isset($this->metadata['description'])) ? $this->metadata['description'] : '',

			'META_HOMEPAGE'		=> (isset($this->metadata['homepage'])) ? $this->metadata['homepage'] : '',

			'META_HOMEPAGE'		=> (isset($this->metadata['homepage'])) ? $this->metadata['homepage'] : '',

			'META_VERSION'		=> (isset($this->metadata['version'])) ? htmlspecialchars($this->metadata['version']) : '',
'META_TIME' => (isset($this->metadata['time'])) ? htmlspecialchars($this->metadata['time']) : '',
'META_LICENSE' => htmlspecialchars($this->metadata['license']),

			'META_VERSION'		=> (isset($this->metadata['version'])) ? $this->metadata['version'] : '',
'META_TIME' => (isset($this->metadata['time'])) ? $this->metadata['time'] : '',
'META_LICENSE' => $this->metadata['license'],





			'META_REQUIRE_PHP'		=> (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '',

			'META_REQUIRE_PHP'		=> (isset($this->metadata['require']['php'])) ? $this->metadata['require']['php'] : '',

			'META_REQUIRE_PHP_FAIL'	=> !$this->validate_require_php(),


			'META_REQUIRE_PHP_FAIL'	=> !$this->validate_require_php(),


			'META_REQUIRE_PHPBB'		=> (isset($this->metadata['extra']['soft-require']['phpbb/phpbb'])) ? htmlspecialchars($this->metadata['extra']['soft-require']['phpbb/phpbb']) : '',

			'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'	=> !$this->validate_require_phpbb(),


			'META_DISPLAY_NAME'	=> (isset($this->metadata['extra']['display-name'])) ? htmlspecialchars($this->metadata['extra']['display-name']) : '',

			'META_DISPLAY_NAME'	=> (isset($this->metadata['extra']['display-name'])) ? $this->metadata['extra']['display-name'] : '',

		));

foreach ($this->metadata['authors'] as $author)
{

		));

foreach ($this->metadata['authors'] as $author)
{

			$this->template->assign_block_vars('meta_authors', array(
'AUTHOR_NAME' => htmlspecialchars($author['name']),

			$template->assign_block_vars('meta_authors', array(
'AUTHOR_NAME' => $author['name'],

				'AUTHOR_EMAIL'		=> (isset($author['email'])) ? $author['email'] : '',
'AUTHOR_HOMEPAGE' => (isset($author['homepage'])) ? $author['homepage'] : '',

				'AUTHOR_EMAIL'		=> (isset($author['email'])) ? $author['email'] : '',
'AUTHOR_HOMEPAGE' => (isset($author['homepage'])) ? $author['homepage'] : '',

				'AUTHOR_ROLE'		=> (isset($author['role'])) ? htmlspecialchars($author['role']) : '',

				'AUTHOR_ROLE'		=> (isset($author['role'])) ? $author['role'] : '',

			));
}
}

			));
}
}