You are here

class FeedsFacebookParser in Feeds: Facebook parser 6

Same name and namespace in other branches
  1. 7 FeedsFacebookParser.inc \FeedsFacebookParser

Class definition for Facebook Parser.

Hierarchy

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

Namesort descending Modifiers Type Description Overrides
FeedsConfigurable::$config protected property
FeedsConfigurable::$disabled protected property CTools export enabled status of this object.
FeedsConfigurable::$export_type protected property
FeedsConfigurable::$id protected property
FeedsConfigurable::addConfig public function Similar to setConfig but adds to existing configuration. 1
FeedsConfigurable::configDefaults public function Return default configuration. 6
FeedsConfigurable::configForm 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::configFormSubmit public function Submission handler for configForm(). 3
FeedsConfigurable::configFormValidate public function Validation handler for configForm(). 3
FeedsConfigurable::copy public function Copy a configuration. 1
FeedsConfigurable::existing 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::getConfig public function Implementation of getConfig(). 1
FeedsConfigurable::instance public static function Instantiate a FeedsConfigurable object. 1
FeedsConfigurable::setConfig public function Set configuration. 1
FeedsConfigurable::__get public function Override magic method __get(). Make sure that $this->config goes through getConfig()
FeedsConfigurable::__isset public function Override magic method __isset(). This is needed due to overriding __get().
FeedsFacebookParser::getMappingSources public function Declare the possible mapping sources that this parser produces. Overrides FeedsParser::getMappingSources
FeedsFacebookParser::parse public function Parse content fetched by fetcher. Overrides FeedsParser::parse
FeedsParser::clear public function Clear all caches for results for given source.
FeedsParser::getSourceElement 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::hasSourceConfig public function Returns TRUE if $this->sourceForm() returns a form. Overrides FeedsSourceInterface::hasSourceConfig
FeedsPlugin::loadMappers protected static function Loads on-behalf implementations from mappers/ directory.
FeedsPlugin::save 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::save
FeedsPlugin::sourceDefaults public function Implementation of FeedsSourceInterface::sourceDefaults(). Overrides FeedsSourceInterface::sourceDefaults 1
FeedsPlugin::sourceDelete public function A source is being deleted. Overrides FeedsSourceInterface::sourceDelete 1
FeedsPlugin::sourceForm public function Callback methods, exposes source form. Overrides FeedsSourceInterface::sourceForm 3
FeedsPlugin::sourceFormValidate public function Validation handler for sourceForm. Overrides FeedsSourceInterface::sourceFormValidate 2
FeedsPlugin::sourceSave public function A source is being saved. Overrides FeedsSourceInterface::sourceSave 1
FeedsPlugin::__construct protected function Constructor. Overrides FeedsConfigurable::__construct