diff options
author | deva <deva> | 2010-01-28 13:45:42 +0000 |
---|---|---|
committer | deva <deva> | 2010-01-28 13:45:42 +0000 |
commit | 55b8d42b6422f24196078c8adb6a2a59861d0ef4 (patch) | |
tree | 922cb7c3ed395ac28279d5091d057b9f30bcdbfa /utils/modules.php | |
parent | 657b191f6b4ae00d714fffe6911d8999d0a99873 (diff) |
Lazy load on modules.
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; } ?> |