How can I use HTMLPurifier to filter xss but also to allow iframe Vimeo and Youtube video?
require_once 'htmlpurifier/library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.Trusted', true);
$config->set('Filter.YouTube', true);
$config->set('HTML.DefinitionID', '1');
$config->set('HTML.SafeObject', 'true');
$config->set('Output.FlashCompat', 'true');
$config->set('HTML.FlashAllowFullScreen', 'true');
$purifier = new HTMLPurifier($config);
$temp = $purifier->purify($temp);
Using drupal 7.19 and the htmlpurifier module you can configure the following setting without needing to write this code.
See http://drupal.org/node/711728#comment-5600344
Also do not forget to set
if you've set it to
true
before.I just read this blog entry, and successfully created and used the custom filter. I made some changes to the code and added Vimeo support:
Adding the filter to your HTML Purifier config
For anyone who is struggling (how to enable iframe and allowfullscreen)
Get rid of the %HTML.Trusted, %Filter.YouTube and %HTML.DefinitionID. They're probably interacting poorly with SafeObject/FlashCompat.
This much should do the trick