Page 1 of 1

Censored words and BBCode

PostPosted:December 3rd, 2021, 11:35 pm
by pawlshepherd
Asking here before I try the absolute landfill that the phpBB community forums seem to be 😅

Does anybody know if it's possible to get the censored words list to parse BBCode?

I'm trying to implement a way to post custom icons in line with text. So far there is about 170 svg icons, which I intended to convert into two font files using free svg > font services. Each of those fonts would get a custom code tag, [twsfont1] and [twsfont2], which would be replaced by an HTML span.
The censored words list would then change something like what the user types, following this chain:
[aquila] -> [twsfont2]G[/twsfont2] -> <span style="font-family:twsfont2;">G</span>
This would then result in the 'aquila' icon being added to the text. This is the current list of icons, but there will likely be more added in the future.

As it stands the censored words don't parse BBCode, so the result is that something like [twsfont2]G[/twsfont2] gets posted instead.


There's probably an easier way of doing this (definitely easier than messing around with two font files! 😩) but it was the only way I could think of making it work.

Re: Censored words and BBCode

PostPosted:December 4th, 2021, 5:13 pm
by Dion
The short answer is no, there is no simple way to do what you want.

The long answer is that I think it's possible to write an extension that disables the s9e textformatter's word censor and replaces it with the original phpBB word censor. It's also possible to write an extension that replaces the ACP word censor module with one that allows HTML in the word replacements. If the two were combined, it would be possible for you to create HTML-based word replacements.

I have long considered it a flaw in phpBB to not allow HTML-based replacements in the word censor. (And also for rank titles.)

Re: Censored words and BBCode

PostPosted:December 4th, 2021, 6:31 pm
by pawlshepherd
Of course there isn't. Why would there be? 😂

Would it be easier for me to simply pay the (actually not outrageous) charges for something like Icomoon and just do it properly? I'm getting the feeling it would be!

Re: Censored words and BBCode

PostPosted:December 4th, 2021, 7:27 pm
by Dion
It would be much easier to hack phpBB to allow HTML in word censor replacement text in posts. In the vendor/s9e/text-formatter/src/Plugins/Censor/Helper.php file, find the following line:
Code: Select all
				return \htmlspecialchars($this->getReplacement(\html_entity_decode($m[0], \ENT_QUOTES, 'UTF-8')), \ENT_QUOTES);

Change it to this:
Code: Select all
				return \html_entity_decode($this->getReplacement(\html_entity_decode($m[0], \ENT_QUOTES, 'UTF-8')), \ENT_QUOTES);

Save the file. Next, in the includes/functions_content.php file, find the following line:
Code: Select all
		return preg_replace($censors['match'], $censors['replace'], $text);

Change it to this:
Code: Select all
		$replace = array_map(function($v) {return html_entity_decode($v, ENT_QUOTES, 'UTF-8');}, $censors['replace']);
		return preg_replace($censors['match'], $replace, $text);

Save the file and purge the cache. phpBB will now allow HTML replacement text for censored words.Note that you'll need to repeat this hack every time phpBB is updated.

Re: Censored words and BBCode

PostPosted:December 4th, 2021, 7:56 pm
by pawlshepherd
I'll have play when I get my laptop out later - cheers Dion! 🙂