Skip to content

Commit 479af5f

Browse files
committed
MediaEmbed: fixed PeerTube helper
1 parent f6bdc27 commit 479af5f

File tree

6 files changed

+38
-4
lines changed

6 files changed

+38
-4
lines changed

docs/Plugins/MediaEmbed/Federated_sites.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,29 @@ echo $html;
5151
```
5252

5353

54+
### PeerTube
55+
56+
```php
57+
$configurator = new s9e\TextFormatter\Configurator;
58+
59+
// Use the PeerTube helper to add 'neat.tube' as a supported instance
60+
$peertubeHelper = $configurator->MediaEmbed->getSiteHelper('peertube');
61+
$peertubeHelper->addHost('neat.tube');
62+
63+
// Get an instance of the parser and the renderer
64+
extract($configurator->finalize());
65+
66+
$text = 'https://neat.tube/w/3PWC7CoQnqfZ4AkupAcVGB';
67+
$xml = $parser->parse($text);
68+
$html = $renderer->render($xml);
69+
70+
echo $html;
71+
```
72+
```html
73+
<span data-s9e-mediaembed="peertube" style="display:inline-block;width:100%;max-width:640px"><span style="display:block;overflow:hidden;position:relative;padding-bottom:56.25%"><iframe allowfullscreen="" loading="lazy" scrolling="no" style="border:0;height:100%;left:0;position:absolute;width:100%" src="https://neat.tube/videos/embed/3PWC7CoQnqfZ4AkupAcVGB"></iframe></span></span>
74+
```
75+
76+
5477
### XenForo 2.3+
5578

5679
While not technically a federated platform, XenForo 2.3+ allows embedding content from one forum into another. In the following example, we use the `XenForoHelper` class to allow embedding content from `xenforo.com`.

docs/testdox.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7310,6 +7310,7 @@ Parser (s9e\TextFormatter\Tests\Plugins\MediaEmbed\Parser)
73107310
[x] Parsing tests with data set #345
73117311
[x] Parsing tests with data set #346
73127312
[x] Parsing tests with data set #347
7313+
[x] Parsing tests with data set #348
73137314
[x] Parsing tests (JavaScript) with data set #0
73147315
[x] Parsing tests (JavaScript) with data set #1
73157316
[x] Parsing tests (JavaScript) with data set #2
@@ -7658,6 +7659,7 @@ Parser (s9e\TextFormatter\Tests\Plugins\MediaEmbed\Parser)
76587659
[x] Parsing tests (JavaScript) with data set #345
76597660
[x] Parsing tests (JavaScript) with data set #346
76607661
[x] Parsing tests (JavaScript) with data set #347
7662+
[x] Parsing tests (JavaScript) with data set #348
76617663
[x] Parsing+rendering tests with data set #0
76627664
[x] Parsing+rendering tests with data set #1
76637665
[x] Parsing+rendering tests with data set #2

src/Plugins/MediaEmbed/Configurator/Collections/CachedDefinitionCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class CachedDefinitionCollection extends SiteDefinitionCollection
9292
'on3'=>['attributes'=>[],'example'=>['https://www.on3.com/rivals/darion-jones-240802/','https://www.on3.com/db/christian-jones-150372/industry-comparison/'],'extract'=>['!/db/(?:[-\\w]*-)?(?\'id\'[0-9]+)/industry-comparison/!','!/rivals/(?:[-\\w]*-)?(?\'id\'[0-9]+)/!'],'homepage'=>'https://www.on3.com/db/','host'=>['on3.com'],'iframe'=>['data-s9e-livepreview-ignore-attrs'=>'style','height'=>476,'onload'=>'let b=this.contentWindow;window.addEventListener(\'message\',a=>{{a.source===b&&a.data.height&&(this.style.height=+a.data.height+20+\'px\')}});b.postMessage(\'\',\'*\')','src'=>'https://embed.on3.com/db/{@id}/industry-comparison/','width'=>600],'name'=>'On3 DB','scrape'=>[],'tags'=>['sports']],
9393
'orfium'=>['attributes'=>[],'example'=>['https://www.orfium.com/album/24371/everybody-loves-kanye-totom/','https://www.orfium.com/live-set/614763/foof-no-lights-5-foof/','https://www.orfium.com/playlist/511651/electronic-live-sessions-creamtronic/','https://www.orfium.com/track/625367/the-ambience-of-the-goss-vistas/'],'extract'=>['@album/(?\'album_id\'\\d+)@','@playlist/(?\'playlist_id\'\\d+)@','@live-set/(?\'set_id\'\\d+)@','@track/(?\'track_id\'\\d+)@'],'homepage'=>'https://www.orfium.com/','host'=>['orfium.com'],'iframe'=>['height'=>'<xsl:choose><xsl:when test="@album_id">550</xsl:when><xsl:otherwise>275</xsl:otherwise></xsl:choose>','max-width'=>900,'src'=>'https://www.orfium.com/embedded/<xsl:choose><xsl:when test="@album_id">album/<xsl:value-of select="@album_id"/></xsl:when><xsl:when test="@playlist_id">playlist/<xsl:value-of select="@playlist_id"/></xsl:when><xsl:when test="@set_id">live-set/<xsl:value-of select="@set_id"/></xsl:when><xsl:otherwise>track/<xsl:value-of select="@track_id"/></xsl:otherwise></xsl:choose>','width'=>'100%'],'name'=>'Orfium','scrape'=>[],'tags'=>['music']],
9494
'pastebin'=>['attributes'=>[],'example'=>'https://pastebin.com/9jEf44nc','extract'=>['@pastebin\\.com/(?!u/)(?:\\w+(?:\\.php\\?i=|/))?(?\'id\'\\w+)@'],'homepage'=>'https://pastebin.com/','host'=>['pastebin.com'],'iframe'=>['height'=>300,'scrolling'=>'','src'=>'//pastebin.com/embed_iframe/{@id}','style'=>['resize'=>'vertical'],'width'=>'100%'],'name'=>'Pastebin','scrape'=>[]],
95-
'peertube'=>['attributes'=>['host'=>['required'=>true],'id'=>['filterChain'=>['#identifier'],'required'=>true],'start'=>['filterChain'=>['#timestamp'],'required'=>false]],'example'=>'https://peertube.tv/w/5JHc2MW1LS4HjDExModcwo','extract'=>['!^https://(?\'host\'[-.\\w]+)/(?:videos/embed|w)/(?\'id\'[-\\w]+)(?:\\?start=(?\'start\'\\d[\\dhms]*))?!'],'homepage'=>'https://joinpeertube.org/','host'=>['peertube.tv'],'iframe'=>['src'=>'https://<xsl:value-of select="@host"/>/videos/embed/<xsl:value-of select="@id"/><xsl:if test="@start">?start=<xsl:value-of select="@start"/></xsl:if>'],'name'=>'PeerTube','scrape'=>[['extract'=>['!https://(?\'host\'[-.\\w]+)/videos/embed/(?\'id\'[-\\w]+)(?:\\?start=(?\'start\'\\d[\\dhms]*))?!'],'match'=>['!^https://(?\'host\'[-.\\w]+)/w/(?\'id\'\\w+)!'],'url'=>'https://{@host}/services/oembed?url=https%3A%2F%2F{@host}%2Fw%2F%2F{@id}']],'tags'=>['videos']],
95+
'peertube'=>['attributes'=>['host'=>['required'=>true],'id'=>['filterChain'=>['#identifier'],'required'=>true],'start'=>['filterChain'=>['#timestamp'],'required'=>false]],'example'=>'https://peertube.tv/w/5JHc2MW1LS4HjDExModcwo','extract'=>['!^https://(?\'host\'[-.\\w]+)/(?:videos/embed|w)/(?\'id\'[-\\w]+)(?:\\?start=(?\'start\'\\d[\\dhms]*))?!'],'helper'=>'s9e\\TextFormatter\\Plugins\\MediaEmbed\\Configurator\\SiteHelpers\\PeerTubeHelper','homepage'=>'https://joinpeertube.org/','host'=>['peertube.tv'],'iframe'=>['src'=>'https://<xsl:value-of select="@host"/>/videos/embed/<xsl:value-of select="@id"/><xsl:if test="@start">?start=<xsl:value-of select="@start"/></xsl:if>'],'name'=>'PeerTube','scrape'=>[['extract'=>['!https://(?\'host\'[-.\\w]+)/videos/embed/(?\'id\'[-\\w]+)(?:\\?start=(?\'start\'\\d[\\dhms]*))?!'],'match'=>['!^https://(?\'host\'[-.\\w]+)/w/(?\'id\'\\w+)!'],'url'=>'https://{@host}/services/oembed?url=https%3A%2F%2F{@host}%2Fw%2F%2F{@id}']],'tags'=>['videos']],
9696
'pinterest'=>['amp'=>['custom-element'=>'amp-pinterest','src'=>'https://cdn.ampproject.org/v0/amp-pinterest-0.1.js','template'=>'<amp-pinterest width="245" height="330" data-do="embedPin" data-url="https://www.pinterest.com/pin/{@id}/"/>'],'attributes'=>[],'example'=>['https://www.pinterest.com/pin/99360735500167749/','https://www.pinterest.com/pinterest/official-news/'],'extract'=>['@pinterest.com/pin/(?\'id\'\\d+)@','@pinterest.com/(?!_/|discover/|explore/|news_hub/|pin/|search/)(?\'id\'[-\\w]+/[-\\w]+)@'],'homepage'=>'https://www.pinterest.com/','host'=>['pinterest.com'],'iframe'=>['data-s9e-livepreview-ignore-attrs'=>'style','height'=>360,'onload'=>'let c=new MessageChannel;c.port1.onmessage=e=>this.style.height=e.data+\'px\';this.contentWindow.postMessage(\'s9e:init\',\'*\',[c.port2])','src'=>'https://s9e.github.io/iframe/2/pinterest.min.html#{@id}','width'=>'<xsl:choose><xsl:when test="contains(@id,\'/\')">730</xsl:when><xsl:otherwise>345</xsl:otherwise></xsl:choose>'],'name'=>'Pinterest','scrape'=>[],'source'=>'https://developers.pinterest.com/tools/widget-builder/','tags'=>['social']],
9797
'podbean'=>['attributes'=>[],'example'=>['https://dialhforheroclix.podbean.com/e/dial-h-for-heroclix-episode-46-all-ya-need-is-love/','https://www.podbean.com/ew/pb-gmyyz-d6e065'],'extract'=>['!podbean\\.com/(?:[-\\w]+/)*(?:player[-\\w]*/|\\w+/pb-)(?\'id\'[-\\w]+)!'],'homepage'=>'https://www.podbean.com/','host'=>['podbean.com'],'iframe'=>['height'=>150,'max-width'=>900,'src'=>'https://www.podbean.com/player-v2/?i={@id}','width'=>'100%'],'name'=>'Podbean','scrape'=>[['extract'=>['!podbean\\.com/player[^/]*/\\?i=(?\'id\'[-\\w]+)!'],'header'=>'User-agent: PHP (not Mozilla)','match'=>['@podbean\\.com/(?:media/shar)?e/(?!pb-)@']]],'tags'=>['podcasts']],
9898
'prezi'=>['attributes'=>[],'example'=>'https://prezi.com/5ye8po_hmikp/10-most-common-rookie-presentation-mistakes/','extract'=>['#//prezi\\.com/(?!(?:a(?:bout|mbassadors)|c(?:o(?:llaborate|mmunity|ntact)|reate)|exp(?:erts|lore)|ip(?:ad|hone)|jobs|l(?:ear|ogi)n|m(?:ac|obility)|pr(?:es(?:s|ent)|icing)|recommend|support|user|windows|your)/)(?\'id\'\\w+)/#'],'homepage'=>'https://prezi.com/','host'=>['prezi.com'],'iframe'=>['height'=>400,'src'=>'//prezi.com/embed/{@id}/','width'=>550],'name'=>'Prezi','scrape'=>[],'tags'=>['presentations']],

src/Plugins/MediaEmbed/Configurator/PeerTubeHelper.php renamed to src/Plugins/MediaEmbed/Configurator/SiteHelpers/PeerTubeHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @copyright Copyright (c) The s9e authors
66
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
77
*/
8-
namespace s9e\TextFormatter\Plugins\MediaEmbed\Configurator;
8+
namespace s9e\TextFormatter\Plugins\MediaEmbed\Configurator\SiteHelpers;
99

1010
class PeerTubeHelper extends AbstractConfigurableHostHelper
1111
{

src/Plugins/MediaEmbed/Configurator/sites/peertube.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<site name="PeerTube" homepage="https://joinpeertube.org/">
1+
<site name="PeerTube" homepage="https://joinpeertube.org/" helper="s9e\TextFormatter\Plugins\MediaEmbed\Configurator\SiteHelpers\PeerTubeHelper">
22
<example>https://peertube.tv/w/5JHc2MW1LS4HjDExModcwo</example>
33

44
<tags><tag>videos</tag></tags>

tests/Plugins/MediaEmbed/ParserTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ function ($configurator)
990990
{
991991
$configurator->registeredVars['cacheDir'] = __DIR__ . '/../../.cache';
992992

993-
$peertubeHelper = new PeerTubeHelper($configurator);
993+
$peertubeHelper = $configurator->MediaEmbed->getSiteHelper('peertube');
994994
$peertubeHelper->addHost('neat.tube');
995995
}
996996
],
@@ -3136,6 +3136,15 @@ function ($configurator)
31363136
$configurator->MediaEmbed->add('pastebin');
31373137
}
31383138
],
3139+
[
3140+
'https://peertube.test/w/5JHc2MW1LS4HjDExModcwo',
3141+
'<t>https://peertube.test/w/5JHc2MW1LS4HjDExModcwo</t>',
3142+
[],
3143+
function ($configurator)
3144+
{
3145+
$configurator->MediaEmbed->add('peertube');
3146+
}
3147+
],
31393148
[
31403149
'https://www.pinterest.com/pin/99360735500167749/',
31413150
'<r><PINTEREST id="99360735500167749">https://www.pinterest.com/pin/99360735500167749/</PINTEREST></r>',

0 commit comments

Comments
 (0)