添加快捷录入文章
This commit is contained in:
parent
656108fcc9
commit
742e8c7ab2
@ -3,6 +3,7 @@
|
|||||||
namespace app\controller\api;
|
namespace app\controller\api;
|
||||||
|
|
||||||
use app\common\model\user\User;
|
use app\common\model\user\User;
|
||||||
|
use app\common\repositories\article\ArticleRepository;
|
||||||
use app\common\repositories\community\CommunityRepository;
|
use app\common\repositories\community\CommunityRepository;
|
||||||
use app\validate\api\CommunityValidate;
|
use app\validate\api\CommunityValidate;
|
||||||
use crmeb\basic\BaseController;
|
use crmeb\basic\BaseController;
|
||||||
@ -23,6 +24,75 @@ class Upload extends BaseController
|
|||||||
$this->repository = app()->make(CommunityRepository::class);
|
$this->repository = app()->make(CommunityRepository::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function article()
|
||||||
|
{
|
||||||
|
$rand = $this->request->post('rand');
|
||||||
|
if ($rand != md5('qwert12345')) {
|
||||||
|
return app('json')->fail('无效的请求');
|
||||||
|
}
|
||||||
|
$url = $this->request->post('url');
|
||||||
|
$cid = $this->request->post('cid', 20);
|
||||||
|
$parse = parse_url($url);
|
||||||
|
$domain = $parse['scheme'] . '://' . $parse['host'];
|
||||||
|
$html = file_get_contents($url);
|
||||||
|
$title = '';
|
||||||
|
$content = '';
|
||||||
|
$poster = '';
|
||||||
|
$images = [];
|
||||||
|
if (preg_match('/<h2 class="title">\s*(.*?)\s*</ims', $html, $matches)) {
|
||||||
|
$title = $matches[1];
|
||||||
|
}
|
||||||
|
if (preg_match('/<div class="conTxt"(.*?)>\s*(.*?)\s*<\/div>/ims', $html, $matches)) {
|
||||||
|
$content = $matches[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preg_match('/<p.*?>\s*(.*?)\s*<\/p>/ims', $content, $matches)) {
|
||||||
|
$synopsis = $matches[1];
|
||||||
|
}
|
||||||
|
if (preg_match_all('/<img.*?src="(.*?)".*?>/ims', $content, $matches)) {
|
||||||
|
$images = $matches[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var UploadService $uploader */
|
||||||
|
$uploader = UploadService::create();
|
||||||
|
if (!empty($images)) {
|
||||||
|
foreach ($images as $k => $image) {
|
||||||
|
$imageLink = $domain . $image;
|
||||||
|
$stream = file_get_contents($imageLink);
|
||||||
|
if (!$stream) {
|
||||||
|
return app('json')->fail('图片获取出错');
|
||||||
|
}
|
||||||
|
$res = $uploader->to('def')->stream($stream);
|
||||||
|
if ($res === false) {
|
||||||
|
return app('json')->fail($uploader->getError());
|
||||||
|
}
|
||||||
|
$link = tidy_url($uploader->getFileInfo()->filePath);
|
||||||
|
if ($k == 0) {
|
||||||
|
$poster = $link;
|
||||||
|
}
|
||||||
|
$content = str_replace($image, $link, $content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$data = [
|
||||||
|
'cid' => $cid,
|
||||||
|
'title' => $title,
|
||||||
|
'author' => '里海云',
|
||||||
|
'image_input' => $poster,
|
||||||
|
'content' => $content,
|
||||||
|
'synopsis' => empty($synopsis) ? $title : strip_tags($synopsis),
|
||||||
|
'url' => $url,
|
||||||
|
'is_hot' => 0,
|
||||||
|
'is_banner' => 0,
|
||||||
|
'status' => 1,
|
||||||
|
'admin_id' => 6,
|
||||||
|
'mer_id' => 0,
|
||||||
|
];
|
||||||
|
/** @var ArticleRepository $repo */
|
||||||
|
$repo = app()->make(ArticleRepository::class);
|
||||||
|
$repo->create($data);
|
||||||
|
return app('json')->success('保存成功');
|
||||||
|
}
|
||||||
|
|
||||||
public function save()
|
public function save()
|
||||||
{
|
{
|
||||||
$rand = $this->request->post('rand');
|
$rand = $this->request->post('rand');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user