You are here

function fb_admin_get_app_info in Drupal for Facebook 6.3

Same name and namespace in other branches
  1. 7.3 fb.admin.inc \fb_admin_get_app_info()
4 calls to fb_admin_get_app_info()
fb_admin_app_page in ./fb.admin.inc
fb_admin_page in ./fb.admin.inc
Drupal page callback.
fb_app_admin_form_submit in ./fb_app.admin.inc
fb_app_edit_form_validate in ./fb_app.admin.inc
Form validation.

File

./fb.admin.inc, line 155
Admin pages and forms for Drupal for Facebook.

Code

function fb_admin_get_app_info(&$fb_app) {
  static $cache;
  static $props_map;
  if (!isset($cache)) {
    $cache = array();

    // https://developers.facebook.com/docs/reference/api/application/
    $props_map = array(
      t('Application Name') => 'name',
      t('Namespace') => 'namespace',
      t('Logo') => 'logo_url',
    );
    $props_map = fb_invoke(FB_ADMIN_OP_LIST_PROPERTIES, array(
      'fb_app' => $fb_app,
    ), $props_map, FB_ADMIN_HOOK);
  }
  if (!isset($cache[$fb_app->id])) {
    if ($fb = fb_api_init($fb_app)) {
      try {
        $info = fb_graph($fb_app->id, array(
          'access_token' => fb_get_token($fb),
          'fields' => implode(',', array_values($props_map)),
        ));
        $cache[$fb_app->id] = $info;
      } catch (Exception $e) {
        fb_log_exception($e, t('Failed to get application properties (%label) from Facebook', array(
          '%label' => $fb_app->label,
        )));
      }
    }
  }
  else {
    $info = $cache[$fb_app->id];
  }

  // Update $fb_app with the values we got from facebook api.
  foreach ($props_map as $key) {
    if (isset($info[$key])) {
      $fb_app->{$key} = $info[$key];
    }
  }
}