mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 03:01:43 +09:00
issue 2662 coding convention in xml class
git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12225 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
fb0df50f3f
commit
2cb9487ba1
10 changed files with 1924 additions and 1660 deletions
|
|
@ -6,7 +6,8 @@
|
|||
* @package /classes/xml
|
||||
* @version 0.1
|
||||
*/
|
||||
class GeneralXmlParser {
|
||||
class GeneralXmlParser
|
||||
{
|
||||
/**
|
||||
* result of parse
|
||||
* @var array
|
||||
|
|
@ -14,78 +15,86 @@ class GeneralXmlParser {
|
|||
var $output = array();
|
||||
|
||||
/**
|
||||
* Parse a given input to product a object containing parse values.
|
||||
* @param string $input data to be parsed
|
||||
* @return array|NULL Returns an object containing parsed values or NULL in case of failure
|
||||
*/
|
||||
function parse($input = '') {
|
||||
$oParser = xml_parser_create('UTF-8');
|
||||
xml_set_object($oParser, $this);
|
||||
xml_set_element_handler($oParser, "_tagOpen", "_tagClosed");
|
||||
xml_set_character_data_handler($oParser, "_tagBody");
|
||||
* Parse a given input to product a object containing parse values.
|
||||
* @param string $input data to be parsed
|
||||
* @return array|NULL Returns an object containing parsed values or NULL in case of failure
|
||||
*/
|
||||
function parse($input = '')
|
||||
{
|
||||
$oParser = xml_parser_create('UTF-8');
|
||||
xml_set_object($oParser, $this);
|
||||
xml_set_element_handler($oParser, "_tagOpen", "_tagClosed");
|
||||
xml_set_character_data_handler($oParser, "_tagBody");
|
||||
|
||||
xml_parse($oParser, $input);
|
||||
xml_parser_free($oParser);
|
||||
xml_parse($oParser, $input);
|
||||
xml_parser_free($oParser);
|
||||
|
||||
if(!count($this->output)) return;
|
||||
$this->output = array_shift($this->output);
|
||||
if(!count($this->output)) return;
|
||||
$this->output = array_shift($this->output);
|
||||
|
||||
return $this->output;
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start element handler
|
||||
* @param resource $parser an instance of parser
|
||||
* @param string $node_name a name of node
|
||||
* @param array $attrs attributes to be set
|
||||
* @return void
|
||||
*/
|
||||
function _tagOpen($parser, $node_name, $attrs) {
|
||||
$obj->node_name = strtolower($node_name);
|
||||
$obj->attrs = $attrs;
|
||||
$obj->childNodes = array();
|
||||
* Start element handler
|
||||
* @param resource $parser an instance of parser
|
||||
* @param string $node_name a name of node
|
||||
* @param array $attrs attributes to be set
|
||||
* @return void
|
||||
*/
|
||||
function _tagOpen($parser, $node_name, $attrs)
|
||||
{
|
||||
$obj->node_name = strtolower($node_name);
|
||||
$obj->attrs = $attrs;
|
||||
$obj->childNodes = array();
|
||||
|
||||
array_push($this->output, $obj);
|
||||
array_push($this->output, $obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Character data handler
|
||||
* Variable in the last element of this->output
|
||||
* @param resource $parse an instance of parser
|
||||
* @param string $body a data to be added
|
||||
* @return void
|
||||
*/
|
||||
function _tagBody($parser, $body) {
|
||||
//if(!trim($body)) return;
|
||||
$this->output[count($this->output)-1]->body .= $body;
|
||||
* Character data handler
|
||||
* Variable in the last element of this->output
|
||||
* @param resource $parse an instance of parser
|
||||
* @param string $body a data to be added
|
||||
* @return void
|
||||
*/
|
||||
function _tagBody($parser, $body)
|
||||
{
|
||||
//if(!trim($body)) return;
|
||||
$this->output[count($this->output)-1]->body .= $body;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* End element handler
|
||||
* @param resource $parse an instance of parser
|
||||
* @param string $node_name name of xml node
|
||||
* @return void
|
||||
*/
|
||||
function _tagClosed($parser, $node_name) {
|
||||
$node_name = strtolower($node_name);
|
||||
$cur_obj = array_pop($this->output);
|
||||
$parent_obj = &$this->output[count($this->output)-1];
|
||||
* End element handler
|
||||
* @param resource $parse an instance of parser
|
||||
* @param string $node_name name of xml node
|
||||
* @return void
|
||||
*/
|
||||
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($parent_obj->childNodes[$node_name])
|
||||
{
|
||||
$tmp_obj = $parent_obj->childNodes[$node_name];
|
||||
if(is_array($tmp_obj)) {
|
||||
array_push($parent_obj->childNodes[$node_name], $cur_obj);
|
||||
} else {
|
||||
$parent_obj->childNodes[$node_name] = array();
|
||||
array_push($parent_obj->childNodes[$node_name], $tmp_obj);
|
||||
array_push($parent_obj->childNodes[$node_name], $cur_obj);
|
||||
}
|
||||
} else {
|
||||
$parent_obj->childNodes[$node_name] = $cur_obj;
|
||||
}
|
||||
if($parent_obj->childNodes[$node_name])
|
||||
{
|
||||
$tmp_obj = $parent_obj->childNodes[$node_name];
|
||||
if(is_array($tmp_obj))
|
||||
{
|
||||
array_push($parent_obj->childNodes[$node_name], $cur_obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
$parent_obj->childNodes[$node_name] = array();
|
||||
array_push($parent_obj->childNodes[$node_name], $tmp_obj);
|
||||
array_push($parent_obj->childNodes[$node_name], $cur_obj);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$parent_obj->childNodes[$node_name] = $cur_obj;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
/* End of file GeneralXmlParser.class.php */
|
||||
/* Location: ./classes/xml/GeneralXmlParser.class.php */
|
||||
|
|
|
|||
|
|
@ -5,53 +5,70 @@
|
|||
* @package /classes/xml
|
||||
* @version 0.1
|
||||
*/
|
||||
class XmlGenerator{
|
||||
class XmlGenerator
|
||||
{
|
||||
/**
|
||||
* object change to xml
|
||||
* @param object $xml
|
||||
* @return string
|
||||
*/
|
||||
function obj2xml($xml){
|
||||
* object change to xml
|
||||
* @param object $xml
|
||||
* @return string
|
||||
*/
|
||||
function obj2xml($xml)
|
||||
{
|
||||
$buff = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
|
||||
|
||||
foreach($xml as $nodeName => $nodeItem){
|
||||
foreach($xml as $nodeName => $nodeItem)
|
||||
{
|
||||
$buff .= $this->_makexml($nodeItem);
|
||||
}
|
||||
return $buff;
|
||||
}
|
||||
|
||||
/**
|
||||
* object change to xml
|
||||
* @param object $node node in xml object
|
||||
* @return string
|
||||
*/
|
||||
function _makexml($node){
|
||||
* object change to xml
|
||||
* @param object $node node in xml object
|
||||
* @return string
|
||||
*/
|
||||
function _makexml($node)
|
||||
{
|
||||
$body = '';
|
||||
foreach($node as $key => $value){
|
||||
switch($key){
|
||||
foreach($node as $key => $value)
|
||||
{
|
||||
switch($key)
|
||||
{
|
||||
case 'node_name' : break;
|
||||
case 'attrs' : {
|
||||
$attrs = '';
|
||||
if (isset($value)){
|
||||
foreach($value as $attrName=>$attrValue){
|
||||
$attrs .= sprintf(' %s="%s"', $attrName, htmlspecialchars($attrValue));
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 'body' : $body = $value; break;
|
||||
default : {
|
||||
if (is_array($value)){
|
||||
foreach($value as $idx => $arrNode){
|
||||
$body .= $this->_makexml($arrNode);
|
||||
}
|
||||
}else if(is_object($value)){
|
||||
$body = $this->_makexml($value);
|
||||
}
|
||||
}
|
||||
case 'attrs' :
|
||||
{
|
||||
$attrs = '';
|
||||
if (isset($value))
|
||||
{
|
||||
foreach($value as $attrName=>$attrValue)
|
||||
{
|
||||
$attrs .= sprintf(' %s="%s"', $attrName, htmlspecialchars($attrValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'body' :
|
||||
$body = $value;
|
||||
break;
|
||||
default :
|
||||
{
|
||||
if (is_array($value))
|
||||
{
|
||||
foreach($value as $idx => $arrNode)
|
||||
{
|
||||
$body .= $this->_makexml($arrNode);
|
||||
}
|
||||
}
|
||||
else if(is_object($value))
|
||||
{
|
||||
$body = $this->_makexml($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return sprintf('<%s%s>%s</%s>'."\n", $node->node_name, $attrs, $body, $node->node_name);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
/* End of file XmlGenerator.class.php */
|
||||
/* Location: ./classes/xml/XmlGenerator.class.php */
|
||||
|
|
|
|||
|
|
@ -1,315 +1,335 @@
|
|||
<?php
|
||||
/**
|
||||
* filter class traslate xml content into javascript code
|
||||
*
|
||||
* it convert xml code into js file and save the result as a cache file
|
||||
* @code
|
||||
* <pre>{
|
||||
* <filter name="name of javascript funcion" act="action name" confirm_msg_code="message string to be prompted when submitting the form" >
|
||||
* <form> <-- code to validate data in the form
|
||||
* <node target="name" required="true" minlength="1" maxlength="5" filter="email,userid,alpha,number" equalto="target" />
|
||||
* </form>
|
||||
* <parameter> "- A form of key = val combination of items to js array return, act required
|
||||
* <param name="key" target="target" />
|
||||
* </parameter>
|
||||
* <response callback_func="specifying the name of js function to callback" > "- Result to get by sending ajax to the server
|
||||
* <tag name="error" /> <- get the result of error name
|
||||
* </response>
|
||||
* </filter>
|
||||
* }</pre>
|
||||
*
|
||||
* @detail
|
||||
* <pre>{
|
||||
* - syntax description of <form> node
|
||||
* target = name of for element
|
||||
* required = flag indicating whether a field is mandatory or not
|
||||
* minlength, maxlength = mininum, maxinum length of string allowed for the field
|
||||
* filter = name of filter to be used for javascript validation. Following is the description of filter available
|
||||
* 1) email : validate the confirmance of the value against an email format
|
||||
* 2) userid : validate the confirmance of the value against the format of user id. (combination of number[0-9],alphabet(lower case) and '_', underscore starting with an alphatic character)
|
||||
* 3) alpha : check if the value is consists of alphabatic characters.
|
||||
* 4) number : check if the value is consists of numerical digits
|
||||
* 5) equalto = target : indicate that values in the form should be equal to those in target
|
||||
* 6) pattern_id/regex pattern/[i] : check the value using custom regular expression.
|
||||
*
|
||||
* - parameter - param
|
||||
* name = key : indicate that a new array, 'key' will be created and a value will be assigned to it
|
||||
* target = target_name: get the value of the target form element
|
||||
*
|
||||
* - response
|
||||
* tag = key : name of variable that will contain the result of the execution
|
||||
* }</pre>
|
||||
* @class XmlJsFilter
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml
|
||||
* @version 0.2
|
||||
*/
|
||||
class XmlJsFilter extends XmlParser
|
||||
{
|
||||
/**
|
||||
* filter class traslate xml content into javascript code
|
||||
*
|
||||
* it convert xml code into js file and save the result as a cache file
|
||||
* @code
|
||||
* <pre>{
|
||||
* <filter name="name of javascript funcion" act="action name" confirm_msg_code="message string to be prompted when submitting the form" >
|
||||
* <form> <-- code to validate data in the form
|
||||
* <node target="name" required="true" minlength="1" maxlength="5" filter="email,userid,alpha,number" equalto="target" />
|
||||
* </form>
|
||||
* <parameter> "- A form of key = val combination of items to js array return, act required
|
||||
* <param name="key" target="target" />
|
||||
* </parameter>
|
||||
* <response callback_func="specifying the name of js function to callback" > "- Result to get by sending ajax to the server
|
||||
* <tag name="error" /> <- get the result of error name
|
||||
* </response>
|
||||
* </filter>
|
||||
* }</pre>
|
||||
*
|
||||
* @detail
|
||||
* <pre>{
|
||||
* - syntax description of <form> node
|
||||
* target = name of for element
|
||||
* required = flag indicating whether a field is mandatory or not
|
||||
* minlength, maxlength = mininum, maxinum length of string allowed for the field
|
||||
* filter = name of filter to be used for javascript validation. Following is the description of filter available
|
||||
* 1) email : validate the confirmance of the value against an email format
|
||||
* 2) userid : validate the confirmance of the value against the format of user id. (combination of number[0-9],alphabet(lower case) and '_', underscore starting with an alphatic character)
|
||||
* 3) alpha : check if the value is consists of alphabatic characters.
|
||||
* 4) number : check if the value is consists of numerical digits
|
||||
* 5) equalto = target : indicate that values in the form should be equal to those in target
|
||||
* 6) pattern_id/regex pattern/[i] : check the value using custom regular expression.
|
||||
*
|
||||
* - parameter - param
|
||||
* name = key : indicate that a new array, 'key' will be created and a value will be assigned to it
|
||||
* target = target_name: get the value of the target form element
|
||||
*
|
||||
* - response
|
||||
* tag = key : name of variable that will contain the result of the execution
|
||||
* }</pre>
|
||||
* @class XmlJsFilter
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml
|
||||
* @version 0.2
|
||||
* version
|
||||
* @var string
|
||||
*/
|
||||
class XmlJsFilter extends XmlParser {
|
||||
/**
|
||||
* version
|
||||
* @var string
|
||||
*/
|
||||
var $version = '0.2.5';
|
||||
/**
|
||||
* compiled javascript cache path
|
||||
* @var string
|
||||
*/
|
||||
var $compiled_path = './files/cache/js_filter_compiled/'; // / directory path for compiled cache file
|
||||
/**
|
||||
* Target xml file
|
||||
* @var string
|
||||
*/
|
||||
var $xml_file = NULL;
|
||||
/**
|
||||
* Compiled js file
|
||||
* @var string
|
||||
*/
|
||||
var $js_file = NULL; // /
|
||||
var $version = '0.2.5';
|
||||
/**
|
||||
* compiled javascript cache path
|
||||
* @var string
|
||||
*/
|
||||
var $compiled_path = './files/cache/js_filter_compiled/'; // / directory path for compiled cache file
|
||||
/**
|
||||
* Target xml file
|
||||
* @var string
|
||||
*/
|
||||
var $xml_file = NULL;
|
||||
/**
|
||||
* Compiled js file
|
||||
* @var string
|
||||
*/
|
||||
var $js_file = NULL; // /
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $path
|
||||
* @param string $xml_file
|
||||
* @return void
|
||||
*/
|
||||
function XmlJsFilter($path, $xml_file) {
|
||||
if(substr($path,-1)!=='/') $path .= '/';
|
||||
$this->xml_file = sprintf("%s%s",$path, $xml_file);
|
||||
$this->js_file = $this->_getCompiledFileName($this->xml_file);
|
||||
}
|
||||
/**
|
||||
* constructor
|
||||
* @param string $path
|
||||
* @param string $xml_file
|
||||
* @return void
|
||||
*/
|
||||
function XmlJsFilter($path, $xml_file)
|
||||
{
|
||||
if(substr($path,-1)!=='/') $path .= '/';
|
||||
$this->xml_file = sprintf("%s%s",$path, $xml_file);
|
||||
$this->js_file = $this->_getCompiledFileName($this->xml_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a xml_file only when a corresponding js file does not exists or is outdated
|
||||
* @return void Returns NULL regardless of the success of failure of the operation
|
||||
*/
|
||||
function compile() {
|
||||
if(!file_exists($this->xml_file)) return;
|
||||
if(!file_exists($this->js_file)) $this->_compile();
|
||||
else if(filemtime($this->xml_file)>filemtime($this->js_file)) $this->_compile();
|
||||
Context::loadFile(array($this->js_file, 'body', '',null));
|
||||
}
|
||||
/**
|
||||
* Compile a xml_file only when a corresponding js file does not exists or is outdated
|
||||
* @return void Returns NULL regardless of the success of failure of the operation
|
||||
*/
|
||||
function compile()
|
||||
{
|
||||
if(!file_exists($this->xml_file)) return;
|
||||
if(!file_exists($this->js_file)) $this->_compile();
|
||||
else if(filemtime($this->xml_file)>filemtime($this->js_file)) $this->_compile();
|
||||
Context::loadFile(array($this->js_file, 'body', '',null));
|
||||
}
|
||||
|
||||
/**
|
||||
* compile a xml_file into js_file
|
||||
* @return void
|
||||
*/
|
||||
function _compile() {
|
||||
global $lang;
|
||||
/**
|
||||
* compile a xml_file into js_file
|
||||
* @return void
|
||||
*/
|
||||
function _compile()
|
||||
{
|
||||
global $lang;
|
||||
|
||||
// read xml file
|
||||
$buff = FileHandler::readFile($this->xml_file);
|
||||
// read xml file
|
||||
$buff = FileHandler::readFile($this->xml_file);
|
||||
|
||||
// xml parsing
|
||||
$xml_obj = parent::parse($buff);
|
||||
// xml parsing
|
||||
$xml_obj = parent::parse($buff);
|
||||
|
||||
$attrs = $xml_obj->filter->attrs;
|
||||
$rules = $xml_obj->filter->rules;
|
||||
$attrs = $xml_obj->filter->attrs;
|
||||
$rules = $xml_obj->filter->rules;
|
||||
|
||||
// XmlJsFilter handles three data; filter_name, field, and parameter
|
||||
$filter_name = $attrs->name;
|
||||
$confirm_msg_code = $attrs->confirm_msg_code;
|
||||
$module = $attrs->module;
|
||||
$act = $attrs->act;
|
||||
$extend_filter = $attrs->extend_filter;
|
||||
// XmlJsFilter handles three data; filter_name, field, and parameter
|
||||
$filter_name = $attrs->name;
|
||||
$confirm_msg_code = $attrs->confirm_msg_code;
|
||||
$module = $attrs->module;
|
||||
$act = $attrs->act;
|
||||
$extend_filter = $attrs->extend_filter;
|
||||
|
||||
|
||||
$field_node = $xml_obj->filter->form->node;
|
||||
if($field_node && !is_array($field_node)) $field_node = array($field_node);
|
||||
$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);
|
||||
$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);
|
||||
$response_tag = $xml_obj->filter->response->tag;
|
||||
if($response_tag && !is_array($response_tag)) $response_tag = array($response_tag);
|
||||
|
||||
// If extend_filter exists, result returned by calling the method
|
||||
if($extend_filter) {
|
||||
// If extend_filter exists, result returned by calling the method
|
||||
if($extend_filter)
|
||||
{
|
||||
// If extend_filter exists, it changes the name of cache not to use cache
|
||||
$this->js_file .= '.nocache.js';
|
||||
|
||||
// If extend_filter exists, it changes the name of cache not to use cache
|
||||
$this->js_file .= '.nocache.js';
|
||||
// Separate the extend_filter
|
||||
list($module_name, $method) = explode('.',$extend_filter);
|
||||
|
||||
// Separate the extend_filter
|
||||
list($module_name, $method) = explode('.',$extend_filter);
|
||||
// contibue if both module_name and methos exist.
|
||||
if($module_name&&$method)
|
||||
{
|
||||
// get model object of the module
|
||||
$oExtendFilter = &getModel($module_name);
|
||||
|
||||
// contibue if both module_name and methos exist.
|
||||
if($module_name&&$method) {
|
||||
// get model object of the module
|
||||
$oExtendFilter = &getModel($module_name);
|
||||
// execute if method exists
|
||||
if(method_exists($oExtendFilter, $method))
|
||||
{
|
||||
// get the result
|
||||
$extend_filter_list = $oExtendFilter->{$method}(true);
|
||||
$extend_filter_count = count($extend_filter_list);
|
||||
|
||||
// execute if method exists
|
||||
if(method_exists($oExtendFilter, $method)) {
|
||||
// get the result
|
||||
$extend_filter_list = $oExtendFilter->{$method}(true);
|
||||
$extend_filter_count = count($extend_filter_list);
|
||||
|
||||
// apply lang_value from the result to the variable
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// search the field to be used for entering language
|
||||
$target_list = array();
|
||||
$target_type_list = array();
|
||||
|
||||
// javascript contents
|
||||
$js_rules = array();
|
||||
$js_messages = array();
|
||||
|
||||
$fields = array();
|
||||
|
||||
// create custom rule
|
||||
if ($rules && $rules->rule) {
|
||||
if (!is_array($rules->rule)) $rules->rule = array($rules->rule);
|
||||
foreach($rules->rule as $r) {
|
||||
if ($r->attrs->type == 'regex') {
|
||||
$js_rules[] = "v.cast('ADD_RULE', ['{$r->attrs->name}', {$r->body}]);";
|
||||
// apply lang_value from the result to the variable
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// generates a field, which is a script of the checked item
|
||||
$node_count = count($field_node);
|
||||
if($node_count) {
|
||||
foreach($field_node as $key =>$node) {
|
||||
$attrs = $node->attrs;
|
||||
$target = trim($attrs->target);
|
||||
// search the field to be used for entering language
|
||||
$target_list = array();
|
||||
$target_type_list = array();
|
||||
|
||||
if(!$target) continue;
|
||||
// javascript contents
|
||||
$js_rules = array();
|
||||
$js_messages = array();
|
||||
|
||||
$rule = trim($attrs->rule?$attrs->rule:$attrs->filter);
|
||||
$equalto = trim($attrs->equalto);
|
||||
$fields = array();
|
||||
|
||||
$field = array();
|
||||
|
||||
if($attrs->required == 'true') $field[] = 'required:true';
|
||||
if($attrs->minlength > 0) $field[] = 'minlength:'.$attrs->minlength;
|
||||
if($attrs->maxlength > 0) $field[] = 'maxlength:'.$attrs->maxlength;
|
||||
if($equalto) $field[] = "equalto:'{$attrs->equalto}'";
|
||||
if($rule) $field[] = "rule:'{$rule}'";
|
||||
|
||||
$fields[] = "'{$target}': {".implode(',', $field)."}";
|
||||
|
||||
if(!in_array($target, $target_list)) $target_list[] = $target;
|
||||
if(!$target_type_list[$target]) $target_type_list[$target] = $filter;
|
||||
// create custom rule
|
||||
if($rules && $rules->rule)
|
||||
{
|
||||
if(!is_array($rules->rule)) $rules->rule = array($rules->rule);
|
||||
foreach($rules->rule as $r)
|
||||
{
|
||||
if($r->attrs->type == 'regex')
|
||||
{
|
||||
$js_rules[] = "v.cast('ADD_RULE', ['{$r->attrs->name}', {$r->body}]);";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check extend_filter_item
|
||||
$rule_types = array('homepage'=>'homepage', 'email_address'=>'email');
|
||||
|
||||
for($i=0;$i<$extend_filter_count;$i++) {
|
||||
$filter_item = $extend_filter_list[$i];
|
||||
$target = trim($filter_item->name);
|
||||
// generates a field, which is a script of the checked item
|
||||
$node_count = count($field_node);
|
||||
if($node_count)
|
||||
{
|
||||
foreach($field_node as $key =>$node)
|
||||
{
|
||||
$attrs = $node->attrs;
|
||||
$target = trim($attrs->target);
|
||||
|
||||
if(!$target) continue;
|
||||
|
||||
// get the filter from the type of extend filter item
|
||||
$type = $filter_item->type;
|
||||
$rule = $rule_types[$type]?$rule_types[$type]:'';
|
||||
$required = ($filter_item->required == 'true');
|
||||
$rule = trim($attrs->rule?$attrs->rule:$attrs->filter);
|
||||
$equalto = trim($attrs->equalto);
|
||||
|
||||
$field = array();
|
||||
if($required) $field[] = 'required:true';
|
||||
if($rule) $field[] = "rule:'{$rule}'";
|
||||
$fields[] = "\t\t'{$target}' : {".implode(',', $field)."}";
|
||||
|
||||
if($attrs->required == 'true') $field[] = 'required:true';
|
||||
if($attrs->minlength > 0) $field[] = 'minlength:'.$attrs->minlength;
|
||||
if($attrs->maxlength > 0) $field[] = 'maxlength:'.$attrs->maxlength;
|
||||
if($equalto) $field[] = "equalto:'{$attrs->equalto}'";
|
||||
if($rule) $field[] = "rule:'{$rule}'";
|
||||
|
||||
$fields[] = "'{$target}': {".implode(',', $field)."}";
|
||||
|
||||
if(!in_array($target, $target_list)) $target_list[] = $target;
|
||||
if(!$target_type_list[$target]) $target_type_list[$target] = $type;
|
||||
if(!$target_type_list[$target]) $target_type_list[$target] = $filter;
|
||||
}
|
||||
|
||||
// generates parameter script to create dbata
|
||||
$rename_params = array();
|
||||
$parameter_count = count($parameter_param);
|
||||
if($parameter_count) {
|
||||
// contains parameter of the default filter contents
|
||||
foreach($parameter_param as $key =>$param) {
|
||||
$attrs = $param->attrs;
|
||||
$name = trim($attrs->name);
|
||||
$target = trim($attrs->target);
|
||||
|
||||
//if($name && $target && ($name != $target)) $js_doc[] = "\t\tparams['{$name}'] = params['{$target}']; delete params['{$target}'];";
|
||||
if($name && $target && ($name != $target)) $rename_params[] = "'{$target}':'{$name}'";
|
||||
if($name && !in_array($name, $target_list)) $target_list[] = $name;
|
||||
}
|
||||
|
||||
// Check 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;
|
||||
|
||||
if(!in_array($name, $target_list)) $target_list[] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
// generates the response script
|
||||
$response_count = count($response_tag);
|
||||
$responses = array();
|
||||
for($i=0;$i<$response_count;$i++) {
|
||||
$attrs = $response_tag[$i]->attrs;
|
||||
$name = $attrs->name;
|
||||
$responses[] = "'{$name}'";
|
||||
}
|
||||
|
||||
// writes lang values of the form field
|
||||
$target_count = count($target_list);
|
||||
for($i=0;$i<$target_count;$i++) {
|
||||
$target = $target_list[$i];
|
||||
if(!$lang->{$target}) $lang->{$target} = $target;
|
||||
$text = preg_replace('@\r?\n@', '\\n', addslashes($lang->{$target}));
|
||||
$js_messages[] = "v.cast('ADD_MESSAGE',['{$target}','{$text}']);";
|
||||
}
|
||||
|
||||
// writes the 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);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// writes error messages
|
||||
foreach($lang->filter as $key => $val) {
|
||||
if(!$val) $val = $key;
|
||||
$val = preg_replace('@\r?\n@', '\\n', addslashes($val));
|
||||
$js_messages[] = sprintf("v.cast('ADD_MESSAGE',['%s','%s']);", $key, $val);
|
||||
}
|
||||
|
||||
$callback_func = $xml_obj->filter->response->attrs->callback_func;
|
||||
if(!$callback_func) $callback_func = "filterAlertMessage";
|
||||
|
||||
$confirm_msg = '';
|
||||
if ($confirm_msg_code) $confirm_msg = $lang->{$confirm_msg_code};
|
||||
|
||||
$jsdoc = array();
|
||||
$jsdoc[] = "function {$filter_name}(form){ return legacy_filter('{$filter_name}', form, '{$module}', '{$act}', {$callback_func}, [".implode(',', $responses)."], '".addslashes($confirm_msg)."', {".implode(',', $rename_params)."}) };";
|
||||
$jsdoc[] = '(function($){';
|
||||
$jsdoc[] = "\tvar v=xe.getApp('validator')[0];if(!v)return false;";
|
||||
$jsdoc[] = "\t".'v.cast("ADD_FILTER", ["'.$filter_name.'", {'.implode(',', $fields).'}]);';
|
||||
$jsdoc[] = "\t".implode("\n\t", $js_rules);
|
||||
$jsdoc[] = "\t".implode("\n\t", $js_messages);
|
||||
$jsdoc[] = '})(jQuery);';
|
||||
$jsdoc = implode("\n", $jsdoc);
|
||||
|
||||
// generates the js file
|
||||
FileHandler::writeFile($this->js_file, $jsdoc);
|
||||
}
|
||||
|
||||
/**
|
||||
* return a file name of js file corresponding to the xml file
|
||||
* @param string $xml_file
|
||||
* @return string
|
||||
**/
|
||||
function _getCompiledFileName($xml_file) {
|
||||
return sprintf('%s%s.%s.compiled.js',$this->compiled_path, md5($this->version.$xml_file),Context::getLangType());
|
||||
// Check extend_filter_item
|
||||
$rule_types = array('homepage'=>'homepage', 'email_address'=>'email');
|
||||
|
||||
for($i=0;$i<$extend_filter_count;$i++)
|
||||
{
|
||||
$filter_item = $extend_filter_list[$i];
|
||||
$target = trim($filter_item->name);
|
||||
|
||||
if(!$target) continue;
|
||||
|
||||
// get the filter from the type of extend filter item
|
||||
$type = $filter_item->type;
|
||||
$rule = $rule_types[$type]?$rule_types[$type]:'';
|
||||
$required = ($filter_item->required == 'true');
|
||||
|
||||
$field = array();
|
||||
if($required) $field[] = 'required:true';
|
||||
if($rule) $field[] = "rule:'{$rule}'";
|
||||
$fields[] = "\t\t'{$target}' : {".implode(',', $field)."}";
|
||||
|
||||
if(!in_array($target, $target_list)) $target_list[] = $target;
|
||||
if(!$target_type_list[$target]) $target_type_list[$target] = $type;
|
||||
}
|
||||
|
||||
// generates parameter script to create dbata
|
||||
$rename_params = array();
|
||||
$parameter_count = count($parameter_param);
|
||||
if($parameter_count)
|
||||
{
|
||||
// contains parameter of the default filter contents
|
||||
foreach($parameter_param as $key =>$param)
|
||||
{
|
||||
$attrs = $param->attrs;
|
||||
$name = trim($attrs->name);
|
||||
$target = trim($attrs->target);
|
||||
|
||||
//if($name && $target && ($name != $target)) $js_doc[] = "\t\tparams['{$name}'] = params['{$target}']; delete params['{$target}'];";
|
||||
if($name && $target && ($name != $target)) $rename_params[] = "'{$target}':'{$name}'";
|
||||
if($name && !in_array($name, $target_list)) $target_list[] = $name;
|
||||
}
|
||||
|
||||
// Check 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;
|
||||
|
||||
if(!in_array($name, $target_list)) $target_list[] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
// generates the response script
|
||||
$response_count = count($response_tag);
|
||||
$responses = array();
|
||||
for($i=0;$i<$response_count;$i++)
|
||||
{
|
||||
$attrs = $response_tag[$i]->attrs;
|
||||
$name = $attrs->name;
|
||||
$responses[] = "'{$name}'";
|
||||
}
|
||||
|
||||
// writes lang values of the form field
|
||||
$target_count = count($target_list);
|
||||
for($i=0;$i<$target_count;$i++)
|
||||
{
|
||||
$target = $target_list[$i];
|
||||
if(!$lang->{$target}) $lang->{$target} = $target;
|
||||
$text = preg_replace('@\r?\n@', '\\n', addslashes($lang->{$target}));
|
||||
$js_messages[] = "v.cast('ADD_MESSAGE',['{$target}','{$text}']);";
|
||||
}
|
||||
|
||||
// writes the 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);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// writes error messages
|
||||
foreach($lang->filter as $key => $val)
|
||||
{
|
||||
if(!$val) $val = $key;
|
||||
$val = preg_replace('@\r?\n@', '\\n', addslashes($val));
|
||||
$js_messages[] = sprintf("v.cast('ADD_MESSAGE',['%s','%s']);", $key, $val);
|
||||
}
|
||||
|
||||
$callback_func = $xml_obj->filter->response->attrs->callback_func;
|
||||
if(!$callback_func) $callback_func = "filterAlertMessage";
|
||||
|
||||
$confirm_msg = '';
|
||||
if ($confirm_msg_code) $confirm_msg = $lang->{$confirm_msg_code};
|
||||
|
||||
$jsdoc = array();
|
||||
$jsdoc[] = "function {$filter_name}(form){ return legacy_filter('{$filter_name}', form, '{$module}', '{$act}', {$callback_func}, [".implode(',', $responses)."], '".addslashes($confirm_msg)."', {".implode(',', $rename_params)."}) };";
|
||||
$jsdoc[] = '(function($){';
|
||||
$jsdoc[] = "\tvar v=xe.getApp('validator')[0];if(!v)return false;";
|
||||
$jsdoc[] = "\t".'v.cast("ADD_FILTER", ["'.$filter_name.'", {'.implode(',', $fields).'}]);';
|
||||
$jsdoc[] = "\t".implode("\n\t", $js_rules);
|
||||
$jsdoc[] = "\t".implode("\n\t", $js_messages);
|
||||
$jsdoc[] = '})(jQuery);';
|
||||
$jsdoc = implode("\n", $jsdoc);
|
||||
|
||||
// generates the js file
|
||||
FileHandler::writeFile($this->js_file, $jsdoc);
|
||||
}
|
||||
?>
|
||||
|
||||
/**
|
||||
* return a file name of js file corresponding to the xml file
|
||||
* @param string $xml_file
|
||||
* @return string
|
||||
*/
|
||||
function _getCompiledFileName($xml_file)
|
||||
{
|
||||
return sprintf('%s%s.%s.compiled.js',$this->compiled_path, md5($this->version.$xml_file),Context::getLangType());
|
||||
}
|
||||
}
|
||||
/* End of file XmlJsFilter.class.php */
|
||||
/* Location: ./classes/xml/XmlJsFilter.class.php */
|
||||
|
|
|
|||
|
|
@ -1,198 +1,223 @@
|
|||
<?php
|
||||
/**
|
||||
* XmlLangParser class
|
||||
* Change to lang php file from xml.
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml
|
||||
* @version 0.1
|
||||
*/
|
||||
class XmlLangParser extends XmlParser
|
||||
{
|
||||
/**
|
||||
* XmlLangParser class
|
||||
* Change to lang php file from xml.
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml
|
||||
* @version 0.1
|
||||
**/
|
||||
class XmlLangParser extends XmlParser {
|
||||
/**
|
||||
* compiled language cache path
|
||||
* @var string
|
||||
*/
|
||||
var $compiled_path = './files/cache/lang/'; // / directory path for compiled cache file
|
||||
/**
|
||||
* Target xml file
|
||||
* @var string
|
||||
*/
|
||||
var $xml_file = NULL;
|
||||
/**
|
||||
* Target php file
|
||||
* @var string
|
||||
*/
|
||||
var $php_file = NULL;
|
||||
/**
|
||||
* result source code
|
||||
* @var string
|
||||
*/
|
||||
var $code;
|
||||
/**
|
||||
* language list, for example ko, en...
|
||||
* @var array
|
||||
*/
|
||||
var $lang_types;
|
||||
/**
|
||||
* language type
|
||||
* @see _XE_PATH_.'/common/lang/lang.info'
|
||||
* @var string
|
||||
*/
|
||||
var $lang_type;
|
||||
* compiled language cache path
|
||||
* @var string
|
||||
*/
|
||||
var $compiled_path = './files/cache/lang/'; // / directory path for compiled cache file
|
||||
/**
|
||||
* Target xml file
|
||||
* @var string
|
||||
*/
|
||||
var $xml_file = NULL;
|
||||
/**
|
||||
* Target php file
|
||||
* @var string
|
||||
*/
|
||||
var $php_file = NULL;
|
||||
/**
|
||||
* result source code
|
||||
* @var string
|
||||
*/
|
||||
var $code;
|
||||
/**
|
||||
* language list, for example ko, en...
|
||||
* @var array
|
||||
*/
|
||||
var $lang_types;
|
||||
/**
|
||||
* language type
|
||||
* @see _XE_PATH_.'/common/lang/lang.info'
|
||||
* @var string
|
||||
*/
|
||||
var $lang_type;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $xml_file
|
||||
* @param string $lang_type
|
||||
* @return void
|
||||
*/
|
||||
function XmlLangParser($xml_file, $lang_type) {
|
||||
$this->lang_type = $lang_type;
|
||||
$this->xml_file = $xml_file;
|
||||
$this->php_file = $this->_getCompiledFileName($lang_type);
|
||||
}
|
||||
/**
|
||||
* constructor
|
||||
* @param string $xml_file
|
||||
* @param string $lang_type
|
||||
* @return void
|
||||
*/
|
||||
function XmlLangParser($xml_file, $lang_type)
|
||||
{
|
||||
$this->lang_type = $lang_type;
|
||||
$this->xml_file = $xml_file;
|
||||
$this->php_file = $this->_getCompiledFileName($lang_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* compile a xml_file only when a corresponding php lang file does not exists or is outdated
|
||||
* @return string|bool Returns compiled php file.
|
||||
*/
|
||||
function compile() {
|
||||
if(!file_exists($this->xml_file)) return false;
|
||||
if(!file_exists($this->php_file)){
|
||||
$this->_compile();
|
||||
} else {
|
||||
if(filemtime($this->xml_file)>filemtime($this->php_file)) $this->_compile();
|
||||
else return $this->php_file;
|
||||
}
|
||||
|
||||
return $this->_writeFile() ? $this->php_file : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return compiled content
|
||||
* @return string Returns compiled lang source code
|
||||
*/
|
||||
function getCompileContent() {
|
||||
if(!file_exists($this->xml_file)) return false;
|
||||
/**
|
||||
* compile a xml_file only when a corresponding php lang file does not exists or is outdated
|
||||
* @return string|bool Returns compiled php file.
|
||||
*/
|
||||
function compile()
|
||||
{
|
||||
if(!file_exists($this->xml_file)) return false;
|
||||
if(!file_exists($this->php_file))
|
||||
{
|
||||
$this->_compile();
|
||||
|
||||
return $this->code;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(filemtime($this->xml_file)>filemtime($this->php_file)) $this->_compile();
|
||||
else return $this->php_file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a xml_file
|
||||
* @return void
|
||||
*/
|
||||
function _compile() {
|
||||
$lang_selected = Context::loadLangSelected();
|
||||
$this->lang_types = array_keys($lang_selected);
|
||||
return $this->_writeFile() ? $this->php_file : false;
|
||||
}
|
||||
|
||||
// read xml file
|
||||
$buff = FileHandler::readFile($this->xml_file);
|
||||
$buff = str_replace('xml:lang','xml_lang',$buff);
|
||||
/**
|
||||
* Return compiled content
|
||||
* @return string Returns compiled lang source code
|
||||
*/
|
||||
function getCompileContent()
|
||||
{
|
||||
if(!file_exists($this->xml_file)) return false;
|
||||
$this->_compile();
|
||||
|
||||
// xml parsing
|
||||
$xml_obj = parent::parse($buff);
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
$item = $xml_obj->lang->item;
|
||||
if(!is_array($item)) $item = array($item);
|
||||
foreach($item as $i){
|
||||
$this->_parseItem($i, $var='$lang->%s');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Compile a xml_file
|
||||
* @return void
|
||||
*/
|
||||
function _compile()
|
||||
{
|
||||
$lang_selected = Context::loadLangSelected();
|
||||
$this->lang_types = array_keys($lang_selected);
|
||||
|
||||
/**
|
||||
* Writing cache file
|
||||
* @return void|bool
|
||||
*/
|
||||
function _writeFile(){
|
||||
if(!$this->code) return;
|
||||
FileHandler::writeFile($this->php_file, "<?php\n".$this->code);
|
||||
return false;
|
||||
}
|
||||
// read xml file
|
||||
$buff = FileHandler::readFile($this->xml_file);
|
||||
$buff = str_replace('xml:lang','xml_lang',$buff);
|
||||
|
||||
/**
|
||||
* Parsing item node, set content to '$this->code'
|
||||
* @param object $item
|
||||
* @param string $var
|
||||
* @return void
|
||||
*/
|
||||
function _parseItem($item, $var){
|
||||
$name = $item->attrs->name;
|
||||
$value = $item->value;
|
||||
$var = sprintf($var, $name);
|
||||
// xml parsing
|
||||
$xml_obj = parent::parse($buff);
|
||||
|
||||
if($item->item) {
|
||||
$type = $item->attrs->type;
|
||||
|
||||
if($type == 'array'){
|
||||
$this->code .= $var."=array();\n";
|
||||
$var .= '[\'%s\']';
|
||||
}else{
|
||||
$this->code .= $var."=new stdClass;\n";
|
||||
$var .= '->%s';
|
||||
}
|
||||
|
||||
$items = $item->item;
|
||||
if(!is_array($items)) $items = array($items);
|
||||
foreach($items as $item){
|
||||
$this->_parseItem($item, $var);
|
||||
}
|
||||
|
||||
} else {
|
||||
$code = $this->_parseValues($value, $var);
|
||||
$this->code .= $code;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsing value nodes
|
||||
* @param array $nodes
|
||||
* @param string $var
|
||||
* @return array|string
|
||||
*/
|
||||
function _parseValues($nodes, $var) {
|
||||
if(!is_array($nodes)) $nodes = array($nodes);
|
||||
|
||||
$value = array();
|
||||
foreach($nodes as $node){
|
||||
$return = $this->_parseValue($node, $var);
|
||||
if($return && is_array($return)) $value = array_merge($value, $return);
|
||||
}
|
||||
|
||||
if($value[$this->lang_type]) return $value[$this->lang_type];
|
||||
else if($value['en']) return $value['en'];
|
||||
else if($value['ko']) return $value['ko'];
|
||||
|
||||
foreach($this->lang_types as $lang_type) {
|
||||
if($lang_type == 'en' || $lang_type == 'ko' || $lang_type == $this->lang_type) continue;
|
||||
if($value[$lang_type]) return $value[$lang_type];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsing value node
|
||||
* @param object $node
|
||||
* @param string $var
|
||||
* @return array|bool
|
||||
*/
|
||||
function _parseValue($node, $var) {
|
||||
$lang_type = $node->attrs->xml_lang;
|
||||
$value = $node->body;
|
||||
if(!$value) return false;
|
||||
|
||||
$var .= '=\'' . str_replace("'","\'",$value) . "';\n";
|
||||
return array($lang_type=>$var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cache file name
|
||||
* @param string $lang_type
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
function _getCompiledFileName($lang_type, $type='php') {
|
||||
return sprintf('%s%s.%s.php',$this->compiled_path, md5($this->xml_file), $lang_type);
|
||||
$item = $xml_obj->lang->item;
|
||||
if(!is_array($item)) $item = array($item);
|
||||
foreach($item as $i)
|
||||
{
|
||||
$this->_parseItem($i, $var='$lang->%s');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writing cache file
|
||||
* @return void|bool
|
||||
*/
|
||||
function _writeFile()
|
||||
{
|
||||
if(!$this->code) return;
|
||||
FileHandler::writeFile($this->php_file, "<?php\n".$this->code);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsing item node, set content to '$this->code'
|
||||
* @param object $item
|
||||
* @param string $var
|
||||
* @return void
|
||||
*/
|
||||
function _parseItem($item, $var)
|
||||
{
|
||||
$name = $item->attrs->name;
|
||||
$value = $item->value;
|
||||
$var = sprintf($var, $name);
|
||||
|
||||
if($item->item)
|
||||
{
|
||||
$type = $item->attrs->type;
|
||||
|
||||
if($type == 'array')
|
||||
{
|
||||
$this->code .= $var."=array();\n";
|
||||
$var .= '[\'%s\']';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->code .= $var."=new stdClass;\n";
|
||||
$var .= '->%s';
|
||||
}
|
||||
|
||||
$items = $item->item;
|
||||
if(!is_array($items)) $items = array($items);
|
||||
foreach($items as $item)
|
||||
{
|
||||
$this->_parseItem($item, $var);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$code = $this->_parseValues($value, $var);
|
||||
$this->code .= $code;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsing value nodes
|
||||
* @param array $nodes
|
||||
* @param string $var
|
||||
* @return array|string
|
||||
*/
|
||||
function _parseValues($nodes, $var)
|
||||
{
|
||||
if(!is_array($nodes)) $nodes = array($nodes);
|
||||
|
||||
$value = array();
|
||||
foreach($nodes as $node)
|
||||
{
|
||||
$return = $this->_parseValue($node, $var);
|
||||
if($return && is_array($return)) $value = array_merge($value, $return);
|
||||
}
|
||||
|
||||
if($value[$this->lang_type]) return $value[$this->lang_type];
|
||||
else if($value['en']) return $value['en'];
|
||||
else if($value['ko']) return $value['ko'];
|
||||
|
||||
foreach($this->lang_types as $lang_type)
|
||||
{
|
||||
if($lang_type == 'en' || $lang_type == 'ko' || $lang_type == $this->lang_type) continue;
|
||||
if($value[$lang_type]) return $value[$lang_type];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsing value node
|
||||
* @param object $node
|
||||
* @param string $var
|
||||
* @return array|bool
|
||||
*/
|
||||
function _parseValue($node, $var)
|
||||
{
|
||||
$lang_type = $node->attrs->xml_lang;
|
||||
$value = $node->body;
|
||||
if(!$value) return false;
|
||||
|
||||
$var .= '=\'' . str_replace("'","\'",$value) . "';\n";
|
||||
return array($lang_type=>$var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cache file name
|
||||
* @param string $lang_type
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
function _getCompiledFileName($lang_type, $type='php')
|
||||
{
|
||||
return sprintf('%s%s.%s.php',$this->compiled_path, md5($this->xml_file), $lang_type);
|
||||
}
|
||||
}
|
||||
/* End of file XmlLangParser.class.php */
|
||||
/* Location: ./classes/xml/XmlLangParser.class.php */
|
||||
|
|
|
|||
|
|
@ -1,195 +1,217 @@
|
|||
<?php
|
||||
/**
|
||||
* Xml_Node_ class
|
||||
* Element node or attribute node.
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml
|
||||
* @version 0.1
|
||||
*/
|
||||
class Xml_Node_
|
||||
{
|
||||
/**
|
||||
* Xml_Node_ class
|
||||
* Element node or attribute node.
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml
|
||||
* @version 0.1
|
||||
*/
|
||||
class Xml_Node_
|
||||
{
|
||||
/** In PHP5 this will silence E_STRICT warnings
|
||||
* for undeclared properties.
|
||||
* No effect in PHP4
|
||||
*/
|
||||
function __get($name)
|
||||
{
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* XmlParser class
|
||||
* Class parsing a given xmlrpc request and creating a data object
|
||||
* @remarks <pre>{
|
||||
* This class may drops unsupported xml lanuage attributes when multiple language attributes are given.
|
||||
* For example, if 'xml:lang='ko, en, ch, jp..' is given in a xml file, only ko will be left ignoring all other language
|
||||
* attributes when kor is only supported language. It seems to work fine now but we did not scrutinze any potential side effects,
|
||||
* }</pre>
|
||||
*
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml
|
||||
* @version 0.1
|
||||
*/
|
||||
class XmlParser
|
||||
{
|
||||
/**
|
||||
* Xml parser
|
||||
* @var resource
|
||||
*/
|
||||
var $oParser = NULL;
|
||||
/**
|
||||
* Input xml
|
||||
* @var string
|
||||
*/
|
||||
var $input = NULL;
|
||||
/**
|
||||
* Output object in array
|
||||
* @var array
|
||||
*/
|
||||
var $output = array();
|
||||
/**
|
||||
* The default language type
|
||||
* @var string
|
||||
*/
|
||||
var $lang = "en";
|
||||
|
||||
/**
|
||||
* XmlParser class
|
||||
* Class parsing a given xmlrpc request and creating a data object
|
||||
* @remarks <pre>{
|
||||
* This class may drops unsupported xml lanuage attributes when multiple language attributes are given.
|
||||
* For example, if 'xml:lang='ko, en, ch, jp..' is given in a xml file, only ko will be left ignoring all other language
|
||||
* attributes when kor is only supported language. It seems to work fine now but we did not scrutinze any potential side effects,
|
||||
* }</pre>
|
||||
*
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml
|
||||
* @version 0.1
|
||||
* Load a xml file specified by a filename and parse it to Return the resultant data object
|
||||
* @param string $filename a file path of file
|
||||
* @return array Returns a data object containing data extracted from a xml file or NULL if a specified file does not exist
|
||||
*/
|
||||
class XmlParser {
|
||||
/**
|
||||
* Xml parser
|
||||
* @var resource
|
||||
*/
|
||||
var $oParser = NULL;
|
||||
/**
|
||||
* Input xml
|
||||
* @var string
|
||||
*/
|
||||
var $input = NULL;
|
||||
/**
|
||||
* Output object in array
|
||||
* @var array
|
||||
*/
|
||||
var $output = array();
|
||||
/**
|
||||
* The default language type
|
||||
* @var string
|
||||
*/
|
||||
var $lang = "en";
|
||||
function loadXmlFile($filename)
|
||||
{
|
||||
if(!file_exists($filename)) return;
|
||||
$buff = FileHandler::readFile($filename);
|
||||
|
||||
/**
|
||||
* Load a xml file specified by a filename and parse it to Return the resultant data object
|
||||
* @param string $filename a file path of file
|
||||
* @return array Returns a data object containing data extracted from a xml file or NULL if a specified file does not exist
|
||||
*/
|
||||
function loadXmlFile($filename) {
|
||||
if(!file_exists($filename)) return;
|
||||
$buff = FileHandler::readFile($filename);
|
||||
$oXmlParser = new XmlParser();
|
||||
return $oXmlParser->parse($buff);
|
||||
}
|
||||
|
||||
$oXmlParser = new XmlParser();
|
||||
return $oXmlParser->parse($buff);
|
||||
}
|
||||
/**
|
||||
* Parse xml data to extract values from it and construct data object
|
||||
* @param string $input a data buffer containing xml data
|
||||
* @param mixed $arg1 ???
|
||||
* @param mixed $arg2 ???
|
||||
* @return array Returns a resultant data object or NULL in case of error
|
||||
*/
|
||||
function parse($input = '', $arg1 = NULL, $arg2 = NULL)
|
||||
{
|
||||
// Save the compile starting time for debugging
|
||||
if(__DEBUG__==3) $start = getMicroTime();
|
||||
|
||||
/**
|
||||
* Parse xml data to extract values from it and construct data object
|
||||
* @param string $input a data buffer containing xml data
|
||||
* @param mixed $arg1 ???
|
||||
* @param mixed $arg2 ???
|
||||
* @return array Returns a resultant data object or NULL in case of error
|
||||
*/
|
||||
function parse($input = '', $arg1 = NULL, $arg2 = NULL) {
|
||||
// Save the compile starting time for debugging
|
||||
if(__DEBUG__==3) $start = getMicroTime();
|
||||
$this->lang = Context::getLangType();
|
||||
|
||||
$this->lang = Context::getLangType();
|
||||
$this->input = $input?$input:$GLOBALS['HTTP_RAW_POST_DATA'];
|
||||
$this->input = str_replace(array('',''),array('',''),$this->input);
|
||||
|
||||
$this->input = $input?$input:$GLOBALS['HTTP_RAW_POST_DATA'];
|
||||
$this->input = str_replace(array('',''),array('',''),$this->input);
|
||||
// extracts a supported language
|
||||
preg_match_all("/xml:lang=\"([^\"].+)\"/i", $this->input, $matches);
|
||||
|
||||
// extracts a supported language
|
||||
preg_match_all("/xml:lang=\"([^\"].+)\"/i", $this->input, $matches);
|
||||
// extracts the supported lanuage when xml:lang is used
|
||||
if(count($matches[1]) && $supported_lang = array_unique($matches[1]))
|
||||
{
|
||||
$tmpLangList = array_flip($supported_lang);
|
||||
// if lang of the first log-in user doesn't exist, apply en by default if exists. Otherwise apply the first lang.
|
||||
if(!isset($tmpLangList[$this->lang]))
|
||||
{
|
||||
if(isset($tmpLangList['en']))
|
||||
{
|
||||
$this->lang = 'en';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->lang = array_shift($supported_lang);
|
||||
}
|
||||
}
|
||||
// uncheck the language if no specific language is set.
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->lang = '';
|
||||
}
|
||||
|
||||
// extracts the supported lanuage when xml:lang is used
|
||||
if(count($matches[1]) && $supported_lang = array_unique($matches[1])) {
|
||||
$tmpLangList = array_flip($supported_lang);
|
||||
// if lang of the first log-in user doesn't exist, apply en by default if exists. Otherwise apply the first lang.
|
||||
if(!isset($tmpLangList[$this->lang])) {
|
||||
if(isset($tmpLangList['en'])) {
|
||||
$this->lang = 'en';
|
||||
} else {
|
||||
$this->lang = array_shift($supported_lang);
|
||||
}
|
||||
}
|
||||
// uncheck the language if no specific language is set.
|
||||
} else {
|
||||
$this->lang = '';
|
||||
}
|
||||
$this->oParser = xml_parser_create('UTF-8');
|
||||
|
||||
$this->oParser = xml_parser_create('UTF-8');
|
||||
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;
|
||||
|
||||
if(!count($this->output)) return;
|
||||
$output = array_shift($this->output);
|
||||
// Save compile starting time for debugging
|
||||
if(__DEBUG__==3) $GLOBALS['__xmlparse_elapsed__'] += getMicroTime() - $start;
|
||||
|
||||
$output = array_shift($this->output);
|
||||
// Save compile starting time for debugging
|
||||
if(__DEBUG__==3) $GLOBALS['__xmlparse_elapsed__'] += getMicroTime() - $start;
|
||||
|
||||
return $output;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start element handler.
|
||||
* @param resource $parse an instance of parser
|
||||
* @param string $node_name a name of node
|
||||
* @param array $attrs attributes to be set
|
||||
* @return array
|
||||
*/
|
||||
function _tagOpen($parser, $node_name, $attrs) {
|
||||
$obj = new Xml_Node_();
|
||||
$obj->node_name = strtolower($node_name);
|
||||
$obj->attrs = $this->_arrToAttrsObj($attrs);
|
||||
/**
|
||||
* Start element handler.
|
||||
* @param resource $parse an instance of parser
|
||||
* @param string $node_name a name of node
|
||||
* @param array $attrs attributes to be set
|
||||
* @return array
|
||||
*/
|
||||
function _tagOpen($parser, $node_name, $attrs)
|
||||
{
|
||||
$obj = new Xml_Node_();
|
||||
$obj->node_name = strtolower($node_name);
|
||||
$obj->attrs = $this->_arrToAttrsObj($attrs);
|
||||
|
||||
array_push($this->output, $obj);
|
||||
}
|
||||
array_push($this->output, $obj);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Character data handler
|
||||
* Variable in the last element of this->output
|
||||
* @param resource $parse an instance of parser
|
||||
* @param string $body a data to be added
|
||||
* @return void
|
||||
*/
|
||||
function _tagBody($parser, $body) {
|
||||
//if(!trim($body)) return;
|
||||
$this->output[count($this->output)-1]->body .= $body;
|
||||
}
|
||||
/**
|
||||
* Character data handler
|
||||
* Variable in the last element of this->output
|
||||
* @param resource $parse an instance of parser
|
||||
* @param string $body a data to be added
|
||||
* @return void
|
||||
*/
|
||||
function _tagBody($parser, $body)
|
||||
{
|
||||
//if(!trim($body)) return;
|
||||
$this->output[count($this->output)-1]->body .= $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* End element handler
|
||||
* @param resource $parse an instance of parser
|
||||
* @param string $node_name name of xml node
|
||||
* @return void
|
||||
*/
|
||||
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;
|
||||
/**
|
||||
* End element handler
|
||||
* @param resource $parse an instance of parser
|
||||
* @param string $node_name name of xml node
|
||||
* @return void
|
||||
*/
|
||||
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(isset($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 {
|
||||
if (!is_object($parent_obj))
|
||||
$parent_obj = (object)$parent_obj;
|
||||
if(isset($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
|
||||
{
|
||||
if(!is_object($parent_obj))
|
||||
$parent_obj = (object)$parent_obj;
|
||||
|
||||
$parent_obj->{$node_name} = $cur_obj;
|
||||
}
|
||||
}
|
||||
$parent_obj->{$node_name} = $cur_obj;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to transfer values in an array to a data object
|
||||
* @param array $arr data array
|
||||
* @return Xml_Node_ object
|
||||
**/
|
||||
function _arrToAttrsObj($arr) {
|
||||
$output = new Xml_Node_();
|
||||
foreach($arr as $key => $val) {
|
||||
$key = strtolower($key);
|
||||
$output->{$key} = $val;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
?>
|
||||
/**
|
||||
* Method to transfer values in an array to a data object
|
||||
* @param array $arr data array
|
||||
* @return Xml_Node_ object
|
||||
*/
|
||||
function _arrToAttrsObj($arr)
|
||||
{
|
||||
$output = new Xml_Node_();
|
||||
foreach($arr as $key => $val)
|
||||
{
|
||||
$key = strtolower($key);
|
||||
$output->{$key} = $val;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
/* End of file XmlParser.class.php */
|
||||
/* Location: ./classes/xml/XmlParser.class.php */
|
||||
|
|
|
|||
|
|
@ -1,109 +1,110 @@
|
|||
<?php
|
||||
if(!defined('__XE_LOADED_XML_CLASS__')){
|
||||
define('__XE_LOADED_XML_CLASS__', 1);
|
||||
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/query/QueryTag.class.php');
|
||||
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/table/TableTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/table/HintTableTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/table/TablesTag.class.php');
|
||||
if(!defined('__XE_LOADED_XML_CLASS__'))
|
||||
{
|
||||
define('__XE_LOADED_XML_CLASS__', 1);
|
||||
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/query/QueryTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/table/TableTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/table/HintTableTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/table/TablesTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/ColumnTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/SelectColumnTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php');
|
||||
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionsTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php');
|
||||
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/group/GroupsTag.class.php');
|
||||
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/navigation/NavigationTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/navigation/IndexTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/SelectColumnTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionsTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/group/GroupsTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/navigation/NavigationTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/navigation/IndexTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/navigation/LimitTag.class.php');
|
||||
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/QueryArgument.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/SortQueryArgument.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/QueryArgument.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/SortQueryArgument.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/DefaultValue.class.php');
|
||||
}
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/DefaultValue.class.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* New XmlQueryParser class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @brief case to parse XE xml query
|
||||
* @version 0.1
|
||||
*
|
||||
* @todo need to support extend query such as subquery, union
|
||||
* @todo include info about column types for parsing user input
|
||||
*/
|
||||
class XmlQueryParser extends XmlParser
|
||||
{
|
||||
/**
|
||||
* New XmlQueryParser class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @brief case to parse XE xml query
|
||||
* @version 0.1
|
||||
*
|
||||
* @todo need to support extend query such as subquery, union
|
||||
* @todo include info about column types for parsing user input
|
||||
* constructor
|
||||
* @return void
|
||||
*/
|
||||
class XmlQueryParser extends XmlParser {
|
||||
/**
|
||||
* constructor
|
||||
* @return void
|
||||
*/
|
||||
function XmlQueryParser(){
|
||||
}
|
||||
|
||||
/**
|
||||
* Create XmlQueryParser instance for Singleton
|
||||
* @return XmlQueryParser object
|
||||
*/
|
||||
function &getInstance(){
|
||||
static $theInstance = null;
|
||||
if(!isset($theInstance)){
|
||||
$theInstance = new XmlQueryParser();
|
||||
}
|
||||
return $theInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. Read xml file<br />
|
||||
* 2. Check the action<br />
|
||||
* 3. Parsing and write a cache file<br />
|
||||
* @return QueryParser object
|
||||
*/
|
||||
function &parse_xml_query($query_id, $xml_file, $cache_file)
|
||||
function XmlQueryParser()
|
||||
{
|
||||
// Read xml file
|
||||
$xml_obj = $this->getXmlFileContent($xml_file);
|
||||
|
||||
// insert, update, delete, select action
|
||||
$action = strtolower($xml_obj->query->attrs->action);
|
||||
if(!$action) return;
|
||||
|
||||
// Write query cache file
|
||||
$parser = new QueryParser($xml_obj->query);
|
||||
FileHandler::writeFile($cache_file, $parser->toString());
|
||||
|
||||
return $parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query XML file parsing
|
||||
* @return QueryParser object
|
||||
*/
|
||||
function parse($query_id = NULL, $xml_file = NULL, $cache_file = NULL)
|
||||
{
|
||||
$this->parse_xml_query($query_id, $xml_file, $cache_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return XML file content
|
||||
* @return array|NULL Returns a resultant data object or NULL in case of error
|
||||
*/
|
||||
function getXmlFileContent($xml_file){
|
||||
$buff = FileHandler::readFile($xml_file);
|
||||
$xml_obj = parent::parse($buff);
|
||||
if(!$xml_obj) return;
|
||||
unset($buff);
|
||||
return $xml_obj;
|
||||
}
|
||||
}
|
||||
?>
|
||||
/**
|
||||
* Create XmlQueryParser instance for Singleton
|
||||
* @return XmlQueryParser object
|
||||
*/
|
||||
function &getInstance()
|
||||
{
|
||||
static $theInstance = null;
|
||||
if(!isset($theInstance))
|
||||
{
|
||||
$theInstance = new XmlQueryParser();
|
||||
}
|
||||
return $theInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. Read xml file<br />
|
||||
* 2. Check the action<br />
|
||||
* 3. Parsing and write a cache file<br />
|
||||
* @return QueryParser object
|
||||
*/
|
||||
function &parse_xml_query($query_id, $xml_file, $cache_file)
|
||||
{
|
||||
// Read xml file
|
||||
$xml_obj = $this->getXmlFileContent($xml_file);
|
||||
|
||||
// insert, update, delete, select action
|
||||
$action = strtolower($xml_obj->query->attrs->action);
|
||||
if(!$action) return;
|
||||
|
||||
// Write query cache file
|
||||
$parser = new QueryParser($xml_obj->query);
|
||||
FileHandler::writeFile($cache_file, $parser->toString());
|
||||
|
||||
return $parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query XML file parsing
|
||||
* @return QueryParser object
|
||||
*/
|
||||
function parse($query_id = NULL, $xml_file = NULL, $cache_file = NULL)
|
||||
{
|
||||
$this->parse_xml_query($query_id, $xml_file, $cache_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return XML file content
|
||||
* @return array|NULL Returns a resultant data object or NULL in case of error
|
||||
*/
|
||||
function getXmlFileContent($xml_file)
|
||||
{
|
||||
$buff = FileHandler::readFile($xml_file);
|
||||
$xml_obj = parent::parse($buff);
|
||||
if(!$xml_obj) return;
|
||||
unset($buff);
|
||||
return $xml_obj;
|
||||
}
|
||||
}
|
||||
/* End of file XmlQueryParser.150.class.php */
|
||||
/* Location: ./classes/xml/XmlQueryParser.150.class.php */
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,193 +1,214 @@
|
|||
<?php
|
||||
/**
|
||||
* DBParser class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery
|
||||
* @version 0.1
|
||||
*/
|
||||
class DBParser
|
||||
{
|
||||
/**
|
||||
* DBParser class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery
|
||||
* @version 0.1
|
||||
* Character for escape target value on the left
|
||||
* @var string
|
||||
*/
|
||||
class DBParser {
|
||||
/**
|
||||
* Character for escape target value on the left
|
||||
* @var string
|
||||
*/
|
||||
var $escape_char_left;
|
||||
/**
|
||||
* Character for escape target value on the right
|
||||
* @var string
|
||||
*/
|
||||
var $escape_char_right;
|
||||
/**
|
||||
* Table prefix string
|
||||
* @var string
|
||||
*/
|
||||
var $table_prefix;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $escape_char_left
|
||||
* @param string $escape_char_right
|
||||
* @param string $table_prefix
|
||||
* @return void
|
||||
*/
|
||||
function DBParser($escape_char_left, $escape_char_right = "", $table_prefix = "xe_"){
|
||||
$this->escape_char_left = $escape_char_left;
|
||||
if ($escape_char_right !== "")$this->escape_char_right = $escape_char_right;
|
||||
else $this->escape_char_right = $escape_char_left;
|
||||
$this->table_prefix = $table_prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get escape character
|
||||
* @param string $leftOrRight left or right
|
||||
* @return string
|
||||
*/
|
||||
function getEscapeChar($leftOrRight){
|
||||
if ($leftOrRight === 'left')return $this->escape_char_left;
|
||||
else return $this->escape_char_right;
|
||||
}
|
||||
|
||||
/**
|
||||
* escape the value
|
||||
* @param mixed $name
|
||||
* @return string
|
||||
*/
|
||||
function escape($name){
|
||||
return $this->escape_char_left . $name . $this->escape_char_right;
|
||||
}
|
||||
|
||||
/**
|
||||
* escape the string value
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
function escapeString($name){
|
||||
return "'".$this->escapeStringValue($name)."'";
|
||||
}
|
||||
|
||||
/**
|
||||
* escape the string value
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
function escapeStringValue($value){
|
||||
if($value == "*") return $value;
|
||||
if (is_string($value)) return $value = str_replace("'","''",$value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return table full name
|
||||
* @param string $name table name without table prefix
|
||||
* @return string table full name with table prefix
|
||||
*/
|
||||
function parseTableName($name){
|
||||
return $this->table_prefix . $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return colmun name after escape
|
||||
* @param string $name column name before escape
|
||||
* @return string column name after escape
|
||||
*/
|
||||
function parseColumnName($name){
|
||||
return $this->escapeColumn($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape column
|
||||
* @param string $column_name
|
||||
* @return string column name with db name
|
||||
*/
|
||||
function escapeColumn($column_name){
|
||||
if($this->isUnqualifiedColumnName($column_name))
|
||||
return $this->escape($column_name);
|
||||
if($this->isQualifiedColumnName($column_name)){
|
||||
list($table, $column) = explode('.', $column_name);
|
||||
// $table can also be an alias, so the prefix should not be added
|
||||
return $this->escape($table).'.'.$this->escape($column);
|
||||
//return $this->escape($this->parseTableName($table)).'.'.$this->escape($column);
|
||||
}
|
||||
}
|
||||
var $escape_char_left;
|
||||
/**
|
||||
* Character for escape target value on the right
|
||||
* @var string
|
||||
*/
|
||||
var $escape_char_right;
|
||||
/**
|
||||
* Table prefix string
|
||||
* @var string
|
||||
*/
|
||||
var $table_prefix;
|
||||
|
||||
/**
|
||||
* Column name is suitable for use in checking
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isUnqualifiedColumnName($column_name){
|
||||
if(strpos($column_name,'.')===false && strpos($column_name,'(')===false) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Column name is suitable for use in checking
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isQualifiedColumnName($column_name){
|
||||
if(strpos($column_name,'.')!==false && strpos($column_name,'(')===false) return true;
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* constructor
|
||||
* @param string $escape_char_left
|
||||
* @param string $escape_char_right
|
||||
* @param string $table_prefix
|
||||
* @return void
|
||||
*/
|
||||
function DBParser($escape_char_left, $escape_char_right = "", $table_prefix = "xe_")
|
||||
{
|
||||
$this->escape_char_left = $escape_char_left;
|
||||
if ($escape_char_right !== "")$this->escape_char_right = $escape_char_right;
|
||||
else $this->escape_char_right = $escape_char_left;
|
||||
$this->table_prefix = $table_prefix;
|
||||
}
|
||||
|
||||
function parseExpression($column_name){
|
||||
$functions = preg_split('/([\+\-\*\/\ ])/', $column_name, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
||||
foreach($functions as $k => $v){
|
||||
$function = &$functions[$k];
|
||||
if(strlen($function)==1) continue; // skip delimiters
|
||||
$pos = strrpos("(", $function);
|
||||
$matches = preg_split('/([a-zA-Z0-9_*]+)/', $function, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
||||
$total_brackets = substr_count($function, "(");
|
||||
$brackets = 0;
|
||||
foreach($matches as $i => $j){
|
||||
$match = &$matches[$i];
|
||||
if($match == '(') {$brackets++; continue;}
|
||||
if(strpos($match,')') !== false) continue;
|
||||
if(in_array($match, array(',', '.'))) continue;
|
||||
if($brackets == $total_brackets){
|
||||
if(!is_numeric($match)) {
|
||||
$match = $this->escapeColumnExpression($match);
|
||||
}
|
||||
/**
|
||||
* Get escape character
|
||||
* @param string $leftOrRight left or right
|
||||
* @return string
|
||||
*/
|
||||
function getEscapeChar($leftOrRight)
|
||||
{
|
||||
if ($leftOrRight === 'left')return $this->escape_char_left;
|
||||
else return $this->escape_char_right;
|
||||
}
|
||||
|
||||
/**
|
||||
* escape the value
|
||||
* @param mixed $name
|
||||
* @return string
|
||||
*/
|
||||
function escape($name)
|
||||
{
|
||||
return $this->escape_char_left . $name . $this->escape_char_right;
|
||||
}
|
||||
|
||||
/**
|
||||
* escape the string value
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
function escapeString($name)
|
||||
{
|
||||
return "'".$this->escapeStringValue($name)."'";
|
||||
}
|
||||
|
||||
/**
|
||||
* escape the string value
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
function escapeStringValue($value)
|
||||
{
|
||||
if($value == "*") return $value;
|
||||
if (is_string($value)) return $value = str_replace("'","''",$value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return table full name
|
||||
* @param string $name table name without table prefix
|
||||
* @return string table full name with table prefix
|
||||
*/
|
||||
function parseTableName($name)
|
||||
{
|
||||
return $this->table_prefix . $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return colmun name after escape
|
||||
* @param string $name column name before escape
|
||||
* @return string column name after escape
|
||||
*/
|
||||
function parseColumnName($name)
|
||||
{
|
||||
return $this->escapeColumn($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape column
|
||||
* @param string $column_name
|
||||
* @return string column name with db name
|
||||
*/
|
||||
function escapeColumn($column_name)
|
||||
{
|
||||
if($this->isUnqualifiedColumnName($column_name))
|
||||
return $this->escape($column_name);
|
||||
if($this->isQualifiedColumnName($column_name))
|
||||
{
|
||||
list($table, $column) = explode('.', $column_name);
|
||||
// $table can also be an alias, so the prefix should not be added
|
||||
return $this->escape($table).'.'.$this->escape($column);
|
||||
//return $this->escape($this->parseTableName($table)).'.'.$this->escape($column);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Column name is suitable for use in checking
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isUnqualifiedColumnName($column_name)
|
||||
{
|
||||
if(strpos($column_name,'.')===false && strpos($column_name,'(')===false) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Column name is suitable for use in checking
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isQualifiedColumnName($column_name)
|
||||
{
|
||||
if(strpos($column_name,'.')!==false && strpos($column_name,'(')===false) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function parseExpression($column_name)
|
||||
{
|
||||
$functions = preg_split('/([\+\-\*\/\ ])/', $column_name, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
||||
foreach($functions as $k => $v)
|
||||
{
|
||||
$function = &$functions[$k];
|
||||
if(strlen($function)==1) continue; // skip delimiters
|
||||
$pos = strrpos("(", $function);
|
||||
$matches = preg_split('/([a-zA-Z0-9_*]+)/', $function, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
||||
$total_brackets = substr_count($function, "(");
|
||||
$brackets = 0;
|
||||
foreach($matches as $i => $j)
|
||||
{
|
||||
$match = &$matches[$i];
|
||||
if($match == '(') {$brackets++; continue;}
|
||||
if(strpos($match,')') !== false) continue;
|
||||
if(in_array($match, array(',', '.'))) continue;
|
||||
if($brackets == $total_brackets)
|
||||
{
|
||||
if(!is_numeric($match))
|
||||
{
|
||||
$match = $this->escapeColumnExpression($match);
|
||||
}
|
||||
}
|
||||
$function = implode('', $matches);
|
||||
}
|
||||
return implode('', $functions);
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks argument is asterisk
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isStar($column_name){
|
||||
if(substr($column_name,-1) == '*') return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks to see if expression is an aggregate star function
|
||||
* like count(*)
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isStarFunction($column_name){
|
||||
if(strpos($column_name, "(*)")!==false) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return column name after escape
|
||||
* @param string $column_name
|
||||
* @return string
|
||||
*/
|
||||
function escapeColumnExpression($column_name){
|
||||
if($this->isStar($column_name)) return $column_name;
|
||||
if($this->isStarFunction($column_name)){
|
||||
return $column_name;
|
||||
}
|
||||
if(strpos(strtolower($column_name), 'distinct') !== false) return $column_name;
|
||||
return $this->escapeColumn($column_name);
|
||||
}
|
||||
$function = implode('', $matches);
|
||||
}
|
||||
return implode('', $functions);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Checks argument is asterisk
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isStar($column_name)
|
||||
{
|
||||
if(substr($column_name,-1) == '*') return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks to see if expression is an aggregate star function
|
||||
* like count(*)
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isStarFunction($column_name)
|
||||
{
|
||||
if(strpos($column_name, "(*)")!==false) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return column name after escape
|
||||
* @param string $column_name
|
||||
* @return string
|
||||
*/
|
||||
function escapeColumnExpression($column_name)
|
||||
{
|
||||
if($this->isStar($column_name)) return $column_name;
|
||||
if($this->isStarFunction($column_name))
|
||||
{
|
||||
return $column_name;
|
||||
}
|
||||
if(strpos(strtolower($column_name), 'distinct') !== false) return $column_name;
|
||||
return $this->escapeColumn($column_name);
|
||||
}
|
||||
}
|
||||
/* End of file DBParser.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/DBParser.class.php */
|
||||
|
|
|
|||
|
|
@ -1,92 +1,104 @@
|
|||
<?php
|
||||
/**
|
||||
* QueryParser class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery
|
||||
* @version 0.1
|
||||
*/
|
||||
class QueryParser
|
||||
{
|
||||
/**
|
||||
* QueryParser class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery
|
||||
* @version 0.1
|
||||
* QueryTag object
|
||||
* @var QueryTag object
|
||||
*/
|
||||
class QueryParser {
|
||||
/**
|
||||
* QueryTag object
|
||||
* @var QueryTag object
|
||||
*/
|
||||
var $queryTag;
|
||||
var $queryTag;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param object $query
|
||||
* @param bool $isSubQuery
|
||||
* @return void
|
||||
*/
|
||||
function QueryParser($query = NULL, $isSubQuery = false) {
|
||||
if ($query)
|
||||
$this->queryTag = new QueryTag($query, $isSubQuery);
|
||||
}
|
||||
/**
|
||||
* constructor
|
||||
* @param object $query
|
||||
* @param bool $isSubQuery
|
||||
* @return void
|
||||
*/
|
||||
function QueryParser($query = NULL, $isSubQuery = false)
|
||||
{
|
||||
if($query)
|
||||
$this->queryTag = new QueryTag($query, $isSubQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return table information
|
||||
* @param object $query_id
|
||||
* @param bool $table_name
|
||||
* @return array
|
||||
*/
|
||||
function getTableInfo($query_id, $table_name) {
|
||||
$column_type = array();
|
||||
$module = '';
|
||||
|
||||
$id_args = explode('.', $query_id);
|
||||
if (count($id_args) == 2) {
|
||||
$target = 'modules';
|
||||
$module = $id_args[0];
|
||||
$id = $id_args[1];
|
||||
} elseif (count($id_args) == 3) {
|
||||
$target = $id_args[0];
|
||||
$targetList = array('modules'=>1, 'addons'=>1, 'widgets'=>1);
|
||||
if (!isset($targetList[$target]))
|
||||
return;
|
||||
$module = $id_args[1];
|
||||
$id = $id_args[2];
|
||||
}
|
||||
/**
|
||||
* Return table information
|
||||
* @param object $query_id
|
||||
* @param bool $table_name
|
||||
* @return array
|
||||
*/
|
||||
function getTableInfo($query_id, $table_name)
|
||||
{
|
||||
$column_type = array();
|
||||
$module = '';
|
||||
|
||||
// get column properties from the table
|
||||
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $module, $table_name);
|
||||
if (!file_exists($table_file)) {
|
||||
$searched_list = FileHandler::readDir(_XE_PATH_ . 'modules');
|
||||
$searched_count = count($searched_list);
|
||||
for ($i = 0; $i < $searched_count; $i++) {
|
||||
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $searched_list[$i], $table_name);
|
||||
if (file_exists($table_file))
|
||||
break;
|
||||
}
|
||||
}
|
||||
$id_args = explode('.', $query_id);
|
||||
if(count($id_args) == 2)
|
||||
{
|
||||
$target = 'modules';
|
||||
$module = $id_args[0];
|
||||
$id = $id_args[1];
|
||||
}
|
||||
else if(count($id_args) == 3)
|
||||
{
|
||||
$target = $id_args[0];
|
||||
$targetList = array('modules'=>1, 'addons'=>1, 'widgets'=>1);
|
||||
if (!isset($targetList[$target]))
|
||||
return;
|
||||
$module = $id_args[1];
|
||||
$id = $id_args[2];
|
||||
}
|
||||
|
||||
if (file_exists($table_file)) {
|
||||
$table_xml = FileHandler::readFile($table_file);
|
||||
$xml_parser = new XmlParser();
|
||||
$table_obj = $xml_parser->parse($table_xml);
|
||||
if ($table_obj->table) {
|
||||
if (isset($table_obj->table->column) && !is_array($table_obj->table->column)) {
|
||||
$table_obj->table->column = array($table_obj->table->column);
|
||||
}
|
||||
// get column properties from the table
|
||||
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $module, $table_name);
|
||||
if(!file_exists($table_file))
|
||||
{
|
||||
$searched_list = FileHandler::readDir(_XE_PATH_ . 'modules');
|
||||
$searched_count = count($searched_list);
|
||||
for($i = 0; $i < $searched_count; $i++)
|
||||
{
|
||||
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $searched_list[$i], $table_name);
|
||||
if(file_exists($table_file))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($table_obj->table->column as $k => $v) {
|
||||
$column_type[$v->attrs->name] = $v->attrs->type;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(file_exists($table_file))
|
||||
{
|
||||
$table_xml = FileHandler::readFile($table_file);
|
||||
$xml_parser = new XmlParser();
|
||||
$table_obj = $xml_parser->parse($table_xml);
|
||||
if($table_obj->table)
|
||||
{
|
||||
if(isset($table_obj->table->column) && !is_array($table_obj->table->column))
|
||||
{
|
||||
$table_obj->table->column = array($table_obj->table->column);
|
||||
}
|
||||
|
||||
return $column_type;
|
||||
}
|
||||
foreach($table_obj->table->column as $k => $v)
|
||||
{
|
||||
$column_type[$v->attrs->name] = $v->attrs->type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change code string from queryTag object
|
||||
* @return string
|
||||
*/
|
||||
function toString() {
|
||||
return "<?php if(!defined('__ZBXE__')) exit();\n"
|
||||
. $this->queryTag->toString()
|
||||
. 'return $query; ?>';
|
||||
}
|
||||
return $column_type;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
/**
|
||||
* Change code string from queryTag object
|
||||
* @return string
|
||||
*/
|
||||
function toString()
|
||||
{
|
||||
return "<?php if(!defined('__ZBXE__')) exit();\n"
|
||||
. $this->queryTag->toString()
|
||||
. 'return $query; ?>';
|
||||
}
|
||||
}
|
||||
/* End of file QueryParser.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/QueryParser.class.php */
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@
|
|||
* @package /classes/xml/xmlquery/argument
|
||||
* @version 0.1
|
||||
*/
|
||||
class Argument {
|
||||
class Argument
|
||||
{
|
||||
/**
|
||||
* argument value
|
||||
* @var mixed
|
||||
|
|
@ -52,51 +53,62 @@ class Argument {
|
|||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
function Argument($name, $value) {
|
||||
function Argument($name, $value)
|
||||
{
|
||||
$this->value = $value;
|
||||
$this->name = $name;
|
||||
$this->isValid = true;
|
||||
}
|
||||
|
||||
function getType() {
|
||||
if (isset($this->type))
|
||||
function getType()
|
||||
{
|
||||
if(isset($this->type))
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
if (is_string($this->value))
|
||||
if(is_string($this->value))
|
||||
return 'column_name';
|
||||
|
||||
return 'number';
|
||||
}
|
||||
|
||||
function setColumnType($value) {
|
||||
function setColumnType($value)
|
||||
{
|
||||
$this->type = $value;
|
||||
}
|
||||
|
||||
function setColumnOperation($operation) {
|
||||
function setColumnOperation($operation)
|
||||
{
|
||||
$this->column_operation = $operation;
|
||||
}
|
||||
|
||||
function getName() {
|
||||
function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
function getValue() {
|
||||
if (!isset($this->_value)) {
|
||||
function getValue()
|
||||
{
|
||||
if(!isset($this->_value))
|
||||
{
|
||||
$value = $this->getEscapedValue();
|
||||
$this->_value = $this->toString($value);
|
||||
}
|
||||
return $this->_value;
|
||||
}
|
||||
|
||||
function getColumnOperation() {
|
||||
function getColumnOperation()
|
||||
{
|
||||
return $this->column_operation;
|
||||
}
|
||||
|
||||
function getEscapedValue() {
|
||||
function getEscapedValue()
|
||||
{
|
||||
return $this->escapeValue($this->value);
|
||||
}
|
||||
|
||||
function getUnescapedValue() {
|
||||
function getUnescapedValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
|
|
@ -105,11 +117,13 @@ class Argument {
|
|||
* @param mixed $value
|
||||
* @return string
|
||||
*/
|
||||
function toString($value) {
|
||||
if (is_array($value)) {
|
||||
if (count($value) === 0)
|
||||
function toString($value)
|
||||
{
|
||||
if(is_array($value))
|
||||
{
|
||||
if(count($value) === 0)
|
||||
return '';
|
||||
if (count($value) === 1 && $value[0] === '')
|
||||
if(count($value) === 1 && $value[0] === '')
|
||||
return '';
|
||||
return '(' . implode(',', $value) . ')';
|
||||
}
|
||||
|
|
@ -121,35 +135,45 @@ class Argument {
|
|||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
function escapeValue($value) {
|
||||
function escapeValue($value)
|
||||
{
|
||||
$column_type = $this->getType();
|
||||
if ($column_type == 'column_name') {
|
||||
if($column_type == 'column_name')
|
||||
{
|
||||
$dbParser = DB::getParser();
|
||||
return $dbParser->parseExpression($value);
|
||||
}
|
||||
if (!isset($value))
|
||||
if(!isset($value))
|
||||
return null;
|
||||
|
||||
$columnTypeList = array('date'=>1, 'varchar'=>1, 'char'=>1, 'text'=>1, 'bigtext'=>1);
|
||||
if (isset($columnTypeList[$column_type])) {
|
||||
if (!is_array($value))
|
||||
if(isset($columnTypeList[$column_type]))
|
||||
{
|
||||
if(!is_array($value))
|
||||
$value = $this->_escapeStringValue($value);
|
||||
else {
|
||||
else
|
||||
{
|
||||
$total = count($value);
|
||||
for ($i = 0; $i < $total; $i++)
|
||||
for($i = 0; $i < $total; $i++)
|
||||
$value[$i] = $this->_escapeStringValue($value[$i]);
|
||||
//$value[$i] = '\''.$value[$i].'\'';
|
||||
}
|
||||
}
|
||||
if($this->uses_default_value) return $value;
|
||||
if ($column_type == 'number') {
|
||||
if (is_array($value)) {
|
||||
foreach ($value AS $key => $val) {
|
||||
if (isset($val) && $val !== '') {
|
||||
if($column_type == 'number')
|
||||
{
|
||||
if(is_array($value))
|
||||
{
|
||||
foreach ($value AS $key => $val)
|
||||
{
|
||||
if(isset($val) && $val !== '')
|
||||
{
|
||||
$value[$key] = (int) $val;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = (int) $value;
|
||||
}
|
||||
}
|
||||
|
|
@ -162,7 +186,8 @@ class Argument {
|
|||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
function _escapeStringValue($value) {
|
||||
function _escapeStringValue($value)
|
||||
{
|
||||
// Remove non-utf8 chars.
|
||||
$regex = '@((?:[\x00-\x7F]|[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}){1,100})|([\xF0-\xF7][\x80-\xBF]{3})|([\x80-\xBF])|([\xC0-\xFF])@x';
|
||||
|
||||
|
|
@ -172,13 +197,14 @@ class Argument {
|
|||
return '\'' . $value . '\'';
|
||||
}
|
||||
|
||||
function utf8Replacer($captures) {
|
||||
if (!empty($captures[1]))
|
||||
function utf8Replacer($captures)
|
||||
{
|
||||
if(!empty($captures[1]))
|
||||
{
|
||||
// Valid byte sequence. Return unmodified.
|
||||
return $captures[1];
|
||||
}
|
||||
elseif(!empty($captures[2]))
|
||||
else if(!empty($captures[2]))
|
||||
{
|
||||
// Remove user defined area
|
||||
if("\xF3\xB0\x80\x80" <= $captures[2])
|
||||
|
|
@ -194,23 +220,27 @@ class Argument {
|
|||
}
|
||||
}
|
||||
|
||||
function isValid() {
|
||||
function isValid()
|
||||
{
|
||||
return $this->isValid;
|
||||
}
|
||||
|
||||
function isColumnName(){
|
||||
function isColumnName()
|
||||
{
|
||||
$type = $this->getType();
|
||||
if($type == 'column_name') return true;
|
||||
if($type == 'number' && !is_numeric($this->value) && $this->uses_default_value) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function getErrorMessage() {
|
||||
function getErrorMessage()
|
||||
{
|
||||
return $this->errorMessage;
|
||||
}
|
||||
|
||||
function ensureDefaultValue($default_value) {
|
||||
if (!isset($this->value) || $this->value == '')
|
||||
function ensureDefaultValue($default_value)
|
||||
{
|
||||
if(!isset($this->value) || $this->value == '')
|
||||
{
|
||||
$this->value = $default_value;
|
||||
$this->uses_default_value = true;
|
||||
|
|
@ -222,49 +252,58 @@ class Argument {
|
|||
* @param string $filter_type
|
||||
* @return void
|
||||
*/
|
||||
function checkFilter($filter_type) {
|
||||
if (isset($this->value) && $this->value != '') {
|
||||
function checkFilter($filter_type)
|
||||
{
|
||||
if(isset($this->value) && $this->value != '')
|
||||
{
|
||||
global $lang;
|
||||
$val = $this->value;
|
||||
$key = $this->name;
|
||||
switch ($filter_type) {
|
||||
switch ($filter_type)
|
||||
{
|
||||
case 'email' :
|
||||
case 'email_address' :
|
||||
if (!preg_match('/^[\w-]+((?:\.|\+|\~)[\w-]+)*@[\w-]+(\.[\w-]+)+$/is', $val)) {
|
||||
if(!preg_match('/^[\w-]+((?:\.|\+|\~)[\w-]+)*@[\w-]+(\.[\w-]+)+$/is', $val))
|
||||
{
|
||||
$this->isValid = false;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_email, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'homepage' :
|
||||
if (!preg_match('/^(http|https)+(:\/\/)+[0-9a-z_-]+\.[^ ]+$/is', $val)) {
|
||||
if(!preg_match('/^(http|https)+(:\/\/)+[0-9a-z_-]+\.[^ ]+$/is', $val))
|
||||
{
|
||||
$this->isValid = false;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_homepage, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'userid' :
|
||||
case 'user_id' :
|
||||
if (!preg_match('/^[a-zA-Z]+([_0-9a-zA-Z]+)*$/is', $val)) {
|
||||
if(!preg_match('/^[a-zA-Z]+([_0-9a-zA-Z]+)*$/is', $val))
|
||||
{
|
||||
$this->isValid = false;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_userid, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'number' :
|
||||
case 'numbers' :
|
||||
if (is_array($val))
|
||||
if(is_array($val))
|
||||
$val = join(',', $val);
|
||||
if (!preg_match('/^(-?)[0-9]+(,\-?[0-9]+)*$/is', $val)) {
|
||||
if(!preg_match('/^(-?)[0-9]+(,\-?[0-9]+)*$/is', $val))
|
||||
{
|
||||
$this->isValid = false;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_number, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'alpha' :
|
||||
if (!preg_match('/^[a-z]+$/is', $val)) {
|
||||
if(!preg_match('/^[a-z]+$/is', $val))
|
||||
{
|
||||
$this->isValid = false;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'alpha_number' :
|
||||
if (!preg_match('/^[0-9a-z]+$/is', $val)) {
|
||||
if(!preg_match('/^[0-9a-z]+$/is', $val))
|
||||
{
|
||||
$this->isValid = false;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha_number, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
|
|
@ -273,8 +312,10 @@ class Argument {
|
|||
}
|
||||
}
|
||||
|
||||
function checkMaxLength($length) {
|
||||
if ($this->value && (strlen($this->value) > $length)) {
|
||||
function checkMaxLength($length)
|
||||
{
|
||||
if($this->value && (strlen($this->value) > $length))
|
||||
{
|
||||
global $lang;
|
||||
$this->isValid = false;
|
||||
$key = $this->name;
|
||||
|
|
@ -282,8 +323,10 @@ class Argument {
|
|||
}
|
||||
}
|
||||
|
||||
function checkMinLength($length) {
|
||||
if ($this->value && (strlen($this->value) < $length)) {
|
||||
function checkMinLength($length)
|
||||
{
|
||||
if($this->value && (strlen($this->value) < $length))
|
||||
{
|
||||
global $lang;
|
||||
$this->isValid = false;
|
||||
$key = $this->name;
|
||||
|
|
@ -291,15 +334,16 @@ class Argument {
|
|||
}
|
||||
}
|
||||
|
||||
function checkNotNull() {
|
||||
if (!isset($this->value)) {
|
||||
function checkNotNull()
|
||||
{
|
||||
if(!isset($this->value))
|
||||
{
|
||||
global $lang;
|
||||
$this->isValid = false;
|
||||
$key = $this->name;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->isnull, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
/* End of file Argument.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/Argument.class.php */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue