From 32e5f32ceebfad710fddb752fde41eceedf24675 Mon Sep 17 00:00:00 2001 From: wangyuting Date: Tue, 12 Dec 2023 17:24:19 +0800 Subject: [PATCH] * Add unHTMLArray to zin encodeJsonWithRawJs. --- framework/helper.class.php | 25 +++++++++++++++++++++++++ lib/zin/core/h.class.php | 3 ++- lib/zin/utils/json.func.php | 9 +++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 lib/zin/utils/json.func.php diff --git a/framework/helper.class.php b/framework/helper.class.php index f616c7fae9..54125a10b4 100644 --- a/framework/helper.class.php +++ b/framework/helper.class.php @@ -608,6 +608,7 @@ function initTableData(array $items, array &$fieldList, object $model = null): a if(count($item->actions) > $maxActionCount) $maxActionCount = count($item->actions); } + if(isset($fieldList['actions'])) $fieldList['actions']['minWidth'] = $maxActionCount * 24 + 24; if($fieldList['actions']['minWidth'] < 48) $fieldList['actions']['minWidth'] = 48; @@ -744,3 +745,27 @@ function getVisions(): array $visionList = $lang->visionList; return array_intersect_key($visionList, $visions); } + +/** + * 对数据进行HTML实体转为字符。 + * Un HTML array. + * + * @param mixed $data + * @access public + * @return mixed + */ +function unHTMLArray($data, $processed = array()) +{ + if(is_string($data)) return htmlspecialchars_decode($data); + + if(is_array($data) || is_object($data)) + { + if(in_array($data, $processed, true)) { + return $data; + } + + $processed[] = $data; + foreach($data as &$value) $value = unHTMLArray($value, $processed); + } + return $data; +} diff --git a/lib/zin/core/h.class.php b/lib/zin/core/h.class.php index dfa2530b50..0a5c38e1e9 100644 --- a/lib/zin/core/h.class.php +++ b/lib/zin/core/h.class.php @@ -13,6 +13,7 @@ declare(strict_types=1); namespace zin; require_once dirname(__DIR__) . DS . 'utils' . DS . 'flat.func.php'; +require_once dirname(__DIR__) . DS . 'utils' . DS . 'json.func.php'; require_once __DIR__ . DS . 'wg.class.php'; require_once __DIR__ . DS . 'wg.func.php'; @@ -294,7 +295,7 @@ class h extends wg protected static function encodeJsonWithRawJs($data) { - $json = json_encode($data, JSON_UNESCAPED_UNICODE); + $json = \zin\utils\jsonEncode($data, JSON_UNESCAPED_UNICODE); if(empty($json) && (is_array($data) || is_object($data))) return '[]'; $json = str_replace('"RAWJS<', '', str_replace('>RAWJS"', '', $json)); diff --git a/lib/zin/utils/json.func.php b/lib/zin/utils/json.func.php new file mode 100644 index 0000000000..f3e6c3d116 --- /dev/null +++ b/lib/zin/utils/json.func.php @@ -0,0 +1,9 @@ +