News.class.php
5.67 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
<?php
/**
* 默认控制器
*/
class Controller_News extends Controller_Abstract
{
public function indexAction()
{
$requestTag = trim($this->_request->tag);//标签
$limit = 40;
$tag = $requestTag;
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();
$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 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;
if(empty($brand_ids)|| empty($title) || empty($content) || empty($pics))
{
return $this->returnJson(false, 403, '','参数不能为空');
}
$brand_ids = array_filter(explode(',', $brand_ids));
$pics = array_filter(explode(',', $pics));
$thumb = $pics[0];
list($width, $height, $type, $attr) = getimagesize($thumb);
$thumb_size = json_encode(array('width'=> $width,'height'=> $height));
$data = array('title' => $title, 'content' => $content, 'pics' => implode('|', $pics),'tag'=> $tag,
'thumb' => $thumb, 'thumb_size'=> $thumb_size);
//新建
$id = Facade_News::setInfo($data);
foreach($brand_ids as $brandID)
{
Facade_Brand::setBrandNewsRela($id, $brandID);
}
return $this->returnJson(true, 200, '','发布成功');
}
else
{
return $this->returnJson(false, 403, '','密钥不正确');
}
}
/**
* 详情页
*/
public function detailAction()
{
$id = intval($this->_request->id);
$news = array();
if (empty($id))
{
return $this->_redirect('news/index');
}
$info = Facade_News::getOneById($id);
if (!$info)
{
return $this->_redirect('news/index');
}
if($this->_platform == 'android' || $this->_platform == 'iphone')
{
$exceptTags = array('视频');
$news[] = Facade_News::getSameNewsById($id, $exceptTags);
$news = array_merge($news, Facade_News::getList(array(), 0, 3, $exceptTags));
$news = array_slice(array_filter($news), 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);
$this->_view['info'] = $info;
$this->_view['banners'] = Facade_Index::getIndex(4);
$this->_view['news'] = $news;
}
/**
* 详情页相关新闻
*
* @return json
*/
public function getdetailnewsAction()
{
$id = intval($this->_request->id);
$list = array('recom'=> array(), 'hotVideo'=> array(), 'lastVideo' => array());
$tag = '视频';
$exceptTags = array('手机视频');
$recom = array();
$recom[] = Facade_News::getSameNewsById($id, $exceptTags);
$recom = array_merge($recom, Facade_News::getList(array(), 0, 3, $exceptTags));
$recom = array_slice(array_filter($recom), 0, 3);
$hotVideo = array_values(Facade_News::getListByHits($tag, 0, 5, $exceptTags));
$lastVideo = array_values(Facade_News::getList($tag, 0, 5, $exceptTags));
$list['recom'] = $recom;
$list['hotVideo'] = $hotVideo;
$list['lastVideo'] = $lastVideo;
foreach($list as $key => $listnews)
{
if(!empty($listnews))
{
foreach($listnews as $key2 => $news)
{
//不需要内容
$list[$key][$key2]['content'] = '';
}
}
}
return $this->returnJson(true, 200, $list);
}
}