<?php
$useavatar = iif($vbulletin->GPC['avatarid'] == -1, 0, 1);
$avataroverride = true;

$vbulletin->options['dbtech_vbshop_override_cancustomavatar_exempt'] = @unserialize($vbulletin->options['dbtech_vbshop_override_cancustomavatar_exempt']);
if (
	$useavatar AND
	$vbulletin->GPC['avatarid'] == 0 AND
	($vbulletin->userinfo['permissions']['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canuseavatar']) AND 
	$vbulletin->options['dbtech_vbshop_override_cancustomavatar'] AND 
	!is_member_of($vbulletin->userinfo, (array)$vbulletin->options['dbtech_vbshop_override_cancustomavatar_exempt'])
)
{
	// Verify purchases
	VBSHOP::verify_purchases($vbulletin->userinfo);
	
	foreach ($vbulletin->userinfo['dbtech_vbshop_purchase'] as $purchaseid => $purchase)
	{
		if ($purchase['feature'] != 'item' OR $purchase['userid'] != $vbulletin->userinfo['userid'])
		{
			// Skip the feature
			continue;
		}
		
		if (!$purchase['active'])
		{
			// Skip the feature
			continue;
		}
		
		if (!$item = VBSHOP::$cache[$purchase['feature']][$purchase['featureid']])
		{
			// Skip this
			continue;
		}

		if (!$item['active'])
		{
			// Skip this
			continue;
		}

		if ($item['itemtypeid'] != 'avatarchange')
		{
			// Skip this
			continue;
		}

		// We're not overriding permissions
		$avataroverride = false;
		break;
	}

	if ($avataroverride)
	{
		// Fake no permissions
		$vbulletin->userinfo['permissions']['genericpermissions'] -= $vbulletin->bf_ugp_genericpermissions['canuseavatar'];
	}
}
?>