Welcome! » Log In » Create A New Profile

Error in YouTube embedding documentation

Posted by vbMark 
vbMark
Error in YouTube embedding documentation
March 10, 2009 09:56PM

Hello,

It took me forever to figure out why my YouTube Embedding code was not working.

In the "Embedding YouTube Videos" documentation here: http://htmlpurifier.org/docs/enduser-youtube.html

It says to embed like this:

<span class="embed-youtube">AyPzM5WK8ys</span>

But that was not working. Finally I looked at the code here http://repo.or.cz/w/htmlpurifier.git?a=blob;hb=HEAD;f=library/HTMLPurifier/Filter/YouTube.php

and saw that the regex looks for this:

<span class="youtube-embed">

Thanks, Mark

Re: Error in YouTube embedding documentation
March 10, 2009 10:34PM

Whoops, my bad! I'll be sure to update the documentation. Thanks for pointing it out.

vbMark
Re: Error in YouTube embedding documentation
March 11, 2009 12:02AM

Just for testing purposes I took the YouTube code from the documentation page

<object width="425" height="350">
  <param name="movie" value="http://www.youtube.com/v/AyPzM5WK8ys" />
  <param name="wmode" value="transparent" />
  <embed src="http://www.youtube.com/v/AyPzM5WK8ys"
         type="application/x-shockwave-flash"
         wmode="transparent" width="425" height="350" />
</object>

and pasted it into my rich text box to see what would happen.

I thought it would get removed since only the below should be allowed.

<span class="youtube-embed">AyPzM5WK8ys</span>

However, the raw YouTube embedding code is not being filtered out! Here is my filter:

function purifyInput($value) {
    require_once &#039;htmlpurifier/HTMLPurifier.auto.php&#039;;
    $config = HTMLPurifier_Config::createDefault();
    $config->set(&#039;Core&#039;, &#039;Encoding&#039;, &#039;ISO-8859-1&#039;);
    $config->set(&#039;HTML&#039;, &#039;Doctype&#039;, &#039;HTML 4.01 Transitional&#039;);
    $config->set(&#039;Filter&#039;, &#039;YouTube&#039;, true);
    $purifier = new HTMLPurifier($config);
    $purified_value = $purifier->purify($value);

    if (!is_numeric($purified_value))
    {
	$purified_value = mysql_real_escape_string($purified_value);
    }

    return $purified_value;
}

Am I just not understanding this correctly?

Thanks! Mark

Re: Error in YouTube embedding documentation
March 11, 2009 01:21AM

The point of the filter is that users can copypaste YouTube code and it will automatically get converted into the span. So that's expected behavior.

Sorry, you do not have permission to post/reply in this forum.