News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Minimum number of words

Started by Gobo, February 27, 2006, 09:31:25 PM

Previous topic - Next topic

Gobo

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


anunlike


Aitsukai

vB has this feature. I support this.

loudyboy

Yup, I'd like to see this too please :)

URPG

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!

RyanJones

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.

Skipdawg

Very kewl! Could come in handy down the road. I like it!  ;)
Skipdawg's Community

Powered by SMF 1.1.3

RyanJones

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['minWordLen'])
	
    
$post_errors[] = 'minWordLen';
  }


Close & Save File




Open: /Sources/ManagePosts.php

Find:

	
	
// Update the actual settings.
	
	
updateSettings(array(


After, add:

	
	
	
'minWordLen' => empty($_POST['minWordLen']) ? '0' : (int) $_POST['minWordLen'],


Close & Save File




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

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

After, add:


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


Close & Save File




Open: /Sources/ManagePosts.php

Find:

	
	
// Update the actual settings.
	
	
updateSettings(array(


After, add:

	
	
	
'minWordLen' => empty($_POST['minWordLen']) ? '0' : (int) $_POST['minWordLen'],


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="', empty($modSettings['max_messageLength']) ? '0' : $modSettings['max_messageLength'], '" size="5" /> ', $txt['manageposts_characters'], '
	
	
	
	
</
td>
	
	
	
</
tr>


After, add:


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


Close & Save File

Cheers,

Ryan Jones
RyanJ (Ryan Jones)

Support Web Standards!

Currently working On: Additions to the Karma system.

Gobo

wow thanks :D

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

anunlike

Thanks, RyanJones.

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

RyanJones

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.

paki

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

Aitsukai

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? :)

RyanJones

Quote from: Aitsukai 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.

Not undertanding what the problem is...

Quote from: Aitsukai on March 06, 2006, 03:47:46 PM
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.

Quote from: Aitsukai on March 06, 2006, 03:47:46 PMThirdly, is there any way to implement a minimum number of characters, rather than words?

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

Quote from: Aitsukai on March 06, 2006, 03:47:46 PM
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.

Aitsukai

#14
Quote from: RyanJones on March 06, 2006, 04:11:51 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.

Quote from: RyanJones on March 06, 2006, 04:11:51 PM
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. :)

RyanJones

#15
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['error_long_message'] = 'The message exceeds the maximum allowed length (' $modSettings['max_messageLength'] . ' characters).';


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


Close & Save File




Open: /Sources/Post.php

Find:

	
// Check the subject and message.


After, add:


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


Close & Save File




Open: /Sources/ManagePosts.php

Find:

	
	
// Update the actual settings.
	
	
updateSettings(array(


After, add:

	
	
	
'minChar' => empty($_POST['minChar']) ? '0' : (int) $_POST['minChar'],


Close & Save File




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




Open: /Sources/ManagePosts.php

Find:

	
	
// Update the actual settings.
	
	
updateSettings(array(


After, add:

	
	
	
'minWordLen' => empty($_POST['minChar']) ? '0' : (int) $_POST['minChar'],


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="', empty($modSettings['max_messageLength']) ? '0' : $modSettings['max_messageLength'], '" size="5" /> ', $txt['manageposts_characters'], '
	
	
	
	
</
td>
	
	
	
</
tr>


After, add:


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


Close & Save File

Cheers,

Ryan Jones
RyanJ (Ryan Jones)

Support Web Standards!

Currently working On: Additions to the Karma system.

Aitsukai

Thank you!

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

paki

#17
thanks!

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

QuoteOpen: /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
Quote from: RyanJones on March 06, 2006, 05:01:32 PM
    if (strlen($_POST['message']) > (int)$modSettings['minChar'])
[/php]

You have a verrrry small error that throws the entire thing off :P
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
http://www.dfwhyundais.com <-- Dallas/Ft. Worth's Local Hyundai Group

Aitsukai

Haha, I was wondering why that wouldn't work. Anyway, I'll package them together and release a minimum word/character mod. :D

paki

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

Advertisement: