From d981c6c9c66b3a81f0cf5c3f6a12747c56200c12 Mon Sep 17 00:00:00 2001 From: dg9vh Date: Tue, 10 May 2016 09:17:50 +0200 Subject: [PATCH] improved configuration-readout --- include/functions.php | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/include/functions.php b/include/functions.php index 415592d..b98c9cc 100644 --- a/include/functions.php +++ b/include/functions.php @@ -19,27 +19,33 @@ function getMMDVMConfig() { } function getCallsign($mmdvmconfigs) { - foreach ($mmdvmconfigs as $config) { - $pos = strpos($config, "Callsign"); - if ($pos !== false) { - return substr($config, 9); - } + return getConfigItem("general", "Callsign", $mmdvmconfigs); +} + +function getConfigItem($section, $key, $configs) { + $sectionpos = array_search("[" . $section . "]", $configs) + 1; + $len = count($configs); + while(startsWith($configs[$sectionpos],$key."=") === false && $sectionpos <= ($len) ) { + if (startsWith($configs[$sectionpos],"[")) { + return null; + } + $sectionpos++; } + + return substr($configs[$sectionpos], strlen($key) + 1); } function getEnabled ($mode, $mmdvmconfigs) { - $modepos = array_search($mode,$mmdvmconfigs); - while(strpos($mmdvmconfigs[$modepos],"Enable") === false ) { - $modepos++; - } - return substr($mmdvmconfigs[$modepos], 7); + return getConfigItem($mode, "Enable", $mmdvmconfigs); + } function showMode($mode, $mmdvmconfigs) { ?> ">