Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: RyanJones on February 28, 2006, 07:33:13 PM

Title: [TIP] Kill shouting in posts...
Post by: RyanJones on February 28, 2006, 07:33:13 PM
Hi all!

I hate those people who are to lazy to turn caps mode off so this mod will do it wether they do or not (Admin enable / disable) :)




Open: /Themes/theme_name_here/languages/Admin.english.php

Find: ?>

Before, Add:


$txt['disable_shouting_title'] = 'Disable shouting in posts';
$txt['disable_shouting_warning'] = 'This will remove all caps posts and titles';


Close & Save File




Open: /Themes/theme_name_here/Admin.template.php

Find:

<td valign="top">
<input type="checkbox" name="enableSpellChecking" id="enableSpellChecking_check"', empty($modSettings['enableSpellChecking']) ? '' : ' checked="checked"', ' class="check" />
</td>
</tr>


Replace With:

<td valign="top">
<input type="checkbox" name="enableSpellChecking" id="enableSpellChecking_check"', empty($modSettings['enableSpellChecking']) ? '' : ' checked="checked"', ' class="check" />
</td>
</tr><tr class="windowbg2">
<th width="50%" align="right">
<label for="disableShouting_check"></label>', $txt['disable_shouting_title'], ' :
<div class="smalltext" style="font-weight: normal;">', $txt['disable_shouting_warning'], '</div>
</th>
<td valign="top">
<input type="checkbox" name="disableShouting" id="disableShouting"', empty($modSettings['disableShouting']) ? '' : ' checked="checked"', ' class="check" />
</td>
</tr>

Close & Save File




Open: /Sources/ManagePosts.php

Find:

// Update the actual settings.
updateSettings(array(

After, Add:


'disableShouting' => empty($_POST['disableShouting']) ? '0' : '1',


Close & Save File




Open: /Sources/Subs-Post.php

Find:

$posterOptions['ip'] = empty($posterOptions['ip']) ? $user_info['ip'] : $posterOptions['ip'];

After, Add:

  /*
*************************************************************
    Block shouting in posts if enabled.
*************************************************************
    How do we decide?
    After close thinking using strtoupper checking will not work.
    They need only use one lower to beat it.
    Best way - loop through each char and count it as upper or lower.
    If over 3/4 are upper - lower it.
  */
  if ($modSettings['disableShouting'])
  {
    $Temp   = preg_replace('~[^a-z]~i', '', $msgOptions['subject']);
    $Margin = strlen($Temp) / 3;
    $Count  = 0;
    for ($i = 0; $i < strlen($Temp); $i++)
    {
      if (strtoupper($Temp{$i}) == $Temp{$i})
        ++$Count;
    }
    $msgOptions['subject'] = ($Count < $Margin) ? $msgOptions['subject'] : ucfirst(strtolower($msgOptions['subject']));
  }
  if ($modSettings['disableShouting'])
  {
    $Temp   = preg_replace('~[^a-z]~i', '', $msgOptions['body']);
    $Margin = strlen($Temp) / 3;
    $Count  = 0;
    for ($i = 0; $i < strlen($Temp); $i++)
    {
      if (strtoupper($Temp{$i}) == $Temp{$i})
        ++$Count;
    }
    $msgOptions['body'] = ($Count < $Margin) ? $msgOptions['body'] : ucfirst(strtolower($msgOptions['body']));
  }

Find:

$topicOptions['lock_mode'] = isset($topicOptions['lock_mode']) ? $topicOptions['lock_mode'] : null;
$topicOptions['sticky_mode'] = isset($topicOptions['sticky_mode']) ? $topicOptions['sticky_mode'] : null;

After, Add:

  /*
*************************************************************
    Block shouting in posts if enabled.
*************************************************************
    How do we decide?
    After close thinking using strtoupper checking will not work.
    They need only use one lower to beat it.
    Best way - loop through each char and count it as upper or lower.
    If over 3/4 are upper - lower it.
  */
  if ($modSettings['disableShouting'])
  {
    $Temp   = preg_replace('~[^a-z]~i', '', $msgOptions['subject']);
    $Margin = strlen($Temp) / 3;
    $Count  = 0;
    for ($i = 0; $i < strlen($Temp); $i++)
    {
      if (strtoupper($Temp{$i}) == $Temp{$i})
        ++$Count;
    }
    $msgOptions['subject'] = ($Count < $Margin) ? $msgOptions['subject'] : ucfirst(strtolower($msgOptions['subject']));
  }
  if ($modSettings['disableShouting'])
  {
    $Temp   = preg_replace('~[^a-z]~i', '', $msgOptions['body']);
    $Margin = strlen($Temp) / 3;
    $Count  = 0;
    for ($i = 0; $i < strlen($Temp); $i++)
    {
      if (strtoupper($Temp{$i}) == $Temp{$i})
        ++$Count;
    }
    $msgOptions['body'] = ($Count < $Margin) ? $msgOptions['body'] : ucfirst(strtolower($msgOptions['body']));
  }

Close & Save File


Enjoy!

Ryan Jones
Title: Re: [TIP] Kill shouting in posts...
Post by: snork13 on February 28, 2006, 11:30:03 PM
works, i had updated this mod from yabbse, but never published, glad to see it around...no one shouts on my forum, but on other i host it's a welcome feature :)
Title: Re: [TIP] Kill shouting in posts...
Post by: Elmacik on February 28, 2006, 11:34:39 PM
RyanJones, just to let you know, you have a span tag closed which is not open:

<label for="disableShouting_check"></label>', $txt['disable_shouting_title'], ' </span>:
Title: Re: [TIP] Kill shouting in posts...
Post by: JayBachatero on March 01, 2006, 12:04:26 AM
If you want to package it up into a mod take a look at.  Package SDK, anyone? (http://www.simplemachines.org/community/index.php?topic=20319.0)
Title: Re: [TIP] Kill shouting in posts...
Post by: RyanJones on March 01, 2006, 03:04:27 AM
Quote from: Elmacik on February 28, 2006, 11:34:39 PM
RyanJones, just to let you know, you have a span tag closed which is not open:

<label for="disableShouting_check"></label>', $txt['disable_shouting_title'], ' </span>:

OOps, sorry - fixed.

Cheers,

Ryan Jones
Title: Re: [TIP] Kill shouting in posts...
Post by: tim antley on November 29, 2006, 02:27:05 AM
Thanks for this wonderful (and most-needed) mod.

I can't believe this hasn't been implemented in the releases.
Title: Re: [TIP] Kill shouting in posts...
Post by: Rudolf on November 29, 2006, 03:39:05 AM
Don't want to be the bad guy, but this is not quite the best approach.

Suppose you have a post like
Quote
Hello world! How ARE YOU DOING TONIGHT? I'm fine.
which will result as
Quote
Hello world! how are you doing tonight? i'm fine.

And this is wrong.
It should be
QuoteHello world! How are you doing tonight? I'm fine.

Ok, put the preg_replace (and Co.) to better use then just to replace some characters. Use preg_match_all to match all the sequences that are in uppercase and have some minimum length, then iterate through them and check if it's at the start of the sentence (there's a punctuation character before) and use the ucfirst on them, else just make it lowercase.

This is the basic idea, I bet it can be done in less lines of code.
You can use this function to get all the uppercase substrings with their offset

preg_match_all('([A-Z ]{5,})',$string, $matches, PREG_OFFSET_CAPTURE);

From this you just iterate through the $matches array and use ucfirst or strtolower depending on where it appears. This will really take care of accidental caps lock clICK BY THE USER.

Just one small note.
The code

  if ($modSettings['disableShouting'])
  {
//do one thing
  }
  if ($modSettings['disableShouting'])
  {
//do another thing
  }

You can write it like

  if ($modSettings['disableShouting'])
  {
//do one thing
//do another thing
  }

It doesn't really help readability separating them, and removes the need to evaluate twice (less work).
Title: Re: [TIP] Kill shouting in posts...
Post by: Zenigata on February 21, 2007, 09:32:22 PM
Great! Why don't you make an official mod?
Title: Re: [TIP] Kill shouting in posts...
Post by: trenchteam on July 17, 2007, 04:47:29 AM
Can we get a package for this? This would be extremely useful for my forums.
Title: Re: [TIP] Kill shouting in posts...
Post by: Rudolf on July 17, 2007, 11:37:32 AM
Disable shouting (http://custom.simplemachines.org/mods/index.php?mod=869)
Alternative download link (http://digilander.libero.it/rudoka/smfmods/disableshouting/Disable_shouting-1.0.zip)

This mod is not based on the current tip, but on my own idea. Naturally, I think it does a slightly better job. The content of the post is affected only when displaying. The original content is left alone, therefore you can effectively enable/disable this feature.
To be able to write text in upper case letter you can use a custom BBC code which will allow this. You can use the Custom BBC mod to create the code easily.
Title: Re: [TIP] Kill shouting in posts...
Post by: Miyagi on October 20, 2007, 07:19:30 AM
A very nice mod Rudolf. :)

Thx,
Miyagi
Title: Re: [TIP] Kill shouting in posts...
Post by: metallica48423 on November 14, 2007, 10:31:54 PM
For anyone who views this topic -- this mod was inspired by this tip:
http://custom.simplemachines.org/mods/index.php?mod=869

If you require assistance with this or with the mod, please post in this topic:
http://www.simplemachines.org/community/index.php?topic=183334.0

This one is locked for redundancy