public function FeedsFacebookParser::parse in Feeds: Facebook parser 7
Same name and namespace in other branches
- 6 FeedsFacebookParser.inc \FeedsFacebookParser::parse()
File
- ./
FeedsFacebookParser.inc, line 12 - Facebook feeds parser class.
Class
- FeedsFacebookParser
- Class definition for Facebook Parser.
Code
public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
$facebook_feed = $fetcher_result
->getRaw();
$result = new FeedsParserResult();
$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,
);
}
}
$result->items = $items;
return $result;
}