You are here

function _janrain_capture_update_picture in Janrain Registration 7

Same name and namespace in other branches
  1. 7.4 janrain_capture.module \_janrain_capture_update_picture()
  2. 7.2 janrain_capture.module \_janrain_capture_update_picture()
  3. 7.3 janrain_capture.module \_janrain_capture_update_picture()

Helper function for updating a user picture.

1 call to _janrain_capture_update_picture()
janrain_capture_sync_account in ./janrain_capture.module
Modifies the user account with values from the Janrain Capture profile array.

File

./janrain_capture.module, line 456
This module implements authentication endpoints for Janrain Capture.

Code

function _janrain_capture_update_picture($account, $variant) {
  $args = array(
    ':uid' => $account->uid,
    ':uri' => $variant['value'],
  );
  if (empty($account->picture) || !db_query('SELECT uid FROM {janrain_capture_photos} WHERE uid = :uid and uri = :uri', $args)
    ->fetchField()) {

    // Either first or updated user profile image. Download remote image,
    // save locally and set user picture to this image.
    $image_response = drupal_http_request($variant['value']);
    if ($image_response->code == 200 && !empty($image_response->data)) {
      $image_file = file_save_data($image_response->data);
      if (!empty($image_file)) {

        // Make the file non-permanent, so we can get it moved and
        // renamed as a proper user picture on the righ path. (which
        // happens inside user_save()).
        $image_file->status = 0;
        $image_file = file_save($image_file);
        $account->picture = $image_file;

        // Keep track of the remote image URI so we only download it once.
        db_merge('janrain_capture_photos')
          ->key(array(
          'uid' => $account->uid,
        ))
          ->fields(array(
          'uid' => $account->uid,
          'uri' => $variant['value'],
        ))
          ->execute();
      }
    }
  }
}