Remember me? forgot password | register

SilverStripe Forum

10690 Posts in 2797 Topics by 1519 members

Jump to:

Site Builders

If this is your first visit, you will need to register before you can post. However, you can browse all messages below.

Community » SilverStripe Forum » Site Builders » restful service rss
Page: 1 go to end Reply
Author Topic: restful service rss 454 views
  • superautomatic
    avatar
    Community Member
    46 posts
    7 SilverStripe Sites

    restful service rss Link to this post

    Hi, I'm trying to import and display an external rss-feed, as in the example code on "How to use RestfulService to easily embed an RSS feed" (http://doc.silverstripe.com/doku.php?id=restfulservice)

    It works well if I use the rss feed in the example, but if I use another rss (for example http://www.euro2008.uefa.com/rss/index.xml), it returns nothing at all. Why is this?

    Last edited: 10 June 2008 at 9:47pm

  • willr
    avatar
    Core Development Team
    1263 posts
    3 SilverStripe Sites 2 SilverStripe Themes

    Re: restful service rss Link to this post

    The blog modules RSS Feed widget uses SimplePie. I dont know how it differs from RestFulService it terms of what you actually want to do but that uses something like

    http://pastie.org/212736

  • bortamatch
    bortamatch's avatar
    21 posts

    Re: restful service rss Link to this post

    I have the same problem as superautomatic. Got it working as described in the documentation, with help from the comments. But it only works with that feed, none else.

    I can't seem to get the http://mypage/PageComment/rss/ feed working either. It says that Xml- or textdeclaration not in beginning of entity. Any clues on that?

    Besides that there is a typo in RestfulService.php, in line 134. $respnoseBody should be $responseBody I suppose.

  • Re: restful service rss Link to this post

    With 2.3 coming up I decided to use the RestfulService.php from the 2.3 branch instead of the current stable one, and as it is pretty self contained it seems to work fine on 2.2.3.

    The problem I had was with the difference in format between RSS feeds of different versions: RSS 1.0 places the <item> tags outside the <channel>, while RSS 2.0 places them outside. The end result of this is that you need to call getValues slightly differently, here's a snippet of code that I wrote for a recent site:


    function Items($limit = 3) {
    if(!$this->Link) return 0;
    $feed = new RestfulService($this->Link);
    $feedXML = $feed->request()->getBody();

    // Extract items from feed
    if($this->Type == 'RSS2') {
    $result = $feed->getValues($feedXML, 'channel', 'item');
    } elseif($this->Type == 'RSS1') {
    $result = $feed->getValues($feedXML, 'item');
    }

    // Return items up to limit
    return $result->getRange(0,$limit);
    }

    Hope that helps.

    BTW I've posted a patch to Trac that re-enables the response caching as I couldn't live without it for this site. Not sure whether it's good enough for inclusion in trunk though.

    454 views
go to top Reply

Currently Online:

g, eljefe, patrics, Aster, motoservo

Welcome to our latest member: patrics