<?
/*
clsTemplate.php verwaltet Templatesinformationen
Copyright (C) 2004 Thomas Meinusch
*/
class Template{
var $CONTENT = "";
var $CONFIG = "";
var $dir = "";
var $src = "";
var $folder = "";
var $file = "";
var $PATH = array();
var $ERROR = array();
var $fileOK = true;
#************************************************************
function Template($PATH, $dir="", $src="", $checkfile=true){
if(is_array($PATH)){
// Array, dir, src check
$this->PATH = $PATH;
$this->dir = $dir;
$this->src = $src;
$this->getPath();
$this->getFile();
}else{
// pfad/datei,check
$this->file=realpath(trim($PATH));
$checkfile=true;
if(is_bool($dir)) $checkfile=$dir;
}
$this->getFileContent($checkfile);
// if(!$this->fileOK) return $this=NULL;
}
function getPath(){
if(isset($this->PATH[$this->dir])){
$el=$this->PATH[$this->dir];
}else{
$el=reset($this->PATH); // erste Element
$this->dir = key($this->PATH);
}
// PATH["name"]["path"]
if(is_array($el)) $this->folder= $el["path"];
}
function getFile(){
if($this->src==""){
$el=reset($this->PATH); // erste Element
$this->src = $this->PATH[$this->dir]["file"];
}
$this->file=realpath(trim($this->folder)."/".trim($this->src));
}
function checkFile(){
$fname=$this->src;
$folder=$this->folder;
if(realpath($folder)!= substr(realpath($this->file), 0,strlen(realpath($folder)))){
$this->ERROR[]="Datei $fname in $folder ist unzuläßig!";
$this->fileOK=false;
}
# Datei prüfen
if(!file_exists($this->file) || $this->file==""){
$this->ERROR[]="Datei $fname in $folder nicht gefunden";
$this->fileOK=false;
}else{
if(!is_readable($this->file)){
$this->ERROR[]="Datei $fname in $folder nicht lesbar";
$this->fileOK=false;
}
if(!is_file($this->file)){
$this->ERROR[]="Datei $fname in $folder ist keine Datei";
$this->fileOK=false;
}
}
}
function getFileContent($checkfile){
if($checkfile) $this->checkFile();
$filename=$this->file;
if($this->fileOK==false){
if(is_file($this->PATH[$this->dir]["sorry"])){
$filename=$this->PATH[$this->dir]["sorry"];
$this->fileOK=true;
}
}
if($this->fileOK==true && $filename) $this->CONTENT= trim(implode("",(@file($filename))));
}
function getError(){
$temp="";
foreach($this->ERROR as $err){
$temp.= "$err<br />\n";
}
return $temp;
}
}