diff --git a/README.md b/README.md index b5929d1..595c3b6 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,22 @@ Engine Implementation.
  • Dwoo tempalte eninge tests
  • Twig tempalte eninge tests
  • Improved routing
  • - + +

    Update

    +

    Version 0.2 beta 19.07.2017

    + +

    Still in progress for the next version

    + diff --git a/application/controller/indexController.php b/application/controller/indexController.php index b1813bd..4e3a606 100644 --- a/application/controller/indexController.php +++ b/application/controller/indexController.php @@ -14,8 +14,7 @@ class indexController extends View implements IController { public function __construct() { - $this->navigationAction(); - $this->pageAction(); + } public function pageAction() diff --git a/application/settings/config/navigation.json b/application/settings/config/navigation.json index 28a24dd..0eabcbd 100644 --- a/application/settings/config/navigation.json +++ b/application/settings/config/navigation.json @@ -1,6 +1,6 @@ { "navigation" : { - "Home": { "link": "/", "tooltip": "Home", "icon": "icon-home" } + "Home": { "link": "/", "tooltip": "Home", "icon": "icon icon-home" } } } \ No newline at end of file diff --git a/application/view/templates/navigation.tpl b/application/view/templates/navigation.tpl index 0528a55..a309b59 100644 --- a/application/view/templates/navigation.tpl +++ b/application/view/templates/navigation.tpl @@ -6,10 +6,17 @@ diff --git a/core/c/dispatcher.php b/core/c/dispatcher.php new file mode 100644 index 0000000..d702a29 --- /dev/null +++ b/core/c/dispatcher.php @@ -0,0 +1,52 @@ +route(); + require_once __DIR__ . '/../../application/controller/' . Router::getInstance()->tplName() . 'Controller.php'; + $class = "Sunrise\\".\Sunrise\Router::getInstance()->tplName()."Controller"; + $controller = new $class(); + + if(array_key_exists('_action', $_REQUEST)) + { + $action = $_REQUEST['_action']."Action"; + $controller->navigationAction(); + $controller->$action(); + $controller->pageAction(); + } + else + { + $controller->navigationAction(); + $controller->pageAction(); + } + + Debug::getInstance(); + Display::getInstance()->display(); + } +} \ No newline at end of file diff --git a/core/c/json-navigation.php b/core/c/json-navigation.php old mode 100644 new mode 100755 index 9e54ae5..f77ed78 --- a/core/c/json-navigation.php +++ b/core/c/json-navigation.php @@ -44,7 +44,7 @@ class JsonNavigation extends Config */ private static function setFileContentString( ) { - self::$_file_content_string = file_get_contents( Settings::SETTINGS_PATH . self::getConfig()["SETTINGS"]["navigation"] ); + self::$_file_content_string = file_get_contents( Settings::SETTINGS_PATH . parent::getInstance()->getConfig()["SETTINGS"]["navigation"] ); } /** @@ -60,7 +60,7 @@ class JsonNavigation extends Config */ private static function setFileContentArray( ) { - self::$_file_content_array = file( Settings::SETTINGS_PATH . self::getConfig()["SETTINGS"]["navigation"] ); + self::$_file_content_array = file( Settings::SETTINGS_PATH . parent::getInstance()->getConfig()["SETTINGS"]["navigation"] ); } /** @@ -116,12 +116,24 @@ class JsonNavigation extends Config $keys = array_keys($value); for($i=0; sizeof($keys)>$i;$i++) { - self::$_navigation_array[] = array( - 'title' => $keys[$i], - 'icon' => $value[$keys[$i]]["icon"], - 'link' => $value[$keys[$i]]["link"], - 'tooltip' => $value[$keys[$i]]["tooltip"], - ); + if(array_key_exists('link', $value[$keys[$i]])) + { + self::$_navigation_array[] = array( + 'title' => $keys[$i], + 'icon' => $value[$keys[$i]]["icon"], + 'link' => $value[$keys[$i]]["link"], + 'tooltip' => $value[$keys[$i]]["tooltip"] + ); + } + elseif(array_key_exists('onclick', $value[$keys[$i]])) + { + self::$_navigation_array[] = array( + 'title' => $keys[$i], + 'icon' => $value[$keys[$i]]["icon"], + 'tooltip' => $value[$keys[$i]]["tooltip"], + 'onclick' => $value[$keys[$i]]["onclick"] + ); + } } } } diff --git a/core/c/mysql.php b/core/c/mysql.php old mode 100644 new mode 100755 index 482a191..a05eaa8 --- a/core/c/mysql.php +++ b/core/c/mysql.php @@ -14,15 +14,15 @@ class Mysql implements IMysql private static $_instance; - private $_dsn = self::PLACE_DSN; - private $_username = self::PLACE_USERNAME; - private $_password = self::PLACE_PASSWORD; - private $_diver = self::PLACE_DRIVER; - private $_hostname = self::PLACE_HOSTNAME; - private $_dbname = self::PLACE_DATABASE; - private $_port = self::PLACE_PORT; + protected $_dsn = self::PLACE_DSN; + protected $_username = self::PLACE_USERNAME; + protected $_password = self::PLACE_PASSWORD; + protected $_diver = self::PLACE_DRIVER; + protected $_hostname = self::PLACE_HOSTNAME; + protected $_dbname = self::PLACE_DATABASE; + protected $_port = self::PLACE_PORT; - private $_conn = self::PLACE_CONNECTION; + protected $_conn = self::PLACE_CONNECTION; protected function __construct( ) { diff --git a/core/c/odbc.php b/core/c/odbc.php new file mode 100755 index 0000000..7cc2977 --- /dev/null +++ b/core/c/odbc.php @@ -0,0 +1,121 @@ +getConfig()[self::SETTINGS_DATABASE]; + $this->_setUsername($settings[self::PLACE_USERNAME]); + $this->_setPassword($settings[self::PLACE_PASSWORD]); + $this->_setDbname($settings[self::PLACE_DATABASE]); + $this->_setDiver($settings[self::PLACE_DRIVER]); + $this->_setHostname($settings[self::PLACE_HOSTNAME]); + $this->_setPort($settings[self::PLACE_PORT]); + $this->_setReadOnly($settings[self::PLACE_READONLY]); + $this->_setDsn(); + $this->_setConn(); + } + + public static function getInstance() + { + $className = get_called_class(); + if(self::$_instance==null) self::$_instance = new $className(); + return self::$_instance; + } + + /** + * @param string $dsn + */ + private function _setDsn( ) + { + $this->_dsn = 'Driver=' . $this->getDiver() . ';Server=' . $this->getHostname() . ';Port=' . $this->getPort() . ';Database=' . $this->getDbname() . ';ReadOnly=' . $this->getReadOnly(); + } + + /** + * @param string $username + */ + private function _setUsername( $username ) + { + $this->_username = $username; + } + + /** + * @param string $password + */ + private function _setPassword( $password ) + { + $this->_password = $password; + } + + /** + * @param mixed $diver + */ + private function _setDiver( $diver ) + { + $this->_diver = $diver; + } + + /** + * @param string $hostname + */ + private function _setHostname( $hostname ) + { + $this->_hostname = $hostname; + } + + /** + * @param string $dbname + */ + private function _setDbname( $dbname ) + { + $this->_dbname = $dbname; + } + + /** + * @param string $conn + */ + private function _setConn( ) + { + $this->_conn = \odbc_connect( $this->getDsn(), $this->getUsername(), $this->getPassword() ); + } + + /** + * @param string $port + */ + private function _setPort( $port ) + { + $this->_port = $port; + } + + /** + * @return boolean + */ + private function getReadOnly() + { + return $this->_readOnly; + } + + /** + * @param boolean $readOnly + */ + protected function _setReadOnly( $readOnly ) + { + $this->_readOnly = $readOnly; + } +} \ No newline at end of file diff --git a/core/c/postgres.php b/core/c/postgres.php new file mode 100755 index 0000000..3770614 --- /dev/null +++ b/core/c/postgres.php @@ -0,0 +1,155 @@ +getConn(), $string); + for($i=1;$row=\odbc_fetch_object($result,$i);$i++) + { + $row_values = array(); + $key_values = array(); + + foreach($row as $key=>$item) + { + $row_values[] = $item; + $key_values[] = $key; + } + $all[] = array_combine($key_values, $row_values); + } + return $all; + } + + public static function fetchRowInArrayById($tablename = IOdbc::PLACE_TABLE_NAME, $id = IOdbc::NO_ID) + { + // TODO: Implement fetchRowInArrayById() method. + } + + public static function fetchRowInArrayByWhere($tablename = IOdbc::PLACE_TABLE_NAME, + $column_name = IOdbc::PLACE_COLUMN_NAME, + $parameter_name = IOdbc::PLACE_SEARCH_TERM) + { + return self::query("SELECT * FROM " . $tablename . " WHERE " . $column_name . "='" . $parameter_name . "';"); + } + + public static function getLastInsertedID() + { + // TODO: Implement getLastInsertedID() method. + } + + public static function fetchTableFieldsAsArray($tablename = IOdbc::PLACE_TABLE_NAME) + { + $columns = array(); + $result = \odbc_columns(parent::getInstance()->getConn(), null, null, $tablename); + for($i=0;$row=\odbc_fetch_object($result, $i);$i++) + { + foreach ($row as $key=>$entry) + { + if(self::FILTER_COLUMN_NAME == $key) + { + $columns[] = $entry; + } + } + } + return $columns; + } + + public static function fetchTableAsArray($tablename = IOdbc::PLACE_TABLE_NAME) + { + return self::query("SELECT * FROM " . $tablename . ";"); + } + + public static function insertArrayIntoTable($tablename = IOdbc::PLACE_TABLE_NAME, + $array_name = IOdbc::PLACE_ARRAY_NAME, + $encrypted = IOdbc::PLACE_DES_ENCRYPT) + { + if(array_key_exists(0, $array_name)) + { + foreach( $array_name as $entry ) + { + $field_names = array_keys( $entry ); + $numItems = sizeof( $field_names ); + $i = 0; + $row = " ( "; + foreach( $field_names as $field ) + { + if( ++$i === $numItems ) + { + $row .= $field; + } + else + { + $row .= $field . ", "; + } + } + $i = 0; + $row .= " ) VALUES ( "; + foreach ( $entry as $field ) + { + if( ++$i === $numItems ) + { + $row .= "'" . $field . "'"; + } + else + { + $row .= "'" . $field . "', "; + } + } + $row .= " )"; + $sql = 'INSERT INTO ' . $tablename . $row . ';'; + + \odbc_exec(parent::getInstance()->getConn(), $sql); + } + } + else + { + $field_names = array_keys($array_name); + $numItems = sizeof($field_names); + $i = 0; + $row = " ( "; + foreach( $field_names as $field ) + { + if( ++$i === $numItems ) + { + $row .= $field; + } + else + { + $row .= $field . ", "; + } + } + $row .= " ) VALUES ( "; + $i = 0; + foreach ( $array_name as $entry ) + { + if( ++$i === $numItems ) + { + $row .= "'" . $entry . "'"; + } + else + { + $row .= "'" . $entry . "', "; + } + } + $row .= " )"; + $sql = 'INSERT INTO ' . $tablename . $row . ';'; + + \odbc_exec(parent::getInstance()->getConn(), $sql); + } + } + +} \ No newline at end of file diff --git a/core/c/router.php b/core/c/router.php old mode 100644 new mode 100755 index 9f3fc80..7825912 --- a/core/c/router.php +++ b/core/c/router.php @@ -12,7 +12,7 @@ namespace Nibiru; class Router extends Config { private static $_routing; - private static $_cur_route; + private static $_cur_route = null; private static $_instance; private static $_cur_page; private static $_routes = array(); @@ -36,6 +36,30 @@ class Router extends Config self::$_routing = Config::getInstance()->getConfig()[View::ATM_ROUTING]; self::setRoutes(self::$_routing); } + + /** + * @return mixed + */ + protected static function getCurRoute() + { + return self::$_cur_route; + } + + /** + * @param mixed $cur_route + */ + private static function _setCurRoute( ) + { + if( Controller::getInstance()->getController() != IController::START_CONTROLLER_NAME ) + { + self::$_cur_route = Controller::getInstance()->getController(); + } + else + { + self::$_cur_route = IController::START_CONTROLLER_NAME; + } + } + /** * @return mixed */ @@ -94,19 +118,25 @@ class Router extends Config */ private static function setCurPage( ) { - - $uri_parts = explode('/', $_SERVER["REQUEST_URI"]); - if(is_array($uri_parts)) + self::_setCurRoute(); + if( self::getCurRoute() == null ) { - if($uri_parts[1] == "") + $uri_parts = explode('/', $_SERVER["REQUEST_URI"]); + if(is_array($uri_parts)) { - self::$_cur_page = "index"; + if($uri_parts[1] == "") + { + self::$_cur_page = "index"; + } + else + { + self::$_cur_page = $uri_parts[1]; + } } - else - { - self::$_cur_page = $uri_parts[1]; - } - + } + else + { + self::$_cur_page = self::getCurRoute(); } } diff --git a/core/c/view.php b/core/c/view.php old mode 100644 new mode 100755 index f341b3c..2131c9e --- a/core/c/view.php +++ b/core/c/view.php @@ -19,6 +19,13 @@ class View extends Controller implements IView private static $smarty = array(); private static $engine = array(); + /** + * @desc not part of the core should be working standalone on the + * $this->buildCsv() method + * @var int + */ + private $xmlPos = 0; + protected function __construct() { Controller::getInstance(); @@ -52,10 +59,10 @@ class View extends Controller implements IView { case Engine::T_ENGINE_SMARTY: self::$engine = new \Smarty(); - self::$engine->setTemplateDir(Config::getInstance()->getConfig()[Engine::T_ENGINE]["templates"]); - self::$engine->setCompileDir(Config::getInstance()->getConfig()[Engine::T_ENGINE]["templates_c"]); - self::$engine->setCacheDir(Config::getInstance()->getConfig()[Engine::T_ENGINE]["cache"]); - self::$engine->setConfigDir(Config::getInstance()->getConfig()[Engine::T_ENGINE]["config_dir"]); + self::$engine->setTemplateDir(__DIR__ . Config::getInstance()->getConfig()[Engine::T_ENGINE]["templates"]); + self::$engine->setCompileDir(__DIR__ . Config::getInstance()->getConfig()[Engine::T_ENGINE]["templates_c"]); + self::$engine->setCacheDir(__DIR__ . Config::getInstance()->getConfig()[Engine::T_ENGINE]["cache"]); + self::$engine->setConfigDir(__DIR__ . Config::getInstance()->getConfig()[Engine::T_ENGINE]["config_dir"]); self::$engine->assign('debuging', Config::getInstance()->getConfig()[Engine::T_ENGINE]["debugbar"]); break; case Engine::T_ENGINE_TWIG: @@ -100,4 +107,32 @@ class View extends Controller implements IView Controller::getInstance()->action( $this->getEngine(), $page ); } + /** + * @param mixed $xmlPos + */ + protected function _setXmlPos( $xmlPos ) + { + $this->xmlPos = $xmlPos; + } + + /** + * @return mixed + */ + protected function getXmlPos( ) + { + return $this->xmlPos; + } + + protected static function printStuffToScreen( $stuff, $die = false ) + { + $output = "
    " . print_r( $stuff, true ) . "
    "; + if( $die ) + { + die( $output ); + } + else + { + return $output; + } + } } \ No newline at end of file diff --git a/core/framework.php b/core/framework.php index 9e34424..d707ab5 100644 --- a/core/framework.php +++ b/core/framework.php @@ -8,6 +8,11 @@ * @license - BSD License */ session_start(); +/** + * @desc Nibiru framework functionality + * TODO: write a javascript controller handler + * in order to be full scale compatible with limbas + */ require_once __DIR__ . '/t/messages.php'; require_once __DIR__ . '/c/settings.php'; require_once __DIR__ . '/c/config.php'; @@ -29,10 +34,29 @@ require_once __DIR__ . '/i/mysql.php'; require_once __DIR__ . '/c/mysql.php'; require_once __DIR__ . '/i/pdo.php'; require_once __DIR__ . '/c/pdo.php'; +require_once __DIR__ . '/i/odbc.php'; +require_once __DIR__ . '/c/odbc.php'; +require_once __DIR__ . '/i/postgres.php'; +require_once __DIR__ . '/c/postgres.php'; + +/** + * @desc currently unfinished + */ require_once __DIR__ . '/i/soap.php'; require_once __DIR__ . '/c/soap.php'; require_once __DIR__ . '/i/auth.php'; require_once __DIR__ . '/c/auth.php'; +/** + * @desc main application starters + */ require_once __DIR__ . '/c/debug.php'; require_once __DIR__ . '/c/display.php'; -require_once __DIR__ . '/dispatch.php'; \ No newline at end of file +/** + * @desc Framework dispatch process + * basic controller and action handling + */ +require_once __DIR__ . '/c/dispatcher.php'; +/** + * @desc Run the framework no game no gain + */ +Nibiru\Dispatcher::getInstance()->run(); \ No newline at end of file diff --git a/core/i/odbc.php b/core/i/odbc.php new file mode 100755 index 0000000..3867fb6 --- /dev/null +++ b/core/i/odbc.php @@ -0,0 +1,16 @@ +