|
@@ -13,13 +13,14 @@ 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
|
|
|
{
|
|
@@ -57,12 +58,16 @@ class Article extends Base
|
|
|
}
|
|
|
|
|
|
$params['content'] = isset($params['content']) ? $params['content'] : '';
|
|
|
+ if ($content_type == 0) {
|
|
|
+ $params['content'] = $this->saveRomteImage($params['content']);
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
if ($params['id'] != 0) {
|
|
|
ArticleModel::update($params);
|
|
|
} else {
|
|
|
$params['userid'] = $this->getSysUser()->userid;
|
|
|
- $params['username'] = $this->getSysUser()->username;
|
|
|
+ $params['username'] = $this->getSysUser()->nickname;
|
|
|
unset($params['id']);
|
|
|
ArticleModel::create($params);
|
|
|
}
|
|
@@ -90,4 +95,31 @@ class Article extends Base
|
|
|
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->urlImg($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;
|
|
|
+ }
|
|
|
}
|