issue 2119. supporting php 5.4. widget and xml classes.

git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12697 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
flyskyko 2013-02-05 03:25:47 +00:00
parent 285301a8c9
commit ba9800ff34
37 changed files with 1187 additions and 473 deletions

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @class WidgetHandler * @class WidgetHandler
* @author NHN (developers@xpressengine.com) * @author NHN (developers@xpressengine.com)
@ -7,7 +8,9 @@
*/ */
class WidgetHandler class WidgetHandler
{ {
var $widget_path = ''; var $widget_path = '';
} }
/* End of file WidgetHandler.class.php */ /* End of file WidgetHandler.class.php */
/* Location: ./classes/widget/WidgetHandler.class.php */ /* Location: ./classes/widget/WidgetHandler.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* GeneralXmlParser class * GeneralXmlParser class
* Generic XML parser for XE * Generic XML parser for XE
@ -8,6 +9,7 @@
*/ */
class GeneralXmlParser class GeneralXmlParser
{ {
/** /**
* result of parse * result of parse
* @var array * @var array
@ -29,7 +31,10 @@ class GeneralXmlParser
xml_parse($oParser, $input); xml_parse($oParser, $input);
xml_parser_free($oParser); xml_parser_free($oParser);
if(!count($this->output)) return; if(!count($this->output))
{
return;
}
$this->output = array_shift($this->output); $this->output = array_shift($this->output);
return $this->output; return $this->output;
@ -61,7 +66,7 @@ class GeneralXmlParser
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;
} }
/** /**
@ -74,9 +79,9 @@ class GeneralXmlParser
{ {
$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($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))
@ -95,6 +100,7 @@ class GeneralXmlParser
$parent_obj->childNodes[$node_name] = $cur_obj; $parent_obj->childNodes[$node_name] = $cur_obj;
} }
} }
} }
/* End of file GeneralXmlParser.class.php */ /* End of file GeneralXmlParser.class.php */
/* Location: ./classes/xml/GeneralXmlParser.class.php */ /* Location: ./classes/xml/GeneralXmlParser.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* XmlGenerator class * XmlGenerator class
* @author NHN (developers@xpressengine.com) * @author NHN (developers@xpressengine.com)
@ -7,6 +8,7 @@
*/ */
class XmlGenerator class XmlGenerator
{ {
/** /**
* object change to xml * object change to xml
* @param object $xml * @param object $xml
@ -36,12 +38,11 @@ class XmlGenerator
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));
} }
@ -51,9 +52,8 @@ class XmlGenerator
case 'body' : case 'body' :
$body = $value; $body = $value;
break; break;
default : default : {
{ if(is_array($value))
if (is_array($value))
{ {
foreach($value as $idx => $arrNode) foreach($value as $idx => $arrNode)
{ {
@ -67,8 +67,9 @@ 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 */ /* End of file XmlGenerator.class.php */
/* Location: ./classes/xml/XmlGenerator.class.php */ /* Location: ./classes/xml/XmlGenerator.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* filter class traslate xml content into javascript code * filter class traslate xml content into javascript code
* *
@ -46,11 +47,13 @@
*/ */
class XmlJsFilter extends XmlParser class XmlJsFilter extends XmlParser
{ {
/** /**
* version * version
* @var string * @var string
*/ */
var $version = '0.2.5'; var $version = '0.2.5';
/** /**
* compiled javascript cache path * compiled javascript cache path
* @var string * @var string
@ -61,6 +64,7 @@ class XmlJsFilter extends XmlParser
* @var string * @var string
*/ */
var $xml_file = NULL; var $xml_file = NULL;
/** /**
* Compiled js file * Compiled js file
* @var string * @var string
@ -73,10 +77,14 @@ class XmlJsFilter extends XmlParser
* @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) !== '/')
$this->xml_file = sprintf("%s%s",$path, $xml_file); {
$path .= '/';
}
$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);
} }
@ -86,10 +94,19 @@ class XmlJsFilter extends XmlParser
*/ */
function compile() function compile()
{ {
if(!file_exists($this->xml_file)) return; if(!file_exists($this->xml_file))
if(!file_exists($this->js_file)) $this->_compile(); {
else if(filemtime($this->xml_file)>filemtime($this->js_file)) $this->_compile(); return;
Context::loadFile(array($this->js_file, 'body', '',null)); }
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));
} }
/** /**
@ -110,21 +127,30 @@ class XmlJsFilter extends XmlParser
$rules = $xml_obj->filter->rules; $rules = $xml_obj->filter->rules;
// XmlJsFilter handles three data; filter_name, field, and parameter // XmlJsFilter handles three data; filter_name, field, and parameter
$filter_name = $attrs->name; $filter_name = $attrs->name;
$confirm_msg_code = $attrs->confirm_msg_code; $confirm_msg_code = $attrs->confirm_msg_code;
$module = $attrs->module; $module = $attrs->module;
$act = $attrs->act; $act = $attrs->act;
$extend_filter = $attrs->extend_filter; $extend_filter = $attrs->extend_filter;
$field_node = $xml_obj->filter->form->node; $field_node = $xml_obj->filter->form->node;
if($field_node && !is_array($field_node)) $field_node = array($field_node); if($field_node && !is_array($field_node))
{
$field_node = array($field_node);
}
$parameter_param = $xml_obj->filter->parameter->param; $parameter_param = $xml_obj->filter->parameter->param;
if($parameter_param && !is_array($parameter_param)) $parameter_param = array($parameter_param); if($parameter_param && !is_array($parameter_param))
{
$parameter_param = array($parameter_param);
}
$response_tag = $xml_obj->filter->response->tag; $response_tag = $xml_obj->filter->response->tag;
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)
@ -133,46 +159,52 @@ class XmlJsFilter extends XmlParser
$this->js_file .= '.nocache.js'; $this->js_file .= '.nocache.js';
// Separate the extend_filter // Separate the extend_filter
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;
}
} }
} }
} }
} }
// search the field to be used for entering language // search the field to be used for entering language
$target_list = array(); $target_list = array();
$target_type_list = array(); $target_type_list = array();
// javascript contents // javascript contents
$js_rules = array(); $js_rules = array();
$js_messages = array(); $js_messages = array();
$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')
@ -186,87 +218,138 @@ class XmlJsFilter extends XmlParser
$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);
if(!$target) continue; if(!$target)
{
continue;
}
$rule = trim($attrs->rule?$attrs->rule:$attrs->filter); $rule = trim($attrs->rule ? $attrs->rule : $attrs->filter);
$equalto = trim($attrs->equalto); $equalto = trim($attrs->equalto);
$field = array(); $field = array();
if($attrs->required == 'true') $field[] = 'required:true'; if($attrs->required == 'true')
if($attrs->minlength > 0) $field[] = 'minlength:'.$attrs->minlength; {
if($attrs->maxlength > 0) $field[] = 'maxlength:'.$attrs->maxlength; $field[] = 'required:true';
if($equalto) $field[] = "equalto:'{$attrs->equalto}'"; }
if($rule) $field[] = "rule:'{$rule}'"; 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)."}"; $fields[] = "'{$target}': {" . implode(',', $field) . "}";
if(!in_array($target, $target_list)) $target_list[] = $target; if(!in_array($target, $target_list))
if(!$target_type_list[$target]) $target_type_list[$target] = $filter; {
$target_list[] = $target;
}
if(!$target_type_list[$target])
{
$target_type_list[$target] = $filter;
}
} }
} }
// 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);
if(!$target) continue; if(!$target)
{
continue;
}
// get the filter from the type of extend filter item // get the filter from the type of extend filter item
$type = $filter_item->type; $type = $filter_item->type;
$rule = $rule_types[$type]?$rule_types[$type]:''; $rule = $rule_types[$type] ? $rule_types[$type] : '';
$required = ($filter_item->required == 'true'); $required = ($filter_item->required == 'true');
$field = array(); $field = array();
if($required) $field[] = 'required:true'; if($required)
if($rule) $field[] = "rule:'{$rule}'"; {
$fields[] = "\t\t'{$target}' : {".implode(',', $field)."}"; $field[] = 'required:true';
}
if($rule)
{
$field[] = "rule:'{$rule}'";
}
$fields[] = "\t\t'{$target}' : {" . implode(',', $field) . "}";
if(!in_array($target, $target_list)) $target_list[] = $target; if(!in_array($target, $target_list))
if(!$target_type_list[$target]) $target_type_list[$target] = $type; {
$target_list[] = $target;
}
if(!$target_type_list[$target])
{
$target_type_list[$target] = $type;
}
} }
// 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);
//if($name && $target && ($name != $target)) $js_doc[] = "\t\tparams['{$name}'] = params['{$target}']; delete params['{$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 && $target && ($name != $target))
if($name && !in_array($name, $target_list)) $target_list[] = $name; {
$rename_params[] = "'{$target}':'{$name}'";
}
if($name && !in_array($name, $target_list))
{
$target_list[] = $name;
}
} }
// 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;
}
if(!in_array($name, $target_list)) $target_list[] = $name; if(!in_array($name, $target_list))
{
$target_list[] = $name;
}
} }
} }
// 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;
@ -275,47 +358,59 @@ class XmlJsFilter extends XmlParser
// 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}));
$js_messages[] = "v.cast('ADD_MESSAGE',['{$target}','{$text}']);"; $js_messages[] = "v.cast('ADD_MESSAGE',['{$target}','{$text}']);";
} }
// writes the target type // writes the target type
/* /*
$target_type_count = count($target_type_list); $target_type_count = count($target_type_list);
if($target_type_count) { if($target_type_count) {
foreach($target_type_list as $target => $type) { foreach($target_type_list as $target => $type) {
//$js_doc .= sprintf("target_type_list[\"%s\"] = \"%s\";\n", $target, $type); //$js_doc .= sprintf("target_type_list[\"%s\"] = \"%s\";\n", $target, $type);
} }
} }
*/ */
// 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);
} }
$callback_func = $xml_obj->filter->response->attrs->callback_func; $callback_func = $xml_obj->filter->response->attrs->callback_func;
if(!$callback_func) $callback_func = "filterAlertMessage"; if(!$callback_func)
{
$callback_func = "filterAlertMessage";
}
$confirm_msg = ''; $confirm_msg = '';
if ($confirm_msg_code) $confirm_msg = $lang->{$confirm_msg_code}; if($confirm_msg_code)
{
$confirm_msg = $lang->{$confirm_msg_code};
}
$jsdoc = array(); $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 {$filter_name}(form){ return legacy_filter('{$filter_name}', form, '{$module}', '{$act}', {$callback_func}, [" . implode(',', $responses) . "], '" . addslashes($confirm_msg) . "', {" . implode(',', $rename_params) . "}) };";
$jsdoc[] = '(function($){'; $jsdoc[] = '(function($){';
$jsdoc[] = "\tvar v=xe.getApp('validator')[0];if(!v)return false;"; $jsdoc[] = "\tvar v=xe.getApp('validator')[0];if(!v)return false;";
$jsdoc[] = "\t".'v.cast("ADD_FILTER", ["'.$filter_name.'", {'.implode(',', $fields).'}]);'; $jsdoc[] = "\t" . 'v.cast("ADD_FILTER", ["' . $filter_name . '", {' . implode(',', $fields) . '}]);';
$jsdoc[] = "\t".implode("\n\t", $js_rules); $jsdoc[] = "\t" . implode("\n\t", $js_rules);
$jsdoc[] = "\t".implode("\n\t", $js_messages); $jsdoc[] = "\t" . implode("\n\t", $js_messages);
$jsdoc[] = '})(jQuery);'; $jsdoc[] = '})(jQuery);';
$jsdoc = implode("\n", $jsdoc); $jsdoc = implode("\n", $jsdoc);
// generates the js file // generates the js file
FileHandler::writeFile($this->js_file, $jsdoc); FileHandler::writeFile($this->js_file, $jsdoc);
@ -328,8 +423,9 @@ class XmlJsFilter extends XmlParser
*/ */
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 */ /* End of file XmlJsFilter.class.php */
/* Location: ./classes/xml/XmlJsFilter.class.php */ /* Location: ./classes/xml/XmlJsFilter.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* XmlLangParser class * XmlLangParser class
* Change to lang php file from xml. * Change to lang php file from xml.
@ -8,6 +9,7 @@
*/ */
class XmlLangParser extends XmlParser class XmlLangParser extends XmlParser
{ {
/** /**
* compiled language cache path * compiled language cache path
* @var string * @var string
@ -18,21 +20,25 @@ class XmlLangParser extends XmlParser
* @var string * @var string
*/ */
var $xml_file = NULL; var $xml_file = NULL;
/** /**
* Target php file * Target php file
* @var string * @var string
*/ */
var $php_file = NULL; var $php_file = NULL;
/** /**
* result source code * result source code
* @var string * @var string
*/ */
var $code; var $code;
/** /**
* language list, for example ko, en... * language list, for example ko, en...
* @var array * @var array
*/ */
var $lang_types; var $lang_types;
/** /**
* language type * language type
* @see _XE_PATH_.'/common/lang/lang.info' * @see _XE_PATH_.'/common/lang/lang.info'
@ -59,18 +65,27 @@ class XmlLangParser extends XmlParser
*/ */
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))
else return $this->php_file; {
$this->_compile();
}
else
{
return $this->php_file;
}
} }
return $this->_writeFile() ? $this->php_file : false; return $this->_writeFile() ? $this->php_file : FALSE;
} }
/** /**
@ -79,7 +94,10 @@ class XmlLangParser extends XmlParser
*/ */
function getCompileContent() function getCompileContent()
{ {
if(!file_exists($this->xml_file)) return false; if(!file_exists($this->xml_file))
{
return FALSE;
}
$this->_compile(); $this->_compile();
return $this->code; return $this->code;
@ -96,16 +114,19 @@ class XmlLangParser extends XmlParser
// read xml file // read xml file
$buff = FileHandler::readFile($this->xml_file); $buff = FileHandler::readFile($this->xml_file);
$buff = str_replace('xml:lang','xml_lang',$buff); $buff = str_replace('xml:lang', 'xml_lang', $buff);
// xml parsing // xml parsing
$xml_obj = parent::parse($buff); $xml_obj = parent::parse($buff);
$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');
} }
} }
@ -115,8 +136,11 @@ class XmlLangParser extends XmlParser
*/ */
function _writeFile() function _writeFile()
{ {
if(!$this->code) return; if(!$this->code)
FileHandler::writeFile($this->php_file, "<?php\n".$this->code); {
return;
}
FileHandler::writeFile($this->php_file, "<?php\n" . $this->code);
return false; return false;
} }
@ -138,22 +162,24 @@ class XmlLangParser extends XmlParser
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
{ {
@ -170,23 +196,44 @@ class XmlLangParser extends XmlParser
*/ */
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);
}
} }
if($value[$this->lang_type]) return $value[$this->lang_type]; if($value[$this->lang_type])
else if($value['en']) return $value['en']; {
else if($value['ko']) return $value['ko']; 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) 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)
if($value[$lang_type]) return $value[$lang_type]; {
continue;
}
if($value[$lang_type])
{
return $value[$lang_type];
}
} }
return ''; return '';
@ -202,10 +249,13 @@ class XmlLangParser extends XmlParser
{ {
$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;
}
$var .= '=\'' . str_replace("'","\'",$value) . "';\n"; $var .= '=\'' . str_replace("'", "\'", $value) . "';\n";
return array($lang_type=>$var); return array($lang_type => $var);
} }
/** /**
@ -214,10 +264,11 @@ class XmlLangParser extends XmlParser
* @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 */ /* End of file XmlLangParser.class.php */
/* Location: ./classes/xml/XmlLangParser.class.php */ /* Location: ./classes/xml/XmlLangParser.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Xml_Node_ class * Xml_Node_ class
* Element node or attribute node. * Element node or attribute node.
@ -8,6 +9,7 @@
*/ */
class Xml_Node_ class Xml_Node_
{ {
/** In PHP5 this will silence E_STRICT warnings /** In PHP5 this will silence E_STRICT warnings
* for undeclared properties. * for undeclared properties.
* No effect in PHP4 * No effect in PHP4
@ -16,6 +18,7 @@ class Xml_Node_
{ {
return NULL; return NULL;
} }
} }
/** /**
@ -33,21 +36,25 @@ class Xml_Node_
*/ */
class XmlParser class XmlParser
{ {
/** /**
* Xml parser * Xml parser
* @var resource * @var resource
*/ */
var $oParser = NULL; var $oParser = NULL;
/** /**
* Input xml * Input xml
* @var string * @var string
*/ */
var $input = NULL; var $input = NULL;
/** /**
* Output object in array * Output object in array
* @var array * @var array
*/ */
var $output = array(); var $output = array();
/** /**
* The default language type * The default language type
* @var string * @var string
@ -61,7 +68,10 @@ class XmlParser
*/ */
function loadXmlFile($filename) function loadXmlFile($filename)
{ {
if(!file_exists($filename)) return; if(!file_exists($filename))
{
return;
}
$buff = FileHandler::readFile($filename); $buff = FileHandler::readFile($filename);
$oXmlParser = new XmlParser(); $oXmlParser = new XmlParser();
@ -78,12 +88,15 @@ class XmlParser
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();
}
$this->lang = Context::getLangType(); $this->lang = Context::getLangType();
$this->input = $input?$input:$GLOBALS['HTTP_RAW_POST_DATA']; $this->input = $input ? $input : $GLOBALS['HTTP_RAW_POST_DATA'];
$this->input = str_replace(array('',''),array('',''),$this->input); $this->input = str_replace(array('', ''), array('', ''), $this->input);
// extracts a supported language // extracts a supported language
preg_match_all("/xml:lang=\"([^\"].+)\"/i", $this->input, $matches); preg_match_all("/xml:lang=\"([^\"].+)\"/i", $this->input, $matches);
@ -120,16 +133,21 @@ class XmlParser
xml_parse($this->oParser, $this->input); xml_parse($this->oParser, $this->input);
xml_parser_free($this->oParser); xml_parser_free($this->oParser);
if(!count($this->output)) return; if(!count($this->output))
{
return;
}
$output = array_shift($this->output); $output = array_shift($this->output);
// Save compile starting time for debugging // Save compile starting time for debugging
if(__DEBUG__==3) $GLOBALS['__xmlparse_elapsed__'] += getMicroTime() - $start; if(__DEBUG__ == 3)
{
$GLOBALS['__xmlparse_elapsed__'] += getMicroTime() - $start;
}
return $output; return $output;
} }
/** /**
* Start element handler. * Start element handler.
* @param resource $parse an instance of parser * @param resource $parse an instance of parser
@ -146,7 +164,6 @@ class XmlParser
array_push($this->output, $obj); array_push($this->output, $obj);
} }
/** /**
* Character data handler * Character data handler
* Variable in the last element of this->output * Variable in the last element of this->output
@ -157,7 +174,7 @@ class XmlParser
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;
} }
/** /**
@ -170,9 +187,15 @@ class XmlParser
{ {
$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)
if($this->lang&&$parent_obj->{$node_name}->attrs->{'xml:lang'}&&$parent_obj->{$node_name}->attrs->{'xml:lang'}!=$this->lang) return; {
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}))
{ {
@ -191,7 +214,9 @@ class XmlParser
else else
{ {
if(!is_object($parent_obj)) if(!is_object($parent_obj))
$parent_obj = (object)$parent_obj; {
$parent_obj = (object) $parent_obj;
}
$parent_obj->{$node_name} = $cur_obj; $parent_obj->{$node_name} = $cur_obj;
} }
@ -212,6 +237,7 @@ class XmlParser
} }
return $output; return $output;
} }
} }
/* End of file XmlParser.class.php */ /* End of file XmlParser.class.php */
/* Location: ./classes/xml/XmlParser.class.php */ /* Location: ./classes/xml/XmlParser.class.php */

View file

@ -1,36 +1,36 @@
<?php <?php
/** /**
* File containing the XE 1.5 XmlQueryParserClass * File containing the XE 1.5 XmlQueryParserClass
*/ */
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');
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php'); require(_XE_PATH_ . 'classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php'); require(_XE_PATH_ . 'classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php');
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');
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/DefaultValue.class.php'); require(_XE_PATH_ . 'classes/xml/xmlquery/queryargument/DefaultValue.class.php');
} }
/** /**
@ -43,12 +43,14 @@ if(!defined('__XE_LOADED_XML_CLASS__'))
*/ */
class XmlQueryParser extends XmlParser class XmlQueryParser extends XmlParser
{ {
/** /**
* constructor * constructor
* @return void * @return void
*/ */
function XmlQueryParser() function XmlQueryParser()
{ {
} }
/** /**
@ -86,7 +88,10 @@ class XmlQueryParser extends XmlParser
// insert, update, delete, select action // insert, update, delete, select action
$action = strtolower($xml_obj->query->attrs->action); $action = strtolower($xml_obj->query->attrs->action);
if(!$action) return; if(!$action)
{
return;
}
// Write query cache file // Write query cache file
$parser = new QueryParser($xml_obj->query); $parser = new QueryParser($xml_obj->query);
@ -120,10 +125,14 @@ class XmlQueryParser extends XmlParser
{ {
$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;
}
unset($buff); unset($buff);
return $xml_obj; return $xml_obj;
} }
} }
/* End of file XmlQueryParser.150.class.php */ /* End of file XmlQueryParser.150.class.php */
/* Location: ./classes/xml/XmlQueryParser.150.class.php */ /* Location: ./classes/xml/XmlQueryParser.150.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* XmlQueryParser * XmlQueryParser
* Case to parse XE xml query * Case to parse XE xml query
@ -27,28 +28,37 @@ class XmlQueryParser extends XmlParser
// 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);
if(!$xml_obj) return; if(!$xml_obj)
{
return;
}
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;
}
$module = $id_args[1]; $module = $id_args[1];
$id = $id_args[2]; $id = $id_args[2];
} }
// insert, update, delete, select등의 action // insert, update, delete, select등의 action
$action = strtolower($xml_obj->query->attrs->action); $action = strtolower($xml_obj->query->attrs->action);
if(!$action) return; if(!$action)
{
return;
}
// 테이블 정리 (배열코드로 변환) // 테이블 정리 (배열코드로 변환)
$tables = $xml_obj->query->tables->table; $tables = $xml_obj->query->tables->table;
@ -56,21 +66,30 @@ class XmlQueryParser extends XmlParser
$left_conditions = array(); $left_conditions = array();
if(!$tables) return; if(!$tables)
if(!is_array($tables)) $tables = array($tables); {
$joinList = array('left join'=>1, 'left outer join'=>1, 'right join'=>1, 'right outer join'=>1); 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) 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;
if(!$alias) $alias = $table_name; if(!$alias)
{
$alias = $table_name;
}
$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;
} }
@ -78,12 +97,15 @@ class XmlQueryParser extends XmlParser
$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;
}
} }
} }
@ -142,12 +164,12 @@ class XmlQueryParser extends XmlParser
$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);
} }
} }
$buff .= ' );'."\n"; $buff .= ' );' . "\n";
// php script 생성 // php script 생성
$buff .= '$output->_tables = array( '; $buff .= '$output->_tables = array( ';
@ -155,7 +177,7 @@ class XmlQueryParser extends XmlParser
{ {
$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))
{ {
@ -164,7 +186,7 @@ class XmlQueryParser extends XmlParser
{ {
$buff .= sprintf('"%s"=>"%s",', $key, $val); $buff .= sprintf('"%s"=>"%s",', $key, $val);
} }
$buff .= ' );'."\n"; $buff .= ' );' . "\n";
} }
// column 정리 // column 정리
@ -172,7 +194,7 @@ class XmlQueryParser extends XmlParser
{ {
$buff .= '$output->columns = array ( '; $buff .= '$output->columns = array ( ';
$buff .= $this->_getColumn($output->columns); $buff .= $this->_getColumn($output->columns);
$buff .= ' );'."\n"; $buff .= ' );' . "\n";
} }
// conditions 정리 // conditions 정리
@ -180,7 +202,7 @@ class XmlQueryParser extends XmlParser
{ {
$buff .= '$output->conditions = array ( '; $buff .= '$output->conditions = array ( ';
$buff .= $this->_getConditions($output->conditions); $buff .= $this->_getConditions($output->conditions);
$buff .= ' );'."\n"; $buff .= ' );' . "\n";
} }
// conditions 정리 // conditions 정리
@ -193,7 +215,7 @@ class XmlQueryParser extends XmlParser
$buff .= $this->_getConditions($val); $buff .= $this->_getConditions($val);
$buff .= "),\n"; $buff .= "),\n";
} }
$buff .= ' );'."\n"; $buff .= ' );' . "\n";
} }
// args 변수 확인 // args 변수 확인
@ -202,8 +224,8 @@ class XmlQueryParser extends XmlParser
{ {
foreach($arg_list as $arg) 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_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"; $pre_buff .= 'if(is_array($args->' . $arg . ') && count($args->' . $arg . ')==0){ unset($args->' . $arg . '); };' . "\n";
} }
} }
@ -215,31 +237,31 @@ class XmlQueryParser extends XmlParser
{ {
$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
@ -247,7 +269,7 @@ class XmlQueryParser extends XmlParser
{ {
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";
} }
} }
@ -256,7 +278,7 @@ class XmlQueryParser extends XmlParser
{ {
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";
} }
} }
@ -265,7 +287,7 @@ class XmlQueryParser extends XmlParser
{ {
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");
} }
} }
@ -274,7 +296,7 @@ class XmlQueryParser extends XmlParser
{ {
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";
} }
} }
@ -283,16 +305,16 @@ class XmlQueryParser extends XmlParser
{ {
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";
} }
} }
$buff = "<?php if(!defined('__ZBXE__')) exit();\n" $buff = "<?php if(!defined('__ZBXE__')) exit();\n"
. sprintf('$output->query_id = "%s";%s', $query_id, "\n") . sprintf('$output->query_id = "%s";%s', $query_id, "\n")
. sprintf('$output->action = "%s";%s', $action, "\n") . sprintf('$output->action = "%s";%s', $action, "\n")
. $pre_buff . $pre_buff
. $buff . $buff
. 'return $output; ?>'; . 'return $output; ?>';
// 저장 // 저장
FileHandler::writeFile($cache_file, $buff); FileHandler::writeFile($cache_file, $buff);
@ -311,16 +333,19 @@ class XmlQueryParser extends XmlParser
} }
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) {
$tmp = array_values($output->tables); $tmp = array_values($output->tables);
$name = sprintf('%s.%s', $tmp[0], $val->attrs->name); $name = sprintf('%s.%s', $tmp[0], $val->attrs->name);
} }
*/ */
$output->columns[] = array( $output->columns[] = array(
"name" => $name, "name" => $name,
@ -354,11 +379,23 @@ class XmlQueryParser extends XmlParser
$condition = array($obj); $condition = array($obj);
} }
$condition_group = $conditions->group; $condition_group = $conditions->group;
if($condition_group && !is_array($condition_group)) $condition_group = array($condition_group); if($condition_group && !is_array($condition_group))
{
$condition_group = array($condition_group);
}
if($condition && $condition_group) $cond = array_merge($condition, $condition_group); if($condition && $condition_group)
elseif($condition_group) $cond = $condition_group; {
else $cond = $condition; $cond = array_merge($condition, $condition_group);
}
elseif($condition_group)
{
$cond = $condition_group;
}
else
{
$cond = $condition;
}
if($cond) if($cond)
{ {
@ -366,16 +403,31 @@ class XmlQueryParser extends XmlParser
{ {
unset($cond_output); unset($cond_output);
if($val->attrs->pipe) $cond_output->pipe = $val->attrs->pipe; if($val->attrs->pipe)
else $cond_output->pipe = null; {
$cond_output->pipe = $val->attrs->pipe;
}
else
{
$cond_output->pipe = null;
}
if(!$val->condition) continue; if(!$val->condition)
if(!is_array($val->condition)) $val->condition = array($val->condition); {
continue;
}
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;
} }
@ -395,15 +447,24 @@ class XmlQueryParser extends XmlParser
// group 정리 // group 정리
if($group_list) if($group_list)
{ {
if(!is_array($group_list)) $group_list = array($group_list); if(!is_array($group_list))
for($i=0;$i<count($group_list);$i++) {
$group_list = array($group_list);
}
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;
}
$group_column_list[] = $column; $group_column_list[] = $column;
} }
if(count($group_column_list)) $output->groups = $group_column_list; if(count($group_column_list))
{
$output->groups = $group_column_list;
}
} }
return $output; return $output;
} }
@ -421,7 +482,10 @@ class XmlQueryParser extends XmlParser
$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;
@ -435,7 +499,7 @@ class XmlQueryParser extends XmlParser
$output->page_count = $page_count; $output->page_count = $page_count;
$page = $navigation->page->attrs; $page = $navigation->page->attrs;
$output->page = $page ; $output->page = $page;
} }
return $output; return $output;
} }
@ -460,18 +524,18 @@ class XmlQueryParser extends XmlParser
$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'];
} }
} }
@ -479,7 +543,7 @@ class XmlQueryParser extends XmlParser
{ {
if($val['default']) if($val['default'])
{ {
$str .= ',"value"=>%s'; $str .= ',"value"=>%s';
$print_vars[] = $val['default']; $print_vars[] = $val['default'];
} }
} }
@ -509,17 +573,26 @@ class XmlQueryParser extends XmlParser
$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)
if($v->filter) $this->filter_list[] = $v; {
if($v->notnull) $this->notnull_list[] = $v->var; $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) 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"); $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");
@ -540,15 +613,15 @@ class XmlQueryParser extends XmlParser
{ {
if($v->default) if($v->default)
{ {
$buff .= sprintf('array("column"=>"%s", "value"=>%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->default ,$v->pipe, $v->operation,"\n"); $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"); $buff .= sprintf('array("column"=>"%s", "pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->pipe, $v->operation, "\n");
} }
} }
} }
$buff .= ')),'."\n"; $buff .= ')),' . "\n";
} }
return $buff; return $buff;
} }
@ -580,13 +653,19 @@ class XmlQueryParser extends XmlParser
*/ */
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, '(');
if($str_pos===false) return '"'.$value.'"'; if($str_pos === FALSE)
{
return '"' . $value . '"';
}
$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)
{ {
@ -606,7 +685,7 @@ class XmlQueryParser extends XmlParser
$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
{ {
@ -617,7 +696,7 @@ class XmlQueryParser extends XmlParser
$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
{ {
@ -628,7 +707,7 @@ class XmlQueryParser extends XmlParser
$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
{ {
@ -639,6 +718,7 @@ class XmlQueryParser extends XmlParser
return $val; return $val;
} }
} }
/* End of file XmlQueryParser.class.php */ /* End of file XmlQueryParser.class.php */
/* Location: ./classes/xml/XmlQueryParser.class.php */ /* Location: ./classes/xml/XmlQueryParser.class.php */

View file

@ -1,7 +1,9 @@
<?php <?php
/** /**
* File containing the DBParser class * File containing the DBParser class
*/ */
/** /**
* Escapes query statements: <br /> * Escapes query statements: <br />
* - column names: member.member_srl =&gt; "member"."member_srl" <br /> * - column names: member.member_srl =&gt; "member"."member_srl" <br />
@ -13,6 +15,7 @@
*/ */
class DBParser class DBParser
{ {
/** /**
* Character for escape target value on the left * Character for escape target value on the left
* *
@ -56,11 +59,17 @@ class DBParser
* *
* @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 !== "")
else $this->escape_char_right = $escape_char_left; {
$this->escape_char_right = $escape_char_right;
}
else
{
$this->escape_char_right = $escape_char_left;
}
$this->table_prefix = $table_prefix; $this->table_prefix = $table_prefix;
} }
@ -72,8 +81,14 @@ class DBParser
*/ */
function getEscapeChar($leftOrRight) function getEscapeChar($leftOrRight)
{ {
if ($leftOrRight === 'left')return $this->escape_char_left; if($leftOrRight === 'left')
else return $this->escape_char_right; {
return $this->escape_char_left;
}
else
{
return $this->escape_char_right;
}
} }
/** /**
@ -95,7 +110,7 @@ class DBParser
*/ */
function escapeString($name) function escapeString($name)
{ {
return "'".$this->escapeStringValue($name)."'"; return "'" . $this->escapeStringValue($name) . "'";
} }
/** /**
@ -106,8 +121,14 @@ class DBParser
*/ */
function escapeStringValue($value) function escapeStringValue($value)
{ {
if($value == "*") return $value; if($value == "*")
if (is_string($value)) return $value = str_replace("'","''",$value); {
return $value;
}
if(is_string($value))
{
return $value = str_replace("'", "''", $value);
}
return $value; return $value;
} }
@ -144,12 +165,14 @@ class DBParser
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);
//return $this->escape($this->parseTableName($table)).'.'.$this->escape($column); //return $this->escape($this->parseTableName($table)).'.'.$this->escape($column);
} }
} }
@ -165,7 +188,10 @@ class DBParser
*/ */
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;
} }
@ -180,7 +206,10 @@ class DBParser
*/ */
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;
} }
@ -204,26 +233,39 @@ class DBParser
*/ */
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 == '(')
if(strpos($match,')') !== FALSE) continue; {
if(in_array($match, array(',', '.'))) continue; $brackets++;
continue;
}
if(strpos($match, ')') !== FALSE)
{
continue;
}
if(in_array($match, array(',', '.')))
{
continue;
}
if($brackets == $total_brackets) if($brackets == $total_brackets)
{ {
if(!is_numeric($match) && !in_array(strtoupper($match), array('UNSIGNED', 'INTEGER', 'AS'))) if(!is_numeric($match) && !in_array(strtoupper($match), array('UNSIGNED', 'INTEGER', 'AS')))
{ {
$match = $this->escapeColumnExpression($match); $match = $this->escapeColumnExpression($match);
} }
} }
} }
@ -240,7 +282,10 @@ class DBParser
*/ */
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;
} }
@ -253,7 +298,10 @@ class DBParser
*/ */
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;
} }
@ -264,14 +312,21 @@ class DBParser
*/ */
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 */ /* End of file DBParser.class.php */
/* Location: ./classes/xml/xmlquery/DBParser.class.php */ /* Location: ./classes/xml/xmlquery/DBParser.class.php */

View file

@ -1,7 +1,9 @@
<?php <?php
/** /**
* File containing the QueryParser class * File containing the QueryParser class
*/ */
/** /**
* Parses an XML Object and returns a string used for generating the PHP cache file <br /> * Parses an XML Object and returns a string used for generating the PHP cache file <br />
* The XML Object structure must be the one defined in the XmlParser class * The XML Object structure must be the one defined in the XmlParser class
@ -60,12 +62,14 @@ class QueryParser
else if(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]))
{
return; return;
}
$module = $id_args[1]; $module = $id_args[1];
$id = $id_args[2]; $id = $id_args[2];
} }
// 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);
@ -77,7 +81,9 @@ class QueryParser
{ {
$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;
}
} }
} }
@ -111,9 +117,10 @@ class QueryParser
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 */ /* End of file QueryParser.class.php */
/* Location: ./classes/xml/xmlquery/QueryParser.class.php */ /* Location: ./classes/xml/xmlquery/QueryParser.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Argument class * Argument class
* @author NHN (developers@xpressengine.com) * @author NHN (developers@xpressengine.com)
@ -7,40 +8,48 @@
*/ */
class Argument class Argument
{ {
/** /**
* argument value * argument value
* @var mixed * @var mixed
*/ */
var $value; var $value;
/** /**
* argument name * argument name
* @var string * @var string
*/ */
var $name; var $name;
/** /**
* argument type * argument type
* @var string * @var string
*/ */
var $type; var $type;
/** /**
* result of argument type check * result of argument type check
* @var bool * @var bool
*/ */
var $isValid; var $isValid;
/** /**
* error message * error message
* @var Object * @var Object
*/ */
var $errorMessage; var $errorMessage;
/** /**
* column operation * column operation
*/ */
var $column_operation; var $column_operation;
/** /**
* Check if arg value is user submnitted or default * Check if arg value is user submnitted or default
* @var mixed * @var mixed
*/ */
var $uses_default_value; var $uses_default_value;
/** /**
* Caches escaped and toString value so that the parsing won't happen multiple times * Caches escaped and toString value so that the parsing won't happen multiple times
* @var mixed * @var mixed
@ -53,11 +62,12 @@ 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()
@ -67,7 +77,9 @@ class Argument
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';
} }
@ -76,7 +88,7 @@ class Argument
{ {
$this->type = $value; $this->type = $value;
} }
function setColumnOperation($operation) function setColumnOperation($operation)
{ {
$this->column_operation = $operation; $this->column_operation = $operation;
@ -109,7 +121,10 @@ class Argument
function getUnescapedValue() function getUnescapedValue()
{ {
if($this->value === 'null') return null; if($this->value === 'null')
{
return null;
}
return $this->value; return $this->value;
} }
@ -123,9 +138,13 @@ class Argument
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] === '')
{
return ''; return '';
}
return '(' . implode(',', $value) . ')'; return '(' . implode(',', $value) . ')';
} }
return $value; return $value;
@ -145,27 +164,36 @@ class Argument
return $dbParser->parseExpression($value); return $dbParser->parseExpression($value);
} }
if(!isset($value)) if(!isset($value))
{
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]);
}
//$value[$i] = '\''.$value[$i].'\''; //$value[$i] = '\''.$value[$i].'\'';
} }
} }
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)) if(is_array($value))
{ {
foreach ($value AS $key => $val) foreach($value AS $key => $val)
{ {
if(isset($val) && $val !== '') if(isset($val) && $val !== '')
{ {
@ -193,7 +221,7 @@ class Argument
$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';
$value = preg_replace_callback($regex, array($this, 'utf8Replacer'), $value); $value = preg_replace_callback($regex, array($this, 'utf8Replacer'), $value);
$db = &DB::getInstance(); $db = DB::getInstance();
$value = $db->addQuotes($value); $value = $db->addQuotes($value);
return '\'' . $value . '\''; return '\'' . $value . '\'';
} }
@ -225,15 +253,24 @@ class Argument
{ {
return $this->isValid; return $this->isValid;
} }
function isColumnName() function isColumnName()
{ {
$type = $this->getType(); $type = $this->getType();
$value = $this->getUnescapedValue(); $value = $this->getUnescapedValue();
if($type == 'column_name') return true; if($type == 'column_name')
if($type == 'number' && is_null($value)) return false; {
if($type == 'number' && !is_numeric($value) && $this->uses_default_value) return true; return TRUE;
return false; }
if($type == 'number' && is_null($value))
{
return FALSE;
}
if($type == 'number' && !is_numeric($value) && $this->uses_default_value)
{
return TRUE;
}
return FALSE;
} }
function getErrorMessage() function getErrorMessage()
@ -246,7 +283,7 @@ class Argument
if(!isset($this->value) || $this->value == '') if(!isset($this->value) || $this->value == '')
{ {
$this->value = $default_value; $this->value = $default_value;
$this->uses_default_value = true; $this->uses_default_value = TRUE;
} }
} }
@ -262,20 +299,20 @@ class Argument
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;
@ -283,31 +320,33 @@ class Argument
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));
} }
break; break;
case 'number' : case 'number' :
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));
} }
break; break;
@ -320,7 +359,7 @@ class Argument
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;
$this->errorMessage = new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key)); $this->errorMessage = new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key));
} }
@ -331,7 +370,7 @@ class Argument
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;
$this->errorMessage = new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key)); $this->errorMessage = new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key));
} }
@ -342,11 +381,12 @@ class Argument
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 */ /* End of file Argument.class.php */
/* Location: ./classes/xml/xmlquery/argument/Argument.class.php */ /* Location: ./classes/xml/xmlquery/argument/Argument.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* ConditionArgument class * ConditionArgument class
* @author NHN (developers@xpressengine.com) * @author NHN (developers@xpressengine.com)
@ -7,6 +8,7 @@
*/ */
class ConditionArgument extends Argument class ConditionArgument extends Argument
{ {
/** /**
* Operator keyword. for example 'in', 'notint', 'between' * Operator keyword. for example 'in', 'notint', 'between'
* @var string * @var string
@ -22,7 +24,7 @@ class ConditionArgument extends Argument
*/ */
function ConditionArgument($name, $value, $operation) function ConditionArgument($name, $value, $operation)
{ {
$operationList = array('in'=>1, 'notin'=>1, 'not_in'=>1, 'between'=>1); $operationList = array('in' => 1, 'notin' => 1, 'not_in' => 1, 'between' => 1);
if(isset($value) && isset($operationList[$operation]) && !is_array($value) && $value != '') if(isset($value) && isset($operationList[$operation]) && !is_array($value) && $value != '')
{ {
$value = str_replace(' ', '', $value); $value = str_replace(' ', '', $value);
@ -39,7 +41,10 @@ class ConditionArgument extends Argument
*/ */
function createConditionValue() function createConditionValue()
{ {
if(!isset($this->value)) return; if(!isset($this->value))
{
return;
}
$operation = $this->operation; $operation = $this->operation;
$value = $this->value; $value = $this->value;
@ -52,13 +57,19 @@ class ConditionArgument extends Argument
$this->value = '^' . str_replace('%', '(.*)', preg_quote($value)); $this->value = '^' . str_replace('%', '(.*)', preg_quote($value));
} }
else else
$this->value = $value.'%'; {
$this->value = $value . '%';
}
break; break;
case 'like_tail' : case 'like_tail' :
if(defined('__CUBRID_VERSION__') && __CUBRID_VERSION__ >= '8.4.1') if(defined('__CUBRID_VERSION__') && __CUBRID_VERSION__ >= '8.4.1')
{
$this->value = str_replace('%', '(.*)', preg_quote($value)) . '$'; $this->value = str_replace('%', '(.*)', preg_quote($value)) . '$';
else }
$this->value = '%'.$value; else
{
$this->value = '%' . $value;
}
break; break;
case 'like' : case 'like' :
if(defined('__CUBRID_VERSION__') && __CUBRID_VERSION__ >= '8.4.1') if(defined('__CUBRID_VERSION__') && __CUBRID_VERSION__ >= '8.4.1')
@ -66,23 +77,31 @@ class ConditionArgument extends Argument
$this->value = str_replace('%', '(.*)', preg_quote($value)); $this->value = str_replace('%', '(.*)', preg_quote($value));
} }
else else
$this->value = '%'.$value.'%'; {
$this->value = '%' . $value . '%';
}
break; break;
case 'notlike' : case 'notlike' :
$this->value = '%'.$value.'%'; $this->value = '%' . $value . '%';
break; break;
case 'notlike_prefix' : case 'notlike_prefix' :
$this->value = $value.'%'; $this->value = $value . '%';
break; break;
case 'notlike_tail' : case 'notlike_tail' :
$this->value = '%'.$value; $this->value = '%' . $value;
break; break;
case 'in': case 'in':
if(!is_array($value)) $this->value = array($value); if(!is_array($value))
{
$this->value = array($value);
}
break; break;
case 'notin': case 'notin':
case 'not_in': case 'not_in':
if(!is_array($value)) $this->value = array($value); if(!is_array($value))
{
$this->value = array($value);
}
break; break;
} }
} }
@ -101,14 +120,14 @@ class ConditionArgument extends Argument
function getType() function getType()
{ {
if($this->type) if($this->type)
{ {
return $this->type; return $this->type;
} }
else if(!is_numeric($this->value)) else if(!is_numeric($this->value))
{ {
return 'varchar'; return 'varchar';
} }
else else
{ {
return ''; return '';
} }
@ -116,8 +135,14 @@ class ConditionArgument extends Argument
function setColumnType($column_type) function setColumnType($column_type)
{ {
if(!isset($this->value)) return; if(!isset($this->value))
if($column_type === '') return; {
return;
}
if($column_type === '')
{
return;
}
$this->type = $column_type; $this->type = $column_type;
} }

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* SortArgument class * SortArgument class
* @author NHN (developers@xpressengine.com) * @author NHN (developers@xpressengine.com)
@ -7,10 +8,12 @@
*/ */
class SortArgument extends Argument class SortArgument extends Argument
{ {
function getValue() function getValue()
{ {
return $this->getUnescapedValue(); return $this->getUnescapedValue();
} }
} }
/* End of file SortArgument.class.php */ /* End of file SortArgument.class.php */
/* Location: ./classes/xml/xmlquery/argument/SortArgument.class.php */ /* Location: ./classes/xml/xmlquery/argument/SortArgument.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* DefaultValue class * DefaultValue class
* @author NHN (developers@xpressengine.com) * @author NHN (developers@xpressengine.com)
@ -7,41 +8,48 @@
*/ */
class DefaultValue class DefaultValue
{ {
/** /**
* Column name * Column name
* @var string * @var string
*/ */
var $column_name; var $column_name;
/** /**
* Value * Value
* @var mixed * @var mixed
*/ */
var $value; var $value;
/** /**
* sequnence status * sequnence status
* @var bool * @var bool
*/ */
var $is_sequence = false; var $is_sequence = FALSE;
/** /**
* operation status * operation status
* @var bool * @var bool
*/ */
var $is_operation = false; var $is_operation = FALSE;
/** /**
* operation * operation
* @var string * @var string
*/ */
var $operation = ''; var $operation = '';
/** /**
* Checks if value is plain string or name of XE function (ipaddress, plus, etc). * Checks if value is plain string or name of XE function (ipaddress, plus, etc).
* @var bool * @var bool
*/ */
var $_is_string = false; var $_is_string = FALSE;
/** /**
* Checks if value is string resulted from evaluating a piece of PHP code (see $_SERVER[REMOTE_ADDR]) * Checks if value is string resulted from evaluating a piece of PHP code (see $_SERVER[REMOTE_ADDR])
* @var bool * @var bool
*/ */
var $_is_string_from_function = false; var $_is_string_from_function = FALSE;
/** /**
* constructor * constructor
@ -51,7 +59,7 @@ class DefaultValue
*/ */
function DefaultValue($column_name, $value) function DefaultValue($column_name, $value)
{ {
$dbParser = &DB::getParser(); $dbParser = DB::getParser();
$this->column_name = $dbParser->parseColumnName($column_name); $this->column_name = $dbParser->parseColumnName($column_name);
$this->value = $value; $this->value = $value;
$this->value = $this->_setValue(); $this->value = $this->_setValue();
@ -61,8 +69,11 @@ class DefaultValue
{ {
return $this->_is_string; return $this->_is_string;
$str_pos = strpos($this->value, '('); $str_pos = strpos($this->value, '(');
if($str_pos===false) return true; if($str_pos === false)
return false; {
return TRUE;
}
return FALSE;
} }
function isStringFromFunction() function isStringFromFunction()
@ -87,65 +98,68 @@ class DefaultValue
function _setValue() function _setValue()
{ {
if(!isset($this->value)) return; if(!isset($this->value))
{
return;
}
// If value contains comma separated values and does not contain paranthesis // If value contains comma separated values and does not contain paranthesis
// -> default value is an array // -> default value is an array
if(strpos($this->value, ',') !== false && strpos($this->value, '(') === false) if(strpos($this->value, ',') !== FALSE && strpos($this->value, '(') === FALSE)
{ {
return sprintf('array(%s)', $this->value); return sprintf('array(%s)', $this->value);
} }
$str_pos = strpos($this->value, '('); $str_pos = strpos($this->value, '(');
// // TODO Replace this with parseExpression // // TODO Replace this with parseExpression
if($str_pos===false) if($str_pos === FALSE)
{ {
$this->_is_string = true; $this->_is_string = TRUE;
return '\''.$this->value.'\''; return '\'' . $this->value . '\'';
} }
//if($str_pos===false) return $this->value; //if($str_pos===false) return $this->value;
$func_name = substr($this->value, 0, $str_pos); $func_name = substr($this->value, 0, $str_pos);
$args = substr($this->value, $str_pos+1, -1); $args = substr($this->value, $str_pos + 1, -1);
switch($func_name) switch($func_name)
{ {
case 'ipaddress' : case 'ipaddress' :
$val = '$_SERVER[\'REMOTE_ADDR\']'; $val = '$_SERVER[\'REMOTE_ADDR\']';
$this->_is_string_from_function = true; $this->_is_string_from_function = TRUE;
break; break;
case 'unixtime' : case 'unixtime' :
$val = 'time()'; $val = 'time()';
break; break;
case 'curdate' : case 'curdate' :
$val = 'date("YmdHis")'; $val = 'date("YmdHis")';
$this->_is_string_from_function = true; $this->_is_string_from_function = TRUE;
break; break;
case 'sequence' : case 'sequence' :
$this->is_sequence = true; $this->is_sequence = TRUE;
$val = '$sequence'; $val = '$sequence';
break; break;
case 'plus' : case 'plus' :
$args = abs($args); $args = abs($args);
$this->is_operation = true; $this->is_operation = TRUE;
$this->operation = '+'; $this->operation = '+';
$val = sprintf('%d', $args); $val = sprintf('%d', $args);
break; break;
case 'minus' : case 'minus' :
$args = abs($args); $args = abs($args);
$this->is_operation = true; $this->is_operation = TRUE;
$this->operation = '-'; $this->operation = '-';
$val = sprintf('%d', $args); $val = sprintf('%d', $args);
break; break;
case 'multiply' : case 'multiply' :
$args = intval($args); $args = intval($args);
$this->is_operation = true; $this->is_operation = TRUE;
$this->operation = '*'; $this->operation = '*';
$val = sprintf('%d', $args); $val = sprintf('%d', $args);
break; break;
default : default :
$val = '\'' . $this->value . '\''; $val = '\'' . $this->value . '\'';
//$val = $this->value; //$val = $this->value;
} }
return $val; return $val;
@ -155,6 +169,7 @@ class DefaultValue
{ {
return $this->value; return $this->value;
} }
} }
/* End of file DefaultValue.class.php */ /* End of file DefaultValue.class.php */
/* Location: ./classes/xml/xmlquery/queryargument/DefaultValue.class.php */ /* Location: ./classes/xml/xmlquery/queryargument/DefaultValue.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* QueryArgument class * QueryArgument class
* @author NHN (developers@xpressengine.com) * @author NHN (developers@xpressengine.com)
@ -7,36 +8,43 @@
*/ */
class QueryArgument class QueryArgument
{ {
/** /**
* Argument name * Argument name
* @var string * @var string
*/ */
var $argument_name; var $argument_name;
/** /**
* Variable name * Variable name
* @var string * @var string
*/ */
var $variable_name; var $variable_name;
/** /**
* Argument validator * Argument validator
* @var QueryArgumentValidator * @var QueryArgumentValidator
*/ */
var $argument_validator; var $argument_validator;
/** /**
* Column name * Column name
* @var string * @var string
*/ */
var $column_name; var $column_name;
/** /**
* Table name * Table name
* @var string * @var string
*/ */
var $table_name; var $table_name;
/** /**
* Operation * Operation
* @var string * @var string
*/ */
var $operation; var $operation;
/** /**
* Ignore value * Ignore value
* @var bool * @var bool
@ -49,15 +57,19 @@ class QueryArgument
* @param bool $ignore_value * @param bool $ignore_value
* @return void * @return void
*/ */
function QueryArgument($tag, $ignore_value = false) function QueryArgument($tag, $ignore_value = FALSE)
{ {
static $number_of_arguments = 0; static $number_of_arguments = 0;
$this->argument_name = $tag->attrs->var; $this->argument_name = $tag->attrs->var;
if(!$this->argument_name) if(!$this->argument_name)
{
$this->argument_name = str_replace('.', '_', $tag->attrs->name); $this->argument_name = str_replace('.', '_', $tag->attrs->name);
}
if(!$this->argument_name) if(!$this->argument_name)
{
$this->argument_name = str_replace('.', '_', $tag->attrs->column); $this->argument_name = str_replace('.', '_', $tag->attrs->column);
}
$this->variable_name = $this->argument_name; $this->variable_name = $this->argument_name;
@ -66,9 +78,13 @@ class QueryArgument
$name = $tag->attrs->name; $name = $tag->attrs->name;
if(!$name) if(!$name)
{
$name = $tag->attrs->column; $name = $tag->attrs->column;
if(strpos($name, '.') === false) }
if(strpos($name, '.') === FALSE)
{
$this->column_name = $name; $this->column_name = $name;
}
else else
{ {
list($prefix, $name) = explode('.', $name); list($prefix, $name) = explode('.', $name);
@ -77,7 +93,9 @@ class QueryArgument
} }
if($tag->attrs->operation) if($tag->attrs->operation)
{
$this->operation = $tag->attrs->operation; $this->operation = $tag->attrs->operation;
}
$this->argument_validator = new QueryArgumentValidator($tag, $this); $this->argument_validator = new QueryArgumentValidator($tag, $this);
$this->ignore_value = $ignore_value; $this->ignore_value = $ignore_value;
@ -106,8 +124,10 @@ class QueryArgument
function isConditionArgument() function isConditionArgument()
{ {
if($this->operation) if($this->operation)
return true; {
return false; return TRUE;
}
return FALSE;
} }
/** /**
@ -120,50 +140,51 @@ class QueryArgument
{ {
// Instantiation // Instantiation
$arg = sprintf("\n" . '${\'%s_argument\'} = new ConditionArgument(\'%s\', %s, \'%s\');' . "\n" $arg = sprintf("\n" . '${\'%s_argument\'} = new ConditionArgument(\'%s\', %s, \'%s\');' . "\n"
, $this->argument_name , $this->argument_name
, $this->variable_name , $this->variable_name
, '$args->' . $this->variable_name , '$args->' . $this->variable_name
, $this->operation , $this->operation
); );
// Call methods to validate argument and ensure default value // Call methods to validate argument and ensure default value
$arg .= $this->argument_validator->toString(); $arg .= $this->argument_validator->toString();
// Prepare condition string // Prepare condition string
$arg .= sprintf('${\'%s_argument\'}->createConditionValue();' . "\n" $arg .= sprintf('${\'%s_argument\'}->createConditionValue();' . "\n"
, $this->argument_name , $this->argument_name
); );
// Check that argument passed validation, else return // Check that argument passed validation, else return
$arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n" $arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n"
, $this->argument_name , $this->argument_name
, $this->argument_name , $this->argument_name
); );
} }
else else
{ {
$arg = sprintf("\n" . '${\'%s_argument\'} = new Argument(\'%s\', %s);' . "\n" $arg = sprintf("\n" . '${\'%s_argument\'} = new Argument(\'%s\', %s);' . "\n"
, $this->argument_name , $this->argument_name
, $this->variable_name , $this->variable_name
, $this->ignore_value ? 'null' : '$args->{\'' . $this->variable_name . '\'}'); , $this->ignore_value ? 'NULL' : '$args->{\'' . $this->variable_name . '\'}');
$arg .= $this->argument_validator->toString(); $arg .= $this->argument_validator->toString();
$arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n" $arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n"
, $this->argument_name , $this->argument_name
, $this->argument_name , $this->argument_name
); );
} }
// If the argument is null, skip it // If the argument is null, skip it
if($this->argument_validator->isIgnorable()) if($this->argument_validator->isIgnorable())
{ {
$arg = sprintf("if(isset(%s)) {", '$args->' . $this->variable_name) $arg = sprintf("if(isset(%s)) {", '$args->' . $this->variable_name)
. $arg . $arg
. sprintf("} else\n" . '${\'%s_argument\'} = null;', $this->argument_name); . sprintf("} else\n" . '${\'%s_argument\'} = NULL;', $this->argument_name);
} }
return $arg; return $arg;
} }
} }
/* End of file QueryArgument.class.php */ /* End of file QueryArgument.class.php */
/* Location: ./classes/xml/xmlquery/queryargument/QueryArgument.class.php */ /* Location: ./classes/xml/xmlquery/queryargument/QueryArgument.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* SortQueryArgument class * SortQueryArgument class
* @author NHN (developers@xpressengine.com) * @author NHN (developers@xpressengine.com)
@ -7,6 +8,7 @@
*/ */
class SortQueryArgument extends QueryArgument class SortQueryArgument extends QueryArgument
{ {
/** /**
* Change SortQueryArgument object to string * Change SortQueryArgument object to string
* @return string * @return string
@ -14,17 +16,18 @@ class SortQueryArgument extends QueryArgument
function toString() function toString()
{ {
$arg = sprintf("\n" . '${\'%s_argument\'} = new SortArgument(\'%s\', %s);' . "\n" $arg = sprintf("\n" . '${\'%s_argument\'} = new SortArgument(\'%s\', %s);' . "\n"
, $this->argument_name , $this->argument_name
, $this->argument_name , $this->argument_name
, '$args->'.$this->variable_name); , '$args->' . $this->variable_name);
$arg .= $this->argument_validator->toString(); $arg .= $this->argument_validator->toString();
$arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n" $arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n"
, $this->argument_name , $this->argument_name
, $this->argument_name , $this->argument_name
); );
return $arg; return $arg;
} }
} }
/* End of file DefaultValue.class.php */ /* End of file DefaultValue.class.php */
/* Location: ./classes/xml/xmlquery/queryargument/DefaultValue.class.php */ /* Location: ./classes/xml/xmlquery/queryargument/DefaultValue.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* QueryArgumentValidator class * QueryArgumentValidator class
* @author NHN (developers@xpressengine.com) * @author NHN (developers@xpressengine.com)
@ -7,37 +8,42 @@
*/ */
class QueryArgumentValidator class QueryArgumentValidator
{ {
/** /**
* Argument name * Argument name
* @var string * @var string
*/ */
var $argument_name; var $argument_name;
/** /**
* Default value * Default value
* @var string * @var string
*/ */
var $default_value; var $default_value;
/** /**
* Notnull status setting, if value should be not null, this value is 'notnull' * Notnull status setting, if value should be not null, this value is 'notnull'
* @var string * @var string
*/ */
var $notnull; var $notnull;
/** /**
* Filter for value type, for example number * Filter for value type, for example number
* @var string * @var string
*/ */
var $filter; var $filter;
/** /**
* Minimum length for value * Minimum length for value
* @var int * @var int
*/ */
var $min_length; var $min_length;
/** /**
* Maximum length for value * Maximum length for value
* @var int * @var int
*/ */
var $max_length; var $max_length;
var $validator_string; var $validator_string;
/** /**
@ -66,8 +72,11 @@ class QueryArgumentValidator
function isIgnorable() function isIgnorable()
{ {
if(isset($this->default_value) || isset($this->notnull)) return false; if(isset($this->default_value) || isset($this->notnull))
return true; {
return FALSE;
}
return TRUE;
} }
function toString() function toString()
@ -76,50 +85,50 @@ class QueryArgumentValidator
if($this->filter) if($this->filter)
{ {
$validator .= sprintf('${\'%s_argument\'}->checkFilter(\'%s\');' . "\n" $validator .= sprintf('${\'%s_argument\'}->checkFilter(\'%s\');' . "\n"
, $this->argument_name , $this->argument_name
, $this->filter , $this->filter
); );
} }
if($this->min_length) if($this->min_length)
{ {
$validator .= sprintf('${\'%s_argument\'}->checkMinLength(%s);' . "\n" $validator .= sprintf('${\'%s_argument\'}->checkMinLength(%s);' . "\n"
, $this->argument_name , $this->argument_name
, $this->min_length , $this->min_length
); );
} }
if($this->max_length) if($this->max_length)
{ {
$validator .= sprintf('${\'%s_argument\'}->checkMaxLength(%s);'. "\n" $validator .= sprintf('${\'%s_argument\'}->checkMaxLength(%s);' . "\n"
, $this->argument_name , $this->argument_name
, $this->max_length , $this->max_length
); );
} }
if(isset($this->default_value)) if(isset($this->default_value))
{ {
$this->default_value = new DefaultValue($this->argument_name, $this->default_value); $this->default_value = new DefaultValue($this->argument_name, $this->default_value);
if($this->default_value->isSequence()) if($this->default_value->isSequence())
$validator .= '$db = &DB::getInstance(); $sequence = $db->getNextSequence(); '; $validator .= '$db = DB::getInstance(); $sequence = $db->getNextSequence(); ';
if($this->default_value->isOperation()) if($this->default_value->isOperation())
{ {
$validator .= sprintf('${\'%s_argument\'}->setColumnOperation(\'%s\');' . "\n" $validator .= sprintf('${\'%s_argument\'}->setColumnOperation(\'%s\');' . "\n"
, $this->argument_name , $this->argument_name
, $this->default_value->getOperation() , $this->default_value->getOperation()
); );
} }
$validator .= sprintf('${\'%s_argument\'}->ensureDefaultValue(%s);' . "\n" $validator .= sprintf('${\'%s_argument\'}->ensureDefaultValue(%s);' . "\n"
, $this->argument_name , $this->argument_name
, $this->default_value->toString() , $this->default_value->toString()
); );
} }
if($this->notnull) if($this->notnull)
{ {
$validator .= sprintf('${\'%s_argument\'}->checkNotNull();' . "\n" $validator .= sprintf('${\'%s_argument\'}->checkNotNull();' . "\n"
, $this->argument_name , $this->argument_name
); );
} }
return $validator; return $validator;
} }
}
}
/* End of file QueryArgumentValidator.class.php */ /* End of file QueryArgumentValidator.class.php */
/* Location: ./classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php */ /* Location: ./classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Models the &lt;column&gt; tag inside an XML Query file <br /> * Models the &lt;column&gt; tag inside an XML Query file <br />
* Since the &lt;column&gt; tag supports different attributes depending on * Since the &lt;column&gt; tag supports different attributes depending on
@ -11,6 +12,7 @@
*/ */
class ColumnTag class ColumnTag
{ {
/** /**
* Column name * Column name
* @var string * @var string
@ -26,6 +28,7 @@ class ColumnTag
{ {
$this->name = $name; $this->name = $name;
} }
} }
/* End of file ColumnTag.class.php */ /* End of file ColumnTag.class.php */
/* Location: ./classes/xml/xmlquery/tags/column/ColumnTag.class.php */ /* Location: ./classes/xml/xmlquery/tags/column/ColumnTag.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Models the &lt;column&gt; tag inside an XML Query file whose action is 'insert' * Models the &lt;column&gt; tag inside an XML Query file whose action is 'insert'
* *
@ -8,6 +9,7 @@
*/ */
class InsertColumnTag extends ColumnTag class InsertColumnTag extends ColumnTag
{ {
/** /**
* Argument * Argument
* *
@ -40,8 +42,8 @@ class InsertColumnTag extends ColumnTag
function getExpressionString() function getExpressionString()
{ {
return sprintf('new InsertExpression(\'%s\', ${\'%s_argument\'})' return sprintf('new InsertExpression(\'%s\', ${\'%s_argument\'})'
, $this->name , $this->name
, $this->argument->argument_name); , $this->argument->argument_name);
} }
/** /**

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Models the &lt;column&gt; tag inside an XML Query file whose action is 'insert-select' * Models the &lt;column&gt; tag inside an XML Query file whose action is 'insert-select'
* *
@ -8,6 +9,7 @@
*/ */
class InsertColumnTagWithoutArgument extends ColumnTag class InsertColumnTagWithoutArgument extends ColumnTag
{ {
/** /**
* Constructor * Constructor
* *

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Models the &lt;columns&gt; tag inside an XML Query file whose action is 'insert' * Models the &lt;columns&gt; tag inside an XML Query file whose action is 'insert'
* *
@ -8,6 +9,7 @@
*/ */
class InsertColumnsTag class InsertColumnsTag
{ {
/** /**
* Column list * Column list
* *
@ -26,15 +28,29 @@ class InsertColumnsTag
$this->columns = array(); $this->columns = array();
if(!$xml_columns) if(!$xml_columns)
{
return; return;
}
if(!is_array($xml_columns)) $xml_columns = array($xml_columns); if(!is_array($xml_columns))
{
$xml_columns = array($xml_columns);
}
foreach($xml_columns as $column) foreach($xml_columns as $column)
{ {
if($column->name === 'query') $this->columns[] = new QueryTag($column, true); if($column->name === 'query')
else if(!isset($column->attrs->var) && !isset($column->attrs->default)) $this->columns[] = new InsertColumnTagWithoutArgument($column); {
else $this->columns[] = new InsertColumnTag($column); $this->columns[] = new QueryTag($column, TRUE);
}
else if(!isset($column->attrs->var) && !isset($column->attrs->default))
{
$this->columns[] = new InsertColumnTagWithoutArgument($column);
}
else
{
$this->columns[] = new InsertColumnTag($column);
}
} }
} }

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Models the &lt;column&gt; tag inside an XML Query file whose action is 'select' * Models the &lt;column&gt; tag inside an XML Query file whose action is 'select'
* *
@ -8,6 +9,7 @@
*/ */
class SelectColumnTag extends ColumnTag class SelectColumnTag extends ColumnTag
{ {
/** /**
* Column alias * Column alias
* *
@ -30,7 +32,7 @@ class SelectColumnTag extends ColumnTag
*/ */
function SelectColumnTag($column) function SelectColumnTag($column)
{ {
if ($column == "*" || $column->attrs->name == '*') if($column == "*" || $column->attrs->name == '*')
{ {
parent::ColumnTag(NULL); parent::ColumnTag(NULL);
$this->name = "*"; $this->name = "*";
@ -38,7 +40,7 @@ class SelectColumnTag extends ColumnTag
else else
{ {
parent::ColumnTag($column->attrs->name); parent::ColumnTag($column->attrs->name);
$dbParser = new DB(); $dbParser = &$dbParser->getParser(); $dbParser = DB::getParser();
$this->name = $dbParser->parseExpression($this->name); $this->name = $dbParser->parseExpression($this->name);
$this->alias = $column->attrs->alias; $this->alias = $column->attrs->alias;
@ -60,14 +62,22 @@ class SelectColumnTag extends ColumnTag
*/ */
function getExpressionString() function getExpressionString()
{ {
if($this->name == '*') return "new StarExpression()"; if($this->name == '*')
{
return "new StarExpression()";
}
if($this->click_count) if($this->click_count)
return sprintf('new ClickCountExpression(\'%s\', %s, $args->%s)', $this->name, $this->alias ? '\'' . $this->alias . '\'' : "''",$this->click_count); {
return sprintf('new ClickCountExpression(\'%s\', %s, $args->%s)', $this->name, $this->alias ? '\'' . $this->alias . '\'' : "''", $this->click_count);
}
if(strpos($this->name, '$') === 0) if(strpos($this->name, '$') === 0)
{
return sprintf('new SelectExpression($args->%s)', substr($this->name, 1)); return sprintf('new SelectExpression($args->%s)', substr($this->name, 1));
}
$dbParser = DB::getParser(); $dbParser = DB::getParser();
return sprintf('new SelectExpression(\'%s\'%s)', $this->name, $this->alias ? ', \''.$dbParser->escape($this->alias) .'\'': ''); return sprintf('new SelectExpression(\'%s\'%s)', $this->name, $this->alias ? ', \'' . $dbParser->escape($this->alias) . '\'' : '');
} }
} }
/* End of file SelectColumnTag.class.php */ /* End of file SelectColumnTag.class.php */
/* Location: ./classes/xml/xmlquery/tags/column/SelectColumnTag.class.php */ /* Location: ./classes/xml/xmlquery/tags/column/SelectColumnTag.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Models the &lt;columns&gt; tag inside an XML Query file whose action is 'select' * Models the &lt;columns&gt; tag inside an XML Query file whose action is 'select'
* *
@ -8,6 +9,7 @@
*/ */
class SelectColumnsTag class SelectColumnsTag
{ {
/** /**
* Column list * Column list
* *
@ -24,8 +26,10 @@ class SelectColumnsTag
*/ */
function SelectColumnsTag($xml_columns_tag) function SelectColumnsTag($xml_columns_tag)
{ {
if (!$xml_columns_tag) if(!$xml_columns_tag)
{
$xml_columns_tag = new Xml_Node_(); $xml_columns_tag = new Xml_Node_();
}
$xml_columns = $xml_columns_tag->column; $xml_columns = $xml_columns_tag->column;
$xml_queries = $xml_columns_tag->query; $xml_queries = $xml_columns_tag->query;
@ -38,7 +42,10 @@ class SelectColumnsTag
return; return;
} }
if(!is_array($xml_columns)) $xml_columns = array($xml_columns); if(!is_array($xml_columns))
{
$xml_columns = array($xml_columns);
}
foreach($xml_columns as $column) foreach($xml_columns as $column)
{ {
@ -51,7 +58,10 @@ class SelectColumnsTag
return; return;
} }
if(!is_array($xml_queries)) $xml_queries = array($xml_queries); if(!is_array($xml_queries))
{
$xml_queries = array($xml_queries);
}
foreach($xml_queries as $column) foreach($xml_queries as $column)
{ {
@ -70,9 +80,13 @@ class SelectColumnsTag
foreach($this->columns as $column) foreach($this->columns as $column)
{ {
if(is_a($column, 'QueryTag')) if(is_a($column, 'QueryTag'))
{
$output_columns .= $column->toString() . PHP_EOL . ','; $output_columns .= $column->toString() . PHP_EOL . ',';
}
else else
{
$output_columns .= $column->getExpressionString() . PHP_EOL . ','; $output_columns .= $column->getExpressionString() . PHP_EOL . ',';
}
} }
$output_columns = substr($output_columns, 0, -1); $output_columns = substr($output_columns, 0, -1);
$output_columns .= ')'; $output_columns .= ')';
@ -90,10 +104,13 @@ class SelectColumnsTag
foreach($this->columns as $column) foreach($this->columns as $column)
{ {
if(is_a($column, 'QueryTag')) if(is_a($column, 'QueryTag'))
{
$arguments = array_merge($arguments, $column->getArguments()); $arguments = array_merge($arguments, $column->getArguments());
}
} }
return $arguments; return $arguments;
} }
} }
/* End of file SelectColumnsTag.class.php */ /* End of file SelectColumnsTag.class.php */
/* Location: ./classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php */ /* Location: ./classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Models the &lt;column&gt; tag inside an XML Query file whose action is 'update' * Models the &lt;column&gt; tag inside an XML Query file whose action is 'update'
* *
@ -8,6 +9,7 @@
*/ */
class UpdateColumnTag extends ColumnTag class UpdateColumnTag extends ColumnTag
{ {
/** /**
* Argument * Argument
* *
@ -36,7 +38,9 @@ class UpdateColumnTag extends ColumnTag
$this->name = $dbParser->parseColumnName($this->name); $this->name = $dbParser->parseColumnName($this->name);
if($column->attrs->var) if($column->attrs->var)
{
$this->argument = new QueryArgument($column); $this->argument = new QueryArgument($column);
}
else else
{ {
if(strpos($column->attrs->default, '.') !== FALSE) if(strpos($column->attrs->default, '.') !== FALSE)
@ -77,14 +81,14 @@ class UpdateColumnTag extends ColumnTag
if($this->argument) if($this->argument)
{ {
return sprintf('new UpdateExpression(\'%s\', ${\'%s_argument\'})' return sprintf('new UpdateExpression(\'%s\', ${\'%s_argument\'})'
, $this->name , $this->name
, $this->argument->argument_name); , $this->argument->argument_name);
} }
else else
{ {
return sprintf('new UpdateExpressionWithoutArgument(\'%s\', %s)' return sprintf('new UpdateExpressionWithoutArgument(\'%s\', %s)'
, $this->name , $this->name
, $this->default_value); , $this->default_value);
} }
} }
@ -97,6 +101,7 @@ class UpdateColumnTag extends ColumnTag
{ {
return $this->argument; return $this->argument;
} }
} }
/* End of file UpdateColumnTag.class.php */ /* End of file UpdateColumnTag.class.php */
/* Location: ./classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php */ /* Location: ./classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Models the &lt;columns&gt; tag inside an XML Query file whose action is 'update' * Models the &lt;columns&gt; tag inside an XML Query file whose action is 'update'
* *
@ -8,6 +9,7 @@
*/ */
class UpdateColumnsTag class UpdateColumnsTag
{ {
/** /**
* Column list * Column list
* *
@ -25,12 +27,21 @@ class UpdateColumnsTag
{ {
$this->columns = array(); $this->columns = array();
if(!is_array($xml_columns)) $xml_columns = array($xml_columns); if(!is_array($xml_columns))
{
$xml_columns = array($xml_columns);
}
foreach($xml_columns as $column) foreach($xml_columns as $column)
{ {
if($column->name === 'query') $this->columns[] = new QueryTag($column, true); if($column->name === 'query')
else $this->columns[] = new UpdateColumnTag($column); {
$this->columns[] = new QueryTag($column, true);
}
else
{
$this->columns[] = new UpdateColumnTag($column);
}
} }
} }
@ -65,6 +76,7 @@ class UpdateColumnsTag
} }
return $arguments; return $arguments;
} }
} }
/* End of file UpdateColumnsTag.class.php */ /* End of file UpdateColumnsTag.class.php */
/* Location: ./classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php */ /* Location: ./classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* ConditionGroupTag class * ConditionGroupTag class
* *
@ -8,11 +9,13 @@
*/ */
class ConditionGroupTag class ConditionGroupTag
{ {
/** /**
* condition list * condition list
* @var string|array value is ConditionTag object * @var string|array value is ConditionTag object
*/ */
var $conditions; var $conditions;
/** /**
* pipe * pipe
* @var string * @var string
@ -29,7 +32,10 @@ class ConditionGroupTag
{ {
$this->pipe = $pipe; $this->pipe = $pipe;
if(!is_array($conditions)) $conditions = array($conditions); if(!is_array($conditions))
{
$conditions = array($conditions);
}
foreach($conditions as $condition) foreach($conditions as $condition)
{ {
@ -49,15 +55,15 @@ class ConditionGroupTag
*/ */
function getConditionGroupString() function getConditionGroupString()
{ {
$conditions_string = 'array('.PHP_EOL; $conditions_string = 'array(' . PHP_EOL;
foreach($this->conditions as $condition) foreach($this->conditions as $condition)
{ {
$conditions_string .= $condition->getConditionString() . PHP_EOL . ','; $conditions_string .= $condition->getConditionString() . PHP_EOL . ',';
} }
$conditions_string = substr($conditions_string, 0, -2);//remove ',' $conditions_string = substr($conditions_string, 0, -2); //remove ','
$conditions_string .= ')'; $conditions_string .= ')';
return sprintf("new ConditionGroup(%s%s)", $conditions_string, $this->pipe ? ',\''.$this->pipe . '\'': ''); return sprintf("new ConditionGroup(%s%s)", $conditions_string, $this->pipe ? ',\'' . $this->pipe . '\'' : '');
} }
function getArguments() function getArguments()
@ -69,6 +75,7 @@ class ConditionGroupTag
} }
return $arguments; return $arguments;
} }
} }
/* End of file ConditionGroupTag.class.php */ /* End of file ConditionGroupTag.class.php */
/* Location: ./classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php */ /* Location: ./classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* ConditionTag * ConditionTag
* Models the <condition> tag inside an XML Query file. Base class. * Models the <condition> tag inside an XML Query file. Base class.
@ -9,36 +10,43 @@
*/ */
class ConditionTag class ConditionTag
{ {
/** /**
* operation for example 'in', 'between', 'not in'... * operation for example 'in', 'between', 'not in'...
* @var string * @var string
*/ */
var $operation; var $operation;
/** /**
* Column name * Column name
* @var string * @var string
*/ */
var $column_name; var $column_name;
/** /**
* Pipe * Pipe
* @var string * @var string
*/ */
var $pipe; var $pipe;
/** /**
* Argument name * Argument name
* @var string * @var string
*/ */
var $argument_name; var $argument_name;
/** /**
* QueryArgument object * QueryArgument object
* @var QueryArgument * @var QueryArgument
*/ */
var $argument; var $argument;
/** /**
* Default column * Default column
* @var string * @var string
*/ */
var $default_column; var $default_column;
/** /**
* QueryTag object * QueryTag object
* @var QueryTag * @var QueryTag
@ -58,9 +66,9 @@ class ConditionTag
$this->column_name = $dbParser->parseExpression($condition->attrs->column); $this->column_name = $dbParser->parseExpression($condition->attrs->column);
// If default value is column name, it should be escaped // If default value is column name, it should be escaped
if($isColumnName = (strpos($condition->attrs->default, '.') !== false if($isColumnName = (strpos($condition->attrs->default, '.') !== FALSE
&& strpos($condition->attrs->default, '.') !== 0 && strpos($condition->attrs->default, '.') !== 0
&& strpos($condition->attrs->default, '%') === false )) && strpos($condition->attrs->default, '%') === FALSE ))
{ {
$condition->attrs->default = $dbParser->parseExpression($condition->attrs->default); $condition->attrs->default = $dbParser->parseExpression($condition->attrs->default);
} }
@ -84,7 +92,9 @@ class ConditionTag
{ {
$default_value = $condition->attrs->default; $default_value = $condition->attrs->default;
if(strpos($default_value, "'") !== FALSE) if(strpos($default_value, "'") !== FALSE)
{
$default_value = "\"" . $default_value . "\""; $default_value = "\"" . $default_value . "\"";
}
else else
{ {
$default_value = "'" . $default_value . "'"; $default_value = "'" . $default_value . "'";
@ -103,15 +113,21 @@ class ConditionTag
if($default_value_object->isString() && !$isColumnName && !is_numeric($condition->attrs->default)) if($default_value_object->isString() && !$isColumnName && !is_numeric($condition->attrs->default))
{ {
if(strpos($default_value, "'") !== FALSE) if(strpos($default_value, "'") !== FALSE)
{
$default_value = "\"" . $default_value . "\""; $default_value = "\"" . $default_value . "\"";
}
else else
{
$default_value = "'" . $default_value . "'"; $default_value = "'" . $default_value . "'";
}
} }
} }
$this->default_column = $default_value; $this->default_column = $default_value;
} }
else else
{
$this->default_column = "'" . $dbParser->parseColumnName($condition->attrs->var) . "'"; $this->default_column = "'" . $dbParser->parseColumnName($condition->attrs->var) . "'";
}
} }
} }
@ -124,9 +140,13 @@ class ConditionTag
{ {
$arguments = array(); $arguments = array();
if($this->query) if($this->query)
{
$arguments = array_merge($arguments, $this->query->getArguments()); $arguments = array_merge($arguments, $this->query->getArguments());
}
if($this->argument) if($this->argument)
{
$arguments[] = $this->argument; $arguments[] = $this->argument;
}
return $arguments; return $arguments;
} }
@ -135,31 +155,32 @@ class ConditionTag
if($this->query) if($this->query)
{ {
return sprintf("new ConditionSubquery('%s',%s,%s%s)" return sprintf("new ConditionSubquery('%s',%s,%s%s)"
, $this->column_name , $this->column_name
, $this->default_column , $this->default_column
, '"'.$this->operation.'"' , '"' . $this->operation . '"'
, $this->pipe ? ", '" . $this->pipe . "'" : '' , $this->pipe ? ", '" . $this->pipe . "'" : ''
); );
} }
else if(isset($this->default_column)) else if(isset($this->default_column))
{ {
return sprintf("new ConditionWithoutArgument('%s',%s,%s%s)" return sprintf("new ConditionWithoutArgument('%s',%s,%s%s)"
, $this->column_name , $this->column_name
, $this->default_column , $this->default_column
, '"'.$this->operation.'"' , '"' . $this->operation . '"'
, $this->pipe ? ", '" . $this->pipe . "'" : '' , $this->pipe ? ", '" . $this->pipe . "'" : ''
); );
} }
else else
{ {
return sprintf("new ConditionWithArgument('%s',%s,%s%s)" return sprintf("new ConditionWithArgument('%s',%s,%s%s)"
, $this->column_name , $this->column_name
, '$' . $this->argument_name . '_argument' , '$' . $this->argument_name . '_argument'
, '"'.$this->operation.'"' , '"' . $this->operation . '"'
, $this->pipe ? ", '" . $this->pipe . "'" : '' , $this->pipe ? ", '" . $this->pipe . "'" : ''
); );
} }
} }
} }
/* End of file ConditionTag.class.php */ /* End of file ConditionTag.class.php */
/* Location: ./classes/xml/xmlquery/tags/condition/ConditionTag.class.php */ /* Location: ./classes/xml/xmlquery/tags/condition/ConditionTag.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* ConditionsTag class * ConditionsTag class
* *
@ -8,6 +9,7 @@
*/ */
class ConditionsTag class ConditionsTag
{ {
/** /**
* ConditionGroupTag list * ConditionGroupTag list
* @var array value is ConditionGroupTag object * @var array value is ConditionGroupTag object
@ -23,16 +25,26 @@ class ConditionsTag
{ {
$this->condition_groups = array(); $this->condition_groups = array();
if(!$xml_conditions) if(!$xml_conditions)
{
return; return;
}
$xml_condition_list = array(); $xml_condition_list = array();
if($xml_conditions->condition) if($xml_conditions->condition)
{
$xml_condition_list = $xml_conditions->condition; $xml_condition_list = $xml_conditions->condition;
}
if($xml_conditions->query) if($xml_conditions->query)
{ {
if(!is_array($xml_condition_list)) $xml_condition_list = array($xml_condition_list); if(!is_array($xml_condition_list))
if(!is_array($xml_conditions->query)) $xml_conditions->query = array($xml_conditions->query); {
$xml_condition_list = array($xml_condition_list);
}
if(!is_array($xml_conditions->query))
{
$xml_conditions->query = array($xml_conditions->query);
}
$xml_condition_list = array_merge($xml_condition_list, $xml_conditions->query); $xml_condition_list = array_merge($xml_condition_list, $xml_conditions->query);
} }
if($xml_condition_list) if($xml_condition_list)
@ -43,7 +55,10 @@ class ConditionsTag
$xml_groups = $xml_conditions->group; $xml_groups = $xml_conditions->group;
if($xml_groups) if($xml_groups)
{ {
if(!is_array($xml_groups)) $xml_groups = array($xml_groups); if(!is_array($xml_groups))
{
$xml_groups = array($xml_groups);
}
foreach($xml_groups as $group) foreach($xml_groups as $group)
{ {
$this->condition_groups[] = new ConditionGroupTag($group->condition, $group->attrs->pipe); $this->condition_groups[] = new ConditionGroupTag($group->condition, $group->attrs->pipe);
@ -76,6 +91,7 @@ class ConditionsTag
} }
return $arguments; return $arguments;
} }
} }
/* End of file ConditionsTag.class.php */ /* End of file ConditionsTag.class.php */
/* Location: ./classes/xml/xmlquery/tags/condition/ConditionsTag.class.php */ /* Location: ./classes/xml/xmlquery/tags/condition/ConditionsTag.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* JoinConditionsTag class * JoinConditionsTag class
* *
@ -8,6 +9,7 @@
*/ */
class JoinConditionsTag extends ConditionsTag class JoinConditionsTag extends ConditionsTag
{ {
/** /**
* constructor * constructor
* @param object $xml_conditions * @param object $xml_conditions
@ -18,6 +20,7 @@ class JoinConditionsTag extends ConditionsTag
parent::ConditionsTag($xml_conditions); parent::ConditionsTag($xml_conditions);
$this->condition_groups[0]->conditions[0]->setPipe(""); $this->condition_groups[0]->conditions[0]->setPipe("");
} }
} }
/* End of file JoinConditionsTag.class.php */ /* End of file JoinConditionsTag.class.php */
/* Location: ./classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php */ /* Location: ./classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* GroupsTag class * GroupsTag class
* *
@ -8,6 +9,7 @@
*/ */
class GroupsTag class GroupsTag
{ {
/** /**
* column list * column list
* @var array * @var array
@ -25,14 +27,20 @@ class GroupsTag
if($xml_groups) if($xml_groups)
{ {
if(!is_array($xml_groups)) $xml_groups = array($xml_groups); if(!is_array($xml_groups))
{
$xml_groups = array($xml_groups);
}
$dbParser = &DB::getParser(); $dbParser = &DB::getParser();
for($i=0;$i<count($xml_groups);$i++) for($i = 0; $i < count($xml_groups); $i++)
{ {
$group = $xml_groups[$i]; $group = $xml_groups[$i];
$column = trim($group->attrs->column); $column = trim($group->attrs->column);
if(!$column) continue; if(!$column)
{
continue;
}
$column = $dbParser->parseExpression($column); $column = $dbParser->parseExpression($column);
$this->groups[] = $column; $this->groups[] = $column;
@ -48,9 +56,10 @@ class GroupsTag
$output .= "'" . $group . "' ,"; $output .= "'" . $group . "' ,";
} }
$output = substr($output, 0, -1); $output = substr($output, 0, -1);
$output .= ')'; $output .= ')';
return $output; return $output;
} }
} }
/* End of file GroupsTag.class.php */ /* End of file GroupsTag.class.php */
/* Location: ./classes/xml/xmlquery/tags/group/GroupsTag.class.php */ /* Location: ./classes/xml/xmlquery/tags/group/GroupsTag.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* IndexTag class * IndexTag class
* *
@ -8,26 +9,31 @@
*/ */
class IndexTag class IndexTag
{ {
/** /**
* argument name * argument name
* @var string * @var string
*/ */
var $argument_name; var $argument_name;
/** /**
* QueryArgument object * QueryArgument object
* @var QueryArgument * @var QueryArgument
*/ */
var $argument; var $argument;
/** /**
* Default value * Default value
* @var string * @var string
*/ */
var $default; var $default;
/** /**
* Sort order * Sort order
* @var string * @var string
*/ */
var $sort_order; var $sort_order;
/** /**
* Sort order argument * Sort order argument
* @var SortQueryArgument object * @var SortQueryArgument object
@ -51,7 +57,7 @@ class IndexTag
// Sort order - asc / desc // Sort order - asc / desc
$this->sort_order = $index->attrs->order; $this->sort_order = $index->attrs->order;
$sortList = array('asc'=>1, 'desc'=>1); $sortList = array('asc' => 1, 'desc' => 1);
if(!isset($sortList[$this->sort_order])) if(!isset($sortList[$this->sort_order]))
{ {
$arg = new Xml_Node_(); $arg = new Xml_Node_();
@ -59,9 +65,12 @@ class IndexTag
$arg->attrs->var = $this->sort_order; $arg->attrs->var = $this->sort_order;
$arg->attrs->default = 'asc'; $arg->attrs->default = 'asc';
$this->sort_order_argument = new SortQueryArgument($arg); $this->sort_order_argument = new SortQueryArgument($arg);
$this->sort_order = '$'.$this->sort_order_argument->getArgumentName().'_argument'; $this->sort_order = '$' . $this->sort_order_argument->getArgumentName() . '_argument';
}
else
{
$this->sort_order = '"' . $this->sort_order . '"';
} }
else $this->sort_order = '"'.$this->sort_order.'"';
} }
function toString() function toString()
@ -74,9 +83,12 @@ class IndexTag
$arguments = array(); $arguments = array();
$arguments[] = $this->argument; $arguments[] = $this->argument;
if($this->sort_order_argument) if($this->sort_order_argument)
{
$arguments[] = $this->sort_order_argument; $arguments[] = $this->sort_order_argument;
}
return $arguments; return $arguments;
} }
} }
/* End of file IndexTag.class.php */ /* End of file IndexTag.class.php */
/* Location: ./classes/xml/xmlquery/tags/navigation/IndexTag.class.php */ /* Location: ./classes/xml/xmlquery/tags/navigation/IndexTag.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* LimitTag class * LimitTag class
* *
@ -8,21 +9,25 @@
*/ */
class LimitTag class LimitTag
{ {
/** /**
* Value is relate to limit query * Value is relate to limit query
* @var array * @var array
*/ */
var $arguments; var $arguments;
/** /**
* QueryArgument object * QueryArgument object
* @var QueryArgument * @var QueryArgument
*/ */
var $page; var $page;
/** /**
* QueryArgument object * QueryArgument object
* @var QueryArgument * @var QueryArgument
*/ */
var $page_count; var $page_count;
/** /**
* QueryArgument object * QueryArgument object
* @var QueryArgument * @var QueryArgument
@ -50,14 +55,21 @@ class LimitTag
function toString() function toString()
{ {
if($this->page)return sprintf('new Limit(${\'%s_argument\'}, ${\'%s_argument\'}, ${\'%s_argument\'})', $this->list_count->getArgumentName(), $this->page->getArgumentName(), $this->page_count->getArgumentName()); if($this->page)
else return sprintf('new Limit(${\'%s_argument\'})', $this->list_count->getArgumentName()); {
return sprintf('new Limit(${\'%s_argument\'}, ${\'%s_argument\'}, ${\'%s_argument\'})', $this->list_count->getArgumentName(), $this->page->getArgumentName(), $this->page_count->getArgumentName());
}
else
{
return sprintf('new Limit(${\'%s_argument\'})', $this->list_count->getArgumentName());
}
} }
function getArguments() function getArguments()
{ {
return $this->arguments; return $this->arguments;
} }
} }
/* End of file LimitTag.class.php */ /* End of file LimitTag.class.php */
/* Location: ./classes/xml/xmlquery/tags/navigation/LimitTag.class.php */ /* Location: ./classes/xml/xmlquery/tags/navigation/LimitTag.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* NavigationTag class * NavigationTag class
* *
@ -8,26 +9,31 @@
*/ */
class NavigationTag class NavigationTag
{ {
/** /**
* Order * Order
* @var array * @var array
*/ */
var $order; var $order;
/** /**
* List count * List count
* @var int * @var int
*/ */
var $list_count; var $list_count;
/** /**
* Page count * Page count
* @var int * @var int
*/ */
var $page_count; var $page_count;
/** /**
* Page * Page
* @var int * @var int
*/ */
var $page; var $page;
/** /**
* Limit * Limit
* @var LimitTag object * @var LimitTag object
@ -47,23 +53,34 @@ class NavigationTag
$order = $xml_navigation->index; $order = $xml_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)
{ {
$this->order[] = new IndexTag($order_info); $this->order[] = new IndexTag($order_info);
} }
if($xml_navigation->page && $xml_navigation->page->attrs || $xml_navigation->list_count && $xml_navigation->list_count->attrs) if($xml_navigation->page && $xml_navigation->page->attrs || $xml_navigation->list_count && $xml_navigation->list_count->attrs)
{
$this->limit = new LimitTag($xml_navigation); $this->limit = new LimitTag($xml_navigation);
}
if($xml_navigation->list_count) if($xml_navigation->list_count)
$this->list_count = $xml_navigation->list_count->attrs; {
$this->list_count = $xml_navigation->list_count->attrs;
}
if($xml_navigation->page_count) if($xml_navigation->page_count)
$this->page_count = $xml_navigation->page_count->attrs; {
$this->page_count = $xml_navigation->page_count->attrs;
}
if($xml_navigation->page) if($xml_navigation->page)
{
$this->page = $xml_navigation->page->attrs; $this->page = $xml_navigation->page->attrs;
}
} }
} }
} }
@ -90,8 +107,14 @@ class NavigationTag
*/ */
function getLimitString() function getLimitString()
{ {
if($this->limit) return $this->limit->toString(); if($this->limit)
else return ""; {
return $this->limit->toString();
}
else
{
return "";
}
} }
function getArguments() function getArguments()
@ -101,9 +124,13 @@ class NavigationTag
{ {
$arguments = array_merge($order->getArguments(), $arguments); $arguments = array_merge($order->getArguments(), $arguments);
} }
if($this->limit) $arguments = array_merge($this->limit->getArguments(), $arguments); if($this->limit)
{
$arguments = array_merge($this->limit->getArguments(), $arguments);
}
return $arguments; return $arguments;
} }
} }
/* End of file NavigationTag.class.php */ /* End of file NavigationTag.class.php */
/* Location: ./classes/xml/xmlquery/tags/navigation/NavigationTag.class.php */ /* Location: ./classes/xml/xmlquery/tags/navigation/NavigationTag.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* QueryTag class * QueryTag class
* *
@ -8,86 +9,103 @@
*/ */
class QueryTag class QueryTag
{ {
/** /**
* Action for example, 'select', 'insert', 'delete'... * Action for example, 'select', 'insert', 'delete'...
* @var string * @var string
*/ */
var $action; var $action;
/** /**
* Query id * Query id
* @var string * @var string
*/ */
var $query_id; var $query_id;
/** /**
* Priority * Priority
* @var string * @var string
*/ */
var $priority; var $priority;
/** /**
* column type list * column type list
* @var array * @var array
*/ */
var $column_type; var $column_type;
/** /**
* Query stdClass object * Query stdClass object
* @var object * @var object
*/ */
var $query; var $query;
/** /**
* Columns in xml tags * Columns in xml tags
* @var object * @var object
*/ */
var $columns; var $columns;
/** /**
* Tables in xml tags * Tables in xml tags
* @var object * @var object
*/ */
var $tables; var $tables;
/** /**
* Subquery in xml tags * Subquery in xml tags
* @var object * @var object
*/ */
var $subquery; var $subquery;
/** /**
* Conditions in xml tags * Conditions in xml tags
* @var object * @var object
*/ */
var $conditions; var $conditions;
/** /**
* Groups in xml tags * Groups in xml tags
* @var object * @var object
*/ */
var $groups; var $groups;
/** /**
* Navigation in xml tags * Navigation in xml tags
* @var object * @var object
*/ */
var $navigation; var $navigation;
/** /**
* Arguments in xml tags * Arguments in xml tags
* @var object * @var object
*/ */
var $arguments; var $arguments;
/** /**
* PreBuff * PreBuff
* @var string * @var string
*/ */
var $preBuff; var $preBuff;
/** /**
* Buff * Buff
* @var string * @var string
*/ */
var $buff; var $buff;
/** /**
* Subquery status * Subquery status
* @var bool * @var bool
*/ */
var $isSubQuery; var $isSubQuery;
/** /**
* Join type * Join type
* @var string * @var string
*/ */
var $join_type; var $join_type;
/** /**
* alias * alias
* @var string * @var string
@ -100,7 +118,7 @@ class QueryTag
* @param bool $isSubQuery * @param bool $isSubQuery
* @return void * @return void
*/ */
function QueryTag($query, $isSubQuery = false) function QueryTag($query, $isSubQuery = FALSE)
{ {
$this->action = $query->attrs->action; $this->action = $query->attrs->action;
$this->query_id = $query->attrs->id; $this->query_id = $query->attrs->id;
@ -108,7 +126,9 @@ class QueryTag
$this->query = $query; $this->query = $query;
$this->isSubQuery = $isSubQuery; $this->isSubQuery = $isSubQuery;
if($this->isSubQuery) if($this->isSubQuery)
{
$this->action = 'select'; $this->action = 'select';
}
if($query->attrs->alias) if($query->attrs->alias)
{ {
$dbParser = DB::getParser(); $dbParser = DB::getParser();
@ -130,7 +150,7 @@ class QueryTag
function show() function show()
{ {
return true; return TRUE;
} }
function getQueryId() function getQueryId()
@ -155,7 +175,7 @@ class QueryTag
{ {
$table_tags = $tables->getTables(); $table_tags = $tables->getTables();
$column_type = array(); $column_type = array();
foreach ($table_tags as $table_tag) foreach($table_tags as $table_tag)
{ {
if(is_a($table_tag, 'TableTag')) if(is_a($table_tag, 'TableTag'))
{ {
@ -173,30 +193,33 @@ class QueryTag
{ {
if($this->action == 'select') if($this->action == 'select')
{ {
return $this->columns = new SelectColumnsTag($this->query->columns); return $this->columns = new SelectColumnsTag($this->query->columns);
} }
else if($this->action == 'insert' || $this->action == 'insert-select') else if($this->action == 'insert' || $this->action == 'insert-select')
{ {
return $this->columns = new InsertColumnsTag($this->query->columns->column); return $this->columns = new InsertColumnsTag($this->query->columns->column);
} }
else if($this->action == 'update') else if($this->action == 'update')
{ {
return $this->columns = new UpdateColumnsTag($this->query->columns->column); return $this->columns = new UpdateColumnsTag($this->query->columns->column);
} }
else if($this->action == 'delete') else if($this->action == 'delete')
{ {
return $this->columns = null; return $this->columns = null;
} }
} }
function getPrebuff() function getPrebuff()
{ {
if($this->isSubQuery) return; if($this->isSubQuery)
{
return;
}
// TODO Check if this work with arguments in join clause // TODO Check if this work with arguments in join clause
$arguments = $this->getArguments(); $arguments = $this->getArguments();
$prebuff = ''; $prebuff = '';
foreach ($arguments as $argument) foreach($arguments as $argument)
{ {
if(isset($argument)) if(isset($argument))
{ {
@ -209,26 +232,30 @@ class QueryTag
$table_alias = $argument->getTableName(); $table_alias = $argument->getTableName();
if(isset($table_alias)) if(isset($table_alias))
{ {
if (isset($this->column_type[$this->getQueryId()][$table_alias][$argument->getColumnName()])) if(isset($this->column_type[$this->getQueryId()][$table_alias][$argument->getColumnName()]))
$column_type = $this->column_type[$this->getQueryId()][$table_alias][$argument->getColumnName()]; {
$column_type = $this->column_type[$this->getQueryId()][$table_alias][$argument->getColumnName()];
}
} }
else else
{ {
$current_tables = $this->column_type[$this->getQueryId()]; $current_tables = $this->column_type[$this->getQueryId()];
$column_name = $argument->getColumnName(); $column_name = $argument->getColumnName();
foreach($current_tables as $current_table) foreach($current_tables as $current_table)
{ {
if(isset($current_table[$column_name])) if(isset($current_table[$column_name]))
{
$column_type = $current_table[$column_name]; $column_type = $current_table[$column_name];
}
} }
} }
if (isset($column_type)) if(isset($column_type))
{ {
$prebuff .= sprintf('if(${\'%s_argument\'} !== null) ${\'%s_argument\'}->setColumnType(\'%s\');' . "\n" $prebuff .= sprintf('if(${\'%s_argument\'} !== null) ${\'%s_argument\'}->setColumnType(\'%s\');' . "\n"
, $arg_name , $arg_name
, $arg_name , $arg_name
, $column_type); , $column_type);
} }
} }
} }
@ -265,15 +292,19 @@ class QueryTag
$buff .= sprintf('$query->setPriority("%s");%s', $this->priority, "\n"); $buff .= sprintf('$query->setPriority("%s");%s', $this->priority, "\n");
$buff .= $this->preBuff; $buff .= $this->preBuff;
if($this->columns) if($this->columns)
{
$buff .= '$query->setColumns(' . $this->columns->toString() . ');' . PHP_EOL; $buff .= '$query->setColumns(' . $this->columns->toString() . ');' . PHP_EOL;
}
$buff .= '$query->setTables(' . $this->tables->toString() .');'.PHP_EOL; $buff .= '$query->setTables(' . $this->tables->toString() . ');' . PHP_EOL;
if($this->action == 'insert-select') if($this->action == 'insert-select')
$buff .= '$query->setSubquery(' . $this->subquery->toString() .');'.PHP_EOL; {
$buff .= '$query->setConditions('.$this->conditions->toString() .');'.PHP_EOL; $buff .= '$query->setSubquery(' . $this->subquery->toString() . ');' . PHP_EOL;
$buff .= '$query->setGroups(' . $this->groups->toString() . ');'.PHP_EOL; }
$buff .= '$query->setOrder(' . $this->navigation->getOrderByString() .');'.PHP_EOL; $buff .= '$query->setConditions(' . $this->conditions->toString() . ');' . PHP_EOL;
$buff .= '$query->setLimit(' . $this->navigation->getLimitString() .');'.PHP_EOL; $buff .= '$query->setGroups(' . $this->groups->toString() . ');' . PHP_EOL;
$buff .= '$query->setOrder(' . $this->navigation->getOrderByString() . ');' . PHP_EOL;
$buff .= '$query->setLimit(' . $this->navigation->getLimitString() . ');' . PHP_EOL;
$this->buff = $buff; $this->buff = $buff;
return $this->buff; return $this->buff;
@ -282,9 +313,13 @@ class QueryTag
function getTables() function getTables()
{ {
if($this->query->index_hint && ($this->query->index_hint->attrs->for == 'ALL' || Context::getDBType() == strtolower($this->query->index_hint->attrs->for))) if($this->query->index_hint && ($this->query->index_hint->attrs->for == 'ALL' || Context::getDBType() == strtolower($this->query->index_hint->attrs->for)))
{
return $this->tables = new TablesTag($this->query->tables, $this->query->index_hint); return $this->tables = new TablesTag($this->query->tables, $this->query->index_hint);
}
else else
{
return $this->tables = new TablesTag($this->query->tables); return $this->tables = new TablesTag($this->query->tables);
}
} }
function getSubquery() function getSubquery()
@ -303,9 +338,13 @@ class QueryTag
function getGroups() function getGroups()
{ {
if($this->query->groups) if($this->query->groups)
{
return $this->groups = new GroupsTag($this->query->groups->group); return $this->groups = new GroupsTag($this->query->groups->group);
}
else else
{
return $this->groups = new GroupsTag(NULL); return $this->groups = new GroupsTag(NULL);
}
} }
function getNavigation() function getNavigation()
@ -337,14 +376,19 @@ class QueryTag
{ {
$arguments = array(); $arguments = array();
if($this->columns) if($this->columns)
{
$arguments = array_merge($arguments, $this->columns->getArguments()); $arguments = array_merge($arguments, $this->columns->getArguments());
if($this->action =='insert-select') }
if($this->action == 'insert-select')
{
$arguments = array_merge($arguments, $this->subquery->getArguments()); $arguments = array_merge($arguments, $this->subquery->getArguments());
}
$arguments = array_merge($arguments, $this->tables->getArguments()); $arguments = array_merge($arguments, $this->tables->getArguments());
$arguments = array_merge($arguments, $this->conditions->getArguments()); $arguments = array_merge($arguments, $this->conditions->getArguments());
$arguments = array_merge($arguments, $this->navigation->getArguments()); $arguments = array_merge($arguments, $this->navigation->getArguments());
return $arguments; return $arguments;
} }
} }
/* End of file QueryTag.class.php */ /* End of file QueryTag.class.php */
/* Location: ./classes/xml/xmlquery/tags/navigation/QueryTag.class.php */ /* Location: ./classes/xml/xmlquery/tags/navigation/QueryTag.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* HintTableTag * HintTableTag
* Models the <table> tag inside an XML Query file and the corresponding <index_hint> tag * Models the <table> tag inside an XML Query file and the corresponding <index_hint> tag
@ -9,6 +10,7 @@
*/ */
class HintTableTag extends TableTag class HintTableTag extends TableTag
{ {
/** /**
* Action for example, 'select', 'insert', 'delete'... * Action for example, 'select', 'insert', 'delete'...
* @var array * @var array
@ -36,13 +38,13 @@ class HintTableTag extends TableTag
$result = sprintf('new %sTableWithHint(\'%s\'%s, array(' $result = sprintf('new %sTableWithHint(\'%s\'%s, array('
, $dbType == 'Mysqli' ? 'Mysql' : $dbType , $dbType == 'Mysqli' ? 'Mysql' : $dbType
, $dbParser->escape($this->name) , $dbParser->escape($this->name)
, $this->alias ? ', \'' . $dbParser->escape($this->alias) .'\'' : ', null' , $this->alias ? ', \'' . $dbParser->escape($this->alias) . '\'' : ', null'
//, ', \'' . $dbParser->escape($this->index->name) .'\', \'' . $this->index->type .'\'' //, ', \'' . $dbParser->escape($this->index->name) .'\', \'' . $this->index->type .'\''
); );
foreach($this->index as $indx) foreach($this->index as $indx)
{ {
$result .= "new IndexHint("; $result .= "new IndexHint(";
$result .= '\'' . $dbParser->escape($indx->name) .'\', \'' . $indx->type .'\'' . ') , '; $result .= '\'' . $dbParser->escape($indx->name) . '\', \'' . $indx->type . '\'' . ') , ';
} }
$result = substr($result, 0, -2); $result = substr($result, 0, -2);
$result .= '))'; $result .= '))';
@ -51,9 +53,13 @@ class HintTableTag extends TableTag
function getArguments() function getArguments()
{ {
if(!isset($this->conditionsTag)) return array(); if(!isset($this->conditionsTag))
{
return array();
}
return $this->conditionsTag->getArguments(); return $this->conditionsTag->getArguments();
} }
} }
/* End of file HintTableTag.class.php */ /* End of file HintTableTag.class.php */
/* Location: ./classes/xml/xmlquery/tags/table/HintTableTag.class.php */ /* Location: ./classes/xml/xmlquery/tags/table/HintTableTag.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* TableTag * TableTag
* Models the <table> tag inside an XML Query file * Models the <table> tag inside an XML Query file
@ -20,32 +21,38 @@
*/ */
class TableTag class TableTag
{ {
/** /**
* Unescaped name * Unescaped name
* @var string * @var string
*/ */
var $unescaped_name; var $unescaped_name;
/** /**
* name * name
* @var string * @var string
*/ */
var $name; var $name;
/** /**
* alias * alias
* @var string * @var string
*/ */
var $alias; var $alias;
/** /**
* Join type * Join type
* @example 'left join', 'left outer join', 'right join', 'right outer join' * @example 'left join', 'left outer join', 'right join', 'right outer join'
* @var string * @var string
*/ */
var $join_type; var $join_type;
/** /**
* Condition object * Condition object
* @var object * @var object
*/ */
var $conditions; var $conditions;
/** /**
* JoinConditionsTag * JoinConditionsTag
* @var JoinConditionsTag object * @var JoinConditionsTag object
@ -66,21 +73,28 @@ class TableTag
$this->name = $dbParser->parseTableName($table->attrs->name); $this->name = $dbParser->parseTableName($table->attrs->name);
$this->alias = $table->attrs->alias; $this->alias = $table->attrs->alias;
if(!$this->alias) $this->alias = $table->attrs->name; if(!$this->alias)
{
$this->alias = $table->attrs->name;
}
$this->join_type = $table->attrs->type; $this->join_type = $table->attrs->type;
$this->conditions = $table->conditions; $this->conditions = $table->conditions;
if($this->isJoinTable()) if($this->isJoinTable())
{
$this->conditionsTag = new JoinConditionsTag($this->conditions); $this->conditionsTag = new JoinConditionsTag($this->conditions);
}
} }
function isJoinTable() function isJoinTable()
{ {
$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);
if(isset($joinList[$this->join_type]) if(isset($joinList[$this->join_type]) && count($this->conditions))
&& count($this->conditions)) return true; {
return true;
}
return false; return false;
} }
@ -107,20 +121,24 @@ class TableTag
if($this->isJoinTable()) if($this->isJoinTable())
{ {
return sprintf('new JoinTable(\'%s\', \'%s\', "%s", %s)' return sprintf('new JoinTable(\'%s\', \'%s\', "%s", %s)'
, $dbParser->escape($this->name) , $dbParser->escape($this->name)
, $dbParser->escape($this->alias) , $dbParser->escape($this->alias)
, $this->join_type, $this->conditionsTag->toString()); , $this->join_type, $this->conditionsTag->toString());
} }
return sprintf('new Table(\'%s\'%s)' return sprintf('new Table(\'%s\'%s)'
, $dbParser->escape($this->name) , $dbParser->escape($this->name)
, $this->alias ? ', \'' . $dbParser->escape($this->alias) .'\'' : ''); , $this->alias ? ', \'' . $dbParser->escape($this->alias) . '\'' : '');
} }
function getArguments() function getArguments()
{ {
if(!isset($this->conditionsTag)) return array(); if(!isset($this->conditionsTag))
{
return array();
}
return $this->conditionsTag->getArguments(); return $this->conditionsTag->getArguments();
} }
} }
/* End of file TableTag.class.php */ /* End of file TableTag.class.php */
/* Location: ./classes/xml/xmlquery/tags/table/TableTag.class.php */ /* Location: ./classes/xml/xmlquery/tags/table/TableTag.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* TablesTag class * TablesTag class
* Models the <tables> tag inside an XML Query file * Models the <tables> tag inside an XML Query file
@ -18,6 +19,7 @@
*/ */
class TablesTag class TablesTag
{ {
/** /**
* Table list * Table list
* @var array * @var array
@ -35,15 +37,24 @@ class TablesTag
$this->tables = array(); $this->tables = array();
$xml_tables = $xml_tables_tag->table; $xml_tables = $xml_tables_tag->table;
if(!is_array($xml_tables)) $xml_tables = array($xml_tables); if(!is_array($xml_tables))
{
$xml_tables = array($xml_tables);
}
if($xml_index_hints_tag) if($xml_index_hints_tag)
{ {
$index_nodes = $xml_index_hints_tag->index; $index_nodes = $xml_index_hints_tag->index;
if(!is_array($index_nodes)) $index_nodes = array($index_nodes); if(!is_array($index_nodes))
{
$index_nodes = array($index_nodes);
}
foreach($index_nodes as $index_node) foreach($index_nodes as $index_node)
{ {
if(!isset($indexes[$index_node->attrs->table])) $indexes[$index_node->attrs->table] = array(); if(!isset($indexes[$index_node->attrs->table]))
{
$indexes[$index_node->attrs->table] = array();
}
$count = count($indexes[$index_node->attrs->table]); $count = count($indexes[$index_node->attrs->table]);
$indexes[$index_node->attrs->table][$count] = (object) NULL; $indexes[$index_node->attrs->table][$count] = (object) NULL;
$indexes[$index_node->attrs->table][$count]->name = $index_node->attrs->name; $indexes[$index_node->attrs->table][$count]->name = $index_node->attrs->name;
@ -60,9 +71,13 @@ class TablesTag
else else
{ {
if(isset($indexes[$tag->attrs->name]) && $indexes[$tag->attrs->name]) if(isset($indexes[$tag->attrs->name]) && $indexes[$tag->attrs->name])
{
$this->tables[] = new HintTableTag($tag, $indexes[$tag->attrs->name]); $this->tables[] = new HintTableTag($tag, $indexes[$tag->attrs->name]);
}
else else
{
$this->tables[] = new TableTag($tag); $this->tables[] = new TableTag($tag);
}
} }
} }
} }
@ -78,9 +93,13 @@ class TablesTag
foreach($this->tables as $table) foreach($this->tables as $table)
{ {
if(is_a($table, 'QueryTag')) if(is_a($table, 'QueryTag'))
{
$output_tables .= $table->toString() . PHP_EOL . ','; $output_tables .= $table->toString() . PHP_EOL . ',';
}
else else
{
$output_tables .= $table->getTableString() . PHP_EOL . ','; $output_tables .= $table->getTableString() . PHP_EOL . ',';
}
} }
$output_tables = substr($output_tables, 0, -1); $output_tables = substr($output_tables, 0, -1);
$output_tables .= ')'; $output_tables .= ')';
@ -91,9 +110,12 @@ class TablesTag
{ {
$arguments = array(); $arguments = array();
foreach($this->tables as $table) foreach($this->tables as $table)
{
$arguments = array_merge($arguments, $table->getArguments()); $arguments = array_merge($arguments, $table->getArguments());
}
return $arguments; return $arguments;
} }
} }
/* End of file TablesTag.class.php */ /* End of file TablesTag.class.php */
/* Location: ./classes/xml/xmlquery/tags/table/TablesTag.class.php */ /* Location: ./classes/xml/xmlquery/tags/table/TablesTag.class.php */