class templateengine
{
define(TPL_DIR,"../templates/");
define(TPL_EXT,".tpl.php");
define(TPL_NOT_FOUND,"../templates/error.tpl");
function display($tpl)
{
global $vars;
(is_array($vars)?extract($vars):"");
if(file_exists(TPL_DIR.$tpl.TPL_EXT))
{
$tpl=$this->replacevars($tpl);
$this->print(TPL_DIR.$tpl.TPL_EXT);
}
else
{
$this->print(TPL_NOT_FOUND);
}
}
function replacevars($template)
{
$connection=mysql_connect($databaseserver,$databaseuser,$databasepass);
mysql_select_db($databasename,$connection);
$sql="SELECT * FROM forum_users WHERE sessionid NOT LIKE ' '";
$result=mysql_query($sql) or die(mysql_error());
$onlineusers=mysql_affected_rows($result);
str_replace("%onlineusers","Es sind ".$onlineusers." registrierte User online.","%onlineusers");
$nameforumsql="SELECT * FROM forum_foren WHERE is_forum='1'";
$resultforum=mysql_query($nameforumsql) or die(mysql_error());
while($nameforums=mysql_fetch_assoc($this->resultforum))
{
str_replace("%forumname",$nameforums['name'],"%forumname");
}
$contentsql="SELECT content FROM forum_posts_threads";
$resultcontent=mysql_query($contentsql);
while($content=mysql_fetch_assoc($this->resultcontent))
{
str_replace("%content",$content['content'],"%content");
}
$authorsql="SELECT * FROM forum_post_threads WHERE content='".$content['content']."' LIMIT 1";
$authorresult=mysql_query($contentsql);
while($author=mysql_fetch_assoc($this->authorresult)
{
str_replace("%author",$author['name'],"%author");
}
$timesql="SELECT * FROM forum_post_threads WHERE content='".$content['content']."' AND name='".$author['name']."'";
$result=mysql_query($timesql);
while($time=mysql_fetch_assoc($result))
{
str_replace("%time",date(d.m.Y H:i,$time['time']),"%time");
}
}
}