So, i was playing with HTML Purifier a few minutes ago and noticed that the implementation made in Yii is very primitive, or at least from my point of view.
Say i want to allow the target="_blank" attribute in my text editors, with the current implementation this not possible as i don’t have access to the purifier classes.
$purifier=new CHtmlPurifier;
$purifier->options=array('options here to build the config from scratch');
$purifier->purify($text);
[This idea just hit me 2 seconds ago]
Not sure, hadn’t had the chance to test, but maybe
$purifier=new CHtmlPurifier; // this would make all html purifier classes available
$config=HTMLPurifier_Config::createDefault();//grab the default configuration.
$def=$config->getHTMLDefinition(true);
$def->addAttribute('a', 'target', 'Enum#_blank,_self,_target,_top');//append to it.
$purifier->options=$config;//and pass it further to the __construct of the main HtmlPurifier class.
$purifier->purify($text);
Hmm, i am sure the above "hack" will do it just fine.
Cannot set directive after finalization on line 1546 in file /home/xxx/public_html/framework/vendors/htmlpurifier/HTMLPurifier.standalone.php
I don’t get why it throws this error, the $options object reaches HtmlPurifier from inside of the purify() method of the CHtmlPurifier widget, so it should work just fine .