IndexController.php
5.3 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?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()
{
$map['id']=['in','86,72'];
$top=DB::connect('rds1')->name('arctype')->field('id,typename')->where($map)->select();
$this->assign('top',$top);
return $this->fetch(':index');
}
public function getMiddle(){
$id=input('topid');
$map['reid']=$id;
$middle=DB::connect('rds1')->name('arctype')->field('id,typename')->where($map)->select();
$this->success('','',$middle);
}
public function getThird(){
$id=input('middleid');
$map['reid']=$id;
$middle=DB::connect('rds1')->name('arctype')->field('id,typename')->where($map)->select();
$this->success('','',$middle);
}
public function getSecond(){
}
public function caiji(){
$param=$this->request->param('url');
if (empty($param)){
$this->error('请输入网址!');
}
$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){
if (empty($item['content'])){
$this->error('无法获取相关内容,请检查链接可用性。','/','','10');
}
$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());
//按照织梦规则进行存储
//判断要存储的栏目位置
$top_id=input('top_id');
$middle_id=input('middle_id');
$third_id=input('third_id');
if (empty($middle_id)||empty($middle_id)){
$this->error('请输入您的目标栏目!');
}
if (empty($third_id)){
$type_id=$middle_id;
}
$insert['typeid']=$type_id;
$insert['channel']=1;
$insert['senddate']=time();
$insert['sortrank']=time();
$insert['mid']=1;
DB::connect('rds1')->name('arctiny')->insert($insert);
$max_id=DB::connect('rds1')->name('archives')->max('id');
$insert_arc['id']=$max_id+1;
$insert_arc['typeid']=$type_id;
$insert_arc['ismake']=1;
$insert_arc['channel']=1;
$insert_arc['click']=rand(50,100);
$insert_arc['title']=$image->all()[0]['header'];
$insert_arc['writer']='admin';
$insert_arc['source']='微信文章';
$insert_arc['pubdate']=time();
$insert_arc['senddate']=time();
$insert_arc['mid']=1;
$insert_arc['keywords']='天津协和干细胞';
$insert_arc['description']=$image->all()[0]['header'];
$arc_id=DB::connect('rds1')->name('archives')->insertGetId($insert_arc);
$insert_info['aid']=$insert_arc['id'];
$insert_info['typeid']=$type_id;
$insert_info['body']=$image->all()[0]['content'];
$insert_info['userip']=get_client_ip();
$result=DB::connect('rds1')->name('addonarticle')->insert($insert_info);
dump($result);
$id=db('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');
}
}