mirror of
https://code.castopod.org/adaures/castopod
synced 2025-04-19 13:01:19 +00:00
fix(premium-podcasts): return different cached page when podcast is unlocked
- clear podcast cache when setting subscription link - update and add missing translation keys
This commit is contained in:
parent
65173e5180
commit
b1303c5255
@ -70,11 +70,18 @@ class EpisodeController extends BaseController
|
||||
$this->registerPodcastWebpageHit($this->episode->podcast_id);
|
||||
}
|
||||
|
||||
$locale = service('request')
|
||||
->getLocale();
|
||||
$cacheName =
|
||||
"page_podcast#{$this->podcast->id}_episode#{$this->episode->id}_{$locale}" .
|
||||
(can_user_interact() ? '_authenticated' : '');
|
||||
$cacheName = implode(
|
||||
'_',
|
||||
array_filter([
|
||||
'page',
|
||||
"podcast#{$this->podcast->id}",
|
||||
"episode#{$this->episode->id}",
|
||||
service('request')
|
||||
->getLocale(),
|
||||
is_unlocked($this->podcast->handle) ? 'unlocked' : null,
|
||||
can_user_interact() ? 'authenticated' : null,
|
||||
]),
|
||||
);
|
||||
|
||||
if (! ($cachedView = cache($cacheName))) {
|
||||
$data = [
|
||||
@ -112,11 +119,19 @@ class EpisodeController extends BaseController
|
||||
$this->registerPodcastWebpageHit($this->episode->podcast_id);
|
||||
}
|
||||
|
||||
$locale = service('request')
|
||||
->getLocale();
|
||||
$cacheName =
|
||||
"page_podcast#{$this->podcast->id}_episode#{$this->episode->id}_activity_{$locale}" .
|
||||
(can_user_interact() ? '_authenticated' : '');
|
||||
$cacheName = implode(
|
||||
'_',
|
||||
array_filter([
|
||||
'page',
|
||||
"podcast#{$this->podcast->id}",
|
||||
"episode#{$this->episode->id}",
|
||||
'activity',
|
||||
service('request')
|
||||
->getLocale(),
|
||||
is_unlocked($this->podcast->handle) ? 'unlocked' : null,
|
||||
can_user_interact() ? 'authenticated' : null,
|
||||
]),
|
||||
);
|
||||
|
||||
if (! ($cachedView = cache($cacheName))) {
|
||||
$data = [
|
||||
|
@ -74,6 +74,7 @@ class PodcastController extends BaseController
|
||||
'activity',
|
||||
service('request')
|
||||
->getLocale(),
|
||||
is_unlocked($this->podcast->handle) ? 'unlocked' : null,
|
||||
can_user_interact() ? 'authenticated' : null,
|
||||
]),
|
||||
);
|
||||
@ -122,6 +123,7 @@ class PodcastController extends BaseController
|
||||
'about',
|
||||
service('request')
|
||||
->getLocale(),
|
||||
is_unlocked($this->podcast->handle) ? 'unlocked' : null,
|
||||
can_user_interact() ? 'authenticated' : null,
|
||||
]),
|
||||
);
|
||||
@ -188,6 +190,7 @@ class PodcastController extends BaseController
|
||||
$seasonQuery ? 'season' . $seasonQuery : null,
|
||||
service('request')
|
||||
->getLocale(),
|
||||
is_unlocked($this->podcast->handle) ? 'unlocked' : null,
|
||||
can_user_interact() ? 'authenticated' : null,
|
||||
]),
|
||||
);
|
||||
|
@ -47,4 +47,5 @@ return [
|
||||
'video-clips' => 'video clips',
|
||||
'embed' => 'embeddable player',
|
||||
'notifications' => 'notifications',
|
||||
'suspend' => 'suspend',
|
||||
];
|
||||
|
@ -110,7 +110,7 @@ return [
|
||||
'bonus_hint' => 'Extra content for the show (for example, behind the scenes info or interviews with the cast) or cross-promotional content for another show',
|
||||
],
|
||||
'premium_title' => 'Premium',
|
||||
'premium' => 'Episode must only be accessible to premium subscribers',
|
||||
'premium' => 'Episode must be accessible to premium subscribers only',
|
||||
'parental_advisory' => [
|
||||
'label' => 'Parental advisory',
|
||||
'hint' => 'Does the episode contain explicit content?',
|
||||
|
@ -99,17 +99,17 @@ $routes->group(
|
||||
],
|
||||
);
|
||||
$routes->get(
|
||||
'remove',
|
||||
'SubscriptionController::remove/$1/$2',
|
||||
'delete',
|
||||
'SubscriptionController::delete/$1/$2',
|
||||
[
|
||||
'as' => 'subscription-remove',
|
||||
'as' => 'subscription-delete',
|
||||
'filter' =>
|
||||
'permission:podcast-manage_subscriptions',
|
||||
],
|
||||
);
|
||||
$routes->post(
|
||||
'remove',
|
||||
'SubscriptionController::attemptRemove/$1/$2',
|
||||
'delete',
|
||||
'SubscriptionController::attemptDelete/$1/$2',
|
||||
[
|
||||
'filter' =>
|
||||
'permission:podcast-manage_subscriptions',
|
||||
|
@ -45,33 +45,15 @@ class LockController extends BaseController
|
||||
|
||||
public function index(): string
|
||||
{
|
||||
$locale = service('request')
|
||||
->getLocale();
|
||||
$cacheName =
|
||||
"page_podcast#{$this->podcast->id}_{$locale}_unlock" .
|
||||
(can_user_interact() ? '_authenticated' : '');
|
||||
$data = [
|
||||
// TODO: metatags for locked premium podcasts
|
||||
'metatags' => '',
|
||||
'podcast' => $this->podcast,
|
||||
];
|
||||
|
||||
if (! ($cachedView = cache($cacheName))) {
|
||||
$data = [
|
||||
// TODO: metatags for locked premium podcasts
|
||||
'metatags' => '',
|
||||
'podcast' => $this->podcast,
|
||||
];
|
||||
helper('form');
|
||||
|
||||
helper('form');
|
||||
|
||||
if (can_user_interact()) {
|
||||
return view('podcast/unlock', $data);
|
||||
}
|
||||
|
||||
// The page cache is set to a decade so it is deleted manually upon podcast update
|
||||
return view('podcast/unlock', $data, [
|
||||
'cache' => DECADE,
|
||||
'cache_name' => $cacheName,
|
||||
]);
|
||||
}
|
||||
|
||||
return $cachedView;
|
||||
return view('podcast/unlock', $data);
|
||||
}
|
||||
|
||||
public function attemptUnlock(): RedirectResponse
|
||||
|
@ -88,6 +88,10 @@ class SubscriptionController extends BaseController
|
||||
service('settings')
|
||||
->set('Subscription.link', $subscriptionLink, 'podcast:' . $this->podcast->id);
|
||||
|
||||
// clear cached podcast pages to render Call To Action
|
||||
cache()
|
||||
->deleteMatching("page_podcast#{$this->podcast->id}*");
|
||||
|
||||
return redirect()->route('subscription-list', [$this->podcast->id])->with(
|
||||
'message',
|
||||
lang('Subscription.messages.linkSaveSuccess')
|
||||
@ -396,7 +400,7 @@ class SubscriptionController extends BaseController
|
||||
);
|
||||
}
|
||||
|
||||
public function remove(): string
|
||||
public function delete(): string
|
||||
{
|
||||
helper('form');
|
||||
|
||||
@ -412,7 +416,7 @@ class SubscriptionController extends BaseController
|
||||
return view('subscription/delete', $data);
|
||||
}
|
||||
|
||||
public function attemptRemove(): RedirectResponse
|
||||
public function attemptDelete(): RedirectResponse
|
||||
{
|
||||
$db = db_connect();
|
||||
$db->transStart();
|
||||
@ -423,15 +427,15 @@ class SubscriptionController extends BaseController
|
||||
$email = service('email');
|
||||
|
||||
if (! $email->setTo($this->subscription->email)
|
||||
->setSubject(lang('Subscription.emails.removed_subject', [], $this->podcast->language_code))
|
||||
->setMessage(view('subscription/email/removed', [
|
||||
->setSubject(lang('Subscription.emails.deleted_subject', [], $this->podcast->language_code))
|
||||
->setMessage(view('subscription/email/deleted', [
|
||||
'subscription' => $this->subscription,
|
||||
]))->setMailType('html')
|
||||
->send()) {
|
||||
$db->transRollback();
|
||||
return redirect()->route('subscription-list', [$this->podcast->id])->with(
|
||||
'errors',
|
||||
[lang('Subscription.messages.removeError'), $email->printDebugger([])]
|
||||
[lang('Subscription.messages.deleteError'), $email->printDebugger([])]
|
||||
);
|
||||
}
|
||||
|
||||
@ -439,7 +443,7 @@ class SubscriptionController extends BaseController
|
||||
|
||||
return redirect()->route('subscription-list', [$this->podcast->id])->with(
|
||||
'messages',
|
||||
lang('Subscription.messages.removeSuccess', [
|
||||
lang('Subscription.messages.deleteSuccess', [
|
||||
'subscriber' => $this->subscription->email,
|
||||
])
|
||||
);
|
||||
|
@ -60,8 +60,8 @@ return [
|
||||
'editError' => 'Subscription could not be edited.',
|
||||
'regenerateTokenSuccess' => 'Token regenerated! An email was sent to {subscriber} with the new token.',
|
||||
'regenerateTokenError' => 'Token could not be regenerated.',
|
||||
'removeSuccess' => 'Subscription was canceled! An email was sent to {subscriber} to tell him.',
|
||||
'removeError' => 'Subscription could not be canceled.',
|
||||
'deleteSuccess' => 'Subscription was removed! An email was sent to {subscriber}.',
|
||||
'deleteError' => 'Subscription could not be removed.',
|
||||
'suspendSuccess' => 'Subscription was suspended! An email was sent to {subscriber}.',
|
||||
'suspendError' => 'Subscription could not be suspended.',
|
||||
'resumeSuccess' => 'Subscription was resumed! An email was sent to {subscriber}.',
|
||||
@ -93,8 +93,8 @@ return [
|
||||
'suspended_reason' => 'That is for the following reason: {0}',
|
||||
'resumed_subject' => 'Your subscription has been resumed!',
|
||||
'resumed' => 'Your subscription for {podcastTitle} has been resumed! You may access the podcast\'s premium episodes again.',
|
||||
'removed_subject' => 'Your subscription has been removed!',
|
||||
'removed' => 'Your subscription for {podcastTitle} has been removed! You no longer have access to the podcast\'s premium episodes.',
|
||||
'deleted_subject' => 'Your subscription has been removed!',
|
||||
'deleted' => 'Your subscription for {podcastTitle} has been removed! You no longer have access to the podcast\'s premium episodes.',
|
||||
'footer' => '{castopod} hosted on {host}',
|
||||
],
|
||||
];
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?= lang('Subscription.emails.greeting', [], $subscription->podcast->language_code) ?><br/><br/>
|
||||
|
||||
<?= lang('Subscription.emails.removed', [
|
||||
<?= lang('Subscription.emails.deleted', [
|
||||
'podcastTitle' => '<strong>' . $subscription->podcast->title . '</strong>',
|
||||
], $subscription->podcast->language_code, false) ?>
|
||||
|
@ -94,7 +94,7 @@
|
||||
[
|
||||
'type' => 'link',
|
||||
'title' => lang('Subscription.delete'),
|
||||
'uri' => route_to('subscription-remove', $podcast->id, $subscription->id),
|
||||
'uri' => route_to('subscription-delete', $podcast->id, $subscription->id),
|
||||
'class' => 'font-semibold text-red-600',
|
||||
],
|
||||
];
|
||||
|
@ -75,7 +75,7 @@
|
||||
<header class="relative flex flex-col-reverse justify-between w-full col-start-2 bg-top bg-no-repeat bg-cover sm:flex-row sm:items-end bg-header aspect-[3/1]" style="background-image: url('<?= $podcast->banner->medium_url ?>');">
|
||||
<div class="absolute bottom-0 left-0 w-full h-full backdrop-gradient mix-blend-multiply"></div>
|
||||
<div class="flex items-center pl-4 -mb-6 md:pl-8 md:-mb-8 gap-x-4">
|
||||
<img src="<?= $podcast->cover->thumbnail_url ?>" alt="<?= esc($podcast->title) ?>" class="h-24 rounded-full sm:h-28 md:h-36 ring-3 ring-background-elevated aspect-square" loading="lazy" />
|
||||
<img src="<?= $podcast->cover->thumbnail_url ?>" alt="<?= esc($podcast->title) ?>" class="z-[45] h-24 rounded-full sm:h-28 md:h-36 ring-3 ring-background-elevated aspect-square" loading="lazy" />
|
||||
<div class="relative flex flex-col text-white -top-3 sm:top-0 md:top-2">
|
||||
<h1 class="text-lg font-bold leading-none line-clamp-2 md:leading-none md:text-2xl font-display"><?= esc($podcast->title) ?><span class="ml-1 font-sans text-base font-normal">@<?= esc($podcast->handle) ?></span></h1>
|
||||
<div class="">
|
||||
|
Loading…
x
Reference in New Issue
Block a user