| // +--------------------------------------------------------------------+ // // $Id$ // // +X2C Class 130 :HIT /** * Hooks vs. IT (HIT) is a simple template implementation, based on hooks and IT template systems. * * @access public */ class HTML_Template_HIT { /** * Root directory where template files are. * * @var string $root * @access public */ var $root = '.'; /** * Group of templates to use (a subdirectory in root). * * @var string $group * @access public */ var $group = ''; /** * Templates cache. * * @var array $cache * @access protected */ var $cache = array(); // ~X2C // +X2C Operation 136 /** * Constructor. * * @param string $root Root directory where template files are. * @param string $group Group of templates to use (a subdirectory in root). * * @return void * @access public */ function HTML_Template_HIT($root = '.', $group = '') // ~X2C { $this->__construct($root, $group); } // -X2C // +X2C Operation 137 /** * Constructor. * * @param int $root Root directory where template files are. * @param int $group Group of templates to use (a subdirectory in root). * * @return void * @access public */ function __construct($root = '.', $group = '') // ~X2C { $this->root = $root; $this->group = $group; } // -X2C // +X2C Operation 138 /** * Parse a template. If $vars is an array, the {[keys]} are replaced with [values] ($val is ignored). If is a string, {$vars} is replaced with $val. * * @param string $name Name of template to parse. * @param mixed $vars Variables to replace in the template. * @param string $val If $vars is a string, the value to replace for $vars. * * @return void * @access public */ function parse($name, $vars = '', $val = '') // ~X2C { if ($this->group) { $file = "{$this->root}/{$this->group}/$name.tpl.html"; } else { $file = "{$this->root}/$name.tpl.html"; } if (!isset($this->cache[$file])) { $this->cache[$file] = join('', file($file)); } //if (!is_readable($file)) { // trigger_error("Can't read '$file'."); //} if ($vars) { if (is_string($vars)) { $vars = array($vars => $val); } foreach ($vars as $key => $val) { $keys[] = '{' . $key . '}'; $vals[] = $val; } return str_replace($keys, $vals, $this->cache[$file]); } else { return $this->cache[$file]; } } // -X2C } // -X2C Class :HIT ?>