I'm setting up an rss feed amalgamator on a site and I've found this great code which I've tweaked to suit the site.

Here's the code below which works fine but the problem I've got is that I can't work out how to get the posts to display based on date order or how to limit the number of posts pulled in from each feed.

Any help with this would be greatly appreciated.

PHP Code:
<?php
 
class Feed_Amalgamator
{
    public 
$urls = array();
    public 
$data = array();
 
    public function 
addFeeds( array $feeds )
    {
        
$this->urls array_merge$this->urlsarray_values($feeds) );
    }
 
    public function 
grabRss()
    {
        foreach ( 
$this->urls as $feed )
        {
            
$data = @new SimpleXMLElement$feed0true );
            if ( !
$data )
                throw new 
Exception'Could not load: ' $feed );
            foreach ( 
$data->channel->item as $item )
            {
                
$this->data[] = $item;
            }
        }
    }
 
    public function 
amalgamate()
    {
        
shuffle$this->data );
        
$temp = array();
        foreach ( 
$this->data as $item )
        {
            if ( !
in_array($item->link$this->links($temp)) )
            {
                
$temp[] = $item;
            }
        }
        
$this->data $temp;
        
shuffle$this->data );
    }
 
    private function 
links( array $items )
    {
        
$links = array();
        foreach ( 
$items as $item )
        {
            
$links[] = $item->link;
        }
        return 
$links;
    }
}
 
/********* Example *********/
 
$urls = array( 'http://news.sky.com/feeds/rss/technology.xml''http://en.nauticwebnews.com/feed/''http://en.nauticwebnews.com/category/companies/events-companies/feed/''http://www.cobham.com/rss.aspx');
 
try
{
    
$feeds = new Feed_Amalgamator;
    
$feeds->addFeeds$urls );
    
$feeds->grabRss();
    
$feeds->amalgamate();
}
catch ( 
exception $e )
{
    die( 
$e->getMessage() );
}
 
foreach ( 
$feeds->data as $item ) :
extract( (array) $item );

$Mydate strtotime($pubDate);
$day date('m'$Mydate);
$month date('M'$Mydate);  
?>
<div class="entry clearfix">
    <div class="entry_c">
    <div class="entry_date">
    <div class="day"><?php echo $day?></div>
    <div class="month"><?php echo $month?></div>
    </div>
    <div class="entry_title"><h2><a href="<?php echo $link?>"><?php echo $title?></a></h2></div>
    
    <div class="clear"></div>
    <span class="page-divider"></span>
    <div class="entry_content">
    <?php echo $description?>
    </div>
    </div>
    </div>
<?php endforeach; ?>