PHP
Feed your site with RSS
Do you need to feed your site? It's possible with RSS. Just use this script and you are done! You can set multiple feeds and show them as on list.
This script is written for PHP5 or higher. I will write one for PHP4, but got no time right now. I also need to build in some cache otherwise it will slowdone the loading time of your page.
Does this script work? Yes, you can see the demo or live version on my homepage (del.icio.us links).
The Script
$iRssItems = 20;
$oRSS = new RSSreader();
$oRSS->setRSSfeed( 'http://del.icio.us/rss/dicabrio' );
$oRSS->parseFeeds();
if( $oRSS->length() < $iRssItems )
{
$iRssItems = $oItemList->length;
}
echo '<ul>';
for( $i=0; $i < $iRssItems; $i++ )
{
$oRSSitem = $oRSS->getFeedItem( $i );
echo '<li><span title="'. $oRSSitem->getTag( 'link' )
.'">'.substr( $oRSSitem->getTag( 'title' ), 0, 28 )
. '</span></li>';
}
echo '</ul>';
// classes
class RSSreader extends DOMDocument
{
private $m_aRSSfeeds;
private $m_aFeedItems;
public function __construct()
{
$this->m_aRSSfeeds = array();
}
public function setRSSfeed( $p_sFileName )
{
if( !in_array( $p_sFileName, $this->m_aRSSfeeds ) )
{
$this->m_aRSSfeeds[] = $p_sFileName;
}
}
public function parseFeeds()
{
// Loop throught the feeds specified
for( $i=0; $i < count( $this->m_aRSSfeeds ); $i++ )
{
parent::load( $this->m_aRSSfeeds[$i] );
$this->m_oFeedItems = parent::getElementsByTagName( 'item' );
foreach( $this->m_oFeedItems as $oFeedItem )
{
$this->m_aFeedItems[] = new RSSfeedItem( $oFeedItem );
}
}
}
public function getFeedItem( $p_iItemNum )
{
if( isset( $this->m_aFeedItems[$p_iItemNum]) )
{
return $this->m_aFeedItems[$p_iItemNum];
}
}
public function getFeedItems()
{
return $this->m_aFeedItems;
}
public function length()
{
return count( $this->m_aFeedItems );
}
}
class RSSfeedItem
{
private $m_oFeedItem;
public function __construct( $p_oFeedItem )
{
$this->m_oFeedItem = $p_oFeedItem;
}
public function getTag( $p_sTagName )
{
return $this->m_oFeedItem->getElementsByTagName( $p_sTagName )¶
->item(0)->nodeValue;
}
}
