2002-01-13 13:18:48 +00:00
|
|
|
<?php
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
// initialize modules:
|
|
|
|
function module_init() {
|
2002-11-08 13:19:12 +00:00
|
|
|
// Note: changing this also requires changing system_admin() @ modules/system.module.
|
2003-01-06 19:51:01 +00:00
|
|
|
require_once "modules/admin.module";
|
2002-05-23 19:01:49 +00:00
|
|
|
require_once "modules/user.module";
|
|
|
|
require_once "modules/system.module";
|
|
|
|
require_once "modules/watchdog.module";
|
2002-01-13 13:18:48 +00:00
|
|
|
module_list();
|
2002-11-29 05:53:40 +00:00
|
|
|
module_invoke_all("init");
|
2002-01-13 13:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// apply function $function to every known module:
|
|
|
|
function module_iterate($function, $argument = "") {
|
2002-10-17 18:34:38 +00:00
|
|
|
foreach (module_list() as $name) {
|
|
|
|
$function($name, $argument);
|
|
|
|
}
|
2002-01-13 13:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// invoke hook $hook of module $name with optional arguments:
|
2002-08-15 07:14:37 +00:00
|
|
|
function module_invoke($name, $hook, $a1 = NULL, $a2 = NULL, $a3 = NULL, $a4 = NULL) {
|
|
|
|
$function = $name ."_". $hook;
|
2002-01-13 13:18:48 +00:00
|
|
|
if (function_exists($function)) {
|
2002-08-15 07:14:37 +00:00
|
|
|
return $function($a1, $a2, $a3, $a4);
|
2002-01-13 13:18:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-30 18:15:02 +00:00
|
|
|
// invoke $hook for all appropriate modules:
|
2002-08-15 07:14:37 +00:00
|
|
|
function module_invoke_all($hook, $a1 = NULL, $a2 = NULL, $a3 = NULL, $a4 = NULL) {
|
2002-01-30 18:15:02 +00:00
|
|
|
$return = array();
|
|
|
|
foreach (module_list() as $name) {
|
2002-12-21 19:10:47 +00:00
|
|
|
$result = module_invoke($name, $hook, $a1, $a2, $a3, $a4);
|
|
|
|
if (isset($result)) {
|
|
|
|
$return = array_merge($return, $result);
|
2002-01-30 18:15:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2003-11-18 19:44:36 +00:00
|
|
|
// return array of module names (includes lazy module loading if not in bootstrap mode)
|
|
|
|
function module_list($refresh = 0, $bootstrap = 0) {
|
2002-01-13 13:18:48 +00:00
|
|
|
static $list;
|
|
|
|
|
2003-03-12 21:46:14 +00:00
|
|
|
if ($refresh) {
|
|
|
|
unset($list);
|
|
|
|
}
|
|
|
|
|
2002-01-13 13:18:48 +00:00
|
|
|
if (!$list) {
|
2003-06-06 14:07:45 +00:00
|
|
|
$list = array("admin" => "admin", "system" => "system", "user" => "user", "watchdog" => "watchdog");
|
2003-11-18 19:44:36 +00:00
|
|
|
$result = db_query("SELECT name, filename, bootstrap FROM {system} WHERE type = 'module' AND status = '1' ORDER BY name");
|
2002-04-14 19:34:04 +00:00
|
|
|
while ($module = db_fetch_object($result)) {
|
2002-11-08 13:19:12 +00:00
|
|
|
if (file_exists($module->filename)) {
|
2003-11-18 19:44:36 +00:00
|
|
|
if ($bootstrap) {
|
|
|
|
$list[$module->name] = array("name"=> $module->name, "bootstrap" => $module->bootstrap, "filename" => $module->filename);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$list[$module->name] = $module->name;
|
|
|
|
include_once $module->filename;
|
|
|
|
}
|
2002-06-01 21:57:29 +00:00
|
|
|
}
|
2002-01-13 13:18:48 +00:00
|
|
|
}
|
2002-11-17 16:26:06 +00:00
|
|
|
natcasesort($list);
|
2002-01-13 13:18:48 +00:00
|
|
|
}
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return 1 if module $name exists, 0 otherwise:
|
|
|
|
function module_exist($name) {
|
|
|
|
$list = module_list();
|
2003-04-21 14:55:03 +00:00
|
|
|
return isset($list[$name]) ? 1 : 0;
|
2002-01-13 13:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// return 1 if module $name implements hook $hook, 0 otherwise:
|
|
|
|
function module_hook($name, $hook) {
|
|
|
|
return function_exists($name ."_". $hook);
|
|
|
|
}
|
|
|
|
|
2002-11-29 05:53:40 +00:00
|
|
|
?>
|