&$value) {} /** * Implements hook_menu(). */ function menu_block_menu() { $items['admin/build/block/add-menu-block'] = array( 'title' => 'Add menu block', 'description' => 'Add a new menu block.', 'access arguments' => array('administer blocks'), 'page callback' => 'drupal_get_form', 'page arguments' => array('menu_block_add_block_form'), 'type' => MENU_LOCAL_TASK, 'file' => 'menu_block.admin.inc', ); $items['admin/build/block/delete-menu-block'] = array( 'title' => 'Delete menu block', 'access arguments' => array('administer blocks'), 'page callback' => 'drupal_get_form', 'page arguments' => array('menu_block_delete'), 'type' => MENU_CALLBACK, 'file' => 'menu_block.admin.inc', ); return $items; } /** * Implements hook_help(). */ function menu_block_help($path, $arg) { switch ($path) { case 'admin/build/block/configure': if ($arg[4] != 'menu_block') { break; } case 'admin/help#menu_block': case 'admin/build/block': case 'admin/build/block/add-menu-block': module_load_include('inc', 'menu_block', 'menu_block.pages'); return _menu_block_help($path, $arg); } } /** * Implements hook_theme(). */ function menu_block_theme() { return array( 'menu_block_wrapper' => array( 'template' => 'menu-block-wrapper', 'arguments' => array('content' => NULL, 'settings' => NULL), ), ); } /** * Process variables for menu-block-wrapper.tpl.php. * * @see menu-block-wrapper.tpl.php * @see theme_menu_block_wrapper() */ function template_preprocess_menu_block_wrapper(&$variables) { $variables['classes_array'][] = 'menu-name-' . $variables['settings']['menu_name']; $variables['classes_array'][] = 'parent-mlid-' . $variables['settings']['parent_mlid']; $variables['classes_array'][] = 'menu-level-' . $variables['settings']['level']; $variables['classes'] = check_plain(implode(' ', $variables['classes_array'])); $variables['template_files'][] = 'menu-block-wrapper-' . $variables['settings']['menu_name']; } /** * Alters the block admin form to add delete links next to menu blocks. */ function menu_block_form_block_admin_display_form_alter(&$form, $form_state) { module_load_include('inc', 'menu_block', 'menu_block.admin'); _menu_block_form_block_admin_display_form_alter($form, $form_state); } /** * Returns a list of menu names implemented by all modules. * * @return * array A list of menu names and titles. */ function menu_block_get_all_menus() { static $all_menus; if (!$all_menus) { // Include book support. if (module_exists('book')) { module_load_include('inc', 'menu_block', 'menu_block.book'); } // We're generalizing menu's menu_get_menus() by making it into a hook. // Retrieve all the menu names provided by hook_get_menus(). $all_menus = module_invoke_all('get_menus'); asort($all_menus); } return $all_menus; } /** * Implements hook_block(). */ function menu_block_block($op = 'list', $delta = NULL, $edit = NULL) { $function = '_menu_block_block_' . $op; if (function_exists($function)) { return $function($delta, $edit); } else { // "op"s besides "view" are seldom used, so we store them in a separate file. module_load_include('inc', 'menu_block', 'menu_block.admin'); if (function_exists($function)) { return $function($delta, $edit); } } } /** * Returns the 'view' $op info for hook_block(). * * @param $delta * string The name of the block to render. */ function _menu_block_block_view($delta) { $data = array(); // Get the block configuration options. list($menu_name, $parent_mlid) = split(':', variable_get("menu_block_{$delta}_parent", 'navigation:0')); $level = variable_get("menu_block_{$delta}_level", 1); $follow = variable_get("menu_block_{$delta}_follow", 0); $depth = variable_get("menu_block_{$delta}_depth", 0); $expanded = variable_get("menu_block_{$delta}_expanded", 0); $sort = variable_get("menu_block_{$delta}_sort", 0); // Get the default block name $menu_names = menu_block_get_all_menus(); $data['subject'] = $menu_names[$menu_name]; // Optionally load the specified parent menu item. $parent_item = $parent_mlid ? menu_link_load($parent_mlid) : NULL; if ($expanded || $parent_mlid) { // Get the full, un-pruned tree. $tree = menu_tree_all_data($menu_name); // And add the active trail data back to the full tree. menu_tree_add_active_path($tree); } else { // Get the tree pruned for just the active trail. //$tree = menu_tree_page_data($menu_name); $tree = menu_tree_all_data($menu_name); } // Prune the tree along the active trail to the specified level. if ($level > 1 || $parent_mlid) { $data['subject'] = menu_tree_prune_tree($tree, $level, $parent_item); } // Prune the tree to the active menu item. if ($follow && $new_title = menu_tree_prune_active_tree($tree, $follow)) { $data['subject'] = $new_title; } // If the menu-item-based tree is not "expanded", trim the tree to the active path. if ($parent_mlid && !$expanded) { //////////////////////////////////////////////////////////////////////////////////////////// // removed for dhtml_menu so have full tree in DOM..... if(!module_exists("menu_block")){ menu_tree_trim_active_path($tree); } // menu_tree_trim_active_path($tree); // removed //////////////////////////////////////////////////////////////////////////////////////////// } // Trim the branches that extend beyond the specified depth. if ($depth > 0) { menu_tree_depth_trim($tree, $depth); } // Sort the active path to the top of the tree. if ($sort) { menu_tree_sort_active_path($tree); } // Localize the tree. if (module_exists('i18nmenu')) { i18nmenu_localize_tree($tree); } // Render the tree. $data['content'] = menu_block_tree_output($tree); if ($data['content']) { $settings = array( 'menu_name' => $menu_name, 'parent_mlid' => $parent_mlid, 'level' => $level, 'follow' => $follow, 'depth' => $depth, 'expanded' => $expanded, 'sort' => $sort, ); $data['content'] = theme('menu_block_wrapper', $data['content'], $settings); } return $data; } /** * Add the active trail indicators into the tree. * * The data returned by menu_tree_page_data() has link['in_active_trail'] set to * TRUE for each menu item in the active trail. The data returned from * menu_tree_all_data() does not contain the active trail indicators. This is a * helper function that adds it back in. * * @param $tree * array The menu tree to prune. * @return * void */ function menu_tree_add_active_path(&$tree) { // Grab any menu item to find the menu_name for this tree. $menu_item = current($tree); $tree_with_trail = menu_tree_page_data($menu_item['link']['menu_name']); // To traverse the original tree down the active trail, we use a pointer. $subtree_pointer =& $tree; // Find each key in the active trail. while ($tree_with_trail) { foreach (array_keys($tree_with_trail) AS $key) { if ($tree_with_trail[$key]['link']['in_active_trail']) { // Set the active trail info in the original tree. $subtree_pointer[$key]['link']['in_active_trail'] = TRUE; // Continue in the subtree, if it exists. $tree_with_trail =& $tree_with_trail[$key]['below']; $subtree_pointer =& $subtree_pointer[$key]['below']; break; } else { unset($tree_with_trail[$key]); } } } } /** * Trim everything but the active trail in the tree. * * @param $tree * array The menu tree to trim. * @return * void */ function menu_tree_trim_active_path(&$tree) { // To traverse the original tree down the active trail, we use a pointer. $current_level =& $tree; // Traverse the tree along the active trail. do { $next_level = FALSE; foreach (array_keys($current_level) AS $key) { if ($current_level[$key]['link']['in_active_trail'] && $current_level[$key]['below']) { // Continue in the subtree, if it exists. $next_level = $key; } else { // Trim anything not along the active trail. $current_level[$key]['below'] = FALSE; } } if ($next_level) { $current_level =& $current_level[$next_level]['below']; } } while ($next_level); } /** * Sort the active trail to the top of the tree. * * @param $tree * array The menu tree to sort. * @return * void */ function menu_tree_sort_active_path(&$tree) { module_load_include('inc', 'menu_block', 'menu_block.sort'); _menu_tree_sort_active_path($tree); } /** * Prune a tree so that it begins at the specified level. * * This function will follow the active menu trail to the specified level. * * @param $tree * array The menu tree to prune. * @param $level * int The level of the original tree that will start the pruned tree. * @param $parent_item * array The menu item that should be used as the root of the tree. * @return * string Returns the title of the pruned tree. */ function menu_tree_prune_tree(&$tree, $level, $parent_item = FALSE) { // Get the default menu title. if (!empty($parent_item)) { // Use the title of the menu item. $menu_title = $parent_item['title']; } elseif ($level == 1) { $menu_names = menu_block_get_all_menus(); // Grab any menu item to find the menu_name for this tree. $menu_item = current($tree); $menu_title = $menu_names[$menu_item['link']['menu_name']]; } else { // We won't know the title until we've pruned the tree. $menu_title = ''; } if (!empty($parent_item)) { // Prune the tree along the path to the menu item. for ($i = 1; $i <= MENU_MAX_DEPTH && $parent_item["p$i"] != '0'; $i++) { $plid = $parent_item["p$i"]; $found_active_trail = FALSE; // Examine each element at this level for the ancestor. foreach (array_keys($tree) AS $key) { if ($tree[$key]['link']['mlid'] == $plid) { // Prune the tree to the children of this ancestor. $tree = $tree[$key]['below'] ? $tree[$key]['below'] : array(); $found_active_trail = TRUE; break; } } // If we don't find the ancestor, bail out. if (!$found_active_trail) { $tree = array(); break; } } } // Trim the upper levels down to the one desired. for ($i = 1; $i < $level; $i++) { $found_active_trail = FALSE; // Examine each element at this level for the active trail. foreach (array_keys($tree) AS $key) { if ($tree[$key]['link']['in_active_trail']) { // Get the title for the pruned tree. $menu_title = $tree[$key]['link']['title']; // Prune the tree to the children of the item in the active trail. $tree = $tree[$key]['below'] ? $tree[$key]['below'] : array(); $found_active_trail = TRUE; break; } } // If we don't find the active trail, the active item isn't in the tree we want. if (!$found_active_trail) { $tree = array(); break; } } return $menu_title; } /** * Prune a tree so that it begins at the active menu item. * * @param $tree * array The menu tree to prune. * @param $level * string The level which the tree will be pruned to: 'active' or 'child'. * @return * string Returns the title of the pruned tree. */ function menu_tree_prune_active_tree(&$tree, $level) { module_load_include('inc', 'menu_block', 'menu_block.follow'); return _menu_tree_prune_active_tree($tree, $level); } /** * Prune a tree so it does not extend beyond the specified depth limit. * * @param $tree * array The menu tree to prune. * @param $depth_limit * int The maximum depth of the returned tree; must be a positive integer. * @return * void */ function menu_tree_depth_trim(&$tree, $depth_limit) { // Prevent invalid input from returning a trimmed tree. if ($depth_limit < 1) { return; } // Examine each element at this level to find any possible children. foreach (array_keys($tree) AS $key) { if ($tree[$key]['below']) { if ($depth_limit > 1) { menu_tree_depth_trim($tree[$key]['below'], $depth_limit-1); } else { // Remove the children items. $tree[$key]['below'] = FALSE; } } if ($depth_limit == 1 && $tree[$key]['link']['has_children']) { // Turn off the menu styling that shows there were children. $tree[$key]['link']['has_children'] = FALSE; $tree[$key]['link']['leaf_has_children'] = TRUE; } } } /** * Returns a rendered menu tree. * * This is an optimized version of menu_tree_output() with additional classes * added to the output. * * @param $tree * array A data structure representing the tree as returned from menu_tree_data. * @return * string The rendered HTML of that data structure. */ function menu_block_tree_output(&$tree) { $output = ''; $items = array(); // Pull out just the menu items we are going to render so that we // get an accurate count for the first/last classes. foreach (array_keys($tree) as $key) { if (!$tree[$key]['link']['hidden']) { $items[$key] = array( 'link' => $tree[$key]['link'], // To prevent copying the entire child array, we render it first. 'below' => !empty($tree[$key]['below']) ? menu_block_tree_output($tree[$key]['below']) : '', ); } } $num_items = count($items); $i = 1; foreach (array_keys($items) as $key) { // Render the link. $link_class = array(); if (!empty($items[$key]['link']['localized_options']['attributes']['class'])) { $link_class[] = $items[$key]['link']['localized_options']['attributes']['class']; } if ($items[$key]['link']['in_active_trail']) { $link_class[] = 'active-trail'; } if (!empty($link_class)) { $items[$key]['link']['localized_options']['attributes']['class'] = implode(' ', $link_class); } $link = theme('menu_item_link', $items[$key]['link']); // Render the menu item. $extra_class = array(); if ($i == 1) { $extra_class[] = 'first'; } if ($i == $num_items) { $extra_class[] = 'last'; } //////////////////////////////////////////////////////////////////////////////////////////// // add li class for menu block..... if(module_exists("menu_block")){ $extra_class[] = 'dhtml-menu menu-mlid-' . $items[$key]['link']['mlid']; } else{ $extra_class[] = 'menu-mlid-' . $items[$key]['link']['mlid']; } //$extra_class[] = 'menu-mlid-' . $items[$key]['link']['mlid']; // removed... //////////////////////////////////////////////////////////////////////////////////////////// if (!empty($items[$key]['link']['leaf_has_children'])) { $extra_class[] = 'has-children'; } if ($items[$key]['link']['href'] == $_GET['q'] || ($items[$key]['link']['href'] == '' && drupal_is_front_page())) { $extra_class[] = 'active'; } //////////////////////////////////////////////////////////////////////////////////////////// // make sure non active nested lists are closed elseif(module_exists("menu_block")){ $extra_class[] = 'collapsed start-collapsed'; } // add an id to link for dhtml menu ..... if(module_exists("menu_block")){ $link=str_replace('