$filename = $this->template;
if (isset($this->request->get['theme']) && $this->request->get['theme'] || isset($this->session->data['theme'])) {
$directories = glob(DIR_APPLICATION . 'view/theme/*', GLOB_ONLYDIR);
$this->session->data['theme'] = (isset($this->request->get['theme']) && $this->request->get['theme']) ? $this->request->get['theme'] : $this->session->data['theme'];
foreach ($directories as $directory) {
if ($this->session->data['theme'] == basename($directory)) {
$tmp = explode('/', $filename);
$tmp[0] = $this->session->data['theme'];
$filename2 = implode('/', $tmp);
$file2 = DIR_TEMPLATE . $filename2;
if (file_exists($file2)) {
$filename = $filename2;
$this->data['template'] = $tmp[0];
}
break;
}
}
}
$file = DIR_TEMPLATE . $filename;
if (file_exists($file)) {
extract($this->data);
ob_start();
require($file);
$this->output = ob_get_contents();
ob_end_clean();
return $this->output;
} else {
exit('Error: Could not load template ' . $file . '!');
}