Federated sites
Bluesky
The default Bluesky media site can be customized with different hosts. This can be done using the BlueskyHelper class. In the example below, we configure the Bluesky media site to support both the main bsky.app domain, as well as our own hypothetical instance hosted on bluesky.local.
$configurator = new s9e\TextFormatter\Configurator;
// Use the Bluesky helper to set 'bsky.app' and 'bluesky.local' as supported instances
$mastodonHelper = $configurator->MediaEmbed->getSiteHelper('bluesky');
$mastodonHelper->setHosts(['bsky.app', 'bluesky.local']);
// Get an instance of the parser and the renderer
extract($configurator->finalize());
$text = 'https://bsky.app/profile/bsky.app/post/3kkrqzuydho2v';
$xml = $parser->parse($text);
$html = $renderer->render($xml);
echo $html;
<iframe data-s9e-mediaembed="bluesky" allowfullscreen="" loading="lazy" onload="let c=new MessageChannel;c.port1.onmessage=e=>this.style.height=e.data+'px';this.contentWindow.postMessage('s9e:init','*',[c.port2])" scrolling="no" src="https://s9e.github.io/iframe/2/bluesky.min.html#at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.post/3kkrqzuydho2v#embed.bsky.app" style="border:0;height:600px;max-width:600px;width:100%"></iframe>
Mastodon
The default Mastodon media site can be customized with additional hosts. This can be done using the MastodonHelper class. In the example below, we add support for toots published by the infosec.exchange instance.
$configurator = new s9e\TextFormatter\Configurator;
// Use the Mastodon helper to add 'infosec.exchange' as a supported instance
$mastodonHelper = $configurator->MediaEmbed->getSiteHelper('mastodon');
$mastodonHelper->addHost('infosec.exchange');
// Get an instance of the parser and the renderer
extract($configurator->finalize());
$text = 'https://infosec.exchange/@SwiftOnSecurity/109579438603578302';
$xml = $parser->parse($text);
$html = $renderer->render($xml);
echo $html;
<iframe data-s9e-mediaembed="mastodon" allowfullscreen="" loading="lazy" onload="let c=new MessageChannel;c.port1.onmessage=e=>this.style.height=e.data+'px';this.contentWindow.postMessage('s9e:init','*',[c.port2])" scrolling="no" style="border:0;height:300px;max-width:550px;width:100%" src="https://s9e.github.io/iframe/2/mastodon.min.html#SwiftOnSecurity@infosec.exchange/109579438603578302"></iframe>
PeerTube
$configurator = new s9e\TextFormatter\Configurator;
// Use the PeerTube helper to add 'neat.tube' as a supported instance
$peertubeHelper = $configurator->MediaEmbed->getSiteHelper('peertube');
$peertubeHelper->addHost('neat.tube');
// Get an instance of the parser and the renderer
extract($configurator->finalize());
$text = 'https://neat.tube/w/3PWC7CoQnqfZ4AkupAcVGB';
$xml = $parser->parse($text);
$html = $renderer->render($xml);
echo $html;
<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>
XenForo 2.3+
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.
$configurator = new s9e\TextFormatter\Configurator;
// Use the XenForo helper to add 'xenforo.com' as an authorized source
$xenforoHelper = $configurator->MediaEmbed->getSiteHelper('xenforo');
$xenforoHelper->addHost('xenforo.com');
// Get an instance of the parser and the renderer
extract($configurator->finalize());
$text = 'https://xenforo.com/community/threads/embed-your-content-anywhere.217381/';
$xml = $parser->parse($text);
$html = $renderer->render($xml);
echo $html;
<iframe data-s9e-mediaembed="xenforo" allowfullscreen="" loading="lazy" onload="let c=new MessageChannel;c.port1.onmessage=e=>this.style.height=e.data+'px';this.contentWindow.postMessage('s9e:init','*',[c.port2])" scrolling="no" style="border:0;height:300px;width:100%" src="https://s9e.github.io/iframe/2/xenforo.min.html#https://xenforo.com/community/threads/217381"></iframe>
Discoverability
Some of the default sites have a helper class used to configure them. In particular, federated sites offer a ConfigurableHostInterface interface that can be used to manipulate the list of allowed instances.
In the example below, we check all of the default sites for the presence of an helper attribute in their config and list those whose the actual helper instance implements ConfigurableHostInterface. This can be used to discover federated sites in the default sites.
use s9e\TextFormatter\Plugins\MediaEmbed\Configurator\SiteHelpers\ConfigurableHostInterface;
$configurator = new s9e\TextFormatter\Configurator;
foreach ($configurator->MediaEmbed->defaultSites as $siteId => $siteConfig)
{
if (!isset($siteConfig['helper']))
{
continue;
}
$siteHelper = $configurator->MediaEmbed->getSiteHelper($siteId);
if ($siteHelper instanceof ConfigurableHostInterface)
{
echo $siteConfig['name'], " is configurable via getSiteHelper('$siteId')->setHosts()\n";
}
}
Bluesky is configurable via getSiteHelper('bluesky')->setHosts()
Mastodon is configurable via getSiteHelper('mastodon')->setHosts()
PeerTube is configurable via getSiteHelper('peertube')->setHosts()
XenForo is configurable via getSiteHelper('xenforo')->setHosts()