Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: Ben_S on July 23, 2005, 10:57:35 AM

Title: Restrict access to a board based of users age in profile.
Post by: Ben_S on July 23, 2005, 10:57:35 AM
This will allow you to prevent people under a certain age from accessing a certain board. Bear in mind it is only basic and probably not coded to well as I cobbled it together in 5 mins. It will not prevent people from viewing posts in a certain board by using the recent posts features or search.

Someday I may come back to it and turn it into a proper mod with an admin interface and correct the limitations.

Code: [Select]
Sources/Load.php

Find
'time_offset' => empty($user_settings['timeOffset']) ? 0 : $user_settings['timeOffset'],

Add After
                'birthdate' => empty($user_settings['birthdate']) ? 0 : $user_settings['birthdate'],


Sources/MessageIndex.php

Find
if (WIRELESS)
$context['sub_template'] = WIRELESS_PROTOCOL . '_messageindex';
else
loadTemplate('MessageIndex');


Add After
    //check their age for acess to a certain board
    if ($board == '20') // Change 20 to the ID_BOARD you want to restrict access to.
    {
        if (!empty($user_info['birthdate']))
{
            if ($user_info['birthdate'] != '0000-00-00')
            {
list ($birth_year, $birth_month, $birth_day) = sscanf($user_info['birthdate'], '%d-%d-%d');
$datearray = getdate(forum_time());
$user_info += array(
'age' => empty($birth_year) ? $txt[470] : $datearray['year'] - $birth_year - (($datearray['mon'] > $birth_month || ($datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day)) ? 0 : 1),
                'today_is_birthday' => $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day
);
            }
            else
            {
                $user_info['age'] = '0';
            }
}
       
        if ((@$user_info['age'] < '18') && (!$user_info['is_admin']))
            fatal_error('Sorry, you must be at least 18 to access this board', false);
    }

Sources/Display.php

Find
// Load the proper template and/or sub template.
if (WIRELESS)
$context['sub_template'] = WIRELESS_PROTOCOL . '_display';
else
loadTemplate('Display');

Add After
    //check their age for tickets board
    if ($board == '20')
    {
        if (!empty($user_info['birthdate']))
{
            if ($user_info['birthdate'] != '0000-00-00')
            {
list ($birth_year, $birth_month, $birth_day) = sscanf($user_info['birthdate'], '%d-%d-%d');
$datearray = getdate(forum_time());
$user_info += array(
'age' => empty($birth_year) ? $txt[470] : $datearray['year'] - $birth_year - (($datearray['mon'] > $birth_month || ($datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day)) ? 0 : 1),
                'today_is_birthday' => $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day
);
            }
            else
            {
                $user_info['age'] = '0';
            }
}
       
        if ((@$user_info['age'] < '18') && (!$user_info['is_admin']))
            fatal_error('Sorry, you must be at least 18 to access this board', false);
    }

Theres also probably a load of stuff in there that isn't required, if anyone want's to clean it up, feel free.
Title: Re: Restrict access to a board based of users age in profile.
Post by: Furvert on July 24, 2005, 10:26:22 PM
Thanks for pointing this out, I may try it.

Yup, that type of code can work.

It would be nicer as a permission, so I will continue to look into adding that. I have multiple boards with age restricts so it would get messy to code specifics for it.
Title: Re: Restrict access to a board based of users age in profile.
Post by: Ben_S on July 25, 2005, 04:14:26 AM
It was something I did quick as I needed something similar for my board, I may come back to it and use the permissions system and turn it into a mod.
Title: Re: Restrict access to a board based of users age in profile.
Post by: mennou on July 25, 2005, 03:31:30 PM
where can we  add this code? 
Title: Re: Restrict access to a board based of users age in profile.
Post by: Furvert on July 25, 2005, 05:54:26 PM
Permissions would be the best and more compatible for everyone.
I will still look into how to do that but I cant currently edit my database so its a bit harder to do.
I think I recall some tutorials here that may mention some of this, as too which files need to be moded.
Title: Re: Restrict access to a board based of users age in profile.
Post by: trenchteam on July 25, 2005, 08:20:31 PM
wow, this will be great standard. As I have an area for X rated topics. 
Title: Re: Restrict access to a board based of users age in profile.
Post by: Furvert on July 26, 2005, 06:54:48 PM
It appears that a simple mod to permissions would allow this.
http://www.simplemachines.org/community/index.php?topic=19136.0 covers permissions briefly

What is needed is a setting for age>=xxx required, thus a permission variable of 'MinAge' needs to be added. This would need to be put in 'ManagePermissions.php' and added to the database with default of 0. The code to use it would need to declare undefined birthday as age -1 in that case, so perhaps a better default is needed.

I have not yet found where the use code is needed so that is blends seamlessly with other permissions. But it should be possible to do so. The same place that determines membergroup access to boards should work in which case the forbidden boards do not show.

edit- $user_info[query_see_board] is where it is needed, now to find it. 'Security.php' may have it?
Title: Re: Restrict access to a board based of users age in profile.
Post by: Furvert on July 31, 2005, 04:38:40 AM
See http://www.simplemachines.org/community/index.php?topic=43818.0
I changed to a new topic for code help
Title: Re: Restrict access to a board based of users age in profile.
Post by: SeaOfSin on November 29, 2005, 06:46:30 PM
Does this work with RC1?  I tried it but nothing happened.
Title: Re: Restrict access to a board based of users age in profile.
Post by: SeaOfSin on November 29, 2005, 07:07:52 PM
OK, I sorted that problem but how can I do it for multiple boards?

I'm doing well today. Solved that too.  Just use the following

    if ($board == '2' || $board == '36' || $board == '20' || $board == '35' || $board == '36' || $board == '72')

Sea Of Sin
Title: Re: Restrict access to a board based of users age in profile.
Post by: desistyle on December 02, 2005, 12:02:05 AM
One question where we will be able to add the permssions than in admin panel after we install these codes ?
Title: Re: Restrict access to a board based of users age in profile.
Post by: onijin on May 30, 2006, 11:09:37 AM
works good.  However, if they don't input an age, they can access the board.  Is there a way to include the <18 with no birthdate given?
Title: Re: Restrict access to a board based of users age in profile.
Post by: Dem0n on November 23, 2006, 01:51:43 AM
how exactly does this restrict a users age? I've installed it and have no idea what I'm supposed to be looking for. How do I restrict access?
Title: Re: Restrict access to a board based of users age in profile.
Post by: 05185736 on August 14, 2007, 01:42:22 PM
was this ever made into a mod??
Title: Re: Restrict access to a board based of users age in profile.
Post by: statichrist on September 03, 2007, 11:24:23 PM
If anyone is willing to work with me on making this a mod (since the owner has seemingly not replied for 2 years) I will be glad to! I have very little experience, but wouldn't mind learning and also helping someone else do this!
email edited out

Thanks!
Title: Re: Restrict access to a board based of users age in profile.
Post by: statichrist on September 03, 2007, 11:54:28 PM
I've begun doing the very basicsc of making this a real modification. Please, if anyone is interested, let me know. I'm not sur what the next steps are.
Title: Re: Restrict access to a board based of users age in profile.
Post by: greyknight17 on September 30, 2007, 11:05:24 PM
@statichrist: This is a public forum (spambots crawl here) and I don't recommend posting your email here...edited out ;)

Were you able to get this working somehow? If so, there is help here on how to make it a mod if you know what code edits are needed. If you still need help with this, you can ask in the SMF Coding Discussion (http://www.simplemachines.org/community/index.php?board=60.0) for more help on this possible mod.
Title: Re: Restrict access to a board based of users age in profile.
Post by: Hollywood™ on November 17, 2007, 07:09:44 AM
Where do you put the codes? Does this work for 1.1.4?
And does anyone have any new updates on whether this became a Mod or not?
Title: Re: Restrict access to a board based of users age in profile.
Post by: Hollywood™ on November 17, 2007, 11:26:58 AM
Bump
Title: Re: Restrict access to a board based of users age in profile.
Post by: dave007 on November 24, 2007, 07:02:54 AM
thanks this helped me !
Title: Re: Restrict access to a board based of users age in profile.
Post by: $hawn on November 24, 2007, 01:41:26 PM
This is a nice little code snippet! I'm sure someone(or you) can improve on it and make a full fledged mod :)
Title: Ynt: Restrict access to a board based of users age in profile.
Post by: Bulakbol on December 05, 2007, 07:53:49 PM
Do you still need this?
Title: Re: Restrict access to a board based of users age in profile.
Post by: desquinn on January 18, 2008, 06:52:06 PM
I could definetly do with this as a mod for an Adult board.
Title: Re: Restrict access to a board based of users age in profile.
Post by: Sarge on January 31, 2008, 12:33:00 AM
Well, I might consider packaging this as a mod... I probably won't give any support for it, though.
Title: Re: Restrict access to a board based of users age in profile.
Post by: desquinn on January 31, 2008, 02:59:49 AM
that would be great if you could
Title: Re: Restrict access to a board based of users age in profile.
Post by: Robin1989 on February 24, 2008, 05:14:19 PM
yeh if this could be a fully fledged mod with an admin panel so you could change the age and the members groups it affect then that would be great. i would even do a small donation for it.
Title: Re: Restrict access to a board based of users age in profile.
Post by: glennk on March 25, 2008, 05:17:13 AM
has anyone taken this any further ?
Title: Re: Restrict access to a board based of users age in profile.
Post by: Joomlamz on April 28, 2008, 09:58:25 PM
where can finder that Mod