From c0658ced68e802abe44e828583b3467ee7c5498f Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sat, 8 Jul 2017 07:40:40 -0700 Subject: [PATCH] store author info for tweets and full tweet json --- app/Http/Controllers/ImportController.php | 3 ++ app/Http/Controllers/TwitterController.php | 3 ++ app/Tweet.php | 2 +- .../2017_07_08_143449_add_tweet_userinfo.php | 34 +++++++++++++++++++ .../2017_07_08_143922_store_full_tweet.php | 32 +++++++++++++++++ resources/views/components/tweet.blade.php | 8 +++-- 6 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2017_07_08_143449_add_tweet_userinfo.php create mode 100644 database/migrations/2017_07_08_143922_store_full_tweet.php diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php index d44dab4..5d4118f 100644 --- a/app/Http/Controllers/ImportController.php +++ b/app/Http/Controllers/ImportController.php @@ -112,6 +112,9 @@ class ImportController extends BaseController $tweet->tweet_date = date('Y-m-d H:i:s', strtotime($data->created_at)); $tweet->geo = json_encode($data->geo); $tweet->place = json_encode($data->place); + $tweet->author_username = $data->user->screen_name; + $tweet->author_photo = $data->user->profile_image_url_https; + $tweet->json = json_encode($data); return $tweet; } diff --git a/app/Http/Controllers/TwitterController.php b/app/Http/Controllers/TwitterController.php index bf4f4c3..6e05c25 100644 --- a/app/Http/Controllers/TwitterController.php +++ b/app/Http/Controllers/TwitterController.php @@ -57,10 +57,13 @@ class TwitterController extends BaseController $tweet->photo = json_encode($photos, JSON_UNESCAPED_SLASHES); $tweet->mission_id = $mission_id; $tweet->tweet_date = date('Y-m-d H:i:s', strtotime($data['created_at'])); + $tweet->author_username = $data['user']['screen_name']; + $tweet->author_photo = $data['user']['profile_image_url_https']; if(isset($data['geo'])) $tweet->geo = json_encode($data['geo']); if(isset($data['place'])) $tweet->place = json_encode($data['place']); + $tweet->json = json_encode($data); $tweet->save(); if($tweet->mission_id && $tweet->team_id) { diff --git a/app/Tweet.php b/app/Tweet.php index 8d72df2..d856a4a 100644 --- a/app/Tweet.php +++ b/app/Tweet.php @@ -56,7 +56,7 @@ class Tweet extends Model } public function twitter_permalink() { - return 'https://twitter.com/'.$this->player->twitter.'/status/'.$this->tweet_id; + return 'https://twitter.com/'.($this->player ? $this->player->twitter : $this->author_username).'/status/'.$this->tweet_id; } public static function claimed_timeout() { diff --git a/database/migrations/2017_07_08_143449_add_tweet_userinfo.php b/database/migrations/2017_07_08_143449_add_tweet_userinfo.php new file mode 100644 index 0000000..169ba17 --- /dev/null +++ b/database/migrations/2017_07_08_143449_add_tweet_userinfo.php @@ -0,0 +1,34 @@ +string('author_username', 255); + $table->string('author_photo', 255); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('tweets', function (Blueprint $table) { + $table->dropColumn('author_username'); + $table->dropColumn('author_photo'); + }); + } +} diff --git a/database/migrations/2017_07_08_143922_store_full_tweet.php b/database/migrations/2017_07_08_143922_store_full_tweet.php new file mode 100644 index 0000000..0a79cfe --- /dev/null +++ b/database/migrations/2017_07_08_143922_store_full_tweet.php @@ -0,0 +1,32 @@ +binary('json'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('tweets', function (Blueprint $table) { + $table->dropColumn('json'); + }); + } +} diff --git a/resources/views/components/tweet.blade.php b/resources/views/components/tweet.blade.php index b884493..8ffb6ee 100644 --- a/resources/views/components/tweet.blade.php +++ b/resources/views/components/tweet.blade.php @@ -1,8 +1,12 @@
- - {{ '@'.$tweet->player->twitter }} + @if($tweet->player) + + {{ '@'.$tweet->player->twitter }} + @else + + @endif
{!! Twitter::linkify($tweet->text) !!}