Legendary Battlemage
- Joined
- Aug 16, 2008
- Messages
- 600
- Reaction score
- 259
I've been pretty busy for the past week, but here's the new template class that'll I'll be using from now on. Basically I didn't like the fact that the template class (original) was using two classes and that there were functions inside the class that weren't needed etc.
PHP:
<?php
if (!defined('INDEX'))
{
exit ('<h1>Access denied</h1><p>You do not have the privileges to access this webpage.</p>');
}
class template
{
private $template = NULL;
private $input = array ();
private $output;
public function template ($string)
{
$this->template = $string;
}
public function template_page ()
{
extract ($this->input);
$input = ('resources/resources_private/private_template/template_private/'.$this->template.'.tpl');
if (file_exists($input))
{
ob_start ();
include ($input);
$output = ob_get_contents ();
ob_end_clean ();
return $this->template_filter_input ($output);
}
else
{
exit ('<h1>Access denied</h1><p>Template ('.$this->template.') does not have the privileges to access this webpage.</p>');
}
}
private function template_filter_input ($string)
{
foreach ($this->input as $input => $output)
{
if (is_object($output))
{
continue;
}
$string = str_ireplace ('%'.$input.'%', $output, $string);
}
return $string;
}
public function template_input ($input, $output)
{
$this->input[$input] = is_object ($output) ? $output->fetch () : $output;
}
public function template_output ()
{
$this->output .= $this->template_page ();
echo $this->template_filter_input ($this->output);
}
}
?>