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

External RSS Feed Page


Reply

243 Views

Avatar
socks

11 November 2013 at 12:33pm Community Member, 190 Posts

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