mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 01:01:41 +09:00
git-svn-id: http://xe-core.googlecode.com/svn/trunk@18 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
5efaa4d880
commit
9aa4e0dc3f
3 changed files with 594 additions and 543 deletions
|
|
@ -1,158 +1,164 @@
|
|||
<?php
|
||||
/**
|
||||
* @file : classes/xml/XmlJSFilter.class.php
|
||||
* @author : zero <zero@nzeo.com>
|
||||
* @desc : filter xml문서를 해석하여 js파일로 만듬
|
||||
* filter xml은 tpl 파일과 같은 위치에 있어야 함
|
||||
* <filter id='js function 이름'>
|
||||
* <field> <-- 폼 항목의 체크
|
||||
* <item target="name" required="true" minlength="1" maxlength="5"
|
||||
* filter="email,userid,alpha,number" reualto="target" />
|
||||
* </field>
|
||||
* <parameter> <-- 폼 항목을 조합하여 key=val 의 js array로 return, act는 필수
|
||||
* <item param="key" value="target" concat="'@',target2..." />
|
||||
* </parameter>
|
||||
* <response> <-- 서버에 ajax로 전송하여 받을 결과값
|
||||
* <item name="error" /> <-- error이름의 결과값을 받겠다는 것
|
||||
* </response>
|
||||
* </filter>
|
||||
*
|
||||
* - field
|
||||
* target = 폼 element의 이름
|
||||
* required = true/ false 꼭 있어야 하는지에 대한 체크
|
||||
* minlength, maxlength = 최소/최대 길이
|
||||
* filter = javascript로 체크하기 위한 체크 필터
|
||||
* email : email의 형식 ( aaa.aaa@aaa.com)
|
||||
* userid : 영문+숫자+_, 첫 글자는 영문, 소문자
|
||||
* alpha : 영문값만 허용
|
||||
* number : 숫자만 허용
|
||||
* equalto = target , 현재 폼과 지정 target의 값이 동일해야 함
|
||||
* - parameter
|
||||
* param = key : key를 이름으로 가지고 value의 값을 가지는 array 값 생성
|
||||
* value = target : target form element의 값을 가져옴
|
||||
* concat = str1,str2,target2... : 값들의 string 또는 form element value를 연결
|
||||
* - response
|
||||
* name = key : return받을 결과값의 변수명
|
||||
**/
|
||||
/**
|
||||
* @class XmlJsFilter
|
||||
* @author zero (zero@nzeo.com)
|
||||
* @brief filter xml문서를 해석하여 js파일로 만듬
|
||||
*
|
||||
* filter xml은 tpl 파일과 같은 위치에 있어야 함
|
||||
* <filter id='js function 이름'>
|
||||
* <field> <-- 폼 항목의 체크
|
||||
* <item target="name" required="true" minlength="1" maxlength="5"
|
||||
* filter="email,userid,alpha,number" reualto="target" />
|
||||
* </field>
|
||||
* <parameter> <-- 폼 항목을 조합하여 key=val 의 js array로 return, act는 필수
|
||||
* <item param="key" value="target" concat="'@',target2..." />
|
||||
* </parameter>
|
||||
* <response> <-- 서버에 ajax로 전송하여 받을 결과값
|
||||
* <item name="error" /> <-- error이름의 결과값을 받겠다는 것
|
||||
* </response>
|
||||
* </filter>
|
||||
*
|
||||
* - field
|
||||
* target = 폼 element의 이름
|
||||
* required = true/ false 꼭 있어야 하는지에 대한 체크
|
||||
* minlength, maxlength = 최소/최대 길이
|
||||
* filter = javascript로 체크하기 위한 체크 필터
|
||||
* email : email의 형식 ( aaa.aaa@aaa.com)
|
||||
* userid : 영문+숫자+_, 첫 글자는 영문, 소문자
|
||||
* alpha : 영문값만 허용
|
||||
* number : 숫자만 허용
|
||||
* equalto = target , 현재 폼과 지정 target의 값이 동일해야 함
|
||||
* - parameter
|
||||
* param = key : key를 이름으로 가지고 value의 값을 가지는 array 값 생성
|
||||
* value = target : target form element의 값을 가져옴
|
||||
* concat = str1,str2,target2... : 값들의 string 또는 form element value를 연결
|
||||
* - response
|
||||
* name = key : return받을 결과값의 변수명
|
||||
**/
|
||||
|
||||
class XmlJsFilter {
|
||||
var $compiled_path = './files/js_filter_compiled/';
|
||||
var $xml_file = NULL;
|
||||
var $js_file = NULL;
|
||||
class XmlJsFilter {
|
||||
var $compiled_path = './files/js_filter_compiled/'; ///< 컴파일된 캐시 파일이 놓일 위치
|
||||
var $xml_file = NULL; ///< 대상 xml 파일
|
||||
var $js_file = NULL; ///< 컴파일된 js 파일
|
||||
|
||||
// public void XmlJsFilter($path, $xml_file)/*{{{*/
|
||||
function XmlJsFilter($path, $xml_file) {
|
||||
$this->xml_file = sprintf("%s%s",$path, $xml_file);
|
||||
$this->js_file = $this->_getCompiledFileName($this->xml_file);
|
||||
}/*}}}*/
|
||||
/**
|
||||
* @brief constructor
|
||||
**/
|
||||
function XmlJsFilter($path, $xml_file) {
|
||||
$this->xml_file = sprintf("%s%s",$path, $xml_file);
|
||||
$this->js_file = $this->_getCompiledFileName($this->xml_file);
|
||||
}
|
||||
|
||||
// public void compile()/*{{{*/
|
||||
// 원 xml파일과 compiled된js파일의 시간 비교 및 유무 비교등을 처리
|
||||
function compile() {
|
||||
if(!file_exists($this->xml_file)) return;
|
||||
if(!file_exists($this->js_file)) $this->_compile();
|
||||
if(filectime($this->xml_file)>filectime($this->js_file)) $this->_compile();
|
||||
$this->_compile();
|
||||
Context::addJsFile($this->js_file);
|
||||
}/*}}}*/
|
||||
/**
|
||||
* @brief 원 xml파일과 compiled된js파일의 시간 비교 및 유무 비교등을 처리
|
||||
**/
|
||||
function compile() {
|
||||
if(!file_exists($this->xml_file)) return;
|
||||
if(!file_exists($this->js_file)) $this->_compile();
|
||||
if(filectime($this->xml_file)>filectime($this->js_file)) $this->_compile();
|
||||
$this->_compile();
|
||||
Context::addJsFile($this->js_file);
|
||||
}
|
||||
|
||||
// private void _compile()/*{{{*/
|
||||
// 실제 xml_file을 컴파일하여 js_file을 생성
|
||||
function _compile() {
|
||||
global $lang;
|
||||
/**
|
||||
* @brief 실제 xml_file을 컴파일하여 js_file을 생성
|
||||
**/
|
||||
function _compile() {
|
||||
global $lang;
|
||||
|
||||
// xml 파일을 읽음
|
||||
$buff = FileHandler::readFile($this->xml_file);
|
||||
// xml 파일을 읽음
|
||||
$buff = FileHandler::readFile($this->xml_file);
|
||||
|
||||
// xml parsing
|
||||
$oXml = new XmlParser();
|
||||
$xml_obj = $oXml->parse($buff);
|
||||
// xml parsing
|
||||
$oXml = new XmlParser();
|
||||
$xml_obj = $oXml->parse($buff);
|
||||
|
||||
// XmlJsFilter는 filter_id, field, parameter 3개의 데이터를 핸들링
|
||||
$filter_id = $xml_obj->filter->attrs->id;
|
||||
$confirm_msg_code = $xml_obj->filter->attrs->confirm_msg_code;
|
||||
$field_item = $xml_obj->filter->field->item;
|
||||
$parameter_item = $xml_obj->filter->parameter->item;
|
||||
$response_item = $xml_obj->filter->response->item;
|
||||
// XmlJsFilter는 filter_id, field, parameter 3개의 데이터를 핸들링
|
||||
$filter_id = $xml_obj->filter->attrs->id;
|
||||
$confirm_msg_code = $xml_obj->filter->attrs->confirm_msg_code;
|
||||
$field_item = $xml_obj->filter->field->item;
|
||||
$parameter_item = $xml_obj->filter->parameter->item;
|
||||
$response_item = $xml_obj->filter->response->item;
|
||||
|
||||
// 언어 입력을 위한 사용되는 필드 조사
|
||||
$target_list = array();
|
||||
// 언어 입력을 위한 사용되는 필드 조사
|
||||
$target_list = array();
|
||||
|
||||
// js function 을 만들기 시작
|
||||
$js_doc = sprintf("function %s(fo_obj, callback_user_func) {\n", $filter_id);
|
||||
$js_doc .= "\tvar oFilter = new XmlJsFilter(fo_obj, callback_user_func);\n";
|
||||
// js function 을 만들기 시작
|
||||
$js_doc = sprintf("function %s(fo_obj, callback_user_func) {\n", $filter_id);
|
||||
$js_doc .= "\tvar oFilter = new XmlJsFilter(fo_obj, callback_user_func);\n";
|
||||
|
||||
// field, 즉 체크항목의 script 생성
|
||||
$field_cnt = count($field_item);
|
||||
if($field_cnt) {
|
||||
foreach($field_item as $key =>$field_obj) {
|
||||
$attrs = $field_obj->attrs;
|
||||
$target = trim($attrs->target);
|
||||
if(!$target) continue;
|
||||
$required = $attrs->required=='true'?'true':'false';
|
||||
$minlength = $attrs->minlength>0?$attrs->minlength:'0';
|
||||
$maxlength = $attrs->maxlength>0?$attrs->maxlength:'0';
|
||||
$equalto = trim($attrs->equalto);
|
||||
$filter = $attrs->filter;
|
||||
// field, 즉 체크항목의 script 생성
|
||||
$field_cnt = count($field_item);
|
||||
if($field_cnt) {
|
||||
foreach($field_item as $key =>$field_obj) {
|
||||
$attrs = $field_obj->attrs;
|
||||
$target = trim($attrs->target);
|
||||
if(!$target) continue;
|
||||
$required = $attrs->required=='true'?'true':'false';
|
||||
$minlength = $attrs->minlength>0?$attrs->minlength:'0';
|
||||
$maxlength = $attrs->maxlength>0?$attrs->maxlength:'0';
|
||||
$equalto = trim($attrs->equalto);
|
||||
$filter = $attrs->filter;
|
||||
|
||||
$js_doc .= sprintf(
|
||||
$js_doc .= sprintf(
|
||||
"\toFilter.addFieldItem(\"%s\",%s,%s,%s,\"%s\",\"%s\");\n",
|
||||
$target, $required, $minlength, $maxlength, $equalto, $filter
|
||||
);
|
||||
);
|
||||
|
||||
if(!in_array($target, $target_list)) $target_list[] = $target;
|
||||
if(!in_array($target, $target_list)) $target_list[] = $target;
|
||||
}
|
||||
}
|
||||
|
||||
// 데이터를 만들기 위한 parameter script 생성
|
||||
$parameter_cnt = count($parameter_item);
|
||||
if($parameter_cnt) {
|
||||
foreach($parameter_item as $key =>$parameter_obj) {
|
||||
$attrs = $parameter_obj->attrs;
|
||||
$param = trim($attrs->param);
|
||||
$target = trim($attrs->target);
|
||||
if(!$param || !$target) continue;
|
||||
$target = htmlentities($target,ENT_QUOTES);
|
||||
$js_doc .= sprintf(
|
||||
"\toFilter.addParameterItem(\"%s\",\"%s\");\n",
|
||||
$param, $target
|
||||
);
|
||||
if(!in_array($param, $target_list)) $target_list[] = $param;
|
||||
}
|
||||
}
|
||||
|
||||
// response script 생성
|
||||
$response_cnt = count($response_item);
|
||||
for($i=0;$i<$response_cnt;$i++) {
|
||||
$attrs = $response_item[$i]->attrs;
|
||||
$name = $attrs->name;
|
||||
$js_doc .= sprintf("\toFilter.addResponseItem(\"%s\");\n", $name);
|
||||
}
|
||||
|
||||
if($confirm_msg_code) $js_doc .= sprintf("\treturn oFilter.proc(\"%s\");\n",str_replace('"','\"',$lang->{$confirm_msg_code}));
|
||||
else $js_doc .= sprintf("\treturn oFilter.proc();\n");
|
||||
$js_doc .= "}\n";
|
||||
|
||||
// form 필드 lang 값을 기록
|
||||
$target_cnt = count($target_list);
|
||||
for($i=0;$i<$target_cnt;$i++) {
|
||||
$target = $target_list[$i];
|
||||
$js_doc .= sprintf("alertMsg[\"%s\"] = \"%s\"\n", $target, str_replace("\"","\\\"",$lang->{$target}));
|
||||
}
|
||||
|
||||
// 에러 메세지를 기록
|
||||
foreach($lang->filter as $key => $val) {
|
||||
$js_doc .= sprintf("alertMsg[\"%s\"] = \"%s\";\n", $key, str_replace("\"","\\\"",$val));
|
||||
}
|
||||
|
||||
// js파일 생성
|
||||
FileHandler::writeFile($this->js_file, $js_doc);
|
||||
}
|
||||
}
|
||||
|
||||
// 데이터를 만들기 위한 parameter script 생성
|
||||
$parameter_cnt = count($parameter_item);
|
||||
if($parameter_cnt) {
|
||||
foreach($parameter_item as $key =>$parameter_obj) {
|
||||
$attrs = $parameter_obj->attrs;
|
||||
$param = trim($attrs->param);
|
||||
$target = trim($attrs->target);
|
||||
if(!$param || !$target) continue;
|
||||
$target = htmlentities($target,ENT_QUOTES);
|
||||
$js_doc .= sprintf(
|
||||
"\toFilter.addParameterItem(\"%s\",\"%s\");\n",
|
||||
$param, $target
|
||||
);
|
||||
if(!in_array($param, $target_list)) $target_list[] = $param;
|
||||
/**
|
||||
* @brief $xml_file로 compiled_xml_file이름을 return
|
||||
**/
|
||||
function _getCompiledFileName($xml_file) {
|
||||
return sprintf('%s%s.%s.compiled.js',$this->compiled_path, md5($xml_file),Context::getLangType());
|
||||
}
|
||||
}
|
||||
|
||||
// response script 생성
|
||||
$response_cnt = count($response_item);
|
||||
for($i=0;$i<$response_cnt;$i++) {
|
||||
$attrs = $response_item[$i]->attrs;
|
||||
$name = $attrs->name;
|
||||
$js_doc .= sprintf("\toFilter.addResponseItem(\"%s\");\n", $name);
|
||||
}
|
||||
|
||||
if($confirm_msg_code) $js_doc .= sprintf("\treturn oFilter.proc(\"%s\");\n",str_replace('"','\"',$lang->{$confirm_msg_code}));
|
||||
else $js_doc .= sprintf("\treturn oFilter.proc();\n");
|
||||
$js_doc .= "}\n";
|
||||
|
||||
// form 필드 lang 값을 기록
|
||||
$target_cnt = count($target_list);
|
||||
for($i=0;$i<$target_cnt;$i++) {
|
||||
$target = $target_list[$i];
|
||||
$js_doc .= sprintf("alertMsg[\"%s\"] = \"%s\"\n", $target, str_replace("\"","\\\"",$lang->{$target}));
|
||||
}
|
||||
|
||||
// 에러 메세지를 기록
|
||||
foreach($lang->filter as $key => $val) {
|
||||
$js_doc .= sprintf("alertMsg[\"%s\"] = \"%s\";\n", $key, str_replace("\"","\\\"",$val));
|
||||
}
|
||||
|
||||
// js파일 생성
|
||||
FileHandler::writeFile($this->js_file, $js_doc);
|
||||
}/*}}}*/
|
||||
|
||||
// private string _getCompiledFileName($xml_file) /*{{{*/
|
||||
// $xml_file로 compiled_xml_file이름을 return
|
||||
function _getCompiledFileName($xml_file) {
|
||||
return sprintf('%s%s.%s.compiled.js',$this->compiled_path, md5($xml_file),Context::getLangType());
|
||||
}/*}}}*/
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,111 +1,127 @@
|
|||
<?php
|
||||
/**
|
||||
* @file : classes/xml/XmlParser.class.php
|
||||
* @author : zero <zero@nzeo.com>
|
||||
* @desc : xmlrpc를 해석하여 object로 return 하는 simple xml parser
|
||||
**/
|
||||
/**
|
||||
* @class XmlParser
|
||||
* @author zero (zero@nzeo.com)
|
||||
* @brief xmlrpc를 해석하여 object로 return 하는 simple xml parser
|
||||
*
|
||||
* xml 데이터의 attribute중에 xml:lang=""이 있을 경우 지정된 lang\n
|
||||
* 값에 해당하는 것만 남기는 트릭이 적용됨.\n
|
||||
* 무슨 문제를 일으킬지는 현재 모르나 잘 동작하고 있음\n
|
||||
**/
|
||||
|
||||
class XmlParser {
|
||||
class XmlParser {
|
||||
|
||||
var $oParser = NULL;
|
||||
var $oParser = NULL; ///< xml parser
|
||||
|
||||
var $input = NULL;
|
||||
var $output = array();
|
||||
var $input = NULL; ///< input xml
|
||||
var $output = array(); ///< output object
|
||||
|
||||
var $lang = "en";
|
||||
var $lang = "en"; ///< 기본 언어타입
|
||||
|
||||
// public object loadXmlFile($filename)/*{{{*/
|
||||
function loadXmlFile($filename) {
|
||||
if(!file_exists($filename)) return;
|
||||
/**
|
||||
* @brief xml 파일을 로딩하여 parsing 처리 후 return
|
||||
**/
|
||||
function loadXmlFile($filename) {
|
||||
if(!file_exists($filename)) return;
|
||||
|
||||
$buff = FileHandler::readFile($filename);
|
||||
$buff = FileHandler::readFile($filename);
|
||||
|
||||
$oXmlParser = new XmlParser();
|
||||
return $oXmlParser->parse($buff);
|
||||
}/*}}}*/
|
||||
|
||||
// public void parse($input)/*{{{*/
|
||||
function parse($input = '') {
|
||||
$this->lang = Context::getLangType();
|
||||
|
||||
$this->input = $input?$input:$GLOBALS['HTTP_RAW_POST_DATA'];
|
||||
|
||||
// 지원언어 종류를 뽑음
|
||||
preg_match_all("/xml:lang=\"([^\"].+)\"/i", $this->input, $matches);
|
||||
|
||||
// xml:lang이 쓰였을 경우 지원하는 언어종류를 뽑음
|
||||
if(count($matches[1]) && $supported_lang = array_unique($matches[1])) {
|
||||
// supported_lang에 현재 접속자의 lang이 없으면 en이 있는지 확인하여 en이 있으면 en을 기본, 아니면 첫번째것을..
|
||||
if(!in_array($this->lang, $supported_lang)) {
|
||||
if(in_array('en', $supported_lang)) {
|
||||
$this->lang = 'en';
|
||||
} else {
|
||||
$this->lang = array_shift($supported_lang);
|
||||
}
|
||||
$oXmlParser = new XmlParser();
|
||||
return $oXmlParser->parse($buff);
|
||||
}
|
||||
// 특별한 언어가 지정되지 않았다면 언어체크를 하지 않음
|
||||
} else {
|
||||
unset($this->lang);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief xml 파싱
|
||||
**/
|
||||
function parse($input = '') {
|
||||
$this->lang = Context::getLangType();
|
||||
|
||||
$this->input = $input?$input:$GLOBALS['HTTP_RAW_POST_DATA'];
|
||||
|
||||
// 지원언어 종류를 뽑음
|
||||
preg_match_all("/xml:lang=\"([^\"].+)\"/i", $this->input, $matches);
|
||||
|
||||
// xml:lang이 쓰였을 경우 지원하는 언어종류를 뽑음
|
||||
if(count($matches[1]) && $supported_lang = array_unique($matches[1])) {
|
||||
// supported_lang에 현재 접속자의 lang이 없으면 en이 있는지 확인하여 en이 있으면 en을 기본, 아니면 첫번째것을..
|
||||
if(!in_array($this->lang, $supported_lang)) {
|
||||
if(in_array('en', $supported_lang)) {
|
||||
$this->lang = 'en';
|
||||
} else {
|
||||
$this->lang = array_shift($supported_lang);
|
||||
}
|
||||
}
|
||||
// 특별한 언어가 지정되지 않았다면 언어체크를 하지 않음
|
||||
} else {
|
||||
unset($this->lang);
|
||||
}
|
||||
|
||||
|
||||
$this->oParser = xml_parser_create();
|
||||
$this->oParser = xml_parser_create();
|
||||
|
||||
xml_set_object($this->oParser, $this);
|
||||
xml_set_element_handler($this->oParser, "_tagOpen", "_tagClosed");
|
||||
xml_set_character_data_handler($this->oParser, "_tagBody");
|
||||
xml_set_object($this->oParser, $this);
|
||||
xml_set_element_handler($this->oParser, "_tagOpen", "_tagClosed");
|
||||
xml_set_character_data_handler($this->oParser, "_tagBody");
|
||||
|
||||
xml_parse($this->oParser, $this->input);
|
||||
xml_parser_free($this->oParser);
|
||||
xml_parse($this->oParser, $this->input);
|
||||
xml_parser_free($this->oParser);
|
||||
|
||||
if(!count($this->output)) return;
|
||||
return array_shift($this->output);
|
||||
}/*}}}*/
|
||||
|
||||
// private void _tagOpen($parser, $node_name, $attrs)/*{{{*/
|
||||
function _tagOpen($parser, $node_name, $attrs) {
|
||||
$obj->node_name = strtolower($node_name);
|
||||
$obj->attrs = $this->_arrToObj($attrs);
|
||||
|
||||
array_push($this->output, $obj);
|
||||
}/*}}}*/
|
||||
|
||||
// private void _tagBody($parser, $body)/*{{{*/
|
||||
function _tagBody($parser, $body) {
|
||||
if(!trim($body)) return;
|
||||
$this->output[count($this->output)-1]->body .= $body;
|
||||
}/*}}}*/
|
||||
|
||||
// private void _tagClosed($parser, $node_name)/*{{{*/
|
||||
function _tagClosed($parser, $node_name) {
|
||||
$node_name = strtolower($node_name);
|
||||
$cur_obj = array_pop($this->output);
|
||||
$parent_obj = &$this->output[count($this->output)-1];
|
||||
if($this->lang&&$cur_obj->attrs->{'xml:lang'}&&$cur_obj->attrs->{'xml:lang'}!=$this->lang) return;
|
||||
if($this->lang&&$parent_obj->{$node_name}->attrs->{'xml:lang'}&&$parent_obj->{$node_name}->attrs->{'xml:lang'}!=$this->lang) return;
|
||||
|
||||
if($parent_obj->{$node_name}) {
|
||||
$tmp_obj = $parent_obj->{$node_name};
|
||||
if(is_array($tmp_obj)) {
|
||||
array_push($parent_obj->{$node_name}, $cur_obj);
|
||||
} else {
|
||||
$parent_obj->{$node_name} = array();
|
||||
array_push($parent_obj->{$node_name}, $tmp_obj);
|
||||
array_push($parent_obj->{$node_name}, $cur_obj);
|
||||
if(!count($this->output)) return;
|
||||
return array_shift($this->output);
|
||||
}
|
||||
} else {
|
||||
$parent_obj->{$node_name} = $cur_obj;
|
||||
}
|
||||
}/*}}}*/
|
||||
|
||||
// private void _arrToObj($arr)/*{{{*/
|
||||
function _arrToObj($arr) {
|
||||
if(!count($arr)) return;
|
||||
foreach($arr as $key => $val) {
|
||||
$key = strtolower($key);
|
||||
$output->{$key} = $val;
|
||||
}
|
||||
return $output;
|
||||
}/*}}}*/
|
||||
}
|
||||
/**
|
||||
* @brief 태그 오픈
|
||||
**/
|
||||
function _tagOpen($parser, $node_name, $attrs) {
|
||||
$obj->node_name = strtolower($node_name);
|
||||
$obj->attrs = $this->_arrToObj($attrs);
|
||||
|
||||
array_push($this->output, $obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief body 내용
|
||||
**/
|
||||
function _tagBody($parser, $body) {
|
||||
if(!trim($body)) return;
|
||||
$this->output[count($this->output)-1]->body .= $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 태그 닫음
|
||||
**/
|
||||
function _tagClosed($parser, $node_name) {
|
||||
$node_name = strtolower($node_name);
|
||||
$cur_obj = array_pop($this->output);
|
||||
$parent_obj = &$this->output[count($this->output)-1];
|
||||
if($this->lang&&$cur_obj->attrs->{'xml:lang'}&&$cur_obj->attrs->{'xml:lang'}!=$this->lang) return;
|
||||
if($this->lang&&$parent_obj->{$node_name}->attrs->{'xml:lang'}&&$parent_obj->{$node_name}->attrs->{'xml:lang'}!=$this->lang) return;
|
||||
|
||||
if($parent_obj->{$node_name}) {
|
||||
$tmp_obj = $parent_obj->{$node_name};
|
||||
if(is_array($tmp_obj)) {
|
||||
array_push($parent_obj->{$node_name}, $cur_obj);
|
||||
} else {
|
||||
$parent_obj->{$node_name} = array();
|
||||
array_push($parent_obj->{$node_name}, $tmp_obj);
|
||||
array_push($parent_obj->{$node_name}, $cur_obj);
|
||||
}
|
||||
} else {
|
||||
$parent_obj->{$node_name} = $cur_obj;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 파싱한 결과를 object vars에 담기 위한 method
|
||||
**/
|
||||
function _arrToObj($arr) {
|
||||
if(!count($arr)) return;
|
||||
foreach($arr as $key => $val) {
|
||||
$key = strtolower($key);
|
||||
$output->{$key} = $val;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,340 +1,369 @@
|
|||
<?php
|
||||
/**
|
||||
* @file : classes/db/DB.class.php
|
||||
* @author : zero <zero@nzeo.com>
|
||||
* @desc : query xml을 파싱하여 결과를 return
|
||||
**/
|
||||
/**
|
||||
* @class XmlQueryParser
|
||||
* @author zero (zero@nzeo.com)
|
||||
* @brief query xml을 파싱하여 결과를 return
|
||||
* @version 0.1
|
||||
*
|
||||
* @todo subquery나 union등의 확장 쿼리에 대한 지원이 필요
|
||||
**/
|
||||
|
||||
class XmlQueryParser {
|
||||
class XmlQueryParser {
|
||||
|
||||
// 조건문에서 조건을 등호로 표시하는 변수
|
||||
var $cond_operation = array(
|
||||
'equal' => '=',
|
||||
'more' => '>=',
|
||||
'excess' => '>',
|
||||
'less' => '<=',
|
||||
'below' => '<',
|
||||
'notequal' => '!=',
|
||||
'notnull' => 'is not null',
|
||||
'null' => 'is null',
|
||||
/**
|
||||
* @brief 조건문에서 조건을 등호로 표시하는 변수
|
||||
**/
|
||||
var $cond_operation = array(
|
||||
'equal' => '=',
|
||||
'more' => '>=',
|
||||
'excess' => '>',
|
||||
'less' => '<=',
|
||||
'below' => '<',
|
||||
'notequal' => '!=',
|
||||
'notnull' => 'is not null',
|
||||
'null' => 'is null',
|
||||
);
|
||||
|
||||
// private string parse($query_id, $xml_file, $cache_file)/*{{{*/
|
||||
// 쿼리 파일을 찾아서 파싱하고 cacheing한다
|
||||
function parse($query_id, $xml_file, $cache_file) {
|
||||
// query xml 파일을 찾아서 파싱, 결과가 없으면 return
|
||||
$buff = FileHandler::readFile($xml_file);
|
||||
$oXml = new XmlParser();
|
||||
$xml_obj = $oXml->parse($buff);
|
||||
if(!$xml_obj) return;
|
||||
/**
|
||||
* @brief 쿼리 파일을 찾아서 파싱하고 cacheing한다
|
||||
**/
|
||||
function parse($query_id, $xml_file, $cache_file) {
|
||||
// query xml 파일을 찾아서 파싱, 결과가 없으면 return
|
||||
$buff = FileHandler::readFile($xml_file);
|
||||
$oXml = new XmlParser();
|
||||
$xml_obj = $oXml->parse($buff);
|
||||
if(!$xml_obj) return;
|
||||
|
||||
// 쿼리 스크립트를 만들때 필요한 변수들
|
||||
$filter_script = $notnull_script = $column_script = $default_script = '';
|
||||
// 쿼리 스크립트를 만들때 필요한 변수들
|
||||
$filter_script = $notnull_script = $column_script = $default_script = '';
|
||||
|
||||
// insert, update, delete, select등의 action
|
||||
$action = strtolower($xml_obj->query->attrs->action);
|
||||
if(!$action) return;
|
||||
// insert, update, delete, select등의 action
|
||||
$action = strtolower($xml_obj->query->attrs->action);
|
||||
if(!$action) return;
|
||||
|
||||
// 테이블 정리 (배열코드로 변환)
|
||||
$tables = $this->_getTablesScript($xml_obj);
|
||||
// 테이블 정리 (배열코드로 변환)
|
||||
$tables = $this->_getTablesScript($xml_obj);
|
||||
|
||||
// 컬럼 정리
|
||||
$column_script = $this->_getColumnsScript($xml_obj, $default_script, $notnull_script, $filter_script, $action);
|
||||
// 컬럼 정리
|
||||
$column_script = $this->_getColumnsScript($xml_obj, $default_script, $notnull_script, $filter_script, $action);
|
||||
|
||||
// 조건절 정리
|
||||
$condition_script = $this->_getConditionScript($xml_obj, $default_script, $notnull_script, $filter_script);
|
||||
// 조건절 정리
|
||||
$condition_script = $this->_getConditionScript($xml_obj, $default_script, $notnull_script, $filter_script);
|
||||
|
||||
// group 정리
|
||||
$group_script = $this->_getGroupScript($xml_obj);
|
||||
// group 정리
|
||||
$group_script = $this->_getGroupScript($xml_obj);
|
||||
|
||||
// 네비게이션 정리
|
||||
$navigation_script = $this->_getNavigationScript($xml_obj);
|
||||
// 네비게이션 정리
|
||||
$navigation_script = $this->_getNavigationScript($xml_obj);
|
||||
|
||||
// 캐쉬 내용 작성
|
||||
$buff =
|
||||
sprintf(
|
||||
'<?php if(!__ZB5__) exit();'."\n".
|
||||
'$pass_quotes = array();'."\n".
|
||||
'$id = \'%s\';'."\n".
|
||||
'$action = \'%s\';'."\n".
|
||||
'$tables = array(%s);'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'$group_script = \'%s\''."\n".
|
||||
'?>',
|
||||
$query_id,
|
||||
$action,
|
||||
$tables,
|
||||
$default_script,
|
||||
$column_script,
|
||||
$notnull_script,
|
||||
$filter_script,
|
||||
$condition_script,
|
||||
$navigation_script,
|
||||
$group_script
|
||||
);
|
||||
// 캐쉬 내용 작성
|
||||
$buff =
|
||||
sprintf(
|
||||
'<?php if(!__ZB5__) exit();'."\n".
|
||||
'$pass_quotes = array();'."\n".
|
||||
'$id = \'%s\';'."\n".
|
||||
'$action = \'%s\';'."\n".
|
||||
'$tables = array(%s);'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'$group_script = \'%s\''."\n".
|
||||
'?>',
|
||||
$query_id,
|
||||
$action,
|
||||
$tables,
|
||||
$default_script,
|
||||
$column_script,
|
||||
$notnull_script,
|
||||
$filter_script,
|
||||
$condition_script,
|
||||
$navigation_script,
|
||||
$group_script
|
||||
);
|
||||
|
||||
// 저장
|
||||
FileHandler::writeFile($cache_file, $buff);
|
||||
}/*}}}*/
|
||||
|
||||
// private string _getDefaultCode($name, $value)/*{{{*/
|
||||
function _getDefaultCode($name, $value) {
|
||||
if(!$value) return;
|
||||
if(substr($value, -1)!=')') return sprintf('if(!$args->%s) $args->%s = \'%s\';'."\n", $name, $name, $value);
|
||||
|
||||
$str_pos = strpos($value, '(');
|
||||
$func_name = substr($value, 0, $str_pos);
|
||||
$args = substr($value, $str_pos+1, strlen($value)-1);
|
||||
|
||||
switch($func_name) {
|
||||
case 'ipaddress' :
|
||||
$val = '\''.$_SERVER['REMOTE_ADDR'].'\'';
|
||||
break;
|
||||
case 'unixtime' :
|
||||
$val = 'time()';
|
||||
break;
|
||||
case 'curdate' :
|
||||
$val = 'date("YmdHis")';
|
||||
break;
|
||||
case 'sequence' :
|
||||
$val = '$this->getNextSequence()';
|
||||
break;
|
||||
case 'plus' :
|
||||
$args = abs($args);
|
||||
$val = sprintf('\'%s+%d\'', $name, $args);
|
||||
$pass_quotes = true;
|
||||
break;
|
||||
case 'minus' :
|
||||
$args = abs($args);
|
||||
$val = sprintf('\'%s-%d\'', $name, $args);
|
||||
$pass_quotes = true;
|
||||
break;
|
||||
}
|
||||
|
||||
$output = sprintf('if(!$args->%s) $args->%s = %s;'."\n", $name, $name, $val);
|
||||
if($pass_quotes) $output .= sprintf('$pass_quotes[] = \'%s\';'."\n",$name);
|
||||
return $output;
|
||||
}/*}}}*/
|
||||
|
||||
// private string _getFilterCode($key, $type, $minlength, $maxlength, $var='column')/*{{{*/
|
||||
function _getFilterCode($key, $type, $minlength, $maxlength, $var='column', $notnull='') {
|
||||
if(!$type||!$minlength||!$maxlength) return;
|
||||
if(!$notnull) $notnull_code = sprintf('if($%s->%s) ', $var, $key);
|
||||
return
|
||||
sprintf('unset($output); %s$output = $this->_checkFilter(\'%s\', $%s->%s, \'%s\', \'%d\', \'%d\'); if(!$output->toBool()) return $output;'."\n",
|
||||
$notnull_code,
|
||||
$key,
|
||||
$var,
|
||||
$key,
|
||||
$type,
|
||||
(int)$minlength,
|
||||
(int)$maxlength
|
||||
);
|
||||
}/*}}}*/
|
||||
|
||||
// private string _getNotNullCode($name)/*{{{*/
|
||||
function _getNotNullCode($name, $var='column') {
|
||||
return
|
||||
sprintf('if(!$%s->%s) return new Output(-1, sprintf($lang->filter->isnull, $lang->%s?$lang->%s:\'%s\'));'."\n",
|
||||
$var,
|
||||
$name,
|
||||
$name,
|
||||
$name,
|
||||
$name
|
||||
);
|
||||
}/*}}}*/
|
||||
|
||||
// private string _getTablesScript($xml_obj) /*{{{*/
|
||||
function _getTablesScript($xml_obj) {
|
||||
$obj_tables = $xml_obj->query->tables->table;
|
||||
if(!is_array($obj_tables)) $obj_tables = array('', $obj_tables);
|
||||
|
||||
foreach($obj_tables as $table_info) {
|
||||
$name = trim($table_info->attrs->name);
|
||||
if(!$name) continue;
|
||||
$alias = trim($table_info->attrs->alias);
|
||||
if(!$alias) $alias = $name;
|
||||
$table_list[] = sprintf('\'%s\'=>\'%s\'', $name, $alias);
|
||||
}
|
||||
return implode(",",$table_list);
|
||||
}/*}}}*/
|
||||
|
||||
// private string _getColumnsScript($xml_obj, &$default_script, &$notnull_script, &$filter_script, $action)/*{{{*/
|
||||
function _getColumnsScript($xml_obj, &$default_script, &$notnull_script, &$filter_script, $action) {
|
||||
$obj_columns = $xml_obj->query->columns->column;
|
||||
if(!is_array($obj_columns)) $obj_columns = array('', $obj_columns);
|
||||
|
||||
foreach($obj_columns as $column_info) {
|
||||
$name = trim($column_info->attrs->name);
|
||||
if(!$name || $name == '*') continue;
|
||||
|
||||
$var = trim($column_info->attrs->var);
|
||||
$alias = trim($column_info->attrs->alias);
|
||||
if(!$alias) $alias = $name;
|
||||
$default = trim($column_info->attrs->default);
|
||||
$notnull = trim($column_info->attrs->notnull);
|
||||
|
||||
$filter_type = trim($column_info->attrs->filter);
|
||||
$minlength = (int)trim($column_info->attrs->minlength);
|
||||
$maxlength = (int)trim($column_info->attrs->maxlength);
|
||||
|
||||
$column_script .= sprintf('$column->%s = $args->%s;'."\n", $alias, $var?$var:$alias);
|
||||
$invert_columns[] = sprintf('\'%s\'=>\'%s\'', $alias, $name);
|
||||
|
||||
$default_script .= $this->_getDefaultCode($alias, $default);
|
||||
if($action != 'select') {
|
||||
if($filter_type) $filter_script .= $this->_getFilterCode($alias, $filter_type, $minlength, $maxlength, 'column', $notnull);
|
||||
if($notnull) $notnull_script .= $this->_getNotNullCode($alias);
|
||||
// 저장
|
||||
FileHandler::writeFile($cache_file, $buff);
|
||||
}
|
||||
}
|
||||
if(is_array($invert_columns)) $column_script .= sprintf('$invert_columns = array(%s);'."\n", implode(',',$invert_columns));
|
||||
return $column_script;
|
||||
}/*}}}*/
|
||||
|
||||
// private string _getConditionScript($xml_obj, &$default_script, &$notnull_script, &$filter_script)/*{{{*/
|
||||
function _getConditionScript($xml_obj, &$default_script, &$notnull_script, &$filter_script) {
|
||||
$cond_idx = 0;
|
||||
/**
|
||||
* @brief column, condition등의 key에 default 값을 세팅
|
||||
**/
|
||||
function _getDefaultCode($name, $value) {
|
||||
if(!$value) return;
|
||||
if(substr($value, -1)!=')') return sprintf('if(!$args->%s) $args->%s = \'%s\';'."\n", $name, $name, $value);
|
||||
|
||||
$obj_conditions = $xml_obj->query->conditions->condition;
|
||||
$str_pos = strpos($value, '(');
|
||||
$func_name = substr($value, 0, $str_pos);
|
||||
$args = substr($value, $str_pos+1, strlen($value)-1);
|
||||
|
||||
$condition_script = $condition = $this->_getConditionQuery($cond_idx++, $obj_conditions, NULL, $notnull_script, $filter_script);
|
||||
switch($func_name) {
|
||||
case 'ipaddress' :
|
||||
$val = '\''.$_SERVER['REMOTE_ADDR'].'\'';
|
||||
break;
|
||||
case 'unixtime' :
|
||||
$val = 'time()';
|
||||
break;
|
||||
case 'curdate' :
|
||||
$val = 'date("YmdHis")';
|
||||
break;
|
||||
case 'sequence' :
|
||||
$val = '$this->getNextSequence()';
|
||||
break;
|
||||
case 'plus' :
|
||||
$args = abs($args);
|
||||
$val = sprintf('\'%s+%d\'', $name, $args);
|
||||
$pass_quotes = true;
|
||||
break;
|
||||
case 'minus' :
|
||||
$args = abs($args);
|
||||
$val = sprintf('\'%s-%d\'', $name, $args);
|
||||
$pass_quotes = true;
|
||||
break;
|
||||
}
|
||||
|
||||
$obj_groups = $xml_obj->query->conditions->group;
|
||||
if(!is_array($obj_groups)) $obj_groups = array('', $obj_groups);
|
||||
$output = sprintf('if(!$args->%s) $args->%s = %s;'."\n", $name, $name, $val);
|
||||
if($pass_quotes) $output .= sprintf('$pass_quotes[] = \'%s\';'."\n",$name);
|
||||
return $output;
|
||||
}
|
||||
|
||||
foreach($obj_groups as $obj_group) {
|
||||
$group_pipe = $obj_group->attrs->pipe;
|
||||
if(!$group_pipe) continue;
|
||||
$buff = $this->_getConditionQuery($cond_idx++, $obj_group->condition, $group_pipe, $notnull_script, $filter_script);
|
||||
$condition_script .= $buff;
|
||||
}
|
||||
/**
|
||||
* @brief 필터 체크
|
||||
**/
|
||||
function _getFilterCode($key, $type, $minlength, $maxlength, $var='column', $notnull='') {
|
||||
if(!$type||!$minlength||!$maxlength) return;
|
||||
if(!$notnull) $notnull_code = sprintf('if($%s->%s) ', $var, $key);
|
||||
|
||||
$condition_script .= '$condition = $this->_combineCondition($cond_group, $group_pipe);'."\n";
|
||||
return $condition_script;
|
||||
}/*}}}*/
|
||||
|
||||
// private string _getConditionQuery($cond_idx, $obj, $group_pipe, &$notnull_script, &$filter_script) /*{{{*/
|
||||
// 조건문의 쿼리를 만들어 줌
|
||||
function _getConditionQuery($cond_idx, $obj, $group_pipe, &$notnull_script, &$filter_script) {
|
||||
if(!is_array($obj)) $obj = array('', $obj);
|
||||
|
||||
$idx = 0;
|
||||
foreach($obj as $obj_cond) {
|
||||
$operation = $obj_cond->attrs->operation;
|
||||
if(!$operation) continue;
|
||||
|
||||
$column = $obj_cond->attrs->column;
|
||||
$var = $obj_cond->attrs->var;
|
||||
$filter = $obj_cond->attrs->filter;
|
||||
$notnull = $obj_cond->attrs->notnull;
|
||||
$pipe = $obj_cond->attrs->pipe;
|
||||
if(!$pipe) $pipe = 'and';
|
||||
$default = $obj_cond->attrs->default;
|
||||
|
||||
// 비교 대상이 다른 혹은 같은 테이블의 column일 경우
|
||||
if(eregi("\.", $var)) {
|
||||
switch($operation) {
|
||||
case 'in' :
|
||||
$buff = sprintf('%s in (%s)', $column, $var);
|
||||
break;
|
||||
default :
|
||||
$operation = $this->cond_operation[$operation];
|
||||
if(!$operation) $operation = 'and';
|
||||
$buff = sprintf('%s %s %s', $column, $operation, $var);
|
||||
break;
|
||||
}
|
||||
$condition_script .= sprintf('$cond_group[%d][][\'%s\'] = \'%s\';'."\n",$cond_idx, $pipe, $buff);
|
||||
|
||||
// 입력받을 변수일 경우
|
||||
} else {
|
||||
switch($operation) {
|
||||
case 'like' :
|
||||
$buff = sprintf('sprintf("%s like \'%%%%%%s%%%%\' ", $this->addQuotes($args->%s))', $column, $var);
|
||||
break;
|
||||
case 'like_prefix' :
|
||||
$buff = sprintf('sprintf("%s like \'%%s%%%%\' ", $this->addQuotes($args->%s))', $column, $var);
|
||||
break;
|
||||
case 'in' :
|
||||
$buff = sprintf('sprintf("%s in (%%s) ", $this->addQuotes($args->%s))', $column, $var);
|
||||
break;
|
||||
case 'notnull' :
|
||||
case 'null' :
|
||||
$operation = $this->cond_operation[$operation];
|
||||
unset($var);
|
||||
$buff = sprintf('"%s %s "', $column, $operation);
|
||||
break;
|
||||
default :
|
||||
$operation = $this->cond_operation[$operation];
|
||||
if($default) $buff = sprintf('sprintf("%s %s \'%%s\' ", $args->%s?$this->addQuotes($args->%s):\'%s\')', $column, $operation, $var?$var:$column, $var?$var:$column, $default);
|
||||
else $buff = sprintf('sprintf("%s %s \'%%s\' ", $this->addQuotes($args->%s))', $column, $operation, $var?$var:$column);
|
||||
break;
|
||||
}
|
||||
$buff = sprintf('$cond_group[%d][][\'%s\'] = %s;'."\n",$cond_idx, $pipe, $buff);
|
||||
|
||||
if(!$notnull && $var) $buff = sprintf('if($args->%s) ', $var).$buff;
|
||||
$condition_script .= $buff;
|
||||
if($notnull) $notnull_script .= $this->_getNotNullCode($var?$var:$column, 'args');
|
||||
if($filter) $filter_script .= $this->_getFilterCode($var, $filter, 0, 0, 'args', $notnull);
|
||||
return
|
||||
sprintf(
|
||||
'unset($output); %s$output = $this->_checkFilter(\'%s\', $%s->%s, \'%s\', \'%d\', \'%d\'); if(!$output->toBool()) return $output;'."\n",
|
||||
$notnull_code,
|
||||
$key,
|
||||
$var,
|
||||
$key,
|
||||
$type,
|
||||
(int)$minlength,
|
||||
(int)$maxlength
|
||||
);
|
||||
}
|
||||
}
|
||||
$condition_script .= sprintf('$group_pipe[%d] = \'%s\';'."\n", $cond_idx, $group_pipe);
|
||||
return $condition_script;
|
||||
}/*}}}*/
|
||||
|
||||
// private string _getGroupScript($xml_obj)/*{{{*/
|
||||
function _getGroupScript($xml_obj) {
|
||||
$group_list = $xml_obj->query->groups->group;
|
||||
if(!$group_list) return;
|
||||
if(!is_array($group_list)) $group_list = array($group_list);
|
||||
for($i=0;$i<count($group_list);$i++) {
|
||||
$group = $group_list[$i];
|
||||
$column = trim($group->attrs->column);
|
||||
if(!$column) continue;
|
||||
$group_column_list[] = $column;
|
||||
}
|
||||
if(count($group_column_list)) {
|
||||
return ' group by '.implode(" , ", $group_column_list);
|
||||
}
|
||||
}/*}}}*/
|
||||
/**
|
||||
* @brief not null 체크된 항목에 대한 처리
|
||||
**/
|
||||
function _getNotNullCode($name, $var='column') {
|
||||
return
|
||||
sprintf(
|
||||
'if(!$%s->%s) return new Output(-1, sprintf($lang->filter->isnull, $lang->%s?$lang->%s:\'%s\'));'."\n",
|
||||
$var,
|
||||
$name,
|
||||
$name,
|
||||
$name,
|
||||
$name
|
||||
);
|
||||
}
|
||||
|
||||
// private string _getNavigationScript($xml_obj) /*{{{*/
|
||||
function _getNavigationScript($xml_obj) {
|
||||
$obj_navigation = $xml_obj->query->navigation;
|
||||
if(!$obj_navigation) return;
|
||||
/**
|
||||
* @brief 대상 테이블에 대한 처리
|
||||
**/
|
||||
function _getTablesScript($xml_obj) {
|
||||
$obj_tables = $xml_obj->query->tables->table;
|
||||
if(!is_array($obj_tables)) $obj_tables = array('', $obj_tables);
|
||||
|
||||
$obj_index = $obj_navigation->index->attrs;
|
||||
$index_list = array();
|
||||
if(!is_array($obj_index)) $obj_index = array('', $obj_index);
|
||||
foreach($obj_index as $index_info) {
|
||||
$var = trim($index_info->var);
|
||||
if(!$var) continue;
|
||||
$default = trim($index_info->default);
|
||||
$order = trim($index_info->order);
|
||||
if(!$order) $order = 'asc';
|
||||
foreach($obj_tables as $table_info) {
|
||||
$name = trim($table_info->attrs->name);
|
||||
if(!$name) continue;
|
||||
$alias = trim($table_info->attrs->alias);
|
||||
if(!$alias) $alias = $name;
|
||||
$table_list[] = sprintf('\'%s\'=>\'%s\'', $name, $alias);
|
||||
}
|
||||
return implode(",",$table_list);
|
||||
}
|
||||
|
||||
$navigation_script .= sprintf('$navigation->index[] = array($args->%s?$args->%s:\'%s\', \'%s\');'."\n", $var, $var, $default, $order);
|
||||
}
|
||||
/**
|
||||
* @brief 컬럼 처리
|
||||
**/
|
||||
function _getColumnsScript($xml_obj, &$default_script, &$notnull_script, &$filter_script, $action) {
|
||||
$obj_columns = $xml_obj->query->columns->column;
|
||||
if(!is_array($obj_columns)) $obj_columns = array('', $obj_columns);
|
||||
|
||||
$obj_list_count = $obj_navigation->list_count->attrs;
|
||||
$count_var = $obj_list_count->var;
|
||||
$count_default = $obj_list_count->default;
|
||||
if($count_var) $navigation_script .= sprintf('$navigation->list_count = $args->%s?$args->%s%s;'."\n", $count_var, $count_var, $count_default?':'.$count_default:'');
|
||||
foreach($obj_columns as $column_info) {
|
||||
$name = trim($column_info->attrs->name);
|
||||
if(!$name || $name == '*') continue;
|
||||
|
||||
$obj_page_count = $obj_navigation->page_count->attrs;
|
||||
$count_var = $obj_page_count->var;
|
||||
$count_default = $obj_page_count->default;
|
||||
if($count_var) $navigation_script .= sprintf('$navigation->page_count = $args->%s?$args->%s%s;'."\n", $count_var, $count_var, $count_default?':'.$count_default:'');
|
||||
$var = trim($column_info->attrs->var);
|
||||
$alias = trim($column_info->attrs->alias);
|
||||
if(!$alias) $alias = $name;
|
||||
$default = trim($column_info->attrs->default);
|
||||
$notnull = trim($column_info->attrs->notnull);
|
||||
|
||||
$obj_page = $obj_navigation->page->attrs;
|
||||
$page_var = $obj_page->var;
|
||||
$page_default = $obj_page->default;
|
||||
if($page_var) $navigation_script .= sprintf('$navigation->page = $args->%s?$args->%s%s;'."\n", $page_var, $page_var, $page_default?':'.$page_default:'');
|
||||
return $navigation_script;
|
||||
}/*}}}*/
|
||||
}
|
||||
$filter_type = trim($column_info->attrs->filter);
|
||||
$minlength = (int)trim($column_info->attrs->minlength);
|
||||
$maxlength = (int)trim($column_info->attrs->maxlength);
|
||||
|
||||
$column_script .= sprintf('$column->%s = $args->%s;'."\n", $alias, $var?$var:$alias);
|
||||
$invert_columns[] = sprintf('\'%s\'=>\'%s\'', $alias, $name);
|
||||
|
||||
$default_script .= $this->_getDefaultCode($alias, $default);
|
||||
if($action != 'select') {
|
||||
if($filter_type) $filter_script .= $this->_getFilterCode($alias, $filter_type, $minlength, $maxlength, 'column', $notnull);
|
||||
if($notnull) $notnull_script .= $this->_getNotNullCode($alias);
|
||||
}
|
||||
}
|
||||
if(is_array($invert_columns)) $column_script .= sprintf('$invert_columns = array(%s);'."\n", implode(',',$invert_columns));
|
||||
return $column_script;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 조건절 처리
|
||||
**/
|
||||
function _getConditionScript($xml_obj, &$default_script, &$notnull_script, &$filter_script) {
|
||||
$cond_idx = 0;
|
||||
|
||||
$obj_conditions = $xml_obj->query->conditions->condition;
|
||||
|
||||
$condition_script = $condition = $this->_getConditionQuery($cond_idx++, $obj_conditions, NULL, $notnull_script, $filter_script);
|
||||
|
||||
$obj_groups = $xml_obj->query->conditions->group;
|
||||
if(!is_array($obj_groups)) $obj_groups = array('', $obj_groups);
|
||||
|
||||
foreach($obj_groups as $obj_group) {
|
||||
$group_pipe = $obj_group->attrs->pipe;
|
||||
if(!$group_pipe) continue;
|
||||
$buff = $this->_getConditionQuery($cond_idx++, $obj_group->condition, $group_pipe, $notnull_script, $filter_script);
|
||||
$condition_script .= $buff;
|
||||
}
|
||||
|
||||
$condition_script .= '$condition = $this->_combineCondition($cond_group, $group_pipe);'."\n";
|
||||
return $condition_script;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 조건문의 쿼리를 만들어 줌
|
||||
**/
|
||||
function _getConditionQuery($cond_idx, $obj, $group_pipe, &$notnull_script, &$filter_script) {
|
||||
if(!is_array($obj)) $obj = array('', $obj);
|
||||
|
||||
$idx = 0;
|
||||
foreach($obj as $obj_cond) {
|
||||
$operation = $obj_cond->attrs->operation;
|
||||
if(!$operation) continue;
|
||||
|
||||
$column = $obj_cond->attrs->column;
|
||||
$var = $obj_cond->attrs->var;
|
||||
$filter = $obj_cond->attrs->filter;
|
||||
$notnull = $obj_cond->attrs->notnull;
|
||||
$pipe = $obj_cond->attrs->pipe;
|
||||
if(!$pipe) $pipe = 'and';
|
||||
$default = $obj_cond->attrs->default;
|
||||
|
||||
// 비교 대상이 다른 혹은 같은 테이블의 column일 경우
|
||||
if(eregi("\.", $var)) {
|
||||
switch($operation) {
|
||||
case 'in' :
|
||||
$buff = sprintf('%s in (%s)', $column, $var);
|
||||
break;
|
||||
default :
|
||||
$operation = $this->cond_operation[$operation];
|
||||
if(!$operation) $operation = 'and';
|
||||
$buff = sprintf('%s %s %s', $column, $operation, $var);
|
||||
break;
|
||||
}
|
||||
$condition_script .= sprintf('$cond_group[%d][][\'%s\'] = \'%s\';'."\n",$cond_idx, $pipe, $buff);
|
||||
|
||||
// 입력받을 변수일 경우
|
||||
} else {
|
||||
switch($operation) {
|
||||
case 'like' :
|
||||
$buff = sprintf('sprintf("%s like \'%%%%%%s%%%%\' ", $this->addQuotes($args->%s))', $column, $var);
|
||||
break;
|
||||
case 'like_prefix' :
|
||||
$buff = sprintf('sprintf("%s like \'%%s%%%%\' ", $this->addQuotes($args->%s))', $column, $var);
|
||||
break;
|
||||
case 'in' :
|
||||
$buff = sprintf('sprintf("%s in (%%s) ", $this->addQuotes($args->%s))', $column, $var);
|
||||
break;
|
||||
case 'notnull' :
|
||||
case 'null' :
|
||||
$operation = $this->cond_operation[$operation];
|
||||
unset($var);
|
||||
$buff = sprintf('"%s %s "', $column, $operation);
|
||||
break;
|
||||
default :
|
||||
$operation = $this->cond_operation[$operation];
|
||||
if($default) $buff = sprintf('sprintf("%s %s \'%%s\' ", $args->%s?$this->addQuotes($args->%s):\'%s\')', $column, $operation, $var?$var:$column, $var?$var:$column, $default);
|
||||
else $buff = sprintf('sprintf("%s %s \'%%s\' ", $this->addQuotes($args->%s))', $column, $operation, $var?$var:$column);
|
||||
break;
|
||||
}
|
||||
|
||||
$buff = sprintf('$cond_group[%d][][\'%s\'] = %s;'."\n",$cond_idx, $pipe, $buff);
|
||||
|
||||
if(!$notnull && $var) $buff = sprintf('if($args->%s) ', $var).$buff;
|
||||
$condition_script .= $buff;
|
||||
if($notnull) $notnull_script .= $this->_getNotNullCode($var?$var:$column, 'args');
|
||||
if($filter) $filter_script .= $this->_getFilterCode($var, $filter, 0, 0, 'args', $notnull);
|
||||
}
|
||||
}
|
||||
$condition_script .= sprintf('$group_pipe[%d] = \'%s\';'."\n", $cond_idx, $group_pipe);
|
||||
return $condition_script;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief group by 쿼리 처리
|
||||
**/
|
||||
function _getGroupScript($xml_obj) {
|
||||
$group_list = $xml_obj->query->groups->group;
|
||||
if(!$group_list) return;
|
||||
if(!is_array($group_list)) $group_list = array($group_list);
|
||||
for($i=0;$i<count($group_list);$i++) {
|
||||
$group = $group_list[$i];
|
||||
$column = trim($group->attrs->column);
|
||||
if(!$column) continue;
|
||||
$group_column_list[] = $column;
|
||||
}
|
||||
|
||||
if(count($group_column_list)) {
|
||||
return ' group by '.implode(" , ", $group_column_list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief page navigation 처리
|
||||
**/
|
||||
function _getNavigationScript($xml_obj) {
|
||||
$obj_navigation = $xml_obj->query->navigation;
|
||||
if(!$obj_navigation) return;
|
||||
|
||||
$obj_index = $obj_navigation->index->attrs;
|
||||
$index_list = array();
|
||||
if(!is_array($obj_index)) $obj_index = array('', $obj_index);
|
||||
foreach($obj_index as $index_info) {
|
||||
$var = trim($index_info->var);
|
||||
if(!$var) continue;
|
||||
$default = trim($index_info->default);
|
||||
$order = trim($index_info->order);
|
||||
if(!$order) $order = 'asc';
|
||||
|
||||
$navigation_script .= sprintf('$navigation->index[] = array($args->%s?$args->%s:\'%s\', \'%s\');'."\n", $var, $var, $default, $order);
|
||||
}
|
||||
|
||||
$obj_list_count = $obj_navigation->list_count->attrs;
|
||||
$count_var = $obj_list_count->var;
|
||||
$count_default = $obj_list_count->default;
|
||||
if($count_var) $navigation_script .= sprintf('$navigation->list_count = $args->%s?$args->%s%s;'."\n", $count_var, $count_var, $count_default?':'.$count_default:'');
|
||||
|
||||
$obj_page_count = $obj_navigation->page_count->attrs;
|
||||
$count_var = $obj_page_count->var;
|
||||
$count_default = $obj_page_count->default;
|
||||
if($count_var) $navigation_script .= sprintf('$navigation->page_count = $args->%s?$args->%s%s;'."\n", $count_var, $count_var, $count_default?':'.$count_default:'');
|
||||
|
||||
$obj_page = $obj_navigation->page->attrs;
|
||||
$page_var = $obj_page->var;
|
||||
$page_default = $obj_page->default;
|
||||
if($page_var) $navigation_script .= sprintf('$navigation->page = $args->%s?$args->%s%s;'."\n", $page_var, $page_var, $page_default?':'.$page_default:'');
|
||||
|
||||
return $navigation_script;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue