Blame Identity/Models/Html/phpBB/3.0.4/includes/template.php

d6e8d8
d6e8d8
/**
d6e8d8
*
d6e8d8
* @package phpBB3
d6e8d8
* @version $Id: template.php 8943 2008-09-26 13:09:56Z acydburn $
d6e8d8
* @copyright (c) 2005 phpBB Group, sections (c) 2001 ispi of Lincoln Inc
d6e8d8
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
d6e8d8
*
d6e8d8
*/
d6e8d8
d6e8d8
/**
d6e8d8
* @ignore
d6e8d8
*/
d6e8d8
if (!defined('IN_PHPBB'))
d6e8d8
{
d6e8d8
	exit;
d6e8d8
}
d6e8d8
d6e8d8
/**
d6e8d8
* Base Template class.
d6e8d8
* @package phpBB3
d6e8d8
*/
d6e8d8
class template
d6e8d8
{
d6e8d8
	/** variable that holds all the data we'll be substituting into
d6e8d8
	* the compiled templates. Takes form:
d6e8d8
	* --> $this->_tpldata[block][iteration#][child][iteration#][child2][iteration#][variablename] == value
d6e8d8
	* if it's a root-level variable, it'll be like this:
d6e8d8
	* --> $this->_tpldata[.][0][varname] == value
d6e8d8
	*/
d6e8d8
	var $_tpldata = array('.' => array(0 => array()));
d6e8d8
	var $_rootref;
d6e8d8
d6e8d8
	// Root dir and hash of filenames for each template handle.
d6e8d8
	var $root = '';
d6e8d8
	var $cachepath = '';
d6e8d8
	var $files = array();
d6e8d8
	var $filename = array();
d6e8d8
	var $files_inherit = array();
d6e8d8
	var $files_template = array();
d6e8d8
	var $inherit_root = '';
d6e8d8
d6e8d8
	// this will hash handle names to the compiled/uncompiled code for that handle.
d6e8d8
	var $compiled_code = array();
d6e8d8
d6e8d8
	/**
d6e8d8
	* Set template location
d6e8d8
	* @access public
d6e8d8
	*/
d6e8d8
	function set_template()
d6e8d8
	{
d6e8d8
		global $phpbb_root_path, $user;
d6e8d8
d6e8d8
		if (file_exists($phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template'))
d6e8d8
		{
d6e8d8
			$this->root = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template';
d6e8d8
			$this->cachepath = $phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $user->theme['template_path']) . '_';
d6e8d8
			
d6e8d8
			if ($user->theme['template_inherits_id'])
d6e8d8
			{
d6e8d8
				$this->inherit_root = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template';
d6e8d8
			}
d6e8d8
		}
d6e8d8
		else
d6e8d8
		{
d6e8d8
			trigger_error('Template path could not be found: styles/' . $user->theme['template_path'] . '/template', E_USER_ERROR);
d6e8d8
		}
d6e8d8
d6e8d8
		$this->_rootref = &$this->_tpldata['.'][0];
d6e8d8
d6e8d8
		return true;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Set custom template location (able to use directory outside of phpBB)
d6e8d8
	* @access public
d6e8d8
	*/
d6e8d8
	function set_custom_template($template_path, $template_name)
d6e8d8
	{
d6e8d8
		global $phpbb_root_path;
d6e8d8
d6e8d8
		$this->root = $template_path;
d6e8d8
		$this->cachepath = $phpbb_root_path . 'cache/ctpl_' . str_replace('_', '-', $template_name) . '_';
d6e8d8
d6e8d8
		return true;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Sets the template filenames for handles. $filename_array
d6e8d8
	* should be a hash of handle => filename pairs.
d6e8d8
	* @access public
d6e8d8
	*/
d6e8d8
	function set_filenames($filename_array)
d6e8d8
	{
d6e8d8
		if (!is_array($filename_array))
d6e8d8
		{
d6e8d8
			return false;
d6e8d8
		}
d6e8d8
		foreach ($filename_array as $handle => $filename)
d6e8d8
		{
d6e8d8
			if (empty($filename))
d6e8d8
			{
d6e8d8
				trigger_error("template->set_filenames: Empty filename specified for $handle", E_USER_ERROR);
d6e8d8
			}
d6e8d8
d6e8d8
			$this->filename[$handle] = $filename;
d6e8d8
			$this->files[$handle] = $this->root . '/' . $filename;
d6e8d8
			
d6e8d8
			if ($this->inherit_root)
d6e8d8
			{
d6e8d8
				$this->files_inherit[$handle] = $this->inherit_root . '/' . $filename;
d6e8d8
			}
d6e8d8
		}
d6e8d8
		
d6e8d8
		return true;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Destroy template data set
d6e8d8
	* @access public
d6e8d8
	*/
d6e8d8
	function destroy()
d6e8d8
	{
d6e8d8
		$this->_tpldata = array('.' => array(0 => array()));
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Reset/empty complete block
d6e8d8
	* @access public
d6e8d8
	*/
d6e8d8
	function destroy_block_vars($blockname)
d6e8d8
	{
d6e8d8
		if (strpos($blockname, '.') !== false)
d6e8d8
		{
d6e8d8
			// Nested block.
d6e8d8
			$blocks = explode('.', $blockname);
d6e8d8
			$blockcount = sizeof($blocks) - 1;
d6e8d8
d6e8d8
			$str = &$this->_tpldata;
d6e8d8
			for ($i = 0; $i < $blockcount; $i++)
d6e8d8
			{
d6e8d8
				$str = &$str[$blocks[$i]];
d6e8d8
				$str = &$str[sizeof($str) - 1];
d6e8d8
			}
d6e8d8
d6e8d8
			unset($str[$blocks[$blockcount]]);
d6e8d8
		}
d6e8d8
		else
d6e8d8
		{
d6e8d8
			// Top-level block.
d6e8d8
			unset($this->_tpldata[$blockname]);
d6e8d8
		}
d6e8d8
d6e8d8
		return true;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Display handle
d6e8d8
	* @access public
d6e8d8
	*/
d6e8d8
	function display($handle, $include_once = true)
d6e8d8
	{
d6e8d8
		global $user, $phpbb_hook;
d6e8d8
d6e8d8
		if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, __FUNCTION__), $handle, $include_once))
d6e8d8
		{
d6e8d8
			if ($phpbb_hook->hook_return(array(__CLASS__, __FUNCTION__)))
d6e8d8
			{
d6e8d8
				return $phpbb_hook->hook_return_result(array(__CLASS__, __FUNCTION__));
d6e8d8
			}
d6e8d8
		}
d6e8d8
d6e8d8
		if (defined('IN_ERROR_HANDLER'))
d6e8d8
		{
d6e8d8
			if ((E_NOTICE & error_reporting()) == E_NOTICE)
d6e8d8
			{
d6e8d8
				error_reporting(error_reporting() ^ E_NOTICE);
d6e8d8
			}
d6e8d8
		}
d6e8d8
d6e8d8
		if ($filename = $this->_tpl_load($handle))
d6e8d8
		{
d6e8d8
			($include_once) ? include_once($filename) : include($filename);
d6e8d8
		}
d6e8d8
		else
d6e8d8
		{
d6e8d8
			eval(' ?>' . $this->compiled_code[$handle] . '
d6e8d8
		}
d6e8d8
d6e8d8
		return true;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Display the handle and assign the output to a template variable or return the compiled result.
d6e8d8
	* @access public
d6e8d8
	*/
d6e8d8
	function assign_display($handle, $template_var = '', $return_content = true, $include_once = false)
d6e8d8
	{
d6e8d8
		ob_start();
d6e8d8
		$this->display($handle, $include_once);
d6e8d8
		$contents = ob_get_clean();
d6e8d8
d6e8d8
		if ($return_content)
d6e8d8
		{
d6e8d8
			return $contents;
d6e8d8
		}
d6e8d8
d6e8d8
		$this->assign_var($template_var, $contents);
d6e8d8
d6e8d8
		return true;
d6e8d8
	}
d6e8d8
	
d6e8d8
	/**
d6e8d8
	* Load a compiled template if possible, if not, recompile it
d6e8d8
	* @access private
d6e8d8
	*/
d6e8d8
	function _tpl_load(&$handle)
d6e8d8
	{
d6e8d8
		global $user, $phpEx, $config;
d6e8d8
d6e8d8
		$filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . '.' . $phpEx;
d6e8d8
		$this->files_template[$handle] = $user->theme['template_id'];
d6e8d8
		
d6e8d8
		$recompile = false;
d6e8d8
		if (!file_exists($filename) || @filesize($filename) === 0)
d6e8d8
		{
d6e8d8
			$recompile = true;
d6e8d8
		}
d6e8d8
		else if ($config['load_tplcompile'])
d6e8d8
		{
d6e8d8
			// No way around it: we need to check inheritance here
d6e8d8
			if ($user->theme['template_inherits_id'] && !file_exists($this->files[$handle]))
d6e8d8
			{
d6e8d8
				$this->files[$handle] = $this->files_inherit[$handle];
d6e8d8
				$this->files_template[$handle] = $user->theme['template_inherits_id'];
d6e8d8
			}
d6e8d8
			$recompile = (@filemtime($filename) < filemtime($this->files[$handle])) ? true : false;
d6e8d8
		}
d6e8d8
		
d6e8d8
		// Recompile page if the original template is newer, otherwise load the compiled version
d6e8d8
		if (!$recompile)
d6e8d8
		{
d6e8d8
			return $filename;
d6e8d8
		}
d6e8d8
d6e8d8
		global $db, $phpbb_root_path;
d6e8d8
d6e8d8
		if (!class_exists('template_compile'))
d6e8d8
		{
d6e8d8
			include($phpbb_root_path . 'includes/functions_template.' . $phpEx);
d6e8d8
		}
d6e8d8
		
d6e8d8
		// Inheritance - we point to another template file for this one. Equality is also used for store_db
d6e8d8
		if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($this->files[$handle]))
d6e8d8
		{
d6e8d8
			$this->files[$handle] = $this->files_inherit[$handle];
d6e8d8
			$this->files_template[$handle] = $user->theme['template_inherits_id'];
d6e8d8
		}
d6e8d8
		
d6e8d8
		$compile = new template_compile($this);
d6e8d8
d6e8d8
		// If we don't have a file assigned to this handle, die.
d6e8d8
		if (!isset($this->files[$handle]))
d6e8d8
		{
d6e8d8
			trigger_error("template->_tpl_load(): No file specified for handle $handle", E_USER_ERROR);
d6e8d8
		}
d6e8d8
d6e8d8
		// Just compile if no user object is present (happens within the installer)
d6e8d8
		if (!$user)
d6e8d8
		{
d6e8d8
			$compile->_tpl_load_file($handle);
d6e8d8
			return false;
d6e8d8
		}
d6e8d8
d6e8d8
		if (isset($user->theme['template_storedb']) && $user->theme['template_storedb'])
d6e8d8
		{
d6e8d8
			$rows = array();
d6e8d8
			$ids = array();
d6e8d8
			// Inheritance
d6e8d8
			if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'])
d6e8d8
			{
d6e8d8
				$ids[] = $user->theme['template_inherits_id'];
d6e8d8
			}
d6e8d8
			$ids[] = $user->theme['template_id'];
d6e8d8
			
d6e8d8
			foreach ($ids as $id)
d6e8d8
			{
d6e8d8
				$sql = 'SELECT *
d6e8d8
				FROM ' . STYLES_TEMPLATE_DATA_TABLE . '
d6e8d8
				WHERE template_id = ' . $id . "
d6e8d8
					AND (template_filename = '" . $db->sql_escape($this->filename[$handle]) . "'
d6e8d8
						OR template_included " . $db->sql_like_expression($db->any_char . $this->filename[$handle] . ':' . $db->any_char) . ')';
d6e8d8
			
d6e8d8
				$result = $db->sql_query($sql);
d6e8d8
				while ($row = $db->sql_fetchrow($result))
d6e8d8
				{
d6e8d8
					$rows[$row['template_filename']] = $row;
d6e8d8
				}
d6e8d8
				$db->sql_freeresult($result);
d6e8d8
			}
d6e8d8
					
d6e8d8
			if (sizeof($rows))
d6e8d8
			{
d6e8d8
				foreach ($rows as $row)
d6e8d8
				{
d6e8d8
					$file = $this->root . '/' . $row['template_filename'];
d6e8d8
					$force_reload = false;
d6e8d8
					if ($row['template_id'] != $user->theme['template_id'])
d6e8d8
					{
d6e8d8
						// make sure that we are not overlooking a file not in the db yet
d6e8d8
						if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($file))
d6e8d8
						{
d6e8d8
							$file = $this->inherit_root . '/' . $row['template_filename'];
d6e8d8
							$this->files[$row['template_filename']] = $file;
d6e8d8
							$this->files_inherit[$row['template_filename']] = $file;
d6e8d8
							$this->files_template[$row['template_filename']] = $user->theme['template_inherits_id'];
d6e8d8
						}
d6e8d8
						else if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'])
d6e8d8
						{
d6e8d8
							// Ok, we have a situation. There is a file in the subtemplate, but nothing in the DB. We have to fix that.
d6e8d8
							$force_reload = true;
d6e8d8
							$this->files_template[$row['template_filename']] = $user->theme['template_inherits_id'];
d6e8d8
						}
d6e8d8
					}
d6e8d8
					else
d6e8d8
					{
d6e8d8
						$this->files_template[$row['template_filename']] = $user->theme['template_id'];
d6e8d8
					}
d6e8d8
					
d6e8d8
					if ($force_reload || $row['template_mtime'] < filemtime($file))
d6e8d8
					{
d6e8d8
						if ($row['template_filename'] == $this->filename[$handle])
d6e8d8
						{
d6e8d8
							$compile->_tpl_load_file($handle, true);
d6e8d8
						}
d6e8d8
						else
d6e8d8
						{
d6e8d8
							$this->files[$row['template_filename']] = $file;
d6e8d8
							$this->filename[$row['template_filename']] = $row['template_filename'];
d6e8d8
							$compile->_tpl_load_file($row['template_filename'], true);
d6e8d8
							unset($this->compiled_code[$row['template_filename']]);
d6e8d8
							unset($this->files[$row['template_filename']]);
d6e8d8
							unset($this->filename[$row['template_filename']]);
d6e8d8
						}
d6e8d8
					}
d6e8d8
d6e8d8
					if ($row['template_filename'] == $this->filename[$handle])
d6e8d8
					{
d6e8d8
						$this->compiled_code[$handle] = $compile->compile(trim($row['template_data']));
d6e8d8
						$compile->compile_write($handle, $this->compiled_code[$handle]);
d6e8d8
					}
d6e8d8
					else
d6e8d8
					{
d6e8d8
						// Only bother compiling if it doesn't already exist
d6e8d8
						if (!file_exists($this->cachepath . str_replace('/', '.', $row['template_filename']) . '.' . $phpEx))
d6e8d8
						{
d6e8d8
							$this->filename[$row['template_filename']] = $row['template_filename'];
d6e8d8
							$compile->compile_write($row['template_filename'], $compile->compile(trim($row['template_data'])));
d6e8d8
							unset($this->filename[$row['template_filename']]);
d6e8d8
						}
d6e8d8
					}
d6e8d8
				}
d6e8d8
			}
d6e8d8
			else
d6e8d8
			{
d6e8d8
				$file = $this->root . '/' . $row['template_filename'];
d6e8d8
d6e8d8
				if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($file))
d6e8d8
				{
d6e8d8
					$file = $this->inherit_root . '/' . $row['template_filename'];
d6e8d8
					$this->files[$row['template_filename']] = $file;
d6e8d8
					$this->files_inherit[$row['template_filename']] = $file;
d6e8d8
					$this->files_template[$row['template_filename']] = $user->theme['template_inherits_id'];
d6e8d8
				}
d6e8d8
				// Try to load from filesystem and instruct to insert into the styles table...
d6e8d8
				$compile->_tpl_load_file($handle, true);
d6e8d8
				return false;
d6e8d8
			}
d6e8d8
d6e8d8
			return false;
d6e8d8
		}
d6e8d8
d6e8d8
		$compile->_tpl_load_file($handle);
d6e8d8
		return false;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Assign key variable pairs from an array
d6e8d8
	* @access public
d6e8d8
	*/
d6e8d8
	function assign_vars($vararray)
d6e8d8
	{
d6e8d8
		foreach ($vararray as $key => $val)
d6e8d8
		{
d6e8d8
			$this->_rootref[$key] = $val;
d6e8d8
		}
d6e8d8
d6e8d8
		return true;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Assign a single variable to a single key
d6e8d8
	* @access public
d6e8d8
	*/
d6e8d8
	function assign_var($varname, $varval)
d6e8d8
	{
d6e8d8
		$this->_rootref[$varname] = $varval;
d6e8d8
d6e8d8
		return true;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Assign key variable pairs from an array to a specified block
d6e8d8
	* @access public
d6e8d8
	*/
d6e8d8
	function assign_block_vars($blockname, $vararray)
d6e8d8
	{
d6e8d8
		if (strpos($blockname, '.') !== false)
d6e8d8
		{
d6e8d8
			// Nested block.
d6e8d8
			$blocks = explode('.', $blockname);
d6e8d8
			$blockcount = sizeof($blocks) - 1;
d6e8d8
d6e8d8
			$str = &$this->_tpldata;
d6e8d8
			for ($i = 0; $i < $blockcount; $i++)
d6e8d8
			{
d6e8d8
				$str = &$str[$blocks[$i]];
d6e8d8
				$str = &$str[sizeof($str) - 1];
d6e8d8
			}
d6e8d8
d6e8d8
			$s_row_count = isset($str[$blocks[$blockcount]]) ? sizeof($str[$blocks[$blockcount]]) : 0;
d6e8d8
			$vararray['S_ROW_COUNT'] = $s_row_count;
d6e8d8
d6e8d8
			// Assign S_FIRST_ROW
d6e8d8
			if (!$s_row_count)
d6e8d8
			{
d6e8d8
				$vararray['S_FIRST_ROW'] = true;
d6e8d8
			}
d6e8d8
d6e8d8
			// Now the tricky part, we always assign S_LAST_ROW and remove the entry before
d6e8d8
			// This is much more clever than going through the complete template data on display (phew)
d6e8d8
			$vararray['S_LAST_ROW'] = true;
d6e8d8
			if ($s_row_count > 0)
d6e8d8
			{
d6e8d8
				unset($str[$blocks[$blockcount]][($s_row_count - 1)]['S_LAST_ROW']);
d6e8d8
			}
d6e8d8
d6e8d8
			// Now we add the block that we're actually assigning to.
d6e8d8
			// We're adding a new iteration to this block with the given
d6e8d8
			// variable assignments.
d6e8d8
			$str[$blocks[$blockcount]][] = $vararray;
d6e8d8
		}
d6e8d8
		else
d6e8d8
		{
d6e8d8
			// Top-level block.
d6e8d8
			$s_row_count = (isset($this->_tpldata[$blockname])) ? sizeof($this->_tpldata[$blockname]) : 0;
d6e8d8
			$vararray['S_ROW_COUNT'] = $s_row_count;
d6e8d8
d6e8d8
			// Assign S_FIRST_ROW
d6e8d8
			if (!$s_row_count)
d6e8d8
			{
d6e8d8
				$vararray['S_FIRST_ROW'] = true;
d6e8d8
			}
d6e8d8
d6e8d8
			// We always assign S_LAST_ROW and remove the entry before
d6e8d8
			$vararray['S_LAST_ROW'] = true;
d6e8d8
			if ($s_row_count > 0)
d6e8d8
			{
d6e8d8
				unset($this->_tpldata[$blockname][($s_row_count - 1)]['S_LAST_ROW']);
d6e8d8
			}
d6e8d8
			
d6e8d8
			// Add a new iteration to this block with the variable assignments we were given.
d6e8d8
			$this->_tpldata[$blockname][] = $vararray;
d6e8d8
		}
d6e8d8
d6e8d8
		return true;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Change already assigned key variable pair (one-dimensional - single loop entry)
d6e8d8
	*
d6e8d8
	* An example of how to use this function:
d6e8d8
	* {@example alter_block_array.php}
d6e8d8
	*
d6e8d8
	* @param	string	$blockname	the blockname, for example 'loop'
d6e8d8
	* @param	array	$vararray	the var array to insert/add or merge
d6e8d8
	* @param	mixed	$key		Key to search for
d6e8d8
	*
d6e8d8
	* array: KEY => VALUE [the key/value pair to search for within the loop to determine the correct position]
d6e8d8
	*
d6e8d8
	* int: Position [the position to change or insert at directly given]
d6e8d8
	*
d6e8d8
	* If key is false the position is set to 0
d6e8d8
	* If key is true the position is set to the last entry
d6e8d8
	*
d6e8d8
	* @param	string	$mode		Mode to execute (valid modes are 'insert' and 'change')
d6e8d8
	*
d6e8d8
	*	If insert, the vararray is inserted at the given position (position counting from zero).
d6e8d8
	*	If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new value).
d6e8d8
	*
d6e8d8
	* Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array)
d6e8d8
	* and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars)
d6e8d8
	*
d6e8d8
	* @return bool false on error, true on success
d6e8d8
	* @access public
d6e8d8
	*/
d6e8d8
	function alter_block_array($blockname, $vararray, $key = false, $mode = 'insert')
d6e8d8
	{
d6e8d8
		if (strpos($blockname, '.') !== false)
d6e8d8
		{
d6e8d8
			// Nested blocks are not supported
d6e8d8
			return false;
d6e8d8
		}
d6e8d8
		
d6e8d8
		// Change key to zero (change first position) if false and to last position if true
d6e8d8
		if ($key === false || $key === true)
d6e8d8
		{
d6e8d8
			$key = ($key === false) ? 0 : sizeof($this->_tpldata[$blockname]);
d6e8d8
		}
d6e8d8
d6e8d8
		// Get correct position if array given
d6e8d8
		if (is_array($key))
d6e8d8
		{
d6e8d8
			// Search array to get correct position
d6e8d8
			list($search_key, $search_value) = @each($key);
d6e8d8
d6e8d8
			$key = NULL;
d6e8d8
			foreach ($this->_tpldata[$blockname] as $i => $val_ary)
d6e8d8
			{
d6e8d8
				if ($val_ary[$search_key] === $search_value)
d6e8d8
				{
d6e8d8
					$key = $i;
d6e8d8
					break;
d6e8d8
				}
d6e8d8
			}
d6e8d8
d6e8d8
			// key/value pair not found
d6e8d8
			if ($key === NULL)
d6e8d8
			{
d6e8d8
				return false;
d6e8d8
			}
d6e8d8
		}
d6e8d8
d6e8d8
		// Insert Block
d6e8d8
		if ($mode == 'insert')
d6e8d8
		{
d6e8d8
			// Make sure we are not exceeding the last iteration
d6e8d8
			if ($key >= sizeof($this->_tpldata[$blockname]))
d6e8d8
			{
d6e8d8
				$key = sizeof($this->_tpldata[$blockname]);
d6e8d8
				unset($this->_tpldata[$blockname][($key - 1)]['S_LAST_ROW']);
d6e8d8
				$vararray['S_LAST_ROW'] = true;
d6e8d8
			}
d6e8d8
			else if ($key === 0)
d6e8d8
			{
d6e8d8
				unset($this->_tpldata[$blockname][0]['S_FIRST_ROW']);
d6e8d8
				$vararray['S_FIRST_ROW'] = true;
d6e8d8
			}
d6e8d8
d6e8d8
			// Re-position template blocks
d6e8d8
			for ($i = sizeof($this->_tpldata[$blockname]); $i > $key; $i--)
d6e8d8
			{
d6e8d8
				$this->_tpldata[$blockname][$i] = $this->_tpldata[$blockname][$i-1];
d6e8d8
				$this->_tpldata[$blockname][$i]['S_ROW_COUNT'] = $i;
d6e8d8
			}
d6e8d8
d6e8d8
			// Insert vararray at given position
d6e8d8
			$vararray['S_ROW_COUNT'] = $key;
d6e8d8
			$this->_tpldata[$blockname][$key] = $vararray;
d6e8d8
d6e8d8
			return true;
d6e8d8
		}
d6e8d8
d6e8d8
		// Which block to change?
d6e8d8
		if ($mode == 'change')
d6e8d8
		{
d6e8d8
			if ($key == sizeof($this->_tpldata[$blockname]))
d6e8d8
			{
d6e8d8
				$key--;
d6e8d8
			}
d6e8d8
d6e8d8
			$this->_tpldata[$blockname][$key] = array_merge($this->_tpldata[$blockname][$key], $vararray);
d6e8d8
			return true;
d6e8d8
		}
d6e8d8
d6e8d8
		return false;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Include a separate template
d6e8d8
	* @access private
d6e8d8
	*/
d6e8d8
	function _tpl_include($filename, $include = true)
d6e8d8
	{
d6e8d8
		$handle = $filename;
d6e8d8
		$this->filename[$handle] = $filename;
d6e8d8
		$this->files[$handle] = $this->root . '/' . $filename;
d6e8d8
		if ($this->inherit_root)
d6e8d8
		{
d6e8d8
			$this->files_inherit[$handle] = $this->inherit_root . '/' . $filename;
d6e8d8
		}
d6e8d8
d6e8d8
		$filename = $this->_tpl_load($handle);
d6e8d8
d6e8d8
		if ($include)
d6e8d8
		{
d6e8d8
			global $user;
d6e8d8
d6e8d8
			if ($filename)
d6e8d8
			{
d6e8d8
				include($filename);
d6e8d8
				return;
d6e8d8
			}
d6e8d8
			eval(' ?>' . $this->compiled_code[$handle] . '
d6e8d8
		}
d6e8d8
	}
d6e8d8
}
d6e8d8
d6e8d8
?>