<?php
abstract class v3_templated_data
{
protected $_template = false;
protected $_data;
protected $_children;
protected $_db;
abstract protected function _init($args);
function __construct()
{
$args = func_get_args();
$this->_template = v3_factory::new_instance('template');
$this->_db = v3_factory::new_instance('db');
$this->_init($args);
}
protected function _load_template($name)
{
$this->_template = new template($name);
$this->_template->load();
}
public function set_template($name, $content)
{
if($this->_template === false)
$this->_template = v3_factory::new_instance('template');
$this->_template->set($name, $content);
}
public function set_data($data)
{
$this->_data = $data;
}
public function children()
{
return $this->_children;
}
public function template()
{
return $this->_template !== false ? $this->_template->content() : false;
}
public function data()
{
return $this->_data;
}
public function parse_template($clean_output=true, $entitise=true, $reps=false)
{
$tpl = $this->_template;
$data = array_merge(
$this->data(),
array(
'currdate' => date('Y-m-d H:i:s'),
'curryear' => date('Y'),
'siteauthor' => V3_SITE_AUTHOR,
'sitename' => V3_SITE_NAME
)
);
$out = $tpl->parse($data, $entitise);
if(is_array($reps)) {
foreach($reps as $s => $r)
$out = str_replace($s, $r, $out);
}
return $clean_output ? preg_replace('|\\' . TPL_VAR_PREFIX . '[\:\-\w]+\\' . TPL_VAR_SUFFIX . '|', '', $out) : $out;
}
} ?>