2002-01-13 13:18:48 +00:00
|
|
|
<?php
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
// initialize modules:
|
|
|
|
function module_init() {
|
2004-01-05 19:19:05 +00:00
|
|
|
// Note: changing this also requires changing system_listing() @ modules/system.module.
|
2003-01-06 19:51:01 +00:00
|
|
|
require_once "modules/admin.module";
|
2004-01-05 19:19:05 +00:00
|
|
|
require_once "modules/filter.module";
|
2002-05-23 19:01:49 +00:00
|
|
|
require_once "modules/system.module";
|
2004-01-05 19:19:05 +00:00
|
|
|
require_once "modules/user.module";
|
2002-05-23 19:01:49 +00:00
|
|
|
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) {
|
2004-01-05 19:19:05 +00:00
|
|
|
$list = array("admin" => "admin", "filter" => "filter", "system" => "system", "user" => "user", "watchdog" => "watchdog");
|
2004-01-26 18:55:43 +00:00
|
|
|
if ($bootstrap) {
|
|
|
|
$result = db_query("SELECT name, filename, throttle, bootstrap FROM {system} WHERE type = 'module' AND status = 1 AND bootstrap = 1");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$result = db_query("SELECT name, filename, throttle, bootstrap FROM {system} WHERE type = 'module' AND status = 1");
|
|
|
|
}
|
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-12-07 18:25:09 +00:00
|
|
|
/*
|
|
|
|
** Determine the current throttle status and see if module should be
|
|
|
|
** loaded based on server load. We have to directly access the
|
|
|
|
** throttle variables as the throttle.module may not be loaded yet.
|
|
|
|
*/
|
2004-01-19 22:11:46 +00:00
|
|
|
$throttle = ($module->throttle && variable_get("throttle_level", 0) > 4);
|
2004-01-26 18:55:43 +00:00
|
|
|
if (!$throttle) {
|
2003-11-18 19:44:36 +00:00
|
|
|
$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
|
|
|
}
|
2004-01-27 18:14:25 +00:00
|
|
|
asort($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
|
|
|
?>
|