<?php

// require_once 'tpl.inc';

class Template_V extends Template
{
	var $vartags = array();
	
	function set_vartag($vartag, $vartag_value)
	{
		$eval = $vartag_value;
		
		if (strpos($eval, '$') === false)
		{
			//$vartag_value is a constant value
			$eval="'".$eval."'";
		}
		else
		{
			//replace all $x with a $GLOBALS['x']
			$eval = preg_replace('/(\$)([a-zA-Z_0-9]{1,})/', '\$GLOBALS["\\2"]', $eval);
		}
		
		$eval = 'return '.$eval.';';
		
		$this->vartags[$vartag] = $eval;
	}
	
	
	function unset_vartag($vartag)
	{
		if (isset($this->vartags[$vartag]))
			unset($this->vartags[$vartag]);
	}
	
	
	function get_vartag_data($vartag)
	{
		return $this->vartags[$vartag];
	}
	
	
	function get_vartag_value($vartag)
	{
		if (isset($this->vartags[$vartag]))
			return eval($this->vartags[$vartag]);
		
		return "{{V_$vartag}}";
	}
	
	
	function get_info()
	{
		return array("info"=>"Get and set variables in a template", "version"=>1.1);
	}
}

?>