Translations of this page:

Aggregate

This is a hack to the MagpieRSS RSS feed reader. It reads multiple feeds, merges them, sorts by date and outputs as a single “web page”. You would need to insert it into your page template. I run it from a Cron job redirecting standard output into an html page under my htdocs directory.

<?php
# full path to Magpie Install directory
define('MAGPIE_DIR', './');
require_once(MAGPIE_DIR.'rss_fetch.inc');
$num_items=10;
$urls = array(
	"http://sp-rss.danielarndt.com/new_articles.rss",
	"http://www.powdermag.com/features/news/rss/standard_rss.xml",
	"http://community.freeskier.com/profiles/rss.php?user_id=17345"
);
?>
$myItems = array();
 
foreach ($urls as $url) {
	$rss = fetch_rss( $url );
	$myItems=array_merge($myItems, $rss->items);
}
usort($myItems, "cmp");
$myItems = array_slice($myItems, 0, $num_items);
 
foreach ($myItems as $item) {
	print "<h3 class=\"date\">" . date('l dS \, F Y', $item['date_timestamp']) . "</h3>";
	print "<h2><a href=\"" . $item['link'] . "\">" . $item['title'] . "</a></h2>";
	if (isset($item["description"])) {
		print "<p>" . $item['description'] . "</p>";
	}
	print "<div class=\"posted\"><a href=\"" . $item['link'] . "\">Read More</a></div>";
}
 
 
function cmp($a,$b) {
	if ($a['date_timestamp'] == $b['date_timestamp']) {
		return 0;
	}
	return ($a['date_timestamp'] > $b['date_timestamp']) ? -1 : 1;
}
?>
tech/aggregate.txt · Last modified: 2008/01/15 09:18 by davidof
Recent changes RSS feed