tweet news

This commit is contained in:
HolgerHatGarKeineNode
2023-02-11 16:53:51 +01:00
parent a95e6222d2
commit a067408463
15 changed files with 147 additions and 27 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Http\Livewire\News;
use App\Models\LibraryItem;
use App\Traits\TwitterTrait;
use Livewire\Component;
use RalphJSmit\Laravel\SEO\Support\SEOData;
use WireUi\Traits\Actions;
@@ -10,6 +11,56 @@ use WireUi\Traits\Actions;
class ArticleOverview extends Component
{
use Actions;
use TwitterTrait;
public function tweet($id)
{
$libraryItem = LibraryItem::query()
->with([
'lecturer',
])
->find($id);
$libraryItem->setStatus('published');
$libraryItemName = $libraryItem->name;
if ($libraryItem->lecturer->twitter_username && $libraryItem->type !== 'markdown_article') {
$libraryItemName .= ' von @'.$libraryItem->lecturer->twitter_username;
}
if (!$libraryItem->lecturer->twitter_username) {
$libraryItemName .= ' von '.$libraryItem->lecturer->name;
}
try {
if (config('feeds.services.twitterAccountId')) {
$this->setNewAccessToken(1);
if (!$libraryItem->approved) {
$this->notification()
->error(__('Article not approved yet'));
return;
}
$text = sprintf("Ein neuer News-Artikel wurde verfasst:\n\n%s\n\n%s\n\n#Bitcoin #News #Einundzwanzig #gesundesgeld",
$libraryItemName,
url()->route('article.view',
['libraryItem' => $libraryItem->slug]),
);
$this->postTweet($text);
$libraryItem->tweet = true;
$libraryItem->save();
$this->notification()
->success(__('Article tweeted'));
$this->emit('$refresh');
}
} catch (\Exception $e) {
$this->notification()
->error(__('Error tweeting article', $e->getMessage()));
}
}
public function approve($id)
{
@@ -20,7 +71,7 @@ class ArticleOverview extends Component
$this->notification()
->success(__('Article approved'));
$this->emit('$reload');
$this->emit('$refresh');
}
public function render()

View File

@@ -48,19 +48,6 @@ class LibraryItemObserver
$this->postTweet($text);
}
} else {
if (!$libraryItem->approved) {
return;
}
$text = sprintf("Ein neuer News-Artikel wurde verfasst:\n\n%s\n\n%s\n\n#Bitcoin #News #Einundzwanzig #gesundesgeld",
$libraryItemName,
url()->route('article.view',
['libraryItem' => $libraryItem->slug]),
);
//$this->postTweet($text);
}
}
} catch (\Exception $e) {

View File

@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/**
* Run the migrations.
* @return void
*/
public function up()
{
Schema::table('library_items', function (Blueprint $table) {
$table->string('tweet')
->default(false);
});
}
/**
* Reverse the migrations.
* @return void
*/
public function down()
{
Schema::table('library_items', function (Blueprint $table) {
//
});
}
};

View File

@@ -753,5 +753,9 @@
"Current picture": "Derzeitiges Bild",
"Article approved": "Artikel genehmigt",
"approved": "genehmigt",
"not approved": "nicht genehmigt"
"not approved": "nicht genehmigt",
"Article not approved yet": "Artikel noch nicht genehmigt",
"Article tweeted": "Artikel getwittert",
"Error tweeting article": "Fehler beim Twittern des Artikels",
"Tweet": "Tweet"
}

View File

@@ -749,5 +749,9 @@
"Current picture": "",
"Article approved": "",
"approved": "",
"not approved": ""
"not approved": "",
"Article not approved yet": "",
"Article tweeted": "",
"Error tweeting article": "",
"Tweet": ""
}

View File

@@ -749,5 +749,9 @@
"Current picture": "",
"Article approved": "",
"approved": "",
"not approved": ""
"not approved": "",
"Article not approved yet": "",
"Article tweeted": "",
"Error tweeting article": "",
"Tweet": ""
}

View File

@@ -750,5 +750,9 @@
"Current picture": "",
"Article approved": "",
"approved": "",
"not approved": ""
"not approved": "",
"Article not approved yet": "",
"Article tweeted": "",
"Error tweeting article": "",
"Tweet": ""
}

View File

@@ -750,5 +750,9 @@
"Current picture": "",
"Article approved": "",
"approved": "",
"not approved": ""
"not approved": "",
"Article not approved yet": "",
"Article tweeted": "",
"Error tweeting article": "",
"Tweet": ""
}

View File

@@ -750,5 +750,9 @@
"Current picture": "",
"Article approved": "",
"approved": "",
"not approved": ""
"not approved": "",
"Article not approved yet": "",
"Article tweeted": "",
"Error tweeting article": "",
"Tweet": ""
}

View File

@@ -750,5 +750,9 @@
"Current picture": "",
"Article approved": "",
"approved": "",
"not approved": ""
"not approved": "",
"Article not approved yet": "",
"Article tweeted": "",
"Error tweeting article": "",
"Tweet": ""
}

View File

@@ -750,5 +750,9 @@
"Current picture": "",
"Article approved": "",
"approved": "",
"not approved": ""
"not approved": "",
"Article not approved yet": "",
"Article tweeted": "",
"Error tweeting article": "",
"Tweet": ""
}

View File

@@ -750,5 +750,9 @@
"Current picture": "",
"Article approved": "",
"approved": "",
"not approved": ""
"not approved": "",
"Article not approved yet": "",
"Article tweeted": "",
"Error tweeting article": "",
"Tweet": ""
}

View File

@@ -712,5 +712,9 @@
"Add tag...": "",
"Article approved": "",
"approved": "",
"not approved": ""
"not approved": "",
"Article not approved yet": "",
"Article tweeted": "",
"Error tweeting article": "",
"Tweet": ""
}

View File

@@ -724,5 +724,9 @@
"Current picture": "",
"Article approved": "",
"approved": "",
"not approved": ""
"not approved": "",
"Article not approved yet": "",
"Article tweeted": "",
"Error tweeting article": "",
"Tweet": ""
}

View File

@@ -45,7 +45,7 @@
<p class="mt-3 text-base text-gray-300 line-clamp-6">{{ strip_tags($libraryItem->excerpt) }}</p>
</a>
</div>
<div class="mt-6 flex items-center">
<div class="mt-6 flex items-center w-full">
<div class="flex-shrink-0">
<div>
<span
@@ -67,11 +67,19 @@
<span>{{ $libraryItem->read_time }} {{ __('min read') }}</span>
@endif
</div>
<div class="flex space-x-1 text-sm text-gray-500 justify-end items-end">
<div
class="flex flex-wrap space-x-1 text-sm text-gray-500 justify-end items-end">
@if($libraryItem->created_by === auth()->id() || auth()->user()?->hasRole('news-editor'))
<div>
@if($libraryItem->approved)
<x-badge green>{{ __('approved') }}</x-badge>
@if(auth()->user()?->hasRole('news-editor') && !$libraryItem->tweet)
<x-button xs
wire:click="tweet({{ $libraryItem->id }})">
<i class="fa fa-brand fa-twitter"></i>
{{ __('Tweet') }}
</x-button>
@endif
@else
<x-badge negative>{{ __('not approved') }}</x-badge>
@endif