Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: slinouille on February 11, 2009, 01:18:38 AM

Title: Check Before Posting
Post by: slinouille on February 11, 2009, 01:18:38 AM
Link to Mod (http://custom.simplemachines.org/mods/index.php?mod=1627)
Check Before Posting v0.3.2
By Slinouille (http://custom.simplemachines.org/mods/index.php?action=search;author=68142)

Introduction
The mod permits to do some checks before a message is posted.

Features
This mod checks that:
o a link is done to a website you allow or disallow (based on a list you create)
o an image is hosted on a website you allow or not (based on a list you create)
o a subject doesn't have a too big ratio of uppercase letters (define your own ratio)
o a message doesn't have a too big ratio of uppercase letters (define your own ratio)
o Languages : French, English

Installation
Simply install the package to install this modification on the SMF Default Core theme.
Manual edits will be required for other themes.

This mod is compatible with SMF 2.0 Beta 4 Public and above only.

Support
Please use the modification thread for support with this modification.

Changelog
0.3.2 - 27th February 2009
o Correcting an error in source
o New check : uppercase letters ratio in Message

0.3.1 - 23th February 2009
o Packaging errors

0.3 - 20th February 2009
o Links check can be based on a list of allowed or disallowed websites
o Host linked images check can be based on a list of allowed or disallowed websites

0.2 - 11th February 2009
o New check : uppercase letters ratio in Subject
o Changing mod name from Manage Forbidden Links And Images to Check Before Posting

0.1 - 09th February 2009
o Initial release[/hr][/hr]
Title: Re: Manage Forbidden Links And Images
Post by: alex30 on February 11, 2009, 01:21:57 AM
Can be a useful mod guys.

Thanks slinouille.
Title: Re: Check Before Posting
Post by: qtime on February 11, 2009, 03:14:52 AM
this is a very welcome!
But I have also a big forum running on smf 118, any chances for that version?
Title: Re: Check Before Posting
Post by: chrisb on February 11, 2009, 03:39:45 AM
I would like to see this on 1.1.8 as well, as this will stop people going to other sites
Title: Re: Check Before Posting
Post by: digger on February 11, 2009, 08:49:27 AM
Can you make a list of allowed sites.
Title: Re: Check Before Posting
Post by: slinouille on February 11, 2009, 08:51:42 AM
Quote from: digger on February 11, 2009, 08:49:27 AM
Can you make a list of allowed sites.
It can be an evolution for next release  ;)

Sorry for SMF1.1.8 version but I don't have knowledge and time to realize both. If someone can adapte, please feel free, the code is really simple  ;D
Title: Re: Check Before Posting
Post by: edi67 on February 11, 2009, 02:01:37 PM
great mod let me try
Title: Re: Check Before Posting
Post by: mgrmgr on February 11, 2009, 06:09:08 PM
Quote from: digger on February 11, 2009, 08:49:27 AM
Can you make a list of allowed sites.

Just to give slinouille another nudge besides saying thank you for this mod: I second this wish, because we usually only allow links to our own site in our forum
Title: Re: Check Before Posting
Post by: DareDevil1990 on February 12, 2009, 12:51:46 AM
damn i would have loved this mod for smf 1.1.8 :D any chance of making this compatible with it :-s
Title: Re: Check Before Posting
Post by: Marcus Forsberg on February 12, 2009, 01:01:32 AM
Looks very nice.
Swedish:


Modifications.swedish.php


//Begin mod CheckBeforePosting
$txt['enable_check_forbidden_images'] = 'Aktivera kontroll av bilders webbhotell';
$txt['forbidden_images'] = 'Lista över förbjudna webbhotell (Separera med kommatecken)';
$txt['enable_check_forbidden_links'] = 'Aktivera kontroll av länkar';
$txt['forbidden_links'] = 'Hemsidor som inte får länkas (Separera med kommatecken)';
$txt['uppercase_ratio_in_subject'] = 'Antal stora bokstäver som tillåts i en ämnesrad, i procent (tomt för att inaktivera)';
//End mod CheckBeforePosting



Help.swedish.php



// Begin mod CheckBeforePosting
$helptxt['enable_check_forbidden_images'] = 'Denna inställning kontrollerar vilket webbhotell som postade bilder kommer ifrån';
$helptxt['forbidden_images'] = 'Ange en lista över de webbhotell du inte vill visa bilder från, och separera dem med kommatecken, t.ex: imageshack,zimagez.';
$helptxt['enable_check_forbidden_links']='Denna inställning kontrollerar alla länkar som postas i ditt forum.';
$helptxt['forbidden_links']='Ange en lista över hemsidor som inte får länkas, separerade med kommatecken. t.ex: yahoo,google.';
$helptxt['uppercase_ratio_in_subject'] = 'Detta tillåter dig att kontrollera procentantalet stora bokstäver i ett ämnes ämnesrad.<br>- om du lämnar fältet tomt inaktiveras detta,<br>- Om du anger 0, tillåts inga stora bokstäver,<br>- om du anger 100 kan man skriva en hel ämnesrad i stora bokstäver.';
//End mod CheckBeforePosting



Errors.swedish.php


//Begin mod CheckBeforePosting
$txt['error_forbidden_image'] = 'Du kan inte visa bilder som ligger hos %s';
$txt['error_forbidden_link'] = 'Du kan inte länka till %s';
$txt['error_too_many_uppercase_letters_in_subject'] = 'En ämnesrad får inte innehålla så många stora bokstäver';
//End mod CheckBeforePosting







A quick look on the code makes me believe that it wouldn't be very hard to make a 1.1.x-version.
Title: Re: Check Before Posting
Post by: slinouille on February 12, 2009, 12:32:09 PM
Thank you all  :D

@Nas:  thanks for swedish translations.

@mgrmgr: I'll do that once I'll have corrected some other mods on which I've got some troubles  ;)

Really sorry for SMF1.1.8 users but I really don't have time to make it compliant.
Title: Re: Check Before Posting
Post by: edi67 on February 13, 2009, 04:33:58 AM
mod work but i have a lot of these errors:


8: Undefined index: uppercase_ratio_in_subject
File: /home/crazyzone/data/www/crazyzone.biz/Sources/Post.php
Riga: 1459

8: Undefined index: enable_check_forbidden_links
File: /home/crazyzone/data/www/crazyzone.biz/Sources/Subs.php
Riga: 4201


some solution ?
Title: Re: Check Before Posting
Post by: slinouille on February 13, 2009, 05:09:00 AM
@edi67: I'll check that ... but I would like to know what "tool" you are using in order to get warned about those "undefined index" ... should be usefull when debuging mods ;)
Title: Re: Check Before Posting
Post by: edi67 on February 13, 2009, 06:16:16 AM
Quote from: slinouille on February 13, 2009, 05:09:00 AM
@edi67: I'll check that ... but I would like to know what "tool" you are using in order to get warned about those "undefined index" ... should be usefull when debuging mods ;)

i check the Log Register in admin panel
Title: Re: Check Before Posting
Post by: mgrmgr on February 19, 2009, 11:14:20 AM
(List of allowed sites)
Quote from: slinouille on February 12, 2009, 12:32:09 PM
...
@mgrmgr: I'll do that once I'll have corrected some other mods on which I've got some troubles  ;)

LOL - nice solution in v 0.3 - just a little quirk:

the definded $txt variables are defined as  cbb_links_allowed and ..._disallowed,

in ManageSettings.php (for the dropdown-boxes you use cbp_allowed  and cbp_disallowed. I inserted the missing "links_" in Managesettings - works ok now :)
Title: Re: Check Before Posting
Post by: slinouille on February 22, 2009, 01:56:23 AM
@mgrmgr: ok correction will be done ... thank you :)
Title: Re: Check Before Posting
Post by: mgrmgr on February 22, 2009, 03:12:46 PM
oups - me again :(

Now I have another problem: Set both fields to "allowed" and two sites in the list: for each posting now both warnings show up - no picture (not even smiley) or anything like a link is contained.

Something I broke or is there anyone having a similar problem?

Just my lazyness to ask before searching for a reason :)
Title: Re: Check Before Posting
Post by: edi67 on February 23, 2009, 03:36:19 AM
Quote from: mgrmgr on February 22, 2009, 03:12:46 PM
oups - me again :(

Now I have another problem: Set both fields to "allowed" and two sites in the list: for each posting now both warnings show up - no picture (not even smiley) or anything like a link is contained.

Something I broke or is there anyone having a similar problem?

Just my lazyness to ask before searching for a reason :)

words allowed and disallowed in list of choice not appear,
is i choice allowed or disallowed system DONT permit me to posts nothing, no censored link no permitted link everything seem to be disabled
Title: Re: Check Before Posting
Post by: slinouille on February 23, 2009, 06:05:39 AM
oops there is a lot of errors in this package ... I'll delete 0.3 from downloading center and upload a new one.

I must have been confused somewhere ... perhaps too much beers ?
Title: Re: Check Before Posting
Post by: slinouille on February 23, 2009, 08:34:32 AM
I've uploaded release 0.3.1 that should correct my previous very bad mod packaging.
I've tested it on my forum and on a fresh rc1 smf forum ... should work as it should ;)
Please tell me if on your forum it's okay?
Title: Re: Check Before Posting
Post by: edi67 on February 25, 2009, 05:42:44 AM
Quote from: slinouille on February 23, 2009, 08:34:32 AM
I've uploaded release 0.3.1 that should correct my previous very bad mod packaging.
I've tested it on my forum and on a fresh rc1 smf forum ... should work as it should ;)
Please tell me if on your forum it's okay?

i dont understand, not work for me, i insert url of site image not allowed and nothing happen, i disallowed url and nothing, i allow and nothing....i can post normally image from not permitted host
Title: Re: Check Before Posting
Post by: slinouille on February 26, 2009, 02:31:35 AM
@edi67: perhaps is it my code parser that is not good ?!? can you post what kind of text you have put in the "restriction list" so that I test it

Thks
Title: Re: Check Before Posting
Post by: edi67 on February 26, 2009, 02:42:16 AM
Quote from: slinouille on February 26, 2009, 02:31:35 AM
@edi67: perhaps is it my code parser that is not good ?!? can you post what kind of text you have put in the "restriction list" so that I test it

Thks

for example

amazon.com
Title: Re: Check Before Posting
Post by: mgrmgr on February 26, 2009, 06:37:57 AM
Thanks for that version 0.3.1, slinouille, does work now (on my page).

Just a suggestion for the next improvement:

the mod seems to work only with the img and url bbc-tags. Automatically activated links like http://www.yahoo.de or so seem not to be checked (answer also for edi67's question?) I'd like to have also checked those kind auf automatic links :)

Edit: disabling those "automatic" links is no real solution, because it would also disallow links to our own site (like forum links) which should be working.
Title: Re: Check Before Posting
Post by: slinouille on February 27, 2009, 01:52:23 AM
@edi67: I've seen an error in my code.
in file Sources/Post.php, select
//CheckBeforePosting mod
    if ( isset($modSettings['enable_check_images']) && $modSettings['enable_check_images'] == 1 || ( $modSettings['enable_check_links'] != '0' && isset($modSettings['enable_check_links']) ) ){

replace by
//CheckBeforePosting mod
    if ( isset($modSettings['enable_check_images']) && $modSettings['enable_check_images'] != '0' || ( $modSettings['enable_check_links'] != '0' && isset($modSettings['enable_check_links']) ) ){


I'll put a new release today
Title: Re: Check Before Posting
Post by: eddie8 on March 20, 2009, 05:24:28 PM
This Mod is a really good idea

This Mod seems like a good thing to have, is their any outstanding issues
I should know about before I install it? I read the thread and I see some
updates then nothing, I know its probably completed I'm just double checking

Thanks
Ed
Title: Re: Check Before Posting
Post by: mgrmgr on March 21, 2009, 10:03:46 AM
Quote from: eddie8 on March 20, 2009, 05:24:28 PM
This Mod is a really good idea

This Mod seems like a good thing to have, is their any outstanding issues
I should know about before I install it? I read the thread and I see some
updates then nothing, I know its probably completed I'm just double checking

I have installed version 0.3.2 on my Test forum 2.0 RC1 - works ok for me.
Title: Re: Check Before Posting
Post by: SFF Forum on April 13, 2009, 02:01:08 PM
Thanks for your good job,it is really a good mod.But can you please update this mod to SMF1.1.8,too
Title: Re: Check Before Posting
Post by: Shark-Time on August 17, 2009, 06:13:59 AM
need for SMF 1.1.10
Title: Re: Check Before Posting
Post by: mgrmgr on November 21, 2009, 06:08:34 AM
Quote from: Shark-Time on August 17, 2009, 06:13:59 AM
need for SMF 1.1.10

I agree - I'd like to have also an updated (if necessary) version for 2.0 RC2 or an entry in the description that it works on that version too.

@slinouille : But I won't hold my breath :)
Title: Re: Check Before Posting
Post by: Mick. on January 22, 2010, 05:49:21 PM
Maybe we need to fine tune this mod a bit...

I get the following errors:

8: Undefined index: uppercase_ratio_in_message
File: /home/******/public_html/Sources/Post.php
Line: 1535


and...

8: Undefined index: uppercase_ratio_in_subject
File: /home/*******/public_html/Sources/Post.php
Line: 1528



FYI,  those are the only options im not using.  The uppercases.   

The links and hosting options seem to be fine without errors.




These are the lines....

//CheckBeforePosting mod - check uppercase letters ratio in SUBJECT
if ( $modSettings['uppercase_ratio_in_subject'] >= 0 && !empty($modSettings['uppercase_ratio_in_subject']) ){
$subject = str_replace(' ','',$_POST['subject']); //don't take spaces into account
$ratio = preg_match_all( "/[A-Z]/", $subject, $res ) / strlen($subject) * 100;
if ( $ratio >= $modSettings['uppercase_ratio_in_subject'] )
$post_errors[] = 'too_many_uppercase_letters_in_subject';
}
//CheckBeforePosting mod - check uppercase letters ratio in MESSAGE
if ( $modSettings['uppercase_ratio_in_message'] >= 0 && !empty($modSettings['uppercase_ratio_in_message']) ){
$message = str_replace(' ','',$_POST['message']); //don't take spaces into account
$ratio = preg_match_all( "/[A-Z]/", $message, $res ) / strlen($message) * 100;
if ( $ratio >= $modSettings['uppercase_ratio_in_message'] )
$post_errors[] = 'too_many_uppercase_letters_in_message';
}
Title: Re: Check Before Posting
Post by: SISPro on December 15, 2010, 12:42:19 PM

Quote
Quote from: bluedevil on January 22, 2010, 05:49:21 PM
Maybe we need to fine tune this mod a bit...

I get the following errors:

8: Undefined index: uppercase_ratio_in_message
File: /home/******/public_html/Sources/Post.php
Line: 1535


and...

8: Undefined index: uppercase_ratio_in_subject
File: /home/*******/public_html/Sources/Post.php
Line: 1528



FYI,  those are the only options im not using.  The uppercases.   

The links and hosting options seem to be fine without errors.




These are the lines....

//CheckBeforePosting mod - check uppercase letters ratio in SUBJECT
if ( $modSettings['uppercase_ratio_in_subject'] >= 0 && !empty($modSettings['uppercase_ratio_in_subject']) ){
$subject = str_replace(' ','',$_POST['subject']); //don't take spaces into account
$ratio = preg_match_all( "/[A-Z]/", $subject, $res ) / strlen($subject) * 100;
if ( $ratio >= $modSettings['uppercase_ratio_in_subject'] )
$post_errors[] = 'too_many_uppercase_letters_in_subject';
}
//CheckBeforePosting mod - check uppercase letters ratio in MESSAGE
if ( $modSettings['uppercase_ratio_in_message'] >= 0 && !empty($modSettings['uppercase_ratio_in_message']) ){
$message = str_replace(' ','',$_POST['message']); //don't take spaces into account
$ratio = preg_match_all( "/[A-Z]/", $message, $res ) / strlen($message) * 100;
if ( $ratio >= $modSettings['uppercase_ratio_in_message'] )
$post_errors[] = 'too_many_uppercase_letters_in_message';
}


getting the same thing.

well not sure about this mod it looks and sound like a cool but, I am getting way to many errors in the error log. here are some.


with this mod any page i go to it puts a error in the error log
also not matter how i have it set lets say disallowed hosting sites i put in the ones i don't want i can't post anything it is always telling me that site is not allowed.

would like to see this get fix i do like it this mod.
Title: Re: Check Before Posting
Post by: Kindred on December 21, 2010, 12:21:07 PM
something which I discovered, which may be related to the errors noted:

If you do not SET each of the field values, the system does not set them and thus you get undefined_index errors.

to fix:
for EACH field, choose a setting other than the default.
---
turn on the link check, set a value for the caps check, etc.
Save
then change the settings back to what you want, i.e. turn off link check, but leave caps check on...

this sets the variable in the system and thus stops the undefined_index errors.



the ultimate fix for this would be to have the mod actually SET those values, if it determines a NULL.


edit: just discovered another error...
Division by 0

This is due to the fact that the subject and message CAPS check happen before the "is the subject/message empty" check.

Either change
if ( $modSettings['uppercase_ratio_in_subject'] >= 0 && !empty($modSettings['uppercase_ratio_in_subject']) ) {
to
if ( $modSettings['uppercase_ratio_in_subject'] >= 0 && !empty($modSettings['uppercase_ratio_in_subject']) && strlen($_POST['subject'])>0 ) {
and
if ( $modSettings['uppercase_ratio_in_message'] >= 0 && !empty($modSettings['uppercase_ratio_in_message']) ){
to
if ( $modSettings['uppercase_ratio_in_message'] >= 0 && !empty($modSettings['uppercase_ratio_in_message']) && strlen($_POST['message'])>0 ){

or (better choice)
move the entire caps check to AFTER

// Check the subject and message.
if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
$post_errors[] = 'no_subject';
if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
$post_errors[] = 'no_message';
elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
$post_errors[] = 'long_message';
else
{
Title: Re: Check Before Posting
Post by: SISPro on December 24, 2010, 10:47:46 PM
is there a for sure fix for this mod
Title: Re: Check Before Posting
Post by: Kindred on December 24, 2010, 11:50:05 PM
for sure fix for WHAT?

The mod works correctly for me. I noted (and listed the fix for) two minor issues.... but neither of those issues affect how the mod works.
Title: Re: Check Before Posting
Post by: SISPro on December 28, 2010, 09:25:21 AM
this is the message i get when posting

The following error or errors occurred while posting this message:
You can't insert a link to
Title: Re: Check Before Posting
Post by: Kindred on December 28, 2010, 09:41:26 AM
and what do you have in the "denied link" field in admin?
Title: Re: Check Before Posting
Post by: SISPro on December 29, 2010, 10:04:01 AM
these are image hosting sites that i don't want allowed.

imagepix,imageshack,imagepix,tinypic,hotlinkimage,yourfreeporn,linkbee,linkbucks,imagecash,hostapicture,

and so far file hosting sites.

Letitbit,filemonster,

the links i was posting was done of these.
Title: Re: Check Before Posting
Post by: Kindred on December 29, 2010, 10:24:41 AM
hmmm.... the empty comma at the end might be the issue...
Title: Re: Check Before Posting
Post by: sharks on December 29, 2010, 11:14:13 AM
Yeah, this can very useful. Maybe you could add more options, like block certain keywords from being used in the topic title and/or topic body.

Also, please optimize it such that it does not crash big forums. Decrease the number of queries if possible.
Title: Re: Check Before Posting
Post by: Texan78 on August 20, 2012, 03:18:41 PM
I have installed this mod with now errors, but I am unable to find in the Admin CP with the settings are made.

Where do I find these settings?

-Thanks
Title: Re: Check Before Posting
Post by: Yiorgos on October 03, 2012, 04:34:02 PM
Quote from: Texan78 on August 20, 2012, 03:18:41 PM
Where do I find these settings?

    Forum »
    Administration Center »
    Modification Settings »
    Miscellaneous

I installed that mod too, on SMF 2.0.2

I was getting a lot of undefined errors

Thanks to Kindered 's post (http://www.simplemachines.org/community/index.php?topic=292272.msg2887767#msg2887767) all errors dismissed.

Quote from: Kindred on December 21, 2010, 12:21:07 PM

If you do not SET each of the field values, the system does not set them and thus you get undefined_index errors.

to fix:
for EACH field, choose a setting other than the default.
---
turn on the link check, set a value for the caps check, etc.
Save
then change the settings back to what you want, i.e. turn off link check, but leave caps check on...

this sets the variable in the system and thus stops the undefined_index errors.
Title: Re: Check Before Posting
Post by: littlenicki on September 15, 2013, 11:08:50 AM
Hello, this is a very usefull mod. Could you possibly please do a SMF 1.1.18 version of it? Thank you, Nicole
Title: Re: Check Before Posting
Post by: Kindred on September 15, 2013, 11:51:42 AM
Unlikely to happen.

The coding for 2.x is different so the mod would have to be recoded completely.
Additionally, very few people are coding for 1.1.x these days.