You are here

function fb_get_object_fbu in Drupal for Facebook 7.3

Same name and namespace in other branches
  1. 6.3 fb.module \fb_get_object_fbu()
  2. 6.2 fb.module \fb_get_object_fbu()

Convenience function to learn the fbu associated with a user, node or comment. Used in theming (X)FBML tags.

2 calls to fb_get_object_fbu()
fb_connect_theme_username_override in ./fb_connect.module
Our replacement for theme('username', ...)
fb_connect_theme_user_picture_override in ./fb_connect.module
Our replacement for theme('user_picture', ...)

File

./fb.module, line 1135
This is the core required module of Drupal for Facebook.

Code

function fb_get_object_fbu($object) {
  $cache =& drupal_static(__FUNCTION__);
  if (!isset($cache)) {
    $cache = array();
  }
  if (isset($object->uid) && isset($cache[$object->uid])) {
    $fbu = $cache[$object->uid];
    return $fbu;
  }
  elseif (isset($object->fbu)) {

    // Explicitly set.
    $fbu = $object->fbu;
  }
  elseif (isset($object->init) && ($pos = strpos($object->init, '@facebook'))) {

    // Naming convention used by fb_user when creating accounts.
    // $object->init may be present when object is a user.
    $fbu = substr($object->init, 0, $pos);
  }
  elseif (!empty($object->name) && ($pos = strpos($object->name, '@facebook'))) {
    $fbu = substr($object->name, 0, $pos);
  }
  elseif (!empty($object->uid)) {

    // This can be expensive on pages with many comments or nodes!
    $fbu = fb_get_fbu($object->uid);
  }
  if (isset($fbu) && is_numeric($fbu)) {
    if (isset($object->uid) && $object->uid > 0) {
      $cache[$object->uid] = $fbu;
    }
    return $fbu;
  }
}