mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-01 20:19:13 +02:00
[ticket/10824] Use json_sanitzer::decode and improve migrations from pre 3.2
PHPBB3-10824
This commit is contained in:
parent
5dc2e500f5
commit
204f81c6f7
@ -1191,6 +1191,7 @@ class acp_styles
|
||||
* Read style composer.json file
|
||||
*
|
||||
* @param string $dir style directory
|
||||
*
|
||||
* @return array Style data
|
||||
* @throws \DomainException in case of error
|
||||
*/
|
||||
@ -1203,7 +1204,7 @@ class acp_styles
|
||||
}
|
||||
|
||||
$json = file_get_contents($this->styles_path . $dir . '/composer.json');
|
||||
$style_data = \phpbb\json_sanitizer::sanitize(json_decode($json, true));
|
||||
$style_data = \phpbb\json_sanitizer::decode($json);
|
||||
|
||||
if (!is_array($style_data) || !isset($style_data['type']) || $style_data['type'] !== 'phpbb-style')
|
||||
{
|
||||
|
4
phpBB/phpbb/cache/service.php
vendored
4
phpBB/phpbb/cache/service.php
vendored
@ -13,6 +13,8 @@
|
||||
|
||||
namespace phpbb\cache;
|
||||
|
||||
use phpbb\json_sanitizer;
|
||||
|
||||
/**
|
||||
* Class for grabbing/handling cached entries
|
||||
*/
|
||||
@ -355,7 +357,7 @@ class service
|
||||
{
|
||||
// Re-parse cfg file
|
||||
$json = file_get_contents($filename);
|
||||
$parsed_array = json_decode($json, true);
|
||||
$parsed_array = json_sanitizer::decode($json);
|
||||
$parsed_array['filetime'] = @filemtime($filename);
|
||||
|
||||
$this->driver->put('_cfg_' . $style['style_path'], $parsed_array);
|
||||
|
@ -13,6 +13,8 @@
|
||||
|
||||
namespace phpbb\db\migration\data\v310;
|
||||
|
||||
use phpbb\json_sanitizer;
|
||||
|
||||
class style_update_p1 extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
@ -69,14 +71,26 @@ 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() . '/composer.json'))
|
||||
if ($fileinfo->isDir() && !in_array($fileinfo->getFilename(), $skip_dirs))
|
||||
{
|
||||
$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', '>='))
|
||||
if (file_exists($fileinfo->getPathname() . '/style.cfg'))
|
||||
{
|
||||
// 3.1 style
|
||||
$available_styles[] = $fileinfo->getFilename();
|
||||
$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', '>='))
|
||||
{
|
||||
// 3.1 & 3.2 style
|
||||
$available_styles[] = $fileinfo->getFilename();
|
||||
}
|
||||
}
|
||||
else if (file_exists($fileinfo->getPathname() . '/composer.json'))
|
||||
{
|
||||
$json = file_get_contents($fileinfo->getPathname() . '/composer.json');
|
||||
$style_data = json_sanitizer::decode($json);
|
||||
if (isset($style_data['extra']['phpbb-version']) && version_compare($style_data['extra']['phpbb-version'], '3.3.0-dev', '>='))
|
||||
{
|
||||
// 3.3 style
|
||||
$available_styles[] = $fileinfo->getFilename();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,8 +49,11 @@ 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))
|
||||
{
|
||||
// Stop running this if prosilver composer.json file can't be read
|
||||
if (file_exists($this->phpbb_root_path . 'styles/prosilver/composer.json'))
|
||||
// Try to parse config file
|
||||
$cfg = parse_cfg_file($this->phpbb_root_path . 'styles/prosilver/style.cfg');
|
||||
|
||||
// Stop running this if both prosilver cfg file and composer.json file can't be read
|
||||
if (empty($cfg) && !file_exists($this->phpbb_root_path . 'styles/prosilver/composer.json'))
|
||||
{
|
||||
throw new \RuntimeException('No styles available and could not fall back to prosilver.');
|
||||
}
|
||||
@ -120,7 +123,7 @@ class style_update extends \phpbb\db\migration\migration
|
||||
continue;
|
||||
}
|
||||
|
||||
if (file_exists("{$dir}/composer.json"))
|
||||
if (file_exists("{$dir}/composer.json") || file_exists("{$dir}/style.cfg"))
|
||||
{
|
||||
$styles[] = $file;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
namespace phpbb\language;
|
||||
|
||||
use phpbb\json_sanitizer;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
/**
|
||||
@ -54,7 +55,7 @@ class language_file_helper
|
||||
foreach ($finder as $file)
|
||||
{
|
||||
$json = $file->getContents();
|
||||
$data = \phpbb\json_sanitizer::sanitize(json_decode($json, true));
|
||||
$data = json_sanitizer::decode($json);
|
||||
|
||||
$available_languages[] = $this->get_language_data_from_json($data);
|
||||
}
|
||||
@ -71,7 +72,7 @@ class language_file_helper
|
||||
public function get_language_data_from_composer_file($path)
|
||||
{
|
||||
$json_data = file_get_contents($path);
|
||||
return $this->get_language_data_from_json(json_decode($json_data, true));
|
||||
return $this->get_language_data_from_json(json_sanitizer::decode($json_data));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,7 +102,6 @@ class language_file_helper
|
||||
|
||||
return array(
|
||||
'iso' => $data['extra']['language-iso'],
|
||||
|
||||
'name' => $data['extra']['english-name'],
|
||||
'local_name' => $data['extra']['local-name'],
|
||||
'author' => implode(', ', $authors),
|
||||
|
@ -390,7 +390,7 @@ class version_helper
|
||||
}
|
||||
|
||||
// Sanitize any data we retrieve from a server
|
||||
$info = \phpbb\json_sanitizer::sanitize(json_decode($info, true));
|
||||
$info = json_sanitizer::decode($info);
|
||||
|
||||
if (empty($info['stable']) && empty($info['unstable']))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user