You are here

function twitter_status_save in Twitter 7.6

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.3 twitter.inc \twitter_status_save()
  5. 7.4 twitter.inc \twitter_status_save()
  6. 7.5 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 158

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;
    }
  }
  $twitter_status = new TwitterStatus();
  $twitter_status->twitter_id = $status->id;
  $twitter_status->screen_name = $status->user->screen_name;
  $twitter_status->created_time = strtotime($status->created_at);
  $twitter_status->text = $text;
  $twitter_status->source = $status->source;
  $twitter_status->in_reply_to_status_id = $status->in_reply_to_status_id > 0 ? (string) $status->in_reply_to_status_id : NULL;
  $twitter_status->in_reply_to_user_id = $status->in_reply_to_user_id;
  $twitter_status->in_reply_to_screen_name = $status->in_reply_to_screen_name;
  $twitter_status->truncated = (int) $status->truncated;
  $twitter_status->retweet_count = $status->retweet_count;
  $twitter_status->is_new = entity_load_single('twitter_status', $twitter_status->twitter_id) ? FALSE : TRUE;
  entity_save('twitter_status', $twitter_status);

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