Json 지원

git-svn-id: http://xe-core.googlecode.com/svn/sandbox@4744 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ngleader 2008-11-03 09:32:57 +00:00
parent 4939b325f8
commit 40326eec5f
7 changed files with 292 additions and 33 deletions

View file

@ -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");
}
}
?>