[xExtension-YouTube] add player autosize feature

This commit is contained in:
intriguedlife 2025-02-08 20:32:27 +01:00
parent 5c43bd5fcd
commit 6fe50ddd1e
7 changed files with 44 additions and 1 deletions

View file

@ -9,6 +9,10 @@
*/
final class YouTubeExtension extends Minz_Extension
{
/**
* Whether we set the Youtube iframe to autosize
*/
private bool $autoSize = false;
/**
* Video player width
*/
@ -32,6 +36,8 @@ final class YouTubeExtension extends Minz_Extension
#[\Override]
public function init(): void
{
Minz_View::appendStyle($this->getFileUrl('style.css', 'css'));
$this->registerHook('entry_before_display', [$this, 'embedYouTubeVideo']);
$this->registerHook('check_url_before_add', [self::class, 'convertYoutubeFeedUrl']);
$this->registerTranslates();
@ -63,6 +69,11 @@ final class YouTubeExtension extends Minz_Extension
return;
}
$autoSize = FreshRSS_Context::userConf()->attributeBool('yt_autosize');
if ($autoSize !== null) {
$this->autoSize = $autoSize;
}
$width = FreshRSS_Context::userConf()->attributeInt('yt_player_width');
if ($width !== null) {
$this->width = $width;
@ -84,6 +95,15 @@ final class YouTubeExtension extends Minz_Extension
}
}
/**
* Returns whether this extension enables autosize for the YouTube player iframe.
* You have to call loadConfigValues() before this one, otherwise you get default values.
*/
public function isAutoSize(): bool
{
return $this->autoSize;
}
/**
* Returns the width in pixel for the YouTube player iframe.
* You have to call loadConfigValues() before this one, otherwise you get default values.
@ -181,7 +201,13 @@ final class YouTubeExtension extends Minz_Extension
{
$content = '';
$iframe = '<iframe class="youtube-plugin-video"
if ($this->autoSize) {
$class = "yt_autosize_true";
} else {
$class = "yt_autosize_false";
}
$iframe = '<iframe class="' . $class . '"
style="height: ' . $this->height . 'px; width: ' . $this->width . 'px;"
width="' . $this->width . '"
height="' . $this->height . '"
@ -252,6 +278,7 @@ final class YouTubeExtension extends Minz_Extension
$this->registerTranslates();
if (Minz_Request::isPost()) {
FreshRSS_Context::userConf()->_attribute('yt_autosize', Minz_Request::paramBoolean('yt_autosize'));
FreshRSS_Context::userConf()->_attribute('yt_player_height', Minz_Request::paramInt('yt_height'));
FreshRSS_Context::userConf()->_attribute('yt_player_width', Minz_Request::paramInt('yt_width'));
FreshRSS_Context::userConf()->_attribute('yt_show_content', Minz_Request::paramBoolean('yt_show_content'));