diff --git a/app/Resources/icons/history.svg b/app/Resources/icons/history.svg new file mode 100644 index 00000000..684091df --- /dev/null +++ b/app/Resources/icons/history.svg @@ -0,0 +1,4 @@ + diff --git a/app/Views/Components/IconButton.php b/app/Views/Components/IconButton.php index f02c8078..636f755c 100644 --- a/app/Views/Components/IconButton.php +++ b/app/Views/Components/IconButton.php @@ -4,27 +4,28 @@ declare(strict_types=1); namespace App\Views\Components; -use ViewComponents\Component; - -class IconButton extends Component +class IconButton extends Button { public string $glyph = ''; - public function render(): string + public function __construct(array $attributes) { - $attributes = [ + $iconButtonAttributes = [ 'isSquared' => 'true', - 'title' => $this->slot, + 'title' => $attributes['slot'], 'data-tooltip' => 'bottom', ]; - $attributes = array_merge($attributes, $this->attributes); + $glyphSize = [ + 'small' => 'text-sm', + 'base' => 'text-lg', + 'large' => 'text-2xl', + ]; - $attributes['slot'] = icon($this->glyph); + $allAttributes = array_merge($attributes, $iconButtonAttributes); - unset($attributes['glyph']); + parent::__construct($allAttributes); - $iconButton = new Button($attributes); - return $iconButton->render(); + $this->slot = icon($this->glyph, $glyphSize[$this->size]); } } diff --git a/modules/Admin/Config/Routes.php b/modules/Admin/Config/Routes.php index 06aadf0e..ad767a0d 100644 --- a/modules/Admin/Config/Routes.php +++ b/modules/Admin/Config/Routes.php @@ -327,6 +327,23 @@ $routes->group( 'permission:podcast-manage_publications', ], ); + $routes->get( + 'publish-date-edit', + 'EpisodeController::publishDateEdit/$1/$2', + [ + 'as' => 'episode-publish_date_edit', + 'filter' => + 'permission:podcast-manage_publications', + ], + ); + $routes->post( + 'publish-date-edit', + 'EpisodeController::attemptPublishDateEdit/$1/$2', + [ + 'filter' => + 'permission:podcast-manage_publications', + ], + ); $routes->get( 'unpublish', 'EpisodeController::unpublish/$1/$2', diff --git a/modules/Admin/Controllers/EpisodeController.php b/modules/Admin/Controllers/EpisodeController.php index 9e5e906f..6c14d7f3 100644 --- a/modules/Admin/Controllers/EpisodeController.php +++ b/modules/Admin/Controllers/EpisodeController.php @@ -683,29 +683,104 @@ class EpisodeController extends BaseController return redirect()->route('episode-view', [$this->podcast->id, $this->episode->id]); } - public function unpublish(): string | RedirectResponse + public function publishDateEdit(): string|RedirectResponse { - if ($this->episode->publication_status === 'published') { - helper(['form']); + // only accessible if episode is already published + if ($this->episode->publication_status !== 'published') { + return redirect()->route('episode-view', [$this->podcast->id, $this->episode->id])->with( + 'error', + lang('Episode.publish_date_edit_error') + ); + } - $data = [ - 'podcast' => $this->podcast, - 'episode' => $this->episode, - ]; + helper('form'); - replace_breadcrumb_params([ - 0 => $this->podcast->title, - 1 => $this->episode->title, - ]); - return view('episode/unpublish', $data); + $data = [ + 'podcast' => $this->podcast, + 'episode' => $this->episode, + ]; + + replace_breadcrumb_params([ + 0 => $this->podcast->title, + 1 => $this->episode->title, + ]); + + return view('episode/publish_date_edit', $data); + } + + /** + * Allows to set an episode's publication date to a past date + * + * Prevents setting a future date as it does not make sense to set a future published date to an already published + * episode. This also prevents any side-effects from occurring. + */ + public function attemptPublishDateEdit(): RedirectResponse + { + $rules = [ + 'new_publication_date' => 'valid_date[Y-m-d H:i]', + ]; + + if (! $this->validate($rules)) { + return redirect() + ->back() + ->withInput() + ->with('errors', $this->validator->getErrors()); + } + + $newPublicationDate = $this->request->getPost('new_publication_date'); + + $newPublicationDate = Time::createFromFormat( + 'Y-m-d H:i', + $newPublicationDate, + $this->request->getPost('client_timezone'), + )->setTimezone(app_timezone()); + + if ($newPublicationDate->isAfter(Time::now())) { + return redirect() + ->back() + ->withInput() + ->with('error', lang('Episode.publish_date_edit_future_error')); + } + + $this->episode->published_at = $newPublicationDate; + + $episodeModel = new EpisodeModel(); + if (! $episodeModel->update($this->episode->id, $this->episode)) { + return redirect() + ->back() + ->withInput() + ->with('errors', $episodeModel->errors()); } return redirect()->route('episode-view', [$this->podcast->id, $this->episode->id])->with( - 'error', - lang('Episode.unpublish_error') + 'message', + lang('Episode.publish_date_edit_success') ); } + public function unpublish(): string | RedirectResponse + { + if ($this->episode->publication_status !== 'published') { + return redirect()->route('episode-view', [$this->podcast->id, $this->episode->id])->with( + 'error', + lang('Episode.unpublish_error') + ); + } + + helper(['form']); + + $data = [ + 'podcast' => $this->podcast, + 'episode' => $this->episode, + ]; + + replace_breadcrumb_params([ + 0 => $this->podcast->title, + 1 => $this->episode->title, + ]); + return view('episode/unpublish', $data); + } + public function attemptUnpublish(): RedirectResponse { $rules = [ diff --git a/modules/Admin/Language/en/Breadcrumb.php b/modules/Admin/Language/en/Breadcrumb.php index 46863af3..f3269bfa 100644 --- a/modules/Admin/Language/en/Breadcrumb.php +++ b/modules/Admin/Language/en/Breadcrumb.php @@ -25,6 +25,7 @@ return [ 'persons' => 'persons', 'publish' => 'publish', 'publish-edit' => 'edit publication', + 'publish-date-edit' => 'edit publication date', 'unpublish' => 'unpublish', 'delete' => 'delete', 'fediverse' => 'fediverse', diff --git a/modules/Admin/Language/en/Episode.php b/modules/Admin/Language/en/Episode.php index 92631ddf..91313a7c 100644 --- a/modules/Admin/Language/en/Episode.php +++ b/modules/Admin/Language/en/Episode.php @@ -24,10 +24,14 @@ return [ 'edit' => 'Edit', 'publish' => 'Publish', 'publish_edit' => 'Edit publication', + 'publish_date_edit' => 'Edit publication date', 'unpublish' => 'Unpublish', 'publish_error' => 'Episode is already published.', 'publish_edit_error' => 'Episode is already published.', 'publish_cancel_error' => 'Episode is already published.', + 'publish_date_edit_error' => 'Episode has not been published yet, you cannot edit its publication date.', + 'publish_date_edit_future_error' => 'Episode\'s publication date can only be set to a past date! If you would like to reschedule it, unpublish it first.', + 'publish_date_edit_success' => 'Episode\'s publication date has been updated successfully!', 'unpublish_error' => 'Episode is not published.', 'delete' => 'Delete', 'go_to_page' => 'Go to page', @@ -178,6 +182,11 @@ return [ 'message_warning_hint' => 'Having a message increases social engagement, resulting in a better visibility for your episode.', 'message_warning_submit' => 'Publish anyways', ], + 'publish_date_edit_form' => [ + 'new_publication_date' => 'New publication date', + 'new_publication_date_hint' => 'Must be set to a past date.', + 'submit' => 'Edit publication date', + ], 'unpublish_form' => [ 'disclaimer' => "Unpublishing the episode will delete all the comments and posts associated with it and remove it from the podcast's RSS feed.", diff --git a/themes/cp_admin/_layout.php b/themes/cp_admin/_layout.php index 78e41ca0..d23a48a4 100644 --- a/themes/cp_admin/_layout.php +++ b/themes/cp_admin/_layout.php @@ -1,3 +1,9 @@ + + @@ -32,9 +38,9 @@ = render_breadcrumb('text-xs items-center flex') ?>