优化查询代码;增加RSS1

This commit is contained in:
2023-03-02 09:43:25 +08:00
parent 76b123aa53
commit 138708182b
6 changed files with 138 additions and 7 deletions

48
app/common/tools/Rss.php Normal file
View 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;
}
}