summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2004-07-31 11:17:27 +0000
committerDries Buytaert <dries@buytaert.net>2004-07-31 11:17:27 +0000
commit9945bca5288ab004ff99701361350b6f250afa10 (patch)
tree2f0d5d5d36c9a73be312e4aa9d7c94b76c2443c4 /includes
parent202eee42a929a0f48ce693e10943cc156ef5a7ef (diff)
downloadbrdo-9945bca5288ab004ff99701361350b6f250afa10.tar.gz
brdo-9945bca5288ab004ff99701361350b6f250afa10.tar.bz2
- Patch #9650 by Adrian: this change introduces a module_load function, which maintains a list of modules that have already been loaded in a static array, and will not load another module of the same name, or if the file does not exist.
Modules can be stored anywhere, as there is now a set of functions called module_get_filename, and module_set_filename .. which allow system_listing and module_list to specify the locations of the files. A new function module_load_all() replaces the hardcoded includes in module_init, and loads all modules which have been enabled, using module_load. module_listing no longer includes files itself, instead it just keeps the listing (and sets the filenames). This patch is a requirement for the multisite configuration patch, as overriding modules are currently being loaded due to the only protection of loading them is include_once.
Diffstat (limited to 'includes')
-rw-r--r--includes/module.inc96
1 files changed, 86 insertions, 10 deletions
diff --git a/includes/module.inc b/includes/module.inc
index 567dedd8e..18c7dfb4c 100644
--- a/includes/module.inc
+++ b/includes/module.inc
@@ -13,12 +13,7 @@
* system_listing() and module_list().
*/
function module_init() {
- require_once 'modules/admin.module';
- require_once 'modules/filter.module';
- require_once 'modules/system.module';
- require_once 'modules/user.module';
- require_once 'modules/watchdog.module';
- module_list();
+ module_load_all();
module_invoke_all('init');
}
@@ -34,9 +29,6 @@ function module_iterate($function, $argument = '') {
/**
* Collect a list of all installed and enabled modules.
*
- * If any modules are enabled but have not yet been loaded, this function performs
- * the include_once() to load them.
- *
* @param $refresh
* Whether to force the module list to be regenerated (such as after the
* administrator has changed the system settings).
@@ -70,7 +62,7 @@ function module_list($refresh = FALSE, $bootstrap = FALSE) {
$throttle = ($module->throttle && variable_get('throttle_level', 0) > 4);
if (!$throttle) {
$list[$module->name] = $module->name;
- include_once $module->filename;
+ module_set_filename($module->name, $module->filename);
}
}
}
@@ -80,6 +72,90 @@ function module_list($refresh = FALSE, $bootstrap = FALSE) {
}
/**
+ * Set the filename of a module, for future loading through module_load()
+ *
+ * @param $module
+ * Name of the module which to specify the filename of.
+ * @param $pa
+ * Filename of the module named $module.
+ * @return
+ * Filename of module, if no $path has been specified.
+ */
+function module_set_filename($module, $path = null) {
+ static $list;
+
+ if ($path) {
+ $list[$module] = $path;
+ }
+ else {
+ return $list[$module] ? $list[$module] : "modules/$module.module";
+ }
+}
+
+/**
+ * Retrieve the filename of a module
+ *
+ * @param $module
+ * Name of the module which to retrieve the filename of.
+ * @return
+ * Filename of module.
+ */
+function module_get_filename($module) {
+ return module_set_filename($module);
+}
+
+/**
+ * Retrieve the path of a module
+ *
+ * @param $module
+ * Name of the module which to retrieve the path of.
+ * @return
+ * Path of module.
+ */
+function module_get_path($module) {
+ return dirname(module_get_filename($module));
+}
+
+/**
+ * Load a module into Drupal, but check first wether a module by the same name
+ * has been loaded, and that the filename being included exists.
+ * @param $module
+ * The name of the module to be loaded.
+ * @return
+ * TRUE if the load was successfull.
+ */
+function module_load($module) {
+ static $loaded = array();
+
+ if (!$loaded[$module]) {
+ $filename = module_get_filename($module);
+ if (file_exists($filename)) {
+ include_once($filename);
+ $loaded[$module] = $filename;
+ return true;
+ }
+ }
+ return false;
+}
+
+
+/**
+ * Load all the modules that have been enabled in the system table.
+ *
+ * @return
+ * TRUE if all modules were loaded successfully
+ */
+function module_load_all() {
+ $list = module_list();
+ $status = true;
+ foreach ($list as $module) {
+ $status = $status && module_load($module);
+ }
+ return $status;
+}
+
+
+/**
* Determine whether a given module exists.
*
* @param $module