MyBB Community Forums
Disable nl2br for a MyCode - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: 1.8 Support (https://community.mybb.com/forum-175.html)
+--- Forum: General Support (https://community.mybb.com/forum-176.html)
+--- Thread: Disable nl2br for a MyCode (/thread-230056.html)



Disable nl2br for a MyCode - volkling - 2020-11-05

Hello,

I'm running a roleplay forum and the nl2br feature in parsing creates problems when the users want to use HTML templates for their threads.
The coders are from the Jcink platform, where a MyCode "dohtml" exists; when this "dohtml" code is used, new lines are NOT converted to <br>. Jcink isn't open source, so I don't know how they managed to do this but I know that in MyBB, class_parser.php is the file regulating this behavior.

Similarly, I want to use a MyCode and when the user adds this around their code, no new lines will be converted to br. Simply put, I want to reverse the nl2br procedure only for this MyCode.

I thought about replacing all br codes inside a MyCode but that would also remove necessary "br" line breaks put there by the user.

Is there any workaround for this?

At the top of the class_parser file, there's a list of options but I couldn't find any of them on Admin CP:

options = array(
	allow_html
	allow_smilies
	allow_mycode
	nl2br
	filter_badwords
	me_username
	shorten_urls
	highlight
	filter_cdata

This is the nl2br part in the class_parser file:

if(!isset($this->options['nl2br']) || $this->options['nl2br'] != 0)
		{
			$message = nl2br($message);
			// Fix up new lines and block level elements
			$message = preg_replace("#(</?(?:html|head|body|div|p|form|table|thead|tbody|tfoot|tr|td|th|ul|ol|li|div|p|blockquote|cite|hr)[^>]*>)\s*<br />#i", "$1", $message);
			$message = preg_replace("#(&nbsp;)+(</?(?:html|head|body|div|p|form|table|thead|tbody|tfoot|tr|td|th|ul|ol|li|div|p|blockquote|cite|hr)[^>]*>)#i", "$2", $message);
		}

Could we do something like, if $message contains "dohtml" then nl2br isn't applied?

Thanks!


RE: Disable nl2br for a MyCode - Laird - 2020-11-05

I've created a little plugin for you that hopefully achieves your aim. It ensures that any text enclosed in [nobr][/nobr] tags does not have newlines replaced with <br>s. Please see the attached file - simply add to your inc/plugins directory and then activate as usual.


RE: Disable nl2br for a MyCode - volkling - 2020-11-05

Wow, thank you so much!

I've just installed it and tested it. Works perfectly!!!

I know that a lot of forums might need this functionality as it's such a pain to try to use the HTML templates we get from "roleplay help" forums. They're made for Jcink and they don't work well on MyBB due to its security-related limitations.

With this plugin, it works like magic Smile

You could easily market this plugin as an alternative to "dohtml" on Jcink.
Of course, people also need to edit the "style/script" blocking code line from the class_parser file.

Thanks again!


RE: Disable nl2br for a MyCode - Laird - 2020-11-05

You're welcome! I've just updated it though 'cos there was a little bug in it: it wasn't stripping the [nobr] opening and [/nobr] closing tags from the final output. Please download the new version - simply as the (updated) attachment of my previous post.