1、更新内核
2、代码格式化
This commit is contained in:
@@ -24,7 +24,7 @@
|
|||||||
* )
|
* )
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function int_to_string(&$data,$map=array('status'=>array(1=>'正常',-1=>'删除',0=>'禁用',2=>'未审核',3=>'草稿'))) {
|
function intToString(&$data, $map = array('status' => array(1 => '正常', -1 => '删除', 0 => '禁用', 2 => '未审核', 3 => '草稿'))) {
|
||||||
if ($data === false || $data === null) {
|
if ($data === false || $data === null) {
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
@@ -45,26 +45,35 @@ function int_to_string(&$data,$map=array('status'=>array(1=>'正常',-1=>'删除
|
|||||||
* @return string 状态文字 ,false 未获取到
|
* @return string 状态文字 ,false 未获取到
|
||||||
* @author huajie <banhuajie@163.com>
|
* @author huajie <banhuajie@163.com>
|
||||||
*/
|
*/
|
||||||
function get_status_title($status = null){
|
function getStatusTitle($status = null) {
|
||||||
if (!isset($status)) {
|
if (!isset($status)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
switch ($status) {
|
switch ($status) {
|
||||||
case -1 : return '已删除'; break;
|
case -1:return '已删除';
|
||||||
case 0 : return '禁用'; break;
|
break;
|
||||||
case 1 : return '正常'; break;
|
case 0:return '禁用';
|
||||||
case 2 : return '待审核'; break;
|
break;
|
||||||
default : return false; break;
|
case 1:return '正常';
|
||||||
|
break;
|
||||||
|
case 2:return '待审核';
|
||||||
|
break;
|
||||||
|
default:return false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取数据的状态操作
|
// 获取数据的状态操作
|
||||||
function show_status_op($status) {
|
function showStatusOp($status) {
|
||||||
switch ($status) {
|
switch ($status) {
|
||||||
case 0 : return '启用'; break;
|
case 0:return '启用';
|
||||||
case 1 : return '禁用'; break;
|
break;
|
||||||
case 2 : return '审核'; break;
|
case 1:return '禁用';
|
||||||
default : return false; break;
|
break;
|
||||||
|
case 2:return '审核';
|
||||||
|
break;
|
||||||
|
default:return false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +83,7 @@ function show_status_op($status) {
|
|||||||
* @param bool $all 是否返回全部类型
|
* @param bool $all 是否返回全部类型
|
||||||
* @author huajie <banhuajie@163.com>
|
* @author huajie <banhuajie@163.com>
|
||||||
*/
|
*/
|
||||||
function get_action_type($type, $all = false){
|
function getActionType($type, $all = false) {
|
||||||
$list = array(
|
$list = array(
|
||||||
1 => '系统',
|
1 => '系统',
|
||||||
2 => '用户',
|
2 => '用户',
|
||||||
@@ -91,7 +100,7 @@ function get_action_type($type, $all = false){
|
|||||||
* @param string $field 需要获取的字段
|
* @param string $field 需要获取的字段
|
||||||
* @author huajie <banhuajie@163.com>
|
* @author huajie <banhuajie@163.com>
|
||||||
*/
|
*/
|
||||||
function get_action($id = null, $field = null){
|
function getAction($id = null, $field = null) {
|
||||||
if (empty($id) && !is_numeric($id)) {
|
if (empty($id) && !is_numeric($id)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -110,7 +119,7 @@ function get_action($id = null, $field = null){
|
|||||||
* @param string $field 需要返回的字段,不传则返回整个数据
|
* @param string $field 需要返回的字段,不传则返回整个数据
|
||||||
* @author huajie <banhuajie@163.com>
|
* @author huajie <banhuajie@163.com>
|
||||||
*/
|
*/
|
||||||
function get_document_field($value = null, $condition = 'id', $field = null){
|
function getDocumentField($value = null, $condition = 'id', $field = null) {
|
||||||
if (empty($value)) {
|
if (empty($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class Addons extends Admin {
|
|||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'list' => $list,
|
'list' => $list,
|
||||||
'page' => $list->render()
|
'page' => $list->render(),
|
||||||
);
|
);
|
||||||
$this->setMeta("插件管理");
|
$this->setMeta("插件管理");
|
||||||
$this->assign($data);
|
$this->assign($data);
|
||||||
@@ -163,7 +163,7 @@ class Addons extends Admin {
|
|||||||
|
|
||||||
$keyList = array();
|
$keyList = array();
|
||||||
$data = array(
|
$data = array(
|
||||||
'keyList' => $keyList
|
'keyList' => $keyList,
|
||||||
);
|
);
|
||||||
$this->assign($data);
|
$this->assign($data);
|
||||||
$this->setMeta($info['title'] . " - 设置");
|
$this->setMeta($info['title'] . " - 设置");
|
||||||
@@ -223,7 +223,7 @@ class Addons extends Admin {
|
|||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'list' => $list,
|
'list' => $list,
|
||||||
'page' => $list->render()
|
'page' => $list->render(),
|
||||||
);
|
);
|
||||||
$this->setMeta("钩子管理");
|
$this->setMeta("钩子管理");
|
||||||
$this->assign($data);
|
$this->assign($data);
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
|
|||||||
* @return string
|
* @return string
|
||||||
+----------------------------------------------------------
|
+----------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
function rand_string($len=6,$type='',$addChars='') {
|
function randString($len = 6, $type = '', $addChars = '') {
|
||||||
$str = '';
|
$str = '';
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -98,7 +98,8 @@ function rand_string($len=6,$type='',$addChars='') {
|
|||||||
$chars = 'ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789' . $addChars;
|
$chars = 'ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789' . $addChars;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if($len>10 ) {//位数过长重复字符串一定次数
|
if ($len > 10) {
|
||||||
|
//位数过长重复字符串一定次数
|
||||||
$chars = $type == 1 ? str_repeat($chars, $len) : str_repeat($chars, 5);
|
$chars = $type == 1 ? str_repeat($chars, $len) : str_repeat($chars, 5);
|
||||||
}
|
}
|
||||||
if ($type != 4) {
|
if ($type != 4) {
|
||||||
@@ -171,7 +172,7 @@ function ad($name, $param = array()){
|
|||||||
* 获取插件类的类名
|
* 获取插件类的类名
|
||||||
* @param strng $name 插件名
|
* @param strng $name 插件名
|
||||||
*/
|
*/
|
||||||
function get_addon_class($name){
|
function getAddonClass($name) {
|
||||||
$class = "\\addons\\" . strtolower($name) . "\\{$name}";
|
$class = "\\addons\\" . strtolower($name) . "\\{$name}";
|
||||||
return $class;
|
return $class;
|
||||||
}
|
}
|
||||||
@@ -180,8 +181,8 @@ function get_addon_class($name){
|
|||||||
* 获取插件类的配置文件数组
|
* 获取插件类的配置文件数组
|
||||||
* @param string $name 插件名
|
* @param string $name 插件名
|
||||||
*/
|
*/
|
||||||
function get_addon_config($name){
|
function getAddonConfig($name) {
|
||||||
$class = get_addon_class($name);
|
$class = getAddonClass($name);
|
||||||
if (class_exists($class)) {
|
if (class_exists($class)) {
|
||||||
$addon = new $class();
|
$addon = new $class();
|
||||||
return $addon->getConfig();
|
return $addon->getConfig();
|
||||||
@@ -196,11 +197,11 @@ function get_addon_config($name){
|
|||||||
* @param array $param 参数
|
* @param array $param 参数
|
||||||
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
||||||
*/
|
*/
|
||||||
function addons_url($url, $param = array()){
|
function addonsUrl($url, $param = array()) {
|
||||||
$url = parse_url($url);
|
$url = parse_url($url);
|
||||||
$case = config('URL_CASE_INSENSITIVE');
|
$case = config('URL_CASE_INSENSITIVE');
|
||||||
$addons = $case ? parse_name($url['scheme']) : $url['scheme'];
|
$addons = $case ? parseName($url['scheme']) : $url['scheme'];
|
||||||
$controller = $case ? parse_name($url['host']) : $url['host'];
|
$controller = $case ? parseName($url['host']) : $url['host'];
|
||||||
$action = trim($case ? strtolower($url['path']) : $url['path'], '/');
|
$action = trim($case ? strtolower($url['path']) : $url['path'], '/');
|
||||||
|
|
||||||
/* 解析URL带的参数 */
|
/* 解析URL带的参数 */
|
||||||
@@ -226,7 +227,7 @@ function addons_url($url, $param = array()){
|
|||||||
* @return string 解析或的url
|
* @return string 解析或的url
|
||||||
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
||||||
*/
|
*/
|
||||||
function get_nav_url($url){
|
function getNavUrl($url) {
|
||||||
switch ($url) {
|
switch ($url) {
|
||||||
case 'http://' === substr($url, 0, 7):
|
case 'http://' === substr($url, 0, 7):
|
||||||
case '#' === substr($url, 0, 1):
|
case '#' === substr($url, 0, 1):
|
||||||
@@ -238,7 +239,6 @@ function get_nav_url($url){
|
|||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文档封面图片
|
* 获取文档封面图片
|
||||||
* @param int $cover_id
|
* @param int $cover_id
|
||||||
@@ -246,7 +246,7 @@ function get_nav_url($url){
|
|||||||
* @return 完整的数据 或者 指定的$field字段值
|
* @return 完整的数据 或者 指定的$field字段值
|
||||||
* @author huajie <banhuajie@163.com>
|
* @author huajie <banhuajie@163.com>
|
||||||
*/
|
*/
|
||||||
function get_cover($cover_id, $field = null){
|
function getCover($cover_id, $field = null) {
|
||||||
if (empty($cover_id)) {
|
if (empty($cover_id)) {
|
||||||
return BASE_PATH . '/public/images/default.png';
|
return BASE_PATH . '/public/images/default.png';
|
||||||
}
|
}
|
||||||
@@ -267,13 +267,13 @@ function get_cover($cover_id, $field = null){
|
|||||||
* @return 返回图片列表
|
* @return 返回图片列表
|
||||||
* @author molong <molong@tensent.cn>
|
* @author molong <molong@tensent.cn>
|
||||||
*/
|
*/
|
||||||
function get_cover_list($covers){
|
function getCoverList($covers) {
|
||||||
if ($covers == '') {
|
if ($covers == '') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$cover_list = explode(',', $covers);
|
$cover_list = explode(',', $covers);
|
||||||
foreach ($cover_list as $item) {
|
foreach ($cover_list as $item) {
|
||||||
$list[] = get_cover($item, 'path');
|
$list[] = getCover($item, 'path');
|
||||||
}
|
}
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
@@ -285,7 +285,7 @@ function get_cover_list($covers){
|
|||||||
* @param integer $type 转换类型
|
* @param integer $type 转换类型
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function parse_name($name, $type=0) {
|
function parseName($name, $type = 0) {
|
||||||
if ($type) {
|
if ($type) {
|
||||||
return ucfirst(preg_replace_callback('/_([a-zA-Z])/', function ($match) {return strtoupper($match[1]);}, $name));
|
return ucfirst(preg_replace_callback('/_([a-zA-Z])/', function ($match) {return strtoupper($match[1]);}, $name));
|
||||||
} else {
|
} else {
|
||||||
@@ -294,7 +294,7 @@ function parse_name($name, $type=0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 不区分大小写的in_array实现
|
// 不区分大小写的in_array实现
|
||||||
function in_array_case($value,$array){
|
function inArrayCase($value, $array) {
|
||||||
return in_array(strtolower($value), array_map('strtolower', $array));
|
return in_array(strtolower($value), array_map('strtolower', $array));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,7 +304,7 @@ function in_array_case($value,$array){
|
|||||||
* @return string 签名
|
* @return string 签名
|
||||||
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
||||||
*/
|
*/
|
||||||
function data_auth_sign($data) {
|
function dataAuthSign($data) {
|
||||||
//数据类型检测
|
//数据类型检测
|
||||||
if (!is_array($data)) {
|
if (!is_array($data)) {
|
||||||
$data = (array) $data;
|
$data = (array) $data;
|
||||||
@@ -320,12 +320,12 @@ function data_auth_sign($data) {
|
|||||||
* @return integer 0-未登录,大于0-当前登录用户ID
|
* @return integer 0-未登录,大于0-当前登录用户ID
|
||||||
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
||||||
*/
|
*/
|
||||||
function is_login(){
|
function isLogin() {
|
||||||
$user = session('user_auth');
|
$user = session('user_auth');
|
||||||
if (empty($user)) {
|
if (empty($user)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return session('user_auth_sign') == data_auth_sign($user) ? $user['uid'] : 0;
|
return session('user_auth_sign') == dataAuthSign($user) ? $user['uid'] : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,8 +334,8 @@ function is_login(){
|
|||||||
* @return boolean true-管理员,false-非管理员
|
* @return boolean true-管理员,false-非管理员
|
||||||
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
||||||
*/
|
*/
|
||||||
function is_administrator($uid = null){
|
function isAdministrator($uid = null) {
|
||||||
$uid = is_null($uid) ? is_login() : $uid;
|
$uid = is_null($uid) ? isLogin() : $uid;
|
||||||
return $uid && (intval($uid) === config('user_administrator'));
|
return $uid && (intval($uid) === config('user_administrator'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,15 +345,21 @@ function is_administrator($uid = null){
|
|||||||
* @param boolean $adv 是否进行高级模式获取(有可能被伪装)
|
* @param boolean $adv 是否进行高级模式获取(有可能被伪装)
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function get_client_ip($type = 0,$adv=false) {
|
function getClientIp($type = 0, $adv = false) {
|
||||||
$type = $type ? 1 : 0;
|
$type = $type ? 1 : 0;
|
||||||
static $ip = NULL;
|
static $ip = NULL;
|
||||||
if ($ip !== NULL) return $ip[$type];
|
if ($ip !== NULL) {
|
||||||
|
return $ip[$type];
|
||||||
|
}
|
||||||
|
|
||||||
if ($adv) {
|
if ($adv) {
|
||||||
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||||
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
|
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
|
||||||
$pos = array_search('unknown', $arr);
|
$pos = array_search('unknown', $arr);
|
||||||
if(false !== $pos) unset($arr[$pos]);
|
if (false !== $pos) {
|
||||||
|
unset($arr[$pos]);
|
||||||
|
}
|
||||||
|
|
||||||
$ip = trim($arr[0]);
|
$ip = trim($arr[0]);
|
||||||
} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
|
} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
|
||||||
$ip = $_SERVER['HTTP_CLIENT_IP'];
|
$ip = $_SERVER['HTTP_CLIENT_IP'];
|
||||||
@@ -375,7 +381,7 @@ function get_client_ip($type = 0,$adv=false) {
|
|||||||
* @return string 完整的时间显示
|
* @return string 完整的时间显示
|
||||||
* @author huajie <banhuajie@163.com>
|
* @author huajie <banhuajie@163.com>
|
||||||
*/
|
*/
|
||||||
function time_format($time = NULL,$format='Y-m-d H:i'){
|
function timeFormat($time = NULL, $format = 'Y-m-d H:i') {
|
||||||
$time = $time === NULL ? time() : intval($time);
|
$time = $time === NULL ? time() : intval($time);
|
||||||
return date($format, $time);
|
return date($format, $time);
|
||||||
}
|
}
|
||||||
@@ -385,24 +391,25 @@ function time_format($time = NULL,$format='Y-m-d H:i'){
|
|||||||
* @param integer $uid 用户ID
|
* @param integer $uid 用户ID
|
||||||
* @return string 用户名
|
* @return string 用户名
|
||||||
*/
|
*/
|
||||||
function get_username($uid = 0){
|
function getUsername($uid = 0) {
|
||||||
static $list;
|
static $list;
|
||||||
if(!($uid && is_numeric($uid))){ //获取当前登录用户名
|
if (!($uid && is_numeric($uid))) {
|
||||||
|
//获取当前登录用户名
|
||||||
return session('user_auth.username');
|
return session('user_auth.username');
|
||||||
}
|
}
|
||||||
$name = db('member')->where(array('uid' => $uid))->value('username');
|
$name = db('member')->where(array('uid' => $uid))->value('username');
|
||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户ID获取用户昵称
|
* 根据用户ID获取用户昵称
|
||||||
* @param integer $uid 用户ID
|
* @param integer $uid 用户ID
|
||||||
* @return string 用户昵称
|
* @return string 用户昵称
|
||||||
*/
|
*/
|
||||||
function get_nickname($uid = 0){
|
function getNickname($uid = 0) {
|
||||||
static $list;
|
static $list;
|
||||||
if(!($uid && is_numeric($uid))){ //获取当前登录用户名
|
if (!($uid && is_numeric($uid))) {
|
||||||
|
//获取当前登录用户名
|
||||||
return session('user_auth.username');
|
return session('user_auth.username');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,9 +420,11 @@ function get_nickname($uid = 0){
|
|||||||
|
|
||||||
/* 查找用户信息 */
|
/* 查找用户信息 */
|
||||||
$key = "u{$uid}";
|
$key = "u{$uid}";
|
||||||
if(isset($list[$key])){ //已缓存,直接使用
|
if (isset($list[$key])) {
|
||||||
|
//已缓存,直接使用
|
||||||
$name = $list[$key];
|
$name = $list[$key];
|
||||||
} else { //调用接口获取用户信息
|
} else {
|
||||||
|
//调用接口获取用户信息
|
||||||
$info = db('Member')->field('nickname')->find($uid);
|
$info = db('Member')->field('nickname')->find($uid);
|
||||||
if ($info !== false && $info['nickname']) {
|
if ($info !== false && $info['nickname']) {
|
||||||
$nickname = $info['nickname'];
|
$nickname = $info['nickname'];
|
||||||
@@ -443,11 +452,13 @@ function get_nickname($uid = 0){
|
|||||||
* asc正向排序 desc逆向排序 nat自然排序
|
* asc正向排序 desc逆向排序 nat自然排序
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function list_sort_by($list,$field, $sortby='asc') {
|
function listSortBy($list, $field, $sortby = 'asc') {
|
||||||
if (is_array($list)) {
|
if (is_array($list)) {
|
||||||
$refer = $resultSet = array();
|
$refer = $resultSet = array();
|
||||||
foreach ($list as $i => $data)
|
foreach ($list as $i => $data) {
|
||||||
$refer[$i] = &$data[$field];
|
$refer[$i] = &$data[$field];
|
||||||
|
}
|
||||||
|
|
||||||
switch ($sortby) {
|
switch ($sortby) {
|
||||||
case 'asc': // 正向排序
|
case 'asc': // 正向排序
|
||||||
asort($refer);
|
asort($refer);
|
||||||
@@ -459,8 +470,10 @@ function list_sort_by($list,$field, $sortby='asc') {
|
|||||||
natcasesort($refer);
|
natcasesort($refer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
foreach ( $refer as $key=> $val)
|
foreach ($refer as $key => $val) {
|
||||||
$resultSet[] = &$list[$key];
|
$resultSet[] = &$list[$key];
|
||||||
|
}
|
||||||
|
|
||||||
return $resultSet;
|
return $resultSet;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -474,7 +487,7 @@ function list_sort_by($list,$field, $sortby='asc') {
|
|||||||
* @return array
|
* @return array
|
||||||
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
||||||
*/
|
*/
|
||||||
function list_to_tree($list, $pk='id', $pid = 'pid', $child = '_child', $root = 0) {
|
function listToTree($list, $pk = 'id', $pid = 'pid', $child = '_child', $root = 0) {
|
||||||
// 创建Tree
|
// 创建Tree
|
||||||
$tree = array();
|
$tree = array();
|
||||||
if (is_array($list) && !is_object($list)) {
|
if (is_array($list) && !is_object($list)) {
|
||||||
@@ -509,17 +522,17 @@ function list_to_tree($list, $pk='id', $pid = 'pid', $child = '_child', $root =
|
|||||||
* @return array 返回排过序的列表数组
|
* @return array 返回排过序的列表数组
|
||||||
* @author yangweijie <yangweijiester@gmail.com>
|
* @author yangweijie <yangweijiester@gmail.com>
|
||||||
*/
|
*/
|
||||||
function tree_to_list($tree, $child = '_child', $order='id', &$list = array()){
|
function treeToList($tree, $child = '_child', $order = 'id', &$list = array()) {
|
||||||
if (is_array($tree)) {
|
if (is_array($tree)) {
|
||||||
foreach ($tree as $key => $value) {
|
foreach ($tree as $key => $value) {
|
||||||
$reffer = $value;
|
$reffer = $value;
|
||||||
if (isset($reffer[$child])) {
|
if (isset($reffer[$child])) {
|
||||||
unset($reffer[$child]);
|
unset($reffer[$child]);
|
||||||
tree_to_list($value[$child], $child, $order, $list);
|
treeToList($value[$child], $child, $order, $list);
|
||||||
}
|
}
|
||||||
$list[] = $reffer;
|
$list[] = $reffer;
|
||||||
}
|
}
|
||||||
$list = list_sort_by($list, $order, $sortby='asc');
|
$list = listSortBy($list, $order, $sortby = 'asc');
|
||||||
}
|
}
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
@@ -527,7 +540,7 @@ function tree_to_list($tree, $child = '_child', $order='id', &$list = array()){
|
|||||||
// 分析枚举类型字段值 格式 a:名称1,b:名称2
|
// 分析枚举类型字段值 格式 a:名称1,b:名称2
|
||||||
// 暂时和 parse_config_attr功能相同
|
// 暂时和 parse_config_attr功能相同
|
||||||
// 但请不要互相使用,后期会调整
|
// 但请不要互相使用,后期会调整
|
||||||
function parse_field_attr($string) {
|
function parseFieldAttr($string) {
|
||||||
if (0 === strpos($string, ':')) {
|
if (0 === strpos($string, ':')) {
|
||||||
// 采用函数定义
|
// 采用函数定义
|
||||||
return eval('return ' . substr($string, 1) . ';');
|
return eval('return ' . substr($string, 1) . ';');
|
||||||
@@ -549,7 +562,7 @@ function parse_field_attr($string) {
|
|||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse_field_bind($table,$selected = '',$model = 0) {
|
function parseFieldBind($table, $selected = '', $model = 0) {
|
||||||
if ($table) {
|
if ($table) {
|
||||||
$select = db($table);
|
$select = db($table);
|
||||||
$res = $select->select();
|
$res = $select->select();
|
||||||
@@ -574,7 +587,7 @@ function parse_field_bind($table,$selected = '',$model = 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 分析枚举类型配置值 格式 a:名称1,b:名称2
|
// 分析枚举类型配置值 格式 a:名称1,b:名称2
|
||||||
function parse_config_attr($string) {
|
function parseConfigAttr($string) {
|
||||||
$array = preg_split('/[,;\r\n]+/', trim($string, ",;\r\n"));
|
$array = preg_split('/[,;\r\n]+/', trim($string, ",;\r\n"));
|
||||||
if (strpos($string, ':')) {
|
if (strpos($string, ':')) {
|
||||||
$value = array();
|
$value = array();
|
||||||
@@ -597,14 +610,14 @@ function parse_config_attr($string) {
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
* @author huajie <banhuajie@163.com>
|
* @author huajie <banhuajie@163.com>
|
||||||
*/
|
*/
|
||||||
function action_log($action = null, $model = null, $record_id = null, $user_id = null){
|
function actionLog($action = null, $model = null, $record_id = null, $user_id = null) {
|
||||||
|
|
||||||
//参数检查
|
//参数检查
|
||||||
if (empty($action) || empty($model) || empty($record_id)) {
|
if (empty($action) || empty($model) || empty($record_id)) {
|
||||||
return '参数不能为空';
|
return '参数不能为空';
|
||||||
}
|
}
|
||||||
if (empty($user_id)) {
|
if (empty($user_id)) {
|
||||||
$user_id = is_login();
|
$user_id = isLogin();
|
||||||
}
|
}
|
||||||
|
|
||||||
//查询行为,判断是否执行
|
//查询行为,判断是否执行
|
||||||
@@ -616,7 +629,7 @@ function action_log($action = null, $model = null, $record_id = null, $user_id =
|
|||||||
//插入行为日志
|
//插入行为日志
|
||||||
$data['action_id'] = $action_info['id'];
|
$data['action_id'] = $action_info['id'];
|
||||||
$data['user_id'] = $user_id;
|
$data['user_id'] = $user_id;
|
||||||
$data['action_ip'] = ip2long(get_client_ip());
|
$data['action_ip'] = ip2long(getClientIp());
|
||||||
$data['model'] = $model;
|
$data['model'] = $model;
|
||||||
$data['record_id'] = $record_id;
|
$data['record_id'] = $record_id;
|
||||||
$data['create_time'] = time();
|
$data['create_time'] = time();
|
||||||
@@ -650,10 +663,10 @@ function action_log($action = null, $model = null, $record_id = null, $user_id =
|
|||||||
|
|
||||||
if (!empty($action_info['rule'])) {
|
if (!empty($action_info['rule'])) {
|
||||||
//解析行为
|
//解析行为
|
||||||
$rules = parse_action($action, $user_id);
|
$rules = parseAction($action, $user_id);
|
||||||
|
|
||||||
//执行行为
|
//执行行为
|
||||||
$res = execute_action($rules, $action_info['id'], $user_id);
|
$res = executeAction($rules, $action_info['id'], $user_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -672,7 +685,7 @@ function action_log($action = null, $model = null, $record_id = null, $user_id =
|
|||||||
* @return boolean|array: false解析出错 , 成功返回规则数组
|
* @return boolean|array: false解析出错 , 成功返回规则数组
|
||||||
* @author huajie <banhuajie@163.com>
|
* @author huajie <banhuajie@163.com>
|
||||||
*/
|
*/
|
||||||
function parse_action($action = null, $self){
|
function parseAction($action = null, $self) {
|
||||||
if (empty($action)) {
|
if (empty($action)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -720,7 +733,7 @@ function parse_action($action = null, $self){
|
|||||||
* @return boolean false 失败 , true 成功
|
* @return boolean false 失败 , true 成功
|
||||||
* @author huajie <banhuajie@163.com>
|
* @author huajie <banhuajie@163.com>
|
||||||
*/
|
*/
|
||||||
function execute_action($rules = false, $action_id = null, $user_id = null){
|
function executeAction($rules = false, $action_id = null, $user_id = null) {
|
||||||
if (!$rules || empty($action_id) || empty($user_id)) {
|
if (!$rules || empty($action_id) || empty($user_id)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -737,9 +750,8 @@ function execute_action($rules = false, $action_id = null, $user_id = null){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//执行数据库操作
|
//执行数据库操作
|
||||||
$Model = db(ucfirst($rule['table']));
|
|
||||||
$field = $rule['field'];
|
$field = $rule['field'];
|
||||||
$res = $Model->where($rule['condition'])->setField($field, array('exp', $rule['rule']));
|
$res = db(ucfirst($rule['table']))->where($rule['condition'])->setField($field, array('exp', $rule['rule']));
|
||||||
|
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
$return = false;
|
$return = false;
|
||||||
@@ -748,7 +760,6 @@ function execute_action($rules = false, $action_id = null, $user_id = null){
|
|||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function avatar($uid, $size = 'middle') {
|
function avatar($uid, $size = 'middle') {
|
||||||
$size = in_array($size, array('big', 'middle', 'small', 'real')) ? $size : 'middle';
|
$size = in_array($size, array('big', 'middle', 'small', 'real')) ? $size : 'middle';
|
||||||
$dir = setavatardir($uid);
|
$dir = setavatardir($uid);
|
||||||
@@ -768,14 +779,20 @@ function setavatardir($uid){
|
|||||||
$dir4 = substr($uid, 7, 2);
|
$dir4 = substr($uid, 7, 2);
|
||||||
$dir = $dir1 . '/' . $dir2 . '/' . $dir3 . '/' . $dir4 . '/';
|
$dir = $dir1 . '/' . $dir2 . '/' . $dir3 . '/' . $dir4 . '/';
|
||||||
if (!is_dir("./uploads/avatar/$dir")) {
|
if (!is_dir("./uploads/avatar/$dir")) {
|
||||||
mk_dir("./uploads/avatar/".$dir);
|
mkDir("./uploads/avatar/" . $dir);
|
||||||
}
|
}
|
||||||
return $dir;
|
return $dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
function mk_dir($dir, $mode = 0755){
|
function mkDir($dir, $mode = 0755) {
|
||||||
if (is_dir($dir) || @mkdir($dir,$mode,true)) return true;
|
if (is_dir($dir) || @mkdir($dir, $mode, true)) {
|
||||||
if (!mk_dir(dirname($dir),$mode,true)) return false;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mkDir(dirname($dir), $mode, true)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return @mkdir($dir, $mode, true);
|
return @mkdir($dir, $mode, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -816,13 +833,16 @@ function arr2str($arr = array(), $glue = ','){
|
|||||||
* @return string 格式化后的带单位的大小
|
* @return string 格式化后的带单位的大小
|
||||||
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
||||||
*/
|
*/
|
||||||
function format_bytes($size, $delimiter = '') {
|
function formatBytes($size, $delimiter = '') {
|
||||||
$units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
|
$units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
|
||||||
for ($i = 0; $size >= 1024 && $i < 5; $i++) $size /= 1024;
|
for ($i = 0; $size >= 1024 && $i < 5; $i++) {
|
||||||
|
$size /= 1024;
|
||||||
|
}
|
||||||
|
|
||||||
return round($size, 2) . $delimiter . $units[$i];
|
return round($size, 2) . $delimiter . $units[$i];
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_grid_list($list_grids){
|
function getGridList($list_grids) {
|
||||||
$grids = preg_split('/[;\r\n]+/s', trim($list_grids));
|
$grids = preg_split('/[;\r\n]+/s', trim($list_grids));
|
||||||
foreach ($grids as &$value) {
|
foreach ($grids as &$value) {
|
||||||
// 字段:标题:链接
|
// 字段:标题:链接
|
||||||
@@ -849,8 +869,10 @@ function get_grid_list($list_grids){
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取属性类型信息
|
/**
|
||||||
function get_attribute_type($type = ''){
|
* 获取字段类型
|
||||||
|
*/
|
||||||
|
function getAttributeType($type = '') {
|
||||||
// TODO 可以加入系统配置
|
// TODO 可以加入系统配置
|
||||||
$type_array = config('config_type_list');
|
$type_array = config('config_type_list');
|
||||||
static $type_list = array();
|
static $type_list = array();
|
||||||
@@ -860,14 +882,13 @@ function get_attribute_type($type = ''){
|
|||||||
return $type ? $type_list[$type][0] : $type_list;
|
return $type ? $type_list[$type][0] : $type_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文档模型信息
|
* 获取文档模型信息
|
||||||
* @param integer $id 模型ID
|
* @param integer $id 模型ID
|
||||||
* @param string $field 模型字段
|
* @param string $field 模型字段
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function get_document_model($id = null, $field = null){
|
function getDocumentModel($id = null, $field = null) {
|
||||||
static $list;
|
static $list;
|
||||||
|
|
||||||
/* 非法分类ID */
|
/* 非法分类ID */
|
||||||
@@ -900,24 +921,23 @@ function get_document_model($id = null, $field = null){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_content_status($status){
|
function getContentStatus($status) {
|
||||||
$text = array(
|
$text = array(
|
||||||
'-1' => '<span class="label label-danger">删除</span>',
|
'-1' => '<span class="label label-danger">删除</span>',
|
||||||
'0' => '<span class="label label-default">禁用</span>',
|
'0' => '<span class="label label-default">禁用</span>',
|
||||||
'1' => '<span class="label label-primary">正常</span>',
|
'1' => '<span class="label label-primary">正常</span>',
|
||||||
'2' => '<span class="label label-info">待审核</span>'
|
'2' => '<span class="label label-info">待审核</span>',
|
||||||
);
|
);
|
||||||
return $text[$status];
|
return $text[$status];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取分类信息并缓存分类
|
* 获取分类信息并缓存分类
|
||||||
* @param integer $id 分类ID
|
* @param integer $id 分类ID
|
||||||
* @param string $field 要获取的字段名
|
* @param string $field 要获取的字段名
|
||||||
* @return string 分类信息
|
* @return string 分类信息
|
||||||
*/
|
*/
|
||||||
function get_category($id, $field = null){
|
function getCategory($id, $field = null) {
|
||||||
/* 非法分类ID */
|
/* 非法分类ID */
|
||||||
if (empty($id) || !is_numeric($id)) {
|
if (empty($id) || !is_numeric($id)) {
|
||||||
return '';
|
return '';
|
||||||
@@ -928,17 +948,17 @@ function get_category($id, $field = null){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 根据ID获取分类标识 */
|
/* 根据ID获取分类标识 */
|
||||||
function get_category_name($id){
|
function getCategoryName($id) {
|
||||||
return get_category($id, 'title');
|
return getCategory($id, 'title');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 根据ID获取分类名称 */
|
/* 根据ID获取分类名称 */
|
||||||
function get_category_title($id){
|
function getCategoryTitle($id) {
|
||||||
return get_category($id, 'title');
|
return getCategory($id, 'title');
|
||||||
}
|
}
|
||||||
|
|
||||||
//分类分组
|
//分类分组
|
||||||
function get_category_list_tree($model){
|
function getCategoryListTree($model) {
|
||||||
$list = cache('sys_category_list');
|
$list = cache('sys_category_list');
|
||||||
|
|
||||||
/* 读取缓存数据 */
|
/* 读取缓存数据 */
|
||||||
@@ -957,7 +977,7 @@ function get_category_list_tree($model){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$res = list_unique($res);
|
$res = list_unique($res);
|
||||||
$tree = list_to_tree($res);
|
$tree = listToTree($res);
|
||||||
if ($limit) {
|
if ($limit) {
|
||||||
$tree = array_slice($tree, 0, $limit);
|
$tree = array_slice($tree, 0, $limit);
|
||||||
}
|
}
|
||||||
@@ -965,7 +985,7 @@ function get_category_list_tree($model){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//获取栏目子ID
|
//获取栏目子ID
|
||||||
function get_category_child($id){
|
function getCategoryChild($id) {
|
||||||
$list = cache('sys_category_list');
|
$list = cache('sys_category_list');
|
||||||
|
|
||||||
/* 读取缓存数据 */
|
/* 读取缓存数据 */
|
||||||
@@ -977,18 +997,18 @@ function get_category_child($id){
|
|||||||
foreach ($list as $key => $value) {
|
foreach ($list as $key => $value) {
|
||||||
if ($value['pid'] == $id) {
|
if ($value['pid'] == $id) {
|
||||||
$ids[] = $value['id'];
|
$ids[] = $value['id'];
|
||||||
$ids = array_merge($ids,get_category_child($value['id']));
|
$ids = array_merge($ids, getCategoryChild($value['id']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return array_unique($ids);
|
return array_unique($ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
function send_email($to, $subject, $message){
|
function sendEmail($to, $subject, $message) {
|
||||||
$config = array(
|
$config = array(
|
||||||
'protocol' => 'smtp',
|
'protocol' => 'smtp',
|
||||||
'smtp_host' => \think\Config::get('mail_host'),
|
'smtp_host' => \think\Config::get('mail_host'),
|
||||||
'smtp_user' => \think\Config::get('mail_username'),
|
'smtp_user' => \think\Config::get('mail_username'),
|
||||||
'smtp_pass' => \think\Config::get('mail_password')
|
'smtp_pass' => \think\Config::get('mail_password'),
|
||||||
);
|
);
|
||||||
$email = new \com\Email($config);
|
$email = new \com\Email($config);
|
||||||
$email->from(\think\Config::get('mail_fromname'), \think\Config::get('web_site_title'));
|
$email->from(\think\Config::get('mail_fromname'), \think\Config::get('web_site_title'));
|
||||||
@@ -1003,41 +1023,113 @@ function send_email($to, $subject, $message){
|
|||||||
//php获取中文字符拼音首字母
|
//php获取中文字符拼音首字母
|
||||||
function getFirstCharter($s0) {
|
function getFirstCharter($s0) {
|
||||||
$fchar = ord($s0{0});
|
$fchar = ord($s0{0});
|
||||||
if($fchar >= ord("A") and $fchar <= ord("z") )return strtoupper($s0{0});
|
if ($fchar >= ord("A") and $fchar <= ord("z")) {
|
||||||
$s1 = \iconv("UTF-8","gb2312", $s0);
|
return strtoupper($s0{0});
|
||||||
$s2 = \iconv("gb2312","UTF-8", $s1);
|
}
|
||||||
|
|
||||||
|
$s1 = iconv("UTF-8", "gb2312", $s0);
|
||||||
|
$s2 = iconv("gb2312", "UTF-8", $s1);
|
||||||
if ($s2 == $s0) {$s = $s1;} else { $s = $s0;}
|
if ($s2 == $s0) {$s = $s1;} else { $s = $s0;}
|
||||||
$asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
|
$asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
|
||||||
if($asc >= -20319 and $asc <= -20284) return "A";
|
if ($asc >= -20319 and $asc <= -20284) {
|
||||||
if($asc >= -20283 and $asc <= -19776) return "B";
|
return "A";
|
||||||
if($asc >= -19775 and $asc <= -19219) return "C";
|
}
|
||||||
if($asc >= -19218 and $asc <= -18711) return "D";
|
|
||||||
if($asc >= -18710 and $asc <= -18527) return "E";
|
if ($asc >= -20283 and $asc <= -19776) {
|
||||||
if($asc >= -18526 and $asc <= -18240) return "F";
|
return "B";
|
||||||
if($asc >= -18239 and $asc <= -17923) return "G";
|
}
|
||||||
if($asc >= -17922 and $asc <= -17418) return "H";
|
|
||||||
if($asc >= -17417 and $asc <= -16475) return "J";
|
if ($asc >= -19775 and $asc <= -19219) {
|
||||||
if($asc >= -16474 and $asc <= -16213) return "K";
|
return "C";
|
||||||
if($asc >= -16212 and $asc <= -15641) return "L";
|
}
|
||||||
if($asc >= -15640 and $asc <= -15166) return "M";
|
|
||||||
if($asc >= -15165 and $asc <= -14923) return "N";
|
if ($asc >= -19218 and $asc <= -18711) {
|
||||||
if($asc >= -14922 and $asc <= -14915) return "O";
|
return "D";
|
||||||
if($asc >= -14914 and $asc <= -14631) return "P";
|
}
|
||||||
if($asc >= -14630 and $asc <= -14150) return "Q";
|
|
||||||
if($asc >= -14149 and $asc <= -14091) return "R";
|
if ($asc >= -18710 and $asc <= -18527) {
|
||||||
if($asc >= -14090 and $asc <= -13319) return "S";
|
return "E";
|
||||||
if($asc >= -13318 and $asc <= -12839) return "T";
|
}
|
||||||
if($asc >= -12838 and $asc <= -12557) return "W";
|
|
||||||
if($asc >= -12556 and $asc <= -11848) return "X";
|
if ($asc >= -18526 and $asc <= -18240) {
|
||||||
if($asc >= -11847 and $asc <= -11056) return "Y";
|
return "F";
|
||||||
if($asc >= -11055 and $asc <= -10247) return "Z";
|
}
|
||||||
|
|
||||||
|
if ($asc >= -18239 and $asc <= -17923) {
|
||||||
|
return "G";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($asc >= -17922 and $asc <= -17418) {
|
||||||
|
return "H";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($asc >= -17417 and $asc <= -16475) {
|
||||||
|
return "J";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($asc >= -16474 and $asc <= -16213) {
|
||||||
|
return "K";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($asc >= -16212 and $asc <= -15641) {
|
||||||
|
return "L";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($asc >= -15640 and $asc <= -15166) {
|
||||||
|
return "M";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($asc >= -15165 and $asc <= -14923) {
|
||||||
|
return "N";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($asc >= -14922 and $asc <= -14915) {
|
||||||
|
return "O";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($asc >= -14914 and $asc <= -14631) {
|
||||||
|
return "P";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($asc >= -14630 and $asc <= -14150) {
|
||||||
|
return "Q";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($asc >= -14149 and $asc <= -14091) {
|
||||||
|
return "R";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($asc >= -14090 and $asc <= -13319) {
|
||||||
|
return "S";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($asc >= -13318 and $asc <= -12839) {
|
||||||
|
return "T";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($asc >= -12838 and $asc <= -12557) {
|
||||||
|
return "W";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($asc >= -12556 and $asc <= -11848) {
|
||||||
|
return "X";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($asc >= -11847 and $asc <= -11056) {
|
||||||
|
return "Y";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($asc >= -11055 and $asc <= -10247) {
|
||||||
|
return "Z";
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function PyFirst($zh) {
|
function PyFirst($zh) {
|
||||||
$ret = "";
|
$ret = "";
|
||||||
$s1 = \iconv("UTF-8","gb2312", $zh);
|
$s1 = iconv("UTF-8", "gb2312", $zh);
|
||||||
$s2 = \iconv("gb2312","UTF-8", $s1);
|
$s2 = iconv("gb2312", "UTF-8", $s1);
|
||||||
if ($s2 == $zh) {$zh = $s1;}
|
if ($s2 == $zh) {$zh = $s1;}
|
||||||
for ($i = 0; $i < strlen($zh); $i++) {
|
for ($i = 0; $i < strlen($zh); $i++) {
|
||||||
$s1 = substr($zh, $i, 1);
|
$s1 = substr($zh, $i, 1);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ return array(
|
|||||||
'url_common_param' => false,
|
'url_common_param' => false,
|
||||||
|
|
||||||
'template' => array(
|
'template' => array(
|
||||||
'taglib_build_in' => 'cx,com\Sent'
|
'taglib_build_in' => 'cx,com\Sent',
|
||||||
),
|
),
|
||||||
|
|
||||||
// 'dispatch_success_tmpl' => APP_PATH . 'common/view/default/jump.html',
|
// 'dispatch_success_tmpl' => APP_PATH . 'common/view/default/jump.html',
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class Content extends User{
|
|||||||
$data = array(
|
$data = array(
|
||||||
'grid' => $grid_list,
|
'grid' => $grid_list,
|
||||||
'list' => $list,
|
'list' => $list,
|
||||||
'page' => $list->render()
|
'page' => $list->render(),
|
||||||
);
|
);
|
||||||
$this->assign($data);
|
$this->assign($data);
|
||||||
return $this->fetch();
|
return $this->fetch();
|
||||||
@@ -74,11 +74,11 @@ class Content extends User{
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$info = array(
|
$info = array(
|
||||||
'model_id' => $this->modelInfo['id']
|
'model_id' => $this->modelInfo['id'],
|
||||||
);
|
);
|
||||||
$data = array(
|
$data = array(
|
||||||
'info' => $info,
|
'info' => $info,
|
||||||
'fieldGroup' => $this->getField($this->modelInfo)
|
'fieldGroup' => $this->getField($this->modelInfo),
|
||||||
);
|
);
|
||||||
$this->assign($data);
|
$this->assign($data);
|
||||||
return $this->fetch('public/edit');
|
return $this->fetch('public/edit');
|
||||||
@@ -108,7 +108,7 @@ class Content extends User{
|
|||||||
$info['model_id'] = $this->modelInfo['id'];
|
$info['model_id'] = $this->modelInfo['id'];
|
||||||
$data = array(
|
$data = array(
|
||||||
'info' => $info,
|
'info' => $info,
|
||||||
'fieldGroup' => $this->getField($this->modelInfo)
|
'fieldGroup' => $this->getField($this->modelInfo),
|
||||||
);
|
);
|
||||||
$this->assign($data);
|
$this->assign($data);
|
||||||
return $this->fetch('public/edit');
|
return $this->fetch('public/edit');
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ if (!function_exists('input')) {
|
|||||||
* @param string $filter 过滤方法
|
* @param string $filter 过滤方法
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function input($key, $default = null, $filter = null)
|
function input($key = '', $default = null, $filter = null)
|
||||||
{
|
{
|
||||||
if (0 === strpos($key, '?')) {
|
if (0 === strpos($key, '?')) {
|
||||||
$key = substr($key, 1);
|
$key = substr($key, 1);
|
||||||
@@ -124,7 +124,7 @@ if (!function_exists('input')) {
|
|||||||
if ($pos = strpos($key, '.')) {
|
if ($pos = strpos($key, '.')) {
|
||||||
// 指定参数来源
|
// 指定参数来源
|
||||||
$method = substr($key, 0, $pos);
|
$method = substr($key, 0, $pos);
|
||||||
if (in_array($method, ['get', 'post', 'put', 'delete', 'param', 'request', 'session', 'cookie', 'server', 'env', 'path', 'file'])) {
|
if (in_array($method, ['get', 'post', 'put', 'patch', 'delete', 'param', 'request', 'session', 'cookie', 'server', 'env', 'path', 'file'])) {
|
||||||
$key = substr($key, $pos + 1);
|
$key = substr($key, $pos + 1);
|
||||||
} else {
|
} else {
|
||||||
$method = 'param';
|
$method = 'param';
|
||||||
@@ -191,7 +191,7 @@ if (!function_exists('db')) {
|
|||||||
*/
|
*/
|
||||||
function db($name = '', $config = [])
|
function db($name = '', $config = [])
|
||||||
{
|
{
|
||||||
return Db::connect($config)->name($name);
|
return Db::connect($config, true)->name($name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -421,12 +421,13 @@ if (!function_exists('view')) {
|
|||||||
* 渲染模板输出
|
* 渲染模板输出
|
||||||
* @param string $template 模板文件
|
* @param string $template 模板文件
|
||||||
* @param array $vars 模板变量
|
* @param array $vars 模板变量
|
||||||
|
* @param array $replace 模板替换
|
||||||
* @param integer $code 状态码
|
* @param integer $code 状态码
|
||||||
* @return \think\response\View
|
* @return \think\response\View
|
||||||
*/
|
*/
|
||||||
function view($template = '', $vars = [], $code = 200)
|
function view($template = '', $vars = [], $replace = [], $code = 200)
|
||||||
{
|
{
|
||||||
return Response::create($template, 'view', $code)->vars($vars);
|
return Response::create($template, 'view', $code)->replace($replace)->assign($vars);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -337,9 +337,9 @@ class App
|
|||||||
} catch (\ReflectionException $e) {
|
} catch (\ReflectionException $e) {
|
||||||
// 操作不存在
|
// 操作不存在
|
||||||
if (method_exists($instance, '_empty')) {
|
if (method_exists($instance, '_empty')) {
|
||||||
$method = new \ReflectionMethod($instance, '_empty');
|
$reflect = new \ReflectionMethod($instance, '_empty');
|
||||||
$data = $method->invokeArgs($instance, [$action, '']);
|
$data = $reflect->invokeArgs($instance, [$action]);
|
||||||
self::$debug && Log::record('[ RUN ] ' . $method->__toString(), 'info');
|
self::$debug && Log::record('[ RUN ] ' . $reflect->__toString(), 'info');
|
||||||
} else {
|
} else {
|
||||||
throw new HttpException(404, 'method not exists:' . (new \ReflectionClass($instance))->getName() . '->' . $action);
|
throw new HttpException(404, 'method not exists:' . (new \ReflectionClass($instance))->getName() . '->' . $action);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -195,12 +195,9 @@ class File extends SplFileObject
|
|||||||
{
|
{
|
||||||
$extension = strtolower(pathinfo($this->getInfo('name'), PATHINFO_EXTENSION));
|
$extension = strtolower(pathinfo($this->getInfo('name'), PATHINFO_EXTENSION));
|
||||||
/* 对图像文件进行严格检测 */
|
/* 对图像文件进行严格检测 */
|
||||||
if (in_array($extension, array('gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf'))) {
|
if (in_array($extension, ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf']) && !in_array(exif_imagetype($this->filename), [1, 2, 3, 4, 6])) {
|
||||||
$imginfo = getimagesize($this->filename);
|
|
||||||
if (empty($imginfo) || ('gif' == $extension && empty($imginfo['bits']))) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -756,7 +756,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
$value = null;
|
$value = null;
|
||||||
}
|
}
|
||||||
if (!in_array($field, $this->change)) {
|
if (!in_array($field, $this->change)) {
|
||||||
$this->setAttr($field, isset($this->data[$field]) ? $this->data[$field] : $value);
|
$this->setAttr($field, !is_null($value) ? $value : (isset($this->data[$field]) ? $this->data[$field] : $value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,6 @@ class Request
|
|||||||
protected $request = [];
|
protected $request = [];
|
||||||
protected $route = [];
|
protected $route = [];
|
||||||
protected $put;
|
protected $put;
|
||||||
protected $delete;
|
|
||||||
protected $session = [];
|
protected $session = [];
|
||||||
protected $file = [];
|
protected $file = [];
|
||||||
protected $cookie = [];
|
protected $cookie = [];
|
||||||
@@ -490,6 +489,7 @@ class Request
|
|||||||
} elseif (!$this->method) {
|
} elseif (!$this->method) {
|
||||||
if (isset($_POST[Config::get('var_method')])) {
|
if (isset($_POST[Config::get('var_method')])) {
|
||||||
$this->method = strtoupper($_POST[Config::get('var_method')]);
|
$this->method = strtoupper($_POST[Config::get('var_method')]);
|
||||||
|
$this->{$this->method}($_POST);
|
||||||
} elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
|
} elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
|
||||||
$this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
|
$this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
|
||||||
} else {
|
} else {
|
||||||
@@ -612,10 +612,9 @@ class Request
|
|||||||
$vars = $this->post(false);
|
$vars = $this->post(false);
|
||||||
break;
|
break;
|
||||||
case 'PUT':
|
case 'PUT':
|
||||||
$vars = $this->put(false);
|
|
||||||
break;
|
|
||||||
case 'DELETE':
|
case 'DELETE':
|
||||||
$vars = $this->delete(false);
|
case 'PATCH':
|
||||||
|
$vars = $this->put(false);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$vars = [];
|
$vars = [];
|
||||||
@@ -718,13 +717,20 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function delete($name = '', $default = null, $filter = null)
|
public function delete($name = '', $default = null, $filter = null)
|
||||||
{
|
{
|
||||||
if (is_array($name)) {
|
return $this->put($name, $default, $filter);
|
||||||
return $this->delete = is_null($this->delete) ? $name : array_merge($this->delete, $name);
|
|
||||||
}
|
}
|
||||||
if (is_null($this->delete)) {
|
|
||||||
parse_str(file_get_contents('php://input'), $this->delete);
|
/**
|
||||||
}
|
* 设置获取获取PATCH参数
|
||||||
return $this->input($this->delete, $name, $default, $filter);
|
* @access public
|
||||||
|
* @param string|array $name 变量名
|
||||||
|
* @param mixed $default 默认值
|
||||||
|
* @param string|array $filter 过滤方法
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function patch($name = '', $default = null, $filter = null)
|
||||||
|
{
|
||||||
|
return $this->put($name, $default, $filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class Route
|
|||||||
'POST' => [],
|
'POST' => [],
|
||||||
'PUT' => [],
|
'PUT' => [],
|
||||||
'DELETE' => [],
|
'DELETE' => [],
|
||||||
|
'PATCH' => [],
|
||||||
'HEAD' => [],
|
'HEAD' => [],
|
||||||
'OPTIONS' => [],
|
'OPTIONS' => [],
|
||||||
'*' => [],
|
'*' => [],
|
||||||
@@ -59,7 +60,7 @@ class Route
|
|||||||
// 域名绑定
|
// 域名绑定
|
||||||
private static $bind = [];
|
private static $bind = [];
|
||||||
// 当前分组
|
// 当前分组
|
||||||
private static $group;
|
private static $group = '';
|
||||||
// 当前参数
|
// 当前参数
|
||||||
private static $option = [];
|
private static $option = [];
|
||||||
|
|
||||||
@@ -242,7 +243,7 @@ class Route
|
|||||||
self::$rules[$type][$rule] = ['rule' => $rule, 'route' => $route, 'var' => $vars, 'option' => $option, 'pattern' => $pattern];
|
self::$rules[$type][$rule] = ['rule' => $rule, 'route' => $route, 'var' => $vars, 'option' => $option, 'pattern' => $pattern];
|
||||||
if ('*' == $type) {
|
if ('*' == $type) {
|
||||||
// 注册路由快捷方式
|
// 注册路由快捷方式
|
||||||
foreach (['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'OPTIONS'] as $method) {
|
foreach (['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'] as $method) {
|
||||||
self::$rules[$method][$rule] = true;
|
self::$rules[$method][$rule] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -257,8 +258,12 @@ class Route
|
|||||||
*/
|
*/
|
||||||
public static function setGroup($name)
|
public static function setGroup($name)
|
||||||
{
|
{
|
||||||
|
if (self::$group) {
|
||||||
|
self::$group = self::$group . '/' . ltrim($name, '/');
|
||||||
|
} else {
|
||||||
self::$group = $name;
|
self::$group = $name;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置当前的路由参数
|
* 设置当前的路由参数
|
||||||
@@ -291,9 +296,11 @@ class Route
|
|||||||
if (!empty($name)) {
|
if (!empty($name)) {
|
||||||
// 分组
|
// 分组
|
||||||
if ($routes instanceof \Closure) {
|
if ($routes instanceof \Closure) {
|
||||||
|
$curentGroup = self::$group;
|
||||||
self::setGroup($name);
|
self::setGroup($name);
|
||||||
call_user_func_array($routes, []);
|
call_user_func_array($routes, []);
|
||||||
self::setGroup(null);
|
self::$group = $curentGroup;
|
||||||
|
|
||||||
self::$rules[$type][$name]['route'] = '';
|
self::$rules[$type][$name]['route'] = '';
|
||||||
self::$rules[$type][$name]['var'] = self::parseVar($name);
|
self::$rules[$type][$name]['var'] = self::parseVar($name);
|
||||||
self::$rules[$type][$name]['option'] = $option;
|
self::$rules[$type][$name]['option'] = $option;
|
||||||
@@ -317,7 +324,7 @@ class Route
|
|||||||
self::$rules[$type][$name] = ['rule' => $item, 'route' => '', 'var' => [], 'option' => $option, 'pattern' => $pattern];
|
self::$rules[$type][$name] = ['rule' => $item, 'route' => '', 'var' => [], 'option' => $option, 'pattern' => $pattern];
|
||||||
}
|
}
|
||||||
if ('*' == $type) {
|
if ('*' == $type) {
|
||||||
foreach (['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'OPTIONS'] as $method) {
|
foreach (['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'] as $method) {
|
||||||
if (!isset(self::$rules[$method][$name])) {
|
if (!isset(self::$rules[$method][$name])) {
|
||||||
self::$rules[$method][$name] = true;
|
self::$rules[$method][$name] = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -408,6 +415,20 @@ class Route
|
|||||||
self::rule($rule, $route, 'DELETE', $option, $pattern);
|
self::rule($rule, $route, 'DELETE', $option, $pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册PATCH路由
|
||||||
|
* @access public
|
||||||
|
* @param string $rule 路由规则
|
||||||
|
* @param string $route 路由地址
|
||||||
|
* @param array $option 路由参数
|
||||||
|
* @param array $pattern 变量规则
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function patch($rule, $route = '', $option = [], $pattern = [])
|
||||||
|
{
|
||||||
|
self::rule($rule, $route, 'PATCH', $option, $pattern);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册资源路由
|
* 注册资源路由
|
||||||
* @access public
|
* @access public
|
||||||
|
|||||||
@@ -19,9 +19,6 @@ use think\Route;
|
|||||||
|
|
||||||
class Url
|
class Url
|
||||||
{
|
{
|
||||||
// 生成URL地址的root
|
|
||||||
protected static $root;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL生成 支持路由反射
|
* URL生成 支持路由反射
|
||||||
* @param string $url URL表达式,
|
* @param string $url URL表达式,
|
||||||
@@ -116,7 +113,7 @@ class Url
|
|||||||
// 检测域名
|
// 检测域名
|
||||||
$domain = self::parseDomain($url, $domain);
|
$domain = self::parseDomain($url, $domain);
|
||||||
// URL组装
|
// URL组装
|
||||||
$url = $domain . (self::$root ?: Request::instance()->root()) . '/' . ltrim($url, '/');
|
$url = $domain . Request::instance()->root() . '/' . ltrim($url, '/');
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,11 +316,4 @@ class Url
|
|||||||
{
|
{
|
||||||
Cache::rm('think_route_map');
|
Cache::rm('think_route_map');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 指定当前生成URL地址的root
|
|
||||||
public static function root($root)
|
|
||||||
{
|
|
||||||
self::$root = $root;
|
|
||||||
Request::instance()->root($root);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -68,6 +68,7 @@ class Validate
|
|||||||
'allowIp' => '不允许的IP访问',
|
'allowIp' => '不允许的IP访问',
|
||||||
'denyIp' => '禁止的IP访问',
|
'denyIp' => '禁止的IP访问',
|
||||||
'confirm' => ':attribute和字段 :rule 不一致',
|
'confirm' => ':attribute和字段 :rule 不一致',
|
||||||
|
'different' => ':attribute和字段 :rule 不能相同',
|
||||||
'egt' => ':attribute必须大于等于 :rule',
|
'egt' => ':attribute必须大于等于 :rule',
|
||||||
'gt' => ':attribute必须大于 :rule',
|
'gt' => ':attribute必须大于 :rule',
|
||||||
'elt' => ':attribute必须小于等于 :rule',
|
'elt' => ':attribute必须小于等于 :rule',
|
||||||
@@ -400,6 +401,19 @@ class Validate
|
|||||||
return $this->getDataValue($data, $rule) == $value;
|
return $this->getDataValue($data, $rule) == $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证是否和某个字段的值是否不同
|
||||||
|
* @access protected
|
||||||
|
* @param mixed $value 字段值
|
||||||
|
* @param mixed $rule 验证规则
|
||||||
|
* @param array $data 数据
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function different($value, $rule, $data)
|
||||||
|
{
|
||||||
|
return $this->getDataValue($data, $rule) != $value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证是否大于等于某个值
|
* 验证是否大于等于某个值
|
||||||
* @access protected
|
* @access protected
|
||||||
|
|||||||
@@ -11,8 +11,9 @@
|
|||||||
|
|
||||||
namespace think\controller;
|
namespace think\controller;
|
||||||
|
|
||||||
use think\Response;
|
use think\App;
|
||||||
use think\Request;
|
use think\Request;
|
||||||
|
use think\Response;
|
||||||
|
|
||||||
abstract class Rest
|
abstract class Rest
|
||||||
{
|
{
|
||||||
@@ -61,11 +62,10 @@ abstract class Rest
|
|||||||
* REST 调用
|
* REST 调用
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $method 方法名
|
* @param string $method 方法名
|
||||||
* @param array $args 参数
|
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function _empty($method, $args)
|
public function _empty($method)
|
||||||
{
|
{
|
||||||
if (method_exists($this, $method . '_' . $this->method . '_' . $this->type)) {
|
if (method_exists($this, $method . '_' . $this->method . '_' . $this->type)) {
|
||||||
// RESTFul方法支持
|
// RESTFul方法支持
|
||||||
@@ -76,7 +76,7 @@ abstract class Rest
|
|||||||
$fun = $method . '_' . $this->method;
|
$fun = $method . '_' . $this->method;
|
||||||
}
|
}
|
||||||
if (isset($fun)) {
|
if (isset($fun)) {
|
||||||
return $this->$fun();
|
return App::invokeMethod([$this, $fun]);
|
||||||
} else {
|
} else {
|
||||||
// 抛出异常
|
// 抛出异常
|
||||||
throw new \Exception('error action :' . $method);
|
throw new \Exception('error action :' . $method);
|
||||||
|
|||||||
@@ -1599,13 +1599,15 @@ class Query
|
|||||||
$options = $this->parseExpress();
|
$options = $this->parseExpress();
|
||||||
// 生成SQL语句
|
// 生成SQL语句
|
||||||
$sql = $this->builder()->insert($data, $options, $replace);
|
$sql = $this->builder()->insert($data, $options, $replace);
|
||||||
|
// 获取参数绑定
|
||||||
|
$bind = $this->getBind();
|
||||||
if ($options['fetch_sql']) {
|
if ($options['fetch_sql']) {
|
||||||
// 获取实际执行的SQL语句
|
// 获取实际执行的SQL语句
|
||||||
return $this->connection->getRealSql($sql, $this->bind);
|
return $this->connection->getRealSql($sql, $bind);
|
||||||
}
|
}
|
||||||
$sequence = $sequence ?: (isset($options['sequence']) ? $options['sequence'] : null);
|
$sequence = $sequence ?: (isset($options['sequence']) ? $options['sequence'] : null);
|
||||||
// 执行操作
|
// 执行操作
|
||||||
return $this->execute($sql, $this->getBind(), $getLastInsID, $sequence);
|
return $this->execute($sql, $bind, $getLastInsID, $sequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1636,12 +1638,14 @@ class Query
|
|||||||
}
|
}
|
||||||
// 生成SQL语句
|
// 生成SQL语句
|
||||||
$sql = $this->builder()->insertAll($dataSet, $options);
|
$sql = $this->builder()->insertAll($dataSet, $options);
|
||||||
|
// 获取参数绑定
|
||||||
|
$bind = $this->getBind();
|
||||||
if ($options['fetch_sql']) {
|
if ($options['fetch_sql']) {
|
||||||
// 获取实际执行的SQL语句
|
// 获取实际执行的SQL语句
|
||||||
return $this->connection->getRealSql($sql, $this->bind);
|
return $this->connection->getRealSql($sql, $bind);
|
||||||
} else {
|
} else {
|
||||||
// 执行操作
|
// 执行操作
|
||||||
return $this->execute($sql, $this->getBind());
|
return $this->execute($sql, $bind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1660,12 +1664,14 @@ class Query
|
|||||||
// 生成SQL语句
|
// 生成SQL语句
|
||||||
$table = $this->parseSqlTable($table);
|
$table = $this->parseSqlTable($table);
|
||||||
$sql = $this->builder()->selectInsert($fields, $table, $options);
|
$sql = $this->builder()->selectInsert($fields, $table, $options);
|
||||||
|
// 获取参数绑定
|
||||||
|
$bind = $this->getBind();
|
||||||
if ($options['fetch_sql']) {
|
if ($options['fetch_sql']) {
|
||||||
// 获取实际执行的SQL语句
|
// 获取实际执行的SQL语句
|
||||||
return $this->connection->getRealSql($sql, $this->bind);
|
return $this->connection->getRealSql($sql, $bind);
|
||||||
} else {
|
} else {
|
||||||
// 执行操作
|
// 执行操作
|
||||||
return $this->execute($sql, $this->getBind());
|
return $this->execute($sql, $bind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1708,9 +1714,11 @@ class Query
|
|||||||
}
|
}
|
||||||
// 生成UPDATE SQL语句
|
// 生成UPDATE SQL语句
|
||||||
$sql = $this->builder()->update($data, $options);
|
$sql = $this->builder()->update($data, $options);
|
||||||
|
// 获取参数绑定
|
||||||
|
$bind = $this->getBind();
|
||||||
if ($options['fetch_sql']) {
|
if ($options['fetch_sql']) {
|
||||||
// 获取实际执行的SQL语句
|
// 获取实际执行的SQL语句
|
||||||
return $this->connection->getRealSql($sql, $this->bind);
|
return $this->connection->getRealSql($sql, $bind);
|
||||||
} else {
|
} else {
|
||||||
// 检测缓存
|
// 检测缓存
|
||||||
if (isset($key) && Cache::get($key)) {
|
if (isset($key) && Cache::get($key)) {
|
||||||
@@ -1718,7 +1726,7 @@ class Query
|
|||||||
Cache::rm($key);
|
Cache::rm($key);
|
||||||
}
|
}
|
||||||
// 执行操作
|
// 执行操作
|
||||||
return '' == $sql ? 0 : $this->execute($sql, $this->getBind());
|
return '' == $sql ? 0 : $this->execute($sql, $bind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1760,12 +1768,14 @@ class Query
|
|||||||
if (!$resultSet) {
|
if (!$resultSet) {
|
||||||
// 生成查询SQL
|
// 生成查询SQL
|
||||||
$sql = $this->builder()->select($options);
|
$sql = $this->builder()->select($options);
|
||||||
|
// 获取参数绑定
|
||||||
|
$bind = $this->getBind();
|
||||||
if ($options['fetch_sql']) {
|
if ($options['fetch_sql']) {
|
||||||
// 获取实际执行的SQL语句
|
// 获取实际执行的SQL语句
|
||||||
return $this->connection->getRealSql($sql, $this->bind);
|
return $this->connection->getRealSql($sql, $bind);
|
||||||
}
|
}
|
||||||
// 执行查询操作
|
// 执行查询操作
|
||||||
$resultSet = $this->query($sql, $this->getBind(), $options['master'], $options['fetch_class']);
|
$resultSet = $this->query($sql, $bind, $options['master'], $options['fetch_class']);
|
||||||
|
|
||||||
if ($resultSet instanceof \PDOStatement) {
|
if ($resultSet instanceof \PDOStatement) {
|
||||||
// 返回PDOStatement对象
|
// 返回PDOStatement对象
|
||||||
@@ -1845,12 +1855,14 @@ class Query
|
|||||||
if (!$result) {
|
if (!$result) {
|
||||||
// 生成查询SQL
|
// 生成查询SQL
|
||||||
$sql = $this->builder()->select($options);
|
$sql = $this->builder()->select($options);
|
||||||
|
// 获取参数绑定
|
||||||
|
$bind = $this->getBind();
|
||||||
if ($options['fetch_sql']) {
|
if ($options['fetch_sql']) {
|
||||||
// 获取实际执行的SQL语句
|
// 获取实际执行的SQL语句
|
||||||
return $this->connection->getRealSql($sql, $this->bind);
|
return $this->connection->getRealSql($sql, $bind);
|
||||||
}
|
}
|
||||||
// 执行查询
|
// 执行查询
|
||||||
$result = $this->query($sql, $this->getBind(), $options['master'], $options['fetch_class']);
|
$result = $this->query($sql, $bind, $options['master'], $options['fetch_class']);
|
||||||
|
|
||||||
if ($result instanceof \PDOStatement) {
|
if ($result instanceof \PDOStatement) {
|
||||||
// 返回PDOStatement对象
|
// 返回PDOStatement对象
|
||||||
@@ -2015,10 +2027,11 @@ class Query
|
|||||||
}
|
}
|
||||||
// 生成删除SQL语句
|
// 生成删除SQL语句
|
||||||
$sql = $this->builder()->delete($options);
|
$sql = $this->builder()->delete($options);
|
||||||
|
// 获取参数绑定
|
||||||
|
$bind = $this->getBind();
|
||||||
if ($options['fetch_sql']) {
|
if ($options['fetch_sql']) {
|
||||||
// 获取实际执行的SQL语句
|
// 获取实际执行的SQL语句
|
||||||
return $this->connection->getRealSql($sql, $this->bind);
|
return $this->connection->getRealSql($sql, $bind);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测缓存
|
// 检测缓存
|
||||||
@@ -2027,7 +2040,7 @@ class Query
|
|||||||
Cache::rm($key);
|
Cache::rm($key);
|
||||||
}
|
}
|
||||||
// 执行操作
|
// 执行操作
|
||||||
return $this->execute($sql, $this->getBind());
|
return $this->execute($sql, $bind);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ class Handle
|
|||||||
$status = $e->getStatusCode();
|
$status = $e->getStatusCode();
|
||||||
$template = Config::get('http_exception_template');
|
$template = Config::get('http_exception_template');
|
||||||
if (!App::$debug && !empty($template[$status])) {
|
if (!App::$debug && !empty($template[$status])) {
|
||||||
return Response::create($template[$status], 'view')->vars(['e' => $e]);
|
return Response::create($template[$status], 'view', $status)->assign(['e' => $e]);
|
||||||
} else {
|
} else {
|
||||||
return $this->convertExceptionToResponse($e);
|
return $this->convertExceptionToResponse($e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,18 +36,6 @@ class View extends Response
|
|||||||
->fetch($data, $this->vars, $this->replace);
|
->fetch($data, $this->vars, $this->replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 视图变量赋值
|
|
||||||
* @access public
|
|
||||||
* @param array $vars 模板变量
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function vars($vars = [])
|
|
||||||
{
|
|
||||||
$this->vars = $vars;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取视图变量
|
* 获取视图变量
|
||||||
* @access public
|
* @access public
|
||||||
|
|||||||
Reference in New Issue
Block a user