You are here

function twitter_status_save in Twitter 7.5

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

Saves a TwitterStatus object to {twitter}

2 calls to twitter_status_save()
twitter_fetch_mentions_timeline in ./twitter.inc
Fetches user's mentions of an authenticated account.
twitter_fetch_user_timeline in ./twitter.inc
Fetches a user's timeline.

File

./twitter.inc, line 220

Code

function twitter_status_save($status) {

  // RT's get special handling.
  if (!empty($status->retweeted_status)) {
    if (is_array($status->retweeted_status)) {
      $text = 'RT @' . $status->retweeted_status['user']['screen_name'];
      if (empty($status->retweeted_status['full_text'])) {
        $text .= ': ' . $status->retweeted_status['text'];
      }
      else {
        $text .= ': ' . $status->retweeted_status['full_text'];
      }
    }
    else {
      $text = 'RT @' . $status->retweeted_status->user->screen_name;
      if (empty($status->retweeted_status->full_text)) {
        $text .= ': ' . $status->retweeted_status->text;
      }
      else {
        $text .= ': ' . $status->retweeted_status->full_text;
      }
    }
  }
  else {
    if (empty($status->full_text)) {
      $text = $status->text;
    }
    else {
      $text = $status->full_text;
    }
  }
  $row = array(
    'twitter_id' => $status->id,
    'screen_name' => $status->user->screen_name,
    'created_time' => strtotime($status->created_at),
    'text' => $text,
    'source' => $status->source,
    'in_reply_to_status_id' => $status->in_reply_to_status_id > 0 ? (string) $status->in_reply_to_status_id : NULL,
    'in_reply_to_user_id' => $status->in_reply_to_user_id,
    'in_reply_to_screen_name' => $status->in_reply_to_screen_name,
    'truncated' => (int) $status->truncated,
    'entities' => isset($status->entities) ? serialize($status->entities) : NULL,
  );
  db_merge('twitter')
    ->key(array(
    'twitter_id' => $row['twitter_id'],
  ))
    ->fields($row)
    ->execute();

  // Let other modules know that a status has been saved.
  module_invoke_all('twitter_status_save', $status);
}