mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-07 02:31:40 +09:00
Json 지원
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@4744 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
4939b325f8
commit
40326eec5f
7 changed files with 292 additions and 33 deletions
|
|
@ -108,6 +108,7 @@
|
|||
|
||||
// Request Argument 설정
|
||||
$this->_setXmlRpcArgument();
|
||||
$this->_setJSONRequestArgument();
|
||||
$this->_setRequestArgument();
|
||||
$this->_setUploadedArgument();
|
||||
|
||||
|
|
@ -492,7 +493,7 @@
|
|||
/**
|
||||
* @brief response method를 강제로 지정 (기본으로는 request method를 이용함)
|
||||
*
|
||||
* method의 종류에는 HTML/ TEXT/ XMLRPC가 있음
|
||||
* method의 종류에는 HTML/ TEXT/ XMLRPC/ JSON가 있음
|
||||
**/
|
||||
function setResponseMethod($method = "HTML") {
|
||||
$oContext = &Context::getInstance();
|
||||
|
|
@ -517,12 +518,14 @@
|
|||
function _getResponseMethod() {
|
||||
if($this->response_method) return $this->response_method;
|
||||
|
||||
if($this->_getRequestMethod()=="XMLRPC") return "XMLRPC";
|
||||
$RequestMethod = $this->_getRequestMethod();
|
||||
if($RequestMethod=="XMLRPC") return "XMLRPC";
|
||||
else if($RequestMethod=="JSON") return "JSON";
|
||||
return "HTML";
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief request method가 어떤것인지 판단하여 저장 (GET/POST/XMLRPC)
|
||||
* @brief request method가 어떤것인지 판단하여 저장 (GET/POST/XMLRPC/JSON)
|
||||
**/
|
||||
function setRequestMethod($type) {
|
||||
$oContext = &Context::getInstance();
|
||||
|
|
@ -531,11 +534,12 @@
|
|||
|
||||
|
||||
/**
|
||||
* @brief request method가 어떤것인지 판단하여 저장 (GET/POST/XMLRPC)
|
||||
* @brief request method가 어떤것인지 판단하여 저장 (GET/POST/XMLRPC/JSON)
|
||||
**/
|
||||
function _setRequestMethod($type = '') {
|
||||
if($type) return $this->request_method = $type;
|
||||
|
||||
if(strpos($_SERVER['CONTENT_TYPE'],'json')) return $this->request_method = 'JSON';
|
||||
if($GLOBALS['HTTP_RAW_POST_DATA']) return $this->request_method = "XMLRPC";
|
||||
|
||||
$this->request_method = $_SERVER['REQUEST_METHOD'];
|
||||
|
|
@ -558,6 +562,22 @@
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief JSON 방식일 경우 처리
|
||||
**/
|
||||
function _setJSONRequestArgument() {
|
||||
if($this->_getRequestMethod() != 'JSON') return;
|
||||
// if(!$GLOBALS['HTTP_RAW_POST_DATA']) return;
|
||||
|
||||
$params = array();
|
||||
parse_str($GLOBALS['HTTP_RAW_POST_DATA'],$params);
|
||||
|
||||
foreach($params as $key => $val) {
|
||||
$val = $this->_filterRequestVar($key, $val);
|
||||
$this->_set($key, $val, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XML RPC일때
|
||||
**/
|
||||
|
|
@ -571,7 +591,6 @@
|
|||
|
||||
unset($params->attrs);
|
||||
if(!count($params)) return;
|
||||
|
||||
foreach($params as $key => $obj) {
|
||||
$val = $this->_filterRequestVar($key, $obj->body);
|
||||
$this->_set($key, $val, true);
|
||||
|
|
@ -629,7 +648,7 @@
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Request Method값을 return (GET/POST/XMLRPC);
|
||||
* @brief Request Method값을 return (GET/POST/XMLRPC/JSON);
|
||||
**/
|
||||
function getRequestMethod() {
|
||||
$oContext = &Context::getInstance();
|
||||
|
|
@ -637,7 +656,7 @@
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Request Method값을 return (GET/POST/XMLRPC);
|
||||
* @brief Request Method값을 return (GET/POST/XMLRPC/JSON);
|
||||
**/
|
||||
function _getRequestMethod() {
|
||||
return $this->request_method;
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@
|
|||
|
||||
// header 출력
|
||||
$this->_printHeader();
|
||||
|
||||
// request method에 따른 처리
|
||||
if(Context::getRequestMethod() == 'XMLRPC') $content = $this->_toXmlDoc($oModule);
|
||||
else if(Context::getRequestMethod() == 'JSON') $content = $this->_toJSON($oModule);
|
||||
else $content = $this->_toHTMLDoc($oModule);
|
||||
|
||||
// 요청방식에 따라 출력을 별도로
|
||||
if(Context::getResponseMethod()!="XMLRPC") {
|
||||
if(Context::getResponseMethod()=="HTML") {
|
||||
|
||||
Context::set('content', $content);
|
||||
|
||||
|
|
@ -93,6 +93,17 @@
|
|||
else print $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RequestMethod가 JSON이면 JSON 데이터로 컨텐츠 생성
|
||||
**/
|
||||
function _toJSON(&$oModule) {
|
||||
$variables = $oModule->getVariables();
|
||||
//if(function_exists('json_encode')) return json_encode($variables);
|
||||
//else return json_encode2($variables);
|
||||
return json_encode2($variables);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief RequestMethod가 XML이면 XML 데이터로 컨텐츠 생성
|
||||
**/
|
||||
|
|
@ -209,7 +220,8 @@
|
|||
***/
|
||||
function _printHeader() {
|
||||
if($this->gz_enabled) header("Content-Encoding: gzip");
|
||||
if(Context::getResponseMethod() != 'HTML') return $this->_printXMLHeader();
|
||||
if(Context::getResponseMethod() == 'JSON') return $this->_printJSONHeader();
|
||||
else if(Context::getResponseMethod() != 'HTML') return $this->_printXMLHeader();
|
||||
else return $this->_printHTMLHeader();
|
||||
}
|
||||
|
||||
|
|
@ -236,5 +248,17 @@
|
|||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief JSON header 출력 (utf8 고정)
|
||||
**/
|
||||
function _printJSONHeader() {
|
||||
header("Content-Type: text/html; charset=UTF-8");
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@
|
|||
}
|
||||
|
||||
// XMLRPC call 이 아니면 message view 객체 이용하도록
|
||||
if(Context::getRequestMethod() != 'XMLRPC') {
|
||||
if(Context::getRequestMethod() != 'XMLRPC' && Context::getRequestMethod() != 'JSON') {
|
||||
// 에러가 발생하였을시 처리
|
||||
if($this->error) {
|
||||
// message 모듈 객체를 생성해서 컨텐츠 생성
|
||||
|
|
|
|||
|
|
@ -350,7 +350,7 @@
|
|||
}
|
||||
|
||||
// view action이고 결과 출력이 XMLRPC일 경우 해당 모듈의 api method를 실행
|
||||
if(Context::getResponseMethod() == 'XMLRPC' && $this->module_info->module_type == 'view') {
|
||||
if((Context::getResponseMethod() == 'XMLRPC' || Context::getResponseMethod() == 'JSON') && $this->module_info->module_type == 'view') {
|
||||
$oAPI = getAPI($this->module_info->module, 'api');
|
||||
if(method_exists($oAPI, $this->act)) {
|
||||
$oAPI->{$this->act}($this);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue