You are here

function fb_permission_fb in Drupal for Facebook 6.2

Same name and namespace in other branches
  1. 7.3 contrib/fb_permission.module \fb_permission_fb()

Implementation of hook_fb(). Here we customize the behavior of Drupal for Facebook.

Prompts user for extended permission when they have authorized the application.

Currently supporting only connect pages, not canvas pages.

File

contrib/fb_permission.module, line 207
Code pertaining to Facebook's extended permissions. see http://wiki.developers.facebook.com/index.php/Extended_permissions

Code

function fb_permission_fb($op, $data, &$return) {
  if ($op == FB_APP_OP_EVENT) {
    if ($data['event_type'] == FB_APP_EVENT_POST_AUTHORIZE) {

      // User has authorized the application.
      $fb_app = isset($data['fb_app']) ? $data['fb_app'] : NULL;
      $fb_app_data = fb_get_app_data($fb_app);
      $fb_permission_data = $fb_app_data['fb_permission'];
      if (is_array($fb_permission_data['prompt'])) {
        $perms = array();
        foreach ($fb_permission_data['prompt'] as $key => $value) {
          if ($value) {
            $perms[] = $key;
          }
        }
        if (count($perms)) {

          // http://wiki.developers.facebook.com/index.php/JS_API_M_FB.Connect.ShowPermissionDialog
          $js = "FB.Connect.showPermissionDialog('" . implode(',', $perms) . "')";
          fb_connect_init_js($js);

          // Add javascript to the next page.
        }
      }
    }
  }
}