aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2023-05-10 14:03:37 +0200
committerMario Vavti <mario@mariovavti.com>2023-05-10 14:03:37 +0200
commit380775540d98d89bbeeb0873563f299ef769ef25 (patch)
tree2c2d2d47201a4bc05f3481b35417534ccd610b41
parent65e3b0dafdbec9d90c03ad1fb83360cd293bbe86 (diff)
downloadvolse-hubzilla-380775540d98d89bbeeb0873563f299ef769ef25.tar.gz
volse-hubzilla-380775540d98d89bbeeb0873563f299ef769ef25.tar.bz2
volse-hubzilla-380775540d98d89bbeeb0873563f299ef769ef25.zip
missing function
-rw-r--r--include/items.php33
1 files changed, 33 insertions, 0 deletions
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.