MyBB Community Forums

Full Version: A way not to parse Font and/or Color BBCodes?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all,

You all know how users can sometimes be really messy and make unnecessary use of formatting BBCodes like changing the font, font size and colors when it's really not necessary. If every users behave this way, a 20-post thread page looks really ugly to me so I'd like to:

  1. prevent users from using those three codes
    OR
  2. prevent those three codes from being parsed

I guess the second solution requires a lot more modifications... Plus I'd like to strip those codes from current posts aswell and not only from future posts.

So maybe the first solution can be implemented more easily with less code modification?

Also, it would be nice if you could give the choice of enabling/disabling one, two, or the three codes at the same time because I'm not really sure which codes I really need to remove so I can achieve a decent level of aesthetics for the forum! ^^

Thanks for reading me, I hope someone can help me!
You can remove parsed codes by editing the inc/class_parser.php file.

For colour, delete the following lines from the above file:
		$standard_mycode['color']['regex'] = "#\[color=([a-zA-Z]*|\#?[0-9a-fA-F]{6})](.*?)\[/color\]#si";
		$standard_mycode['color']['replacement'] = "<span style=\"color: $1;\">$2</span>";
For font:
		$standard_mycode['font']['regex'] = "#\[font=([a-z ]+?)\](.+?)\[/font\]#si";
		$standard_mycode['font']['replacement'] = "<span style=\"font-family: $1;\">$2</span>";
All the other standard bbCodes are around that area in the file, so it's a matter of deleting the lines that you don't want (remember to delete both the "regex" and "replacement" lines).

Hope that helps.
Yes, that helps a lot, thank you! But I guess I shouldn't delete those lines but actually edit them to:

        $standard_mycode['color']['regex'] = "#\[color=([a-zA-Z]*|\#?[0-9a-fA-F]{6})](.*?)\[/color\]#si";
        $standard_mycode['color']['replacement'] = "$2"; 

So the content is still displayed, without the BBCodes, but with the default color (in this case), right?

Now, I also have people who bold their whole messages, is there a way to prevent those whole messages to be displayed in bold while not deactivating the [b] code? This one's still pretty useful! Smile

Anyway thanks for the answer! And if anyone would like to develop a plugin that would selectively parse BB Codes, I'd be interested and willing to provide a few examples and ideas of what could be useful.
Here's a plugin which will stop the whole post becoming bold (note, the [b] tags must surround the entire post for this to work)
Whoh! Thanks a lot!

I've tested it and it works, but it doesn't work for some posts because the user has applied several BB codes to the entire message like color+font+bold and hasn't applied the bold last so it doesn't actually starts and ends with the and code. But don't bother trying to solve my problem here unless you have a quick solution in mind because I think this matter is getting a bit complicated here!

I may just have to deal with the idea that not everybody cares about using BB codes with sobriety Smile
I can modify the plugin so that it will remove [color] and [font] tags if they surround the whole post, but an easy way to defeat it is sticking something before or after the codes as you may have noticed.

As you probably know, automated post fixing can only go so far - if it's a real issue, I'd suggest having some posting rules/guidelines in place, and ask your moderators to help fix up posts.
Yep, that's what I thought... :/ You can leave it like that, you've already been really helpful, thanks again!