Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS

RSS feed items to pages


Reply

751 Views

Avatar
LesC

9 May 2009 at 4:12am (Last edited: 9 May 2009 4:13am), Community Member, 70 Posts

Hi,

Background: I've seen a few posts around using SimplePie and the RestfulService that show how to present RSS feed items on pages, and have seen WillR's response nearly a year ago for how to insert RSS entries as blog posts (http://silverstripe.org/archive/show/187016#post187016).

Situation: I'm trying to grab a news feed and create pages from it (it's a stock news feed, but I'd like to be able to use it with any RSS feed). I have a FeedHolder class that shows a list of FeedEntry items (these are the pages I want to create), and have set it up so they can be manually created in the CMS.

Problem: I understand that I need to first pull in the feed, then insert each feed as a page, but I'm getting a bit confused with his example and can't see how it should be creating entries. Once I get it creating entries, I'd like to call it every so often to update the entries from the feed.

WillR's code from the aforementioned post:

$feed = new RestfulService("URL OF RSS FEED");
$conn = $feed->connect('');
$msgs = $feed->getValues($conn, "status");

$output = new DataObjectSet();
foreach($msgs as $msg){
foreach($feed as $feedItem) {
$blog = new Blog_Entry();
$blog->Title = "This is the Title"; // should come from $feedItem
$blog->setDate(date("Y-m-d H:i:s",time()));
$blog->publish("Stage", "Live");
$blog->Author = "Author";
$blog->Content = $feedItem->Content;
$blog->ParentID = DataObject::get_one('BlogHolder')->ID;
$blog->write();
}
}

Can anyone point me in the right direction? Or even better show me what needs to be done to get it working?