You are here

function fb_app_user in Drupal for Facebook 7.3

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. 6.2 fb_app.module \fb_app_user()

Implements hook_user.

File

./fb_app.module, line 206
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);
        if (fb_facebook_user($fb)) {
          try {
            $info = $fb
              ->api(array(
              'method' => 'users.getInfo',
              'uids' => array(
                $fbu,
              ),
              'fields' => array(
                'about_me',
                'affiliations',
                'name',
                'is_app_user',
                'pic_big',
                'profile_update_time',
                'status',
              ),
            ));
            if (isset($info) && count($info)) {
              $output = theme('fb_app_user_info', $fb_app, $info[0]);
              $items[$fb_app->label] = array(
                '#title' => $fb_app->title,
                '#type' => 'fieldset',
                'value' => array(
                  '#value' => $output,
                ),
              );
            }
          } catch (Exception $e) {
            fb_log_exception($e, "Failed to get Facebook user info for account {$fbu}");
          }
        }
      }
    }
    if (count($items)) {
      $account->content['fb_app'] = $items;
      $account->content['fb_app']['#weight'] = 6;

      // Appear after history (user.module)
    }
  }
}