diff options
Diffstat (limited to 'Zotlabs/Lib/Config.php')
-rw-r--r-- | Zotlabs/Lib/Config.php | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/Zotlabs/Lib/Config.php b/Zotlabs/Lib/Config.php index 40d5cc246..5e735be34 100644 --- a/Zotlabs/Lib/Config.php +++ b/Zotlabs/Lib/Config.php @@ -36,7 +36,7 @@ class Config { if (! array_key_exists('config_loaded', App::$config[$family])) { $r = q("SELECT * FROM config WHERE cat = '%s'", dbesc($family)); - if ($r === false) { + if ($r === false && !App::$install) { sleep(3); $recursionCounter ++; if ($recursionCounter > 10) { @@ -44,7 +44,7 @@ class Config { } self::Load($family, $recursionCounter); } - else { + elseif (is_array($r)) { foreach ($r as $rr) { $k = $rr['k']; App::$config[$family][$k] = $rr['v']; @@ -72,7 +72,7 @@ class Config { */ public static function Set($family, $key, $value) { // manage array value - $dbvalue = ((is_array($value)) ? serialise($value) : $value); + $dbvalue = ((is_array($value)) ? 'json:' . json_encode($value) : $value); $dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue); if (self::Get($family, $key) === false || (! self::get_from_storage($family, $key))) { @@ -121,6 +121,7 @@ class Config { * @return mixed Return value or false on error or if not set */ public static function Get($family, $key, $default = false) { + if ((! array_key_exists($family, App::$config)) || (! array_key_exists('config_loaded', App::$config[$family]))) { self::Load($family); } @@ -130,11 +131,20 @@ class Config { return $default; } - return ((! is_array(App::$config[$family][$key])) && (preg_match('|^a:[0-9]+:{.*}$|s', App::$config[$family][$key])) - ? unserialize(App::$config[$family][$key]) - : App::$config[$family][$key] - ); - + $value = App::$config[$family][$key]; + + if (! is_array($value)) { + if (substr($value, 0, 5) == 'json:') { + return json_decode(substr($value, 5), true); + } else if (preg_match('|^a:[0-9]+:{.*}$|s', $value)) { + // Unserialize in inherently unsafe. Try to mitigate by not + // allowing unserializing objects. Only kept for backwards + // compatibility. JSON serialization should be prefered. + return unserialize($value, array('allowed_classes' => false)); + } else { + return $value; + } + } } return $default; |