1、更新内核

2、代码格式化
This commit is contained in:
2016-07-21 14:29:32 +08:00
parent 3cc2c38dc7
commit a72ba86faa
20 changed files with 1214 additions and 1083 deletions

View File

@@ -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) {
return $data;
}
@@ -45,26 +45,35 @@ function int_to_string(&$data,$map=array('status'=>array(1=>'正常',-1=>'删除
* @return string 状态文字 false 未获取到
* @author huajie <banhuajie@163.com>
*/
function get_status_title($status = null){
function getStatusTitle($status = null) {
if (!isset($status)) {
return false;
}
switch ($status) {
case -1 : return '已删除'; break;
case 0 : return '禁用'; break;
case 1 : return '正常'; break;
case 2 : return '待审核'; break;
default : return false; break;
case -1:return '已删除';
break;
case 0:return '禁用';
break;
case 1:return '正常';
break;
case 2:return '待审核';
break;
default:return false;
break;
}
}
// 获取数据的状态操作
function show_status_op($status) {
function showStatusOp($status) {
switch ($status) {
case 0 : return '启用'; break;
case 1 : return '禁用'; break;
case 2 : return '审核'; break;
default : return false; break;
case 0:return '启用';
break;
case 1:return '禁用';
break;
case 2:return '审核';
break;
default:return false;
break;
}
}
@@ -74,7 +83,7 @@ function show_status_op($status) {
* @param bool $all 是否返回全部类型
* @author huajie <banhuajie@163.com>
*/
function get_action_type($type, $all = false){
function getActionType($type, $all = false) {
$list = array(
1 => '系统',
2 => '用户',
@@ -91,7 +100,7 @@ function get_action_type($type, $all = false){
* @param string $field 需要获取的字段
* @author huajie <banhuajie@163.com>
*/
function get_action($id = null, $field = null){
function getAction($id = null, $field = null) {
if (empty($id) && !is_numeric($id)) {
return false;
}
@@ -110,7 +119,7 @@ function get_action($id = null, $field = null){
* @param string $field 需要返回的字段,不传则返回整个数据
* @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)) {
return false;
}

View File

@@ -34,7 +34,7 @@ class Addons extends Admin {
$data = array(
'list' => $list,
'page' => $list->render()
'page' => $list->render(),
);
$this->setMeta("插件管理");
$this->assign($data);
@@ -163,7 +163,7 @@ class Addons extends Admin {
$keyList = array();
$data = array(
'keyList' => $keyList
'keyList' => $keyList,
);
$this->assign($data);
$this->setMeta($info['title'] . " - 设置");
@@ -223,7 +223,7 @@ class Addons extends Admin {
$data = array(
'list' => $list,
'page' => $list->render()
'page' => $list->render(),
);
$this->setMeta("钩子管理");
$this->assign($data);

View File

@@ -75,7 +75,7 @@ function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
* @return string
+----------------------------------------------------------
*/
function rand_string($len=6,$type='',$addChars='') {
function randString($len = 6, $type = '', $addChars = '') {
$str = '';
switch ($type) {
case 0:
@@ -98,7 +98,8 @@ function rand_string($len=6,$type='',$addChars='') {
$chars = 'ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789' . $addChars;
break;
}
if($len>10 ) {//位数过长重复字符串一定次数
if ($len > 10) {
//位数过长重复字符串一定次数
$chars = $type == 1 ? str_repeat($chars, $len) : str_repeat($chars, 5);
}
if ($type != 4) {
@@ -171,7 +172,7 @@ function ad($name, $param = array()){
* 获取插件类的类名
* @param strng $name 插件名
*/
function get_addon_class($name){
function getAddonClass($name) {
$class = "\\addons\\" . strtolower($name) . "\\{$name}";
return $class;
}
@@ -180,8 +181,8 @@ function get_addon_class($name){
* 获取插件类的配置文件数组
* @param string $name 插件名
*/
function get_addon_config($name){
$class = get_addon_class($name);
function getAddonConfig($name) {
$class = getAddonClass($name);
if (class_exists($class)) {
$addon = new $class();
return $addon->getConfig();
@@ -196,11 +197,11 @@ function get_addon_config($name){
* @param array $param 参数
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
function addons_url($url, $param = array()){
function addonsUrl($url, $param = array()) {
$url = parse_url($url);
$case = config('URL_CASE_INSENSITIVE');
$addons = $case ? parse_name($url['scheme']) : $url['scheme'];
$controller = $case ? parse_name($url['host']) : $url['host'];
$addons = $case ? parseName($url['scheme']) : $url['scheme'];
$controller = $case ? parseName($url['host']) : $url['host'];
$action = trim($case ? strtolower($url['path']) : $url['path'], '/');
/* 解析URL带的参数 */
@@ -226,7 +227,7 @@ function addons_url($url, $param = array()){
* @return string 解析或的url
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
function get_nav_url($url){
function getNavUrl($url) {
switch ($url) {
case 'http://' === substr($url, 0, 7):
case '#' === substr($url, 0, 1):
@@ -238,7 +239,6 @@ function get_nav_url($url){
return $url;
}
/**
* 获取文档封面图片
* @param int $cover_id
@@ -246,7 +246,7 @@ function get_nav_url($url){
* @return 完整的数据 或者 指定的$field字段值
* @author huajie <banhuajie@163.com>
*/
function get_cover($cover_id, $field = null){
function getCover($cover_id, $field = null) {
if (empty($cover_id)) {
return BASE_PATH . '/public/images/default.png';
}
@@ -267,13 +267,13 @@ function get_cover($cover_id, $field = null){
* @return 返回图片列表
* @author molong <molong@tensent.cn>
*/
function get_cover_list($covers){
function getCoverList($covers) {
if ($covers == '') {
return false;
}
$cover_list = explode(',', $covers);
foreach ($cover_list as $item) {
$list[] = get_cover($item, 'path');
$list[] = getCover($item, 'path');
}
return $list;
}
@@ -285,7 +285,7 @@ function get_cover_list($covers){
* @param integer $type 转换类型
* @return string
*/
function parse_name($name, $type=0) {
function parseName($name, $type = 0) {
if ($type) {
return ucfirst(preg_replace_callback('/_([a-zA-Z])/', function ($match) {return strtoupper($match[1]);}, $name));
} else {
@@ -294,7 +294,7 @@ function parse_name($name, $type=0) {
}
// 不区分大小写的in_array实现
function in_array_case($value,$array){
function inArrayCase($value, $array) {
return in_array(strtolower($value), array_map('strtolower', $array));
}
@@ -304,7 +304,7 @@ function in_array_case($value,$array){
* @return string 签名
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
function data_auth_sign($data) {
function dataAuthSign($data) {
//数据类型检测
if (!is_array($data)) {
$data = (array) $data;
@@ -320,12 +320,12 @@ function data_auth_sign($data) {
* @return integer 0-未登录大于0-当前登录用户ID
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
function is_login(){
function isLogin() {
$user = session('user_auth');
if (empty($user)) {
return 0;
} 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-非管理员
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
function is_administrator($uid = null){
$uid = is_null($uid) ? is_login() : $uid;
function isAdministrator($uid = null) {
$uid = is_null($uid) ? isLogin() : $uid;
return $uid && (intval($uid) === config('user_administrator'));
}
@@ -345,15 +345,21 @@ function is_administrator($uid = null){
* @param boolean $adv 是否进行高级模式获取(有可能被伪装)
* @return mixed
*/
function get_client_ip($type = 0,$adv=false) {
function getClientIp($type = 0, $adv = false) {
$type = $type ? 1 : 0;
static $ip = NULL;
if ($ip !== NULL) return $ip[$type];
if ($ip !== NULL) {
return $ip[$type];
}
if ($adv) {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$pos = array_search('unknown', $arr);
if(false !== $pos) unset($arr[$pos]);
if (false !== $pos) {
unset($arr[$pos]);
}
$ip = trim($arr[0]);
} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
@@ -375,7 +381,7 @@ function get_client_ip($type = 0,$adv=false) {
* @return string 完整的时间显示
* @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);
return date($format, $time);
}
@@ -385,24 +391,25 @@ function time_format($time = NULL,$format='Y-m-d H:i'){
* @param integer $uid 用户ID
* @return string 用户名
*/
function get_username($uid = 0){
function getUsername($uid = 0) {
static $list;
if(!($uid && is_numeric($uid))){ //获取当前登录用户名
if (!($uid && is_numeric($uid))) {
//获取当前登录用户名
return session('user_auth.username');
}
$name = db('member')->where(array('uid' => $uid))->value('username');
return $name;
}
/**
* 根据用户ID获取用户昵称
* @param integer $uid 用户ID
* @return string 用户昵称
*/
function get_nickname($uid = 0){
function getNickname($uid = 0) {
static $list;
if(!($uid && is_numeric($uid))){ //获取当前登录用户名
if (!($uid && is_numeric($uid))) {
//获取当前登录用户名
return session('user_auth.username');
}
@@ -413,9 +420,11 @@ function get_nickname($uid = 0){
/* 查找用户信息 */
$key = "u{$uid}";
if(isset($list[$key])){ //已缓存,直接使用
if (isset($list[$key])) {
//已缓存,直接使用
$name = $list[$key];
} else { //调用接口获取用户信息
} else {
//调用接口获取用户信息
$info = db('Member')->field('nickname')->find($uid);
if ($info !== false && $info['nickname']) {
$nickname = $info['nickname'];
@@ -443,11 +452,13 @@ function get_nickname($uid = 0){
* asc正向排序 desc逆向排序 nat自然排序
* @return array
*/
function list_sort_by($list,$field, $sortby='asc') {
function listSortBy($list, $field, $sortby = 'asc') {
if (is_array($list)) {
$refer = $resultSet = array();
foreach ($list as $i => $data)
foreach ($list as $i => $data) {
$refer[$i] = &$data[$field];
}
switch ($sortby) {
case 'asc': // 正向排序
asort($refer);
@@ -459,8 +470,10 @@ function list_sort_by($list,$field, $sortby='asc') {
natcasesort($refer);
break;
}
foreach ( $refer as $key=> $val)
foreach ($refer as $key => $val) {
$resultSet[] = &$list[$key];
}
return $resultSet;
}
return false;
@@ -474,7 +487,7 @@ function list_sort_by($list,$field, $sortby='asc') {
* @return array
* @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 = array();
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 返回排过序的列表数组
* @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)) {
foreach ($tree as $key => $value) {
$reffer = $value;
if (isset($reffer[$child])) {
unset($reffer[$child]);
tree_to_list($value[$child], $child, $order, $list);
treeToList($value[$child], $child, $order, $list);
}
$list[] = $reffer;
}
$list = list_sort_by($list, $order, $sortby='asc');
$list = listSortBy($list, $order, $sortby = 'asc');
}
return $list;
}
@@ -527,7 +540,7 @@ function tree_to_list($tree, $child = '_child', $order='id', &$list = array()){
// 分析枚举类型字段值 格式 a:名称1,b:名称2
// 暂时和 parse_config_attr功能相同
// 但请不要互相使用,后期会调整
function parse_field_attr($string) {
function parseFieldAttr($string) {
if (0 === strpos($string, ':')) {
// 采用函数定义
return eval('return ' . substr($string, 1) . ';');
@@ -549,7 +562,7 @@ function parse_field_attr($string) {
return $value;
}
function parse_field_bind($table,$selected = '',$model = 0) {
function parseFieldBind($table, $selected = '', $model = 0) {
if ($table) {
$select = db($table);
$res = $select->select();
@@ -574,7 +587,7 @@ function parse_field_bind($table,$selected = '',$model = 0) {
}
// 分析枚举类型配置值 格式 a:名称1,b:名称2
function parse_config_attr($string) {
function parseConfigAttr($string) {
$array = preg_split('/[,;\r\n]+/', trim($string, ",;\r\n"));
if (strpos($string, ':')) {
$value = array();
@@ -597,14 +610,14 @@ function parse_config_attr($string) {
* @return boolean
* @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)) {
return '参数不能为空';
}
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['user_id'] = $user_id;
$data['action_ip'] = ip2long(get_client_ip());
$data['action_ip'] = ip2long(getClientIp());
$data['model'] = $model;
$data['record_id'] = $record_id;
$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'])) {
//解析行为
$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解析出错 成功返回规则数组
* @author huajie <banhuajie@163.com>
*/
function parse_action($action = null, $self){
function parseAction($action = null, $self) {
if (empty($action)) {
return false;
}
@@ -720,7 +733,7 @@ function parse_action($action = null, $self){
* @return boolean false 失败 true 成功
* @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)) {
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'];
$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) {
$return = false;
@@ -748,7 +760,6 @@ function execute_action($rules = false, $action_id = null, $user_id = null){
return $return;
}
function avatar($uid, $size = 'middle') {
$size = in_array($size, array('big', 'middle', 'small', 'real')) ? $size : 'middle';
$dir = setavatardir($uid);
@@ -768,14 +779,20 @@ function setavatardir($uid){
$dir4 = substr($uid, 7, 2);
$dir = $dir1 . '/' . $dir2 . '/' . $dir3 . '/' . $dir4 . '/';
if (!is_dir("./uploads/avatar/$dir")) {
mk_dir("./uploads/avatar/".$dir);
mkDir("./uploads/avatar/" . $dir);
}
return $dir;
}
function mk_dir($dir, $mode = 0755){
if (is_dir($dir) || @mkdir($dir,$mode,true)) return true;
if (!mk_dir(dirname($dir),$mode,true)) return false;
function mkDir($dir, $mode = 0755) {
if (is_dir($dir) || @mkdir($dir, $mode, true)) {
return true;
}
if (!mkDir(dirname($dir), $mode, true)) {
return false;
}
return @mkdir($dir, $mode, true);
}
@@ -816,13 +833,16 @@ function arr2str($arr = array(), $glue = ','){
* @return string 格式化后的带单位的大小
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
function format_bytes($size, $delimiter = '') {
function formatBytes($size, $delimiter = '') {
$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];
}
function get_grid_list($list_grids){
function getGridList($list_grids) {
$grids = preg_split('/[;\r\n]+/s', trim($list_grids));
foreach ($grids as &$value) {
// 字段:标题:链接
@@ -849,8 +869,10 @@ function get_grid_list($list_grids){
return $data;
}
// 获取属性类型信息
function get_attribute_type($type = ''){
/**
* 获取字段类型
*/
function getAttributeType($type = '') {
// TODO 可以加入系统配置
$type_array = config('config_type_list');
static $type_list = array();
@@ -860,14 +882,13 @@ function get_attribute_type($type = ''){
return $type ? $type_list[$type][0] : $type_list;
}
/**
* 获取文档模型信息
* @param integer $id 模型ID
* @param string $field 模型字段
* @return array
*/
function get_document_model($id = null, $field = null){
function getDocumentModel($id = null, $field = null) {
static $list;
/* 非法分类ID */
@@ -900,24 +921,23 @@ function get_document_model($id = null, $field = null){
}
}
function get_content_status($status){
function getContentStatus($status) {
$text = array(
'-1' => '<span class="label label-danger">删除</span>',
'0' => '<span class="label label-default">禁用</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];
}
/**
* 获取分类信息并缓存分类
* @param integer $id 分类ID
* @param string $field 要获取的字段名
* @return string 分类信息
*/
function get_category($id, $field = null){
function getCategory($id, $field = null) {
/* 非法分类ID */
if (empty($id) || !is_numeric($id)) {
return '';
@@ -928,17 +948,17 @@ function get_category($id, $field = null){
}
/* 根据ID获取分类标识 */
function get_category_name($id){
return get_category($id, 'title');
function getCategoryName($id) {
return getCategory($id, 'title');
}
/* 根据ID获取分类名称 */
function get_category_title($id){
return get_category($id, 'title');
function getCategoryTitle($id) {
return getCategory($id, 'title');
}
//分类分组
function get_category_list_tree($model){
function getCategoryListTree($model) {
$list = cache('sys_category_list');
/* 读取缓存数据 */
@@ -957,7 +977,7 @@ function get_category_list_tree($model){
}
}
$res = list_unique($res);
$tree = list_to_tree($res);
$tree = listToTree($res);
if ($limit) {
$tree = array_slice($tree, 0, $limit);
}
@@ -965,7 +985,7 @@ function get_category_list_tree($model){
}
//获取栏目子ID
function get_category_child($id){
function getCategoryChild($id) {
$list = cache('sys_category_list');
/* 读取缓存数据 */
@@ -977,18 +997,18 @@ function get_category_child($id){
foreach ($list as $key => $value) {
if ($value['pid'] == $id) {
$ids[] = $value['id'];
$ids = array_merge($ids,get_category_child($value['id']));
$ids = array_merge($ids, getCategoryChild($value['id']));
}
}
return array_unique($ids);
}
function send_email($to, $subject, $message){
function sendEmail($to, $subject, $message) {
$config = array(
'protocol' => 'smtp',
'smtp_host' => \think\Config::get('mail_host'),
'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->from(\think\Config::get('mail_fromname'), \think\Config::get('web_site_title'));
@@ -1003,41 +1023,113 @@ function send_email($to, $subject, $message){
//php获取中文字符拼音首字母
function getFirstCharter($s0) {
$fchar = ord($s0{0});
if($fchar >= ord("A") and $fchar <= ord("z") )return strtoupper($s0{0});
$s1 = \iconv("UTF-8","gb2312", $s0);
$s2 = \iconv("gb2312","UTF-8", $s1);
if ($fchar >= ord("A") and $fchar <= ord("z")) {
return strtoupper($s0{0});
}
$s1 = iconv("UTF-8", "gb2312", $s0);
$s2 = iconv("gb2312", "UTF-8", $s1);
if ($s2 == $s0) {$s = $s1;} else { $s = $s0;}
$asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
if($asc >= -20319 and $asc <= -20284) return "A";
if($asc >= -20283 and $asc <= -19776) return "B";
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 >= -18526 and $asc <= -18240) return "F";
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";
if ($asc >= -20319 and $asc <= -20284) {
return "A";
}
if ($asc >= -20283 and $asc <= -19776) {
return "B";
}
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 >= -18526 and $asc <= -18240) {
return "F";
}
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;
}
function PyFirst($zh) {
$ret = "";
$s1 = \iconv("UTF-8","gb2312", $zh);
$s2 = \iconv("gb2312","UTF-8", $s1);
$s1 = iconv("UTF-8", "gb2312", $zh);
$s2 = iconv("gb2312", "UTF-8", $s1);
if ($s2 == $zh) {$zh = $s1;}
for ($i = 0; $i < strlen($zh); $i++) {
$s1 = substr($zh, $i, 1);

View File

@@ -23,7 +23,7 @@ return array(
'url_common_param' => false,
'template' => array(
'taglib_build_in' => 'cx,com\Sent'
'taglib_build_in' => 'cx,com\Sent',
),
// 'dispatch_success_tmpl' => APP_PATH . 'common/view/default/jump.html',

View File

@@ -54,7 +54,7 @@ class Content extends User{
$data = array(
'grid' => $grid_list,
'list' => $list,
'page' => $list->render()
'page' => $list->render(),
);
$this->assign($data);
return $this->fetch();
@@ -74,11 +74,11 @@ class Content extends User{
}
} else {
$info = array(
'model_id' => $this->modelInfo['id']
'model_id' => $this->modelInfo['id'],
);
$data = array(
'info' => $info,
'fieldGroup' => $this->getField($this->modelInfo)
'fieldGroup' => $this->getField($this->modelInfo),
);
$this->assign($data);
return $this->fetch('public/edit');
@@ -108,7 +108,7 @@ class Content extends User{
$info['model_id'] = $this->modelInfo['id'];
$data = array(
'info' => $info,
'fieldGroup' => $this->getField($this->modelInfo)
'fieldGroup' => $this->getField($this->modelInfo),
);
$this->assign($data);
return $this->fetch('public/edit');

View File

@@ -115,7 +115,7 @@ if (!function_exists('input')) {
* @param string $filter 过滤方法
* @return mixed
*/
function input($key, $default = null, $filter = null)
function input($key = '', $default = null, $filter = null)
{
if (0 === strpos($key, '?')) {
$key = substr($key, 1);
@@ -124,7 +124,7 @@ if (!function_exists('input')) {
if ($pos = strpos($key, '.')) {
// 指定参数来源
$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);
} else {
$method = 'param';
@@ -191,7 +191,7 @@ if (!function_exists('db')) {
*/
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 array $vars 模板变量
* @param array $replace 模板替换
* @param integer $code 状态码
* @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);
}
}

View File

@@ -337,9 +337,9 @@ class App
} catch (\ReflectionException $e) {
// 操作不存在
if (method_exists($instance, '_empty')) {
$method = new \ReflectionMethod($instance, '_empty');
$data = $method->invokeArgs($instance, [$action, '']);
self::$debug && Log::record('[ RUN ] ' . $method->__toString(), 'info');
$reflect = new \ReflectionMethod($instance, '_empty');
$data = $reflect->invokeArgs($instance, [$action]);
self::$debug && Log::record('[ RUN ] ' . $reflect->__toString(), 'info');
} else {
throw new HttpException(404, 'method not exists:' . (new \ReflectionClass($instance))->getName() . '->' . $action);
}

View File

@@ -195,12 +195,9 @@ class File extends SplFileObject
{
$extension = strtolower(pathinfo($this->getInfo('name'), PATHINFO_EXTENSION));
/* 对图像文件进行严格检测 */
if (in_array($extension, array('gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf'))) {
$imginfo = getimagesize($this->filename);
if (empty($imginfo) || ('gif' == $extension && empty($imginfo['bits']))) {
if (in_array($extension, ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf']) && !in_array(exif_imagetype($this->filename), [1, 2, 3, 4, 6])) {
return false;
}
}
return true;
}

View File

@@ -756,7 +756,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
$value = null;
}
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));
}
}
}

View File

@@ -83,7 +83,6 @@ class Request
protected $request = [];
protected $route = [];
protected $put;
protected $delete;
protected $session = [];
protected $file = [];
protected $cookie = [];
@@ -490,6 +489,7 @@ class Request
} elseif (!$this->method) {
if (isset($_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'])) {
$this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
} else {
@@ -612,10 +612,9 @@ class Request
$vars = $this->post(false);
break;
case 'PUT':
$vars = $this->put(false);
break;
case 'DELETE':
$vars = $this->delete(false);
case 'PATCH':
$vars = $this->put(false);
break;
default:
$vars = [];
@@ -718,13 +717,20 @@ class Request
*/
public function delete($name = '', $default = null, $filter = null)
{
if (is_array($name)) {
return $this->delete = is_null($this->delete) ? $name : array_merge($this->delete, $name);
return $this->put($name, $default, $filter);
}
if (is_null($this->delete)) {
parse_str(file_get_contents('php://input'), $this->delete);
}
return $this->input($this->delete, $name, $default, $filter);
/**
* 设置获取获取PATCH参数
* @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);
}
/**

View File

@@ -26,6 +26,7 @@ class Route
'POST' => [],
'PUT' => [],
'DELETE' => [],
'PATCH' => [],
'HEAD' => [],
'OPTIONS' => [],
'*' => [],
@@ -59,7 +60,7 @@ class Route
// 域名绑定
private static $bind = [];
// 当前分组
private static $group;
private static $group = '';
// 当前参数
private static $option = [];
@@ -242,7 +243,7 @@ class Route
self::$rules[$type][$rule] = ['rule' => $rule, 'route' => $route, 'var' => $vars, 'option' => $option, 'pattern' => $pattern];
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;
}
}
@@ -257,8 +258,12 @@ class Route
*/
public static function setGroup($name)
{
if (self::$group) {
self::$group = self::$group . '/' . ltrim($name, '/');
} else {
self::$group = $name;
}
}
/**
* 设置当前的路由参数
@@ -291,9 +296,11 @@ class Route
if (!empty($name)) {
// 分组
if ($routes instanceof \Closure) {
$curentGroup = self::$group;
self::setGroup($name);
call_user_func_array($routes, []);
self::setGroup(null);
self::$group = $curentGroup;
self::$rules[$type][$name]['route'] = '';
self::$rules[$type][$name]['var'] = self::parseVar($name);
self::$rules[$type][$name]['option'] = $option;
@@ -317,7 +324,7 @@ class Route
self::$rules[$type][$name] = ['rule' => $item, 'route' => '', 'var' => [], 'option' => $option, 'pattern' => $pattern];
}
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])) {
self::$rules[$method][$name] = true;
} else {
@@ -408,6 +415,20 @@ class Route
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

View File

@@ -19,9 +19,6 @@ use think\Route;
class Url
{
// 生成URL地址的root
protected static $root;
/**
* URL生成 支持路由反射
* @param string $url URL表达式
@@ -116,7 +113,7 @@ class Url
// 检测域名
$domain = self::parseDomain($url, $domain);
// URL组装
$url = $domain . (self::$root ?: Request::instance()->root()) . '/' . ltrim($url, '/');
$url = $domain . Request::instance()->root() . '/' . ltrim($url, '/');
return $url;
}
@@ -319,11 +316,4 @@ class Url
{
Cache::rm('think_route_map');
}
// 指定当前生成URL地址的root
public static function root($root)
{
self::$root = $root;
Request::instance()->root($root);
}
}

View File

@@ -68,6 +68,7 @@ class Validate
'allowIp' => '不允许的IP访问',
'denyIp' => '禁止的IP访问',
'confirm' => ':attribute和字段 :rule 不一致',
'different' => ':attribute和字段 :rule 不能相同',
'egt' => ':attribute必须大于等于 :rule',
'gt' => ':attribute必须大于 :rule',
'elt' => ':attribute必须小于等于 :rule',
@@ -400,6 +401,19 @@ class Validate
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

View File

@@ -11,8 +11,9 @@
namespace think\controller;
use think\Response;
use think\App;
use think\Request;
use think\Response;
abstract class Rest
{
@@ -61,11 +62,10 @@ abstract class Rest
* REST 调用
* @access public
* @param string $method 方法名
* @param array $args 参数
* @return mixed
* @throws \Exception
*/
public function _empty($method, $args)
public function _empty($method)
{
if (method_exists($this, $method . '_' . $this->method . '_' . $this->type)) {
// RESTFul方法支持
@@ -76,7 +76,7 @@ abstract class Rest
$fun = $method . '_' . $this->method;
}
if (isset($fun)) {
return $this->$fun();
return App::invokeMethod([$this, $fun]);
} else {
// 抛出异常
throw new \Exception('error action :' . $method);

View File

@@ -1599,13 +1599,15 @@ class Query
$options = $this->parseExpress();
// 生成SQL语句
$sql = $this->builder()->insert($data, $options, $replace);
// 获取参数绑定
$bind = $this->getBind();
if ($options['fetch_sql']) {
// 获取实际执行的SQL语句
return $this->connection->getRealSql($sql, $this->bind);
return $this->connection->getRealSql($sql, $bind);
}
$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 = $this->builder()->insertAll($dataSet, $options);
// 获取参数绑定
$bind = $this->getBind();
if ($options['fetch_sql']) {
// 获取实际执行的SQL语句
return $this->connection->getRealSql($sql, $this->bind);
return $this->connection->getRealSql($sql, $bind);
} else {
// 执行操作
return $this->execute($sql, $this->getBind());
return $this->execute($sql, $bind);
}
}
@@ -1660,12 +1664,14 @@ class Query
// 生成SQL语句
$table = $this->parseSqlTable($table);
$sql = $this->builder()->selectInsert($fields, $table, $options);
// 获取参数绑定
$bind = $this->getBind();
if ($options['fetch_sql']) {
// 获取实际执行的SQL语句
return $this->connection->getRealSql($sql, $this->bind);
return $this->connection->getRealSql($sql, $bind);
} else {
// 执行操作
return $this->execute($sql, $this->getBind());
return $this->execute($sql, $bind);
}
}
@@ -1708,9 +1714,11 @@ class Query
}
// 生成UPDATE SQL语句
$sql = $this->builder()->update($data, $options);
// 获取参数绑定
$bind = $this->getBind();
if ($options['fetch_sql']) {
// 获取实际执行的SQL语句
return $this->connection->getRealSql($sql, $this->bind);
return $this->connection->getRealSql($sql, $bind);
} else {
// 检测缓存
if (isset($key) && Cache::get($key)) {
@@ -1718,7 +1726,7 @@ class Query
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) {
// 生成查询SQL
$sql = $this->builder()->select($options);
// 获取参数绑定
$bind = $this->getBind();
if ($options['fetch_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) {
// 返回PDOStatement对象
@@ -1845,12 +1855,14 @@ class Query
if (!$result) {
// 生成查询SQL
$sql = $this->builder()->select($options);
// 获取参数绑定
$bind = $this->getBind();
if ($options['fetch_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) {
// 返回PDOStatement对象
@@ -2015,10 +2027,11 @@ class Query
}
// 生成删除SQL语句
$sql = $this->builder()->delete($options);
// 获取参数绑定
$bind = $this->getBind();
if ($options['fetch_sql']) {
// 获取实际执行的SQL语句
return $this->connection->getRealSql($sql, $this->bind);
return $this->connection->getRealSql($sql, $bind);
}
// 检测缓存
@@ -2027,7 +2040,7 @@ class Query
Cache::rm($key);
}
// 执行操作
return $this->execute($sql, $this->getBind());
return $this->execute($sql, $bind);
}
/**

View File

@@ -103,7 +103,7 @@ class Handle
$status = $e->getStatusCode();
$template = Config::get('http_exception_template');
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 {
return $this->convertExceptionToResponse($e);
}

View File

@@ -36,18 +36,6 @@ class View extends Response
->fetch($data, $this->vars, $this->replace);
}
/**
* 视图变量赋值
* @access public
* @param array $vars 模板变量
* @return $this
*/
public function vars($vars = [])
{
$this->vars = $vars;
return $this;
}
/**
* 获取视图变量
* @access public