From 166ffedf04d355c73a1a8debb6e008b198a9bc94 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Tue, 12 Dec 2023 08:59:56 +0100 Subject: [PATCH] correctly merge themeoptions array to use correct image on login when using darkmode Signed-off-by: Michael Kaufmann --- lib/Froxlor/PhpHelper.php | 24 ++++++++++++++++++++---- lib/init.php | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/Froxlor/PhpHelper.php b/lib/Froxlor/PhpHelper.php index 7e08e2b5..a09947db 100644 --- a/lib/Froxlor/PhpHelper.php +++ b/lib/Froxlor/PhpHelper.php @@ -220,8 +220,11 @@ class PhpHelper if (is_dir($data_dirname)) { $data_dirhandle = opendir($data_dirname); while (false !== ($data_filename = readdir($data_dirhandle))) { - if ($data_filename != '.' && $data_filename != '..' && $data_filename != '' && substr($data_filename, - -4) == '.php') { + if ($data_filename != '.' + && $data_filename != '..' + && $data_filename != '' + && substr($data_filename, -4) == '.php' + ) { $data_files[] = $data_dirname . $data_filename; } } @@ -415,8 +418,8 @@ class PhpHelper */ public static function recursive_array_search( string $needle, - array $haystack, - array &$keys = [], + array $haystack, + array &$keys = [], string $currentKey = '' ): bool { foreach ($haystack as $key => $value) { @@ -557,4 +560,17 @@ class PhpHelper } return $tab . $str; } + + public static function array_merge_recursive_distinct(array &$array1, array &$array2) + { + $merged = $array1; + foreach ($array2 as $key => &$value) { + if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) { + $merged[$key] = self::array_merge_recursive_distinct($merged[$key], $value); + } else { + $merged[$key] = $value; + } + } + return $merged; + } } diff --git a/lib/init.php b/lib/init.php index 3b8e5b82..dacd548f 100644 --- a/lib/init.php +++ b/lib/init.php @@ -225,7 +225,7 @@ if (is_array($_themeoptions) && (!array_key_exists('variants', $_themeoptions) | } if (array_key_exists('global', $_themeoptions)) { - $_themeoptions['variants'][$themevariant] = array_merge_recursive($_themeoptions['variants'][$themevariant], $_themeoptions['global']); + $_themeoptions['variants'][$themevariant] = PhpHelper::array_merge_recursive_distinct($_themeoptions['global'], $_themeoptions['variants'][$themevariant]); } // check for custom header-graphic