2020-06-10 17:00:12 +02:00
|
|
|
<?php
|
2020-08-04 13:25:22 +02:00
|
|
|
|
2020-06-10 17:00:12 +02:00
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Controllers;
|
|
|
|
|
|
|
|
use App\Models\EpisodeModel;
|
|
|
|
use App\Models\PodcastModel;
|
|
|
|
|
2020-06-26 16:34:52 +02:00
|
|
|
class Episode extends BaseController
|
2020-06-10 17:00:12 +02:00
|
|
|
{
|
2020-08-05 19:26:04 +02:00
|
|
|
/**
|
|
|
|
* @var \App\Entities\Podcast
|
|
|
|
*/
|
|
|
|
protected $podcast;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \App\Entities\Episode|null
|
|
|
|
*/
|
|
|
|
protected $episode;
|
2020-06-10 17:00:12 +02:00
|
|
|
|
2020-06-30 18:17:41 +02:00
|
|
|
public function _remap($method, ...$params)
|
|
|
|
{
|
2020-09-04 11:09:26 +02:00
|
|
|
$this->podcast = (new PodcastModel())->getPodcastByName($params[0]);
|
2020-08-04 13:25:22 +02:00
|
|
|
|
|
|
|
if (
|
|
|
|
count($params) > 1 &&
|
2020-09-04 11:09:26 +02:00
|
|
|
!($this->episode = (new EpisodeModel())->getEpisodeBySlug(
|
|
|
|
$this->podcast->id,
|
|
|
|
$params[1]
|
|
|
|
))
|
2020-08-04 13:25:22 +02:00
|
|
|
) {
|
|
|
|
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
2020-06-30 18:17:41 +02:00
|
|
|
}
|
2021-02-27 22:21:26 +01:00
|
|
|
unset($params[1]);
|
|
|
|
unset($params[0]);
|
|
|
|
return $this->$method(...$params);
|
2020-06-30 18:17:41 +02:00
|
|
|
}
|
|
|
|
|
2020-07-10 14:20:25 +02:00
|
|
|
public function index()
|
2020-06-30 18:17:41 +02:00
|
|
|
{
|
2020-09-04 11:09:26 +02:00
|
|
|
self::triggerWebpageHit($this->episode->podcast_id);
|
2020-07-02 12:08:32 +02:00
|
|
|
|
2020-10-20 12:31:40 +02:00
|
|
|
$locale = service('request')->getLocale();
|
|
|
|
$cacheName = "page_podcast{$this->episode->podcast_id}_episode{$this->episode->id}_{$locale}";
|
|
|
|
|
|
|
|
if (!($cachedView = cache($cacheName))) {
|
2020-10-22 19:41:59 +02:00
|
|
|
$episodeModel = new EpisodeModel();
|
|
|
|
$previousNextEpisodes = $episodeModel->getPreviousNextEpisodes(
|
2020-09-04 11:09:26 +02:00
|
|
|
$this->episode,
|
|
|
|
$this->podcast->type
|
|
|
|
);
|
|
|
|
|
2021-02-27 22:21:26 +01:00
|
|
|
helper(['persons']);
|
2021-02-10 17:20:01 +01:00
|
|
|
$persons = [];
|
2021-02-27 22:21:26 +01:00
|
|
|
construct_episode_person_array(
|
|
|
|
$this->episode->episode_persons,
|
|
|
|
$persons
|
|
|
|
);
|
2021-02-10 17:20:01 +01:00
|
|
|
|
2020-09-04 11:09:26 +02:00
|
|
|
$data = [
|
|
|
|
'previousEpisode' => $previousNextEpisodes['previous'],
|
|
|
|
'nextEpisode' => $previousNextEpisodes['next'],
|
2020-10-02 17:38:16 +02:00
|
|
|
'podcast' => $this->podcast,
|
2020-09-04 11:09:26 +02:00
|
|
|
'episode' => $this->episode,
|
2021-02-10 17:20:01 +01:00
|
|
|
'persons' => $persons,
|
2020-09-04 11:09:26 +02:00
|
|
|
];
|
|
|
|
|
2020-10-22 19:41:59 +02:00
|
|
|
$secondsToNextUnpublishedEpisode = $episodeModel->getSecondsToNextUnpublishedEpisode(
|
|
|
|
$this->podcast->id
|
|
|
|
);
|
|
|
|
|
2020-09-04 11:09:26 +02:00
|
|
|
// The page cache is set to a decade so it is deleted manually upon podcast update
|
|
|
|
return view('episode', $data, [
|
2020-10-22 19:41:59 +02:00
|
|
|
'cache' => $secondsToNextUnpublishedEpisode
|
|
|
|
? $secondsToNextUnpublishedEpisode
|
|
|
|
: DECADE,
|
2020-10-20 12:31:40 +02:00
|
|
|
'cache_name' => $cacheName,
|
2020-09-04 11:09:26 +02:00
|
|
|
]);
|
|
|
|
}
|
2020-06-26 16:34:52 +02:00
|
|
|
|
2020-09-04 11:09:26 +02:00
|
|
|
return $cachedView;
|
2020-06-10 17:00:12 +02:00
|
|
|
}
|
2021-02-27 22:21:26 +01:00
|
|
|
|
|
|
|
public function embeddablePlayer($theme = 'light-transparent')
|
|
|
|
{
|
|
|
|
self::triggerWebpageHit($this->episode->podcast_id);
|
|
|
|
|
|
|
|
$session = \Config\Services::session();
|
|
|
|
$session->start();
|
|
|
|
if (isset($_SERVER['HTTP_REFERER'])) {
|
|
|
|
$session->set(
|
|
|
|
'embeddable_player_domain',
|
|
|
|
parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$locale = service('request')->getLocale();
|
|
|
|
|
|
|
|
$cacheName = "page_podcast{$this->episode->podcast_id}_episode{$this->episode->id}_embeddable_player_{$theme}_{$locale}";
|
|
|
|
|
|
|
|
if (!($cachedView = cache($cacheName))) {
|
|
|
|
$episodeModel = new EpisodeModel();
|
|
|
|
$theme = EpisodeModel::$themes[$theme];
|
|
|
|
helper(['persons']);
|
|
|
|
$persons = [];
|
|
|
|
construct_episode_person_array(
|
|
|
|
$this->episode->episode_persons,
|
|
|
|
$persons
|
|
|
|
);
|
|
|
|
constructs_podcast_person_array(
|
|
|
|
$this->podcast->podcast_persons,
|
|
|
|
$persons
|
|
|
|
);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
'episode' => $this->episode,
|
|
|
|
'persons' => $persons,
|
|
|
|
'theme' => $theme,
|
|
|
|
];
|
|
|
|
|
|
|
|
$secondsToNextUnpublishedEpisode = $episodeModel->getSecondsToNextUnpublishedEpisode(
|
|
|
|
$this->podcast->id
|
|
|
|
);
|
|
|
|
|
|
|
|
// The page cache is set to a decade so it is deleted manually upon podcast update
|
|
|
|
return view('embeddable_player', $data, [
|
|
|
|
'cache' => $secondsToNextUnpublishedEpisode
|
|
|
|
? $secondsToNextUnpublishedEpisode
|
|
|
|
: DECADE,
|
|
|
|
'cache_name' => $cacheName,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $cachedView;
|
|
|
|
}
|
2020-06-10 17:00:12 +02:00
|
|
|
}
|