[Tutorial] Banning CAPSLOCK / shouting in posts
#1
Pencil 
This modification will stop your users from "shouting" in posts. (Posting with caps-lock on for everything)

Open newthread.php.

Find (somewhere around line 265):

	// Set up posthandler.
	require_once MYBB_ROOT."inc/datahandlers/post.php";
	$posthandler = new PostDataHandler("insert");
	$posthandler->action = "thread";

Add below:

	// Caps lock / shouting? Nonono!
	if(strtoupper($mybb->input['message']) == $mybb->input['message']) {
			$mybb->input['message'] = $message = ucfirst(strtolower($mybb->input['message']));
	} 


Open newreply.php

Find (somewhere around line 333):

	// Set up posthandler.
	require_once MYBB_ROOT."inc/datahandlers/post.php";
	$posthandler = new PostDataHandler("insert");

Add below:

	// Caps lock / shouting? Nonono!
	if(strtoupper($mybb->input['message']) == $mybb->input['message']) {
		$mybb->input['message'] = $message = ucfirst(strtolower($mybb->input['message']));
	} 



OLD WAY (not recommended):

Open inc/class_parser.php.

Find:
		// Get rid of cartridge returns for they are the workings of the devil
		$message = str_replace("\r", "", $message);

Add below:
		// Caps lock / shouting? Nonono!
		if(strtoupper($message) == $message) {
			$message = strtolower($message);
			$message = ucfirst($message);
		}



Example:
"OH MY GOD YOU ARE STUPID"
will become:
"Oh my god you are stupid"


-Brandon
Reply
#2
Great tutorial! Thank you very much for this!
Reply
#3
If I post something like this :

You need to DO SOMETHING like this...

Will it change my post to :

You need to do something like this...

Anyway, thanks for your submitted tutorial.
Reply
#4
Unfortunately no, it'll only alter it if it is like this:

(2013-03-26, 08:02 AM)LCTG Wrote: YOU NEED TO DO SOMETHING LIKE THIS...

I have a piece of code on my localhost somewhere that parses it if over half of the message is uppercase, I'll see if I can dig it up. Smile
Please don't PM me for support. Smile
Reply
#5
This user has been denied support. This user has been denied support.
Thank you for this!
Reply
#6
@Seabody, thanks! That's what I'm wavering few hours ago Smile
Reply
#7
Turns out I'd deleted it, but it was easy enough to figure out the code again. Ignore the comments, it's part of a project I'm working on. Smile

// Do a tad of fancy examination
			if((strlen($message) / 2) < strlen(preg_replace('![^A-Z]+!', '', $message)))
			{
				// Half the message is uppercase.
				// User is (probably) trying to SHOUT.
				$message = ucfirst(strtolower($message));
			}

Notes:
- This is slightly more reliable than the OP, as with that, a single punctuation mark can cause it not to parse.
- Sentences will lack grammar correction: I's will not be capitalized, and new sentences aren't capitalized. It's probably possible to do both, but this is a very basic example.
Please don't PM me for support. Smile
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)