12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058 |
- <?php
- function module_load_all($bootstrap = FALSE) {
- static $has_run = FALSE;
- if (isset($bootstrap)) {
- foreach (module_list(TRUE, $bootstrap) as $module) {
- drupal_load('module', $module);
- }
-
- $has_run = !$bootstrap;
- }
- return $has_run;
- }
- function module_list($refresh = FALSE, $bootstrap_refresh = FALSE, $sort = FALSE, $fixed_list = NULL) {
- static $list = array(), $sorted_list;
- if (empty($list) || $refresh || $fixed_list) {
- $list = array();
- $sorted_list = NULL;
- if ($fixed_list) {
- foreach ($fixed_list as $name => $module) {
- drupal_get_filename('module', $name, $module['filename']);
- $list[$name] = $name;
- }
- }
- else {
- if ($refresh) {
-
-
- drupal_static_reset('system_list');
- }
- if ($bootstrap_refresh) {
- $list = system_list('bootstrap');
- }
- else {
-
- $list = array_keys(system_list('module_enabled'));
- $list = (!empty($list) ? array_combine($list, $list) : array());
- }
- }
- }
- if ($sort) {
- if (!isset($sorted_list)) {
- $sorted_list = $list;
- ksort($sorted_list);
- }
- return $sorted_list;
- }
- return $list;
- }
- function system_list($type) {
- $lists = &drupal_static(__FUNCTION__);
-
-
-
- if ($type == 'bootstrap') {
- if (isset($lists['bootstrap'])) {
- return $lists['bootstrap'];
- }
- if ($cached = cache_get('bootstrap_modules', 'cache_bootstrap')) {
- $bootstrap_list = $cached->data;
- }
- else {
- $bootstrap_list = db_query("SELECT name, filename FROM {system} WHERE status = 1 AND bootstrap = 1 AND type = 'module' ORDER BY weight ASC, name ASC")->fetchAllAssoc('name');
- cache_set('bootstrap_modules', $bootstrap_list, 'cache_bootstrap');
- }
-
-
-
- foreach ($bootstrap_list as $module) {
- drupal_get_filename('module', $module->name, $module->filename);
- }
-
-
- $lists['bootstrap'] = array_keys($bootstrap_list);
- }
-
- elseif (!isset($lists['module_enabled'])) {
- if ($cached = cache_get('system_list', 'cache_bootstrap')) {
- $lists = $cached->data;
- }
- else {
- $lists = array(
- 'module_enabled' => array(),
- 'theme' => array(),
- 'filepaths' => array(),
- );
-
-
-
-
-
- $result = db_query("SELECT * FROM {system} WHERE type = 'theme' OR (type = 'module' AND status = 1) ORDER BY weight ASC, name ASC");
- foreach ($result as $record) {
- $record->info = unserialize($record->info);
-
- if ($record->type == 'module') {
- $lists['module_enabled'][$record->name] = $record;
- }
-
- if ($record->type == 'theme') {
- $lists['theme'][$record->name] = $record;
- }
-
- if ($record->status) {
- $lists['filepaths'][] = array('type' => $record->type, 'name' => $record->name, 'filepath' => $record->filename);
- }
- }
- foreach ($lists['theme'] as $key => $theme) {
- if (!empty($theme->info['base theme'])) {
-
- require_once DRUPAL_ROOT . '/includes/theme.inc';
- $lists['theme'][$key]->base_themes = drupal_find_base_themes($lists['theme'], $key);
-
- if (!current($lists['theme'][$key]->base_themes)) {
- continue;
- }
-
- $base_key = key($lists['theme'][$key]->base_themes);
-
- foreach (array_keys($lists['theme'][$key]->base_themes) as $base_theme) {
- $lists['theme'][$base_theme]->sub_themes[$key] = $lists['theme'][$key]->info['name'];
- }
-
- $lists['theme'][$key]->info['engine'] = isset($lists['theme'][$base_key]->info['engine']) ? $lists['theme'][$base_key]->info['engine'] : 'theme';
- }
- else {
-
- $base_key = $key;
- if (!isset($lists['theme'][$key]->info['engine'])) {
- $lists['theme'][$key]->info['engine'] = 'theme';
- }
- }
-
- $lists['theme'][$key]->prefix = ($lists['theme'][$key]->info['engine'] == 'theme') ? $base_key : $lists['theme'][$key]->info['engine'];
- }
- cache_set('system_list', $lists, 'cache_bootstrap');
- }
-
-
- foreach ($lists['filepaths'] as $item) {
- drupal_get_filename($item['type'], $item['name'], $item['filepath']);
- }
- }
- return $lists[$type];
- }
- function system_list_reset() {
- drupal_static_reset('system_list');
- drupal_static_reset('system_rebuild_module_data');
- drupal_static_reset('list_themes');
- cache_clear_all('bootstrap_modules', 'cache_bootstrap');
- cache_clear_all('system_list', 'cache_bootstrap');
- }
- function _module_build_dependencies($files) {
- require_once DRUPAL_ROOT . '/includes/graph.inc';
- foreach ($files as $filename => $file) {
- $graph[$file->name]['edges'] = array();
- if (isset($file->info['dependencies']) && is_array($file->info['dependencies'])) {
- foreach ($file->info['dependencies'] as $dependency) {
- $dependency_data = drupal_parse_dependency($dependency);
- $graph[$file->name]['edges'][$dependency_data['name']] = $dependency_data;
- }
- }
- }
- drupal_depth_first_search($graph);
- foreach ($graph as $module => $data) {
- $files[$module]->required_by = isset($data['reverse_paths']) ? $data['reverse_paths'] : array();
- $files[$module]->requires = isset($data['paths']) ? $data['paths'] : array();
- $files[$module]->sort = $data['weight'];
- }
- return $files;
- }
- function module_exists($module) {
- $list = module_list();
- return isset($list[$module]);
- }
- function module_load_install($module) {
-
- include_once DRUPAL_ROOT . '/includes/install.inc';
- return module_load_include('install', $module);
- }
- function module_load_include($type, $module, $name = NULL) {
- if (!isset($name)) {
- $name = $module;
- }
- if (function_exists('drupal_get_path')) {
- $file = DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . "/$name.$type";
- if (is_file($file)) {
- require_once $file;
- return $file;
- }
- }
- return FALSE;
- }
- function module_load_all_includes($type, $name = NULL) {
- $modules = module_list();
- foreach ($modules as $module) {
- module_load_include($type, $module, $name);
- }
- }
- function module_enable($module_list, $enable_dependencies = TRUE) {
- if ($enable_dependencies) {
-
- $module_data = system_rebuild_module_data();
-
- $module_list = array_flip(array_values($module_list));
- while (list($module) = each($module_list)) {
- if (!isset($module_data[$module])) {
-
- return FALSE;
- }
- if ($module_data[$module]->status) {
-
- unset($module_list[$module]);
- continue;
- }
- $module_list[$module] = $module_data[$module]->sort;
-
-
- foreach (array_keys($module_data[$module]->requires) as $dependency) {
- if (!isset($module_list[$dependency])) {
- $module_list[$dependency] = 0;
- }
- }
- }
- if (!$module_list) {
-
- return TRUE;
- }
-
- arsort($module_list);
- $module_list = array_keys($module_list);
- }
-
- include_once DRUPAL_ROOT . '/includes/install.inc';
- $modules_installed = array();
- $modules_enabled = array();
- foreach ($module_list as $module) {
-
- $existing = db_query("SELECT status FROM {system} WHERE type = :type AND name = :name", array(
- ':type' => 'module',
- ':name' => $module))
- ->fetchObject();
- if ($existing->status == 0) {
-
- drupal_load('module', $module);
- module_load_install($module);
-
-
-
-
- db_update('system')
- ->fields(array('status' => 1))
- ->condition('type', 'module')
- ->condition('name', $module)
- ->execute();
-
- system_list_reset();
- module_list(TRUE);
- module_implements('', FALSE, TRUE);
- _system_update_bootstrap_status();
-
- registry_update();
-
- drupal_get_schema(NULL, TRUE);
-
- drupal_theme_rebuild();
-
- entity_info_cache_clear();
-
- if (drupal_get_installed_schema_version($module, TRUE) == SCHEMA_UNINSTALLED) {
- drupal_install_schema($module);
-
-
- $versions = drupal_get_schema_versions($module);
- $version = $versions ? max($versions) : SCHEMA_INSTALLED;
-
-
-
- if ($last_removed = module_invoke($module, 'update_last_removed')) {
- $version = max($version, $last_removed);
- }
- drupal_set_installed_schema_version($module, $version);
-
- module_invoke($module, 'install');
-
- $modules_installed[] = $module;
- watchdog('system', '%module module installed.', array('%module' => $module), WATCHDOG_INFO);
- }
-
- module_invoke($module, 'enable');
-
- $modules_enabled[] = $module;
- watchdog('system', '%module module enabled.', array('%module' => $module), WATCHDOG_INFO);
- }
- }
-
- if (!empty($modules_installed)) {
- module_invoke_all('modules_installed', $modules_installed);
- }
-
- if (!empty($modules_enabled)) {
- module_invoke_all('modules_enabled', $modules_enabled);
- }
- return TRUE;
- }
- function module_disable($module_list, $disable_dependents = TRUE) {
- if ($disable_dependents) {
-
- $module_data = system_rebuild_module_data();
-
- $module_list = array_flip(array_values($module_list));
- $profile = drupal_get_profile();
- while (list($module) = each($module_list)) {
- if (!isset($module_data[$module]) || !$module_data[$module]->status) {
-
- unset($module_list[$module]);
- continue;
- }
- $module_list[$module] = $module_data[$module]->sort;
-
-
- foreach ($module_data[$module]->required_by as $dependent => $dependent_data) {
- if (!isset($module_list[$dependent]) && $dependent != $profile) {
- $module_list[$dependent] = 0;
- }
- }
- }
-
- asort($module_list);
- $module_list = array_keys($module_list);
- }
- $invoke_modules = array();
- foreach ($module_list as $module) {
- if (module_exists($module)) {
-
- if (!node_access_needs_rebuild() && module_hook($module, 'node_grants')) {
- node_access_needs_rebuild(TRUE);
- }
- module_load_install($module);
- module_invoke($module, 'disable');
- db_update('system')
- ->fields(array('status' => 0))
- ->condition('type', 'module')
- ->condition('name', $module)
- ->execute();
- $invoke_modules[] = $module;
- watchdog('system', '%module module disabled.', array('%module' => $module), WATCHDOG_INFO);
- }
- }
- if (!empty($invoke_modules)) {
-
- system_list_reset();
- module_list(TRUE);
- module_implements('', FALSE, TRUE);
- entity_info_cache_clear();
-
-
- module_invoke_all('modules_disabled', $invoke_modules);
-
- registry_update();
- _system_update_bootstrap_status();
-
- drupal_theme_rebuild();
- }
-
-
- if (node_access_needs_rebuild() && count(module_implements('node_grants')) == 0) {
- node_access_rebuild();
- }
- }
- function module_hook($module, $hook) {
- $function = $module . '_' . $hook;
- if (function_exists($function)) {
- return TRUE;
- }
-
-
- $hook_info = module_hook_info();
- if (isset($hook_info[$hook]['group'])) {
- module_load_include('inc', $module, $module . '.' . $hook_info[$hook]['group']);
- if (function_exists($function)) {
- return TRUE;
- }
- }
- return FALSE;
- }
- function module_implements($hook, $sort = FALSE, $reset = FALSE) {
-
- static $drupal_static_fast;
- if (!isset($drupal_static_fast)) {
- $drupal_static_fast['implementations'] = &drupal_static(__FUNCTION__);
- }
- $implementations = &$drupal_static_fast['implementations'];
-
-
-
-
-
-
-
-
-
-
- if ($reset) {
- $implementations = array();
- cache_set('module_implements', array(), 'cache_bootstrap');
- drupal_static_reset('module_hook_info');
- drupal_static_reset('drupal_alter');
- cache_clear_all('hook_info', 'cache_bootstrap');
- return;
- }
-
- if (empty($implementations)) {
- $implementations = cache_get('module_implements', 'cache_bootstrap');
- if ($implementations === FALSE) {
- $implementations = array();
- }
- else {
- $implementations = $implementations->data;
- }
- }
- if (!isset($implementations[$hook])) {
-
-
- $implementations['#write_cache'] = TRUE;
- $hook_info = module_hook_info();
- $implementations[$hook] = array();
- $list = module_list(FALSE, FALSE, $sort);
- foreach ($list as $module) {
- $include_file = isset($hook_info[$hook]['group']) && module_load_include('inc', $module, $module . '.' . $hook_info[$hook]['group']);
-
-
- if (function_exists($module . '_' . $hook)) {
- $implementations[$hook][$module] = $include_file ? $hook_info[$hook]['group'] : FALSE;
- }
- }
-
-
- if ($hook != 'module_implements_alter') {
- drupal_alter('module_implements', $implementations[$hook], $hook);
- }
- }
- else {
- foreach ($implementations[$hook] as $module => $group) {
-
-
- if ($group) {
- module_load_include('inc', $module, "$module.$group");
- }
-
-
-
-
-
- if (!function_exists($module . '_' . $hook)) {
-
-
- unset($implementations[$hook][$module]);
- $implementations['#write_cache'] = TRUE;
- }
- }
- }
- return array_keys($implementations[$hook]);
- }
- function module_hook_info() {
-
-
-
-
- if (drupal_bootstrap(NULL, FALSE) != DRUPAL_BOOTSTRAP_FULL) {
- return array();
- }
- $hook_info = &drupal_static(__FUNCTION__);
- if (!isset($hook_info)) {
- $hook_info = array();
- $cache = cache_get('hook_info', 'cache_bootstrap');
- if ($cache === FALSE) {
-
-
-
- foreach (module_list() as $module) {
- $function = $module . '_hook_info';
- if (function_exists($function)) {
- $result = $function();
- if (isset($result) && is_array($result)) {
- $hook_info = array_merge_recursive($hook_info, $result);
- }
- }
- }
-
- foreach (module_list() as $module) {
- $function = $module . '_hook_info_alter';
- if (function_exists($function)) {
- $function($hook_info);
- }
- }
- cache_set('hook_info', $hook_info, 'cache_bootstrap');
- }
- else {
- $hook_info = $cache->data;
- }
- }
- return $hook_info;
- }
- function module_implements_write_cache() {
- $implementations = &drupal_static('module_implements');
-
-
-
- if (isset($implementations['#write_cache']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD')) {
- unset($implementations['#write_cache']);
- cache_set('module_implements', $implementations, 'cache_bootstrap');
- }
- }
- function module_invoke($module, $hook) {
- $args = func_get_args();
-
- unset($args[0], $args[1]);
- if (module_hook($module, $hook)) {
- return call_user_func_array($module . '_' . $hook, $args);
- }
- }
- function module_invoke_all($hook) {
- $args = func_get_args();
-
- unset($args[0]);
- $return = array();
- foreach (module_implements($hook) as $module) {
- $function = $module . '_' . $hook;
- if (function_exists($function)) {
- $result = call_user_func_array($function, $args);
- if (isset($result) && is_array($result)) {
- $return = array_merge_recursive($return, $result);
- }
- elseif (isset($result)) {
- $return[] = $result;
- }
- }
- }
- return $return;
- }
- function drupal_required_modules() {
- $files = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.info$/', 'modules', 'name', 0);
- $required = array();
-
- $required[] = drupal_get_profile();
- foreach ($files as $name => $file) {
- $info = drupal_parse_info_file($file->uri);
- if (!empty($info) && !empty($info['required']) && $info['required']) {
- $required[] = $name;
- }
- }
- return $required;
- }
- function drupal_alter($type, &$data, &$context1 = NULL, &$context2 = NULL) {
-
- static $drupal_static_fast;
- if (!isset($drupal_static_fast)) {
- $drupal_static_fast['functions'] = &drupal_static(__FUNCTION__);
- }
- $functions = &$drupal_static_fast['functions'];
-
-
-
-
- if (is_array($type)) {
- $cid = implode(',', $type);
- $extra_types = $type;
- $type = array_shift($extra_types);
-
-
-
- if (empty($extra_types)) {
- unset($extra_types);
- }
- }
- else {
- $cid = $type;
- }
-
-
-
- if (!isset($functions[$cid])) {
- $functions[$cid] = array();
- $hook = $type . '_alter';
- $modules = module_implements($hook);
- if (!isset($extra_types)) {
-
-
-
- foreach ($modules as $module) {
- $functions[$cid][] = $module . '_' . $hook;
- }
- }
- else {
-
-
- $extra_modules = array();
- foreach ($extra_types as $extra_type) {
- $extra_modules = array_merge($extra_modules, module_implements($extra_type . '_alter'));
- }
-
-
-
-
-
-
-
- if (array_diff($extra_modules, $modules)) {
-
- $modules = array_intersect(module_list(), array_merge($modules, $extra_modules));
-
-
- $implementations = array_fill_keys($modules, FALSE);
-
-
-
-
-
- drupal_alter('module_implements', $implementations, $hook);
- $modules = array_keys($implementations);
- }
- foreach ($modules as $module) {
-
-
-
- $function = $module . '_' . $hook;
- if (function_exists($function)) {
- $functions[$cid][] = $function;
- }
- foreach ($extra_types as $extra_type) {
- $function = $module . '_' . $extra_type . '_alter';
- if (function_exists($function)) {
- $functions[$cid][] = $function;
- }
- }
- }
- }
-
-
- global $theme, $base_theme_info;
- if (isset($theme)) {
- $theme_keys = array();
- foreach ($base_theme_info as $base) {
- $theme_keys[] = $base->name;
- }
- $theme_keys[] = $theme;
- foreach ($theme_keys as $theme_key) {
- $function = $theme_key . '_' . $hook;
- if (function_exists($function)) {
- $functions[$cid][] = $function;
- }
- if (isset($extra_types)) {
- foreach ($extra_types as $extra_type) {
- $function = $theme_key . '_' . $extra_type . '_alter';
- if (function_exists($function)) {
- $functions[$cid][] = $function;
- }
- }
- }
- }
- }
- }
- foreach ($functions[$cid] as $function) {
- $function($data, $context1, $context2);
- }
- }
|