Closed pattyland closed 8 years ago
I had the same problem when using the autoEmbed() method.
I got around it by reproducing the autoEmbed method but changing the strstr() function call which does the replacement to a preg_replace() call which ignores URLs inside links.
The code I'm using is:
public static function OEmbed($text)
{
$embera = new Embera();
if ($data = $embera->getUrlInfo($text)) {
$table = [];
foreach ($data as $url => $service) {
if (!empty($service['html'])) {
$table[$url] = $service['html'];
}
}
foreach ($table as $url => $replacement) {
$text = preg_replace('~(?<![\'\"])'.preg_quote($url).'(?![\'\"])(?!\</a\>)~', $replacement, $text);
}
}
return $text;
}
I'm not sure why I never made a pull request to Embera for that, perhaps as an autoEmbedHtml() method, very selfish of me :(
Hi Pattyland!
Thanks for the report! You are right, that behaviour ocurrs with Html text and I never thought too much about it, since I always used Embera with plain text.
I gotta thank robbytaylor for giving a very viable soultion, I might copy it just as well :smiley: , but im debating if It should be a new method only for html input or a configuration option, and modify the main autoEmbed()
method or just modify the behaviour and document that Embera ignores html links with oembed urls.
Either way, I'll be adding the code tonight or tomorrow morning.
Thank you both!
:thumbsup:
Hi
I have the same issue. Embera replaces all links - including links in quotations. Do you have plan to include this functionality into some version of embera? (right now i am using fix from @robbytaylor)
Thanks
Hi Guys!
Thank you very much for the input and report.
Since I already had another report about ignoring urls inside other tags (see #22), I decided to create another class that takes care of auto-embedding when the content seems to be HTML code.
Embera now should be able to ignore <a>
, <pre>
, <code>
and <img>
tags when using the autoEmbed()
method. I tested it and It was working without any problems, however I would appreciate if you guys can test it, before I tag this last commit as 1.9.0
.
It is a bigger solution and more expensive than just a simple preg_replace()
, but it might be more flexible in terms, that I can easily add more html tags, users have the power of adding their own set of html tags and It might be easier to maintain, than adding a list of regex's to preg_replace()
.
The HtmlProcessor
is in charge of all that jazz and only runs when the content has a >
, which most of the cases should mean that it probably has html in it.
Saddly, for now, Embera still replaces links that are inside quotations (" or '), I'll look into it when I have more time, but that could be done with robby's preg_replace pattern and some minor modifications.
One other HTML tag is should be ignoring is iframe
I just tagged a new version, 1.9.0
with this functionality. Allthough I have been testing it for a while now and that it is working without any trouble, I encourage you to please open a new report if you have any problems.
@hrtrulz , you can use the ignore_tags option to add your own tags. You can add the iframe
tag and test it out. Please test it, and report back if everything is working, and perhaps I'll add iframe
to the default tags that should be ignored.
Thanks guys for the help and report!
Hi, I guess oEmbed was invented to enhance user generated content. The big problem I have is that I'm getting a mix of plaintext and html. Plaintext is fine, but for example
<a href="http://youtube.com/***">http://youtube.com/***</a>
is getting messed up when parsed through Embara.There are several solutions I thought off:
Did you encountered such a problem and what did you do?
Greets, Sören