List.php
7.18 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
<?php
use Action\AbstractAction;
use LibModels\Wap\Guang\ListData;
use Plugin\Helpers;
/**
* 逛首页、列表页、编辑页
*/
class ListController extends AbstractAction
{
/**
* 首页
*
* @param int type 分类ID 0:最新,1:话题,2:搭配,3:潮人,4:潮品,5:小贴士
* @param string gender '1,3'表示男,'2,3'表示女
*/
public function indexAction()
{
$this->setTitle('逛');
$this->setNavHeader('逛', true, SITE_MAIN);
$category = ListData::category();
$articleGroup = array();
$uid = $this->getUid();
$udid = $this->getUdid();
$type = $this->get('type', 0);
$gender = $this->get('gender');
// 男
if ($gender === '1,3') {
$articleGroup = ListData::articleGroup($category['data'], '1,3', $uid, $udid);
}
// 女
elseif ($gender === '2,3') {
$articleGroup = ListData::articleGroup($category['data'], '2,3', $uid, $udid);
}
// 所有
else {
$articleGroup = ListData::articleGroup($category['data'], '1,2,3', $uid, $udid);
}
$data = array();
$build = array();
// 模板中使用JS的标识
$data['guangHome'] = true;
// 顶部的分类列表
foreach ($category['data'] as $value) {
$build = array();
$build['typeId'] = $value['id'];
$build['type'] = $value['name'];
$build['focus'] = ($value['id'] == $type);
$data['navs'][] = $build;
}
$data['guang']['swiper'] = array();
$data['guang']['infos'] = array();
foreach ($articleGroup as $id => $value) {
// 判断是否有内容
if (empty($value['list'])) {
continue;
}
// 轮番广告
if ($id == 0) {
$build = array();
foreach ($value['list']['adlist'] as $banner) {
$build['url'] = $banner['url'];
$build['img'] = Helpers::getImageUrl($banner['src'], 830, 327);
$data['guang']['swiper'][] = $build;
}
}
// 内容列表
$build = array();
$build['show'] = ($id == $type);
foreach ($value['list']['artList'] as $article) {
$build['info'][] = Helpers::formatArticle($article, true, false);
}
$data['guang']['infos'][] = $build;
}
// 分页需要参数
$data['guang']['gender'] = $gender;
$this->_view->display('index', $data);
}
/**
* 列表页
*
* @param string tag 标签名称
*/
public function tagAction()
{
$tag = $this->get('query');
$uid = $this->getUid();
$udid = $this->getUdid();
// 标签聚合内容列表
$article = ListData::article('', 0, $uid, $udid, 1, $tag);
// 标签聚合内容不存在, 跳到错误页面
if (empty($article['data']['list']['artList'])) {
$this->error();
}
$this->setTitle($tag);
$this->setNavHeader($tag, true, SITE_MAIN);
$data = array();
// 模板中使用JS的标识
$data['guangList'] = true;
// 构建资讯文章内容
$build = array();
foreach ($article['data']['list']['artList'] as $article) {
$build[] = Helpers::formatArticle($article, true, false);
}
$data['guang']['infos'] = $build;
// 分页需要的参数
$data['guang']['tag'] = $tag;
$this->_view->display('list', $data);
}
/**
* 编辑页
*/
public function editorAction()
{
$id = $this->get('id');
// 获取作者信息
$author = ListData::author($id);
// 作者信息不存在,则跳到错误页面
if (!isset($author['name'])) {
$this->error();
}
$this->setTitle('编辑简介');
$this->setNavHeader('编辑简介', true, SITE_MAIN);
$uid = $this->getUid();
$udid = $this->getUdid();
$data = array();
// 模板中使用JS的标识
$data['guangList'] = true;
// 作者信息
$data['author'] = array();
$data['author']['avatar'] = Helpers::getImageUrl($author['avatar'], 100, 100);
$data['author']['name'] = $author['name'];
$data['author']['info'] = $author['author_desc'];
$data['author']['id'] = $id;
// 标签聚合内容列表
$article = ListData::article('', 0, $uid, $udid, 1, null, $id);
// 构建资讯文章内容
if (!empty($article['data']['list']['artList'])) {
$build = array();
foreach ($article['data']['list']['artList'] as $article) {
$build[] = Helpers::formatArticle($article, true, false, false);
}
$data['guang']['infos'] = $build;
}
$this->_view->display('list', $data);
}
/**
* 逛列表页面的资讯分页
*
* 逛首页、标签页、编辑页资讯列表
*
* @param string tag 标签名称, 没有传空或不传
* @param int type 逛首页的分类ID
* @param int page 分页的页码
* @param string gender "1,2,3"表示所有, "1,3"表示男, "2,3"表示女
* @param int authorId 作者ID
* @return html
*/
public function pageAction()
{
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
/* 判断参数是否有效 */
$tag = $this->get('tag');
$sortId = $this->get('type', 0);
$page = $this->get('page');
$gender = $this->get('gender');
$authorId = $this->get('authorId');
$showAuthor = true;
if (!empty($sortId) && !is_numeric($sortId)) {
break;
}
if (!empty($page) && !is_numeric($page)) {
break;
}
if (!empty($authorId) && is_numeric($authorId)) {
$showAuthor = false;
}
/* 获取资讯文章列表 */
$uid = $this->getUid();
$udid = $this->getUdid();
$page = intval($page) + 1;
$article = ListData::article($gender, $sortId, $uid, $udid, $page, $tag, $authorId);
if (empty($article['data']['list']['artList'])) {
break;
}
/* 构建资讯文章内容 */
$data = array();
$build = array();
foreach ($article['data']['list']['artList'] as $article) {
$build[] = Helpers::formatArticle($article, true, false, $showAuthor);
}
$data['infos'] = $build;
$this->_view->display('page', $data);
exit();
}
while (false);
echo ' ';
}
}