You are here

function fb_admin_add_token_form_submit in Drupal for Facebook 7.4

File

./fb.admin.inc, line 478

Code

function fb_admin_add_token_form_submit(&$form, &$form_state) {
  extract($form_state['fb']);

  // $app, $me, $token, $options
  $status = $options['status'];
  if ($token) {
    $status |= FB_STATUS_FLAG_VALID;
    $fba = $app['id'];

    // Application ID.
    if (empty($me)) {
      $record->status |= FB_STATUS_FLAG_APP;

      // It's an app token.
      $me = $app;

      // Use app ID for $fbu.
    }
    $fbu = $me['id'];

    // User ID.
    $data = empty($form_state['values']['data']) ? NULL : $form_state['values']['data'];
    $result = fb_token_save($token, array(
      'fba' => $fba,
      'fbu' => $fbu,
      'status' => $status,
    ));
    if ($result) {
      drupal_set_message(t('Saved !user\'s access token for !app.', array(
        '!user' => l($me['name'], $me['link']),
        '!app' => l($app['name'], $app['link']),
      )));
    }
    else {
      drupal_set_message(t('Failed to save token!'), 'error');
    }
  }
  if (!empty($form_state['fb_user_token'])) {
    extract($form_state['fb_user_token']);
  }
  if (!empty($user_token)) {
    $result = fb_token_save($user_token, array(
      'graph' => $graph,
      'fba' => $graph['app']['id'],
      'fbu' => $graph['me']['id'],
      'status' => FB_STATUS_FLAG_VALID | FB_STATUS_FLAG_ADMIN,
    ));
    if ($result) {
      drupal_set_message(t('Saved !user\'s access token for !app.', array(
        '!user' => l($graph['me']['name'], $graph['me']['link']),
        '!app' => l($graph['app']['name'], $graph['app']['link']),
      )));
    }
    else {
      drupal_set_message(t('Failed to save token!'), 'error');
    }
  }
}