MyBB Community Forums

Full Version: Profanity feature you can toggle.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Due to the userbase of my forum, I would be greatly appreciative if someone could perhaps develop a feature where a user can toggle a profanity feature. For example, the default setting would be on so all cursing would be filtered, but the user can go into their settings turn it off at will. Unless I'm missing the obvious, there is no way of doing this with MyBB (though I have hardly checked tbh).

My userbase consists of many grown adults but many younger adolescents, due to it being based on a genre watched by all age ranges. Thanks in advance, I could see this being quite a popular feature.
So basically something to toggle the word filter on/off based on user preferences? I think such a thing would be fairly easy as the word filter operates as part of the parser so you could simply disable it for users with "show profanity" enabled.
(2013-01-01, 12:51 AM)euantor Wrote: [ -> ]So basically something to toggle the word filter on/off based on user preferences? I think such a thing would be fairly easy as the word filter operates as part of the parser so you could simply disable it for users with "show profanity" enabled.

Yeah, you always manage to explain things much better than me using less words. I didn't think it would be complicated, I'm quite surprised no one has requested this before.

Edit: The only issue I thought people might bring up about using the built in word filter system is that a lot of people don't just use the word filter for cursing. Some use it for rival sites or many other things, things that you don't ever want to be displayed so giving them the option to disable that is worrying. How would the profanity feature differentiate between cursing and other factors that need to be permanently filtered?
Just checked the source of the parser. It looks like the filter_badwords option is usually hard-coded as 1 (true). Would probably need a core edit to add a new hook into the parser's parse_message function allowing the options to be modified before they are set.

So this:

	/**
	 * Parses a message with the specified options.
	 *
	 * @param string The message to be parsed.
	 * @param array Array of yes/no options - allow_html,filter_badwords,allow_mycode,allow_smilies,nl2br,me_username.
	 * @return string The parsed message.
	 */
	function parse_message($message, $options=array())
	{
		global $plugins, $mybb;

		// Set base URL for parsing smilies
		$this->base_url = $mybb->settings['bburl'];

		if($this->base_url != "")
		{
			if(my_substr($this->base_url, my_strlen($this->base_url) -1) != "/")
			{
				$this->base_url = $this->base_url."/";
			}
		}
		
		// Set the options		
		$this->options = $options;

Becomes this:

    /**
     * Parses a message with the specified options.
     *
     * @param string The message to be parsed.
     * @param array Array of yes/no options - allow_html,filter_badwords,allow_mycode,allow_smilies,nl2br,me_username.
     * @return string The parsed message.
     */
    function parse_message($message, $options=array())
    {
        global $plugins, $mybb;

        // Set base URL for parsing smilies
        $this->base_url = $mybb->settings['bburl'];

        if($this->base_url != "")
        {
            if(my_substr($this->base_url, my_strlen($this->base_url) -1) != "/")
            {
                $this->base_url = $this->base_url."/";
            }
        }

        $options = $plugins->run_hooks("parse_message_start_pre_options", $options);
        
        // Set the options      
        $this->options = $options;

Then the plugin would just do:

$plugins->add_hook('parse_message_start_pre_options', 'advbadwords_modify_opts');
function advbadwords_modify_opts(&$options)
{
    global $mybb;

    if ($mybb->user['advbadwords_disable_filter']) {
        $options['filter_badwords'] = 0;
    }

    return $options;
}
How would you deal with the issue I have posted above though?
I have had this built for a while now

http://www.communityplugins.com/forum/my...down&did=6
Well, there you go. Pavemen beat me to it.

Regarding filtering only certain phrases, you'd need to extend the current system in order to differentiate between true swear words and other phrases.