- 
                Notifications
    You must be signed in to change notification settings 
- Fork 82
[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
      
      
            intriguedlife
  wants to merge
  6
  commits into
  FreshRSS:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
intriguedlife:YoutubeAutosize
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      6fe50dd
              
                [xExtension-YouTube] add player autosize feature
              
              
                intriguedlife 8ed35c8
              
                [xExtension-YouTube] correct player autosize variable name
              
              
                intriguedlife 284445e
              
                [xExtension-YouTube] Correct CSS formatting
              
              
                intriguedlife bb097e5
              
                [xExtension-YouTube] refine iframe element logic
              
              
                intriguedlife 4533d7a
              
                [xExtension-YouTube] another CSS correction
              
              
                intriguedlife 94a9396
              
                [xExtension-YouTube] CSS correction 3
              
              
                intriguedlife File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -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 @@ 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; | ||
|  | @@ -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. | ||
|  | @@ -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) { | ||
| $iframe_attribute = 'class="yt_player_autosize"'; | ||
| } else { | ||
| $iframe_attribute = 'width="' . $this->width . '" height="' . $this->height . '"'; | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
| } | ||
|  | ||
| $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>'; | ||
|  | @@ -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')); | ||
|  | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|  | @@ -2,6 +2,7 @@ | |||||
|  | ||||||
| return array( | ||||||
| 'yt_videos' => array( | ||||||
| 'autosize' => 'Autogröße des Players', | ||||||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
        Suggested change
       
 | ||||||
| 'height' => 'Höhe des Players', | ||||||
| 'width' => 'Breite des Players', | ||||||
| 'updates' => 'Die neueste Version des Plugins findest Du bei', | ||||||
|  | ||||||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| .yt_player_autosize { | ||
| width: 100%; | ||
| aspect-ratio: 16 / 9; | ||
| } | 
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
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?