Customizing SMF > Tips and Tricks

Exclude specific group IDs and long term 'Newbies' from post/PM captcha

(1/1)

GL700Wing:
I noticed that someone asked for a mod that allows specific group IDs to be excluded from post captcha. 

This is something I implemented on one of my forums a few years ago because some members take out a Paid Subscription as soon as they join and I figured these members shouldn't have to complete captcha for posts (or PMs).  Also, and because I'd actually migrated this particular forum from a vBulletin forum that had been in existence for a few years, I added an option to exclude members who had joined more than a specific time ago from having to complete captcha (some long term but not very active members who were still 'Newbies').

In ./Sources/Display.php

Find:

--- Code: --- // Do we need to show the visual verification image?
$context['require_verification'] = !$user_info['is_mod'] && !$user_info['is_admin'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1));

--- End code ---

Replace with:

--- Code: --- // Do we need to show the visual verification image?
// Code to exclude post verification for specific group IDs and members who joined more than a specific time ago.
$context['require_verification'] = !$user_info['is_mod'] && !$user_info['is_admin'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)) && !$user_info['no_post_captcha'] && !$user_info['bypass_captcha'];

--- End code ---


In ./Sources/Load.php

Find:

--- Code: --- // This is a logged in user, so definitely not a spider.
$user_info['possibly_robot'] = false;

--- End code ---

Add After:

--- Code: ---
// Added code to exclude post and PM verification for specific group IDs and members who joined more than a specific time ago.
$groups_no_post_captcha = (!empty($modSettings['groups_no_post_captcha']) ? explode(',', $modSettings['groups_no_post_captcha'], 20) : array(-1));
$no_post_captcha = (in_array($user_settings['id_group'], $groups_no_post_captcha));
$groups_no_pm_captcha = (!empty($modSettings['groups_no_pm_captcha']) ? explode(',', $modSettings['groups_no_pm_captcha'], 20) : array(-1));
$no_pm_captcha = (in_array($user_settings['id_group'], $groups_no_pm_captcha));
$bypass_captcha = (!empty($modSettings['joined_days_no_captcha']) && $modSettings['joined_days_no_captcha'] > 0 && ($user_settings['date_registered'] < strtotime($modSettings['joined_days_no_captcha'] . ' days')));

--- End code ---


Find:

--- Code: --- if (isset($_COOKIE[$cookiename]))
$_COOKIE[$cookiename] = '';

--- End code ---

Add Before:

--- Code: --- // Added code to exclude post and PM verification for specific group IDs and members who joined more than a specific time ago.
$no_post_captcha = false;
$no_pm_captcha = false;
$bypass_captcha = false;


--- End code ---


Find:

--- Code: --- 'permissions' => array(),

--- End code ---

Add After:

--- Code: --- // Added code to exclude post and PM verification for specific group IDs and members who joined more than a specific time ago.
'no_post_captcha' => $no_post_captcha,
'no_pm_captcha' => $no_pm_captcha,
'bypass_captcha' => $bypass_captcha,

--- End code ---


In ./Sources/ManageSettings.php

Find:

--- Code: --- array('check', 'guests_report_require_captcha'),
--- End code ---

Add Before:

--- Code: --- // Added code to exclude post verification for specific group IDs and members who joined more than a specific time ago.
array('text', 'groups_no_post_captcha'),
array('int', 'joined_days_no_captcha'),

--- End code ---


Find:

--- Code: --- 'pm2' => array('int', 'pm_posts_verification'),

--- End code ---

Add After:

--- Code: --- // Added code to exclude PM verification for specific group IDs.
'pm4' => array('text', 'groups_no_pm_captcha'),

--- End code ---


Find:

--- Code: ---$save_vars['pm2'],

--- End code ---

Add After:

--- Code: ---$save_vars['pm4'],

--- End code ---


In ./Sources/PersonalMessage.php

Find:

--- Code: --- $context['require_verification'] = !$user_info['is_admin'] && !empty($modSettings['pm_posts_verification']) && $user_info['posts'] < $modSettings['pm_posts_verification'];
if ($context['require_verification'])
{
$verificationOptions = array(

--- End code ---

Replace with:

--- Code: --- // Added code to exclude PM verification for specific group IDs and members who joined more than a specific time ago.
$context['require_verification'] = !$user_info['is_admin'] && !empty($modSettings['pm_posts_verification']) && ($user_info['posts'] < $modSettings['pm_posts_verification'] && !$user_info['no_pm_captcha'] && !$user_info['bypass_captcha']);
if ($context['require_verification'])
{
$verificationOptions = array(

--- End code ---


Find:

--- Code: --- // Check whether we need to show the code again.
$context['require_verification'] = !$user_info['is_admin'] && !empty($modSettings['pm_posts_verification']) && $user_info['posts'] < $modSettings['pm_posts_verification'];

--- End code ---

Replace With:

--- Code: --- // Check whether we need to show the code again.
// Added code to exclude PM verification for specific group IDs and members who joined more than a specific time ago.
$context['require_verification'] = !$user_info['is_admin'] && !empty($modSettings['pm_posts_verification']) && ($user_info['posts'] < $modSettings['pm_posts_verification'] && $user_info['no_pm_captcha'] && !$user_info['bypass_captcha']);

--- End code ---


Find:

--- Code: --- // Wrong verification code?
if (!$user_info['is_admin'] && !empty($modSettings['pm_posts_verification']) && $user_info['posts'] < $modSettings['pm_posts_verification'])

--- End code ---

Replace With:

--- Code: --- // Wrong verification code?
// Added code to exclude PM verification for specific group IDs and members who joined more than a specific time ago.
if (!$user_info['is_admin'] && !empty($modSettings['pm_posts_verification']) && ($user_info['posts'] < $modSettings['pm_posts_verification'] && !$user_info['no_pm_captcha'] && !$user_info['bypass_captcha']))

--- End code ---


In ./Sources/Post.php

Find:

--- Code: --- // Do we need to show the visual verification image?
$context['require_verification'] = !$user_info['is_mod'] && !$user_info['is_admin'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1));

--- End code ---

Replace With:

--- Code: --- // Do we need to show the visual verification image?
// Added code to exclude post verification for specific group IDs and members who joined more than a specific time ago.
$context['require_verification'] = !$user_info['is_mod'] && !$user_info['is_admin'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)) && !$user_info['no_post_captcha'] && !$user_info['bypass_captcha'];

--- End code ---


Find:

--- Code: --- // Wrong verification code?
if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)))

--- End code ---

Replace With:

--- Code: --- // Wrong verification code?
// Added code to exclude post verification for specific group IDs and members who joined more than a specific time ago.
if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)) && !$user_info['no_post_captcha'] && !$user_info['bypass_captcha'])

--- End code ---


In ./Themes/default/languages/ManageSettings.english.php

Add to end of file (ie, before ?>):

--- Code: ---// Text strings to exclude post and PM verification for specific group IDs and members who joined more than a specified time ago.
$txt['pm_posts_verification'] = 'Post count under which members must pass verification when sending personal messages<div class="smalltext">(0 for no limit, admins and group IDs listed below are exempt)</div>';
$txt['posts_require_captcha_desc'] = '(0 for no limit; moderators, group IDs listed below and members who joined more than the number of days shown below are exempt)';
$txt['groups_no_post_captcha'] = 'Group IDs to be excluded from post verification.<div class="smalltext">(Must be separated by comma. i.e. 1,2,4)</div>';
$txt['groups_no_pm_captcha'] = 'Group IDs to be excluded from PM verification.<div class="smalltext">(Must be separated by comma. i.e. 1,2,4)</div>';
$txt['joined_days_no_captcha'] = 'Number of days after which members joined they are excluded from post verification.<div class="smalltext">(0 for not excluded)</div>';

--- End code ---

GL700Wing:
If the Anti-Spam-Links mod is installed the captcha exclusions can also be applied to links as follows:

In ./Sources/Post.php

Find:

--- Code: --- // Ugly but necessary.
// Takes into account moderation when deciding whether to show the post error.
if((($own_post && $user_info['is_guest']) || (!$own_post && empty($poster_id)) && $modSettings['anti_spam_links_guests'] == 1) || ((($own_post && !$user_info['is_guest']) || !$own_post && !empty($poster_id)) && !empty($modSettings['anti_spam_links_nolinks']) && $posts < $modSettings['anti_spam_links_nolinks']))

--- End code ---

Replace With:

--- Code: --- // Ugly but necessary.
// Takes into account moderation when deciding whether to show the post error.
// Don't include member if they belong to a group ID for whom post captcha doesn't apply or if they are allowed to bypass captcha because of their length of membership.
if ((($own_post && $user_info['is_guest']) || (!$own_post && empty($poster_id)) && $modSettings['anti_spam_links_guests'] == 1) || ((($own_post && !$user_info['is_guest']) || !$own_post && !empty($poster_id)) && !empty($modSettings['anti_spam_links_nolinks']) && $posts < $modSettings['anti_spam_links_nolinks']) && !$user_info['no_post_captcha'] && !$user_info['bypass_captcha'])

--- End code ---


Find:

--- Code: --- // Ugly but necessary.
// Takes into account moderation when deciding whether to show the post error.
if((($own_post && $user_info['is_guest']) || (!$own_post && empty($poster_id)) && $modSettings['anti_spam_links_guests'] == 1) || ((($own_post && !$user_info['is_guest']) || !$own_post && !empty($poster_id)) && !empty($modSettings['anti_spam_links_nolinks']) && $posts < $modSettings['anti_spam_links_nolinks']))

--- End code ---

Replace With:

--- Code: --- // Ugly but necessary.
// Takes into account moderation when deciding whether to show the post error.
// Don't include member if they belong to a group ID for whom post captcha doesn't apply or if they are allowed to bypass captcha because of their length of membership.
if ((($own_post && $user_info['is_guest']) || (!$own_post && empty($poster_id)) && $modSettings['anti_spam_links_guests'] == 1) || ((($own_post && !$user_info['is_guest']) || !$own_post && !empty($poster_id)) && !empty($modSettings['anti_spam_links_nolinks']) && $posts < $modSettings['anti_spam_links_nolinks']) && !$user_info['no_post_captcha'] && !$user_info['bypass_captcha'])

--- End code ---


Find:

--- Code: --- // Ugly but necessary.
// Takes into account moderation when deciding whether to show the post error.
if((($own_post && $user_info['is_guest']) || (!$own_post && empty($poster_id)) && $modSettings['anti_spam_links_guests'] == 1) || ((($own_post && !$user_info['is_guest']) || !$own_post && !empty($poster_id)) && !empty($modSettings['anti_spam_links_nolinks']) && $posts < $modSettings['anti_spam_links_nolinks']))

--- End code ---

Replace With:

--- Code: --- // Ugly but necessary.
// Takes into account moderation when deciding whether to show the post error.
// Don't include member if they belong to a group ID for whom post captcha doesn't apply or if they are allowed to bypass captcha because of their length of membership.
if ((($own_post && $user_info['is_guest']) || (!$own_post && empty($poster_id)) && $modSettings['anti_spam_links_guests'] == 1) || ((($own_post && !$user_info['is_guest']) || !$own_post && !empty($poster_id)) && !empty($modSettings['anti_spam_links_nolinks']) && $posts < $modSettings['anti_spam_links_nolinks']) && !$user_info['no_post_captcha'] && !$user_info['bypass_captcha'])

--- End code ---

Jedrek78:
I was looking for something like this mod and finally I found it :) Thanks

shadav:
thank you for this
and yeah I've run into that issue, quite annoying

but as Arantor pointed out, simply change mine and the persons post count ;)

GL700Wing:

--- Quote from: shadav on August 23, 2020, 10:09:56 AM ---thank you for this
and yeah I've run into that issue, quite annoying

but as Arantor pointed out, simply change mine and the persons post count ;)

--- End quote ---
I developed this tip/trick after I migrated a forum that had +2500 members from vBulletin to SMF - the forum had been in existence for several years and about 450 of the members had paid subscriptions. 

I guess I could have written some SQL to manually increase the post counts of long-term/financial members but this method allows the member's true post count to be shown and is not affected if the "Recount all member post counts" maintenance task is run.

Navigation

[0] Message Index

Go to full version