<?php
if (!class_exists('vBShop_Item_Core'))
{
	die('No direct access allowed.');
}

class vBShop_Item_usernamestyle2 extends vBShop_Item_Core
{
	/**
	* The constructor
	*
	* @param	vBulletin	vBulletin registry
	* @param	array		Item info
	*/	
	public function __construct(&$registry, &$item)
	{
		parent::__construct($registry, $item);
		
		// Set purchase template
		$this->config['purchasetemplate'] = 'dbtech_vbshop_configure_style';
		
		// HTML safe
		$this->config['code']['color'] = htmlspecialchars_uni($this->config['code']['color']);
		$this->config['code']['glow'] = htmlspecialchars_uni($this->config['code']['glow']);
		$this->config['code']['shadow'] = htmlspecialchars_uni($this->config['code']['shadow']);
	}
	
	/**
	* Function to call before every action
	*/	
	public function action()
	{
		if (!parent::action())
		{
			// This type is inactive
			return false;
		}
		
		// We made it!
		return true;
	}
	
	/**
	* Prints out an AdminCP form
	*/	
	public function print_admin_form($code)
	{
		global $vbphrase;
		
		print_checkbox_row($vbphrase['dbtech_vbshop_bold'], 			'item[code][bold]', 			$code['bold']);
		print_checkbox_row($vbphrase['dbtech_vbshop_italic'], 			'item[code][italic]', 			$code['italic']);
		print_checkbox_row($vbphrase['dbtech_vbshop_underline'], 		'item[code][underline]', 		$code['underline']);
		print_input_row($vbphrase['dbtech_vbshop_color'], 				'item[code][color]', 			$code['color']);
		print_checkbox_row($vbphrase['dbtech_vbshop_enable_glow'], 		'item[code][glow_onoff]', 		$code['glow_onoff']);
		print_input_row($vbphrase['dbtech_vbshop_glow_colour'], 		'item[code][glow]', 			$code['glow']);
		print_checkbox_row($vbphrase['dbtech_vbshop_enable_shadow'], 	'item[code][shadow_onoff]', 	$code['shadow_onoff']);
		print_input_row($vbphrase['dbtech_vbshop_shadow_colour'], 		'item[code][shadow]', 			$code['shadow']);
	}
	
	/**
	* Actions that override the musername / usertitle
	*
	* @param	array		User info
	* @param	integer		Display group id
	*/	
	public function fetch_musername(&$user, $displaygroupid)
	{
		if (!$this->config['active'])
		{
			// We're not doin this
			return false;
		}
		
		// By default, no open tag
		$this->config['code']['opentag'] = '';
		
		if ($this->config['code']['bold'])
		{
			// Bolded username
			$this->config['code']['opentag'] .= 'font-weight:bold; ';
		}
		
		if ($this->config['code']['italic'])
		{
			// Bolded username
			$this->config['code']['opentag'] .= 'font-style:italic; ';
		}
		
		if ($this->config['code']['underline'])
		{
			// Bolded username
			$this->config['code']['opentag'] .= 'text-decoration:underline; ';
		}
		
		if ($this->config['code']['color'])
		{
			// Bolded username
			$this->config['code']['opentag'] .= 'color:' . $this->config['code']['color'] . '; ';
		}
		
		if ($this->config['code']['glow_onoff'])
		{
			$this->config['code']['opentag'] .= 'text-shadow: 0px 0px 0.2em ' . $this->config['code']['glow'] . ', 0px 0px 0.2em ' . $this->config['code']['glow'] . ', 0px 0px 0.2em ' . $this->config['code']['glow'] . '; ';
			//  filter:progid:DXImageTransform.Microsoft.Glow(Color=#FF0000, Strength=5); _height:1px; 
		}
		
		if ($this->config['code']['shadow_onoff'])
		{
			$this->config['code']['opentag'] .= 'text-shadow:2px 2px 4px ' . $this->config['code']['shadow'] . '; ';
		}
		
		if ($this->config['code']['opentag'])
		{
			// Close the tag
			$this->config['code']['opentag'] = '<span style="' . $this->config['code']['opentag'] . '">';
			$this->config['code']['closetag'] = '</span>';
		}
		
		if (!empty($this->config['code']['opentag']))
		{
			// We've got musername 
			$user['musername'] = $this->registry->usergroupcache[$displaygroupid]['opentag'] . $this->config['code']['opentag'] . str_replace(array(
					$this->registry->usergroupcache[$displaygroupid]['opentag'],
					$this->registry->usergroupcache[$displaygroupid]['closetag']
				),
				'',
				$user['musername']) . $this->config['code']['closetag'] . $this->registry->usergroupcache[$displaygroupid]['closetag'];			
		}
	}	
}
?>