You are here

function fb_graph_load in Drupal for Facebook 7.3

Implementation of a %wildcard_load(). http://drupal.org/node/224170

Handles menu items with %fb_graph in the path. Seems to get called a lot(!) so we cache.

File

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

Code

function fb_graph_load($id) {
  extract(fb_vars());

  // Drupal stupidly calls this before fb_init()! So _fb may not be initialized.
  if ($GLOBALS['_fb_app'] && !$GLOBALS['_fb']) {
    $fb = fb_api_init($GLOBALS['_fb_app']);
    $fbu = fb_facebook_user($fb);
  }
  $cache =& drupal_static(__FUNCTION__);
  if (!isset($cache)) {
    $cache = array();
  }
  if (!isset($cache[$id])) {
    $params = array(
      'access_token' => fb_get_token($fb, $fbu),
      'metadata' => 1,
    );
    try {
      $cache[$id] = fb_graph($id, $params, 'GET', $fb);
    } catch (Exception $e) {
      fb_log_exception($e, t('Failed to load facebook graph object %id.', array(
        '%id' => $id,
      )));
    }
  }
  return $cache[$id];
}