merge from 1.5.3 (~r10943)

git-svn-id: http://xe-core.googlecode.com/svn/trunk@10951 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
flyskyko 2012-07-27 02:47:10 +00:00
parent 7aa4798373
commit 54e3a72065
334 changed files with 13011 additions and 5561 deletions

View file

@ -1,18 +1,23 @@
<?php
/**
* @class GeneralXmlParser
* @author NHN (developers@xpressengine.com)
* @brief Generic XML parser for XE
* @version 0.1
*/
class GeneralXmlParser {
/**
* GeneralXmlParser class
* Generic XML parser for XE
* @author NHN (developers@xpressengine.com)
* @package /classes/xml
* @version 0.1
*/
class GeneralXmlParser {
/**
* result of parse
* @var array
*/
var $output = array();
/**
* @brief parse a given input to product a object containing parse values.
* @param[in] $input data to be parsed
* @return Returns an object containing parsed values or NULL in case of failure
*/
/**
* Parse a given input to product a object containing parse values.
* @param string $input data to be parsed
* @return array|NULL Returns an object containing parsed values or NULL in case of failure
*/
function parse($input = '') {
$oParser = xml_parser_create('UTF-8');
xml_set_object($oParser, $this);
@ -28,12 +33,13 @@
return $this->output;
}
/**
* @brief start element handler
* @param[in] $parse an instance of parser
* @param[in] $node_name a name of node
* @param[in] $attrs attributes to be set
*/
/**
* Start element handler
* @param resource $parser an instance of parser
* @param string $node_name a name of node
* @param array $attrs attributes to be set
* @return void
*/
function _tagOpen($parser, $node_name, $attrs) {
$obj->node_name = strtolower($node_name);
$obj->attrs = $attrs;
@ -42,23 +48,25 @@
array_push($this->output, $obj);
}
/**
* @brief character data handler
* variable in the last element of this->output
* @param[in] $parse an instance of parser
* @param[in] $body a data to be added
*/
/**
* Character data handler
* Variable in the last element of this->output
* @param resource $parse an instance of parser
* @param string $body a data to be added
* @return void
*/
function _tagBody($parser, $body) {
//if(!trim($body)) return;
$this->output[count($this->output)-1]->body .= $body;
}
/**
* @brief end element handler
* @param[in] $parse an instance of parser
* @param[in] $node_name name of xml node
*/
/**
* End element handler
* @param resource $parse an instance of parser
* @param string $node_name name of xml node
* @return void
*/
function _tagClosed($parser, $node_name) {
$node_name = strtolower($node_name);
$cur_obj = array_pop($this->output);
@ -79,5 +87,5 @@
}
}
}
}
?>

View file

@ -1,7 +1,16 @@
<?php
/**
* XmlGenerator class
* @author NHN (developers@xpressengine.com)
* @package /classes/xml
* @version 0.1
*/
class XmlGenerator{
/**
* object change to xml
* @param object $xml
* @return string
*/
function obj2xml($xml){
$buff = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
@ -11,6 +20,11 @@ class XmlGenerator{
return $buff;
}
/**
* object change to xml
* @param object $node node in xml object
* @return string
*/
function _makexml($node){
$body = '';
foreach($node as $key => $value){

View file

@ -1,13 +1,10 @@
<?php
/**
* @class XmlJsFilter
* @author NHN (developers@xpressengine.com)
* @brief filter class traslate xml content into javascript code
* @version 0.2
* filter class traslate xml content into javascript code
*
* it convert xml code into js file and save the result as a cache file
* @code
* {
* <pre>{
* <filter name="name of javascript funcion" act="action name" confirm_msg_code="message string to be prompted when submitting the form" >
* <form> <-- code to validate data in the form
* <node target="name" required="true" minlength="1" maxlength="5" filter="email,userid,alpha,number" equalto="target" />
@ -19,9 +16,10 @@
* <tag name="error" /> <- get the result of error name
* </response>
* </filter>
* }
* }</pre>
*
* @detail {
* @detail
* <pre>{
* - syntax description of <form> node
* target = name of for element
* required = flag indicating whether a field is mandatory or not
@ -40,18 +38,40 @@
*
* - response
* tag = key : name of variable that will contain the result of the execution
* }
**/
* }</pre>
* @class XmlJsFilter
* @author NHN (developers@xpressengine.com)
* @package /classes/xml
* @version 0.2
*/
class XmlJsFilter extends XmlParser {
/**
* version
* @var string
*/
var $version = '0.2.5';
/**
* compiled javascript cache path
* @var string
*/
var $compiled_path = './files/cache/js_filter_compiled/'; // / directory path for compiled cache file
var $xml_file = NULL; // / Target xml file
var $js_file = NULL; // / Compiled js file
/**
* Target xml file
* @var string
*/
var $xml_file = NULL;
/**
* Compiled js file
* @var string
*/
var $js_file = NULL; // /
/**
* @brief constructor
**/
* constructor
* @param string $path
* @param string $xml_file
* @return void
*/
function XmlJsFilter($path, $xml_file) {
if(substr($path,-1)!=='/') $path .= '/';
$this->xml_file = sprintf("%s%s",$path, $xml_file);
@ -59,9 +79,9 @@
}
/**
* @brief compile a xml_file only when a corresponding js file does not exists or is outdated
* @return Returns NULL regardless of the success of failure of the operation
**/
* Compile a xml_file only when a corresponding js file does not exists or is outdated
* @return void Returns NULL regardless of the success of failure of the operation
*/
function compile() {
if(!file_exists($this->xml_file)) return;
if(!file_exists($this->js_file)) $this->_compile();
@ -70,8 +90,9 @@
}
/**
* @brief compile a xml_file into js_file
**/
* compile a xml_file into js_file
* @return void
*/
function _compile() {
global $lang;
@ -283,7 +304,9 @@
}
/**
* @brief return a file name of js file corresponding to the xml file
* return a file name of js file corresponding to the xml file
* @param string $xml_file
* @return string
**/
function _getCompiledFileName($xml_file) {
return sprintf('%s%s.%s.compiled.js',$this->compiled_path, md5($this->version.$xml_file),Context::getLangType());

View file

@ -1,22 +1,50 @@
<?php
/**
* @class XmlLangParser
* XmlLangParser class
* Change to lang php file from xml.
* @author NHN (developers@xpressengine.com)
* @brief change to lang php file from xml.
* @version 0.1
* @package /classes/xml
* @version 0.1
**/
class XmlLangParser extends XmlParser {
/**
* compiled language cache path
* @var string
*/
var $compiled_path = './files/cache/lang/'; // / directory path for compiled cache file
var $xml_file = NULL; // / Target xml file
var $php_file = NULL; // / Target php file
/**
* Target xml file
* @var string
*/
var $xml_file = NULL;
/**
* Target php file
* @var string
*/
var $php_file = NULL;
/**
* result source code
* @var string
*/
var $code;
/**
* language list, for example ko, en...
* @var array
*/
var $lang_types;
/**
* language type
* @see _XE_PATH_.'/common/lang/lang.info'
* @var string
*/
var $lang_type;
/**
* @brief constructor
**/
* constructor
* @param string $xml_file
* @param string $lang_type
* @return void
*/
function XmlLangParser($xml_file, $lang_type) {
$this->lang_type = $lang_type;
$this->xml_file = $xml_file;
@ -24,9 +52,9 @@
}
/**
* @brief compile a xml_file only when a corresponding php lang file does not exists or is outdated
* @return Returns compiled php file.
**/
* compile a xml_file only when a corresponding php lang file does not exists or is outdated
* @return string|bool Returns compiled php file.
*/
function compile() {
if(!file_exists($this->xml_file)) return false;
if(!file_exists($this->php_file)){
@ -36,9 +64,13 @@
else return $this->php_file;
}
return $this->_writefile() ? $this->php_file : false;
return $this->_writeFile() ? $this->php_file : false;
}
/**
* Return compiled content
* @return string Returns compiled lang source code
*/
function getCompileContent() {
if(!file_exists($this->xml_file)) return false;
$this->_compile();
@ -47,8 +79,9 @@
}
/**
* @brief compile a xml_file
**/
* Compile a xml_file
* @return void
*/
function _compile() {
$lang_selected = Context::loadLangSelected();
$this->lang_types = array_keys($lang_selected);
@ -68,8 +101,9 @@
}
/**
* @brief writing cache file
**/
* Writing cache file
* @return void|bool
*/
function _writeFile(){
if(!$this->code) return;
FileHandler::writeFile($this->php_file, "<?php\n".$this->code);
@ -77,8 +111,11 @@
}
/**
* @brief Parsing item node
**/
* Parsing item node, set content to '$this->code'
* @param object $item
* @param string $var
* @return void
*/
function _parseItem($item, $var){
$name = $item->attrs->name;
$value = $item->value;
@ -108,8 +145,11 @@
}
/**
* @brief Parsing value nodes
**/
* Parsing value nodes
* @param array $nodes
* @param string $var
* @return array|string
*/
function _parseValues($nodes, $var) {
if(!is_array($nodes)) $nodes = array($nodes);
@ -132,8 +172,11 @@
}
/**
* @brief Parsing value node
**/
* Parsing value node
* @param object $node
* @param string $var
* @return array|bool
*/
function _parseValue($node, $var) {
$lang_type = $node->attrs->xml_lang;
$value = $node->body;
@ -144,8 +187,11 @@
}
/**
* @brief get cache file name
**/
* Get cache file name
* @param string $lang_type
* @param string $type
* @return string
*/
function _getCompiledFileName($lang_type, $type='php') {
return sprintf('%s%s.%s.php',$this->compiled_path, md5($this->xml_file), $lang_type);
}

View file

@ -1,6 +1,11 @@
<?php
/* Element node or attribute node. */
/**
* Xml_Node_ class
* Element node or attribute node.
* @author NHN (developers@xpressengine.com)
* @package /classes/xml
* @version 0.1
*/
class Xml_Node_
{
/** In PHP5 this will silence E_STRICT warnings
@ -13,33 +18,46 @@
}
}
/**
* @class XmlParser
* @author NHN (developers@xpressengine.com)
* @brief class parsing a given xmlrpc request and creating a data object
* @version 0.1
*
* @remarks {
* This class may drops unsupported xml lanuage attributes when multiple language attributes are given.
* For example, if 'xml:lang='ko, en, ch, jp..' is given in a xml file, only ko will be left ignoring all other language
* attributes when kor is only supported language. It seems to work fine now but we did not scrutinze any potential side effects,
* }
**/
/**
* XmlParser class
* Class parsing a given xmlrpc request and creating a data object
* @remarks <pre>{
* This class may drops unsupported xml lanuage attributes when multiple language attributes are given.
* For example, if 'xml:lang='ko, en, ch, jp..' is given in a xml file, only ko will be left ignoring all other language
* attributes when kor is only supported language. It seems to work fine now but we did not scrutinze any potential side effects,
* }</pre>
*
* @author NHN (developers@xpressengine.com)
* @package /classes/xml
* @version 0.1
*/
class XmlParser {
/**
* Xml parser
* @var resource
*/
var $oParser = NULL;
/**
* Input xml
* @var string
*/
var $input = NULL;
/**
* Output object in array
* @var array
*/
var $output = array();
/**
* The default language type
* @var string
*/
var $lang = "en";
var $oParser = NULL; ///< xml parser
var $input = NULL; ///< input xml
var $output = array(); ///< output object
var $lang = "en"; // /< The default language type
/**
* @brief load a xml file specified by a filename and parse it to Return the resultant data object
* @param[in] $filename a file path of file
* @return Returns a data object containing data extracted from a xml file or NULL if a specified file does not exist
**/
/**
* Load a xml file specified by a filename and parse it to Return the resultant data object
* @param string $filename a file path of file
* @return array Returns a data object containing data extracted from a xml file or NULL if a specified file does not exist
*/
function loadXmlFile($filename) {
if(!file_exists($filename)) return;
$buff = FileHandler::readFile($filename);
@ -48,11 +66,13 @@
return $oXmlParser->parse($buff);
}
/**
* @brief parse xml data to extract values from it and construct data object
* @param[in] a data buffer containing xml data
* @return Returns a resultant data object or NULL in case of error
**/
/**
* Parse xml data to extract values from it and construct data object
* @param string $input a data buffer containing xml data
* @param mixed $arg1 ???
* @param mixed $arg2 ???
* @return array Returns a resultant data object or NULL in case of error
*/
function parse($input = '', $arg1 = NULL, $arg2 = NULL) {
// Save the compile starting time for debugging
if(__DEBUG__==3) $start = getMicroTime();
@ -67,9 +87,10 @@
// extracts the supported lanuage when xml:lang is used
if(count($matches[1]) && $supported_lang = array_unique($matches[1])) {
$tmpLangList = array_flip($supported_lang);
// if lang of the first log-in user doesn't exist, apply en by default if exists. Otherwise apply the first lang.
if(!in_array($this->lang, $supported_lang)) {
if(in_array('en', $supported_lang)) {
if(!isset($tmpLangList[$this->lang])) {
if(isset($tmpLangList['en'])) {
$this->lang = 'en';
} else {
$this->lang = array_shift($supported_lang);
@ -99,12 +120,13 @@
}
/**
* @brief start element handler.
* @param[in] $parse an instance of parser
* @param[in] $node_name a name of node
* @param[in] $attrs attributes to be set
*/
/**
* Start element handler.
* @param resource $parse an instance of parser
* @param string $node_name a name of node
* @param array $attrs attributes to be set
* @return array
*/
function _tagOpen($parser, $node_name, $attrs) {
$obj = new Xml_Node_();
$obj->node_name = strtolower($node_name);
@ -114,23 +136,24 @@
}
/**
* @brief character data handler
* variable in the last element of this->output
* @param[in] $parse an instance of parser
* @param[in] $body a data to be added
* @remark the first parameter, $parser ought to be remove since it is not used.
*/
/**
* Character data handler
* Variable in the last element of this->output
* @param resource $parse an instance of parser
* @param string $body a data to be added
* @return void
*/
function _tagBody($parser, $body) {
//if(!trim($body)) return;
$this->output[count($this->output)-1]->body .= $body;
}
/**
* @brief end element handler
* @param[in] $parse an instance of parser
* @param[in] $node_name name of xml node
*/
/**
* End element handler
* @param resource $parse an instance of parser
* @param string $node_name name of xml node
* @return void
*/
function _tagClosed($parser, $node_name) {
$node_name = strtolower($node_name);
$cur_obj = array_pop($this->output);
@ -155,10 +178,11 @@
}
}
/**
* @brief method to transfer values in an array to a data object
* @param[in] $arr data array
**/
/**
* Method to transfer values in an array to a data object
* @param array $arr data array
* @return Xml_Node_ object
**/
function _arrToAttrsObj($arr) {
$output = new Xml_Node_();
foreach($arr as $key => $val) {

View file

@ -1,14 +1,4 @@
<?php
/**
* @class NewXmlQueryParser
* @author NHN (developers@xpressengine.com)
* @brief case to parse XE xml query
* @version 0.1
*
* @todo need to support extend query such as subquery, union
* @todo include info about column types for parsing user input
**/
if(!defined('__XE_LOADED_XML_CLASS__')){
define('__XE_LOADED_XML_CLASS__', 1);
@ -21,6 +11,7 @@
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/ColumnTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/SelectColumnTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php');
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php');
@ -43,12 +34,27 @@
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/DefaultValue.class.php');
}
/**
* New XmlQueryParser class
* @author NHN (developers@xpressengine.com)
* @brief case to parse XE xml query
* @version 0.1
*
* @todo need to support extend query such as subquery, union
* @todo include info about column types for parsing user input
*/
class XmlQueryParser extends XmlParser {
/**
* constructor
* @return void
*/
function XmlQueryParser(){
}
/**
* Create XmlQueryParser instance for Singleton
* @return XmlQueryParser object
*/
function &getInstance(){
static $theInstance = null;
if(!isset($theInstance)){
@ -57,6 +63,12 @@
return $theInstance;
}
/**
* 1. Read xml file<br />
* 2. Check the action<br />
* 3. Parsing and write a cache file<br />
* @return QueryParser object
*/
function &parse_xml_query($query_id, $xml_file, $cache_file)
{
// Read xml file
@ -73,11 +85,19 @@
return $parser;
}
/**
* Query XML file parsing
* @return QueryParser object
*/
function parse($query_id = NULL, $xml_file = NULL, $cache_file = NULL)
{
$query_parser = &$this->parse_xml_query($query_id, $xml_file, $cache_file);
$this->parse_xml_query($query_id, $xml_file, $cache_file);
}
/**
* Return XML file content
* @return array|NULL Returns a resultant data object or NULL in case of error
*/
function getXmlFileContent($xml_file){
$buff = FileHandler::readFile($xml_file);
$xml_obj = parent::parse($buff);

View file

@ -1,13 +1,12 @@
<?php
/**
* @class XmlQueryParser
* @author NHN (developers@xpressengine.com)
* @brief case to parse XE xml query
* @version 0.1
* XmlQueryParser
* Case to parse XE xml query
*
* @author NHN (developers@xpressengine.com)
* @version 0.1
* @todo need to support extend query such as subquery, union
**/
*/
class XmlQueryParser extends XmlParser {
var $default_list = array();
@ -15,13 +14,13 @@
var $filter_list = array();
/**
* @brief parse a xml query file and save the result as a new file specified by cache_file
* @param[in] $query_id name of query
* @param[in] $xml_file file path of a xml query file to be loaded
* @param[in] $cache_file file path of a cache file to store resultant php code after parsing xml query
* @return Nothing is requred.
* @remarks {there should be a way to report an error}
**/
* Parse a xml query file and save the result as a new file specified by cache_file
* {there should be a way to report an error}
* @param string $query_id name of query
* @param string $xml_file file path of a xml query file to be loaded
* @param string $cache_file file path of a cache file to store resultant php code after parsing xml query
* @return void Nothing is requred.
*/
function parse($query_id, $xml_file, $cache_file) {
// query xml 파일을 찾아서 파싱, 결과가 없으면 return
$buff = FileHandler::readFile($xml_file);
@ -36,7 +35,8 @@
$id = $id_args[1];
} elseif(count($id_args)==3) {
$target = $id_args[0];
if(!in_array($target, array('modules','addons','widgets'))) return;
$typeList = array('modules'=>1, 'addons'=>1, 'widgets'=>1);
if(!isset($typeList[$target])) return;
$module = $id_args[1];
$id = $id_args[2];
}
@ -53,6 +53,7 @@
if(!$tables) return;
if(!is_array($tables)) $tables = array($tables);
$joinList = array('left join'=>1, 'left outer join'=>1, 'right join'=>1, 'right outer join'=>1);
foreach($tables as $key => $val) {
// 테이블과 alias의 이름을 구함
@ -62,7 +63,7 @@
$output->tables[$alias] = $table_name;
if(in_array($val->attrs->type,array('left join','left outer join','right join','right outer join')) && count($val->conditions)){
if(isset($joinList[$val->attrs->type]) && count($val->conditions)){
$output->left_tables[$alias] = $val->attrs->type;
$left_conditions[$alias] = $val->conditions;
}
@ -260,11 +261,10 @@
}
/**
* @brief transfer given column information to object->columns
* @param[in] column information
* @result Returns $object
* Transfer given column information to object->columns
* @param array $columns column information
* @return object
*/
function _setColumn($columns){
if(!$columns) {
$output->column[] = array("*" => "*");
@ -296,9 +296,9 @@
}
/**
* @brief transfer condition information to $object->conditions
* @param[in] SQL condition information
* @result Returns $output
* Transfer condition information to $object->conditions
* @param object @condition SQL condition information
* @retrun object
*/
function _setConditions($conditions){
// 조건절 정리
@ -339,9 +339,9 @@
}
/**
* @brief transfer condition information to $object->groups
* @param[in] SQL group information
* @result Returns $output
* Transfer condition information to $object->groups
* @param array $group_list SQL group information
* @return object
*/
function _setGroup($group_list){
// group 정리
@ -361,9 +361,9 @@
/**
* @brief transfer pagnation information to $output
* @param[in] $xml_obj xml object containing Navigation information
* @result Returns $output
* Transfer pagnation information to $output
* @param object $xml_obj xml object containing Navigation information
* @return object
*/
function _setNavigation($xml_obj){
$navigation = $xml_obj->query->navigation;
@ -389,10 +389,10 @@
}
/**
* @brief retrieve column information from $output->colums to generate corresponding php code
* @param[in] $column
* @remarks the name of this method is misleading.
* @result Returns string buffer containing php code
* Retrieve column information from $output->colums to generate corresponding php code <br />
* The name of this method is misleading.
* @param array $columns
* @return string buffer containing php code
*/
function _getColumn($columns){
$buff = '';
@ -439,10 +439,10 @@
}
/**
* @brief retrieve condition information from $output->condition to generate corresponding php code
* @param[in] $conditions array containing Query conditions
* @remarks the name of this method is misleading.
* @return Returns string buffer containing php code
* Retrieve condition information from $output->condition to generate corresponding php code
* The name of this method is misleading.
* @param array $conditions array containing Query conditions
* @return string buffer containing php code
*/
function _getConditions($conditions){
$buff = '';
@ -472,21 +472,30 @@
return $buff;
}
/**
* Add argument to $this->args
* @param mixed $args_name argument value
* @return void
*/
function addArguments($args_name)
{
$this->args[] = $args_name;
}
/**
* Get argument from $this->args
* @return mixed
*/
function getArguments()
{
return $this->args;
}
/**
* @brief returns predefined default values correspoding to given parameters
* @param[in] $name
* @param[in] $value
* @return Returns a default value for specified field
* Returns predefined default values correspoding to given parameters
* @param string $name
* @param mixed $value
* @return mixed Returns a default value for specified field
*/
function getDefault($name, $value) {
$db_info = Context::getDBInfo ();

View file

@ -1,9 +1,34 @@
<?php
/**
* DBParser class
* @author NHN (developers@xpressengine.com)
* @package /classes/xml/xmlquery
* @version 0.1
*/
class DBParser {
/**
* Character for escape target value on the left
* @var string
*/
var $escape_char_left;
/**
* Character for escape target value on the right
* @var string
*/
var $escape_char_right;
/**
* Table prefix string
* @var string
*/
var $table_prefix;
/**
* constructor
* @param string $escape_char_left
* @param string $escape_char_right
* @param string $table_prefix
* @return void
*/
function DBParser($escape_char_left, $escape_char_right = "", $table_prefix = "xe_"){
$this->escape_char_left = $escape_char_left;
if ($escape_char_right !== "")$this->escape_char_right = $escape_char_right;
@ -11,33 +36,68 @@
$this->table_prefix = $table_prefix;
}
/**
* Get escape character
* @param string $leftOrRight left or right
* @return string
*/
function getEscapeChar($leftOrRight){
if ($leftOrRight === 'left')return $this->escape_char_left;
else return $this->escape_char_right;
}
/**
* escape the value
* @param mixed $name
* @return string
*/
function escape($name){
return $this->escape_char_left . $name . $this->escape_char_right;
}
/**
* escape the string value
* @param string $name
* @return string
*/
function escapeString($name){
return "'".$this->escapeStringValue($name)."'";
}
/**
* escape the string value
* @param string $value
* @return string
*/
function escapeStringValue($value){
if($value == "*") return $value;
if (is_string($value)) return $value = str_replace("'","''",$value);
return $value;
}
/**
* Return table full name
* @param string $name table name without table prefix
* @return string table full name with table prefix
*/
function parseTableName($name){
return $this->table_prefix . $name;
}
/**
* Return colmun name after escape
* @param string $name column name before escape
* @return string column name after escape
*/
function parseColumnName($name){
return $this->escapeColumn($name);
}
/**
* Escape column
* @param string $column_name
* @return string column name with db name
*/
function escapeColumn($column_name){
if($this->isUnqualifiedColumnName($column_name))
return $this->escape($column_name);
@ -49,11 +109,21 @@
}
}
/**
* Column name is suitable for use in checking
* @param string $column_name
* @return bool
*/
function isUnqualifiedColumnName($column_name){
if(strpos($column_name,'.')===false && strpos($column_name,'(')===false) return true;
return false;
}
/**
* Column name is suitable for use in checking
* @param string $column_name
* @return bool
*/
function isQualifiedColumnName($column_name){
if(strpos($column_name,'.')!==false && strpos($column_name,'(')===false) return true;
return false;
@ -84,6 +154,11 @@
return implode('', $functions);
}
/*
* Checks argument is asterisk
* @param string $column_name
* @return bool
*/
function isStar($column_name){
if(substr($column_name,-1) == '*') return true;
return false;
@ -92,12 +167,19 @@
/*
* Checks to see if expression is an aggregate star function
* like count(*)
* @param string $column_name
* @return bool
*/
function isStarFunction($column_name){
if(strpos($column_name, "(*)")!==false) return true;
return false;
}
/*
* Return column name after escape
* @param string $column_name
* @return string
*/
function escapeColumnExpression($column_name){
if($this->isStar($column_name)) return $column_name;
if($this->isStarFunction($column_name)){
@ -108,4 +190,4 @@
}
}

View file

@ -1,14 +1,34 @@
<?php
/**
* QueryParser class
* @author NHN (developers@xpressengine.com)
* @package /classes/xml/xmlquery
* @version 0.1
*/
class QueryParser {
/**
* QueryTag object
* @var QueryTag object
*/
var $queryTag;
/**
* constructor
* @param object $query
* @param bool $isSubQuery
* @return void
*/
function QueryParser($query = NULL, $isSubQuery = false) {
if ($query)
$this->queryTag = new QueryTag($query, $isSubQuery);
}
/**
* Return table information
* @param object $query_id
* @param bool $table_name
* @return array
*/
function getTableInfo($query_id, $table_name) {
$column_type = array();
$module = '';
@ -20,7 +40,8 @@
$id = $id_args[1];
} elseif (count($id_args) == 3) {
$target = $id_args[0];
if (!in_array($target, array('modules', 'addons', 'widgets')))
$targetList = array('modules'=>1, 'addons'=>1, 'widgets'=>1);
if (!isset($targetList[$target]))
return;
$module = $id_args[1];
$id = $id_args[2];
@ -56,6 +77,10 @@
return $column_type;
}
/**
* Change code string from queryTag object
* @return string
*/
function toString() {
return "<?php if(!defined('__ZBXE__')) exit();\n"
. $this->queryTag->toString()

View file

@ -1,17 +1,57 @@
<?php
/**
* Argument class
* @author NHN (developers@xpressengine.com)
* @package /classes/xml/xmlquery/argument
* @version 0.1
*/
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;
var $uses_default_value; // Check if arg value is user submnitted or default
var $_value; // Caches escaped and toString value so that the parsing won't happen multiple times;
/**
* 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
*/
var $_value; //
/**
* constructor
* @param string $name
* @param mixed $value
* @return void
*/
function Argument($name, $value) {
$this->value = $value;
$this->name = $name;
@ -60,6 +100,11 @@ class Argument {
return $this->value;
}
/**
* mixed value to string
* @param mixed $value
* @return string
*/
function toString($value) {
if (is_array($value)) {
if (count($value) === 0)
@ -71,6 +116,11 @@ class Argument {
return $value;
}
/**
* escape value
* @param mixed $value
* @return mixed
*/
function escapeValue($value) {
$column_type = $this->getType();
if ($column_type == 'column_name') {
@ -80,7 +130,8 @@ class Argument {
if (!isset($value))
return null;
if (in_array($column_type, array('date', 'varchar', 'char', 'text', 'bigtext'))) {
$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 {
@ -106,6 +157,11 @@ class Argument {
return $value;
}
/**
* escape string value
* @param string $value
* @return string
*/
function _escapeStringValue($value) {
$db = &DB::getInstance();
$value = $db->addQuotes($value);
@ -135,6 +191,11 @@ class Argument {
}
}
/**
* check filter by filter type
* @param string $filter_type
* @return void
*/
function checkFilter($filter_type) {
if (isset($this->value) && $this->value != '') {
global $lang;

View file

@ -1,11 +1,28 @@
<?php
/**
* ConditionArgument class
* @author NHN (developers@xpressengine.com)
* @package /classes/xml/xmlquery/argument
* @version 0.1
*/
class ConditionArgument extends Argument {
/**
* Operator keyword. for example 'in', 'notint', 'between'
* @var string
*/
var $operation;
/**
* constructor
* @param string $name
* @param mixed $value
* @param string $operation
* @return void
*/
function ConditionArgument($name, $value, $operation){
if(isset($value) && in_array($operation, array('in', 'notin', 'between')) && !is_array($value) && $value != ''){
$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);
$value = str_replace('\'', '', $value);
$value = explode(',', $value);
@ -14,6 +31,10 @@
$this->operation = $operation;
}
/**
* create condition value. set $this->value
* @return void
*/
function createConditionValue(){
if(!isset($this->value)) return;
@ -57,22 +78,23 @@
if(!is_array($value)) $this->value = array($value);
break;
case 'notin':
case 'not_in':
if(!is_array($value)) $this->value = array($value);
break;
}
}
/**
* Since ConditionArgument is used in WHERE clause,
* where the argument value is compared to a table column,
* it is assumed that all arguments have type. There are cases though
* where the column does not have any type - if it was removed from
* the XML schema for example - see the is_secret column in xe_documents table.
* In this case, the column type is retrieved according to argument
* value type (using the PHP function is_numeric).
*
* @return type string
*/
* Since ConditionArgument is used in WHERE clause,
* where the argument value is compared to a table column,
* it is assumed that all arguments have type. There are cases though
* where the column does not have any type - if it was removed from
* the XML schema for example - see the is_secret column in xe_documents table.
* In this case, the column type is retrieved according to argument
* value type (using the PHP function is_numeric).
*
* @return type string
*/
function getType(){
if($this->type)
{

View file

@ -1,5 +1,10 @@
<?php
/**
* SortArgument class
* @author NHN (developers@xpressengine.com)
* @package /classes/xml/xmlquery/argument
* @version 0.1
*/
class SortArgument extends Argument {
function getValue(){

View file

@ -1,15 +1,53 @@
<?php
/**
* DefaultValue class
* @author NHN (developers@xpressengine.com)
* @package /classes/xml/xmlquery/queryargument
* @version 0.1
*/
class DefaultValue {
/**
* Column name
* @var string
*/
var $column_name;
/**
* Value
* @var mixed
*/
var $value;
/**
* sequnence status
* @var bool
*/
var $is_sequence = false;
/**
* operation status
* @var bool
*/
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;
/**
* 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 = false; ///< Checks if value is plain string or name of XE function (ipaddress, plus, etc).
var $_is_string_from_function = false; //< Checks if value is string resulted from evaluating a piece of PHP code (see $_SERVER[REMOTE_ADDR])
/**
* constructor
* @param string $column_name column name
* @param mixed $value value
* @return void
*/
function DefaultValue($column_name, $value){
$dbParser = &DB::getParser();
$this->column_name = $dbParser->parseColumnName($column_name);

View file

@ -1,15 +1,53 @@
<?php
/**
* QueryArgument class
* @author NHN (developers@xpressengine.com)
* @package /classes/xml/xmlquery/queryargument
* @version 0.1
*/
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
*/
var $ignore_value;
/**
* constructor
* @param object $tag tag object
* @param bool $ignore_value
* @return void
*/
function QueryArgument($tag, $ignore_value = false) {
static $number_of_arguments = 0;
@ -64,6 +102,10 @@ class QueryArgument {
return false;
}
/**
* Change QueryArgument object to string
* @return string
*/
function toString() {
if ($this->isConditionArgument()) {
// Instantiation

View file

@ -1,6 +1,15 @@
<?php
/**
* SortQueryArgument class
* @author NHN (developers@xpressengine.com)
* @package /classes/xml/xmlquery/queryargument
* @version 0.1
*/
class SortQueryArgument extends QueryArgument{
/**
* Change SortQueryArgument object to string
* @return string
*/
function toString(){
$arg = sprintf("\n" . '${\'%s_argument\'} = new SortArgument(\'%s\', %s);' . "\n"
, $this->argument_name

View file

@ -1,16 +1,56 @@
<?php
/**
* QueryArgumentValidator class
* @author NHN (developers@xpressengine.com)
* @package /classes/xml/xmlquery/queryargument/validator
* @version 0.1
*/
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;
/**
* Query argument for validate
* @var QueryArgument object
*/
var $argument;
/**
* constructor
* @param Xml_Node_ $tag tag object by Query xml file parse
* @param QueryArgument $argument
* @return void
*/
function QueryArgumentValidator($tag, $argument){
$this->argument = $argument;
$this->argument_name = $this->argument->getArgumentName();

View file

@ -1,19 +1,28 @@
<?php
/**
* @class ColumnTag
* @author Arnia Software
* @brief Models the <column> tag inside an XML Query file
*
* Since the <column> tag supports different attributes depending on
* the type of query (select, update, insert, delete) this is only
* the base class for the classes that will model each type <column> tag.
/**
* ColumnTag class
* Models the <column> tag inside an XML Query file
* Since the <column> tag supports different attributes depending on
* the type of query (select, update, insert, delete) this is only
* the base class for the classes that will model each type <column> tag.
*
**/
* @author Arnia Software
* @package /classes/xml/xmlquery/tags/column
* @version 0.1
*/
class ColumnTag {
/**
* Column name
* @var string
*/
var $name;
/**
* constructor
* @param string $name
* @return void
*/
function ColumnTag($name){
$this->name = $name;
}
}
}

View file

@ -1,15 +1,24 @@
<?php
/**
* @class InsertColumnTag
* @author Arnia Software
* @brief Models the <column> tag inside an XML Query file whose action is 'insert'
*
**/
/**
* InsertColumnTag
* Models the <column> tag inside an XML Query file whose action is 'insert'
*
* @author Arnia Software
* @package /classes/xml/xmlquery/tags/column
* @version 0.1
*/
class InsertColumnTag extends ColumnTag {
/**
* argument
* @var QueryArgument object
*/
var $argument;
/**
* constructor
* @param object $column
* @return void
*/
function InsertColumnTag($column) {
parent::ColumnTag($column->attrs->name);
$dbParser = DB::getParser();

View file

@ -0,0 +1,31 @@
<?php
/**
* InsertColumnTagWithoutArgument
* Models the <column> tag inside an XML Query file whose action is 'insert-select'
*
* @author Arnia Software
* @package /classes/xml/xmlquery/tags/column
* @version 0.1
*/
class InsertColumnTagWithoutArgument extends ColumnTag {
/**
* constructor
* @param object $column
* @return void
*/
function InsertColumnTagWithoutArgument($column) {
parent::ColumnTag($column->attrs->name);
$dbParser = DB::getParser();
$this->name = $dbParser->parseColumnName($this->name);
}
function getExpressionString(){
return sprintf('new Expression(\'%s\')', $this->name);
}
function getArgument(){
return null;
}
}
?>

View file

@ -1,14 +1,24 @@
<?php
/**
* @class InsertColumnsTag
* @author Arnia Software
* @brief Models the <column> tag inside an XML Query file whose action is 'insert'
*
**/
/**
* InsertColumnsTag class
* Models the <column> tag inside an XML Query file whose action is 'insert'
*
* @author Arnia Software
* @package /classes/xml/xmlquery/tags/column
* @version 0.1
*/
class InsertColumnsTag{
/**
* Column list
* @var array value is InsertColumnTag object
*/
var $columns;
/**
* constructor
* @param array|string $xml_columns
* @return void
*/
function InsertColumnsTag($xml_columns) {
$this->columns = array();
@ -19,10 +29,15 @@
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);
}
}
/**
* InsertColumnTag object to string
* @return string
*/
function toString(){
$output_columns = 'array(' . PHP_EOL;
foreach($this->columns as $column){
@ -33,6 +48,10 @@
return $output_columns;
}
/**
* Return argument list
* @return array
*/
function getArguments(){
$arguments = array();
foreach($this->columns as $column){
@ -43,4 +62,4 @@
}
?>
?>

View file

@ -1,16 +1,29 @@
<?php
/**
* @class SelectColumnTag
* @author Arnia Software
* @brief Models the <column> tag inside an XML Query file whose action is 'select'
*
**/
/**
* SelectColumnTag
* Models the <column> tag inside an XML Query file whose action is 'select'
*
* @author Arnia Software
* @package /classes/xml/xmlquery/tags/column
* @version 0.1
*/
class SelectColumnTag extends ColumnTag{
/**
* alias
* @var string
*/
var $alias;
/**
* click count status
* @var bool
*/
var $click_count;
/**
* constructor
* @param string|object $column
* @return void
*/
function SelectColumnTag($column){
if ($column == "*" || $column->attrs->name == '*')
{
@ -32,6 +45,8 @@
if($this->name == '*') return "new StarExpression()";
if($this->click_count)
return sprintf('new ClickCountExpression(%s, %s, $args->%s)', $this->name, $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) .'\'': '');
}

View file

@ -1,8 +1,23 @@
<?php
/**
* SelectColumnTag class
*
* @author Arnia Software
* @package /classes/xml/xmlquery/tags/column
* @version 0.1
*/
class SelectColumnsTag {
/**
* Column list
* @var array value is SelectColumnTag object
*/
var $columns;
/**
* constructor
* @param Xml_Node_ $xml_columns
* @return void
*/
function SelectColumnsTag($xml_columns_tag){
if (!$xml_columns_tag)
$xml_columns_tag = new Xml_Node_();
@ -35,6 +50,10 @@
}
}
/**
* SelectColumnTag object to string
* @return string
*/
function toString(){
$output_columns = 'array(' . PHP_EOL;
foreach($this->columns as $column){
@ -48,6 +67,10 @@
return $output_columns;
}
/**
* Return argument list
* @return array
*/
function getArguments(){
$arguments = array();
foreach($this->columns as $column){

View file

@ -1,18 +1,29 @@
<?php
/**
* @class UpdateColumnTag
* @author Arnia Software
* @brief Models the <column> tag inside an XML Query file whose action is 'update'
*
**/
/**
* UpdateColumnTag
* Models the <column> tag inside an XML Query file whose action is 'update'
*
* @author Arnia Software
* @package /classes/xml/xmlquery/tags/column
* @version 0.1
*/
class UpdateColumnTag extends ColumnTag {
/**
* argument
* @var QueryArgument object
*/
var $argument;
/**
* default value
* @var string
*/
var $default_value;
/**
* constructor
* @param object $column
* @return void
*/
function UpdateColumnTag($column) {
parent::ColumnTag($column->attrs->name);
$dbParser = DB::getParser();

View file

@ -1,15 +1,24 @@
<?php
/**
* @class UpdateColumnsTag
* @author Arnia Software
* @brief Models the <column> tag inside an XML Query file whose action is 'update'
*
**/
/**
* UpdateColumnsTag
* Models the <column> tag inside an XML Query file whose action is 'update'
*
* @author Arnia Software
* @package /classes/xml/xmlquery/tags/column
* @version 0.1
*/
class UpdateColumnsTag{
/**
* Column list
* @var array value is UpdateColumnTag object
*/
var $columns;
/**
* constructor
* @param array|string $xml_columns
* @return void
*/
function UpdateColumnsTag($xml_columns) {
$this->columns = array();
@ -21,6 +30,10 @@
}
}
/**
* UpdateColumnTag object to string
* @return string
*/
function toString(){
$output_columns = 'array(' . PHP_EOL;
foreach($this->columns as $column){
@ -31,6 +44,10 @@
return $output_columns;
}
/**
* Return argument list
* @return array
*/
function getArguments(){
$arguments = array();
foreach($this->columns as $column){
@ -41,4 +58,4 @@
}
?>
?>

View file

@ -1,9 +1,29 @@
<?php
/**
* ConditionGroupTag class
*
* @author Arnia Software
* @package /classes/xml/xmlquery/tags/condition
* @version 0.1
*/
class ConditionGroupTag {
/**
* condition list
* @var string|array value is ConditionTag object
*/
var $conditions;
/**
* pipe
* @var string
*/
var $pipe;
/**
* constructor
* @param string|array $conditions
* @param string $pipe
* @return void
*/
function ConditionGroupTag($conditions, $pipe = ""){
$this->pipe = $pipe;
@ -19,6 +39,10 @@
return $this->conditions;
}
/**
* ConditionTag object to string
* @return string
*/
function getConditionGroupString(){
$conditions_string = 'array('.PHP_EOL;
foreach($this->conditions as $condition){
@ -39,4 +63,4 @@
}
}
?>
?>

View file

@ -1,22 +1,54 @@
<?php
/**
* @class ConditionTag
* @author Corina
* @brief Models the <condition> tag inside an XML Query file. Base class.
* ConditionTag
* Models the <condition> tag inside an XML Query file. Base class.
*
* @author Corina
* @package /classes/xml/xmlquery/tags/condition
* @version 0.1
*/
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
*/
var $query;
/**
* constructor
* @param object $condition
* @return void
*/
function ConditionTag($condition){
$this->operation = $condition->attrs->operation;
$this->pipe = $condition->attrs->pipe;
@ -38,7 +70,8 @@
}
else {
if(isset($condition->attrs->default)){
if(in_array($this->operation, array('in', 'between', 'not in'))){
$operationList = array('in'=>1, 'between'=>1, 'not in'=>1);
if(isset($operationList[$this->operation])){
$default_value = $condition->attrs->default;
if(strpos($default_value, "'") !== false)
$default_value = "\"" . $default_value . "\"";

View file

@ -1,7 +1,23 @@
<?php
/**
* ConditionsTag class
*
* @author Arnia Software
* @package /classes/xml/xmlquery/tags/condition
* @version 0.1
*/
class ConditionsTag {
/**
* ConditionGroupTag list
* @var array value is ConditionGroupTag object
*/
var $condition_groups;
/**
* constructor
* @param object $xml_conditions
* @return void
*/
function ConditionsTag($xml_conditions){
$this->condition_groups = array();
if (!$xml_conditions)
@ -29,6 +45,10 @@
}
}
/**
* ConditionGroupTag object to string
* @return string
*/
function toString(){
$output_conditions = 'array(' . PHP_EOL;
foreach($this->condition_groups as $condition){

View file

@ -1,11 +1,21 @@
<?php
/**
* JoinConditionsTag class
*
* @author Corina
* @package /classes/xml/xmlquery/tags/condition
* @version 0.1
*/
class JoinConditionsTag extends ConditionsTag {
/**
* constructor
* @param object $xml_conditions
* @return void
*/
function JoinConditionsTag($xml_conditions){
parent::ConditionsTag($xml_conditions);
$this->condition_groups[0]->conditions[0]->setPipe("");
}
}
?>
?>

View file

@ -1,8 +1,23 @@
<?php
/**
* GroupsTag class
*
* @author Arnia Software
* @package /classes/xml/xmlquery/tags/group
* @version 0.1
*/
class GroupsTag {
/**
* column list
* @var array
*/
var $groups;
/**
* constructor
* @param array|string $xml_groups
* @return void
*/
function GroupsTag($xml_groups){
$this->groups = array();

View file

@ -1,12 +1,43 @@
<?php
/**
* IndexTag class
*
* @author Arnia Software
* @package /classes/xml/xmlquery/tags/navigation
* @version 0.1
*/
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
*/
var $sort_order_argument;
/**
* constructor
* @param object $index
* @return void
*/
function IndexTag($index){
$this->argument_name = $index->attrs->var;
@ -18,7 +49,8 @@
// Sort order - asc / desc
$this->sort_order = $index->attrs->order;
if(!in_array($this->sort_order, array("asc", "desc"))){
$sortList = array('asc'=>1, 'desc'=>1);
if(!isset($sortList[$this->sort_order])){
$arg = new Xml_Node_();
$arg->attrs = new Xml_Node_();
$arg->attrs->var = $this->sort_order;

View file

@ -1,11 +1,38 @@
<?php
/**
* LimitTag class
*
* @author Arnia Software
* @package /classes/xml/xmlquery/tags/navigation
* @version 0.1
*/
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
*/
var $list_count;
/**
* constructor
* @param object $index
* @return void
*/
function LimitTag($index){
if($index->page && $index->page->attrs && $index->page_count && $index->page_count->attrs){
$this->page = new QueryArgument($index->page);

View file

@ -1,11 +1,43 @@
<?php
/**
* NavigationTag class
*
* @author Arnia Software
* @package /classes/xml/xmlquery/tags/navigation
* @version 0.1
*/
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
*/
var $limit;
/**
* constructor
* @param object $xml_navigation
* @return void
*/
function NavigationTag($xml_navigation){
$this->order = array();
if($xml_navigation) {
@ -31,6 +63,10 @@
}
}
/**
* NavigationTag object to string
* @return string
*/
function getOrderByString(){
$output = 'array(' . PHP_EOL;
foreach($this->order as $order){
@ -41,6 +77,10 @@
return $output;
}
/**
* LimitTag object to string
* @return string
*/
function getLimitString(){
if ($this->limit) return $this->limit->toString();
else return "";

View file

@ -1,25 +1,104 @@
<?php
/**
* QueryTag class
*
* @author Arnia Software
* @package /classes/xml/xmlquery/tags/query
* @version 0.1
*/
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;
//xml tags
/**
* 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
*/
var $alias;
/**
* constructor
* @param object $query
* @param bool $isSubQuery
* @return void
*/
function QueryTag($query, $isSubQuery = false) {
$this->action = $query->attrs->action;
$this->query_id = $query->attrs->id;
@ -37,9 +116,12 @@ class QueryTag {
$this->getColumns();
$tables = $this->getTables();
$this->setTableColumnTypes($tables);
$this->getSubquery(); // Used for insert-select
$this->getConditions();
$this->getGroups();
$this->getNavigation();
$this->getPrebuff();
$this->getBuff();
}
@ -77,19 +159,20 @@ class QueryTag {
}
}
function getColumns() {
if ($this->action == 'select') {
return $this->columns = new SelectColumnsTag($this->query->columns);
} else if ($this->action == 'insert') {
return $this->columns = new InsertColumnsTag($this->query->columns->column);
} else if ($this->action == 'update') {
return $this->columns = new UpdateColumnsTag($this->query->columns->column);
} else if ($this->action == 'delete') {
return $this->columns = null;
function getColumns(){
if($this->action == 'select'){
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);
}else if($this->action == 'update') {
return $this->columns = new UpdateColumnsTag($this->query->columns->column);
}else if($this->action == 'delete') {
return $this->columns = null;
}
}
function getPrebuff() {
if($this->isSubQuery) return;
// TODO Check if this work with arguments in join clause
$arguments = $this->getArguments();
@ -159,11 +242,13 @@ class QueryTag {
if ($this->columns)
$buff .= '$query->setColumns(' . $this->columns->toString() . ');' . PHP_EOL;
$buff .= '$query->setTables(' . $this->tables->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->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;
$this->buff = $buff;
return $this->buff;
@ -176,7 +261,13 @@ class QueryTag {
return $this->tables = new TablesTag($this->query->tables);
}
function getConditions() {
function getSubquery(){
if($this->query->query){
$this->subquery = new QueryTag($this->query->query, true);
}
}
function getConditions(){
return $this->conditions = new ConditionsTag($this->query->conditions);
}
@ -207,11 +298,13 @@ class QueryTag {
return $this->buff;
}
function getArguments() {
function getArguments(){
$arguments = array();
if ($this->columns)
$arguments = array_merge($arguments, $this->columns->getArguments());
$arguments = array_merge($arguments, $this->tables->getArguments());
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;

View file

@ -1,20 +1,26 @@
<?php
/**
* @class HintTableTag
* @author Arnia Sowftare
* @brief Models the <table> tag inside an XML Query file
* and the corresponding <index_hint> tag
* HintTableTag
* Models the <table> tag inside an XML Query file and the corresponding <index_hint> tag
*
* @author Arnia Sowftare
* @package /classes/xml/xmlquery/tags/table
* @version 0.1
*/
class HintTableTag extends TableTag {
/**
* Action for example, 'select', 'insert', 'delete'...
* @var array
*/
var $index;
/**
* @brief Initialises Table Tag properties
* @param XML <table> tag $table
*/
/**
* constructor
* Initialises Table Tag properties
* @param object $table XML <table> tag
* @param array $index
* @return void
*/
function HintTableTag($table, $index){
parent::TableTag($table);
$this->index = $index;

View file

@ -1,34 +1,62 @@
<?php
/**
* @class TableTag
* @author Arnia Sowftare
* @brief Models the <table> tag inside an XML Query file
* TableTag
* Models the <table> tag inside an XML Query file
* @abstract
* Example
* <table name="modules" />
* <table name="documents" alias="doc" />
* Attributes
* name - name of the table - table prefix will be automatically added
* alias - table alias. If no value is specified, the table name will be set as default alias
* join_type - in case the table is part of a join clause, this specifies the type of join: left, right etc.
* - permitted values: 'left join','left outer join','right join','right outer join'
* Children
* Can have children of type <conditions>
*
* @abstract
* Example
* <table name="modules" />
* <table name="documents" alias="doc" />
* Attributes
* name - name of the table - table prefix will be automatically added
* alias - table alias. If no value is specified, the table name will be set as default alias
* join_type - in case the table is part of a join clause, this specifies the type of join: left, right etc.
* - permitted values: 'left join','left outer join','right join','right outer join'
* Children
* Can have children of type <conditions>
* @author Arnia Sowftare
* @package /classes/xml/xmlquery/tags/table
* @version 0.1
*/
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
*/
var $conditionsTag;
/**
* @brief Initialises Table Tag properties
* @param XML <table> tag $table
*/
/**
* constructor
* Initialises Table Tag properties
* @param object $table XML <table> tag
* @return void
*/
function TableTag($table){
$dbParser = DB::getParser();
@ -47,7 +75,8 @@
}
function isJoinTable(){
if(in_array($this->join_type,array('left join','left outer join','right join','right outer join'))
$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;
}
@ -60,12 +89,12 @@
return $this->unescaped_name;
}
/**
* @brief Returns string for printing in PHP query cache file
* The string contains code for instantiation of either
* a Table or a JoinTable object
* @return string
*/
/**
* Returns string for printing in PHP query cache file
* The string contains code for instantiation of either
* a Table or a JoinTable object
* @return string
*/
function getTableString(){
$dbParser = DB::getParser();

View file

@ -1,24 +1,34 @@
<?php
/**
* @class TablesTag
* @author Arnia Sowftare
* @brief Models the <tables> tag inside an XML Query file
* TablesTag class
* Models the <tables> tag inside an XML Query file
* @abstract
* Example
* <tables>
* <table name="documents" alias="doc" />
* </tables>
* Attributes
* None.
* Children
* Can have children of type <table> or <query>
*
* @abstract
* Example
* <tables>
* <table name="documents" alias="doc" />
* </tables>
* Attributes
* None.
* Children
* Can have children of type <table> or <query>
* @author Arnia Sowftare
* @package /classes/xml/xmlquery/tags/table
* @version 0.1
*/
class TablesTag {
/**
* Table list
* @var array
*/
var $tables;
/**
* constructor
* @param object $xml_tables_tag
* @param object $xml_index_hints_tag
* @return void
*/
function TablesTag($xml_tables_tag, $xml_index_hints_tag = NULL){
$this->tables = array();
@ -42,7 +52,7 @@
$this->tables[] = new QueryTag($tag, true);
}
else {
if(isset($indexes) && $indexes && isset($indexes[$tag->attrs->name]))
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);