From 380775540d98d89bbeeb0873563f299ef769ef25 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 10 May 2023 14:03:37 +0200 Subject: missing function --- include/items.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'include/items.php') diff --git a/include/items.php b/include/items.php index 989edf683..316ab4b23 100644 --- a/include/items.php +++ b/include/items.php @@ -1539,6 +1539,39 @@ function item_sign(&$item) { $item['item_verified'] = 1; } +/** + * @brief packs json data for storage. + * if it is a string, check if it is already json encoded. + * Otherwise, json encode it + * If it is an array, sanitise it and then json_encode it. + * + * @param array $arr + * @param string | intval $k + * + * @return string | null + */ + +function item_json_encapsulate($arr, $k) { + $retval = null; + + if (isset($arr[$k])) { + if (is_string($arr[$k])) { + // determine if it is json encoded already + $test = json_decode($arr[$k]); + // assume it is json encoded already + $retval = $arr[$k]; + if ($test === NULL) { + $retval = json_encode($arr[$k], JSON_UNESCAPED_SLASHES); + } + } + else { + activity_sanitise($arr[$k]); + $retval = json_encode($arr[$k], JSON_UNESCAPED_SLASHES); + } + } + + return $retval; +} /** * @brief Stores an item type record. -- cgit v1.2.3