You are here

function twitter_account_save in Twitter 7.4

Same name and namespace in other branches
  1. 6.5 twitter.inc \twitter_account_save()
  2. 6.3 twitter.inc \twitter_account_save()
  3. 6.4 twitter.inc \twitter_account_save()
  4. 7.6 twitter.inc \twitter_account_save()
  5. 7.3 twitter.inc \twitter_account_save()
  6. 7.5 twitter.inc \twitter_account_save()

Saves a TwitterUser object to {twitter_account}

5 calls to twitter_account_save()
twitter_account_list_form_submit in ./twitter.pages.inc
Form submit handler for altering the list of Twitter accounts.
twitter_fetch_mentions_timeline in ./twitter.inc
Fetches user's mentions.
twitter_fetch_user_timeline in ./twitter.inc
Fetches a user's timeline
twitter_oauth_callback_form_submit in ./twitter.pages.inc
Handle a Twitter OAuth return request and store the account creds in the DB. Redirects to user/%/edit/twitter
_twitter_signin_add_account in twitter_signin/twitter_signin.module
Relates a user account with a Twitter account.

File

./twitter.inc, line 28

Code

function twitter_account_save($twitter_user, $save_auth = FALSE, $account = NULL) {
  $values = (array) $twitter_user;
  $values['twitter_uid'] = $values['id'];

  // bool => int for DB storage
  foreach (array(
    'protected',
    'verified',
    'profile_background_tile',
  ) as $k) {
    if (isset($values[$k])) {
      $values[$k] = (int) $values[$k];
    }
  }
  if ($save_auth) {
    $values += $twitter_user
      ->get_auth();
    if (empty($account)) {
      global $user;
      $account = $user;
    }
    $values['uid'] = $account->uid;
  }
  $schema = drupal_get_schema('twitter_account');
  foreach ($values as $k => $v) {
    if (!isset($schema['fields'][$k])) {
      unset($values[$k]);
    }
  }
  if (!isset($values['uid'])) {
    $values['uid'] = 0;
  }
  db_merge('twitter_account')
    ->key(array(
    'twitter_uid' => $values['twitter_uid'],
  ))
    ->fields($values)
    ->execute();

  // Notify other modules of the twitter account save
  if (!empty($account)) {
    module_invoke_all('twitter_account_save', $account, $values);
  }
}