2002-01-13 13:18:48 +00:00
|
|
|
<?php
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
// initialize modules:
|
|
|
|
function module_init() {
|
2002-04-14 19:34:04 +00:00
|
|
|
require_once("modules/user.module");
|
|
|
|
require_once("modules/drupal.module");
|
|
|
|
require_once("modules/system.module");
|
|
|
|
require_once("modules/watchdog.module");
|
2002-01-13 13:18:48 +00:00
|
|
|
module_list();
|
|
|
|
}
|
|
|
|
|
|
|
|
// apply function $function to every known module:
|
|
|
|
function module_iterate($function, $argument = "") {
|
|
|
|
foreach (module_list() as $name) $function($name, $argument);
|
|
|
|
}
|
|
|
|
|
|
|
|
// invoke hook $hook of module $name with optional arguments:
|
|
|
|
function module_invoke($name, $hook, $a1 = NULL, $a2 = NULL, $a3 = NULL, $a4 = NULL) {
|
|
|
|
$function = $name ."_". $hook;
|
|
|
|
if (function_exists($function)) {
|
|
|
|
return $function($a1, $a2, $a3, $a4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-30 18:15:02 +00:00
|
|
|
// invoke $hook for all appropriate modules:
|
|
|
|
function module_invoke_all($hook, $a1 = NULL, $a2 = NULL, $a3 = NULL, $a4 = NULL) {
|
|
|
|
$return = array();
|
|
|
|
foreach (module_list() as $name) {
|
|
|
|
if (module_hook($name, $hook)) {
|
|
|
|
if ($result = module_invoke($name, $hook, $a1, $a2, $a3, $a4)) {
|
|
|
|
$return = array_merge($return, $result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2002-01-13 13:18:48 +00:00
|
|
|
// return array of module names (includes lazy module loading):
|
|
|
|
function module_list() {
|
|
|
|
static $list;
|
|
|
|
|
|
|
|
if (!$list) {
|
2002-04-14 19:34:04 +00:00
|
|
|
$list = array("drupal" => "drupal", "system" => "system", "user" => "user", "watchdog" => "watchdog");
|
|
|
|
$result = db_query("SELECT name, filename FROM system WHERE type = 'module' AND status = '1' ORDER BY name");
|
|
|
|
while ($module = db_fetch_object($result)) {
|
|
|
|
$list[$module->name] = $module->name;
|
|
|
|
@include_once "modules/$module->filename";
|
2002-01-13 13:18:48 +00:00
|
|
|
}
|
2002-04-14 19:34:04 +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();
|
|
|
|
return ($list[$name]) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return 1 if module $name implements hook $hook, 0 otherwise:
|
|
|
|
function module_hook($name, $hook) {
|
|
|
|
return function_exists($name ."_". $hook);
|
|
|
|
}
|
|
|
|
|
|
|
|
// rehash module-exported blocks:
|
|
|
|
function module_rehash_blocks($name) {
|
|
|
|
db_query("UPDATE blocks SET remove = '1' WHERE module = '$name'");
|
|
|
|
|
|
|
|
if ($blocks = module_invoke($name, "block")) {
|
|
|
|
foreach ($blocks as $delta => $block) {
|
|
|
|
foreach ($block as $item => $data) {
|
|
|
|
$block[$item] = addslashes($data);
|
|
|
|
}
|
|
|
|
if (!db_fetch_object(db_query("SELECT * FROM blocks WHERE module = '$name' AND name = '$block[info]'"))) {
|
|
|
|
db_query("INSERT INTO blocks (name, module, delta) VALUES ('$block[info]', '$name', '$delta')");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
db_query("UPDATE blocks SET delta = '$delta', remove = '0' WHERE module = '$name' AND name = '$block[info]'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
db_query("DELETE FROM blocks WHERE module = '$name' AND remove = '1'");
|
|
|
|
}
|
|
|
|
|
|
|
|
// rehash a module:
|
|
|
|
function module_rehash($name) {
|
|
|
|
if (module_exist($name)) {
|
|
|
|
$result = db_query("SELECT * FROM modules WHERE name = '$name'");
|
|
|
|
|
|
|
|
if (!$object = db_fetch_object($result)) {
|
|
|
|
db_query("INSERT INTO modules (name) VALUES ('$name')");
|
|
|
|
}
|
|
|
|
|
|
|
|
// rehash module-exported blocks (if necessary):
|
|
|
|
module_rehash_blocks($name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// remove all reference to module:
|
|
|
|
db_query("DELETE FROM modules WHERE name = '$name'");
|
|
|
|
db_query("DELETE FROM blocks WHERE module = '$name'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-14 19:34:04 +00:00
|
|
|
?>
|