TinyPortal

General => Chit chat => Topic started by: knat on April 25, 2007, 05:47:05 PM

Title: Who can help me with this code please - Not TP related, but SMF not responding !
Post by: knat on April 25, 2007, 05:47:05 PM
Hi guys and girls

I need help really bad and people at SMF are not responding.  :P

I installed a mod that forces a minimum of words or characters for a post to be made. This is to prevent one word spamming on my forum. My members like it but my staff hate that it also applies to them. And it even applies to admins also. so is there any simple IF/ELSE i can insert into this script so it will skip it if the user is in any of the admin/moderator groups ?

Here is what the mod did to my sources/post.php file.. i wouldnt ask this question here but the mod seems to be abandoned and i really need help with this. And i know how helpful people are here at TP.  :coolsmiley:

Please dont close my topic right away, i really need this fixed, any help will be appreciated !  :)


<edit file>
$sourcedir/Post.php
</edit file>

<search for>
// Check the subject and message.
</search for>

<add after>
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';
}

if (!empty($modSettings['minChar']) && ((int)$modSettings['minChar'] != 0))
{
    if (strlen($_POST['message']) < (int)$modSettings['minChar'])
      $post_errors[] = 'minChar';
}
</add after>
Title: Re: Who can help me with this code please - Not TP related, but SMF not respondi
Post by: G6Cad on April 25, 2007, 06:34:56 PM
Im sorry Tank, but i will have to ask you to wait for an answer on SMF.
We try to limit the SMF and other mods support here to the minimum or non at all.

They will give you a reply as soon as they can give you the answer you need.
Title: Re: Who can help me with this code please - Not TP related, but SMF not respondi
Post by: Thurnok on April 25, 2007, 08:36:27 PM
Here you go... change the mod XML to use the following instead:

<edit file>
$sourcedir/Post.php
</edit file>

<search for>
// Check the subject and message.
</search for>

<add after>
if (!empty($modSettings['minWordLen']) && ((int)$modSettings['minWordLen'] != 0) && empty($user_info['is_admin']) && empty($user_info['is_mod']))
{
    $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';
}

if (!empty($modSettings['minChar']) && ((int)$modSettings['minChar'] != 0) && empty($user_info['is_admin']) && empty($user_info['is_mod']))
{
    if (strlen($_POST['message']) < (int)$modSettings['minChar'])
      $post_errors[] = 'minChar';
}
</add after>


Or, if you already have it installed, just add the following parts to the Post.php file in bold maroon to the original mod's lines shown:

if (!empty($modSettings['minWordLen']) && ((int)$modSettings['minWordLen'] != 0) && empty($user_info['is_admin']) && empty($user_info['is_mod']) )

and

if (!empty($modSettings['minChar']) && ((int)$modSettings['minChar'] != 0) && empty($user_info['is_admin']) && empty($user_info['is_mod']) )

Title: Re: Who can help me with this code please - Not TP related, but SMF not responding !
Post by: knat on April 26, 2007, 05:19:41 AM
@ G6 - Yeah i know I'm kinda breaking the rules but i really needed this fixed before my mods was having my head. Sorry bout that, it wont happen again any time soon ;)

@ Thurnok - Thanks a million, you saved my head from being chopped off :) any chance to add one more group that is post count based ? If it is not to much trouble ^-^ I want to turn this off for charter members and that is usergroup # 12

Final question: is empty($user_info['is_mod']) = usergroup # 2 ??

BIG THANKS YOU AND TONS OF RESPECT !!  O0
Title: Re: Who can help me with this code please - Not TP related, but SMF not respondi
Post by: Sarge on April 26, 2007, 10:49:51 AM
Quote from: Tank on April 26, 2007, 05:19:41 AM
I want to turn this off for charter members and that is usergroup # 12

Try changing this:

if (!empty($modSettings['minWordLen']) && ((int)$modSettings['minWordLen'] != 0) && empty($user_info['is_admin']) && empty($user_info['is_mod']) )

and

if (!empty($modSettings['minChar']) && ((int)$modSettings['minChar'] != 0) && empty($user_info['is_admin']) && empty($user_info['is_mod']) )

to these:

if (!empty($modSettings['minWordLen']) && ((int)$modSettings['minWordLen'] != 0) && empty($user_info['is_admin']) && empty($user_info['is_mod']) && !in_array('2', $user_info['groups']) && !in_array('12', $user_info['groups']) )

and

if (!empty($modSettings['minChar']) && ((int)$modSettings['minChar'] != 0) && empty($user_info['is_admin']) && empty($user_info['is_mod']) && !in_array('2', $user_info['groups']) && !in_array('12', $user_info['groups']) )

The code I added is in teal. :)

To answer your other question:
Quote from: Tank on April 26, 2007, 05:19:41 AM
Final question: is empty($user_info['is_mod']) = usergroup # 2 ??

As far as I know, $user_info['is_mod'] means a local (board) moderator, not a global moderator (membergroup #2). Just in case, I added both membergroups #2 and #12 in the code above. ;)
Title: Re: Who can help me with this code please - Not TP related, but SMF not responding !
Post by: knat on April 26, 2007, 04:32:02 PM
Thanks alot Sarge - Everything is working perfect  ;)

Thanks to both of you helping me out even if it was not TP related. Big thanks  :) :) :)