mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-30 21:40:43 +02:00
[ticket/10824] Make styles use composer.json files
PHPBB3-10824
This commit is contained in:
committed by
Marc Alexander
parent
cd74556058
commit
a200446646
@@ -787,22 +787,26 @@ class acp_styles
|
||||
// Style is already installed
|
||||
continue;
|
||||
}
|
||||
$cfg = $this->read_style_cfg($dir);
|
||||
if ($cfg === false)
|
||||
|
||||
try
|
||||
{
|
||||
// Invalid style.cfg
|
||||
$style_data = $this->read_style_composer_file($dir);
|
||||
}
|
||||
catch (\DomainException $e)
|
||||
{
|
||||
// Invalid composer.json
|
||||
continue;
|
||||
}
|
||||
|
||||
// Style should be available for installation
|
||||
$parent = $cfg['parent'];
|
||||
$parent = $style_data['extra']['parent-style'];
|
||||
$style = array(
|
||||
'style_id' => 0,
|
||||
'style_name' => $cfg['name'],
|
||||
'style_copyright' => $cfg['copyright'],
|
||||
'style_name' => $style_data['name'],
|
||||
'style_copyright' => $style_data['license'],
|
||||
'style_active' => 0,
|
||||
'style_path' => $dir,
|
||||
'bbcode_bitfield' => $cfg['template_bitfield'],
|
||||
'bbcode_bitfield' => $style_data['extra']['template-bitfield'],
|
||||
'style_parent_id' => 0,
|
||||
'style_parent_tree' => '',
|
||||
// Extra values for styles list
|
||||
@@ -1107,7 +1111,7 @@ class acp_styles
|
||||
continue;
|
||||
}
|
||||
|
||||
if (file_exists("{$dir}/style.cfg"))
|
||||
if (file_exists("{$dir}/composer.json"))
|
||||
{
|
||||
$styles[] = $file;
|
||||
}
|
||||
@@ -1135,43 +1139,44 @@ class acp_styles
|
||||
}
|
||||
|
||||
/**
|
||||
* Read style configuration file
|
||||
*
|
||||
* @param string $dir style directory
|
||||
* @return array|bool Style data, false on error
|
||||
*/
|
||||
protected function read_style_cfg($dir)
|
||||
* Read style composer.json file
|
||||
*
|
||||
* @param string $dir style directory
|
||||
* @return array Style data
|
||||
* @throws \DomainException in case of error
|
||||
*/
|
||||
protected function read_style_composer_file($dir)
|
||||
{
|
||||
// This should never happen, we give them a red warning because of its relevance.
|
||||
if (!file_exists($this->styles_path . $dir . '/style.cfg'))
|
||||
if (!file_exists($this->styles_path . $dir . '/style.json'))
|
||||
{
|
||||
trigger_error($this->user->lang('NO_STYLE_CFG', $dir), E_USER_WARNING);
|
||||
}
|
||||
|
||||
static $required = array('name', 'phpbb_version', 'copyright');
|
||||
$json = file_get_contents($this->styles_path . $dir . '/composer.json');
|
||||
$style_data = json_decode($json, true);
|
||||
|
||||
$cfg = parse_cfg_file($this->styles_path . $dir . '/style.cfg');
|
||||
|
||||
// Check if it is a valid file
|
||||
foreach ($required as $key)
|
||||
if (!is_array($style_data) || !isset($style_data['type']) || $style_data['type'] !== 'phpbb-style')
|
||||
{
|
||||
if (!isset($cfg[$key]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
throw new \DomainException('NO_VALID_STYLE');
|
||||
}
|
||||
|
||||
if (!isset($style_data['extra']))
|
||||
{
|
||||
$style_data['extra'] = array();
|
||||
}
|
||||
|
||||
// Check data
|
||||
if (!isset($cfg['parent']) || !is_string($cfg['parent']) || $cfg['parent'] == $cfg['name'])
|
||||
if (!isset($style_data['extra']['parent-style']) || !is_string($style_data['extra']['parent-style']) || $style_data['extra']['parent-style'] === $style_data['name'])
|
||||
{
|
||||
$cfg['parent'] = '';
|
||||
$style_data['extra']['parent-style'] = '';
|
||||
}
|
||||
if (!isset($cfg['template_bitfield']))
|
||||
if (!isset($style_data['extra']['template-bitfield']))
|
||||
{
|
||||
$cfg['template_bitfield'] = $this->default_bitfield();
|
||||
$style_data['extra']['template-bitfield'] = $this->default_bitfield();
|
||||
}
|
||||
|
||||
return $cfg;
|
||||
return $style_data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -2669,8 +2669,13 @@ function build_hidden_fields($field_ary, $specialchar = false, $stripslashes = f
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse cfg file
|
||||
*/
|
||||
* Parse cfg file
|
||||
* @param string $filename
|
||||
* @param bool|array $lines
|
||||
* @return array
|
||||
*
|
||||
* @deprecated Will be removed in the future as *.cfg files are being replaced by composer.json files
|
||||
*/
|
||||
function parse_cfg_file($filename, $lines = false)
|
||||
{
|
||||
$parsed_items = array();
|
||||
|
Reference in New Issue
Block a user