You are here

function fb_permission_user in Drupal for Facebook 6.2

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

Implementation of hook_user.

File

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

Code

function fb_permission_user($op, &$edit, &$account, $category = NULL) {
  global $user;
  if ($op == 'categories') {
    $items = array();

    // A tab for each application
    foreach (fb_get_all_apps() as $fb_app) {

      // TODO: limit only to apps which can be added to a user's account.
      $items[] = array(
        'name' => $fb_app->label,
        'title' => $fb_app->label,
        // TODO: human-readable title.
        'access callback' => 'fb_permission_access_own',
        'access arguments' => array(
          1,
          'edit own extended permissions',
        ),
        'weight' => 2,
      );
    }
    return $items;
  }
  elseif ($op == 'form') {

    // See if the category corresponds to a facebook app.
    $fb_app = fb_get_app(array(
      'label' => $category,
    ));
    if ($fb_app) {
      $map = fb_permission_map();

      // All known permissions.
      // Show only permissions we've configured for this app.
      $fb_app_data = fb_get_app_data($fb_app);
      $fb_permission_data = $fb_app_data['fb_permission'];
      if (is_array($fb_permission_data['map'])) {
        foreach ($fb_permission_data['map'] as $key => $value) {
          if (!$value) {
            unset($map[$key]);
          }
        }
      }

      //TODO: support for non-fbml pages
      $form = fb_permission_form_fbml($fb_app, $map);
      $form['description'] = array(
        '#type' => 'markup',
        '#value' => l(t('All settings for %application (and other Facebook Applications).', array(
          '%application' => $fb_app->title,
        )), 'http://www.facebook.com/editapps.php', array(
          'html' => TRUE,
        )),
        '#prefix' => '<p>',
        '#suffix' => "</p>\n",
      );

      // A value for hook_form_alter to find.
      $form['_fb_permission'] = array(
        '#type' => 'value',
        '#value' => TRUE,
      );
      return $form;
    }
  }
}