mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
增加view_filter行为标签
This commit is contained in:
@@ -176,6 +176,8 @@ class View
|
|||||||
}
|
}
|
||||||
// 获取并清空缓存
|
// 获取并清空缓存
|
||||||
$content = ob_get_clean();
|
$content = ob_get_clean();
|
||||||
|
// 内容过滤标签
|
||||||
|
APP_HOOK && Hook::listen('view_filter', $content);
|
||||||
// 允许用户自定义模板的字符串替换
|
// 允许用户自定义模板的字符串替换
|
||||||
if (!empty($this->config['parse_str'])) {
|
if (!empty($this->config['parse_str'])) {
|
||||||
$replace = $this->config['parse_str'];
|
$replace = $this->config['parse_str'];
|
||||||
|
|||||||
@@ -35,9 +35,9 @@ trait Auto
|
|||||||
$this->error = Lang::get('_DATA_TYPE_INVALID_');
|
$this->error = Lang::get('_DATA_TYPE_INVALID_');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$pk = $this->getPk();
|
||||||
// 状态
|
// 状态
|
||||||
$type = $type ? $type : (!empty($data[$this->getPk()]) ? self::MODEL_UPDATE : self::MODEL_INSERT);
|
$type = $type ? $type : (is_string($pk) && !empty($data[$pk]) ? self::MODEL_UPDATE : self::MODEL_INSERT);
|
||||||
$type = 1 << ($type - 1);
|
$type = 1 << ($type - 1);
|
||||||
// 字段列表
|
// 字段列表
|
||||||
$keys = array_keys($data);
|
$keys = array_keys($data);
|
||||||
@@ -193,8 +193,8 @@ trait Auto
|
|||||||
$auto[3] = 'string';
|
$auto[3] = 'string';
|
||||||
}
|
}
|
||||||
switch (trim($auto[3])) {
|
switch (trim($auto[3])) {
|
||||||
case 'function':// 使用函数进行填充 字段的值作为参数
|
case 'function': // 使用函数进行填充 字段的值作为参数
|
||||||
case 'callback': // 使用回调方法
|
case 'callback': // 使用回调方法
|
||||||
$args = isset($auto[4]) ? (array) $auto[4] : [];
|
$args = isset($auto[4]) ? (array) $auto[4] : [];
|
||||||
if (is_string($auto[0]) && strpos($auto[0], ',')) {
|
if (is_string($auto[0]) && strpos($auto[0], ',')) {
|
||||||
$auto[0] = explode(',', $auto[0]);
|
$auto[0] = explode(',', $auto[0]);
|
||||||
@@ -214,16 +214,16 @@ trait Auto
|
|||||||
$data[$auto[0]] = call_user_func_array([ & $this, $auto[1]], $args);
|
$data[$auto[0]] = call_user_func_array([ & $this, $auto[1]], $args);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'field': // 用其它字段的值进行填充
|
case 'field': // 用其它字段的值进行填充
|
||||||
$data[$auto[0]] = $data[$auto[1]];
|
$data[$auto[0]] = $data[$auto[1]];
|
||||||
break;
|
break;
|
||||||
case 'ignore': // 为空忽略
|
case 'ignore': // 为空忽略
|
||||||
if ($auto[1] === $data[$auto[0]]) {
|
if ($auto[1] === $data[$auto[0]]) {
|
||||||
unset($data[$auto[0]]);
|
unset($data[$auto[0]]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'string':
|
case 'string':
|
||||||
default: // 默认作为字符串填充
|
default: // 默认作为字符串填充
|
||||||
$data[$auto[0]] = $auto[1];
|
$data[$auto[0]] = $auto[1];
|
||||||
}
|
}
|
||||||
if (isset($data[$auto[0]]) && false === $data[$auto[0]]) {
|
if (isset($data[$auto[0]]) && false === $data[$auto[0]]) {
|
||||||
@@ -321,15 +321,15 @@ trait Auto
|
|||||||
$status = true;
|
$status = true;
|
||||||
// 判断验证条件
|
// 判断验证条件
|
||||||
switch ($val[3]) {
|
switch ($val[3]) {
|
||||||
case self::MUST_VALIDATE: // 必须验证 不管表单是否有设置该字段
|
case self::MUST_VALIDATE: // 必须验证 不管表单是否有设置该字段
|
||||||
$status = $this->_validationFieldItem($data, $val);
|
$status = $this->_validationFieldItem($data, $val);
|
||||||
break;
|
break;
|
||||||
case self::VALUE_VALIDATE: // 值不为空的时候才验证
|
case self::VALUE_VALIDATE: // 值不为空的时候才验证
|
||||||
if ('' != trim($data[$val[0]])) {
|
if ('' != trim($data[$val[0]])) {
|
||||||
$status = $this->_validationFieldItem($data, $val);
|
$status = $this->_validationFieldItem($data, $val);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: // 默认表单存在该字段就验证
|
default: // 默认表单存在该字段就验证
|
||||||
if (isset($data[$val[0]])) {
|
if (isset($data[$val[0]])) {
|
||||||
$status = $this->_validationFieldItem($data, $val);
|
$status = $this->_validationFieldItem($data, $val);
|
||||||
}
|
}
|
||||||
@@ -356,8 +356,8 @@ trait Auto
|
|||||||
protected function _validationFieldItem($data, $val)
|
protected function _validationFieldItem($data, $val)
|
||||||
{
|
{
|
||||||
switch (strtolower(trim($val[4]))) {
|
switch (strtolower(trim($val[4]))) {
|
||||||
case 'function':// 使用函数进行验证
|
case 'function': // 使用函数进行验证
|
||||||
case 'callback': // 调用方法进行验证
|
case 'callback': // 调用方法进行验证
|
||||||
$args = isset($val[6]) ? (array) $val[6] : [];
|
$args = isset($val[6]) ? (array) $val[6] : [];
|
||||||
if (is_string($val[0]) && strpos($val[0], ',')) {
|
if (is_string($val[0]) && strpos($val[0], ',')) {
|
||||||
$val[0] = explode(',', $val[0]);
|
$val[0] = explode(',', $val[0]);
|
||||||
@@ -372,9 +372,9 @@ trait Auto
|
|||||||
array_unshift($args, isset($data[$val[0]]) ? $data[$val[0]] : null);
|
array_unshift($args, isset($data[$val[0]]) ? $data[$val[0]] : null);
|
||||||
}
|
}
|
||||||
return call_user_func_array('function' == $val[4] ? $val[1] : [ & $this, $val[1]], $args);
|
return call_user_func_array('function' == $val[4] ? $val[1] : [ & $this, $val[1]], $args);
|
||||||
case 'confirm': // 验证两个字段是否相同
|
case 'confirm': // 验证两个字段是否相同
|
||||||
return $data[$val[0]] == $data[$val[1]];
|
return $data[$val[0]] == $data[$val[1]];
|
||||||
case 'unique': // 验证某个值是否唯一
|
case 'unique': // 验证某个值是否唯一
|
||||||
if (is_string($val[0])) {
|
if (is_string($val[0])) {
|
||||||
$val[0] = explode(',', $val[0]);
|
$val[0] = explode(',', $val[0]);
|
||||||
}
|
}
|
||||||
@@ -399,7 +399,7 @@ trait Auto
|
|||||||
}
|
}
|
||||||
$this->options = $options;
|
$this->options = $options;
|
||||||
return true;
|
return true;
|
||||||
default: // 检查附加规则
|
default: // 检查附加规则
|
||||||
return $this->check($data[$val[0]], $val[1], $val[4]);
|
return $this->check($data[$val[0]], $val[1], $val[4]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -416,12 +416,12 @@ trait Auto
|
|||||||
{
|
{
|
||||||
$type = strtolower(trim($type));
|
$type = strtolower(trim($type));
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'in':// 验证是否在某个指定范围之内 逗号分隔字符串或者数组
|
case 'in': // 验证是否在某个指定范围之内 逗号分隔字符串或者数组
|
||||||
case 'notin':
|
case 'notin':
|
||||||
$range = is_array($rule) ? $rule : explode(',', $rule);
|
$range = is_array($rule) ? $rule : explode(',', $rule);
|
||||||
return 'in' == $type ? in_array($value, $range) : !in_array($value, $range);
|
return 'in' == $type ? in_array($value, $range) : !in_array($value, $range);
|
||||||
case 'between':// 验证是否在某个范围
|
case 'between': // 验证是否在某个范围
|
||||||
case 'notbetween': // 验证是否不在某个范围
|
case 'notbetween': // 验证是否不在某个范围
|
||||||
if (is_array($rule)) {
|
if (is_array($rule)) {
|
||||||
$min = $rule[0];
|
$min = $rule[0];
|
||||||
$max = $rule[1];
|
$max = $rule[1];
|
||||||
@@ -429,11 +429,11 @@ trait Auto
|
|||||||
list($min, $max) = explode(',', $rule);
|
list($min, $max) = explode(',', $rule);
|
||||||
}
|
}
|
||||||
return 'between' == $type ? $value >= $min && $value <= $max : $value < $min || $value > $max;
|
return 'between' == $type ? $value >= $min && $value <= $max : $value < $min || $value > $max;
|
||||||
case 'equal':// 验证是否等于某个值
|
case 'equal': // 验证是否等于某个值
|
||||||
case 'notequal': // 验证是否等于某个值
|
case 'notequal': // 验证是否等于某个值
|
||||||
return 'equal' == $type ? $value == $rule : $value != $rule;
|
return 'equal' == $type ? $value == $rule : $value != $rule;
|
||||||
case 'length': // 验证长度
|
case 'length': // 验证长度
|
||||||
$length = mb_strlen($value, 'utf-8'); // 当前数据长度
|
$length = mb_strlen($value, 'utf-8'); // 当前数据长度
|
||||||
if (strpos($rule, ',')) {
|
if (strpos($rule, ',')) {
|
||||||
// 长度区间
|
// 长度区间
|
||||||
list($min, $max) = explode(',', $rule);
|
list($min, $max) = explode(',', $rule);
|
||||||
@@ -451,15 +451,15 @@ trait Auto
|
|||||||
$end = strtotime($end);
|
$end = strtotime($end);
|
||||||
}
|
}
|
||||||
return NOW_TIME >= $start && NOW_TIME <= $end;
|
return NOW_TIME >= $start && NOW_TIME <= $end;
|
||||||
case 'ip_allow': // IP 操作许可验证
|
case 'ip_allow': // IP 操作许可验证
|
||||||
return in_array($_SERVER['REMOTE_ADDR'], explode(',', $rule));
|
return in_array($_SERVER['REMOTE_ADDR'], explode(',', $rule));
|
||||||
case 'ip_deny': // IP 操作禁止验证
|
case 'ip_deny': // IP 操作禁止验证
|
||||||
return !in_array($_SERVER['REMOTE_ADDR'], explode(',', $rule));
|
return !in_array($_SERVER['REMOTE_ADDR'], explode(',', $rule));
|
||||||
case 'filter': // 使用filter_var验证
|
case 'filter': // 使用filter_var验证
|
||||||
$result = filter_var($value, is_int($rule) ? $rule : filter_id($rule));
|
$result = filter_var($value, is_int($rule) ? $rule : filter_id($rule));
|
||||||
return false === $result ? false : true;
|
return false === $result ? false : true;
|
||||||
case 'regex':
|
case 'regex':
|
||||||
default: // 默认使用正则验证 可以使用验证类中定义的验证名称
|
default: // 默认使用正则验证 可以使用验证类中定义的验证名称
|
||||||
// 检查附加规则
|
// 检查附加规则
|
||||||
return $this->regex($value, $rule);
|
return $this->regex($value, $rule);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user