2023-08-28 13:53:04 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @copyright 2023 Ad Aures
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Controllers;
|
|
|
|
|
|
|
|
use App\Entities\Episode;
|
|
|
|
use App\Models\EpisodeModel;
|
|
|
|
use CodeIgniter\Exceptions\PageNotFoundException;
|
2024-02-26 10:24:49 +00:00
|
|
|
use Modules\Media\FileManagers\FileManagerInterface;
|
2023-08-28 13:53:04 +00:00
|
|
|
|
|
|
|
class EpisodePreviewController extends BaseController
|
|
|
|
{
|
|
|
|
protected Episode $episode;
|
|
|
|
|
|
|
|
public function _remap(string $method, string ...$params): mixed
|
|
|
|
{
|
|
|
|
if (count($params) < 1) {
|
|
|
|
throw PageNotFoundException::forPageNotFound();
|
|
|
|
}
|
|
|
|
|
|
|
|
// find episode by previewUUID
|
|
|
|
$episode = (new EpisodeModel())->getEpisodeByPreviewId($params[0]);
|
|
|
|
|
|
|
|
if (! $episode instanceof Episode) {
|
|
|
|
throw PageNotFoundException::forPageNotFound();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->episode = $episode;
|
|
|
|
|
|
|
|
if ($episode->publication_status === 'published') {
|
|
|
|
// redirect to episode page
|
|
|
|
return redirect()->route('episode', [$episode->podcast->handle, $episode->slug]);
|
|
|
|
}
|
|
|
|
|
|
|
|
unset($params[0]);
|
|
|
|
|
|
|
|
return $this->{$method}(...$params);
|
|
|
|
}
|
|
|
|
|
2024-04-17 09:13:07 +00:00
|
|
|
public function index(): string
|
2023-08-28 13:53:04 +00:00
|
|
|
{
|
|
|
|
helper('form');
|
|
|
|
|
|
|
|
return view('episode/preview-comments', [
|
|
|
|
'podcast' => $this->episode->podcast,
|
|
|
|
'episode' => $this->episode,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2024-04-17 09:13:07 +00:00
|
|
|
public function activity(): string
|
2023-08-28 13:53:04 +00:00
|
|
|
{
|
|
|
|
helper('form');
|
|
|
|
|
|
|
|
return view('episode/preview-activity', [
|
|
|
|
'podcast' => $this->episode->podcast,
|
|
|
|
'episode' => $this->episode,
|
|
|
|
]);
|
|
|
|
}
|
2024-02-17 12:02:38 +00:00
|
|
|
|
2024-04-17 09:13:07 +00:00
|
|
|
public function chapters(): string
|
2024-02-17 12:02:38 +00:00
|
|
|
{
|
2024-02-26 10:24:49 +00:00
|
|
|
$data = [
|
2024-02-17 12:02:38 +00:00
|
|
|
'podcast' => $this->episode->podcast,
|
|
|
|
'episode' => $this->episode,
|
2024-02-26 10:24:49 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
if (isset($this->episode->chapters->file_key)) {
|
|
|
|
/** @var FileManagerInterface $fileManager */
|
|
|
|
$fileManager = service('file_manager');
|
|
|
|
$episodeChaptersJsonString = (string) $fileManager->getFileContents($this->episode->chapters->file_key);
|
|
|
|
|
|
|
|
$chapters = json_decode($episodeChaptersJsonString, true);
|
|
|
|
$data['chapters'] = $chapters;
|
|
|
|
}
|
|
|
|
|
|
|
|
helper('form');
|
|
|
|
return view('episode/preview-chapters', $data);
|
2024-02-17 12:02:38 +00:00
|
|
|
}
|
2024-04-17 09:13:07 +00:00
|
|
|
|
|
|
|
public function transcript(): string
|
|
|
|
{
|
|
|
|
// get transcript from json file
|
|
|
|
$data = [
|
|
|
|
'podcast' => $this->episode->podcast,
|
|
|
|
'episode' => $this->episode,
|
|
|
|
];
|
|
|
|
|
|
|
|
if ($this->episode->transcript !== null) {
|
|
|
|
$data['transcript'] = $this->episode->transcript;
|
|
|
|
|
|
|
|
if ($this->episode->transcript->json_key !== null) {
|
|
|
|
/** @var FileManagerInterface $fileManager */
|
|
|
|
$fileManager = service('file_manager');
|
|
|
|
$transcriptJsonString = (string) $fileManager->getFileContents(
|
|
|
|
$this->episode->transcript->json_key
|
|
|
|
);
|
|
|
|
|
|
|
|
$data['captions'] = json_decode($transcriptJsonString, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
helper('form');
|
|
|
|
return view('episode/preview-transcript', $data);
|
|
|
|
}
|
2023-08-28 13:53:04 +00:00
|
|
|
}
|