Ruby on Rails Helpers - Some of the Ruby/Rails helpers that I have created and use. Take ‘em
getRSS
Can be used as a Wordpress plugin or standalone
Description
This script makes it easy for you to display RSS feeds in a readable format on your website. It would be great for showing @commented-on, del.icio.us, Technorati or even your companies’ feed.
Although the format of this script is Wordpress plugin orientated, it doesn’t need Wordpress and can be used as a general function (by removing everything around function { … }). Unfortunately, this is PHP5 only as it takes advantage of PHP5’s DOM functions.
NOTE: You can implement this into a website multiple times but this version does NOT have caching yet, so if you are calling someone else’s feed, be gentle.
/*
Plugin Name: getRSS
Plugin URI: http://www.zachinglis.com/projects/getrss/
Description: Example: <?php echo getFeed('http://www.website.com/feed','<li>','</li>'); ?> and then stick it in between a <ul>
Author: Jeremy Keith & Zach Inglis
Author URI: http://www.adactio.com
Version: 1.00
Based upon the original Gravatar plugin:
http://gravatar.com/implement.php#section_2_2
*/
function getFeed($feed,$before=’
‘) {
$return = “”;
$rss = new DOMDocument();
if (!$rss -> load($feed)) {
return $before.”Couldn’t find RSS file.”.$after;
}
$count = 0;
foreach ($rss -> getElementsByTagName(”item”) as $item) {
if ($item -> getElementsByTagName(”title”) -> item(0)) {
$return.= $before;
$return.= “
$return.= $item -> getElementsByTagName(”link”) -> item(0) -> nodeValue;
$return.= “\” title=\”View the ‘”;
$return.= $item -> getElementsByTagName(”title”) -> item(0) -> nodeValue;
$return.= “‘ entry \”>”;
$return.= $item -> getElementsByTagName(”title”) -> item(0) -> nodeValue;
$return.= ““;
$return.= $after;
$return.= “\n”;
}
$count ++;
}
if ($count == 0) {
$return = $before.”This feed has no items.”.$after;
}
if ($count > 10) { return; }
return $return;
}
?>



