| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
define('MODULE_IMPLEMENTS_WRITE_CACHE', -1);
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
define('MODULE_IMPLEMENTS_CLEAR_CACHE', -2);
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
function module_load_all() {
|
| 24 |
foreach (module_list(TRUE) as $module) {
|
| 25 |
drupal_load('module', $module);
|
| 26 |
}
|
| 27 |
}
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
function module_list($refresh = FALSE, $sort = FALSE, $fixed_list = NULL) {
|
| 47 |
static $list = array(), $sorted_list;
|
| 48 |
|
| 49 |
if (empty($list) || $refresh || $fixed_list) {
|
| 50 |
$list = array();
|
| 51 |
$sorted_list = NULL;
|
| 52 |
if ($fixed_list) {
|
| 53 |
foreach ($fixed_list as $name => $module) {
|
| 54 |
drupal_get_filename('module', $name, $module['filename']);
|
| 55 |
$list[$name] = $name;
|
| 56 |
}
|
| 57 |
}
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
$result = db_query("SELECT name, filename FROM {system} WHERE type = 'module' AND status = 1 ORDER BY weight ASC, name ASC");
|
| 65 |
foreach ($result as $module) {
|
| 66 |
if (file_exists($module->filename)) {
|
| 67 |
drupal_get_filename('module', $module->name, $module->filename);
|
| 68 |
$list[$module->name] = $module->name;
|
| 69 |
}
|
| 70 |
}
|
| 71 |
|
| 72 |
}
|
| 73 |
if ($sort) {
|
| 74 |
if (!isset($sorted_list)) {
|
| 75 |
$sorted_list = $list;
|
| 76 |
ksort($sorted_list);
|
| 77 |
}
|
| 78 |
return $sorted_list;
|
| 79 |
}
|
| 80 |
return $list;
|
| 81 |
}
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
function _module_build_dependencies($files) {
|
| 96 |
require_once DRUPAL_ROOT . '/includes/graph.inc';
|
| 97 |
$roots = $files;
|
| 98 |
foreach ($files as $filename => $file) {
|
| 99 |
$graph[$file->name]['edges'] = array();
|
| 100 |
if (isset($file->info['dependencies']) && is_array($file->info['dependencies'])) {
|
| 101 |
foreach ($file->info['dependencies'] as $dependency) {
|
| 102 |
$dependency_data = drupal_parse_dependency($dependency);
|
| 103 |
$graph[$file->name]['edges'][$dependency_data['name']] = $dependency_data;
|
| 104 |
unset($roots[$dependency_data['name']]);
|
| 105 |
}
|
| 106 |
}
|
| 107 |
}
|
| 108 |
drupal_depth_first_search($graph, array_keys($roots));
|
| 109 |
foreach ($graph as $module => $data) {
|
| 110 |
$files[$module]->required_by = isset($data['reverse_paths']) ? $data['reverse_paths'] : array();
|
| 111 |
$files[$module]->requires = isset($data['paths']) ? $data['paths'] : array();
|
| 112 |
$files[$module]->sort = $data['weight'];
|
| 113 |
}
|
| 114 |
return $files;
|
| 115 |
}
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
function module_exists($module) {
|
| 126 |
$list = module_list();
|
| 127 |
return isset($list[$module]);
|
| 128 |
}
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
function module_load_install($module) {
|
| 134 |
|
| 135 |
include_once DRUPAL_ROOT . '/includes/install.inc';
|
| 136 |
|
| 137 |
module_load_include('install', $module);
|
| 138 |
}
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
function module_load_include($type, $module, $name = NULL) {
|
| 163 |
if (empty($name)) {
|
| 164 |
$name = $module;
|
| 165 |
}
|
| 166 |
|
| 167 |
if (drupal_function_exists('drupal_get_path')) {
|
| 168 |
$file = DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . "/$name.$type";
|
| 169 |
if (is_file($file)) {
|
| 170 |
require_once $file;
|
| 171 |
return $file;
|
| 172 |
}
|
| 173 |
}
|
| 174 |
return FALSE;
|
| 175 |
}
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
function module_load_all_includes($type, $name = NULL) {
|
| 182 |
$modules = module_list();
|
| 183 |
foreach ($modules as $module) {
|
| 184 |
module_load_include($type, $module, $name);
|
| 185 |
}
|
| 186 |
}
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
function module_enable($module_list, $disable_modules_installed_hook = FALSE) {
|
| 197 |
$invoke_modules = array();
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
$modules_installed = array_filter($module_list, '_drupal_install_module');
|
| 202 |
foreach ($module_list as $module) {
|
| 203 |
$existing = db_query("SELECT status FROM {system} WHERE type = :type AND name = :name", array(
|
| 204 |
':type' => 'module',
|
| 205 |
':name' => $module))
|
| 206 |
->fetchObject();
|
| 207 |
if ($existing->status == 0) {
|
| 208 |
module_load_install($module);
|
| 209 |
db_update('system')
|
| 210 |
->fields(array('status' => 1))
|
| 211 |
->condition('type', 'module')
|
| 212 |
->condition('name', $module)
|
| 213 |
->execute();
|
| 214 |
drupal_load('module', $module);
|
| 215 |
$invoke_modules[] = $module;
|
| 216 |
watchdog('system', '%module module enabled.', array('%module' => $module), WATCHDOG_INFO);
|
| 217 |
}
|
| 218 |
}
|
| 219 |
|
| 220 |
if (!empty($invoke_modules)) {
|
| 221 |
|
| 222 |
module_list(TRUE);
|
| 223 |
|
| 224 |
registry_rebuild();
|
| 225 |
|
| 226 |
|
| 227 |
if (!$disable_modules_installed_hook && !empty($modules_installed)) {
|
| 228 |
module_invoke_all('modules_installed', $modules_installed);
|
| 229 |
}
|
| 230 |
}
|
| 231 |
|
| 232 |
foreach ($invoke_modules as $module) {
|
| 233 |
module_invoke($module, 'enable');
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
if (drupal_function_exists('node_access_needs_rebuild') && !node_access_needs_rebuild() && module_hook($module, 'node_grants')) {
|
| 239 |
node_access_needs_rebuild(TRUE);
|
| 240 |
}
|
| 241 |
}
|
| 242 |
|
| 243 |
if (!empty($invoke_modules)) {
|
| 244 |
|
| 245 |
|
| 246 |
module_invoke_all('modules_enabled', $invoke_modules);
|
| 247 |
}
|
| 248 |
}
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
function module_disable($module_list) {
|
| 257 |
$invoke_modules = array();
|
| 258 |
foreach ($module_list as $module) {
|
| 259 |
if (module_exists($module)) {
|
| 260 |
|
| 261 |
if (!node_access_needs_rebuild() && module_hook($module, 'node_grants')) {
|
| 262 |
node_access_needs_rebuild(TRUE);
|
| 263 |
}
|
| 264 |
|
| 265 |
module_load_install($module);
|
| 266 |
module_invoke($module, 'disable');
|
| 267 |
db_update('system')
|
| 268 |
->fields(array('status' => 0))
|
| 269 |
->condition('type', 'module')
|
| 270 |
->condition('name', $module)
|
| 271 |
->execute();
|
| 272 |
$invoke_modules[] = $module;
|
| 273 |
watchdog('system', '%module module disabled.', array('%module' => $module), WATCHDOG_INFO);
|
| 274 |
}
|
| 275 |
}
|
| 276 |
|
| 277 |
if (!empty($invoke_modules)) {
|
| 278 |
|
| 279 |
|
| 280 |
module_invoke_all('modules_disabled', $invoke_modules);
|
| 281 |
|
| 282 |
module_list(TRUE);
|
| 283 |
|
| 284 |
registry_rebuild();
|
| 285 |
}
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
if (node_access_needs_rebuild() && count(module_implements('node_grants')) == 0) {
|
| 290 |
node_access_rebuild();
|
| 291 |
}
|
| 292 |
}
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
function module_hook($module, $hook) {
|
| 327 |
$function = $module . '_' . $hook;
|
| 328 |
return function_exists($function) || drupal_function_exists($function);
|
| 329 |
}
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
function module_implements($hook, $sort = FALSE) {
|
| 350 |
static $implementations = array(), $sorted_implementations = array(), $loaded = array(), $cached_hooks = 0, $maintenance;
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
if (!isset($maintenance)) {
|
| 355 |
$maintenance = defined('MAINTENANCE_MODE');
|
| 356 |
}
|
| 357 |
|
| 358 |
if ($maintenance) {
|
| 359 |
return _module_implements_maintenance($hook, $sort);
|
| 360 |
}
|
| 361 |
if ($hook === MODULE_IMPLEMENTS_CLEAR_CACHE) {
|
| 362 |
$implementations = array();
|
| 363 |
$sorted_implementations = array();
|
| 364 |
$loaded = array();
|
| 365 |
$cached_hooks = 0;
|
| 366 |
cache_clear_all('hooks', 'cache_registry');
|
| 367 |
return;
|
| 368 |
}
|
| 369 |
if ($hook === MODULE_IMPLEMENTS_WRITE_CACHE) {
|
| 370 |
|
| 371 |
if (count($implementations) > $cached_hooks) {
|
| 372 |
cache_set('hooks', $implementations, 'cache_registry');
|
| 373 |
}
|
| 374 |
return;
|
| 375 |
}
|
| 376 |
|
| 377 |
if (!isset($loaded[$hook])) {
|
| 378 |
if (empty($implementations) && ($cache = cache_get('hooks', 'cache_registry'))) {
|
| 379 |
$implementations = $cache->data;
|
| 380 |
$cached_hooks = count($implementations);
|
| 381 |
}
|
| 382 |
if (!isset($implementations[$hook])) {
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
$implementations[$hook] = db_query("SELECT module FROM {registry} WHERE type = 'function' AND suffix = :hook ORDER BY weight, module", array(':hook' => $hook))->fetchCol();
|
| 389 |
}
|
| 390 |
foreach ($implementations[$hook] as $module) {
|
| 391 |
$function = $module . '_' . $hook;
|
| 392 |
if (!function_exists($function)) {
|
| 393 |
drupal_function_exists($function);
|
| 394 |
}
|
| 395 |
}
|
| 396 |
$loaded[$hook] = TRUE;
|
| 397 |
}
|
| 398 |
|
| 399 |
if ($sort) {
|
| 400 |
if (!isset($sorted_implementations[$hook])) {
|
| 401 |
$sorted_implementations[$hook] = $implementations[$hook];
|
| 402 |
sort($sorted_implementations[$hook]);
|
| 403 |
}
|
| 404 |
return $sorted_implementations[$hook];
|
| 405 |
}
|
| 406 |
|
| 407 |
return $implementations[$hook];
|
| 408 |
|
| 409 |
}
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
function _module_implements_maintenance($hook, $sort = FALSE) {
|
| 429 |
$implementations = array();
|
| 430 |
foreach (module_list() as $module) {
|
| 431 |
$function = $module . '_' . $hook;
|
| 432 |
if (function_exists($function)) {
|
| 433 |
$implementations[] = $module;
|
| 434 |
}
|
| 435 |
if ($sort) {
|
| 436 |
sort($implementations);
|
| 437 |
}
|
| 438 |
}
|
| 439 |
return $implementations;
|
| 440 |
}
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
function module_invoke() {
|
| 455 |
$args = func_get_args();
|
| 456 |
$module = $args[0];
|
| 457 |
$hook = $args[1];
|
| 458 |
unset($args[0], $args[1]);
|
| 459 |
if (module_hook($module, $hook)) {
|
| 460 |
return call_user_func_array($module . '_' . $hook, $args);
|
| 461 |
}
|
| 462 |
}
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
function module_invoke_all() {
|
| 475 |
$args = func_get_args();
|
| 476 |
$hook = $args[0];
|
| 477 |
unset($args[0]);
|
| 478 |
$return = array();
|
| 479 |
foreach (module_implements($hook) as $module) {
|
| 480 |
$function = $module . '_' . $hook;
|
| 481 |
if (drupal_function_exists($function)) {
|
| 482 |
$result = call_user_func_array($function, $args);
|
| 483 |
if (isset($result) && is_array($result)) {
|
| 484 |
$return = array_merge_recursive($return, $result);
|
| 485 |
}
|
| 486 |
elseif (isset($result)) {
|
| 487 |
$return[] = $result;
|
| 488 |
}
|
| 489 |
}
|
| 490 |
}
|
| 491 |
|
| 492 |
return $return;
|
| 493 |
}
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
function drupal_required_modules() {
|
| 503 |
$files = drupal_system_listing('/\.info$/', 'modules', 'name', 0);
|
| 504 |
$required = array();
|
| 505 |
foreach ($files as $name => $file) {
|
| 506 |
$info = drupal_parse_info_file($file->filepath);
|
| 507 |
if (!empty($info) && !empty($info['required']) && $info['required']) {
|
| 508 |
$required[] = $name;
|
| 509 |
}
|
| 510 |
}
|
| 511 |
return $required;
|
| 512 |
}
|
| 513 |
|