Tooo many changes to list

This commit is contained in:
2019-04-29 16:55:06 -03:00
parent f71d63b578
commit e696e99c4c
20 changed files with 284 additions and 172 deletions
+28 -106
View File
@@ -3,16 +3,17 @@
class Output {
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==============================================
private function __construct() {
$this->_template = ( defined('TEMPLATE_DEFAULT') ) ? TEMPLATE_DEFAULT : 'DefaultTemplate';
$this->_extension = ( defined('TEMPLATE_FILETYPE') ) ? TEMPLATE_FILETYPE : '.mustache';
}
private static function newObj() {
@@ -29,127 +30,48 @@ class Output {
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) {
$segments = explode('/', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[0]['file']);
array_pop($segments);
$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 );
self::$_instance->setView($name, $values, $location)->render();
}
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'] );
}
public function set_view($name, $values = null, $location = null) {
public function setView($name, $values = Array(), $location = null) {
$folder = '';
if (!$location) {
$segments = explode('/', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[0]['file']);
array_pop($segments);
$location = implode('/', $segments) . '/views/';
}
$folder = $location;
$location .= $name;
if (strpos('.php', $location) == 0) {
$location .= '.php';
if (strpos($this->_extension, $location) == 0) {
$location .= $this->_extension;
}
$this->view = Array();
$this->view['location'] = $location;
$this->view['folder'] = $folder;
$this->view['values'] = $values;
return $this;
}
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;
}
}
+3 -3
View File
@@ -1,9 +1,9 @@
<?php
use BBRouter\RouteCollection as RouteCollection;
use MenuBuilder\Menu as Menu;
use Routes\RouteCollection as RouteCollection;
use Menus\Menu as Menu;
RouteCollection::add('GET', '*', function(){
RouteCollection::get('*', function(){
include_once 'Output.class.php';
@@ -0,0 +1,71 @@
<?php
use Template\RenderableTemplate as RenderableTemplate;
class Dashboard extends RenderableTemplate {
public $content;
public function render() {
if (is_ajax_request()) {
$this->content = file_get_contents($this->getView()['location']);
$this->implate();
return;
}
global $DROPDOWN, $SIDEBAR;
$head = '';
$head .= '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
$head .= '<script src="/plugins/jquery/jquery.min.js"></script>';
$head .= '<script src="/plugins/mousetrap/mousetrap.min.js"></script>';
$head .= '<script src="/plugins/jquery-mask-plugin/jquery.mask.min.js"></script>';
$head .= '<link href="/plugins/bootstrap/bootstrap.min.css" rel="stylesheet" />';
$head .= '<script src="/plugins/bootstrap/bootstrap.min.js"></script>';
$head .= '<link href="/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" />';
$head .= '<link href="/plugins/normalize-css/normalize.css" rel="stylesheet">';
$head .= '<link href="/dist/style.css" rel="stylesheet">';
$head .= '<link href="/dist/theme/black_and_white.css" rel="stylesheet">';
$head .= '<link href="/plugins/metisMenu/metisMenu.min.css" rel="stylesheet">';
$head .= '<script src="/plugins/metisMenu/metisMenu.min.js"></script>';
$head .= '<link href="/plugins/select2/select2.min.css" rel="stylesheet">';
$head .= '<script src="/plugins/select2/select2.min.js"></script>';
$head .= '<link rel="stylesheet" href="/plugins/datatables/dataTables.css">';
$head .= '<script src="/plugins/datatables/dataTables.js"></script>';
$head .= '<link rel="stylesheet" href="/plugins/trumbowyg/ui/trumbowyg.min.css">';
$head .= '<script src="/plugins/trumbowyg/trumbowyg.min.js"></script>';
$foot = '';
$foot .= '<script src="/dist/script.js"></script>';
$foot .= '<script src="/dist/exercicio_form.js"></script>';
$this->content = file_get_contents(__DIR__ . '/template.html');
$this->content = str_replace("{{usermenu}}", "", $this->content);
$this->content = str_replace("{{elements}}", $SIDEBAR->render(), $this->content);
$this->content = str_replace("{{head}}", $head, $this->content);
if(is_file($this->getView()['location'])){
$this->content = str_replace('{{>content}}', $this->replaceSections(file_get_contents($this->getView()['location']), $this->_view['values']), $this->content);
}else{
$this->content = str_replace('{{>content}}', '', $this->content);
}
$this->content = str_replace("{{footer}}", $foot, $this->content);
$this->implate();
}
}
@@ -0,0 +1,71 @@
<html>
<head>
{{head}}
</head>
<body>
<div id="wrapper">
<!-- Sidebar -->
<!-- Sidebar -->
<nav id="sidebar-wrapper">
<div class="logo" style="">
<img src='/media/logo_white.png' alt="logo" />
</div>
<!-- <div class="search-nav" style="">
<input class="form-control" type="text" placeholder="Busca"/>
</div> -->
<hr />
{{elements}}
<ul id="side-second-menu" class="hidden nav">
</ul>
</nav>
<!-- /#sidebar-wrapper -->
<!-- /#sidebar-wrapper -->
<!-- Page Content -->
<div id="main-page-wrapper">
<header style='min-height: 50px; background-color: #000;'>
<ul class="nav navbar-nav navbar-left">
<li class="tooltip-sidebar-toggle">
<a href="" id="menu-toggle">
<i class="fa fa-th-list" aria-hidden="true"></i>
</a>
</li>
</ul>
<!-- <ul id='menu-usuario' class="nav navbar-nav navbar-right nav-dropdown">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" data-method="reload">
<i class="fa fa-user" aria-hidden="true"></i> <span class="caret"></span>
</a>
{{usermenu}}
</li>
</ul> -->
</header>
<div id="progress" class="progress hidden" >
<div class="progress-bar progress-bar-striped progress-bar-animated active" style="width: 100%;"></div>
</div>
<!-- BreadCrumbs -->
<!-- /BreadCrumbs -->
<div id="page-content-wrapper">
<div class="container-fluid" style="height: 1024px;">
<div class="row">
<div id="content" class="col-lg-12">
{{>content}}
</div>
</div>
</div>
</div>
</div>
<!-- /#page-content-wrapper -->
</div>
<div id="modal" class="modal fade" role="dialog"> </div>
{{footer}}
</body>
</html>
@@ -0,0 +1,20 @@
<?php
use Template\RenderableTemplate as RenderableTemplate;
class DefaultTemplate extends RenderableTemplate {
public function __construct() {
}
public function render() {
if (is_file($this->getView()['location'])) {
$this->content = file_get_contents($this->getView()['location']);
$this->implate();
}
}
}