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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

RSS feed items to pages


Go to End


1333 Views

Avatar
LesC

Community Member, 70 Posts

9 May 2009 at 4:12am

Edited: 09/05/2009 4:13am

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?