62 lines
1.1 KiB
PHP
62 lines
1.1 KiB
PHP
|
|
<?php
|
||
|
|
/**
|
||
|
|
* view.php
|
||
|
|
*
|
||
|
|
* simple view class, template-based.
|
||
|
|
* @todo indent markup using tidy?
|
||
|
|
*
|
||
|
|
* $Rev$
|
||
|
|
* $Author$
|
||
|
|
* $Date$
|
||
|
|
*/
|
||
|
|
class view
|
||
|
|
{
|
||
|
|
protected $hasLayout;
|
||
|
|
private $file;
|
||
|
|
|
||
|
|
public function __construct( $file_path ) {
|
||
|
|
if(!file_exists($file_path)) {
|
||
|
|
throw new Exception('file ' . $file_path . ' does not exist!', 666);
|
||
|
|
} else {
|
||
|
|
$this->file = $file_path;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Compile the view
|
||
|
|
*
|
||
|
|
* @return $HTMLSource the compiled view
|
||
|
|
*/
|
||
|
|
public function compile($registry = false) {
|
||
|
|
if($registry === false){
|
||
|
|
$registry =& registry::getInstance();
|
||
|
|
}
|
||
|
|
$user =& user::getInstance();
|
||
|
|
foreach($registry as $k=>$v){
|
||
|
|
$$k = $v;
|
||
|
|
}
|
||
|
|
ob_start();
|
||
|
|
require $this->file;
|
||
|
|
$body = ob_get_clean();
|
||
|
|
|
||
|
|
(isset($contentType)) ? http_response::content($contentType) : http_response::content(CONTENT_TYPE);
|
||
|
|
|
||
|
|
$isFragment = isset($this->isFragment);
|
||
|
|
|
||
|
|
if(defined('LAYOUT') && !$isFragment){
|
||
|
|
ob_start();
|
||
|
|
require LAYOUT;
|
||
|
|
$body = ob_get_clean();
|
||
|
|
}
|
||
|
|
return $body;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function isFragment() {
|
||
|
|
$this->isFragment = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
function __toString() {
|
||
|
|
return __CLASS__;
|
||
|
|
}
|
||
|
|
}
|