zhexiao / yii-simplepie
yii 扩展的 simplepie
dev-master
2015-03-19 02:01 UTC
Requires
- php: >=5.2.0
- yii: >1.2
This package is not auto-updated.
Last update: 2020-01-10 15:24:04 UTC
README
yii-simplepie 是一个用于解析 RSS 提要的 yii 扩展:
- simplepie:http://simplepie.org/
- simplepie 文档:http://simplepie.org/wiki/reference/start
使用方法
在 yii 中安装扩展
下载所有文件并将它们放入 yii 扩展文件夹中,然后在 config/main.php 中添加以下代码:
'simplepie' => array( 'class' => 'ext.simplepie-library.bootstrap' ),
配置和初始化
$feed = Yii::app()->simplepie->config(array( 'set_feed_url' => $rssFeed, 'enable_cache' => true, 'set_cache_location' => Yii::app()->runtimePath . DIRECTORY_SEPARATOR . 'cache' ))->parse();
所有默认配置
array( // URL of the feed you want to parse 'set_feed_url' => '', // Force SimplePie to parse the content, even if it doesn't believe it's a feed 'force_feed' => true, // Enable/disable caching in SimplePie 'enable_cache' => false, // Set the folder where the cache files should be written 'set_cache_location' => './cache', // Set the minimum time for which a feed will be cached 'set_cache_duration' => 3600, // Enable/disable the reordering of items into reverse chronological order 'enable_order_by_date' => true, // Set a limit on how many items are returned per feed with Multifeeds 'set_item_limit' => 0, // HTML attributes to strip 'strip_attributes' => array('alt', 'bgsound', 'onclick'), // HTML tags to strip 'strip_htmltags' => array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'), // Override the character set within the feed 'set_input_encoding' => false, // Set the output character set 'set_output_encoding' => 'UTF-8', // Timeout for fetching remote files 'set_timeout' => 30, );
获取 RSS 提要属性
$feed->author // Get a single author for the feed. $feed->copyright // Get the feed copyright information. $feed->description // Get the feed description. $feed->encoding // Get the character set for the returned values. $feed->favicon // Get the URL for the favicon of the feed's website. $feed->item // Get a single item. $feed->items // Get all the items. $feed->item_quantity // Get the number of items in the feed. $feed->language // Get the feed language. $feed->link // Get a single link. $feed->links // Get all the links of a specific relation. $feed->permalink // Get the first feed link (i.e. the permalink). $feed->title // Get the feed title. $feed->type // Get the type of feed.