You are here

public function FeedsFacebookParser::parse in Feeds: Facebook parser 6

Same name and namespace in other branches
  1. 7 FeedsFacebookParser.inc \FeedsFacebookParser::parse()

Parse content fetched by fetcher.

Extending classes must implement this method.

Parameters

$batch: FeedsImportBatch returned by fetcher.

FeedsSource $source: Source information.

Overrides FeedsParser::parse

File

./FeedsFacebookParser.inc, line 13

Class

FeedsFacebookParser
Class definition for Facebook Parser.

Code

public function parse(FeedsImportBatch $batch, FeedsSource $source) {
  $facebook_feed = $batch
    ->getRaw();
  $json = json_decode($facebook_feed);
  $items = array();
  foreach ($json->data as $entry) {
    if (!isset($entry->to)) {
      $items[] = array(
        'post_id' => $entry->id,
        'from_name' => $entry->from->name,
        'from_category' => $entry->from->category,
        'from_id' => $entry->from->id,
        'to_name' => isset($entry->to) ? $entry->to->data[0]->name : '',
        'to_category' => isset($entry->to) ? $entry->to->data[0]->category : '',
        'to_id' => isset($entry->to) ? $entry->to->data[0]->id : '',
        'message' => $entry->message,
        'picture' => isset($entry->picture) ? $entry->picture : '',
        'link' => isset($entry->link) ? $entry->link : '',
        'source' => isset($entry->source) ? $entry->source : '',
        'name' => isset($entry->name) ? $entry->name : '',
        'caption' => isset($entry->caption) ? $entry->caption : '',
        'description' => isset($entry->description) ? $entry->description : '',
        'icon' => isset($entry->icon) ? $entry->icon : '',
        'type' => isset($entry->type) ? $entry->type : '',
        'likes_count' => isset($entry->likes) ? $entry->likes->count : 0,
        'likes' => isset($entry->likes) ? json_encode($entry->likes) : '',
        'comments_count' => isset($entry->comments) ? $entry->comments->count : 0,
        'comments' => isset($entry->comments) ? json_encode($entry->comments) : '',
        'created_time' => $entry->created_time,
        'updated_time' => $entry->updated_time,
      );
    }
    $batch
      ->setTitle(isset($json->name) ? $json->name : $json->message);
    $batch
      ->setItems($items);
  }
}