You are here

public function SocialContentFacebook::prepareRow in Social Content 7.2

Do the uploads and attach expected fields to a row about to be imported.

Overrides SocialContent::prepareRow

File

modules/facebook/social_content_facebook.class.inc, line 194
Social Content Facebook class.

Class

SocialContentFacebook
@file Social Content Facebook class.

Code

public function prepareRow($row) {

  // Only add direct wall posts.
  if (isset($row->to)) {
    return FALSE;
  }

  // Discard updates without content.
  if (!isset($row->message)) {
    return FALSE;
  }
  $global_settings = $this->settings['global'];
  $settings = $this->settings['instance'];
  $id_parts = explode('_', $row->id);
  $row->id = $id_parts[1];
  $row->link = 'http://www.facebook.com/' . $row->from->id . '/posts/' . $row->id;
  $row->created = strtotime($row->created_time);
  $row->account = $row->from->name;
  $row->account_link = 'http://www.facebook.com/' . $row->from->id;
  if (parent::prepareRow($row) === FALSE) {
    return FALSE;
  }
  if (!empty($row->full_picture)) {
    $validators = array();
    if (!empty($settings['min_resolution'])) {
      $validators = array(
        'file_validate_image_resolution' => array(
          0,
          $settings['min_resolution'],
        ),
      );
    }
    $image_url = $this
      ->getImageUrl($row, $global_settings);
    if ($image_url) {
      $mappings = $this
        ->getFieldMappings();
      $picture = $this
        ->saveExternalFile($image_url, $mappings['picture'], $validators);
    }
  }

  // For legacy reasons we store this in $row->picture.
  // Facebook changed where they stored this field.
  // See https://www.drupal.org/node/2559873
  $row->picture = !empty($picture) ? $picture : NULL;
  return TRUE;
}