diff options
Diffstat (limited to 'utils/modules.php')
-rw-r--r-- | utils/modules.php | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/utils/modules.php b/utils/modules.php index 4c34228..54682a4 100644 --- a/utils/modules.php +++ b/utils/modules.php @@ -2,14 +2,48 @@ $modules = array(); -/** - * Iterate all defined modules, and load them into the global array. - * FIXME: Make this lazy (load on demand) - */ -foreach($MODULES as $modulename) { - include_once($MODULES_DIR . "/" . $modulename . ".php"); - $module = call_user_func($modulename . "_init"); - $modules[$modulename] = $module; +function loadModule($modulename) +{ + global $MODULES_DIR; + global $modules; + + $modulefile = $MODULES_DIR . "/" . $modulename . ".php"; + if(!$modules[$modulename]) { + if(file_exists($modulefile)) { + include_once($modulefile); + $module = call_user_func($modulename . "_init"); + $modules[$modulename] = $module; + } else { + // Module does not exist. + } + } +} + +function getModuleParams($code) +{ + return explode(",", $code); +} + +function runModule($code) +{ + global $modules; + + $str = ""; + + $m = explode("?", $code); + $module = $m[0]; + $params = getModuleParams($m[1]); + + loadModule($module); + + if($modules[$module]) { + $str .= $modules[$module]->run($params); + } else { + $str .= "<p><strong>CMS ERROR: Could not find module:"; + $str .= " [[" . $modulecode . "]]</strong></p>\n"; + } + + return $str; } ?> |