MyBB Community Forums

Full Version: Age Restricted Thread Prefix
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Can anyone point me in the direction of a plugin/mod that can do the following or show me how I can do it myself?

What I need is a thread prefix (e.g. [NSFW]) that when added to a thread restricts users under 18/guests from viewing the contents (they can still see the thread is there, but get an error when trying to look inside).

My board will only occasionally have age restricted content and so I don't want to have to create a whole forum to cater for them.

Any help is greatly appreciated!
There is no such plugin already available.
What you could do it create a new usergroup called something like "18+" that anyone can choose to join, having a little note saying that by joining this group you're verifying that you are allowed to view NSFW content etc. Then only users that are in that group can see threads that are using the NSFW prefix.

If you install the template conditionals plugin you can do it with a simple edit to one template. http://mybbhacks.zingaburga.com/showthread.php?tid=464

Once you install that, go into your showthread template, and find

	{$pollbox}

above it add;

<if $thread['prefix'] == 2 AND $mybb->user['additionalgroups'] != 10 then>
Error. You cannot view this thread because it is marked as NSFW. 
<else>

Replace "2" with the prefix ID that you want to use, and "10" with the ID for the new 18+ usergroup you have created.

Then find;

	<div class="float_right" style="text-align: right;">
		{$moderationoptions}

and above that add;

</if>

That just displays a simple text error but you can obviously style it however you want the error to look.
(2012-09-02, 06:15 AM)YoshiOlly Wrote: [ -> ]What you could do it create a new usergroup called something like "18+" that anyone can choose to join, having a little note saying that by joining this group you're verifying that you are allowed to view NSFW content etc. Then only users that are in that group can see threads that are using the NSFW prefix.
*snip*

Thanks a lot for the help YoshiOlly, that worked perfectly Smile
(2012-09-02, 03:17 PM)DavinFelth Wrote: [ -> ]
(2012-09-02, 06:15 AM)YoshiOlly Wrote: [ -> ]What you could do it create a new usergroup called something like "18+" that anyone can choose to join, having a little note saying that by joining this group you're verifying that you are allowed to view NSFW content etc. Then only users that are in that group can see threads that are using the NSFW prefix.
*snip*

Thanks a lot for the help YoshiOlly, that worked perfectly Smile

Happy to help Smile
You have to note that $mybb->user['additionalgroups'] can be a comma separated list of groups, what if current user's is "9,10,11" ? I will not work.

Also, a core edit may be better for this:

Open showthread.php, find:
$plugins->run_hooks("showthread_start");

Add after:
if($thread['prefix'] && $thread['prefix'] == 2 && $mybb->user['usergroup'] != 10 && !stripos(','.$mybb->user['additionalgroups'].',', ',10,'))
{
error_no_permission();
}

(May be done with a plugin, but for this I don't think it is worth it.)
Can you actually put 18+ users automatically in another user group? I think it'd be easier to check the actual age of the user (explode('-', $mybb->user[birthday]) and you'll have the array). It's actually quite interesting, I might make a similar plugin once I have time, since I haven't programmed any plugin for quite some time, it'll be great to refresh my mind about it!

I've made a quite advanced plugin for it. You can find it here.