Comments (3)
Hi!
Oh, my bad I understood it the other way around.
The first thing that comes to mind is converting the oembed tag into the url inside of it. You can pass the output to Embera and process.
There is a setting inside the ProviderCollectionAdapter
called url_extractor_regex
that could be changed in order to support oembed tags but It would require more changes into the library itself, so I think preparing the text before passing it through Embera is your best choice.
$text = '<p>This is a some text</p>
<figure class="media">
<oembed url="https://www.youtube.com/watch?v=NyEq7unEv5I"></oembed>
</figure>
<p>Other Video: https://www.youtube.com/watch?v=pILCn6VO_RU</p>';
$text = preg_replace('~<oembed url="(https?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/|_)))"></oembed>~is', '$1', $text);
$embera = new Embera();
echo $embera->autoEmbed($text);
Outputs:
<p>This is a some text</p>
<figure class="media">
<iframe width="480" height="270" src="https://www.youtube.com/embed/NyEq7unEv5I?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</figure>
<p>Other Video: <iframe width="480" height="270" src="https://www.youtube.com/embed/pILCn6VO_RU?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
That should work if there is only one oembed
element in your content.
However I think the better solution should be something like this
$text = '<p>This is a some text</p>
<figure class="media">
<oembed url="https://www.youtube.com/watch?v=NyEq7unEv5I"></oembed>
</figure>
<figure class="media">
<oembed url="https://unsupportedprovider.com/watch?v=NyEq7unEv5I"></oembed>
</figure>
<p>Other Video: https://www.youtube.com/watch?v=pILCn6VO_RU</p>
<figure class="media">
<oembed url="https://www.youtube.com/watch?v=62EB4JniuTc"></oembed>
</figure>';
if (preg_match_all('~<oembed url="(https?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/|_)))"></oembed>~is', $text, $matches, PREG_SET_ORDER)) {
foreach ($matches as $m) {
$text = str_replace($m['0'], $m['1'], $text);
}
}
$embera = new Embera();
$text = $embera->autoEmbed($text);
foreach ((array) $matches as $m) {
$text = str_replace($m['1'], $m['0'], $text);
}
echo $text;
The last loop ensures that we dont loose content in case there is an oembed tag with an unsupported oembed provider.
I think this is the best way to handle this type of scenarios.
from embera.
Sorry for the late response. You can use the ignore_tags
directive.
use Embera\Embera;
$config = [
'ignore_tags' => [ 'pre', 'code', 'a', 'img', 'iframe', 'oembed' ]
];
$embera = new Embera($config);
echo $embera->autoEmbed('<p>This is a some text</p>
<figure class="media">
<oembed url="https://www.youtube.com/watch?v=NyEq7unEv5I"></oembed>
</figure>
<p>Above and below some video</p>');
Should output
<p>This is a some text</p><figure class="media"><oembed url="https://www.youtube.com/watch?v=NyEq7unEv5I"></oembed></figure><p>Above and below some video</p>
As you can see, the url remains intact.
Let me know if that is what you are searching for.
from embera.
HI @mpratt
I was hoping it would translate to:
<p>This is a some text</p>
<figure class="media"><iframe width="480" height="270" src="https://www.youtube.com/embed/NyEq7unEv5I?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></figure>
<p>Above and below some video</p>
So it translates the URL into the iFrame using the autoEmbed functionality
from embera.
Related Issues (20)
- iFrame `frameborder` attribute is deprecated in HTLM5 HOT 1
- Add an option for iframe lazyloading HOT 1
- Spotify artist link not working
- Allow hidden vi HOT 1
- Silk defunct HOT 1
- Playbuzz implementation is incomplete HOT 1
- youtube rel=0 ? HOT 1
- How about dropping support php version prior to 7.2? HOT 3
- Argument 2 passed to Embera\Http\OembedClient::__construct() must be an instance of Embera\Http\HttpClient, instance of Embera\Http\HttpClientCache given HOT 3
- Added Wordwall provider HOT 3
- Custom Provider Parameters HOT 6
- Broken/Unsupported Providers HOT 3
- Get video_id from Youtube URL HOT 3
- Facebook is problematic HOT 4
- Instagram oEmbed is deprecated HOT 1
- Support custom request headers HOT 2
- Vimeo private video links HOT 1
- Imgur not embedded? HOT 1
- Twitter embeds don't work on production HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from embera.