Extension:XFeed - RSS Feed Aggregator

Note: Copied most of this template from another RSS extension page. me input to improve the code and output (I'm sure I've made a mess of it).

--Brill 04:55, 15 August 2006 (UTC)

Syntax
 http://feed-url-1 http://feed-url-2

Note: The attributes are optional and some basic defaults will be used if none are specified.

Example
 http://www.digg.com/rss/containertechnology.xml http://rss.slashdot.org/Slashdot/slashdot http://brill.pappin.ca/wp-rss2.php

Result
A list of items sorted by date and including title, content, date and feed channel.

 TechTV Reborn as 'UndoTV' 2006-08-15 01:20:03 EDT (digg / Technology) "Pirillo and LaPorte hope to attract a sponsor and begin producing original content, but for now will let the site evolve from the ground up. Contributors will keep 100 percent control of the content they provide to the site, Pirillo wrote."  AJAX e-mail and more 2006-08-15 00:55:56 EDT (digg / Technology) A unique amalgam of Linux mail server and open source development platform, the Zimbra Collaboration Suite (ZCS) combines truly integrated e-mail, calendaring, and contacts with a mashup-friendly AJAX client and easy extensibility using Zimlets.

Source
Note: The default location for you to install magpie rss is in your includes folder; if you have installed it somewhere else then you will have to change the XFeeds code from  to wherever you installed it.

Add an XFeeds.php include to you LocalSettings.php like every other extension.

'XFeeds',    'author'=>'Brill',    'url'=>'http://meta.wikimedia.org/w/index.php?title=XFeed_-_RSS_Feed_Aggregator',    'description' => 'RSS feed aggregator'    );

function wfXFeeds { global $wgParser; $wgParser->setHook( "xfeeds", "renderFeeds" ); }

function renderFeeds( $input, $argv, &$parser ) { $parser->disableCache;
 * 1) The callback function for converting the input text to HTML output

$contentcolour = getParameter($argv, "contentcolour", "#EEEEEE"); $titlecolour = getParameter($argv, "titlecolour", "#B0C4DE"); $feedlimit = getParameter($argv, "feedlimit", 0); $totallimit = getParameter($argv, "totallimit", 10);

$feedItems = array;

$feedUrls = explode("\n",$input); #$output = ""; foreach ($feedUrls as $url){ if(strlen($url) > 0){ $feed = fetch_rss( $url ); $channel_title = $feed->channel['title']; $channel_link = $feed->channel['link']; $itemCount = 1; foreach ($feed->items as $item) { $href = $item['link']; $title = $item['title']; $description = $item['description']; $date = $item['pubdate']; $timestamp = 0; if($date == ""){ $date = $item['dc']['date']; if($date != ""){ $timestamp = pubDateToTimestamp($date); }                               }else{ $timestamp = pubDateToTimestamp($date); }                               $tStampStr = $date; if($timestamp > 0){ $tStampStr = formatDateTimestamp($timestamp); }

$outputItem = <<  $title $tStampStr [$channel_title] $description EOF;

$feedItems[$timestamp] = $outputItem; $itemCount = $itemCount + 1; if($itemCount > $feedlimit){ break; }                       }                }        }

krsort($feedItems, SORT_NUMERIC); $output = ""; $outCount = 0; foreach($feedItems as $tsKey => $itemValue){ $output .= $itemValue."\n"; $outCount = $outCount + 1; if($outCount > $totallimit){ break; }       }

return $output; }

function getParameter($argArray, $key, $defaultValue){ $value = $argArray[$key]; if(isset($value)){ return $value; }else{ return $defaultValue; } }

function pubDateToTimestamp($dateStr){ $tstamp = strtotime($dateStr,0); return $tstamp; }

function formatDateTimestamp($tstamp){ $result = strftime("%Y-%m-%d %T %Z", $tstamp); return $result; } ?>

Change Log

 * 2007-02-02
 * Fixed typo in extension credits.
 * 2007-01-25
 * Changed back to "$feed->items" per magpierss 0.72 documentation. I'm not sure what the mentioned php error was, but the change is what was causing the blank page problems.
 * Added parserhook credits
 * Kitzke 20:50, 25 January 2007 (UTC)


 * 2006-09-11 - Changed "$feed->items" to "$feedItems" because that's what it's supposed to be (Fixes a php error.)
 * Also changed the place that magpie is grabed from to be the includes or current directory, because that's the recomended location. Dantman


 * 2006-08-30 - Changed html output method - Thanks Mark F.

Known Issues

 * several feed item data formats are not parsed correctly, which causes only the last one to be added.
 * I've seen this before with date formats, but haven't had to fix them yet. Brill 06:33, 2 February 2007 (UTC)

Sites Using This Extension
Go ahead, add your site so we can all see the extension in action.
 * http://www.pappin.ca
 * http://www.troop439md.net/
 * http://www.wikistock.com
 * Flyer Wiki
 * Sarvagya Hindi Wiki
 * http://www.workinshanghai.com
 * OpenNMS
 * ControlTheoryPro.com
 * Brock University Wiki Server

I would love to use it here, but need some help!:
 * http://visiblepolitics.org