issue 2119. supporting php 5.4. validator class.

git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12695 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
flyskyko 2013-02-05 02:53:25 +00:00
parent 0973ed647a
commit 19cda127e4

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Validator class * Validator class
* @author NHN (developers@xpressengine.com) * @author NHN (developers@xpressengine.com)
@ -7,41 +8,49 @@
*/ */
class Validator class Validator
{ {
/** /**
* cache directory * cache directory
* @var string * @var string
*/ */
var $_cache_dir = ''; var $_cache_dir = '';
/** /**
* last error * last error
* @var array * @var array
*/ */
var $_last_error; var $_last_error;
/** /**
* xml ruleset object * xml ruleset object
* @var Xml_Node_ object * @var Xml_Node_ object
*/ */
var $_xml_ruleset = null; var $_xml_ruleset = NULL;
/** /**
* rule list * rule list
* @var array * @var array
*/ */
var $_rules; var $_rules;
/** /**
* filter list * filter list
* @var array * @var array
*/ */
var $_filters; var $_filters;
/** /**
* Can usable status for multibyte string function * Can usable status for multibyte string function
* @var boolean * @var boolean
*/ */
var $_has_mb_func; var $_has_mb_func;
/** /**
* validator version * validator version
* @var string * @var string
*/ */
var $_version = '1.0'; var $_version = '1.0';
/** /**
* ruleset xml file path * ruleset xml file path
* @var string * @var string
@ -53,33 +62,24 @@ class Validator
* @param string $xml_path * @param string $xml_path
* @return void * @return void
*/ */
function Validator($xml_path='') function __construct($xml_path = '')
{ {
$this->__construct($xml_path); $this->_rules = array();
}
/**
* @constructor
* @param string $xml_path
* @return void
*/
function __construct($xml_path='')
{
$this->_rules = array();
$this->_filters = array(); $this->_filters = array();
$this->_xml_ruleset = null; $this->_xml_ruleset = NULL;
if($xml_path) $this->load($xml_path); if($xml_path)
$this->load($xml_path);
// predefined rules // predefined rules
$this->addRule(array( $this->addRule(array(
'email' => '/^[\w-]+((?:\.|\+|\~)[\w-]+)*@[\w-]+(\.[\w-]+)+$/', 'email' => '/^[\w-]+((?:\.|\+|\~)[\w-]+)*@[\w-]+(\.[\w-]+)+$/',
'userid' => '/^[a-z]+[\w-]*[a-z0-9_]+$/i', 'userid' => '/^[a-z]+[\w-]*[a-z0-9_]+$/i',
'url' => '/^(https?|ftp|mms):\/\/[0-9a-z-]+(\.[_0-9a-z-]+)+(:\d+)?/', 'url' => '/^(https?|ftp|mms):\/\/[0-9a-z-]+(\.[_0-9a-z-]+)+(:\d+)?/',
'alpha' => '/^[a-z]*$/i', 'alpha' => '/^[a-z]*$/i',
'alpha_number' => '/^[a-z][a-z0-9_]*$/i', 'alpha_number' => '/^[a-z][a-z0-9_]*$/i',
'number' => '/^(?:[1-9]\\d*|0)$/' 'number' => '/^(?:[1-9]\\d*|0)$/'
)); ));
$this->_has_mb_func = is_callable('mb_strlen'); $this->_has_mb_func = is_callable('mb_strlen');
$this->setCacheDir('./files/cache'); $this->setCacheDir('./files/cache');
@ -91,8 +91,8 @@ class Validator
*/ */
function __destruct() function __destruct()
{ {
$this->_rules = null; $this->_rules = NULL;
$this->_filters = null; $this->_filters = NULL;
} }
/** /**
@ -102,47 +102,68 @@ class Validator
*/ */
function load($xml_path) function load($xml_path)
{ {
$this->_xml_ruleset = null; $this->_xml_ruleset = NULL;
$xml_path = realpath($xml_path); $xml_path = realpath($xml_path);
if(!is_readable($xml_path)) return false; if(!is_readable($xml_path))
{
return FALSE;
}
$parser = new XmlParser(); $parser = new XmlParser();
$xml = $parser->loadXmlFile($xml_path); $xml = $parser->loadXmlFile($xml_path);
if(!isset($xml->ruleset) || !isset($xml->ruleset->fields) || !isset($xml->ruleset->fields->field)) return false; if(!isset($xml->ruleset) || !isset($xml->ruleset->fields) || !isset($xml->ruleset->fields->field))
{
return FALSE;
}
// custom rules // custom rules
if(isset($xml->ruleset->customrules) && isset($xml->ruleset->customrules->rule)) if(isset($xml->ruleset->customrules) && isset($xml->ruleset->customrules->rule))
{ {
$customrules = $xml->ruleset->customrules->rule; $customrules = $xml->ruleset->customrules->rule;
if(!is_array($customrules)) $customrules = array($customrules); if(!is_array($customrules))
{
$customrules = array($customrules);
}
$rules = array(); $rules = array();
foreach($customrules as $rule) foreach($customrules as $rule)
{ {
if(!isset($rule->attrs) || !isset($rule->attrs->name)) continue; if(!isset($rule->attrs) || !isset($rule->attrs->name))
{
continue;
}
$rule = (array)$rule->attrs; $rule = (array) $rule->attrs;
$name = $rule['name']; $name = $rule['name'];
unset($rule['name']); unset($rule['name']);
$rules[$name] = $rule; $rules[$name] = $rule;
} }
if(count($rules)) $this->addRule($rules); if(count($rules))
{
$this->addRule($rules);
}
} }
// filters // filters
$fields = $xml->ruleset->fields->field; $fields = $xml->ruleset->fields->field;
if(!is_array($fields)) $fields = array($fields); if(!is_array($fields))
{
$fields = array($fields);
}
$filters = array(); $filters = array();
foreach($fields as $field) foreach($fields as $field)
{ {
$name = ''; $name = '';
$filter = array(); $filter = array();
if(!isset($field->attrs) || !isset($field->attrs->name)) continue; if(!isset($field->attrs) || !isset($field->attrs->name))
$filter = (array)$field->attrs; {
continue;
}
$filter = (array) $field->attrs;
$name = $filter['name']; $name = $filter['name'];
unset($filter['name']); unset($filter['name']);
@ -151,10 +172,13 @@ class Validator
if(isset($field->if)) if(isset($field->if))
{ {
$if = $field->if; $if = $field->if;
if(!is_array($if)) $if = array($if); if(!is_array($if))
foreach($if as $idx=>$cond)
{ {
$if[$idx] = (array)$cond->attrs; $if = array($if);
}
foreach($if as $idx => $cond)
{
$if[$idx] = (array) $cond->attrs;
} }
$filter['if'] = $if; $filter['if'] = $if;
} }
@ -163,10 +187,10 @@ class Validator
} }
$this->_xml_ruleset = $xml->ruleset; $this->_xml_ruleset = $xml->ruleset;
$this->_filters = $filters; $this->_filters = $filters;
$this->_xml_path = $xml_path; $this->_xml_path = $xml_path;
return true; return TRUE;
} }
/** /**
@ -187,7 +211,7 @@ class Validator
* @param array $fields Target fields. The keys of the array represents field's name, its values represents field's value. * @param array $fields Target fields. The keys of the array represents field's name, its values represents field's value.
* @return boolean TRUE if it is valid, FALSE otherwise. * @return boolean TRUE if it is valid, FALSE otherwise.
*/ */
function validate($fields_=null) function validate($fields_ = null)
{ {
if(is_array($fields_)) if(is_array($fields_))
{ {
@ -195,21 +219,24 @@ class Validator
} }
else else
{ {
$args = array_keys($this->_filters); $args = array_keys($this->_filters);
$fields = (array)Context::getRequestVars(); $fields = (array) Context::getRequestVars();
} }
if(!is_array($fields)) return true; if(!is_array($fields))
{
return TRUE;
}
$filter_default = array( $filter_default = array(
'required' => 'false', 'required' => 'false',
'default' => '', 'default' => '',
'modifiers' => array(), 'modifiers' => array(),
'length' => 0, 'length' => 0,
'equalto' => 0, 'equalto' => 0,
'rule' => 0, 'rule' => 0,
'if' => array() 'if' => array()
); );
$fields = array_map(array($this, 'arrayTrim'), $fields); $fields = array_map(array($this, 'arrayTrim'), $fields);
$field_names = array_keys($fields); $field_names = array_keys($fields);
@ -217,16 +244,16 @@ class Validator
$filters = array(); $filters = array();
// get field names matching patterns // get field names matching patterns
foreach($this->_filters as $key=>$filter) foreach($this->_filters as $key => $filter)
{ {
$names = array(); $names = array();
if($key{0} == '^') if($key{0} == '^')
{ {
$names = preg_grep('/^'.preg_quote(substr($key,1)).'/', $field_names); $names = preg_grep('/^' . preg_quote(substr($key, 1)) . '/', $field_names);
} }
elseif(substr($key,-2) == '[]') elseif(substr($key, -2) == '[]')
{ {
$filters[substr($key,0,-2)] = $filter; $filters[substr($key, 0, -2)] = $filter;
unset($filters[$key]); unset($filters[$key]);
} }
else else
@ -234,7 +261,10 @@ class Validator
$filters[$key] = $filter; $filters[$key] = $filter;
} }
if(!count($names)) continue; if(!count($names))
{
continue;
}
foreach($names as $name) foreach($names as $name)
{ {
@ -243,20 +273,20 @@ class Validator
unset($filters[$key]); unset($filters[$key]);
} }
foreach($filters as $key=>$filter) foreach($filters as $key => $filter)
{ {
$fname = preg_replace('/\[\]$/', '', $key); $fname = preg_replace('/\[\]$/', '', $key);
$filter = array_merge($filter_default, $filter); $filter = array_merge($filter_default, $filter);
if(preg_match("/(^[a-z_]*)[\[](?:\'|\")?([a-z_]*)(?:\'|\")?[\]]$/i", $key, $matches)) if(preg_match("/(^[a-z_]*)[\[](?:\'|\")?([a-z_]*)(?:\'|\")?[\]]$/i", $key, $matches))
{ {
$exists = array_key_exists($matches[1], $fields); $exists = array_key_exists($matches[1], $fields);
$value = $exists ? $fields[$matches[1]][$matches[2]] : null; $value = $exists ? $fields[$matches[1]][$matches[2]] : NULL;
} }
else else
{ {
$exists = array_key_exists($key, $fields); $exists = array_key_exists($key, $fields);
$value = $exists ? $fields[$fname] : null; $value = $exists ? $fields[$fname] : NULL;
} }
if(is_array($value)) if(is_array($value))
@ -274,70 +304,103 @@ class Validator
// conditional statement // conditional statement
foreach($filter['if'] as $cond) foreach($filter['if'] as $cond)
{ {
if(!isset($cond['test']) || !isset($cond['attr'])) continue; if(!isset($cond['test']) || !isset($cond['attr']))
{
continue;
}
$func_body = preg_replace('/\\$(\w+)/', '$c[\'$1\']', $cond['test']); $func_body = preg_replace('/\\$(\w+)/', '$c[\'$1\']', $cond['test']);
$func = create_function('$c', "return !!({$func_body});"); $func = create_function('$c', "return !!({$func_body});");
if($func($fields)) $filter[$cond['attr']] = $cond['value']; if($func($fields))
{
$filter[$cond['attr']] = $cond['value'];
}
} }
// attr : default // attr : default
if(!$value && strlen($default=trim($filter['default']))) if(!$value && strlen($default = trim($filter['default'])))
{ {
$value = $default; $value = $default;
if(is_null($fields_)) Context::set($fname, $value); if(is_null($fields_))
else $fields_[$fname] = $value; {
Context::set($fname, $value);
}
else
{
$fields_[$fname] = $value;
}
} }
$value_len = strlen($value); $value_len = strlen($value);
// attr : modifier // attr : modifier
if(is_string($modifiers=$filter['modifiers'])) $modifiers = explode(',', trim($modifiers)); if(is_string($modifiers = $filter['modifiers']))
{
$modifiers = explode(',', trim($modifiers));
}
// attr : required // attr : required
if($filter['required'] === 'true' && !$value_len) return $this->error($key, 'isnull'); if($filter['required'] === 'true' && !$value_len)
{
return $this->error($key, 'isnull');
}
// if the field wasn't passed, ignore this value // if the field wasn't passed, ignore this value
if(!$exists && !$value_len) continue; if(!$exists && !$value_len)
{
continue;
}
// attr : length // attr : length
if($length=$filter['length']) if($length = $filter['length'])
{ {
list($min, $max) = explode(':', trim($length)); list($min, $max) = explode(':', trim($length));
$is_min_b = (substr($min, -1) === 'b'); $is_min_b = (substr($min, -1) === 'b');
$is_max_b = (substr($max, -1) === 'b'); $is_max_b = (substr($max, -1) === 'b');
list($min, $max) = array((int)$min, (int)$max); list($min, $max) = array((int) $min, (int) $max);
$strbytes = strlen($value); $strbytes = strlen($value);
if(!$is_min_b || !$is_max_b) if(!$is_min_b || !$is_max_b)
{ {
$strlength = $this->_has_mb_func?mb_strlen($value,'utf-8'):$this->mbStrLen($value); $strlength = $this->_has_mb_func ? mb_strlen($value, 'utf-8') : $this->mbStrLen($value);
} }
if(($min && $min > ($is_min_b?$strbytes:$strlength)) || ($max && $max < ($is_max_b?$strbytes:$strlength))) return $this->error($key, 'outofrange'); if(($min && $min > ($is_min_b ? $strbytes : $strlength)) || ($max && $max < ($is_max_b ? $strbytes : $strlength)))
{
return $this->error($key, 'outofrange');
}
} }
// equalto // equalto
if($equalto=$filter['equalto']) if($equalto = $filter['equalto'])
{ {
if(!array_key_exists($equalto, $fields) || trim($fields[$equalto]) !== $value) return $this->error($key, 'equalto'); if(!array_key_exists($equalto, $fields) || trim($fields[$equalto]) !== $value)
{
return $this->error($key, 'equalto');
}
} }
// rules // rules
if($rules=$filter['rule']) if($rules = $filter['rule'])
{ {
$rules = explode(',', $rules); $rules = explode(',', $rules);
foreach($rules as $rule) foreach($rules as $rule)
{ {
$result = $this->applyRule($rule, $value); $result = $this->applyRule($rule, $value);
// apply the 'not' modifier // apply the 'not' modifier
if(in_array('not', $modifiers)) $result = !$result; if(in_array('not', $modifiers))
if(!$result) return $this->error($key, 'invalid_'.$rule); {
$result = !$result;
}
if(!$result)
{
return $this->error($key, 'invalid_' . $rule);
}
} }
} }
} }
return true; return TRUE;
} }
/** /**
@ -347,7 +410,10 @@ class Validator
*/ */
function arrayTrim($array) function arrayTrim($array)
{ {
if(!is_array($array)) return trim($array); if(!is_array($array))
{
return trim($array);
}
foreach($array as $key => $value) foreach($array as $key => $value)
{ {
@ -365,12 +431,12 @@ class Validator
function error($field, $msg) function error($field, $msg)
{ {
$lang_filter = Context::getLang('filter'); $lang_filter = Context::getLang('filter');
$msg = isset($lang_filter->{$msg})?$lang_filter->{$msg}:$lang_filter->invalid; $msg = isset($lang_filter->{$msg}) ? $lang_filter->{$msg} : $lang_filter->invalid;
$msg = sprintf($msg, Context::getLang($field)); $msg = sprintf($msg, Context::getLang($field));
$this->_last_error = array('field'=>$field, 'msg'=>$msg); $this->_last_error = array('field' => $field, 'msg' => $msg);
return false; return FALSE;
} }
/** /**
@ -388,19 +454,31 @@ class Validator
* @param mixed $rule * @param mixed $rule
* @return void * @return void
*/ */
function addRule($name, $rule='') function addRule($name, $rule = '')
{ {
if(is_array($name)) $args = $name; if(is_array($name))
else $args = array($name=>$rule);
foreach($args as $name=>$rule)
{ {
if(!$rule) continue; $args = $name;
if(is_string($rule)) $rule = array('type'=>'regex', 'test'=>$rule); }
else
{
$args = array($name => $rule);
}
foreach($args as $name => $rule)
{
if(!$rule)
{
continue;
}
if(is_string($rule))
{
$rule = array('type' => 'regex', 'test' => $rule);
}
if($rule['type'] == 'enum') if($rule['type'] == 'enum')
{ {
$delim = isset($rule['delim'])?$rule['delim']:','; $delim = isset($rule['delim']) ? $rule['delim'] : ',';
$rule['test'] = explode($delim, $rule['test']); $rule['test'] = explode($delim, $rule['test']);
} }
@ -424,21 +502,33 @@ class Validator
* @param string $filter filter * @param string $filter filter
* @return void * @return void
*/ */
function addFilter($name, $filter='') function addFilter($name, $filter = '')
{ {
if(is_array($name)) $args = $name; if(is_array($name))
else $args = array($name=>$filter);
foreach($args as $name=>$filter)
{ {
if(!$filter) continue; $args = $name;
}
else
{
$args = array($name => $filter);
}
foreach($args as $name => $filter)
{
if(!$filter)
{
continue;
}
if(isset($filter['if'])) if(isset($filter['if']))
{ {
if(is_array($filter['if']) && count($filter['if'])) if(is_array($filter['if']) && count($filter['if']))
{ {
$key = key($filter['if']); $key = key($filter['if']);
if(!is_int($key)) $filter['if'] = array($filter['if']); if(!is_int($key))
{
$filter['if'] = array($filter['if']);
}
} }
else else
{ {
@ -470,7 +560,7 @@ class Validator
{ {
$rule = $this->_rules[$name]; $rule = $this->_rules[$name];
if (is_array($value) && isset($value['tmp_name'])) if(is_array($value) && isset($value['tmp_name']))
{ {
$value = $value['name']; $value = $value['name'];
} }
@ -484,12 +574,12 @@ class Validator
case 'expr': case 'expr':
if(!$rule['func_test']) if(!$rule['func_test'])
{ {
$rule['func_test'] = create_function('$a', 'return ('.preg_replace('/\$\$/', '$a', html_entity_decode($rule['test'])).');'); $rule['func_test'] = create_function('$a', 'return (' . preg_replace('/\$\$/', '$a', html_entity_decode($rule['test'])) . ');');
} }
return $rule['func_test']($value); return $rule['func_test']($value);
} }
return true; return TRUE;
} }
/** /**
@ -500,7 +590,7 @@ class Validator
function mbStrLen($str) function mbStrLen($str)
{ {
$arr = count_chars($str); $arr = count_chars($str);
for($i=0x80; $i < 0xc0; $i++) for($i = 0x80; $i < 0xc0; $i++)
{ {
unset($arr[$i]); unset($arr[$i]);
} }
@ -513,21 +603,36 @@ class Validator
*/ */
function getJsPath() function getJsPath()
{ {
if(!$this->_cache_dir) return false; if(!$this->_cache_dir)
{
return FALSE;
}
$dir = $this->_cache_dir.'/ruleset'; $dir = $this->_cache_dir . '/ruleset';
if(!is_dir($dir) && !mkdir($dir)) return false; if(!is_dir($dir) && !mkdir($dir))
if(!$this->_xml_path) return false; {
return FALSE;
}
if(!$this->_xml_path)
{
return FALSE;
}
// current language // current language
$lang_type = class_exists('Context')?Context::getLangType():'en'; $lang_type = class_exists('Context') ? Context::getLangType() : 'en';
// check the file // check the file
$filepath = $dir.'/'.md5($this->_version.' '.$this->_xml_path).".{$lang_type}.js"; $filepath = $dir . '/' . md5($this->_version . ' ' . $this->_xml_path) . ".{$lang_type}.js";
if(is_readable($filepath) && filemtime($filepath) > filemtime($this->_xml_path)) return $filepath; if(is_readable($filepath) && filemtime($filepath) > filemtime($this->_xml_path))
{
return $filepath;
}
$content = $this->_compile2js(); $content = $this->_compile2js();
if($content === false) return false; if($content === FALSE)
{
return FALSE;
}
if(is_callable('file_put_contents')) if(is_callable('file_put_contents'))
{ {
@ -554,28 +659,34 @@ class Validator
{ {
global $lang; global $lang;
$ruleset = basename($this->_xml_path,'.xml'); $ruleset = basename($this->_xml_path, '.xml');
$content = array(); $content = array();
if(preg_match('@(^|/)files/ruleset/\w+\.xml$@i', $this->_xml_path)) $ruleset = '@'.$ruleset; if(preg_match('@(^|/)files/ruleset/\w+\.xml$@i', $this->_xml_path))
{
$ruleset = '@' . $ruleset;
}
list($ruleset) = explode('.', $ruleset); list($ruleset) = explode('.', $ruleset);
// current language // current language
$lang_type = class_exists('Context')?Context::getLangType():'en'; $lang_type = class_exists('Context') ? Context::getLangType() : 'en';
// custom rulesets // custom rulesets
$addrules = array(); $addrules = array();
foreach($this->_rules as $name=>$rule) foreach($this->_rules as $name => $rule)
{ {
if(strpos('email,userid,url,alpha,alpha_number,number,', $name.',') !== false) continue; if(strpos('email,userid,url,alpha,alpha_number,number,', $name . ',') !== false)
{
continue;
}
switch($rule['type']) switch($rule['type'])
{ {
case 'regex': case 'regex':
$content[] = "v.cast('ADD_RULE', ['{$name}', {$rule['test']}]);"; $content[] = "v.cast('ADD_RULE', ['{$name}', {$rule['test']}]);";
break; break;
case 'enum': case 'enum':
$enums = '"'.implode('","', $rule['test']).'"'; $enums = '"' . implode('","', $rule['test']) . '"';
$content[] = "v.cast('ADD_RULE', ['{$name}', function($$){ return ($.inArray($$,[{$enums}]) > -1); }]);"; $content[] = "v.cast('ADD_RULE', ['{$name}', function($$){ return ($.inArray($$,[{$enums}]) > -1); }]);";
break; break;
case 'expr': case 'expr':
@ -586,9 +697,9 @@ class Validator
$addrules = implode('', $addrules); $addrules = implode('', $addrules);
// filters // filters
$content = array(); $content = array();
$messages = array(); $messages = array();
foreach($this->_filters as $name=>$filter) foreach($this->_filters as $name => $filter)
{ {
$field = array(); $field = array();
@ -599,37 +710,61 @@ class Validator
$messages[] = "v.cast('ADD_MESSAGE',['{$name}','{$field_lang}']);"; $messages[] = "v.cast('ADD_MESSAGE',['{$name}','{$field_lang}']);";
} }
if($filter['required'] == 'true') $field[] = 'required:true'; if($filter['required'] == 'true')
if($filter['rule']) $field[] = "rule:'{$filter['rule']}'"; {
if($filter['default']) $field[] = "default:'{$filter['default']}'"; $field[] = 'required:true';
if($filter['modifier']) $field[] = "modifier:'{$filter['modifier']}'"; }
if($filter['rule'])
{
$field[] = "rule:'{$filter['rule']}'";
}
if($filter['default'])
{
$field[] = "default:'{$filter['default']}'";
}
if($filter['modifier'])
{
$field[] = "modifier:'{$filter['modifier']}'";
}
if($filter['length']) if($filter['length'])
{ {
list($min, $max) = explode(':', $filter['length']); list($min, $max) = explode(':', $filter['length']);
if($min) $field[] = "minlength:'{$min}'"; if($min)
if($max) $field[] = "maxlength:'{$max}'"; {
$field[] = "minlength:'{$min}'";
}
if($max)
{
$field[] = "maxlength:'{$max}'";
}
} }
if($filter['if']) if($filter['if'])
{ {
$ifs = array(); $ifs = array();
if(!isset($filter['if'][0])) $filter['if'] = array($filter['if']); if(!isset($filter['if'][0]))
{
$filter['if'] = array($filter['if']);
}
foreach($filter['if'] as $if) foreach($filter['if'] as $if)
{ {
$ifs[] = "{test:'".addslashes($if['test'])."', attr:'{$if['attr']}', value:'".addslashes($if['value'])."'}"; $ifs[] = "{test:'" . addslashes($if['test']) . "', attr:'{$if['attr']}', value:'" . addslashes($if['value']) . "'}";
} }
$field[] = "'if':[".implode(',', $ifs)."]"; $field[] = "'if':[" . implode(',', $ifs) . "]";
} }
if(count($field)) if(count($field))
{ {
$field = '{'.implode(',', $field).'}'; $field = '{' . implode(',', $field) . '}';
$content[] = "'{$name}':{$field}"; $content[] = "'{$name}':{$field}";
} }
} }
if(!$content) return '/* Error : empty ruleset */'; if(!$content)
{
return '/* Error : empty ruleset */';
}
// error messages // error messages
foreach($lang->filter as $key=>$text) foreach($lang->filter as $key => $text)
{ {
if($text) if($text)
{ {
@ -638,11 +773,12 @@ class Validator
} }
} }
$content = implode(',', $content); $content = implode(',', $content);
$messages = implode("\n", $messages); $messages = implode("\n", $messages);
return "(function($,v){\nv=xe.getApp('validator')[0];if(!v)return;\n{$addrules}\nv.cast('ADD_FILTER',['{$ruleset}', {{$content}}]);\n{$messages}\n})(jQuery);"; return "(function($,v){\nv=xe.getApp('validator')[0];if(!v)return;\n{$addrules}\nv.cast('ADD_FILTER',['{$ruleset}', {{$content}}]);\n{$messages}\n})(jQuery);";
} }
} }
/* End of file Validator.class.php */ /* End of file Validator.class.php */
/* Location: ./classes/validator/Validator.class.php */ /* Location: ./classes/validator/Validator.class.php */