Browse Source

store author info for tweets and full tweet json

master
Aaron Parecki 7 years ago
parent
commit
c0658ced68
No known key found for this signature in database GPG Key ID: 276C2817346D6056
6 changed files with 79 additions and 3 deletions
  1. +3
    -0
      app/Http/Controllers/ImportController.php
  2. +3
    -0
      app/Http/Controllers/TwitterController.php
  3. +1
    -1
      app/Tweet.php
  4. +34
    -0
      database/migrations/2017_07_08_143449_add_tweet_userinfo.php
  5. +32
    -0
      database/migrations/2017_07_08_143922_store_full_tweet.php
  6. +6
    -2
      resources/views/components/tweet.blade.php

+ 3
- 0
app/Http/Controllers/ImportController.php View File

@ -112,6 +112,9 @@ class ImportController extends BaseController
$tweet->tweet_date = date('Y-m-d H:i:s', strtotime($data->created_at)); $tweet->tweet_date = date('Y-m-d H:i:s', strtotime($data->created_at));
$tweet->geo = json_encode($data->geo); $tweet->geo = json_encode($data->geo);
$tweet->place = json_encode($data->place); $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; return $tweet;
} }

+ 3
- 0
app/Http/Controllers/TwitterController.php View File

@ -57,10 +57,13 @@ class TwitterController extends BaseController
$tweet->photo = json_encode($photos, JSON_UNESCAPED_SLASHES); $tweet->photo = json_encode($photos, JSON_UNESCAPED_SLASHES);
$tweet->mission_id = $mission_id; $tweet->mission_id = $mission_id;
$tweet->tweet_date = date('Y-m-d H:i:s', strtotime($data['created_at'])); $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'])) if(isset($data['geo']))
$tweet->geo = json_encode($data['geo']); $tweet->geo = json_encode($data['geo']);
if(isset($data['place'])) if(isset($data['place']))
$tweet->place = json_encode($data['place']); $tweet->place = json_encode($data['place']);
$tweet->json = json_encode($data);
$tweet->save(); $tweet->save();
if($tweet->mission_id && $tweet->team_id) { if($tweet->mission_id && $tweet->team_id) {

+ 1
- 1
app/Tweet.php View File

@ -56,7 +56,7 @@ class Tweet extends Model
} }
public function twitter_permalink() { 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() { public static function claimed_timeout() {

+ 34
- 0
database/migrations/2017_07_08_143449_add_tweet_userinfo.php View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddTweetUserinfo extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('tweets', function (Blueprint $table) {
$table->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');
});
}
}

+ 32
- 0
database/migrations/2017_07_08_143922_store_full_tweet.php View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class StoreFullTweet extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('tweets', function (Blueprint $table) {
$table->binary('json');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('tweets', function (Blueprint $table) {
$table->dropColumn('json');
});
}
}

+ 6
- 2
resources/views/components/tweet.blade.php View File

@ -1,8 +1,12 @@
<div class="tweet h-entry"> <div class="tweet h-entry">
<div class="profile u-author h-card"> <div class="profile u-author h-card">
<img src="{{ $tweet->player->photo }}" style="border-color: {{ '#'.$tweet->team->color }}" class="u-photo">
<span><a href="https://twitter.com/{{ $tweet->player->twitter }}" class="u-url p-name">{{ '@'.$tweet->player->twitter }}</a></span>
@if($tweet->player)
<img src="{{ $tweet->player->photo }}" style="border-color: {{ '#'.$tweet->team->color }}" class="u-photo">
<span><a href="https://twitter.com/{{ $tweet->player->twitter }}" class="u-url p-name">{{ '@'.$tweet->player->twitter }}</a></span>
@else
<img src="{{ $tweet->author_photo }}" class="u-photo">
@endif
</div> </div>
<div class="text e-content p-name">{!! Twitter::linkify($tweet->text) !!}</div> <div class="text e-content p-name">{!! Twitter::linkify($tweet->text) !!}</div>

Loading…
Cancel
Save