»
S
I
D
E
B
A
R
«
Add an attribute to HTML Purifier filter?
November 10th, 2009 by wood

I'm trying to allow rel attribute in a elements within HTML Purifier filter. I'm following this guide http://htmlpurifier.org/docs/enduser-customize.html and here is my code:

                $config = HTMLPurifier_Config::createDefault();
                $config->set('HTML.Doctype', 'XHTML 1.0 Strict');
                $config->set('HTML.DefinitionID', 'enduser-customize.html tutorial');
                $config->set('HTML.DefinitionRev', 1);
                $config->set('Cache.DefinitionImpl', null); // remove this later!
                $def = $config->getHTMLDefinition(true);
                $def->addAttribute('a', 'href*', 'URI');
                $def->addAttribute('a', 'rel', 'CDATA');
                $purifier = new HTMLPurifier($config);

However, the HTML purifier is still filtering out all rel attributes... I'm a little confused what the problem could be.

When I use:

$config->set('Attr', 'AllowedRel', array('something'));

I get this error:

Notice: Using deprecated API: use $config->set('Attr.AllowedRel', ...) instead on line 191 in file C:\wamp\www\neonet\application\modules\admin\controllers\IndexController.php in C:\wamp\www\neonet\library\My\htmlpurifier-4.0.0-standalone\HTMLPurifier.standalone.php on line 1819

EDIT:

New code:

                $config = HTMLPurifier_Config::createDefault();
                $config->set('HTML.Doctype', 'XHTML 1.0 Strict');
                $config->set('Attr.AllowedRel', array('something'));
                $purifier = new HTMLPurifier($config);

When I use:

<href="/" rel="something">anchor</a>

Rel attribute still gets filtered.


Leave a Reply

»  Substance: PHP Frameworks   »  SiteMap