News.class.php
9.97 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php
/**
* 默认控制器
*/
class Controller_News extends Controller_Abstract
{
public function indexAction()
{
$requestTag = trim($this->_request->tag);//标签
$limit = 24;
$tag = $requestTag;
$exceptTags = array('手机视频');
/*if($this->_platform == 'android' || $this->_platform == 'iphone')
{
$exceptTags = array('视频');
if($requestTag == '视频')
{
$tag = '手机视频';//html5视频为手机视频
}
}
else
{
$exceptTags = array('手机视频');
}*/
$total = Facade_News::getTotal($tag, $exceptTags);
$page = new Lib_Helper_Pagination($total, $limit);
if ($tag)
{
$page->setParames(array('tag' => $requestTag)) ;
}
$tagKeys = Facade_News::$types;
$list = Facade_News::getList($tag, $page->getOffset(), $limit, $exceptTags);
$this->_view['list'] = $list;
$newTags = Facade_News::getTags();
$nums=0;
foreach($newTags as $vo){
$nums+=$vo['num'];
}
$this->_view['nums'] = $nums;
$this->_view['total'] = 0;
$tags = $temp = array();
foreach($newTags as $tag)
{
$temp[$tag['tag']] = $tag;
}
foreach($tagKeys as $tagKey)
{
$tags[$tagKey] = array('tag' => $tagKey, 'num'=> 0);
if(isset($temp[$tagKey]))
{
$tags[$tagKey] = $temp[$tagKey];
}
}
if($this->_platform == 'android' || $this->_platform == 'iphone')
{
$tags['视频'] = $temp['手机视频'];
}
$this->_view['tags'] = $tags;
foreach($this->_view['tags'] as $val)
{
$this->_view['total'] += $val['num'];
}
$page->setOptions(array('afterAppend' => 'setLayout'));
$this->_view['pagination'] = $page->getPagination();
$this->_view['current_tag'] = $requestTag;
}
/**
* 手机端最新资讯
*
*/
public function indexMobileAction()
{
$requestTag = $tag = trim($this->_request->tag);//标签
// $exceptTags = array('视频');
$exceptTags = array('手机视频');
$limit = 8;
$total = Facade_News::getTotal($tag, $exceptTags);
$page = new Lib_Helper_Pagination($total, $limit);
$tagKeys = Facade_News::$types;
$list = Facade_News::getList($tag, $page->getOffset(), $limit, $exceptTags);
$this->_view['list'] = $list;
$newTags = Facade_News::getTags();
$this->_view['total'] = 0;
$tags = $temp = array();
foreach($newTags as $tag)
{
$temp[$tag['tag']] = $tag;
}
foreach($tagKeys as $tagKey)
{
$tags[$tagKey] = array('tag' => $tagKey, 'num'=> 0);
if(isset($temp[$tagKey]))
{
$tags[$tagKey] = $temp[$tagKey];
}
}
// $tags['视频'] = $temp['手机视频'];
$this->_view['tags'] = $tags;
foreach($this->_view['tags'] as $val)
{
$this->_view['total'] += $val['num'];
}
$this->_view['current_tag'] = $requestTag;
$this->_view['isAjax'] = $this->_request->isAjax();
$this->_view['pageTotal'] = $total;
$this->_view['limit'] = $limit;
$this->_view['page'] = $page->getCurrentPage();
}
/**
* 发布资讯
*/
public function publishAction()
{
$secret = $this->_request->secret;
if($secret == SITE_PUBLISH_NEWS_SECRET)
{
$tag_id = $this->_request->tag_id;
if(!isset(Facade_News::$types[$tag_id]))
{
return $this->returnJson(false, 403, '','频道不存在');
}
$tag = Facade_News::$types[$tag_id];
$brand_ids = $this->_request->brand_ids;
$title = $this->_request->title;
$content = $this->_request->content;
$pics = $this->_request->pics;
$thumb = $this->_request->thumb;
$is_video = $this->_request->is_video?1:0;
if(empty($title) || empty($content) || empty($thumb))
{
return $this->returnJson(false, 403, '','参数不能为空');
}
$brand_ids = array_filter(explode(',', $brand_ids));
$pics = array_filter(explode(',', $pics));
list($width, $height, $type, $attr) = getimagesize($thumb);
$thumb_size = json_encode(array('width'=> $width,'height'=> $height));
//是否存在视频
// if($is_video==1)
// {
// $tag = '视频';
// }
/* $videos = array_filter(explode(',', $videos));
$html = '';
foreach($videos as $video)
{
$html = <<<EOT
<object class="content-web-flash" width="700px" height="394px" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
<param value="res_site/swf/YohoodPlayer.swf?url=video_url" name="movie" /><param value="high" name="quality" />
<param value="#ffffff" name="bgcolor" />
<param name="allowFullScreen" value="true" />
<param value="always" name="allowScriptAccess" />
<param value="transparent" name="wmode" />
<embed align="middle" style="width:700px;height:394px;"
allowscriptaccess="always" loop="false" quality="high" src="res_site/swf/YohoodPlayer.swf?url=video_url"
width="0" height="0" />
</object>
EOT;
$html = str_replace('res_site', SITE_RES, $html);
$html = str_replace('video_url', $video, $html);
$content .= '<br/>'.$html;
}*/
$data = array('title' => $title, 'content' => $content, 'pics' => implode('|', $pics),'tag'=> $tag,
'thumb' => $thumb, 'thumb_size'=> $thumb_size,'is_video'=>$is_video);
//新建
$id = Facade_News::setInfo($data);
foreach($brand_ids as $brandID)
{
if(Facade_Brand::getBrandByID($brandID))
{
Facade_Brand::setBrandNewsRela($id, $brandID);
}
}
return $this->returnJson(true, 200, '','发布成功');
}
else
{
return $this->returnJson(false, 403, '','密钥不正确');
}
}
/**
* 获取标签
*
* @return json
*/
public function gettagsAction()
{
$res = array();
foreach(Facade_News::$types as $key=> $name)
{
$res[] = array('id'=> $key, 'name'=> $name);
}
return $this->returnJson(true, 200, $res);
}
/**
* 详情页
*/
public function detailAction()
{
$id = intval($this->_request->id);
$type = $this->_request->get('type','');
$news = array();
if (empty($id))
{
return $this->_redirect('news/index');
}
$info = Facade_News::getOneById($id);
$thumb= Lib_Images::getImageUrl($info['thumb'], 'source','fragmentimg');
if (!$info)
{
return $this->_redirect('news/index');
}
if($this->_platform == 'android' || $this->_platform == 'iphone')
{
//$exceptTags = array('视频');
$exceptTags = array('手机视频');
$temp = Facade_News::getSameNewsById($id, $exceptTags);
$temp2 = Facade_News::getLatestNews(array(), 0, 5, $exceptTags);
unset($temp2[$id]);
if(!empty($temp))
{
$news = array($temp['id'] => $temp);
}
$news = array_slice(array_filter($news + $temp2), 0, 3);
}
$info['title'] = strip_tags($info['title']);
$info['pics'] = array_filter(explode('|', $info['pics']));
$info['thumb'] = Lib_Images::getImageUrl($info['thumb'], 'source','fragmentimg');
//增加浏览量
Facade_News::updateHits($id);
$info = str_replace('<embed align="middle"','<embed align="middle" allowfullscreen="true" ' , $info);
$this->_view['info'] = $info;
$this->_view['banners'] = Facade_Index::getIndex(4);
$this->_view['news'] = $news;
$this->_view['type'] = $type;
$this->_view['thumb'] = $thumb;
}
/**
* 详情页相关新闻
*
* @return json
*/
public function getdetailnewsAction()
{
$id = intval($this->_request->id);
$list = array('recom'=> array(), 'hotVideo'=> array(), 'lastNews' => array());
$tag = '视频';
$exceptTags = array('手机视频');
$recom = array();
$temp = Facade_News::getSameNewsById($id, $exceptTags);
$temp2 = Facade_News::getLatestNews(array(), 0, 5, $exceptTags);
unset($temp2[$id]);
if(!empty($temp))
{
$recom = array($temp['id'] => $temp);
}
$recom = array_slice(array_filter($recom + $temp2), 0, 3);
$hotVideo = array_values(Facade_News::getListByDateHits($tag, 0, 5, $exceptTags));
$lastNews = array_values(Facade_News::getLatestNews('', 0, 5, $exceptTags));
$list['recom'] = $recom;
$list['hotVideo'] = $hotVideo;
$list['lastNews'] = $lastNews;
foreach($list as $key => $listnews)
{
if(!empty($listnews))
{
foreach($listnews as $key2 => $news)
{
//不需要内容
$list[$key][$key2]['content'] = '';
}
}
}
return $this->returnJson(true, 200, $list);
}
public function getwechatsignpackageAction()
{
$signPackage = Lib_Wechat_JSSDK::getSignPackage();
$callback = $this->_request->query('callback', '');
$json = json_encode($signPackage);
header('Content-Type: application/javascript;');
return $callback . '(' . $json . ');';
}
}