PlusstarIndex.php
3.39 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
<?php
namespace WebPlugin\DataProcess\Channel;
use WebPlugin\Images;
class PlusstarIndex extends AbstractChannel
{
/**
* 格式化数据
*
* @param array $resource
* @return
*/
public static function format($resources)
{
$singleGoods = array('name'=>'','list'=> array());
$video = array('name'=> '','list'=> array());
$news = array('name' =>'', 'pics'=> array('list' => array()),'txts'=> array('list'=> array()));
$ads = array('list'=> array());
$result = array();
if(!empty($resources))
{
$len = count($resources) + 4 ;//4个是默认已经处理了
foreach($resources as $key => $resource) {
if($key == 4 && $resource['template_name'] == 'text') {//单品名称
$singleGoods['name'] = $resource['data']['text'];
}
if($key == 5 && $resource['template_name'] == 'floor') {//单品列表
foreach($resource['data'] as $pos => $val) {
$val['src'] = Images::getImageUrl($val['src'], 280, 374, 1);
$singleGoods['list'][] = array('href' => $val['url'],'name'=> $val['title'],'img' => $val['src']);
}
$result[$key] = array('singlegoods' => $singleGoods);
}
if($key == 6 && $resource['template_name'] == 'text') { //视频名称
$video['name'] = $resource['data']['text'];
}
if($key == 7 && $resource['template_name'] == 'floor') { //视频名称
foreach($resource['data'] as $pos => $val) {
$val['src'] = Images::getImageUrl($val['src'], 378, 241, 1);
$video['list'][] = array('href' => $val['url'],'name'=> $val['title'],'img' => $val['src']);
}
$result[$key] = array('video' => $video);
}
//倒数第三个
if($key == ($len - 3) && $resource['template_name'] == 'text'){//资讯名称
$news['name'] = $resource['data']['text'];
}
//倒数第二个
if($key == ($len - 2) && $resource['template_name'] == 'textNav') { //资讯banner
foreach($resource['data'] as $val) {
if(is_numeric($val['name'])) {
$id = $val['name'];
$news['pics']['list'][$id] = array('id' => $id,'href' => $val['url'], 'img'=>'','tips'=>'');
}
}
$result[$key] = array('news' => $news);
}
//最后一个
if($key == ($len - 1) && $resource['template_name'] == 'textNav') {//小资讯
foreach($resource['data'] as $pos => $val) {
if(is_numeric($val['name'])) {
$id = $val['name'];
$ads['list'][$id] = array('id' => $id,'href' => $val['url'],'img'=>'',);
}
}
$result[$key] = array('ads' => $ads);
}
}
}
return $result;
}
}