123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173 |
- <?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');
-
- drupal_static_reset('_drupal_file_scan_cache');
- cache_clear_all('_drupal_file_scan_cache', '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) {
- static $files = array();
- if (!isset($name)) {
- $name = $module;
- }
- $key = $type . ':' . $module . ':' . $name;
- if (isset($files[$key])) {
- return $files[$key];
- }
- if (function_exists('drupal_get_path')) {
- $file = DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . "/$name.$type";
- if (is_file($file)) {
- require_once $file;
- $files[$key] = $file;
- return $file;
- }
- else {
- $files[$key] = FALSE;
- }
- }
- 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 ($module = key($module_list)) {
- next($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 ($module = key($module_list)) {
- next($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__);
- $drupal_static_fast['verified'] = &drupal_static(__FUNCTION__ . ':verified');
- }
- $implementations = &$drupal_static_fast['implementations'];
- $verified = &$drupal_static_fast['verified'];
-
-
-
-
-
-
-
-
-
-
- if ($reset) {
- $implementations = array();
- $verified = 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');
- cache_clear_all('system_cache_tables', 'cache');
- return;
- }
-
-
-
-
- if (empty($implementations)) {
- $implementations = cache_get('module_implements', 'cache_bootstrap');
- if ($implementations === FALSE) {
- $implementations = array();
- }
- else {
- $implementations = $implementations->data;
- }
-
-
-
- $verified = array();
- }
- 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') {
-
- $implementations_before = $implementations[$hook];
- drupal_alter('module_implements', $implementations[$hook], $hook);
-
- foreach (array_diff_assoc($implementations[$hook], $implementations_before) as $module => $group) {
-
-
- if ($group) {
- module_load_include('inc', $module, "$module.$group");
- }
-
- if (!function_exists($module . '_' . $hook)) {
- unset($implementations[$hook][$module]);
- }
- }
- }
-
- $verified[$hook] = TRUE;
- }
- elseif (!isset($verified[$hook])) {
-
-
- 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;
- }
- }
- $verified[$hook] = 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() {
-
-
- if (drupal_get_bootstrap_phase() != DRUPAL_BOOTSTRAP_FULL) {
- return;
- }
- $implementations = &drupal_static('module_implements');
- if (isset($implementations['#write_cache'])) {
- 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, &$context3 = 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, $context3);
- }
- }
|