mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-17 02:10:02 +09:00
merge from 1.7.3.5(r13153:r13167)
git-svn-id: http://xe-core.googlecode.com/svn/trunk@13168 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
cc47d2b247
commit
2d3f149b5a
2042 changed files with 129266 additions and 126243 deletions
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* GeneralXmlParser class
|
||||
* Generic XML parser for XE
|
||||
|
|
@ -6,7 +7,9 @@
|
|||
* @package /classes/xml
|
||||
* @version 0.1
|
||||
*/
|
||||
class GeneralXmlParser {
|
||||
class GeneralXmlParser
|
||||
{
|
||||
|
||||
/**
|
||||
* result of parse
|
||||
* @var array
|
||||
|
|
@ -14,78 +17,90 @@ class GeneralXmlParser {
|
|||
var $output = array();
|
||||
|
||||
/**
|
||||
* Parse a given input to product a object containing parse values.
|
||||
* @param string $input data to be parsed
|
||||
* @return array|NULL Returns an object containing parsed values or NULL in case of failure
|
||||
*/
|
||||
function parse($input = '') {
|
||||
$oParser = xml_parser_create('UTF-8');
|
||||
xml_set_object($oParser, $this);
|
||||
xml_set_element_handler($oParser, "_tagOpen", "_tagClosed");
|
||||
xml_set_character_data_handler($oParser, "_tagBody");
|
||||
* Parse a given input to product a object containing parse values.
|
||||
* @param string $input data to be parsed
|
||||
* @return array|NULL Returns an object containing parsed values or NULL in case of failure
|
||||
*/
|
||||
function parse($input = '')
|
||||
{
|
||||
$oParser = xml_parser_create('UTF-8');
|
||||
xml_set_object($oParser, $this);
|
||||
xml_set_element_handler($oParser, "_tagOpen", "_tagClosed");
|
||||
xml_set_character_data_handler($oParser, "_tagBody");
|
||||
|
||||
xml_parse($oParser, $input);
|
||||
xml_parser_free($oParser);
|
||||
xml_parse($oParser, $input);
|
||||
xml_parser_free($oParser);
|
||||
|
||||
if(!count($this->output)) return;
|
||||
$this->output = array_shift($this->output);
|
||||
if(!count($this->output))
|
||||
{
|
||||
return;
|
||||
}
|
||||
$this->output = array_shift($this->output);
|
||||
|
||||
return $this->output;
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start element handler
|
||||
* @param resource $parser an instance of parser
|
||||
* @param string $node_name a name of node
|
||||
* @param array $attrs attributes to be set
|
||||
* @return void
|
||||
*/
|
||||
function _tagOpen($parser, $node_name, $attrs) {
|
||||
$obj->node_name = strtolower($node_name);
|
||||
$obj->attrs = $attrs;
|
||||
$obj->childNodes = array();
|
||||
* Start element handler
|
||||
* @param resource $parser an instance of parser
|
||||
* @param string $node_name a name of node
|
||||
* @param array $attrs attributes to be set
|
||||
* @return void
|
||||
*/
|
||||
function _tagOpen($parser, $node_name, $attrs)
|
||||
{
|
||||
$obj->node_name = strtolower($node_name);
|
||||
$obj->attrs = $attrs;
|
||||
$obj->childNodes = array();
|
||||
|
||||
array_push($this->output, $obj);
|
||||
array_push($this->output, $obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Character data handler
|
||||
* Variable in the last element of this->output
|
||||
* @param resource $parse an instance of parser
|
||||
* @param string $body a data to be added
|
||||
* @return void
|
||||
*/
|
||||
function _tagBody($parser, $body) {
|
||||
//if(!trim($body)) return;
|
||||
$this->output[count($this->output)-1]->body .= $body;
|
||||
* Character data handler
|
||||
* Variable in the last element of this->output
|
||||
* @param resource $parse an instance of parser
|
||||
* @param string $body a data to be added
|
||||
* @return void
|
||||
*/
|
||||
function _tagBody($parser, $body)
|
||||
{
|
||||
//if(!trim($body)) return;
|
||||
$this->output[count($this->output) - 1]->body .= $body;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* End element handler
|
||||
* @param resource $parse an instance of parser
|
||||
* @param string $node_name name of xml node
|
||||
* @return void
|
||||
*/
|
||||
function _tagClosed($parser, $node_name) {
|
||||
$node_name = strtolower($node_name);
|
||||
$cur_obj = array_pop($this->output);
|
||||
$parent_obj = &$this->output[count($this->output)-1];
|
||||
* End element handler
|
||||
* @param resource $parse an instance of parser
|
||||
* @param string $node_name name of xml node
|
||||
* @return void
|
||||
*/
|
||||
function _tagClosed($parser, $node_name)
|
||||
{
|
||||
$node_name = strtolower($node_name);
|
||||
$cur_obj = array_pop($this->output);
|
||||
$parent_obj = &$this->output[count($this->output) - 1];
|
||||
|
||||
if($parent_obj->childNodes[$node_name])
|
||||
{
|
||||
$tmp_obj = $parent_obj->childNodes[$node_name];
|
||||
if(is_array($tmp_obj)) {
|
||||
array_push($parent_obj->childNodes[$node_name], $cur_obj);
|
||||
} else {
|
||||
$parent_obj->childNodes[$node_name] = array();
|
||||
array_push($parent_obj->childNodes[$node_name], $tmp_obj);
|
||||
array_push($parent_obj->childNodes[$node_name], $cur_obj);
|
||||
}
|
||||
} else {
|
||||
$parent_obj->childNodes[$node_name] = $cur_obj;
|
||||
}
|
||||
if($parent_obj->childNodes[$node_name])
|
||||
{
|
||||
$tmp_obj = $parent_obj->childNodes[$node_name];
|
||||
if(is_array($tmp_obj))
|
||||
{
|
||||
array_push($parent_obj->childNodes[$node_name], $cur_obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
$parent_obj->childNodes[$node_name] = array();
|
||||
array_push($parent_obj->childNodes[$node_name], $tmp_obj);
|
||||
array_push($parent_obj->childNodes[$node_name], $cur_obj);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$parent_obj->childNodes[$node_name] = $cur_obj;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
/* End of file GeneralXmlParser.class.php */
|
||||
/* Location: ./classes/xml/GeneralXmlParser.class.php */
|
||||
|
|
|
|||
|
|
@ -1,57 +1,75 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* XmlGenerator class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml
|
||||
* @version 0.1
|
||||
*/
|
||||
class XmlGenerator{
|
||||
class XmlGenerator
|
||||
{
|
||||
|
||||
/**
|
||||
* object change to xml
|
||||
* @param object $xml
|
||||
* @return string
|
||||
*/
|
||||
function obj2xml($xml){
|
||||
* object change to xml
|
||||
* @param object $xml
|
||||
* @return string
|
||||
*/
|
||||
function obj2xml($xml)
|
||||
{
|
||||
$buff = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
|
||||
|
||||
foreach($xml as $nodeName => $nodeItem){
|
||||
foreach($xml as $nodeName => $nodeItem)
|
||||
{
|
||||
$buff .= $this->_makexml($nodeItem);
|
||||
}
|
||||
return $buff;
|
||||
}
|
||||
|
||||
/**
|
||||
* object change to xml
|
||||
* @param object $node node in xml object
|
||||
* @return string
|
||||
*/
|
||||
function _makexml($node){
|
||||
* object change to xml
|
||||
* @param object $node node in xml object
|
||||
* @return string
|
||||
*/
|
||||
function _makexml($node)
|
||||
{
|
||||
$body = '';
|
||||
foreach($node as $key => $value){
|
||||
switch($key){
|
||||
foreach($node as $key => $value)
|
||||
{
|
||||
switch($key)
|
||||
{
|
||||
case 'node_name' : break;
|
||||
case 'attrs' : {
|
||||
$attrs = '';
|
||||
if (isset($value)){
|
||||
foreach($value as $attrName=>$attrValue){
|
||||
$attrs .= sprintf(' %s="%s"', $attrName, htmlspecialchars($attrValue));
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 'body' : $body = $value; break;
|
||||
$attrs = '';
|
||||
if(isset($value))
|
||||
{
|
||||
foreach($value as $attrName => $attrValue)
|
||||
{
|
||||
$attrs .= sprintf(' %s="%s"', $attrName, htmlspecialchars($attrValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'body' :
|
||||
$body = $value;
|
||||
break;
|
||||
default : {
|
||||
if (is_array($value)){
|
||||
foreach($value as $idx => $arrNode){
|
||||
$body .= $this->_makexml($arrNode);
|
||||
}
|
||||
}else if(is_object($value)){
|
||||
$body = $this->_makexml($value);
|
||||
}
|
||||
}
|
||||
if(is_array($value))
|
||||
{
|
||||
foreach($value as $idx => $arrNode)
|
||||
{
|
||||
$body .= $this->_makexml($arrNode);
|
||||
}
|
||||
}
|
||||
else if(is_object($value))
|
||||
{
|
||||
$body = $this->_makexml($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return sprintf('<%s%s>%s</%s>'."\n", $node->node_name, $attrs, $body, $node->node_name);
|
||||
return sprintf('<%s%s>%s</%s>' . "\n", $node->node_name, $attrs, $body, $node->node_name);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
}
|
||||
/* End of file XmlGenerator.class.php */
|
||||
/* Location: ./classes/xml/XmlGenerator.class.php */
|
||||
|
|
|
|||
|
|
@ -1,315 +1,431 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* 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" />
|
||||
* </form>
|
||||
* <parameter> "- A form of key = val combination of items to js array return, act required
|
||||
* <param name="key" target="target" />
|
||||
* </parameter>
|
||||
* <response callback_func="specifying the name of js function to callback" > "- Result to get by sending ajax to the server
|
||||
* <tag name="error" /> <- get the result of error name
|
||||
* </response>
|
||||
* </filter>
|
||||
* }</pre>
|
||||
*
|
||||
* @detail
|
||||
* <pre>{
|
||||
* - syntax description of <form> node
|
||||
* target = name of for element
|
||||
* required = flag indicating whether a field is mandatory or not
|
||||
* minlength, maxlength = mininum, maxinum length of string allowed for the field
|
||||
* filter = name of filter to be used for javascript validation. Following is the description of filter available
|
||||
* 1) email : validate the confirmance of the value against an email format
|
||||
* 2) userid : validate the confirmance of the value against the format of user id. (combination of number[0-9],alphabet(lower case) and '_', underscore starting with an alphatic character)
|
||||
* 3) alpha : check if the value is consists of alphabatic characters.
|
||||
* 4) number : check if the value is consists of numerical digits
|
||||
* 5) equalto = target : indicate that values in the form should be equal to those in target
|
||||
* 6) pattern_id/regex pattern/[i] : check the value using custom regular expression.
|
||||
*
|
||||
* - parameter - param
|
||||
* name = key : indicate that a new array, 'key' will be created and a value will be assigned to it
|
||||
* target = target_name: get the value of the target form element
|
||||
*
|
||||
* - response
|
||||
* tag = key : name of variable that will contain the result of the execution
|
||||
* }</pre>
|
||||
* @class XmlJsFilter
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml
|
||||
* @version 0.2
|
||||
*/
|
||||
class XmlJsFilter extends XmlParser
|
||||
{
|
||||
|
||||
/**
|
||||
* filter class traslate xml content into javascript code
|
||||
*
|
||||
* it convert xml code into js file and save the result as a cache file
|
||||
* @code
|
||||
* <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" />
|
||||
* </form>
|
||||
* <parameter> "- A form of key = val combination of items to js array return, act required
|
||||
* <param name="key" target="target" />
|
||||
* </parameter>
|
||||
* <response callback_func="specifying the name of js function to callback" > "- Result to get by sending ajax to the server
|
||||
* <tag name="error" /> <- get the result of error name
|
||||
* </response>
|
||||
* </filter>
|
||||
* }</pre>
|
||||
*
|
||||
* @detail
|
||||
* <pre>{
|
||||
* - syntax description of <form> node
|
||||
* target = name of for element
|
||||
* required = flag indicating whether a field is mandatory or not
|
||||
* minlength, maxlength = mininum, maxinum length of string allowed for the field
|
||||
* filter = name of filter to be used for javascript validation. Following is the description of filter available
|
||||
* 1) email : validate the confirmance of the value against an email format
|
||||
* 2) userid : validate the confirmance of the value against the format of user id. (combination of number[0-9],alphabet(lower case) and '_', underscore starting with an alphatic character)
|
||||
* 3) alpha : check if the value is consists of alphabatic characters.
|
||||
* 4) number : check if the value is consists of numerical digits
|
||||
* 5) equalto = target : indicate that values in the form should be equal to those in target
|
||||
* 6) pattern_id/regex pattern/[i] : check the value using custom regular expression.
|
||||
*
|
||||
* - parameter - param
|
||||
* name = key : indicate that a new array, 'key' will be created and a value will be assigned to it
|
||||
* target = target_name: get the value of the target form element
|
||||
*
|
||||
* - response
|
||||
* tag = key : name of variable that will contain the result of the execution
|
||||
* }</pre>
|
||||
* @class XmlJsFilter
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml
|
||||
* @version 0.2
|
||||
* version
|
||||
* @var string
|
||||
*/
|
||||
class XmlJsFilter extends XmlParser {
|
||||
/**
|
||||
* version
|
||||
* @var string
|
||||
*/
|
||||
var $version = '0.2.5';
|
||||
/**
|
||||
* compiled javascript cache path
|
||||
* @var string
|
||||
*/
|
||||
var $compiled_path = './files/cache/js_filter_compiled/'; // / directory path for compiled cache file
|
||||
/**
|
||||
* Target xml file
|
||||
* @var string
|
||||
*/
|
||||
var $xml_file = NULL;
|
||||
/**
|
||||
* Compiled js file
|
||||
* @var string
|
||||
*/
|
||||
var $js_file = NULL; // /
|
||||
var $version = '0.2.5';
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $path
|
||||
* @param string $xml_file
|
||||
* @return void
|
||||
*/
|
||||
function XmlJsFilter($path, $xml_file) {
|
||||
if(substr($path,-1)!=='/') $path .= '/';
|
||||
$this->xml_file = sprintf("%s%s",$path, $xml_file);
|
||||
$this->js_file = $this->_getCompiledFileName($this->xml_file);
|
||||
/**
|
||||
* compiled javascript cache path
|
||||
* @var string
|
||||
*/
|
||||
var $compiled_path = './files/cache/js_filter_compiled/'; // / directory path for compiled cache file
|
||||
/**
|
||||
* Target xml file
|
||||
* @var string
|
||||
*/
|
||||
var $xml_file = NULL;
|
||||
|
||||
/**
|
||||
* Compiled js file
|
||||
* @var string
|
||||
*/
|
||||
var $js_file = NULL; // /
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $path
|
||||
* @param string $xml_file
|
||||
* @return void
|
||||
*/
|
||||
|
||||
function XmlJsFilter($path, $xml_file)
|
||||
{
|
||||
if(substr($path, -1) !== '/')
|
||||
{
|
||||
$path .= '/';
|
||||
}
|
||||
$this->xml_file = sprintf("%s%s", $path, $xml_file);
|
||||
$this->js_file = $this->_getCompiledFileName($this->xml_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a xml_file only when a corresponding js file does not exists or is outdated
|
||||
* @return void Returns NULL regardless of the success of failure of the operation
|
||||
*/
|
||||
function compile()
|
||||
{
|
||||
if(!file_exists($this->xml_file))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(!file_exists($this->js_file))
|
||||
{
|
||||
$this->_compile();
|
||||
}
|
||||
else if(filemtime($this->xml_file) > filemtime($this->js_file))
|
||||
{
|
||||
$this->_compile();
|
||||
}
|
||||
Context::loadFile(array($this->js_file, 'body', '', null));
|
||||
}
|
||||
|
||||
/**
|
||||
* compile a xml_file into js_file
|
||||
* @return void
|
||||
*/
|
||||
function _compile()
|
||||
{
|
||||
global $lang;
|
||||
|
||||
// read xml file
|
||||
$buff = FileHandler::readFile($this->xml_file);
|
||||
|
||||
// xml parsing
|
||||
$xml_obj = parent::parse($buff);
|
||||
|
||||
$attrs = $xml_obj->filter->attrs;
|
||||
$rules = $xml_obj->filter->rules;
|
||||
|
||||
// XmlJsFilter handles three data; filter_name, field, and parameter
|
||||
$filter_name = $attrs->name;
|
||||
$confirm_msg_code = $attrs->confirm_msg_code;
|
||||
$module = $attrs->module;
|
||||
$act = $attrs->act;
|
||||
$extend_filter = $attrs->extend_filter;
|
||||
|
||||
|
||||
$field_node = $xml_obj->filter->form->node;
|
||||
if($field_node && !is_array($field_node))
|
||||
{
|
||||
$field_node = array($field_node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a xml_file only when a corresponding js file does not exists or is outdated
|
||||
* @return void Returns NULL regardless of the success of failure of the operation
|
||||
*/
|
||||
function compile() {
|
||||
if(!file_exists($this->xml_file)) return;
|
||||
if(!file_exists($this->js_file)) $this->_compile();
|
||||
else if(filemtime($this->xml_file)>filemtime($this->js_file)) $this->_compile();
|
||||
Context::loadFile(array($this->js_file, 'body', '',null));
|
||||
$parameter_param = $xml_obj->filter->parameter->param;
|
||||
if($parameter_param && !is_array($parameter_param))
|
||||
{
|
||||
$parameter_param = array($parameter_param);
|
||||
}
|
||||
|
||||
/**
|
||||
* compile a xml_file into js_file
|
||||
* @return void
|
||||
*/
|
||||
function _compile() {
|
||||
global $lang;
|
||||
$response_tag = $xml_obj->filter->response->tag;
|
||||
if($response_tag && !is_array($response_tag))
|
||||
{
|
||||
$response_tag = array($response_tag);
|
||||
}
|
||||
|
||||
// read xml file
|
||||
$buff = FileHandler::readFile($this->xml_file);
|
||||
// If extend_filter exists, result returned by calling the method
|
||||
if($extend_filter)
|
||||
{
|
||||
// If extend_filter exists, it changes the name of cache not to use cache
|
||||
$this->js_file .= '.nocache.js';
|
||||
|
||||
// xml parsing
|
||||
$xml_obj = parent::parse($buff);
|
||||
// Separate the extend_filter
|
||||
list($module_name, $method) = explode('.', $extend_filter);
|
||||
|
||||
$attrs = $xml_obj->filter->attrs;
|
||||
$rules = $xml_obj->filter->rules;
|
||||
// contibue if both module_name and methos exist.
|
||||
if($module_name && $method)
|
||||
{
|
||||
// get model object of the module
|
||||
$oExtendFilter = getModel($module_name);
|
||||
|
||||
// XmlJsFilter handles three data; filter_name, field, and parameter
|
||||
$filter_name = $attrs->name;
|
||||
$confirm_msg_code = $attrs->confirm_msg_code;
|
||||
$module = $attrs->module;
|
||||
$act = $attrs->act;
|
||||
$extend_filter = $attrs->extend_filter;
|
||||
// execute if method exists
|
||||
if(method_exists($oExtendFilter, $method))
|
||||
{
|
||||
// get the result
|
||||
$extend_filter_list = $oExtendFilter->{$method}(TRUE);
|
||||
$extend_filter_count = count($extend_filter_list);
|
||||
|
||||
|
||||
$field_node = $xml_obj->filter->form->node;
|
||||
if($field_node && !is_array($field_node)) $field_node = array($field_node);
|
||||
|
||||
$parameter_param = $xml_obj->filter->parameter->param;
|
||||
if($parameter_param && !is_array($parameter_param)) $parameter_param = array($parameter_param);
|
||||
|
||||
$response_tag = $xml_obj->filter->response->tag;
|
||||
if($response_tag && !is_array($response_tag)) $response_tag = array($response_tag);
|
||||
|
||||
// If extend_filter exists, result returned by calling the method
|
||||
if($extend_filter) {
|
||||
|
||||
// If extend_filter exists, it changes the name of cache not to use cache
|
||||
$this->js_file .= '.nocache.js';
|
||||
|
||||
// Separate the extend_filter
|
||||
list($module_name, $method) = explode('.',$extend_filter);
|
||||
|
||||
// contibue if both module_name and methos exist.
|
||||
if($module_name&&$method) {
|
||||
// get model object of the module
|
||||
$oExtendFilter = &getModel($module_name);
|
||||
|
||||
// execute if method exists
|
||||
if(method_exists($oExtendFilter, $method)) {
|
||||
// get the result
|
||||
$extend_filter_list = $oExtendFilter->{$method}(true);
|
||||
$extend_filter_count = count($extend_filter_list);
|
||||
|
||||
// apply lang_value from the result to the variable
|
||||
for($i=0; $i < $extend_filter_count; $i++) {
|
||||
$name = $extend_filter_list[$i]->name;
|
||||
$lang_value = $extend_filter_list[$i]->lang;
|
||||
if($lang_value) $lang->{$name} = $lang_value;
|
||||
// apply lang_value from the result to the variable
|
||||
for($i = 0; $i < $extend_filter_count; $i++)
|
||||
{
|
||||
$name = $extend_filter_list[$i]->name;
|
||||
$lang_value = $extend_filter_list[$i]->lang;
|
||||
if($lang_value)
|
||||
{
|
||||
$lang->{$name} = $lang_value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// search the field to be used for entering language
|
||||
$target_list = array();
|
||||
$target_type_list = array();
|
||||
// search the field to be used for entering language
|
||||
$target_list = array();
|
||||
$target_type_list = array();
|
||||
|
||||
// javascript contents
|
||||
$js_rules = array();
|
||||
$js_messages = array();
|
||||
// javascript contents
|
||||
$js_rules = array();
|
||||
$js_messages = array();
|
||||
|
||||
$fields = array();
|
||||
$fields = array();
|
||||
|
||||
// create custom rule
|
||||
if ($rules && $rules->rule) {
|
||||
if (!is_array($rules->rule)) $rules->rule = array($rules->rule);
|
||||
foreach($rules->rule as $r) {
|
||||
if ($r->attrs->type == 'regex') {
|
||||
$js_rules[] = "v.cast('ADD_RULE', ['{$r->attrs->name}', {$r->body}]);";
|
||||
}
|
||||
// create custom rule
|
||||
if($rules && $rules->rule)
|
||||
{
|
||||
if(!is_array($rules->rule))
|
||||
{
|
||||
$rules->rule = array($rules->rule);
|
||||
}
|
||||
foreach($rules->rule as $r)
|
||||
{
|
||||
if($r->attrs->type == 'regex')
|
||||
{
|
||||
$js_rules[] = "v.cast('ADD_RULE', ['{$r->attrs->name}', {$r->body}]);";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// generates a field, which is a script of the checked item
|
||||
$node_count = count($field_node);
|
||||
if($node_count) {
|
||||
foreach($field_node as $key =>$node) {
|
||||
$attrs = $node->attrs;
|
||||
$target = trim($attrs->target);
|
||||
// generates a field, which is a script of the checked item
|
||||
$node_count = count($field_node);
|
||||
if($node_count)
|
||||
{
|
||||
foreach($field_node as $key => $node)
|
||||
{
|
||||
$attrs = $node->attrs;
|
||||
$target = trim($attrs->target);
|
||||
|
||||
if(!$target) continue;
|
||||
if(!$target)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$rule = trim($attrs->rule?$attrs->rule:$attrs->filter);
|
||||
$equalto = trim($attrs->equalto);
|
||||
$rule = trim($attrs->rule ? $attrs->rule : $attrs->filter);
|
||||
$equalto = trim($attrs->equalto);
|
||||
|
||||
$field = array();
|
||||
$field = array();
|
||||
|
||||
if($attrs->required == 'true') $field[] = 'required:true';
|
||||
if($attrs->minlength > 0) $field[] = 'minlength:'.$attrs->minlength;
|
||||
if($attrs->maxlength > 0) $field[] = 'maxlength:'.$attrs->maxlength;
|
||||
if($equalto) $field[] = "equalto:'{$attrs->equalto}'";
|
||||
if($rule) $field[] = "rule:'{$rule}'";
|
||||
if($attrs->required == 'true')
|
||||
{
|
||||
$field[] = 'required:true';
|
||||
}
|
||||
if($attrs->minlength > 0)
|
||||
{
|
||||
$field[] = 'minlength:' . $attrs->minlength;
|
||||
}
|
||||
if($attrs->maxlength > 0)
|
||||
{
|
||||
$field[] = 'maxlength:' . $attrs->maxlength;
|
||||
}
|
||||
if($equalto)
|
||||
{
|
||||
$field[] = "equalto:'{$attrs->equalto}'";
|
||||
}
|
||||
if($rule)
|
||||
{
|
||||
$field[] = "rule:'{$rule}'";
|
||||
}
|
||||
|
||||
$fields[] = "'{$target}': {".implode(',', $field)."}";
|
||||
$fields[] = "'{$target}': {" . implode(',', $field) . "}";
|
||||
|
||||
if(!in_array($target, $target_list)) $target_list[] = $target;
|
||||
if(!$target_type_list[$target]) $target_type_list[$target] = $filter;
|
||||
if(!in_array($target, $target_list))
|
||||
{
|
||||
$target_list[] = $target;
|
||||
}
|
||||
if(!$target_type_list[$target])
|
||||
{
|
||||
$target_type_list[$target] = $filter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check extend_filter_item
|
||||
$rule_types = array('homepage' => 'homepage', 'email_address' => 'email');
|
||||
|
||||
for($i = 0; $i < $extend_filter_count; $i++)
|
||||
{
|
||||
$filter_item = $extend_filter_list[$i];
|
||||
$target = trim($filter_item->name);
|
||||
|
||||
if(!$target)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// get the filter from the type of extend filter item
|
||||
$type = $filter_item->type;
|
||||
$rule = $rule_types[$type] ? $rule_types[$type] : '';
|
||||
$required = ($filter_item->required == 'true');
|
||||
|
||||
$field = array();
|
||||
if($required)
|
||||
{
|
||||
$field[] = 'required:true';
|
||||
}
|
||||
if($rule)
|
||||
{
|
||||
$field[] = "rule:'{$rule}'";
|
||||
}
|
||||
$fields[] = "\t\t'{$target}' : {" . implode(',', $field) . "}";
|
||||
|
||||
if(!in_array($target, $target_list))
|
||||
{
|
||||
$target_list[] = $target;
|
||||
}
|
||||
if(!$target_type_list[$target])
|
||||
{
|
||||
$target_type_list[$target] = $type;
|
||||
}
|
||||
}
|
||||
|
||||
// generates parameter script to create dbata
|
||||
$rename_params = array();
|
||||
$parameter_count = count($parameter_param);
|
||||
if($parameter_count)
|
||||
{
|
||||
// contains parameter of the default filter contents
|
||||
foreach($parameter_param as $key => $param)
|
||||
{
|
||||
$attrs = $param->attrs;
|
||||
$name = trim($attrs->name);
|
||||
$target = trim($attrs->target);
|
||||
|
||||
//if($name && $target && ($name != $target)) $js_doc[] = "\t\tparams['{$name}'] = params['{$target}']; delete params['{$target}'];";
|
||||
if($name && $target && ($name != $target))
|
||||
{
|
||||
$rename_params[] = "'{$target}':'{$name}'";
|
||||
}
|
||||
if($name && !in_array($name, $target_list))
|
||||
{
|
||||
$target_list[] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
// Check extend_filter_item
|
||||
$rule_types = array('homepage'=>'homepage', 'email_address'=>'email');
|
||||
|
||||
for($i=0;$i<$extend_filter_count;$i++) {
|
||||
for($i = 0; $i < $extend_filter_count; $i++)
|
||||
{
|
||||
$filter_item = $extend_filter_list[$i];
|
||||
$target = trim($filter_item->name);
|
||||
|
||||
if(!$target) continue;
|
||||
|
||||
// get the filter from the type of extend filter item
|
||||
$type = $filter_item->type;
|
||||
$rule = $rule_types[$type]?$rule_types[$type]:'';
|
||||
$required = ($filter_item->required == 'true');
|
||||
|
||||
$field = array();
|
||||
if($required) $field[] = 'required:true';
|
||||
if($rule) $field[] = "rule:'{$rule}'";
|
||||
$fields[] = "\t\t'{$target}' : {".implode(',', $field)."}";
|
||||
|
||||
if(!in_array($target, $target_list)) $target_list[] = $target;
|
||||
if(!$target_type_list[$target]) $target_type_list[$target] = $type;
|
||||
}
|
||||
|
||||
// generates parameter script to create dbata
|
||||
$rename_params = array();
|
||||
$parameter_count = count($parameter_param);
|
||||
if($parameter_count) {
|
||||
// contains parameter of the default filter contents
|
||||
foreach($parameter_param as $key =>$param) {
|
||||
$attrs = $param->attrs;
|
||||
$name = trim($attrs->name);
|
||||
$target = trim($attrs->target);
|
||||
|
||||
//if($name && $target && ($name != $target)) $js_doc[] = "\t\tparams['{$name}'] = params['{$target}']; delete params['{$target}'];";
|
||||
if($name && $target && ($name != $target)) $rename_params[] = "'{$target}':'{$name}'";
|
||||
if($name && !in_array($name, $target_list)) $target_list[] = $name;
|
||||
$target = $name = trim($filter_item->name);
|
||||
if(!$name || !$target)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check extend_filter_item
|
||||
for($i=0;$i<$extend_filter_count;$i++) {
|
||||
$filter_item = $extend_filter_list[$i];
|
||||
$target = $name = trim($filter_item->name);
|
||||
if(!$name || !$target) continue;
|
||||
|
||||
if(!in_array($name, $target_list)) $target_list[] = $name;
|
||||
if(!in_array($name, $target_list))
|
||||
{
|
||||
$target_list[] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
// generates the response script
|
||||
$response_count = count($response_tag);
|
||||
$responses = array();
|
||||
for($i=0;$i<$response_count;$i++) {
|
||||
$attrs = $response_tag[$i]->attrs;
|
||||
$name = $attrs->name;
|
||||
$responses[] = "'{$name}'";
|
||||
}
|
||||
|
||||
// writes lang values of the form field
|
||||
$target_count = count($target_list);
|
||||
for($i=0;$i<$target_count;$i++) {
|
||||
$target = $target_list[$i];
|
||||
if(!$lang->{$target}) $lang->{$target} = $target;
|
||||
$text = preg_replace('@\r?\n@', '\\n', addslashes($lang->{$target}));
|
||||
$js_messages[] = "v.cast('ADD_MESSAGE',['{$target}','{$text}']);";
|
||||
}
|
||||
|
||||
// writes the target type
|
||||
/*
|
||||
$target_type_count = count($target_type_list);
|
||||
if($target_type_count) {
|
||||
foreach($target_type_list as $target => $type) {
|
||||
//$js_doc .= sprintf("target_type_list[\"%s\"] = \"%s\";\n", $target, $type);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// writes error messages
|
||||
foreach($lang->filter as $key => $val) {
|
||||
if(!$val) $val = $key;
|
||||
$val = preg_replace('@\r?\n@', '\\n', addslashes($val));
|
||||
$js_messages[] = sprintf("v.cast('ADD_MESSAGE',['%s','%s']);", $key, $val);
|
||||
}
|
||||
|
||||
$callback_func = $xml_obj->filter->response->attrs->callback_func;
|
||||
if(!$callback_func) $callback_func = "filterAlertMessage";
|
||||
|
||||
$confirm_msg = '';
|
||||
if ($confirm_msg_code) $confirm_msg = $lang->{$confirm_msg_code};
|
||||
|
||||
$jsdoc = array();
|
||||
$jsdoc[] = "function {$filter_name}(form){ return legacy_filter('{$filter_name}', form, '{$module}', '{$act}', {$callback_func}, [".implode(',', $responses)."], '".addslashes($confirm_msg)."', {".implode(',', $rename_params)."}) };";
|
||||
$jsdoc[] = '(function($){';
|
||||
$jsdoc[] = "\tvar v=xe.getApp('validator')[0];if(!v)return false;";
|
||||
$jsdoc[] = "\t".'v.cast("ADD_FILTER", ["'.$filter_name.'", {'.implode(',', $fields).'}]);';
|
||||
$jsdoc[] = "\t".implode("\n\t", $js_rules);
|
||||
$jsdoc[] = "\t".implode("\n\t", $js_messages);
|
||||
$jsdoc[] = '})(jQuery);';
|
||||
$jsdoc = implode("\n", $jsdoc);
|
||||
|
||||
// generates the js file
|
||||
FileHandler::writeFile($this->js_file, $jsdoc);
|
||||
}
|
||||
|
||||
/**
|
||||
* return a file name of js file corresponding to the xml file
|
||||
* @param string $xml_file
|
||||
* @return string
|
||||
**/
|
||||
function _getCompiledFileName($xml_file) {
|
||||
return sprintf('%s%s.%s.compiled.js',$this->compiled_path, md5($this->version.$xml_file),Context::getLangType());
|
||||
// generates the response script
|
||||
$response_count = count($response_tag);
|
||||
$responses = array();
|
||||
for($i = 0; $i < $response_count; $i++)
|
||||
{
|
||||
$attrs = $response_tag[$i]->attrs;
|
||||
$name = $attrs->name;
|
||||
$responses[] = "'{$name}'";
|
||||
}
|
||||
|
||||
// writes lang values of the form field
|
||||
$target_count = count($target_list);
|
||||
for($i = 0; $i < $target_count; $i++)
|
||||
{
|
||||
$target = $target_list[$i];
|
||||
if(!$lang->{$target})
|
||||
{
|
||||
$lang->{$target} = $target;
|
||||
}
|
||||
$text = preg_replace('@\r?\n@', '\\n', addslashes($lang->{$target}));
|
||||
$js_messages[] = "v.cast('ADD_MESSAGE',['{$target}','{$text}']);";
|
||||
}
|
||||
|
||||
// writes the target type
|
||||
/*
|
||||
$target_type_count = count($target_type_list);
|
||||
if($target_type_count) {
|
||||
foreach($target_type_list as $target => $type) {
|
||||
//$js_doc .= sprintf("target_type_list[\"%s\"] = \"%s\";\n", $target, $type);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// writes error messages
|
||||
foreach($lang->filter as $key => $val)
|
||||
{
|
||||
if(!$val)
|
||||
{
|
||||
$val = $key;
|
||||
}
|
||||
$val = preg_replace('@\r?\n@', '\\n', addslashes($val));
|
||||
$js_messages[] = sprintf("v.cast('ADD_MESSAGE',['%s','%s']);", $key, $val);
|
||||
}
|
||||
|
||||
$callback_func = $xml_obj->filter->response->attrs->callback_func;
|
||||
if(!$callback_func)
|
||||
{
|
||||
$callback_func = "filterAlertMessage";
|
||||
}
|
||||
|
||||
$confirm_msg = '';
|
||||
if($confirm_msg_code)
|
||||
{
|
||||
$confirm_msg = $lang->{$confirm_msg_code};
|
||||
}
|
||||
|
||||
$jsdoc = array();
|
||||
$jsdoc[] = "function {$filter_name}(form){ return legacy_filter('{$filter_name}', form, '{$module}', '{$act}', {$callback_func}, [" . implode(',', $responses) . "], '" . addslashes($confirm_msg) . "', {" . implode(',', $rename_params) . "}) };";
|
||||
$jsdoc[] = '(function($){';
|
||||
$jsdoc[] = "\tvar v=xe.getApp('validator')[0];if(!v)return false;";
|
||||
$jsdoc[] = "\t" . 'v.cast("ADD_FILTER", ["' . $filter_name . '", {' . implode(',', $fields) . '}]);';
|
||||
$jsdoc[] = "\t" . implode("\n\t", $js_rules);
|
||||
$jsdoc[] = "\t" . implode("\n\t", $js_messages);
|
||||
$jsdoc[] = '})(jQuery);';
|
||||
$jsdoc = implode("\n", $jsdoc);
|
||||
|
||||
// generates the js file
|
||||
FileHandler::writeFile($this->js_file, $jsdoc);
|
||||
}
|
||||
?>
|
||||
|
||||
/**
|
||||
* return a file name of js file corresponding to the xml file
|
||||
* @param string $xml_file
|
||||
* @return string
|
||||
*/
|
||||
function _getCompiledFileName($xml_file)
|
||||
{
|
||||
return sprintf('%s%s.%s.compiled.js', $this->compiled_path, md5($this->version . $xml_file), Context::getLangType());
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file XmlJsFilter.class.php */
|
||||
/* Location: ./classes/xml/XmlJsFilter.class.php */
|
||||
|
|
|
|||
|
|
@ -1,198 +1,279 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* XmlLangParser class
|
||||
* Change to lang php file from xml.
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml
|
||||
* @version 0.1
|
||||
*/
|
||||
class XmlLangParser extends XmlParser
|
||||
{
|
||||
|
||||
/**
|
||||
* XmlLangParser class
|
||||
* Change to lang php file from xml.
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @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
|
||||
/**
|
||||
* 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;
|
||||
* compiled language cache path
|
||||
* @var string
|
||||
*/
|
||||
var $compiled_path = './files/cache/lang/'; // / directory path for compiled cache file
|
||||
/**
|
||||
* Target xml file
|
||||
* @var string
|
||||
*/
|
||||
var $xml_file = NULL;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $xml_file
|
||||
* @param string $lang_type
|
||||
* @return void
|
||||
*/
|
||||
function XmlLangParser($xml_file, $lang_type) {
|
||||
$this->lang_type = $lang_type;
|
||||
$this->xml_file = $xml_file;
|
||||
$this->php_file = $this->_getCompiledFileName($lang_type);
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $xml_file
|
||||
* @param string $lang_type
|
||||
* @return void
|
||||
*/
|
||||
function XmlLangParser($xml_file, $lang_type)
|
||||
{
|
||||
$this->lang_type = $lang_type;
|
||||
$this->xml_file = $xml_file;
|
||||
$this->php_file = $this->_getCompiledFileName($lang_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* compile a xml_file only when a corresponding php lang file does not exists or is outdated
|
||||
* @return string|bool Returns compiled php file.
|
||||
*/
|
||||
function compile()
|
||||
{
|
||||
if(!file_exists($this->xml_file))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* compile a xml_file only when a corresponding php lang file does not exists or is outdated
|
||||
* @return string|bool Returns compiled php file.
|
||||
*/
|
||||
function compile() {
|
||||
if(!file_exists($this->xml_file)) return false;
|
||||
if(!file_exists($this->php_file)){
|
||||
$this->_compile();
|
||||
} else {
|
||||
if(filemtime($this->xml_file)>filemtime($this->php_file)) $this->_compile();
|
||||
else return $this->php_file;
|
||||
}
|
||||
|
||||
return $this->_writeFile() ? $this->php_file : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return compiled content
|
||||
* @return string Returns compiled lang source code
|
||||
*/
|
||||
function getCompileContent() {
|
||||
if(!file_exists($this->xml_file)) return false;
|
||||
if(!file_exists($this->php_file))
|
||||
{
|
||||
$this->_compile();
|
||||
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a xml_file
|
||||
* @return void
|
||||
*/
|
||||
function _compile() {
|
||||
$lang_selected = Context::loadLangSelected();
|
||||
$this->lang_types = array_keys($lang_selected);
|
||||
|
||||
// read xml file
|
||||
$buff = FileHandler::readFile($this->xml_file);
|
||||
$buff = str_replace('xml:lang','xml_lang',$buff);
|
||||
|
||||
// xml parsing
|
||||
$xml_obj = parent::parse($buff);
|
||||
|
||||
$item = $xml_obj->lang->item;
|
||||
if(!is_array($item)) $item = array($item);
|
||||
foreach($item as $i){
|
||||
$this->_parseItem($i, $var='$lang->%s');
|
||||
else
|
||||
{
|
||||
if(filemtime($this->xml_file) > filemtime($this->php_file))
|
||||
{
|
||||
$this->_compile();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->php_file;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writing cache file
|
||||
* @return void|bool
|
||||
*/
|
||||
function _writeFile(){
|
||||
if(!$this->code) return;
|
||||
FileHandler::writeFile($this->php_file, "<?php\n".$this->code);
|
||||
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();
|
||||
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a xml_file
|
||||
* @return void
|
||||
*/
|
||||
function _compile()
|
||||
{
|
||||
$lang_selected = Context::loadLangSelected();
|
||||
$this->lang_types = array_keys($lang_selected);
|
||||
|
||||
// read xml file
|
||||
$buff = FileHandler::readFile($this->xml_file);
|
||||
$buff = str_replace('xml:lang', 'xml_lang', $buff);
|
||||
|
||||
// xml parsing
|
||||
$xml_obj = parent::parse($buff);
|
||||
|
||||
$item = $xml_obj->lang->item;
|
||||
if(!is_array($item))
|
||||
{
|
||||
$item = array($item);
|
||||
}
|
||||
foreach($item as $i)
|
||||
{
|
||||
$this->_parseItem($i, $var = '$lang->%s');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writing cache file
|
||||
* @return void|bool
|
||||
*/
|
||||
function _writeFile()
|
||||
{
|
||||
if(!$this->code)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FileHandler::writeFile($this->php_file, "<?php\n" . $this->code);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsing item node, set content to '$this->code'
|
||||
* @param object $item
|
||||
* @param string $var
|
||||
* @return void
|
||||
*/
|
||||
function _parseItem($item, $var)
|
||||
{
|
||||
$name = $item->attrs->name;
|
||||
$value = $item->value;
|
||||
$var = sprintf($var, $name);
|
||||
|
||||
if($item->item)
|
||||
{
|
||||
$type = $item->attrs->type;
|
||||
$mode = $item->attrs->mode;
|
||||
|
||||
if($type == 'array')
|
||||
{
|
||||
$this->code .= "if(!is_array({$var})){\n";
|
||||
$this->code .= " {$var} = array();\n";
|
||||
$this->code .= "}\n";
|
||||
$var .= '[\'%s\']';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->code .= "if(!is_object({$var})){\n";
|
||||
$this->code .= " {$var} = new stdClass();\n";
|
||||
$this->code .= "}\n";
|
||||
$var .= '->%s';
|
||||
}
|
||||
|
||||
$items = $item->item;
|
||||
if(!is_array($items))
|
||||
{
|
||||
$items = array($items);
|
||||
}
|
||||
foreach($items as $item)
|
||||
{
|
||||
$this->_parseItem($item, $var);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$code = $this->_parseValues($value, $var);
|
||||
$this->code .= $code;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsing value nodes
|
||||
* @param array $nodes
|
||||
* @param string $var
|
||||
* @return array|string
|
||||
*/
|
||||
function _parseValues($nodes, $var)
|
||||
{
|
||||
if(!is_array($nodes))
|
||||
{
|
||||
$nodes = array($nodes);
|
||||
}
|
||||
|
||||
$value = array();
|
||||
foreach($nodes as $node)
|
||||
{
|
||||
$return = $this->_parseValue($node, $var);
|
||||
if($return && is_array($return))
|
||||
{
|
||||
$value = array_merge($value, $return);
|
||||
}
|
||||
}
|
||||
|
||||
if($value[$this->lang_type])
|
||||
{
|
||||
return $value[$this->lang_type];
|
||||
}
|
||||
else if($value['en'])
|
||||
{
|
||||
return $value['en'];
|
||||
}
|
||||
else if($value['ko'])
|
||||
{
|
||||
return $value['ko'];
|
||||
}
|
||||
|
||||
foreach($this->lang_types as $lang_type)
|
||||
{
|
||||
if($lang_type == 'en' || $lang_type == 'ko' || $lang_type == $this->lang_type)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if($value[$lang_type])
|
||||
{
|
||||
return $value[$lang_type];
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsing value node
|
||||
* @param object $node
|
||||
* @param string $var
|
||||
* @return array|bool
|
||||
*/
|
||||
function _parseValue($node, $var)
|
||||
{
|
||||
$lang_type = $node->attrs->xml_lang;
|
||||
$value = $node->body;
|
||||
if(!$value)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsing item node, set content to '$this->code'
|
||||
* @param object $item
|
||||
* @param string $var
|
||||
* @return void
|
||||
*/
|
||||
function _parseItem($item, $var){
|
||||
$name = $item->attrs->name;
|
||||
$value = $item->value;
|
||||
$var = sprintf($var, $name);
|
||||
|
||||
if($item->item) {
|
||||
$type = $item->attrs->type;
|
||||
|
||||
if($type == 'array'){
|
||||
$this->code .= $var."=array();\n";
|
||||
$var .= '[\'%s\']';
|
||||
}else{
|
||||
$this->code .= $var."=new stdClass;\n";
|
||||
$var .= '->%s';
|
||||
}
|
||||
|
||||
$items = $item->item;
|
||||
if(!is_array($items)) $items = array($items);
|
||||
foreach($items as $item){
|
||||
$this->_parseItem($item, $var);
|
||||
}
|
||||
|
||||
} else {
|
||||
$code = $this->_parseValues($value, $var);
|
||||
$this->code .= $code;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsing value nodes
|
||||
* @param array $nodes
|
||||
* @param string $var
|
||||
* @return array|string
|
||||
*/
|
||||
function _parseValues($nodes, $var) {
|
||||
if(!is_array($nodes)) $nodes = array($nodes);
|
||||
|
||||
$value = array();
|
||||
foreach($nodes as $node){
|
||||
$return = $this->_parseValue($node, $var);
|
||||
if($return && is_array($return)) $value = array_merge($value, $return);
|
||||
}
|
||||
|
||||
if($value[$this->lang_type]) return $value[$this->lang_type];
|
||||
else if($value['en']) return $value['en'];
|
||||
else if($value['ko']) return $value['ko'];
|
||||
|
||||
foreach($this->lang_types as $lang_type) {
|
||||
if($lang_type == 'en' || $lang_type == 'ko' || $lang_type == $this->lang_type) continue;
|
||||
if($value[$lang_type]) return $value[$lang_type];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsing value node
|
||||
* @param object $node
|
||||
* @param string $var
|
||||
* @return array|bool
|
||||
*/
|
||||
function _parseValue($node, $var) {
|
||||
$lang_type = $node->attrs->xml_lang;
|
||||
$value = $node->body;
|
||||
if(!$value) return false;
|
||||
|
||||
$var .= '=\'' . str_replace("'","\'",$value) . "';\n";
|
||||
return array($lang_type=>$var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cache file name
|
||||
* @param string $lang_type
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
function _getCompiledFileName($lang_type, $type='php') {
|
||||
return sprintf('%s%s.%s.php',$this->compiled_path, md5($this->xml_file), $lang_type);
|
||||
}
|
||||
$var .= '=\'' . str_replace("'", "\'", $value) . "';\n";
|
||||
return array($lang_type => $var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cache file name
|
||||
* @param string $lang_type
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
function _getCompiledFileName($lang_type, $type = 'php')
|
||||
{
|
||||
return sprintf('%s%s.%s.php', $this->compiled_path, md5($this->xml_file), $lang_type);
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file XmlLangParser.class.php */
|
||||
/* Location: ./classes/xml/XmlLangParser.class.php */
|
||||
|
|
|
|||
|
|
@ -1,195 +1,243 @@
|
|||
<?php
|
||||
/**
|
||||
* Xml_Node_ class
|
||||
* Element node or attribute node.
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml
|
||||
* @version 0.1
|
||||
*/
|
||||
class Xml_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
|
||||
* for undeclared properties.
|
||||
* No effect in PHP4
|
||||
*/
|
||||
function __get($name)
|
||||
{
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Xml parser
|
||||
* @var resource
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
/**
|
||||
* Input xml
|
||||
* @var string
|
||||
*/
|
||||
var $input = NULL;
|
||||
|
||||
$oXmlParser = new XmlParser();
|
||||
return $oXmlParser->parse($buff);
|
||||
}
|
||||
/**
|
||||
* Output object in array
|
||||
* @var array
|
||||
*/
|
||||
var $output = array();
|
||||
|
||||
/**
|
||||
* 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();
|
||||
/**
|
||||
* The default language type
|
||||
* @var string
|
||||
*/
|
||||
var $lang = "en";
|
||||
|
||||
$this->lang = Context::getLangType();
|
||||
/**
|
||||
* 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);
|
||||
|
||||
$this->input = $input?$input:$GLOBALS['HTTP_RAW_POST_DATA'];
|
||||
$this->input = str_replace(array('',''),array('',''),$this->input);
|
||||
$oXmlParser = new XmlParser();
|
||||
return $oXmlParser->parse($buff);
|
||||
}
|
||||
|
||||
// extracts a supported language
|
||||
preg_match_all("/xml:lang=\"([^\"].+)\"/i", $this->input, $matches);
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
// extracts the supported lanuage when xml:lang is used
|
||||
if(count($matches[1]) && $supported_lang = array_unique($matches[1])) {
|
||||
$tmpLangList = array_flip($supported_lang);
|
||||
// if lang of the first log-in user doesn't exist, apply en by default if exists. Otherwise apply the first lang.
|
||||
if(!isset($tmpLangList[$this->lang])) {
|
||||
if(isset($tmpLangList['en'])) {
|
||||
$this->lang = 'en';
|
||||
} else {
|
||||
$this->lang = array_shift($supported_lang);
|
||||
}
|
||||
}
|
||||
// uncheck the language if no specific language is set.
|
||||
} else {
|
||||
$this->lang = '';
|
||||
}
|
||||
$this->lang = Context::getLangType();
|
||||
|
||||
$this->oParser = xml_parser_create('UTF-8');
|
||||
$this->input = $input ? $input : $GLOBALS['HTTP_RAW_POST_DATA'];
|
||||
$this->input = str_replace(array('', ''), array('', ''), $this->input);
|
||||
|
||||
xml_set_object($this->oParser, $this);
|
||||
xml_set_element_handler($this->oParser, "_tagOpen", "_tagClosed");
|
||||
xml_set_character_data_handler($this->oParser, "_tagBody");
|
||||
// extracts a supported language
|
||||
preg_match_all("/xml:lang=\"([^\"].+)\"/i", $this->input, $matches);
|
||||
|
||||
xml_parse($this->oParser, $this->input);
|
||||
xml_parser_free($this->oParser);
|
||||
// extracts the supported lanuage when xml:lang is used
|
||||
if(count($matches[1]) && $supported_lang = array_unique($matches[1]))
|
||||
{
|
||||
$tmpLangList = array_flip($supported_lang);
|
||||
// if lang of the first log-in user doesn't exist, apply en by default if exists. Otherwise apply the first lang.
|
||||
if(!isset($tmpLangList[$this->lang]))
|
||||
{
|
||||
if(isset($tmpLangList['en']))
|
||||
{
|
||||
$this->lang = 'en';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->lang = array_shift($supported_lang);
|
||||
}
|
||||
}
|
||||
// uncheck the language if no specific language is set.
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->lang = '';
|
||||
}
|
||||
|
||||
if(!count($this->output)) return;
|
||||
$this->oParser = xml_parser_create('UTF-8');
|
||||
|
||||
$output = array_shift($this->output);
|
||||
// Save compile starting time for debugging
|
||||
if(__DEBUG__==3) $GLOBALS['__xmlparse_elapsed__'] += getMicroTime() - $start;
|
||||
xml_set_object($this->oParser, $this);
|
||||
xml_set_element_handler($this->oParser, "_tagOpen", "_tagClosed");
|
||||
xml_set_character_data_handler($this->oParser, "_tagBody");
|
||||
|
||||
return $output;
|
||||
}
|
||||
xml_parse($this->oParser, $this->input);
|
||||
xml_parser_free($this->oParser);
|
||||
|
||||
if(!count($this->output))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start element handler.
|
||||
* @param resource $parse an instance of parser
|
||||
* @param string $node_name a name of node
|
||||
* @param array $attrs attributes to be set
|
||||
* @return array
|
||||
*/
|
||||
function _tagOpen($parser, $node_name, $attrs) {
|
||||
$obj = new Xml_Node_();
|
||||
$obj->node_name = strtolower($node_name);
|
||||
$obj->attrs = $this->_arrToAttrsObj($attrs);
|
||||
$output = array_shift($this->output);
|
||||
// Save compile starting time for debugging
|
||||
if(__DEBUG__ == 3)
|
||||
{
|
||||
$GLOBALS['__xmlparse_elapsed__'] += getMicroTime() - $start;
|
||||
}
|
||||
|
||||
array_push($this->output, $obj);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start element handler.
|
||||
* @param resource $parse an instance of parser
|
||||
* @param string $node_name a name of node
|
||||
* @param array $attrs attributes to be set
|
||||
* @return array
|
||||
*/
|
||||
function _tagOpen($parser, $node_name, $attrs)
|
||||
{
|
||||
$obj = new Xml_Node_();
|
||||
$obj->node_name = strtolower($node_name);
|
||||
$obj->attrs = $this->_arrToAttrsObj($attrs);
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
array_push($this->output, $obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* End element handler
|
||||
* @param resource $parse an instance of parser
|
||||
* @param string $node_name name of xml node
|
||||
* @return void
|
||||
*/
|
||||
function _tagClosed($parser, $node_name) {
|
||||
$node_name = strtolower($node_name);
|
||||
$cur_obj = array_pop($this->output);
|
||||
$parent_obj = &$this->output[count($this->output)-1];
|
||||
if($this->lang&&$cur_obj->attrs->{'xml:lang'}&&$cur_obj->attrs->{'xml:lang'}!=$this->lang) return;
|
||||
if($this->lang&&$parent_obj->{$node_name}->attrs->{'xml:lang'}&&$parent_obj->{$node_name}->attrs->{'xml:lang'}!=$this->lang) return;
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
if(isset($parent_obj->{$node_name})) {
|
||||
$tmp_obj = $parent_obj->{$node_name};
|
||||
if(is_array($tmp_obj)) {
|
||||
array_push($parent_obj->{$node_name}, $cur_obj);
|
||||
} else {
|
||||
$parent_obj->{$node_name} = array();
|
||||
array_push($parent_obj->{$node_name}, $tmp_obj);
|
||||
array_push($parent_obj->{$node_name}, $cur_obj);
|
||||
}
|
||||
} else {
|
||||
if (!is_object($parent_obj))
|
||||
$parent_obj = (object)$parent_obj;
|
||||
/**
|
||||
* End element handler
|
||||
* @param resource $parse an instance of parser
|
||||
* @param string $node_name name of xml node
|
||||
* @return void
|
||||
*/
|
||||
function _tagClosed($parser, $node_name)
|
||||
{
|
||||
$node_name = strtolower($node_name);
|
||||
$cur_obj = array_pop($this->output);
|
||||
$parent_obj = &$this->output[count($this->output) - 1];
|
||||
if($this->lang && $cur_obj->attrs->{'xml:lang'} && $cur_obj->attrs->{'xml:lang'} != $this->lang)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if($this->lang && $parent_obj->{$node_name}->attrs->{'xml:lang'} && $parent_obj->{$node_name}->attrs->{'xml:lang'} != $this->lang)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$parent_obj->{$node_name} = $cur_obj;
|
||||
}
|
||||
}
|
||||
if(isset($parent_obj->{$node_name}))
|
||||
{
|
||||
$tmp_obj = $parent_obj->{$node_name};
|
||||
if(is_array($tmp_obj))
|
||||
{
|
||||
array_push($parent_obj->{$node_name}, $cur_obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
$parent_obj->{$node_name} = array();
|
||||
array_push($parent_obj->{$node_name}, $tmp_obj);
|
||||
array_push($parent_obj->{$node_name}, $cur_obj);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!is_object($parent_obj))
|
||||
{
|
||||
$parent_obj = (object) $parent_obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to transfer values in an array to a data object
|
||||
* @param array $arr data array
|
||||
* @return Xml_Node_ object
|
||||
**/
|
||||
function _arrToAttrsObj($arr) {
|
||||
$output = new Xml_Node_();
|
||||
foreach($arr as $key => $val) {
|
||||
$key = strtolower($key);
|
||||
$output->{$key} = $val;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
?>
|
||||
$parent_obj->{$node_name} = $cur_obj;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to transfer values in an array to a data object
|
||||
* @param array $arr data array
|
||||
* @return Xml_Node_ object
|
||||
*/
|
||||
function _arrToAttrsObj($arr)
|
||||
{
|
||||
$output = new Xml_Node_();
|
||||
foreach($arr as $key => $val)
|
||||
{
|
||||
$key = strtolower($key);
|
||||
$output->{$key} = $val;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file XmlParser.class.php */
|
||||
/* Location: ./classes/xml/XmlParser.class.php */
|
||||
|
|
|
|||
|
|
@ -1,41 +1,36 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* File containing the XE 1.5 XmlQueryParserClass
|
||||
*/
|
||||
|
||||
if(!defined('__XE_LOADED_XML_CLASS__')){
|
||||
if(!defined('__XE_LOADED_XML_CLASS__'))
|
||||
{
|
||||
define('__XE_LOADED_XML_CLASS__', 1);
|
||||
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/query/QueryTag.class.php');
|
||||
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/table/TableTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/table/HintTableTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/table/TablesTag.class.php');
|
||||
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/ColumnTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/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');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php');
|
||||
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionsTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php');
|
||||
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/group/GroupsTag.class.php');
|
||||
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/navigation/NavigationTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/navigation/IndexTag.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/navigation/LimitTag.class.php');
|
||||
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/QueryArgument.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/SortQueryArgument.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php');
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/DefaultValue.class.php');
|
||||
require(_XE_PATH_ . 'classes/xml/xmlquery/tags/query/QueryTag.class.php');
|
||||
require(_XE_PATH_ . 'classes/xml/xmlquery/tags/table/TableTag.class.php');
|
||||
require(_XE_PATH_ . 'classes/xml/xmlquery/tags/table/HintTableTag.class.php');
|
||||
require(_XE_PATH_ . 'classes/xml/xmlquery/tags/table/TablesTag.class.php');
|
||||
require(_XE_PATH_ . 'classes/xml/xmlquery/tags/column/ColumnTag.class.php');
|
||||
require(_XE_PATH_ . 'classes/xml/xmlquery/tags/column/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');
|
||||
require(_XE_PATH_ . 'classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php');
|
||||
require(_XE_PATH_ . 'classes/xml/xmlquery/tags/condition/ConditionTag.class.php');
|
||||
require(_XE_PATH_ . 'classes/xml/xmlquery/tags/condition/ConditionsTag.class.php');
|
||||
require(_XE_PATH_ . 'classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php');
|
||||
require(_XE_PATH_ . 'classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php');
|
||||
require(_XE_PATH_ . 'classes/xml/xmlquery/tags/group/GroupsTag.class.php');
|
||||
require(_XE_PATH_ . 'classes/xml/xmlquery/tags/navigation/NavigationTag.class.php');
|
||||
require(_XE_PATH_ . 'classes/xml/xmlquery/tags/navigation/IndexTag.class.php');
|
||||
require(_XE_PATH_ . 'classes/xml/xmlquery/tags/navigation/LimitTag.class.php');
|
||||
require(_XE_PATH_ . 'classes/xml/xmlquery/queryargument/QueryArgument.class.php');
|
||||
require(_XE_PATH_ . 'classes/xml/xmlquery/queryargument/SortQueryArgument.class.php');
|
||||
require(_XE_PATH_ . 'classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php');
|
||||
require(_XE_PATH_ . 'classes/xml/xmlquery/queryargument/DefaultValue.class.php');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -46,7 +41,17 @@ if(!defined('__XE_LOADED_XML_CLASS__')){
|
|||
* @package classes\xml
|
||||
* @version 0.1
|
||||
*/
|
||||
class XmlQueryParser extends XmlParser {
|
||||
class XmlQueryParser extends XmlParser
|
||||
{
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @return void
|
||||
*/
|
||||
function XmlQueryParser()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create XmlQueryParser instance for Singleton
|
||||
|
|
@ -56,8 +61,9 @@ class XmlQueryParser extends XmlParser {
|
|||
function &getInstance()
|
||||
{
|
||||
static $theInstance = NULL;
|
||||
if(!isset($theInstance)){
|
||||
$theInstance = new XmlQueryParser();
|
||||
if(!isset($theInstance))
|
||||
{
|
||||
$theInstance = new XmlQueryParser();
|
||||
}
|
||||
return $theInstance;
|
||||
}
|
||||
|
|
@ -65,8 +71,8 @@ class XmlQueryParser extends XmlParser {
|
|||
/**
|
||||
* Parses an XML query file
|
||||
*
|
||||
* 1. Read xml file <br />
|
||||
* 2. Check the action <br />
|
||||
* 1. Read xml file<br />
|
||||
* 2. Check the action<br />
|
||||
* 3. Parse and write cache file <br />
|
||||
*
|
||||
* @param $query_id
|
||||
|
|
@ -82,7 +88,10 @@ class XmlQueryParser extends XmlParser {
|
|||
|
||||
// insert, update, delete, select action
|
||||
$action = strtolower($xml_obj->query->attrs->action);
|
||||
if(!$action) return;
|
||||
if(!$action)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Write query cache file
|
||||
$parser = new QueryParser($xml_obj->query);
|
||||
|
|
@ -116,9 +125,14 @@ class XmlQueryParser extends XmlParser {
|
|||
{
|
||||
$buff = FileHandler::readFile($xml_file);
|
||||
$xml_obj = parent::parse($buff);
|
||||
if(!$xml_obj) return;
|
||||
if(!$xml_obj)
|
||||
{
|
||||
return;
|
||||
}
|
||||
unset($buff);
|
||||
return $xml_obj;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
/* End of file XmlQueryParser.150.class.php */
|
||||
/* Location: ./classes/xml/XmlQueryParser.150.class.php */
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,7 +1,9 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* File containing the DBParser class
|
||||
*/
|
||||
|
||||
/**
|
||||
* Escapes query statements: <br />
|
||||
* - column names: member.member_srl => "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,11 +165,14 @@ class DBParser
|
|||
function escapeColumn($column_name)
|
||||
{
|
||||
if($this->isUnqualifiedColumnName($column_name))
|
||||
{
|
||||
return $this->escape($column_name);
|
||||
if($this->isQualifiedColumnName($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);
|
||||
}
|
||||
}
|
||||
|
|
@ -164,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;
|
||||
}
|
||||
|
||||
|
|
@ -179,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;
|
||||
}
|
||||
|
||||
|
|
@ -203,21 +233,38 @@ class DBParser
|
|||
*/
|
||||
function parseExpression($column_name)
|
||||
{
|
||||
$functions = preg_split('/([\+\-\*\/\ ])/', $column_name, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
||||
foreach($functions as $k => $v){
|
||||
$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){
|
||||
foreach($matches as $i => $j)
|
||||
{
|
||||
$match = &$matches[$i];
|
||||
if($match == '(') {$brackets++; continue;}
|
||||
if(strpos($match,')') !== FALSE) continue;
|
||||
if(in_array($match, array(',', '.'))) continue;
|
||||
if($brackets == $total_brackets){
|
||||
if(!is_numeric($match) && !in_array(strtoupper($match), array('UNSIGNED', 'INTEGER', 'AS'))) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -235,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;
|
||||
}
|
||||
|
||||
|
|
@ -248,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;
|
||||
}
|
||||
|
||||
|
|
@ -259,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 */
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -10,7 +12,8 @@
|
|||
* @package classes\xml\xmlquery
|
||||
* @version 0.1
|
||||
*/
|
||||
class QueryParser {
|
||||
class QueryParser
|
||||
{
|
||||
|
||||
/**
|
||||
* Property containing the associated QueryTag object
|
||||
|
|
@ -28,7 +31,7 @@ class QueryParser {
|
|||
*/
|
||||
function QueryParser($query = NULL, $isSubQuery = FALSE)
|
||||
{
|
||||
if ($query)
|
||||
if($query)
|
||||
{
|
||||
$this->queryTag = new QueryTag($query, $isSubQuery);
|
||||
}
|
||||
|
|
@ -44,46 +47,60 @@ class QueryParser {
|
|||
* @param bool $table_name
|
||||
* @return array
|
||||
*/
|
||||
function getTableInfo($query_id, $table_name) {
|
||||
function getTableInfo($query_id, $table_name)
|
||||
{
|
||||
$column_type = array();
|
||||
$module = '';
|
||||
|
||||
$id_args = explode('.', $query_id);
|
||||
if (count($id_args) == 2) {
|
||||
if(count($id_args) == 2)
|
||||
{
|
||||
$target = 'modules';
|
||||
$module = $id_args[0];
|
||||
$id = $id_args[1];
|
||||
} elseif (count($id_args) == 3) {
|
||||
}
|
||||
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);
|
||||
if (!file_exists($table_file)) {
|
||||
if(!file_exists($table_file))
|
||||
{
|
||||
$searched_list = FileHandler::readDir(_XE_PATH_ . 'modules');
|
||||
$searched_count = count($searched_list);
|
||||
for ($i = 0; $i < $searched_count; $i++) {
|
||||
for($i = 0; $i < $searched_count; $i++)
|
||||
{
|
||||
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $searched_list[$i], $table_name);
|
||||
if (file_exists($table_file))
|
||||
if(file_exists($table_file))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (file_exists($table_file)) {
|
||||
if(file_exists($table_file))
|
||||
{
|
||||
$table_xml = FileHandler::readFile($table_file);
|
||||
$xml_parser = new XmlParser();
|
||||
$table_obj = $xml_parser->parse($table_xml);
|
||||
if ($table_obj->table) {
|
||||
if (isset($table_obj->table->column) && !is_array($table_obj->table->column)) {
|
||||
if($table_obj->table)
|
||||
{
|
||||
if(isset($table_obj->table->column) && !is_array($table_obj->table->column))
|
||||
{
|
||||
$table_obj->table->column = array($table_obj->table->column);
|
||||
}
|
||||
|
||||
foreach ($table_obj->table->column as $k => $v) {
|
||||
foreach($table_obj->table->column as $k => $v)
|
||||
{
|
||||
$column_type[$v->attrs->name] = $v->attrs->type;
|
||||
}
|
||||
}
|
||||
|
|
@ -97,12 +114,13 @@ class QueryParser {
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
function toString() {
|
||||
return "<?php if(!defined('__ZBXE__')) exit();\n"
|
||||
. $this->queryTag->toString()
|
||||
. 'return $query; ?>';
|
||||
function toString()
|
||||
{
|
||||
return "<?php if(!defined('__XE__')) exit();\n"
|
||||
. $this->queryTag->toString()
|
||||
. 'return $query; ?>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
/* End of file QueryParser.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/QueryParser.class.php */
|
||||
|
|
|
|||
|
|
@ -1,50 +1,60 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Argument class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery/argument
|
||||
* @version 0.1
|
||||
*/
|
||||
class Argument {
|
||||
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
|
||||
*/
|
||||
var $_value; //
|
||||
var $_value; //
|
||||
|
||||
/**
|
||||
* constructor
|
||||
|
|
@ -52,52 +62,74 @@ class Argument {
|
|||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
function Argument($name, $value) {
|
||||
|
||||
function Argument($name, $value)
|
||||
{
|
||||
$this->value = $value;
|
||||
$this->name = $name;
|
||||
$this->isValid = true;
|
||||
$this->isValid = TRUE;
|
||||
}
|
||||
|
||||
function getType() {
|
||||
if (isset($this->type))
|
||||
function getType()
|
||||
{
|
||||
if(isset($this->type))
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
if (is_string($this->value))
|
||||
if(is_string($this->value))
|
||||
{
|
||||
return 'column_name';
|
||||
}
|
||||
|
||||
return 'number';
|
||||
}
|
||||
|
||||
function setColumnType($value) {
|
||||
function setColumnType($value)
|
||||
{
|
||||
$this->type = $value;
|
||||
}
|
||||
|
||||
function setColumnOperation($operation) {
|
||||
|
||||
function setColumnOperation($operation)
|
||||
{
|
||||
$this->column_operation = $operation;
|
||||
}
|
||||
|
||||
function getName() {
|
||||
function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
function getValue() {
|
||||
if (!isset($this->_value)) {
|
||||
function getValue()
|
||||
{
|
||||
if(!isset($this->_value))
|
||||
{
|
||||
$value = $this->getEscapedValue();
|
||||
$this->_value = $this->toString($value);
|
||||
}
|
||||
return $this->_value;
|
||||
}
|
||||
|
||||
function getColumnOperation() {
|
||||
function getPureValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
function getColumnOperation()
|
||||
{
|
||||
return $this->column_operation;
|
||||
}
|
||||
|
||||
function getEscapedValue() {
|
||||
function getEscapedValue()
|
||||
{
|
||||
return $this->escapeValue($this->value);
|
||||
}
|
||||
|
||||
function getUnescapedValue() {
|
||||
if($this->value === 'null') return null;
|
||||
function getUnescapedValue()
|
||||
{
|
||||
if($this->value === 'null')
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
|
|
@ -106,12 +138,18 @@ class Argument {
|
|||
* @param mixed $value
|
||||
* @return string
|
||||
*/
|
||||
function toString($value) {
|
||||
if (is_array($value)) {
|
||||
if (count($value) === 0)
|
||||
function toString($value)
|
||||
{
|
||||
if(is_array($value))
|
||||
{
|
||||
if(count($value) === 0)
|
||||
{
|
||||
return '';
|
||||
if (count($value) === 1 && $value[0] === '')
|
||||
}
|
||||
if(count($value) === 1 && $value[0] === '')
|
||||
{
|
||||
return '';
|
||||
}
|
||||
return '(' . implode(',', $value) . ')';
|
||||
}
|
||||
return $value;
|
||||
|
|
@ -122,35 +160,54 @@ class Argument {
|
|||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
function escapeValue($value) {
|
||||
function escapeValue($value)
|
||||
{
|
||||
$column_type = $this->getType();
|
||||
if ($column_type == 'column_name') {
|
||||
if($column_type == 'column_name')
|
||||
{
|
||||
$dbParser = DB::getParser();
|
||||
return $dbParser->parseExpression($value);
|
||||
}
|
||||
if (!isset($value))
|
||||
if(!isset($value))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$columnTypeList = array('date'=>1, 'varchar'=>1, 'char'=>1, 'text'=>1, 'bigtext'=>1);
|
||||
if (isset($columnTypeList[$column_type])) {
|
||||
if (!is_array($value))
|
||||
$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 {
|
||||
}
|
||||
else
|
||||
{
|
||||
$total = count($value);
|
||||
for ($i = 0; $i < $total; $i++)
|
||||
for($i = 0; $i < $total; $i++)
|
||||
{
|
||||
$value[$i] = $this->_escapeStringValue($value[$i]);
|
||||
}
|
||||
//$value[$i] = '\''.$value[$i].'\'';
|
||||
}
|
||||
}
|
||||
if($this->uses_default_value) return $value;
|
||||
if ($column_type == 'number') {
|
||||
if (is_array($value)) {
|
||||
foreach ($value AS $key => $val) {
|
||||
if (isset($val) && $val !== '') {
|
||||
if($this->uses_default_value)
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
if($column_type == 'number')
|
||||
{
|
||||
if(is_array($value))
|
||||
{
|
||||
foreach($value AS $key => $val)
|
||||
{
|
||||
if(isset($val) && $val !== '')
|
||||
{
|
||||
$value[$key] = (int) $val;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = (int) $value;
|
||||
}
|
||||
}
|
||||
|
|
@ -163,23 +220,25 @@ class Argument {
|
|||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
function _escapeStringValue($value) {
|
||||
function _escapeStringValue($value)
|
||||
{
|
||||
// Remove non-utf8 chars.
|
||||
$regex = '@((?:[\x00-\x7F]|[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}){1,100})|([\xF0-\xF7][\x80-\xBF]{3})|([\x80-\xBF])|([\xC0-\xFF])@x';
|
||||
|
||||
$value = preg_replace_callback($regex, array($this, 'utf8Replacer'), $value);
|
||||
$db = &DB::getInstance();
|
||||
$db = DB::getInstance();
|
||||
$value = $db->addQuotes($value);
|
||||
return '\'' . $value . '\'';
|
||||
}
|
||||
|
||||
function utf8Replacer($captures) {
|
||||
if (!empty($captures[1]))
|
||||
function utf8Replacer($captures)
|
||||
{
|
||||
if(strlen($captures[1]))
|
||||
{
|
||||
// Valid byte sequence. Return unmodified.
|
||||
return $captures[1];
|
||||
}
|
||||
elseif(!empty($captures[2]))
|
||||
else if(strlen($captures[2]))
|
||||
{
|
||||
// Remove user defined area
|
||||
if("\xF3\xB0\x80\x80" <= $captures[2])
|
||||
|
|
@ -195,28 +254,41 @@ class Argument {
|
|||
}
|
||||
}
|
||||
|
||||
function isValid() {
|
||||
function isValid()
|
||||
{
|
||||
return $this->isValid;
|
||||
}
|
||||
|
||||
function isColumnName(){
|
||||
|
||||
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() {
|
||||
function getErrorMessage()
|
||||
{
|
||||
return $this->errorMessage;
|
||||
}
|
||||
|
||||
function ensureDefaultValue($default_value) {
|
||||
if (!isset($this->value) || $this->value == '')
|
||||
function ensureDefaultValue($default_value)
|
||||
{
|
||||
if(!isset($this->value) || $this->value == '')
|
||||
{
|
||||
$this->value = $default_value;
|
||||
$this->uses_default_value = true;
|
||||
$this->uses_default_value = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -225,50 +297,61 @@ class Argument {
|
|||
* @param string $filter_type
|
||||
* @return void
|
||||
*/
|
||||
function checkFilter($filter_type) {
|
||||
if (isset($this->value) && $this->value != '') {
|
||||
function checkFilter($filter_type)
|
||||
{
|
||||
if(isset($this->value) && $this->value != '')
|
||||
{
|
||||
global $lang;
|
||||
$val = $this->value;
|
||||
$key = $this->name;
|
||||
switch ($filter_type) {
|
||||
switch($filter_type)
|
||||
{
|
||||
case 'email' :
|
||||
case 'email_address' :
|
||||
if (!preg_match('/^[\w-]+((?:\.|\+|\~)[\w-]+)*@[\w-]+(\.[\w-]+)+$/is', $val)) {
|
||||
$this->isValid = false;
|
||||
if(!preg_match('/^[\w-]+((?:\.|\+|\~)[\w-]+)*@[\w-]+(\.[\w-]+)+$/is', $val))
|
||||
{
|
||||
$this->isValid = FALSE;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_email, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'homepage' :
|
||||
if (!preg_match('/^(http|https)+(:\/\/)+[0-9a-z_-]+\.[^ ]+$/is', $val)) {
|
||||
$this->isValid = false;
|
||||
if(!preg_match('/^(http|https)+(:\/\/)+[0-9a-z_-]+\.[^ ]+$/is', $val))
|
||||
{
|
||||
$this->isValid = FALSE;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_homepage, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'userid' :
|
||||
case 'user_id' :
|
||||
if (!preg_match('/^[a-zA-Z]+([_0-9a-zA-Z]+)*$/is', $val)) {
|
||||
$this->isValid = false;
|
||||
if(!preg_match('/^[a-zA-Z]+([_0-9a-zA-Z]+)*$/is', $val))
|
||||
{
|
||||
$this->isValid = FALSE;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_userid, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'number' :
|
||||
case 'numbers' :
|
||||
if (is_array($val))
|
||||
if(is_array($val))
|
||||
{
|
||||
$val = join(',', $val);
|
||||
if (!preg_match('/^(-?)[0-9]+(,\-?[0-9]+)*$/is', $val)) {
|
||||
$this->isValid = false;
|
||||
}
|
||||
if(!preg_match('/^(-?)[0-9]+(,\-?[0-9]+)*$/is', $val))
|
||||
{
|
||||
$this->isValid = FALSE;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_number, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'alpha' :
|
||||
if (!preg_match('/^[a-z]+$/is', $val)) {
|
||||
$this->isValid = false;
|
||||
if(!preg_match('/^[a-z]+$/is', $val))
|
||||
{
|
||||
$this->isValid = FALSE;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'alpha_number' :
|
||||
if (!preg_match('/^[0-9a-z]+$/is', $val)) {
|
||||
$this->isValid = false;
|
||||
if(!preg_match('/^[0-9a-z]+$/is', $val))
|
||||
{
|
||||
$this->isValid = FALSE;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha_number, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
|
|
@ -276,33 +359,39 @@ class Argument {
|
|||
}
|
||||
}
|
||||
|
||||
function checkMaxLength($length) {
|
||||
if ($this->value && (strlen($this->value) > $length)) {
|
||||
function checkMaxLength($length)
|
||||
{
|
||||
if($this->value && (strlen($this->value) > $length))
|
||||
{
|
||||
global $lang;
|
||||
$this->isValid = false;
|
||||
$this->isValid = FALSE;
|
||||
$key = $this->name;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
}
|
||||
|
||||
function checkMinLength($length) {
|
||||
if ($this->value && (strlen($this->value) < $length)) {
|
||||
function checkMinLength($length)
|
||||
{
|
||||
if($this->value && (strlen($this->value) < $length))
|
||||
{
|
||||
global $lang;
|
||||
$this->isValid = false;
|
||||
$this->isValid = FALSE;
|
||||
$key = $this->name;
|
||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
}
|
||||
|
||||
function checkNotNull() {
|
||||
if (!isset($this->value)) {
|
||||
function checkNotNull()
|
||||
{
|
||||
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 */
|
||||
|
|
|
|||
|
|
@ -1,122 +1,152 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ConditionArgument class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery/argument
|
||||
* @version 0.1
|
||||
*/
|
||||
class ConditionArgument extends Argument
|
||||
{
|
||||
|
||||
/**
|
||||
* ConditionArgument class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery/argument
|
||||
* @version 0.1
|
||||
* Operator keyword. for example 'in', 'notint', 'between'
|
||||
* @var string
|
||||
*/
|
||||
class ConditionArgument extends Argument {
|
||||
/**
|
||||
* Operator keyword. for example 'in', 'notint', 'between'
|
||||
* @var string
|
||||
*/
|
||||
var $operation;
|
||||
var $operation;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @param string $operation
|
||||
* @return void
|
||||
*/
|
||||
function ConditionArgument($name, $value, $operation)
|
||||
{
|
||||
$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);
|
||||
}
|
||||
parent::Argument($name, $value);
|
||||
$this->operation = $operation;
|
||||
}
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @param string $operation
|
||||
* @return void
|
||||
*/
|
||||
function ConditionArgument($name, $value, $operation){
|
||||
$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);
|
||||
}
|
||||
parent::Argument($name, $value);
|
||||
$this->operation = $operation;
|
||||
/**
|
||||
* create condition value. set $this->value
|
||||
* @return void
|
||||
*/
|
||||
function createConditionValue()
|
||||
{
|
||||
if(!isset($this->value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* create condition value. set $this->value
|
||||
* @return void
|
||||
*/
|
||||
function createConditionValue(){
|
||||
if(!isset($this->value)) return;
|
||||
$operation = $this->operation;
|
||||
$value = $this->value;
|
||||
|
||||
$operation = $this->operation;
|
||||
$value = $this->value;
|
||||
switch($operation)
|
||||
{
|
||||
case 'like_prefix' :
|
||||
if(defined('__CUBRID_VERSION__') && __CUBRID_VERSION__ >= '8.4.1')
|
||||
{
|
||||
$this->value = '^' . str_replace('%', '(.*)', preg_quote($value));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->value = $value . '%';
|
||||
}
|
||||
break;
|
||||
case 'like_tail' :
|
||||
if(defined('__CUBRID_VERSION__') && __CUBRID_VERSION__ >= '8.4.1')
|
||||
{
|
||||
$this->value = str_replace('%', '(.*)', preg_quote($value)) . '$';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->value = '%' . $value;
|
||||
}
|
||||
break;
|
||||
case 'like' :
|
||||
if(defined('__CUBRID_VERSION__') && __CUBRID_VERSION__ >= '8.4.1')
|
||||
{
|
||||
$this->value = str_replace('%', '(.*)', preg_quote($value));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->value = '%' . $value . '%';
|
||||
}
|
||||
break;
|
||||
case 'notlike' :
|
||||
$this->value = '%' . $value . '%';
|
||||
break;
|
||||
case 'notlike_prefix' :
|
||||
$this->value = $value . '%';
|
||||
break;
|
||||
case 'notlike_tail' :
|
||||
$this->value = '%' . $value;
|
||||
break;
|
||||
case 'in':
|
||||
if(!is_array($value))
|
||||
{
|
||||
$this->value = array($value);
|
||||
}
|
||||
break;
|
||||
case 'notin':
|
||||
case 'not_in':
|
||||
if(!is_array($value))
|
||||
{
|
||||
$this->value = array($value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch($operation) {
|
||||
case 'like_prefix' :
|
||||
if(defined('__CUBRID_VERSION__')
|
||||
&& __CUBRID_VERSION__ >= '8.4.1') {
|
||||
$this->value = '^' . str_replace('%', '(.*)', preg_quote($value));
|
||||
}
|
||||
else
|
||||
$this->value = $value.'%';
|
||||
break;
|
||||
case 'like_tail' :
|
||||
if(defined('__CUBRID_VERSION__')
|
||||
&& __CUBRID_VERSION__ >= '8.4.1')
|
||||
$this->value = str_replace('%', '(.*)', preg_quote($value)) . '$';
|
||||
else
|
||||
$this->value = '%'.$value;
|
||||
break;
|
||||
case 'like' :
|
||||
if(defined('__CUBRID_VERSION__')
|
||||
&& __CUBRID_VERSION__ >= '8.4.1') {
|
||||
$this->value = str_replace('%', '(.*)', preg_quote($value));
|
||||
}
|
||||
else
|
||||
$this->value = '%'.$value.'%';
|
||||
break;
|
||||
case 'notlike' :
|
||||
$this->value = '%'.$value.'%';
|
||||
break;
|
||||
case 'notlike_prefix' :
|
||||
$this->value = $value.'%';
|
||||
break;
|
||||
case 'notlike_tail' :
|
||||
$this->value = '%'.$value;
|
||||
break;
|
||||
case 'in':
|
||||
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
|
||||
*/
|
||||
function getType()
|
||||
{
|
||||
if($this->type)
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
else if(!is_numeric($this->value))
|
||||
{
|
||||
return 'varchar';
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function setColumnType($column_type)
|
||||
{
|
||||
if(!isset($this->value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if($column_type === '')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
else if(!is_numeric($this->value))
|
||||
{
|
||||
return 'varchar';
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
$this->type = $column_type;
|
||||
}
|
||||
|
||||
function setColumnType($column_type){
|
||||
if(!isset($this->value)) return;
|
||||
if($column_type === '') return;
|
||||
|
||||
$this->type = $column_type;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
}
|
||||
/* End of file ConditionArgument.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/argument/ConditionArgument.class.php */
|
||||
|
|
|
|||
|
|
@ -1,16 +1,19 @@
|
|||
<?php
|
||||
/**
|
||||
* SortArgument class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery/argument
|
||||
* @version 0.1
|
||||
*/
|
||||
class SortArgument extends Argument {
|
||||
|
||||
function getValue(){
|
||||
return $this->getUnescapedValue();
|
||||
}
|
||||
/**
|
||||
* SortArgument class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery/argument
|
||||
* @version 0.1
|
||||
*/
|
||||
class SortArgument extends Argument
|
||||
{
|
||||
|
||||
}
|
||||
function getValue()
|
||||
{
|
||||
return $this->getUnescapedValue();
|
||||
}
|
||||
|
||||
?>
|
||||
}
|
||||
/* End of file SortArgument.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/argument/SortArgument.class.php */
|
||||
|
|
|
|||
|
|
@ -1,146 +1,175 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* DefaultValue class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery/queryargument
|
||||
* @version 0.1
|
||||
*/
|
||||
class DefaultValue
|
||||
{
|
||||
|
||||
/**
|
||||
* DefaultValue class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery/queryargument
|
||||
* @version 0.1
|
||||
* Column name
|
||||
* @var string
|
||||
*/
|
||||
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 $column_name;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
$this->value = $value;
|
||||
$this->value = $this->_setValue();
|
||||
}
|
||||
/**
|
||||
* Value
|
||||
* @var mixed
|
||||
*/
|
||||
var $value;
|
||||
|
||||
function isString(){
|
||||
return $this->_is_string;
|
||||
$str_pos = strpos($this->value, '(');
|
||||
if($str_pos===false) return true;
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* sequnence status
|
||||
* @var bool
|
||||
*/
|
||||
var $is_sequence = FALSE;
|
||||
|
||||
function isStringFromFunction(){
|
||||
return $this->_is_string_from_function;
|
||||
}
|
||||
/**
|
||||
* operation status
|
||||
* @var bool
|
||||
*/
|
||||
var $is_operation = FALSE;
|
||||
|
||||
function isSequence(){
|
||||
return $this->is_sequence;
|
||||
}
|
||||
/**
|
||||
* operation
|
||||
* @var string
|
||||
*/
|
||||
var $operation = '';
|
||||
|
||||
function isOperation(){
|
||||
return $this->is_operation;
|
||||
}
|
||||
/**
|
||||
* Checks if value is plain string or name of XE function (ipaddress, plus, etc).
|
||||
* @var bool
|
||||
*/
|
||||
var $_is_string = FALSE;
|
||||
|
||||
function getOperation(){
|
||||
return $this->operation;
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
|
||||
function _setValue(){
|
||||
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) {
|
||||
return sprintf('array(%s)', $this->value);
|
||||
}
|
||||
|
||||
$str_pos = strpos($this->value, '(');
|
||||
// // TODO Replace this with parseExpression
|
||||
if($str_pos===false) {
|
||||
$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);
|
||||
|
||||
switch($func_name) {
|
||||
case 'ipaddress' :
|
||||
$val = '$_SERVER[\'REMOTE_ADDR\']';
|
||||
$this->_is_string_from_function = true;
|
||||
break;
|
||||
case 'unixtime' :
|
||||
$val = 'time()';
|
||||
break;
|
||||
case 'curdate' :
|
||||
$val = 'date("YmdHis")';
|
||||
$this->_is_string_from_function = true;
|
||||
break;
|
||||
case 'sequence' :
|
||||
$this->is_sequence = true;
|
||||
$val = '$sequence';
|
||||
break;
|
||||
case 'plus' :
|
||||
$args = abs($args);
|
||||
$this->is_operation = true;
|
||||
$this->operation = '+';
|
||||
$val = sprintf('%d', $args);
|
||||
break;
|
||||
case 'minus' :
|
||||
$args = abs($args);
|
||||
$this->is_operation = true;
|
||||
$this->operation = '-';
|
||||
$val = sprintf('%d', $args);
|
||||
break;
|
||||
case 'multiply' :
|
||||
$args = intval($args);
|
||||
$this->is_operation = true;
|
||||
$this->operation = '*';
|
||||
$val = sprintf('%d', $args);
|
||||
break;
|
||||
default :
|
||||
$val = '\'' . $this->value . '\'';
|
||||
//$val = $this->value;
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
function toString(){
|
||||
return $this->value;
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
$this->value = $value;
|
||||
$this->value = $this->_setValue();
|
||||
}
|
||||
|
||||
function isString()
|
||||
{
|
||||
return $this->_is_string;
|
||||
$str_pos = strpos($this->value, '(');
|
||||
if($str_pos === false)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function isStringFromFunction()
|
||||
{
|
||||
return $this->_is_string_from_function;
|
||||
}
|
||||
|
||||
function isSequence()
|
||||
{
|
||||
return $this->is_sequence;
|
||||
}
|
||||
|
||||
function isOperation()
|
||||
{
|
||||
return $this->is_operation;
|
||||
}
|
||||
|
||||
function getOperation()
|
||||
{
|
||||
return $this->operation;
|
||||
}
|
||||
|
||||
function _setValue()
|
||||
{
|
||||
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)
|
||||
{
|
||||
return sprintf('array(%s)', $this->value);
|
||||
}
|
||||
|
||||
$str_pos = strpos($this->value, '(');
|
||||
// // TODO Replace this with parseExpression
|
||||
if($str_pos === FALSE)
|
||||
{
|
||||
$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);
|
||||
|
||||
switch($func_name)
|
||||
{
|
||||
case 'ipaddress' :
|
||||
$val = '$_SERVER[\'REMOTE_ADDR\']';
|
||||
$this->_is_string_from_function = TRUE;
|
||||
break;
|
||||
case 'unixtime' :
|
||||
$val = 'time()';
|
||||
break;
|
||||
case 'curdate' :
|
||||
$val = 'date("YmdHis")';
|
||||
$this->_is_string_from_function = TRUE;
|
||||
break;
|
||||
case 'sequence' :
|
||||
$this->is_sequence = TRUE;
|
||||
$val = '$sequence';
|
||||
break;
|
||||
case 'plus' :
|
||||
$args = abs($args);
|
||||
$this->is_operation = TRUE;
|
||||
$this->operation = '+';
|
||||
$val = sprintf('%d', $args);
|
||||
break;
|
||||
case 'minus' :
|
||||
$args = abs($args);
|
||||
$this->is_operation = TRUE;
|
||||
$this->operation = '-';
|
||||
$val = sprintf('%d', $args);
|
||||
break;
|
||||
case 'multiply' :
|
||||
$args = intval($args);
|
||||
$this->is_operation = TRUE;
|
||||
$this->operation = '*';
|
||||
$val = sprintf('%d', $args);
|
||||
break;
|
||||
default :
|
||||
$val = '\'' . $this->value . '\'';
|
||||
//$val = $this->value;
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
function toString()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file DefaultValue.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/queryargument/DefaultValue.class.php */
|
||||
|
|
|
|||
|
|
@ -1,41 +1,50 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* QueryArgument class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery/queryargument
|
||||
* @version 0.1
|
||||
*/
|
||||
class QueryArgument {
|
||||
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
|
||||
|
|
@ -48,14 +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)
|
||||
if(!$this->argument_name)
|
||||
{
|
||||
$this->argument_name = str_replace('.', '_', $tag->attrs->name);
|
||||
if (!$this->argument_name)
|
||||
}
|
||||
if(!$this->argument_name)
|
||||
{
|
||||
$this->argument_name = str_replace('.', '_', $tag->attrs->column);
|
||||
}
|
||||
|
||||
$this->variable_name = $this->argument_name;
|
||||
|
||||
|
|
@ -63,51 +77,67 @@ class QueryArgument {
|
|||
$this->argument_name .= $number_of_arguments;
|
||||
|
||||
$name = $tag->attrs->name;
|
||||
if (!$name)
|
||||
if(!$name)
|
||||
{
|
||||
$name = $tag->attrs->column;
|
||||
if (strpos($name, '.') === false)
|
||||
}
|
||||
if(strpos($name, '.') === FALSE)
|
||||
{
|
||||
$this->column_name = $name;
|
||||
else {
|
||||
}
|
||||
else
|
||||
{
|
||||
list($prefix, $name) = explode('.', $name);
|
||||
$this->column_name = $name;
|
||||
$this->table_name = $prefix;
|
||||
}
|
||||
|
||||
if ($tag->attrs->operation)
|
||||
if($tag->attrs->operation)
|
||||
{
|
||||
$this->operation = $tag->attrs->operation;
|
||||
}
|
||||
|
||||
$this->argument_validator = new QueryArgumentValidator($tag, $this);
|
||||
$this->ignore_value = $ignore_value;
|
||||
}
|
||||
|
||||
function getArgumentName() {
|
||||
function getArgumentName()
|
||||
{
|
||||
return $this->argument_name;
|
||||
}
|
||||
|
||||
function getColumnName() {
|
||||
function getColumnName()
|
||||
{
|
||||
return $this->column_name;
|
||||
}
|
||||
|
||||
function getTableName(){
|
||||
|
||||
function getTableName()
|
||||
{
|
||||
return $this->table_name;
|
||||
}
|
||||
|
||||
function getValidatorString() {
|
||||
function getValidatorString()
|
||||
{
|
||||
return $this->argument_validator->toString();
|
||||
}
|
||||
|
||||
function isConditionArgument() {
|
||||
if ($this->operation)
|
||||
return true;
|
||||
return false;
|
||||
function isConditionArgument()
|
||||
{
|
||||
if($this->operation)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change QueryArgument object to string
|
||||
* @return string
|
||||
*/
|
||||
function toString() {
|
||||
if ($this->isConditionArgument()) {
|
||||
function toString()
|
||||
{
|
||||
if($this->isConditionArgument())
|
||||
{
|
||||
// Instantiation
|
||||
$arg = sprintf("\n" . '${\'%s_argument\'} = new ConditionArgument(\'%s\', %s, \'%s\');' . "\n"
|
||||
, $this->argument_name
|
||||
|
|
@ -128,11 +158,13 @@ class QueryArgument {
|
|||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
);
|
||||
} else {
|
||||
}
|
||||
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->ignore_value ? 'NULL' : '$args->{\'' . $this->variable_name . '\'}');
|
||||
|
||||
$arg .= $this->argument_validator->toString();
|
||||
|
||||
|
|
@ -143,15 +175,16 @@ class QueryArgument {
|
|||
}
|
||||
|
||||
// If the argument is null, skip it
|
||||
if ($this->argument_validator->isIgnorable()) {
|
||||
if($this->argument_validator->isIgnorable())
|
||||
{
|
||||
$arg = sprintf("if(isset(%s)) {", '$args->' . $this->variable_name)
|
||||
. $arg
|
||||
. sprintf("} else\n" . '${\'%s_argument\'} = null;', $this->argument_name);
|
||||
. 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 */
|
||||
|
|
|
|||
|
|
@ -1,29 +1,33 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SortQueryArgument class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery/queryargument
|
||||
* @version 0.1
|
||||
*/
|
||||
class SortQueryArgument extends QueryArgument
|
||||
{
|
||||
|
||||
/**
|
||||
* SortQueryArgument class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery/queryargument
|
||||
* @version 0.1
|
||||
* Change SortQueryArgument object to string
|
||||
* @return string
|
||||
*/
|
||||
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
|
||||
, $this->argument_name
|
||||
, '$args->'.$this->variable_name);
|
||||
function toString()
|
||||
{
|
||||
$arg = sprintf("\n" . '${\'%s_argument\'} = new SortArgument(\'%s\', %s);' . "\n"
|
||||
, $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;
|
||||
}
|
||||
|
||||
$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 */
|
||||
|
|
|
|||
|
|
@ -1,113 +1,134 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* QueryArgumentValidator class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery/queryargument/validator
|
||||
* @version 0.1
|
||||
*/
|
||||
class QueryArgumentValidator
|
||||
{
|
||||
|
||||
/**
|
||||
* QueryArgumentValidator class
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery/queryargument/validator
|
||||
* @version 0.1
|
||||
* Argument name
|
||||
* @var string
|
||||
*/
|
||||
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 $argument_name;
|
||||
|
||||
var $validator_string;
|
||||
/**
|
||||
* Default value
|
||||
* @var string
|
||||
*/
|
||||
var $default_value;
|
||||
|
||||
/**
|
||||
* Query argument for validate
|
||||
* @var QueryArgument object
|
||||
*/
|
||||
var $argument;
|
||||
/**
|
||||
* Notnull status setting, if value should be not null, this value is 'notnull'
|
||||
* @var string
|
||||
*/
|
||||
var $notnull;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
/**
|
||||
* Filter for value type, for example number
|
||||
* @var string
|
||||
*/
|
||||
var $filter;
|
||||
|
||||
$this->default_value = $tag->attrs->default;
|
||||
$this->notnull = $tag->attrs->notnull;
|
||||
$this->filter = $tag->attrs->filter;
|
||||
$this->min_length = $tag->attrs->min_length;
|
||||
$this->max_length = $tag->attrs->max_length;
|
||||
}
|
||||
/**
|
||||
* Minimum length for value
|
||||
* @var int
|
||||
*/
|
||||
var $min_length;
|
||||
|
||||
function isIgnorable(){
|
||||
if(isset($this->default_value) || isset($this->notnull)) return false;
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Maximum length for value
|
||||
* @var int
|
||||
*/
|
||||
var $max_length;
|
||||
var $validator_string;
|
||||
|
||||
function toString(){
|
||||
$validator = '';
|
||||
if($this->filter){
|
||||
$validator .= sprintf('${\'%s_argument\'}->checkFilter(\'%s\');' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->filter
|
||||
);
|
||||
}
|
||||
if($this->min_length){
|
||||
$validator .= sprintf('${\'%s_argument\'}->checkMinLength(%s);' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->min_length
|
||||
);
|
||||
}
|
||||
if($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(); ';
|
||||
if($this->default_value->isOperation())
|
||||
$validator .= sprintf('${\'%s_argument\'}->setColumnOperation(\'%s\');' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->default_value->getOperation()
|
||||
);
|
||||
$validator .= sprintf('${\'%s_argument\'}->ensureDefaultValue(%s);' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->default_value->toString()
|
||||
);
|
||||
}
|
||||
if($this->notnull){
|
||||
$validator .= sprintf('${\'%s_argument\'}->checkNotNull();' . "\n"
|
||||
, $this->argument_name
|
||||
);
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
/**
|
||||
* 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();
|
||||
|
||||
$this->default_value = $tag->attrs->default;
|
||||
$this->notnull = $tag->attrs->notnull;
|
||||
$this->filter = $tag->attrs->filter;
|
||||
$this->min_length = $tag->attrs->min_length;
|
||||
$this->max_length = $tag->attrs->max_length;
|
||||
}
|
||||
|
||||
?>
|
||||
function isIgnorable()
|
||||
{
|
||||
if(isset($this->default_value) || isset($this->notnull))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function toString()
|
||||
{
|
||||
$validator = '';
|
||||
if($this->filter)
|
||||
{
|
||||
$validator .= sprintf('${\'%s_argument\'}->checkFilter(\'%s\');' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->filter
|
||||
);
|
||||
}
|
||||
if($this->min_length)
|
||||
{
|
||||
$validator .= sprintf('${\'%s_argument\'}->checkMinLength(%s);' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->min_length
|
||||
);
|
||||
}
|
||||
if($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(); ';
|
||||
if($this->default_value->isOperation())
|
||||
{
|
||||
$validator .= sprintf('${\'%s_argument\'}->setColumnOperation(\'%s\');' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->default_value->getOperation()
|
||||
);
|
||||
}
|
||||
$validator .= sprintf('${\'%s_argument\'}->ensureDefaultValue(%s);' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->default_value->toString()
|
||||
);
|
||||
}
|
||||
if($this->notnull)
|
||||
{
|
||||
$validator .= sprintf('${\'%s_argument\'}->checkNotNull();' . "\n"
|
||||
, $this->argument_name
|
||||
);
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file QueryArgumentValidator.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Models the <column> tag inside an XML Query file <br />
|
||||
* Since the <column> tag supports different attributes depending on
|
||||
|
|
@ -11,6 +12,7 @@
|
|||
*/
|
||||
class ColumnTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Column name
|
||||
* @var string
|
||||
|
|
@ -26,4 +28,7 @@ class ColumnTag
|
|||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file ColumnTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/column/ColumnTag.class.php */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Models the <column> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -55,4 +57,5 @@ class InsertColumnTag extends ColumnTag
|
|||
}
|
||||
|
||||
}
|
||||
?>
|
||||
/* End of file InsertColumnTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/column/InsertColumnTag.class.php */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Models the <column> tag inside an XML Query file whose action is 'insert-select'
|
||||
*
|
||||
|
|
@ -8,6 +9,7 @@
|
|||
*/
|
||||
class InsertColumnTagWithoutArgument extends ColumnTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
|
|
@ -42,4 +44,5 @@ class InsertColumnTagWithoutArgument extends ColumnTag
|
|||
}
|
||||
|
||||
}
|
||||
?>
|
||||
/* End of file InsertColumnTagWithoutArgument.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Models the <columns> tag inside an XML Query file whose action is 'insert'
|
||||
*
|
||||
|
|
@ -8,6 +9,7 @@
|
|||
*/
|
||||
class InsertColumnsTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Column list
|
||||
*
|
||||
|
|
@ -26,14 +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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +62,8 @@ class InsertColumnsTag
|
|||
function toString()
|
||||
{
|
||||
$output_columns = 'array(' . PHP_EOL;
|
||||
foreach($this->columns as $column){
|
||||
foreach($this->columns as $column)
|
||||
{
|
||||
$output_columns .= $column->getExpressionString() . PHP_EOL . ',';
|
||||
}
|
||||
$output_columns = substr($output_columns, 0, -1);
|
||||
|
|
@ -61,12 +79,13 @@ class InsertColumnsTag
|
|||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
foreach($this->columns as $column){
|
||||
foreach($this->columns as $column)
|
||||
{
|
||||
$arguments[] = $column->getArgument();
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
/* End of file InsertColumnsTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Models the <column> 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,12 +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 */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Models the <columns> tag inside an XML Query file whose action is 'select'
|
||||
*
|
||||
|
|
@ -8,6 +9,7 @@
|
|||
*/
|
||||
class SelectColumnsTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Column list
|
||||
*
|
||||
|
|
@ -24,33 +26,45 @@ 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;
|
||||
|
||||
$this->columns = array();
|
||||
|
||||
if(!$xml_columns) {
|
||||
if(!$xml_columns)
|
||||
{
|
||||
$this->columns[] = new SelectColumnTag("*");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!is_array($xml_columns)) $xml_columns = array($xml_columns);
|
||||
if(!is_array($xml_columns))
|
||||
{
|
||||
$xml_columns = array($xml_columns);
|
||||
}
|
||||
|
||||
foreach($xml_columns as $column){
|
||||
foreach($xml_columns as $column)
|
||||
{
|
||||
$this->columns[] = new SelectColumnTag($column);
|
||||
}
|
||||
|
||||
|
||||
if(!$xml_queries) {
|
||||
if(!$xml_queries)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(!is_array($xml_queries)) $xml_queries = array($xml_queries);
|
||||
if(!is_array($xml_queries))
|
||||
{
|
||||
$xml_queries = array($xml_queries);
|
||||
}
|
||||
|
||||
foreach($xml_queries as $column){
|
||||
foreach($xml_queries as $column)
|
||||
{
|
||||
$this->columns[] = new QueryTag($column, TRUE);
|
||||
}
|
||||
}
|
||||
|
|
@ -63,11 +77,16 @@ class SelectColumnsTag
|
|||
function toString()
|
||||
{
|
||||
$output_columns = 'array(' . PHP_EOL;
|
||||
foreach($this->columns as $column){
|
||||
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 .= ')';
|
||||
|
|
@ -82,11 +101,16 @@ class SelectColumnsTag
|
|||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
foreach($this->columns as $column){
|
||||
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 */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Models the <column> tag inside an XML Query file whose action is 'update'
|
||||
*
|
||||
|
|
@ -8,6 +9,7 @@
|
|||
*/
|
||||
class UpdateColumnTag extends ColumnTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Argument
|
||||
*
|
||||
|
|
@ -36,8 +38,11 @@ class UpdateColumnTag extends ColumnTag
|
|||
$this->name = $dbParser->parseColumnName($this->name);
|
||||
|
||||
if($column->attrs->var)
|
||||
{
|
||||
$this->argument = new QueryArgument($column);
|
||||
else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if(strpos($column->attrs->default, '.') !== FALSE)
|
||||
{
|
||||
$this->default_value = "'" . $dbParser->parseColumnName($column->attrs->default) . "'";
|
||||
|
|
@ -62,8 +67,6 @@ class UpdateColumnTag extends ColumnTag
|
|||
$this->default_value = '"' . $this->default_value . '"';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -78,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -98,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 */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Models the <columns> tag inside an XML Query file whose action is 'update'
|
||||
*
|
||||
|
|
@ -8,6 +9,7 @@
|
|||
*/
|
||||
class UpdateColumnsTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Column list
|
||||
*
|
||||
|
|
@ -25,11 +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);
|
||||
foreach($xml_columns as $column)
|
||||
{
|
||||
if($column->name === 'query')
|
||||
{
|
||||
$this->columns[] = new QueryTag($column, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->columns[] = new UpdateColumnTag($column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -41,7 +53,8 @@ class UpdateColumnsTag
|
|||
function toString()
|
||||
{
|
||||
$output_columns = 'array(' . PHP_EOL;
|
||||
foreach($this->columns as $column){
|
||||
foreach($this->columns as $column)
|
||||
{
|
||||
$output_columns .= $column->getExpressionString() . PHP_EOL . ',';
|
||||
}
|
||||
$output_columns = substr($output_columns, 0, -1);
|
||||
|
|
@ -57,12 +70,13 @@ class UpdateColumnsTag
|
|||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
foreach($this->columns as $column){
|
||||
foreach($this->columns as $column)
|
||||
{
|
||||
$arguments[] = $column->getArgument();
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
/* End of file UpdateColumnsTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php */
|
||||
|
|
|
|||
|
|
@ -1,66 +1,81 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ConditionGroupTag class
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/condition
|
||||
* @version 0.1
|
||||
*/
|
||||
class ConditionGroupTag
|
||||
{
|
||||
|
||||
/**
|
||||
* ConditionGroupTag class
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/condition
|
||||
* @version 0.1
|
||||
* condition list
|
||||
* @var string|array value is ConditionTag object
|
||||
*/
|
||||
class ConditionGroupTag {
|
||||
/**
|
||||
* condition list
|
||||
* @var string|array value is ConditionTag object
|
||||
*/
|
||||
var $conditions;
|
||||
/**
|
||||
* pipe
|
||||
* @var string
|
||||
*/
|
||||
var $pipe;
|
||||
var $conditions;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string|array $conditions
|
||||
* @param string $pipe
|
||||
* @return void
|
||||
*/
|
||||
function ConditionGroupTag($conditions, $pipe = ""){
|
||||
$this->pipe = $pipe;
|
||||
/**
|
||||
* pipe
|
||||
* @var string
|
||||
*/
|
||||
var $pipe;
|
||||
|
||||
if(!is_array($conditions)) $conditions = array($conditions);
|
||||
/**
|
||||
* constructor
|
||||
* @param string|array $conditions
|
||||
* @param string $pipe
|
||||
* @return void
|
||||
*/
|
||||
function ConditionGroupTag($conditions, $pipe = "")
|
||||
{
|
||||
$this->pipe = $pipe;
|
||||
|
||||
foreach($conditions as $condition){
|
||||
//if($condition->node_name === 'query') $this->conditions[] = new QueryTag($condition, true);
|
||||
$this->conditions[] = new ConditionTag($condition);
|
||||
}
|
||||
if(!is_array($conditions))
|
||||
{
|
||||
$conditions = array($conditions);
|
||||
}
|
||||
|
||||
function getConditions(){
|
||||
return $this->conditions;
|
||||
foreach($conditions as $condition)
|
||||
{
|
||||
//if($condition->node_name === 'query') $this->conditions[] = new QueryTag($condition, true);
|
||||
$this->conditions[] = new ConditionTag($condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* ConditionTag object to string
|
||||
* @return string
|
||||
*/
|
||||
function getConditionGroupString(){
|
||||
$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 .= ')';
|
||||
|
||||
return sprintf("new ConditionGroup(%s%s)", $conditions_string, $this->pipe ? ',\''.$this->pipe . '\'': '');
|
||||
}
|
||||
|
||||
function getArguments(){
|
||||
$arguments = array();
|
||||
foreach($this->conditions as $condition){
|
||||
$arguments = array_merge($arguments, $condition->getArguments());
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
function getConditions()
|
||||
{
|
||||
return $this->conditions;
|
||||
}
|
||||
|
||||
/**
|
||||
* ConditionTag object to string
|
||||
* @return string
|
||||
*/
|
||||
function getConditionGroupString()
|
||||
{
|
||||
$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 .= ')';
|
||||
|
||||
return sprintf("new ConditionGroup(%s%s)", $conditions_string, $this->pipe ? ',\'' . $this->pipe . '\'' : '');
|
||||
}
|
||||
|
||||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
foreach($this->conditions as $condition)
|
||||
{
|
||||
$arguments = array_merge($arguments, $condition->getArguments());
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file ConditionGroupTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php */
|
||||
|
|
|
|||
|
|
@ -1,156 +1,186 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
|
||||
/**
|
||||
* ConditionTag
|
||||
* Models the <condition> tag inside an XML Query file. Base class.
|
||||
*
|
||||
* @author Corina
|
||||
* @package /classes/xml/xmlquery/tags/condition
|
||||
* @version 0.1
|
||||
* operation for example 'in', 'between', 'not in'...
|
||||
* @var string
|
||||
*/
|
||||
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;
|
||||
var $operation;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param object $condition
|
||||
* @return void
|
||||
*/
|
||||
function ConditionTag($condition){
|
||||
$this->operation = $condition->attrs->operation;
|
||||
$this->pipe = $condition->attrs->pipe;
|
||||
$dbParser = DB::getParser();
|
||||
$this->column_name = $dbParser->parseExpression($condition->attrs->column);
|
||||
/**
|
||||
* Column name
|
||||
* @var string
|
||||
*/
|
||||
var $column_name;
|
||||
|
||||
// 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 ))
|
||||
{
|
||||
$condition->attrs->default = $dbParser->parseExpression($condition->attrs->default);
|
||||
}
|
||||
/**
|
||||
* Pipe
|
||||
* @var string
|
||||
*/
|
||||
var $pipe;
|
||||
|
||||
if($condition->node_name == 'query')
|
||||
/**
|
||||
* 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;
|
||||
$dbParser = DB::getParser();
|
||||
$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 ))
|
||||
{
|
||||
$condition->attrs->default = $dbParser->parseExpression($condition->attrs->default);
|
||||
}
|
||||
|
||||
if($condition->node_name == 'query')
|
||||
{
|
||||
$this->query = new QueryTag($condition, TRUE);
|
||||
$this->default_column = $this->query->toString();
|
||||
}
|
||||
else if($condition->attrs->var && !strpos($condition->attrs->var, '.'))
|
||||
{
|
||||
$this->argument = new QueryArgument($condition);
|
||||
$this->argument_name = $this->argument->getArgumentName();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isset($condition->attrs->default))
|
||||
{
|
||||
$this->query = new QueryTag($condition, TRUE);
|
||||
$this->default_column = $this->query->toString();
|
||||
}
|
||||
else if($condition->attrs->var && !strpos($condition->attrs->var, '.'))
|
||||
{
|
||||
$this->argument = new QueryArgument($condition);
|
||||
$this->argument_name = $this->argument->getArgumentName();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isset($condition->attrs->default))
|
||||
$operationList = array('in' => 1, 'between' => 1, 'not in' => 1);
|
||||
if(isset($operationList[$this->operation]))
|
||||
{
|
||||
$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 = $condition->attrs->default;
|
||||
if(strpos($default_value, "'") !== FALSE)
|
||||
$default_value = "\"" . $default_value . "\"";
|
||||
else
|
||||
{
|
||||
$default_value = "'" . $default_value . "'";
|
||||
}
|
||||
$default_value = "\"" . $default_value . "\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
$default_value_object = new DefaultValue($this->column_name, $condition->attrs->default);
|
||||
$default_value = $default_value_object->toString();
|
||||
|
||||
if($default_value_object->isStringFromFunction())
|
||||
{
|
||||
$default_value = '"\'".' . $default_value . '."\'"';
|
||||
}
|
||||
|
||||
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 . "'";
|
||||
}
|
||||
$default_value = "'" . $default_value . "'";
|
||||
}
|
||||
$this->default_column = $default_value;
|
||||
}
|
||||
else
|
||||
$this->default_column = "'" . $dbParser->parseColumnName($condition->attrs->var) . "'";
|
||||
{
|
||||
$default_value_object = new DefaultValue($this->column_name, $condition->attrs->default);
|
||||
$default_value = $default_value_object->toString();
|
||||
|
||||
if($default_value_object->isStringFromFunction())
|
||||
{
|
||||
$default_value = '"\'".' . $default_value . '."\'"';
|
||||
}
|
||||
|
||||
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) . "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setPipe($pipe){
|
||||
$this->pipe = $pipe;
|
||||
function setPipe($pipe)
|
||||
{
|
||||
$this->pipe = $pipe;
|
||||
}
|
||||
|
||||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
if($this->query)
|
||||
{
|
||||
$arguments = array_merge($arguments, $this->query->getArguments());
|
||||
}
|
||||
|
||||
function getArguments(){
|
||||
$arguments = array();
|
||||
if($this->query)
|
||||
$arguments = array_merge($arguments, $this->query->getArguments());
|
||||
if($this->argument)
|
||||
$arguments[] = $this->argument;
|
||||
return $arguments;
|
||||
if($this->argument)
|
||||
{
|
||||
$arguments[] = $this->argument;
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
function getConditionString(){
|
||||
if($this->query){
|
||||
return sprintf("new ConditionSubquery('%s',%s,%s%s)"
|
||||
, $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 . "'" : ''
|
||||
);
|
||||
}
|
||||
else{
|
||||
return sprintf("new ConditionWithArgument('%s',%s,%s%s)"
|
||||
, $this->column_name
|
||||
, '$' . $this->argument_name . '_argument'
|
||||
, '"'.$this->operation.'"'
|
||||
, $this->pipe ? ", '" . $this->pipe . "'" : ''
|
||||
);
|
||||
}
|
||||
function getConditionString()
|
||||
{
|
||||
if($this->query)
|
||||
{
|
||||
return sprintf("new ConditionSubquery('%s',%s,%s%s)"
|
||||
, $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 . "'" : ''
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return sprintf("new ConditionWithArgument('%s',%s,%s%s)"
|
||||
, $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 */
|
||||
|
|
|
|||
|
|
@ -1,70 +1,97 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ConditionsTag class
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/condition
|
||||
* @version 0.1
|
||||
*/
|
||||
class ConditionsTag
|
||||
{
|
||||
|
||||
/**
|
||||
* ConditionsTag class
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/condition
|
||||
* @version 0.1
|
||||
* ConditionGroupTag list
|
||||
* @var array value is ConditionGroupTag object
|
||||
*/
|
||||
class ConditionsTag {
|
||||
/**
|
||||
* ConditionGroupTag list
|
||||
* @var array value is ConditionGroupTag object
|
||||
*/
|
||||
var $condition_groups;
|
||||
var $condition_groups;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param object $xml_conditions
|
||||
* @return void
|
||||
*/
|
||||
function ConditionsTag($xml_conditions){
|
||||
$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);
|
||||
$xml_condition_list = array_merge($xml_condition_list, $xml_conditions->query);
|
||||
}
|
||||
if($xml_condition_list){
|
||||
$this->condition_groups[] = new ConditionGroupTag($xml_condition_list);
|
||||
}
|
||||
|
||||
$xml_groups = $xml_conditions->group;
|
||||
if($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);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* constructor
|
||||
* @param object $xml_conditions
|
||||
* @return void
|
||||
*/
|
||||
function ConditionsTag($xml_conditions)
|
||||
{
|
||||
$this->condition_groups = array();
|
||||
if(!$xml_conditions)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* ConditionGroupTag object to string
|
||||
* @return string
|
||||
*/
|
||||
function toString(){
|
||||
$output_conditions = 'array(' . PHP_EOL;
|
||||
foreach($this->condition_groups as $condition){
|
||||
$output_conditions .= $condition->getConditionGroupString() . PHP_EOL . ',';
|
||||
}
|
||||
$output_conditions = substr($output_conditions, 0, -1);
|
||||
$output_conditions .= ')';
|
||||
return $output_conditions;
|
||||
$xml_condition_list = array();
|
||||
if($xml_conditions->condition)
|
||||
{
|
||||
$xml_condition_list = $xml_conditions->condition;
|
||||
}
|
||||
|
||||
function getArguments(){
|
||||
$arguments = array();
|
||||
foreach($this->condition_groups as $condition){
|
||||
$arguments = array_merge($arguments, $condition->getArguments());
|
||||
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);
|
||||
}
|
||||
$xml_condition_list = array_merge($xml_condition_list, $xml_conditions->query);
|
||||
}
|
||||
if($xml_condition_list)
|
||||
{
|
||||
$this->condition_groups[] = new ConditionGroupTag($xml_condition_list);
|
||||
}
|
||||
|
||||
$xml_groups = $xml_conditions->group;
|
||||
if($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);
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
/**
|
||||
* ConditionGroupTag object to string
|
||||
* @return string
|
||||
*/
|
||||
function toString()
|
||||
{
|
||||
$output_conditions = 'array(' . PHP_EOL;
|
||||
foreach($this->condition_groups as $condition)
|
||||
{
|
||||
$output_conditions .= $condition->getConditionGroupString() . PHP_EOL . ',';
|
||||
}
|
||||
$output_conditions = substr($output_conditions, 0, -1);
|
||||
$output_conditions .= ')';
|
||||
return $output_conditions;
|
||||
}
|
||||
|
||||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
foreach($this->condition_groups as $condition)
|
||||
{
|
||||
$arguments = array_merge($arguments, $condition->getArguments());
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file ConditionsTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/condition/ConditionsTag.class.php */
|
||||
|
|
|
|||
|
|
@ -1,21 +1,26 @@
|
|||
<?php
|
||||
<?php
|
||||
|
||||
/**
|
||||
* JoinConditionsTag class
|
||||
*
|
||||
* @author Corina
|
||||
* @package /classes/xml/xmlquery/tags/condition
|
||||
* @version 0.1
|
||||
*/
|
||||
class JoinConditionsTag extends ConditionsTag
|
||||
{
|
||||
|
||||
/**
|
||||
* JoinConditionsTag class
|
||||
*
|
||||
* @author Corina
|
||||
* @package /classes/xml/xmlquery/tags/condition
|
||||
* @version 0.1
|
||||
* constructor
|
||||
* @param object $xml_conditions
|
||||
* @return void
|
||||
*/
|
||||
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("");
|
||||
}
|
||||
function JoinConditionsTag($xml_conditions)
|
||||
{
|
||||
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 */
|
||||
|
|
|
|||
|
|
@ -1,50 +1,65 @@
|
|||
<?php
|
||||
<?php
|
||||
|
||||
/**
|
||||
* GroupsTag class
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/group
|
||||
* @version 0.1
|
||||
*/
|
||||
class GroupsTag
|
||||
{
|
||||
|
||||
/**
|
||||
* GroupsTag class
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/group
|
||||
* @version 0.1
|
||||
* column list
|
||||
* @var array
|
||||
*/
|
||||
class GroupsTag {
|
||||
/**
|
||||
* column list
|
||||
* @var array
|
||||
*/
|
||||
var $groups;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param array|string $xml_groups
|
||||
* @return void
|
||||
*/
|
||||
function GroupsTag($xml_groups){
|
||||
$this->groups = array();
|
||||
|
||||
if($xml_groups) {
|
||||
if(!is_array($xml_groups)) $xml_groups = array($xml_groups);
|
||||
|
||||
$dbParser = &DB::getParser();
|
||||
for($i=0;$i<count($xml_groups);$i++) {
|
||||
$group = $xml_groups[$i];
|
||||
$column = trim($group->attrs->column);
|
||||
if(!$column) continue;
|
||||
|
||||
$column = $dbParser->parseExpression($column);
|
||||
$this->groups[] = $column;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function toString(){
|
||||
$output = 'array(' . PHP_EOL;
|
||||
foreach($this->groups as $group){
|
||||
$output .= "'" . $group . "' ,";
|
||||
var $groups;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param array|string $xml_groups
|
||||
* @return void
|
||||
*/
|
||||
function GroupsTag($xml_groups)
|
||||
{
|
||||
$this->groups = array();
|
||||
|
||||
if($xml_groups)
|
||||
{
|
||||
if(!is_array($xml_groups))
|
||||
{
|
||||
$xml_groups = array($xml_groups);
|
||||
}
|
||||
|
||||
$dbParser = &DB::getParser();
|
||||
for($i = 0; $i < count($xml_groups); $i++)
|
||||
{
|
||||
$group = $xml_groups[$i];
|
||||
$column = trim($group->attrs->column);
|
||||
if(!$column)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$column = $dbParser->parseExpression($column);
|
||||
$this->groups[] = $column;
|
||||
}
|
||||
$output = substr($output, 0, -1);
|
||||
$output .= ')';
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
function toString()
|
||||
{
|
||||
$output = 'array(' . PHP_EOL;
|
||||
foreach($this->groups as $group)
|
||||
{
|
||||
$output .= "'" . $group . "' ,";
|
||||
}
|
||||
$output = substr($output, 0, -1);
|
||||
$output .= ')';
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file GroupsTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/group/GroupsTag.class.php */
|
||||
|
|
|
|||
|
|
@ -1,77 +1,94 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* IndexTag class
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/navigation
|
||||
* @version 0.1
|
||||
*/
|
||||
class IndexTag
|
||||
{
|
||||
|
||||
/**
|
||||
* IndexTag class
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/navigation
|
||||
* @version 0.1
|
||||
* argument name
|
||||
* @var string
|
||||
*/
|
||||
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;
|
||||
var $argument_name;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param object $index
|
||||
* @return void
|
||||
*/
|
||||
function IndexTag($index){
|
||||
$this->argument_name = $index->attrs->var;
|
||||
/**
|
||||
* QueryArgument object
|
||||
* @var QueryArgument
|
||||
*/
|
||||
var $argument;
|
||||
|
||||
// Sort index - column by which to sort
|
||||
//$dbParser = new DB(); $dbParser = &$dbParser->getParser();
|
||||
//$index->attrs->default = $dbParser->parseExpression($index->attrs->default);
|
||||
$this->default = $index->attrs->default;
|
||||
$this->argument = new QueryArgument($index);
|
||||
/**
|
||||
* Default value
|
||||
* @var string
|
||||
*/
|
||||
var $default;
|
||||
|
||||
// Sort order - asc / desc
|
||||
$this->sort_order = $index->attrs->order;
|
||||
$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;
|
||||
$arg->attrs->default = 'asc';
|
||||
$this->sort_order_argument = new SortQueryArgument($arg);
|
||||
$this->sort_order = '$'.$this->sort_order_argument->getArgumentName().'_argument';
|
||||
}
|
||||
else $this->sort_order = '"'.$this->sort_order.'"';
|
||||
/**
|
||||
* 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;
|
||||
|
||||
// Sort index - column by which to sort
|
||||
//$dbParser = new DB(); $dbParser = &$dbParser->getParser();
|
||||
//$index->attrs->default = $dbParser->parseExpression($index->attrs->default);
|
||||
$this->default = $index->attrs->default;
|
||||
$this->argument = new QueryArgument($index);
|
||||
|
||||
// Sort order - asc / desc
|
||||
$this->sort_order = $index->attrs->order;
|
||||
$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;
|
||||
$arg->attrs->default = 'asc';
|
||||
$this->sort_order_argument = new SortQueryArgument($arg);
|
||||
$this->sort_order = '$' . $this->sort_order_argument->getArgumentName() . '_argument';
|
||||
}
|
||||
|
||||
function toString(){
|
||||
return sprintf('new OrderByColumn(${\'%s_argument\'}, %s)', $this->argument->getArgumentName(), $this->sort_order);
|
||||
}
|
||||
|
||||
function getArguments(){
|
||||
$arguments = array();
|
||||
$arguments[] = $this->argument;
|
||||
if($this->sort_order_argument)
|
||||
$arguments[] = $this->sort_order_argument;
|
||||
return $arguments;
|
||||
else
|
||||
{
|
||||
$this->sort_order = '"' . $this->sort_order . '"';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
function toString()
|
||||
{
|
||||
return sprintf('new OrderByColumn(${\'%s_argument\'}, %s)', $this->argument->getArgumentName(), $this->sort_order);
|
||||
}
|
||||
|
||||
function getArguments()
|
||||
{
|
||||
$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 */
|
||||
|
|
|
|||
|
|
@ -1,57 +1,75 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* LimitTag class
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/navigation
|
||||
* @version 0.1
|
||||
*/
|
||||
class LimitTag
|
||||
{
|
||||
|
||||
/**
|
||||
* LimitTag class
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/navigation
|
||||
* @version 0.1
|
||||
* Value is relate to limit query
|
||||
* @var array
|
||||
*/
|
||||
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;
|
||||
var $arguments;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
$this->page_count = new QueryArgument($index->page_count);
|
||||
$this->arguments[] = $this->page;
|
||||
$this->arguments[] = $this->page_count;
|
||||
}
|
||||
/**
|
||||
* QueryArgument object
|
||||
* @var QueryArgument
|
||||
*/
|
||||
var $page;
|
||||
|
||||
$this->list_count = new QueryArgument($index->list_count);
|
||||
$this->arguments[] = $this->list_count;
|
||||
/**
|
||||
* 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);
|
||||
$this->page_count = new QueryArgument($index->page_count);
|
||||
$this->arguments[] = $this->page;
|
||||
$this->arguments[] = $this->page_count;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
$this->list_count = new QueryArgument($index->list_count);
|
||||
$this->arguments[] = $this->list_count;
|
||||
}
|
||||
|
||||
function getArguments(){
|
||||
return $this->arguments;
|
||||
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());
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
function getArguments()
|
||||
{
|
||||
return $this->arguments;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file LimitTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/navigation/LimitTag.class.php */
|
||||
|
|
|
|||
|
|
@ -1,99 +1,136 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NavigationTag class
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/navigation
|
||||
* @version 0.1
|
||||
*/
|
||||
class NavigationTag
|
||||
{
|
||||
|
||||
/**
|
||||
* NavigationTag class
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/navigation
|
||||
* @version 0.1
|
||||
* Order
|
||||
* @var array
|
||||
*/
|
||||
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;
|
||||
var $order;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param object $xml_navigation
|
||||
* @return void
|
||||
*/
|
||||
function NavigationTag($xml_navigation){
|
||||
$this->order = array();
|
||||
if($xml_navigation) {
|
||||
$order = $xml_navigation->index;
|
||||
if($order) {
|
||||
if(!is_array($order)) $order = array($order);
|
||||
foreach($order as $order_info) {
|
||||
$this->order[] = new IndexTag($order_info);
|
||||
}
|
||||
/**
|
||||
* List count
|
||||
* @var int
|
||||
*/
|
||||
var $list_count;
|
||||
|
||||
if($xml_navigation->page && $xml_navigation->page->attrs || $xml_navigation->list_count && $xml_navigation->list_count->attrs)
|
||||
$this->limit = new LimitTag($xml_navigation);
|
||||
/**
|
||||
* Page count
|
||||
* @var int
|
||||
*/
|
||||
var $page_count;
|
||||
|
||||
if ($xml_navigation->list_count)
|
||||
$this->list_count = $xml_navigation->list_count->attrs;
|
||||
/**
|
||||
* Page
|
||||
* @var int
|
||||
*/
|
||||
var $page;
|
||||
|
||||
if ($xml_navigation->page_count)
|
||||
$this->page_count = $xml_navigation->page_count->attrs;
|
||||
/**
|
||||
* Limit
|
||||
* @var LimitTag object
|
||||
*/
|
||||
var $limit;
|
||||
|
||||
if ($xml_navigation->page)
|
||||
$this->page = $xml_navigation->page->attrs;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* constructor
|
||||
* @param object $xml_navigation
|
||||
* @return void
|
||||
*/
|
||||
function NavigationTag($xml_navigation)
|
||||
{
|
||||
$this->order = array();
|
||||
if($xml_navigation)
|
||||
{
|
||||
$order = $xml_navigation->index;
|
||||
if($order)
|
||||
{
|
||||
if(!is_array($order))
|
||||
{
|
||||
$order = array($order);
|
||||
}
|
||||
foreach($order as $order_info)
|
||||
{
|
||||
$this->order[] = new IndexTag($order_info);
|
||||
}
|
||||
|
||||
/**
|
||||
* NavigationTag object to string
|
||||
* @return string
|
||||
*/
|
||||
function getOrderByString(){
|
||||
$output = 'array(' . PHP_EOL;
|
||||
foreach($this->order as $order){
|
||||
$output .= $order->toString() . PHP_EOL . ',';
|
||||
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;
|
||||
}
|
||||
|
||||
if($xml_navigation->page_count)
|
||||
{
|
||||
$this->page_count = $xml_navigation->page_count->attrs;
|
||||
}
|
||||
|
||||
if($xml_navigation->page)
|
||||
{
|
||||
$this->page = $xml_navigation->page->attrs;
|
||||
}
|
||||
}
|
||||
$output = substr($output, 0, -1);
|
||||
$output .= ')';
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* LimitTag object to string
|
||||
* @return string
|
||||
*/
|
||||
function getLimitString(){
|
||||
if ($this->limit) return $this->limit->toString();
|
||||
else return "";
|
||||
}
|
||||
|
||||
function getArguments(){
|
||||
$arguments = array();
|
||||
foreach($this->order as $order){
|
||||
$arguments = array_merge($order->getArguments(), $arguments);
|
||||
}
|
||||
if($this->limit) $arguments = array_merge($this->limit->getArguments(), $arguments);
|
||||
return $arguments;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
/**
|
||||
* NavigationTag object to string
|
||||
* @return string
|
||||
*/
|
||||
function getOrderByString()
|
||||
{
|
||||
$output = 'array(' . PHP_EOL;
|
||||
foreach($this->order as $order)
|
||||
{
|
||||
$output .= $order->toString() . PHP_EOL . ',';
|
||||
}
|
||||
$output = substr($output, 0, -1);
|
||||
$output .= ')';
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* LimitTag object to string
|
||||
* @return string
|
||||
*/
|
||||
function getLimitString()
|
||||
{
|
||||
if($this->limit)
|
||||
{
|
||||
return $this->limit->toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
foreach($this->order as $order)
|
||||
{
|
||||
$arguments = array_merge($order->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 */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* QueryTag class
|
||||
*
|
||||
|
|
@ -6,87 +7,105 @@
|
|||
* @package /classes/xml/xmlquery/tags/query
|
||||
* @version 0.1
|
||||
*/
|
||||
class QueryTag {
|
||||
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
|
||||
|
|
@ -99,15 +118,19 @@ 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;
|
||||
$this->priority = $query->attrs->priority;
|
||||
$this->query = $query;
|
||||
$this->isSubQuery = $isSubQuery;
|
||||
if ($this->isSubQuery)
|
||||
if($this->isSubQuery)
|
||||
{
|
||||
$this->action = 'select';
|
||||
if ($query->attrs->alias) {
|
||||
}
|
||||
if($query->attrs->alias)
|
||||
{
|
||||
$dbParser = DB::getParser();
|
||||
$this->alias = $dbParser->escape($query->attrs->alias);
|
||||
}
|
||||
|
|
@ -120,35 +143,42 @@ class QueryTag {
|
|||
$this->getConditions();
|
||||
$this->getGroups();
|
||||
$this->getNavigation();
|
||||
|
||||
|
||||
|
||||
$this->getPrebuff();
|
||||
$this->getBuff();
|
||||
}
|
||||
|
||||
function show() {
|
||||
return true;
|
||||
function show()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function getQueryId() {
|
||||
function getQueryId()
|
||||
{
|
||||
return $this->query->attrs->query_id ? $this->query->attrs->query_id : $this->query->attrs->id;
|
||||
}
|
||||
|
||||
function getPriority() {
|
||||
function getPriority()
|
||||
{
|
||||
return $this->query->attrs->priority;
|
||||
}
|
||||
|
||||
function getAction() {
|
||||
function getAction()
|
||||
{
|
||||
return $this->query->attrs->action;
|
||||
}
|
||||
|
||||
function setTableColumnTypes($tables) {
|
||||
function setTableColumnTypes($tables)
|
||||
{
|
||||
$query_id = $this->getQueryId();
|
||||
if (!isset($this->column_type[$query_id])) {
|
||||
if(!isset($this->column_type[$query_id]))
|
||||
{
|
||||
$table_tags = $tables->getTables();
|
||||
$column_type = array();
|
||||
foreach ($table_tags as $table_tag) {
|
||||
if (is_a($table_tag, 'TableTag')) {
|
||||
foreach($table_tags as $table_tag)
|
||||
{
|
||||
if(is_a($table_tag, 'TableTag'))
|
||||
{
|
||||
$table_name = $table_tag->getTableName();
|
||||
$table_alias = $table_tag->getTableAlias();
|
||||
$tag_column_type = QueryParser::getTableInfo($query_id, $table_name);
|
||||
|
|
@ -159,54 +189,74 @@ class QueryTag {
|
|||
}
|
||||
}
|
||||
|
||||
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 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;
|
||||
function getPrebuff()
|
||||
{
|
||||
if($this->isSubQuery)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// TODO Check if this work with arguments in join clause
|
||||
$arguments = $this->getArguments();
|
||||
|
||||
$prebuff = '';
|
||||
foreach ($arguments as $argument) {
|
||||
if (isset($argument)) {
|
||||
foreach($arguments as $argument)
|
||||
{
|
||||
if(isset($argument))
|
||||
{
|
||||
$arg_name = $argument->getArgumentName();
|
||||
if ($arg_name) {
|
||||
if($arg_name)
|
||||
{
|
||||
unset($column_type);
|
||||
$prebuff .= $argument->toString();
|
||||
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -215,9 +265,11 @@ class QueryTag {
|
|||
return $this->preBuff = $prebuff;
|
||||
}
|
||||
|
||||
function getBuff() {
|
||||
function getBuff()
|
||||
{
|
||||
$buff = '';
|
||||
if ($this->isSubQuery) {
|
||||
if($this->isSubQuery)
|
||||
{
|
||||
$buff = 'new Subquery(';
|
||||
$buff .= "'" . $this->alias . '\', ';
|
||||
$buff .= ($this->columns ? $this->columns->toString() : 'null' ) . ', ' . PHP_EOL;
|
||||
|
|
@ -239,77 +291,104 @@ class QueryTag {
|
|||
$buff .= sprintf('$query->setAction("%s");%s', $this->action, "\n");
|
||||
$buff .= sprintf('$query->setPriority("%s");%s', $this->priority, "\n");
|
||||
$buff .= $this->preBuff;
|
||||
if ($this->columns)
|
||||
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;
|
||||
}
|
||||
|
||||
function getTables() {
|
||||
function getTables()
|
||||
{
|
||||
if($this->query->index_hint && ($this->query->index_hint->attrs->for == 'ALL' || Context::getDBType() == strtolower($this->query->index_hint->attrs->for)))
|
||||
{
|
||||
return $this->tables = new TablesTag($this->query->tables, $this->query->index_hint);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->tables = new TablesTag($this->query->tables);
|
||||
}
|
||||
}
|
||||
|
||||
function getSubquery(){
|
||||
if($this->query->query){
|
||||
function getSubquery()
|
||||
{
|
||||
if($this->query->query)
|
||||
{
|
||||
$this->subquery = new QueryTag($this->query->query, true);
|
||||
}
|
||||
}
|
||||
|
||||
function getConditions(){
|
||||
|
||||
function getConditions()
|
||||
{
|
||||
return $this->conditions = new ConditionsTag($this->query->conditions);
|
||||
}
|
||||
|
||||
function getGroups() {
|
||||
if ($this->query->groups)
|
||||
return $this->groups = new GroupsTag($this->query->groups->group);
|
||||
function getGroups()
|
||||
{
|
||||
if($this->query->groups)
|
||||
{
|
||||
return $this->groups = new GroupsTag($this->query->groups->group);
|
||||
}
|
||||
else
|
||||
return $this->groups = new GroupsTag(NULL);
|
||||
{
|
||||
return $this->groups = new GroupsTag(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
function getNavigation() {
|
||||
function getNavigation()
|
||||
{
|
||||
return $this->navigation = new NavigationTag($this->query->navigation);
|
||||
}
|
||||
|
||||
function toString() {
|
||||
function toString()
|
||||
{
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
function getTableString() {
|
||||
function getTableString()
|
||||
{
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
function getConditionString() {
|
||||
function getConditionString()
|
||||
{
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
function getExpressionString() {
|
||||
function getExpressionString()
|
||||
{
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
function getArguments(){
|
||||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
if ($this->columns)
|
||||
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->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 */
|
||||
|
|
|
|||
|
|
@ -1,54 +1,65 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Action for example, 'select', 'insert', 'delete'...
|
||||
* @var array
|
||||
*/
|
||||
class HintTableTag extends TableTag {
|
||||
/**
|
||||
* Action for example, 'select', 'insert', 'delete'...
|
||||
* @var array
|
||||
*/
|
||||
var $index;
|
||||
var $index;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
function getTableString(){
|
||||
$dbParser = DB::getParser();
|
||||
$dbType = ucfirst(Context::getDBType());
|
||||
|
||||
$result = sprintf('new %sTableWithHint(\'%s\'%s, array('
|
||||
, $dbType == 'Mysqli' ? 'Mysql' : $dbType
|
||||
, $dbParser->escape($this->name)
|
||||
, $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 = substr($result, 0, -2);
|
||||
$result .= '))';
|
||||
return $result;
|
||||
}
|
||||
|
||||
function getArguments(){
|
||||
if(!isset($this->conditionsTag)) return array();
|
||||
return $this->conditionsTag->getArguments();
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
?>
|
||||
function getTableString()
|
||||
{
|
||||
$dbParser = DB::getParser();
|
||||
$dbType = ucfirst(Context::getDBType());
|
||||
|
||||
$result = sprintf('new %sTableWithHint(\'%s\'%s, array('
|
||||
, $dbType == 'Mysqli' ? 'Mysql' : $dbType
|
||||
, $dbParser->escape($this->name)
|
||||
, $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 = substr($result, 0, -2);
|
||||
$result .= '))';
|
||||
return $result;
|
||||
}
|
||||
|
||||
function getArguments()
|
||||
{
|
||||
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 */
|
||||
|
|
|
|||
|
|
@ -1,118 +1,144 @@
|
|||
<?php
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*
|
||||
* @author Arnia Sowftare
|
||||
* @package /classes/xml/xmlquery/tags/table
|
||||
* @version 0.1
|
||||
*/
|
||||
class TableTag
|
||||
{
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*
|
||||
* @author Arnia Sowftare
|
||||
* @package /classes/xml/xmlquery/tags/table
|
||||
* @version 0.1
|
||||
* Unescaped name
|
||||
* @var string
|
||||
*/
|
||||
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;
|
||||
var $unescaped_name;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* Initialises Table Tag properties
|
||||
* @param object $table XML <table> tag
|
||||
* @return void
|
||||
*/
|
||||
function TableTag($table){
|
||||
$dbParser = DB::getParser();
|
||||
|
||||
$this->unescaped_name = $table->attrs->name;
|
||||
$this->name = $dbParser->parseTableName($table->attrs->name);
|
||||
|
||||
$this->alias = $table->attrs->alias;
|
||||
if(!$this->alias) $this->alias = $table->attrs->name;
|
||||
|
||||
$this->join_type = $table->attrs->type;
|
||||
|
||||
$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;
|
||||
return false;
|
||||
}
|
||||
|
||||
function getTableAlias(){
|
||||
return $this->alias;
|
||||
}
|
||||
|
||||
function getTableName(){
|
||||
return $this->unescaped_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
/**
|
||||
* name
|
||||
* @var string
|
||||
*/
|
||||
var $name;
|
||||
|
||||
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());
|
||||
}
|
||||
return sprintf('new Table(\'%s\'%s)'
|
||||
, $dbParser->escape($this->name)
|
||||
, $this->alias ? ', \'' . $dbParser->escape($this->alias) .'\'' : '');
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* Initialises Table Tag properties
|
||||
* @param object $table XML <table> tag
|
||||
* @return void
|
||||
*/
|
||||
function TableTag($table)
|
||||
{
|
||||
$dbParser = DB::getParser();
|
||||
|
||||
$this->unescaped_name = $table->attrs->name;
|
||||
$this->name = $dbParser->parseTableName($table->attrs->name);
|
||||
|
||||
$this->alias = $table->attrs->alias;
|
||||
if(!$this->alias)
|
||||
{
|
||||
$this->alias = $table->attrs->name;
|
||||
}
|
||||
|
||||
$this->join_type = $table->attrs->type;
|
||||
|
||||
$this->conditions = $table->conditions;
|
||||
|
||||
if($this->isJoinTable())
|
||||
{
|
||||
$this->conditionsTag = new JoinConditionsTag($this->conditions);
|
||||
}
|
||||
|
||||
function getArguments(){
|
||||
if(!isset($this->conditionsTag)) return array();
|
||||
return $this->conditionsTag->getArguments();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getTableAlias()
|
||||
{
|
||||
return $this->alias;
|
||||
}
|
||||
|
||||
function getTableName()
|
||||
{
|
||||
return $this->unescaped_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
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());
|
||||
}
|
||||
return sprintf('new Table(\'%s\'%s)'
|
||||
, $dbParser->escape($this->name)
|
||||
, $this->alias ? ', \'' . $dbParser->escape($this->alias) . '\'' : '');
|
||||
}
|
||||
|
||||
function getArguments()
|
||||
{
|
||||
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 */
|
||||
|
|
|
|||
|
|
@ -1,87 +1,121 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*
|
||||
* @author Arnia Sowftare
|
||||
* @package /classes/xml/xmlquery/tags/table
|
||||
* @version 0.1
|
||||
*/
|
||||
class TablesTag
|
||||
{
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*
|
||||
* @author Arnia Sowftare
|
||||
* @package /classes/xml/xmlquery/tags/table
|
||||
* @version 0.1
|
||||
* Table list
|
||||
* @var array
|
||||
*/
|
||||
class TablesTag {
|
||||
/**
|
||||
* Table list
|
||||
* @var array
|
||||
*/
|
||||
var $tables;
|
||||
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();
|
||||
/**
|
||||
* 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();
|
||||
|
||||
$xml_tables = $xml_tables_tag->table;
|
||||
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);
|
||||
foreach($index_nodes as $index_node) {
|
||||
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;
|
||||
$indexes[$index_node->attrs->table][$count]->type = $index_node->attrs->type;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($xml_tables as $tag){
|
||||
if($tag->attrs->query == 'true'){
|
||||
$this->tables[] = new QueryTag($tag, true);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
$xml_tables = $xml_tables_tag->table;
|
||||
if(!is_array($xml_tables))
|
||||
{
|
||||
$xml_tables = array($xml_tables);
|
||||
}
|
||||
|
||||
function getTables(){
|
||||
return $this->tables;
|
||||
}
|
||||
|
||||
function toString(){
|
||||
$output_tables = 'array(' . PHP_EOL;
|
||||
foreach($this->tables as $table){
|
||||
if(is_a($table, 'QueryTag'))
|
||||
$output_tables .= $table->toString() . PHP_EOL . ',';
|
||||
else
|
||||
$output_tables .= $table->getTableString() . PHP_EOL . ',';
|
||||
if($xml_index_hints_tag)
|
||||
{
|
||||
$index_nodes = $xml_index_hints_tag->index;
|
||||
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();
|
||||
}
|
||||
$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;
|
||||
$indexes[$index_node->attrs->table][$count]->type = $index_node->attrs->type;
|
||||
}
|
||||
$output_tables = substr($output_tables, 0, -1);
|
||||
$output_tables .= ')';
|
||||
return $output_tables;
|
||||
}
|
||||
|
||||
function getArguments(){
|
||||
$arguments = array();
|
||||
foreach($this->tables as $table)
|
||||
$arguments = array_merge($arguments, $table->getArguments());
|
||||
return $arguments;
|
||||
}
|
||||
foreach($xml_tables as $tag)
|
||||
{
|
||||
if($tag->attrs->query == 'true')
|
||||
{
|
||||
$this->tables[] = new QueryTag($tag, true);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
function getTables()
|
||||
{
|
||||
return $this->tables;
|
||||
}
|
||||
|
||||
function toString()
|
||||
{
|
||||
$output_tables = 'array(' . PHP_EOL;
|
||||
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 .= ')';
|
||||
return $output_tables;
|
||||
}
|
||||
|
||||
function getArguments()
|
||||
{
|
||||
$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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue