diff --git a/app/Controllers/EpisodeController.php b/app/Controllers/EpisodeController.php index 5465474e123dcf2bee3576a58d8aa47d33be31cb..3d30b4e54c20c8fccf2da4c24d4c55e973ec184a 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 a46348e5fa132e0b1c3590877c16a27df70c111e..74468fa2e5959a730df0fb2022ad427fa1b491e2 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 478e0b2c91ea987f4c715f243a9f80c0828e92fc..26621ea0485f5c219804f3ebdea8d5f9397d1c91 100644 --- a/themes/cp_app/embed.php +++ b/themes/cp_app/embed.php @@ -33,6 +33,9 @@ <a href="<?= $episode->link ?>" class="flex flex-col items-start text-sm" style="color: <?= $themeData['text'] ?>;" target="_blank" rel="noopener noreferrer"> <h1 class="font-semibold leading-tight opacity-100 line-clamp-2 hover:opacity-75"><?= esc($episode->title) ?></h1> </a> + <?php if ($episode->is_premium && ! is_unlocked($podcast->handle)): ?> + <Button variant="primary" class="mt-auto mb-2" iconLeft="lock" uri="<?= $episode->link ?>" target="_blank" rel="noopener noreferrer"><?= lang('PremiumPodcasts.unlock') ?></Button> + <?php else: ?> <vm-player id="castopod-vm-player" theme="<?= str_starts_with($theme, 'dark') ? 'dark' : 'light' ?>" @@ -60,6 +63,7 @@ </vm-controls> </vm-ui> </vm-player> + <?php endif; ?> </div> </body> diff --git a/themes/cp_app/episode/_partials/card.php b/themes/cp_app/episode/_partials/card.php index 165b00c0f96671a52b3890ba52b566429f4ee2ca..d2e4e8781c8eddb61889187b18e93b4fec480806 100644 --- a/themes/cp_app/episode/_partials/card.php +++ b/themes/cp_app/episode/_partials/card.php @@ -17,7 +17,7 @@ </div> <h2 class="flex-1 mt-1 font-semibold leading-tight line-clamp-2"><a class="hover:underline" href="<?= $episode->link ?>"><?= esc($episode->title) ?></a></h2> </div> - <?php if ($episode->is_premium && ! subscription($podcast->handle)): ?> + <?php if ($episode->is_premium && ! is_unlocked($podcast->handle)): ?> <a href="<?= route_to('episode', $episode->podcast->handle, $episode->slug) ?>" class="p-3 rounded-full bg-brand bg-accent-base text-accent-contrast hover:bg-accent-hover focus:ring-accent" title="<?= lang('PremiumPodcasts.unlock_episode') ?>" data-tooltip="bottom"> <Icon glyph="lock" class="text-xl" /> </a> diff --git a/themes/cp_app/episode/_partials/preview_card.php b/themes/cp_app/episode/_partials/preview_card.php index 0d425b566362daf09d54610cc810e46323c101eb..5072a99dc6a56f68ce80cf1f242268d9bc4af881 100644 --- a/themes/cp_app/episode/_partials/preview_card.php +++ b/themes/cp_app/episode/_partials/preview_card.php @@ -17,7 +17,7 @@ </div> <a href="<?= $episode->link ?>" class="flex items-baseline font-semibold line-clamp-2" title="<?= esc($episode->title) ?>"><?= esc($episode->title) ?></a> </div> - <?php if ($episode->is_premium && ! subscription($episode->podcast->handle)): ?> + <?php if ($episode->is_premium && ! is_unlocked($episode->podcast->handle)): ?> <a href="<?= route_to('episode', $episode->podcast->handle, $episode->slug) ?>" class="p-3 mr-4 rounded-full bg-brand bg-accent-base text-accent-contrast hover:bg-accent-hover focus:ring-accent" title="<?= lang('PremiumPodcasts.unlock_episode') ?>" data-tooltip="bottom"> <Icon glyph="lock" class="text-xl" /> </a>