Authored by hf

do add yohobuy guang code

@@ -4,8 +4,9 @@ namespace Guang; @@ -4,8 +4,9 @@ namespace Guang;
4 4
5 use LibModels\Wap\Guang\ListData; 5 use LibModels\Wap\Guang\ListData;
6 use LibModels\Wap\Guang\DetailData; 6 use LibModels\Wap\Guang\DetailData;
7 -use Plugin\Helpers;  
8 use Configs\CacheConfig; 7 use Configs\CacheConfig;
  8 +use Plugin\Helpers;
  9 +use Plugin\Cache;
9 10
10 /** 11 /**
11 * 12 *
@@ -223,11 +224,14 @@ class IndexModel @@ -223,11 +224,14 @@ class IndexModel
223 if (!empty($article['data']['list']['artList'])) { 224 if (!empty($article['data']['list']['artList'])) {
224 $build = array(); 225 $build = array();
225 foreach ($article['data']['list']['artList'] as $value) { 226 foreach ($article['data']['list']['artList'] as $value) {
226 - if (!isset($value['id'])) {  
227 - continue; 227 + if (isset($value['id'])) {
  228 + $build = Helpers::formatArticle($value, false, false, true);
  229 + if (!isset($build['author']['name'])) {
  230 + $build['author']['name'] = '';
  231 + }
  232 + $build['intro'] = self::genIntro($value['id']);
  233 + $result[] = $build;
228 } 234 }
229 - $build = Helpers::formatArticle($value, false, false, false);  
230 - $build['intro'] = DetailData::intro($value['id']);  
231 } 235 }
232 } 236 }
233 237
@@ -246,34 +250,38 @@ class IndexModel @@ -246,34 +250,38 @@ class IndexModel
246 } 250 }
247 251
248 /** 252 /**
  253 + * 构建信息内容
249 * 254 *
250 * @param array $data 255 * @param array $data
251 * @return array 256 * @return array
252 */ 257 */
253 - private static function buildIntro($data) 258 + private static function genIntro($id)
254 { 259 {
255 - foreach ($data as $value) {  
256 - $build = array();  
257 - // 文字  
258 - if (isset($value['text'])) {  
259 - $build['text'] = $value['text']['data']['text'];  
260 - }  
261 - // 单张图  
262 - elseif (isset($value['singleImage'])) {  
263 - $build['bigImage'] = Helpers::getImageUrl($value['singleImage']['data'][0]['src'], 640, 640);  
264 - }  
265 - elseif (isset($value['smallPic']['data'])) {  
266 - $imgs = $value['smallPic']['data'];  
267 - $build['smallImage'] = array(  
268 - array(  
269 - 'src' => Helpers::getImageUrl($imgs[0]['src'], 315, 420)  
270 - ),  
271 - array(  
272 - 'src' => Helpers::getImageUrl($imgs[1]['src'], 315, 420)  
273 - )  
274 - ); 260 + $result = '';
  261 +
  262 + $data = DetailData::intro($id);
  263 + if (!empty($data)) {
  264 + foreach ($data as $value) {
  265 + // 文字
  266 + if (isset($value['text'])) {
  267 + $result .= trim( strip_tags( htmlspecialchars_decode($value['text']['data']['text']) ) ) . '<br/>';
  268 + }
  269 + // 单张图
  270 + elseif (isset($value['singleImage'])) {
  271 + $result .= '<img src="' . Helpers::getImageUrl($value['singleImage']['data'][0]['src'], 640, 640) . '"/><br/>';
  272 + }
  273 + // 多张小图
  274 + elseif (isset($value['smallPic']['data'])) {
  275 + foreach ($value['smallPic']['data'] as $small) {
  276 + $result .= '<img src="' . Helpers::getImageUrl($small['src'], 315, 420) . '"/>';
  277 + }
  278 + $result .= '<br/>';
  279 + }
275 } 280 }
276 } 281 }
  282 + $data = array();
  283 +
  284 + return $result;
277 } 285 }
278 286
279 } 287 }
1 <?php 1 <?php
  2 +
2 use Action\AbstractAction; 3 use Action\AbstractAction;
3 4
4 /** 5 /**
@@ -12,33 +13,49 @@ use Action\AbstractAction; @@ -12,33 +13,49 @@ use Action\AbstractAction;
12 */ 13 */
13 class RssController extends AbstractAction 14 class RssController extends AbstractAction
14 { 15 {
15 - 16 +
  17 + /**
  18 + * 订阅逛最新的资讯
  19 + */
16 public function indexAction() 20 public function indexAction()
17 { 21 {
18 headers_sent() || header('Content-Type: text/xml; charset=utf-8'); 22 headers_sent() || header('Content-Type: text/xml; charset=utf-8');
19 - 23 +
20 $time = date('D, d M Y H:i:s O'); 24 $time = date('D, d M Y H:i:s O');
21 - 25 + $gender = $this->get('gender', '1,2,3');
  26 +
22 // 输出顶部公共的信息 27 // 输出顶部公共的信息
23 echo <<<RSS 28 echo <<<RSS
24 <?xml version="1.0" encoding="UTF-8"?> 29 <?xml version="1.0" encoding="UTF-8"?>
25 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 30 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
26 <channel> 31 <channel>
27 - <title>有货逛</title>  
28 - <link>http://guang.m.yohobuy.com</link>  
29 - <description>Yoho!Buy有货 | 年轻人潮流购物中心</description>  
30 - <atom:link href="http://guang.m.yohobuy.com/rss" rel="self"></atom:link>  
31 - <atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/>  
32 - <language>zh-cn</language>  
33 - <copyright>2015 yoho.inc</copyright>  
34 - <lastBuildDate>{$time}</lastBuildDate>  
35 - <ttl>30</ttl>  
36 -RSS;  
37 -  
38 -  
39 -  
40 - 32 +<title>有货逛</title>
  33 +<link>http://yohobuy.com</link>
  34 +<generator>http://m.yohobuy.com</generator>
  35 +<description>Yoho!Buy有货 | 年轻人潮流购物中心</description>
  36 +<atom:link href="http://guang.m.yohobuy.com/rss" rel="self"></atom:link>
  37 +<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/>
  38 +<language>zh-cn</language>
  39 +<copyright>2015 yoho.inc</copyright>
  40 +<lastBuildDate>{$time}</lastBuildDate>
  41 +<ttl>50</ttl>
41 42
  43 +RSS;
  44 +
  45 + $items = \Guang\IndexModel::getRssArticle($gender);
  46 + foreach ($items as $item) {
  47 + echo '<item>', "\n",
  48 + '<title><![CDATA[', $item['title'], ']]></title>', "\n",
  49 + '<link><![CDATA[', $item['url'], '&ref=rss]]></link>', "\n",
  50 + '<description><![CDATA[', $item['intro'], ']]></description>', "\n",
  51 + '<pubDate>', $item['publishTime'], '</pubDate>', "\n",
  52 + '<author><![CDATA[', $item['author']['name'], ']]></author>', "\n",
  53 + '<guid><![CDATA[', $item['url'], '&ref=rss]]></guid>', "\n",
  54 + '<source>有货</source>',
  55 + '</item>', "\n";
  56 + }
  57 +
  58 + echo "</channel>\n</rss>";
42 } 59 }
43 - 60 +
44 } 61 }