<?php
global $vbulletin;

if (intval($vbulletin->versionnumber) == 3 AND !class_exists('vB_Template'))
{
	// We need the template class
	require_once(DIR . '/dbtech/vbshop/includes/class_template.php');
}	

if (!class_exists('VBSHOP'))
{
	global $show, $specialtemplates;
	
	// Fetch required classes
	require_once(DIR . '/dbtech/vbshop/includes/class_core.php');
	require_once(DIR . '/dbtech/vbshop/includes/class_cache.php');
	
	if (isset($this) AND is_object($this))
	{
		// Loads the cache class
		VBSHOP_CACHE::init($vbulletin, $this->datastore_entries);
	}
	else
	{
		// Loads the cache class
		VBSHOP_CACHE::init($vbulletin, $specialtemplates);
	}
	
	foreach (VBSHOP::$cache['itemtype'] as $typeid => $type)
	{
		if (!file_exists(DIR . $type['filename']))
		{
			// Probably Pro onry
			VBSHOP::$cache['itemtype'][$typeid]['settings'] = VBSHOP::$cache['itemtype'][$typeid]['active'] = 0;
		}
	}
	
	if (!isset($vbulletin->bf_ugp_dbtech_vbshoppermissions['isexcluded']) OR !$vbulletin->bf_ugp_dbtech_vbshoppermissions['isexcluded'])
	{
		// For some reason.
		$vbulletin->bf_ugp_dbtech_vbshoppermissions['isexcluded'] = 16;
	}
	
	// Initialise forumon
	VBSHOP::init($vbulletin);
	
	if (VBSHOP::$permissions['canview'])
	{
		$show['vbshop'] = $vbulletin->options['dbtech_vbshop_navbar'];
		$show['vbshop_ispro'] = VBSHOP::$isPro;
		if ($vbulletin->options['dbtech_vbshop_integration'] & 1)
		{
			$show['vbshop_ql'] = true;
		}
		if ($vbulletin->options['dbtech_vbshop_integration'] & 2)
		{
			$show['vbshop_com'] = true;
		}
	}

	// Show branding or not
	$show['vbshop_branding'] = $vbulletin->options['dbtech_vbshop_branding_free'] != base64_decode('dmJ3YXJlei5uZXQ=');
	$show['dbtech_vbshop_producttype'] = (VBSHOP::$isPro ? ' (Pro)' : ' (Lite)');

	if (THIS_SCRIPT == 'vbshop' AND $show['vbshop_branding'] AND !$show['_dbtech_branding_override'])
	{
		$brandingVariables = array(
			'flavour' 			=> 'Forum Shop provided by ',
			'productid' 		=> 50,
			'utm_source' 		=> str_replace('www.', '', htmlspecialchars_uni($_SERVER['HTTP_HOST'])),		
			'utm_content' 		=> (VBSHOP::$isPro ? 'Pro' : 'Lite'),
			'referrerid' 		=> $vbulletin->options['dbtech_vbshop_referral'],
			'title' 			=> 'vBShop',
			'displayversion' 	=> $vbulletin->options['dbtech_vbshop_displayversion'],
			'version' 			=> '3.2.3',
			'producttype' 		=> $show['dbtech_vbshop_producttype'],
			'showhivel' 		=> (!VBSHOP::$isPro AND !$vbulletin->options['dbtech_vbshop_nohivel'])
		);

		$str = $brandingVariables['flavour'] . '
			<a rel="nofollow" href="http://www.dragonbyte-tech.com/vbecommerce.php' . ($brandingVariables['productid'] ? '?productid=' . $brandingVariables['productid'] . '&do=product&' : '?') . 'utm_source=' . $brandingVariables['utm_source'] . '&utm_campaign=product&utm_medium=' . urlencode(str_replace(' ', '+', $brandingVariables['title'])) . '&utm_content=' . $brandingVariables['utm_content'] . ($brandingVariables['referrerid'] ? '&referrerid=' . $brandingVariables['referrerid'] : '') . '" target="_blank">' . $brandingVariables['title'] . ($brandingVariables['displayversion'] ? ' v' . $brandingVariables['version'] : '') . $brandingVariables['producttype'] . '</a> - 
			<a rel="nofollow" href="http://www.dragonbyte-tech.com/?utm_source=' . $brandingVariables['utm_source'] . '&utm_campaign=site&utm_medium=' . urlencode(str_replace(' ', '+', $brandingVariables['title'])) . '&utm_content=' . $brandingVariables['utm_content'] . ($brandingVariables['referrerid'] ? '&referrerid=' . $brandingVariables['referrerid'] : '') . '" target="_blank">vBulletin Mods &amp; Addons</a> Copyright &copy; ' . date('Y') . ' DragonByte Technologies Ltd.' . 
			($brandingVariables['showhivel'] ? ' Runs best on <a rel="nofollow" href="http://www.hivelocity.net/?utm_source=Iain%2BKidd&utm_medium=back%2Blink&utm_term=Dedicated%2BServer%2BSponsor&utm_campaign=Back%2BLinks%2Bfrom%2BIain%2BKidd" target="_blank">HiVelocity Hosting</a>.' : '');
		$vbulletin->options['copyrighttext'] = (trim($vbulletin->options['copyrighttext']) != '' ? $str . '<br />' . $vbulletin->options['copyrighttext'] : $str);
	}
	
	foreach ((array)VBSHOP::$cache['currency'] as $currencyid => $currency)
	{
		// Create a quick view for the amount of points we have
		$show['vbshop_' . $currency['pointscolumn']] = $currency['title'] . ': ' . (isset($vbulletin->userinfo[$currency['pointscolumn']]) ? $vbulletin->userinfo[$currency['pointscolumn']] : 0);
	}

	// reset musername
	unset($vbulletin->userinfo['musername']);
	fetch_musername($vbulletin->userinfo);	
}
?>