Line 66 | Line 66 |
---|
*/ protected $metadata_file;
|
*/ 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
|
/** * 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. */
|
* @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;
| { $this->config = $config; $this->extension_manager = $extension_manager;
|
Line 88 | Line 89 |
---|
$this->metadata = array(); $this->metadata_file = ''; }
|
$this->metadata = array(); $this->metadata_file = ''; }
|
| // @codingStandardsIgnoreEnd
|
/** * Processes and gets the metadata requested
| /** * Processes and gets the metadata requested
|
Line 97 | Line 99 |
---|
*/ public function get_metadata($element = 'all') {
|
*/ 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) { case 'all': default:
|
switch ($element) { case 'all': default:
|
// Validate the metadata if (!$this->validate()) { return false; }
| $this->validate();
|
return $this->metadata; break;
|
return $this->metadata; break;
|
| case 'version':
|
case 'name':
|
case 'name':
|
return ($this->validate('name')) ? $this->metadata['name'] : false;
| $this->validate($element); return $this->metadata[$element];
|
break;
case 'display-name':
|
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; } }
/**
|
break; } }
/**
|
* 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 */
|
* * @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';
| { $ext_filepath = $this->extension_manager->get_extension_path($this->ext_name); $metadata_filepath = $this->phpbb_root_path . $ext_filepath . 'composer.json';
|
Line 150 | Line 140 |
---|
if (!file_exists($this->metadata_file)) { throw new \phpbb\extension\exception($this->user->lang('FILE_NOT_FOUND', $this->metadata_file));
|
if (!file_exists($this->metadata_file)) { 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)) { throw new \phpbb\extension\exception($this->user->lang('FILE_NOT_FOUND', $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 (!($file_contents = file_get_contents($this->metadata_file))) { throw new \phpbb\extension\exception($this->user->lang('FILE_CONTENT_ERR', $this->metadata_file));
|
Line 179 | Line 154 |
---|
array_walk_recursive($metadata, array($this, 'sanitize_json')); $this->metadata = $metadata;
|
array_walk_recursive($metadata, array($this, 'sanitize_json')); $this->metadata = $metadata;
|
return true; }
| |
}
/**
| }
/**
|
Line 193 | Line 165 |
---|
public function sanitize_json(&$value, $key) { $value = htmlspecialchars($value);
|
public function sanitize_json(&$value, $key) { $value = htmlspecialchars($value);
|
}
/** * This array handles the cleaning of the array * * @return array Contains the cleaned metadata array */ private function clean_metadata_array() { return $this->metadata;
| |
}
/**
| }
/**
|
Line 227 | Line 189 |
---|
switch ($name) { case 'all':
|
switch ($name) { case 'all':
|
$this->validate('display');
| |
$this->validate_enable();
|
$this->validate_enable();
|
break;
| // no break
|
case 'display': foreach ($fields as $field => $data)
| case 'display': foreach ($fields as $field => $data)
|
Line 287 | Line 247 |
---|
/** * This array handles the verification that this extension can be enabled on this board *
|
/** * 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
|
*/ 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. *
|
}
/** * 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() {
|
*/ 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 *
|
}
/** * 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'])) {
|
*/ 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;
| }
return true;
|
Line 329 | Line 292 |
---|
/** * Validates the contents of the php requirement field *
|
/** * 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'])) {
|
*/ 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;
| }
return true;
|
Line 358 | Line 322 |
---|
'META_LICENSE' => $this->metadata['license'],
'META_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? $this->metadata['require']['php'] : '',
|
'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' => (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'] : '', ));
| 'META_DISPLAY_NAME' => (isset($this->metadata['extra']['display-name'])) ? $this->metadata['extra']['display-name'] : '', ));
|