You are here

function fb_user_load in Drupal for Facebook 5.2

Same name and namespace in other branches
  1. 5 fb.module \fb_user_load()
  2. 6.2 fb.module \fb_user_load()

File

./fb.module, line 478

Code

function fb_user_load($fbu = NULL) {
  global $user;
  if (!$fbu) {

    // default to current logged in user
    $fbu = fb_facebook_user();
  }
  if ($fbu && $user->fbu == $fbu) {
    return $user;
  }
  if ($fbu) {
    $account = user_external_load("{$fbu}-{$fb_app->apikey}@facebook.com");
    if (!$account) {
      $account = user_external_load("{$fbu}@facebook.com");
    }
    if (!$account) {
      $account = user_load(array(
        'uid' => variable_get('fb_facebook_user', 2),
      ));
    }
    if (!$account) {
      watchdog('fb', t('Failed to load user from facebook fbu=%fbu', array(
        '%fbu' => $fbu,
      )), 'error');
    }
    $account->fbu = $fbu;
    return $account;
  }
}