Jump to:

23003 Posts in 11856 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » External RSS Feed Page

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

Page: 1
Go to End
Author Topic: 146 Views
  • socks
    Avatar
    Community Member
    190 Posts

    External RSS Feed Page Link to this post

    I'm upgrading to SS3.1 from 2.4 and am using code from the blog module, but it's not working.

    I get an "Uncaught LogicException: 0" error.

    If I uncomment the include_once (which is what I had in my 2.4 version), I just get a white page.

    class FeedPage extends Page {

    ...

       function getAbsoluteRssUrl() {
          $urlParts = parse_url($this->RssUrl);
          if(!isset($urlParts['host']) || !$urlParts['host']) {
             return Director::absoluteBaseURL() . $this->RssUrl;
          } else {
             return $this->RssUrl;
          }
       }
       
    function Title() {
    return ($this->RssTitle) ? $this->RssTitle : 'RSS Feed';
    }

    function getFeedItems() {
    $output = new ArrayList();

    // include_once(Director::getAbsFile(FRAMEWORK_DIR . '/thirdparty/simplepie/simplepie.inc'));

    // Protection against infinite loops when an RSS widget pointing to this page is added to this page
    if(stristr($_SERVER['HTTP_USER_AGENT'], 'SimplePie')) {
    return $output;
    }

    if(!class_exists('SimplePie')) {
    throw new LogicException(
    'Please install the "simplepie/simplepie" library by adding it to the "require" '
    + 'section of your composer.json'
    );
    }

    $t1 = microtime(true);
    $feed = new SimplePie();
    $feed->set_feed_url($this->AbsoluteRssUrl);
    $feed->set_cache_location(TEMP_FOLDER);
    $feed->init();
    if($items = $feed->get_items(0, $this->NumberToShow)) {
    foreach($items as $item) {

    // Cast the Title
    $title = new Text('Title');
    $title->setValue($item->get_title());

    $output->push(new ArrayData(array(
    'Title' => $title,
    'Content' => $item->get_content(),
    'Date' => $item->get_date(),
    'Link' => $item->get_link()
    )));
    }
    return $output;
    }
    }

    }

    Any help appreciated

    146 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.