Created
March 27, 2010 17:03
-
-
Save navarr/346225 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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