Aside from just plain having control over the formatting and content, the fact that a PHP version of an RSS feed "embedder" gives you a page that Google reads as actual content for indexing and ad placement makes for a big bonus.
This script is the one powering the front page of :phpgeek: that shows the PHP articles from :here:. The next step that I intend to integrate for that site's implementation is to proxy the articles themselves over. In the mean time, it works fairly well.
In order to make the script as flexible as possible and able to be integrated into a variety of loosely coupled systems, this one script can either be included and the main function called from another PHP script or it can be used as a very basic web service and called from a URL.
To include it and call the function would look like this:
include("rss2htmlblock.php");
$php_feedurl = "http://www.wynia.org/wordpress/?feed=rss2&category_name=php";
display_feed($php_feedurl);
That would be replaced by the HTML block.
Calling it by URL looks like this (obviously wrapped to fit):
http://www.wynia.org/onyxcube/rss2htmlblock.php?feedurl=
http://www.wynia.org/wordpress/?feed=rss2&category_name=php
At any rate, here's the script itself, commented to explain.
<?php
//Change the path to your MagpieRSS directory
require_once('/html/lib/magpierss/rss_fetch.inc');
//This is the function wrapper for the functionality.
//$url is an RSS feed URL string
function display_feed($url){
//Use MagpieRSS to grab the content of the feed
$rss = fetch_rss($url);
//If you're curious what it looks like, dump out the contents
//print_r($rss);
//We pull out the channel information.
//This could be used to add a title and link to the feed.
//If you were offering the feed to the public, you
//probably want to do that.
$channel = array_slice($rss->channel,0);
//The items are what we'll display
$items = array_slice($rss->items,0);
//Loop through the items
foreach ($items as $item){
//Grab the useful bits of the item
$id = $item['guid'];
$link = $item['link'];
$subject = $item['title'];
$content = $item['content']['encoded'];
$description = $item['description'];
//spit out the actual HTML.
//The sample shows the description with a link to read the
//real item.
print("<div class='post'>");
print("<div class='post-title'>$subject</div>");
print("<div class='content'>$description <a href='$link'>Read Entire Article</a></div>");
print("</div>");
}
}
//This is the mini web service portion
//Check for a feedurl on the request
if($_GET['feedurl']){
//Show the feed directly
display_feed($_GET['feedurl']);
}
?>
The output is left entirely unstyled, so you'll want to add CSS like the following to make it match your site, but it's functional the way it is. Enjoy.
.post {
width: 450px;
margin-bottom: 20px;
}
.post-title {
font-size: 1.3em;
font-weight: bold;
}
Incidentally, I think this is the basis for a much better system for managing multiple blogs than any I've looked at. I've been frustrated as to exactly what to do with stuff that doesn't really belong on a certain site or stuff that belongs on more than one site. In my vision...
You'd have a central authoring place, where you added the content and did so, not for any specific blog or site. That content would just be a big pile of your authored content. You'd then build feeds for your sites from it. I'd make a :here: feed that would result in the contents of this blog and a :phpgeek: feed that would be its own. This goes along with my belief that RSS is more of a delivery mechanism than anything else and we're going to see a lot more of them being nothing more than customized views and queries.
This would give you a simple, centralized way to build your own blogging network on a variety of topics and the maintenance of the blogging engine would be limited to dropping this script and some caching into place inside a layout template of some sort. It'd be fast, simple, easy to use and easy to maintain. I just need to figure out the big flaw I'm missing that makes it impractical (there always is one).