File: D:/HostingSpaces/NVonken/mijneigenlied.com/wwwroot/Core/Core Parts/tpl.part.php
<?php
class tpl{
private $Contents = array();
private $Lang;
private static $pageElementsLoaded = false;
private static $pageElements = array();
function tpl()
{
$lang = array();
require_once("Core/Languages/".strtoupper(ACTIVE_LANGUAGE)."/".strtolower(ACTIVE_LANGUAGE).".lang.php");
$this->Lang = $lang;
if(!tpl::$pageElementsLoaded)
{
tpl::$pageElementsLoaded = true;
$dirElements = opendir("Core/Page Elements/");
while(($fileElements = readdir($dirElements)) !== false)
{
if(!is_dir("Core/Page Elements/" . $fileElements) && strpos($fileElements, "element") !== false)
{
$elementName = "Element_".substr($fileElements,0,strpos($fileElements,"."));
require_once("Core/Page Elements/" . $fileElements);
if(class_exists($elementName))
{
$x = new $elementName();
$settings = $x::Settings();
if($settings["Pageable"] == false)
{
tpl::$pageElements[$x->elementName] = $x;
}
}
}
}
$this->PageElementsLoaded = true;
closedir($dirElements);
}
}
function assign($VarName, $Content, $KeepAlive = 1)
{
$this->Contents[$VarName] = $Content;
}
function Clear()
{
$this->Contents = array();
}
function parse( $TemplateFile, $includeElements = false)
{
$Path = 'Core/Templates/'.$TemplateFile.'.tpl';
if( !file_exists( $Path ) )
die("Template Error: While loading the template an error occured. The Template file was not found: ".$Path);
$createCachedPage = true;
$TemplateFile = str_replace("/","_",$TemplateFile);
$cachedPath = 'Core/Templates/Cached/'.$TemplateFile.'.tpl';
if(file_exists($cachedPath))
{
if(filemtime($Path) < filemtime($cachedPath))
{
$createCachedPage = false;
}
}
if($createCachedPage)
{
$handle = fopen($Path, 'r');
$FileContent = fread($handle, filesize($Path) );
fclose($handle);
//search all vars
$items = array();
preg_match_all('/\{\$(.*?)\}/',$FileContent,$items);
foreach($items[1] as $item)
{
$FileContent = str_replace('{$'.$item."}",'<?=$this->getData("'.$item.'")?>',$FileContent);
}
$cachedFile = fopen($cachedPath,"w");
fwrite($cachedFile,$FileContent);
fclose($cachedFile);
}
ob_start();
$this->loadCustomVars();
$assContent = $this->Contents;
include($cachedPath);
$TemplateContent = ob_get_contents();
ob_end_clean();
return $TemplateContent;
}
private function getData($name)
{
if(strpos($name,"Element:") !== false)
{
$name = str_replace("Element:", "", $name);
if(isset(tpl::$pageElements[$name]))
{
return tpl::$pageElements[$name]->run();
}
}
return $this->Contents[$name];
}
private function loadCustomVars()
{
foreach($this->Lang as $Key => $Data)
{
$this->assign("L:".$Key, $Data);
}
$this->assign("S:SETTING_ROOT",SETTING_ROOT);
$this->assign("S:SETTING_DOMAIN",SETTING_DOMAIN);
$this->assign("S:SETTING_LANG", ACTIVE_LANGUAGE);
$this->assign("S:SETTING_HATCH", ACTIVE_HATCH);
$this->assign("S:PAGE_URL", PAGE_URL);
$this->assign("S:BASE_URL", BASE_URL);
$this->assign("S:BASE_URL_COMPONENT", BASE_URL_COMPONENT);
$this->assign("S:SETTING_YEAR", date("Y"));
}
}
?>