summaryrefslogtreecommitdiff
path: root/utils/modules.php
blob: 54682a423015816dac97abfdc13238a3698c2b55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php

$modules = array();

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;
}

?>