You are here

function _fb_user_track in Drupal for Facebook 6.2

Same name and namespace in other branches
  1. 5.2 fb_user.module \_fb_user_track()
  2. 5 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.

Historically this supported infinite sessions. I believe if this data is no longer necessary for the offline access extended permission.

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

File

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

Code

function _fb_user_track($fb, $fb_app, $account) {
  if (variable_get(FB_USER_VAR_STATS, TRUE)) {

    // In special cases, do not modify the uid column.
    $fb_user_data = _fb_user_get_config($fb_app);
    if (!$account->uid || $account->uid == $fb_user_data['not_logged_in_uid'] || $account->uid == $fb_user_data['logged_in_uid']) {

      // Keep data for fbu, even if we do not know uid.
      $uid = 0;
    }
    else {

      // Uid is accurate.
      $uid = $account->uid;
    }
    $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, $uid, $fb_app->apikey, fb_facebook_user($fb));
    if ($result && !db_affected_rows()) {

      // The row for this user was never inserted, or deleted.  Insert now.
      $fbu = fb_facebook_user($fb);
      if ($fbu) {
        $info = fb_users_getInfo(array(
          $fbu,
        ), $fb);
        $data = $info[0];
        $result = db_query("INSERT INTO {fb_user_app} (apikey, fbu, added, session_key, session_key_expires, time_access, uid, proxied_email, time_cron) VALUES ('%s', %d, %d, '%s', %d, %d, %d, '%s', %d)", $fb_app->apikey, $fbu, $data['is_app_user'], $fb->session_key, $fb->session_key_expires, time(), $uid, $data['proxied_email'], 0);
      }
    }
    if ($result === FALSE) {
      watchdog('fb_user', "Failed to update fb_user_app table.", array(), WATCHDOG_ERROR);
    }
  }
}