Automatically Add Friend (like MySpace)

Hoxxy

New Member
Introduction
This modification acts somewhat like Myspace. When you register on Myspace, the creator of Myspace (Tom) is automatically added as a friend (mutually). This acts the same way on your forum by adding any number of users (user IDs required) to the new users friend list.

Requirements
vBulletin 3.7.x (This should work on ALL betas & RCs!)

Installation
Upload the attached product file by following this path:
ACP -> Plugins & Products -> Manage Products -> [Add/Import Product]
Head over to the vBulletin options, open up the "User Registration Options", and set a list of users under the "Automatically Add Friends" option.
Enjoy!
 

Hoxxy

New Member
Yeah... Well, since people want the fix here's the only problem...
PHP:
$userid
I'm sure you used that for good reason, and later on in the plugin code you also (correctly) use
PHP:
$userinfo[userid]
That's the same thing... So swapping them out resulted in the fix (I tested it, works great). In order to make this compatable with the e-mail activation here's the plugin

Plugin:
Add Friend After Validation

Hook:
register_activate_process

PHP:
if(!empty($vbulletin->options['kk_auto_friends']))
{
	$friends = explode(',', $vbulletin->options['kk_auto_friends']);
	
	foreach($friends AS $friendid)
	{
		$db->query("INSERT INTO " . TABLE_PREFIX . "userlist (userid, relationid, type, friend) VALUES ({$userinfo['userid']}, {$friendid}, 'buddy', 'yes')");
		if($vbulletin->options['kk_auto_friends_mutual'])
		{
			$db->query("INSERT INTO " . TABLE_PREFIX . "userlist (userid, relationid, type, friend) VALUES ({$friendid}, {$userinfo['userid']}, 'buddy', 'yes')");
		}
		$db->query_write("UPDATE " . TABLE_PREFIX . "user SET friendcount = friendcount + 1	WHERE userid IN ($userinfo[userid], " . $vbulletin->userinfo['userid'] . ")");
		$db->query_write("UPDATE " . TABLE_PREFIX . "user SET friendcount = friendcount + 1	WHERE userid={$friendid}");
	}
}


Plugin:
Automatically Add Friend

Hook:
register_addmember_complete
PHP:
if(!empty($vbulletin->options['kk_auto_friends']) && !$vbulletin->options['verifyemail'])
{
	$friends = explode(',', $vbulletin->options['kk_auto_friends']);
	foreach($friends AS $friendid)
	{
		$db->query("INSERT INTO " . TABLE_PREFIX . "userlist (userid, relationid, type, friend) VALUES ({$userinfo['userid']}, {$friendid}, 'buddy', 'yes')");
		if($vbulletin->options['kk_auto_friends_mutual'])
		{
			$db->query("INSERT INTO " . TABLE_PREFIX . "userlist (userid, relationid, type, friend) VALUES ({$friendid}, {$userinfo['userid']}, 'buddy', 'yes')");
		}
		$db->query_write("UPDATE " . TABLE_PREFIX . "user SET friendcount = friendcount + 1	WHERE userid IN ($userinfo[userid], " . $vbulletin->userinfo['userid'] . ")");
		$db->query_write("UPDATE " . TABLE_PREFIX . "user SET friendcount = friendcount + 1	WHERE userid={$friendid}");
	}
}
 
Top