Advertisement:

Author Topic: Minimum number of words  (Read 14860 times)

Offline Gobo

  • Sr. Member
  • ****
  • Posts: 912
  • Gender: Male
  • Peace Be Upon You
    • Path To Peace
Minimum number of words
« on: February 27, 2006, 09:31:25 PM »
Hi I checked in the mods library and didnt find this mod so I was wondering if anyone could make it?

- Minimum number of words in a post : The ability to specify that a post if less than X number of characters will not be posted and instead the user will get an alert that their post must be above X characters

I ask cos my board is currently plagued by user making 1 word posts like "lol" "thanks" "funny" "good"

All I can do for now is make a rule and enforce it, in which case I have to manually remove all posts which is pretty time consuming

Thanks


Offline anunlike

  • Sr. Member
  • ****
  • Posts: 746
  • Gender: Male
Re: Minimum number of words
« Reply #1 on: February 28, 2006, 11:38:54 AM »
Sounds like a good idea to me.

Offline Aitsukai

  • Jr. Member
  • **
  • Posts: 114
Re: Minimum number of words
« Reply #2 on: February 28, 2006, 11:39:51 AM »
vB has this feature. I support this.

Offline loudyboy

  • Semi-Newbie
  • *
  • Posts: 25
Re: Minimum number of words
« Reply #3 on: February 28, 2006, 06:59:21 PM »
Yup, I'd like to see this too please :)

Offline URPG

  • Jr. Member
  • **
  • Posts: 360
Re: Minimum number of words
« Reply #4 on: February 28, 2006, 07:21:17 PM »
There is currently some trouble with the word-censoring function and as it is re-coded someone could easilie put this into it too...

I support this too!

Offline RyanJones

  • Jr. Member
  • **
  • Posts: 103
  • Gender: Male
  • Remember kids: High energy EM radiation is fun!
    • Support Web Standards!
Re: Minimum number of words
« Reply #5 on: February 28, 2006, 07:44:00 PM »
I'll do my best to make this mod tonight, if not I'll try to have it done tomrow :)

Cheers,

Ryan Jones
RyanJ (Ryan Jones)

Support Web Standards!

Currently working On: Additions to the Karma system.

Offline Skipdawg

  • Sr. Member
  • ****
  • Posts: 895
  • Gender: Male
  • SMF Über Fan!
    • Skipdawg Central
Re: Minimum number of words
« Reply #6 on: February 28, 2006, 07:53:03 PM »
Very kewl! Could come in handy down the road. I like it!  ;)
Skipdawg's Community

Powered by SMF 1.1.3

Offline RyanJones

  • Jr. Member
  • **
  • Posts: 103
  • Gender: Male
  • Remember kids: High energy EM radiation is fun!
    • Support Web Standards!
Re: Minimum number of words
« Reply #7 on: February 28, 2006, 09:16:41 PM »
OK, try this:

Open: /Themes/theme_name_here/language/Errors.english.php

Find: $txt['error_long_message'] = 'The message exceeds the maximum allowed length (' . $modSettings['max_messageLength'] . ' characters).';

After, Add: $txt['error_minWordLen'] = 'The message does not meet the minimum word requirements (' . $modSettings['minWordLen'] . ' words).';

Close & Save File



Open: /Sources/Post.php

Find:

	
// Check the subject and message.


After, add:

	
if (!empty(
$modSettings['minWordLen']) && ((int)$modSettings['minWordLen'] != 0))
	
{
    
$Temp trim(preg_replace('~[^a-z0-9 ]~si', '', $_POST['message']));
    
$Temp preg_replace('~(( )+)~si', ' ', $Temp);
    
$WordArr explode(' ', $Temp);
    
if (count($WordArr) < (int)$modSettings[&#39;minWordLen&#39;])
	
    
$post_errors[] = &#39;minWordLen&#39;;
  
}


Close & Save File



Open: /Sources/ManagePosts.php

Find:

	
	
// Update the actual settings.
	
	
updateSettings(array(


After, add:

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


Close & Save File



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

Find: $txt['caching_settings'] = 'Caching';

After, add:


$txt
[&#39;minWordLen&#39;] = &#39;Minimum Word Length&#39;;
$txt[&#39;minWordLen_zero&#39;] = &#39;0 for no minimum.&#39;;
$txt[&#39;minWordLen_words&#39;] = &#39;words&#39;;


Close & Save File



Open: /Sources/ManagePosts.php

Find:

	
	
// Update the actual settings.
	
	
updateSettings(array(


After, add:

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


Close & Save File



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

Find:


	
	
	
	
<
td valign="top">
	
	
	
	
	
<
input type="text" name="max_messageLength" id="max_messageLength_input" value="&#39;, empty($modSettings[&#39;max_messageLength&#39;]) ? &#39;0&#39; : $modSettings[&#39;max_messageLength&#39;], &#39;" size="5" /> &#39;, $txt[&#39;manageposts_characters&#39;], &#39;
	
	
	
	
</
td>
	
	
	
</
tr>


After, add:


<tr class="windowbg2">
	
	
	
	
<
th width="50%" align="right">
	
	
	
	
	
<
label for="minWordLen_input">&#39;, $txt[&#39;minWordLen&#39;], &#39; :
	
	
	
	
	
<
div class="smalltext" style="font-weight: normal;">&#39;, $txt[&#39;minWordLen_zero&#39;], &#39;</div>
	
	
	
	
</
th>
	
	
	
	
<
td valign="top">
	
	
	
	
	
<
input type="text" name="minWordLen" id="minWordLen_input" value="&#39;, empty($modSettings[&#39;minWordLen&#39;]) ? &#39;5&#39; : $modSettings[&#39;minWordLen&#39;], &#39;" size="5" /> &#39;, $txt[&#39;minWordLen_words&#39;], &#39;
	
	
	
	
</
td>
	
	
	
</
tr>


Close & Save File

Cheers,

Ryan Jones
RyanJ (Ryan Jones)

Support Web Standards!

Currently working On: Additions to the Karma system.

Offline Gobo

  • Sr. Member
  • ****
  • Posts: 912
  • Gender: Male
  • Peace Be Upon You
    • Path To Peace
Re: Minimum number of words
« Reply #8 on: February 28, 2006, 10:07:21 PM »
wow thanks :D

I will try it out this weekend when I have more time :D thanks a lot :D:D:D:D

Offline anunlike

  • Sr. Member
  • ****
  • Posts: 746
  • Gender: Male
Re: Minimum number of words
« Reply #9 on: February 28, 2006, 11:43:53 PM »
Thanks, RyanJones.

Would still be cool as a built in feature, IMO.

Offline RyanJones

  • Jr. Member
  • **
  • Posts: 103
  • Gender: Male
  • Remember kids: High energy EM radiation is fun!
    • Support Web Standards!
Re: Minimum number of words
« Reply #10 on: March 01, 2006, 03:01:20 AM »
Your welcome :)

Would have used the PHP str_word_count function but its crap forthis sort of thing :)

Cheers,

Ryan Jones
RyanJ (Ryan Jones)

Support Web Standards!

Currently working On: Additions to the Karma system.

Offline paki

  • Jr. Member
  • **
  • Posts: 184
  • Gender: Male
    • DFWHyundais.com
Re: Minimum number of words
« Reply #11 on: March 04, 2006, 12:49:14 PM »
its a good modification.. but i think i would've liked it more if it was based on characters rather than words. oh well.. thanks anyway!
http://www.dfwhyundais.com <-- Dallas/Ft. Worth's Local Hyundai Group

Offline Aitsukai

  • Jr. Member
  • **
  • Posts: 114
Re: Minimum number of words
« Reply #12 on: March 06, 2006, 03:47:46 PM »
Few things.

First, that didn't work when I put a ~ at the end of my post.

Second, when the post is too short, it simply says 'The following errors occured:' with nothing after it.

Thirdly, is there any way to implement a minimum number of characters, rather than words?

Finally, might I ask your permission to make it into a package and release it? :)

Offline RyanJones

  • Jr. Member
  • **
  • Posts: 103
  • Gender: Male
  • Remember kids: High energy EM radiation is fun!
    • Support Web Standards!
Re: Minimum number of words
« Reply #13 on: March 06, 2006, 04:11:51 PM »
Few things.

First, that didn't work when I put a ~ at the end of my post.

Not undertanding what the problem is...

Second, when the post is too short, it simply says 'The following errors occured:' with nothing after it.

Did you put the information in the correct language file? This would happen if that was the case / if it were not included.

Thirdly, is there any way to implement a minimum number of characters, rather than words?

Yes, quote easy... will write up a mod for that.

Finally, might I ask your permission to make it into a package and release it? :)

You have my permission to do what you like with it :)

Cheers,

Ryan Jones
RyanJ (Ryan Jones)

Support Web Standards!

Currently working On: Additions to the Karma system.

Offline Aitsukai

  • Jr. Member
  • **
  • Posts: 114
Re: Minimum number of words
« Reply #14 on: March 06, 2006, 04:20:03 PM »
Not undertanding what the problem is...
To elaborate, I left the word limit at the default of 5 words. I attempted to post 'hi~', and it succeeded without the error. I then tried to post 'hi', and it failed.

Did you put the information in the correct language file? This would happen if that was the case / if it were not included.
I put it in /Themes/default/languages/Admin.english.php. Is that correct?

Edit: Whoops! I completely missed that first part, LOL. Sorry!

Thanks for the permission. :)
« Last Edit: March 06, 2006, 04:27:52 PM by Aitsukai »

Offline RyanJones

  • Jr. Member
  • **
  • Posts: 103
  • Gender: Male
  • Remember kids: High energy EM radiation is fun!
    • Support Web Standards!
Re: Minimum number of words
« Reply #15 on: March 06, 2006, 05:01:32 PM »
For part 1, it should not affect it becaue it gets stripped out...I will check.

And here is the code for the character limit:

Open: /Themes/theme_name_here/language/Errors.english.php

Find: $txt[&#39;error_long_message&#39;] = &#39;The message exceeds the maximum allowed length (&#39; . $modSettings[&#39;max_messageLength&#39;] . &#39; characters).&#39;;


After, Add: $txt[&#39;error_minChar&#39;] = &#39;The message does not meet the minimum character requirements (&#39; . $modSettings[&#39;minChar&#39;] . &#39; characters).&#39;;


Close & Save File



Open: /Sources/Post.php

Find:

	
// Check the subject and message.


After, add:


	
if (!empty(
$modSettings[&#39;minChar&#39;]) && ((int)$modSettings[&#39;minChar&#39;] != 0))
	
{
    if (
strlen($_POST[&#39;message&#39;]) > (int)$modSettings[&#39;minChar&#39;])
      
$post_errors[] = &#39;minChar&#39;;
  
}


Close & Save File



Open: /Sources/ManagePosts.php

Find:

	
	
// Update the actual settings.
	
	
updateSettings(array(


After, add:

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


Close & Save File



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

Find: $txt['caching_settings'] = 'Caching';

After, add:


$txt
[&#39;minChar&#39;] = &#39;Minimum Characers&#39;;
$txt[&#39;minChar_zero&#39;] = &#39;0 for no minimum.&#39;;
$txt[&#39;minChar_chars&#39;] = &#39;characters&#39;;


Close & Save File



Open: /Sources/ManagePosts.php

Find:

	
	
// Update the actual settings.
	
	
updateSettings(array(


After, add:

	
	
	
&
#39;minWordLen&#39; => empty($_POST[&#39;minChar&#39;]) ? &#39;0&#39; : (int) $_POST[&#39;minChar&#39;],


Close & Save File



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

Find:


	
	
	
	
<
td valign="top">
	
	
	
	
	
<
input type="text" name="max_messageLength" id="max_messageLength_input" value="&#39;, empty($modSettings[&#39;max_messageLength&#39;]) ? &#39;0&#39; : $modSettings[&#39;max_messageLength&#39;], &#39;" size="5" /> &#39;, $txt[&#39;manageposts_characters&#39;], &#39;
	
	
	
	
</
td>
	
	
	
</
tr>


After, add:


<tr class="windowbg2">
	
	
	
	
<
th width="50%" align="right">
	
	
	
	
	
<
label for="minChar_input">&#39;, $txt[&#39;minChar&#39;], &#39; :
	
	
	
	
	
<
div class="smalltext" style="font-weight: normal;">&#39;, $txt[&#39;minChar_zero&#39;], &#39;</div>
	
	
	
	
</
th>
	
	
	
	
<
td valign="top">
	
	
	
	
	
<
input type="text" name="minChar" id="minChar_input" value="&#39;, empty($modSettings[&#39;minChar&#39;]) ? &#39;100&#39; : $modSettings[&#39;minChar&#39;], &#39;" size="5" /> &#39;, $txt[&#39;minChar_chars&#39;], &#39;
	
	
	
	
</
td>
	
	
	
</
tr>


Close & Save File

Cheers,

Ryan Jones
« Last Edit: March 06, 2006, 05:03:15 PM by RyanJones »
RyanJ (Ryan Jones)

Support Web Standards!

Currently working On: Additions to the Karma system.

Offline Aitsukai

  • Jr. Member
  • **
  • Posts: 114
Re: Minimum number of words
« Reply #16 on: March 06, 2006, 05:45:33 PM »
Thank you!

I submitted the package. It's here, waiting for approval. :D

Offline paki

  • Jr. Member
  • **
  • Posts: 184
  • Gender: Male
    • DFWHyundais.com
Re: Minimum number of words
« Reply #17 on: March 07, 2006, 12:48:32 AM »
thanks!

just to let everyone know.. the "minimum word" set up worked in SMF 1.1 RC1. Here is the only problem I encountered:

Quote
Open: /Themes/theme_name_here/language/Admin.english.php

Find: $txt['caching_settings'] = 'Caching';

After, add:

$txt['minChar'] = 'Minimum Characers';
$txt['minChar_zero'] = '0 for no minimum.';
$txt['minChar_chars'] = 'characters';
Close & Save File

That certain text does not exist in the file. I simply added all that text anywhere before the ending of the PHP code and it worked fine :)

For some reason the minimum character one is not working with mine.. any clue to why? i've filled everything in and the minimum is set to 20 characters.. but users can still post shorter (subject: x, post content: x). Any idea?

-edit- found the problem

Ryan, here is what you had for Post.php
    if (strlen($_POST['message']) > (int)$modSettings['minChar'])
[/php]

You have a verrrry small error that throws the entire thing off :P
Code: [Select]
if (strlen($_POST['message']) < (int)$modSettings['minChar'])
Instead of a > sign, you need a < :) The mod you've posted is a maximum character mod! :-P
« Last Edit: March 07, 2006, 01:24:18 AM by paki »
http://www.dfwhyundais.com <-- Dallas/Ft. Worth's Local Hyundai Group

Offline Aitsukai

  • Jr. Member
  • **
  • Posts: 114
Re: Minimum number of words
« Reply #18 on: March 07, 2006, 02:21:14 AM »
Haha, I was wondering why that wouldn't work. Anyway, I'll package them together and release a minimum word/character mod. :D

Offline paki

  • Jr. Member
  • **
  • Posts: 184
  • Gender: Male
    • DFWHyundais.com
Re: Minimum number of words
« Reply #19 on: March 07, 2006, 07:08:04 PM »
Would there be a way to strip out regular punctuation? One of the posters on my board decided to get smart and put !!!!!!!! after each less than 10 character post he had  >:(
http://www.dfwhyundais.com <-- Dallas/Ft. Worth's Local Hyundai Group