diff --git a/.gitignore b/.gitignore
index bb878b7..e3205bb 100755
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
+.idea
+
config/database.db
config/modules.ini
@@ -6,4 +8,4 @@ vendor/
composer.lock
!public/.htaccess
-!public/index.php
\ No newline at end of file
+!public/index.php
diff --git a/application/module/core/generator/GeneratorController.php b/application/module/core/generator/GeneratorController.php
old mode 100644
new mode 100755
index fa7e111..a4240e0
--- a/application/module/core/generator/GeneratorController.php
+++ b/application/module/core/generator/GeneratorController.php
@@ -31,9 +31,9 @@ class GeneratorController {
};
/* $menu = (new CliMenuBuilder)
- ->setTitle(Lang::get_string('main_title', 'generator'))
- ->addItem(Lang::get_string('name_definition', 'generator'), $module_name)
- ->addItem(Lang::get_string('show_info', 'generator'), $show_info)
+ ->setTitle(Lang::getString('main_title', 'generator'))
+ ->addItem(Lang::getString('name_definition', 'generator'), $module_name)
+ ->addItem(Lang::getString('show_info', 'generator'), $show_info)
->setItemExtra('[COMPLETE!]')
->addLineBreak('-')
->setBorder(1, 2, 'yellow')
diff --git a/application/module/core/generator/Routes.php b/application/module/core/generator/Routes.php
index 88ba51d..ffd2bb5 100755
--- a/application/module/core/generator/Routes.php
+++ b/application/module/core/generator/Routes.php
@@ -1,23 +1,23 @@
_verb), 10) . "| $route->_uri \n";
}
});
-RouteCollection::add('CLI', '/core/generator', function(){
+RouteCollection::cli('/core/generator', function(){
include_once 'GeneratorController.php';
last_class()->menu();
diff --git a/application/module/core/lang/en.php b/application/module/core/lang/en.php
old mode 100644
new mode 100755
index a76f3b5..e38514b
--- a/application/module/core/lang/en.php
+++ b/application/module/core/lang/en.php
@@ -1,5 +1,5 @@
do_block()->set_http_error(500);
+ if(INSTALL_REQUIRE){
+ //App need to be installed
+ if (!is_file(DIR_CONFIG . 'modules.ini')) {
+ $ROUTE->do_block()->set_http_error(500);
+ }
}
+
}, -19)->do_ignore()->middleware_ignore('auth');
\ No newline at end of file
diff --git a/application/module/core/template/Output.class.php b/application/module/core/template/Output.class.php
index 468e264..dbea721 100755
--- a/application/module/core/template/Output.class.php
+++ b/application/module/core/template/Output.class.php
@@ -3,16 +3,17 @@
class Output {
private static $_instance;
- private $_doctype = "";
- 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[] = '';
-
- $this->_head_items[] = '';
-
- $this->_head_items[] = '';
-
- $this->_head_items[] = '';
- $this->_head_items[] = '';
-
- $this->_head_items[] = '';
-
- $this->_head_items[] = '';
- $this->_head_items[] = '';
-
- $this->_head_items[] = '';
-
- $this->_head_items[] = '';
- $this->_head_items[] = '';
-
- $this->_head_items[] = '';
- $this->_head_items[] = '';
-
- $this->_head_items[] = '';
- $this->_head_items[] = '';
-
- $this->_foot_items[] = '';
-
- $head = "
";
- foreach ($this->_head_items as $head_item) {
- $head .= $head_item . "\n";
- }
- $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 .= '
';
-
- $body_end = file_get_contents(__DIR__ . "/views/body_section.html");
- $body_end = str_replace("{{footer}}", $foot, $body_end);
-
- echo $this->_doctype . "\n";
- echo " \n";
- echo $head;
- echo $body_first;
- if ($this->view) {
- $this->render_view();
- }
- echo $body_end;
- echo "";
+ include_once __DIR__."/classes/".strtolower($this->_template)."/".$this->_template.'.php';
+ last_class()->setView($this->view)->render();
}
-
- public function set_content($content) {
- $this->_content = $content;
- }
-
}
diff --git a/application/module/core/template/Routes.php b/application/module/core/template/Routes.php
index 72a3822..ee74112 100755
--- a/application/module/core/template/Routes.php
+++ b/application/module/core/template/Routes.php
@@ -1,9 +1,9 @@
content = file_get_contents($this->getView()['location']);
+ $this->implate();
+ return;
+ }
+
+ global $DROPDOWN, $SIDEBAR;
+
+ $head = '';
+ $head .= '';
+ $head .= '';
+
+ $head .= '';
+
+ $head .= '';
+
+ $head .= '';
+ $head .= '';
+
+ $head .= '';
+
+ $head .= '';
+ $head .= '';
+
+ $head .= '';
+
+ $head .= '';
+ $head .= '';
+
+ $head .= '';
+ $head .= '';
+
+ $head .= '';
+ $head .= '';
+
+ $head .= '';
+ $head .= '';
+
+ $foot = '';
+ $foot .= '';
+ $foot .= '';
+
+ $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();
+
+ }
+
+}
diff --git a/application/module/core/template/classes/dashboard/template.html b/application/module/core/template/classes/dashboard/template.html
new file mode 100755
index 0000000..c330000
--- /dev/null
+++ b/application/module/core/template/classes/dashboard/template.html
@@ -0,0 +1,71 @@
+
+
+ {{head}}
+
+
+
+
+
+ {{footer}}
+
+
\ No newline at end of file
diff --git a/application/module/core/template/classes/defaulttemplate/DefaultTemplate.php b/application/module/core/template/classes/defaulttemplate/DefaultTemplate.php
new file mode 100755
index 0000000..d578fba
--- /dev/null
+++ b/application/module/core/template/classes/defaulttemplate/DefaultTemplate.php
@@ -0,0 +1,20 @@
+getView()['location'])) {
+ $this->content = file_get_contents($this->getView()['location']);
+ $this->implate();
+ }
+
+ }
+
+}
diff --git a/application/module/core/wellcome/Routes.php b/application/module/core/wellcome/Routes.php
index 283d1d4..3152aa0 100755
--- a/application/module/core/wellcome/Routes.php
+++ b/application/module/core/wellcome/Routes.php
@@ -1,13 +1,16 @@
load_view('wellcome');
-})->middleware_ignore('auth');
+include_once 'WellcomeController.php';
-RouteCollection::add("GET", '/wellcome', function() {
- Response::json('This is an other wellcome message')->send();
-})->middleware_ignore('auth');
+RouteCollection::add('GET','/', function(){
+
+ global $OUTPUT;
+ $OUTPUT->setTemplate();
+ $OUTPUT->renderView('wellcome', Array('string' => Array('welcome' => 'Bem vindo')));
+
+ //$OUTPUT->renderView('wellcome', Array('string' => Lang::getStrings('welcome')));
+});
+
+RouteCollection::add('get', '/welcome', 'WellcomeController@welcome');
diff --git a/application/module/core/wellcome/WellcomeController.php b/application/module/core/wellcome/WellcomeController.php
new file mode 100755
index 0000000..13ea3f2
--- /dev/null
+++ b/application/module/core/wellcome/WellcomeController.php
@@ -0,0 +1,11 @@
+ Lang::getString('welcome', 'welcome')))->send()->done();
+ }
+
+}
\ No newline at end of file
diff --git a/application/module/core/wellcome/lang/en.php b/application/module/core/wellcome/lang/en.php
index a4abe2d..b7c9773 100755
--- a/application/module/core/wellcome/lang/en.php
+++ b/application/module/core/wellcome/lang/en.php
@@ -1,2 +1,7 @@
-
-Wellcome to hell...
+{{string.welcome}} to hell...
I shal be your guide
\ No newline at end of file
diff --git a/bootstrap.php b/bootstrap.php
index 0614bd3..848f6c7 100755
--- a/bootstrap.php
+++ b/bootstrap.php
@@ -4,11 +4,13 @@ include_once 'vendor/autoload.php';
include_once 'config/info.php';
include_once 'publiclib.php';
-include_once 'config/database.php';
+if(is_file('config/database.php')){
+ include_once 'config/database.php';
+}
-use BBRouter\RouteCollection as RouteCollection;
+use Routes\RouteCollection as RouteCollection;
-Lang::build_strings();
+Lang::buildStrings();
RouteCollection::getInstance()->crawl(__DIR__.'/application')->load_routes();
-RouteCollection::getInstance()->submit();
\ No newline at end of file
+RouteCollection::getInstance()->submit();
diff --git a/config/info.php b/config/info.php
index 8109b7e..91360a0 100755
--- a/config/info.php
+++ b/config/info.php
@@ -6,3 +6,12 @@ define('DIR_CONFIG', __DIR__.'/');
define('DIR_ROOT', __DIR__.'/../');
define('DIR_APPLICATION', DIR_ROOT . 'application/');
define('DIR_MODULE', DIR_APPLICATION . 'module/');
+
+define('TEMPLATE_DEFAULT', 'Dashboard');
+//define('TEMPLATE_DEFAULT', 'DefaultTemplate');
+define('TEMPLATE_FILETYPE', '.mustache');
+
+
+define('INSTALL_REQUIRE', FALSE);
+
+define('CACHE_LANG', FALSE);
\ No newline at end of file
diff --git a/publiclib.php b/publiclib.php
index ac095dd..4311f98 100755
--- a/publiclib.php
+++ b/publiclib.php
@@ -177,7 +177,18 @@ $_LANG = Array();
class Lang {
- public static function get_string($string = '', $module = null, $lang = null) {
+ public static function getStrings($module = '', $lang = null){
+ global $_LANG;
+ if($lang == null){
+ $lang = APP_LANG;
+ }
+ if (isset($_LANG[$lang][$module])) {
+ return $_LANG[$lang][$module];
+ }
+ return $module;
+ }
+
+ public static function getString($string = '', $module = null, $lang = null) {
global $_LANG;
if($lang == null){
$lang = APP_LANG;
@@ -191,10 +202,10 @@ class Lang {
return $string;
}
- public static function build_strings() {
+ public static function buildStrings() {
global $_LANG;
- if (isset($_SESSION['cache']['strings'])) {
+ if (isset($_SESSION['cache']['strings']) && CACHE_LANG) {
$_LANG = $_SESSION['cache']['strings'];
return;
}
@@ -217,28 +228,4 @@ class Lang {
abstract class Controller {
-}
-
-/*function load_view($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 );
-}*/
+}
\ No newline at end of file