diff --git a/f_install/j_create_admin.php b/f_install/j_create_admin.php index 1a08cd9f..43e268d2 100644 --- a/f_install/j_create_admin.php +++ b/f_install/j_create_admin.php @@ -65,12 +65,12 @@ $rootDB->insert('member_log', [ 'member_no'=>$userID, 'date'=>$nowDate, 'action_type'=>'reg', - 'action'=>json_encode([ + 'action'=>Json::encode([ 'type'=>'none', 'aux'=>'admin', 'id'=>$username, 'name'=>$nickname - ], JSON_UNESCAPED_UNICODE) + ]) ]); Json::die([ diff --git a/hwe/func_history.php b/hwe/func_history.php index 19443710..9609bb76 100644 --- a/hwe/func_history.php +++ b/hwe/func_history.php @@ -175,7 +175,7 @@ function getGeneralPublicRecordRecent($count) { return join('
', $texts); } -function getGeneralPublicRecordWithDate($count, $year, $month, $isFirst=0) { +function getGeneralPublicRecordWithDate($year, $month) { $db = DB::db(); $texts = []; @@ -225,10 +225,10 @@ function LogHistory($isFirst=0) { $year = $map['year']; $month = $map['month']; - $map_json = json_encode($map, JSON_UNESCAPED_UNICODE); + $map_json = Json::encode($map); $log = getWorldHistoryWithDate($year, $month); - $genlog = getGeneralPublicRecordWithDate(50, $year, $month, $isFirst); + $genlog = getGeneralPublicRecordWithDate($year, $month); $nationStr = ""; $powerStr = ""; diff --git a/hwe/func_map.php b/hwe/func_map.php index ff96dcee..575014c9 100644 --- a/hwe/func_map.php +++ b/hwe/func_map.php @@ -34,7 +34,7 @@ function getHistoryMap($year, $month){ return ['result'=>false, 'reason'=>'연감이 저장되지 않음']; } - return json_decode($map, true);//까짓거 json_decode, json_encode 두번하지 뭐. + return Json::decode($map);//까짓거 json_decode, json_encode 두번하지 뭐. } /** diff --git a/hwe/func_message.php b/hwe/func_message.php index 68d72367..24244c33 100644 --- a/hwe/func_message.php +++ b/hwe/func_message.php @@ -130,7 +130,7 @@ function sendRawMessage($msgType, $isSender, $mailbox, $src, $dest, $msg, $date, unset($msgOption['alert']); } - DB::db()->insert('message', array( + DB::db()->insert('message', [ 'address' => $dest, 'type' => $msgType, 'is_sender' => $isSender, @@ -138,13 +138,13 @@ function sendRawMessage($msgType, $isSender, $mailbox, $src, $dest, $msg, $date, 'dest' => $dest['id'], 'time' => $date, 'valid_until' => $validUntil, - 'message' => json_encode(Util::eraseNullValue([ + 'message' => Json::encode([ 'src' => $src, 'dest' =>$dest, 'text' => $msg, 'option' => $msgOption - ])) - )); + ], Json::DELETE_NULL) + ]); } function sendMessage($msgType, $src, $dest, $msg, $date = null, $validUntil = null, $msgOption = null){ diff --git a/hwe/j_msg_decide_opt.php b/hwe/j_msg_decide_opt.php index c28eb61a..25b3d18e 100644 --- a/hwe/j_msg_decide_opt.php +++ b/hwe/j_msg_decide_opt.php @@ -62,13 +62,13 @@ if ($validUntil < $date) { ]); } -$msgOption = json_decode(Util::array_get($messageInfo['option'], '{}')); +$msgOption = Json::decode(Util::array_get($messageInfo['option'], '{}')); $msgAction = Util::array_get($msgOption['action'], null); $messageInfo['option'] = $msgOption; -$msgSrc = json_decode($messageInfo['src']); +$msgSrc = Json::decode($messageInfo['src']); $messageInfo['src'] = $msgSrc; -$msgDest = json_decode($messageInfo['dest']); +$msgDest = Json::decode($messageInfo['dest']); $messageInfo['dest'] = $msgDest; if (!$msgAction) { diff --git a/i_entrance/j_change_password.php b/i_entrance/j_change_password.php index dd02cc7f..bcfd7029 100644 --- a/i_entrance/j_change_password.php +++ b/i_entrance/j_change_password.php @@ -32,7 +32,7 @@ if(!$db->affectedRows()){ $db->insert('member_log', [ 'member_no'=>$session->userID, 'action_type'=>'change_pw', - 'action'=>json_encode([ + 'action'=>Json::encode([ 'type'=>'plain', 'result'=>false ]) @@ -47,7 +47,7 @@ if(!$db->affectedRows()){ $db->insert('member_log', [ 'member_no'=>$session->userID, 'action_type'=>'change_pw', - 'action'=>json_encode([ + 'action'=>Json::encode([ 'type'=>'plain', 'result'=>true ]) diff --git a/i_entrance/j_server_change_status.php b/i_entrance/j_server_change_status.php index 18356c7c..ac0a3e17 100644 --- a/i_entrance/j_server_change_status.php +++ b/i_entrance/j_server_change_status.php @@ -93,4 +93,4 @@ function doAdminPost($action, $notice, $server){ $response = doAdminPost($action, $notice, $server); -echo json_encode($response); +Json::die($response); diff --git a/oauth_kakao/j_change_pw.php b/oauth_kakao/j_change_pw.php index e0ad9076..bbc08b93 100644 --- a/oauth_kakao/j_change_pw.php +++ b/oauth_kakao/j_change_pw.php @@ -100,11 +100,11 @@ RootDB::db()->insert('member_log', [ 'member_no'=>$userID, 'date'=>$nowDate, 'action_type'=>'change_pw', - 'action'=>json_encode([ + 'action'=>Json::encode([ 'type'=>'kakao', 'no'=>$userID, 'token'=>$access_token - ], JSON_UNESCAPED_UNICODE) + ]) ]); RootDB::db()->query("unlock tables"); diff --git a/oauth_kakao/j_join_process.php b/oauth_kakao/j_join_process.php index 69f1ab4b..7716e2c3 100644 --- a/oauth_kakao/j_join_process.php +++ b/oauth_kakao/j_join_process.php @@ -108,7 +108,7 @@ $kakaoID = Util::array_get($signupResult['id']); if(!$kakaoID && Util::array_get($signupResult['msg'])!='already registered'){ Json::die([ 'result'=>false, - 'reason'=>'카카오 로그인 과정 중 앱 연결 절차를 실패했습니다'.json_encode($signupResult) + 'reason'=>'카카오 로그인 과정 중 앱 연결 절차를 실패했습니다'.Json::encode($signupResult) ]); } @@ -158,11 +158,11 @@ RootDB::db()->insert('member_log', [ 'member_no'=>$userID, 'date'=>$nowDate, 'action_type'=>'reg', - 'action'=>json_encode([ + 'action'=>Json::encode([ 'type'=>'kakao', 'id'=>$kakaoID, 'email'=>$email, 'name'=>$nickname - ], JSON_UNESCAPED_UNICODE) + ]) ]); Json::die([ diff --git a/oauth_kakao/oauth.php b/oauth_kakao/oauth.php index a01c49a5..754d2ddc 100644 --- a/oauth_kakao/oauth.php +++ b/oauth_kakao/oauth.php @@ -37,7 +37,7 @@ else{ die('알 수 없는 에러:'.$me['msg']); } -$_SESSION['tmpx'] = json_encode($result,JSON_UNESCAPED_UNICODE); +$_SESSION['tmpx'] = Json::encode($result); //echo "
\n"; $me = $restAPI->meWithEmail(); diff --git a/src/sammo/Json.php b/src/sammo/Json.php index 703357ae..6e7df823 100644 --- a/src/sammo/Json.php +++ b/src/sammo/Json.php @@ -2,29 +2,38 @@ namespace sammo; class Json{ - public static function encode($value, $pretty = false){ - if($pretty){ - $flag = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT; + const PRETTY = 1; + const DELETE_NULL = 2; + const NO_CACHE = 4; + + public static function encode($value, $flag = 0){ + $rawFlag = JSON_UNESCAPED_UNICODE; + if($flag & static::PRETTY){ + $rawFlag |= JSON_PRETTY_PRINT; } - else{ - $flag = JSON_UNESCAPED_UNICODE; + if($flag & static::DELETE_NULL){ + $value = Util::eraseNullValue($value); } - return json_encode($value, $flag); + return json_encode($value, $rawFlag); + } + + public static function encodePack($value, $pretty = false){ + } public static function decode($value){ return json_decode($value, true); } - public static function die($value, $noCache = true, $pretty = false, $die = true){ + public static function die($value, $flag = NO_CACHE){ //NOTE: REST 형식에 맞게, ok(), fail()로 쪼개는게 낫지 않을까 생각해봄. - if($noCache){ + if($flag & static::NO_CACHE){ WebUtil::setHeaderNoCache(); } header('Content-Type: application/json'); - echo Json::encode($value, $pretty); + echo Json::encode($value, $flag); if($die){ die(); } diff --git a/src/sammo/WebUtil.php b/src/sammo/WebUtil.php index 8253fd29..7f18c7d3 100644 --- a/src/sammo/WebUtil.php +++ b/src/sammo/WebUtil.php @@ -28,7 +28,7 @@ class WebUtil{ $content = trim(file_get_contents("php://input")); //Attempt to decode the incoming RAW post data from JSON. - $decoded = json_decode($content, true); + $decoded = Json::decode($content); $jsonError = json_last_error(); diff --git a/tmp_msg/add_msg_dummy.php b/tmp_msg/add_msg_dummy.php index 253ab4fe..7315a93a 100644 --- a/tmp_msg/add_msg_dummy.php +++ b/tmp_msg/add_msg_dummy.php @@ -4,8 +4,8 @@ require('../twe/lib.php'); $jsonPost = WebUtil::parseJsonPost(); -echo json_encode([ +Json::die([ 'result'=>true, 'reason'=>'success', 'msgID'=>1997 -], JSON_UNESCAPED_UNICODE); \ No newline at end of file +]); \ No newline at end of file diff --git a/tmp_msg/json_result.php b/tmp_msg/json_result.php index 60016ba8..0d99d5d3 100644 --- a/tmp_msg/json_result.php +++ b/tmp_msg/json_result.php @@ -18,8 +18,8 @@ function relayJson($filepath, $noCache = true, $die = true){ header('Pragma: no-cache'); } - $json = json_decode(file_get_contents($filepath)); - echo json_encode($json,JSON_UNESCAPED_UNICODE); + $json = Json::decode(file_get_contents($filepath)); + echo Json::encode($json); if($die){ die(); diff --git a/tmp_msg/prompt_dummy.php b/tmp_msg/prompt_dummy.php index 6a0ebcdc..3718dff8 100644 --- a/tmp_msg/prompt_dummy.php +++ b/tmp_msg/prompt_dummy.php @@ -4,7 +4,7 @@ require('../twe/lib.php'); $jsonPost = WebUtil::parseJsonPost(); -echo json_encode([ +Json::die([ 'result'=>true, 'reason'=>'success' -], JSON_UNESCAPED_UNICODE); \ No newline at end of file +]); \ No newline at end of file