1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * Contains general utility functions for CTools that do not need to be |
---|
6 | * in the module file. |
---|
7 | * |
---|
8 | * In particular, things that are only needed during hook_menu() and |
---|
9 | * hook_theme() are placed here. |
---|
10 | */ |
---|
11 | |
---|
12 | /** |
---|
13 | * Provide a hook passthrough to included files. |
---|
14 | * |
---|
15 | * To organize things neatly, each CTools tool gets its own toolname.$type.inc |
---|
16 | * file. If it exists, it's loaded and ctools_$tool_$type() is executed. |
---|
17 | * To save time we pass the $items array in so we don't need to do array |
---|
18 | * addition. It modifies the array by reference and doesn't need to return it. |
---|
19 | */ |
---|
20 | function ctools_passthrough($module, $type, &$items) { |
---|
21 | $files = drupal_system_listing('.' . $type . '.inc$', drupal_get_path('module', $module) . '/includes', 'name', 0); |
---|
22 | foreach ($files as $file) { |
---|
23 | require_once './' . $file->filename; |
---|
24 | list($tool) = explode('.', $file->name, 2); |
---|
25 | |
---|
26 | $function = $module . '_' . str_replace ('-', '_', $tool) . '_' . $type; |
---|
27 | if (function_exists($function)) { |
---|
28 | $function($items); |
---|
29 | } |
---|
30 | } |
---|
31 | } |
---|
32 | |
---|
33 | /** |
---|
34 | * Implementation of hook_theme_registry_alter() |
---|
35 | */ |
---|
36 | function ctools_theme_registry_alter(&$registry) { |
---|
37 | if ($registry['menu_local_tasks']['function'] == 'theme_menu_local_tasks') { |
---|
38 | $registry['menu_local_tasks'] = array( |
---|
39 | 'function' => 'ctools_theme_menu_local_tasks', |
---|
40 | 'path' => drupal_get_path('module', 'ctools') . '/includes', |
---|
41 | 'file' => 'menu.inc', |
---|
42 | ) + $registry['menu_local_tasks']; |
---|
43 | } |
---|
44 | |
---|
45 | if (isset($registry['help']['function']) && $registry['help']['function'] == 'theme_help') { |
---|
46 | $registry['help'] = array( |
---|
47 | 'function' => 'ctools_menu_help', |
---|
48 | 'path' => drupal_get_path('module', 'ctools') . '/includes', |
---|
49 | 'file' => 'menu.inc', |
---|
50 | ) + $registry['help']; |
---|
51 | } |
---|
52 | |
---|
53 | // Handle a special override for garland because it's cute and does its own |
---|
54 | // thing with tabs and we can't ask users to edit a core theme for us. |
---|
55 | if ($registry['menu_local_tasks']['function'] == 'phptemplate_menu_local_tasks' && |
---|
56 | $registry['menu_local_tasks']['theme paths'][1] == 'themes/garland') { |
---|
57 | $registry['menu_local_tasks'] = array( |
---|
58 | 'function' => 'ctools_garland_menu_local_tasks', |
---|
59 | 'path' => drupal_get_path('module', 'ctools') . '/includes', |
---|
60 | 'file' => 'menu.inc', |
---|
61 | ) + $registry['menu_local_tasks']; |
---|
62 | } |
---|
63 | |
---|
64 | if (isset($registry['page']['preprocess functions'][2]) && |
---|
65 | $registry['page']['preprocess functions'][2] == 'phptemplate_preprocess_page' && |
---|
66 | $registry['page']['theme paths'][1] == 'themes/garland') { |
---|
67 | $registry['page']['preprocess functions'][2] = 'ctools_garland_preprocess_page'; |
---|
68 | } |
---|
69 | |
---|
70 | // Move this one last last last so it can catch changes made by modules and themes. |
---|
71 | $key = array_search('ctools_preprocess_page', $registry['page']['preprocess functions']); |
---|
72 | if ($key) { |
---|
73 | unset($registry['page']['preprocess functions'][$key]); |
---|
74 | } |
---|
75 | $registry['page']['preprocess functions'][] = 'ctools_preprocess_page'; |
---|
76 | } |
---|
77 | |
---|