mirror of
https://code.castopod.org/adaures/castopod
synced 2025-04-23 01:01:20 +00:00

- add "ActivityPub" library to handle server to server federation and basic client to server protocols using activitypub: - add webfinger endpoint to look for actor - add actor definition with inbox / outbox / followers - remote follow an actor - create notes with possible preview cards - interract with favourites, reblogs and replies - block incoming actors and/or domains - broadcast/schedule activities to fediverse followers using a cron task - For castopod, the podcast is the actor: - overwrite the activitypub library for castopod's specific needs - perform basic interactions administrating a podcast to interact with fediverse users: - create notes with episode attachment - favourite and share a note + reply - add specific castopod_namespaces for podcasts and episodes definitions - overwrite CodeIgniter's Route service to include alternate-content option for activitystream requests - update episode publication logic: - remove publication inputs in create / edit episode form - publish / schedule or unpublish an episode after creation - the podcaster publishes a note when publishing an episode - Javascript / Typescript modules: - fix Dropdown.ts to keep dropdown menu in foreground - add Modal.ts for funding links modal - add Toggler.ts to toggle various css states in ui - User Interface: - update tailwindcss to v2 - use castopod's pine and rose colors - update public layout to a 3 column layout - add pages in public for podcast activity, episode list and notes - update episode page to include linked notes - remove previous and next episodes from episode pages - show different public views depending on whether user is authenticated or not - use Kumbh Sans and Montserrat fonts - update CodeIgniter's config files - with CodeIgniter's new requirements, update docker environments are now based on php v7.3 image - move Image entity to Libraries - update composer and npm packages to latest versions closes #69 #65 #85, fixes #51 #91 #92 #88
192 lines
6.4 KiB
PHP
192 lines
6.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @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;
|
|
use SimpleXMLElement;
|
|
|
|
class Episode extends BaseController
|
|
{
|
|
/**
|
|
* @var \App\Entities\Podcast
|
|
*/
|
|
protected $podcast;
|
|
|
|
/**
|
|
* @var \App\Entities\Episode|null
|
|
*/
|
|
protected $episode;
|
|
|
|
public function _remap($method, ...$params)
|
|
{
|
|
$this->podcast = (new PodcastModel())->getPodcastByName($params[0]);
|
|
|
|
if (
|
|
count($params) > 1 &&
|
|
!($this->episode = (new EpisodeModel())->getEpisodeBySlug(
|
|
$this->podcast->id,
|
|
$params[1],
|
|
))
|
|
) {
|
|
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
|
}
|
|
unset($params[1]);
|
|
unset($params[0]);
|
|
return $this->$method(...$params);
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$episodeModel = new EpisodeModel();
|
|
|
|
self::triggerWebpageHit($this->podcast->id);
|
|
|
|
$locale = service('request')->getLocale();
|
|
$cacheName = "page_podcast{$this->episode->podcast_id}_episode{$this->episode->id}_{$locale}";
|
|
|
|
if (!($cachedView = cache($cacheName))) {
|
|
helper('persons');
|
|
$episodePersons = [];
|
|
construct_person_array($this->episode->persons, $episodePersons);
|
|
$podcastPersons = [];
|
|
construct_person_array($this->podcast->persons, $podcastPersons);
|
|
|
|
$data = [
|
|
'podcast' => $this->podcast,
|
|
'episode' => $this->episode,
|
|
'episodePersons' => $episodePersons,
|
|
'persons' => $podcastPersons,
|
|
];
|
|
|
|
$secondsToNextUnpublishedEpisode = $episodeModel->getSecondsToNextUnpublishedEpisode(
|
|
$this->podcast->id,
|
|
);
|
|
|
|
if (can_user_interact()) {
|
|
helper('form');
|
|
// The page cache is set to a decade so it is deleted manually upon podcast update
|
|
return view('podcast/episode_authenticated', $data, [
|
|
'cache' => $secondsToNextUnpublishedEpisode
|
|
? $secondsToNextUnpublishedEpisode
|
|
: DECADE,
|
|
'cache_name' => $cacheName . '_authenticated',
|
|
]);
|
|
} else {
|
|
// The page cache is set to a decade so it is deleted manually upon podcast update
|
|
return view('podcast/episode', $data, [
|
|
'cache' => $secondsToNextUnpublishedEpisode
|
|
? $secondsToNextUnpublishedEpisode
|
|
: DECADE,
|
|
'cache_name' => $cacheName,
|
|
]);
|
|
}
|
|
}
|
|
|
|
return $cachedView;
|
|
}
|
|
|
|
public function embeddablePlayer($theme = 'light-transparent')
|
|
{
|
|
header('Content-Security-Policy: frame-ancestors https://* http://*');
|
|
|
|
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];
|
|
|
|
$data = [
|
|
'podcast' => $this->podcast,
|
|
'episode' => $this->episode,
|
|
'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;
|
|
}
|
|
|
|
public function oembedJSON()
|
|
{
|
|
return $this->response->setJSON([
|
|
'type' => 'rich',
|
|
'version' => '1.0',
|
|
'title' => $this->episode->title,
|
|
'provider_name' => $this->podcast->title,
|
|
'provider_url' => $this->podcast->link,
|
|
'author_name' => $this->podcast->title,
|
|
'author_url' => $this->podcast->link,
|
|
'html' =>
|
|
'<iframe src="' .
|
|
$this->episode->embeddable_player .
|
|
'" width="100%" height="200" frameborder="0" scrolling="no"></iframe>',
|
|
'width' => 600,
|
|
'height' => 200,
|
|
'thumbnail_url' => $this->episode->image->large_url,
|
|
'thumbnail_width' => config('Images')->largeSize,
|
|
'thumbnail_height' => config('Images')->largeSize,
|
|
]);
|
|
}
|
|
|
|
public function oembedXML()
|
|
{
|
|
$oembed = new SimpleXMLElement(
|
|
"<?xml version='1.0' encoding='utf-8' standalone='yes'?><oembed></oembed>",
|
|
);
|
|
|
|
$oembed->addChild('type', 'rich');
|
|
$oembed->addChild('version', '1.0');
|
|
$oembed->addChild('title', $this->episode->title);
|
|
$oembed->addChild('provider_name', $this->podcast->title);
|
|
$oembed->addChild('provider_url', $this->podcast->link);
|
|
$oembed->addChild('author_name', $this->podcast->title);
|
|
$oembed->addChild('author_url', $this->podcast->link);
|
|
$oembed->addChild('thumbnail', $this->episode->image->large_url);
|
|
$oembed->addChild('thumbnail_width', config('Images')->largeSize);
|
|
$oembed->addChild('thumbnail_height', config('Images')->largeSize);
|
|
$oembed->addChild(
|
|
'html',
|
|
htmlentities(
|
|
'<iframe src="' .
|
|
$this->episode->embeddable_player .
|
|
'" width="100%" height="200" frameborder="0" scrolling="no"></iframe>',
|
|
),
|
|
);
|
|
$oembed->addChild('width', 600);
|
|
$oembed->addChild('height', 200);
|
|
|
|
return $this->response->setXML($oembed);
|
|
}
|
|
}
|