/[drupal]/contributions/modules/admin_menu/admin_menu.inc
ViewVC logotype

Contents of /contributions/modules/admin_menu/admin_menu.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.67 - (show annotations) (download) (as text)
Thu Oct 29 21:28:17 2009 UTC (4 weeks, 2 days ago) by sun
Branch: MAIN
Changes since 1.66: +2 -2 lines
File MIME type: text/x-php
by sun: Fixed Devel settings form integration no longer working.
1 <?php
2 // $Id: admin_menu.inc,v 1.66 2009/10/28 13:37:41 sun Exp $
3
4 /**
5 * @file
6 * Menu builder functions for Administration menu.
7 */
8
9 /**
10 * Build the administration menu as renderable menu links.
11 *
12 * @param $tree
13 * A data structure representing the administration menu tree as returned from
14 * menu_tree_all_data().
15 *
16 * @return
17 * The complete administration menu, suitable for theme_admin_menu_links().
18 *
19 * @see theme_admin_menu_links()
20 * @see admin_menu_menu_alter()
21 */
22 function admin_menu_links_menu($tree) {
23 $links = array();
24 foreach ($tree as $data) {
25 // Skip menu callbacks (mostly dynamic items).
26 if (isset($data['link']['type']) && $data['link']['type'] == MENU_CALLBACK) {
27 continue;
28 }
29 // Hide 'Administer' and make child links appear on this level.
30 // @todo Make this configurable.
31 if ($data['link']['router_path'] == 'admin') {
32 if ($data['below']) {
33 $links = array_merge($links, admin_menu_links_menu($data['below']));
34 }
35 continue;
36 }
37 // Omit alias lookups.
38 $data['link']['localized_options']['alias'] = TRUE;
39 // Remove description to prevent mouseover tooltip clashes.
40 unset($data['link']['localized_options']['attributes']['title']);
41
42 $links[$data['link']['mlid']] = array(
43 '#title' => $data['link']['title'],
44 '#href' => $data['link']['href'],
45 '#options' => $data['link']['localized_options'],
46 '#weight' => $data['link']['weight'],
47 );
48 if ($data['below']) {
49 $links[$data['link']['mlid']] += admin_menu_links_menu($data['below']);
50 }
51 }
52 return $links;
53 }
54
55 /**
56 * Build icon menu links; mostly containing maintenance helpers.
57 *
58 * @see theme_admin_menu_links()
59 */
60 function admin_menu_links_icon() {
61 $destination = drupal_get_destination();
62
63 $links = array(
64 '#theme' => 'admin_menu_links',
65 '#weight' => -100,
66 );
67 $links['icon'] = array(
68 '#title' => theme('admin_menu_icon'),
69 '#attributes' => array('class' => array('admin-menu-icon')),
70 '#href' => '<front>',
71 '#options' => array(
72 'html' => TRUE,
73 ),
74 );
75 // Add link to manually run cron.
76 $links['icon']['cron'] = array(
77 '#title' => t('Run cron'),
78 '#weight' => 50,
79 '#access' => user_access('administer site configuration'),
80 '#href' => 'admin/reports/status/run-cron',
81 );
82 // Add link to run update.php.
83 $links['icon']['update'] = array(
84 '#title' => t('Run updates'),
85 '#weight' => 50,
86 '#access' => ($GLOBALS['user']->uid == 1 || !empty($GLOBALS['update_free_access'])),
87 '#href' => base_path() . 'update.php',
88 '#options' => array(
89 'external' => TRUE,
90 ),
91 );
92 // Add link to drupal.org.
93 $links['icon']['drupal.org'] = array(
94 '#title' => 'Drupal.org',
95 '#weight' => 100,
96 '#access' => user_access('display drupal links'),
97 '#href' => 'http://drupal.org',
98 );
99 // Add links to project issue queues.
100 foreach (module_list(FALSE, TRUE) as $module) {
101 $info = drupal_parse_info_file(drupal_get_path('module', $module) . '/' . $module . '.info');
102 if (!isset($info['project']) || isset($links['icon']['drupal.org'][$info['project']])) {
103 continue;
104 }
105 $links['icon']['drupal.org'][$info['project']] = array(
106 '#title' => t('@project issue queue', array('@project' => $info['name'])),
107 '#weight' => ($info['project'] == 'drupal' ? -10 : 0),
108 '#href' => 'http://drupal.org/project/issues/' . $info['project'],
109 '#options' => array(
110 'query' => array('version' => (isset($info['core']) ? $info['core'] : 'All')),
111 ),
112 );
113 }
114 // Add items to flush caches.
115 $links['icon']['flush-cache'] = array(
116 '#title' => t('Flush all caches'),
117 '#weight' => 20,
118 // @todo Add permission to flush cashes.
119 '#access' => user_access('administer site configuration'),
120 '#href' => 'admin_menu/flush-cache',
121 '#options' => array(
122 'query' => $destination,
123 ),
124 );
125 $caches = array(
126 'admin_menu' => t('Administration menu'),
127 'cache' => t('Cache tables'),
128 'menu' => t('Menu'),
129 'registry' => t('Class registry'),
130 'requisites' => t('Page requisites'),
131 'theme' => t('Theme registry'),
132 );
133 foreach ($caches as $arg => $title) {
134 $links['icon']['flush-cache'][$arg] = array(
135 '#title' => $title,
136 '#href' => 'admin_menu/flush-cache/' . $arg,
137 '#options' => array(
138 'query' => $destination,
139 ),
140 );
141 }
142 // Add link to toggle developer modules (performance).
143 $saved_state = variable_get('admin_menu_devel_modules_enabled', NULL);
144 $links['icon']['toggle-modules'] = array(
145 '#title' => isset($saved_state) ? t('Enable developer modules') : t('Disable developer modules'),
146 '#weight' => 88,
147 '#access' => user_access('administer site configuration'),
148 '#href' => 'admin_menu/toggle-modules',
149 '#options' => array(
150 'query' => $destination,
151 ),
152 );
153
154 // Add Devel module links.
155 if (module_exists('devel')) {
156 // Add variable editor.
157 $links['icon']['devel-variables'] = array(
158 '#title' => t('Variable editor'),
159 '#weight' => 20,
160 '#access' => user_access('access devel information'),
161 '#href' => 'devel/variable',
162 );
163 }
164
165 return $links;
166 }
167
168 /**
169 * Build user/action links; mostly account information and links.
170 *
171 * @see theme_admin_menu_links()
172 */
173 function admin_menu_links_user() {
174 $links = array(
175 '#theme' => 'admin_menu_links',
176 '#weight' => 100,
177 );
178 // Add link to show current authenticated/anonymous users.
179 $links['user-counter'] = array(
180 '#title' => admin_menu_get_user_count(),
181 '#description' => t('Current anonymous / authenticated users'),
182 '#weight' => -90,
183 '#attributes' => array('class' => array('admin-menu-action', 'admin-menu-users')),
184 '#href' => (user_access('administer users') ? 'admin/user/user' : 'user'),
185 );
186 $links['account'] = array(
187 '#title' => $GLOBALS['user']->name,
188 '#weight' => -99,
189 '#attributes' => array('class' => array('admin-menu-action', 'admin-menu-account')),
190 '#href' => 'user/' . $GLOBALS['user']->uid,
191 );
192 $links['logout'] = array(
193 '#title' => t('Log out'),
194 '#weight' => -100,
195 '#attributes' => array('class' => array('admin-menu-action')),
196 '#href' => 'user/logout',
197 );
198
199 // Add Devel module links.
200 if (module_exists('devel')) {
201 // Add switch user links.
202 foreach (module_invoke('devel', 'switch_user_list') as $link) {
203 $links['account'][$link['title']] = array(
204 '#title' => $link['title'],
205 '#description' => $link['attributes']['title'],
206 '#href' => $link['href'],
207 '#options' => array(
208 'query' => $link['query'],
209 'html' => !empty($link['html']),
210 ),
211 );
212 }
213 }
214
215 return $links;
216 }
217
218 /**
219 * Form builder function for module settings.
220 */
221 function admin_menu_theme_settings() {
222 $form['admin_menu_margin_top'] = array(
223 '#type' => 'checkbox',
224 '#title' => t('Adjust top margin'),
225 '#default_value' => 1,
226 '#description' => t('If enabled, the site output is shifted down approximately 20 pixels from the top of the viewport to display the administration menu. If disabled, some absolute- or fixed-positioned page elements may be covered by the administration menu.'),
227 );
228 $form['admin_menu_position_fixed'] = array(
229 '#type' => 'checkbox',
230 '#title' => t('Keep menu at top of page'),
231 '#default_value' => 0,
232 '#description' => t('If enabled, the administration menu is always displayed at the top of the browser viewport (even after the page is scrolled). <strong>Note: In some browsers, this setting results in a malformed page, an invisible cursor, non-selectable elements in forms, or other issues. Disable this option if these issues occur.</strong>'),
233 );
234 $form['tweaks'] = array(
235 '#type' => 'fieldset',
236 '#title' => t('Advanced settings'),
237 );
238 $form['tweaks']['admin_menu_tweak_modules'] = array(
239 '#type' => 'checkbox',
240 '#title' => t('Collapse fieldsets on modules page'),
241 '#default_value' => 0,
242 '#description' => t('If enabled, fieldsets on the <a href="!modules-url">modules</a> page are automatically collapsed when loading the page.', array('!modules-url' => url('admin/build/modules'))),
243 );
244 if (module_exists('util')) {
245 $form['tweaks']['admin_menu_tweak_modules']['#description'] .= '<br /><strong>' . t('If the Utility module was installed for this purpose, it can be safely disabled and uninstalled.') . '</strong>';
246 }
247 $form['tweaks']['admin_menu_tweak_tabs'] = array(
248 '#type' => 'checkbox',
249 '#title' => t('Move local tasks into menu'),
250 '#default_value' => 0,
251 '#description' => t('If enabled, the tabs on the current page are moved into the administration menu. This feature is only available in themes that use the CSS classes <code>tabs primary</code> and <code>tabs secondary</code> for tabs.'),
252 );
253
254 // Fetch all available modules manually, since module_list() only returns
255 // currently enabled modules, which makes this setting pointless if developer
256 // modules are currently disabled.
257 $all_modules = array();
258 $result = db_query("SELECT name, filename, info FROM {system} WHERE type = 'module' ORDER BY name ASC");
259 foreach ($result as $module) {
260 if (file_exists($module->filename)) {
261 $info = unserialize($module->info);
262 $all_modules[$module->name] = $info['name'];
263 }
264 }
265 $devel_modules = variable_get('admin_menu_devel_modules', _admin_menu_developer_modules());
266 $devel_modules = array_intersect_key($all_modules, array_flip($devel_modules));
267 $form['tweaks']['admin_menu_devel_modules_skip'] = array(
268 '#type' => 'checkboxes',
269 '#title' => t('Developer modules to keep enabled'),
270 '#default_value' => array(),
271 '#options' => $devel_modules,
272 '#access' => !empty($devel_modules),
273 '#description' => t('Enabled developer modules in this list will not be disabled when the link <em>Disable developer modules</em> in the menu below the icon is invoked.'),
274 );
275
276 return system_settings_form($form);
277 }
278
279 /**
280 * Implementation of hook_form_FORM_ID_alter().
281 *
282 * Extends Devel module with Administration menu developer settings.
283 */
284 function _admin_menu_form_devel_admin_settings_alter(&$form, $form_state) {
285 // Shift system_settings_form buttons.
286 $weight = isset($form['buttons']['#weight']) ? $form['buttons']['#weight'] : 0;
287 $form['buttons']['#weight'] = $weight + 1;
288
289 $form['admin_menu'] = array(
290 '#type' => 'fieldset',
291 '#title' => t('Administration menu settings'),
292 '#collapsible' => TRUE,
293 '#collapsed' => TRUE,
294 );
295 $display_options = array('mid', 'weight', 'pid');
296 $display_options = array(0 => t('None'), 'mlid' => t('Menu link ID'), 'weight' => t('Weight'), 'plid' => t('Parent link ID'));
297 $form['admin_menu']['admin_menu_display'] = array(
298 '#type' => 'radios',
299 '#title' => t('Display additional data for each menu item'),
300 '#default_value' => variable_get('admin_menu_display', 0),
301 '#options' => $display_options,
302 '#description' => t('Display the selected items next to each menu item link.'),
303 );
304 $form['admin_menu']['admin_menu_show_all'] = array(
305 '#type' => 'checkbox',
306 '#title' => t('Display all menu items'),
307 '#default_value' => variable_get('admin_menu_show_all', 0),
308 '#description' => t('If enabled, all menu items are displayed regardless of your site permissions. <em>Note: Do not enable on a production site.</em>'),
309 );
310 }
311
312 /**
313 * Menu callback; Enable/disable developer modules.
314 *
315 * This can save up to 150ms on each uncached page request.
316 */
317 function admin_menu_toggle_modules() {
318 $rebuild = FALSE;
319 $saved_state = variable_get('admin_menu_devel_modules_enabled', NULL);
320 if (isset($saved_state)) {
321 // Re-enable modules that were enabled before.
322 module_enable($saved_state);
323 variable_del('admin_menu_devel_modules_enabled');
324 drupal_set_message(t('Enabled these modules: !module-list.', array('!module-list' => implode(', ', $saved_state))));
325 $rebuild = TRUE;
326 }
327 else {
328 // Allow site admins to override this variable via settings.php.
329 $devel_modules = variable_get('admin_menu_devel_modules', _admin_menu_developer_modules());
330 // Store currently enabled modules in a variable.
331 $devel_modules = array_intersect(module_list(FALSE, FALSE), $devel_modules);
332 $devel_modules = array_diff($devel_modules, variable_get('admin_menu_devel_modules_skip', array()));
333 if (!empty($devel_modules)) {
334 variable_set('admin_menu_devel_modules_enabled', $devel_modules);
335 // Disable developer modules.
336 module_disable($devel_modules);
337 drupal_set_message(t('Disabled these modules: !module-list.', array('!module-list' => implode(', ', $devel_modules))));
338 $rebuild = TRUE;
339 }
340 else {
341 drupal_set_message(t('No developer modules are enabled.'));
342 }
343 }
344 if ($rebuild) {
345 // Make sure everything is rebuilt, basically a combination of the calls
346 // from system_modules() and system_modules_submit().
347 drupal_theme_rebuild();
348 menu_rebuild();
349 cache_clear_all('schema', 'cache');
350 cache_clear_all();
351 drupal_clear_css_cache();
352 drupal_clear_js_cache();
353 // Synchronize to catch any actions that were added or removed.
354 actions_synchronize();
355 // Finally, flush admin_menu's cache.
356 admin_menu_flush_caches();
357 }
358 drupal_goto(referer_uri());
359 }
360
361 /**
362 * Helper function to return a default list of developer modules.
363 */
364 function _admin_menu_developer_modules() {
365 return array(
366 'cache_disable',
367 'coder',
368 'content_copy',
369 'debug',
370 'delete_all',
371 'demo',
372 'devel',
373 'devel_node_access',
374 'devel_themer',
375 'macro',
376 'form_controller',
377 'imagecache_ui',
378 'journal',
379 'rules_admin',
380 'stringoverrides',
381 'trace',
382 'upgrade_status',
383 'user_display_ui',
384 'util',
385 'views_ui',
386 'views_theme_wizard',
387 );
388 }
389
390 /**
391 * Flush all caches or a specific one.
392 *
393 * @param $name
394 * (optional) Name of cache to flush.
395 */
396 function admin_menu_flush_cache($name = NULL) {
397 switch ($name) {
398 case 'admin_menu':
399 admin_menu_flush_caches();
400 break;
401
402 case 'menu':
403 menu_rebuild();
404 break;
405
406 case 'registry':
407 registry_rebuild();
408 // Fall-through to clear cache tables, since registry information is
409 // usually the base for other data that is cached (e.g. SimpleTests).
410
411 case 'cache':
412 // Don't clear cache_form - in-progress form submissions may break.
413 // Ordered so clearing the page cache will always be the last action.
414 $core = array('cache', 'cache_block', 'cache_filter', 'cache_page');
415 $cache_tables = array_merge(module_invoke_all('flush_caches'), $core);
416 foreach ($cache_tables as $table) {
417 cache_clear_all('*', $table, TRUE);
418 }
419 break;
420
421 case 'requisites':
422 // Change query-strings on css/js files to enforce reload for all users.
423 _drupal_flush_css_js();
424
425 drupal_clear_css_cache();
426 drupal_clear_js_cache();
427 break;
428
429 case 'theme':
430 module_invoke('system', 'theme_data');
431 drupal_theme_rebuild();
432 break;
433
434 default:
435 // Flush all caches; no need to re-implement this.
436 module_load_include('inc', 'system', 'system.admin');
437 $form = $form_state = array();
438 system_clear_cache_submit($form, $form_state);
439 break;
440 }
441 drupal_goto();
442 }
443
444 /**
445 * Render an icon to display in the administration menu.
446 *
447 * @ingroup themeable
448 */
449 function theme_admin_menu_icon() {
450 return '<img class="admin-menu-icon" src="' . (theme_get_setting('toggle_favicon') ? theme_get_setting('favicon') : base_path() . 'misc/favicon.ico') . '" width="16" height="16" alt="' . t('Home') . '" />';
451 }
452

  ViewVC Help
Powered by ViewVC 1.1.2