This is a simple tutorial explaining how to utilise RSS/Atom feeds on your website using a combination of WACT and the Magpie RSS Parser.
First thing you need to do is download the Magpie source from http://magpierss.sourceforge.net/. Once you have this it can be integrated into WACT by simply extending the ArrayDataSet class as follows:
require 'rss_fetch.inc';
require '../../framework/common.inc.php';
require WACT_ROOT . '/util/arraydataset.inc.php';
require WACT_ROOT . '/template/template.inc.php';
class RSSFeed extends ArrayDataSet {
var $rss;
function RSSFeed($url="") {
$this->rss = fetch_rss($url);
if(is_array($this->rss->items)) {
$this->setDataSet($this->rss->items);
}
}
function getChannelData($item='') {
return $this->rss->channel[$item];
}
}
Then it is just a matter of using standard ListTag syntax to display the feed:
$Page =& new Template('/rss.html');
$Feed =& new RSSFeed("http://www.livejournal.com/users/static_object/data/atom");
$Page->set('channel_title', $Feed->getChannelData('title'));
$FeedList =& $Page->getChild('rsslist');
$FeedList->registerDataset($Feed);
$Page->display();
If you'd like to use the PHP date() function to manipulate the date formatting, then a filter can be added:
class RSSFilter {
function doFilter(&$row) {
$row['issued'] = date('l dS of F Y @ g:i A', strtotime(str_replace("T", " ", $row['issued'])));
}
}
$Page =& new Template('/rss.html');
$Feed =& new RSSFeed("http://www.livejournal.com/users/static_object/data/atom");
$Page->set('channel_title', $Feed->getChannelData('title'));
$FeedList =& $Page->getChild('rsslist');
$FeedList->registerDataset($Feed);
$FeedList->registerFilter(new RSSFilter);
$Page->display();
And the template source:
{$channel_title}
Shown below is a list of the variable names used in both Atom and RSS feeds:
!Atom Feed fields:
*title
*id
*link
*issued
*modified
*author
*author_name
*atom_content
!RSS Feed fields:
*guid
*pubdate
*link
*description
*comments
*summary
If you'd like to see a demo of this in action, you can find one at http://www.flatnet.net/rss/