vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   Usergroup Based on Age (https://vborg.vbsupport.ru/showthread.php?t=298022)

KGodel 05-10-2013 05:59 PM

Usergroup Based on Age
 
Hey all.

I am trying to make a forum only accessible to a certain age group (18+). I figure the easiest way to do this is to make a usergroup as a secondary group for 18+ members. I want to create a simple plugin or scheduled task that will run and automatically add the additional usergroup to people who are 18+. Can anyone give me some advice on where to start?

kh99 05-10-2013 06:28 PM

I did this on my site by hacking the promotion system (it required code changes as opposed to plugins). I had to change admincp/usergroup.php to add a promotion strategy, and includes/cron/promotion.php to implement it. If you want I could give you the changes I made, in diff format or something. I did it in vb3, but the code for those files didn't change much for vb4 so it shouldn't be hard to figure out.

KGodel 05-10-2013 06:33 PM

Would that method be easier than doing what I proposed? If so I'm definitely open to it.

kh99 05-10-2013 06:46 PM

Well, I guess it's easier because I have it done already, but it requires changing files. It does take advantage of the promotion code that uses a scheduled task to add a secondary group to a user. You could write your own code and use a plugin with one of the cron hooks and then you wouldn't need to modify any files, but you'd have to handle it all yourself.

I'll post my changes and you can use it or do it a different way (even if you don't use these, you might look at promotion.php and see how it works).

Anyway, in admincp/usergroup.php, find:
Code:

        foreach($promotions AS $groupid => $promos)
        {
                print_table_header("$vbphrase[promotions]: <span style=\"font-weight:normal\">" . $vbulletin->usergroupcache["$groupid"]['title'] . ' ' . construct_link_code($vbphrase['add_new_promotion'], "usergroup.php?" . $vbulletin->session->vars['sessionurl'] . "do=updatepromotion&amp;usergroupid=$groupid" . ($vbulletin->GPC['returnug'] ? '&amp;returnug=1' : '')) . "</span>", 8);
                print_cells_row(array(
                        $vbphrase['usergroup'],

and change the 7 to 8 (in red, scroll all the way to the right to see it).

Then find this and add the section in red, and change the lines in blue:
Code:

                        else if ($promotion['strategy'] == 18)
                        {
                                $type = $vbphrase['join_date'];
                        }
                        else if ($promotion['strategy'] == 32)
                        {
                                $type = 'Age >= 18';
                        }
                        else
                        {
                                $type = $vbphrase['promotion_strategy' . ($promotion['strategy'] + 1)];
                        }
                        print_cells_row(array(
                                "<b>$promotion[title]</b>",
                                iif($promotion['type']==1, $vbphrase['primary_usergroup'], $vbphrase['additional_usergroups']),
                                $type,
                                iif($promotion['strategy'] != 32, $promotion['reputation'], 'N/A'),
                                iif($promotion['strategy'] != 32, $promotion['date'], 'N/A'),
                                iif($promotion['strategy'] != 32, $promotion['posts'], 'N/A'),
                                construct_link_code($vbphrase['edit'], "usergroup.php?" . $vbulletin->session->vars['sessionurl'] . "userpromotionid=$promotion[userpromotionid]&do=updatepromotion" . ($vbulletin->GPC['returnug'] ? '&returnug=1' : '')) . construct_link_code($vbphrase['delete'], "usergroup.php?" . $vbulletin->session->vars['sessionurl'] . "userpromotionid=$promotion[userpromotionid]&do=removepromotion" . ($vbulletin->GPC['returnug'] ? '&returnug=1' : '')),
                        ));

Then farther down, find this and add the line in red:
Code:

        $promotionarray = array(
                32=> 'Age >= 18',
                17=> $vbphrase['posts'],
                18=> $vbphrase['join_date'],
                16=> $vbphrase['reputation'],

I'll put changes for promotion.php in the next post.

kh99 05-10-2013 06:53 PM

In includes/cron/promotion.php, find this and add the line in red:
Code:

        SELECT user.joindate, user.userid, user.membergroupids, user.posts, user.reputation,
                user.usergroupid, user.displaygroupid, user.customtitle, user.username, user.ipoints,
                YEAR(user.birthday_search) AS birth_year, MONTH(user.birthday_search) AS birth_month, DAY(user.birthday_search) AS birth_day,
                userpromotion.joinusergroupid, userpromotion.reputation AS jumpreputation, userpromotion.posts AS jumpposts,
                userpromotion.date AS jumpdate, userpromotion.type, userpromotion.strategy,
                usergroup.title, usergroup.usertitle AS ug_usertitle,
                usertextfield.rank


More lines to add:
Code:

$secondarynames = array();
$titles = array();
$today = getdate(TIMENOW);
$min_age = 18;

while ($promotion = $vbulletin->db->fetch_array($promotions))
{


And another:
Code:

                $posts = false;
                $joindate = false;
                $age = false;
                // These strategies are negative reputation checking
                if (($promotion['strategy'] > 7 AND $promotion['strategy'] < 16) OR $promotion['strategy'] == 24)


And another:
Code:

                if ($daysregged >= $promotion['jumpdate'])
                {
                        $joindate = true;
                }
                if ($promotion['birth_year'] > 1900 AND
                    $promotion['birth_month'] >= 1 AND $promotion['birth_month'] <= 12 AND
                    $promotion['birth_day'] >= 1 AND $promotion['birth_day'] <= 31)
                {
                    $yeardiff = $today['year'] - $promotion['birth_year'];
                    if ($yeardiff > $min_age OR
                        ($yeardiff == $min_age AND
                              ($today['mon'] > $promotion['birth_month'] OR
                                      ($today['mon'] == $promotion['birth_month'] AND $today['mday'] >= $promotion['birth_day']))))
                    {
                        $age = true;
                    }
                }

                if ($promotion['strategy'] == 17)
                {
                        $dojoin = iif($posts, true, false);
                }


Last one:
Code:

else if ($promotion['strategy'] == 16 OR $promotion['strategy'] == 24)
                {
                        $dojoin = iif($reputation, true, false);
                }
                else if ($promotion['strategy'] == 32)
                {
                        $dojoin = iif($age, true, false);
                }
                else
                {
                        switch($promotion['strategy'])


Then of course you need to go to the Promotions manager and add a promotion using the new "Age >= 18" strategy. The way promotions work is when the scheduled task runs it will promote everyone who's eligible and who has been active recently. If you want to immediately promote everyone who's eligible, you can run the scheduled task manually from the Scheduled Task manager.


All times are GMT. The time now is 10:25 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01629 seconds
  • Memory Usage 1,739KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (8)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete