You are here

function fb_admin_replace_token_form_submit in Drupal for Facebook 7.4

1 string reference to 'fb_admin_replace_token_form_submit'
fb_admin_replace_token_form in ./fb.admin.inc

File

./fb.admin.inc, line 255

Code

function fb_admin_replace_token_form_submit($form, &$form_state) {
  extract($form_state['fb_vars']);

  // $variable, $options
  $values = $form_state['values'];
  $long_token = NULL;
  $token = NULL;
  foreach (array(
    'fb_admin_token_select',
    'fb_admin_token_generate',
  ) as $key) {
    if ($values[$key] && $values[$key] != -1) {
      $token = $values[$key];
    }
  }
  if ($variable) {
    if ($options['replace']) {
      $orig_token = variable_get($variable, NULL);
      db_query("DELETE FROM {fb_token} WHERE access_token = :token", array(
        ':token' => $orig_token,
      ));

      // @todo: delete any other variables that use the expired token.
    }
    variable_del($variable);
  }
  if (!$token) {
    drupal_set_message(t("No token chosen."));
    return;
  }
  extract($form_state['fb_graph']);

  // $app, $me.
  if ($token && $values[FB_VAR_PREFER_LONG_TOKEN]) {
    $long_token = fb_admin_long_lived_token($token, $app['id']);
  }
  if ($long_token) {
    $token = $long_token;
  }
  if ($variable) {
    variable_set($variable, $token);
  }
  if ($options['save']) {
    fb_token_save($token, array(
      'status' => FB_STATUS_FLAG_ADMIN | FB_STATUS_FLAG_VALID,
      'graph' => $form_state['fb_graph'],
    ));
  }
  drupal_set_message(t("Now using access token for %user_name via application %app_name.", array(
    '%user_name' => fb_get_name($me),
    '%app_name' => fb_get_name($app),
  )));
}