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.
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.
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.
where can we add this code?
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.
wow, this will be great standard. As I have an area for X rated topics.
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?
See http://www.simplemachines.org/community/index.php?topic=43818.0
I changed to a new topic for code help
Does this work with RC1? I tried it but nothing happened.
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
One question where we will be able to add the permssions than in admin panel after we install these codes ?
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?
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?
was this ever made into a mod??
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!
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.
@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.
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?
Bump
thanks this helped me !
This is a nice little code snippet! I'm sure someone(or you) can improve on it and make a full fledged mod :)
Do you still need this?
I could definetly do with this as a mod for an Adult board.
Well, I might consider packaging this as a mod... I probably won't give any support for it, though.
that would be great if you could
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.
has anyone taken this any further ?
where can finder that Mod