|
@@ -1,132 +1,3 @@
|
|
|
-<<<<<<< HEAD
|
|
|
-<?php
|
|
|
-
|
|
|
-declare(strict_types=1);
|
|
|
-/**
|
|
|
- * +----------------------------------------------------------------------
|
|
|
- * 后台文章控制制器
|
|
|
- * @author huwhis@163.com
|
|
|
- * @version 0.0.1
|
|
|
- * +----------------------------------------------------------------------
|
|
|
- */
|
|
|
-
|
|
|
-namespace app\sys\controller;
|
|
|
-
|
|
|
-// 引入框架内置类
|
|
|
-use think\facade\View;
|
|
|
-use think\facade\Config;
|
|
|
-
|
|
|
-use app\common\model\Category as CategoryModel;
|
|
|
-use app\common\model\Article as ArticleModel;
|
|
|
-use app\common\service\FileService;
|
|
|
-
|
|
|
-/**
|
|
|
- * 文章管理控制器
|
|
|
- */
|
|
|
-class Article extends Base
|
|
|
-{
|
|
|
- protected $modelName = "Article";
|
|
|
-
|
|
|
- public function index()
|
|
|
- {
|
|
|
- $categories = CategoryModel::select();
|
|
|
-
|
|
|
- $category_tree = list_tree($categories);
|
|
|
-
|
|
|
- $cid = $this->app->request->param('cid');
|
|
|
-
|
|
|
- $params = $this->app->request->param();
|
|
|
-
|
|
|
- $list = ArticleModel::queryPage($params);
|
|
|
-
|
|
|
- View::assign('category_tree', $category_tree);
|
|
|
-
|
|
|
- View::assign('list', $list);
|
|
|
- View::assign('cid', $cid);
|
|
|
- return View::fetch();
|
|
|
- }
|
|
|
-
|
|
|
- public function save($content_type = 0, $id = 0)
|
|
|
- {
|
|
|
- if ($this->app->request->isPost()) {
|
|
|
- $params = $this->app->request->param();
|
|
|
-
|
|
|
- if (!$params['cid']) {
|
|
|
- $this->error('请选择栏目');
|
|
|
- }
|
|
|
- if ($params['title'] == '') {
|
|
|
- $this->error("标题不能为空");
|
|
|
- }
|
|
|
-
|
|
|
- $params['content'] = isset($params['content']) ? $params['content'] : '';
|
|
|
- if ($content_type == 0) {
|
|
|
- $params['content'] = $this->saveRomteImage($params['content']);
|
|
|
- }
|
|
|
-
|
|
|
- $params['keywords'] = str_replace(' ', '', $params['keywords']);
|
|
|
-
|
|
|
- try {
|
|
|
- if ($params['id'] != 0) {
|
|
|
- ArticleModel::update($params);
|
|
|
- } else {
|
|
|
- $params['userid'] = $this->getSysUser()->userid;
|
|
|
- $params['username'] = $this->getSysUser()->nickname;
|
|
|
- unset($params['id']);
|
|
|
- ArticleModel::create($params);
|
|
|
- }
|
|
|
- } catch (\Exception $e) {
|
|
|
- $msg = $e->getMessage();
|
|
|
-
|
|
|
- $this->error("错误提示:" . $msg);
|
|
|
- }
|
|
|
- $this->success('操作成功', (string) url('index?cid=' . $params['cid']));
|
|
|
- } else {
|
|
|
- if ($id) {
|
|
|
- $data = ArticleModel::find($id);
|
|
|
- } else {
|
|
|
- $data = new ArticleModel();
|
|
|
- $data->content_type = $content_type;
|
|
|
- }
|
|
|
-
|
|
|
- $categories = CategoryModel::field('id, parent_id, name')->select();
|
|
|
-
|
|
|
- View::assign('category_tree', list_tree($categories));
|
|
|
- View::assign('data', $data);
|
|
|
-
|
|
|
- $template = $content_type ? 'savemd' : 'save';
|
|
|
-
|
|
|
- return View::fetch($template);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected function saveRomteImage($content)
|
|
|
- {
|
|
|
- $fileService = new FileService();
|
|
|
-
|
|
|
- $content = stripslashes ($content);
|
|
|
- $img_array = [];
|
|
|
- // 匹配所有远程图片
|
|
|
- $pattern = '/src="(http[s]:\/\/.*)"/isU';
|
|
|
- preg_match_all ($pattern,$content,$img_array);
|
|
|
-
|
|
|
- // 删除重复 url
|
|
|
- $img_arrays = array_unique ($img_array[1]);
|
|
|
-
|
|
|
- foreach ($img_arrays as $value) {
|
|
|
- $file = $fileService->downloadUrlImg($value);
|
|
|
-
|
|
|
- $savename = \think\facade\Filesystem::disk('public')->putFile('/', $file);
|
|
|
-
|
|
|
- $filename = Config::get('filesystem.disks.public.url') . '/' . str_replace('\\', '/', $savename);
|
|
|
-
|
|
|
- // dump($filename);
|
|
|
- $content = str_replace($value, $filename, $content);
|
|
|
- }
|
|
|
-
|
|
|
- return $content;
|
|
|
- }
|
|
|
-}
|
|
|
-=======
|
|
|
<?php
|
|
|
|
|
|
declare(strict_types=1);
|
|
@@ -260,4 +131,3 @@ class Article extends Base
|
|
|
return $content;
|
|
|
}
|
|
|
}
|
|
|
->>>>>>> 78b76253c8ce5873016cf837373af5e30ac80c86
|