You are here

function twitter_auth_account_form_submit in Twitter 7.6

Same name and namespace in other branches
  1. 6.5 twitter.pages.inc \twitter_auth_account_form_submit()
  2. 7.5 twitter.pages.inc \twitter_auth_account_form_submit()

Form submit handler for adding a Twitter account.

Loads Twitter account details and adds them to the user account

File

./twitter.pages.inc, line 410
Page callbacks for Twitter module.

Code

function twitter_auth_account_form_submit($form, &$form_state) {
  $key = variable_get('twitter_consumer_key', '');
  $secret = variable_get('twitter_consumer_secret', '');
  $oauth_callback = variable_get('twitter_oauth_callback_url', TWITTER_OAUTH_CALLBACK_URL);
  $callback_url = url($oauth_callback, array(
    'absolute' => TRUE,
  ));
  $twitter = new Twitter($key, $secret);
  $params = array(
    'oauth_callback' => $callback_url,
  );
  $token = $twitter
    ->get_request_token($params);
  if (!empty($token)) {
    $_SESSION['twitter_oauth']['token'] = $token;
    $_SESSION['twitter_oauth']['destination'] = $_GET['q'];

    // Check for the overlay.
    if (module_exists('overlay') && overlay_get_mode() == 'child') {
      overlay_close_dialog($twitter
        ->get_authorize_url($token), array(
        'external' => TRUE,
      ));
      overlay_deliver_empty_page();
    }
    else {
      drupal_goto($twitter
        ->get_authorize_url($token));
    }
  }
  else {
    drupal_set_message(t('Could not obtain a valid token from the Twitter API. Please review the configuration.'), 'error');
  }
}