<?php

if(!defined('IN_MYBB'))
	die('This file cannot be accessed directly.');

$plugins->add_hook('member_profile_end', 'grpinprof_run');

function grpinprof_info()
{
	return array(
		'name'			=> 'Memberships in Profile',
		'description'	=> 'Displays what usergroups a user is in on their profile page.',
		'website'		=> 'http://mybbhacks.zingaburga.com/',
		'author'		=> 'ZiNgA BuRgA',
		'authorsite'	=> 'http://zingaburga.com/',
		'version'		=> '1.0',
		'compatibility'	=> '1*',
		'guid'			=> ''
	);
}

// need to add {$pmy_group} and {$sec_groups} to member_profile template

function grpinprof_activate()
{
	require MYBB_ROOT.'inc/adminfunctions_templates.php';
	find_replace_templatesets('member_profile', '#\{\$memregdate\}\<br /\>#', '$0<strong>Group Memberships</strong>: <strong>{$pmy_group}</strong>{$sec_groups}<br />');
}

function grpinprof_deactivate()
{
	require MYBB_ROOT.'inc/adminfunctions_templates.php';
	find_replace_templatesets('member_profile', '#'.preg_quote('<strong>Group Memberships</strong>: <strong>{$pmy_group}</strong>{$sec_groups}<br />').'#', '', 0);
}

function grpinprof_run()
{
	global $groupscache, $pmy_group, $sec_groups, $memprofile;
	if(!is_array($groupscache))
	{
		global $cache;
		$groupscache = $cache->read('usergroups');
	}
	$ug = &$groupscache[$memprofile['usergroup']];
	$pmy_group = format_name($ug['title'], $ug['gid'], 0);
	
	$sec_groups = $comma = '';
	$sug = array_unique(explode(',',$memprofile['additionalgroups']));
	foreach($sug as $gid)
	{
		$ug = &$groupscache[$gid];
		if(!isset($ug)) continue;
		$sec_groups .= $comma.format_name($ug['title'], $ug['gid'], 0);
		if(!$comma) $comma = ', ';
	}
	if($sec_groups)
	{
		$sec_groups = ', '.$sec_groups;
	}
}

?>