mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-07 22:41:59 +01:00
7a66346036
Signed-off-by: Janos SUTO <sj@acts.hu>
120 lines
2.5 KiB
PHP
120 lines
2.5 KiB
PHP
<?php
|
|
|
|
|
|
class Controller {
|
|
protected $id;
|
|
protected $data = array();
|
|
protected $children = array();
|
|
protected $layout;
|
|
protected $output;
|
|
protected $template;
|
|
|
|
|
|
public function __construct() {
|
|
$language = Registry::get('language');
|
|
$this->data = array_merge($this->data, $language->data);
|
|
}
|
|
|
|
|
|
public function __get($key) {
|
|
return Registry::get($key);
|
|
}
|
|
|
|
|
|
public function __set($key, $value) {
|
|
Registry::set($key, $value);
|
|
}
|
|
|
|
|
|
public function args($args = array()){
|
|
foreach($args as $key => $value) {
|
|
$this->data[$key] = $value;
|
|
}
|
|
}
|
|
|
|
|
|
protected function render(){
|
|
|
|
foreach ($this->children as $child) {
|
|
$file = DIR_APPLICATION . $child . ".php";
|
|
$class = 'Controller' . preg_replace('/[^a-zA-Z0-9]/', '', $child);
|
|
|
|
if(file_exists($file)){
|
|
require_once($file);
|
|
|
|
$controller = new $class();
|
|
|
|
$controller->index();
|
|
|
|
$this->data[$controller->id] = $controller->output;
|
|
}
|
|
else {
|
|
exit("Error: Could not load controller ($file)" . $child . '!');
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->output = $this->fetch($this->template);
|
|
|
|
|
|
if($this->layout){
|
|
|
|
$file = DIR_APPLICATION . $this->layout . '.php';
|
|
$class = 'Controller' . preg_replace('/[^a-zA-Z0-9]/', '', $this->layout);
|
|
|
|
if(file_exists($file)){
|
|
require_once($file);
|
|
|
|
$controller = new $class();
|
|
|
|
$controller->data[$this->id] = $this->output;
|
|
|
|
$controller->index();
|
|
|
|
$this->output = $controller->output;
|
|
|
|
}
|
|
else {
|
|
exit("Error: Could not load layout ($file) " . $this->layout . '!');
|
|
}
|
|
|
|
print $this->output;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
protected function fetch(){
|
|
$session = Registry::get('session');
|
|
|
|
if($session->get("theme") && preg_match("/^([a-zA-Z0-9\-\_]+)$/", $session->get("theme")) && file_exists(DIR_THEME . $session->get("theme")) ) {
|
|
$file = DIR_THEME . $session->get("theme") . '/templates/' . $this->template;
|
|
} else {
|
|
$file = DIR_THEME . THEME . '/templates/' . $this->template;
|
|
}
|
|
|
|
if(file_exists($file)){
|
|
|
|
extract($this->data);
|
|
|
|
ob_start();
|
|
|
|
include($file);
|
|
|
|
$content = ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
return $content;
|
|
}
|
|
else {
|
|
exit('Error: Could not load template ' . $file . '!');
|
|
}
|
|
}
|
|
|
|
|
|
}
|