Pārlūkot izejas kodu

Tooo many changes to list

ahwelp 6 gadi atpakaļ
vecāks
revīzija
e696e99c4c

+ 3 - 1
.gitignore

@@ -1,3 +1,5 @@
+.idea
+
 config/database.db
 config/modules.ini
 
@@ -6,4 +8,4 @@ vendor/
 composer.lock
 
 !public/.htaccess
-!public/index.php
+!public/index.php

+ 3 - 3
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')

+ 5 - 5
application/module/core/generator/Routes.php

@@ -1,23 +1,23 @@
 <?php
 
-use BBRouter\RouteCollection as RouteCollection;
+use Routes\RouteCollection as RouteCollection;
 
 
-RouteCollection::add('CLI', '/core/purge', function(){
+RouteCollection::cli('/core/purge', function(){
     echo "Purging Everything\n";
 });
 
-RouteCollection::add('CLI', '/core/purge/[h:module]', function($module){
+RouteCollection::cli('/core/purge/[h:module]', function($module){
     echo "Purgin $module\n";
 });
 
-RouteCollection::add('CLI', '/core/routes', function(){
+RouteCollection::cli('/core/routes', function(){
     foreach(RouteCollection::return_routes() as $route){
         echo str_pad( implode(',', $route->_verb), 10) . "| $route->_uri \n";
     }
 });
 
-RouteCollection::add('CLI', '/core/generator', function(){
+RouteCollection::cli('/core/generator', function(){
 
     include_once 'GeneratorController.php';
     last_class()->menu();

+ 2 - 2
application/module/core/lang/en.php

@@ -1,5 +1,5 @@
 <?php
 
-$string['generator']['module_name'] = 'generator';
+$lang['generator']['module_name'] = 'generator';
 
-$string['generator']['main_title'] = 'Module Generator';
+$lang['generator']['main_title'] = 'Module Generator';

+ 2 - 2
application/module/core/lang/pt_br.php

@@ -1,7 +1,7 @@
 <?php
 
-$string['generator']['module_name'] = 'wellcome';
+$lang['generator']['module_name'] = 'wellcome';
 
-$string['generator']['main_title'] = 'Gerador de modulos!';
+$lang['generator']['main_title'] = 'Gerador de modulos!';
 
 

+ 8 - 5
application/module/core/sanity/Routes.php

@@ -1,9 +1,9 @@
 <?php
 
-use BBRouter\RouteCollection as RouteCollection;
+use Routes\RouteCollection as RouteCollection;
 use DDLWrapper\Wrapper as Wrapper;
 
-RouteCollection::add('CLI', 'sanity/install', function() {
+RouteCollection::cli('sanity/install', function() {
     include_once 'classes/Migrator.class.php';
 
     global $DB;
@@ -17,8 +17,11 @@ RouteCollection::add('CLI', 'sanity/install', function() {
 
 RouteCollection::add('*', '*', function() {
     global $ROUTE;
-    //App need to be installed
-    if (!is_file(DIR_CONFIG . 'modules.ini')) {
-        $ROUTE->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');

+ 27 - 105
application/module/core/template/Output.class.php

@@ -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;
+    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 );
-    }
-
-    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) {
             $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
application/module/core/template/Routes.php

@@ -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';
 

+ 71 - 0
application/module/core/template/classes/dashboard/Dashboard.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();
+        
+    }
+
+}

+ 71 - 0
application/module/core/template/classes/dashboard/template.html

@@ -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>    

+ 20 - 0
application/module/core/template/classes/defaulttemplate/DefaultTemplate.php

@@ -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();
+        }
+        
+    }
+
+}

+ 12 - 9
application/module/core/wellcome/Routes.php

@@ -1,13 +1,16 @@
 <?php
 
-use BBRouter\RouteCollection as RouteCollection;
-use RequestResponse\Response as Response;
+use Routes\RouteCollection as RouteCollection;
 
-RouteCollection::add("GET", '/', function() {
-    global $OUTPUT;        
-    $OUTPUT->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');

+ 11 - 0
application/module/core/wellcome/WellcomeController.php

@@ -0,0 +1,11 @@
+<?php
+
+use RR\Response as R;
+
+class WellcomeController{
+
+    function welcome(){
+        R::json(Array('message' => Lang::getString('welcome', 'welcome')))->send()->done();
+    }
+
+}

+ 5 - 0
application/module/core/wellcome/lang/en.php

@@ -1,2 +1,7 @@
 <?php
 
+$lang['welcome']['module_name'] = 'welcome';
+
+$lang['welcome']['welcome'] = 'Welcome!';
+
+

+ 7 - 0
application/module/core/wellcome/lang/fr.php

@@ -0,0 +1,7 @@
+<?php
+
+$lang['welcome']['module_name'] = 'welcome';
+
+$lang['welcome']['welcome'] = 'Bienvenue!';
+
+

+ 2 - 2
application/module/core/wellcome/lang/pt_br.php

@@ -1,7 +1,7 @@
 <?php
 
-$string['wellcome']['module_name'] = 'wellcome';
+$lang['welcome']['module_name'] = 'welcome';
 
-$string['wellcome']['wellcome'] = 'Bem-vindo!';
+$lang['welcome']['welcome'] = 'Bem-vindo!';
 
 

+ 1 - 2
application/module/core/wellcome/views/wellcome.php → application/module/core/wellcome/views/wellcome.mustache

@@ -1,7 +1,6 @@
 <div style="text-align: center">
     <img src="media/logo_black.png" />
 </div>
-
-Wellcome to hell... 
+{{string.welcome}} to hell...
 <br />
 I shal be your guide

+ 6 - 4
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();
+RouteCollection::getInstance()->submit();

+ 9 - 0
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);

+ 15 - 28
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 );
-}*/
+}