<?php
require_once '../include/Functions.php';
$db = new Functions();
  $urls = array(
        "http://www.daily-mail.co.zm/feed/",
        "http://www.lusakatimes.com/feed/",
        "http://www.times.co.zm/?feed=rss2",
        "http://tumfweko.com/feed/",
        "http://www.engadget.com/rss.xml"
  
        );
$uuid = uniqid('', true);
echo "UUID: ".$uuid;
foreach ($urls as $url) {

    $rss = new DOMDocument();
    $rss->load($url);
    $feeds = $rss->getElementsByTagName('item'); 
    foreach ($feeds as $node) {
                $link = $node->getElementsByTagName('link')->item(0)->nodeValue;
                $title = $node->getElementsByTagName('title')->item(0)->nodeValue;
                $link = $node->getElementsByTagName('link')->item(0)->nodeValue;
                $pubDate = $node->getElementsByTagName('pubDate')->item(0)->nodeValue;
                $description = $node->getElementsByTagName('description')->item(0)->nodeValue;

                $content = '';
                if(isset($node->getElementsByTagName('encoded')->item(0)->nodeValue))
                $content = $node->getElementsByTagName('encoded')->item(0)->nodeValue;
                $pubDate = strftime('%Y-%m-%d %I:%M:%S', strtotime($pubDate));

                $imageLink = '';
                if(isset($node->getElementsByTagName('thumbnail')->item(0)->nodeValue))
                $imageLink = $node->getElementsByTagName('thumbnail')->item(0)->nodeValue;

                $db->addFeed($uuid, $link, $imageLink, $description, $title, $content, $pubDate, $content !== '');

    }

    $db->deleteAllOldFeeds($feeds, $uuid);

}

?>
