From 3d35cfc50e8437ee6db8f7e6de4986c42347f63a Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Thu, 14 May 2020 16:40:06 +0800 Subject: [PATCH] remove Services/Json as default encoder.. --- Pman.php | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/Pman.php b/Pman.php index e421451..f449844 100644 --- a/Pman.php +++ b/Pman.php @@ -351,11 +351,23 @@ class Pman extends HTML_FlexyFramework_Page - + function jsencode($v, $header = false) + { + if ($header) { + header("Content-type: text/javascript"); + } + if (function_exists("json_encode")) { + return json_encode($v); + } + require_once 'Services/JSON.php'; + $js = new Services_JSON(); + echo $js->encodeUnsafe($v); + + + + } - - - + /** * ---------------- Global Tools --------------- @@ -487,12 +499,7 @@ class Pman extends HTML_FlexyFramework_Page exit; } - - - require_once 'Services/JSON.php'; - $json = new Services_JSON(); - - // log all errors!!! + // log all errors!!! $retHTML = isset($_SERVER['CONTENT_TYPE']) && preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']); @@ -509,14 +516,14 @@ class Pman extends HTML_FlexyFramework_Page if ($retHTML) { header('Content-type: text/html'); echo ""; - echo $json->encodeUnsafe(array( + echo $this->jsencode(array( 'success'=> false, 'errorMsg' => $str, 'message' => $str, // compate with exeption / loadexception. 'errors' => $errors ? $errors : true, // used by forms to flag errors. 'authFailure' => !empty($errors['authFailure']), - )); + ), false); echo ""; exit; } @@ -534,14 +541,14 @@ class Pman extends HTML_FlexyFramework_Page } - echo $json->encode(array( + echo $this->jsencode(array( 'success'=> false, 'data'=> array(), 'errorMsg' => $str, 'message' => $str, // compate with exeption / loadexception. 'errors' => $errors ? $errors : true, // used by forms to flag errors. 'authFailure' => !empty($errors['authFailure']), - )); + ),true); exit; @@ -558,8 +565,6 @@ class Pman extends HTML_FlexyFramework_Page echo "OK: " .$str . "\n"; exit; } - require_once 'Services/JSON.php'; - $json = new Services_JSON(); $retHTML = isset($_SERVER['CONTENT_TYPE']) && preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']); @@ -577,13 +582,13 @@ class Pman extends HTML_FlexyFramework_Page echo ""; // encode html characters so they can be read.. echo str_replace(array('<','>'), array('\u003c','\u003e'), - $json->encodeUnsafe(array('success'=> true, 'data' => $str))); + $this->jsencode(array('success'=> true, 'data' => $str), false)); echo ""; exit; } - echo $json->encode(array('success'=> true, 'data' => $str)); + echo $this->jsencode(array('success'=> true, 'data' => $str),true); exit; @@ -602,8 +607,7 @@ class Pman extends HTML_FlexyFramework_Page $total = count($ar); } $extra= $extra ? $extra : array(); - require_once 'Services/JSON.php'; - $json = new Services_JSON(); + $retHTML = isset($_SERVER['CONTENT_TYPE']) && preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']); @@ -622,7 +626,7 @@ class Pman extends HTML_FlexyFramework_Page echo ""; // encode html characters so they can be read.. echo str_replace(array('<','>'), array('\u003c','\u003e'), - $json->encodeUnsafe(array('success' => true, 'total'=> $total, 'data' => $ar) + $extra)); + $this->jsencode(array('success' => true, 'total'=> $total, 'data' => $ar) + $extra, false)); echo ""; exit; } @@ -647,7 +651,7 @@ class Pman extends HTML_FlexyFramework_Page } - $ret = $json->encode(array('success' => true, 'total'=> $total, 'data' => $ar) + $extra); + $ret = $this->jsencode(array('success' => true, 'total'=> $total, 'data' => $ar) + $extra,true); if (!empty($cachekey)) { -- 2.39.2