mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-10 04:24:14 +09:00
issue 2662 coding convention in xml class
git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12225 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
fb0df50f3f
commit
2cb9487ba1
10 changed files with 1924 additions and 1660 deletions
|
|
@ -6,7 +6,8 @@
|
||||||
* @package /classes/xml
|
* @package /classes/xml
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
*/
|
*/
|
||||||
class GeneralXmlParser {
|
class GeneralXmlParser
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* result of parse
|
* result of parse
|
||||||
* @var array
|
* @var array
|
||||||
|
|
@ -14,78 +15,86 @@ class GeneralXmlParser {
|
||||||
var $output = array();
|
var $output = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a given input to product a object containing parse values.
|
* Parse a given input to product a object containing parse values.
|
||||||
* @param string $input data to be parsed
|
* @param string $input data to be parsed
|
||||||
* @return array|NULL Returns an object containing parsed values or NULL in case of failure
|
* @return array|NULL Returns an object containing parsed values or NULL in case of failure
|
||||||
*/
|
*/
|
||||||
function parse($input = '') {
|
function parse($input = '')
|
||||||
$oParser = xml_parser_create('UTF-8');
|
{
|
||||||
xml_set_object($oParser, $this);
|
$oParser = xml_parser_create('UTF-8');
|
||||||
xml_set_element_handler($oParser, "_tagOpen", "_tagClosed");
|
xml_set_object($oParser, $this);
|
||||||
xml_set_character_data_handler($oParser, "_tagBody");
|
xml_set_element_handler($oParser, "_tagOpen", "_tagClosed");
|
||||||
|
xml_set_character_data_handler($oParser, "_tagBody");
|
||||||
|
|
||||||
xml_parse($oParser, $input);
|
xml_parse($oParser, $input);
|
||||||
xml_parser_free($oParser);
|
xml_parser_free($oParser);
|
||||||
|
|
||||||
if(!count($this->output)) return;
|
if(!count($this->output)) return;
|
||||||
$this->output = array_shift($this->output);
|
$this->output = array_shift($this->output);
|
||||||
|
|
||||||
return $this->output;
|
return $this->output;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start element handler
|
* Start element handler
|
||||||
* @param resource $parser an instance of parser
|
* @param resource $parser an instance of parser
|
||||||
* @param string $node_name a name of node
|
* @param string $node_name a name of node
|
||||||
* @param array $attrs attributes to be set
|
* @param array $attrs attributes to be set
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function _tagOpen($parser, $node_name, $attrs) {
|
function _tagOpen($parser, $node_name, $attrs)
|
||||||
$obj->node_name = strtolower($node_name);
|
{
|
||||||
$obj->attrs = $attrs;
|
$obj->node_name = strtolower($node_name);
|
||||||
$obj->childNodes = array();
|
$obj->attrs = $attrs;
|
||||||
|
$obj->childNodes = array();
|
||||||
|
|
||||||
array_push($this->output, $obj);
|
array_push($this->output, $obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Character data handler
|
* Character data handler
|
||||||
* Variable in the last element of this->output
|
* Variable in the last element of this->output
|
||||||
* @param resource $parse an instance of parser
|
* @param resource $parse an instance of parser
|
||||||
* @param string $body a data to be added
|
* @param string $body a data to be added
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function _tagBody($parser, $body) {
|
function _tagBody($parser, $body)
|
||||||
//if(!trim($body)) return;
|
{
|
||||||
$this->output[count($this->output)-1]->body .= $body;
|
//if(!trim($body)) return;
|
||||||
|
$this->output[count($this->output)-1]->body .= $body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* End element handler
|
* End element handler
|
||||||
* @param resource $parse an instance of parser
|
* @param resource $parse an instance of parser
|
||||||
* @param string $node_name name of xml node
|
* @param string $node_name name of xml node
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function _tagClosed($parser, $node_name) {
|
function _tagClosed($parser, $node_name)
|
||||||
$node_name = strtolower($node_name);
|
{
|
||||||
$cur_obj = array_pop($this->output);
|
$node_name = strtolower($node_name);
|
||||||
$parent_obj = &$this->output[count($this->output)-1];
|
$cur_obj = array_pop($this->output);
|
||||||
|
$parent_obj = &$this->output[count($this->output)-1];
|
||||||
|
|
||||||
if($parent_obj->childNodes[$node_name])
|
if($parent_obj->childNodes[$node_name])
|
||||||
{
|
{
|
||||||
$tmp_obj = $parent_obj->childNodes[$node_name];
|
$tmp_obj = $parent_obj->childNodes[$node_name];
|
||||||
if(is_array($tmp_obj)) {
|
if(is_array($tmp_obj))
|
||||||
array_push($parent_obj->childNodes[$node_name], $cur_obj);
|
{
|
||||||
} else {
|
array_push($parent_obj->childNodes[$node_name], $cur_obj);
|
||||||
$parent_obj->childNodes[$node_name] = array();
|
}
|
||||||
array_push($parent_obj->childNodes[$node_name], $tmp_obj);
|
else
|
||||||
array_push($parent_obj->childNodes[$node_name], $cur_obj);
|
{
|
||||||
}
|
$parent_obj->childNodes[$node_name] = array();
|
||||||
} else {
|
array_push($parent_obj->childNodes[$node_name], $tmp_obj);
|
||||||
$parent_obj->childNodes[$node_name] = $cur_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 */
|
||||||
|
|
|
||||||
|
|
@ -5,53 +5,70 @@
|
||||||
* @package /classes/xml
|
* @package /classes/xml
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
*/
|
*/
|
||||||
class XmlGenerator{
|
class XmlGenerator
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* object change to xml
|
* object change to xml
|
||||||
* @param object $xml
|
* @param object $xml
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function obj2xml($xml){
|
function obj2xml($xml)
|
||||||
|
{
|
||||||
$buff = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
|
$buff = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
|
||||||
|
|
||||||
foreach($xml as $nodeName => $nodeItem){
|
foreach($xml as $nodeName => $nodeItem)
|
||||||
|
{
|
||||||
$buff .= $this->_makexml($nodeItem);
|
$buff .= $this->_makexml($nodeItem);
|
||||||
}
|
}
|
||||||
return $buff;
|
return $buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* object change to xml
|
* object change to xml
|
||||||
* @param object $node node in xml object
|
* @param object $node node in xml object
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function _makexml($node){
|
function _makexml($node)
|
||||||
|
{
|
||||||
$body = '';
|
$body = '';
|
||||||
foreach($node as $key => $value){
|
foreach($node as $key => $value)
|
||||||
switch($key){
|
{
|
||||||
|
switch($key)
|
||||||
|
{
|
||||||
case 'node_name' : break;
|
case 'node_name' : break;
|
||||||
case 'attrs' : {
|
case 'attrs' :
|
||||||
$attrs = '';
|
{
|
||||||
if (isset($value)){
|
$attrs = '';
|
||||||
foreach($value as $attrName=>$attrValue){
|
if (isset($value))
|
||||||
$attrs .= sprintf(' %s="%s"', $attrName, htmlspecialchars($attrValue));
|
{
|
||||||
}
|
foreach($value as $attrName=>$attrValue)
|
||||||
}
|
{
|
||||||
}break;
|
$attrs .= sprintf(' %s="%s"', $attrName, htmlspecialchars($attrValue));
|
||||||
case 'body' : $body = $value; break;
|
}
|
||||||
default : {
|
}
|
||||||
if (is_array($value)){
|
}
|
||||||
foreach($value as $idx => $arrNode){
|
break;
|
||||||
$body .= $this->_makexml($arrNode);
|
case 'body' :
|
||||||
}
|
$body = $value;
|
||||||
}else if(is_object($value)){
|
break;
|
||||||
$body = $this->_makexml($value);
|
default :
|
||||||
}
|
{
|
||||||
}
|
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,335 @@
|
||||||
<?php
|
<?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
|
* version
|
||||||
*
|
* @var string
|
||||||
* 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 {
|
var $version = '0.2.5';
|
||||||
/**
|
/**
|
||||||
* version
|
* compiled javascript cache path
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
var $version = '0.2.5';
|
var $compiled_path = './files/cache/js_filter_compiled/'; // / directory path for compiled cache file
|
||||||
/**
|
/**
|
||||||
* compiled javascript cache path
|
* Target xml file
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
var $compiled_path = './files/cache/js_filter_compiled/'; // / directory path for compiled cache file
|
var $xml_file = NULL;
|
||||||
/**
|
/**
|
||||||
* Target xml file
|
* Compiled js file
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
var $xml_file = NULL;
|
var $js_file = NULL; // /
|
||||||
/**
|
|
||||||
* Compiled js file
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
var $js_file = NULL; // /
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param string $xml_file
|
* @param string $xml_file
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function XmlJsFilter($path, $xml_file) {
|
function XmlJsFilter($path, $xml_file)
|
||||||
if(substr($path,-1)!=='/') $path .= '/';
|
{
|
||||||
$this->xml_file = sprintf("%s%s",$path, $xml_file);
|
if(substr($path,-1)!=='/') $path .= '/';
|
||||||
$this->js_file = $this->_getCompiledFileName($this->xml_file);
|
$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
|
* Compile a xml_file only when a corresponding js file does not exists or is outdated
|
||||||
* @return void Returns NULL regardless of the success of failure of the operation
|
* @return void Returns NULL regardless of the success of failure of the operation
|
||||||
*/
|
*/
|
||||||
function compile() {
|
function compile()
|
||||||
if(!file_exists($this->xml_file)) return;
|
{
|
||||||
if(!file_exists($this->js_file)) $this->_compile();
|
if(!file_exists($this->xml_file)) return;
|
||||||
else if(filemtime($this->xml_file)>filemtime($this->js_file)) $this->_compile();
|
if(!file_exists($this->js_file)) $this->_compile();
|
||||||
Context::loadFile(array($this->js_file, 'body', '',null));
|
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
|
* compile a xml_file into js_file
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function _compile() {
|
function _compile()
|
||||||
global $lang;
|
{
|
||||||
|
global $lang;
|
||||||
|
|
||||||
// read xml file
|
// read xml file
|
||||||
$buff = FileHandler::readFile($this->xml_file);
|
$buff = FileHandler::readFile($this->xml_file);
|
||||||
|
|
||||||
// xml parsing
|
// xml parsing
|
||||||
$xml_obj = parent::parse($buff);
|
$xml_obj = parent::parse($buff);
|
||||||
|
|
||||||
$attrs = $xml_obj->filter->attrs;
|
$attrs = $xml_obj->filter->attrs;
|
||||||
$rules = $xml_obj->filter->rules;
|
$rules = $xml_obj->filter->rules;
|
||||||
|
|
||||||
// XmlJsFilter handles three data; filter_name, field, and parameter
|
// XmlJsFilter handles three data; filter_name, field, and parameter
|
||||||
$filter_name = $attrs->name;
|
$filter_name = $attrs->name;
|
||||||
$confirm_msg_code = $attrs->confirm_msg_code;
|
$confirm_msg_code = $attrs->confirm_msg_code;
|
||||||
$module = $attrs->module;
|
$module = $attrs->module;
|
||||||
$act = $attrs->act;
|
$act = $attrs->act;
|
||||||
$extend_filter = $attrs->extend_filter;
|
$extend_filter = $attrs->extend_filter;
|
||||||
|
|
||||||
|
|
||||||
$field_node = $xml_obj->filter->form->node;
|
$field_node = $xml_obj->filter->form->node;
|
||||||
if($field_node && !is_array($field_node)) $field_node = array($field_node);
|
if($field_node && !is_array($field_node)) $field_node = array($field_node);
|
||||||
|
|
||||||
$parameter_param = $xml_obj->filter->parameter->param;
|
$parameter_param = $xml_obj->filter->parameter->param;
|
||||||
if($parameter_param && !is_array($parameter_param)) $parameter_param = array($parameter_param);
|
if($parameter_param && !is_array($parameter_param)) $parameter_param = array($parameter_param);
|
||||||
|
|
||||||
$response_tag = $xml_obj->filter->response->tag;
|
$response_tag = $xml_obj->filter->response->tag;
|
||||||
if($response_tag && !is_array($response_tag)) $response_tag = array($response_tag);
|
if($response_tag && !is_array($response_tag)) $response_tag = array($response_tag);
|
||||||
|
|
||||||
// If extend_filter exists, result returned by calling the method
|
// If extend_filter exists, result returned by calling the method
|
||||||
if($extend_filter) {
|
if($extend_filter)
|
||||||
|
{
|
||||||
|
// If extend_filter exists, it changes the name of cache not to use cache
|
||||||
|
$this->js_file .= '.nocache.js';
|
||||||
|
|
||||||
// If extend_filter exists, it changes the name of cache not to use cache
|
// Separate the extend_filter
|
||||||
$this->js_file .= '.nocache.js';
|
list($module_name, $method) = explode('.',$extend_filter);
|
||||||
|
|
||||||
// Separate the extend_filter
|
// contibue if both module_name and methos exist.
|
||||||
list($module_name, $method) = explode('.',$extend_filter);
|
if($module_name&&$method)
|
||||||
|
{
|
||||||
|
// get model object of the module
|
||||||
|
$oExtendFilter = &getModel($module_name);
|
||||||
|
|
||||||
// contibue if both module_name and methos exist.
|
// execute if method exists
|
||||||
if($module_name&&$method) {
|
if(method_exists($oExtendFilter, $method))
|
||||||
// get model object of the module
|
{
|
||||||
$oExtendFilter = &getModel($module_name);
|
// get the result
|
||||||
|
$extend_filter_list = $oExtendFilter->{$method}(true);
|
||||||
|
$extend_filter_count = count($extend_filter_list);
|
||||||
|
|
||||||
// execute if method exists
|
// apply lang_value from the result to the variable
|
||||||
if(method_exists($oExtendFilter, $method)) {
|
for($i=0; $i < $extend_filter_count; $i++)
|
||||||
// get the result
|
{
|
||||||
$extend_filter_list = $oExtendFilter->{$method}(true);
|
$name = $extend_filter_list[$i]->name;
|
||||||
$extend_filter_count = count($extend_filter_list);
|
$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();
|
|
||||||
|
|
||||||
// javascript contents
|
|
||||||
$js_rules = array();
|
|
||||||
$js_messages = 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}]);";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// generates a field, which is a script of the checked item
|
// search the field to be used for entering language
|
||||||
$node_count = count($field_node);
|
$target_list = array();
|
||||||
if($node_count) {
|
$target_type_list = array();
|
||||||
foreach($field_node as $key =>$node) {
|
|
||||||
$attrs = $node->attrs;
|
|
||||||
$target = trim($attrs->target);
|
|
||||||
|
|
||||||
if(!$target) continue;
|
// javascript contents
|
||||||
|
$js_rules = array();
|
||||||
|
$js_messages = array();
|
||||||
|
|
||||||
$rule = trim($attrs->rule?$attrs->rule:$attrs->filter);
|
$fields = array();
|
||||||
$equalto = trim($attrs->equalto);
|
|
||||||
|
|
||||||
$field = array();
|
// create custom rule
|
||||||
|
if($rules && $rules->rule)
|
||||||
if($attrs->required == 'true') $field[] = 'required:true';
|
{
|
||||||
if($attrs->minlength > 0) $field[] = 'minlength:'.$attrs->minlength;
|
if(!is_array($rules->rule)) $rules->rule = array($rules->rule);
|
||||||
if($attrs->maxlength > 0) $field[] = 'maxlength:'.$attrs->maxlength;
|
foreach($rules->rule as $r)
|
||||||
if($equalto) $field[] = "equalto:'{$attrs->equalto}'";
|
{
|
||||||
if($rule) $field[] = "rule:'{$rule}'";
|
if($r->attrs->type == 'regex')
|
||||||
|
{
|
||||||
$fields[] = "'{$target}': {".implode(',', $field)."}";
|
$js_rules[] = "v.cast('ADD_RULE', ['{$r->attrs->name}', {$r->body}]);";
|
||||||
|
|
||||||
if(!in_array($target, $target_list)) $target_list[] = $target;
|
|
||||||
if(!$target_type_list[$target]) $target_type_list[$target] = $filter;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check extend_filter_item
|
// generates a field, which is a script of the checked item
|
||||||
$rule_types = array('homepage'=>'homepage', 'email_address'=>'email');
|
$node_count = count($field_node);
|
||||||
|
if($node_count)
|
||||||
for($i=0;$i<$extend_filter_count;$i++) {
|
{
|
||||||
$filter_item = $extend_filter_list[$i];
|
foreach($field_node as $key =>$node)
|
||||||
$target = trim($filter_item->name);
|
{
|
||||||
|
$attrs = $node->attrs;
|
||||||
|
$target = trim($attrs->target);
|
||||||
|
|
||||||
if(!$target) continue;
|
if(!$target) continue;
|
||||||
|
|
||||||
// get the filter from the type of extend filter item
|
$rule = trim($attrs->rule?$attrs->rule:$attrs->filter);
|
||||||
$type = $filter_item->type;
|
$equalto = trim($attrs->equalto);
|
||||||
$rule = $rule_types[$type]?$rule_types[$type]:'';
|
|
||||||
$required = ($filter_item->required == 'true');
|
|
||||||
|
|
||||||
$field = array();
|
$field = array();
|
||||||
if($required) $field[] = 'required:true';
|
|
||||||
if($rule) $field[] = "rule:'{$rule}'";
|
if($attrs->required == 'true') $field[] = 'required:true';
|
||||||
$fields[] = "\t\t'{$target}' : {".implode(',', $field)."}";
|
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)."}";
|
||||||
|
|
||||||
if(!in_array($target, $target_list)) $target_list[] = $target;
|
if(!in_array($target, $target_list)) $target_list[] = $target;
|
||||||
if(!$target_type_list[$target]) $target_type_list[$target] = $type;
|
if(!$target_type_list[$target]) $target_type_list[$target] = $filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Check extend_filter_item
|
||||||
* return a file name of js file corresponding to the xml file
|
$rule_types = array('homepage'=>'homepage', 'email_address'=>'email');
|
||||||
* @param string $xml_file
|
|
||||||
* @return string
|
for($i=0;$i<$extend_filter_count;$i++)
|
||||||
**/
|
{
|
||||||
function _getCompiledFileName($xml_file) {
|
$filter_item = $extend_filter_list[$i];
|
||||||
return sprintf('%s%s.%s.compiled.js',$this->compiled_path, md5($this->version.$xml_file),Context::getLangType());
|
$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
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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,223 @@
|
||||||
<?php
|
<?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
|
* compiled language cache path
|
||||||
* Change to lang php file from xml.
|
* @var string
|
||||||
* @author NHN (developers@xpressengine.com)
|
*/
|
||||||
* @package /classes/xml
|
var $compiled_path = './files/cache/lang/'; // / directory path for compiled cache file
|
||||||
* @version 0.1
|
/**
|
||||||
**/
|
* Target xml file
|
||||||
class XmlLangParser extends XmlParser {
|
* @var string
|
||||||
/**
|
*/
|
||||||
* compiled language cache path
|
var $xml_file = NULL;
|
||||||
* @var string
|
/**
|
||||||
*/
|
* Target php file
|
||||||
var $compiled_path = './files/cache/lang/'; // / directory path for compiled cache file
|
* @var string
|
||||||
/**
|
*/
|
||||||
* Target xml file
|
var $php_file = NULL;
|
||||||
* @var string
|
/**
|
||||||
*/
|
* result source code
|
||||||
var $xml_file = NULL;
|
* @var string
|
||||||
/**
|
*/
|
||||||
* Target php file
|
var $code;
|
||||||
* @var string
|
/**
|
||||||
*/
|
* language list, for example ko, en...
|
||||||
var $php_file = NULL;
|
* @var array
|
||||||
/**
|
*/
|
||||||
* result source code
|
var $lang_types;
|
||||||
* @var string
|
/**
|
||||||
*/
|
* language type
|
||||||
var $code;
|
* @see _XE_PATH_.'/common/lang/lang.info'
|
||||||
/**
|
* @var string
|
||||||
* language list, for example ko, en...
|
*/
|
||||||
* @var array
|
var $lang_type;
|
||||||
*/
|
|
||||||
var $lang_types;
|
|
||||||
/**
|
|
||||||
* language type
|
|
||||||
* @see _XE_PATH_.'/common/lang/lang.info'
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
var $lang_type;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
* @param string $xml_file
|
* @param string $xml_file
|
||||||
* @param string $lang_type
|
* @param string $lang_type
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function XmlLangParser($xml_file, $lang_type) {
|
function XmlLangParser($xml_file, $lang_type)
|
||||||
$this->lang_type = $lang_type;
|
{
|
||||||
$this->xml_file = $xml_file;
|
$this->lang_type = $lang_type;
|
||||||
$this->php_file = $this->_getCompiledFileName($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
|
* compile a xml_file only when a corresponding php lang file does not exists or is outdated
|
||||||
* @return string|bool Returns compiled php file.
|
* @return string|bool Returns compiled php file.
|
||||||
*/
|
*/
|
||||||
function compile() {
|
function compile()
|
||||||
if(!file_exists($this->xml_file)) return false;
|
{
|
||||||
if(!file_exists($this->php_file)){
|
if(!file_exists($this->xml_file)) return false;
|
||||||
$this->_compile();
|
if(!file_exists($this->php_file))
|
||||||
} 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;
|
|
||||||
$this->_compile();
|
$this->_compile();
|
||||||
|
}
|
||||||
return $this->code;
|
else
|
||||||
|
{
|
||||||
|
if(filemtime($this->xml_file)>filemtime($this->php_file)) $this->_compile();
|
||||||
|
else return $this->php_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
return $this->_writeFile() ? $this->php_file : false;
|
||||||
* 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);
|
* Return compiled content
|
||||||
$buff = str_replace('xml:lang','xml_lang',$buff);
|
* @return string Returns compiled lang source code
|
||||||
|
*/
|
||||||
|
function getCompileContent()
|
||||||
|
{
|
||||||
|
if(!file_exists($this->xml_file)) return false;
|
||||||
|
$this->_compile();
|
||||||
|
|
||||||
// xml parsing
|
return $this->code;
|
||||||
$xml_obj = parent::parse($buff);
|
}
|
||||||
|
|
||||||
$item = $xml_obj->lang->item;
|
/**
|
||||||
if(!is_array($item)) $item = array($item);
|
* Compile a xml_file
|
||||||
foreach($item as $i){
|
* @return void
|
||||||
$this->_parseItem($i, $var='$lang->%s');
|
*/
|
||||||
}
|
function _compile()
|
||||||
}
|
{
|
||||||
|
$lang_selected = Context::loadLangSelected();
|
||||||
|
$this->lang_types = array_keys($lang_selected);
|
||||||
|
|
||||||
/**
|
// read xml file
|
||||||
* Writing cache file
|
$buff = FileHandler::readFile($this->xml_file);
|
||||||
* @return void|bool
|
$buff = str_replace('xml:lang','xml_lang',$buff);
|
||||||
*/
|
|
||||||
function _writeFile(){
|
|
||||||
if(!$this->code) return;
|
|
||||||
FileHandler::writeFile($this->php_file, "<?php\n".$this->code);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// xml parsing
|
||||||
* Parsing item node, set content to '$this->code'
|
$xml_obj = parent::parse($buff);
|
||||||
* @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) {
|
$item = $xml_obj->lang->item;
|
||||||
$type = $item->attrs->type;
|
if(!is_array($item)) $item = array($item);
|
||||||
|
foreach($item as $i)
|
||||||
if($type == 'array'){
|
{
|
||||||
$this->code .= $var."=array();\n";
|
$this->_parseItem($i, $var='$lang->%s');
|
||||||
$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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* End of file XmlLangParser.class.php */
|
||||||
|
/* Location: ./classes/xml/XmlLangParser.class.php */
|
||||||
|
|
|
||||||
|
|
@ -1,195 +1,217 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Xml_Node_ class
|
* Xml_Node_ class
|
||||||
* Element node or attribute node.
|
* Element node or attribute node.
|
||||||
* @author NHN (developers@xpressengine.com)
|
* @author NHN (developers@xpressengine.com)
|
||||||
* @package /classes/xml
|
* @package /classes/xml
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
*/
|
*/
|
||||||
class Xml_Node_
|
class Xml_Node_
|
||||||
{
|
{
|
||||||
/** In PHP5 this will silence E_STRICT warnings
|
/** In PHP5 this will silence E_STRICT warnings
|
||||||
* for undeclared properties.
|
* for undeclared properties.
|
||||||
* No effect in PHP4
|
* No effect in PHP4
|
||||||
*/
|
*/
|
||||||
function __get($name)
|
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
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 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";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XmlParser class
|
* Load a xml file specified by a filename and parse it to Return the resultant data object
|
||||||
* Class parsing a given xmlrpc request and creating a data object
|
* @param string $filename a file path of file
|
||||||
* @remarks <pre>{
|
* @return array Returns a data object containing data extracted from a xml file or NULL if a specified file does not exist
|
||||||
* 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 {
|
function loadXmlFile($filename)
|
||||||
/**
|
{
|
||||||
* Xml parser
|
if(!file_exists($filename)) return;
|
||||||
* @var resource
|
$buff = FileHandler::readFile($filename);
|
||||||
*/
|
|
||||||
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";
|
|
||||||
|
|
||||||
/**
|
$oXmlParser = new XmlParser();
|
||||||
* Load a xml file specified by a filename and parse it to Return the resultant data object
|
return $oXmlParser->parse($buff);
|
||||||
* @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);
|
|
||||||
|
|
||||||
$oXmlParser = new XmlParser();
|
/**
|
||||||
return $oXmlParser->parse($buff);
|
* 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();
|
||||||
|
|
||||||
/**
|
$this->lang = Context::getLangType();
|
||||||
* 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();
|
|
||||||
|
|
||||||
$this->lang = Context::getLangType();
|
$this->input = $input?$input:$GLOBALS['HTTP_RAW_POST_DATA'];
|
||||||
|
$this->input = str_replace(array('',''),array('',''),$this->input);
|
||||||
|
|
||||||
$this->input = $input?$input:$GLOBALS['HTTP_RAW_POST_DATA'];
|
// extracts a supported language
|
||||||
$this->input = str_replace(array('',''),array('',''),$this->input);
|
preg_match_all("/xml:lang=\"([^\"].+)\"/i", $this->input, $matches);
|
||||||
|
|
||||||
// extracts a supported language
|
// extracts the supported lanuage when xml:lang is used
|
||||||
preg_match_all("/xml:lang=\"([^\"].+)\"/i", $this->input, $matches);
|
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 = '';
|
||||||
|
}
|
||||||
|
|
||||||
// extracts the supported lanuage when xml:lang is used
|
$this->oParser = xml_parser_create('UTF-8');
|
||||||
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->oParser = xml_parser_create('UTF-8');
|
xml_set_object($this->oParser, $this);
|
||||||
|
xml_set_element_handler($this->oParser, "_tagOpen", "_tagClosed");
|
||||||
|
xml_set_character_data_handler($this->oParser, "_tagBody");
|
||||||
|
|
||||||
xml_set_object($this->oParser, $this);
|
xml_parse($this->oParser, $this->input);
|
||||||
xml_set_element_handler($this->oParser, "_tagOpen", "_tagClosed");
|
xml_parser_free($this->oParser);
|
||||||
xml_set_character_data_handler($this->oParser, "_tagBody");
|
|
||||||
|
|
||||||
xml_parse($this->oParser, $this->input);
|
if(!count($this->output)) return;
|
||||||
xml_parser_free($this->oParser);
|
|
||||||
|
|
||||||
if(!count($this->output)) return;
|
$output = array_shift($this->output);
|
||||||
|
// Save compile starting time for debugging
|
||||||
|
if(__DEBUG__==3) $GLOBALS['__xmlparse_elapsed__'] += getMicroTime() - $start;
|
||||||
|
|
||||||
$output = array_shift($this->output);
|
return $output;
|
||||||
// Save compile starting time for debugging
|
}
|
||||||
if(__DEBUG__==3) $GLOBALS['__xmlparse_elapsed__'] += getMicroTime() - $start;
|
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start element handler.
|
* Start element handler.
|
||||||
* @param resource $parse an instance of parser
|
* @param resource $parse an instance of parser
|
||||||
* @param string $node_name a name of node
|
* @param string $node_name a name of node
|
||||||
* @param array $attrs attributes to be set
|
* @param array $attrs attributes to be set
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function _tagOpen($parser, $node_name, $attrs) {
|
function _tagOpen($parser, $node_name, $attrs)
|
||||||
$obj = new Xml_Node_();
|
{
|
||||||
$obj->node_name = strtolower($node_name);
|
$obj = new Xml_Node_();
|
||||||
$obj->attrs = $this->_arrToAttrsObj($attrs);
|
$obj->node_name = strtolower($node_name);
|
||||||
|
$obj->attrs = $this->_arrToAttrsObj($attrs);
|
||||||
|
|
||||||
array_push($this->output, $obj);
|
array_push($this->output, $obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Character data handler
|
* Character data handler
|
||||||
* Variable in the last element of this->output
|
* Variable in the last element of this->output
|
||||||
* @param resource $parse an instance of parser
|
* @param resource $parse an instance of parser
|
||||||
* @param string $body a data to be added
|
* @param string $body a data to be added
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function _tagBody($parser, $body) {
|
function _tagBody($parser, $body)
|
||||||
//if(!trim($body)) return;
|
{
|
||||||
$this->output[count($this->output)-1]->body .= $body;
|
//if(!trim($body)) return;
|
||||||
}
|
$this->output[count($this->output)-1]->body .= $body;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* End element handler
|
* End element handler
|
||||||
* @param resource $parse an instance of parser
|
* @param resource $parse an instance of parser
|
||||||
* @param string $node_name name of xml node
|
* @param string $node_name name of xml node
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function _tagClosed($parser, $node_name) {
|
function _tagClosed($parser, $node_name)
|
||||||
$node_name = strtolower($node_name);
|
{
|
||||||
$cur_obj = array_pop($this->output);
|
$node_name = strtolower($node_name);
|
||||||
$parent_obj = &$this->output[count($this->output)-1];
|
$cur_obj = array_pop($this->output);
|
||||||
if($this->lang&&$cur_obj->attrs->{'xml:lang'}&&$cur_obj->attrs->{'xml:lang'}!=$this->lang) return;
|
$parent_obj = &$this->output[count($this->output)-1];
|
||||||
if($this->lang&&$parent_obj->{$node_name}->attrs->{'xml:lang'}&&$parent_obj->{$node_name}->attrs->{'xml:lang'}!=$this->lang) return;
|
if($this->lang&&$cur_obj->attrs->{'xml:lang'}&&$cur_obj->attrs->{'xml:lang'}!=$this->lang) return;
|
||||||
|
if($this->lang&&$parent_obj->{$node_name}->attrs->{'xml:lang'}&&$parent_obj->{$node_name}->attrs->{'xml:lang'}!=$this->lang) return;
|
||||||
|
|
||||||
if(isset($parent_obj->{$node_name})) {
|
if(isset($parent_obj->{$node_name}))
|
||||||
$tmp_obj = $parent_obj->{$node_name};
|
{
|
||||||
if(is_array($tmp_obj)) {
|
$tmp_obj = $parent_obj->{$node_name};
|
||||||
array_push($parent_obj->{$node_name}, $cur_obj);
|
if(is_array($tmp_obj))
|
||||||
} else {
|
{
|
||||||
$parent_obj->{$node_name} = array();
|
array_push($parent_obj->{$node_name}, $cur_obj);
|
||||||
array_push($parent_obj->{$node_name}, $tmp_obj);
|
}
|
||||||
array_push($parent_obj->{$node_name}, $cur_obj);
|
else
|
||||||
}
|
{
|
||||||
} else {
|
$parent_obj->{$node_name} = array();
|
||||||
if (!is_object($parent_obj))
|
array_push($parent_obj->{$node_name}, $tmp_obj);
|
||||||
$parent_obj = (object)$parent_obj;
|
array_push($parent_obj->{$node_name}, $cur_obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(!is_object($parent_obj))
|
||||||
|
$parent_obj = (object)$parent_obj;
|
||||||
|
|
||||||
$parent_obj->{$node_name} = $cur_obj;
|
$parent_obj->{$node_name} = $cur_obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to transfer values in an array to a data object
|
* Method to transfer values in an array to a data object
|
||||||
* @param array $arr data array
|
* @param array $arr data array
|
||||||
* @return Xml_Node_ object
|
* @return Xml_Node_ object
|
||||||
**/
|
*/
|
||||||
function _arrToAttrsObj($arr) {
|
function _arrToAttrsObj($arr)
|
||||||
$output = new Xml_Node_();
|
{
|
||||||
foreach($arr as $key => $val) {
|
$output = new Xml_Node_();
|
||||||
$key = strtolower($key);
|
foreach($arr as $key => $val)
|
||||||
$output->{$key} = $val;
|
{
|
||||||
}
|
$key = strtolower($key);
|
||||||
return $output;
|
$output->{$key} = $val;
|
||||||
}
|
}
|
||||||
}
|
return $output;
|
||||||
?>
|
}
|
||||||
|
}
|
||||||
|
/* End of file XmlParser.class.php */
|
||||||
|
/* Location: ./classes/xml/XmlParser.class.php */
|
||||||
|
|
|
||||||
|
|
@ -1,109 +1,110 @@
|
||||||
<?php
|
<?php
|
||||||
if(!defined('__XE_LOADED_XML_CLASS__')){
|
if(!defined('__XE_LOADED_XML_CLASS__'))
|
||||||
define('__XE_LOADED_XML_CLASS__', 1);
|
{
|
||||||
|
define('__XE_LOADED_XML_CLASS__', 1);
|
||||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/query/QueryTag.class.php');
|
|
||||||
|
|
||||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/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/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/ColumnTag.class.php');
|
||||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/SelectColumnTag.class.php');
|
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/SelectColumnTag.class.php');
|
||||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnTag.class.php');
|
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnTag.class.php');
|
||||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php');
|
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php');
|
||||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php');
|
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php');
|
||||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php');
|
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php');
|
||||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php');
|
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php');
|
||||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php');
|
require(_XE_PATH_.'classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php');
|
||||||
|
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionTag.class.php');
|
||||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionTag.class.php');
|
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionsTag.class.php');
|
||||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionsTag.class.php');
|
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php');
|
||||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php');
|
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php');
|
||||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php');
|
require(_XE_PATH_.'classes/xml/xmlquery/tags/group/GroupsTag.class.php');
|
||||||
|
require(_XE_PATH_.'classes/xml/xmlquery/tags/navigation/NavigationTag.class.php');
|
||||||
require(_XE_PATH_.'classes/xml/xmlquery/tags/group/GroupsTag.class.php');
|
require(_XE_PATH_.'classes/xml/xmlquery/tags/navigation/IndexTag.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/tags/navigation/LimitTag.class.php');
|
||||||
|
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/QueryArgument.class.php');
|
||||||
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/QueryArgument.class.php');
|
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/SortQueryArgument.class.php');
|
||||||
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/SortQueryArgument.class.php');
|
|
||||||
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php');
|
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php');
|
||||||
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/DefaultValue.class.php');
|
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/DefaultValue.class.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New XmlQueryParser class
|
||||||
|
* @author NHN (developers@xpressengine.com)
|
||||||
|
* @brief case to parse XE xml query
|
||||||
|
* @version 0.1
|
||||||
|
*
|
||||||
|
* @todo need to support extend query such as subquery, union
|
||||||
|
* @todo include info about column types for parsing user input
|
||||||
|
*/
|
||||||
|
class XmlQueryParser extends XmlParser
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* New XmlQueryParser class
|
* constructor
|
||||||
* @author NHN (developers@xpressengine.com)
|
* @return void
|
||||||
* @brief case to parse XE xml query
|
|
||||||
* @version 0.1
|
|
||||||
*
|
|
||||||
* @todo need to support extend query such as subquery, union
|
|
||||||
* @todo include info about column types for parsing user input
|
|
||||||
*/
|
*/
|
||||||
class XmlQueryParser extends XmlParser {
|
function XmlQueryParser()
|
||||||
/**
|
|
||||||
* constructor
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function XmlQueryParser(){
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create XmlQueryParser instance for Singleton
|
|
||||||
* @return XmlQueryParser object
|
|
||||||
*/
|
|
||||||
function &getInstance(){
|
|
||||||
static $theInstance = null;
|
|
||||||
if(!isset($theInstance)){
|
|
||||||
$theInstance = new XmlQueryParser();
|
|
||||||
}
|
|
||||||
return $theInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 1. Read xml file<br />
|
|
||||||
* 2. Check the action<br />
|
|
||||||
* 3. Parsing and write a cache file<br />
|
|
||||||
* @return QueryParser object
|
|
||||||
*/
|
|
||||||
function &parse_xml_query($query_id, $xml_file, $cache_file)
|
|
||||||
{
|
{
|
||||||
// Read xml file
|
|
||||||
$xml_obj = $this->getXmlFileContent($xml_file);
|
|
||||||
|
|
||||||
// insert, update, delete, select action
|
|
||||||
$action = strtolower($xml_obj->query->attrs->action);
|
|
||||||
if(!$action) return;
|
|
||||||
|
|
||||||
// Write query cache file
|
|
||||||
$parser = new QueryParser($xml_obj->query);
|
|
||||||
FileHandler::writeFile($cache_file, $parser->toString());
|
|
||||||
|
|
||||||
return $parser;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Query XML file parsing
|
|
||||||
* @return QueryParser object
|
|
||||||
*/
|
|
||||||
function parse($query_id = NULL, $xml_file = NULL, $cache_file = NULL)
|
|
||||||
{
|
|
||||||
$this->parse_xml_query($query_id, $xml_file, $cache_file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return XML file content
|
* Create XmlQueryParser instance for Singleton
|
||||||
* @return array|NULL Returns a resultant data object or NULL in case of error
|
* @return XmlQueryParser object
|
||||||
*/
|
*/
|
||||||
function getXmlFileContent($xml_file){
|
function &getInstance()
|
||||||
$buff = FileHandler::readFile($xml_file);
|
{
|
||||||
$xml_obj = parent::parse($buff);
|
static $theInstance = null;
|
||||||
if(!$xml_obj) return;
|
if(!isset($theInstance))
|
||||||
unset($buff);
|
{
|
||||||
return $xml_obj;
|
$theInstance = new XmlQueryParser();
|
||||||
}
|
}
|
||||||
}
|
return $theInstance;
|
||||||
?>
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1. Read xml file<br />
|
||||||
|
* 2. Check the action<br />
|
||||||
|
* 3. Parsing and write a cache file<br />
|
||||||
|
* @return QueryParser object
|
||||||
|
*/
|
||||||
|
function &parse_xml_query($query_id, $xml_file, $cache_file)
|
||||||
|
{
|
||||||
|
// Read xml file
|
||||||
|
$xml_obj = $this->getXmlFileContent($xml_file);
|
||||||
|
|
||||||
|
// insert, update, delete, select action
|
||||||
|
$action = strtolower($xml_obj->query->attrs->action);
|
||||||
|
if(!$action) return;
|
||||||
|
|
||||||
|
// Write query cache file
|
||||||
|
$parser = new QueryParser($xml_obj->query);
|
||||||
|
FileHandler::writeFile($cache_file, $parser->toString());
|
||||||
|
|
||||||
|
return $parser;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query XML file parsing
|
||||||
|
* @return QueryParser object
|
||||||
|
*/
|
||||||
|
function parse($query_id = NULL, $xml_file = NULL, $cache_file = NULL)
|
||||||
|
{
|
||||||
|
$this->parse_xml_query($query_id, $xml_file, $cache_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return XML file content
|
||||||
|
* @return array|NULL Returns a resultant data object or NULL in case of error
|
||||||
|
*/
|
||||||
|
function getXmlFileContent($xml_file)
|
||||||
|
{
|
||||||
|
$buff = FileHandler::readFile($xml_file);
|
||||||
|
$xml_obj = parent::parse($buff);
|
||||||
|
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,193 +1,214 @@
|
||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* DBParser class
|
||||||
|
* @author NHN (developers@xpressengine.com)
|
||||||
|
* @package /classes/xml/xmlquery
|
||||||
|
* @version 0.1
|
||||||
|
*/
|
||||||
|
class DBParser
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* DBParser class
|
* Character for escape target value on the left
|
||||||
* @author NHN (developers@xpressengine.com)
|
* @var string
|
||||||
* @package /classes/xml/xmlquery
|
|
||||||
* @version 0.1
|
|
||||||
*/
|
*/
|
||||||
class DBParser {
|
var $escape_char_left;
|
||||||
/**
|
/**
|
||||||
* Character for escape target value on the left
|
* Character for escape target value on the right
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
var $escape_char_left;
|
var $escape_char_right;
|
||||||
/**
|
/**
|
||||||
* Character for escape target value on the right
|
* Table prefix string
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
var $escape_char_right;
|
var $table_prefix;
|
||||||
/**
|
|
||||||
* Table prefix string
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
var $table_prefix;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* constructor
|
|
||||||
* @param string $escape_char_left
|
|
||||||
* @param string $escape_char_right
|
|
||||||
* @param string $table_prefix
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function DBParser($escape_char_left, $escape_char_right = "", $table_prefix = "xe_"){
|
|
||||||
$this->escape_char_left = $escape_char_left;
|
|
||||||
if ($escape_char_right !== "")$this->escape_char_right = $escape_char_right;
|
|
||||||
else $this->escape_char_right = $escape_char_left;
|
|
||||||
$this->table_prefix = $table_prefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get escape character
|
|
||||||
* @param string $leftOrRight left or right
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function getEscapeChar($leftOrRight){
|
|
||||||
if ($leftOrRight === 'left')return $this->escape_char_left;
|
|
||||||
else return $this->escape_char_right;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* escape the value
|
|
||||||
* @param mixed $name
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function escape($name){
|
|
||||||
return $this->escape_char_left . $name . $this->escape_char_right;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* escape the string value
|
|
||||||
* @param string $name
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function escapeString($name){
|
|
||||||
return "'".$this->escapeStringValue($name)."'";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* escape the string value
|
|
||||||
* @param string $value
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function escapeStringValue($value){
|
|
||||||
if($value == "*") return $value;
|
|
||||||
if (is_string($value)) return $value = str_replace("'","''",$value);
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return table full name
|
|
||||||
* @param string $name table name without table prefix
|
|
||||||
* @return string table full name with table prefix
|
|
||||||
*/
|
|
||||||
function parseTableName($name){
|
|
||||||
return $this->table_prefix . $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return colmun name after escape
|
|
||||||
* @param string $name column name before escape
|
|
||||||
* @return string column name after escape
|
|
||||||
*/
|
|
||||||
function parseColumnName($name){
|
|
||||||
return $this->escapeColumn($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Escape column
|
|
||||||
* @param string $column_name
|
|
||||||
* @return string column name with db name
|
|
||||||
*/
|
|
||||||
function escapeColumn($column_name){
|
|
||||||
if($this->isUnqualifiedColumnName($column_name))
|
|
||||||
return $this->escape($column_name);
|
|
||||||
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($this->parseTableName($table)).'.'.$this->escape($column);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Column name is suitable for use in checking
|
* constructor
|
||||||
* @param string $column_name
|
* @param string $escape_char_left
|
||||||
* @return bool
|
* @param string $escape_char_right
|
||||||
*/
|
* @param string $table_prefix
|
||||||
function isUnqualifiedColumnName($column_name){
|
* @return void
|
||||||
if(strpos($column_name,'.')===false && strpos($column_name,'(')===false) return true;
|
*/
|
||||||
return false;
|
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;
|
||||||
* Column name is suitable for use in checking
|
else $this->escape_char_right = $escape_char_left;
|
||||||
* @param string $column_name
|
$this->table_prefix = $table_prefix;
|
||||||
* @return bool
|
}
|
||||||
*/
|
|
||||||
function isQualifiedColumnName($column_name){
|
|
||||||
if(strpos($column_name,'.')!==false && strpos($column_name,'(')===false) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseExpression($column_name){
|
/**
|
||||||
$functions = preg_split('/([\+\-\*\/\ ])/', $column_name, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
* Get escape character
|
||||||
foreach($functions as $k => $v){
|
* @param string $leftOrRight left or right
|
||||||
$function = &$functions[$k];
|
* @return string
|
||||||
if(strlen($function)==1) continue; // skip delimiters
|
*/
|
||||||
$pos = strrpos("(", $function);
|
function getEscapeChar($leftOrRight)
|
||||||
$matches = preg_split('/([a-zA-Z0-9_*]+)/', $function, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
{
|
||||||
$total_brackets = substr_count($function, "(");
|
if ($leftOrRight === 'left')return $this->escape_char_left;
|
||||||
$brackets = 0;
|
else return $this->escape_char_right;
|
||||||
foreach($matches as $i => $j){
|
}
|
||||||
$match = &$matches[$i];
|
|
||||||
if($match == '(') {$brackets++; continue;}
|
/**
|
||||||
if(strpos($match,')') !== false) continue;
|
* escape the value
|
||||||
if(in_array($match, array(',', '.'))) continue;
|
* @param mixed $name
|
||||||
if($brackets == $total_brackets){
|
* @return string
|
||||||
if(!is_numeric($match)) {
|
*/
|
||||||
$match = $this->escapeColumnExpression($match);
|
function escape($name)
|
||||||
}
|
{
|
||||||
|
return $this->escape_char_left . $name . $this->escape_char_right;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* escape the string value
|
||||||
|
* @param string $name
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function escapeString($name)
|
||||||
|
{
|
||||||
|
return "'".$this->escapeStringValue($name)."'";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* escape the string value
|
||||||
|
* @param string $value
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function escapeStringValue($value)
|
||||||
|
{
|
||||||
|
if($value == "*") return $value;
|
||||||
|
if (is_string($value)) return $value = str_replace("'","''",$value);
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return table full name
|
||||||
|
* @param string $name table name without table prefix
|
||||||
|
* @return string table full name with table prefix
|
||||||
|
*/
|
||||||
|
function parseTableName($name)
|
||||||
|
{
|
||||||
|
return $this->table_prefix . $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return colmun name after escape
|
||||||
|
* @param string $name column name before escape
|
||||||
|
* @return string column name after escape
|
||||||
|
*/
|
||||||
|
function parseColumnName($name)
|
||||||
|
{
|
||||||
|
return $this->escapeColumn($name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escape column
|
||||||
|
* @param string $column_name
|
||||||
|
* @return string column name with db name
|
||||||
|
*/
|
||||||
|
function escapeColumn($column_name)
|
||||||
|
{
|
||||||
|
if($this->isUnqualifiedColumnName($column_name))
|
||||||
|
return $this->escape($column_name);
|
||||||
|
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($this->parseTableName($table)).'.'.$this->escape($column);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Column name is suitable for use in checking
|
||||||
|
* @param string $column_name
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function isUnqualifiedColumnName($column_name)
|
||||||
|
{
|
||||||
|
if(strpos($column_name,'.')===false && strpos($column_name,'(')===false) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Column name is suitable for use in checking
|
||||||
|
* @param string $column_name
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function isQualifiedColumnName($column_name)
|
||||||
|
{
|
||||||
|
if(strpos($column_name,'.')!==false && strpos($column_name,'(')===false) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseExpression($column_name)
|
||||||
|
{
|
||||||
|
$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
|
||||||
|
$pos = strrpos("(", $function);
|
||||||
|
$matches = preg_split('/([a-zA-Z0-9_*]+)/', $function, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
||||||
|
$total_brackets = substr_count($function, "(");
|
||||||
|
$brackets = 0;
|
||||||
|
foreach($matches as $i => $j)
|
||||||
|
{
|
||||||
|
$match = &$matches[$i];
|
||||||
|
if($match == '(') {$brackets++; continue;}
|
||||||
|
if(strpos($match,')') !== false) continue;
|
||||||
|
if(in_array($match, array(',', '.'))) continue;
|
||||||
|
if($brackets == $total_brackets)
|
||||||
|
{
|
||||||
|
if(!is_numeric($match))
|
||||||
|
{
|
||||||
|
$match = $this->escapeColumnExpression($match);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$function = implode('', $matches);
|
|
||||||
}
|
|
||||||
return implode('', $functions);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Checks argument is asterisk
|
|
||||||
* @param string $column_name
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
function isStar($column_name){
|
|
||||||
if(substr($column_name,-1) == '*') return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Checks to see if expression is an aggregate star function
|
|
||||||
* like count(*)
|
|
||||||
* @param string $column_name
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
function isStarFunction($column_name){
|
|
||||||
if(strpos($column_name, "(*)")!==false) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Return column name after escape
|
|
||||||
* @param string $column_name
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function escapeColumnExpression($column_name){
|
|
||||||
if($this->isStar($column_name)) return $column_name;
|
|
||||||
if($this->isStarFunction($column_name)){
|
|
||||||
return $column_name;
|
|
||||||
}
|
}
|
||||||
if(strpos(strtolower($column_name), 'distinct') !== false) return $column_name;
|
$function = implode('', $matches);
|
||||||
return $this->escapeColumn($column_name);
|
}
|
||||||
}
|
return implode('', $functions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Checks argument is asterisk
|
||||||
|
* @param string $column_name
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function isStar($column_name)
|
||||||
|
{
|
||||||
|
if(substr($column_name,-1) == '*') return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Checks to see if expression is an aggregate star function
|
||||||
|
* like count(*)
|
||||||
|
* @param string $column_name
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function isStarFunction($column_name)
|
||||||
|
{
|
||||||
|
if(strpos($column_name, "(*)")!==false) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return column name after escape
|
||||||
|
* @param string $column_name
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function escapeColumnExpression($column_name)
|
||||||
|
{
|
||||||
|
if($this->isStar($column_name)) return $column_name;
|
||||||
|
if($this->isStarFunction($column_name))
|
||||||
|
{
|
||||||
|
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,92 +1,104 @@
|
||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* QueryParser class
|
||||||
|
* @author NHN (developers@xpressengine.com)
|
||||||
|
* @package /classes/xml/xmlquery
|
||||||
|
* @version 0.1
|
||||||
|
*/
|
||||||
|
class QueryParser
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* QueryParser class
|
* QueryTag object
|
||||||
* @author NHN (developers@xpressengine.com)
|
* @var QueryTag object
|
||||||
* @package /classes/xml/xmlquery
|
|
||||||
* @version 0.1
|
|
||||||
*/
|
*/
|
||||||
class QueryParser {
|
var $queryTag;
|
||||||
/**
|
|
||||||
* QueryTag object
|
|
||||||
* @var QueryTag object
|
|
||||||
*/
|
|
||||||
var $queryTag;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
* @param object $query
|
* @param object $query
|
||||||
* @param bool $isSubQuery
|
* @param bool $isSubQuery
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function QueryParser($query = NULL, $isSubQuery = false) {
|
function QueryParser($query = NULL, $isSubQuery = false)
|
||||||
if ($query)
|
{
|
||||||
$this->queryTag = new QueryTag($query, $isSubQuery);
|
if($query)
|
||||||
}
|
$this->queryTag = new QueryTag($query, $isSubQuery);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return table information
|
* Return table information
|
||||||
* @param object $query_id
|
* @param object $query_id
|
||||||
* @param bool $table_name
|
* @param bool $table_name
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function getTableInfo($query_id, $table_name) {
|
function getTableInfo($query_id, $table_name)
|
||||||
$column_type = array();
|
{
|
||||||
$module = '';
|
$column_type = array();
|
||||||
|
$module = '';
|
||||||
$id_args = explode('.', $query_id);
|
|
||||||
if (count($id_args) == 2) {
|
|
||||||
$target = 'modules';
|
|
||||||
$module = $id_args[0];
|
|
||||||
$id = $id_args[1];
|
|
||||||
} elseif (count($id_args) == 3) {
|
|
||||||
$target = $id_args[0];
|
|
||||||
$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
|
$id_args = explode('.', $query_id);
|
||||||
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $module, $table_name);
|
if(count($id_args) == 2)
|
||||||
if (!file_exists($table_file)) {
|
{
|
||||||
$searched_list = FileHandler::readDir(_XE_PATH_ . 'modules');
|
$target = 'modules';
|
||||||
$searched_count = count($searched_list);
|
$module = $id_args[0];
|
||||||
for ($i = 0; $i < $searched_count; $i++) {
|
$id = $id_args[1];
|
||||||
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $searched_list[$i], $table_name);
|
}
|
||||||
if (file_exists($table_file))
|
else if(count($id_args) == 3)
|
||||||
break;
|
{
|
||||||
}
|
$target = $id_args[0];
|
||||||
}
|
$targetList = array('modules'=>1, 'addons'=>1, 'widgets'=>1);
|
||||||
|
if (!isset($targetList[$target]))
|
||||||
|
return;
|
||||||
|
$module = $id_args[1];
|
||||||
|
$id = $id_args[2];
|
||||||
|
}
|
||||||
|
|
||||||
if (file_exists($table_file)) {
|
// get column properties from the table
|
||||||
$table_xml = FileHandler::readFile($table_file);
|
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $module, $table_name);
|
||||||
$xml_parser = new XmlParser();
|
if(!file_exists($table_file))
|
||||||
$table_obj = $xml_parser->parse($table_xml);
|
{
|
||||||
if ($table_obj->table) {
|
$searched_list = FileHandler::readDir(_XE_PATH_ . 'modules');
|
||||||
if (isset($table_obj->table->column) && !is_array($table_obj->table->column)) {
|
$searched_count = count($searched_list);
|
||||||
$table_obj->table->column = array($table_obj->table->column);
|
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))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($table_obj->table->column as $k => $v) {
|
if(file_exists($table_file))
|
||||||
$column_type[$v->attrs->name] = $v->attrs->type;
|
{
|
||||||
}
|
$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))
|
||||||
|
{
|
||||||
|
$table_obj->table->column = array($table_obj->table->column);
|
||||||
|
}
|
||||||
|
|
||||||
return $column_type;
|
foreach($table_obj->table->column as $k => $v)
|
||||||
}
|
{
|
||||||
|
$column_type[$v->attrs->name] = $v->attrs->type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
return $column_type;
|
||||||
* Change code string from queryTag object
|
}
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function toString() {
|
|
||||||
return "<?php if(!defined('__ZBXE__')) exit();\n"
|
|
||||||
. $this->queryTag->toString()
|
|
||||||
. 'return $query; ?>';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* Change code string from queryTag object
|
||||||
?>
|
* @return string
|
||||||
|
*/
|
||||||
|
function toString()
|
||||||
|
{
|
||||||
|
return "<?php if(!defined('__ZBXE__')) exit();\n"
|
||||||
|
. $this->queryTag->toString()
|
||||||
|
. 'return $query; ?>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* End of file QueryParser.class.php */
|
||||||
|
/* Location: ./classes/xml/xmlquery/QueryParser.class.php */
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@
|
||||||
* @package /classes/xml/xmlquery/argument
|
* @package /classes/xml/xmlquery/argument
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
*/
|
*/
|
||||||
class Argument {
|
class Argument
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* argument value
|
* argument value
|
||||||
* @var mixed
|
* @var mixed
|
||||||
|
|
@ -52,51 +53,62 @@ class Argument {
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function Argument($name, $value) {
|
function Argument($name, $value)
|
||||||
|
{
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->isValid = true;
|
$this->isValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getType() {
|
function getType()
|
||||||
if (isset($this->type))
|
{
|
||||||
|
if(isset($this->type))
|
||||||
{
|
{
|
||||||
return $this->type;
|
return $this->type;
|
||||||
}
|
}
|
||||||
if (is_string($this->value))
|
if(is_string($this->value))
|
||||||
return 'column_name';
|
return 'column_name';
|
||||||
|
|
||||||
return 'number';
|
return 'number';
|
||||||
}
|
}
|
||||||
|
|
||||||
function setColumnType($value) {
|
function setColumnType($value)
|
||||||
|
{
|
||||||
$this->type = $value;
|
$this->type = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setColumnOperation($operation) {
|
function setColumnOperation($operation)
|
||||||
|
{
|
||||||
$this->column_operation = $operation;
|
$this->column_operation = $operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getName() {
|
function getName()
|
||||||
|
{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getValue() {
|
function getValue()
|
||||||
if (!isset($this->_value)) {
|
{
|
||||||
|
if(!isset($this->_value))
|
||||||
|
{
|
||||||
$value = $this->getEscapedValue();
|
$value = $this->getEscapedValue();
|
||||||
$this->_value = $this->toString($value);
|
$this->_value = $this->toString($value);
|
||||||
}
|
}
|
||||||
return $this->_value;
|
return $this->_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getColumnOperation() {
|
function getColumnOperation()
|
||||||
|
{
|
||||||
return $this->column_operation;
|
return $this->column_operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEscapedValue() {
|
function getEscapedValue()
|
||||||
|
{
|
||||||
return $this->escapeValue($this->value);
|
return $this->escapeValue($this->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUnescapedValue() {
|
function getUnescapedValue()
|
||||||
|
{
|
||||||
return $this->value;
|
return $this->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,11 +117,13 @@ class Argument {
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function toString($value) {
|
function toString($value)
|
||||||
if (is_array($value)) {
|
{
|
||||||
if (count($value) === 0)
|
if(is_array($value))
|
||||||
|
{
|
||||||
|
if(count($value) === 0)
|
||||||
return '';
|
return '';
|
||||||
if (count($value) === 1 && $value[0] === '')
|
if(count($value) === 1 && $value[0] === '')
|
||||||
return '';
|
return '';
|
||||||
return '(' . implode(',', $value) . ')';
|
return '(' . implode(',', $value) . ')';
|
||||||
}
|
}
|
||||||
|
|
@ -121,35 +135,45 @@ class Argument {
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function escapeValue($value) {
|
function escapeValue($value)
|
||||||
|
{
|
||||||
$column_type = $this->getType();
|
$column_type = $this->getType();
|
||||||
if ($column_type == 'column_name') {
|
if($column_type == 'column_name')
|
||||||
|
{
|
||||||
$dbParser = DB::getParser();
|
$dbParser = DB::getParser();
|
||||||
return $dbParser->parseExpression($value);
|
return $dbParser->parseExpression($value);
|
||||||
}
|
}
|
||||||
if (!isset($value))
|
if(!isset($value))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
$columnTypeList = array('date'=>1, 'varchar'=>1, 'char'=>1, 'text'=>1, 'bigtext'=>1);
|
$columnTypeList = array('date'=>1, 'varchar'=>1, 'char'=>1, 'text'=>1, 'bigtext'=>1);
|
||||||
if (isset($columnTypeList[$column_type])) {
|
if(isset($columnTypeList[$column_type]))
|
||||||
if (!is_array($value))
|
{
|
||||||
|
if(!is_array($value))
|
||||||
$value = $this->_escapeStringValue($value);
|
$value = $this->_escapeStringValue($value);
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
$total = count($value);
|
$total = count($value);
|
||||||
for ($i = 0; $i < $total; $i++)
|
for($i = 0; $i < $total; $i++)
|
||||||
$value[$i] = $this->_escapeStringValue($value[$i]);
|
$value[$i] = $this->_escapeStringValue($value[$i]);
|
||||||
//$value[$i] = '\''.$value[$i].'\'';
|
//$value[$i] = '\''.$value[$i].'\'';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($this->uses_default_value) return $value;
|
if($this->uses_default_value) return $value;
|
||||||
if ($column_type == 'number') {
|
if($column_type == 'number')
|
||||||
if (is_array($value)) {
|
{
|
||||||
foreach ($value AS $key => $val) {
|
if(is_array($value))
|
||||||
if (isset($val) && $val !== '') {
|
{
|
||||||
|
foreach ($value AS $key => $val)
|
||||||
|
{
|
||||||
|
if(isset($val) && $val !== '')
|
||||||
|
{
|
||||||
$value[$key] = (int) $val;
|
$value[$key] = (int) $val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$value = (int) $value;
|
$value = (int) $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -162,7 +186,8 @@ class Argument {
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function _escapeStringValue($value) {
|
function _escapeStringValue($value)
|
||||||
|
{
|
||||||
// Remove non-utf8 chars.
|
// Remove non-utf8 chars.
|
||||||
$regex = '@((?:[\x00-\x7F]|[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}){1,100})|([\xF0-\xF7][\x80-\xBF]{3})|([\x80-\xBF])|([\xC0-\xFF])@x';
|
$regex = '@((?:[\x00-\x7F]|[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}){1,100})|([\xF0-\xF7][\x80-\xBF]{3})|([\x80-\xBF])|([\xC0-\xFF])@x';
|
||||||
|
|
||||||
|
|
@ -172,13 +197,14 @@ class Argument {
|
||||||
return '\'' . $value . '\'';
|
return '\'' . $value . '\'';
|
||||||
}
|
}
|
||||||
|
|
||||||
function utf8Replacer($captures) {
|
function utf8Replacer($captures)
|
||||||
if (!empty($captures[1]))
|
{
|
||||||
|
if(!empty($captures[1]))
|
||||||
{
|
{
|
||||||
// Valid byte sequence. Return unmodified.
|
// Valid byte sequence. Return unmodified.
|
||||||
return $captures[1];
|
return $captures[1];
|
||||||
}
|
}
|
||||||
elseif(!empty($captures[2]))
|
else if(!empty($captures[2]))
|
||||||
{
|
{
|
||||||
// Remove user defined area
|
// Remove user defined area
|
||||||
if("\xF3\xB0\x80\x80" <= $captures[2])
|
if("\xF3\xB0\x80\x80" <= $captures[2])
|
||||||
|
|
@ -194,23 +220,27 @@ class Argument {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isValid() {
|
function isValid()
|
||||||
|
{
|
||||||
return $this->isValid;
|
return $this->isValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isColumnName(){
|
function isColumnName()
|
||||||
|
{
|
||||||
$type = $this->getType();
|
$type = $this->getType();
|
||||||
if($type == 'column_name') return true;
|
if($type == 'column_name') return true;
|
||||||
if($type == 'number' && !is_numeric($this->value) && $this->uses_default_value) return true;
|
if($type == 'number' && !is_numeric($this->value) && $this->uses_default_value) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getErrorMessage() {
|
function getErrorMessage()
|
||||||
|
{
|
||||||
return $this->errorMessage;
|
return $this->errorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureDefaultValue($default_value) {
|
function ensureDefaultValue($default_value)
|
||||||
if (!isset($this->value) || $this->value == '')
|
{
|
||||||
|
if(!isset($this->value) || $this->value == '')
|
||||||
{
|
{
|
||||||
$this->value = $default_value;
|
$this->value = $default_value;
|
||||||
$this->uses_default_value = true;
|
$this->uses_default_value = true;
|
||||||
|
|
@ -222,49 +252,58 @@ class Argument {
|
||||||
* @param string $filter_type
|
* @param string $filter_type
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function checkFilter($filter_type) {
|
function checkFilter($filter_type)
|
||||||
if (isset($this->value) && $this->value != '') {
|
{
|
||||||
|
if(isset($this->value) && $this->value != '')
|
||||||
|
{
|
||||||
global $lang;
|
global $lang;
|
||||||
$val = $this->value;
|
$val = $this->value;
|
||||||
$key = $this->name;
|
$key = $this->name;
|
||||||
switch ($filter_type) {
|
switch ($filter_type)
|
||||||
|
{
|
||||||
case 'email' :
|
case 'email' :
|
||||||
case 'email_address' :
|
case 'email_address' :
|
||||||
if (!preg_match('/^[\w-]+((?:\.|\+|\~)[\w-]+)*@[\w-]+(\.[\w-]+)+$/is', $val)) {
|
if(!preg_match('/^[\w-]+((?:\.|\+|\~)[\w-]+)*@[\w-]+(\.[\w-]+)+$/is', $val))
|
||||||
|
{
|
||||||
$this->isValid = false;
|
$this->isValid = false;
|
||||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_email, $lang->{$key} ? $lang->{$key} : $key));
|
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_email, $lang->{$key} ? $lang->{$key} : $key));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'homepage' :
|
case 'homepage' :
|
||||||
if (!preg_match('/^(http|https)+(:\/\/)+[0-9a-z_-]+\.[^ ]+$/is', $val)) {
|
if(!preg_match('/^(http|https)+(:\/\/)+[0-9a-z_-]+\.[^ ]+$/is', $val))
|
||||||
|
{
|
||||||
$this->isValid = false;
|
$this->isValid = false;
|
||||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_homepage, $lang->{$key} ? $lang->{$key} : $key));
|
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_homepage, $lang->{$key} ? $lang->{$key} : $key));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'userid' :
|
case 'userid' :
|
||||||
case 'user_id' :
|
case 'user_id' :
|
||||||
if (!preg_match('/^[a-zA-Z]+([_0-9a-zA-Z]+)*$/is', $val)) {
|
if(!preg_match('/^[a-zA-Z]+([_0-9a-zA-Z]+)*$/is', $val))
|
||||||
|
{
|
||||||
$this->isValid = false;
|
$this->isValid = false;
|
||||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_userid, $lang->{$key} ? $lang->{$key} : $key));
|
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_userid, $lang->{$key} ? $lang->{$key} : $key));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'number' :
|
case 'number' :
|
||||||
case 'numbers' :
|
case 'numbers' :
|
||||||
if (is_array($val))
|
if(is_array($val))
|
||||||
$val = join(',', $val);
|
$val = join(',', $val);
|
||||||
if (!preg_match('/^(-?)[0-9]+(,\-?[0-9]+)*$/is', $val)) {
|
if(!preg_match('/^(-?)[0-9]+(,\-?[0-9]+)*$/is', $val))
|
||||||
|
{
|
||||||
$this->isValid = false;
|
$this->isValid = false;
|
||||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_number, $lang->{$key} ? $lang->{$key} : $key));
|
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_number, $lang->{$key} ? $lang->{$key} : $key));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'alpha' :
|
case 'alpha' :
|
||||||
if (!preg_match('/^[a-z]+$/is', $val)) {
|
if(!preg_match('/^[a-z]+$/is', $val))
|
||||||
|
{
|
||||||
$this->isValid = false;
|
$this->isValid = false;
|
||||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha, $lang->{$key} ? $lang->{$key} : $key));
|
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha, $lang->{$key} ? $lang->{$key} : $key));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'alpha_number' :
|
case 'alpha_number' :
|
||||||
if (!preg_match('/^[0-9a-z]+$/is', $val)) {
|
if(!preg_match('/^[0-9a-z]+$/is', $val))
|
||||||
|
{
|
||||||
$this->isValid = false;
|
$this->isValid = false;
|
||||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha_number, $lang->{$key} ? $lang->{$key} : $key));
|
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha_number, $lang->{$key} ? $lang->{$key} : $key));
|
||||||
}
|
}
|
||||||
|
|
@ -273,8 +312,10 @@ class Argument {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkMaxLength($length) {
|
function checkMaxLength($length)
|
||||||
if ($this->value && (strlen($this->value) > $length)) {
|
{
|
||||||
|
if($this->value && (strlen($this->value) > $length))
|
||||||
|
{
|
||||||
global $lang;
|
global $lang;
|
||||||
$this->isValid = false;
|
$this->isValid = false;
|
||||||
$key = $this->name;
|
$key = $this->name;
|
||||||
|
|
@ -282,8 +323,10 @@ class Argument {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkMinLength($length) {
|
function checkMinLength($length)
|
||||||
if ($this->value && (strlen($this->value) < $length)) {
|
{
|
||||||
|
if($this->value && (strlen($this->value) < $length))
|
||||||
|
{
|
||||||
global $lang;
|
global $lang;
|
||||||
$this->isValid = false;
|
$this->isValid = false;
|
||||||
$key = $this->name;
|
$key = $this->name;
|
||||||
|
|
@ -291,15 +334,16 @@ class Argument {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkNotNull() {
|
function checkNotNull()
|
||||||
if (!isset($this->value)) {
|
{
|
||||||
|
if(!isset($this->value))
|
||||||
|
{
|
||||||
global $lang;
|
global $lang;
|
||||||
$this->isValid = false;
|
$this->isValid = false;
|
||||||
$key = $this->name;
|
$key = $this->name;
|
||||||
$this->errorMessage = new Object(-1, sprintf($lang->filter->isnull, $lang->{$key} ? $lang->{$key} : $key));
|
$this->errorMessage = new Object(-1, sprintf($lang->filter->isnull, $lang->{$key} ? $lang->{$key} : $key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/* End of file Argument.class.php */
|
||||||
?>
|
/* Location: ./classes/xml/xmlquery/Argument.class.php */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue