Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Thema gestartet von: Ben_S in Juli 23, 2005, 10:57:35 VORMITTAG

Titel: Restrict access to a board based of users age in profile.
Beitrag von: Ben_S in Juli 23, 2005, 10:57:35 VORMITTAG
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.

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.
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: Furvert in Juli 24, 2005, 10:26:22 NACHMITTAGS
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.
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: Ben_S in Juli 25, 2005, 04:14:26 VORMITTAG
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.
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: mennou in Juli 25, 2005, 03:31:30 NACHMITTAGS
where can we  add this code? 
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: Furvert in Juli 25, 2005, 05:54:26 NACHMITTAGS
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.
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: trenchteam in Juli 25, 2005, 08:20:31 NACHMITTAGS
wow, this will be great standard. As I have an area for X rated topics. 
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: Furvert in Juli 26, 2005, 06:54:48 NACHMITTAGS
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?
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: Furvert in Juli 31, 2005, 04:38:40 VORMITTAG
See http://www.simplemachines.org/community/index.php?topic=43818.0
I changed to a new topic for code help
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: SeaOfSin in November 29, 2005, 06:46:30 NACHMITTAGS
Does this work with RC1?  I tried it but nothing happened.
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: SeaOfSin in November 29, 2005, 07:07:52 NACHMITTAGS
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
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: desistyle in Dezember 02, 2005, 12:02:05 VORMITTAG
One question where we will be able to add the permssions than in admin panel after we install these codes ?
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: onijin in Mai 30, 2006, 11:09:37 VORMITTAG
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?
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: Dem0n in November 23, 2006, 01:51:43 VORMITTAG
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?
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: 05185736 in August 14, 2007, 01:42:22 NACHMITTAGS
was this ever made into a mod??
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: statichrist in September 03, 2007, 11:24:23 NACHMITTAGS
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!
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: statichrist in September 03, 2007, 11:54:28 NACHMITTAGS
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.
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: greyknight17 in September 30, 2007, 11:05:24 NACHMITTAGS
@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.
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: Hollywood™ in November 17, 2007, 07:09:44 VORMITTAG
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?
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: Hollywood™ in November 17, 2007, 11:26:58 VORMITTAG
Bump
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: dave007 in November 24, 2007, 07:02:54 VORMITTAG
thanks this helped me !
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: $hawn in November 24, 2007, 01:41:26 NACHMITTAGS
This is a nice little code snippet! I'm sure someone(or you) can improve on it and make a full fledged mod :)
Titel: Ynt: Restrict access to a board based of users age in profile.
Beitrag von: Bulakbol in Dezember 05, 2007, 07:53:49 NACHMITTAGS
Do you still need this?
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: desquinn in Januar 18, 2008, 06:52:06 NACHMITTAGS
I could definetly do with this as a mod for an Adult board.
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: Sarge in Januar 31, 2008, 12:33:00 VORMITTAG
Well, I might consider packaging this as a mod... I probably won't give any support for it, though.
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: desquinn in Januar 31, 2008, 02:59:49 VORMITTAG
that would be great if you could
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: Robin1989 in Februar 24, 2008, 05:14:19 NACHMITTAGS
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.
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: glennk in März 25, 2008, 05:17:13 VORMITTAG
has anyone taken this any further ?
Titel: Re: Restrict access to a board based of users age in profile.
Beitrag von: Apllicmz in April 28, 2008, 09:58:25 NACHMITTAGS
where can finder that Mod