all(); // Find the user who tweeted this $twitter_user_id = $data['user']['id_str']; $player = Player::where('twitter_user_id', $twitter_user_id)->first(); if(isset($data['extended_tweet']['full_text'])) $text = $data['extended_tweet']['full_text']; else $text = $data['text']; // Unshorten URLs if(isset($data['entities']['urls'])) { foreach($data['entities']['urls'] as $url) { $text = str_replace($url['url'], $url['expanded_url'], $text); } } // Remove media URLs from tweet text $photos = []; if(isset($data['extended_entities']['media'])) { foreach($data['extended_entities']['media'] as $media) { $text = str_replace($media['url'], '', $text); $photos[] = $media['media_url_https']; } $text = trim($text); } // Find the mission hashtag if(strpos($text, '#transitspy') !== false) $mission = 1; elseif(strpos($text, '#intercept') !== false) $mission = 2; elseif(strpos($text, '#airlair') !== false) $mission = 3; elseif(strpos($text, '#transittea') !== false) $mission = 4; elseif(strpos($text, '#sing') !== false) $mission = 5; elseif(strpos($text, '#passport') !== false) $mission = 6; elseif(strpos($text, '#document') !== false) $mission = 7; else $mission = 0; $tweet = new Tweet; $tweet->player_id = $player ? $player->id : 0; $tweet->team_id = $player ? $player->team->id : 0; $tweet->text = $text; $tweet->photo = json_encode($photos); $tweet->mission = $mission; $tweet->tweet_date = date('Y-m-d H:i:s', strtotime($data['created_at'])); $tweet->save(); // TODO: Broadcast this to the web interface return $data['id_str']; } }