[ABD] Disable links for new users & guests

Any abandoned MODs will be moved to this forum.

WARNING: MODs in this forum are not currently being supported or maintained by the original MOD author. Proceed at your own risk.
Forum rules
IMPORTANT: MOD Development Forum rules

WARNING: MODs in this forum are not currently being supported nor updated by the original MOD author. Proceed at your own risk.
User avatar
victory1
Registered User
Posts: 935
Joined: Sun Oct 10, 2010 6:47 pm
Contact:

Re: [RC] Disable links for new users & guests

Post by victory1 » Tue Feb 08, 2011 8:57 pm

I have it installed and set Min post count before posting links:3 and Min days from registration before posting links:0
I just registered a test account and it's letting me post links. Do you think the Newly Register User Group is affecting this?

EDIT: It works but this mod is flawed. It will not take

Code: Select all

http://www.sonyreaderboards.com

Code: Select all

www.sonyreaderboards.com
But it will take

Code: Select all

http://sonyreaderboards.com
By the way, the above is a valid link!

Philthy
Registered User
Posts: 210
Joined: Tue Dec 27, 2005 10:05 am
Location: Dawlish, Devon
Contact:

Re: [RC] Disable links for new users & guests

Post by Philthy » Tue Feb 08, 2011 9:35 pm

victory1 wrote:

Code: Select all

http://sonyreaderboards.com
That is seen as an internal link.

Being honest, I'm not sure how it does that?

Can you post any external links at all?

Edit typo.
Go on ! it's not as steep as it looks.....

User avatar
victory1
Registered User
Posts: 935
Joined: Sun Oct 10, 2010 6:47 pm
Contact:

Re: [RC] Disable links for new users & guests

Post by victory1 » Tue Feb 08, 2011 9:48 pm

You're right. I tried http://i.imgur.com/sAzqo.png and it would not post it. I was testing it with my website address and did not think anything of it. I wonder why it would not take the other versions of that address? :lol: Thanks

Philthy
Registered User
Posts: 210
Joined: Tue Dec 27, 2005 10:05 am
Location: Dawlish, Devon
Contact:

Re: [RC] Disable links for new users & guests

Post by Philthy » Tue Feb 08, 2011 9:55 pm

I registered an account to test your forum, feel free to delete it.
You have some pretty serious anti spam measures in place, but I'd be grateful if you could give me some feedback on this mod.
Go on ! it's not as steep as it looks.....

User avatar
heredia21
Registered User
Posts: 942
Joined: Sun Apr 18, 2010 6:14 pm
Contact:

Re: [RC] Disable links for new users & guests

Post by heredia21 » Tue Feb 08, 2011 10:01 pm

Download link not available?
Best BlackBerry website for all users! BlackBerry News - http://blackberryempire.com

Philthy
Registered User
Posts: 210
Joined: Tue Dec 27, 2005 10:05 am
Location: Dawlish, Devon
Contact:

Re: [RC] Disable links for new users & guests

Post by Philthy » Tue Feb 08, 2011 10:04 pm

heredia21 wrote:Download link not available?
OK here?

http://www.skidvd.co.uk/files/disable_l ... _0.0.2.zip
Go on ! it's not as steep as it looks.....

User avatar
victory1
Registered User
Posts: 935
Joined: Sun Oct 10, 2010 6:47 pm
Contact:

Re: [RC] Disable links for new users & guests

Post by victory1 » Tue Feb 08, 2011 10:20 pm

Philthy wrote:I registered an account to test your forum, feel free to delete it.
You have some pretty serious anti spam measures in place, but I'd be grateful if you could give me some feedback on this mod.
Definitely, I deleted that account. No bots get through my forum. I do have occasionally brave human spammers. They are the nice kind. You know the ones that answer the question and post unrelated links. :lol: Anyway, I will definitely give feedback. It might take a couple of days since the few that I have usually are on the weekends.

User avatar
heredia21
Registered User
Posts: 942
Joined: Sun Apr 18, 2010 6:14 pm
Contact:

Re: [RC] Disable links for new users & guests

Post by heredia21 » Wed Feb 09, 2011 5:44 am

Philthy wrote:
heredia21 wrote:Download link not available?
OK here?

http://www.skidvd.co.uk/files/disable_l ... _0.0.2.zip
Hmmm still doesnt work.
Best BlackBerry website for all users! BlackBerry News - http://blackberryempire.com

John T. Folden
Registered User
Posts: 188
Joined: Tue Sep 04, 2007 12:16 am

Re: [RC] Disable links for new users & guests

Post by John T. Folden » Wed Feb 09, 2011 5:46 am

Works for me...
The Blue Whale Pub - SPN/SF/F TV Discussion Forum
ZOMBIE ALERT: The Walking Dead are coming to AMC!

User avatar
Dragonwolf
Registered User
Posts: 603
Joined: Mon Aug 20, 2007 7:46 pm

Re: [RC] Disable links for new users & guests

Post by Dragonwolf » Thu Feb 10, 2011 12:07 pm

It's about time we had a mod like this! No more fooling around when we can just deny the spammers what they want outright! :lol:

Philthy
Registered User
Posts: 210
Joined: Tue Dec 27, 2005 10:05 am
Location: Dawlish, Devon
Contact:

Re: [RC] Disable links for new users & guests

Post by Philthy » Fri Feb 11, 2011 9:41 am

Updated to version 0.0.3

Minor changes in the text, to reflect that this mod only disables external links, and added some new domain references to be blocked.
Link to the updated download is in the original post.
Go on ! it's not as steep as it looks.....

dangerousprototypes
Registered User
Posts: 91
Joined: Fri Feb 11, 2011 5:53 am
Contact:

Re: [RC] Disable links for new users & guests

Post by dangerousprototypes » Fri Feb 11, 2011 9:43 am

IT looks like you posted while I was typing this up :)

Thanks for this. I added a second round that searches for keywords.

It took me a while to figure out how to include the unicode search characters in a way my ISP was happy with, so I'm sharing my update below. We had a huge problem with spam in unicode (cyrillic, arabic) characters in an english-only forum. This ends that. For unicode blocks and ID values (use the UTF-8 byte/8bit value) see: http://www.fileformat.info/info/unicode/block/index.htm

Note that this is hard-coded for 1 post/1day and doesn't use the ACP stuff.

Find

Code: Select all

if ($submit || $preview || $refresh)
{
Add after

Code: Select all

	// Are you someone who gets the no_link filter treatment
    $no_link_for_you=false;
 //   if ((!$user->data['session_admin']) && (($user->data['user_type']==USER_IGNORE) || ($user->data['user_id']==ANONYMOUS) || ($user->data['user_posts']<=$config['links_after_num_posts']-1) || ($user->data['user_regdate']>($current_time-(86400*$config['links_after_num_days']))))){
     if ((!$user->data['session_admin']) && (($user->data['user_type']==USER_IGNORE) || ($user->data['user_id']==ANONYMOUS) || ($user->data['user_posts']<=0) || ($user->data['user_regdate']>($current_time-(86400*1))))){

        $no_link_for_you=true; //If you're not special, we filter your 
    }

	//filter the looozers
    if ($no_link_for_you){
	
		//If there isn't a phpbb3 no_link message add one
        if (empty($user->lang['NO_LINK_FOR_YOU'])){
            $user->lang['NO_LINK_FOR_YOU']='I\'m sorry, your post looks too spamy for a new user, try it without off-site URLs.';
        }
		//If there isn't a phpbb3 no_word message add one
        if (empty($user->lang['NO_WORD_FOR_YOU'])){
			$user->lang['NO_WORD_FOR_YOU']='I\'m sorry, your post looks too spamy for a new user, try it without bad words or non-english text.';
		}
		
		//make a version of the post and subject
        $no_link_message=' '.trim(utf8_normalize_nfc(request_var('message', '', true)).' '.utf8_normalize_nfc(request_var('subject', '', true)));
		//remove line feeds and stuff
        $no_link_message=str_replace('\n', ' ', str_replace('\r', ' ', $no_link_message));
        //replace double spaces with single spaces
		//don;t know why...
		while (strpos($no_link_message, '  ')){
            $no_link_message=str_replace('  ', ' ', $no_link_message);
        }
		
        //remove any own-site references, these are ok
		//the method is a little intense
		//could just pluck them out....
		//first change http://mysite.com to mysite.com so we only have to look once below
		$no_link_message=str_replace($config['server_protocol'].$config['server_name'], $config['server_name'], $no_link_message);
		//could whitelist other common domains too
		//$no_link_message=str_replace('http://code.google.com', $config['server_name'], $no_link_message);	
		//look at all instances of mysite.com
        while ($ok_start=stripos($no_link_message, $config['server_name'])){ //start of mysite.com
            $ok_end=strpos($no_link_message, '[', $ok_start); //find next [ (bbcode?)
            if (!$ok_end){ //if not bbcode
                $ok_end=strpos($no_link_message, ' ', $ok_start); //end is position of next space
            }
            if ($ok_end){
                $no_link_message=substr($no_link_message, 0, $ok_start).substr($no_link_message, $ok_end);//remove own URL
            }
        }
		
        // An array of no-nos. Add whatever you need...
        $no_link_strings=array('http://', 'www.', '.com', '.us', '.net', '.org', '.uk', '.ly', '.me', '.ru', '.biz', '.info', 'dot com', 'dot net', 'dot org', 'dotcom', 'dotnet', 'dotorg');
        
		//search for each word, throw an error when found
        for ($x=0;$x<sizeof($no_link_strings);$x++){
            if (stripos($no_link_message, $no_link_strings[$x])){
                $error[]=$user->lang['NO_LINK_FOR_YOU'];
                //$x=sizeof($no_link_strings);
				break;//no reason to go further
            }
        }
		
		//a secondary spam words filter
		//common words, russian text, etc
		//for unicode blocks see: http://www.fileformat.info/info/unicode/block/index.htm
       $no_link_strings=array('all natural', 'buy direct', 'home business', //your list of key words
								"\xD0\x94","\xD0\xB4", //CYRILLIC LETTER DE (A)
								"\xD0\x98","\xD0\xB8", //CYRILLIC LETTER I (N)
								"\xD0\x99", "\xD0\xB9", //CYRILLIC LETTER SHORT I (N)
								"\xD0\x9B", "\xD0\xBB", //CYRILLIC LETTER EL (N)
								"\xDA\x9A", "\xDA\xB0", //couple from the arabic block
								);
								//'thanks for sharing',  'new member', 'nice web site', 'nice site',
		
		//search each word, throw an error when found
		for ($x=0;$x<sizeof($no_link_strings);$x++){
            if (stripos($no_link_message, $no_link_strings[$x])){
                $error[]=$user->lang['NO_WORD_FOR_YOU'];
                //$x=sizeof($no_link_strings);
				break;//no reason to search further
            }
        }
        
        unset($no_link_message, $no_link_for_you, $no_link_strings, $x);
    } 
Next I'm going to plug any hole a spammer can use for a URL until they pass the set 'trust' threshold (signature, member URL), I'll follow up with that in case anyone is interested.
Please do not PM or mail with questions. Ask in the forum where everyone can share the answer.

dangerousprototypes
Registered User
Posts: 91
Joined: Fri Feb 11, 2011 5:53 am
Contact:

Re: [RC] Disable links for new users & guests

Post by dangerousprototypes » Fri Feb 11, 2011 12:01 pm

Here's a plug for the other holes where spammers can put URLs. I think with these mods the forum is completely firewalled from dirty URL (assuming you purge sleeper users faster than the trust time).

First, implementing the disable links and dirty words scan for the signiture field:


Find in /includes/ucp/ucp_profile.php

Code: Select all

						if (!check_form_key('ucp_sig'))
						{
							$error[] = 'FORM_INVALID';
						}
Add after

Code: Select all

//---------------------------------------------------------------//
					// Are you someone who gets the no_link filter treatment
					$no_link_for_you=false;
					//   if ((!$user->data['session_admin']) && (($user->data['user_type']==USER_IGNORE) || ($user->data['user_id']==ANONYMOUS) || ($user->data['user_posts']<=$config['links_after_num_posts']-1) || ($user->data['user_regdate']>($current_time-(86400*$config['links_after_num_days']))))){
					 if ((!$user->data['session_admin']) && (($user->data['user_type']==USER_IGNORE) || ($user->data['user_id']==ANONYMOUS) || ($user->data['user_posts']<=0) || ($user->data['user_regdate']>($current_time-(86400*1))))){

						$no_link_for_you=true; //If you're not special, we filter your 
					}

					//filter the looozers
					if ($no_link_for_you){

						//If there isn't a phpbb3 no_link message add one
						if (empty($user->lang['NO_LINK_FOR_YOU'])){
							$user->lang['NO_LINK_FOR_YOU']='Antispam: You can\'t have off-site URLs in your sig until you post a few times.';
						}
						//If there isn't a phpbb3 no_word message add one
						if (empty($user->lang['NO_WORD_FOR_YOU'])){
							$user->lang['NO_WORD_FOR_YOU']='Do you kiss your mom with that mouth? We don\'t want to read that!';
						}
						
						//make a version of the post and subject
						$no_link_message=' '.trim(utf8_normalize_nfc(request_var('signature', (string) $user->data['user_sig'], true))).' ';//need the trailing space or it can hang forever in the while loop if only using a local URL
						//remove line feeds and stuff
						$no_link_message=str_replace('\n', ' ', str_replace('\r', ' ', $no_link_message));
						//replace double spaces with single spaces
						//don;t know why...
						while (strpos($no_link_message, '  ')){
							$no_link_message=str_replace('  ', ' ', $no_link_message);
						}
						
						//remove any own-site references, these are ok
						//the method is a little intense
						//could just pluck them out....
						//first change http://mysite.com to mysite.com so we only have to look once below
						$no_link_message=str_replace($config['server_protocol'].$config['server_name'], $config['server_name'], $no_link_message);
						//could whitelist other common domains too
						//$no_link_message=str_replace('http://code.google.com', $config['server_name'], $no_link_message);	
						//look at all instances of mysite.com
						while ($ok_start=stripos($no_link_message, $config['server_name'])){ //start of mysite.com
							$ok_end=strpos($no_link_message, '[', $ok_start); //find next [ (bbcode?)
							if (!$ok_end){ //if not bbcode
								$ok_end=strpos($no_link_message, ' ', $ok_start); //end is position of next space
							}
							if ($ok_end){
								$no_link_message=substr($no_link_message, 0, $ok_start).substr($no_link_message, $ok_end);//remove own URL
							}
						}
						
						// An array of no-nos. Add whatever you need...
						$no_link_strings=array('http://', 'www.', '.com', '.us', '.net', '.org', '.uk', '.ly', '.me', '.ru', '.biz', '.info', 'dot com', 'dot net', 'dot org', 'dotcom', 'dotnet', 'dotorg');
						
						//search for each word, throw an error when found
						for ($x=0;$x<sizeof($no_link_strings);$x++){
							if (stripos($no_link_message, $no_link_strings[$x])){
								$error[]=$user->lang['NO_LINK_FOR_YOU'];
								//$x=sizeof($no_link_strings);
								break;//no reason to go further
							}
						}
						
						//a secondary spam words filter
						//common words, russian text, etc
						//for unicode blocks see: http://www.fileformat.info/info/unicode/block/index.htm
					   $no_link_strings=array('all natural', 'buy direct', 'home business', 'premium', //your wordlist
												"\xD0\x94","\xD0\xB4", //CYRILLIC LETTER DE (A)
												"\xD0\x98","\xD0\xB8", //CYRILLIC LETTER I (N)
												"\xD0\x99", "\xD0\xB9", //CYRILLIC LETTER SHORT I (N)
												"\xD0\x9B", "\xD0\xBB", //CYRILLIC LETTER EL (N)
												"\xDA\x9A", "\xDA\xB0", //couple from the arabic block
												);
												//'thanks for sharing',  'new member', 'nice web site', 'nice site',
						
						//search each word, throw an error when found
						for ($x=0;$x<sizeof($no_link_strings);$x++){
							if (stripos($no_link_message, $no_link_strings[$x])){
								$error[]=$user->lang['NO_WORD_FOR_YOU'];
								//$x=sizeof($no_link_strings);
								break;//no reason to search further
							}
						}
						
						unset($no_link_message, $no_link_for_you, $no_link_strings, $x);
					} 
					
//---------------------------------------------------------------//
This is nearly identical to the other one I posted, but the errors are slightly different. This could totally be moved to a function for easy reuse.

I forgot to mention one thing last time: I think it probably saves cycles to just break out the loop once the needle is located in the haystack, but that's just me.

The profile field didn't end up as nicely. I didn't dig far enough to stop it from displaying (maybe another time), but I did add a permanent error message for new users that they cannot yet post a profile. If they try, the phpBB throw error is called. I tried to give a 404 or 501 to interfere with scrips a little more, but the headers have already been sent.


Find

Code: Select all

			case 'profile_info':
Insert after

Code: Select all

				//-------------------------------------------------------//
				// Are you someone who gets the no_link filter treatment
				$no_profile_for_you=false;
				//If there isn't a phpbb3 no_link message add one
				if (empty($user->lang['NO_LINK_FOR_YOU'])){
					$user->lang['NO_PROFILE_FOR_YOU']='Antispam: You can\'t have a profile yet. You need to post a few times first.';
				}
				//   if ((!$user->data['session_admin']) && (($user->data['user_type']==USER_IGNORE) || ($user->data['user_id']==ANONYMOUS) || ($user->data['user_posts']<=$config['links_after_num_posts']-1) || ($user->data['user_regdate']>($current_time-(86400*$config['links_after_num_days']))))){
				if ((!$user->data['session_admin']) && (($user->data['user_type']==USER_IGNORE) || ($user->data['user_id']==ANONYMOUS) || ($user->data['user_posts']<=0) || ($user->data['user_regdate']>($current_time-(86400*1))))){
					$error[]=$user->lang['NO_PROFILE_FOR_YOU']; //profiles are earned
					$no_profile_for_you=true;
				}
				//-------------------------------------------------------//
Find

Code: Select all

					if (!check_form_key('ucp_profile_info'))
					{
						$error[] = 'FORM_INVALID';
					}
Add after

Code: Select all

				//-------------------------------------------------------//
				// Are you someone who gets the no_link filter treatment
					if($no_profile_for_you){//recycle to save server cycles
						trigger_error($user->lang['NO_PROFILE_FOR_YOU']);//trigger an error page
						//header('HTTP/1.1 500 Internal Server Error'); //more agressive: send 404 error if user presses anyways (doesn't work, headers already sent)
					}
				//-------------------------------------------------------//
Find

Code: Select all

				$cp->generate_profile_fields('profile', $user->get_iso_lang_id());
Add after

Code: Select all

				//-------------------------------------------------------//				
				unset ($no_profile_for_you);
				//-------------------------------------------------------//
Again, please note that I used hard-coded age and post count vars, not the ones included fromt he DB/ACP with this mod. It would be easy enough to add that though.
Please do not PM or mail with questions. Ask in the forum where everyone can share the answer.

dangerousprototypes
Registered User
Posts: 91
Joined: Fri Feb 11, 2011 5:53 am
Contact:

Re: [RC] Disable links for new users & guests

Post by dangerousprototypes » Fri Feb 11, 2011 12:36 pm

A little bug in my ucp_profile.php code - ther eis no $current_time variable, so that needs to be updated to (time()) in both places it is used.
Please do not PM or mail with questions. Ask in the forum where everyone can share the answer.

dangerousprototypes
Registered User
Posts: 91
Joined: Fri Feb 11, 2011 5:53 am
Contact:

Re: [RC] Disable links for new users & guests

Post by dangerousprototypes » Fri Feb 11, 2011 2:51 pm

This was a fun project and I couldn't stop :)

I turned this into a class for easy tweaking, installing, and reuse. Maybe it will be helpful. Has tested ok on my live site, tested from multiple accounts (permissions).

This is for phpbb 3.0.8. It does the following:
*disables links and bad words for new users and guests in posts (displays warning)
*disables links and bad words for new users in signatures (displays warning)
*displays a warning that new users cannot have a profile, refuses to update the profile (but does not yet remove the page or fields)

Find in posting.php:

Code: Select all

if ($submit || $preview || $refresh)
{
Add under:

Code: Select all

	//---------------------------------------------------------------//
	//check for URLs and bad words in new user post
	require($phpbb_root_path . 'includes/functions_link_filter.' . $phpEx);
	$f= new link_filter; //new link filter
	if($f->link_filter_test_post())//run the check
	{ 
	$error = array_merge($error, $f->error);//add the errors to the error array, if any
	}
	unset($f);
	//---------------------------------------------------------------//
Find In ucp_profile.php:

Code: Select all

			case 'profile_info':
Add under:

Code: Select all

				//---------------------------------------------------------------//
				//display warning that new users can't have a profile
				require($phpbb_root_path . 'includes/functions_link_filter.' . $phpEx);
				$f= new link_filter; //new link filter
				if($f->link_filter_test_profile())//run the check
				{ 
				$error = array_merge($error, $f->error);//add the errors to the error array, if any
				}
				//---------------------------------------------------------------//
Find:

Code: Select all

					if (!check_form_key('ucp_profile_info'))
					{
						$error[] = 'FORM_INVALID';
					}
Add under:

Code: Select all

				//-------------------------------------------------------//
				// don;t allow new users to update profile
					if(sizeof($f->error))//run the check
					{ 
					$error = array_merge($error, $f->error);//add the errors to the error array, if any
					}
				//-------------------------------------------------------//
Find

Code: Select all

$cp->generate_profile_fields('profile', $user->get_iso_lang_id());
Add under

Code: Select all

				//-------------------------------------------------------//	
				//unset f clear down here incase we want to do something more interesting with it later			
				unset($f);
				//-------------------------------------------------------//
Find

Code: Select all

						if (!check_form_key('ucp_sig'))
						{
							$error[] = 'FORM_INVALID';
						}
Add under

Code: Select all

//---------------------------------------------------------------//
//check for URLs and bad words in new user signiture
require($phpbb_root_path . 'includes/functions_link_filter.' . $phpEx);
$f= new link_filter; //new link filter
if($f->link_filter_test_signiture())//run the check
{ 
$error = array_merge($error, $f->error);//add the errors to the error array, if any
}
unset($f);
//---------------------------------------------------------------//

Put the class in includes/function_link_filter.php:

Code: Select all

<?php
/**
*
* functions_link_filter.php
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
   exit;
}

class link_filter{
	// An array of no-nos. Add whatever you need...
	private $no_link_strings=array('http://', 'www.', '.com', '.us', '.net', '.org', '.uk', '.ly', '.me', '.ru', '.biz', '.info', 'dot com', 'dot net', 'dot org', 'dotcom', 'dotnet', 'dotorg');

	//a secondary spam words filter
	//common words, russian text, etc
	//for unicode blocks see: http://www.fileformat.info/info/unicode/block/index.htm
   private $no_word_strings=array('all natural', 'buy direct', 'home business', 'premium', 'betting', 'players', 'gamble', 'gambling',
							"\xD0\x94","\xD0\xB4", //CYRILLIC LETTER DE (A)
							"\xD0\x98","\xD0\xB8", //CYRILLIC LETTER I (N)
							"\xD0\x99", "\xD0\xB9", //CYRILLIC LETTER SHORT I (N)
							"\xD0\x9B", "\xD0\xBB", //CYRILLIC LETTER EL (N)
							"\xDA\x9A", "\xDA\xB0", //couple from the arabic block
							);
							//'thanks for sharing',  'new member', 'nice web site', 'nice site',
	public $error=array(); //holds error array

	
/**
*  Test if user can have a profile yet
*  returns true if they can have a profile
*/
function link_filter_test_profile(){
	global $user;
	
	//do we need to check this user?
	if(!$this->link_filter_check()) return false; //don't check, no error
	
	//If there isn't a phpbb3 no_link message add one
	if (empty($user->lang['NO_LINK_FOR_YOU'])){
		$user->lang['NO_PROFILE_FOR_YOU']='Antispam: You can\'t have a profile yet. You need to post a few times first.';
	}
	
	$this->error[]=$user->lang['NO_PROFILE_FOR_YOU'];
	
	return true;
}	

/**
*  Test a submitted signiture for links and words
*  Returns true if bad things detected
*/
function link_filter_test_signiture(){
	global $user;
	
	//do we need to check this user?
	if(!$this->link_filter_check()) return false; //don't check, no error
	
	//If there isn't a phpbb3 no_link message add one
	if (empty($user->lang['NO_LINK_FOR_YOU'])){
		$user->lang['NO_LINK_FOR_YOU']='Antispam: You can\'t have off-site URLs in your sig until you post a few times.';
	}
	//If there isn't a phpbb3 no_word message add one
	if (empty($user->lang['NO_WORD_FOR_YOU'])){
		$user->lang['NO_WORD_FOR_YOU']='Do you kiss your mom with that mouth? We don\'t want to read that!';
	}
	
	//make a version of the post and subject
	//need the trailing space or it can hang forever in the while loop if only using a local URL
	$this->link_filter_test(' '.trim(utf8_normalize_nfc(request_var('signature', (string) $user->data['user_sig'], true))).' ');
	
	if (sizeof($this->error)){
		return true;
	}else{
		return false;
	}
}

/**
*  Test a submitted post for links and words
*  Returns true if bad things detected
*/
function link_filter_test_post(){
	global $user;
	
	//do we need to check this user?
	if(!$this->link_filter_check()) return false; //don't check, no error
	
	//If there isn't a phpbb3 no_link message add one
	if (empty($user->lang['NO_LINK_FOR_YOU'])){
		$user->lang['NO_LINK_FOR_YOU']='I\'m sorry, your post looks too spamy for a new user, try it without off-site URLs.';
	}
	//If there isn't a phpbb3 no_word message add one
	if (empty($user->lang['NO_WORD_FOR_YOU'])){
		$user->lang['NO_WORD_FOR_YOU']='I\'m sorry, your post looks too spamy for a new user, try it without bad words or non-english text.';
	}
	
	//make a version of the post and subject
	$this->link_filter_test(' '.trim(utf8_normalize_nfc(request_var('message', '', true)).' '.utf8_normalize_nfc(request_var('subject', '', true))));

	if (sizeof($this->error)){
		return true;
	}else{
		return false;
	}
}

/**
* 	Do we need to check this user?
* 
*/
function link_filter_check()
{
	global $user;

	//   if ((!$user->data['session_admin']) && (($user->data['user_type']==USER_IGNORE) || ($user->data['user_id']==ANONYMOUS) || ($user->data['user_posts']<=$config['links_after_num_posts']-1) || ($user->data['user_regdate']>(($time())-(86400*$config['links_after_num_days']))))){
	 if ((!$user->data['session_admin']) && (($user->data['user_type']==USER_IGNORE) || ($user->data['user_id']==ANONYMOUS) || ($user->data['user_posts']<=0) || ($user->data['user_regdate']>((time())-(86400*1))))){
		return true; //If you're not special, we filter you
	}
	
	return false;
}

/**
* 	Search the text for forbidden URLs and text. Add an error to the local error array if found
* 
*/
function link_filter_test($no_link_message){
	global $user, $config;

	//filter the looozers
	//remove line feeds and stuff
	$no_link_message=str_replace('\n', ' ', str_replace('\r', ' ', $no_link_message));
	//replace double spaces with single spaces
	//don;t know why...
	while (strpos($no_link_message, '  ')){
		$no_link_message=str_replace('  ', ' ', $no_link_message);
	}
	
	//remove any own-site references, these are ok
	//first change http://mysite.com to mysite.com so we only have to look once below
	$no_link_message=str_replace($config['server_protocol'].$config['server_name'], $config['server_name'], $no_link_message);
	//could whitelist other common domains too
	//$no_link_message=str_replace('http://code.google.com', $config['server_name'], $no_link_message);	
	
	//look at all instances of mysite.com
	while ($ok_start=stripos($no_link_message, $config['server_name'])){ //start of mysite.com
		$ok_end=strpos($no_link_message, '[', $ok_start); //find next [ (bbcode?)
		if (!$ok_end){ //if not bbcode
			$ok_end=strpos($no_link_message, ' ', $ok_start); //end is position of next space
		}
		if ($ok_end){
			$no_link_message=substr($no_link_message, 0, $ok_start).substr($no_link_message, $ok_end);//remove own URL
		}
	}
		
	//search for each link element, throw an error when found
	for ($x=0;$x<sizeof($this->no_link_strings);$x++){
		if (stripos($no_link_message, $this->no_link_strings[$x])){
			$this->error[]=$user->lang['NO_LINK_FOR_YOU'];
			//$x=sizeof($no_link_strings);
			break;//no reason to go further
		}
	}
	
	//search each word, throw an error when found
	for ($x=0;$x<sizeof($this->no_word_strings);$x++){
		if (stripos($no_link_message, $this->no_word_strings[$x])){
			$this->error[]=$user->lang['NO_WORD_FOR_YOU'];
			//$x=sizeof($no_link_strings);
			break;//no reason to search further
		}
	}

}

}//class

?>
Now the search terms, "who to check" code, and filter loops are all consolidated. You can add more terms to the variables at the top.

Probably it would be good to tease the message text out as constants for easy definition at the top, but whatever.

Since installing this, and removing older spam prevention methods, spam has gone from 1-2 per hour to none :) I even uninstalled bad behavior.

I have some screenshots but don't seem to be able to attach them in the forum.

If you want to use this with the database settings, just uncomment the first line in function link_filter_check(), and comment the second one. That will remove my hard-coded test values.

I seem to be under moderation in this forum, but I'll respond to any questions when I can.

Locked

Return to “[3.0.x] Abandoned MODs”