class FeedsFacebookParser in Feeds: Facebook parser 6
Same name and namespace in other branches
- 7 FeedsFacebookParser.inc \FeedsFacebookParser
Class definition for Facebook Parser.
Hierarchy
- class \FeedsConfigurable
- class \FeedsPlugin implements FeedsSourceInterface
- class \FeedsParser
- class \FeedsFacebookParser
- class \FeedsParser
- class \FeedsPlugin implements FeedsSourceInterface
Expanded class hierarchy of FeedsFacebookParser
1 string reference to 'FeedsFacebookParser'
- feeds_facebook_feeds_plugins in ./
feeds_facebook.module - Implementation of hook_feeds_plugins().
File
- ./
FeedsFacebookParser.inc, line 11
View source
class FeedsFacebookParser extends FeedsParser {
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);
}
}
public function getMappingSources() {
return parent::getMappingSources() + array(
'post_id' => array(
'name' => t('Post id'),
'description' => t('Facebook post id'),
),
'from_name' => array(
'name' => t('From: name'),
'description' => t(''),
),
'from_category' => array(
'name' => t('From: category'),
'description' => t(''),
),
'from_id' => array(
'name' => t('From: id'),
'description' => t(''),
),
'to_name' => array(
'name' => t('To: name'),
'description' => t(''),
),
'to_category' => array(
'name' => t('To: category'),
'description' => t(''),
),
'to_id' => array(
'name' => t('To: id'),
'description' => t(''),
),
'message' => array(
'name' => t('Message'),
'description' => t(''),
),
'picture' => array(
'name' => t('Picture'),
'description' => t('Picture or screenshot of the post'),
),
'name' => array(
'name' => t('Name'),
'description' => t('Post name, could be a file name'),
),
'link' => array(
'name' => t('Link'),
'description' => t(''),
),
'source' => array(
'name' => t('Source'),
'description' => t('Music file source'),
),
'description' => array(
'name' => t('Description'),
'description' => t(''),
),
'icon' => array(
'name' => t('Icon'),
'description' => t(''),
),
'type' => array(
'name' => t('Type'),
'description' => t('Type of post'),
),
'likes' => array(
'name' => t('Likes'),
'description' => t('Likes json encoded'),
),
'likes_count' => array(
'name' => t('Likes count'),
'description' => t('Number of likes'),
),
'comments' => array(
'name' => t('Comments'),
'description' => t('Comments json encoded'),
),
'comments_count' => array(
'name' => t('Comments count'),
'description' => t('Number of comments'),
),
'created_time' => array(
'name' => t('Created time'),
'description' => t('Date/time'),
),
'updated_time' => array(
'name' => t('Updated time'),
'description' => t('Date/time'),
),
);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FeedsConfigurable:: |
protected | property | ||
FeedsConfigurable:: |
protected | property | CTools export enabled status of this object. | |
FeedsConfigurable:: |
protected | property | ||
FeedsConfigurable:: |
protected | property | ||
FeedsConfigurable:: |
public | function | Similar to setConfig but adds to existing configuration. | 1 |
FeedsConfigurable:: |
public | function | Return default configuration. | 6 |
FeedsConfigurable:: |
public | function | Return configuration form for this object. The keys of the configuration form must match the keys of the array returned by configDefaults(). | 10 |
FeedsConfigurable:: |
public | function | Submission handler for configForm(). | 3 |
FeedsConfigurable:: |
public | function | Validation handler for configForm(). | 3 |
FeedsConfigurable:: |
public | function | Copy a configuration. | 1 |
FeedsConfigurable:: |
public | function | Determine whether this object is persistent and enabled. I. e. it is defined either in code or in the database and it is enabled. | 1 |
FeedsConfigurable:: |
public | function | Implementation of getConfig(). | 1 |
FeedsConfigurable:: |
public static | function | Instantiate a FeedsConfigurable object. | 1 |
FeedsConfigurable:: |
public | function | Set configuration. | 1 |
FeedsConfigurable:: |
public | function | Override magic method __get(). Make sure that $this->config goes through getConfig() | |
FeedsConfigurable:: |
public | function | Override magic method __isset(). This is needed due to overriding __get(). | |
FeedsFacebookParser:: |
public | function |
Declare the possible mapping sources that this parser produces. Overrides FeedsParser:: |
|
FeedsFacebookParser:: |
public | function |
Parse content fetched by fetcher. Overrides FeedsParser:: |
|
FeedsParser:: |
public | function | Clear all caches for results for given source. | |
FeedsParser:: |
public | function | Get an element identified by $element_key of the given item. The element key corresponds to the values in the array returned by FeedsParser::getMappingSources(). | 1 |
FeedsPlugin:: |
public | function |
Returns TRUE if $this->sourceForm() returns a form. Overrides FeedsSourceInterface:: |
|
FeedsPlugin:: |
protected static | function | Loads on-behalf implementations from mappers/ directory. | |
FeedsPlugin:: |
public | function |
Save changes to the configuration of this object.
Delegate saving to parent (= Feed) which will collect
information from this object by way of getConfig() and store it. Overrides FeedsConfigurable:: |
|
FeedsPlugin:: |
public | function |
Implementation of FeedsSourceInterface::sourceDefaults(). Overrides FeedsSourceInterface:: |
1 |
FeedsPlugin:: |
public | function |
A source is being deleted. Overrides FeedsSourceInterface:: |
1 |
FeedsPlugin:: |
public | function |
Callback methods, exposes source form. Overrides FeedsSourceInterface:: |
3 |
FeedsPlugin:: |
public | function |
Validation handler for sourceForm. Overrides FeedsSourceInterface:: |
2 |
FeedsPlugin:: |
public | function |
A source is being saved. Overrides FeedsSourceInterface:: |
1 |
FeedsPlugin:: |
protected | function |
Constructor. Overrides FeedsConfigurable:: |