You are here

function _fb_user_track in Drupal for Facebook 5.2

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

Keep track of when the user has visited the app, and whether they've authorized the app or not.

1 call to _fb_user_track()
fb_user_fb in ./fb_user.module
Implementation of hook_fb.

File

./fb_user.module, line 43
This module allows Drupal user records to be associated with Facebook user ids. It can create local user accounts when Facebook users visit an application's canvas pages.

Code

function _fb_user_track($fb, $fb_app, $user) {

  // Keep track of all our app users.  We need this info when updating
  // profiles during cron.  We keep session keys in case user has an
  // infinite session, and we can actually log in as them during cron.
  // In special cases, do not modify the uid column.
  $fb_app_data = fb_app_get_data($fb_app);
  $fb_user_data = $fb_app_data['fb_user'];

  // our configuration
  if (!$user->uid || $user->uid == $fb_user_data['not_logged_in_uid'] || $user->uid == $fb_user_data['logged_in_uid']) {

    // Should we even keep data for users who have not added???
    $result = db_query("UPDATE {fb_user_app} SET time_access=%d, session_key='%s', session_key_expires=%d, uid=NULL WHERE apikey='%s' AND fbu=%d", time(), $fb->api_client->session_key, $fb->session_expires, $fb_app->apikey, fb_facebook_user($fb));
  }
  else {

    // Uid is accurate.
    $result = db_query("UPDATE {fb_user_app} SET time_access=%d, session_key='%s', session_key_expires=%d, uid=%d WHERE apikey='%s' AND fbu=%d", time(), $fb->api_client->session_key, $fb->session_expires, $user->uid, $fb_app->apikey, fb_facebook_user($fb));
  }
  if ($result === FALSE) {
    watchdog('fb_user', t("Failed to update fb_user_app table."), WATCHDOG_ERROR);
  }
}