IndexController.php
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\HomeBaseController;
use EasyWeChat\Foundation\Application;
use QL\QueryList;
use think\Db;
class IndexController extends HomeBaseController
{
protected $abc;
public function index()
{
return $this->fetch(':index');
}
public function caiji(){
$param=$this->request->param('url');
dump($param);
$rules1 = array(
//采集标题
'header' => array(':header','text'),
//采集文章主体内容
'content' => ['#js_content','html']
);
//获取网页链接
$param= htmlspecialchars_decode($param);
$html=file_get_contents("$param");
$html =str_replace("data-src","src",$html);
// echo $html;
//抓取网页信息
$image = QueryList::html($html)
->rules($rules1)
->query()
->getData(function ($item){
$content = QueryList::html($item['content']);
$content->find('section:last')->remove();
$content->find('section:last')->remove();
$content->find('section:last')->remove();
$content->find('section:last')->remove();
$content->find('section:last')->remove();
$content->find('section:last')->remove();
$content->find('img')->map(function($img){
$src = $img->src;
$localSrc = 'upload/image/'.md5($src).'.jpg';
$imageUrl = 'image/'.md5($src).'.jpg';
$stream = file_get_contents($src);
file_put_contents($localSrc,$stream);
$img->attr('width','100%');
$img->attr('src',cmf_get_image_preview_url($imageUrl));
});
$item['content'] = $content->find('')->html();
return $item;
});
// var_dump($image->all());
$id=Db::name('web')->insertGetId(['url'=>$param,'title'=>$image->all()[0]['header'],'create_time'=>time(),'more'=>$image->all()[0]['content']]);
$this->redirect('portal/index/web',['id'=>$id]);
}
public function web(){
$id=$this->request->param('id',0,'intval');
$data=Db::name('web')->where('id',$id)->find();
$this->assign('list',$data);
return $this->fetch(':web');
}
}