<?php
class view{
// layout is the site
private $layout_name = null;
// template is controller and action specific
private $template_name = null;
// used if $template_name hasn't been specified
// so we can guess the name
private $controller_name = null;
// used if $template_name hasn't been specified.
// you can try and guess the name of the template
private $action_name = null;
// if we want to turn on error messages
private $debug = false;
private $xsl_proc = null;
private $dom = null;
public function __construct(DOMDocument $dom,$layout_name,
$template_name,$controller_name,
$action_name, $debug){
$this->dom = $dom;
$this->layout_name = $layout_name;
$this->template_name = $template_name;
$this->action_name = $action_name;
$this->controller_name = $controller_name;
$this->debug = $debug;
}
public function render(){
$out = null;
if( empty($this->layout_name) ){
// we want to try using the default
$file = BASE_DIR.APP_DIR.DS.SITE_TEMPLATES.DS."layouts".DS."default".TEMPLATE_EXTN;
}
else
{
$file = BASE_DIR.APP_DIR.DS.SITE_TEMPLATES.DS."layouts".DS.$this->layout_name.TEMPLATE_EXTN;
}
// now see if its actually a file
if( is_file($file) )
{
// Make a DOMDocument for the xsl file
$xsl = new DomDocument();
$xsl->load( $file );
/* create the processor and import the stylesheet */
$proc = new XsltProcessor();
$xsl = $proc->importStylesheet( $xsl );
// prolly want to do this later
//$proc->setParameter(null, "titles", "Titles");
ob_start();
$proc->transformToURI($this->dom,'php://output');
$out = ob_get_clean();
/* transform and output the xml document */
//print $newdom->saveXML();
}
else
{
if( $this->debug )
{
echo "no such file ".$file;
}
}
echo $out;
}
public function set_debug()
{
$this->debug = true;
}
public function write(){
}
}
?>