Révision 3753f249
Ajouté par Assos Assos il y a plus de 10 ans
htmltest/sites/all/modules/libraries/libraries.module | ||
---|---|---|
9 | 9 |
* Implements hook_flush_caches(). |
10 | 10 |
*/ |
11 | 11 |
function libraries_flush_caches() { |
12 |
// Clear static caches. |
|
13 |
// We don't clear the 'libraries_load' static cache, because that could result |
|
14 |
// in libraries that had been loaded before the cache flushing to be loaded |
|
15 |
// again afterwards. |
|
16 |
foreach (array('libraries_get_path', 'libraries_info') as $name) { |
|
17 |
drupal_static_reset($name); |
|
18 |
} |
|
19 |
|
|
12 | 20 |
// @todo When upgrading from 1.x, update.php attempts to flush caches before |
13 | 21 |
// the cache table has been created. |
14 | 22 |
// @see http://drupal.org/node/1477932 |
... | ... | |
133 | 141 |
$files = array(); |
134 | 142 |
foreach ($directories as $dir) { |
135 | 143 |
if (file_exists($dir)) { |
136 |
$files = array_merge($files, file_scan_directory($dir, '@^[a-z0-9._-]+\.libraries\.info$@', array( |
|
144 |
$files = array_merge($files, file_scan_directory($dir, '@^[A-Za-z0-9._-]+\.libraries\.info$@', array(
|
|
137 | 145 |
'key' => 'name', |
138 | 146 |
'recurse' => FALSE, |
139 | 147 |
))); |
... | ... | |
158 | 166 |
* An array of library information, passed by reference. |
159 | 167 |
*/ |
160 | 168 |
function libraries_invoke($group, &$library) { |
169 |
// When introducing new callback groups in newer versions, stale cached |
|
170 |
// library information somehow reaches this point during the database update |
|
171 |
// before clearing the library cache. |
|
172 |
if (empty($library['callbacks'][$group])) { |
|
173 |
return; |
|
174 |
} |
|
175 |
|
|
161 | 176 |
foreach ($library['callbacks'][$group] as $callback) { |
162 | 177 |
libraries_traverse_library($library, $callback); |
163 | 178 |
} |
... | ... | |
333 | 348 |
|
334 | 349 |
if (!isset($libraries)) { |
335 | 350 |
$libraries = array(); |
336 |
// Gather information from hook_libraries_info(). |
|
351 |
|
|
352 |
// Gather information from hook_libraries_info() in enabled modules. |
|
337 | 353 |
foreach (module_implements('libraries_info') as $module) { |
338 | 354 |
foreach (module_invoke($module, 'libraries_info') as $machine_name => $properties) { |
355 |
$properties['info type'] = 'module'; |
|
339 | 356 |
$properties['module'] = $module; |
340 | 357 |
$libraries[$machine_name] = $properties; |
341 | 358 |
} |
342 | 359 |
} |
360 |
|
|
343 | 361 |
// Gather information from hook_libraries_info() in enabled themes. |
344 |
// @see drupal_alter()
|
|
345 |
global $theme, $base_theme_info;
|
|
346 |
if (isset($theme)) {
|
|
347 |
$theme_keys = array();
|
|
348 |
foreach ($base_theme_info as $base) {
|
|
349 |
$theme_keys[] = $base->name;
|
|
350 |
} |
|
351 |
$theme_keys[] = $theme;
|
|
352 |
foreach ($theme_keys as $theme_key) { |
|
353 |
$function = $theme_key . '_' . 'libraries_info';
|
|
362 |
$themes = array();
|
|
363 |
foreach (list_themes() as $theme_name => $theme_info) {
|
|
364 |
if ($theme_info->status && file_exists(drupal_get_path('theme', $theme_name) . '/template.php')) {
|
|
365 |
// Collect a list of viable themes for re-use when calling the alter
|
|
366 |
// hook.
|
|
367 |
$themes[] = $theme_name;
|
|
368 |
|
|
369 |
include_once drupal_get_path('theme', $theme_name) . '/template.php';
|
|
370 |
|
|
371 |
$function = $theme_name . '_libraries_info';
|
|
354 | 372 |
if (function_exists($function)) { |
355 | 373 |
foreach ($function() as $machine_name => $properties) { |
356 |
$properties['theme'] = $theme_key; |
|
374 |
$properties['info type'] = 'theme'; |
|
375 |
$properties['theme'] = $theme_name; |
|
357 | 376 |
$libraries[$machine_name] = $properties; |
358 | 377 |
} |
359 | 378 |
} |
... | ... | |
364 | 383 |
// .info files override module definitions. |
365 | 384 |
foreach (libraries_scan_info_files() as $machine_name => $file) { |
366 | 385 |
$properties = drupal_parse_info_file($file->uri); |
386 |
$properties['info type'] = 'info file'; |
|
367 | 387 |
$properties['info file'] = $file->uri; |
368 | 388 |
$libraries[$machine_name] = $properties; |
369 | 389 |
} |
... | ... | |
373 | 393 |
libraries_info_defaults($properties, $machine_name); |
374 | 394 |
} |
375 | 395 |
|
376 |
// Allow modules to alter the registered libraries. |
|
377 |
drupal_alter('libraries_info', $libraries); |
|
396 |
// Allow enabled modules and themes to alter the registered libraries. |
|
397 |
// drupal_alter() only takes the currently active theme into account, not |
|
398 |
// all enabled themes. |
|
399 |
foreach (module_implements('libraries_info_alter') as $module) { |
|
400 |
$function = $module . '_libraries_info_alter'; |
|
401 |
$function($libraries); |
|
402 |
} |
|
403 |
foreach ($themes as $theme) { |
|
404 |
$function = $theme . '_libraries_info_alter'; |
|
405 |
// The template.php file was included above. |
|
406 |
if (function_exists($function)) { |
|
407 |
$function($libraries); |
|
408 |
} |
|
409 |
} |
|
378 | 410 |
|
379 | 411 |
// Invoke callbacks in the 'info' group. |
380 | 412 |
foreach ($libraries as &$properties) { |
... | ... | |
418 | 450 |
'versions' => array(), |
419 | 451 |
'integration files' => array(), |
420 | 452 |
'callbacks' => array(), |
453 |
// @todo Remove in 7.x-3.x |
|
454 |
'post-load integration files' => FALSE, |
|
421 | 455 |
); |
422 | 456 |
$library['callbacks'] += array( |
423 | 457 |
'info' => array(), |
... | ... | |
461 | 495 |
// Re-use the statically cached value of libraries_info() to save memory. |
462 | 496 |
$library = &libraries_info($name); |
463 | 497 |
|
498 |
// Exit early if the library was not found. |
|
464 | 499 |
if ($library === FALSE) { |
465 | 500 |
return $library; |
466 | 501 |
} |
502 |
|
|
467 | 503 |
// If 'installed' is set, library detection ran already. |
468 | 504 |
if (isset($library['installed'])) { |
469 | 505 |
return $library; |
... | ... | |
600 | 636 |
cache_set($name, $library, 'cache_libraries'); |
601 | 637 |
} |
602 | 638 |
|
639 |
// Exit early if the library was not found. |
|
640 |
if ($library === FALSE) { |
|
641 |
$loaded[$name] = $library; |
|
642 |
return $loaded[$name]; |
|
643 |
} |
|
644 |
|
|
603 | 645 |
// If a variant was specified, override the top-level properties with the |
604 | 646 |
// variant properties. |
605 | 647 |
if (isset($variant)) { |
... | ... | |
652 | 694 |
*/ |
653 | 695 |
function libraries_load_files($library) { |
654 | 696 |
// Load integration files. |
655 |
if (!empty($library['integration files'])) { |
|
656 |
foreach ($library['integration files'] as $module => $files) { |
|
657 |
libraries_load_files(array( |
|
658 |
'files' => $files, |
|
659 |
'path' => '', |
|
660 |
'library path' => drupal_get_path('module', $module), |
|
661 |
)); |
|
697 |
if (!$library['post-load integration files'] && !empty($library['integration files'])) { |
|
698 |
$enabled_themes = array(); |
|
699 |
foreach (list_themes() as $theme_name => $theme) { |
|
700 |
if ($theme->status) { |
|
701 |
$enabled_themes[] = $theme_name; |
|
702 |
} |
|
703 |
} |
|
704 |
foreach ($library['integration files'] as $provider => $files) { |
|
705 |
if (module_exists($provider)) { |
|
706 |
libraries_load_files(array( |
|
707 |
'files' => $files, |
|
708 |
'path' => '', |
|
709 |
'library path' => drupal_get_path('module', $provider), |
|
710 |
'post-load integration files' => FALSE, |
|
711 |
)); |
|
712 |
} |
|
713 |
elseif (in_array($provider, $enabled_themes)) { |
|
714 |
libraries_load_files(array( |
|
715 |
'files' => $files, |
|
716 |
'path' => '', |
|
717 |
'library path' => drupal_get_path('theme', $provider), |
|
718 |
'post-load integration files' => FALSE, |
|
719 |
)); |
|
720 |
} |
|
662 | 721 |
} |
663 | 722 |
} |
664 | 723 |
|
... | ... | |
706 | 765 |
foreach ($library['files']['php'] as $file => $array) { |
707 | 766 |
$file_path = DRUPAL_ROOT . '/' . $path . '/' . $file; |
708 | 767 |
if (file_exists($file_path)) { |
709 |
require_once $file_path;
|
|
768 |
_libraries_require_once($file_path);
|
|
710 | 769 |
$count++; |
711 | 770 |
} |
712 | 771 |
} |
713 | 772 |
} |
714 | 773 |
|
774 |
// Load integration files. |
|
775 |
if ($library['post-load integration files'] && !empty($library['integration files'])) { |
|
776 |
$enabled_themes = array(); |
|
777 |
foreach (list_themes() as $theme_name => $theme) { |
|
778 |
if ($theme->status) { |
|
779 |
$enabled_themes[] = $theme_name; |
|
780 |
} |
|
781 |
} |
|
782 |
foreach ($library['integration files'] as $provider => $files) { |
|
783 |
if (module_exists($provider)) { |
|
784 |
libraries_load_files(array( |
|
785 |
'files' => $files, |
|
786 |
'path' => '', |
|
787 |
'library path' => drupal_get_path('module', $provider), |
|
788 |
'post-load integration files' => FALSE, |
|
789 |
)); |
|
790 |
} |
|
791 |
elseif (in_array($provider, $enabled_themes)) { |
|
792 |
libraries_load_files(array( |
|
793 |
'files' => $files, |
|
794 |
'path' => '', |
|
795 |
'library path' => drupal_get_path('theme', $provider), |
|
796 |
'post-load integration files' => FALSE, |
|
797 |
)); |
|
798 |
} |
|
799 |
} |
|
800 |
} |
|
801 |
|
|
715 | 802 |
return $count; |
716 | 803 |
} |
717 | 804 |
|
805 |
/** |
|
806 |
* Wrapper function for require_once. |
|
807 |
* |
|
808 |
* A library file could set a $path variable in file scope. Requiring such a |
|
809 |
* file directly in libraries_load_files() would lead to the local $path |
|
810 |
* variable being overridden after the require_once statement. This would |
|
811 |
* break loading further files. Therefore we use this trivial wrapper which has |
|
812 |
* no local state that can be tampered with. |
|
813 |
* |
|
814 |
* @param $file_path |
|
815 |
* The file path of the file to require. |
|
816 |
*/ |
|
817 |
function _libraries_require_once($file_path) { |
|
818 |
require_once $file_path; |
|
819 |
} |
|
820 |
|
|
821 |
|
|
718 | 822 |
/** |
719 | 823 |
* Gets the version information from an arbitrary library. |
720 | 824 |
* |
Formats disponibles : Unified diff
Weekly update of contrib modules