Swiftriver\Core\Modules\SiSPS\Parsers\GoogleNewsParser::GetSimplePieContentEntries PHP Method

GetSimplePieContentEntries() public method

public GetSimplePieContentEntries ( $feedUrl, $logger, $channel )
    function GetSimplePieContentEntries($feedUrl, $logger, $channel)
    {
        //Include the Simple Pie Framework to get and parse feeds
        $config = \Swiftriver\Core\Setup::Configuration();
        $simplePiePath = $config->ModulesDirectory . "/SimplePie/simplepie.inc";
        include_once $simplePiePath;
        //Include the Simple Pie YouTube Framework
        $simpleTubePiePath = $config->ModulesDirectory . "/SimplePie/simpletube.inc";
        include_once $simpleTubePiePath;
        $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [END: Including the SimplePie module]", \PEAR_LOG_DEBUG);
        //Construct a new SimplePie Parser
        $feed = new \SimplePie();
        //Get the cache directory
        $cacheDirectory = $config->CachingDirectory;
        $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [Setting the caching directory to {$cacheDirectory}]", \PEAR_LOG_DEBUG);
        //Set the caching directory
        $feed->set_cache_location($cacheDirectory);
        $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [Setting the feed url to {$feedUrl}]", \PEAR_LOG_DEBUG);
        //Pass the feed URL to the SImplePie object
        $feed->set_feed_url($feedUrl);
        $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [Initializing the feed]", \PEAR_LOG_DEBUG);
        //Run the SimplePie
        $feed->init();
        //Strip HTML
        $feed->strip_htmltags(array('span', 'font', 'style', 'table', 'td', 'tr', 'div', 'p', 'br', 'a'));
        //Create the Content array
        $contentItems = array();
        $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [START: Parsing feed items]", \PEAR_LOG_DEBUG);
        $feeditems = $feed->get_items();
        if (!$feeditems || $feeditems == null || !is_array($feeditems) || count($feeditems) < 1) {
            $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [No feeditems recovered from the feed]", \PEAR_LOG_DEBUG);
        }
        $lastSuccess = $channel->lastSuccess;
        //Loop through the Feed Items
        foreach ($feeditems as $feedItem) {
            //Extract the date of the content
            $contentdate = strtotime($feedItem->get_date());
            if (isset($lastSuccess) && is_numeric($lastSuccess) && isset($contentdate) && is_numeric($contentdate)) {
                if ($contentdate < $lastSuccess) {
                    $textContentDate = date("c", $contentdate);
                    $textlastSuccess = date("c", $lastSuccess);
                    $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [Skipped feed item as date {$textContentDate} less than last sucessful run ({$textlastSuccess})]", \PEAR_LOG_DEBUG);
                    continue;
                }
            }
            $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [Adding feed item]", \PEAR_LOG_DEBUG);
            //Get source data
            $source_name = $feedItem->get_author()->name;
            $source_name = $source_name == null || $source_name == "" ? "Google News Search -" . $this->searchPhrase : $source_name . " @ " . "Google News Search - " . $this->searchPhrase;
            $source = \Swiftriver\Core\ObjectModel\ObjectFactories\SourceFactory::CreateSourceFromIdentifier($source_name, $channel->trusted);
            $source->name = $source_name;
            $source->email = $feedItem->get_author()->email;
            $source->parent = $channel->id;
            $source->type = $channel->type;
            $source->subType = $channel->subType;
            //Extract all the relevant feedItem info
            $title = $feedItem->get_title();
            $description = $feedItem->get_description();
            $contentLink = $feedItem->get_permalink();
            $date = $feedItem->get_date();
            //Create a new Content item
            $item = \Swiftriver\Core\ObjectModel\ObjectFactories\ContentFactory::CreateContent($source);
            //Fill the Content Item
            $item->text[] = new \Swiftriver\Core\ObjectModel\LanguageSpecificText(null, $title, array($description));
            $item->link = $contentLink;
            $item->date = strtotime($date);
            //Add the item to the Content array
            $contentItems[] = $item;
        }
        $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [END: Parsing feed items]", \PEAR_LOG_DEBUG);
        $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [Method finished]", \PEAR_LOG_DEBUG);
        //return the content array
        return $contentItems;
    }