Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Mod Requests => Topic started by: Gobo on February 27, 2006, 09:31:25 PM

Title: Minimum number of words
Post by: Gobo 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

Title: Re: Minimum number of words
Post by: anunlike on February 28, 2006, 11:38:54 AM
Sounds like a good idea to me.
Title: Re: Minimum number of words
Post by: Aitsukai on February 28, 2006, 11:39:51 AM
vB has this feature. I support this.
Title: Re: Minimum number of words
Post by: loudyboy on February 28, 2006, 06:59:21 PM
Yup, I'd like to see this too please :)
Title: Re: Minimum number of words
Post by: URPG 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!
Title: Re: Minimum number of words
Post by: RyanJones 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
Title: Re: Minimum number of words
Post by: Skipdawg on February 28, 2006, 07:53:03 PM
Very kewl! Could come in handy down the road. I like it!  ;)
Title: Re: Minimum number of words
Post by: RyanJones 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['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
Title: Re: Minimum number of words
Post by: Gobo 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
Title: Re: Minimum number of words
Post by: anunlike on February 28, 2006, 11:43:53 PM
Thanks, RyanJones.

Would still be cool as a built in feature, IMO.
Title: Re: Minimum number of words
Post by: RyanJones 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
Title: Re: Minimum number of words
Post by: paki 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!
Title: Re: Minimum number of words
Post by: 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.

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? :)
Title: Re: Minimum number of words
Post by: RyanJones on March 06, 2006, 04:11:51 PM
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
Title: Re: Minimum number of words
Post by: Aitsukai on March 06, 2006, 04:20:03 PM
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. :)
Title: Re: Minimum number of words
Post by: RyanJones 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['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
Title: Re: Minimum number of words
Post by: Aitsukai on March 06, 2006, 05:45:33 PM
Thank you!

I submitted the package. It's here (http://mods.simplemachines.org/index.php?mod=290), waiting for approval. :D
Title: Re: Minimum number of words
Post by: paki 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:

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
Title: Re: Minimum number of words
Post by: Aitsukai 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
Title: Re: Minimum number of words
Post by: paki 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  >:(
Title: Re: Minimum number of words
Post by: Aitsukai on March 08, 2006, 06:50:14 AM
Hm. I believe that's called bypassing, why not add 'no bypassing the character limit' to your forum's rules? :)
Title: Re: Minimum number of words
Post by: paki on March 08, 2006, 01:19:26 PM
Quote from: Aitsukai on March 08, 2006, 06:50:14 AM
Hm. I believe that's called bypassing, why not add 'no bypassing the character limit' to your forum's rules? :)

I probably will.. but I hate going in there and deleting each of this guy's posts. I sent him a private message about it and told him that if it continues, I will take appropriate action (aka banning/suspending for a certain time) but I know he's not the only person who will ever join the site and do so lol. Sometimes its fun just frustrating the hell out of people when they're trying to bypass the limit and it won't work because it won't read their punctuation as a character  :D
Title: Re: Minimum number of words
Post by: paki on May 06, 2006, 03:16:57 PM
kicking the dead horse here

I'd like the topic title to be filtered out of this. Is this possible? I've noticed that if the title has at least the minimum amount of characters, people can post single character posts. If it is possible, please let me know. Thanks!
Title: Re: Minimum number of words
Post by: Gobo on May 07, 2006, 10:52:47 AM
talk about bypassing the people on my board are simply writing gibbrish now to fill up guess how many? a 4 word minimum fo 16 characters! Talk about lazy!