<?php
/*
template.php - scott@graphictype.com

simple classified and hash-enabled template thing.

i wrote this in about 5 minutes as a proof of concept.
it's public domain... do whatever you want with it.
*/
class template {
  var $err	= '';
  var $file	= '';
  var $data	= array();

//load the file
function template ( $file='' ) {
  $this->file = $file;
  $this->data = join ('', file($file));
  if (!is_array($this_data)) {
  	$this->error("Cannot open $file");
  	return ;
  }
  return;
}

//regvar('name', 'value') will change "%{name}%" to "value"
function regvar ($name,$value) {
  $this->data = preg_replace("/\%\{$name\}\%/", $value, $this->data);
  return 1;
}

//will traverse hash and call regvar for each key.
function hash ($hash) {
  while ( list($key,$value) = each($hash) ) {
	$this->regvar($key,$value);
  }
  return 1;
}

//print the template
function tprint () {
  print $this->data;
  return 1;
}

//set error and return
function error ($text='') {
  $this->err = $text;
  return 0;
}

}//class


?>
