Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Thema gestartet von: RyanJones in Februar 28, 2006, 07:33:13 NACHMITTAGS

Titel: [TIP] Kill shouting in posts...
Beitrag von: RyanJones in Februar 28, 2006, 07:33:13 NACHMITTAGS
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
Titel: Re: [TIP] Kill shouting in posts...
Beitrag von: snork13 in Februar 28, 2006, 11:30:03 NACHMITTAGS
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 :)
Titel: Re: [TIP] Kill shouting in posts...
Beitrag von: Elmacik in Februar 28, 2006, 11:34:39 NACHMITTAGS
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>:
Titel: Re: [TIP] Kill shouting in posts...
Beitrag von: JayBachatero in März 01, 2006, 12:04:26 VORMITTAG
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)
Titel: Re: [TIP] Kill shouting in posts...
Beitrag von: RyanJones in März 01, 2006, 03:04:27 VORMITTAG
Zitat von: Elmacik in Februar 28, 2006, 11:34:39 NACHMITTAGS
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
Titel: Re: [TIP] Kill shouting in posts...
Beitrag von: tim antley in November 29, 2006, 02:27:05 VORMITTAG
Thanks for this wonderful (and most-needed) mod.

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

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

And this is wrong.
It should be
ZitatHello 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).
Titel: Re: [TIP] Kill shouting in posts...
Beitrag von: Zenigata in Februar 21, 2007, 09:32:22 NACHMITTAGS
Great! Why don't you make an official mod?
Titel: Re: [TIP] Kill shouting in posts...
Beitrag von: trenchteam in Juli 17, 2007, 04:47:29 VORMITTAG
Can we get a package for this? This would be extremely useful for my forums.
Titel: Re: [TIP] Kill shouting in posts...
Beitrag von: Rudolf in Juli 17, 2007, 11:37:32 VORMITTAG
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.
Titel: Re: [TIP] Kill shouting in posts...
Beitrag von: Miyagi in Oktober 20, 2007, 07:19:30 VORMITTAG
A very nice mod Rudolf. :)

Thx,
Miyagi
Titel: Re: [TIP] Kill shouting in posts...
Beitrag von: metallica48423 in November 14, 2007, 10:31:54 NACHMITTAGS
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