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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Pulling RSS feeds from other sites onto my home page.


Reply


31 Posts   5398 Views

Avatar
zim

Community Member, 135 Posts

30 October 2009 at 12:28pm

i get this error when i use the simplepie class

Fatal error: Class 'SimplePie' not found in C:\wamp\www\SilverStripe01\mysite\code\HomePage.php on line 67

i am using this
function CustomRSSFeed() {
   $feed = new SimplePie("http://feeds.guardian.co.uk/theguardian/world/rss");
   $feed->feed->init();
   $output = new DataObjectSet();
   if($items = $feed->feed->get_items(0, 10)){
      foreach($items as $item){
         $output->push(new ArrayData(array(
            "Title" => $item->get_title(),
            "Link" => $item->get_link()
         )));
      }
   }
      return $output;
}

and

<% control CustomRSSFeed %>
      
$Title
      
<% end_control %>

:(

Avatar
D-L

Community Member, 13 Posts

30 October 2009 at 1:57pm

Regarding your API key dilemma, Google allows you to simply put in localhost as your domain. This will allow you to generate and use an API key for your local WAMP or MAMP installation.

Avatar
D-L

Community Member, 13 Posts

30 October 2009 at 2:00pm

Zim zimma - About your fatal error.... It seems you are using WAMP, so all you need to do is enable curl. click on the wamp icon, an you can enable curl in the PHP extensions. Hope this helps, dude.

Avatar
D-L

Community Member, 13 Posts

30 October 2009 at 2:18pm

Mate...there is also a widget that pulls in news from CNN; I've not personally used it, but looks to me like it could be made to do what you need it to with a little modification to pull in just a single title from CNN, a single title from another news site, and so on...

Avatar
Mo

Community Member, 514 Posts

31 October 2009 at 12:38am

You appear to be missing the line in your method to include SimplePie. It is not included as a default silverstripe library.

Add this:

include_once(Director::getAbsFile(SAPPHIRE_DIR . '/thirdparty/simplepie/SimplePie.php'));

To the first line of your method.

Mo

Avatar
zim

Community Member, 135 Posts

31 October 2009 at 4:44am

Hey Mo,

do you mean like the below... because that made the whole site not display? am I putting the
include in the right place? Thanks for help dude.

function CustomRSSFeed() {

include_once(Director::getAbsFile(SAPPHIRE_DIR . '/thirdparty/simplepie/SimplePie.php'));

   $feed = new SimplePie("http://feeds.guardian.co.uk/theguardian/world/rss");
   $feed->feed->init();
   $output = new DataObjectSet();
   if($items = $feed->feed->get_items(0, 10)){
      foreach($items as $item){
         $output->push(new ArrayData(array(
            "Title" => $item->get_title(),
            "Link" => $item->get_link()
         )));
      }
   }
      return $output;
}

Avatar
Mo

Community Member, 514 Posts

31 October 2009 at 10:22am

Hmm, there are a couple of what look like errors, the biggest one is that you have used $feed->feed->methodname, it should just be $feed->methodname.

Try this:

function CustomRSSFeed() {

   include_once(Director::getAbsFile(SAPPHIRE_DIR . '/thirdparty/simplepie/SimplePie.php'));
   
   $feed = new SimplePie("http://feeds.guardian.co.uk/theguardian/world/rss", TEMP_FOLDER);
   $feed->init();
   
   $output = new DataObjectSet();
   if($items = $feed->get_items(0, 10)){
      foreach($items as $item){
         // Cast the Title to get rid of nasty things
         $title = new Text('Title');
         $title->setValue($item->get_title());
         
         $output->push(new ArrayData(array(
            "Title" => $title,
            "Link" => $item->get_link()
         )));
      }
   }
   return $output;
}

Mo

Avatar
zim

Community Member, 135 Posts

1 November 2009 at 2:27am

Hey Mo,

Thanks dude! That worked. Just what I need.

How would I go about pulling feed from multiple sites. Say BBC, YAHOO, google news etc. as well as just guardian.

Really appreciate your help. I know I need to learn my php!