PublicRecord 함수 수정, json_encode, json_deocde를 Json로 통합

This commit is contained in:
2018-04-01 19:16:00 +09:00
parent 1f5f7e3591
commit 6ee8066c80
15 changed files with 47 additions and 38 deletions
+2 -2
View File
@@ -65,12 +65,12 @@ $rootDB->insert('member_log', [
'member_no'=>$userID, 'member_no'=>$userID,
'date'=>$nowDate, 'date'=>$nowDate,
'action_type'=>'reg', 'action_type'=>'reg',
'action'=>json_encode([ 'action'=>Json::encode([
'type'=>'none', 'type'=>'none',
'aux'=>'admin', 'aux'=>'admin',
'id'=>$username, 'id'=>$username,
'name'=>$nickname 'name'=>$nickname
], JSON_UNESCAPED_UNICODE) ])
]); ]);
Json::die([ Json::die([
+3 -3
View File
@@ -175,7 +175,7 @@ function getGeneralPublicRecordRecent($count) {
return join('<br>', $texts); return join('<br>', $texts);
} }
function getGeneralPublicRecordWithDate($count, $year, $month, $isFirst=0) { function getGeneralPublicRecordWithDate($year, $month) {
$db = DB::db(); $db = DB::db();
$texts = []; $texts = [];
@@ -225,10 +225,10 @@ function LogHistory($isFirst=0) {
$year = $map['year']; $year = $map['year'];
$month = $map['month']; $month = $map['month'];
$map_json = json_encode($map, JSON_UNESCAPED_UNICODE); $map_json = Json::encode($map);
$log = getWorldHistoryWithDate($year, $month); $log = getWorldHistoryWithDate($year, $month);
$genlog = getGeneralPublicRecordWithDate(50, $year, $month, $isFirst); $genlog = getGeneralPublicRecordWithDate($year, $month);
$nationStr = ""; $nationStr = "";
$powerStr = ""; $powerStr = "";
+1 -1
View File
@@ -34,7 +34,7 @@ function getHistoryMap($year, $month){
return ['result'=>false, 'reason'=>'연감이 저장되지 않음']; return ['result'=>false, 'reason'=>'연감이 저장되지 않음'];
} }
return json_decode($map, true);//까짓거 json_decode, json_encode 두번하지 뭐. return Json::decode($map);//까짓거 json_decode, json_encode 두번하지 뭐.
} }
/** /**
+4 -4
View File
@@ -130,7 +130,7 @@ function sendRawMessage($msgType, $isSender, $mailbox, $src, $dest, $msg, $date,
unset($msgOption['alert']); unset($msgOption['alert']);
} }
DB::db()->insert('message', array( DB::db()->insert('message', [
'address' => $dest, 'address' => $dest,
'type' => $msgType, 'type' => $msgType,
'is_sender' => $isSender, 'is_sender' => $isSender,
@@ -138,13 +138,13 @@ function sendRawMessage($msgType, $isSender, $mailbox, $src, $dest, $msg, $date,
'dest' => $dest['id'], 'dest' => $dest['id'],
'time' => $date, 'time' => $date,
'valid_until' => $validUntil, 'valid_until' => $validUntil,
'message' => json_encode(Util::eraseNullValue([ 'message' => Json::encode([
'src' => $src, 'src' => $src,
'dest' =>$dest, 'dest' =>$dest,
'text' => $msg, 'text' => $msg,
'option' => $msgOption 'option' => $msgOption
])) ], Json::DELETE_NULL)
)); ]);
} }
function sendMessage($msgType, $src, $dest, $msg, $date = null, $validUntil = null, $msgOption = null){ function sendMessage($msgType, $src, $dest, $msg, $date = null, $validUntil = null, $msgOption = null){
+3 -3
View File
@@ -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); $msgAction = Util::array_get($msgOption['action'], null);
$messageInfo['option'] = $msgOption; $messageInfo['option'] = $msgOption;
$msgSrc = json_decode($messageInfo['src']); $msgSrc = Json::decode($messageInfo['src']);
$messageInfo['src'] = $msgSrc; $messageInfo['src'] = $msgSrc;
$msgDest = json_decode($messageInfo['dest']); $msgDest = Json::decode($messageInfo['dest']);
$messageInfo['dest'] = $msgDest; $messageInfo['dest'] = $msgDest;
if (!$msgAction) { if (!$msgAction) {
+2 -2
View File
@@ -32,7 +32,7 @@ if(!$db->affectedRows()){
$db->insert('member_log', [ $db->insert('member_log', [
'member_no'=>$session->userID, 'member_no'=>$session->userID,
'action_type'=>'change_pw', 'action_type'=>'change_pw',
'action'=>json_encode([ 'action'=>Json::encode([
'type'=>'plain', 'type'=>'plain',
'result'=>false 'result'=>false
]) ])
@@ -47,7 +47,7 @@ if(!$db->affectedRows()){
$db->insert('member_log', [ $db->insert('member_log', [
'member_no'=>$session->userID, 'member_no'=>$session->userID,
'action_type'=>'change_pw', 'action_type'=>'change_pw',
'action'=>json_encode([ 'action'=>Json::encode([
'type'=>'plain', 'type'=>'plain',
'result'=>true 'result'=>true
]) ])
+1 -1
View File
@@ -93,4 +93,4 @@ function doAdminPost($action, $notice, $server){
$response = doAdminPost($action, $notice, $server); $response = doAdminPost($action, $notice, $server);
echo json_encode($response); Json::die($response);
+2 -2
View File
@@ -100,11 +100,11 @@ RootDB::db()->insert('member_log', [
'member_no'=>$userID, 'member_no'=>$userID,
'date'=>$nowDate, 'date'=>$nowDate,
'action_type'=>'change_pw', 'action_type'=>'change_pw',
'action'=>json_encode([ 'action'=>Json::encode([
'type'=>'kakao', 'type'=>'kakao',
'no'=>$userID, 'no'=>$userID,
'token'=>$access_token 'token'=>$access_token
], JSON_UNESCAPED_UNICODE) ])
]); ]);
RootDB::db()->query("unlock tables"); RootDB::db()->query("unlock tables");
+3 -3
View File
@@ -108,7 +108,7 @@ $kakaoID = Util::array_get($signupResult['id']);
if(!$kakaoID && Util::array_get($signupResult['msg'])!='already registered'){ if(!$kakaoID && Util::array_get($signupResult['msg'])!='already registered'){
Json::die([ Json::die([
'result'=>false, 'result'=>false,
'reason'=>'카카오 로그인 과정 중 앱 연결 절차를 실패했습니다'.json_encode($signupResult) 'reason'=>'카카오 로그인 과정 중 앱 연결 절차를 실패했습니다'.Json::encode($signupResult)
]); ]);
} }
@@ -158,11 +158,11 @@ RootDB::db()->insert('member_log', [
'member_no'=>$userID, 'member_no'=>$userID,
'date'=>$nowDate, 'date'=>$nowDate,
'action_type'=>'reg', 'action_type'=>'reg',
'action'=>json_encode([ 'action'=>Json::encode([
'type'=>'kakao', 'type'=>'kakao',
'id'=>$kakaoID, 'id'=>$kakaoID,
'email'=>$email, 'name'=>$nickname 'email'=>$email, 'name'=>$nickname
], JSON_UNESCAPED_UNICODE) ])
]); ]);
Json::die([ Json::die([
+1 -1
View File
@@ -37,7 +37,7 @@ else{
die('알 수 없는 에러:'.$me['msg']); die('알 수 없는 에러:'.$me['msg']);
} }
$_SESSION['tmpx'] = json_encode($result,JSON_UNESCAPED_UNICODE); $_SESSION['tmpx'] = Json::encode($result);
//echo "<br>\n"; //echo "<br>\n";
$me = $restAPI->meWithEmail(); $me = $restAPI->meWithEmail();
+18 -9
View File
@@ -2,29 +2,38 @@
namespace sammo; namespace sammo;
class Json{ class Json{
public static function encode($value, $pretty = false){ const PRETTY = 1;
if($pretty){ const DELETE_NULL = 2;
$flag = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT; const NO_CACHE = 4;
public static function encode($value, $flag = 0){
$rawFlag = JSON_UNESCAPED_UNICODE;
if($flag & static::PRETTY){
$rawFlag |= JSON_PRETTY_PRINT;
} }
else{ if($flag & static::DELETE_NULL){
$flag = JSON_UNESCAPED_UNICODE; $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){ public static function decode($value){
return json_decode($value, true); 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()로 쪼개는게 낫지 않을까 생각해봄. //NOTE: REST 형식에 맞게, ok(), fail()로 쪼개는게 낫지 않을까 생각해봄.
if($noCache){ if($flag & static::NO_CACHE){
WebUtil::setHeaderNoCache(); WebUtil::setHeaderNoCache();
} }
header('Content-Type: application/json'); header('Content-Type: application/json');
echo Json::encode($value, $pretty); echo Json::encode($value, $flag);
if($die){ if($die){
die(); die();
} }
+1 -1
View File
@@ -28,7 +28,7 @@ class WebUtil{
$content = trim(file_get_contents("php://input")); $content = trim(file_get_contents("php://input"));
//Attempt to decode the incoming RAW post data from JSON. //Attempt to decode the incoming RAW post data from JSON.
$decoded = json_decode($content, true); $decoded = Json::decode($content);
$jsonError = json_last_error(); $jsonError = json_last_error();
+2 -2
View File
@@ -4,8 +4,8 @@ require('../twe/lib.php');
$jsonPost = WebUtil::parseJsonPost(); $jsonPost = WebUtil::parseJsonPost();
echo json_encode([ Json::die([
'result'=>true, 'result'=>true,
'reason'=>'success', 'reason'=>'success',
'msgID'=>1997 'msgID'=>1997
], JSON_UNESCAPED_UNICODE); ]);
+2 -2
View File
@@ -18,8 +18,8 @@ function relayJson($filepath, $noCache = true, $die = true){
header('Pragma: no-cache'); header('Pragma: no-cache');
} }
$json = json_decode(file_get_contents($filepath)); $json = Json::decode(file_get_contents($filepath));
echo json_encode($json,JSON_UNESCAPED_UNICODE); echo Json::encode($json);
if($die){ if($die){
die(); die();
+2 -2
View File
@@ -4,7 +4,7 @@ require('../twe/lib.php');
$jsonPost = WebUtil::parseJsonPost(); $jsonPost = WebUtil::parseJsonPost();
echo json_encode([ Json::die([
'result'=>true, 'result'=>true,
'reason'=>'success' 'reason'=>'success'
], JSON_UNESCAPED_UNICODE); ]);