Пример #1
0
 public static function getFeedStructureFromXML($oRssFeed, $sXMLString, $sStopAt)
 {
     // called when parsing rss feeds, tries to convert a mixed xml string into a structured object
     $oParsedFeed = self::oXMLStringToFeedObject($sXMLString);
     // go through each feed item and save into our system
     foreach ($oParsedFeed->aoItems as $oDataOnlyFeedItem) {
         $oFeedItem = new FeedItem();
         $oFeedItem->title = $oDataOnlyFeedItem->title;
         $oFeedItem->url = $oDataOnlyFeedItem->url;
         $oFeedItem->guid = $oDataOnlyFeedItem->guid;
         $oFeedItem->pubDate = $oDataOnlyFeedItem->pubDate;
         $oFeedItem->feed_id = $oRssFeed->id;
         /*
         if ($oParsedFeed->bPic) {
             $oFeedItem->thumb = $oDataOnlyFeedItem->thumb;
         }
         */
         $oFeedItem->save();
         // schedule crunching our scraping thumb..
         if (!$oParsedFeed->bPic) {
             // schedule for image scrape
             Feeds::scheduleFeedItemImageScrape($oFeedItem->id);
         } else {
             // we have a thumbnail but need to make sure it's the correct size
             Feeds::scheduleThumbCrunch($oFeedItem->sPicURL, $oFeedItem->id);
         }
         $oFeedItem->save();
     }
     return $oParsedFeed;
 }
Пример #2
0
 public static function scrapeThumbFromFeedItem($iFeedItemId)
 {
     try {
         $oFeedItem = FeedItem::find($iFeedItemId);
         $sUrlToHit = $oFeedItem->url;
         ////echo "scrape: ", $sUrlToHit, "<br/>";
         $page_content = @file_get_contents($sUrlToHit);
         if (!empty($page_content)) {
             $dom_obj = new DOMDocument();
             libxml_use_internal_errors(true);
             $dom_obj->loadHTML($page_content);
             $meta_val = null;
             foreach ($dom_obj->getElementsByTagName('meta') as $meta) {
                 if ($meta->getAttribute('property') == 'og:image') {
                     $meta_val = $meta->getAttribute('content');
                     break;
                 }
             }
             if (isset($meta_val)) {
                 self::storeThumbForFeedItem($oFeedItem, $meta_val);
             } else {
                 $oFeedItem->thumb = '';
                 $oFeedItem->save();
             }
         }
     } catch (Exception $e) {
     }
 }