From 388d30d2a6d1e5fc1f89c5ddbd147e160ed51160 Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 25 May 2015 02:12:48 +0100 Subject: [PATCH] updating to f0os function --- includes/definitions.inc.php | 93 +++++++++--------------------------- includes/functions.php | 1 + 2 files changed, 24 insertions(+), 70 deletions(-) diff --git a/includes/definitions.inc.php b/includes/definitions.inc.php index 564697dfec..65245dc739 100644 --- a/includes/definitions.inc.php +++ b/includes/definitions.inc.php @@ -13,82 +13,35 @@ if (!$database_link) } $database_db = mysql_select_db($config['db_name'], $database_link); -function create_array(&$arr,$string,$data,$type) -{ - // The original source of this code is from Stackoverflow (www.stackoverflow.com). - // http://stackoverflow.com/questions/9145902/create-variable-length-array-from-string - // Answer provided by stewe (http://stackoverflow.com/users/511300/stewe) - // This code is slightly adapted from the original posting. - - $a=explode(',',$string); - $last=count($a)-1; - $p=&$arr; - - foreach($a as $k=>$key) - { - if ($k==$last) - { - if($type == 'multi') - { - if (!isset($p[$key])) { - $p[$key]=explode(',',$data); +function mergecnf($obj) { + global $config; + $val = $obj['config_value']; + $obj = $obj['config_name']; + $obj = explode('.',$obj); + $str = ""; + foreach ($obj as $sub) { + if (!empty($sub)) { + $str .= "['".addslashes($sub)."']"; + } else { + $str .= "[]"; } - } - elseif($type == 'single') - { - if (!isset($p[$key])) { - $p[$key]=$data; - } - } } - else if (is_array($p)) - { -// $p[$key]=array(); + $str = '$config'.$str.' = '; + if (filter_var($val,FILTER_VALIDATE_INT)) { + $str .= "(int) '$val';"; + } elseif (filter_var($val,FILTER_VALIDATE_FLOAT)) { + $str .= "(float) '$val';"; + } elseif (filter_var($val,FILTER_VALIDATE_BOOLEAN)) { + $str .= "(boolean) '$val';"; + } else { + $str .= "'$val';"; } - $p=&$p[$key]; - } + eval('return array('.$str.')'); } -// We should be able to get config values from the DB now. -// Single field config values -$config_vars = get_defined_vars(); -$single_config = dbFetchRows("SELECT `config_name`, `config_value` FROM `config` WHERE `config_type` = 'single' AND `config_disabled` = '0'"); -foreach ($single_config as $config_data) -{ - $tmp_name = $config_data['config_name']; - if(!isset($config[$tmp_name])) - { - $config[$tmp_name] = stripslashes($config_data['config_value']); - } +foreach( dbFetchRows('select config_name,config_value from config') as $obj ) { + $config = array_merge_recursive($config,mergecnf($obj)); } -// Array config values -$config_vars = get_defined_vars(); -$array_config = dbFetchRows("SELECT `config_name`, GROUP_CONCAT( `config_value` ) AS `config_value` FROM `config` WHERE `config_type` = 'array' AND `config_disabled` = '0' GROUP BY config_name"); -foreach ($array_config as $config_data) -{ - $tmp_name = $config_data['config_name']; - if(!isset($config[$tmp_name])) - { - $config[$tmp_name] = explode(',',stripslashes($config_data['config_value'])); - } -} - -// Multi-array config values -$config_vars = get_defined_vars(); -$multi_array_config = dbFetchRows("SELECT `config_name`, GROUP_CONCAT( `config_value` ) AS `config_value` FROM `config` WHERE `config_type` = 'multi-array' AND `config_disabled` = '0' GROUP BY config_name"); -foreach ($multi_array_config as $config_data) -{ - create_array($config,$config_data['config_name'],stripslashes($config_data['config_value']),'multi'); -} - -// Single-array config values -$config_vars = get_defined_vars(); -$single_array_config = dbFetchRows("SELECT `config_name`, GROUP_CONCAT( `config_value` ) AS `config_value` FROM `config` WHERE `config_type` = 'single-array' AND `config_disabled` = '0' GROUP BY config_name"); -foreach ($single_array_config as $config_data) -{ - create_array($config,$config_data['config_name'],stripslashes($config_data['config_value']),'single'); -} -unset($config_vars); ///////////////////////////////////////////////////////// # NO CHANGES TO THIS FILE, IT IS NOT USER-EDITABLE # diff --git a/includes/functions.php b/includes/functions.php index d91259d0c1..618117efc0 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -28,6 +28,7 @@ include_once($config['install_dir'] . "/includes/syslog.php"); include_once($config['install_dir'] . "/includes/rewrites.php"); include_once($config['install_dir'] . "/includes/snmp.inc.php"); include_once($config['install_dir'] . "/includes/services.inc.php"); +echo $config['install_dir'] . "/includes/console_colour.php"; include_once($config['install_dir'] . "/includes/console_colour.php"); $console_color = new Console_Color2();