123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- // $Id$
- /**
- * @file
- * Creates a simplemenu.
- */
- /**
- * Implementation of hook_menu().
- */
- function simplemenu_menu($may_cache) {
- $items = array();
- if ($may_cache) {
- $items[] = array(
- 'path' => 'simplemenu/menu',
- 'access' => user_access('view simplemenu'),
- 'callback' => 'simplemenu_get_menu',
- 'type' => MENU_CALLBACK
- );
-
- $items[] = array(
- 'path' => 'admin/settings/simplemenu',
- 'title' => t('SimpleMenu'),
- 'description' => t('Select the menu to display.'),
- 'callback' => 'drupal_get_form',
- 'callback arguments' => array('simplemenu_admin_settings'),
- 'access' => user_access('administer simplemenu')
- );
- }
-
- // We put this in !$may_cache so it's only added once per request
- elseif (user_access('view simplemenu')) {
- $path = drupal_get_path('module', 'simplemenu');
- drupal_add_css($path .'/simplemenu.css');
-
- // pass in base path to the JS file
- // url() handles appending ?q= but in this case, we need to pass in the variable so the menus work when mod_rewrite is off
- drupal_add_js(array('simplemenu' => array('basePath' => base_path() . (variable_get('clean_url', 0) ? '' : '?q='))), 'setting');
- drupal_add_js($path .'/simplemenu.js');
- }
- return $items;
- }
- /**
- * Implementation of hook_perm().
- */
- function simplemenu_perm() {
- return array('view simplemenu', 'administer simplemenu');
- }
- /**
- * SimpleMenu settings page.
- */
- function simplemenu_admin_settings() {
- $form['default_menu']['simplemenu_menu'] = array(
- '#type' => 'select',
- '#title' => t('Menu'),
- '#options' => menu_get_root_menus(),
- '#default_value' => variable_get('simplemenu_menu', 1),
- '#description' => t('Select the menu to display.')
- );
-
- $form['default_menu']['simplemenu_devel'] = array(
- '#type' => 'checkbox',
- '#title' => t('Add devel module links'),
- '#default_value' => variable_get('simplemenu_devel', 0),
- '#description' => t('Add devel module links for those users that can access the devel module.')
- );
-
- return system_settings_form($form);
- }
- /**
- * Return a list of devel module links if the module is enabled
- * and the user has access to this module.
- */
- function simplemenu_get_devel() {
- $output = '';
-
- if (variable_get('simplemenu_devel', 0) && module_exists('devel')) {
- if (user_access('access devel information')) {
- $links[] = l('module settings', 'admin/settings/devel');
- $links[] = l('empty cache', 'devel/cache/clear');
- $links[] = l('phpinfo()', 'devel/phpinfo');
- $links[] = l('reinstall modules', 'devel/reinstall');
- $links[] = l('reset menus', 'devel/menu/reset');
- $links[] = l('variable viewer', 'devel/variable');
- $links[] = l('session viewer', 'devel/session');
- if (function_exists('devel_node_access_perm') && user_access(DNA_ACCESS_VIEW)) {
- // True only if devel_node_access enabled.
- $links[] = l('node_access summary', 'devel/node_access/summary');
- }
-
- $output = '<li class="expanded"><a href="'. url('admin/settings/devel') .'">'. t('devel module') .'</a><ul>';
- $output .= '<li class="leaf">'. implode($links, '</li><li class="leaf">') .'</li>';
- $output .= '</ul></li>';
- }
- }
-
- return $output;
- }
- /**
- * Custom implementation of menu_tree().
- * We want to retrieve the entire menu structure for a given menu,
- * regardless of whether or not the menu item is expanded or not.
- */
- function simplemenu_menu_tree($pid = 1) {
- $menu = menu_get_menu();
- $output = '';
- if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) {
- foreach ($menu['visible'][$pid]['children'] as $mid) {
- $type = isset($menu['visible'][$mid]['type']) ? $menu['visible'][$mid]['type'] : NULL;
- $children = isset($menu['visible'][$mid]['children']) ? $menu['visible'][$mid]['children'] : NULL;
- $output .= theme('menu_item', $mid, simplemenu_theme_menu_tree($mid), count($children) == 0);
- }
- }
- return $output;
- }
- /**
- * Custom implementation of theme_menu_tree() to call our custom menu above.
- */
- function simplemenu_theme_menu_tree($pid = 1) {
- if ($tree = simplemenu_menu_tree($pid)) {
- return '<ul>'. $tree .'</ul>';
- }
- }
- /**
- * AJAX menu callback to return an HTML list of links for a given menu.
- */
- function simplemenu_get_menu() {
- $menu = simplemenu_menu_tree(variable_get('simplemenu_menu', 1));
-
- if (!$menu) {
- $menu = '<li><a href="'. url('admin/settings/simplemenu') .'">'. t('No menu items found. Try a different menu as the default.') .'</a></li>';
- }
-
- print simplemenu_get_devel();
- print $menu;
- exit;
- }
|