diff --git a/app/Http/Livewire/News/ArticleOverview.php b/app/Http/Livewire/News/ArticleOverview.php index d26fd320..e80e7a32 100644 --- a/app/Http/Livewire/News/ArticleOverview.php +++ b/app/Http/Livewire/News/ArticleOverview.php @@ -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() diff --git a/app/Observers/LibraryItemObserver.php b/app/Observers/LibraryItemObserver.php index fd317c0e..565e7c8b 100644 --- a/app/Observers/LibraryItemObserver.php +++ b/app/Observers/LibraryItemObserver.php @@ -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) { diff --git a/database/migrations/2023_02_11_154505_add_tweet_field_to_library_items_table.php b/database/migrations/2023_02_11_154505_add_tweet_field_to_library_items_table.php new file mode 100644 index 00000000..86838dc7 --- /dev/null +++ b/database/migrations/2023_02_11_154505_add_tweet_field_to_library_items_table.php @@ -0,0 +1,30 @@ +string('tweet') + ->default(false); + }); + } + + /** + * Reverse the migrations. + * @return void + */ + public function down() + { + Schema::table('library_items', function (Blueprint $table) { + // + }); + } +}; diff --git a/resources/lang/de.json b/resources/lang/de.json index aec3155f..2f06f6af 100644 --- a/resources/lang/de.json +++ b/resources/lang/de.json @@ -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" } diff --git a/resources/lang/en.json b/resources/lang/en.json index bdaec731..49b1b7be 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -749,5 +749,9 @@ "Current picture": "", "Article approved": "", "approved": "", - "not approved": "" + "not approved": "", + "Article not approved yet": "", + "Article tweeted": "", + "Error tweeting article": "", + "Tweet": "" } \ No newline at end of file diff --git a/resources/lang/es.json b/resources/lang/es.json index dad86e0e..178c949a 100644 --- a/resources/lang/es.json +++ b/resources/lang/es.json @@ -749,5 +749,9 @@ "Current picture": "", "Article approved": "", "approved": "", - "not approved": "" + "not approved": "", + "Article not approved yet": "", + "Article tweeted": "", + "Error tweeting article": "", + "Tweet": "" } \ No newline at end of file diff --git a/resources/lang/fr.json b/resources/lang/fr.json index 341e2ed3..b2f16d94 100644 --- a/resources/lang/fr.json +++ b/resources/lang/fr.json @@ -750,5 +750,9 @@ "Current picture": "", "Article approved": "", "approved": "", - "not approved": "" + "not approved": "", + "Article not approved yet": "", + "Article tweeted": "", + "Error tweeting article": "", + "Tweet": "" } \ No newline at end of file diff --git a/resources/lang/hr.json b/resources/lang/hr.json index e3cead8c..234db7eb 100644 --- a/resources/lang/hr.json +++ b/resources/lang/hr.json @@ -750,5 +750,9 @@ "Current picture": "", "Article approved": "", "approved": "", - "not approved": "" + "not approved": "", + "Article not approved yet": "", + "Article tweeted": "", + "Error tweeting article": "", + "Tweet": "" } \ No newline at end of file diff --git a/resources/lang/it.json b/resources/lang/it.json index c0fe96dc..fa9d1603 100644 --- a/resources/lang/it.json +++ b/resources/lang/it.json @@ -750,5 +750,9 @@ "Current picture": "", "Article approved": "", "approved": "", - "not approved": "" + "not approved": "", + "Article not approved yet": "", + "Article tweeted": "", + "Error tweeting article": "", + "Tweet": "" } \ No newline at end of file diff --git a/resources/lang/mk.json b/resources/lang/mk.json index 72f135a2..cf980997 100644 --- a/resources/lang/mk.json +++ b/resources/lang/mk.json @@ -750,5 +750,9 @@ "Current picture": "", "Article approved": "", "approved": "", - "not approved": "" + "not approved": "", + "Article not approved yet": "", + "Article tweeted": "", + "Error tweeting article": "", + "Tweet": "" } \ No newline at end of file diff --git a/resources/lang/pl.json b/resources/lang/pl.json index 2fda0835..2f81e7c8 100644 --- a/resources/lang/pl.json +++ b/resources/lang/pl.json @@ -750,5 +750,9 @@ "Current picture": "", "Article approved": "", "approved": "", - "not approved": "" + "not approved": "", + "Article not approved yet": "", + "Article tweeted": "", + "Error tweeting article": "", + "Tweet": "" } \ No newline at end of file diff --git a/resources/lang/pt.json b/resources/lang/pt.json index 6cdee5f7..59d73100 100644 --- a/resources/lang/pt.json +++ b/resources/lang/pt.json @@ -750,5 +750,9 @@ "Current picture": "", "Article approved": "", "approved": "", - "not approved": "" + "not approved": "", + "Article not approved yet": "", + "Article tweeted": "", + "Error tweeting article": "", + "Tweet": "" } \ No newline at end of file diff --git a/resources/lang/sv.json b/resources/lang/sv.json index 52c0c921..29deb994 100644 --- a/resources/lang/sv.json +++ b/resources/lang/sv.json @@ -712,5 +712,9 @@ "Add tag...": "", "Article approved": "", "approved": "", - "not approved": "" + "not approved": "", + "Article not approved yet": "", + "Article tweeted": "", + "Error tweeting article": "", + "Tweet": "" } \ No newline at end of file diff --git a/resources/lang/tr.json b/resources/lang/tr.json index 83f98bbb..5f4c298a 100644 --- a/resources/lang/tr.json +++ b/resources/lang/tr.json @@ -724,5 +724,9 @@ "Current picture": "", "Article approved": "", "approved": "", - "not approved": "" + "not approved": "", + "Article not approved yet": "", + "Article tweeted": "", + "Error tweeting article": "", + "Tweet": "" } \ No newline at end of file diff --git a/resources/views/livewire/news/article-overview.blade.php b/resources/views/livewire/news/article-overview.blade.php index 05710a1e..58505aad 100644 --- a/resources/views/livewire/news/article-overview.blade.php +++ b/resources/views/livewire/news/article-overview.blade.php @@ -45,7 +45,7 @@

{{ strip_tags($libraryItem->excerpt) }}

-
+
{{ $libraryItem->read_time }} {{ __('min read') }} @endif
-
+
@if($libraryItem->created_by === auth()->id() || auth()->user()?->hasRole('news-editor'))
@if($libraryItem->approved) {{ __('approved') }} + @if(auth()->user()?->hasRole('news-editor') && !$libraryItem->tweet) + + + {{ __('Tweet') }} + + @endif @else {{ __('not approved') }} @endif