Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
  #1  
Old 05-10-2013, 06:59 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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?
Reply With Quote
  #2  
Old 05-10-2013, 07:28 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 05-10-2013, 07:33 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Would that method be easier than doing what I proposed? If so I'm definitely open to it.
Reply With Quote
  #4  
Old 05-10-2013, 07:46 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Благодарность от:
AzzazelCyC
  #5  
Old 05-10-2013, 07:53 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Благодарность от:
tbworld
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:03 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04129 seconds
  • Memory Usage 2,210KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (8)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (2)post_thanks_box_bit
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete