Extension:XFeed - RSS Feed Aggregator
From MediaWiki.org
|
Release status: unknown |
|
|---|---|
| Implementation | Tag |
| Description | Add a <xfeeds> tag |
| License | No license specified |
| Download | #Source |
|
check usage (experimental) |
|
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)
Contents |
[edit] Syntax
<xfeeds [titlecolour="#B0C4DE"] [contentcolour="#eeeeee"] [feedlimit="1"] [totallimit="10"]> http://feed-url-1 http://feed-url-2 </xfeeds>
Note: The attributes are optional and some basic defaults will be used if none are specified.
[edit] Example
<xfeeds contentcolour="#eeeeee" feedlimit="3" totallimit="10"> http://www.digg.com/rss/containertechnology.xml http://rss.slashdot.org/Slashdot/slashdot http://brill.pappin.ca/wp-rss2.php </xfeeds>
[edit] Result
A list of items sorted by date and including title, content, date and feed channel.
[edit] 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 require_once('magpierss/rss_fetch.inc'); to wherever you installed it.
Add an XFeeds.php include to you LocalSettings.php like every other extension.
<?php require_once('magpierss/rss_fetch.inc'); # Oringinal Author: http://meta.wikimedia.org/wiki/User:Brill # To activate the extension, include it from your LocalSettings.php # with: include("extensions/XFeeds.php"); $wgExtensionFunctions[] = "wfXFeeds"; $wgExtensionCredits['parserhook'][] = array( 'name'=>'XFeeds', 'author'=>'[http://meta.wikimedia.org/wiki/User:Brill Brill]', 'url'=>'http://www.mediawiki.org/wiki/Extension:XFeed_-_RSS_Feed_Aggregator', 'description' => 'RSS feed aggregator' ); function wfXFeeds() { global $wgParser; $wgParser->setHook( "xfeeds", "renderFeeds" ); } # The callback function for converting the input text to HTML output function renderFeeds( $input, $argv, &$parser ) { $parser->disableCache(); $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 = <<<EOF <div style="border: 1px solid $titlecolour; background-color: $contentcolour; width: 100%; margin: 2px 0px 2px 0px;"> <div style="padding: 2px 2px 2px 2px; margin: 0px 0px 0px 0px;; font-weight: bold; font-size: 14px; background-color: $titlecolour; width: 100%;"> <div><a href="$href">$title</a></div> <div style="font-weight: normal; font-size: 12px; color: Gray; font-style: italic; float: right; margin: 0px 4px 0px 2px; border-bottom-style: solid; border-bottom-width: 1px; border-bottom-color: $titlecolour;">$tStampStr [<a href="$channel_link">$channel_title</a>]</div> </div> <div style="padding: 2px 2px 2px 15px; margin: 0px 0px 0px 0px;">$description</div> </div> EOF; while (isset($feedItems[$timestamp])) { $timestamp++; } $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; } ?>
[edit] 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.
[edit] 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)
[edit] 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
- OpenNMS
- ControlTheoryPro.com
- Brock University Wiki Server
- Wiki Baidarkas
- Rosetta Code
- Apologetics Wiki
I would love to use it here, but need some help!: