diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 1ab58c019da..7ba063f8f79 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -165,7 +165,7 @@ class Conf $varname = $partname.'_modules'; // TODO deprecated if (! is_array($this->$varname)) { $this->$varname = array(); } // TODO deprecated if (! is_array($this->modules_parts[$partname])) { $this->modules_parts[$partname] = array(); } - $arrValue = @unserialize($value); + $arrValue = dol_json_decode($value,true); if (is_array($arrValue) && ! empty($arrValue)) $value = $arrValue; else if (in_array($partname,array('login','menus','triggers'))) $value = '/'.$modulename.'/core/'.$partname.'/'; else if (in_array($partname,array('models'))) $value = '/'.$modulename.'/'; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 33d3961ce74..de0358270bd 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -145,6 +145,32 @@ if (! function_exists('json_decode')) } } +/** + * Function that encodes data in json format + * + * @param mixed $elements PHP object to json encode + * @return string Json encoded string + */ +function dol_json_encode($elements) +{ + return json_encode($elements); +} + +/** + * Function that decodes data from json format + * + * @param string $json Json encoded to PHP Object or Array + * @param bool $assoc False return an object, true return an array + * @return mixed Object or Array + */ +function dol_json_decode($json, $assoc=false) +{ + $out=''; + $out = unserialize($json); // For compatibility, test if serialized + if (empty($out)) $out = json_decode($json, $assoc); + return $out; +} + /** * Function to return value of a static property when class * name is dynamically defined (not hard coded). diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index ffb90f0ec9a..9773e518896 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -1277,12 +1277,12 @@ abstract class DolibarrModules // Can defined other parameters if (is_array($value['data']) && ! empty($value['data'])) { - $newvalue = serialize($value['data']); + $newvalue = dol_json_encode($value['data']); if (isset($value['entity'])) $entity = $value['entity']; } else { - $newvalue = serialize($value); + $newvalue = dol_json_encode($value); } }