Advertisement:

Author Topic: [TIP] Kill shouting in posts...  (Read 24395 times)

Offline RyanJones

  • Jr. Member
  • **
  • Posts: 103
  • Gender: Male
  • Remember kids: High energy EM radiation is fun!
    • Support Web Standards!
[TIP] Kill shouting in posts...
« 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"&#39;, empty($modSettings[&#39;enableSpellChecking&#39;]) ? &#39;&#39; : &#39; checked="checked"&#39;, &#39; class="check" />
	
	
	
	
</
td>
	
	
	
</
tr>



Replace With:

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


Close & Save File



Open: /Sources/ManagePosts.php

Find:

	
	
// Update the actual settings.
	
	
updateSettings(array(


After, Add:


	
	
	
&
#39;disableShouting&#39; => empty($_POST[&#39;disableShouting&#39;]) ? &#39;0&#39; : &#39;1&#39;,


Close & Save File



Open: /Sources/Subs-Post.php

Find:

	
$posterOptions[&#39;ip&#39;] = empty($posterOptions[&#39;ip&#39;]) ? $user_info[&#39;ip&#39;] : $posterOptions[&#39;ip&#39;];


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[&#39;disableShouting&#39;])
  
{
    
$Temp   preg_replace(&#39;~[^a-z]~i&#39;, &#39;&#39;, $msgOptions[&#39;subject&#39;]);
    
$Margin strlen($Temp) / 3;
    
$Count  0;
    for (
$i 0$i strlen($Temp); $i++)
    {
      if (
strtoupper($Temp{$i}) == $Temp{$i})
        ++
$Count;
    }
    
$msgOptions[&#39;subject&#39;] = ($Count < $Margin) ? $msgOptions[&#39;subject&#39;] : ucfirst(strtolower($msgOptions[&#39;subject&#39;]));
  
}
  if (
$modSettings[&#39;disableShouting&#39;])
  
{
    
$Temp   preg_replace(&#39;~[^a-z]~i&#39;, &#39;&#39;, $msgOptions[&#39;body&#39;]);
    
$Margin strlen($Temp) / 3;
    
$Count  0;
    for (
$i 0$i strlen($Temp); $i++)
    {
      if (
strtoupper($Temp{$i}) == $Temp{$i})
        ++
$Count;
    }
    
$msgOptions[&#39;body&#39;] = ($Count < $Margin) ? $msgOptions[&#39;body&#39;] : ucfirst(strtolower($msgOptions[&#39;body&#39;]));
  
}


Find:

	
$topicOptions[&#39;lock_mode&#39;] = isset($topicOptions[&#39;lock_mode&#39;]) ? $topicOptions[&#39;lock_mode&#39;] : null;
	
$topicOptions[&#39;sticky_mode&#39;] = isset($topicOptions[&#39;sticky_mode&#39;]) ? $topicOptions[&#39;sticky_mode&#39;] : 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[&#39;disableShouting&#39;])
  
{
    
$Temp   preg_replace(&#39;~[^a-z]~i&#39;, &#39;&#39;, $msgOptions[&#39;subject&#39;]);
    
$Margin strlen($Temp) / 3;
    
$Count  0;
    for (
$i 0$i strlen($Temp); $i++)
    {
      if (
strtoupper($Temp{$i}) == $Temp{$i})
        ++
$Count;
    }
    
$msgOptions[&#39;subject&#39;] = ($Count < $Margin) ? $msgOptions[&#39;subject&#39;] : ucfirst(strtolower($msgOptions[&#39;subject&#39;]));
  
}
  if (
$modSettings[&#39;disableShouting&#39;])
  
{
    
$Temp   preg_replace(&#39;~[^a-z]~i&#39;, &#39;&#39;, $msgOptions[&#39;body&#39;]);
    
$Margin strlen($Temp) / 3;
    
$Count  0;
    for (
$i 0$i strlen($Temp); $i++)
    {
      if (
strtoupper($Temp{$i}) == $Temp{$i})
        ++
$Count;
    }
    
$msgOptions[&#39;body&#39;] = ($Count < $Margin) ? $msgOptions[&#39;body&#39;] : ucfirst(strtolower($msgOptions[&#39;body&#39;]));
  
}


Close & Save File


Enjoy!

Ryan Jones
« Last Edit: March 01, 2006, 03:05:20 AM by RyanJones »
RyanJ (Ryan Jones)

Support Web Standards!

Currently working On: Additions to the Karma system.

Offline snork13

  • SMF Friend
  • Sophist Member
  • *
  • Posts: 1,305
  • Gender: Male
  • so little time
    • simplemachines.org
Re: [TIP] Kill shouting in posts...
« Reply #1 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 :)
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

Offline Elmacik

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,276
  • Gender: Male
  • = Human Draft =
    • IT Store
Re: [TIP] Kill shouting in posts...
« Reply #2 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>:
Home of Elmacik

Offline JayBachatero

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,562
  • Gender: Male
    • @jaycreations on Twitter
    • JayBachatero.com
Re: [TIP] Kill shouting in posts...
« Reply #3 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?
Follow me on Twitter

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

Offline RyanJones

  • Jr. Member
  • **
  • Posts: 103
  • Gender: Male
  • Remember kids: High energy EM radiation is fun!
    • Support Web Standards!
Re: [TIP] Kill shouting in posts...
« Reply #4 on: March 01, 2006, 03:04:27 AM »
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.

Offline tim antley

  • Semi-Newbie
  • *
  • Posts: 19
  • Unamused
    • BayouMX.com
Re: [TIP] Kill shouting in posts...
« Reply #5 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.
BayouMX.com [nofollow]

Offline Rudolf

  • SMF Hero
  • ******
  • Posts: 1,934
  • Gender: Male
  • iamanoompaloompa
Re: [TIP] Kill shouting in posts...
« Reply #6 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
Quote
Hello 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
Code: [Select]
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
Code: [Select]
  if ($modSettings['disableShouting'])
  {
//do one thing
  }
  if ($modSettings['disableShouting'])
  {
//do another thing
  }
You can write it like
Code: [Select]
  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)

Offline Zenigata

  • Jr. Member
  • **
  • Posts: 237
  • Gender: Male
    • Il sito di Zenigata
Re: [TIP] Kill shouting in posts...
« Reply #7 on: February 21, 2007, 09:32:22 PM »
Great! Why don't you make an official mod?

Offline trenchteam

  • Sr. Member
  • ****
  • Posts: 901
  • Gender: Male
    • NO WALLS STANDING
Re: [TIP] Kill shouting in posts...
« Reply #8 on: July 17, 2007, 04:47:29 AM »
Can we get a package for this? This would be extremely useful for my forums.

Offline Rudolf

  • SMF Hero
  • ******
  • Posts: 1,934
  • Gender: Male
  • iamanoompaloompa
Re: [TIP] Kill shouting in posts...
« Reply #9 on: July 17, 2007, 11:37:32 AM »
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)

Offline Miyagi

  • Semi-Newbie
  • *
  • Posts: 49
  • Gender: Male
Re: [TIP] Kill shouting in posts...
« Reply #10 on: October 20, 2007, 07:19:30 AM »
A very nice mod Rudolf. :)

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

Offline metallica48423

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,842
  • Gender: Male
  • Professional Multislacker!
    • Zentendo
Re: [TIP] Kill shouting in posts...
« Reply #11 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


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

Quote
Microsoft 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