RSS Output from XenForo Custom Database

Resolution

New member
I built my first add-on over the past two months which in use on my clients website. The add on retrieves data from an external website in the form of an .xls file, converts it into entries in a set of database tables which I display in tables on various pages. I now want to be able output this data into an RSS feed so that other users can access the information and can't work out how. I have searched websites and community boards but can't see a way to do it and wondered if anyone could point me in the right direction.

I can see that the xenforo software produces its own rss feed which is dynamically updated but dont know how to replicate this functionality. A typical link by clicking the rss icon in the footer is index.php?forums/-/index.rss. How is this link hooked up to a feed? I can see various xenforo files in the library such as globalrss but cannot see how to replicate to create my own rss link, creating my own route prefix would seem a likely option but how would it work with a file extension rather than a folder name?

My idea is that by creating my own RSS feed I could also automatically update certain related threads when a change occurs with the data, using the feeder add-on.
 
Last edited:
I have managed to generate an RSS output for my add-on, based on my database content using the steps below:

1) Create new Proxy Listener class. The 'class_exists' test is required because I had issues with class already being defined when used outside of my add on folder:

class XYZ_Listener_Proxy
{
public static function extendController($class, array &$extend)
{
if (!class_exists('XFCP_XYZ_ControllerPublic_ABC', false))
{$extend[] = 'XYZ_ControllerPublic_ABC';
}
}
}


2) Setup new 'Code Event Listener' in XenForo 'Development' control panel.

Listen to event: load_class_controller
Execute Callback: XYZ_Listener_Proxy :: extendController


3) Create new controllerPublic class:

class XYZ_ControllerPublic_ABC extends XFCP_XYZ_ControllerPublic_ABC
{
public function actionIndex()
{
$parent = parent::actionIndex();

if (!($parent instanceof XenForo_ControllerResponse_View))
{
return $parent;
}

if ($this->_routeMatch->getResponseType() == 'rss')
{
//sample parameter passing
$viewParams = array(
'fgh' => $fgh

);
return $this->responseView('XYZ_ViewPublic_Archive_Rss', '', $viewParams);
} else {
return $parent;
}
}
}


4) Create View class to display the RSS feed:

class XYZ_ViewPublic_Archive_Rss extends XenForo_ViewPublic_Base
{
public function renderRss()
{
$feed = new Zend_Feed_Writer_Feed();
$feed->setEncoding('utf-8');
$feed->setTitle($title);
$feed->setDescription($description);


$feed->setLink(XenForo_Link::buildPublicLink('canonical:foldername'));
if (!$buggyXmlNamespace)
{
$feed->setFeedLink(XenForo_Link::buildPublicLink('canonical:foldername/index.rss'), 'rss');
}
$feed->setDateModified(XenForo_Application::$time);
$feed->setLastBuildDate(XenForo_Application::$time);
$feed->setGenerator($title);

/// Loop for each entry in RSS feed - replace with relevant data
foreach () {
$entry = $feed->createEntry();
$entry->setTitle('title');
$entry->setContent('str');
$feed->addEntry($entry);
}
return $feed->export('rss');
}
}
 
My next query, which I can't find an answer to, is the feed I generate does not import/preview using the XenForo 'feeder', see error below:

There was a problem requesting the feed.
Error message: N/A


If I place a copy of the .xml file (.rss save as) on another server it works fine. I have tried with feeds generated automatically from the 'globalRSS' XenForo software e.g.
http://www.xyz.co.uk/index.php?forums/-/index.rss and these also fail. I'm assuming these don't work because of permissions issues, am I correct? I'm wondering how to get around this problem, surely the feed I listed above is generated so that other websites could be setup to view the content? This applies to the feed I am outputting, I want to be able to read it on another website.

The error I get for my own feed xyz.com/folder name/index.rss when not logged in is:

The requested page is unrepresentable as RSS
 
Last edited:
The problem I have found with my code is that the footer RSS link is being overriden by my code '/index.php?forums/-/index.rss'. This link should show all forum updates, but my feed si displaying instead. Is there another test I can do to avoid the call

if ($this->_routeMatch->getResponseType() == 'rss')

from overiding the globalRSS version of the code?
 
Back
Top Bottom