<?php
/*************************************************************
*                                                            *
*  Author: Andy Guenter @ artbit.ch                          *
*  Version: 1.0                                              *
*                                                            *
*************************************************************/

/*************************************************************
*                                                            *
*  Klasse um HTML-Vorlagen mit PHP-Daten zu fuellen und zur  *
*  Ausgabe vorzubereiten.                                    *
*                                                            *
*************************************************************/
class template {

  var $templatefile;
  var $templatepath;
  var $templatetext;
  var $templatevars;

  function template($file='template.html', $path='templates/'){
    $this->templatefile = $file;
    $this->templatepath = $path;
    // Dateiname mit Pfad erstellen
    $filename = $this->templatepath.$this->templatefile;
    // Wenn eine entsprechende Datei vorhanden ist, Inhalt auslesen
    if(file_exists($filename)){
      $text=file_get_contents($filename);
    }else{
      $text="Die Datei \"".$this->templatefile."\" wurde nicht gefunden!";
    }
    $this->templatetext = $text;
    $this->templatevars = array();
  }

  function get_replaced_template(){
    $vars = $this->templatevars;
    $temptext = $this->templatetext;
    foreach($vars as $key => $value){
      $temptext = str_replace("{".$key."}", $value, $temptext);
    }
    return $temptext;
  }

  function get_template_info(){
    return $this->templatepath.$this->templatefile;
  }
}
?>