Blame view

yohobuy/m.yohobuy.com/application/modules/Guang/controllers/Rss.php 1.76 KB
hf authored
1
<?php
hf authored
2
hf authored
3 4 5 6 7 8 9 10 11 12 13 14 15
use Action\AbstractAction;

/**
 * RSS订阅
 * 
 * @name RssController
 * @package Guang
 * @copyright yoho.inc
 * @version 1.0 (2015-11-16 17:25:09)
 * @author fei.hong <fei.hong@yoho.cn>
 */
class RssController extends AbstractAction
{
hf authored
16 17 18 19

    /**
     * 订阅逛最新的资讯
     */
hf authored
20 21 22
    public function indexAction()
    {
        headers_sent() || header('Content-Type: text/xml; charset=utf-8');
hf authored
23
hf authored
24
        $time = date('D, d M Y H:i:s O');
hf authored
25 26
        $gender = $this->get('gender', '1,2,3');
hf authored
27 28 29 30 31
        // 输出顶部公共的信息
        echo <<<RSS
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
hf authored
32
<title>有货逛</title>
hf authored
33 34 35 36 37 38 39 40 41
<link>http://yohobuy.com</link>
<generator>http://m.yohobuy.com</generator>
<description>Yoho!Buy有货 | 年轻人潮流购物中心</description>
<atom:link href="http://guang.m.yohobuy.com/rss" rel="self"></atom:link>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/>
<language>zh-cn</language>
<copyright>2015 yoho.inc</copyright>
<lastBuildDate>{$time}</lastBuildDate>
<ttl>50</ttl>
hf authored
42
    
hf authored
43 44 45 46 47 48 49 50 51 52 53 54 55 56
RSS;

        $items = \Guang\IndexModel::getRssArticle($gender);
        foreach ($items as $item) {
            echo '<item>', "\n",
            '<title><![CDATA[', $item['title'], ']]></title>', "\n",
            '<link><![CDATA[', $item['url'], '&ref=rss]]></link>', "\n",
            '<description><![CDATA[', $item['intro'], ']]></description>', "\n",
            '<pubDate>', $item['publishTime'], '</pubDate>', "\n",
            '<author><![CDATA[', $item['author']['name'], ']]></author>', "\n",
            '<guid><![CDATA[', $item['url'], '&ref=rss]]></guid>', "\n",
            '<source>有货</source>',
            '</item>', "\n";
        }
57
hf authored
58
        echo "</channel>\n</rss>";
hf authored
59
    }
hf authored
60
hf authored
61
}