Disable links for guests, or users with less than x posts

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Suggested Hosts
Locked
Philthy
Registered User
Posts: 210
Joined: Tue Dec 27, 2005 10:05 am
Location: Dawlish, Devon
Contact:

Disable links for guests, or users with less than x posts

Post by Philthy »

I have managed to to cobble together a solution to a problem I had, but don't have the knowledge to turn it into a mod, which I feel would be useful for others.
I wanted to allow guest posting, using the various anti-bot measures, but disallow them posting links. At the same time, I wanted to stop new users posting links, until they had made a certain number of posts.
There are a few mods about, which almost satisfied these criteria, but not quite.
Interlog's posts on this topic were very useful:
http://www.phpbb.com/community/viewtopi ... 2&t=745615
I would have posted on Tumba25's thread, but it was locked:
http://www.phpbb.com/community/viewtopi ... &t=1576205

Here's my solution:

SQL

Code: Select all

INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('links_after_num_posts', '0', '0');
In posting.php find:

Code: Select all

// Start session management
$user->session_begin();
$auth->acl($user->data);
After add:

Code: Select all

$StopMe = "No";
if ($user->data['user_type'] == USER_IGNORE || $user->data['user_id'] == ANONYMOUS || $user->data['user_posts'] <= $config['links_after_num_posts']
){
  $StopMe = "Yes";
}
Then find:

Code: Select all

if ($submit || $preview || $refresh)
{
After add:

Code: Select all

    $MHT        = utf8_normalize_nfc(request_var('message', '', true));
    if ($StopMe == "Yes" && (strpos($MHT,"http://") || (strpos($MHT,"www.")))){
      trigger_error ("Oops... You can not post links. New users must wait until they have enough posts. Guests cannot post links.");
    }
    if ($StopMe == "Yes" && substr($MHT, 0, 4) == "www."){
      trigger_error ("Oops... You can not post links. New users must wait until they have enough posts. Guests cannot post links.");
    }
  
Open: includes/acp/acp_board.php
Find:

Code: Select all

						'allow_post_links'		=> array('lang' => 'ALLOW_POST_LINKS',		'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => true),
After on a new line add:

Code: Select all

						'links_after_num_posts'	=> array('lang' => 'LINKS_AFTER_NUM_POSTS', 'validate' => 'int:0',	'type' => 'text:4:4', 'explain' => true),
Open: language/en/acp/board.php
Find:

Code: Select all

	'TOPICS_PER_PAGE'				=> 'Topics per page',
After add:

Code: Select all

	'LINKS_AFTER_NUM_POSTS' => 'Min post count before posting links',
	'LINKS_AFTER_NUM_POSTS_EXPLAIN' => 'Users will need this number of posts before they are able to use the [URL] BBCode tag and automatic/magic URLs.',
Go to ACP -> General and purge the cache.

This allows the number of posts, before posting links, to be set in the ACP. Guests will never be able to post them. Some would ask why allow guests to post at all, but that is a different topic for discussion.
I don't know if anyone would like to take all this info, and produce an approved mod?
Thanks to Erik Frerejean for his help with the code, and apologies if I have not credited others for their work.
Go on ! it's not as steep as it looks.....

Ather
Registered User
Posts: 1032
Joined: Fri May 08, 2009 9:42 am
Location: Kingdom of Bahrain
Name: Ather Akber

Re: Disable links for guests, or users with less than x post

Post by Ather »

wow, very nice stuff!, why not put it up in a modx file? [ http://www.phpbb.com/mods/modx-tools/creator/ ]
tag it and release in the Mod's in development, after you get some bug reports(or not?) you can submit to ModDB for validation
CPL Syed Ather Akbar
Regional Command Southwest
Camp Leatherneck, Afghanistan

My Mods/Snippets

Skinny Vinny
Registered User
Posts: 230
Joined: Tue Dec 01, 2009 7:10 pm

Re: Disable links for guests, or users with less than x post

Post by Skinny Vinny »

Very nice. Just a little touchup to one piece of your code. I suggest stripos, rather than strpos, for a case insensitive search. I see you do a second check for posts that begin with www. (but not http://?) as 1st position is 0 (false). Rather than doing a second condition, append the string with a character. I also suggest you move the definition and check on your $MHT var inside a separate $StopMe triggered block, so it only runs for 'stopped' users.

I'd also recommend adding the triggered error text to the lang file and calling it that way.

Code removed, as newer version is available below.

You may want to check your subject lines for domain/page references, too.

One other note...
the users back button will take them back to posting screen, but not all browser will put their post back to edit. I think that rather than trigger an error screen, you may want to just bring the posting screen back up with an alert type message. I'll look at it later if anyone wants that option instead. The reason being here is that a user may have spent a decent amount of time authoring the post and not knew of the restriction. If they invested a lot of time in the post, they're likely not going to do it again if it's lost. You could seriously tick off what may have been a great contributor.
Last edited by Skinny Vinny on Mon Jun 28, 2010 12:21 am, edited 1 time in total.

Skinny Vinny
Registered User
Posts: 230
Joined: Tue Dec 01, 2009 7:10 pm

Re: Disable links for guests, or users with less than x post

Post by Skinny Vinny »

Ok, I ended up playing with this more. It's agreat mod, but wanted to add to it.
Philthy, let me know if you want to submit it to the mods db since this thread was started by you with your version. Otherwise, I probably will in a few days. I don't care about credit, I just think it's a great mod that should be in the db.

I altered it to throw an error to the posting screen, rather than trigger an error screen.
I also added a 'number of days registered' option to also trigger the error (must have been member x days as well as have y post count to post links and domain references). Also, excluded admin from the rules (someone throws this on a new board and starts posting to find they're stuck behind it too lol). Final thing, I added the subject line to check, and added exclusion for internal links.


First, there are now 2 rows to add to config table:

Code: Select all

INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('links_after_num_posts', '0', '0');
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('links_after_num_days', '0', '0');
The code for posting.php (inserted at one location). Find:

Code: Select all

if ($submit || $preview || $refresh)
{ 
After, add:

Code: Select all

    $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']) || ($user->data['user_regdate']>($current_time-(86400*$config['links_after_num_days']))))){
        $no_link_for_you=true;
    }

    if ($no_link_for_you){
        if (empty($user->lang['NO_LINK_FOR_YOU'])){
            $user->lang['NO_LINK_FOR_YOU']='Your account does not have permission to post links or domain/page references.';
        }
        $no_link_message=' '.trim(utf8_normalize_nfc(request_var('message', '', true)).' '.utf8_normalize_nfc(request_var('subject', '', true)));
        $no_link_message=str_replace('\n', ' ', str_replace('\r', ' ', $no_link_message));
        while (strpos($no_link_message, '  ')){
            $no_link_message=str_replace('  ', ' ', $no_link_message);
        }
        $no_link_message=str_replace($config['server_protocol'].$config['server_name'], $config['server_name'], $no_link_message);
        while ($ok_start=stripos($no_link_message, $config['server_name'])){
            $ok_end=strpos($no_link_message, '[', $ok_start);
            if (!$ok_end){
                $ok_end=strpos($no_link_message, ' ', $ok_start);
            }
            if ($ok_end){
                $no_link_message=substr($no_link_message, 0, $ok_start).substr($no_link_message, $ok_end);
            }
        }
        // An array of no-nos. Add whatever you need...
        $no_link_strings=array('http://', 'www.', '.com', '.net', '.org', '.uk', '.ly', '.me', '.ru', '.biz', '.info', 'dot com', 'dot net', 'dot org', 'dotcom', 'dotnet', 'dotorg');
        
        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);
            }
        }
        
        unset($no_link_message, $no_link_for_you, $no_link_strings, $x);
    } 
In includes/acp/acp_board.php, find:

Code: Select all

                        'allow_post_links'        => array('lang' => 'ALLOW_POST_LINKS',        'validate' => 'bool',    'type' => 'radio:yes_no', 'explain' => true), 
Add after on new lines:

Code: Select all

                        'links_after_num_posts'   => array('lang' => 'LINKS_AFTER_NUM_POSTS', 'validate' => 'int:0',   'type' => 'text:4:4', 'explain' => true),
                        'links_after_num_days'    => array('lang' => 'LINKS_AFTER_NUM_DAYS', 'validate' => 'int:0',   'type' => 'text:4:4', 'explain' => true), 
In language/en/acp/board.php, find:

Code: Select all

    'TOPICS_PER_PAGE'                => 'Topics per page', 
After, add on new lines:

Code: Select all

    'LINKS_AFTER_NUM_POSTS'            => 'Min post count before posting links',
    'LINKS_AFTER_NUM_POSTS_EXPLAIN'    => 'Users will need this number of posts before they are able to use the [URL] BBCode tag or post page urls and domain references.',
    'LINKS_AFTER_NUM_DAYS'            => 'Min days from registration before posting links',
    'LINKS_AFTER_NUM_DAYS_EXPLAIN'    => 'Users will need to have registered this many days before they are able to use the [URL] BBCode tag or post page urls and domain references.', 
And be sure to purge your cache from acp index.

Props go to Philthy and friends!
It's a lovely mod. I just added to it :)


Update, added subject line.
Update, added an exclusion for internal links.

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

Re: Disable links for guests, or users with less than x post

Post by Philthy »

Go for it Vinny :D
I was hoping this would happen, I don't have the gumption to put this all together :geek:
I used to have a similar mod on my phpbb2 board, and it stopped spam dead in its tracks.
How about we throw it open to suggestions?
Go on ! it's not as steep as it looks.....

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

Re: Disable links for guests, or users with less than x post

Post by Philthy »

I've been thinking again :D
I know this would expand the mod, but having it auto ban after x attempts could be useful to some. Maybe not a complete ban, but not able to post, or placed in the moderation queue, until approved.

Just a thought.
Go on ! it's not as steep as it looks.....

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

Re: Disable links for guests, or users with less than x post

Post by Philthy »

Another thought:
How about simply emailing the contents of the attempted post to the admin?
It would be very easy to work out if the post is genuine or not, and act accordingly.
Go on ! it's not as steep as it looks.....

Skinny Vinny
Registered User
Posts: 230
Joined: Tue Dec 01, 2009 7:10 pm

Re: Disable links for guests, or users with less than x post

Post by Skinny Vinny »

The one I had written for a former employer on phpbb2 hid posts with link and domain references from public view until approved by an admin or moderator. I had a table of these flagged posts displayed to admins/mods on forum index, and the options to approve, delete, and even ban the user available directly on the post. You could also add the domain of the link/reference to a safe list that was excluded from the conditions. When a new user or user with less than x posts would submit a post with these links and references in it, it would throw up a screen with a 'reminder' of the boards rules, warn that the post would be hidden until reviewed, and present a captcha. It was a fantastic mod, and completely shut down the spam we saw on those boards (which was out of control at that time). I left that company shortly before the release of phpbb3, so never wrote a version of it compatible with phpbb3.

There are countless ways one could handle the risk posts. I don't believe working every possible option into one giant configurable mod is the solution. I like the mods to serve a specific purpose: if one wants the mod to behave in a different manner, it should be a different mod imho. Could it all be incorporated into one? Sure, but it would end up huge. The reason I hopped into this one was the simplicity of it.

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

Re: Disable links for guests, or users with less than x post

Post by Philthy »

No problem Vinny, just thinking out loud really.
The mod works perfectly as it is. Let's face it, why do spammers sign up to a site? To post links of course, this cuts the legs from under them.
Go on ! it's not as steep as it looks.....

User avatar
jmaraujo
Registered User
Posts: 240
Joined: Fri Jun 01, 2007 9:48 pm
Location: Rivera - Uruguay
Name: Juan

Re: Disable links for guests, or users with less than x post

Post by jmaraujo »

Nice job. :D Have you tried validating your mod? If not, do you have plans to do it in the future?

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

Re: Disable links for guests, or users with less than x post

Post by Philthy »

jmaraujo wrote:Nice job. :D Have you tried validating your mod? If not, do you have plans to do it in the future?
There's a RC:
http://www.phpbb.com/community/viewtopi ... &t=2096637
Go on ! it's not as steep as it looks.....

User avatar
jmaraujo
Registered User
Posts: 240
Joined: Fri Jun 01, 2007 9:48 pm
Location: Rivera - Uruguay
Name: Juan

Re: Disable links for guests, or users with less than x post

Post by jmaraujo »

Oh, I didn't see that topic! :oops: :oops: :oops: Thank you, Philthy! :D

Locked

Return to “[3.0.x] MOD Requests”