Skip to content

[xExtension-YouTube] add player autosize feature #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions xExtension-YouTube/configure.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ declare(strict_types=1);
<input type="hidden" name="_csrf" value="<?php echo FreshRSS_Auth::csrfToken(); ?>" />
<div class="form-group">

<div class="group-controls">
<label class="checkbox" for="yt_autosize">
<input type="checkbox" id="yt_autosize" name="yt_autosize" value="1" <?php echo $this->isAutoSize() ? 'checked' : ''; ?>>
<?php echo _t('ext.yt_videos.autosize'); ?>
</label>
</div>

<label class="group-name" for="yt_height"><?php echo _t('ext.yt_videos.height'); ?></label>
<div class="group-controls">
<input type="number" id="yt_height" name="yt_height" value="<?php echo $this->getHeight(); ?>" min="50" data-leave-validation="1">
Expand Down
32 changes: 28 additions & 4 deletions xExtension-YouTube/extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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();
Expand Down Expand Up @@ -63,6 +69,11 @@ public function loadConfigValues(): void
return;
}

$autoSize = FreshRSS_Context::userConf()->attributeBool('yt_player_autosize');
if ($autoSize !== null) {
$this->autoSize = $autoSize;
}

$width = FreshRSS_Context::userConf()->attributeInt('yt_player_width');
if ($width !== null) {
$this->width = $width;
Expand All @@ -84,6 +95,15 @@ public function loadConfigValues(): void
}
}

/**
* 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.
Expand Down Expand Up @@ -180,11 +200,14 @@ public function getHtmlPeerTubeContentForLink(FreshRSS_Entry $entry, string $lin
public function getHtml(FreshRSS_Entry $entry, string $url): string
{
$content = '';

if ($this->autoSize) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You removed the class youtube-plugin-video. Can you re-add it, to not break existing customizations?

$iframe_attribute = 'class="yt_player_autosize"';
} else {
$iframe_attribute = 'width="' . $this->width . '" height="' . $this->height . '"';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember why the style attribute was used, but I am almost certain, that I added it on purpose.
It's gone now.

}

$iframe = '<iframe class="youtube-plugin-video"
style="height: ' . $this->height . 'px; width: ' . $this->width . 'px;"
width="' . $this->width . '"
height="' . $this->height . '"
$iframe = '<iframe ' . $iframe_attribute . '
src="' . $url . '"
frameborder="0"
allowFullScreen></iframe>';
Expand Down Expand Up @@ -252,6 +275,7 @@ public function handleConfigureAction(): void
$this->registerTranslates();

if (Minz_Request::isPost()) {
FreshRSS_Context::userConf()->_attribute('yt_player_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'));
Expand Down
1 change: 1 addition & 0 deletions xExtension-YouTube/i18n/de/ext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

return array(
'yt_videos' => array(
'autosize' => 'Autogröße des Players',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'autosize' => 'Autogröße des Players',
'autosize' => 'Automatische Größe des Players',

'height' => 'Höhe des Players',
'width' => 'Breite des Players',
'updates' => 'Die neueste Version des Plugins findest Du bei',
Expand Down
1 change: 1 addition & 0 deletions xExtension-YouTube/i18n/en/ext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

return array(
'yt_videos' => array(
'autosize' => 'Player autosize',
'height' => 'Player height',
'width' => 'Player width',
'updates' => 'You can find the latest extension version at',
Expand Down
1 change: 1 addition & 0 deletions xExtension-YouTube/i18n/fr/ext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

return array(
'yt_videos' => array(
'autosize' => 'Taille automatique du lecteur',
'height' => 'Hauteur du lecteur',
'width' => 'Largeur du lecteur',
'updates' => 'Vous pouvez trouver la dernière mise à jour de l’extension sur ',
Expand Down
1 change: 1 addition & 0 deletions xExtension-YouTube/i18n/tr/ext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

return array(
'yt_videos' => array(
'autosize' => 'Oynatıcı otomatik boyutlandırma',
'height' => 'Oynatıcı yükseklik',
'width' => 'Oynatıcı genişlik',
'updates' => 'En son uzantı sürümünü şu adreste bulabilirsiniz:',
Expand Down
4 changes: 4 additions & 0 deletions xExtension-YouTube/static/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.yt_player_autosize {
width: 100%;
aspect-ratio: 16 / 9;
}