diff --git "a/blog\345\220\216\345\217\260/.example.env" "b/blog\345\220\216\345\217\260/.example.env" new file mode 100644 index 0000000000000000000000000000000000000000..c27f74caea59e0bc78bae1941793a6ac34c85a9c --- /dev/null +++ "b/blog\345\220\216\345\217\260/.example.env" @@ -0,0 +1 @@ +APP_DEBUG = true [APP] DEFAULT_TIMEZONE = Asia/Shanghai [DATABASE] TYPE = mysql HOSTNAME = 127.0.0.1 DATABASE = test USERNAME = username PASSWORD = password HOSTPORT = 3306 CHARSET = utf8 DEBUG = true [LANG] default_lang = zh-cn \ No newline at end of file diff --git "a/blog\345\220\216\345\217\260/.gitignore" "b/blog\345\220\216\345\217\260/.gitignore" new file mode 100644 index 0000000000000000000000000000000000000000..d465120e74b813c80d55c418ed3cab757a22033c --- /dev/null +++ "b/blog\345\220\216\345\217\260/.gitignore" @@ -0,0 +1,5 @@ +/.idea +/.vscode +/vendor +*.log +.env \ No newline at end of file diff --git "a/blog\345\220\216\345\217\260/.travis.yml" "b/blog\345\220\216\345\217\260/.travis.yml" new file mode 100644 index 0000000000000000000000000000000000000000..36f7b6f90dafe374d0eca306886df83f09ff13a9 --- /dev/null +++ "b/blog\345\220\216\345\217\260/.travis.yml" @@ -0,0 +1,42 @@ +sudo: false + +language: php + +branches: + only: + - stable + +cache: + directories: + - $HOME/.composer/cache + +before_install: + - composer self-update + +install: + - composer install --no-dev --no-interaction --ignore-platform-reqs + - zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Core.zip . + - composer require --update-no-dev --no-interaction "topthink/think-image:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-migration:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-captcha:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-mongo:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-worker:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-helper:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-queue:^1.0" + - composer require --update-no-dev --no-interaction "topthink/think-angular:^1.0" + - composer require --dev --update-no-dev --no-interaction "topthink/think-testing:^1.0" + - zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Full.zip . + +script: + - php think unit + +deploy: + provider: releases + api_key: + secure: TSF6bnl2JYN72UQOORAJYL+CqIryP2gHVKt6grfveQ7d9rleAEoxlq6PWxbvTI4jZ5nrPpUcBUpWIJHNgVcs+bzLFtyh5THaLqm39uCgBbrW7M8rI26L8sBh/6nsdtGgdeQrO/cLu31QoTzbwuz1WfAVoCdCkOSZeXyT/CclH99qV6RYyQYqaD2wpRjrhA5O4fSsEkiPVuk0GaOogFlrQHx+C+lHnf6pa1KxEoN1A0UxxVfGX6K4y5g4WQDO5zT4bLeubkWOXK0G51XSvACDOZVIyLdjApaOFTwamPcD3S1tfvuxRWWvsCD5ljFvb2kSmx5BIBNwN80MzuBmrGIC27XLGOxyMerwKxB6DskNUO9PflKHDPI61DRq0FTy1fv70SFMSiAtUv9aJRT41NQh9iJJ0vC8dl+xcxrWIjU1GG6+l/ZcRqVx9V1VuGQsLKndGhja7SQ+X1slHl76fRq223sMOql7MFCd0vvvxVQ2V39CcFKao/LB1aPH3VhODDEyxwx6aXoTznvC/QPepgWsHOWQzKj9ftsgDbsNiyFlXL4cu8DWUty6rQy8zT2b4O8b1xjcwSUCsy+auEjBamzQkMJFNlZAIUrukL/NbUhQU37TAbwsFyz7X0E/u/VMle/nBCNAzgkMwAUjiHM6FqrKKBRWFbPrSIixjfjkCnrMEPw= + file: + - ThinkPHP_Core.zip + - ThinkPHP_Full.zip + skip_cleanup: true + on: + tags: true diff --git "a/blog\345\220\216\345\217\260/LICENSE.txt" "b/blog\345\220\216\345\217\260/LICENSE.txt" new file mode 100644 index 0000000000000000000000000000000000000000..574a39c401ff71ffcb90d15edb906b8046c7661b --- /dev/null +++ "b/blog\345\220\216\345\217\260/LICENSE.txt" @@ -0,0 +1,32 @@ + +ThinkPHP遵循Apache2开源协议发布,并提供免费使用。 +版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn) +All rights reserved。 +ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。 + +Apache Licence是著名的非盈利开源组织Apache采用的协议。 +该协议和BSD类似,鼓励代码共享和尊重原作者的著作权, +允许代码修改,再作为开源或商业软件发布。需要满足 +的条件: +1. 需要给代码的用户一份Apache Licence ; +2. 如果你修改了代码,需要在被修改的文件中说明; +3. 在延伸的代码中(修改和有源代码衍生的代码中)需要 +带有原来代码中的协议,商标,专利声明和其他原来作者规 +定需要包含的说明; +4. 如果再发布的产品中包含一个Notice文件,则在Notice文 +件中需要带有本协议内容。你可以在Notice中增加自己的 +许可,但不可以表现为对Apache Licence构成更改。 +具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0 + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git "a/blog\345\220\216\345\217\260/README.md" "b/blog\345\220\216\345\217\260/README.md" new file mode 100644 index 0000000000000000000000000000000000000000..2929dad091236d93f73380bd02d6a0bbb58b5b2f --- /dev/null +++ "b/blog\345\220\216\345\217\260/README.md" @@ -0,0 +1,56 @@ +ThinkPHP 6.0 +=============== + +> 运行环境要求PHP7.1+,兼容PHP8.0。 + +[官方应用服务市场](https://market.topthink.com) | [`ThinkAPI`——官方统一API服务](https://docs.topthink.com/think-api) + +ThinkPHPV6.0版本由[亿速云](https://www.yisu.com/)独家赞助发布。 + +## 主要新特性 + +* 采用`PHP7`强类型(严格模式) +* 支持更多的`PSR`规范 +* 原生多应用支持 +* 更强大和易用的查询 +* 全新的事件系统 +* 模型事件和数据库事件统一纳入事件系统 +* 模板引擎分离出核心 +* 内部功能中间件化 +* SESSION/Cookie机制改进 +* 对Swoole以及协程支持改进 +* 对IDE更加友好 +* 统一和精简大量用法 + +## 安装 + +~~~ +composer create-project topthink/think tp 6.0.* +~~~ + +如果需要更新框架使用 +~~~ +composer update topthink/framework +~~~ + +## 文档 + +[完全开发手册](https://www.kancloud.cn/manual/thinkphp6_0/content) + +## 参与开发 + +请参阅 [ThinkPHP 核心框架包](https://github.com/top-think/framework)。 + +## 版权信息 + +ThinkPHP遵循Apache2开源协议发布,并提供免费使用。 + +本项目包含的第三方源码和二进制文件之版权信息另行标注。 + +版权所有Copyright © 2006-2020 by ThinkPHP (http://thinkphp.cn) + +All rights reserved。 + +ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。 + +更多细节参阅 [LICENSE.txt](LICENSE.txt) diff --git "a/blog\345\220\216\345\217\260/app/admin/common.php" "b/blog\345\220\216\345\217\260/app/admin/common.php" new file mode 100644 index 0000000000000000000000000000000000000000..124361568ff89529382ad44b04b53d6fd7543152 --- /dev/null +++ "b/blog\345\220\216\345\217\260/app/admin/common.php" @@ -0,0 +1,2 @@ + $categoryList]); + } + + public function addSave() + { + $params = Request::param(); + $validate = Validate::rule([ + 'admin_name|管理员名称' => 'require|min:2|max:50', + 'admin_email|管理员邮箱' => 'require|min:1|max:100', + 'admin_password|密码' => 'require|min:6|max:20', + 'admin_password2|再次输入密码' => 'require|min:6|max:20', + ]); + if (!$validate->check($params)) { + echo $validate->getError(); + exit(); + } + if ($params['admin_password'] !== $params['admin_password2']) { + return View::fetch('public/tips_error', [ + 'message' => '两次密码输入不一致。', + ]); + } + + $params['add_time'] = time(); + $params['update_time'] = time(); + $params['admin_password'] = AdminModel::encrypt($params['admin_password']); + + $result = AdminModel::create($params); + + return View::fetch('public/tips', ['result' => $result]); + } + + // 编辑管理员 + public function edit() + { + $adminId = Request::param("admin_id"); + $validate = Validate::rule([ + 'admin_id|管理员id' => 'require|between:1,' . PHP_INT_MAX, + ]); + if (!$validate->check(['admin_id' => $adminId])) { + echo $validate->getError(); + exit(); + } + + $admin = AdminModel::find($adminId); + if (!$admin) { + echo '管理员不存在'; + exit(); + } + return View::fetch('', ['admin' => $admin]); + } + + // 保存数据 + public function editSave() + { + $params = Request::param(); + $validate = Validate::rule([ + 'admin_name|管理员名称' => 'require|min:2|max:50', + 'admin_email|管理员邮箱' => 'require|min:1|max:100', + 'admin_password|密码' => 'min:6|max:20', + 'admin_password2|再次输入密码' => 'min:6|max:20', + ]); + if (!$validate->check($params)) { + echo $validate->getError(); + exit(); + } + if ($params['admin_password'] + && ($params['admin_password'] !== $params['admin_password2'])) { + return View::fetch('public/tips_error', [ + 'message' => '两次密码输入不一致。', + ]); + } + + // update + // 查找出对应的管理员信息 + $admin = AdminModel::find($params['admin_id']); + if (!$admin) { + echo '管理员不存在'; + exit(); + } + $admin['admin_name'] = $params['admin_name']; + $admin['admin_email'] = $params['admin_email']; + $admin['admin_password'] = AdminModel::encrypt($params['admin_password']); + $admin['update_time'] = time(); + $result = $admin->save(); + + return View::fetch('public/tips', [ + 'result' => $result, + ]); + } + + // 管理员删除 + public function delete() + { + $adminId = Request::param("admin_id"); + $validate = Validate::rule([ + 'admin_id|管理员id' => 'require|between:1,' . PHP_INT_MAX, + ]); + if (!$validate->check(['admin_id' => $adminId])) { + echo $validate->getError(); + exit(); + } + + $result = AdminModel::destroy($adminId); + return View::fetch('public/tips', ['result' => $result]); + } +} diff --git "a/blog\345\220\216\345\217\260/app/admin/controller/Article.php" "b/blog\345\220\216\345\217\260/app/admin/controller/Article.php" new file mode 100644 index 0000000000000000000000000000000000000000..34e78cd2f745e0b00c9ee74181c4e5297fcbedf1 --- /dev/null +++ "b/blog\345\220\216\345\217\260/app/admin/controller/Article.php" @@ -0,0 +1,128 @@ + $categoryList]); + } + + public function addSave() + { + $params = Request::param(); + $validate = Validate::rule([ + 'article_title|文章标题' => 'require|min:5|max:50', + 'intro|文章简介' => 'require|min:5|max:100', + 'content|文章内容' => 'require|min:10|max:20000', + 'category_id|文章分类' => 'require|between:1,' . PHP_INT_MAX + ]); + if (!$validate->check($params)) { + echo $validate->getError(); + exit(); + } + + $params['add_time'] = time(); + $params['update_time'] = time(); + $result = ArticleModel::create($params); + + return View::fetch('public/tips', [ + 'result' => $result, + 'url' => '/index.php?s=admin/article/index' + ]); + } + + // 编辑文章 + public function edit() + { + $articleId = Request::param("article_id"); + $validate = Validate::rule([ + 'article_id|文章id' => 'require|between:1,' . PHP_INT_MAX, + ]); + if (!$validate->check(['article_id' => $articleId])) { + echo $validate->getError(); + exit(); + } + + $article = ArticleModel::find($articleId); + if (!$article) { + echo '文章不存在'; + exit(); + } + $categoryList = CategoryModel::getAllPreKey(); + return View::fetch('', ['article' => $article, 'categoryList' => $categoryList]); + } + + // 保存数据 + public function editSave() + { + $params = Request::param(); + $validate = Validate::rule([ + 'article_id|文章id' => 'require|between:1,' . PHP_INT_MAX, + 'article_title|文章标题' => 'require|min:5|max:50', + 'intro|文章简介' => 'require|min:5|max:100', + 'content|文章内容' => 'require|min:10|max:20000', + 'category_id|文章分类' => 'require|between:1,' . PHP_INT_MAX + ]); + if (!$validate->check($params)) { + echo $validate->getError(); + exit(); + } + + // update + // 查找出对应的文章信息 + $article = ArticleModel::find($params['article_id']); + if (!$article) { + echo '文章不存在'; + exit(); + } + $article['article_title'] = $params['article_title']; + $article['intro'] = $params['intro']; + $article['content'] = $params['content']; + $article['category_id'] = $params['category_id']; + $article['update_time'] = time(); + $result = $article->save(); + + return View::fetch('public/tips', [ + 'result' => $result, + 'url' => '/index.php?s=admin/article/index' + ]); + } + + // 文章删除 + public function delete() + { + $articleId = Request::param("article_id"); + $validate = Validate::rule([ + 'article_id|文章id' => 'require|between:1,' . PHP_INT_MAX, + ]); + if (!$validate->check(['article_id' => $articleId])) { + echo $validate->getError(); + exit(); + } + + $result = ArticleModel::destroy($articleId); + return View::fetch('public/tips', ['result' => $result]); + } +} diff --git "a/blog\345\220\216\345\217\260/app/admin/controller/Category.php" "b/blog\345\220\216\345\217\260/app/admin/controller/Category.php" new file mode 100644 index 0000000000000000000000000000000000000000..ddd173425e85e1a5e8905db27d592849b4e99063 --- /dev/null +++ "b/blog\345\220\216\345\217\260/app/admin/controller/Category.php" @@ -0,0 +1,147 @@ + 'require|min:2|max:45', + 'category_desc|分类描述' => 'require|min:10|max:255', + ]); + if (!$validate->check($params)) { + echo $validate->getError(); + exit(); + } + + if (CategoryModel::getByCategoryName($params['category_name'])) { + echo '分类已经存在,请用其他分类名。'; + echo '返回上一页'; + exit(); + } + + // 插入数据 + // 连接数据库(TP做好了) + // 新建一个模型 + // 模型操作增加 + $params['add_time'] = time(); + $params['update_time'] = time(); + $result = CategoryModel::create($params); + + return View::fetch('public/tips', ['result' => $result]); + } + + // 编辑分类 + public function edit() + { + // 整出视图, + // 查询出要编辑的分类信息 + // 获取参数category_id + $categoryId = Request::param("category_id"); + $validate = Validate::rule([ + 'category_id|分类id' => 'require|between:1,' . PHP_INT_MAX, + ]); + if (!$validate->check(['category_id' => $categoryId])) { + echo $validate->getError(); + exit(); + } + + $category = CategoryModel::find($categoryId); + if (!$category) { + echo '分类不存在'; + exit(); + } + + return View::fetch('', ['category' => $category]); + } + + // 保存数据 + public function editSave() + { + $params = Request::param(); // 获取参数 + $validate = Validate::rule([ + 'category_id|分类id' => 'require|between:1,' . PHP_INT_MAX, + 'category_name|分类名称' => 'require|min:2|max:45', + 'category_desc|分类描述' => 'require|min:10|max:255', + ]); + if (!$validate->check($params)) { + echo $validate->getError(); + exit(); + } + // update + // 查找出对应的分类信息 + $category = CategoryModel::find($params['category_id']); + if (!$category) { + echo '分类不存在'; + exit(); + } + $category['category_name'] = $params['category_name']; + $category['category_desc'] = $params['category_desc']; + $category['update_time'] = time(); + $result = $category->save(); + + return View::fetch('public/tips', ['result' => $result]); + } + + // 分类删除 + public function delete() + { + $categoryId = Request::param("category_id"); + $validate = Validate::rule([ + 'category_id|分类id' => 'require|between:1,' . PHP_INT_MAX, + ]); + if (!$validate->check(['category_id' => $categoryId])) { + echo $validate->getError(); + exit(); + } + + // 判断是否有文章? + $article = ArticleModel::where('category_id', '=', $categoryId)->find(1); + if ($article) { + echo '分类下有文章,请先删除相关文章。'; + echo '返回上一页'; + exit(); + } + + $result = CategoryModel::destroy($categoryId); + + return View::fetch('public/tips', ['result' => $result]); + } +} diff --git "a/blog\345\220\216\345\217\260/app/admin/controller/Comment.php" "b/blog\345\220\216\345\217\260/app/admin/controller/Comment.php" new file mode 100644 index 0000000000000000000000000000000000000000..b1fa449d8ba79a4fdd05c02ebdb3874f318a1181 --- /dev/null +++ "b/blog\345\220\216\345\217\260/app/admin/controller/Comment.php" @@ -0,0 +1,118 @@ +select(); + + View::assign('commentList', $commentList); + View::assign('status', $status); + return View::fetch(); + } + + // 回收站 + public function garbage() + { + $commentId = Request::param("comment_id"); + $validate = Validate::rule([ + 'comment_id|评论id' => 'require|between:1,' . PHP_INT_MAX, + ]); + if (!$validate->check(['comment_id' => $commentId])) { + $data = [ + 'status' => 0, + 'message' => $validate->getError(), + 'data' => [], + ]; + return json($data); + } + + $result = CommentModel::update(['status' => 2,'comment_id' => $commentId]); + if ($result) { + $data = [ + 'status' => 1, + 'message' => '', + 'data' => [ + 'success' => '移入回收站', + ], + ]; + return json($data); + } + + } + + // 恢复 + public function resume() + { + $commentId = Request::param("comment_id"); + $validate = Validate::rule([ + 'comment_id|评论id' => 'require|between:1,' . PHP_INT_MAX, + ]); + if (!$validate->check(['comment_id' => $commentId])) { + $data = [ + 'status' => 0, + 'message' => $validate->getError(), + 'data' => [], + ]; + return json($data); + } + + $result = CommentModel::update(['status' => 1,'comment_id' => $commentId]); + if ($result) { + $data = [ + 'status' => 2, + 'message' => '', + 'data' => [ + 'success' => '恢复', + ], + ]; + return json($data); + } + } + + // 彻底删除 + public function delete() + { + $commentId = Request::param("comment_id"); + $validate = Validate::rule([ + 'comment_id|评论id' => 'require|between:1,' . PHP_INT_MAX, + ]); + if (!$validate->check(['comment_id' => $commentId])) { + $data = [ + 'status' => 0, + 'message' => $validate->getError(), + 'data' => [], + ]; + return json($data); + } + + $result = CommentModel::destroy(['comment_id' => $commentId]); + if ($result) { + $data = [ + 'status' => 3, + 'message' => '', + 'data' => [ + 'success' => '彻底删除', + ], + ]; + return json($data); + } + } +} \ No newline at end of file diff --git "a/blog\345\220\216\345\217\260/app/admin/controller/Index.php" "b/blog\345\220\216\345\217\260/app/admin/controller/Index.php" new file mode 100644 index 0000000000000000000000000000000000000000..677cfdd769a13e3a88e5ce221c799c49820d1cae --- /dev/null +++ "b/blog\345\220\216\345\217\260/app/admin/controller/Index.php" @@ -0,0 +1,12 @@ + 'require|min:1|max:100', + 'admin_password|密码' => 'require|min:6|max:20', + 'verify_code|验证码' => 'require|min:4|max:4', + ]); + if (!$validate->check($params)) { + echo $validate->getError(); + exit(); + } + session_start(); + if ($_SESSION['verify_code'] != $params['verify_code']) { + return View::fetch('public/tips_error', ['message' => '验证码不对']); + } + + $admin = AdminModel::where("admin_email", '=', $params['admin_email'])->find(); + $result = false; + if ($admin && AdminModel::checkPassword($params['admin_password'], $admin['admin_password'])) { + session("admin_email", $admin['admin_email']); + session("admin_name", $admin['admin_name']); + $result = true; + } + + return View::fetch('', ['result' => $result]); + } + + public function logout() + { + session("admin_name", null); + session("admin_email", null); + + return View::fetch(''); + } + + public function verifyCode() + { + session_start(); + + $image = \imagecreate(58, 25); // 创建一张图片 + $white = \imagecolorallocate($image, 255, 255, 255);// 创建背景为白色 + + $verifyCode = ''; + for ($i = 1; $i <= 4; $i++) { + $str = mt_rand(0, 9); // 要插入的字符串 + $font = 4; // 字体大小,如果 font 是 1,2,3,4 或 5,则使用内置字体。 + $x = 2 + ($i - 1) * 15; // 左偏移量,每画1个,左偏移量就加大一些。 + $y = 5; // 上偏移量 + $color = \imagecolorallocate($image, 255, 192, 203); // 设置一个浅粉色 + \imagestring($image, $font, $x, $y, $str, $color); // 将字符串画到图片上 + + $verifyCode .= $str; + } + $_SESSION['verify_code'] = $verifyCode; + + header("Content-type: image/png"); + \imagepng($image); // 以 PNG 格式将图像输出到浏览器 + \imagedestroy($image); // 销毁一图像, 释放资源 + } +} \ No newline at end of file diff --git "a/blog\345\220\216\345\217\260/app/admin/controller/User.php" "b/blog\345\220\216\345\217\260/app/admin/controller/User.php" new file mode 100644 index 0000000000000000000000000000000000000000..46e657275c02150fc8716992f32083760822337d --- /dev/null +++ "b/blog\345\220\216\345\217\260/app/admin/controller/User.php" @@ -0,0 +1,17 @@ +pathinfo())) { + // 检测是否有登录,如果没有登录,调整到登录页面 + if (empty(session("admin_email"))) { + return redirect('/index.php?s=admin/login/index'); + } + } + $response = $next($request); + return $response; + } + + public function end(Response $response) + { + + } +} \ No newline at end of file diff --git "a/blog\345\220\216\345\217\260/app/admin/view/admin/add.phtml" "b/blog\345\220\216\345\217\260/app/admin/view/admin/add.phtml" new file mode 100644 index 0000000000000000000000000000000000000000..2a78a84cb877359dcdcac80282c968aefa79caaf --- /dev/null +++ "b/blog\345\220\216\345\217\260/app/admin/view/admin/add.phtml" @@ -0,0 +1,40 @@ + + +
非常日记后台管理
+请输入账号和密码
+ +