mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-25 21:32:51 +09:00
삭제
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@2327 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
commit
8326004cb2
2773 changed files with 91485 additions and 0 deletions
268
classes/xml/XmlJsFilter.class.php
Normal file
268
classes/xml/XmlJsFilter.class.php
Normal file
|
|
@ -0,0 +1,268 @@
|
|||
<?php
|
||||
/**
|
||||
* @class XmlJsFilter
|
||||
* @author zero (zero@nzeo.com)
|
||||
* @brief filter xml문서를 해석하여 js파일로 만듬
|
||||
* @version 0.1
|
||||
*
|
||||
* xml filter 파일은 js script로 컴파일 되어 캐싱됨
|
||||
*
|
||||
* <filter name="js function 이름" act="서버에 요청할 action 이름" confirm_msg_code="submit시에 prompt로 물어볼 메세지의 코드" >
|
||||
* <form> <-- 폼 항목의 체크
|
||||
* <node target="name" required="true" minlength="1" maxlength="5" filter="email,userid,alpha,number" equalto="target" />
|
||||
* </form>
|
||||
* <parameter> <-- 폼 항목을 조합하여 key=val 의 js array로 return, act는 필수
|
||||
* <param name="key" target="target" />
|
||||
* </parameter>
|
||||
* <response callback_func="callback 받게 될 js function 이름 지정" > <-- 서버에 ajax로 전송하여 받을 결과값
|
||||
* <tag name="error" /> <-- error이름의 결과값을 받겠다는 것
|
||||
* </response>
|
||||
* </filter>
|
||||
*
|
||||
* - form - node
|
||||
* target = 폼 element의 이름
|
||||
* required = true/ false 꼭 있어야 하는지에 대한 체크
|
||||
* minlength, maxlength = 최소/최대 길이
|
||||
* filter = javascript로 체크하기 위한 체크 필터
|
||||
* email : email의 형식 ( aaa.aaa@aaa.com)
|
||||
* userid : 영문+숫자+_, 첫 글자는 영문, 소문자
|
||||
* alpha : 영문값만 허용
|
||||
* number : 숫자만 허용
|
||||
* equalto = target , 현재 폼과 지정 target의 값이 동일해야 함
|
||||
*
|
||||
* - parameter - param
|
||||
* name = key : key를 이름으로 가지고 value의 값을 가지는 array 값 생성
|
||||
* target = target_name : target form element의 값을 가져옴
|
||||
*
|
||||
* - response
|
||||
* tag = key : return받을 결과값의 변수명
|
||||
**/
|
||||
|
||||
class XmlJsFilter extends XmlParser {
|
||||
var $compiled_path = './files/cache/js_filter_compiled/'; ///< 컴파일된 캐시 파일이 놓일 위치
|
||||
var $xml_file = NULL; ///< 대상 xml 파일
|
||||
var $js_file = NULL; ///< 컴파일된 js 파일
|
||||
|
||||
/**
|
||||
* @brief constructor
|
||||
**/
|
||||
function XmlJsFilter($path, $xml_file) {
|
||||
$this->xml_file = sprintf("%s%s",$path, $xml_file);
|
||||
$this->js_file = $this->_getCompiledFileName($this->xml_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 원 xml파일과 compiled된js파일의 시간 비교 및 유무 비교등을 처리
|
||||
**/
|
||||
function compile() {
|
||||
if(!file_exists($this->xml_file)) return;
|
||||
if(!file_exists($this->js_file)) $this->_compile();
|
||||
else if(filectime($this->xml_file)>filectime($this->js_file)) $this->_compile();
|
||||
Context::addJsFile($this->js_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 실제 xml_file을 컴파일하여 js_file을 생성
|
||||
**/
|
||||
function _compile() {
|
||||
global $lang;
|
||||
|
||||
// xml 파일을 읽음
|
||||
$buff = FileHandler::readFile($this->xml_file);
|
||||
|
||||
// xml parsing
|
||||
$xml_obj = parent::parse($buff);
|
||||
|
||||
// XmlJsFilter는 filter_name, field, parameter 3개의 데이터를 핸들링
|
||||
$filter_name = $xml_obj->filter->attrs->name;
|
||||
$confirm_msg_code = $xml_obj->filter->attrs->confirm_msg_code;
|
||||
$module = $xml_obj->filter->attrs->module;
|
||||
$act = $xml_obj->filter->attrs->act;
|
||||
$extend_filter = $xml_obj->filter->attrs->extend_filter;
|
||||
|
||||
$field_node = $xml_obj->filter->form->node;
|
||||
if($field_node && !is_array($field_node)) $field_node = array($field_node);
|
||||
|
||||
$parameter_param = $xml_obj->filter->parameter->param;
|
||||
if($parameter_param && !is_array($parameter_param)) $parameter_param = array($parameter_param);
|
||||
|
||||
$response_tag = $xml_obj->filter->response->tag;
|
||||
if($response_tag && !is_array($response_tag)) $response_tag = array($response_tag);
|
||||
|
||||
// extend_filter가 있을 경우 해당 method를 호출하여 결과를 받음
|
||||
if($extend_filter) {
|
||||
|
||||
// extend_filter가 있을 경우 캐시 사용을 못하도록 js 캐시 파일명을 변경
|
||||
$this->js_file .= '.nocache.js';
|
||||
|
||||
// extend_filter는 module.method 로 지칭되어 이를 분리
|
||||
list($module_name, $method) = explode('.',$extend_filter);
|
||||
|
||||
// 모듈 이름과 method가 있을 경우 진행
|
||||
if($module_name&&$method) {
|
||||
// 해당 module의 model 객체를 받음
|
||||
$oExtendFilter = &getModel($module_name);
|
||||
|
||||
// method가 존재하면 실행
|
||||
if(method_exists($oExtendFilter, $method)) {
|
||||
// 결과를 받음
|
||||
//$extend_filter_list = call_user_method($method, $oExtendFilter, true);
|
||||
//$extend_filter_list = call_user_func(array($oExtendFilter, $method));
|
||||
$extend_filter_list = $oExtendFilter->{$method}(true);
|
||||
$extend_filter_count = count($extend_filter_list);
|
||||
|
||||
// 결과에서 lang값을 이용 문서 변수에 적용
|
||||
for($i=0;$i<$extend_filter_count;$i++) {
|
||||
$name = $extend_filter_list[$i]->name;
|
||||
$lang_value = $extend_filter_list[$i]->lang;
|
||||
if($lang_value) $lang->{$name} = $lang_value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$callback_func = $xml_obj->filter->response->attrs->callback_func;
|
||||
if(!$callback_func) $callback_func = "filterAlertMessage";
|
||||
|
||||
// 언어 입력을 위한 사용되는 필드 조사
|
||||
$target_list = array();
|
||||
$target_type_list = array();
|
||||
|
||||
// js function 을 만들기 시작
|
||||
$js_doc = sprintf("function %s(fo_obj) {\n", $filter_name);
|
||||
$js_doc .= sprintf("\tvar oFilter = new XmlJsFilter(fo_obj, \"%s\", \"%s\", %s);\n", $module, $act, $callback_func);
|
||||
|
||||
// field, 즉 체크항목의 script 생성
|
||||
$node_count = count($field_node);
|
||||
if($node_count) {
|
||||
foreach($field_node as $key =>$node) {
|
||||
$attrs = $node->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(
|
||||
"\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(!$target_type_list[$target]) $target_type_list[$target] = $filter;
|
||||
}
|
||||
}
|
||||
|
||||
// extend_filter_item 체크
|
||||
for($i=0;$i<$extend_filter_count;$i++) {
|
||||
$filter_item = $extend_filter_list[$i];
|
||||
$target = trim($filter_item->name);
|
||||
if(!$target) continue;
|
||||
$type = $filter_item->type;
|
||||
$required = $filter_item->required?'true':'false';
|
||||
|
||||
// extend filter item의 type으로 filter를 구함
|
||||
switch($type) {
|
||||
case 'homepage' :
|
||||
$filter = 'homepage';
|
||||
break;
|
||||
case 'email_address' :
|
||||
$filter = 'email';
|
||||
break;
|
||||
default :
|
||||
$filter = '';
|
||||
break;
|
||||
}
|
||||
|
||||
$js_doc .= sprintf(
|
||||
"\toFilter.addFieldItem(\"%s\",%s,%s,%s,\"%s\",\"%s\");\n",
|
||||
$target, $required, 0, 0, '', $filter
|
||||
);
|
||||
|
||||
if(!in_array($target, $target_list)) $target_list[] = $target;
|
||||
if(!$target_type_list[$target]) $target_type_list[$target] = $type;
|
||||
|
||||
}
|
||||
|
||||
// 데이터를 만들기 위한 parameter script 생성
|
||||
$parameter_count = count($parameter_param);
|
||||
if($parameter_count) {
|
||||
// 기본 필터 내용의 parameter로 구성
|
||||
foreach($parameter_param as $key =>$param) {
|
||||
$attrs = $param->attrs;
|
||||
$name = trim($attrs->name);
|
||||
$target = trim($attrs->target);
|
||||
if(!$name || !$target) continue;
|
||||
$target = htmlentities($target,ENT_QUOTES);
|
||||
|
||||
$js_doc .= sprintf(
|
||||
"\toFilter.addParameterItem(\"%s\",\"%s\");\n",
|
||||
$name, $target
|
||||
);
|
||||
if(!in_array($name, $target_list)) $target_list[] = $name;
|
||||
}
|
||||
|
||||
// extend_filter_item 체크
|
||||
for($i=0;$i<$extend_filter_count;$i++) {
|
||||
$filter_item = $extend_filter_list[$i];
|
||||
$target = $name = trim($filter_item->name);
|
||||
if(!$name || !$target) continue;
|
||||
$target = htmlentities($target,ENT_QUOTES);
|
||||
|
||||
$js_doc .= sprintf(
|
||||
"\toFilter.addParameterItem(\"%s\",\"%s\");\n",
|
||||
$name, $target
|
||||
);
|
||||
if(!in_array($name, $target_list)) $target_list[] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
// response script 생성
|
||||
$response_count = count($response_tag);
|
||||
for($i=0;$i<$response_count;$i++) {
|
||||
$attrs = $response_tag[$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_count = count($target_list);
|
||||
for($i=0;$i<$target_count;$i++) {
|
||||
$target = $target_list[$i];
|
||||
if(!$lang->{$target}) $lang->{$target} = $target;
|
||||
$js_doc .= sprintf("alertMsg[\"%s\"] = \"%s\";\n", $target, str_replace("\"","\\\"",$lang->{$target}));
|
||||
}
|
||||
|
||||
// target type을 기록
|
||||
$target_type_count = count($target_type_list);
|
||||
if($target_type_count) {
|
||||
foreach($target_type_list as $target => $type) {
|
||||
$js_doc .= sprintf("target_type_list[\"%s\"] = \"%s\";\n", $target, $type);
|
||||
}
|
||||
}
|
||||
|
||||
// 에러 메세지를 기록
|
||||
foreach($lang->filter as $key => $val) {
|
||||
if(!$val) $val = $key;
|
||||
$js_doc .= sprintf("alertMsg[\"%s\"] = \"%s\";\n", $key, str_replace("\"","\\\"",$val));
|
||||
}
|
||||
|
||||
// js파일 생성
|
||||
FileHandler::writeFile($this->js_file, $js_doc);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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());
|
||||
}
|
||||
}
|
||||
?>
|
||||
134
classes/xml/XmlParser.class.php
Normal file
134
classes/xml/XmlParser.class.php
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
/**
|
||||
* @class XmlParser
|
||||
* @author zero (zero@nzeo.com)
|
||||
* @brief xmlrpc를 해석하여 object로 return 하는 simple xml parser
|
||||
* @version 0.1
|
||||
*
|
||||
* xml 데이터의 attribute중에 xml:lang="ko,en,ch,jp,..." 이 있을 경우 지정된 lang 값에 해당하는 것만 남기는 트릭이 적용됨.
|
||||
* 무슨 문제를 일으킬지는 현재 모르나 잘 동작하고 있음
|
||||
**/
|
||||
|
||||
class XmlParser {
|
||||
|
||||
var $oParser = NULL; ///< xml parser
|
||||
|
||||
var $input = NULL; ///< input xml
|
||||
var $output = array(); ///< output object
|
||||
|
||||
var $lang = "en"; ///< 기본 언어타입
|
||||
|
||||
/**
|
||||
* @brief xml 파일을 로딩하여 parsing 처리 후 return
|
||||
**/
|
||||
function loadXmlFile($filename) {
|
||||
if(!file_exists($filename)) return;
|
||||
$buff = FileHandler::readFile($filename);
|
||||
|
||||
$oXmlParser = new XmlParser();
|
||||
return $oXmlParser->parse($buff);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief xml 파싱
|
||||
**/
|
||||
function parse($input = '') {
|
||||
// 디버그를 위한 컴파일 시작 시간 저장
|
||||
if(__DEBUG__==3) $start = getMicroTime();
|
||||
|
||||
$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();
|
||||
|
||||
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);
|
||||
|
||||
if(!count($this->output)) return;
|
||||
|
||||
$output = array_shift($this->output);
|
||||
|
||||
// 디버그를 위한 컴파일 시작 시간 저장
|
||||
if(__DEBUG__==3) $GLOBALS['__xmlparse_elapsed__'] += getMicroTime() - $start;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
337
classes/xml/XmlQueryParser.class.php
Normal file
337
classes/xml/XmlQueryParser.class.php
Normal file
|
|
@ -0,0 +1,337 @@
|
|||
<?php
|
||||
/**
|
||||
* @class XmlQueryParser
|
||||
* @author zero (zero@nzeo.com)
|
||||
* @brief query xml을 파싱하여 캐싱을 한 후 결과를 return
|
||||
* @version 0.1
|
||||
*
|
||||
* @todo subquery나 union등의 확장 쿼리에 대한 지원이 필요
|
||||
**/
|
||||
|
||||
class XmlQueryParser extends XmlParser {
|
||||
|
||||
/**
|
||||
* @brief 쿼리 파일을 찾아서 파싱하고 캐싱한다
|
||||
**/
|
||||
function parse($query_id, $xml_file, $cache_file) {
|
||||
// query xml 파일을 찾아서 파싱, 결과가 없으면 return
|
||||
$buff = FileHandler::readFile($xml_file);
|
||||
$xml_obj = parent::parse($buff);
|
||||
if(!$xml_obj) return;
|
||||
unset($buff);
|
||||
|
||||
list($module, $id) = explode('.',$query_id);
|
||||
|
||||
// insert, update, delete, select등의 action
|
||||
$action = strtolower($xml_obj->query->attrs->action);
|
||||
if(!$action) return;
|
||||
|
||||
// 테이블 정리 (배열코드로 변환)
|
||||
$tables = $xml_obj->query->tables->table;
|
||||
if(!$tables) return;
|
||||
if(!is_array($tables)) $tables = array($tables);
|
||||
foreach($tables as $key => $val) {
|
||||
// 테이블과 alias의 이름을 구함
|
||||
$table_name = $val->attrs->name;
|
||||
$alias = $val->attrs->alias;
|
||||
if(!$alias) $alias = $table_name;
|
||||
|
||||
$output->tables[$table_name] = $alias;
|
||||
|
||||
// 테이블을 찾아서 컬럼의 속성을 구함
|
||||
$table_file = sprintf('./modules/%s/schemas/%s.xml', $module, $table_name);
|
||||
if(!file_exists($table_file)) {
|
||||
$searched_list = FileHandler::readDir('./modules');
|
||||
$searched_count = count($searched_list);
|
||||
for($i=0;$i<$searched_count;$i++) {
|
||||
$table_file = sprintf('./modules/%s/schemas/%s.xml', $searched_list[$i], $table_name);
|
||||
if(file_exists($table_file)) break;
|
||||
}
|
||||
}
|
||||
|
||||
if(file_exists($table_file)) {
|
||||
$table_xml = FileHandler::readFile($table_file);
|
||||
$table_obj = parent::parse($table_xml);
|
||||
if($table_obj->table) {
|
||||
foreach($table_obj->table->column as $k => $v) {
|
||||
$buff .= sprintf('$output->column_type["%s"] = "%s";%s', $v->attrs->name, $v->attrs->type, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 컬럼 정리
|
||||
$columns = $xml_obj->query->columns->column;
|
||||
if(!$columns) {
|
||||
$output->column[] = array("*" => "*");
|
||||
} else {
|
||||
if(!is_array($columns)) $columns = array($columns);
|
||||
foreach($columns as $key => $val) {
|
||||
$name = $val->attrs->name;
|
||||
/*
|
||||
if(strpos('.',$name)===false && count($output->tables)==1) {
|
||||
$tmp = array_values($output->tables);
|
||||
$name = sprintf('%s.%s', $tmp[0], $val->attrs->name);
|
||||
}
|
||||
*/
|
||||
|
||||
$output->columns[] = array(
|
||||
"name" => $name,
|
||||
"var" => $val->attrs->var,
|
||||
"default" => $val->attrs->default,
|
||||
"notnull" => $val->attrs->notnull,
|
||||
"filter" => $val->attrs->filter,
|
||||
"minlength" => $val->attrs->minlength,
|
||||
"maxlength" => $val->attrs->maxlength,
|
||||
"alias" => $val->attrs->alias,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 조건절 정리
|
||||
$conditions = $xml_obj->query->conditions;
|
||||
|
||||
$condition = $conditions->condition;
|
||||
if($condition) {
|
||||
$obj->condition = $condition;
|
||||
unset($condition);
|
||||
$condition = array($obj);
|
||||
}
|
||||
|
||||
$condition_group = $conditions->group;
|
||||
if($condition_group && !is_array($condition_group)) $condition_group = array($condition_group);
|
||||
|
||||
if($condition && $condition_group) $cond = array_merge($condition, $condition_group);
|
||||
elseif($condition_group) $cond = $condition_group;
|
||||
else $cond = $condition;
|
||||
|
||||
if($cond) {
|
||||
foreach($cond as $key => $val) {
|
||||
unset($cond_output);
|
||||
|
||||
if($val->attrs->pipe) $cond_output->pipe = $val->attrs->pipe;
|
||||
else $cond_output->pipe = null;
|
||||
|
||||
if(!$val->condition) continue;
|
||||
if(!is_array($val->condition)) $val->condition = array($val->condition);
|
||||
|
||||
foreach($val->condition as $k => $v) {
|
||||
$obj = $v->attrs;
|
||||
if(!$obj->alias) $obj->alias = $obj->column;
|
||||
$cond_output->condition[] = $obj;
|
||||
}
|
||||
|
||||
$output->conditions[] = $cond_output;
|
||||
}
|
||||
}
|
||||
|
||||
// group 정리
|
||||
$group_list = $xml_obj->query->groups->group;
|
||||
if($group_list) {
|
||||
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)) $output->groups = $group_column_list;
|
||||
}
|
||||
|
||||
// 네비게이션 정리
|
||||
$navigation = $xml_obj->query->navigation;
|
||||
if($navigation) {
|
||||
$order = $navigation->index;
|
||||
if($order) {
|
||||
if(!is_array($order)) $order = array($order);
|
||||
foreach($order as $order_info) {
|
||||
$output->order[] = $order_info->attrs;
|
||||
}
|
||||
}
|
||||
|
||||
$list_count = $navigation->list_count->attrs;
|
||||
$output->list_count = $list_count;
|
||||
|
||||
$page_count = $navigation->page_count->attrs;
|
||||
$output->page_count = $page_count;
|
||||
|
||||
$page = $navigation->page->attrs;
|
||||
$output->page = $page ;
|
||||
}
|
||||
|
||||
$column_count = count($output->columns);
|
||||
$condition_count = count($output->conditions);
|
||||
|
||||
// php script 생성
|
||||
|
||||
// table 정리
|
||||
$buff .= '$output->tables = array( ';
|
||||
foreach($output->tables as $key => $val) {
|
||||
$buff .= sprintf('"%s"=>"%s",', $key, $val);
|
||||
}
|
||||
$buff .= ' );'."\n";
|
||||
|
||||
// column 정리
|
||||
if($column_count) {
|
||||
$buff .= '$output->columns = array ( ';
|
||||
foreach($output->columns as $key => $val) {
|
||||
$val['default'] = $this->getDefault($val['name'], $val['default']);
|
||||
if($val['var'] && strpos($val['var'],'.')===false) {
|
||||
|
||||
if($val['default']) $buff .= sprintf('array("name"=>"%s", "alias"=>"%s", "value"=>$args->%s?$args->%s:%s),%s', $val['name'], $val['alias'], $val['var'], $val['var'], $val['default'] ,"\n");
|
||||
else $buff .= sprintf('array("name"=>"%s", "alias"=>"%s", "value"=>$args->%s),%s', $val['name'], $val['alias'], $val['var'], "\n");
|
||||
|
||||
if($val['default']) $default_list[$val['var']] = $val['default'];
|
||||
if($val['notnull']) $notnull_list[] = $val['var'];
|
||||
if($val['minlength']) $minlength_list[$val['var']] = $val['minlength'];
|
||||
if($val['maxlength']) $maxlength_list[$val['var']] = $val['maxlength'];
|
||||
} else {
|
||||
if($val['default']) $buff .= sprintf('array("name"=>"%s", "alias"=>"%s", "value"=>%s),%s', $val['name'], $val['alias'], $val['default'] ,"\n");
|
||||
else $buff .= sprintf('array("name"=>"%s", "alias"=>"%s",),%s', $val['name'], $val['alias'], "\n");
|
||||
}
|
||||
}
|
||||
$buff .= ' );'."\n";
|
||||
}
|
||||
|
||||
// conditions 정리
|
||||
if($condition_count) {
|
||||
$buff .= '$output->conditions = array ( ';
|
||||
foreach($output->conditions as $key => $val) {
|
||||
$buff .= sprintf('array("pipe"=>"%s",%s"condition"=>array(', $val->pipe,"\n");
|
||||
foreach($val->condition as $k => $v) {
|
||||
$v->default = $this->getDefault($v->column, $v->default);
|
||||
if($v->var) {
|
||||
if(strpos($v->var,".")===false) {
|
||||
if($v->default) $default_list[$v->var] = $v->default;
|
||||
if($v->filter) $filter_list[] = $v;
|
||||
if($v->default) $buff .= sprintf('array("column"=>"%s", "value"=>$args->%s?$args->%s:%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->var, $v->default, $v->pipe, $v->operation, "\n");
|
||||
else $buff .= sprintf('array("column"=>"%s", "value"=>$args->%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->pipe, $v->operation, "\n");
|
||||
} else {
|
||||
$buff .= sprintf('array("column"=>"%s", "value"=>"%s","pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->pipe, $v->operation, "\n");
|
||||
}
|
||||
} else {
|
||||
if($v->default) $buff .= sprintf('array("column"=>"%s", "value"=>%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->default ,$v->pipe, $v->operation,"\n");
|
||||
else $buff .= sprintf('array("column"=>"%s", "pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->pipe, $v->operation,"\n");
|
||||
}
|
||||
}
|
||||
$buff .= ')),'."\n";
|
||||
}
|
||||
|
||||
$buff .= ' );'."\n";
|
||||
}
|
||||
|
||||
// order 정리
|
||||
if($output->order) {
|
||||
$buff .= '$output->order = array(';
|
||||
foreach($output->order as $key => $val) {
|
||||
$buff .= sprintf('array($args->%s?$args->%s:"%s",in_array($args->%s,array("asc","desc"))?$args->%s:("%s"?"%s":"asc")),', $val->var, $val->var, $val->default, $val->order, $val->order, $val->order, $val->order);
|
||||
}
|
||||
$buff .= ');'."\n";
|
||||
}
|
||||
|
||||
// list_count 정리
|
||||
if($output->list_count) {
|
||||
$buff .= sprintf('$output->list_count = array("var"=>"%s", "value"=>$args->%s?$args->%s:"%s");%s', $output->list_count->var, $output->list_count->var, $output->list_count->var, $output->list_count->default,"\n");
|
||||
}
|
||||
|
||||
// page_count 정리
|
||||
if($output->page_count) {
|
||||
$buff .= sprintf('$output->page_count = array("var"=>"%s", "value"=>$args->%s?$args->%s:"%s");%s', $output->page_count->var, $output->page_count->var, $output->page_count->var, $output->list_count->default,"\n");
|
||||
}
|
||||
|
||||
// page 정리
|
||||
if($output->page) {
|
||||
$buff .= sprintf('$output->page = array("var"=>"%s", "value"=>$args->%s?$args->%s:"%s");%s', $output->page->var, $output->page->var, $output->page->var, $output->list->default,"\n");
|
||||
}
|
||||
|
||||
// group by 정리
|
||||
if($output->groups) {
|
||||
$buff .= sprintf('$output->groups = array("%s");%s', implode('","',$output->groups),"\n");
|
||||
}
|
||||
|
||||
// default check
|
||||
if(count($default_list)) {
|
||||
foreach($default_list as $key => $val) {
|
||||
$pre_buff .= 'if(!isset($args->'.$key.')) $args->'.$key.' = '.$val.';'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
// not null check
|
||||
if(count($notnull_list)) {
|
||||
foreach($notnull_list as $key => $val) {
|
||||
$pre_buff .= 'if(!isset($args->'.$val.')) return new Object(-1, sprintf($lang->filter->isnull, $lang->'.$val.'?$lang->'.$val.':\''.$val.'\'));'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
// minlength check
|
||||
if(count($minlength_list)) {
|
||||
foreach($minlength_list as $key => $val) {
|
||||
$pre_buff .= 'if($args->'.$key.'&&strlen($args->'.$key.')<'.$val.') return new Object(-1, sprintf($lang->filter->outofrange, $lang->'.$key.'?$lang->'.$key.':\''.$key.'\'));'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
// maxlength check
|
||||
if(count($maxlength_list)) {
|
||||
foreach($maxlength_list as $key => $val) {
|
||||
$pre_buff .= 'if($args->'.$key.'&&strlen($args->'.$key.')>'.$val.') return new Object(-1, sprintf($lang->filter->outofrange, $lang->'.$key.'?$lang->'.$key.':\''.$key.'\'));'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
// filter check
|
||||
if(count($filter_list)) {
|
||||
foreach($filter_list as $key => $val) {
|
||||
if(!$notnull_list[$key]) continue;
|
||||
$pre_buff .= sprintf('unset($_output); $_output = $this->checkFilter("%s",$args->%s,"%s"); if(!$_output->toBool()) return $_output;%s',$val->var,$val->var,$val->filter,"\n");
|
||||
}
|
||||
}
|
||||
|
||||
$buff = "<?php if(!defined('__ZBXE__')) exit();\n"
|
||||
. sprintf('$output->query_id = "%s";%s', $query_id, "\n")
|
||||
. sprintf('$output->action = "%s";%s', $action, "\n")
|
||||
. $pre_buff
|
||||
. $buff
|
||||
. 'return $output; ?>';
|
||||
|
||||
// 저장
|
||||
FileHandler::writeFile($cache_file, $buff);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief column, condition등의 key에 default 값을 세팅
|
||||
**/
|
||||
function getDefault($name, $value) {
|
||||
if(!$value) return;
|
||||
$str_pos = strpos($value, '(');
|
||||
if($str_pos===false) return '"'.$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);
|
||||
break;
|
||||
case 'minus' :
|
||||
$args = abs($args);
|
||||
$val = sprintf('"%s-%d"', $name, $args);
|
||||
break;
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue