I wanted to get the RSS (Rich Site Summary) feed from [DShield.org], so I started out with a macro to parse this. I decided to generalize it to handle any RSS feed. Here's what I ended up with...
[MagpieRSS] parser installed.
1) Add the following to $ViewMacroEngine? in lib/defaults.php:
'RSS' => 'view_macro_RSS'
2) Add the following function to parse/macros.php:
function view_macro_RSS($args)
{
global $MagpieRSSInc,$RSSsources,$RSSviews;
require_once($MagpieRSSInc);
$url=$RSSsources[$args];
if ($url) {
$rss=fetch_rss($url);
include($RSSviews[$args]?$RSSviews[$args]:$RSSviews['default']);
} else {
$result = "No RSS stream: $args";
}
return $result;
}
3) Add the following lines to the config.php for any Wiki that will use the macro:
$MagpieRSSInc=fill in the full path of rss_fetch.inc in the magpierss directory;
$RSSsources = array(
);
$RSSviews = array(
'default' => 'default_RSS_view.php'
);
4) Add a file called default_RSS_view.php to the same directory as config.php and place the following in it:
<?
//$rss is set by Magpie to contain the parsed RSS output
//this code must set $result to be the HTML that should be displayed
$result = "Site: ".$rss->channel['title']."<br>\n";
foreach ($rss->items as $item) {
$title=$item[title];
$url=$item[link];
$description=$item[description];
$result = $result . "<a href=$url>$title</a><li><br>$description<br>\n";
}
?>
1) For each RSS source, come up with a one word tag that will identify the source.
2) Add the tag and the URL where the RSS file is stored to the $RSSsources array.
$RSSsources = array(
'DShield' => 'http://feeds.dshield.org/news.xml'
);
3) (optional) If you want to make the output do something more than the default (and you probably do), create a php file similar to default_RSS_view.php and add it to the $RSSviews array in config.php. When this file is included $rss will hold the results of the MagpieRSS? fetch_rss function. This file should set $result to contain the HTML that should get returned by the macro.
4) Include the macro in your pages as needed. The macro name is RSS, and it takes the tag you created as an argument.
[[RSS DShield]]
If you have any comments or questions, you can direct them to Geekido:ChrisCooke?.