diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index fc33519882..1b22caca93 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -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; } /** diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 72df25cc03..10c62ed3ea 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -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(); diff --git a/phpBB/phpbb/cache/service.php b/phpBB/phpbb/cache/service.php index 2d4e55bfbb..982ff84ee6 100644 --- a/phpBB/phpbb/cache/service.php +++ b/phpBB/phpbb/cache/service.php @@ -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); diff --git a/phpBB/phpbb/db/migration/data/v310/style_update_p1.php b/phpBB/phpbb/db/migration/data/v310/style_update_p1.php index a7e30a9cb7..2b3fc0b670 100644 --- a/phpBB/phpbb/db/migration/data/v310/style_update_p1.php +++ b/phpBB/phpbb/db/migration/data/v310/style_update_p1.php @@ -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(); diff --git a/phpBB/phpbb/db/migration/data/v31x/style_update.php b/phpBB/phpbb/db/migration/data/v31x/style_update.php index a5f99b5d28..36f1209c71 100644 --- a/phpBB/phpbb/db/migration/data/v31x/style_update.php +++ b/phpBB/phpbb/db/migration/data/v31x/style_update.php @@ -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; } diff --git a/phpBB/styles/prosilver/composer.json b/phpBB/styles/prosilver/composer.json new file mode 100644 index 0000000000..77a52095d7 --- /dev/null +++ b/phpBB/styles/prosilver/composer.json @@ -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" + } +} diff --git a/phpBB/styles/prosilver/style.cfg b/phpBB/styles/prosilver/style.cfg deleted file mode 100644 index 0f795e6a60..0000000000 --- a/phpBB/styles/prosilver/style.cfg +++ /dev/null @@ -1,32 +0,0 @@ -# -# phpBB Style Configuration File -# -# This file is part of the phpBB Forum Software package. -# -# @copyright (c) phpBB Limited -# @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