<?php
   require_once '../include/Functions.php';
        $feeds = array(
            "http://maxburstein.com/rss",
            "http://www.engadget.com/rss.xml",
            "http://www.times.co.zm/?feed=rss2"
  
        );
        
        //Read each feed's items
        $entries = array();
        foreach($feeds as $feed) {
            $xml = simplexml_load_file($feed);
            $entries = array_merge($entries, $xml->xpath("//item"));
        }
        
        //Sort feed entries by pubDate
        usort($entries, function ($feed1, $feed2) {
            return strtotime($feed2->pubDate) - strtotime($feed1->pubDate);
        });
        

        $db = new Functions();
        foreach ($entries as $item)
            $db->addFeed($item->link, $item->imageLink, $item->description, $item->title, $item->{'content:encoded'}, strftime('%Y-%m-%d %I:%M:%S', strtotime($item->pubDate)), isset($item->{'content:encoded'}));
        ?>
        
        <ul><?php
        //Print all the entries
        foreach($entries as $entry){
            ?>
            <li><a href="<?= $entry->link ?>"><?= $entry->title ?></a> (<?= parse_url($entry->link)['host'] ?>)
            <p><?= strftime('%Y-%m-%d %I:%M:%S', strtotime($entry->pubDate)) ?></p>
            <p><?= $entry->pubDate ?></p>
            <p><?= $entry->{'content:encoded'} ?></p></li>
            <?php
          
        }
        ?>
  