From 00b1241dfcc4f991102ab51cefcb4d5ef561e3f4 Mon Sep 17 00:00:00 2001 From: Diederik de Groot Date: Sun, 16 Feb 2020 01:30:52 +0100 Subject: [PATCH] Use Boolean in tree_base data Simplify config['subdirs'] substitution Signed-off-by: Diederik de Groot --- lib/config.php | 37 ++++++++++++++++++------------------- lib/resolver.php | 2 +- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/lib/config.php b/lib/config.php index c4435e4..decdff2 100644 --- a/lib/config.php +++ b/lib/config.php @@ -17,14 +17,14 @@ $base_config = Array( ) ); $tree_base = Array( - 'settings' => array('path' => 'tftproot', "strip" => 1), - 'wallpapers' => array('path' => 'tftproot', "strip" => 0), - 'ringtones' => array('path' => 'tftproot', "strip" => 1), - 'locales' => array('path' => 'tftproot', "strip" => 1), - 'firmware' => array('path' => 'tftproot', "strip" => 1), - 'languages' => array('path' => 'locales', "strip" => 0), - 'countries' => array('path' => 'locales', "strip" => 0), - 'default_language' => array('path' => 'locales', "strip" => 1), + 'settings' => array('path' => 'tftproot', "strip" => TRUE), + 'wallpapers' => array('path' => 'tftproot', "strip" => FALSE), + 'ringtones' => array('path' => 'tftproot', "strip" => TRUE), + 'locales' => array('path' => 'tftproot', "strip" => TRUE), + 'firmware' => array('path' => 'tftproot', "strip" => TRUE), + 'languages' => array('path' => 'locales', "strip" => FALSE), + 'countries' => array('path' => 'locales', "strip" => FALSE), + 'default_language' => array('path' => 'locales', "strip" => TRUE), ); # Merge config @@ -33,19 +33,18 @@ if (!empty($ini_array)) { $config = array_merge($base_config, $ini_array); } -# rewrite config['subdirs'] paths using tree_base data -# Not sure if this is a good way +# build new config['subdirs'] paths substituting bases from tree_base foreach ($tree_base as $key => $value) { - if (!empty($config['subdirs'][$key])) { - if (substr($config['subdirs'][$key], 0, 1) !== "/") { - $path = $config['subdirs'][$value['path']].'/'.$config['subdirs'][$key]; - $config['subdirs'][$key] = $path; + $tmp = $config; + if (!empty($tmp['subdirs'][$key])) { + if (substr($tmp['subdirs'][$key], 0, 1) !== "/") { + if (is_array($tmp['subdirs'][$value['path']])) { + $path = $tmp['subdirs'][$value['path']]['path'].'/'.$tmp['subdirs'][$key]; + } else { + $path = $tmp['subdirs'][$value['path']].'/'.$tmp['subdirs'][$key]; + } } - } -} -foreach ($tree_base as $key => $value) { - if (!empty($config['subdirs'][$key])) { - $config['subdirs'][$key] = array('path' => $config['subdirs'][$key], 'strip' => $value['strip']); + $config['subdirs'][$key] = array('path' => $path, 'strip' => $value['strip']); } } diff --git a/lib/resolver.php b/lib/resolver.php index 1c1f057..5be4c05 100755 --- a/lib/resolver.php +++ b/lib/resolver.php @@ -56,7 +56,7 @@ class Resolver { $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $file) { if ($file->isFile()) { - if ($value['strip'] === 1) { + if ($value['strip']) { $this->addFile($file->getFileName(), $file->getPathname()); } else { $subdir = basename(dirname($file->getPathname()));