mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
tweet news
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Livewire\News;
|
namespace App\Http\Livewire\News;
|
||||||
|
|
||||||
use App\Models\LibraryItem;
|
use App\Models\LibraryItem;
|
||||||
|
use App\Traits\TwitterTrait;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use RalphJSmit\Laravel\SEO\Support\SEOData;
|
use RalphJSmit\Laravel\SEO\Support\SEOData;
|
||||||
use WireUi\Traits\Actions;
|
use WireUi\Traits\Actions;
|
||||||
@@ -10,6 +11,56 @@ use WireUi\Traits\Actions;
|
|||||||
class ArticleOverview extends Component
|
class ArticleOverview extends Component
|
||||||
{
|
{
|
||||||
use Actions;
|
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)
|
public function approve($id)
|
||||||
{
|
{
|
||||||
@@ -20,7 +71,7 @@ class ArticleOverview extends Component
|
|||||||
$this->notification()
|
$this->notification()
|
||||||
->success(__('Article approved'));
|
->success(__('Article approved'));
|
||||||
|
|
||||||
$this->emit('$reload');
|
$this->emit('$refresh');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
|
|||||||
@@ -48,19 +48,6 @@ class LibraryItemObserver
|
|||||||
$this->postTweet($text);
|
$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) {
|
} catch (\Exception $e) {
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
//
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -753,5 +753,9 @@
|
|||||||
"Current picture": "Derzeitiges Bild",
|
"Current picture": "Derzeitiges Bild",
|
||||||
"Article approved": "Artikel genehmigt",
|
"Article approved": "Artikel genehmigt",
|
||||||
"approved": "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"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -749,5 +749,9 @@
|
|||||||
"Current picture": "",
|
"Current picture": "",
|
||||||
"Article approved": "",
|
"Article approved": "",
|
||||||
"approved": "",
|
"approved": "",
|
||||||
"not approved": ""
|
"not approved": "",
|
||||||
|
"Article not approved yet": "",
|
||||||
|
"Article tweeted": "",
|
||||||
|
"Error tweeting article": "",
|
||||||
|
"Tweet": ""
|
||||||
}
|
}
|
||||||
@@ -749,5 +749,9 @@
|
|||||||
"Current picture": "",
|
"Current picture": "",
|
||||||
"Article approved": "",
|
"Article approved": "",
|
||||||
"approved": "",
|
"approved": "",
|
||||||
"not approved": ""
|
"not approved": "",
|
||||||
|
"Article not approved yet": "",
|
||||||
|
"Article tweeted": "",
|
||||||
|
"Error tweeting article": "",
|
||||||
|
"Tweet": ""
|
||||||
}
|
}
|
||||||
@@ -750,5 +750,9 @@
|
|||||||
"Current picture": "",
|
"Current picture": "",
|
||||||
"Article approved": "",
|
"Article approved": "",
|
||||||
"approved": "",
|
"approved": "",
|
||||||
"not approved": ""
|
"not approved": "",
|
||||||
|
"Article not approved yet": "",
|
||||||
|
"Article tweeted": "",
|
||||||
|
"Error tweeting article": "",
|
||||||
|
"Tweet": ""
|
||||||
}
|
}
|
||||||
@@ -750,5 +750,9 @@
|
|||||||
"Current picture": "",
|
"Current picture": "",
|
||||||
"Article approved": "",
|
"Article approved": "",
|
||||||
"approved": "",
|
"approved": "",
|
||||||
"not approved": ""
|
"not approved": "",
|
||||||
|
"Article not approved yet": "",
|
||||||
|
"Article tweeted": "",
|
||||||
|
"Error tweeting article": "",
|
||||||
|
"Tweet": ""
|
||||||
}
|
}
|
||||||
@@ -750,5 +750,9 @@
|
|||||||
"Current picture": "",
|
"Current picture": "",
|
||||||
"Article approved": "",
|
"Article approved": "",
|
||||||
"approved": "",
|
"approved": "",
|
||||||
"not approved": ""
|
"not approved": "",
|
||||||
|
"Article not approved yet": "",
|
||||||
|
"Article tweeted": "",
|
||||||
|
"Error tweeting article": "",
|
||||||
|
"Tweet": ""
|
||||||
}
|
}
|
||||||
@@ -750,5 +750,9 @@
|
|||||||
"Current picture": "",
|
"Current picture": "",
|
||||||
"Article approved": "",
|
"Article approved": "",
|
||||||
"approved": "",
|
"approved": "",
|
||||||
"not approved": ""
|
"not approved": "",
|
||||||
|
"Article not approved yet": "",
|
||||||
|
"Article tweeted": "",
|
||||||
|
"Error tweeting article": "",
|
||||||
|
"Tweet": ""
|
||||||
}
|
}
|
||||||
@@ -750,5 +750,9 @@
|
|||||||
"Current picture": "",
|
"Current picture": "",
|
||||||
"Article approved": "",
|
"Article approved": "",
|
||||||
"approved": "",
|
"approved": "",
|
||||||
"not approved": ""
|
"not approved": "",
|
||||||
|
"Article not approved yet": "",
|
||||||
|
"Article tweeted": "",
|
||||||
|
"Error tweeting article": "",
|
||||||
|
"Tweet": ""
|
||||||
}
|
}
|
||||||
@@ -750,5 +750,9 @@
|
|||||||
"Current picture": "",
|
"Current picture": "",
|
||||||
"Article approved": "",
|
"Article approved": "",
|
||||||
"approved": "",
|
"approved": "",
|
||||||
"not approved": ""
|
"not approved": "",
|
||||||
|
"Article not approved yet": "",
|
||||||
|
"Article tweeted": "",
|
||||||
|
"Error tweeting article": "",
|
||||||
|
"Tweet": ""
|
||||||
}
|
}
|
||||||
@@ -712,5 +712,9 @@
|
|||||||
"Add tag...": "",
|
"Add tag...": "",
|
||||||
"Article approved": "",
|
"Article approved": "",
|
||||||
"approved": "",
|
"approved": "",
|
||||||
"not approved": ""
|
"not approved": "",
|
||||||
|
"Article not approved yet": "",
|
||||||
|
"Article tweeted": "",
|
||||||
|
"Error tweeting article": "",
|
||||||
|
"Tweet": ""
|
||||||
}
|
}
|
||||||
@@ -724,5 +724,9 @@
|
|||||||
"Current picture": "",
|
"Current picture": "",
|
||||||
"Article approved": "",
|
"Article approved": "",
|
||||||
"approved": "",
|
"approved": "",
|
||||||
"not approved": ""
|
"not approved": "",
|
||||||
|
"Article not approved yet": "",
|
||||||
|
"Article tweeted": "",
|
||||||
|
"Error tweeting article": "",
|
||||||
|
"Tweet": ""
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
<p class="mt-3 text-base text-gray-300 line-clamp-6">{{ strip_tags($libraryItem->excerpt) }}</p>
|
<p class="mt-3 text-base text-gray-300 line-clamp-6">{{ strip_tags($libraryItem->excerpt) }}</p>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-6 flex items-center">
|
<div class="mt-6 flex items-center w-full">
|
||||||
<div class="flex-shrink-0">
|
<div class="flex-shrink-0">
|
||||||
<div>
|
<div>
|
||||||
<span
|
<span
|
||||||
@@ -67,11 +67,19 @@
|
|||||||
<span>{{ $libraryItem->read_time }} {{ __('min read') }}</span>
|
<span>{{ $libraryItem->read_time }} {{ __('min read') }}</span>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</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'))
|
@if($libraryItem->created_by === auth()->id() || auth()->user()?->hasRole('news-editor'))
|
||||||
<div>
|
<div>
|
||||||
@if($libraryItem->approved)
|
@if($libraryItem->approved)
|
||||||
<x-badge green>{{ __('approved') }}</x-badge>
|
<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
|
@else
|
||||||
<x-badge negative>{{ __('not approved') }}</x-badge>
|
<x-badge negative>{{ __('not approved') }}</x-badge>
|
||||||
@endif
|
@endif
|
||||||
|
|||||||
Reference in New Issue
Block a user