mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-03-03 16:24:28 +08:00
48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?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;
|
|
}
|
|
} |