mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-01 20:19:13 +02:00
[ticket/10824] Make styles use composer.json files
PHPBB3-10824
This commit is contained in:
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();
|
||||
|
5
phpBB/phpbb/cache/service.php
vendored
5
phpBB/phpbb/cache/service.php
vendored
@ -344,7 +344,7 @@ class service
|
||||
$parsed_array = array();
|
||||
}
|
||||
|
||||
$filename = $this->phpbb_root_path . 'styles/' . $style['style_path'] . '/style.cfg';
|
||||
$filename = $this->phpbb_root_path . 'styles/' . $style['style_path'] . '/composer.json';
|
||||
|
||||
if (!file_exists($filename))
|
||||
{
|
||||
@ -354,7 +354,8 @@ class service
|
||||
if (!isset($parsed_array['filetime']) || (($this->config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime'])))
|
||||
{
|
||||
// Re-parse cfg file
|
||||
$parsed_array = parse_cfg_file($filename);
|
||||
$json = file_get_contents($filename);
|
||||
$parsed_array = json_decode($json, true);
|
||||
$parsed_array['filetime'] = @filemtime($filename);
|
||||
|
||||
$this->driver->put('_cfg_' . $style['style_path'], $parsed_array);
|
||||
|
@ -69,10 +69,11 @@ class style_update_p1 extends \phpbb\db\migration\migration
|
||||
$skip_dirs = array('.', '..', 'prosilver');
|
||||
foreach ($iterator as $fileinfo)
|
||||
{
|
||||
if ($fileinfo->isDir() && !in_array($fileinfo->getFilename(), $skip_dirs) && file_exists($fileinfo->getPathname() . '/style.cfg'))
|
||||
if ($fileinfo->isDir() && !in_array($fileinfo->getFilename(), $skip_dirs) && file_exists($fileinfo->getPathname() . '/composer.json'))
|
||||
{
|
||||
$style_cfg = parse_cfg_file($fileinfo->getPathname() . '/style.cfg');
|
||||
if (isset($style_cfg['phpbb_version']) && version_compare($style_cfg['phpbb_version'], '3.1.0-dev', '>='))
|
||||
$json = file_get_contents($fileinfo->getPathname() . '/composer.json');
|
||||
$style_data = json_decode($json, true);
|
||||
if (isset($style_data['extra']['phpbb-version']) && version_compare($style_data['extra']['phpbb-version'], '3.1.0-dev', '>='))
|
||||
{
|
||||
// 3.1 style
|
||||
$available_styles[] = $fileinfo->getFilename();
|
||||
|
@ -49,11 +49,8 @@ class style_update extends \phpbb\db\migration\migration
|
||||
// Install prosilver if no style is available and prosilver can be installed
|
||||
if (empty($style_paths) && in_array('prosilver', $styles))
|
||||
{
|
||||
// Try to parse config file
|
||||
$cfg = parse_cfg_file($this->phpbb_root_path . 'styles/prosilver/style.cfg');
|
||||
|
||||
// Stop running this if prosilver cfg file can't be read
|
||||
if (empty($cfg))
|
||||
// Stop running this if prosilver composer.json file can't be read
|
||||
if (file_exists($this->phpbb_root_path . 'styles/prosilver/composer.json'))
|
||||
{
|
||||
throw new \RuntimeException('No styles available and could not fall back to prosilver.');
|
||||
}
|
||||
@ -123,7 +120,7 @@ class style_update extends \phpbb\db\migration\migration
|
||||
continue;
|
||||
}
|
||||
|
||||
if (file_exists("{$dir}/style.cfg"))
|
||||
if (file_exists("{$dir}/composer.json"))
|
||||
{
|
||||
$styles[] = $file;
|
||||
}
|
||||
|
29
phpBB/styles/prosilver/composer.json
Normal file
29
phpBB/styles/prosilver/composer.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "prosilver",
|
||||
"description": "phpBB Forum Software default style",
|
||||
"type": "phpbb-style",
|
||||
"version": "3.2.0-a1-dev",
|
||||
"homepage": "https://www.phpbb.com",
|
||||
"license": "GPL-2.0",
|
||||
"authors": [
|
||||
{
|
||||
"name": "phpBB Limited",
|
||||
"email": "operations@phpbb.com",
|
||||
"homepage": "https://www.phpbb.com/go/authors"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://tracker.phpbb.com",
|
||||
"forum": "https://www.phpbb.com/community/",
|
||||
"wiki": "https://wiki.phpbb.com",
|
||||
"irc": "irc://irc.freenode.org/phpbb"
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"extra": {
|
||||
"display-name": "prosilver",
|
||||
"parent-style": "prosilver",
|
||||
"phpbb-version": "3.2.0-a1-dev"
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
#
|
||||
# phpBB Style Configuration File
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# At the left is the name, please do not change this
|
||||
# At the right the value is entered
|
||||
#
|
||||
# Values get trimmed, if you want to add a space in front or at the end of
|
||||
# the value, then enclose the value with single or double quotes.
|
||||
# Single and double quotes do not need to be escaped.
|
||||
#
|
||||
#
|
||||
|
||||
# General Information about this style
|
||||
name = prosilver
|
||||
copyright = © phpBB Limited, 2007
|
||||
style_version = 4.0.0-a1-dev
|
||||
phpbb_version = 4.0.0-a1-dev
|
||||
|
||||
# Defining a different template bitfield
|
||||
# template_bitfield = //g=
|
||||
|
||||
# Parent style
|
||||
# Set value to empty or to this style's name if this style does not have a parent style
|
||||
parent = prosilver
|
Loading…
x
Reference in New Issue
Block a user