RSS aggregation for PHP
I have written a mechanism in PHP that can take several RSS feeds, filter and manipulate them, and re-display them in either RSS or straight HTML.
This can also manipulate content (through the preg_replace function, and configurable per-feed), such as removing names from Twitter entries. I’m using it on loopyapp.com to show all relevant items from both this blog and my Twitter feed automatically, as an alternative to creating a separate blog. I’m also using it on this blog, to incorporate blog entries and Twitter postings.
It uses the MagpieRSS RSS parser for PHP, which provides some nice functionality, including caching.
Here’s the code: aggregate.zip
To use it, unzip it to somewhere in your webroot, then edit aggregate.php and possibly rss.php to set your configuration. Make sure that either the aggregate directory is writable, or create a ‘cache’ directory within and make that writeable, to enable caching. Point your web browser to the rss.php file to immediately view an RSS feed aggregating your supplied feeds. To add a link to the RSS from a website, add it in the header:
<link rel="alternate" type="application/rss+xml" title="RSS Feed" href="http://mysite.com/aggregate/rss.php" /> |
To include content in a website, the provided render_aggregate_items function will do most of the work, or you can write your own rendering code. You just have to include the file, use the functions to obtain and draw the content, and then provide your own CSS styling. Example:
<div class="items"> <?php include("aggregate.php"); render_aggregate_items(aggregate_items()); ?> </div> |
A more comprehensive example is in sample.php.
The code is GPL, so use it however you want – keep the header comments there, though.
Read More