From 762b280d215e13c4bb23956fc281a064689b977c Mon Sep 17 00:00:00 2001 From: molong Date: Sun, 31 Jul 2016 14:17:51 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=AE=89=E8=A3=85=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=202=E3=80=81=E5=86=85=E6=A0=B8=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/behavior/InitHook.php | 128 ++++---- application/common/controller/Base.php | 3 + application/install/common.php | 275 ++++++++++++++++++ application/install/config.php | 16 + application/install/controller/Index.php | 150 ++++++++++ application/install/view/index/check.html | 67 +++++ application/install/view/index/complete.html | 26 ++ application/install/view/index/config.html | 163 +++++++++++ application/install/view/index/index.html | 50 ++++ application/install/view/index/sql.html | 21 ++ application/install/view/public/base.html | 60 ++++ core/base.php | 2 +- core/library/think/App.php | 7 +- core/library/think/Cache.php | 10 +- core/library/think/Config.php | 5 +- core/library/think/Db.php | 1 + core/library/think/Request.php | 2 +- core/library/think/Route.php | 128 +++++--- core/library/think/cache/driver/File.php | 32 +- core/library/think/cache/driver/Lite.php | 10 +- core/library/think/cache/driver/Memcache.php | 6 +- core/library/think/cache/driver/Memcached.php | 6 +- core/library/think/cache/driver/Redis.php | 6 +- core/library/think/cache/driver/Sqlite.php | 10 +- core/library/think/cache/driver/Wincache.php | 10 +- core/library/think/cache/driver/Xcache.php | 10 +- core/library/think/db/Connection.php | 7 + core/library/think/log/driver/File.php | 5 +- data/db.tpl | 44 +++ data/sql.sql | 3 +- 30 files changed, 1082 insertions(+), 181 deletions(-) create mode 100644 application/install/common.php create mode 100644 application/install/config.php create mode 100644 application/install/controller/Index.php create mode 100644 application/install/view/index/check.html create mode 100644 application/install/view/index/complete.html create mode 100644 application/install/view/index/config.html create mode 100644 application/install/view/index/index.html create mode 100644 application/install/view/index/sql.html create mode 100644 application/install/view/public/base.html create mode 100644 data/db.tpl diff --git a/application/common/behavior/InitHook.php b/application/common/behavior/InitHook.php index a9c359d9..15c2c744 100644 --- a/application/common/behavior/InitHook.php +++ b/application/common/behavior/InitHook.php @@ -4,73 +4,75 @@ namespace app\common\behavior; class InitHook { public function run(&$request){ + //未安装时不执行 + if (substr(request()->pathinfo(), 0, 7) != 'install') { + //初始化某些配置信息 + if (cache('db_config_data')) { + \think\Config::set(cache('db_config_data')); + }else{ + $config = model('common/Config'); + \think\Config::set($config->lists()); + } - //初始化某些配置信息 - if (cache('db_config_data')) { - \think\Config::set(cache('db_config_data')); - }else{ - $config = model('common/Config'); - \think\Config::set($config->lists()); - } + //扩展插件 + \think\Loader::addNamespace('addons',ROOT_PATH . '/addons/'); - //扩展插件 - \think\Loader::addNamespace('addons',ROOT_PATH . '/addons/'); + $this->setHook(); - $this->setHook(); - - //设置模型内容路由 - $this->setRoute(); + //设置模型内容路由 + $this->setRoute(); + } } - protected function setHook(){ - $data = cache('hooks'); - if(!$data){ - $hooks = db('Hooks')->column('name,addons'); - foreach ($hooks as $key => $value) { - if($value){ - $map['status'] = 1; - $names = explode(',',$value); - $map['name'] = array('IN',$names); - $data = db('Addons')->where($map)->column('id,name'); - if($data){ - $addons = array_intersect($names, $data); - \think\Hook::add($key,array_map('get_addon_class',$addons)); - } - } - } - cache('hooks',\think\Hook::get()); - }else{ - \think\Hook::import($data,false); - } - } + protected function setHook(){ + $data = cache('hooks'); + if(!$data){ + $hooks = db('Hooks')->column('name,addons'); + foreach ($hooks as $key => $value) { + if($value){ + $map['status'] = 1; + $names = explode(',',$value); + $map['name'] = array('IN',$names); + $data = db('Addons')->where($map)->column('id,name'); + if($data){ + $addons = array_intersect($names, $data); + \think\Hook::add($key,array_map('get_addon_class',$addons)); + } + } + } + cache('hooks',\think\Hook::get()); + }else{ + \think\Hook::import($data,false); + } + } - protected function setRoute(){ - $list = db('Rewrite')->select(); - foreach ($list as $key => $value) { - $route[$value['rule']] = $value['url']; - } - $model = db('Model'); - $map = array( - 'status' => array('gt',0), - 'extend' => array('gt',0), - ); - $list = $model->where($map)->field("name,id,title,'' as 'style'")->select(); - foreach ($list as $key => $value) { - $route["admin/".$value['name']."/index"] = "admin/content/index?model_id=".$value['id']; - $route["admin/".$value['name']."/add"] = "admin/content/add?model_id=".$value['id']; - $route["admin/".$value['name']."/edit"] = "admin/content/edit?model_id=".$value['id']; - $route["admin/".$value['name']."/del"] = "admin/content/del?model_id=".$value['id']; - $route["admin/".$value['name']."/status"] = "admin/content/status?model_id=".$value['id']; - $route[$value['name']."/index"] = "index/content/index?model=".$value['name']; - $route[$value['name']."/list/:id"] = "index/content/lists?model=".$value['name']; - $route[$value['name']."/detail/:id"] = "index/content/detail?model_id=".$value['id']; - $route["/list/:id"] = "index/content/category"; - $route["user/".$value['name']."/index"] = "user/content/index?model_id=".$value['id']; - $route["user/".$value['name']."/add"] = "user/content/add?model_id=".$value['id']; - $route["user/".$value['name']."/edit"] = "user/content/edit?model_id=".$value['id']; - $route["user/".$value['name']."/del"] = "user/content/del?model_id=".$value['id']; - $route["user/".$value['name']."/status"] = "user/content/status?model_id=".$value['id']; - } - \think\Route::rule($route); - } + protected function setRoute(){ + $list = db('Rewrite')->select(); + foreach ($list as $key => $value) { + $route[$value['rule']] = $value['url']; + } + $model = db('Model'); + $map = array( + 'status' => array('gt',0), + 'extend' => array('gt',0), + ); + $list = $model->where($map)->field("name,id,title,'' as 'style'")->select(); + foreach ($list as $key => $value) { + $route["admin/".$value['name']."/index"] = "admin/content/index?model_id=".$value['id']; + $route["admin/".$value['name']."/add"] = "admin/content/add?model_id=".$value['id']; + $route["admin/".$value['name']."/edit"] = "admin/content/edit?model_id=".$value['id']; + $route["admin/".$value['name']."/del"] = "admin/content/del?model_id=".$value['id']; + $route["admin/".$value['name']."/status"] = "admin/content/status?model_id=".$value['id']; + $route[$value['name']."/index"] = "index/content/index?model=".$value['name']; + $route[$value['name']."/list/:id"] = "index/content/lists?model=".$value['name']; + $route[$value['name']."/detail/:id"] = "index/content/detail?model_id=".$value['id']; + $route["/list/:id"] = "index/content/category"; + $route["user/".$value['name']."/index"] = "user/content/index?model_id=".$value['id']; + $route["user/".$value['name']."/add"] = "user/content/add?model_id=".$value['id']; + $route["user/".$value['name']."/edit"] = "user/content/edit?model_id=".$value['id']; + $route["user/".$value['name']."/del"] = "user/content/del?model_id=".$value['id']; + $route["user/".$value['name']."/status"] = "user/content/status?model_id=".$value['id']; + } + \think\Route::rule($route); + } } \ No newline at end of file diff --git a/application/common/controller/Base.php b/application/common/controller/Base.php index f093749c..38d69437 100644 --- a/application/common/controller/Base.php +++ b/application/common/controller/Base.php @@ -18,6 +18,9 @@ class Base extends \think\Controller{ protected $action; public function _initialize(){ + if (!is_file(APP_PATH . 'database.php') || !is_file(APP_PATH . 'install.lock')) { + return $this->redirect('install/index/index'); + } /* 读取数据库中的配置 */ $config = cache('db_config_data'); if(!$config){ diff --git a/application/install/common.php b/application/install/common.php new file mode 100644 index 00000000..04b81e61 --- /dev/null +++ b/application/install/common.php @@ -0,0 +1,275 @@ + +// +---------------------------------------------------------------------- + +// 检测环境是否支持可写 +define('IS_WRITE', true); +define('INSTALL_APP_PATH', BASE_PATH . '/'); + +/** + * 系统环境检测 + * @return array 系统环境数据 + */ +function check_env(){ + $items = array( + 'os' => array('操作系统', '不限制', '类Unix', PHP_OS, 'success'), + 'php' => array('PHP版本', '5.4.0', '5.3+', PHP_VERSION, 'success'), + 'upload' => array('附件上传', '不限制', '2M+', '未知', 'success'), + 'gd' => array('GD库', '2.0', '2.0+', '未知', 'success'), + 'disk' => array('磁盘空间', '5M', '不限制', '未知', 'success'), + ); + + //PHP环境检测 + if($items['php'][3] < $items['php'][1]){ + $items['php'][4] = 'error'; + session('error', true); + } + + //附件上传检测 + if(@ini_get('file_uploads')) + $items['upload'][3] = ini_get('upload_max_filesize'); + + //GD库检测 + $tmp = function_exists('gd_info') ? gd_info() : array(); + if(empty($tmp['GD Version'])){ + $items['gd'][3] = '未安装'; + $items['gd'][4] = 'error'; + session('error', true); + } else { + $items['gd'][3] = $tmp['GD Version']; + } + unset($tmp); + + //磁盘空间检测 + if(function_exists('disk_free_space')) { + $items['disk'][3] = floor(disk_free_space(INSTALL_APP_PATH) / (1024*1024)).'M'; + } + + return $items; +} + +/** + * 目录,文件读写检测 + * @return array 检测数据 + */ +function check_dirfile(){ + $items = array( + array('dir', '可写', 'success', 'uploads/attachment/'), + array('dir', '可写', 'success', 'uploads/avatar/'), + array('dir', '可写', 'success', 'uploads/download/'), + array('dir', '可写', 'success', 'uploads/picture/'), + array('dir', '可写', 'success', 'uploads/editor/'), + + ); + + foreach ($items as &$val) { + $item = INSTALL_APP_PATH . $val[3]; + if('dir' == $val[0]){ + if(!is_writable($item)) { + if(is_dir($item)) { + $val[1] = '可读'; + $val[2] = 'error'; + session('error', true); + } else { + $val[1] = '不存在'; + $val[2] = 'error'; + session('error', true); + } + } + } else { + if(file_exists($item)) { + if(!is_writable($item)) { + $val[1] = '不可写'; + $val[2] = 'error'; + session('error', true); + } + } else { + if(!is_writable(dirname($item))) { + $val[1] = '不存在'; + $val[2] = 'error'; + session('error', true); + } + } + } + } + + return $items; +} + +/** + * 函数检测 + * @return array 检测数据 + */ +function check_func(){ + $items = array( + array('pdo','支持','success','类'), + array('pdo_mysql','支持','success','模块'), + array('file_get_contents', '支持', 'success','函数'), + array('mb_strlen', '支持', 'success','函数'), + ); + + foreach ($items as &$val) { + if(('类'==$val[3] && !class_exists($val[0])) + || ('模块'==$val[3] && !extension_loaded($val[0])) + || ('函数'==$val[3] && !function_exists($val[0])) + ){ + $val[1] = '不支持'; + $val[2] = 'error'; + session('error', true); + } + } + + return $items; +} + +/** + * 写入配置文件 + * @param array $config 配置信息 + */ +function write_config($config){ + if(is_array($config)){ + //读取配置内容 + $conf = file_get_contents(BASE_PATH . './data/db.tpl'); + //替换配置项 + foreach ($config as $name => $value) { + $conf = str_replace("[{$name}]", $value, $conf); + } + + file_put_contents(APP_PATH . 'install.lock', 'ok'); + + //写入应用配置文件 + if(file_put_contents(APP_PATH . 'database.php', $conf)){ + show_msg('配置文件写入成功'); + } else { + show_msg('配置文件写入失败!', 'error'); + session('error', true); + } + return ''; + } +} + +/** + * 创建数据表 + * @param resource $db 数据库连接资源 + */ +function create_tables($db, $prefix = ''){ + //读取SQL文件 + $sql = file_get_contents(BASE_PATH . './data/sql.sql'); + $sql = str_replace("\r", "\n", $sql); + $sql = explode(";\n", $sql); + + //替换表前缀 + $orginal = 'sent_'; + $sql = str_replace(" `{$orginal}", " `{$prefix}", $sql); + + //开始安装 + show_msg('开始安装数据库...'); + foreach ($sql as $value) { + $value = trim($value); + if(empty($value)) continue; + if(substr($value, 0, 12) == 'CREATE TABLE') { + $name = preg_replace("/^CREATE TABLE `(\w+)` .*/s", "\\1", $value); + $msg = "创建数据表{$name}"; + if(false !== $db->execute($value)){ + show_msg($msg . '...成功'); + } else { + show_msg($msg . '...失败!', 'error'); + session('error', true); + } + } else { + $db->execute($value); + } + + } +} + +function register_administrator($db, $prefix, $admin){ + show_msg('开始注册创始人帐号...'); + + $salt = rand_string(); + $password = md5($admin['password'].$salt); + + $sql = "INSERT INTO `[PREFIX]member` (`uid`,`username`,`password`,`nickname`,`email`, `sex`,`birthday`,`qq`,`score`,`salt`,`login`,`reg_ip`,`reg_time`,`last_login_ip`,`last_login_time`,`status`) VALUES ". + "('1', '[NAME]', '[PASS]', '[NAME]', '[EMAIL]', '0', '0000-00-00', '', '0','[SALT]', '1', '0', '[TIME]', '[IP]', '[TIME]', '1');"; + $sql = str_replace( + array('[PREFIX]', '[NAME]','[PASS]','[EMAIL]','[SALT]', '[TIME]', '[IP]'), + array($prefix, $admin['username'],$password, $admin['email'],$salt, time(), get_client_ip(1)), + $sql); + $db->execute($sql); + show_msg('创始人帐号注册完成!'); +} + +/** + * 更新数据表 + * @param resource $db 数据库连接资源 + * @author lyq <605415184@qq.com> + */ +function update_tables($db, $prefix = ''){ + //读取SQL文件 + $sql = file_get_contents(MODULE_PATH . 'Data/update.sql'); + $sql = str_replace("\r", "\n", $sql); + $sql = explode(";\n", $sql); + + //替换表前缀 + $sql = str_replace(" `sent_", " `{$prefix}", $sql); + + //开始安装 + show_msg('开始升级数据库...'); + foreach ($sql as $value) { + $value = trim($value); + if(empty($value)) continue; + if(substr($value, 0, 12) == 'CREATE TABLE') { + $name = preg_replace("/^CREATE TABLE `(\w+)` .*/s", "\\1", $value); + $msg = "创建数据表{$name}"; + if(false !== $db->execute($value)){ + show_msg($msg . '...成功'); + } else { + show_msg($msg . '...失败!', 'error'); + session('error', true); + } + } else { + if(substr($value, 0, 8) == 'UPDATE `') { + $name = preg_replace("/^UPDATE `(\w+)` .*/s", "\\1", $value); + $msg = "更新数据表{$name}"; + } else if(substr($value, 0, 11) == 'ALTER TABLE'){ + $name = preg_replace("/^ALTER TABLE `(\w+)` .*/s", "\\1", $value); + $msg = "修改数据表{$name}"; + } else if(substr($value, 0, 11) == 'INSERT INTO'){ + $name = preg_replace("/^INSERT INTO `(\w+)` .*/s", "\\1", $value); + $msg = "写入数据表{$name}"; + } + if(($db->execute($value)) !== false){ + show_msg($msg . '...成功'); + } else{ + show_msg($msg . '...失败!', 'error'); + session('error', true); + } + } + } +} + +/** + * 及时显示提示信息 + * @param string $msg 提示信息 + */ +function show_msg($msg, $class = 'primary'){ + echo ""; + flush(); + ob_flush(); +} + +/** + * 生成系统AUTH_KEY + * @author 麦当苗儿 + */ +function build_auth_key(){ + $chars = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $chars .= '`~!@#$%^&*()_+-=[]{};:"|,.<>/?'; + $chars = str_shuffle($chars); + return substr($chars, 0, 40); +} \ No newline at end of file diff --git a/application/install/config.php b/application/install/config.php new file mode 100644 index 00000000..bb54f548 --- /dev/null +++ b/application/install/config.php @@ -0,0 +1,16 @@ + array( + '__ADDONS__' => BASE_PATH . '/addons', + '__PUBLIC__' => BASE_PATH . '/public', + '__STATIC__' => BASE_PATH . '/application/admin/static', + '__IMG__' => BASE_PATH . '/application/admin/static/images', + '__CSS__' => BASE_PATH . '/application/admin/static/css', + '__JS__' => BASE_PATH . '/application/admin/static/js', + '__COMPANY__' => '南昌腾速科技有限公司', + '__NAME__' => 'SentCMS网站管理系统', + '__COMPANY_WEBSITE__' => 'www.tensent.cn', + '__WEBSITE__' => 'www.sentcms.cn', + ), +); \ No newline at end of file diff --git a/application/install/controller/Index.php b/application/install/controller/Index.php new file mode 100644 index 00000000..955ebd01 --- /dev/null +++ b/application/install/controller/Index.php @@ -0,0 +1,150 @@ + +// +---------------------------------------------------------------------- + +namespace app\install\controller; + +class Index extends \think\Controller { + + protected $status; + + public function _initialize() { + $this->status = array( + 'index' => 'info', + 'check' => 'info', + 'config' => 'info', + 'sql' => 'info', + 'complete' => 'info', + ); + + if (request()->action() != 'complete' && is_file(APP_PATH . 'database.php') && is_file(APP_PATH . 'install.lock')) { + return $this->redirect('index/index/index'); + } + } + + public function index() { + $this->status['index'] = 'primary'; + $this->assign('status', $this->status); + return $this->fetch(); + } + + public function check() { + session('error', false); + + //环境检测 + $env = check_env(); + + //目录文件读写检测 + if (IS_WRITE) { + $dirfile = check_dirfile(); + $this->assign('dirfile', $dirfile); + } + + //函数检测 + $func = check_func(); + + session('step', 1); + + $this->assign('env', $env); + $this->assign('func', $func); + $this->status['index'] = 'success'; + $this->status['check'] = 'primary'; + $this->assign('status', $this->status); + return $this->fetch(); + } + + public function config($db = null, $admin = null) { + if (request()->IsPost()) { + //检测管理员信息 + if (!is_array($admin) || empty($admin[0]) || empty($admin[1]) || empty($admin[3])) { + return $this->error('请填写完整管理员信息'); + } else if ($admin[1] != $admin[2]) { + return $this->error('确认密码和密码不一致'); + } else { + $info = array(); + list($info['username'], $info['password'], $info['repassword'], $info['email']) + = $admin; + //缓存管理员信息 + session('admin_info', $info); + } + + //检测数据库配置 + if (!is_array($db) || empty($db[0]) || empty($db[1]) || empty($db[2]) || empty($db[3])) { + return $this->error('请填写完整的数据库配置'); + } else { + $DB = array(); + list($DB['type'], $DB['hostname'], $DB['database'], $DB['username'], $DB['password'], + $DB['hostport'], $DB['prefix']) = $db; + //缓存数据库配置 + session('db_config', $DB); + + //创建数据库 + $dbname = $DB['database']; + unset($DB['database']); + $db = \think\Db::connect($DB); + $sql = "CREATE DATABASE IF NOT EXISTS `{$dbname}` DEFAULT CHARACTER SET utf8"; + if (!$db->execute($sql)) { + return $this->error($db->getError()); + } else { + return $this->redirect('install/index/sql'); + } + } + } else { + $this->status['index'] = 'success'; + $this->status['check'] = 'success'; + $this->status['config'] = 'primary'; + $this->assign('status', $this->status); + return $this->fetch(); + } + } + + public function sql() { + session('error', false); + $this->status['index'] = 'success'; + $this->status['check'] = 'success'; + $this->status['config'] = 'success'; + $this->status['sql'] = 'primary'; + $this->assign('status', $this->status); + echo $this->fetch(); + if (session('update')) { + $db = \think\Db::connect(); + //更新数据表 + update_tables($db, config('prefix')); + } else { + //连接数据库 + $dbconfig = session('db_config'); + $db = \think\Db::connect($dbconfig); + //创建数据表 + create_tables($db, $dbconfig['prefix']); + //注册创始人帐号 + $admin = session('admin_info'); + register_administrator($db, $dbconfig['prefix'], $admin); + + //创建配置文件 + $conf = write_config($dbconfig); + session('config_file', $conf); + } + + if (session('error')) { + show_msg('失败'); + } else { + echo ''; + } + } + + public function complete() { + $this->status['index'] = 'success'; + $this->status['check'] = 'success'; + $this->status['config'] = 'success'; + $this->status['sql'] = 'success'; + $this->status['complete'] = 'primary'; + $this->assign('status', $this->status); + $this->assign('status', $this->status); + return $this->fetch(); + } +} \ No newline at end of file diff --git a/application/install/view/index/check.html b/application/install/view/index/check.html new file mode 100644 index 00000000..3ac22634 --- /dev/null +++ b/application/install/view/index/check.html @@ -0,0 +1,67 @@ +{extend name="public/base"/} +{block name="body"} +

环境检测

+ + + + + + + + + + + {volist name="env" id="item"} + + + + + + {/volist} + +

运行环境检查

项目所需配置当前配置
{$item[0]}{$item[1]} {$item[3]}
+ {present name="dirfile"} + + + + + + + + + + + {volist name="dirfile" id="item"} + + + + + + {/volist} + +

目录、文件权限检查

目录/文件所需状态当前状态
{$item[3]} 可写 {$item[1]}
+ {/present} + + + + + + + + + + {volist name="func" id="item"} + + + + + {/volist} + +

函数依赖性检查

函数名称检查结果
{$item[0]}() {$item[1]}
+{/block} +{block name="footer"} + +{/block} \ No newline at end of file diff --git a/application/install/view/index/complete.html b/application/install/view/index/complete.html new file mode 100644 index 00000000..4316be7a --- /dev/null +++ b/application/install/view/index/complete.html @@ -0,0 +1,26 @@ +{extend name="public/base"/} +{block name="body"} +

完成

+ +{/block} +{block name="footer"} + +{/block} \ No newline at end of file diff --git a/application/install/view/index/config.html b/application/install/view/index/config.html new file mode 100644 index 00000000..947064d5 --- /dev/null +++ b/application/install/view/index/config.html @@ -0,0 +1,163 @@ +{extend name="public/base"/} +{block name="body"} +

+ 创建数据库 +

+
+
+

+ 数据库连接信息 +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + 数据库连接类型,服务器支持的情况下建议使用mysql +
+ + + + + 数据库服务器,数据库服务器IP,一般为127.0.0.1,使用localhost可能导致网站速度变慢 + +
+ + + + + 数据库名 + +
+ + + + + 数据库用户名 + +
+ + + + + 数据库密码 + +
+ + + + + 数据库端口,数据库服务连接端口,一般为3306 + +
+ + + + + 数据表前缀,同一个数据库运行多个系统时请修改为不同的前缀 + +
+
+
+

+ 创始人帐号信息 +

+ + + + + + + + + + + + + + + + + +
+ + + + + 用户名( + + 英文+数字,严禁中文与特殊字符 + + ) + +
+ + + + + 密码 + +
+ + + + + 确认密码 + +
+ + + + + 邮箱,请填写正确的邮箱便于收取提醒邮件 + +
+
+
+
+
+{/block} +{block name="footer"} +
+ + + 上一步 + +
+{/block} diff --git a/application/install/view/index/index.html b/application/install/view/index/index.html new file mode 100644 index 00000000..baf3304b --- /dev/null +++ b/application/install/view/index/index.html @@ -0,0 +1,50 @@ +{extend name="public/base"/} +{block name="body"} +
+ +
+

__NAME__ 安装协议

+ +
版权所有 (c) 2014-2015,__COMPANY__保留所有权利。
+
+
+

+ __NAME__基于 + ThinkPHP框架 + 的开发产品。感谢顶想公司为__NAME__提供内核支持。 +

+ +

+ 感谢您选择__NAME__,希望我们的努力可以为您创造价值。公司网址为 + http://__COMPANY_WEBSITE__ + ,产品官方网站网址为 + http://__WEBSITE__ + 。 +

+ +

+ 用户须知:本协议是您于__COMPANY__关于__NAME__产品使用的法律协议。无论您是个人或组织、盈利与否、用途如何(包括以学习和研究为目的),均需仔细阅读本协议,包括免除或者限制__COMPANY__责任的免责条款及对您的权利限制。请您审阅并接受或不接受本服务条款。如您不同意本服务条款及或__COMPANY__随时对其的修改,您应不使用或主动取消__NAME__产品。否则,您的任何对__NAME__的相关服务的注册、登陆、下载、查看等使用行为将被视为您对本服务条款全部的完全接受,包括接受__COMPANY__对服务条款随时所做的任何修改。 +

+ +

+ 本服务条款一旦发生变更,__COMPANY__将在产品官网上公布修改内容。修改后的服务条款一旦在网站公布即有效代替原来的服务条款。您可随时登陆官网查阅最新版服务条款。如果您选择接受本条款,即表示您同意接受协议各项条件的约束。如果您不同意本服务条款,则不能获得使用本服务的权利。您若有违反本条款规定,__COMPANY__有权随时中止或终止您对__NAME__产品的使用资格并保留追究相关法律责任的权利。 +

+ +

+ 在理解、同意、并遵守本协议的全部条款后,方可开始使用__NAME__产品。您也可能与__COMPANY__直接签订另一书面协议,以补充或者取代本协议的全部或者任何部分。 +

+ +

+ __COMPANY__拥有__NAME__的知识产权,包括商标和著作权。本软件只供许可协议,并非出售。想天只允许您在遵守本协议各项条款的情况下复制、下载、安装、使用或者以其他方式受益于本软件的功能或者知识产权。 +

+ +
+ +
+{/block} +{block name="footer"} + +{/block} \ No newline at end of file diff --git a/application/install/view/index/sql.html b/application/install/view/index/sql.html new file mode 100644 index 00000000..d9a24d6b --- /dev/null +++ b/application/install/view/index/sql.html @@ -0,0 +1,21 @@ +{extend name="public/base"/} +{block name="body"} +

安装数据库

+
+
+ +{/block} +{block name="footer"} +
+ +
+{/block} \ No newline at end of file diff --git a/application/install/view/public/base.html b/application/install/view/public/base.html new file mode 100644 index 00000000..4b8eb365 --- /dev/null +++ b/application/install/view/public/base.html @@ -0,0 +1,60 @@ + + + + +SentCMS系统安装 + + + + + + + + + + +
+
+
+

SentCMS系统{if session('update')}升级{else/}安装{/if}

+
+
+
+
+ 系统安装 +
+
+ 环境检查 +
+
+ 系统配置 +
+
+ 数据库安装 +
+
+ 安装完成 +
+
+
+
+ {block name="body"}{/block} + +
+ {block name="footer"}{/block} +
+
+
+
+ + \ No newline at end of file diff --git a/core/base.php b/core/base.php index 80a6e28f..1af1e329 100644 --- a/core/base.php +++ b/core/base.php @@ -32,7 +32,7 @@ defined('ENV_PREFIX') or define('ENV_PREFIX', 'PHP_'); // 环境变量的配置 // 环境常量 define('IS_CLI', PHP_SAPI == 'cli' ? true : false); -define('IS_WIN', strstr(PHP_OS, 'WIN') ? true : false); +define('IS_WIN', strpos(PHP_OS, 'WIN') !== false); // 载入Loader类 require CORE_PATH . 'Loader.php'; diff --git a/core/library/think/App.php b/core/library/think/App.php index 2e50a40f..6daf7300 100644 --- a/core/library/think/App.php +++ b/core/library/think/App.php @@ -280,7 +280,10 @@ class App if ($bind) { // 绑定模块 list($bindModule) = explode('/', $bind); - if ($module == $bindModule) { + if (empty($result[0])) { + $module = $bindModule; + $available = true; + } elseif ($module == $bindModule) { $available = true; } } elseif (!in_array($module, $config['deny_module_list']) && is_dir(APP_PATH . $module)) { @@ -363,7 +366,7 @@ class App self::$debug = Config::get('app_debug'); if (!self::$debug) { ini_set('display_errors', 'Off'); - } else { + } elseif (!IS_CLI) { //重新申请一块比较大的buffer if (ob_get_level() > 0) { $output = ob_get_clean(); diff --git a/core/library/think/Cache.php b/core/library/think/Cache.php index 10ff01c8..7ae31aae 100644 --- a/core/library/think/Cache.php +++ b/core/library/think/Cache.php @@ -115,14 +115,13 @@ class Cache * @access public * @param string $name 缓存变量名 * @param int $step 步长 - * @param int $expire 有效时间 0为永久 * @return false|int */ - public function inc($name, $step = 1, $expire = null) + public static function inc($name, $step = 1) { self::init(); self::$writeTimes++; - return self::$handler->inc($name, $step, $expire); + return self::$handler->inc($name, $step); } /** @@ -130,14 +129,13 @@ class Cache * @access public * @param string $name 缓存变量名 * @param int $step 步长 - * @param int $expire 有效时间 0为永久 * @return false|int */ - public function dec($name, $step = 1, $expire = null) + public static function dec($name, $step = 1) { self::init(); self::$writeTimes++; - return self::$handler->dec($name, $step, $expire); + return self::$handler->dec($name, $step); } /** diff --git a/core/library/think/Config.php b/core/library/think/Config.php index 105920b1..7256e0ed 100644 --- a/core/library/think/Config.php +++ b/core/library/think/Config.php @@ -33,6 +33,7 @@ class Config * @param string $type 配置解析类型 * @param string $name 配置名(如设置即表示二级配置) * @param string $range 作用域 + * @return mixed */ public static function parse($config, $type = '', $name = '', $range = '') { @@ -41,7 +42,7 @@ class Config $type = pathinfo($config, PATHINFO_EXTENSION); } $class = false !== strpos($type, '\\') ? $type : '\\think\\config\\driver\\' . ucwords($type); - self::set((new $class())->parse($config), $name, $range); + return self::set((new $class())->parse($config), $name, $range); } /** @@ -122,7 +123,7 @@ class Config } else { // 二维数组设置和获取支持 $name = explode('.', $name); - $result = getenv(ENV_PREFIX . strtoupper($name[0] . '_' . $name[1])); + $result = getenv(ENV_PREFIX . strtoupper($name[0] . '_' . $name[1])); // 判断环境变量 if (false !== $result) { return $result; diff --git a/core/library/think/Db.php b/core/library/think/Db.php index e46bc80a..f3b0e274 100644 --- a/core/library/think/Db.php +++ b/core/library/think/Db.php @@ -14,6 +14,7 @@ namespace think; use think\App; use think\Collection; use think\db\Query; +use think\paginator\Collection as PaginatorCollection; /** * Class Db diff --git a/core/library/think/Request.php b/core/library/think/Request.php index c19cd9ee..4edf5083 100644 --- a/core/library/think/Request.php +++ b/core/library/think/Request.php @@ -236,7 +236,7 @@ class Request $options['server'] = $server; $options['url'] = $server['REQUEST_URI']; $options['baseUrl'] = $info['path']; - $options['pathinfo'] = ltrim($info['path'], '/'); + $options['pathinfo'] = '/' == $info['path'] ? '/' : ltrim($info['path'], '/'); $options['method'] = $server['REQUEST_METHOD']; $options['domain'] = $server['HTTP_HOST']; $options['content'] = $content; diff --git a/core/library/think/Route.php b/core/library/think/Route.php index 779e40fb..f63e37e1 100644 --- a/core/library/think/Route.php +++ b/core/library/think/Route.php @@ -13,6 +13,7 @@ namespace think; use think\App; use think\Config; +use think\exception\HttpException; use think\Hook; use think\Log; use think\Request; @@ -63,6 +64,8 @@ class Route private static $group = []; // 路由命名标识(用于快速URL生成) private static $name = []; + // 当前子域名绑定 + private static $domain; /** * 注册变量规则 @@ -85,14 +88,18 @@ class Route * @access public * @param string|array $domain 子域名 * @param mixed $rule 路由规则 + * @param array $option 路由参数 + * @param array $pattern 变量规则 * @return void */ - public static function domain($domain = null, $rule = '') + public static function domain($domain, $rule = '', $option = [], $pattern = []) { if (is_array($domain)) { - self::$rules['domain'] = array_merge(self::$rules['domain'], $domain); + foreach ($domain as $key => $item) { + self::$rules['domain'][$key] = [$item, $option, $pattern]; + } } else { - self::$rules['domain'][$domain] = $rule; + self::$rules['domain'][$domain] = [$rule, $option, $pattern]; } } @@ -100,7 +107,7 @@ class Route * 设置路由绑定 * @access public * @param mixed $bind 绑定信息 - * @param string $type 绑定类型 默认为module + * @param string $type 绑定类型 默认为module 支持 namespace class * @return mixed */ public static function bind($bind, $type = 'module') @@ -167,8 +174,13 @@ class Route unset($rule['__rest__']); } - $type = strtoupper($type); - foreach ($rule as $key => $val) { + self::registerRules($rule, strtoupper($type)); + } + + // 批量注册路由 + protected static function registerRules($rules, $type = '*') + { + foreach ($rules as $key => $val) { if (is_numeric($key)) { $key = array_shift($val); } @@ -358,7 +370,7 @@ class Route foreach (['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'] as $method) { if (!isset(self::$rules[$method][$name])) { self::$rules[$method][$name] = true; - } else { + } elseif (is_array(self::$rules[$method][$name])) { self::$rules[$method][$name] = array_merge(self::$rules['*'][$name], self::$rules[$method][$name]); } } @@ -587,6 +599,17 @@ class Route self::rule('__miss__', $route, $method, $option, []); } + /** + * 注册一个自动解析的URL路由 + * @access public + * @param string $route 路由地址 + * @return void + */ + public static function auto($route) + { + self::rule('__auto__', $route, '*', [], []); + } + /** * 获取或者批量设置路由定义 * @access public @@ -610,9 +633,10 @@ class Route * 检测子域名部署 * @access public * @param Request $request Request请求对象 + * @param string $method 请求类型 * @return void */ - public static function checkDomain($request) + public static function checkDomain($request, $method = 'GET') { // 域名规则 $rules = self::$rules['domain']; @@ -621,7 +645,7 @@ class Route $host = $request->host(); if (isset($rules[$host])) { // 完整域名或者IP配置 - $rule = $rules[$host]; + $item = $rules[$host]; } else { $rootDomain = Config::get('url_domain_root'); if ($rootDomain) { @@ -642,27 +666,42 @@ class Route } if ($subDomain && isset($rules[$subDomain])) { // 子域名配置 - $rule = $rules[$subDomain]; + $item = $rules[$subDomain]; } elseif (isset($rules['*.' . $domain2]) && !empty($domain3)) { // 泛三级域名 - $rule = $rules['*.' . $domain2]; + $item = $rules['*.' . $domain2]; $panDomain = $domain3; } elseif (isset($rules['*']) && !empty($domain2)) { // 泛二级域名 if ('www' != $domain2) { - $rule = $rules['*']; + $item = $rules['*']; $panDomain = $domain2; } } } } - if (!empty($rule)) { - // 子域名部署规则 + if (!empty($item)) { + self::$domain = true; + // 解析子域名部署规则 + list($rule, $option, $pattern) = $item; + if (!empty($option['https']) && !$request->isSsl()) { + // https检测 + throw new HttpException(404, 'must use https request:' . $host); + } if ($rule instanceof \Closure) { // 执行闭包 $reflect = new \ReflectionFunction($rule); self::$bind = $reflect->invokeArgs([]); return; + } elseif (is_array($rule)) { + // 清空当前路由规则 + self::$rules[$method] = []; + self::$rules['*'] = []; + self::group('', function () use ($rule) { + // 动态注册域名的路由规则 + self::registerRules($rule); + }, $option, $pattern); + return; } if (strpos($rule, '?')) { @@ -684,16 +723,13 @@ class Route if (0 === strpos($result, '\\')) { // 绑定到命名空间 例如 \app\index\behavior - self::$bind = ['type' => 'namespace', 'namespace' => $result, 'domain' => true]; + self::$bind = ['type' => 'namespace', 'namespace' => $result]; } elseif (0 === strpos($result, '@')) { // 绑定到类 例如 @app\index\controller\User - self::$bind = ['type' => 'class', 'class' => substr($result, 1), 'domain' => true]; - } elseif (0 === strpos($result, '[')) { - // 绑定到分组 例如 [user] - self::$bind = ['type' => 'group', 'group' => substr($result, 1, -1), 'domain' => true]; + self::$bind = ['type' => 'class', 'class' => substr($result, 1)]; } else { // 绑定到模块/控制器 例如 index/user - self::$bind = ['type' => 'module', 'module' => $result, 'domain' => true]; + self::$bind = ['type' => 'module', 'module' => $result]; } } } @@ -722,13 +758,13 @@ class Route return $result; } } - + $method = $request->method(); // 检测域名部署 if ($checkDomain) { - self::checkDomain($request); + self::checkDomain($request, $method); } // 获取当前请求类型的路由规则 - $rules = self::$rules[$request->method()]; + $rules = self::$rules[$method]; // 检测URL绑定 $return = self::checkUrlBind($url, $rules, $depr); @@ -751,7 +787,7 @@ class Route // 路由规则检测 if (!empty($rules)) { - return self::checkRoute($request, $rules, $url); + return self::checkRoute($request, $rules, $url, $depr); } return false; } @@ -762,10 +798,11 @@ class Route * @param Request $request * @param array $rules 路由规则 * @param string $url URL地址 + * @param string $depr URL分割符 * @param string $group 路由分组名 * @return mixed */ - private static function checkRoute($request, $rules, $url, $group = '') + private static function checkRoute($request, $rules, $url, $depr = '/', $group = '') { foreach ($rules as $key => $item) { if (true === $item) { @@ -796,14 +833,15 @@ class Route continue; } - $result = self::checkRoute($request, $rule, $url, $key); + $result = self::checkRoute($request, $rule, $url, $depr, $key); if (false !== $result) { return $result; } } elseif ($route) { - if ('__miss__' == $rule) { - // 指定MISS路由 - $miss = $item; + if ('__miss__' == $rule || '__auto__' == $rule) { + // 指定特殊路由 + $var = trim($rule, '__'); + ${$var} = $item; continue; } if ($group) { @@ -815,7 +853,10 @@ class Route } } } - if (isset($miss)) { + if (isset($auto)) { + // 自动解析URL地址 + return self::parseUrl($auto['route'] . '/' . $url, $depr); + } elseif (isset($miss)) { // 未匹配所有路由的路由规则处理 return self::parseRule('', $miss['route'], $url, $miss['option']); } @@ -866,32 +907,23 @@ class Route */ private static function checkUrlBind(&$url, &$rules, $depr = '/') { - if (!empty(self::$bind['type'])) { + if (!empty(self::$bind)) { + $type = self::$bind['type']; + $bind = self::$bind[$type]; // 记录绑定信息 - App::$debug && Log::record('[ BIND ] ' . var_export(self::$bind, true), 'info'); + App::$debug && Log::record('[ BIND ] ' . var_export($bind, true), 'info'); // 如果有URL绑定 则进行绑定检测 - switch (self::$bind['type']) { + switch ($type) { case 'class': // 绑定到类 - return self::bindToClass($url, self::$bind['class'], $depr); + return self::bindToClass($url, $bind, $depr); case 'namespace': // 绑定到命名空间 - return self::bindToNamespace($url, self::$bind['namespace'], $depr); + return self::bindToNamespace($url, $bind, $depr); case 'module': // 如果有模块/控制器绑定 针对路由到 模块/控制器 有效 - $url = (empty(self::$bind['domain']) ? self::$bind['module'] . '/' : '') . ltrim($url, '/'); + $url = (empty(self::$domain) ? $bind . '/' : '') . ltrim($url, '/'); break; - case 'group': - // 绑定到路由分组 - $key = self::$bind['group']; - if (array_key_exists($key, $rules)) { - $item = $rules[self::$bind['group']]; - if (!empty(self::$bind['domain']) && true === $item) { - $rules = [self::$rules['*'][$key]]; - } else { - $rules = [$key => $item]; - } - } } } return false; @@ -1049,7 +1081,7 @@ class Route { if (isset(self::$bind['module'])) { // 如果有模块/控制器绑定 - $url = self::$bind['module'] . '/' . $url; + $url = self::$bind['module'] . '/' . ltrim($url, '/'); } list($path, $var) = self::parseUrlPath($url, $depr); diff --git a/core/library/think/cache/driver/File.php b/core/library/think/cache/driver/File.php index c356f21c..97ee2bf6 100644 --- a/core/library/think/cache/driver/File.php +++ b/core/library/think/cache/driver/File.php @@ -69,19 +69,17 @@ class File $name = md5($name); if ($this->options['cache_subdir']) { // 使用子目录 - $dir = ''; - $len = $this->options['path_level']; - for ($i = 0; $i < $len; $i++) { - $dir .= $name{$i} . DS; - } - if (!is_dir($this->options['path'] . $dir)) { - mkdir($this->options['path'] . $dir, 0755, true); - } - $filename = $dir . $this->options['prefix'] . $name . '.php'; - } else { - $filename = $this->options['prefix'] . $name . '.php'; + $name = substr($md5, 0, 2) . DS . substr($md5, 2); } - return $this->options['path'] . $filename; + if ($this->options['prefix']) { + $name = $this->options['prefix'] . DS . $name; + } + $filename = $this->options['path'] . $name . '.php'; + $dir = dirname($filename); + if (!is_dir($dir)) { + mkdir($dir, 0755, true); + } + return $filename; } /** @@ -163,17 +161,16 @@ class File * @access public * @param string $name 缓存变量名 * @param int $step 步长 - * @param int $expire 有效时间 0为永久 * @return false|int */ - public function inc($name, $step = 1, $expire = null) + public function inc($name, $step = 1) { if ($this->has($name)) { $value = $this->get($name) + $step; } else { $value = $step; } - return $this->set($name, $value, $expire) ? $value : false; + return $this->set($name, $value, 0) ? $value : false; } /** @@ -181,17 +178,16 @@ class File * @access public * @param string $name 缓存变量名 * @param int $step 步长 - * @param int $expire 有效时间 0为永久 * @return false|int */ - public function dec($name, $step = 1, $expire = null) + public function dec($name, $step = 1) { if ($this->has($name)) { $value = $this->get($name) - $step; } else { $value = $step; } - return $this->set($name, $value, $expire) ? $value : false; + return $this->set($name, $value, 0) ? $value : false; } /** diff --git a/core/library/think/cache/driver/Lite.php b/core/library/think/cache/driver/Lite.php index e83f73e4..41c94d06 100644 --- a/core/library/think/cache/driver/Lite.php +++ b/core/library/think/cache/driver/Lite.php @@ -118,17 +118,16 @@ class Lite * @access public * @param string $name 缓存变量名 * @param int $step 步长 - * @param int $expire 有效时间 0为永久 * @return false|int */ - public function inc($name, $step = 1, $expire = null) + public function inc($name, $step = 1) { if ($this->has($name)) { $value = $this->get($name) + $step; } else { $value = $step; } - return $this->set($name, $value, $expire) ? $value : false; + return $this->set($name, $value, 0) ? $value : false; } /** @@ -136,17 +135,16 @@ class Lite * @access public * @param string $name 缓存变量名 * @param int $step 步长 - * @param int $expire 有效时间 0为永久 * @return false|int */ - public function dec($name, $step = 1, $expire = null) + public function dec($name, $step = 1) { if ($this->has($name)) { $value = $this->get($name) - $step; } else { $value = $step; } - return $this->set($name, $value, $expire) ? $value : false; + return $this->set($name, $value, 0) ? $value : false; } /** diff --git a/core/library/think/cache/driver/Memcache.php b/core/library/think/cache/driver/Memcache.php index 44de09b4..62f98bce 100644 --- a/core/library/think/cache/driver/Memcache.php +++ b/core/library/think/cache/driver/Memcache.php @@ -105,10 +105,9 @@ class Memcache * @access public * @param string $name 缓存变量名 * @param int $step 步长 - * @param int $expire 有效时间 0为永久 * @return false|int */ - public function inc($name, $step = 1, $expire = null) + public function inc($name, $step = 1) { return $this->handler->increment($name, $step); } @@ -118,10 +117,9 @@ class Memcache * @access public * @param string $name 缓存变量名 * @param int $step 步长 - * @param int $expire 有效时间 0为永久 * @return false|int */ - public function dec($name, $step = 1, $expire = null) + public function dec($name, $step = 1) { return $this->handler->decrement($name, $step); } diff --git a/core/library/think/cache/driver/Memcached.php b/core/library/think/cache/driver/Memcached.php index a53533fb..2eec2ea2 100644 --- a/core/library/think/cache/driver/Memcached.php +++ b/core/library/think/cache/driver/Memcached.php @@ -111,10 +111,9 @@ class Memcached * @access public * @param string $name 缓存变量名 * @param int $step 步长 - * @param int $expire 有效时间 0为永久 * @return false|int */ - public function inc($name, $step = 1, $expire = null) + public function inc($name, $step = 1) { return $this->handler->increment($name, $step); } @@ -124,10 +123,9 @@ class Memcached * @access public * @param string $name 缓存变量名 * @param int $step 步长 - * @param int $expire 有效时间 0为永久 * @return false|int */ - public function dec($name, $step = 1, $expire = null) + public function dec($name, $step = 1) { return $this->handler->decrement($name, $step); } diff --git a/core/library/think/cache/driver/Redis.php b/core/library/think/cache/driver/Redis.php index c1749e27..99f9583d 100644 --- a/core/library/think/cache/driver/Redis.php +++ b/core/library/think/cache/driver/Redis.php @@ -111,10 +111,9 @@ class Redis * @access public * @param string $name 缓存变量名 * @param int $step 步长 - * @param int $expire 有效时间 0为永久 * @return false|int */ - public function inc($name, $step = 1, $expire = null) + public function inc($name, $step = 1) { return $this->handler->incrby($name, $step); } @@ -124,10 +123,9 @@ class Redis * @access public * @param string $name 缓存变量名 * @param int $step 步长 - * @param int $expire 有效时间 0为永久 * @return false|int */ - public function dec($name, $step = 1, $expire = null) + public function dec($name, $step = 1) { return $this->handler->decrby($name, $step); } diff --git a/core/library/think/cache/driver/Sqlite.php b/core/library/think/cache/driver/Sqlite.php index 6814773a..a7cbfa01 100644 --- a/core/library/think/cache/driver/Sqlite.php +++ b/core/library/think/cache/driver/Sqlite.php @@ -115,17 +115,16 @@ class Sqlite * @access public * @param string $name 缓存变量名 * @param int $step 步长 - * @param int $expire 有效时间 0为永久 * @return false|int */ - public function inc($name, $step = 1, $expire = null) + public function inc($name, $step = 1) { if ($this->has($name)) { $value = $this->get($name) + $step; } else { $value = $step; } - return $this->set($name, $value, $expire) ? $value : false; + return $this->set($name, $value, 0) ? $value : false; } /** @@ -133,17 +132,16 @@ class Sqlite * @access public * @param string $name 缓存变量名 * @param int $step 步长 - * @param int $expire 有效时间 0为永久 * @return false|int */ - public function dec($name, $step = 1, $expire = null) + public function dec($name, $step = 1) { if ($this->has($name)) { $value = $this->get($name) - $step; } else { $value = $step; } - return $this->set($name, $value, $expire) ? $value : false; + return $this->set($name, $value, 0) ? $value : false; } /** diff --git a/core/library/think/cache/driver/Wincache.php b/core/library/think/cache/driver/Wincache.php index 940ecc4e..e8e79b47 100644 --- a/core/library/think/cache/driver/Wincache.php +++ b/core/library/think/cache/driver/Wincache.php @@ -90,12 +90,11 @@ class Wincache * @access public * @param string $name 缓存变量名 * @param int $step 步长 - * @param int $expire 有效时间 0为永久 * @return false|int */ - public function inc($name, $step = 1, $expire = null) + public function inc($name, $step = 1) { - return wincache_ucache_inc($name, $step, $expire); + return wincache_ucache_inc($name, $step); } /** @@ -103,12 +102,11 @@ class Wincache * @access public * @param string $name 缓存变量名 * @param int $step 步长 - * @param int $expire 有效时间 0为永久 * @return false|int */ - public function dec($name, $step = 1, $expire = null) + public function dec($name, $step = 1) { - return wincache_ucache_dec($name, $step, $expire); + return wincache_ucache_dec($name, $step); } /** diff --git a/core/library/think/cache/driver/Xcache.php b/core/library/think/cache/driver/Xcache.php index 99b01f6b..e58e5102 100644 --- a/core/library/think/cache/driver/Xcache.php +++ b/core/library/think/cache/driver/Xcache.php @@ -90,12 +90,11 @@ class Xcache * @access public * @param string $name 缓存变量名 * @param int $step 步长 - * @param int $expire 有效时间 0为永久 * @return false|int */ - public function inc($name, $step = 1, $expire = null) + public function inc($name, $step = 1) { - return xcache_inc($name, $step, $expire); + return xcache_inc($name, $step); } /** @@ -103,12 +102,11 @@ class Xcache * @access public * @param string $name 缓存变量名 * @param int $step 步长 - * @param int $expire 有效时间 0为永久 * @return false|int */ - public function dec($name, $step = 1, $expire = null) + public function dec($name, $step = 1) { - return xcache_dec($name, $step, $expire); + return xcache_dec($name, $step); } /** diff --git a/core/library/think/db/Connection.php b/core/library/think/db/Connection.php index 2e716b29..38887b09 100644 --- a/core/library/think/db/Connection.php +++ b/core/library/think/db/Connection.php @@ -23,6 +23,13 @@ use think\Exception; use think\exception\PDOException; use think\Log; +/** + * Class Connection + * @package think + * @method Query table(string $table) 指定数据表(含前缀) + * @method Query name(string $name) 指定数据表(不含前缀) + * + */ abstract class Connection { diff --git a/core/library/think/log/driver/File.php b/core/library/think/log/driver/File.php index d1d2852d..be6e1d0f 100644 --- a/core/library/think/log/driver/File.php +++ b/core/library/think/log/driver/File.php @@ -39,9 +39,10 @@ class File public function save(array $log = []) { $now = date($this->config['time_format']); - $destination = $this->config['path'] . date('y_m_d') . '.log'; + $destination = $this->config['path'] . date('Ym') . DS . date('d') . '.log'; - !is_dir($this->config['path']) && mkdir($this->config['path'], 0755, true); + $path = dirname($destination); + !is_dir($path) && mkdir($path, 0755, true); //检测日志文件大小,超过配置大小则备份日志文件重新生成 if (is_file($destination) && floor($this->config['file_size']) <= filesize($destination)) { diff --git a/data/db.tpl b/data/db.tpl new file mode 100644 index 00000000..a0348a58 --- /dev/null +++ b/data/db.tpl @@ -0,0 +1,44 @@ + +// +---------------------------------------------------------------------- + +return array( + // 数据库类型 + 'type' => 'mysql', + // 数据库连接DSN配置 + 'dsn' => '', + // 服务器地址 + 'hostname' => '[hostname]', + // 数据库名 + 'database' => '[database]', + // 数据库用户名 + 'username' => '[username]', + // 数据库密码 + 'password' => '[password]', + // 数据库连接端口 + 'hostport' => '[hostport]', + // 数据库连接参数 + 'params' => [], + // 数据库编码默认采用utf8 + 'charset' => 'utf8', + // 数据库表前缀 + 'prefix' => '[prefix]', + // 数据库调试模式 + 'debug' => false, + // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) + 'deploy' => 0, + // 数据库读写是否分离 主从式有效 + 'rw_separate' => false, + // 读写分离后 主服务器数量 + 'master_num' => 1, + // 指定从服务器序号 + 'slave_no' => '', + 'fields_strict' => false, + // 开启自动写入时间戳字段 + 'auto_timestamp' => true, +); \ No newline at end of file diff --git a/data/sql.sql b/data/sql.sql index df65014c..4192a2e0 100644 --- a/data/sql.sql +++ b/data/sql.sql @@ -1191,12 +1191,11 @@ CREATE TABLE `sent_member` ( `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '会员状态', PRIMARY KEY (`uid`), KEY `status` (`status`) -) ENGINE=MyISAM AUTO_INCREMENT=25 DEFAULT CHARSET=utf8 COMMENT='会员表'; +) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='会员表'; -- ----------------------------- -- Records of `sent_member` -- ----------------------------- -INSERT INTO `sent_member` VALUES ('1', 'admin', 'e927747ef39033eca386584ef290949c', '系统管理员', 'admin@admin.com', '', '1', '0000-00-00', '707479167', '0', '测试用户签名', '0', '0', '0', '0', 'YsIplN', '132', '0', '1455846185', '2130706433', '1467077781', '1'); -- ----------------------------- -- Table structure for `sent_member_extend`