add array support to set_config and get_config
This commit is contained in:
parent
fba2056b1f
commit
10eb79a629
1 changed files with 10 additions and 5 deletions
15
boot.php
15
boot.php
|
@ -1243,8 +1243,10 @@ function get_config($family, $key, $instore = false) {
|
||||||
dbesc($key)
|
dbesc($key)
|
||||||
);
|
);
|
||||||
if(count($ret)) {
|
if(count($ret)) {
|
||||||
$a->config[$family][$key] = $ret[0]['v'];
|
// manage array value
|
||||||
return $ret[0]['v'];
|
$val = (preg_match("|^a:[0-9]+:{.*}$|", $ret[0]['v'])?unserialize( $ret[0]['v']):$ret[0]['v']);
|
||||||
|
$a->config[$family][$key] = $val;
|
||||||
|
return $val;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$a->config[$family][$key] = '!<unset>!';
|
$a->config[$family][$key] = '!<unset>!';
|
||||||
|
@ -1258,22 +1260,25 @@ function get_config($family, $key, $instore = false) {
|
||||||
|
|
||||||
if(! function_exists('set_config')) {
|
if(! function_exists('set_config')) {
|
||||||
function set_config($family,$key,$value) {
|
function set_config($family,$key,$value) {
|
||||||
|
|
||||||
global $a;
|
global $a;
|
||||||
|
|
||||||
|
// manage array value
|
||||||
|
$dbvalue = (is_array($value)?serialize($value):$value);
|
||||||
|
|
||||||
if(get_config($family,$key,true) === false) {
|
if(get_config($family,$key,true) === false) {
|
||||||
$a->config[$family][$key] = $value;
|
$a->config[$family][$key] = $value;
|
||||||
$ret = q("INSERT INTO `config` ( `cat`, `k`, `v` ) VALUES ( '%s', '%s', '%s' ) ",
|
$ret = q("INSERT INTO `config` ( `cat`, `k`, `v` ) VALUES ( '%s', '%s', '%s' ) ",
|
||||||
dbesc($family),
|
dbesc($family),
|
||||||
dbesc($key),
|
dbesc($key),
|
||||||
dbesc($value)
|
dbesc($dbvalue)
|
||||||
);
|
);
|
||||||
if($ret)
|
if($ret)
|
||||||
return $value;
|
return $value;
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = q("UPDATE `config` SET `v` = '%s' WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
|
$ret = q("UPDATE `config` SET `v` = '%s' WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
|
||||||
dbesc($value),
|
dbesc($dbvalue),
|
||||||
dbesc($family),
|
dbesc($family),
|
||||||
dbesc($key)
|
dbesc($key)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue