From ca109ba3a8a08e661fd2484454b1983c3418f15d Mon Sep 17 00:00:00 2001 From: Yassine Doghri Date: Thu, 29 Sep 2022 13:34:28 +0000 Subject: [PATCH] fix(premium-podcasts): display unlock button in embed when premium episode --- app/Controllers/EpisodeController.php | 17 +++++++++++++---- .../Filters/PodcastUnlockFilter.php | 5 +++++ themes/cp_app/embed.php | 4 ++++ themes/cp_app/episode/_partials/card.php | 2 +- .../cp_app/episode/_partials/preview_card.php | 2 +- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/Controllers/EpisodeController.php b/app/Controllers/EpisodeController.php index 5465474e..3d30b4e5 100644 --- a/app/Controllers/EpisodeController.php +++ b/app/Controllers/EpisodeController.php @@ -177,10 +177,19 @@ class EpisodeController extends BaseController $session->set('embed_domain', parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST)); } - $locale = service('request') - ->getLocale(); - - $cacheName = "page_podcast#{$this->podcast->id}_episode#{$this->episode->id}_embed_{$theme}_{$locale}"; + $cacheName = implode( + '_', + array_filter([ + 'page', + "podcast#{$this->podcast->id}", + "episode#{$this->episode->id}", + 'embed', + $theme, + service('request') + ->getLocale(), + is_unlocked($this->podcast->handle) ? 'unlocked' : null, + ]), + ); if (! ($cachedView = cache($cacheName))) { $themeData = EpisodeModel::$themes[$theme]; diff --git a/modules/PremiumPodcasts/Filters/PodcastUnlockFilter.php b/modules/PremiumPodcasts/Filters/PodcastUnlockFilter.php index a46348e5..74468fa2 100644 --- a/modules/PremiumPodcasts/Filters/PodcastUnlockFilter.php +++ b/modules/PremiumPodcasts/Filters/PodcastUnlockFilter.php @@ -67,6 +67,11 @@ class PodcastUnlockFilter implements FilterInterface return; } + // Episode should be embeddable even if it is premium + if ($current === route_to('embed', $episode->podcast->handle, $episode->slug)) { + return; + } + // if podcast is locked then send to the unlock form /** @var PremiumPodcasts $premiumPodcasts */ $premiumPodcasts = service('premium_podcasts'); diff --git a/themes/cp_app/embed.php b/themes/cp_app/embed.php index 478e0b2c..26621ea0 100644 --- a/themes/cp_app/embed.php +++ b/themes/cp_app/embed.php @@ -33,6 +33,9 @@

title) ?>

+ is_premium && ! is_unlocked($podcast->handle)): ?> + + + diff --git a/themes/cp_app/episode/_partials/card.php b/themes/cp_app/episode/_partials/card.php index 165b00c0..d2e4e878 100644 --- a/themes/cp_app/episode/_partials/card.php +++ b/themes/cp_app/episode/_partials/card.php @@ -17,7 +17,7 @@

title) ?>

- is_premium && ! subscription($podcast->handle)): ?> + is_premium && ! is_unlocked($podcast->handle)): ?> diff --git a/themes/cp_app/episode/_partials/preview_card.php b/themes/cp_app/episode/_partials/preview_card.php index 0d425b56..5072a99d 100644 --- a/themes/cp_app/episode/_partials/preview_card.php +++ b/themes/cp_app/episode/_partials/preview_card.php @@ -17,7 +17,7 @@ title) ?> - is_premium && ! subscription($episode->podcast->handle)): ?> + is_premium && ! is_unlocked($episode->podcast->handle)): ?>