You are here

function fb_app_user in Drupal for Facebook 6.2

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

Implementation of hook_user.

File

./fb_app.module, line 221
Implementation of Drupal for Facebook application.

Code

function fb_app_user($op, &$edit, &$account, $category = NULL) {
  $items = array();
  if ($op == 'view') {
    $apps = fb_get_all_apps();
    foreach ($apps as $fb_app) {

      // Learn this user's FB id
      $fbu = fb_get_fbu($account->uid, $fb_app);
      if ($fbu) {

        // The drupal user is a facebook user.  Now, learn more from facebook.
        $fb = fb_api_init($fb_app, FB_FBU_ANY);
        if (fb_facebook_user($fb)) {
          try {
            $info = $fb->api_client
              ->users_getInfo(array(
              $fbu,
            ), array(
              'about_me',
              'affiliations',
              'name',
              'is_app_user',
              'pic_big',
              'profile_update_time',
              'status',
            ));
          } catch (Exception $e) {
            fb_log_exception($e, "Failed to get Facebook user info for account {$fbu}");
          }
        }
        if (isset($info) && count($info)) {

          // Is this working properly??? TODO!
          $output = theme('fb_app_user_info', $fb_app, $info[0]);
          $items[$fb_app->label] = array(
            'title' => $fb_app->title,
            'value' => $output,
            'class' => 'fb_app',
          );
        }
        else {
          fb_report_errors($fb);
        }
      }
    }
    if (count($items)) {
      return array(
        t('Facebook') => $items,
      );
    }
  }
}