cleanup and test of new router
This commit is contained in:
parent
07650b4646
commit
b57f69d14d
@ -5,6 +5,9 @@ namespace Zotlabs\Web;
|
|||||||
|
|
||||||
class Router {
|
class Router {
|
||||||
|
|
||||||
|
private $modname = '';
|
||||||
|
private $controller = null;
|
||||||
|
|
||||||
function __construct(&$a) {
|
function __construct(&$a) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,25 +57,26 @@ class Router {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if(! (\App::$module_loaded)) {
|
if(! (\App::$module_loaded)) {
|
||||||
$newmod = ucfirst($module);
|
try {
|
||||||
logger('0' . "Zotlabs/Module/{$newmod}.php");
|
$modname = "Zotlabs\\Module\\" . ucfirst($module);
|
||||||
if(file_exists("Zotlabs/Module/{$newmod}.php")) {
|
$filename = 'Zotlabs/Module/'. ucfirst($module). '.php';
|
||||||
logger('1' . "Zotlabs/Module/{$newmod}.php");
|
if(file_exists($filename)) {
|
||||||
include_once("Zotlabs/Module/{$newmod}.php");
|
$this->controller = new $modname;
|
||||||
logger('2');
|
|
||||||
if(class_exists("Zotlabs\\Module\\{$newmod}"))
|
|
||||||
\App::$module_loaded = true;
|
\App::$module_loaded = true;
|
||||||
logger('3');
|
}
|
||||||
|
else throw new \Exception('Module not found');
|
||||||
}
|
}
|
||||||
elseif(file_exists("mod/site/{$module}.php")) {
|
catch(\Exception $e) {
|
||||||
include_once("mod/site/{$module}.php");
|
if(file_exists("mod/site/{$module}.php")) {
|
||||||
\App::$module_loaded = true;
|
include_once("mod/site/{$module}.php");
|
||||||
|
\App::$module_loaded = true;
|
||||||
|
}
|
||||||
|
elseif(file_exists("mod/{$module}.php")) {
|
||||||
|
include_once("mod/{$module}.php");
|
||||||
|
\App::$module_loaded = true;
|
||||||
|
}
|
||||||
|
else logger("mod/{$module}.php not found.");
|
||||||
}
|
}
|
||||||
elseif(file_exists("mod/{$module}.php")) {
|
|
||||||
include_once("mod/{$module}.php");
|
|
||||||
\App::$module_loaded = true;
|
|
||||||
}
|
|
||||||
else logger("mod/{$module}.php not found.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -132,16 +136,6 @@ logger('3');
|
|||||||
* Call module functions
|
* Call module functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$nmod = false;
|
|
||||||
$modname = '';
|
|
||||||
|
|
||||||
$newmod = ucfirst(\App::$module);
|
|
||||||
|
|
||||||
if(class_exists("Zotlabs\\Module\\{$newmod}")) {
|
|
||||||
$nmod = true;
|
|
||||||
$modname = "Zotlabs\\Module\\{$newmod}";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(\App::$module_loaded) {
|
if(\App::$module_loaded) {
|
||||||
\App::$page['page_title'] = \App::$module;
|
\App::$page['page_title'] = \App::$module;
|
||||||
$placeholder = '';
|
$placeholder = '';
|
||||||
@ -156,10 +150,8 @@ logger('3');
|
|||||||
$arr = array('init' => true, 'replace' => false);
|
$arr = array('init' => true, 'replace' => false);
|
||||||
call_hooks(\App::$module . '_mod_init', $arr);
|
call_hooks(\App::$module . '_mod_init', $arr);
|
||||||
if(! $arr['replace']) {
|
if(! $arr['replace']) {
|
||||||
if($modname && method_exists($modname,'init')) {
|
if($this->controller && method_exists($this->controller,'init')) {
|
||||||
logger('function_exists: ' . $modname . '->init');
|
$this->controller->init();
|
||||||
$modclass = new $modname;
|
|
||||||
$modclass->init();
|
|
||||||
}
|
}
|
||||||
elseif(function_exists(\App::$module . '_init')) {
|
elseif(function_exists(\App::$module . '_init')) {
|
||||||
$func = \App::$module . '_init';
|
$func = \App::$module . '_init';
|
||||||
@ -204,22 +196,30 @@ logger('3');
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(($_SERVER['REQUEST_METHOD'] === 'POST') && (! \App::$error) && (! x($_POST, 'auth-params'))) {
|
||||||
if(($_SERVER['REQUEST_METHOD'] === 'POST') && (! \App::$error)
|
|
||||||
&& (function_exists(\App::$module . '_post'))
|
|
||||||
&& (! x($_POST, 'auth-params'))) {
|
|
||||||
call_hooks(\App::$module . '_mod_post', $_POST);
|
call_hooks(\App::$module . '_mod_post', $_POST);
|
||||||
$func = \App::$module . '_post';
|
|
||||||
$func($a);
|
if($this->controller && method_exists($this->controller,'post')) {
|
||||||
|
$this->controller->post();
|
||||||
|
}
|
||||||
|
elseif(function_exists(\App::$module . '_post')) {
|
||||||
|
$func = \App::$module . '_post';
|
||||||
|
$func($a);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if((! \App::$error) && (function_exists(\App::$module . '_content'))) {
|
if(! \App::$error) {
|
||||||
$arr = array('content' => \App::$page['content'], 'replace' => false);
|
$arr = array('content' => \App::$page['content'], 'replace' => false);
|
||||||
call_hooks(\App::$module . '_mod_content', $arr);
|
call_hooks(\App::$module . '_mod_content', $arr);
|
||||||
\App::$page['content'] = $arr['content'];
|
\App::$page['content'] = $arr['content'];
|
||||||
if(! $arr['replace']) {
|
if(! $arr['replace']) {
|
||||||
$func = \App::$module . '_content';
|
if($this->controller && method_exists($this->controller,'get')) {
|
||||||
$arr = array('content' => $func($a));
|
$arr = array('content' => $this->controller->get());
|
||||||
|
}
|
||||||
|
elseif(function_exists(\App::$module . '_content')) {
|
||||||
|
$func = \App::$module . '_content';
|
||||||
|
$arr = array('content' => $func($a));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
call_hooks(\App::$module . '_mod_aftercontent', $arr);
|
call_hooks(\App::$module . '_mod_aftercontent', $arr);
|
||||||
\App::$page['content'] .= $arr['content'];
|
\App::$page['content'] .= $arr['content'];
|
||||||
|
Reference in New Issue
Block a user