You are here

function fbconnect_get_fb_avatar in Facebook Connect 5

Recupere l'avatar Facebook de l'utilisateur.

Parameters

Int $fbuid:

2 calls to fbconnect_get_fb_avatar()
fbconnect_refresh_user_avatar in ./fbconnect.module
fbconnect_register_user in ./fbconnect.module

File

./fbconnect.module, line 532
This module allows site visitors to connect and register with facebook account

Code

function fbconnect_get_fb_avatar($fbuid) {
  $size = 'pic_with_logo';

  // Get facebook user picture's url.
  $pic_url = fbconnect_get_info_from_fb($fbuid, $size);
  $result = drupal_http_request($pic_url[$size]);
  if ($result->code != 200) {
    watchdog('fbconnect', 'Failed importing facebook user avatar for !fbuid, code : !code', array(
      '!fbuid' => $fbuid,
      '!code' => $result->code,
    ));
    return;
  }
  if ($result->headers['Content-Type'] != 'image/jpeg') {
    watchdog('fbconnect', 'Failed importing facebook user avatar, invalid content-type.');
    return;
  }
  $filename = 'picture-fb_' . $fbuid . '.jpg';
  $dest = file_directory_path();
  if (variable_get('user_picture_path', '')) {
    $dest .= '/' . variable_get('user_picture_path', '');
  }
  $dest .= '/' . $filename;
  return file_save_data($result->data, $dest, FILE_EXISTS_REPLACE);
}