You are here

function fb_user_fb in Drupal for Facebook 7.4

Same name and namespace in other branches
  1. 5.2 fb_user.module \fb_user_fb()
  2. 5 fb_user.module \fb_user_fb()
  3. 6.3 fb_user.module \fb_user_fb()
  4. 6.2 fb_user.module \fb_user_fb()
  5. 7.3 fb_user.module \fb_user_fb()

Implements hook_fb().

File

./fb_user.module, line 137
This module manages relations between local Drupal user accounts and their accounts on facebook.com.

Code

function fb_user_fb($op, $data, &$return) {

  // TODO: handle session_change.
  if ($op == FB_OP_AJAX && $data['event_type'] == 'fb_new_token') {

    // User has connected to facebook.
    $orig_user = $GLOBALS['user'];
    _fb_user_process_new_token($data['access_token']);
    fb_invoke(FB_USER_OP_TOKEN, array(
      'access_token' => $data['access_token'],
    ), NULL, 'fb_user');
    if ($GLOBALS['user']->uid != $orig_user->uid) {

      // We've become a new user.  Tell fb.js to reload the page.
      if (empty($return['fb_user'])) {
        $return['fb_user'] = 'FB_JS.reload();';
      }
    }
  }
  elseif ($op == FB_OP_TOKEN_USER && !fb_is_ajax()) {

    // User has connected to facebook.
    $orig_user = $GLOBALS['user'];
    _fb_user_process_new_token($data['access_token']);
    fb_invoke(FB_USER_OP_TOKEN, array(
      'access_token' => $data['access_token'],
    ), NULL, 'fb_user');
    if ($GLOBALS['user']->uid != $orig_user->uid) {

      // We've become a new user.  Reload the page.
      drupal_goto(current_path());
    }
  }
}