completed Adding attributes to htmlpurifier in a listener

SteveX
SteveX
@ultrajam
11 years ago
2,584 posts
I have a listener to add elements and attributes to the htmlpurifier config.

I can get the attributes like this:
$_attr = $_data->get('HTML.AllowedAttributes');

But I can't then set them.
Quote: [13-Dec-2014 13:54:45 Europe/Dublin] PHP Fatal error: Cannot set directive after finalization invoked on line 158 in file /Applications/AMPPS/www/demo7.ultrabubble.com/modules/ujWorkbook/include.php in /Applications/AMPPS/www/demo7.ultrabubble.com/modules/jrCore-release-5.2.16/contrib/htmlpurifier/HTMLPurifier.standalone.php on line 2607

Adding the attribute also doesn't work (seems like this is how it is done in config in the htmlpurifier docs.
Quote: [13-Dec-2014 13:58:56 Europe/Dublin] PHP Fatal error: Call to undefined method HTMLPurifier_Config::addAttribute() in /Applications/AMPPS/www/demo7.ultrabubble.com/modules/ujWorkbook/include.php on line 165

It looks like the Jamroom iframe listener turns on a filter rather than adding to the allowed attributes and elements, and I can't get much info from the htmlpurifier docs. Any suggestions would be very much appreciated.


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)

updated by @ultrajam: 01/30/15 06:56:11AM
brian
@brian
11 years ago
10,149 posts
I will check this out Steve - sounds like we may need to tweak the position the event is being triggered in for this to work.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
brian
@brian
11 years ago
10,149 posts
Steve - I've got this fixed for the Jamroom Core 5.2.18 release - inside your listener you'll want to set BOTH the elements and attributes. For example, to add the "blockquote" element and allow the "class" attribute you would do:

$_elem = $_data->get('HTML.AllowedElements');
$_elem['blockquote'] = 1;
$_elem = implode(',', array_keys($_elem));
$_data->set('HTML.AllowedElements', $_elem);

$_attr = $_data->get('HTML.AllowedAttributes');
$_attr['blockquote.class'] = 1;
$_attr = implode(',', array_keys($_attr));
$_data->set('HTML.AllowedAttributes', $_attr);

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

updated by @brian: 12/18/14 06:02:11AM
SteveX
SteveX
@ultrajam
11 years ago
2,584 posts
That's great, thanks Brian.

I'll give this a try later on.


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
SteveX
SteveX
@ultrajam
11 years ago
2,584 posts
This works beautifully! Thank you! :)


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
brian
@brian
11 years ago
10,149 posts
SteveX:
This works beautifully! Thank you! :)

Right on - glad to hear that - thanks :)


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

Tags