News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

[TIP] Kill shouting in posts...

Started by RyanJones, February 28, 2006, 07:33:13 PM

Previous topic - Next topic

RyanJones

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
RyanJ (Ryan Jones)

Support Web Standards!

Currently working On: Additions to the Karma system.

snork13

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 :)
Mods
Please DO NOT PM me with requests for individual support, but post your questions and concerns in the appropriate section of the forum where other users can benefit from them as well. Thank you.
I have been super busy as of late. Working on updates to all my modifications for 2.0.1

Elmacik

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>:
Home of Elmacik

JayBachatero

If you want to package it up into a mod take a look at.  Package SDK, anyone?
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

RyanJones

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
RyanJ (Ryan Jones)

Support Web Standards!

Currently working On: Additions to the Karma system.

tim antley

Thanks for this wonderful (and most-needed) mod.

I can't believe this hasn't been implemented in the releases.
BayouMX.com [nofollow]

Rudolf

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).
I will update all my mods in the next few weeks. Thanks for your patience.

SVG-Collapse (you need an SVG compliant browser)

Zenigata

Great! Why don't you make an official mod?

trenchteam

Can we get a package for this? This would be extremely useful for my forums.

Rudolf

Disable shouting
Alternative download link

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.
I will update all my mods in the next few weeks. Thanks for your patience.

SVG-Collapse (you need an SVG compliant browser)

Miyagi

FordXR5Turbo.com - Dedicated to the Ford Focus & Mondeo XR5 Turbo in Australia
FordXR4.com - Dedicated to the Ford Fiesta XR4 in Australia

metallica48423

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


Justin O'Leary
Ex-Project Manager
Ex-Lead Support Specialist

QuoteMicrosoft wants us to "Imagine life without walls"...
I say, "If there are no walls, who needs Windows?"


Useful Links:
Online Manual!
How to Help us Help you
Search
Settings Repair Tool

Advertisement: