Age & Gender Board Filtering MOD

Started by Senkusha, August 04, 2006, 07:04:00 PM

Previous topic - Next topic

Senkusha

Can somebody who has experiance building MOD's help me out.  I've got all the coding finished, I just need help making the XML file for the package.

What this mod does is it allows the Administrator to filter a board by AGE and GENDER.  These options are set in the Manage Boards page.  If you set the age greater than 0, then the member HAS to be at least that age.  A value of 0 (zero) disables the filter for age.

Also, there is gender filtering capability.  Valid options are:

  • Unrestricted - This option disables the gender filter.
  • Unspecified Gender - This option only allows members that have not supplied a gender in their profile.
  • Boys Only - This option only let's Males see the board.
  • Girls Only - This option only let's Females see the board.
  • Boys and Girls Only - This option only let's members that have supplied a gender in ther profile access to the board
Of course, the Administrator can see all boards.  This has been done for moderation purposes.

Here is the code:
Load.php
Find:

b.ID_THEME, b.override_theme, b.permission_mode, b.countPosts

Replace with:

b.ID_THEME, b.override_theme, b.permission_mode, b.countPosts, b.MinAge, b.gender_sel


Find:

'posts_count' => empty($row['countPosts']),


Add after:

'min_age' => $row['MinAge'],
'gender_sel' => $row['gender_sel'],


Find:

else
$user_info['query_see_board'] = '( (FIND_IN_SET(' . implode(', b.memberGroups) OR FIND_IN_SET(', $user_info['groups']) . ', b.memberGroups))'
. (empty($user_settings['ignoreBoards']) ? ')' : "AND !FIND_IN_SET(b.ID_BOARD, '" . $user_settings['ignoreBoards'] . "'))");


Add After:


if (empty($user_settings['birthdate']))
{
$AGE = 0;
}
else
{
list ($birth_year, $birth_month, $birth_day) = sscanf($user_settings['birthdate'], '%d-%d-%d');
$datearray = getdate(forum_time());
$AGE = empty($birth_year) ? 0 : $datearray['year'] - $birth_year - (($datearray['mon'] > $birth_month || ($datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day)) ? 0 : 1);
}

$memberGenderType = (isset($user_settings['gender']) ? $user_settings['gender'] : 0);
if (!$user_info['is_admin'])
{
$user_info['query_see_board'] .= ' AND b.MinAge <= ' . (int) $AGE;
// Add condition for Unrestricted Genders, then qualify based on 0 (Unspecified), 1 (Males), 2 (Females), 3 (Boys OR Girls, no UNSPECIFIED!)
$user_info['query_see_board'] .= ' AND ((b.gender_sel = -1 OR b.gender_sel = ' . $memberGenderType . ') OR (b.gender_sel = 3 AND ' . $memberGenderType . ' > 0))';
}


ManageBoards.php
Find:

'permission_mode' => 'normal',


Add After:

'min_age' => '0',
'gender_sel' => '-1',


Find:

$boardOptions['access_groups'] = array();


Add After:

$boardOptions['min_age'] = (int) isset($_POST['min_age']) ? $_POST['min_age'] : '0';
$boardOptions['gender_sel'] = (int) isset($_POST['gender_sel']) ? $_POST['gender_sel'] : '-1';


Find:

'permission_mode' => 'normal',


Add After:

'min_age' => '0',
'gender_sel' => '-1',


ManageBoards_template.php
Find:

<td valign="top" align="right">
<textarea name="desc" rows="2" cols="29">', $context['board']['description'], '</textarea>
</td>
</tr>


Add After:

';
// Option for Age Restriction and Gender Restriction.
echo '
<tr>
<td valign="top">
<b>Minimum Age to View Board:</b><br />
What is the mimiumn age for viewing access for this board?<br /><br />
</td>
<td align="right">
<input type="text" name="min_age" value="' . $context['board']['min_age'] . '" size="3" />
</td>
</tr>
<tr>
<td valign="top">
<b>Gender Restricted (only):</b><br />
Which gender is this board restricted to view / post?<br /><br />
</td>
<td align="right">
<select name="gender_sel">
<option ' . (($context['board']['gender_sel'] == '-1') ? 'selected' : 'value') . '="-1">Unrestricted</option>
<option ' . (($context['board']['gender_sel'] == '0') ? 'selected' : 'value') . '="0">Unknown Genders</option>
<option ' . (($context['board']['gender_sel'] == '1') ? 'selected' : 'value') . '="1">Boys Only</option>
<option ' . (($context['board']['gender_sel'] == '2') ? 'selected' : 'value') . '="2">Girls Only</option>
<option ' . (($context['board']['gender_sel'] == '3') ? 'selected' : 'value') . '="3">Boys and Girls Only</option>
</select>
</td>
</tr>


Subs-Boards.php
Find:

b.permission_mode, c.ID_CAT, c.name AS cName, c.catOrder, c.canCollapse


Add After:

, b.MinAge, b.gender_sel


Find:

'prev_board' => $prevBoard,


Add After:

'min_age' => $row['MinAge'],
'gender_sel' => $row['gender_sel'],


Find:

if (isset($boardOptions['board_description']))
$boardUpdates[] = 'description = \'' . $boardOptions['board_description'] . '\'';


Add After:

// Age Mod
if (isset($boardOptions['min_age']))
$boardUpdates[] = 'MinAge = \'' . $boardOptions['min_age'] . '\'';
if (isset($boardOptions['gender_sel']))
$boardUpdates[] = 'gender_sel = \'' . $boardOptions['gender_sel'] . '\'';


Thanks!
--Senkusha
The Anime Brigade
Anime-style Role Playing Games and Discussion.
(SMF v. 2.1.4, PHP v. 8.0)

B Patterson

Okay... I've been kind-enough to do this for you.  You only have to do a few things:
1.) Test it out first with a working board ;)  Make sure the install works ;)

Here's the XML codes:

package-info.xml
<?xml version="1.0"?>
<!DOCTYPE package-info SYSTEM "http://www.simplemachines.org/xml/package-info">
<package-info xmlns="http://www.simplemachines.org/xml/package-info" xmlns:smf="http://www.simplemachines.org/">
<id>Senkusha:AGBF</id>

<name>Age & Gender Board Filter</name>

<version>0.1</version>

<type>modification</type>

<install>
<readme></readme>
<modification>install.xml</modification>
</install>

<uninstall>
<modification revers="true">install.xml</modification>
</uninstall>
</package-info>


install.xml
<?xml version="1.0"?>
<!DOCTYPE modification SYSTEM "http://www.simplemachines.org/xml/modification">
<modification xmlns="http://www.simplemachines.org/xml/modification" xmlns:smf="http://www.simplemachines.org/">
<id>Senkusha:AGBF</id>
<version>0.1</version>

<file name="$sourcedir/Load.php" error="fatal">
<operation>
<search position="replace"><![CDATA[
b.ID_THEME, b.override_theme, b.permission_mode, b.countPosts
]]></search>
<add><![CDATA[
b.ID_THEME, b.override_theme, b.permission_mode, b.countPosts, b.MinAge, b.gender_sel
]]></add>
</operation>

<operation>
<search position="before"><![CDATA[
'posts_count' => empty($row['countPosts']),
]]></search>

<add><![CDATA[
'min_age' => $row['MinAge'],
'gender_sel' => $row['gender_sel'],
]]></add>
</operation>

<operation>
<search position="before"><![CDATA[
else
$user_info['query_see_board'] = '( (FIND_IN_SET(' . implode(', b.memberGroups) OR FIND_IN_SET(', $user_info['groups']) . ', b.memberGroups))'
. (empty($user_settings['ignoreBoards']) ? ')' : "AND !FIND_IN_SET(b.ID_BOARD, '" . $user_settings['ignoreBoards'] . "'))");
]]></search>
<add><![CDATA[

if (empty($user_settings['birthdate']))
{
$AGE = 0;
}
else
{
list ($birth_year, $birth_month, $birth_day) = sscanf($user_settings['birthdate'], '%d-%d-%d');
$datearray = getdate(forum_time());
$AGE = empty($birth_year) ? 0 : $datearray['year'] - $birth_year - (($datearray['mon'] > $birth_month || ($datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day)) ? 0 : 1);
}

$memberGenderType = (isset($user_settings['gender']) ? $user_settings['gender'] : 0);
if (!$user_info['is_admin'])
{
$user_info['query_see_board'] .= ' AND b.MinAge <= ' . (int) $AGE;
// Add condition for Unrestricted Genders, then qualify based on 0 (Unspecified), 1 (Males), 2 (Females), 3 (Boys OR Girls, no UNSPECIFIED!)
$user_info['query_see_board'] .= ' AND ((b.gender_sel = -1 OR b.gender_sel = ' . $memberGenderType . ') OR (b.gender_sel = 3 AND ' . $memberGenderType . ' > 0))';
}
]]></add>
</operation>
</file>

<file name="$sourcedir/ManageBoards.php" error="fatal">
<operation>
<search position="before"><![CDATA[
'permission_mode' => 'normal',
]]></search>
<add><![CDATA[
'min_age' => '0',
'gender_sel' => '-1',
]]></add>
</operation>

<operation>
<search position="before"><![CDATA[
$boardOptions['access_groups'] = array();
]]></search>
<add><![CDATA[
$boardOptions['min_age'] = (int) isset($_POST['min_age']) ? $_POST['min_age'] : '0';
$boardOptions['gender_sel'] = (int) isset($_POST['gender_sel']) ? $_POST['gender_sel'] : '-1';
]]></add>
</operation>

<operation>
<search position="before"><![CDATA[
'permission_mode' => 'normal',
]]></search>
<add><![CDATA[
'min_age' => '0',
'gender_sel' => '-1',
]]></add>
</operation>
</file>

<file name="$themedir/default/ManageBoards_template.php" error="fatal">
<operation>
<search position="before"><![CDATA[
<td valign="top" align="right">
<textarea name="desc" rows="2" cols="29">', $context['board']['description'], '</textarea>
</td>
</tr>
]]></search>

<add><![CDATA[
';
// Option for Age Restriction and Gender Restriction.
echo '
<tr>
<td valign="top">
<b>Minimum Age to View Board:</b><br />
What is the mimiumn age for viewing access for this board?<br /><br />
</td>
<td align="right">
<input type="text" name="min_age" value="' . $context['board']['min_age'] . '" size="3" />
</td>
</tr>
<tr>
<td valign="top">
<b>Gender Restricted (only):</b><br />
Which gender is this board restricted to view / post?<br /><br />
</td>
<td align="right">
<select name="gender_sel">
<option ' . (($context['board']['gender_sel'] == '-1') ? 'selected' : 'value') . '="-1">Unrestricted</option>
<option ' . (($context['board']['gender_sel'] == '0') ? 'selected' : 'value') . '="0">Unknown Genders</option>
<option ' . (($context['board']['gender_sel'] == '1') ? 'selected' : 'value') . '="1">Boys Only</option>
<option ' . (($context['board']['gender_sel'] == '2') ? 'selected' : 'value') . '="2">Girls Only</option>
<option ' . (($context['board']['gender_sel'] == '3') ? 'selected' : 'value') . '="3">Boys and Girls Only</option>
</select>
</td>
</tr>
]]></add>
</operation>
</file>

<file name="$sourcedir/Subs-Boards.php" error="fatal">
<operation>
<search position="before"><![CDATA[
b.permission_mode, c.ID_CAT, c.name AS cName, c.catOrder, c.canCollapse
]]></search>
<add><![CDATA[
, b.MinAge, b.gender_sel
]]></add>
</operation>

<operation>
<search position="before"><![CDATA[
'prev_board' => $prevBoard,
]]></search>
<add><![CDATA[
'min_age' => $row['MinAge'],
'gender_sel' => $row['gender_sel'],
]]></add>
</operation>

<operation>
<search position="before"><![CDATA[
if (isset($boardOptions['board_description']))
$boardUpdates[] = 'description = \'' . $boardOptions['board_description'] . '\'';
]]></search>
<add><![CDATA[
// Age Mod
if (isset($boardOptions['min_age']))
$boardUpdates[] = 'MinAge = \'' . $boardOptions['min_age'] . '\'';
if (isset($boardOptions['gender_sel']))
$boardUpdates[] = 'gender_sel = \'' . $boardOptions['gender_sel'] . '\'';
]]></add>
</operation>
</file>
</modification>

jeremyyeo

does this work guys? cant seem to find any other that's similiar to this mod.

codenaught

You are welcome to try it by copying and pasting the code posted by bpat1434 and calling the first file "package-info.xml" and the other one "install.xml" and then zipping it and seeing if it works.

I am not sure why Senkusha hasn't released it yet.
Dev Consultant
Former SMF Doc Coordinator

Senkusha

There's a minor problem with the mod resetting the gender filter to something other than was has been previously set.  (Anybody know how SELECT boxes work?)  ;D

I need to make a minor database change and change the values slightly for this mod to work correctly.  I didn't release it yet because I was too busy battleing the 1.1 RC3 upgrade.
--Senkusha
The Anime Brigade
Anime-style Role Playing Games and Discussion.
(SMF v. 2.1.4, PHP v. 8.0)

codenaught

Okay then. Don't feel rushed or anything. You are welcome to ask for help if you need it. :)
Quote from: Senkusha on October 03, 2006, 02:11:20 PM
There's a minor problem with the mod resetting the gender filter to something other than was has been previously set.  (Anybody know how SELECT boxes work?)  ;D
Are you using <option selected="selected" on the option that is currently be used?
Dev Consultant
Former SMF Doc Coordinator

Senkusha

Yeah, when the board loads, it displays the correct selection, but for whatever reason, it doesn't save it...almost as if the value isn't sent to POST (instead a value of "0" is being sent)
--Senkusha
The Anime Brigade
Anime-style Role Playing Games and Discussion.
(SMF v. 2.1.4, PHP v. 8.0)

codenaught

I don't know exactly where the problem is, but you should change your select code.

For the current item that is being used you have <option selected="1" which isn't how it is suppose to be used. You need to have it as <option selected="selected" value="1"

The value still needs to be there.
Dev Consultant
Former SMF Doc Coordinator

Senkusha

Oh!  Okay, I must have misread the documentation!  I'll try that and see if it does the trick right away.  Thanks!  ;D
--Senkusha
The Anime Brigade
Anime-style Role Playing Games and Discussion.
(SMF v. 2.1.4, PHP v. 8.0)

Metal_13

does not work on 1.1.3.....
will it work if i intall this manually?


1.     Execute Modification     ./Sources/Load.php     Test failed
2.    Execute Modification    ./Sources/ManageBoards.php    Test successful
3.    Execute Modification    ./Themes/default/default/ManageBoards_template.php    File not found
4.    Execute Modification    ./Sources/Subs-Boards.php    Test failed

Bulakbol

@Senkusha

This is not in the Sources/Load.php.
else
$user_info['query_see_board'] = '( (FIND_IN_SET(' . implode(', b.memberGroups) OR FIND_IN_SET(', $user_info['groups']) . ', b.memberGroups))'
. (empty($user_settings['ignoreBoards']) ? ')' : "AND !FIND_IN_SET(b.ID_BOARD, '" . $user_settings['ignoreBoards'] . "'))");


Either you are using a mod that modified Load.php or you are not using SMF version 1.1.3
Please do not PM me for support · My Mods and Theme · SMF Coding Guidelines · Modifications Approval Guidelines

Dragooon

This post was made 1 year ago. Things have changed ;)

Bulakbol

Quote from: Dragooon on September 10, 2007, 01:44:09 AM
This post was made 1 year ago. Things have changed ;)

o yah haha. I didn't notice the date lol. Thanks.
Please do not PM me for support · My Mods and Theme · SMF Coding Guidelines · Modifications Approval Guidelines

Bulakbol

Quote from: metal13 on September 09, 2007, 06:19:22 AM
does not work on 1.1.3.....
will it work if i intall this manually?


I was interested with this mod so I can create different board for boys and girls. I tried my luck and was lucky enough and made it work with SMF 1.1.3. If you are interested, I can attach the mod here. 
Please do not PM me for support · My Mods and Theme · SMF Coding Guidelines · Modifications Approval Guidelines

chette

Hey, I would be very interested in how you made this work.
chette

Bulakbol

#15
Quote from: chette on September 16, 2007, 12:32:27 PM
Hey, I would be very interested in how you made this work.

Hi.

- added a line of code to make their age 0 if user is over 99 years old.
- replaced the <options .... </options> to hold the right selected settings.
- added 2 fields (minAge and gender_sel) to the board fielset on installation.
Please do not PM me for support · My Mods and Theme · SMF Coding Guidelines · Modifications Approval Guidelines

Sakae

Hi I'm bumping this topic to know if your code works in 1.1.4 Johnny. Does it?
http://www.tigrelog.com.br
l: simple p: machines

Bulakbol

I am using 1.1.4 and am using the mod. It's working and I have no problem.
Please do not PM me for support · My Mods and Theme · SMF Coding Guidelines · Modifications Approval Guidelines

Private_Ale

Quote from: JohnyB on September 11, 2007, 03:22:17 AM
I was interested with this mod so I can create different board for boys and girls. I tried my luck and was lucky enough and made it work with SMF 1.1.3. If you are interested, I can attach the mod here. 

Hey Johny, can you attach the mod?
I will be very grateful as every time i try to use the supplied code it kills my test board lol.. :D

BeerCandle [nofollow] - Administrator
FileCabi.net [nofollow] - Moderator

Save all your prayers
I think we lost today
There's no morning after
No ones around to blame

Bulakbol

Sorry, I can't attach a file to my post. PM me your email address and I'll send you the file.
Please do not PM me for support · My Mods and Theme · SMF Coding Guidelines · Modifications Approval Guidelines

Advertisement: