issue 2662 coding convention in xml class

git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12225 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ovclas 2012-11-15 01:59:10 +00:00
parent fb0df50f3f
commit 2cb9487ba1
10 changed files with 1924 additions and 1660 deletions

View file

@ -6,7 +6,8 @@
* @package /classes/xml * @package /classes/xml
* @version 0.1 * @version 0.1
*/ */
class GeneralXmlParser { class GeneralXmlParser
{
/** /**
* result of parse * result of parse
* @var array * @var array
@ -18,7 +19,8 @@ class GeneralXmlParser {
* @param string $input data to be parsed * @param string $input data to be parsed
* @return array|NULL Returns an object containing parsed values or NULL in case of failure * @return array|NULL Returns an object containing parsed values or NULL in case of failure
*/ */
function parse($input = '') { function parse($input = '')
{
$oParser = xml_parser_create('UTF-8'); $oParser = xml_parser_create('UTF-8');
xml_set_object($oParser, $this); xml_set_object($oParser, $this);
xml_set_element_handler($oParser, "_tagOpen", "_tagClosed"); xml_set_element_handler($oParser, "_tagOpen", "_tagClosed");
@ -40,7 +42,8 @@ class GeneralXmlParser {
* @param array $attrs attributes to be set * @param array $attrs attributes to be set
* @return void * @return void
*/ */
function _tagOpen($parser, $node_name, $attrs) { function _tagOpen($parser, $node_name, $attrs)
{
$obj->node_name = strtolower($node_name); $obj->node_name = strtolower($node_name);
$obj->attrs = $attrs; $obj->attrs = $attrs;
$obj->childNodes = array(); $obj->childNodes = array();
@ -55,19 +58,20 @@ class GeneralXmlParser {
* @param string $body a data to be added * @param string $body a data to be added
* @return void * @return void
*/ */
function _tagBody($parser, $body) { function _tagBody($parser, $body)
{
//if(!trim($body)) return; //if(!trim($body)) return;
$this->output[count($this->output)-1]->body .= $body; $this->output[count($this->output)-1]->body .= $body;
} }
/** /**
* End element handler * End element handler
* @param resource $parse an instance of parser * @param resource $parse an instance of parser
* @param string $node_name name of xml node * @param string $node_name name of xml node
* @return void * @return void
*/ */
function _tagClosed($parser, $node_name) { function _tagClosed($parser, $node_name)
{
$node_name = strtolower($node_name); $node_name = strtolower($node_name);
$cur_obj = array_pop($this->output); $cur_obj = array_pop($this->output);
$parent_obj = &$this->output[count($this->output)-1]; $parent_obj = &$this->output[count($this->output)-1];
@ -75,17 +79,22 @@ class GeneralXmlParser {
if($parent_obj->childNodes[$node_name]) if($parent_obj->childNodes[$node_name])
{ {
$tmp_obj = $parent_obj->childNodes[$node_name]; $tmp_obj = $parent_obj->childNodes[$node_name];
if(is_array($tmp_obj)) { if(is_array($tmp_obj))
{
array_push($parent_obj->childNodes[$node_name], $cur_obj); array_push($parent_obj->childNodes[$node_name], $cur_obj);
} else { }
else
{
$parent_obj->childNodes[$node_name] = array(); $parent_obj->childNodes[$node_name] = array();
array_push($parent_obj->childNodes[$node_name], $tmp_obj); array_push($parent_obj->childNodes[$node_name], $tmp_obj);
array_push($parent_obj->childNodes[$node_name], $cur_obj); array_push($parent_obj->childNodes[$node_name], $cur_obj);
} }
} else { }
else
{
$parent_obj->childNodes[$node_name] = $cur_obj; $parent_obj->childNodes[$node_name] = $cur_obj;
} }
} }
} }
?> /* End of file GeneralXmlParser.class.php */
/* Location: ./classes/xml/GeneralXmlParser.class.php */

View file

@ -5,16 +5,19 @@
* @package /classes/xml * @package /classes/xml
* @version 0.1 * @version 0.1
*/ */
class XmlGenerator{ class XmlGenerator
{
/** /**
* object change to xml * object change to xml
* @param object $xml * @param object $xml
* @return string * @return string
*/ */
function obj2xml($xml){ function obj2xml($xml)
{
$buff = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"; $buff = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
foreach($xml as $nodeName => $nodeItem){ foreach($xml as $nodeName => $nodeItem)
{
$buff .= $this->_makexml($nodeItem); $buff .= $this->_makexml($nodeItem);
} }
return $buff; return $buff;
@ -25,26 +28,40 @@ class XmlGenerator{
* @param object $node node in xml object * @param object $node node in xml object
* @return string * @return string
*/ */
function _makexml($node){ function _makexml($node)
{
$body = ''; $body = '';
foreach($node as $key => $value){ foreach($node as $key => $value)
switch($key){ {
switch($key)
{
case 'node_name' : break; case 'node_name' : break;
case 'attrs' : { case 'attrs' :
{
$attrs = ''; $attrs = '';
if (isset($value)){ if (isset($value))
foreach($value as $attrName=>$attrValue){ {
foreach($value as $attrName=>$attrValue)
{
$attrs .= sprintf(' %s="%s"', $attrName, htmlspecialchars($attrValue)); $attrs .= sprintf(' %s="%s"', $attrName, htmlspecialchars($attrValue));
} }
} }
}break; }
case 'body' : $body = $value; break; break;
default : { case 'body' :
if (is_array($value)){ $body = $value;
foreach($value as $idx => $arrNode){ break;
default :
{
if (is_array($value))
{
foreach($value as $idx => $arrNode)
{
$body .= $this->_makexml($arrNode); $body .= $this->_makexml($arrNode);
} }
}else if(is_object($value)){ }
else if(is_object($value))
{
$body = $this->_makexml($value); $body = $this->_makexml($value);
} }
} }
@ -53,5 +70,5 @@ class XmlGenerator{
return sprintf('<%s%s>%s</%s>'."\n", $node->node_name, $attrs, $body, $node->node_name); return sprintf('<%s%s>%s</%s>'."\n", $node->node_name, $attrs, $body, $node->node_name);
} }
} }
/* End of file XmlGenerator.class.php */
?> /* Location: ./classes/xml/XmlGenerator.class.php */

View file

@ -44,7 +44,8 @@
* @package /classes/xml * @package /classes/xml
* @version 0.2 * @version 0.2
*/ */
class XmlJsFilter extends XmlParser { class XmlJsFilter extends XmlParser
{
/** /**
* version * version
* @var string * @var string
@ -72,7 +73,8 @@
* @param string $xml_file * @param string $xml_file
* @return void * @return void
*/ */
function XmlJsFilter($path, $xml_file) { function XmlJsFilter($path, $xml_file)
{
if(substr($path,-1)!=='/') $path .= '/'; if(substr($path,-1)!=='/') $path .= '/';
$this->xml_file = sprintf("%s%s",$path, $xml_file); $this->xml_file = sprintf("%s%s",$path, $xml_file);
$this->js_file = $this->_getCompiledFileName($this->xml_file); $this->js_file = $this->_getCompiledFileName($this->xml_file);
@ -82,7 +84,8 @@
* Compile a xml_file only when a corresponding js file does not exists or is outdated * 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 * @return void Returns NULL regardless of the success of failure of the operation
*/ */
function compile() { function compile()
{
if(!file_exists($this->xml_file)) return; if(!file_exists($this->xml_file)) return;
if(!file_exists($this->js_file)) $this->_compile(); if(!file_exists($this->js_file)) $this->_compile();
else if(filemtime($this->xml_file)>filemtime($this->js_file)) $this->_compile(); else if(filemtime($this->xml_file)>filemtime($this->js_file)) $this->_compile();
@ -93,7 +96,8 @@
* compile a xml_file into js_file * compile a xml_file into js_file
* @return void * @return void
*/ */
function _compile() { function _compile()
{
global $lang; global $lang;
// read xml file // read xml file
@ -123,8 +127,8 @@
if($response_tag && !is_array($response_tag)) $response_tag = array($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 exists, result returned by calling the method
if($extend_filter) { if($extend_filter)
{
// If extend_filter exists, it changes the name of cache not to use cache // If extend_filter exists, it changes the name of cache not to use cache
$this->js_file .= '.nocache.js'; $this->js_file .= '.nocache.js';
@ -132,24 +136,26 @@
list($module_name, $method) = explode('.',$extend_filter); list($module_name, $method) = explode('.',$extend_filter);
// contibue if both module_name and methos exist. // contibue if both module_name and methos exist.
if($module_name&&$method) { if($module_name&&$method)
{
// get model object of the module // get model object of the module
$oExtendFilter = &getModel($module_name); $oExtendFilter = &getModel($module_name);
// execute if method exists // execute if method exists
if(method_exists($oExtendFilter, $method)) { if(method_exists($oExtendFilter, $method))
{
// get the result // get the result
$extend_filter_list = $oExtendFilter->{$method}(true); $extend_filter_list = $oExtendFilter->{$method}(true);
$extend_filter_count = count($extend_filter_list); $extend_filter_count = count($extend_filter_list);
// apply lang_value from the result to the variable // apply lang_value from the result to the variable
for($i=0; $i < $extend_filter_count; $i++) { for($i=0; $i < $extend_filter_count; $i++)
{
$name = $extend_filter_list[$i]->name; $name = $extend_filter_list[$i]->name;
$lang_value = $extend_filter_list[$i]->lang; $lang_value = $extend_filter_list[$i]->lang;
if($lang_value) $lang->{$name} = $lang_value; if($lang_value) $lang->{$name} = $lang_value;
} }
} }
} }
} }
@ -164,10 +170,13 @@
$fields = array(); $fields = array();
// create custom rule // create custom rule
if ($rules && $rules->rule) { if($rules && $rules->rule)
{
if(!is_array($rules->rule)) $rules->rule = array($rules->rule); if(!is_array($rules->rule)) $rules->rule = array($rules->rule);
foreach($rules->rule as $r) { foreach($rules->rule as $r)
if ($r->attrs->type == 'regex') { {
if($r->attrs->type == 'regex')
{
$js_rules[] = "v.cast('ADD_RULE', ['{$r->attrs->name}', {$r->body}]);"; $js_rules[] = "v.cast('ADD_RULE', ['{$r->attrs->name}', {$r->body}]);";
} }
} }
@ -175,8 +184,10 @@
// generates a field, which is a script of the checked item // generates a field, which is a script of the checked item
$node_count = count($field_node); $node_count = count($field_node);
if($node_count) { if($node_count)
foreach($field_node as $key =>$node) { {
foreach($field_node as $key =>$node)
{
$attrs = $node->attrs; $attrs = $node->attrs;
$target = trim($attrs->target); $target = trim($attrs->target);
@ -203,7 +214,8 @@
// Check extend_filter_item // Check extend_filter_item
$rule_types = array('homepage'=>'homepage', 'email_address'=>'email'); $rule_types = array('homepage'=>'homepage', 'email_address'=>'email');
for($i=0;$i<$extend_filter_count;$i++) { for($i=0;$i<$extend_filter_count;$i++)
{
$filter_item = $extend_filter_list[$i]; $filter_item = $extend_filter_list[$i];
$target = trim($filter_item->name); $target = trim($filter_item->name);
@ -226,9 +238,11 @@
// generates parameter script to create dbata // generates parameter script to create dbata
$rename_params = array(); $rename_params = array();
$parameter_count = count($parameter_param); $parameter_count = count($parameter_param);
if($parameter_count) { if($parameter_count)
{
// contains parameter of the default filter contents // contains parameter of the default filter contents
foreach($parameter_param as $key =>$param) { foreach($parameter_param as $key =>$param)
{
$attrs = $param->attrs; $attrs = $param->attrs;
$name = trim($attrs->name); $name = trim($attrs->name);
$target = trim($attrs->target); $target = trim($attrs->target);
@ -239,7 +253,8 @@
} }
// Check extend_filter_item // Check extend_filter_item
for($i=0;$i<$extend_filter_count;$i++) { for($i=0;$i<$extend_filter_count;$i++)
{
$filter_item = $extend_filter_list[$i]; $filter_item = $extend_filter_list[$i];
$target = $name = trim($filter_item->name); $target = $name = trim($filter_item->name);
if(!$name || !$target) continue; if(!$name || !$target) continue;
@ -251,7 +266,8 @@
// generates the response script // generates the response script
$response_count = count($response_tag); $response_count = count($response_tag);
$responses = array(); $responses = array();
for($i=0;$i<$response_count;$i++) { for($i=0;$i<$response_count;$i++)
{
$attrs = $response_tag[$i]->attrs; $attrs = $response_tag[$i]->attrs;
$name = $attrs->name; $name = $attrs->name;
$responses[] = "'{$name}'"; $responses[] = "'{$name}'";
@ -259,7 +275,8 @@
// writes lang values of the form field // writes lang values of the form field
$target_count = count($target_list); $target_count = count($target_list);
for($i=0;$i<$target_count;$i++) { for($i=0;$i<$target_count;$i++)
{
$target = $target_list[$i]; $target = $target_list[$i];
if(!$lang->{$target}) $lang->{$target} = $target; if(!$lang->{$target}) $lang->{$target} = $target;
$text = preg_replace('@\r?\n@', '\\n', addslashes($lang->{$target})); $text = preg_replace('@\r?\n@', '\\n', addslashes($lang->{$target}));
@ -277,7 +294,8 @@
*/ */
// writes error messages // writes error messages
foreach($lang->filter as $key => $val) { foreach($lang->filter as $key => $val)
{
if(!$val) $val = $key; if(!$val) $val = $key;
$val = preg_replace('@\r?\n@', '\\n', addslashes($val)); $val = preg_replace('@\r?\n@', '\\n', addslashes($val));
$js_messages[] = sprintf("v.cast('ADD_MESSAGE',['%s','%s']);", $key, $val); $js_messages[] = sprintf("v.cast('ADD_MESSAGE',['%s','%s']);", $key, $val);
@ -307,9 +325,11 @@
* return a file name of js file corresponding to the xml file * return a file name of js file corresponding to the xml file
* @param string $xml_file * @param string $xml_file
* @return string * @return string
**/ */
function _getCompiledFileName($xml_file) { function _getCompiledFileName($xml_file)
{
return sprintf('%s%s.%s.compiled.js',$this->compiled_path, md5($this->version.$xml_file),Context::getLangType()); 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 */

View file

@ -5,8 +5,9 @@
* @author NHN (developers@xpressengine.com) * @author NHN (developers@xpressengine.com)
* @package /classes/xml * @package /classes/xml
* @version 0.1 * @version 0.1
**/ */
class XmlLangParser extends XmlParser { class XmlLangParser extends XmlParser
{
/** /**
* compiled language cache path * compiled language cache path
* @var string * @var string
@ -45,7 +46,8 @@
* @param string $lang_type * @param string $lang_type
* @return void * @return void
*/ */
function XmlLangParser($xml_file, $lang_type) { function XmlLangParser($xml_file, $lang_type)
{
$this->lang_type = $lang_type; $this->lang_type = $lang_type;
$this->xml_file = $xml_file; $this->xml_file = $xml_file;
$this->php_file = $this->_getCompiledFileName($lang_type); $this->php_file = $this->_getCompiledFileName($lang_type);
@ -55,11 +57,15 @@
* compile a xml_file only when a corresponding php lang file does not exists or is outdated * compile a xml_file only when a corresponding php lang file does not exists or is outdated
* @return string|bool Returns compiled php file. * @return string|bool Returns compiled php file.
*/ */
function compile() { function compile()
{
if(!file_exists($this->xml_file)) return false; if(!file_exists($this->xml_file)) return false;
if(!file_exists($this->php_file)){ if(!file_exists($this->php_file))
{
$this->_compile(); $this->_compile();
} else { }
else
{
if(filemtime($this->xml_file)>filemtime($this->php_file)) $this->_compile(); if(filemtime($this->xml_file)>filemtime($this->php_file)) $this->_compile();
else return $this->php_file; else return $this->php_file;
} }
@ -71,7 +77,8 @@
* Return compiled content * Return compiled content
* @return string Returns compiled lang source code * @return string Returns compiled lang source code
*/ */
function getCompileContent() { function getCompileContent()
{
if(!file_exists($this->xml_file)) return false; if(!file_exists($this->xml_file)) return false;
$this->_compile(); $this->_compile();
@ -82,7 +89,8 @@
* Compile a xml_file * Compile a xml_file
* @return void * @return void
*/ */
function _compile() { function _compile()
{
$lang_selected = Context::loadLangSelected(); $lang_selected = Context::loadLangSelected();
$this->lang_types = array_keys($lang_selected); $this->lang_types = array_keys($lang_selected);
@ -95,7 +103,8 @@
$item = $xml_obj->lang->item; $item = $xml_obj->lang->item;
if(!is_array($item)) $item = array($item); if(!is_array($item)) $item = array($item);
foreach($item as $i){ foreach($item as $i)
{
$this->_parseItem($i, $var='$lang->%s'); $this->_parseItem($i, $var='$lang->%s');
} }
} }
@ -104,7 +113,8 @@
* Writing cache file * Writing cache file
* @return void|bool * @return void|bool
*/ */
function _writeFile(){ function _writeFile()
{
if(!$this->code) return; if(!$this->code) return;
FileHandler::writeFile($this->php_file, "<?php\n".$this->code); FileHandler::writeFile($this->php_file, "<?php\n".$this->code);
return false; return false;
@ -116,29 +126,37 @@
* @param string $var * @param string $var
* @return void * @return void
*/ */
function _parseItem($item, $var){ function _parseItem($item, $var)
{
$name = $item->attrs->name; $name = $item->attrs->name;
$value = $item->value; $value = $item->value;
$var = sprintf($var, $name); $var = sprintf($var, $name);
if($item->item) { if($item->item)
{
$type = $item->attrs->type; $type = $item->attrs->type;
if($type == 'array'){ if($type == 'array')
{
$this->code .= $var."=array();\n"; $this->code .= $var."=array();\n";
$var .= '[\'%s\']'; $var .= '[\'%s\']';
}else{ }
else
{
$this->code .= $var."=new stdClass;\n"; $this->code .= $var."=new stdClass;\n";
$var .= '->%s'; $var .= '->%s';
} }
$items = $item->item; $items = $item->item;
if(!is_array($items)) $items = array($items); if(!is_array($items)) $items = array($items);
foreach($items as $item){ foreach($items as $item)
{
$this->_parseItem($item, $var); $this->_parseItem($item, $var);
} }
} else { }
else
{
$code = $this->_parseValues($value, $var); $code = $this->_parseValues($value, $var);
$this->code .= $code; $this->code .= $code;
} }
@ -150,11 +168,13 @@
* @param string $var * @param string $var
* @return array|string * @return array|string
*/ */
function _parseValues($nodes, $var) { function _parseValues($nodes, $var)
{
if(!is_array($nodes)) $nodes = array($nodes); if(!is_array($nodes)) $nodes = array($nodes);
$value = array(); $value = array();
foreach($nodes as $node){ foreach($nodes as $node)
{
$return = $this->_parseValue($node, $var); $return = $this->_parseValue($node, $var);
if($return && is_array($return)) $value = array_merge($value, $return); if($return && is_array($return)) $value = array_merge($value, $return);
} }
@ -163,7 +183,8 @@
else if($value['en']) return $value['en']; else if($value['en']) return $value['en'];
else if($value['ko']) return $value['ko']; else if($value['ko']) return $value['ko'];
foreach($this->lang_types as $lang_type) { foreach($this->lang_types as $lang_type)
{
if($lang_type == 'en' || $lang_type == 'ko' || $lang_type == $this->lang_type) continue; if($lang_type == 'en' || $lang_type == 'ko' || $lang_type == $this->lang_type) continue;
if($value[$lang_type]) return $value[$lang_type]; if($value[$lang_type]) return $value[$lang_type];
} }
@ -177,7 +198,8 @@
* @param string $var * @param string $var
* @return array|bool * @return array|bool
*/ */
function _parseValue($node, $var) { function _parseValue($node, $var)
{
$lang_type = $node->attrs->xml_lang; $lang_type = $node->attrs->xml_lang;
$value = $node->body; $value = $node->body;
if(!$value) return false; if(!$value) return false;
@ -192,7 +214,10 @@
* @param string $type * @param string $type
* @return string * @return string
*/ */
function _getCompiledFileName($lang_type, $type='php') { function _getCompiledFileName($lang_type, $type='php')
{
return sprintf('%s%s.%s.php',$this->compiled_path, md5($this->xml_file), $lang_type); 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 */

View file

@ -31,7 +31,8 @@
* @package /classes/xml * @package /classes/xml
* @version 0.1 * @version 0.1
*/ */
class XmlParser { class XmlParser
{
/** /**
* Xml parser * Xml parser
* @var resource * @var resource
@ -58,7 +59,8 @@
* @param string $filename a file path of file * @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 * @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) { function loadXmlFile($filename)
{
if(!file_exists($filename)) return; if(!file_exists($filename)) return;
$buff = FileHandler::readFile($filename); $buff = FileHandler::readFile($filename);
@ -73,7 +75,8 @@
* @param mixed $arg2 ??? * @param mixed $arg2 ???
* @return array Returns a resultant data object or NULL in case of error * @return array Returns a resultant data object or NULL in case of error
*/ */
function parse($input = '', $arg1 = NULL, $arg2 = NULL) { function parse($input = '', $arg1 = NULL, $arg2 = NULL)
{
// Save the compile starting time for debugging // Save the compile starting time for debugging
if(__DEBUG__==3) $start = getMicroTime(); if(__DEBUG__==3) $start = getMicroTime();
@ -86,18 +89,25 @@
preg_match_all("/xml:lang=\"([^\"].+)\"/i", $this->input, $matches); preg_match_all("/xml:lang=\"([^\"].+)\"/i", $this->input, $matches);
// extracts the supported lanuage when xml:lang is used // extracts the supported lanuage when xml:lang is used
if(count($matches[1]) && $supported_lang = array_unique($matches[1])) { if(count($matches[1]) && $supported_lang = array_unique($matches[1]))
{
$tmpLangList = array_flip($supported_lang); $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 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[$this->lang]))
if(isset($tmpLangList['en'])) { {
if(isset($tmpLangList['en']))
{
$this->lang = 'en'; $this->lang = 'en';
} else { }
else
{
$this->lang = array_shift($supported_lang); $this->lang = array_shift($supported_lang);
} }
} }
// uncheck the language if no specific language is set. // uncheck the language if no specific language is set.
} else { }
else
{
$this->lang = ''; $this->lang = '';
} }
@ -127,7 +137,8 @@
* @param array $attrs attributes to be set * @param array $attrs attributes to be set
* @return array * @return array
*/ */
function _tagOpen($parser, $node_name, $attrs) { function _tagOpen($parser, $node_name, $attrs)
{
$obj = new Xml_Node_(); $obj = new Xml_Node_();
$obj->node_name = strtolower($node_name); $obj->node_name = strtolower($node_name);
$obj->attrs = $this->_arrToAttrsObj($attrs); $obj->attrs = $this->_arrToAttrsObj($attrs);
@ -143,7 +154,8 @@
* @param string $body a data to be added * @param string $body a data to be added
* @return void * @return void
*/ */
function _tagBody($parser, $body) { function _tagBody($parser, $body)
{
//if(!trim($body)) return; //if(!trim($body)) return;
$this->output[count($this->output)-1]->body .= $body; $this->output[count($this->output)-1]->body .= $body;
} }
@ -154,23 +166,30 @@
* @param string $node_name name of xml node * @param string $node_name name of xml node
* @return void * @return void
*/ */
function _tagClosed($parser, $node_name) { function _tagClosed($parser, $node_name)
{
$node_name = strtolower($node_name); $node_name = strtolower($node_name);
$cur_obj = array_pop($this->output); $cur_obj = array_pop($this->output);
$parent_obj = &$this->output[count($this->output)-1]; $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&&$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($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})) { if(isset($parent_obj->{$node_name}))
{
$tmp_obj = $parent_obj->{$node_name}; $tmp_obj = $parent_obj->{$node_name};
if(is_array($tmp_obj)) { if(is_array($tmp_obj))
{
array_push($parent_obj->{$node_name}, $cur_obj); array_push($parent_obj->{$node_name}, $cur_obj);
} else { }
else
{
$parent_obj->{$node_name} = array(); $parent_obj->{$node_name} = array();
array_push($parent_obj->{$node_name}, $tmp_obj); array_push($parent_obj->{$node_name}, $tmp_obj);
array_push($parent_obj->{$node_name}, $cur_obj); array_push($parent_obj->{$node_name}, $cur_obj);
} }
} else { }
else
{
if(!is_object($parent_obj)) if(!is_object($parent_obj))
$parent_obj = (object)$parent_obj; $parent_obj = (object)$parent_obj;
@ -182,14 +201,17 @@
* Method to transfer values in an array to a data object * Method to transfer values in an array to a data object
* @param array $arr data array * @param array $arr data array
* @return Xml_Node_ object * @return Xml_Node_ object
**/ */
function _arrToAttrsObj($arr) { function _arrToAttrsObj($arr)
{
$output = new Xml_Node_(); $output = new Xml_Node_();
foreach($arr as $key => $val) { foreach($arr as $key => $val)
{
$key = strtolower($key); $key = strtolower($key);
$output->{$key} = $val; $output->{$key} = $val;
} }
return $output; return $output;
} }
} }
?> /* End of file XmlParser.class.php */
/* Location: ./classes/xml/XmlParser.class.php */

View file

@ -1,13 +1,12 @@
<?php <?php
if(!defined('__XE_LOADED_XML_CLASS__')){ if(!defined('__XE_LOADED_XML_CLASS__'))
{
define('__XE_LOADED_XML_CLASS__', 1); define('__XE_LOADED_XML_CLASS__', 1);
require(_XE_PATH_.'classes/xml/xmlquery/tags/query/QueryTag.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/tags/query/QueryTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/table/TableTag.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/tags/table/TableTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/table/HintTableTag.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/tags/table/HintTableTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/table/TablesTag.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/tags/table/TablesTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/ColumnTag.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/tags/column/ColumnTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/SelectColumnTag.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/tags/column/SelectColumnTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnTag.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnTag.class.php');
@ -16,18 +15,14 @@
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionTag.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionsTag.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionsTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/group/GroupsTag.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/tags/group/GroupsTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/navigation/NavigationTag.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/tags/navigation/NavigationTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/navigation/IndexTag.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/tags/navigation/IndexTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/navigation/LimitTag.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/tags/navigation/LimitTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/QueryArgument.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/queryargument/QueryArgument.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/SortQueryArgument.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/queryargument/SortQueryArgument.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php'); require(_XE_PATH_.'classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php');
@ -43,21 +38,25 @@
* @todo need to support extend query such as subquery, union * @todo need to support extend query such as subquery, union
* @todo include info about column types for parsing user input * @todo include info about column types for parsing user input
*/ */
class XmlQueryParser extends XmlParser { class XmlQueryParser extends XmlParser
{
/** /**
* constructor * constructor
* @return void * @return void
*/ */
function XmlQueryParser(){ function XmlQueryParser()
{
} }
/** /**
* Create XmlQueryParser instance for Singleton * Create XmlQueryParser instance for Singleton
* @return XmlQueryParser object * @return XmlQueryParser object
*/ */
function &getInstance(){ function &getInstance()
{
static $theInstance = null; static $theInstance = null;
if(!isset($theInstance)){ if(!isset($theInstance))
{
$theInstance = new XmlQueryParser(); $theInstance = new XmlQueryParser();
} }
return $theInstance; return $theInstance;
@ -98,7 +97,8 @@
* Return XML file content * Return XML file content
* @return array|NULL Returns a resultant data object or NULL in case of error * @return array|NULL Returns a resultant data object or NULL in case of error
*/ */
function getXmlFileContent($xml_file){ function getXmlFileContent($xml_file)
{
$buff = FileHandler::readFile($xml_file); $buff = FileHandler::readFile($xml_file);
$xml_obj = parent::parse($buff); $xml_obj = parent::parse($buff);
if(!$xml_obj) return; if(!$xml_obj) return;
@ -106,4 +106,5 @@
return $xml_obj; return $xml_obj;
} }
} }
?> /* End of file XmlQueryParser.150.class.php */
/* Location: ./classes/xml/XmlQueryParser.150.class.php */

View file

@ -7,7 +7,8 @@
* @version 0.1 * @version 0.1
* @todo need to support extend query such as subquery, union * @todo need to support extend query such as subquery, union
*/ */
class XmlQueryParser extends XmlParser { class XmlQueryParser extends XmlParser
{
var $default_list = array(); var $default_list = array();
var $notnull_list = array(); var $notnull_list = array();
@ -21,7 +22,8 @@
* @param string $cache_file file path of a cache file to store resultant php code after parsing xml query * @param string $cache_file file path of a cache file to store resultant php code after parsing xml query
* @return void Nothing is requred. * @return void Nothing is requred.
*/ */
function parse($query_id, $xml_file, $cache_file) { function parse($query_id, $xml_file, $cache_file)
{
// query xml 파일을 찾아서 파싱, 결과가 없으면 return // query xml 파일을 찾아서 파싱, 결과가 없으면 return
$buff = FileHandler::readFile($xml_file); $buff = FileHandler::readFile($xml_file);
$xml_obj = parent::parse($buff); $xml_obj = parent::parse($buff);
@ -29,11 +31,14 @@
unset($buff); unset($buff);
$id_args = explode('.', $query_id); $id_args = explode('.', $query_id);
if(count($id_args)==2) { if(count($id_args)==2)
{
$target = 'modules'; $target = 'modules';
$module = $id_args[0]; $module = $id_args[0];
$id = $id_args[1]; $id = $id_args[1];
} elseif(count($id_args)==3) { }
elseif(count($id_args)==3)
{
$target = $id_args[0]; $target = $id_args[0];
$typeList = array('modules'=>1, 'addons'=>1, 'widgets'=>1); $typeList = array('modules'=>1, 'addons'=>1, 'widgets'=>1);
if(!isset($typeList[$target])) return; if(!isset($typeList[$target])) return;
@ -54,8 +59,8 @@
if(!$tables) return; if(!$tables) return;
if(!is_array($tables)) $tables = array($tables); if(!is_array($tables)) $tables = array($tables);
$joinList = array('left join'=>1, 'left outer join'=>1, 'right join'=>1, 'right outer join'=>1); $joinList = array('left join'=>1, 'left outer join'=>1, 'right join'=>1, 'right outer join'=>1);
foreach($tables as $key => $val) { foreach($tables as $key => $val)
{
// 테이블과 alias의 이름을 구함 // 테이블과 alias의 이름을 구함
$table_name = $val->attrs->name; $table_name = $val->attrs->name;
$alias = $val->attrs->alias; $alias = $val->attrs->alias;
@ -63,32 +68,38 @@
$output->tables[$alias] = $table_name; $output->tables[$alias] = $table_name;
if(isset($joinList[$val->attrs->type]) && count($val->conditions)){ if(isset($joinList[$val->attrs->type]) && count($val->conditions))
{
$output->left_tables[$alias] = $val->attrs->type; $output->left_tables[$alias] = $val->attrs->type;
$left_conditions[$alias] = $val->conditions; $left_conditions[$alias] = $val->conditions;
} }
// 테이블을 찾아서 컬럼의 속성을 구함 // 테이블을 찾아서 컬럼의 속성을 구함
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $module, $table_name); $table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $module, $table_name);
if(!file_exists($table_file)) { if(!file_exists($table_file))
{
$searched_list = FileHandler::readDir(_XE_PATH_.'modules'); $searched_list = FileHandler::readDir(_XE_PATH_.'modules');
$searched_count = count($searched_list); $searched_count = count($searched_list);
for($i=0;$i<$searched_count;$i++) { for($i=0;$i<$searched_count;$i++)
{
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $searched_list[$i], $table_name); $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)) break;
} }
} }
if(file_exists($table_file)) { if(file_exists($table_file))
{
$table_xml = FileHandler::readFile($table_file); $table_xml = FileHandler::readFile($table_file);
$table_obj = parent::parse($table_xml); $table_obj = parent::parse($table_xml);
if($table_obj->table) { if($table_obj->table)
{
if(isset($table_obj->table->column) && !is_array($table_obj->table->column)) if(isset($table_obj->table->column) && !is_array($table_obj->table->column))
{ {
$table_obj->table->column = array($table_obj->table->column); $table_obj->table->column = array($table_obj->table->column);
} }
foreach($table_obj->table->column as $k => $v) { foreach($table_obj->table->column as $k => $v)
{
$buff .= sprintf('$output->column_type["%s"] = "%s";%s', $v->attrs->name, $v->attrs->type, "\n"); $buff .= sprintf('$output->column_type["%s"] = "%s";%s', $v->attrs->name, $v->attrs->type, "\n");
} }
} }
@ -105,8 +116,10 @@
$out = $this->_setConditions($conditions); $out = $this->_setConditions($conditions);
$output->conditions = $out->conditions; $output->conditions = $out->conditions;
foreach($output->left_tables as $key => $val){ foreach($output->left_tables as $key => $val)
if($left_conditions[$key]){ {
if($left_conditions[$key])
{
$out = $this->_setConditions($left_conditions[$key]); $out = $this->_setConditions($left_conditions[$key]);
$output->left_conditions[$key] = $out->conditions; $output->left_conditions[$key] = $out->conditions;
} }
@ -127,8 +140,10 @@
$condition_count = count($output->conditions); $condition_count = count($output->conditions);
$buff .= '$output->tables = array( '; $buff .= '$output->tables = array( ';
foreach($output->tables as $key => $val) { foreach($output->tables as $key => $val)
if(!array_key_exists($key,$output->left_tables)){ {
if(!array_key_exists($key,$output->left_tables))
{
$buff .= sprintf('"%s"=>"%s",', $key, $val); $buff .= sprintf('"%s"=>"%s",', $key, $val);
} }
} }
@ -136,37 +151,44 @@
// php script 생성 // php script 생성
$buff .= '$output->_tables = array( '; $buff .= '$output->_tables = array( ';
foreach($output->tables as $key => $val) { foreach($output->tables as $key => $val)
{
$buff .= sprintf('"%s"=>"%s",', $key, $val); $buff .= sprintf('"%s"=>"%s",', $key, $val);
} }
$buff .= ' );'."\n"; $buff .= ' );'."\n";
if(count($output->left_tables)){ if(count($output->left_tables))
{
$buff .= '$output->left_tables = array( '; $buff .= '$output->left_tables = array( ';
foreach($output->left_tables as $key => $val) { foreach($output->left_tables as $key => $val)
{
$buff .= sprintf('"%s"=>"%s",', $key, $val); $buff .= sprintf('"%s"=>"%s",', $key, $val);
} }
$buff .= ' );'."\n"; $buff .= ' );'."\n";
} }
// column 정리 // column 정리
if($column_count) { if($column_count)
{
$buff .= '$output->columns = array ( '; $buff .= '$output->columns = array ( ';
$buff .= $this->_getColumn($output->columns); $buff .= $this->_getColumn($output->columns);
$buff .= ' );'."\n"; $buff .= ' );'."\n";
} }
// conditions 정리 // conditions 정리
if($condition_count) { if($condition_count)
{
$buff .= '$output->conditions = array ( '; $buff .= '$output->conditions = array ( ';
$buff .= $this->_getConditions($output->conditions); $buff .= $this->_getConditions($output->conditions);
$buff .= ' );'."\n"; $buff .= ' );'."\n";
} }
// conditions 정리 // conditions 정리
if(count($output->left_conditions)) { if(count($output->left_conditions))
{
$buff .= '$output->left_conditions = array ( '; $buff .= '$output->left_conditions = array ( ';
foreach($output->left_conditions as $key => $val){ foreach($output->left_conditions as $key => $val)
{
$buff .= "'{$key}' => array ( "; $buff .= "'{$key}' => array ( ";
$buff .= $this->_getConditions($val); $buff .= $this->_getConditions($val);
$buff .= "),\n"; $buff .= "),\n";
@ -186,65 +208,81 @@
} }
// order 정리 // order 정리
if($output->order) { if($output->order)
{
$buff .= '$output->order = array('; $buff .= '$output->order = array(';
foreach($output->order as $key => $val) { 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 .= 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"; $buff .= ');'."\n";
} }
// list_count 정리 // list_count 정리
if($output->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"); $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 정리 // page_count 정리
if($output->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"); $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 정리 // page 정리
if($output->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"); $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 정리 // group by 정리
if($output->groups) { if($output->groups)
{
$buff .= sprintf('$output->groups = array("%s");%s', implode('","',$output->groups),"\n"); $buff .= sprintf('$output->groups = array("%s");%s', implode('","',$output->groups),"\n");
} }
// minlength check // minlength check
if(count($minlength_list)) { if(count($minlength_list))
foreach($minlength_list as $key => $val) { {
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"; $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 // maxlength check
if(count($maxlength_list)) { if(count($maxlength_list))
foreach($maxlength_list as $key => $val) { {
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"; $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 // filter check
if(count($this->filter_list)) { if(count($this->filter_list))
foreach($this->filter_list as $key => $val) { {
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"); $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 // default check
if(count($this->default_list)) { if(count($this->default_list))
foreach($this->default_list as $key => $val) { {
foreach($this->default_list as $key => $val)
{
$pre_buff .= 'if(!isset($args->'.$key.')) $args->'.$key.' = '.$val.';'."\n"; $pre_buff .= 'if(!isset($args->'.$key.')) $args->'.$key.' = '.$val.';'."\n";
} }
} }
// not null check // not null check
if(count($this->notnull_list)) { if(count($this->notnull_list))
foreach($this->notnull_list as $key => $val) { {
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"; $pre_buff .= 'if(!isset($args->'.$val.')) return new Object(-1, sprintf($lang->filter->isnull, $lang->'.$val.'?$lang->'.$val.':\''.$val.'\'));'."\n";
} }
} }
@ -265,12 +303,17 @@
* @param array $columns column information * @param array $columns column information
* @return object * @return object
*/ */
function _setColumn($columns){ function _setColumn($columns)
if(!$columns) { {
if(!$columns)
{
$output->column[] = array("*" => "*"); $output->column[] = array("*" => "*");
} else { }
else
{
if(!is_array($columns)) $columns = array($columns); if(!is_array($columns)) $columns = array($columns);
foreach($columns as $key => $val) { foreach($columns as $key => $val)
{
$name = $val->attrs->name; $name = $val->attrs->name;
/* /*
if(strpos('.',$name)===false && count($output->tables)==1) { if(strpos('.',$name)===false && count($output->tables)==1) {
@ -300,11 +343,12 @@
* @param object @condition SQL condition information * @param object @condition SQL condition information
* @retrun object * @retrun object
*/ */
function _setConditions($conditions){ function _setConditions($conditions)
{
// 조건절 정리 // 조건절 정리
$condition = $conditions->condition; $condition = $conditions->condition;
if($condition) { if($condition)
{
$obj->condition = $condition; $obj->condition = $condition;
unset($condition); unset($condition);
$condition = array($obj); $condition = array($obj);
@ -316,8 +360,10 @@
elseif($condition_group) $cond = $condition_group; elseif($condition_group) $cond = $condition_group;
else $cond = $condition; else $cond = $condition;
if($cond) { if($cond)
foreach($cond as $key => $val) { {
foreach($cond as $key => $val)
{
unset($cond_output); unset($cond_output);
if($val->attrs->pipe) $cond_output->pipe = $val->attrs->pipe; if($val->attrs->pipe) $cond_output->pipe = $val->attrs->pipe;
@ -326,7 +372,8 @@
if(!$val->condition) continue; if(!$val->condition) continue;
if(!is_array($val->condition)) $val->condition = array($val->condition); if(!is_array($val->condition)) $val->condition = array($val->condition);
foreach($val->condition as $k => $v) { foreach($val->condition as $k => $v)
{
$obj = $v->attrs; $obj = $v->attrs;
if(!$obj->alias) $obj->alias = $obj->column; if(!$obj->alias) $obj->alias = $obj->column;
$cond_output->condition[] = $obj; $cond_output->condition[] = $obj;
@ -343,12 +390,14 @@
* @param array $group_list SQL group information * @param array $group_list SQL group information
* @return object * @return object
*/ */
function _setGroup($group_list){ function _setGroup($group_list)
{
// group 정리 // group 정리
if($group_list)
if($group_list) { {
if(!is_array($group_list)) $group_list = array($group_list); if(!is_array($group_list)) $group_list = array($group_list);
for($i=0;$i<count($group_list);$i++) { for($i=0;$i<count($group_list);$i++)
{
$group = $group_list[$i]; $group = $group_list[$i];
$column = trim($group->attrs->column); $column = trim($group->attrs->column);
if(!$column) continue; if(!$column) continue;
@ -359,19 +408,22 @@
return $output; return $output;
} }
/** /**
* Transfer pagnation information to $output * Transfer pagnation information to $output
* @param object $xml_obj xml object containing Navigation information * @param object $xml_obj xml object containing Navigation information
* @return object * @return object
*/ */
function _setNavigation($xml_obj){ function _setNavigation($xml_obj)
{
$navigation = $xml_obj->query->navigation; $navigation = $xml_obj->query->navigation;
if($navigation) { if($navigation)
{
$order = $navigation->index; $order = $navigation->index;
if($order) { if($order)
{
if(!is_array($order)) $order = array($order); if(!is_array($order)) $order = array($order);
foreach($order as $order_info) { foreach($order as $order_info)
{
$output->order[] = $order_info->attrs; $output->order[] = $order_info->attrs;
} }
} }
@ -394,38 +446,46 @@
* @param array $columns * @param array $columns
* @return string buffer containing php code * @return string buffer containing php code
*/ */
function _getColumn($columns){ function _getColumn($columns)
{
$buff = ''; $buff = '';
$str = ''; $str = '';
$print_vars = array(); $print_vars = array();
foreach($columns as $key => $val) { foreach($columns as $key => $val)
{
$str = 'array("name"=>"%s","alias"=>"%s"'; $str = 'array("name"=>"%s","alias"=>"%s"';
$print_vars = array(); $print_vars = array();
$print_vars[] = $val['name']; $print_vars[] = $val['name'];
$print_vars[] = $val['alias']; $print_vars[] = $val['alias'];
$val['default'] = $this->getDefault($val['name'], $val['default']); $val['default'] = $this->getDefault($val['name'], $val['default']);
if($val['var'] && strpos($val['var'],'.')===false) { if($val['var'] && strpos($val['var'],'.')===false)
{
if($val['default']){ if($val['default'])
{
$str .= ',"value"=>$args->%s?$args->%s:%s'; $str .= ',"value"=>$args->%s?$args->%s:%s';
$print_vars[] = $val['var']; $print_vars[] = $val['var'];
$print_vars[] = $val['var']; $print_vars[] = $val['var'];
$print_vars[] = $val['default']; $print_vars[] = $val['default'];
}else{ }
else
{
$str .= ',"value"=>$args->%s'; $str .= ',"value"=>$args->%s';
$print_vars[] = $val['var']; $print_vars[] = $val['var'];
} }
}
} else { else
if($val['default']){ {
if($val['default'])
{
$str .= ',"value"=>%s'; $str .= ',"value"=>%s';
$print_vars[] = $val['default']; $print_vars[] = $val['default'];
} }
} }
if($val['click_count']){ if($val['click_count'])
{
$str .= ',"click_count"=>$args->%s'; $str .= ',"click_count"=>$args->%s';
$print_vars[] = $val['click_count']; $print_vars[] = $val['click_count'];
} }
@ -444,27 +504,48 @@
* @param array $conditions array containing Query conditions * @param array $conditions array containing Query conditions
* @return string buffer containing php code * @return string buffer containing php code
*/ */
function _getConditions($conditions){ function _getConditions($conditions)
{
$buff = ''; $buff = '';
foreach($conditions as $key => $val) { foreach($conditions as $key => $val)
{
$buff .= sprintf('array("pipe"=>"%s",%s"condition"=>array(', $val->pipe,"\n"); $buff .= sprintf('array("pipe"=>"%s",%s"condition"=>array(', $val->pipe,"\n");
foreach($val->condition as $k => $v) { foreach($val->condition as $k => $v)
{
$v->default = $this->getDefault($v->column, $v->default); $v->default = $this->getDefault($v->column, $v->default);
if($v->var) { if($v->var)
if(strpos($v->var,".")===false) { {
if(strpos($v->var,".")===false)
{
if($v->default) $this->default_list[$v->var] = $v->default; if($v->default) $this->default_list[$v->var] = $v->default;
if($v->filter) $this->filter_list[] = $v; if($v->filter) $this->filter_list[] = $v;
if($v->notnull) $this->notnull_list[] = $v->var; 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"); if($v->default)
else $buff .= sprintf('array("column"=>"%s", "value"=>$args->%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->pipe, $v->operation, "\n"); {
$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); $this->addArguments($v->var);
} else { }
else
{
$buff .= sprintf('array("column"=>"%s", "value"=>"%s","pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->pipe, $v->operation, "\n"); $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
else $buff .= sprintf('array("column"=>"%s", "pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->pipe, $v->operation,"\n"); {
if($v->default)
{
$buff .= sprintf('array("column"=>"%s", "value"=>%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->default ,$v->pipe, $v->operation,"\n");
}
else
{
$buff .= sprintf('array("column"=>"%s", "pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->pipe, $v->operation,"\n");
}
} }
} }
$buff .= ')),'."\n"; $buff .= ')),'."\n";
@ -497,7 +578,8 @@
* @param mixed $value * @param mixed $value
* @return mixed Returns a default value for specified field * @return mixed Returns a default value for specified field
*/ */
function getDefault($name, $value) { function getDefault($name, $value)
{
$db_info = Context::getDBInfo (); $db_info = Context::getDBInfo ();
if(!isset($value)) return; if(!isset($value)) return;
$str_pos = strpos($value, '('); $str_pos = strpos($value, '(');
@ -506,7 +588,8 @@
$func_name = substr($value, 0, $str_pos); $func_name = substr($value, 0, $str_pos);
$args = substr($value, $str_pos+1, strlen($value)-1); $args = substr($value, $str_pos+1, strlen($value)-1);
switch($func_name) { switch($func_name)
{
case 'ipaddress' : case 'ipaddress' :
$val = '$_SERVER[\'REMOTE_ADDR\']'; $val = '$_SERVER[\'REMOTE_ADDR\']';
break; break;
@ -521,25 +604,34 @@
break; break;
case 'plus' : case 'plus' :
$args = abs($args); $args = abs($args);
if ($db_info->db_type == 'cubrid') { if($db_info->db_type == 'cubrid')
{
$val = sprintf ('"\\"%s\\"+%d"', $name, $args); $val = sprintf ('"\\"%s\\"+%d"', $name, $args);
} else { }
else
{
$val = sprintf('"%s+%d"', $name, $args); $val = sprintf('"%s+%d"', $name, $args);
} }
break; break;
case 'minus' : case 'minus' :
$args = abs($args); $args = abs($args);
if ($db_info->db_type == 'cubrid') { if($db_info->db_type == 'cubrid')
{
$val = sprintf ('"\\"%s\\"-%d"', $name, $args); $val = sprintf ('"\\"%s\\"-%d"', $name, $args);
} else { }
else
{
$val = sprintf('"%s-%d"', $name, $args); $val = sprintf('"%s-%d"', $name, $args);
} }
break; break;
case 'multiply' : case 'multiply' :
$args = intval($args); $args = intval($args);
if ($db_info->db_type == 'cubrid') { if($db_info->db_type == 'cubrid')
{
$val = sprintf ('"\\"%s\\"*%d"', $name, $args); $val = sprintf ('"\\"%s\\"*%d"', $name, $args);
} else { }
else
{
$val = sprintf('"%s*%d"', $name, $args); $val = sprintf('"%s*%d"', $name, $args);
} }
break; break;
@ -548,4 +640,5 @@
return $val; return $val;
} }
} }
?> /* End of file XmlQueryParser.class.php */
/* Location: ./classes/xml/XmlQueryParser.class.php */

View file

@ -5,7 +5,8 @@
* @package /classes/xml/xmlquery * @package /classes/xml/xmlquery
* @version 0.1 * @version 0.1
*/ */
class DBParser { class DBParser
{
/** /**
* Character for escape target value on the left * Character for escape target value on the left
* @var string * @var string
@ -29,7 +30,8 @@
* @param string $table_prefix * @param string $table_prefix
* @return void * @return void
*/ */
function DBParser($escape_char_left, $escape_char_right = "", $table_prefix = "xe_"){ function DBParser($escape_char_left, $escape_char_right = "", $table_prefix = "xe_")
{
$this->escape_char_left = $escape_char_left; $this->escape_char_left = $escape_char_left;
if ($escape_char_right !== "")$this->escape_char_right = $escape_char_right; if ($escape_char_right !== "")$this->escape_char_right = $escape_char_right;
else $this->escape_char_right = $escape_char_left; else $this->escape_char_right = $escape_char_left;
@ -41,7 +43,8 @@
* @param string $leftOrRight left or right * @param string $leftOrRight left or right
* @return string * @return string
*/ */
function getEscapeChar($leftOrRight){ function getEscapeChar($leftOrRight)
{
if ($leftOrRight === 'left')return $this->escape_char_left; if ($leftOrRight === 'left')return $this->escape_char_left;
else return $this->escape_char_right; else return $this->escape_char_right;
} }
@ -51,7 +54,8 @@
* @param mixed $name * @param mixed $name
* @return string * @return string
*/ */
function escape($name){ function escape($name)
{
return $this->escape_char_left . $name . $this->escape_char_right; return $this->escape_char_left . $name . $this->escape_char_right;
} }
@ -60,7 +64,8 @@
* @param string $name * @param string $name
* @return string * @return string
*/ */
function escapeString($name){ function escapeString($name)
{
return "'".$this->escapeStringValue($name)."'"; return "'".$this->escapeStringValue($name)."'";
} }
@ -69,7 +74,8 @@
* @param string $value * @param string $value
* @return string * @return string
*/ */
function escapeStringValue($value){ function escapeStringValue($value)
{
if($value == "*") return $value; if($value == "*") return $value;
if (is_string($value)) return $value = str_replace("'","''",$value); if (is_string($value)) return $value = str_replace("'","''",$value);
return $value; return $value;
@ -80,7 +86,8 @@
* @param string $name table name without table prefix * @param string $name table name without table prefix
* @return string table full name with table prefix * @return string table full name with table prefix
*/ */
function parseTableName($name){ function parseTableName($name)
{
return $this->table_prefix . $name; return $this->table_prefix . $name;
} }
@ -89,7 +96,8 @@
* @param string $name column name before escape * @param string $name column name before escape
* @return string column name after escape * @return string column name after escape
*/ */
function parseColumnName($name){ function parseColumnName($name)
{
return $this->escapeColumn($name); return $this->escapeColumn($name);
} }
@ -98,10 +106,12 @@
* @param string $column_name * @param string $column_name
* @return string column name with db name * @return string column name with db name
*/ */
function escapeColumn($column_name){ function escapeColumn($column_name)
{
if($this->isUnqualifiedColumnName($column_name)) if($this->isUnqualifiedColumnName($column_name))
return $this->escape($column_name); return $this->escape($column_name);
if($this->isQualifiedColumnName($column_name)){ if($this->isQualifiedColumnName($column_name))
{
list($table, $column) = explode('.', $column_name); list($table, $column) = explode('.', $column_name);
// $table can also be an alias, so the prefix should not be added // $table can also be an alias, so the prefix should not be added
return $this->escape($table).'.'.$this->escape($column); return $this->escape($table).'.'.$this->escape($column);
@ -114,7 +124,8 @@
* @param string $column_name * @param string $column_name
* @return bool * @return bool
*/ */
function isUnqualifiedColumnName($column_name){ function isUnqualifiedColumnName($column_name)
{
if(strpos($column_name,'.')===false && strpos($column_name,'(')===false) return true; if(strpos($column_name,'.')===false && strpos($column_name,'(')===false) return true;
return false; return false;
} }
@ -124,27 +135,33 @@
* @param string $column_name * @param string $column_name
* @return bool * @return bool
*/ */
function isQualifiedColumnName($column_name){ function isQualifiedColumnName($column_name)
{
if(strpos($column_name,'.')!==false && strpos($column_name,'(')===false) return true; if(strpos($column_name,'.')!==false && strpos($column_name,'(')===false) return true;
return false; return false;
} }
function parseExpression($column_name){ function parseExpression($column_name)
{
$functions = preg_split('/([\+\-\*\/\ ])/', $column_name, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); $functions = preg_split('/([\+\-\*\/\ ])/', $column_name, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
foreach($functions as $k => $v){ foreach($functions as $k => $v)
{
$function = &$functions[$k]; $function = &$functions[$k];
if(strlen($function)==1) continue; // skip delimiters if(strlen($function)==1) continue; // skip delimiters
$pos = strrpos("(", $function); $pos = strrpos("(", $function);
$matches = preg_split('/([a-zA-Z0-9_*]+)/', $function, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); $matches = preg_split('/([a-zA-Z0-9_*]+)/', $function, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
$total_brackets = substr_count($function, "("); $total_brackets = substr_count($function, "(");
$brackets = 0; $brackets = 0;
foreach($matches as $i => $j){ foreach($matches as $i => $j)
{
$match = &$matches[$i]; $match = &$matches[$i];
if($match == '(') {$brackets++; continue;} if($match == '(') {$brackets++; continue;}
if(strpos($match,')') !== false) continue; if(strpos($match,')') !== false) continue;
if(in_array($match, array(',', '.'))) continue; if(in_array($match, array(',', '.'))) continue;
if($brackets == $total_brackets){ if($brackets == $total_brackets)
if(!is_numeric($match)) { {
if(!is_numeric($match))
{
$match = $this->escapeColumnExpression($match); $match = $this->escapeColumnExpression($match);
} }
} }
@ -159,7 +176,8 @@
* @param string $column_name * @param string $column_name
* @return bool * @return bool
*/ */
function isStar($column_name){ function isStar($column_name)
{
if(substr($column_name,-1) == '*') return true; if(substr($column_name,-1) == '*') return true;
return false; return false;
} }
@ -170,7 +188,8 @@
* @param string $column_name * @param string $column_name
* @return bool * @return bool
*/ */
function isStarFunction($column_name){ function isStarFunction($column_name)
{
if(strpos($column_name, "(*)")!==false) return true; if(strpos($column_name, "(*)")!==false) return true;
return false; return false;
} }
@ -180,14 +199,16 @@
* @param string $column_name * @param string $column_name
* @return string * @return string
*/ */
function escapeColumnExpression($column_name){ function escapeColumnExpression($column_name)
{
if($this->isStar($column_name)) return $column_name; if($this->isStar($column_name)) return $column_name;
if($this->isStarFunction($column_name)){ if($this->isStarFunction($column_name))
{
return $column_name; return $column_name;
} }
if(strpos(strtolower($column_name), 'distinct') !== false) return $column_name; if(strpos(strtolower($column_name), 'distinct') !== false) return $column_name;
return $this->escapeColumn($column_name); return $this->escapeColumn($column_name);
} }
} }
/* End of file DBParser.class.php */
/* Location: ./classes/xml/xmlquery/DBParser.class.php */

View file

@ -5,7 +5,8 @@
* @package /classes/xml/xmlquery * @package /classes/xml/xmlquery
* @version 0.1 * @version 0.1
*/ */
class QueryParser { class QueryParser
{
/** /**
* QueryTag object * QueryTag object
* @var QueryTag object * @var QueryTag object
@ -18,7 +19,8 @@
* @param bool $isSubQuery * @param bool $isSubQuery
* @return void * @return void
*/ */
function QueryParser($query = NULL, $isSubQuery = false) { function QueryParser($query = NULL, $isSubQuery = false)
{
if($query) if($query)
$this->queryTag = new QueryTag($query, $isSubQuery); $this->queryTag = new QueryTag($query, $isSubQuery);
} }
@ -29,16 +31,20 @@
* @param bool $table_name * @param bool $table_name
* @return array * @return array
*/ */
function getTableInfo($query_id, $table_name) { function getTableInfo($query_id, $table_name)
{
$column_type = array(); $column_type = array();
$module = ''; $module = '';
$id_args = explode('.', $query_id); $id_args = explode('.', $query_id);
if (count($id_args) == 2) { if(count($id_args) == 2)
{
$target = 'modules'; $target = 'modules';
$module = $id_args[0]; $module = $id_args[0];
$id = $id_args[1]; $id = $id_args[1];
} elseif (count($id_args) == 3) { }
else if(count($id_args) == 3)
{
$target = $id_args[0]; $target = $id_args[0];
$targetList = array('modules'=>1, 'addons'=>1, 'widgets'=>1); $targetList = array('modules'=>1, 'addons'=>1, 'widgets'=>1);
if (!isset($targetList[$target])) if (!isset($targetList[$target]))
@ -49,26 +55,32 @@
// get column properties from the table // get column properties from the table
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $module, $table_name); $table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $module, $table_name);
if (!file_exists($table_file)) { if(!file_exists($table_file))
{
$searched_list = FileHandler::readDir(_XE_PATH_ . 'modules'); $searched_list = FileHandler::readDir(_XE_PATH_ . 'modules');
$searched_count = count($searched_list); $searched_count = count($searched_list);
for ($i = 0; $i < $searched_count; $i++) { for($i = 0; $i < $searched_count; $i++)
{
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $searched_list[$i], $table_name); $table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $searched_list[$i], $table_name);
if(file_exists($table_file)) if(file_exists($table_file))
break; break;
} }
} }
if (file_exists($table_file)) { if(file_exists($table_file))
{
$table_xml = FileHandler::readFile($table_file); $table_xml = FileHandler::readFile($table_file);
$xml_parser = new XmlParser(); $xml_parser = new XmlParser();
$table_obj = $xml_parser->parse($table_xml); $table_obj = $xml_parser->parse($table_xml);
if ($table_obj->table) { if($table_obj->table)
if (isset($table_obj->table->column) && !is_array($table_obj->table->column)) { {
if(isset($table_obj->table->column) && !is_array($table_obj->table->column))
{
$table_obj->table->column = array($table_obj->table->column); $table_obj->table->column = array($table_obj->table->column);
} }
foreach ($table_obj->table->column as $k => $v) { foreach($table_obj->table->column as $k => $v)
{
$column_type[$v->attrs->name] = $v->attrs->type; $column_type[$v->attrs->name] = $v->attrs->type;
} }
} }
@ -81,12 +93,12 @@
* Change code string from queryTag object * Change code string from queryTag object
* @return string * @return string
*/ */
function toString() { function toString()
{
return "<?php if(!defined('__ZBXE__')) exit();\n" return "<?php if(!defined('__ZBXE__')) exit();\n"
. $this->queryTag->toString() . $this->queryTag->toString()
. 'return $query; ?>'; . 'return $query; ?>';
} }
} }
/* End of file QueryParser.class.php */
?> /* Location: ./classes/xml/xmlquery/QueryParser.class.php */

View file

@ -5,7 +5,8 @@
* @package /classes/xml/xmlquery/argument * @package /classes/xml/xmlquery/argument
* @version 0.1 * @version 0.1
*/ */
class Argument { class Argument
{
/** /**
* argument value * argument value
* @var mixed * @var mixed
@ -52,51 +53,62 @@ class Argument {
* @param mixed $value * @param mixed $value
* @return void * @return void
*/ */
function Argument($name, $value) { function Argument($name, $value)
{
$this->value = $value; $this->value = $value;
$this->name = $name; $this->name = $name;
$this->isValid = true; $this->isValid = true;
} }
function getType() { function getType()
{
if(isset($this->type)) if(isset($this->type))
{ {
return $this->type; return $this->type;
} }
if(is_string($this->value)) if(is_string($this->value))
return 'column_name'; return 'column_name';
return 'number'; return 'number';
} }
function setColumnType($value) { function setColumnType($value)
{
$this->type = $value; $this->type = $value;
} }
function setColumnOperation($operation) { function setColumnOperation($operation)
{
$this->column_operation = $operation; $this->column_operation = $operation;
} }
function getName() { function getName()
{
return $this->name; return $this->name;
} }
function getValue() { function getValue()
if (!isset($this->_value)) { {
if(!isset($this->_value))
{
$value = $this->getEscapedValue(); $value = $this->getEscapedValue();
$this->_value = $this->toString($value); $this->_value = $this->toString($value);
} }
return $this->_value; return $this->_value;
} }
function getColumnOperation() { function getColumnOperation()
{
return $this->column_operation; return $this->column_operation;
} }
function getEscapedValue() { function getEscapedValue()
{
return $this->escapeValue($this->value); return $this->escapeValue($this->value);
} }
function getUnescapedValue() { function getUnescapedValue()
{
return $this->value; return $this->value;
} }
@ -105,8 +117,10 @@ class Argument {
* @param mixed $value * @param mixed $value
* @return string * @return string
*/ */
function toString($value) { function toString($value)
if (is_array($value)) { {
if(is_array($value))
{
if(count($value) === 0) if(count($value) === 0)
return ''; return '';
if(count($value) === 1 && $value[0] === '') if(count($value) === 1 && $value[0] === '')
@ -121,9 +135,11 @@ class Argument {
* @param mixed $value * @param mixed $value
* @return mixed * @return mixed
*/ */
function escapeValue($value) { function escapeValue($value)
{
$column_type = $this->getType(); $column_type = $this->getType();
if ($column_type == 'column_name') { if($column_type == 'column_name')
{
$dbParser = DB::getParser(); $dbParser = DB::getParser();
return $dbParser->parseExpression($value); return $dbParser->parseExpression($value);
} }
@ -131,10 +147,12 @@ class Argument {
return null; return null;
$columnTypeList = array('date'=>1, 'varchar'=>1, 'char'=>1, 'text'=>1, 'bigtext'=>1); $columnTypeList = array('date'=>1, 'varchar'=>1, 'char'=>1, 'text'=>1, 'bigtext'=>1);
if (isset($columnTypeList[$column_type])) { if(isset($columnTypeList[$column_type]))
{
if(!is_array($value)) if(!is_array($value))
$value = $this->_escapeStringValue($value); $value = $this->_escapeStringValue($value);
else { else
{
$total = count($value); $total = count($value);
for($i = 0; $i < $total; $i++) for($i = 0; $i < $total; $i++)
$value[$i] = $this->_escapeStringValue($value[$i]); $value[$i] = $this->_escapeStringValue($value[$i]);
@ -142,14 +160,20 @@ class Argument {
} }
} }
if($this->uses_default_value) return $value; if($this->uses_default_value) return $value;
if ($column_type == 'number') { if($column_type == 'number')
if (is_array($value)) { {
foreach ($value AS $key => $val) { if(is_array($value))
if (isset($val) && $val !== '') { {
foreach ($value AS $key => $val)
{
if(isset($val) && $val !== '')
{
$value[$key] = (int) $val; $value[$key] = (int) $val;
} }
} }
} else { }
else
{
$value = (int) $value; $value = (int) $value;
} }
} }
@ -162,7 +186,8 @@ class Argument {
* @param string $value * @param string $value
* @return string * @return string
*/ */
function _escapeStringValue($value) { function _escapeStringValue($value)
{
// Remove non-utf8 chars. // 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'; $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,7 +197,8 @@ class Argument {
return '\'' . $value . '\''; return '\'' . $value . '\'';
} }
function utf8Replacer($captures) { function utf8Replacer($captures)
{
if(!empty($captures[1])) if(!empty($captures[1]))
{ {
// Valid byte sequence. Return unmodified. // Valid byte sequence. Return unmodified.
@ -194,22 +220,26 @@ class Argument {
} }
} }
function isValid() { function isValid()
{
return $this->isValid; return $this->isValid;
} }
function isColumnName(){ function isColumnName()
{
$type = $this->getType(); $type = $this->getType();
if($type == 'column_name') return true; if($type == 'column_name') return true;
if($type == 'number' && !is_numeric($this->value) && $this->uses_default_value) return true; if($type == 'number' && !is_numeric($this->value) && $this->uses_default_value) return true;
return false; return false;
} }
function getErrorMessage() { function getErrorMessage()
{
return $this->errorMessage; return $this->errorMessage;
} }
function ensureDefaultValue($default_value) { function ensureDefaultValue($default_value)
{
if(!isset($this->value) || $this->value == '') if(!isset($this->value) || $this->value == '')
{ {
$this->value = $default_value; $this->value = $default_value;
@ -222,28 +252,34 @@ class Argument {
* @param string $filter_type * @param string $filter_type
* @return void * @return void
*/ */
function checkFilter($filter_type) { function checkFilter($filter_type)
if (isset($this->value) && $this->value != '') { {
if(isset($this->value) && $this->value != '')
{
global $lang; global $lang;
$val = $this->value; $val = $this->value;
$key = $this->name; $key = $this->name;
switch ($filter_type) { switch ($filter_type)
{
case 'email' : case 'email' :
case 'email_address' : 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->isValid = false;
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_email, $lang->{$key} ? $lang->{$key} : $key)); $this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_email, $lang->{$key} ? $lang->{$key} : $key));
} }
break; break;
case 'homepage' : 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->isValid = false;
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_homepage, $lang->{$key} ? $lang->{$key} : $key)); $this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_homepage, $lang->{$key} ? $lang->{$key} : $key));
} }
break; break;
case 'userid' : case 'userid' :
case 'user_id' : 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->isValid = false;
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_userid, $lang->{$key} ? $lang->{$key} : $key)); $this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_userid, $lang->{$key} ? $lang->{$key} : $key));
} }
@ -252,19 +288,22 @@ class Argument {
case 'numbers' : case 'numbers' :
if(is_array($val)) if(is_array($val))
$val = join(',', $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->isValid = false;
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_number, $lang->{$key} ? $lang->{$key} : $key)); $this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_number, $lang->{$key} ? $lang->{$key} : $key));
} }
break; break;
case 'alpha' : case 'alpha' :
if (!preg_match('/^[a-z]+$/is', $val)) { if(!preg_match('/^[a-z]+$/is', $val))
{
$this->isValid = false; $this->isValid = false;
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha, $lang->{$key} ? $lang->{$key} : $key)); $this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha, $lang->{$key} ? $lang->{$key} : $key));
} }
break; break;
case 'alpha_number' : case 'alpha_number' :
if (!preg_match('/^[0-9a-z]+$/is', $val)) { if(!preg_match('/^[0-9a-z]+$/is', $val))
{
$this->isValid = false; $this->isValid = false;
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha_number, $lang->{$key} ? $lang->{$key} : $key)); $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) { function checkMaxLength($length)
if ($this->value && (strlen($this->value) > $length)) { {
if($this->value && (strlen($this->value) > $length))
{
global $lang; global $lang;
$this->isValid = false; $this->isValid = false;
$key = $this->name; $key = $this->name;
@ -282,8 +323,10 @@ class Argument {
} }
} }
function checkMinLength($length) { function checkMinLength($length)
if ($this->value && (strlen($this->value) < $length)) { {
if($this->value && (strlen($this->value) < $length))
{
global $lang; global $lang;
$this->isValid = false; $this->isValid = false;
$key = $this->name; $key = $this->name;
@ -291,15 +334,16 @@ class Argument {
} }
} }
function checkNotNull() { function checkNotNull()
if (!isset($this->value)) { {
if(!isset($this->value))
{
global $lang; global $lang;
$this->isValid = false; $this->isValid = false;
$key = $this->name; $key = $this->name;
$this->errorMessage = new Object(-1, sprintf($lang->filter->isnull, $lang->{$key} ? $lang->{$key} : $key)); $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 */