|
@@ -3,16 +3,17 @@
|
|
|
class Output {
|
|
class Output {
|
|
|
|
|
|
|
|
private static $_instance;
|
|
private static $_instance;
|
|
|
- private $_doctype = "<!DOCTYPE html>";
|
|
|
|
|
- private $_head_items = Array();
|
|
|
|
|
- private $_body = "";
|
|
|
|
|
- private $_content = "";
|
|
|
|
|
- private $_foot_items = Array();
|
|
|
|
|
|
|
+
|
|
|
private $view = false;
|
|
private $view = false;
|
|
|
|
|
+ protected $values = Array();
|
|
|
|
|
|
|
|
|
|
+ private $_template = '';
|
|
|
|
|
+ private $_extension = '';
|
|
|
|
|
+
|
|
|
//SINGLETON==============================================
|
|
//SINGLETON==============================================
|
|
|
private function __construct() {
|
|
private function __construct() {
|
|
|
-
|
|
|
|
|
|
|
+ $this->_template = ( defined('TEMPLATE_DEFAULT') ) ? TEMPLATE_DEFAULT : 'DefaultTemplate';
|
|
|
|
|
+ $this->_extension = ( defined('TEMPLATE_FILETYPE') ) ? TEMPLATE_FILETYPE : '.mustache';
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private static function newObj() {
|
|
private static function newObj() {
|
|
@@ -29,127 +30,48 @@ class Output {
|
|
|
return self::$_instance;
|
|
return self::$_instance;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static function load_view($name, $values = null, $location = null) {
|
|
|
|
|
|
|
+ public function setTemplate($template = 'DefaultTemplate') {
|
|
|
|
|
+ $this->_template = $template;
|
|
|
|
|
+ return $this;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static function renderView($name, $values = null, $location = null) {
|
|
|
if (!$location) {
|
|
if (!$location) {
|
|
|
$segments = explode('/', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[0]['file']);
|
|
$segments = explode('/', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[0]['file']);
|
|
|
array_pop($segments);
|
|
array_pop($segments);
|
|
|
$location = implode('/', $segments) . '/views/';
|
|
$location = implode('/', $segments) . '/views/';
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- if (is_array($values) && count($values) > 0) {
|
|
|
|
|
- extract($values, EXTR_PREFIX_SAME, 'data');
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $location .= $name;
|
|
|
|
|
-
|
|
|
|
|
- if (strpos('.php', $location) == 0) {
|
|
|
|
|
- $location .= '.php';
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (!file_exists($location)) {
|
|
|
|
|
- //return require_once GENERAL_VIEW_FOLDER . 'errors/404.php';
|
|
|
|
|
- }
|
|
|
|
|
- return require_once( $location );
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private function render_view() {
|
|
|
|
|
- if (is_array($this->view['values']) && count($this->view['values']) > 0) {
|
|
|
|
|
- extract($this->view['values'], EXTR_PREFIX_SAME, 'data');
|
|
|
|
|
- }
|
|
|
|
|
- return require_once( $this->view['location'] );
|
|
|
|
|
|
|
+
|
|
|
|
|
+ self::$_instance->setView($name, $values, $location)->render();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function set_view($name, $values = null, $location = null) {
|
|
|
|
|
|
|
+ public function setView($name, $values = Array(), $location = null) {
|
|
|
|
|
+
|
|
|
|
|
+ $folder = '';
|
|
|
if (!$location) {
|
|
if (!$location) {
|
|
|
$segments = explode('/', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[0]['file']);
|
|
$segments = explode('/', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[0]['file']);
|
|
|
array_pop($segments);
|
|
array_pop($segments);
|
|
|
$location = implode('/', $segments) . '/views/';
|
|
$location = implode('/', $segments) . '/views/';
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ $folder = $location;
|
|
|
$location .= $name;
|
|
$location .= $name;
|
|
|
|
|
|
|
|
- if (strpos('.php', $location) == 0) {
|
|
|
|
|
- $location .= '.php';
|
|
|
|
|
|
|
+ if (strpos($this->_extension, $location) == 0) {
|
|
|
|
|
+ $location .= $this->_extension;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$this->view = Array();
|
|
$this->view = Array();
|
|
|
$this->view['location'] = $location;
|
|
$this->view['location'] = $location;
|
|
|
|
|
+ $this->view['folder'] = $folder;
|
|
|
$this->view['values'] = $values;
|
|
$this->view['values'] = $values;
|
|
|
|
|
+ return $this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function render() {
|
|
public function render() {
|
|
|
- if (is_ajax_request()) {
|
|
|
|
|
- echo $this->_content;
|
|
|
|
|
- if ($this->view) {
|
|
|
|
|
- $this->render_view();
|
|
|
|
|
- }
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ if(!is_file(__DIR__."/classes/".strtolower($this->_template)."/".$this->_template.'.php') ){
|
|
|
|
|
+ $this->_template = 'DefaultTemplate';
|
|
|
}
|
|
}
|
|
|
- global $DROPDOWN, $SIDEBAR;
|
|
|
|
|
-
|
|
|
|
|
- $this->_head_items[] = '<script src="/plugins/jquery/jquery.min.js"></script>';
|
|
|
|
|
-
|
|
|
|
|
- $this->_head_items[] = '<script src="/plugins/mousetrap/mousetrap.min.js"></script>';
|
|
|
|
|
-
|
|
|
|
|
- $this->_head_items[] = '<script src="/plugins/jquery-mask-plugin/jquery.mask.min.js"></script>';
|
|
|
|
|
-
|
|
|
|
|
- $this->_head_items[] = '<link href="/plugins/bootstrap/bootstrap.min.css" rel="stylesheet" />';
|
|
|
|
|
- $this->_head_items[] = '<script src="/plugins/bootstrap/bootstrap.min.js"></script>';
|
|
|
|
|
-
|
|
|
|
|
- $this->_head_items[] = '<link href="/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" />';
|
|
|
|
|
-
|
|
|
|
|
- $this->_head_items[] = '<link href="/plugins/normalize-css/normalize.css" rel="stylesheet">';
|
|
|
|
|
- $this->_head_items[] = '<link href="/dist/style.css" rel="stylesheet">';
|
|
|
|
|
-
|
|
|
|
|
- $this->_head_items[] = '<link href="/dist/theme/black_and_white.css" rel="stylesheet">';
|
|
|
|
|
-
|
|
|
|
|
- $this->_head_items[] = '<link href="/plugins/metisMenu/metisMenu.min.css" rel="stylesheet">';
|
|
|
|
|
- $this->_head_items[] = '<script src="/plugins/metisMenu/metisMenu.min.js"></script>';
|
|
|
|
|
-
|
|
|
|
|
- $this->_head_items[] = '<link href="/plugins/select2/select2.min.css" rel="stylesheet">';
|
|
|
|
|
- $this->_head_items[] = '<script src="/plugins/select2/select2.min.js"></script>';
|
|
|
|
|
-
|
|
|
|
|
- $this->_head_items[] = '<link rel="stylesheet" href="/plugins/datatables/dataTables.css">';
|
|
|
|
|
- $this->_head_items[] = '<script src="/plugins/datatables/dataTables.js"></script>';
|
|
|
|
|
-
|
|
|
|
|
- $this->_foot_items[] = '<script src="/dist/script.js"></script>';
|
|
|
|
|
-
|
|
|
|
|
- $head = "<head>";
|
|
|
|
|
- foreach ($this->_head_items as $head_item) {
|
|
|
|
|
- $head .= $head_item . "\n";
|
|
|
|
|
- }
|
|
|
|
|
- $head .= "</head>";
|
|
|
|
|
- $foot = "";
|
|
|
|
|
- foreach ($this->_foot_items as $foot_item) {
|
|
|
|
|
- $foot .= $foot_item;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $header = str_replace("{{usermenu}}", "", file_get_contents(__DIR__ . '/views/header.html'));
|
|
|
|
|
- $sidebar = str_replace("{{elements}}", $SIDEBAR->render(), file_get_contents(__DIR__ . '/views/sidebar.html'));
|
|
|
|
|
-
|
|
|
|
|
- $body_first = file_get_contents(__DIR__ . "/views/body.html");
|
|
|
|
|
- $body_first = str_replace("{{header}}", $header, $body_first);
|
|
|
|
|
- $body_first = str_replace("{{sidebar}}", $sidebar, $body_first);
|
|
|
|
|
- $body_first .= $this->_content;
|
|
|
|
|
-
|
|
|
|
|
- $foot .= '<div id="modal" class="modal fade" role="dialog"> </div>';
|
|
|
|
|
-
|
|
|
|
|
- $body_end = file_get_contents(__DIR__ . "/views/body_section.html");
|
|
|
|
|
- $body_end = str_replace("{{footer}}", $foot, $body_end);
|
|
|
|
|
-
|
|
|
|
|
- echo $this->_doctype . "\n";
|
|
|
|
|
- echo "<html> \n";
|
|
|
|
|
- echo $head;
|
|
|
|
|
- echo $body_first;
|
|
|
|
|
- if ($this->view) {
|
|
|
|
|
- $this->render_view();
|
|
|
|
|
- }
|
|
|
|
|
- echo $body_end;
|
|
|
|
|
- echo "</html>";
|
|
|
|
|
|
|
+ include_once __DIR__."/classes/".strtolower($this->_template)."/".$this->_template.'.php';
|
|
|
|
|
+ last_class()->setView($this->view)->render();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- public function set_content($content) {
|
|
|
|
|
- $this->_content = $content;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|