Starclass.php
8.84 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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<?php
use Action\AbstractAction;
use Guang\StarClassModel;
use LibModels\Wap\Guang\StarClassData;
use Plugin\Helpers;
/**
* 星潮教室
* Class StarClassController
*/
class StarClassController extends AbstractAction
{
private $_isApp = false;
/**
* 星潮教室首页
*/
public function indexAction()
{
//获取uid
$uid = $this->getLoggedUid() ? $this->getLoggedUid() : $this->getCookie('uid');
if (!$this->_isApp) {
if ($uid) {
$this->setCookie('uid', $uid);
}
}else{
$this->setCookie('isApp',true);
if ($uid) {
$this->setCookie('uid', $uid);
}
}
//设置头部公共导航
$app = $this->getCookie('isApp', false);
$isApp = $app || $this->_isApp;
if (!$isApp) {
$this->setNavHeader('星潮教室', true, false);
}
$this->setTitle('星潮教室', false, '');
//调用模型获得星潮教室首页数据
$data = StarClassModel::getStarClass($uid, $isApp);
//渲染模板
$this->_view->display('index', array(
'trendClassHome' => $data,
'trendClassHomePage' => true
)
);
}
/**
* 星潮教室-星专题
*/
public function specialAction()
{
//获取uid
$isApp = $this->getCookie('isApp', false);
if (!$isApp) {
//设置头部公共导航
$this->setNavHeader('星潮教室', true, false);
}
$this->setTitle('星潮教室', false, '');
//调用模型获得星专题数据
$data = StarClassModel::getspecial($isApp);
//渲染模板
$this->_view->display('subject', array(
'trendClassSubject' => $data,
'trendClassHomePage' => true
));
}
/**
* 星潮教室-星搭配
*/
public function collocationAction()
{
//获取uid
$isApp = $this->getCookie('isApp', false);
if (!$isApp) {
//设置头部公共导航
$this->setNavHeader('星潮教室', true, false);
}
$this->setTitle('星潮教室', false, '');
//调用模板获得星搭配数据
$data = StarClassModel::getCollocation();
//渲染模板
$this->_view->display('collocation', array(
'trendClassCollocation' => $data,
'trendClassCollocationPage' => true
));
}
/**
* 星潮教室-星搭配文章 ajax请求
*/
public function ajaxCollocationAction()
{
if (!$this->isAjax()) {
return;
}
//获得必要参数
$page = $this->get('page',1);
$isApp = $this->getCookie('isApp', false);
$uid = $this->getCookie('uid', false);
//调取模型获得星搭配文章
$data = StarClassModel::ajaxCollocation($page, $uid, $isApp, $limit = 20);
//返回数据到页面,没有数据返回空格
if (isset($data) && !empty($data)) {
$this->_view->display('collocation-list',$data);
}else{
echo ' ';
}
}
/**
* 星潮教室-签到-Top100排行榜
*/
public function topAction()
{
//获取uid
$isApp = $this->getCookie('isApp', false);
$uid = $this->getCookie('uid', false);
if (!$isApp) {
//设置头部公共导航(此处返回键调转星潮教室首页)
$url = Helpers::url('/guang/starclass/index');
$this->setNavHeader('星潮粉丝榜', $url, false);
}
$this->setTitle('星潮粉丝榜', false, '');
//根据客户端类型,进行未登录跳转
if (!$uid) {
$refer = Helpers::url('/guang/starclass/top');
if (!$isApp) {
$this->go(Helpers::url('/signin.html', array('refer' => $refer)));
} else {
$referEncode = strtr($refer, array('/' => '\\/'));
$this->go($refer . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $referEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}');
}
return;
}
//调取模型获得Top100数据
$data = StarClassModel::getTop($uid);
//渲染模板
$this->_view->display('check-in',array(
'trendClassCheckIn'=>$data,
'trendClassTopPage' => true
));
}
/**
* 星潮教室-签到
*/
public function signAction()
{
if(!$this->isAjax()){
return;
}
//根据客户端类型,进行未登录跳转
$isApp = $this->getCookie('isApp', false);
$uid = $this->getCookie('uid', false);
if (!$uid) {
$refer = Helpers::url('/guang/starclass/index');
if (!$isApp) {
$this->echoJson(array('code'=>201,'data'=>Helpers::url('/signin.html', array('refer' => $refer))));
} else {
$referEncode = strtr($refer, array('/' => '\\/'));
$this->echoJson(array('code'=>201,'data'=>$refer . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $referEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}'));
}
return;
}
//调取模型完成签到,并返回数据
$res = StarClassModel::sign($uid);
//输出签到结果到页面
$this->echoJson($res);
}
/**
* 星搭配-文章分享
*/
public function forwardAction()
{
if(!$this->isAjax()){
return;
}
$result = array();
//根据客户端类型,进行未登录跳转
$isApp = $this->getCookie('isApp', false);
$uid = $this->getCookie('uid', false);
if (!$uid) {
$refer = Helpers::url('/guang/starclass/collocation');
if (!$isApp) {
$this->echoJson(array('code'=>201,'data'=>Helpers::url('/signin.html', array('refer' => $refer))));
} else {
$referEncode = strtr($refer, array('/' => '\\/'));
$this->echoJson(array('code'=>201,'data'=>$refer . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $referEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}'));
}
return;
}else{
//调取接口分享文章
$result = StarClassData::forward($uid);
}
$this->echoJson($result);
}
/**
* 星搭配-收藏资讯文章
*/
public function setFavoriteAction()
{
if (!$this->isAjax()) {
return;
}
//根据客户端类型,进行未登录跳转
$uid = $this->getCookie('uid', false);
$isApp = $this->getCookie('isApp', false);
if (!$uid) {
$refer = Helpers::url('/guang/starclass/collocation');;
if (!$isApp) {
$this->echoJson(array('code'=>201,'data'=>Helpers::url('/signin.html', array('refer' => $refer))));
} else {
$referEncode = strtr($refer, array('/' => '\\/'));
$this->echoJson(array('code'=>201,'data'=>$refer . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $referEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}'));
}
return;
}
//获取文章ID,接口Type(fav调取收藏接口,del调取取消收藏接口)
$articleId = $this->post('articleId');
$type = $this->post('type');
if (!isset($articleId) || !isset($type)) {
$this->echoJson(array('code'=>400,'message'=>'参数错误!'));
}
$result = array();
//调取接口进行收藏
$result = StarClassData::setFavorite($articleId, $uid, $type);
if (!empty($result)) {
$this->echoJson($result);
}
}
/**
* 星鲜事-点赞
*/
public function setPraiseAction()
{
if(!$this->isAjax()){
return;
}
//获得客户端ID(点赞不需要登录)
$udid = $this->getUdid();
//获得文章ID
$articleId = $this->post('articleId');
//调取接口点赞
$result = StarClassData::setPraise($articleId, $udid);
$this->echoJson($result);
}
/**
* 检测登录状态
*
* @return int
*/
private function getLoggedUid()
{
// 判断是否是应用访问, 拼接APP需要的URL参数
$this->_isApp = null !== $this->get('app_version');
$uid = false;
if ($this->_isApp) {
$uid = $this->get('uid');
} else {
$uid = $this->getUid(true);
}
return $uid;
}
}