mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-03-03 16:24:28 +08:00
优化查询代码;增加RSS1
This commit is contained in:
48
app/common/tools/Rss.php
Normal file
48
app/common/tools/Rss.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace app\common\tools;
|
||||
|
||||
use FeedWriter\RSS1;
|
||||
|
||||
class Rss
|
||||
{
|
||||
public static function initRss1()
|
||||
{
|
||||
$feed = new RSS1();
|
||||
|
||||
|
||||
$feed->setTitle(Site::name());
|
||||
$feed->setLink(Site::indexUrl());
|
||||
$feed->setDescription(Site::desc());
|
||||
|
||||
//It's important for RSS 1.0
|
||||
$feed->setChannelAbout(Site::keywords());
|
||||
|
||||
// An image is optional.
|
||||
$feed->setImage(Site::logo(), 'PHP武器库头像', get_source_link('/'));
|
||||
|
||||
//Adding a feed. Generally this portion will be in a loop and add all feeds.
|
||||
|
||||
$list_post = Site::mapRecentlyPost();
|
||||
|
||||
foreach ($list_post as $model_post) {
|
||||
//Create an empty FeedItem
|
||||
|
||||
$new_item = $feed->createNewItem();
|
||||
|
||||
$new_item->setTitle($model_post->title);
|
||||
|
||||
$new_item->setLink($model_post->read_url);
|
||||
//The parameter is a timestamp for setDate() function
|
||||
$new_item->setDate($model_post->publish_time);
|
||||
$new_item->setDescription($model_post->desc);
|
||||
//Use core addElement() function for other supported optional elements
|
||||
|
||||
//Now add the feed item
|
||||
$feed->addItem($new_item);
|
||||
}
|
||||
|
||||
$content = $feed->generateFeed();
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user