diff --git a/classes/xml/GeneralXmlParser.class.php b/classes/xml/GeneralXmlParser.class.php index a4421c28d..bb60c4db0 100644 --- a/classes/xml/GeneralXmlParser.class.php +++ b/classes/xml/GeneralXmlParser.class.php @@ -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 */ diff --git a/classes/xml/XmlGenerator.class.php b/classes/xml/XmlGenerator.class.php index dbe221773..3f5aa3cad 100644 --- a/classes/xml/XmlGenerator.class.php +++ b/classes/xml/XmlGenerator.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 = "\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'."\n", $node->node_name, $attrs, $body, $node->node_name); } } - -?> +/* End of file XmlGenerator.class.php */ +/* Location: ./classes/xml/XmlGenerator.class.php */ diff --git a/classes/xml/XmlJsFilter.class.php b/classes/xml/XmlJsFilter.class.php index 7f1c2190f..542c01855 100644 --- a/classes/xml/XmlJsFilter.class.php +++ b/classes/xml/XmlJsFilter.class.php @@ -1,315 +1,335 @@ { + * + *
<-- code to validate data in the form + * + * + * "- A form of key = val combination of items to js array return, act required + * + * + * "- Result to get by sending ajax to the server + * <- get the result of error name + * + *
+ * } + * + * @detail + *
{
+ * - syntax description of 
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 + * }
+ * @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 - *
{
-	 * 
-	 *   <-- code to validate data in the form
-	 *    
-	 *  
-	 *  "- A form of key = val combination of items to js array return, act required
-	 *    
-	 *  
-	 *  "- Result to get by sending ajax to the server
-	 *  <- get the result of error name
-	 *  
-	 * 
-     * }
- * - * @detail - *
{
-     * - syntax description of 
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 - * }
- * @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 */ diff --git a/classes/xml/XmlLangParser.class.php b/classes/xml/XmlLangParser.class.php index b22a4fb98..587f94259 100644 --- a/classes/xml/XmlLangParser.class.php +++ b/classes/xml/XmlLangParser.class.php @@ -1,198 +1,223 @@ 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, "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, "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 */ diff --git a/classes/xml/XmlParser.class.php b/classes/xml/XmlParser.class.php index 366d40ba3..44ff267a4 100644 --- a/classes/xml/XmlParser.class.php +++ b/classes/xml/XmlParser.class.php @@ -1,195 +1,217 @@ { + * 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, + * } + * + * @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
{ 
-	 * 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,
-	 * }
- * - * @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 */ diff --git a/classes/xml/XmlQueryParser.150.class.php b/classes/xml/XmlQueryParser.150.class.php index b0c2087d4..226251a57 100644 --- a/classes/xml/XmlQueryParser.150.class.php +++ b/classes/xml/XmlQueryParser.150.class.php @@ -1,109 +1,110 @@ - * 2. Check the action
- * 3. Parsing and write a cache file
- * @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
+ * 2. Check the action
+ * 3. Parsing and write a cache file
+ * @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 */ diff --git a/classes/xml/XmlQueryParser.class.php b/classes/xml/XmlQueryParser.class.php index 0bc5c8a0f..42f42279a 100644 --- a/classes/xml/XmlQueryParser.class.php +++ b/classes/xml/XmlQueryParser.class.php @@ -1,551 +1,644 @@ 1, 'addons'=>1, 'widgets'=>1); - if(!isset($typeList[$target])) return; - $module = $id_args[1]; - $id = $id_args[2]; - } + $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]; + $typeList = array('modules'=>1, 'addons'=>1, 'widgets'=>1); + if(!isset($typeList[$target])) return; + $module = $id_args[1]; + $id = $id_args[2]; + } - // insert, update, delete, select등의 action - $action = strtolower($xml_obj->query->attrs->action); - if(!$action) return; + // insert, update, delete, select등의 action + $action = strtolower($xml_obj->query->attrs->action); + if(!$action) return; - // 테이블 정리 (배열코드로 변환) - $tables = $xml_obj->query->tables->table; - $output->left_tables = array(); + // 테이블 정리 (배열코드로 변환) + $tables = $xml_obj->query->tables->table; + $output->left_tables = array(); - $left_conditions = array(); + $left_conditions = array(); - if(!$tables) return; - if(!is_array($tables)) $tables = array($tables); - $joinList = array('left join'=>1, 'left outer join'=>1, 'right join'=>1, 'right outer join'=>1); - foreach($tables as $key => $val) { + if(!$tables) return; + if(!is_array($tables)) $tables = array($tables); + $joinList = array('left join'=>1, 'left outer join'=>1, 'right join'=>1, 'right outer join'=>1); + foreach($tables as $key => $val) + { + // 테이블과 alias의 이름을 구함 + $table_name = $val->attrs->name; + $alias = $val->attrs->alias; + if(!$alias) $alias = $table_name; - // 테이블과 alias의 이름을 구함 - $table_name = $val->attrs->name; - $alias = $val->attrs->alias; - if(!$alias) $alias = $table_name; + $output->tables[$alias] = $table_name; - $output->tables[$alias] = $table_name; - - if(isset($joinList[$val->attrs->type]) && count($val->conditions)){ - $output->left_tables[$alias] = $val->attrs->type; - $left_conditions[$alias] = $val->conditions; - } - - // 테이블을 찾아서 컬럼의 속성을 구함 - $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; - } - } - - if(file_exists($table_file)) { - $table_xml = FileHandler::readFile($table_file); - $table_obj = parent::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); - } - - foreach($table_obj->table->column as $k => $v) { - $buff .= sprintf('$output->column_type["%s"] = "%s";%s', $v->attrs->name, $v->attrs->type, "\n"); - } - } - } - } - - - // 컬럼 정리 - $columns = $xml_obj->query->columns->column; - $out = $this->_setColumn($columns); - $output->columns = $out->columns; - - $conditions = $xml_obj->query->conditions; - $out = $this->_setConditions($conditions); - $output->conditions = $out->conditions; - - foreach($output->left_tables as $key => $val){ - if($left_conditions[$key]){ - $out = $this->_setConditions($left_conditions[$key]); - $output->left_conditions[$key] = $out->conditions; - } - } - - $group_list = $xml_obj->query->groups->group; - $out = $this->_setGroup($group_list); - $output->groups = $out->groups; - - // 네비게이션 정리 - $out = $this->_setNavigation($xml_obj); - $output->order = $out->order; - $output->list_count = $out->list_count; - $output->page_count = $out->page_count; - $output->page = $out->page; - - $column_count = count($output->columns); - $condition_count = count($output->conditions); - - $buff .= '$output->tables = array( '; - foreach($output->tables as $key => $val) { - if(!array_key_exists($key,$output->left_tables)){ - $buff .= sprintf('"%s"=>"%s",', $key, $val); - } - } - $buff .= ' );'."\n"; - - // php script 생성 - $buff .= '$output->_tables = array( '; - foreach($output->tables as $key => $val) { - $buff .= sprintf('"%s"=>"%s",', $key, $val); - } - $buff .= ' );'."\n"; - - if(count($output->left_tables)){ - $buff .= '$output->left_tables = array( '; - foreach($output->left_tables as $key => $val) { - $buff .= sprintf('"%s"=>"%s",', $key, $val); - } - $buff .= ' );'."\n"; - } - - // column 정리 - if($column_count) { - $buff .= '$output->columns = array ( '; - $buff .= $this->_getColumn($output->columns); - $buff .= ' );'."\n"; - } - - // conditions 정리 - if($condition_count) { - $buff .= '$output->conditions = array ( '; - $buff .= $this->_getConditions($output->conditions); - $buff .= ' );'."\n"; - } - - // conditions 정리 - if(count($output->left_conditions)) { - $buff .= '$output->left_conditions = array ( '; - foreach($output->left_conditions as $key => $val){ - $buff .= "'{$key}' => array ( "; - $buff .= $this->_getConditions($val); - $buff .= "),\n"; - } - $buff .= ' );'."\n"; - } - - // args 변수 확인 - $arg_list = $this->getArguments(); - if($arg_list) + if(isset($joinList[$val->attrs->type]) && count($val->conditions)) { - foreach($arg_list as $arg) + $output->left_tables[$alias] = $val->attrs->type; + $left_conditions[$alias] = $val->conditions; + } + + // 테이블을 찾아서 컬럼의 속성을 구함 + $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++) { - $pre_buff .= 'if(is_object($args->'.$arg.')){ $args->'.$arg.' = array_values(get_method_vars($args->'.$arg.')); }'. "\n"; - $pre_buff .= 'if(is_array($args->'.$arg.') && count($args->'.$arg.')==0){ unset($args->'.$arg.'); };'."\n"; + $table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $searched_list[$i], $table_name); + if(file_exists($table_file)) break; } } - // order 정리 - if($output->order) { - $buff .= '$output->order = array('; - foreach($output->order as $key => $val) { - $buff .= sprintf('array($args->%s?$args->%s:"%s",in_array($args->%s,array("asc","desc"))?$args->%s:("%s"?"%s":"asc")),', $val->var, $val->var, $val->default, $val->order, $val->order, $val->order, $val->order); - } - $buff .= ');'."\n"; - } - - // list_count 정리 - if($output->list_count) { - $buff .= sprintf('$output->list_count = array("var"=>"%s", "value"=>$args->%s?$args->%s:"%s");%s', $output->list_count->var, $output->list_count->var, $output->list_count->var, $output->list_count->default,"\n"); - } - - // page_count 정리 - if($output->page_count) { - $buff .= sprintf('$output->page_count = array("var"=>"%s", "value"=>$args->%s?$args->%s:"%s");%s', $output->page_count->var, $output->page_count->var, $output->page_count->var, $output->page_count->default,"\n"); - } - - // page 정리 - if($output->page) { - $buff .= sprintf('$output->page = array("var"=>"%s", "value"=>$args->%s?$args->%s:"%s");%s', $output->page->var, $output->page->var, $output->page->var, $output->list->default,"\n"); - } - - // group by 정리 - if($output->groups) { - $buff .= sprintf('$output->groups = array("%s");%s', implode('","',$output->groups),"\n"); - } - - // minlength check - if(count($minlength_list)) { - foreach($minlength_list as $key => $val) { - $pre_buff .= 'if($args->'.$key.'&&strlen($args->'.$key.')<'.$val.') return new Object(-1, sprintf($lang->filter->outofrange, $lang->'.$key.'?$lang->'.$key.':\''.$key.'\'));'."\n"; - } - } - - // maxlength check - if(count($maxlength_list)) { - foreach($maxlength_list as $key => $val) { - $pre_buff .= 'if($args->'.$key.'&&strlen($args->'.$key.')>'.$val.') return new Object(-1, sprintf($lang->filter->outofrange, $lang->'.$key.'?$lang->'.$key.':\''.$key.'\'));'."\n"; - } - } - - // filter check - if(count($this->filter_list)) { - foreach($this->filter_list as $key => $val) { - $pre_buff .= sprintf('if(isset($args->%s)) { unset($_output); $_output = $this->checkFilter("%s",$args->%s,"%s"); if(!$_output->toBool()) return $_output; } %s',$val->var, $val->var,$val->var,$val->filter,"\n"); - } - } - - // default check - if(count($this->default_list)) { - foreach($this->default_list as $key => $val) { - $pre_buff .= 'if(!isset($args->'.$key.')) $args->'.$key.' = '.$val.';'."\n"; - } - } - - // not null check - if(count($this->notnull_list)) { - foreach($this->notnull_list as $key => $val) { - $pre_buff .= 'if(!isset($args->'.$val.')) return new Object(-1, sprintf($lang->filter->isnull, $lang->'.$val.'?$lang->'.$val.':\''.$val.'\'));'."\n"; - } - } - - $buff = "query_id = "%s";%s', $query_id, "\n") - . sprintf('$output->action = "%s";%s', $action, "\n") - . $pre_buff - . $buff - . 'return $output; ?>'; - - // 저장 - FileHandler::writeFile($cache_file, $buff); - } - - /** - * Transfer given column information to object->columns - * @param array $columns column information - * @return object - */ - function _setColumn($columns){ - if(!$columns) { - $output->column[] = array("*" => "*"); - } else { - if(!is_array($columns)) $columns = array($columns); - foreach($columns as $key => $val) { - $name = $val->attrs->name; - /* - if(strpos('.',$name)===false && count($output->tables)==1) { - $tmp = array_values($output->tables); - $name = sprintf('%s.%s', $tmp[0], $val->attrs->name); - } - */ - - $output->columns[] = array( - "name" => $name, - "var" => $val->attrs->var, - "default" => $val->attrs->default, - "notnull" => $val->attrs->notnull, - "filter" => $val->attrs->filter, - "minlength" => $val->attrs->minlength, - "maxlength" => $val->attrs->maxlength, - "alias" => $val->attrs->alias, - "click_count" => $val->attrs->click_count, - ); - } - } - return $output; - } - - /** - * Transfer condition information to $object->conditions - * @param object @condition SQL condition information - * @retrun object - */ - function _setConditions($conditions){ - // 조건절 정리 - - $condition = $conditions->condition; - if($condition) { - $obj->condition = $condition; - unset($condition); - $condition = array($obj); - } - $condition_group = $conditions->group; - if($condition_group && !is_array($condition_group)) $condition_group = array($condition_group); - - if($condition && $condition_group) $cond = array_merge($condition, $condition_group); - elseif($condition_group) $cond = $condition_group; - else $cond = $condition; - - if($cond) { - foreach($cond as $key => $val) { - unset($cond_output); - - if($val->attrs->pipe) $cond_output->pipe = $val->attrs->pipe; - else $cond_output->pipe = null; - - if(!$val->condition) continue; - if(!is_array($val->condition)) $val->condition = array($val->condition); - - foreach($val->condition as $k => $v) { - $obj = $v->attrs; - if(!$obj->alias) $obj->alias = $obj->column; - $cond_output->condition[] = $obj; - } - - $output->conditions[] = $cond_output; - } - } - return $output; - } - - /** - * Transfer condition information to $object->groups - * @param array $group_list SQL group information - * @return object - */ - function _setGroup($group_list){ - // group 정리 - - if($group_list) { - if(!is_array($group_list)) $group_list = array($group_list); - for($i=0;$iattrs->column); - if(!$column) continue; - $group_column_list[] = $column; - } - if(count($group_column_list)) $output->groups = $group_column_list; - } - return $output; - } - - - /** - * Transfer pagnation information to $output - * @param object $xml_obj xml object containing Navigation information - * @return object - */ - function _setNavigation($xml_obj){ - $navigation = $xml_obj->query->navigation; - if($navigation) { - $order = $navigation->index; - if($order) { - if(!is_array($order)) $order = array($order); - foreach($order as $order_info) { - $output->order[] = $order_info->attrs; - } - } - - $list_count = $navigation->list_count->attrs; - $output->list_count = $list_count; - - $page_count = $navigation->page_count->attrs; - $output->page_count = $page_count; - - $page = $navigation->page->attrs; - $output->page = $page ; - } - return $output; - } - - /** - * Retrieve column information from $output->colums to generate corresponding php code
- * The name of this method is misleading. - * @param array $columns - * @return string buffer containing php code - */ - function _getColumn($columns){ - $buff = ''; - $str = ''; - $print_vars = array(); - - foreach($columns as $key => $val) { - $str = 'array("name"=>"%s","alias"=>"%s"'; - $print_vars = array(); - $print_vars[] = $val['name']; - $print_vars[] = $val['alias']; - - $val['default'] = $this->getDefault($val['name'], $val['default']); - if($val['var'] && strpos($val['var'],'.')===false) { - - if($val['default']){ - $str .= ',"value"=>$args->%s?$args->%s:%s'; - $print_vars[] = $val['var']; - $print_vars[] = $val['var']; - $print_vars[] = $val['default']; - }else{ - $str .= ',"value"=>$args->%s'; - $print_vars[] = $val['var']; + if(file_exists($table_file)) + { + $table_xml = FileHandler::readFile($table_file); + $table_obj = parent::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); } - } else { - if($val['default']){ - $str .= ',"value"=>%s'; - $print_vars[] = $val['default']; + foreach($table_obj->table->column as $k => $v) + { + $buff .= sprintf('$output->column_type["%s"] = "%s";%s', $v->attrs->name, $v->attrs->type, "\n"); } - } + } + } + } - if($val['click_count']){ - $str .= ',"click_count"=>$args->%s'; - $print_vars[] = $val['click_count']; + + // 컬럼 정리 + $columns = $xml_obj->query->columns->column; + $out = $this->_setColumn($columns); + $output->columns = $out->columns; + + $conditions = $xml_obj->query->conditions; + $out = $this->_setConditions($conditions); + $output->conditions = $out->conditions; + + foreach($output->left_tables as $key => $val) + { + if($left_conditions[$key]) + { + $out = $this->_setConditions($left_conditions[$key]); + $output->left_conditions[$key] = $out->conditions; + } + } + + $group_list = $xml_obj->query->groups->group; + $out = $this->_setGroup($group_list); + $output->groups = $out->groups; + + // 네비게이션 정리 + $out = $this->_setNavigation($xml_obj); + $output->order = $out->order; + $output->list_count = $out->list_count; + $output->page_count = $out->page_count; + $output->page = $out->page; + + $column_count = count($output->columns); + $condition_count = count($output->conditions); + + $buff .= '$output->tables = array( '; + foreach($output->tables as $key => $val) + { + if(!array_key_exists($key,$output->left_tables)) + { + $buff .= sprintf('"%s"=>"%s",', $key, $val); + } + } + $buff .= ' );'."\n"; + + // php script 생성 + $buff .= '$output->_tables = array( '; + foreach($output->tables as $key => $val) + { + $buff .= sprintf('"%s"=>"%s",', $key, $val); + } + $buff .= ' );'."\n"; + + if(count($output->left_tables)) + { + $buff .= '$output->left_tables = array( '; + foreach($output->left_tables as $key => $val) + { + $buff .= sprintf('"%s"=>"%s",', $key, $val); + } + $buff .= ' );'."\n"; + } + + // column 정리 + if($column_count) + { + $buff .= '$output->columns = array ( '; + $buff .= $this->_getColumn($output->columns); + $buff .= ' );'."\n"; + } + + // conditions 정리 + if($condition_count) + { + $buff .= '$output->conditions = array ( '; + $buff .= $this->_getConditions($output->conditions); + $buff .= ' );'."\n"; + } + + // conditions 정리 + if(count($output->left_conditions)) + { + $buff .= '$output->left_conditions = array ( '; + foreach($output->left_conditions as $key => $val) + { + $buff .= "'{$key}' => array ( "; + $buff .= $this->_getConditions($val); + $buff .= "),\n"; + } + $buff .= ' );'."\n"; + } + + // args 변수 확인 + $arg_list = $this->getArguments(); + if($arg_list) + { + foreach($arg_list as $arg) + { + $pre_buff .= 'if(is_object($args->'.$arg.')){ $args->'.$arg.' = array_values(get_method_vars($args->'.$arg.')); }'. "\n"; + $pre_buff .= 'if(is_array($args->'.$arg.') && count($args->'.$arg.')==0){ unset($args->'.$arg.'); };'."\n"; + } + } + + // order 정리 + if($output->order) + { + $buff .= '$output->order = array('; + foreach($output->order as $key => $val) + { + $buff .= sprintf('array($args->%s?$args->%s:"%s",in_array($args->%s,array("asc","desc"))?$args->%s:("%s"?"%s":"asc")),', $val->var, $val->var, $val->default, $val->order, $val->order, $val->order, $val->order); + } + $buff .= ');'."\n"; + } + + // list_count 정리 + if($output->list_count) + { + $buff .= sprintf('$output->list_count = array("var"=>"%s", "value"=>$args->%s?$args->%s:"%s");%s', $output->list_count->var, $output->list_count->var, $output->list_count->var, $output->list_count->default,"\n"); + } + + // page_count 정리 + if($output->page_count) + { + $buff .= sprintf('$output->page_count = array("var"=>"%s", "value"=>$args->%s?$args->%s:"%s");%s', $output->page_count->var, $output->page_count->var, $output->page_count->var, $output->page_count->default,"\n"); + } + + // page 정리 + if($output->page) + { + $buff .= sprintf('$output->page = array("var"=>"%s", "value"=>$args->%s?$args->%s:"%s");%s', $output->page->var, $output->page->var, $output->page->var, $output->list->default,"\n"); + } + + // group by 정리 + if($output->groups) + { + $buff .= sprintf('$output->groups = array("%s");%s', implode('","',$output->groups),"\n"); + } + + // minlength check + if(count($minlength_list)) + { + foreach($minlength_list as $key => $val) + { + $pre_buff .= 'if($args->'.$key.'&&strlen($args->'.$key.')<'.$val.') return new Object(-1, sprintf($lang->filter->outofrange, $lang->'.$key.'?$lang->'.$key.':\''.$key.'\'));'."\n"; + } + } + + // maxlength check + if(count($maxlength_list)) + { + foreach($maxlength_list as $key => $val) + { + $pre_buff .= 'if($args->'.$key.'&&strlen($args->'.$key.')>'.$val.') return new Object(-1, sprintf($lang->filter->outofrange, $lang->'.$key.'?$lang->'.$key.':\''.$key.'\'));'."\n"; + } + } + + // filter check + if(count($this->filter_list)) + { + foreach($this->filter_list as $key => $val) + { + $pre_buff .= sprintf('if(isset($args->%s)) { unset($_output); $_output = $this->checkFilter("%s",$args->%s,"%s"); if(!$_output->toBool()) return $_output; } %s',$val->var, $val->var,$val->var,$val->filter,"\n"); + } + } + + // default check + if(count($this->default_list)) + { + foreach($this->default_list as $key => $val) + { + $pre_buff .= 'if(!isset($args->'.$key.')) $args->'.$key.' = '.$val.';'."\n"; + } + } + + // not null check + if(count($this->notnull_list)) + { + foreach($this->notnull_list as $key => $val) + { + $pre_buff .= 'if(!isset($args->'.$val.')) return new Object(-1, sprintf($lang->filter->isnull, $lang->'.$val.'?$lang->'.$val.':\''.$val.'\'));'."\n"; + } + } + + $buff = "query_id = "%s";%s', $query_id, "\n") + . sprintf('$output->action = "%s";%s', $action, "\n") + . $pre_buff + . $buff + . 'return $output; ?>'; + + // 저장 + FileHandler::writeFile($cache_file, $buff); + } + + /** + * Transfer given column information to object->columns + * @param array $columns column information + * @return object + */ + function _setColumn($columns) + { + if(!$columns) + { + $output->column[] = array("*" => "*"); + } + else + { + if(!is_array($columns)) $columns = array($columns); + foreach($columns as $key => $val) + { + $name = $val->attrs->name; + /* + if(strpos('.',$name)===false && count($output->tables)==1) { + $tmp = array_values($output->tables); + $name = sprintf('%s.%s', $tmp[0], $val->attrs->name); + } + */ + + $output->columns[] = array( + "name" => $name, + "var" => $val->attrs->var, + "default" => $val->attrs->default, + "notnull" => $val->attrs->notnull, + "filter" => $val->attrs->filter, + "minlength" => $val->attrs->minlength, + "maxlength" => $val->attrs->maxlength, + "alias" => $val->attrs->alias, + "click_count" => $val->attrs->click_count, + ); + } + } + return $output; + } + + /** + * Transfer condition information to $object->conditions + * @param object @condition SQL condition information + * @retrun object + */ + function _setConditions($conditions) + { + // 조건절 정리 + $condition = $conditions->condition; + if($condition) + { + $obj->condition = $condition; + unset($condition); + $condition = array($obj); + } + $condition_group = $conditions->group; + if($condition_group && !is_array($condition_group)) $condition_group = array($condition_group); + + if($condition && $condition_group) $cond = array_merge($condition, $condition_group); + elseif($condition_group) $cond = $condition_group; + else $cond = $condition; + + if($cond) + { + foreach($cond as $key => $val) + { + unset($cond_output); + + if($val->attrs->pipe) $cond_output->pipe = $val->attrs->pipe; + else $cond_output->pipe = null; + + if(!$val->condition) continue; + if(!is_array($val->condition)) $val->condition = array($val->condition); + + foreach($val->condition as $k => $v) + { + $obj = $v->attrs; + if(!$obj->alias) $obj->alias = $obj->column; + $cond_output->condition[] = $obj; } - $str .= '),%s'; - $print_vars[] = "\n"; - - $buff .= vsprintf($str, $print_vars); - } - return $buff; - } - - /** - * Retrieve condition information from $output->condition to generate corresponding php code - * The name of this method is misleading. - * @param array $conditions array containing Query conditions - * @return string buffer containing php code - */ - function _getConditions($conditions){ - $buff = ''; - foreach($conditions as $key => $val) { - $buff .= sprintf('array("pipe"=>"%s",%s"condition"=>array(', $val->pipe,"\n"); - foreach($val->condition as $k => $v) { - $v->default = $this->getDefault($v->column, $v->default); - if($v->var) { - if(strpos($v->var,".")===false) { - if($v->default) $this->default_list[$v->var] = $v->default; - if($v->filter) $this->filter_list[] = $v; - if($v->notnull) $this->notnull_list[] = $v->var; - if($v->default) $buff .= sprintf('array("column"=>"%s", "value"=>$args->%s?$args->%s:%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->var, $v->default, $v->pipe, $v->operation, "\n"); - else $buff .= sprintf('array("column"=>"%s", "value"=>$args->%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->pipe, $v->operation, "\n"); - - $this->addArguments($v->var); - } else { - $buff .= sprintf('array("column"=>"%s", "value"=>"%s","pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->pipe, $v->operation, "\n"); - } - } else { - if($v->default) $buff .= sprintf('array("column"=>"%s", "value"=>%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->default ,$v->pipe, $v->operation,"\n"); - else $buff .= sprintf('array("column"=>"%s", "pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->pipe, $v->operation,"\n"); - } - } - $buff .= ')),'."\n"; - } - return $buff; - } - - /** - * Add argument to $this->args - * @param mixed $args_name argument value - * @return void - */ - function addArguments($args_name) - { - $this->args[] = $args_name; + $output->conditions[] = $cond_output; + } } - - /** - * Get argument from $this->args - * @return mixed - */ - function getArguments() + return $output; + } + + /** + * Transfer condition information to $object->groups + * @param array $group_list SQL group information + * @return object + */ + function _setGroup($group_list) + { + // group 정리 + if($group_list) { - return $this->args; + if(!is_array($group_list)) $group_list = array($group_list); + for($i=0;$iattrs->column); + if(!$column) continue; + $group_column_list[] = $column; + } + if(count($group_column_list)) $output->groups = $group_column_list; + } + return $output; + } + + /** + * Transfer pagnation information to $output + * @param object $xml_obj xml object containing Navigation information + * @return object + */ + function _setNavigation($xml_obj) + { + $navigation = $xml_obj->query->navigation; + if($navigation) + { + $order = $navigation->index; + if($order) + { + if(!is_array($order)) $order = array($order); + foreach($order as $order_info) + { + $output->order[] = $order_info->attrs; + } + } + + $list_count = $navigation->list_count->attrs; + $output->list_count = $list_count; + + $page_count = $navigation->page_count->attrs; + $output->page_count = $page_count; + + $page = $navigation->page->attrs; + $output->page = $page ; + } + return $output; + } + + /** + * Retrieve column information from $output->colums to generate corresponding php code
+ * The name of this method is misleading. + * @param array $columns + * @return string buffer containing php code + */ + function _getColumn($columns) + { + $buff = ''; + $str = ''; + $print_vars = array(); + + foreach($columns as $key => $val) + { + $str = 'array("name"=>"%s","alias"=>"%s"'; + $print_vars = array(); + $print_vars[] = $val['name']; + $print_vars[] = $val['alias']; + + $val['default'] = $this->getDefault($val['name'], $val['default']); + if($val['var'] && strpos($val['var'],'.')===false) + { + if($val['default']) + { + $str .= ',"value"=>$args->%s?$args->%s:%s'; + $print_vars[] = $val['var']; + $print_vars[] = $val['var']; + $print_vars[] = $val['default']; + } + else + { + $str .= ',"value"=>$args->%s'; + $print_vars[] = $val['var']; + } + } + else + { + if($val['default']) + { + $str .= ',"value"=>%s'; + $print_vars[] = $val['default']; + } + } + + if($val['click_count']) + { + $str .= ',"click_count"=>$args->%s'; + $print_vars[] = $val['click_count']; + } + + $str .= '),%s'; + $print_vars[] = "\n"; + + $buff .= vsprintf($str, $print_vars); + } + return $buff; + } + + /** + * Retrieve condition information from $output->condition to generate corresponding php code + * The name of this method is misleading. + * @param array $conditions array containing Query conditions + * @return string buffer containing php code + */ + function _getConditions($conditions) + { + $buff = ''; + foreach($conditions as $key => $val) + { + $buff .= sprintf('array("pipe"=>"%s",%s"condition"=>array(', $val->pipe,"\n"); + foreach($val->condition as $k => $v) + { + $v->default = $this->getDefault($v->column, $v->default); + if($v->var) + { + if(strpos($v->var,".")===false) + { + if($v->default) $this->default_list[$v->var] = $v->default; + if($v->filter) $this->filter_list[] = $v; + if($v->notnull) $this->notnull_list[] = $v->var; + if($v->default) + { + $buff .= sprintf('array("column"=>"%s", "value"=>$args->%s?$args->%s:%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->var, $v->default, $v->pipe, $v->operation, "\n"); + } + else + { + $buff .= sprintf('array("column"=>"%s", "value"=>$args->%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->pipe, $v->operation, "\n"); + } + + $this->addArguments($v->var); + } + else + { + $buff .= sprintf('array("column"=>"%s", "value"=>"%s","pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->pipe, $v->operation, "\n"); + } + } + else + { + if($v->default) + { + $buff .= sprintf('array("column"=>"%s", "value"=>%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->default ,$v->pipe, $v->operation,"\n"); + } + else + { + $buff .= sprintf('array("column"=>"%s", "pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->pipe, $v->operation,"\n"); + } + } + } + $buff .= ')),'."\n"; + } + return $buff; + } + + /** + * Add argument to $this->args + * @param mixed $args_name argument value + * @return void + */ + function addArguments($args_name) + { + $this->args[] = $args_name; + } + + /** + * Get argument from $this->args + * @return mixed + */ + function getArguments() + { + return $this->args; + } + + /** + * Returns predefined default values correspoding to given parameters + * @param string $name + * @param mixed $value + * @return mixed Returns a default value for specified field + */ + function getDefault($name, $value) + { + $db_info = Context::getDBInfo (); + if(!isset($value)) return; + $str_pos = strpos($value, '('); + if($str_pos===false) return '"'.$value.'"'; + + $func_name = substr($value, 0, $str_pos); + $args = substr($value, $str_pos+1, strlen($value)-1); + + switch($func_name) + { + case 'ipaddress' : + $val = '$_SERVER[\'REMOTE_ADDR\']'; + break; + case 'unixtime' : + $val = 'time()'; + break; + case 'curdate' : + $val = 'date("YmdHis")'; + break; + case 'sequence' : + $val = '$this->getNextSequence()'; + break; + case 'plus' : + $args = abs($args); + if($db_info->db_type == 'cubrid') + { + $val = sprintf ('"\\"%s\\"+%d"', $name, $args); + } + else + { + $val = sprintf('"%s+%d"', $name, $args); + } + break; + case 'minus' : + $args = abs($args); + if($db_info->db_type == 'cubrid') + { + $val = sprintf ('"\\"%s\\"-%d"', $name, $args); + } + else + { + $val = sprintf('"%s-%d"', $name, $args); + } + break; + case 'multiply' : + $args = intval($args); + if($db_info->db_type == 'cubrid') + { + $val = sprintf ('"\\"%s\\"*%d"', $name, $args); + } + else + { + $val = sprintf('"%s*%d"', $name, $args); + } + break; } - /** - * Returns predefined default values correspoding to given parameters - * @param string $name - * @param mixed $value - * @return mixed Returns a default value for specified field - */ - function getDefault($name, $value) { - $db_info = Context::getDBInfo (); - if(!isset($value)) return; - $str_pos = strpos($value, '('); - if($str_pos===false) return '"'.$value.'"'; - - $func_name = substr($value, 0, $str_pos); - $args = substr($value, $str_pos+1, strlen($value)-1); - - switch($func_name) { - case 'ipaddress' : - $val = '$_SERVER[\'REMOTE_ADDR\']'; - break; - case 'unixtime' : - $val = 'time()'; - break; - case 'curdate' : - $val = 'date("YmdHis")'; - break; - case 'sequence' : - $val = '$this->getNextSequence()'; - break; - case 'plus' : - $args = abs($args); - if ($db_info->db_type == 'cubrid') { - $val = sprintf ('"\\"%s\\"+%d"', $name, $args); - } else { - $val = sprintf('"%s+%d"', $name, $args); - } - break; - case 'minus' : - $args = abs($args); - if ($db_info->db_type == 'cubrid') { - $val = sprintf ('"\\"%s\\"-%d"', $name, $args); - } else { - $val = sprintf('"%s-%d"', $name, $args); - } - break; - case 'multiply' : - $args = intval($args); - if ($db_info->db_type == 'cubrid') { - $val = sprintf ('"\\"%s\\"*%d"', $name, $args); - } else { - $val = sprintf('"%s*%d"', $name, $args); - } - break; - } - - return $val; - } - } -?> + return $val; + } +} +/* End of file XmlQueryParser.class.php */ +/* Location: ./classes/xml/XmlQueryParser.class.php */ diff --git a/classes/xml/xmlquery/DBParser.class.php b/classes/xml/xmlquery/DBParser.class.php index 111f698f4..86df40bf3 100644 --- a/classes/xml/xmlquery/DBParser.class.php +++ b/classes/xml/xmlquery/DBParser.class.php @@ -1,193 +1,214 @@ 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 */ diff --git a/classes/xml/xmlquery/QueryParser.class.php b/classes/xml/xmlquery/QueryParser.class.php index ab1366a37..d34f681fe 100644 --- a/classes/xml/xmlquery/QueryParser.class.php +++ b/classes/xml/xmlquery/QueryParser.class.php @@ -1,92 +1,104 @@ 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 "queryTag->toString() - . 'return $query; ?>'; - } + return $column_type; + } - } - -?> + /** + * Change code string from queryTag object + * @return string + */ + function toString() + { + return "queryTag->toString() + . 'return $query; ?>'; + } +} +/* End of file QueryParser.class.php */ +/* Location: ./classes/xml/xmlquery/QueryParser.class.php */ diff --git a/classes/xml/xmlquery/argument/Argument.class.php b/classes/xml/xmlquery/argument/Argument.class.php index 703e79cbc..581908366 100644 --- a/classes/xml/xmlquery/argument/Argument.class.php +++ b/classes/xml/xmlquery/argument/Argument.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 */