Skip to content

Instantly share code, notes, and snippets.

@navarr
Created March 27, 2010 17:03
Show Gist options
  • Save navarr/346225 to your computer and use it in GitHub Desktop.
Save navarr/346225 to your computer and use it in GitHub Desktop.
<?php
class Site
{
public $vars;
public $tpldir;
public function __construct()
{
$this->tpldir = dirname(__FILE__)."/../tpl/";
}
public function set($var,$val)
{
if(is_array($var))
{
foreach($var as $k => $v)
{ $this->vars[$var] = $val[$k]; }
}
$this->vars[$var] = $val;
}
public function get($var)
{
return $this->vars[$var];
}
public function fetch($file)
{
if(is_array($this->vars)) { foreach($this->vars as $var => $val) { ${$var} = $val; } }
ob_start();
if(file_exists($this->tpldir.$file)) { require_once($this->tpldir.$file); }
else { ob_end_clean();return false; }
$content = ob_get_contents();
ob_end_clean();
return $content;
}
public function display($page)
{
if(file_exists($this->tpldir.$page.".php")) { $content = $this->fetch($page.".php"); }
else
{
header("HTTP/1.1 404 Not Found");
$this->set("title","Error 404");
if(file_exists($this->tpldir."errors/404.php")) { $content = $this->fetch("errors/404.php"); }
else { $content = "Error 404"; }
}
require_once($this->tpldir."wrapper.php");
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment