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,7 +1,9 @@
<?php
/**
* File containing the DBParser class
*/
/**
* Escapes query statements: <br />
* - column names: member.member_srl =&gt; "member"."member_srl" <br />
@ -13,6 +15,7 @@
*/
class DBParser
{
/**
* Character for escape target value on the left
*
@ -56,11 +59,17 @@ class DBParser
*
* @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;
if ($escape_char_right !== "")$this->escape_char_right = $escape_char_right;
else $this->escape_char_right = $escape_char_left;
if($escape_char_right !== "")
{
$this->escape_char_right = $escape_char_right;
}
else
{
$this->escape_char_right = $escape_char_left;
}
$this->table_prefix = $table_prefix;
}
@ -72,8 +81,14 @@ class DBParser
*/
function getEscapeChar($leftOrRight)
{
if ($leftOrRight === 'left')return $this->escape_char_left;
else return $this->escape_char_right;
if($leftOrRight === 'left')
{
return $this->escape_char_left;
}
else
{
return $this->escape_char_right;
}
}
/**
@ -95,7 +110,7 @@ class DBParser
*/
function escapeString($name)
{
return "'".$this->escapeStringValue($name)."'";
return "'" . $this->escapeStringValue($name) . "'";
}
/**
@ -106,8 +121,14 @@ class DBParser
*/
function escapeStringValue($value)
{
if($value == "*") return $value;
if (is_string($value)) return $value = str_replace("'","''",$value);
if($value == "*")
{
return $value;
}
if(is_string($value))
{
return $value = str_replace("'", "''", $value);
}
return $value;
}
@ -144,12 +165,14 @@ class DBParser
function escapeColumn($column_name)
{
if($this->isUnqualifiedColumnName($column_name))
{
return $this->escape($column_name);
}
if($this->isQualifiedColumnName($column_name))
{
list($table, $column) = explode('.', $column_name);
// $table can also be an alias, so the prefix should not be added
return $this->escape($table).'.'.$this->escape($column);
return $this->escape($table) . '.' . $this->escape($column);
//return $this->escape($this->parseTableName($table)).'.'.$this->escape($column);
}
}
@ -165,7 +188,10 @@ class DBParser
*/
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;
}
@ -180,7 +206,10 @@ class DBParser
*/
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;
}
@ -204,26 +233,39 @@ class DBParser
*/
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)
{
$function = &$functions[$k];
if(strlen($function)==1) continue; // skip delimiters
if(strlen($function) == 1)
{
continue; // skip delimiters
}
$pos = strrpos("(", $function);
$matches = preg_split('/([a-zA-Z0-9_*]+)/', $function, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
$matches = preg_split('/([a-zA-Z0-9_*]+)/', $function, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$total_brackets = substr_count($function, "(");
$brackets = 0;
foreach($matches as $i => $j)
{
$match = &$matches[$i];
if($match == '(') {$brackets++; continue;}
if(strpos($match,')') !== FALSE) continue;
if(in_array($match, array(',', '.'))) continue;
if($match == '(')
{
$brackets++;
continue;
}
if(strpos($match, ')') !== FALSE)
{
continue;
}
if(in_array($match, array(',', '.')))
{
continue;
}
if($brackets == $total_brackets)
{
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)
{
if(substr($column_name,-1) == '*') return TRUE;
if(substr($column_name, -1) == '*')
{
return TRUE;
}
return FALSE;
}
@ -253,7 +298,10 @@ class DBParser
*/
function isStarFunction($column_name)
{
if(strpos($column_name, "(*)")!==FALSE) return TRUE;
if(strpos($column_name, "(*)") !== FALSE)
{
return TRUE;
}
return FALSE;
}
@ -264,14 +312,21 @@ class DBParser
*/
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))
{
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);
}
}
/* End of file DBParser.class.php */
/* Location: ./classes/xml/xmlquery/DBParser.class.php */

View file

@ -1,7 +1,9 @@
<?php
/**
* File containing the QueryParser class
*/
/**
* 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
@ -60,12 +62,14 @@ class QueryParser
else if(count($id_args) == 3)
{
$target = $id_args[0];
$targetList = array('modules'=>1, 'addons'=>1, 'widgets'=>1);
if (!isset($targetList[$target]))
$targetList = array('modules' => 1, 'addons' => 1, 'widgets' => 1);
if(!isset($targetList[$target]))
{
return;
}
$module = $id_args[1];
$id = $id_args[2];
}
}
// get column properties from the table
$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);
if(file_exists($table_file))
{
break;
}
}
}
@ -111,9 +117,10 @@ class QueryParser
function toString()
{
return "<?php if(!defined('__ZBXE__')) exit();\n"
. $this->queryTag->toString()
. 'return $query; ?>';
. $this->queryTag->toString()
. 'return $query; ?>';
}
}
/* End of file QueryParser.class.php */
/* Location: ./classes/xml/xmlquery/QueryParser.class.php */

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,4 +1,5 @@
<?php
/**
* Models the &lt;columns&gt; tag inside an XML Query file whose action is 'insert'
*
@ -8,6 +9,7 @@
*/
class InsertColumnsTag
{
/**
* Column list
*
@ -26,15 +28,29 @@ class InsertColumnsTag
$this->columns = array();
if(!$xml_columns)
{
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)
{
if($column->name === 'query') $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);
if($column->name === 'query')
{
$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
/**
* Models the &lt;column&gt; tag inside an XML Query file whose action is 'select'
*
@ -8,6 +9,7 @@
*/
class SelectColumnTag extends ColumnTag
{
/**
* Column alias
*
@ -30,7 +32,7 @@ class SelectColumnTag extends ColumnTag
*/
function SelectColumnTag($column)
{
if ($column == "*" || $column->attrs->name == '*')
if($column == "*" || $column->attrs->name == '*')
{
parent::ColumnTag(NULL);
$this->name = "*";
@ -38,7 +40,7 @@ class SelectColumnTag extends ColumnTag
else
{
parent::ColumnTag($column->attrs->name);
$dbParser = new DB(); $dbParser = &$dbParser->getParser();
$dbParser = DB::getParser();
$this->name = $dbParser->parseExpression($this->name);
$this->alias = $column->attrs->alias;
@ -60,14 +62,22 @@ class SelectColumnTag extends ColumnTag
*/
function getExpressionString()
{
if($this->name == '*') return "new StarExpression()";
if($this->name == '*')
{
return "new StarExpression()";
}
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)
{
return sprintf('new SelectExpression($args->%s)', substr($this->name, 1));
}
$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 */
/* Location: ./classes/xml/xmlquery/tags/column/SelectColumnTag.class.php */

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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