diff --git a/README.md b/README.md
index 336e369..c1455a1 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# Nibiru
### Rapid Prototyping PHP Framework
-Version 0.4.0 beta
+Version 0.6.0 beta
## Introduction
Nibiru is a rapid prototyping framework written in PHP and based on the MVC design pattern. Now one may say that writing
@@ -67,8 +67,7 @@ Engine Implementation.
The Database access can now be implemented anywhere in your application by adding the namespace to your database accessing Logic:
use Nibiru\Factory\Db;
-Previous version
-Version 0.3.5 beta 14.03.2018
+Version 0.3.5 beta 14.03.2018
- Bugfix on the Router, now the currentPage will be returned correctly.
- Update for the database adapter, a detailed instruction on how to use it will be within the soon comming documentation
@@ -77,7 +76,7 @@ Engine Implementation.
- Minor bugfixing
-Update
+Previous version
Version 0.4.0 beta 28.08.2018
- Minor update concerning the autoloading class in the core, now it is also possible to give a loading order through the configuration
@@ -86,5 +85,15 @@ Engine Implementation.
- Update for multidatabase support, see the documentation on http://www.nibiru-framework.com
+Update
+Version 0.5.0 beta 05.12.2018
+
+- Added a Pagination to the core it now can be used like in the template file Example, the class just needs to be extended by the module that should have a pageination (e.g. a Blog Module)
+- Some extensions for the Routing option, in order to parmeterize the url.
+- Name fixing.
+- Added an additional attribute for the navigation, so the navigation position can be set to footer.
+- A soap extension will not be part of the system anymore, since that is just a bad habit, so this will be replaced with a REST api.
+
+
The start is done, have success with PHP prototyping, and always remember to have fun!
Author: Stephan Kasdorf
\ No newline at end of file
diff --git a/application/settings/config/navigation.json b/application/settings/config/navigation.json
index 0eabcbd..0115bb2 100644
--- a/application/settings/config/navigation.json
+++ b/application/settings/config/navigation.json
@@ -1,6 +1,6 @@
{
"navigation" :
{
- "Home": { "link": "/", "tooltip": "Home", "icon": "icon icon-home" }
+ "Home": { "link": "/", "tooltip": "Home", "icon": "icon icon-home", "footer": "false" }
}
}
\ No newline at end of file
diff --git a/application/view/templates/pageination.tpl b/application/view/templates/pageination.tpl
new file mode 100755
index 0000000..aaaa51b
--- /dev/null
+++ b/application/view/templates/pageination.tpl
@@ -0,0 +1,16 @@
+
+
\ No newline at end of file
diff --git a/core/a/pageination.php b/core/a/pageination.php
new file mode 100755
index 0000000..f629430
--- /dev/null
+++ b/core/a/pageination.php
@@ -0,0 +1,323 @@
+currentPage() . '/' . Controller::getInstance()->getRequest()['_action'] . '/';
+ }
+
+ private static function getUriPaginationPath()
+ {
+ return self::$_uri_pagination_path;
+ }
+
+ private static function loadPaginationToTemplate()
+ {
+ $pagination = array(
+ 'current' => self::getCurrentNumber(),
+ 'next' => self::getNextPageNumber(),
+ 'previous' => self::getPreviousPageNumber(),
+ 'paginationPath' => self::getUriPaginationPath()
+ );
+ for($i=0;$ivarname(View::getInstance()->getEngine(), array('pagination' => $pagination));
+ }
+
+ /**
+ * @return int
+ */
+ private static function getMaxPageEntries()
+ {
+ return self::$_max_page_entries;
+ }
+
+ /**
+ * @param int $max_page_entries
+ */
+ private static function setMaxPageEntries( $max_page_entries )
+ {
+ self::$_max_page_entries = $max_page_entries;
+ }
+
+ private static function currentPageEntryLimit( )
+ {
+ return self::getPageEntryIndex()[self::getCurrentNumber()];
+ }
+
+ /**
+ * @return array
+ */
+ private static function getPageEntryIndex( )
+ {
+ return self::$_page_entry_index;
+ }
+
+ /**
+ * @param array $page_entry_index
+ */
+ private static function setPageEntryIndex( )
+ {
+ $PagesWithFullEntriesIndex = floor(self::getMaxPageEntries()/self::getEntriesPerPage());
+ $limit = array();
+ for($i=1; $i<$PagesWithFullEntriesIndex+1; $i++)
+ {
+ if(!array_key_exists($i-1, $limit))
+ {
+ $limit[$i] = array(
+ 'start' => 0,
+ 'end' => self::getEntriesPerPage()
+ );
+ }
+ else
+ {
+ if(array_key_exists($i, $limit))
+ {
+ if(array_key_exists('start', $limit[$i]))
+ {
+ $start = $limit[$i]['start'];
+ }
+ else
+ {
+ $start = self::PAGE_ITERATION;
+ }
+ }
+ else
+ {
+ $start = self::PAGE_ITERATION;
+ }
+ $limit[$i] = array(
+ 'end' => self::getEntriesPerPage(),
+ 'start' => $start + self::getEntriesPerPage()
+ );
+ }
+ }
+ $fullEntriesOnPages = $PagesWithFullEntriesIndex*self::getEntriesPerPage();
+ if($fullEntriesOnPages $limit[$i-1]['start'] + self::getEntriesPerPage(),
+ 'end' => $lastPageEntries
+ );
+ }
+ self::$_page_entry_index = $limit;
+ self::setUriPaginationPath();
+ self::loadPaginationToTemplate();
+ }
+
+ /**
+ * @return int
+ */
+ private static function getEntriesPerPage()
+ {
+ return self::$_entries_per_page;
+ }
+
+ /**
+ * @param int $entries_per_page
+ */
+ private static function setEntriesPerPage( )
+ {
+ self::$_entries_per_page = Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS]['entriesperpage'];
+ }
+
+ /**
+ * @return int
+ */
+ public static function getMaxPages( )
+ {
+ return self::$_max_pages;
+ }
+
+ /**
+ * @desc if you have deactivated pages you can set a filter here
+ * @param string $where
+ */
+ private static function setMaxPages( $where = '' )
+ {
+ $tableinfo = self::getTable()->loadAllTableFieldNames();
+ self::setMaxPageEntries( self::getTable()->loadTableRowCount( $tableinfo[0], $where ));
+ self::$_max_pages = ceil(self::getMaxPageEntries()/self::getEntriesPerPage());
+ }
+
+ /**
+ * @return boolean
+ */
+ private static function getTable( )
+ {
+ return self::$_table;
+ }
+
+ /**
+ * @param boolean $table
+ */
+ public static function setTable( Adapter\IDb $table, $where = '' )
+ {
+ if(is_object( $table ))
+ {
+ self::setEntriesPerPage();
+ self::$_table = $table;
+ self::setMaxPages( $where );
+ self::setPageEntryIndex();
+ }
+ }
+
+ /**
+ * @return array
+ */
+ protected static function pageContent()
+ {
+ return self::$_current_page_content;
+ }
+
+ /**
+ * @param array $current_page_content
+ */
+ protected static function setCurrentPageContent( )
+ {
+ self::$_current_page_content = array();
+
+ $sortOrderIndex = 0;
+ for($i=0; sizeof( self::getTable()->loadAllTableFieldNames() ) > $i; $i++)
+ {
+ if( self::getTable()->loadAllTableFieldNames()[$i] == 'time' )
+ {
+ $sortOrderIndex = $i;
+ }
+ }
+ self::$_current_page_content = self::getTable()->loadTableAsArray( self::currentPageEntryLimit(), ' ORDER BY ' . self::getTable()->loadAllTableFieldNames()[$sortOrderIndex] . ' DESC ' );
+ }
+
+ /**
+ * @return int
+ */
+ protected static function getCurrentNumber()
+ {
+ return self::$_current_number;
+ }
+
+ /**
+ * @desc the skip param is for using the pagination on a class that
+ * is also used without the pagination, so in order to avoid the
+ * settings not to work, it is possible to skip the currentNumber
+ * setup.
+ * @param int $current_number
+ */
+ protected static function setCurrentNumber( )
+ {
+ try {
+ $page = false;
+ $uri = explode('/', $_SERVER['REQUEST_URI']);
+ foreach ($uri as $uripart)
+ {
+ if($page)
+ {
+ if(is_numeric($uripart))
+ {
+ self::$_current_number = $uripart;
+ Controller::getInstance()->varname(View::getInstance()->getEngine(), array('pagenumber' => self::getCurrentNumber()));
+ $page = false;
+ self::setNextPageNumber();
+ self::setPreviousPageNumber();
+ }
+ else
+ {
+ throw new \Exception('ERROR: the pagenumber has to be a nummeric value!');
+ }
+ }
+ if($uripart == 'page')
+ {
+ $page = true;
+ }
+ }
+ if(self::getCurrentNumber() == self::CURRENT_PAGE)
+ {
+ throw new \Exception('ERROR: URL parameter [page] is missing, please check your class and add the parameter!');
+ }
+ self::setNextPageNumber();
+ self::setPreviousPageNumber();
+
+ }
+ catch (\Exception $e)
+ {
+ echo '';
+ print_r( $e->getMessage() );
+ echo '
';
+ die();
+ }
+ }
+
+ /**
+ * @return int
+ */
+ protected static function getNextPageNumber()
+ {
+ return self::$_next_page_number;
+ }
+
+ /**
+ * @param int $next_page_number
+ */
+ protected static function setNextPageNumber( )
+ {
+ $next_number = self::getCurrentNumber() + self::PAGE_ITERATION;
+
+ if($next_number>self::getMaxPages())
+ {
+ self::$_next_page_number = self::getCurrentNumber();
+ }
+ else
+ {
+ self::$_next_page_number = self::getCurrentNumber() + self::PAGE_ITERATION;
+ }
+ }
+
+ /**
+ * @return int
+ */
+ public static function getPreviousPageNumber()
+ {
+ return self::$_previous_page_number;
+ }
+
+ /**
+ * @param int $previous_page_number
+ */
+ public static function setPreviousPageNumber( )
+ {
+ $prev_number = self::getCurrentNumber() - self::PAGE_ITERATION;
+
+ if($prev_number $keys[$i],
'icon' => $value[$keys[$i]]["icon"],
'link' => $value[$keys[$i]]["link"],
- 'tooltip' => $value[$keys[$i]]["tooltip"]
+ 'tooltip' => $value[$keys[$i]]["tooltip"],
+ 'footer' => $value[$keys[$i]]['footer']
);
}
elseif(array_key_exists('onclick', $value[$keys[$i]]))
@@ -175,7 +176,8 @@ class JsonNavigation extends Config
'title' => $keys[$i],
'icon' => $value[$keys[$i]]["icon"],
'tooltip' => $value[$keys[$i]]["tooltip"],
- 'onclick' => $value[$keys[$i]]["onclick"]
+ 'onclick' => $value[$keys[$i]]["onclick"],
+ 'footer' => $value[$keys[$i]]['footer']
);
}
}
diff --git a/core/c/pdo.php b/core/c/pdo.php
index 2f48490..fa55770 100644
--- a/core/c/pdo.php
+++ b/core/c/pdo.php
@@ -43,6 +43,17 @@ final class Pdo extends Mysql implements IPdo
return $result;
}
+ /**
+ * @param string $string
+ *
+ * @return array
+ */
+ public static function queryString( $string = self::PLACE_NO_QUERY )
+ {
+ $query = parent::getInstance( self::getSettingsSection() )->getConn()->query( $string );
+ return $query->fetchAll();
+ }
+
public static function selectDatasetByFieldAndValue($tablename = self::PLACE_TABLE_NAME, $fieldAndValue = array() )
{
$result = parent::getInstance( self::getSettingsSection() )->getConn()->query("SELECT * FROM " . $tablename . " WHERE " . $fieldAndValue['name'] . " = '" . $fieldAndValue['value'] . "';");
@@ -124,13 +135,34 @@ final class Pdo extends Mysql implements IPdo
// TODO: Implement getLastInsertedID() method.
}
- public static function fetchTableAsArray( $tablename = self::PLACE_TABLE_NAME )
- {
- $statement = parent::getInstance( self::getSettingsSection() )->getConn()->query('SElECT * FROM ' . $tablename);
- $statement->execute();
- $result = $statement->fetchAll( \PDO::FETCH_ASSOC );
- return $result;
- }
+ public static function fetchTableAsArray( $tablename = self::PLACE_TABLE_NAME, $limit = self::PLACE_QUERY_LIMIT, $order = self::PLACE_SORT_ORDER )
+ {
+ if($limit != self::PLACE_QUERY_LIMIT)
+ {
+ if( $order == self::PLACE_SORT_ORDER )
+ {
+ $order = "";
+ }
+ if(is_array($limit))
+ {
+ if(array_key_exists('start', $limit))
+ {
+ $statement = parent::getInstance( self::getSettingsSection() )->getConn()->query('SELECT * FROM ' . $tablename . $order . ' LIMIT ' . $limit['start'] . ', ' . $limit['end'] . ';' );
+ }
+ }
+ else
+ {
+ $statement = parent::getInstance( self::getSettingsSection() )->getConn()->query('SElECT * FROM ' . $tablename . $order . ' LIMIT ' . $limit . ';');
+ }
+ }
+ else
+ {
+ $statement = parent::getInstance( self::getSettingsSection() )->getConn()->query('SElECT * FROM ' . $tablename);
+ }
+ $statement->execute();
+ $result = $statement->fetchAll( \PDO::FETCH_ASSOC );
+ return $result;
+ }
/**
* @desc will insert the array with fieldnames into the database, if the last parameter is set it should be a string containing the
diff --git a/core/c/router.php b/core/c/router.php
index b430a3b..f6213b6 100755
--- a/core/c/router.php
+++ b/core/c/router.php
@@ -17,6 +17,7 @@ class Router extends Config
private static $_cur_page;
private static $_routes = array();
private static $_action;
+ private static $_page_params = array();
protected function __construct()
{
@@ -95,6 +96,7 @@ class Router extends Config
*/
private static function setAction( $action )
{
+ self::$_action = $action;
$_REQUEST['_action'] = $action;
}
@@ -114,17 +116,24 @@ class Router extends Config
}
public function tplName($ending = false)
- {
- self::setCurPage();
- if($ending)
- {
- return self::getCurPage() . ".tpl";
- }
- else
- {
- return self::getCurPage();
- }
- }
+ {
+ preg_match('/\/'.self::getCurPage().'\//', $_SERVER['REQUEST_URI'], $matches);
+ if(!array_key_exists(0, $matches))
+ {
+ self::setCurPage();
+ }
+ if($ending)
+ {
+ self::setPageParams( $_SERVER["REQUEST_URI"] );
+ return self::getCurPage() . ".tpl";
+ }
+ else
+ {
+ self::setPageParams( $_SERVER["REQUEST_URI"] );
+ return self::getCurPage();
+ }
+ }
+
/**
* @return mixed
*/
@@ -134,34 +143,113 @@ class Router extends Config
}
/**
- * @param mixed $cur_page
- */
- private static function setCurPage( )
- {
- if( self::getCurRoute() == null )
- {
- $uri_parts = explode('/', $_SERVER["REQUEST_URI"]);
- if(is_array($uri_parts))
- {
- if($uri_parts[1] == "")
- {
- self::$_cur_page = "index";
- }
- else
- {
- self::$_cur_page = $uri_parts[1];
- if(array_key_exists(2, $uri_parts))
- {
- self::setAction($uri_parts[2]);
- }
- }
- }
- }
- else
- {
- self::$_cur_page = self::getCurRoute();
- }
- }
+ * @desc sets the current page route in the router
+ */
+ private static function setCurPage( )
+ {
+ $params = false;
+ $uri_parts = explode('/', $_SERVER["REQUEST_URI"]);
+ if(is_array($uri_parts))
+ {
+ if($uri_parts[1] == "")
+ {
+ self::$_cur_page = "index";
+ }
+ else
+ {
+ self::$_cur_page = $uri_parts[1];
+ if(array_key_exists(2, $uri_parts))
+ {
+ self::setAction($uri_parts[2]);
+ $params = true;
+ }
+ }
+ if($params)
+ {
+ self::setPageParams( $uri_parts );
+ }
+ }
+ if( self::getCurRoute() != null )
+ {
+ self::$_cur_page = self::getCurRoute();
+ }
+ }
+ /**
+ * @desc will get the current page parameters concerning url parts
+ * e.g. Controller/Action/Param
+ * @return array
+ */
+ public function getPageParams()
+ {
+ return self::$_page_params;
+ }
+
+ /**
+ * @param array $page_params
+ */
+ private static function setPageParams( $uri_parts )
+ {
+ $skip = false;
+ if(is_array($uri_parts))
+ {
+ for($i=2;sizeof($uri_parts)>$i;$i++)
+ {
+ if(is_string($uri_parts[$i]))
+ {
+ if(array_key_exists($i+1, $uri_parts))
+ {
+ if(!is_numeric($uri_parts[$i]))
+ {
+ foreach(self::getRoutes()['route'] as $routing)
+ {
+ if(stristr($routing, '/' . self::getCurPage() . '/'.self::getAction().'/'))
+ {
+ preg_match('/\{(.*?)\}/', $routing, $matches);
+ preg_match('/\/' . self::getCurPage() . '\/' . self::getAction() . '\/\d+/', $_SERVER["REQUEST_URI"], $routematch);
+ if(is_array($routematch))
+ {
+ if(array_key_exists(0, $routematch))
+ {
+ $param_key = $matches[1];
+ $param = $routematch[0];
+ if(is_string($param_key))
+ {
+ if(!$skip && !array_key_exists($param_key, $_REQUEST[$uri_parts[$i]] ))
+ {
+ preg_match('|\d+|', $param, $digit);
+ $_REQUEST[$uri_parts[$i]] = array($param_key => $digit[0]);
+ $skip = true;
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ if($skip)
+ {
+ if(!array_key_exists($uri_parts[$i], $_REQUEST))
+ {
+ $_REQUEST[$uri_parts[$i]] = $uri_parts[$i + 1];
+ }
+ }
+ else
+ {
+ if(!array_key_exists($uri_parts[$i], $_REQUEST))
+ {
+ $_REQUEST[$uri_parts[$i]] = $uri_parts[$i + 1];
+ }
+ }
+ }
+ }
+ }
+
+ }
+ }
+ }
+ }
+ self::$_page_params = $_REQUEST;
+ }
/**
* Returns an array with all the information about the current page
diff --git a/core/c/settings.php b/core/c/settings.php
index c4557c5..d91927c 100644
--- a/core/c/settings.php
+++ b/core/c/settings.php
@@ -67,7 +67,7 @@ class Settings
}
elseif(file_exists('../' . self::SETTINGS_PATH . $current_settings_file))
{
- if($env==config::CLI_SYSTEM)
+ if($env==Config::CLI_SYSTEM)
{
if(self::$_is_db_connection)
{
diff --git a/core/c/soap.php b/core/c/soap.php
deleted file mode 100644
index c0f61ce..0000000
--- a/core/c/soap.php
+++ /dev/null
@@ -1,15 +0,0 @@
-