--- menu.inc.474orig 2007-01-09 12:54:56.000000000 -0600 +++ menu.inc 2007-01-15 10:59:07.000000000 -0600 @@ -243,7 +243,8 @@ // _menu_build_local_tasks() may indirectly call this function, so prevent // infinite loops. $_menu['local tasks'] = array(); - $pid = menu_get_active_nontask_item(); + //$pid = menu_get_active_nontask_item(); + $pid = menu_get_active_nontask_item_original_path(); if (!_menu_build_local_tasks($pid)) { // If the build returned FALSE, the tasks need not be displayed. $_menu['local tasks'][$pid]['children'] = array(); @@ -309,7 +310,7 @@ * * Frequently, modules may want to make a page or node act as if it were * in the menu tree somewhere, even though it was not registered in a - * hook_menu() implementation. If the administrator has rearranged the menu, + * hook_menu() implementation. If the adminis!trator has rearranged the menu, * the newly set location should respect this in the breadcrumb trail and * expanded/collapsed status of menu items in the tree. This function * allows this behavior. @@ -439,6 +440,123 @@ else { $_GET['q'] = $path; } + + // based on bodomaas' patch in issue http://drupal.org/node/80820 #8 + // menu not expanding with URL-Alias + // only changed to use localepath instead of en + $orig_pathalias = drupal_lookup_path('alias', $path); + if ($orig_pathalias) { + static $valid_locales; + $valid_locales = locale_supported_languages(); + $valid_locales = $valid_locales['name']; + + $exploded_path = explode('/', $orig_pathalias); + $localeinpath = $exploded_path[0]; + if(!(($localeinpath!= '') && array_key_exists($localeinpath, $valid_locales))){ + $localeinpath = ''; + } + + if($localeinpath != ''){ + array_shift($exploded_path); + $pathalias_witoutlocale=implode("/", $exploded_path); + } + else + { + $pathalias_witoutlocale=$orig_pathalias; + } + + $new_path = drupal_get_normal_path($pathalias_witoutlocale); + if($new_path != $pathalias_witoutlocale) { + $path=$new_path; + } + else + { + $new_path = drupal_get_normal_path($localeinpath . '/' . $pathalias_witoutlocale); + if($new_path != $localeinpath . '/' . $pathalias_witoutlocale) { + $path=$new_path; + } + } + } + + while ($path && !isset($menu['path index'][$path])) { + $path = substr($path, 0, strrpos($path, '/')); + } + $stored_mid = isset($menu['path index'][$path]) ? $menu['path index'][$path] : 0; + //$stored_original_mid = isset($menu['path index'][$orig_path]) ? $menu['path index'][$orig_path] : 0; + // Search for default local tasks to activate instead of this item. + $continue = TRUE; + while ($continue) { + $continue = FALSE; + if (isset($menu['items'][$stored_mid]['children'])) { + foreach ($menu['items'][$stored_mid]['children'] as $cid) { + if ($menu['items'][$cid]['type'] & MENU_LINKS_TO_PARENT) { + $stored_mid = $cid; + $continue = TRUE; + } + } + } + } + + // Reset the cached $menu in menu_get_item(). + menu_get_item(NULL, NULL, TRUE); + } + + return $stored_mid; +} + +/** + * Sets the path of the active menu item. + * Th + */ +/*function menu_set_active_item_original_path($path = NULL) { + static $stored_mid; + + if (!isset($stored_mid) || isset($path)) { + $menu = menu_get_menu(); + if (!isset($path)) { + $path = $_GET['q']; + } + else { + $_GET['q'] = $path; + } + + while ($path && !isset($menu['path index'][$path])) { + $path = substr($path, 0, strrpos($path, '/')); + } + $stored_mid = isset($menu['path index'][$path]) ? $menu['path index'][$path] : 0; + + // Search for default local tasks to activate instead of this item. + $continue = TRUE; + while ($continue) { + $continue = FALSE; + if (isset($menu['items'][$stored_mid]['children'])) { + foreach ($menu['items'][$stored_mid]['children'] as $cid) { + if ($menu['items'][$cid]['type'] & MENU_LINKS_TO_PARENT) { + $stored_mid = $cid; + $continue = TRUE; + } + } + } + } + + // Reset the cached $menu in menu_get_item(). + menu_get_item(NULL, NULL, TRUE); + } + + return $stored_mid; +} */ + +function menu_set_active_item_original_path($path = NULL) { + static $stored_mid; + + if (!isset($stored_mid) || isset($path)) { + $menu = menu_get_menu(); + if (!isset($path)) { + $path = $_GET['q']; + } + else { + $_GET['q'] = $path; + } while ($path && !isset($menu['path index'][$path])) { $path = substr($path, 0, strrpos($path, '/')); @@ -466,6 +584,9 @@ return $stored_mid; } + + + /** * Returns the ID of the current menu item or, if the current item is a * local task, the menu item to which this task is attached. @@ -485,6 +606,22 @@ } } +function menu_get_active_nontask_item_original_path() { + $mid = menu_set_active_item_original_path(); + + // Find the first non-task item: + while ($mid) { + $item = menu_get_item($mid); + + if (!($item['type'] & MENU_IS_LOCAL_TASK)) { + return $mid; + } + + $mid = $item['pid']; + } +} + + /** * Returns the title of the active menu item. */ @@ -695,7 +832,55 @@ * @ingroup themeable */ function theme_menu_item_link($item, $link_item) { - return l($item['title'], $link_item['path'], isset($item['description']) ? array('title' => $item['description']) : array()); + $path = $link_item['path']; + $qpath = $_GET['q']; + $lpath = $link_item['path']; + + // it turns out that the menu expansion patch did not make the menu items + // active when appropriate either. this "fixes" this. + // I copy and pasted this from the original in from the expansion patch + // in menu_set_active_item(), because it nicely detects what the path + // should be. sort of. + $orig_pathalias = drupal_lookup_path('alias', $_GET['q']); + if ($orig_pathalias) { + static $valid_locales; + $valid_locales = locale_supported_languages(); + $valid_locales = $valid_locales['name']; + + $exploded_path = explode('/', $orig_pathalias); + $localeinpath = $exploded_path[0]; + if(!(($localeinpath!= '') && array_key_exists($localeinpath, $valid_locales))){ + $localeinpath = ''; + } + + if($localeinpath != ''){ + array_shift($exploded_path); + $pathalias_witoutlocale=implode("/", $exploded_path); + } + else + { + $pathalias_witoutlocale=$orig_pathalias; + } + $new_path = drupal_get_normal_path($pathalias_witoutlocale); + if($new_path != $pathalias_witoutlocale) { + $path=$new_path; + } + else + { + $new_path = drupal_get_normal_path($localeinpath . '/' . $pathalias_witoutlocale); + if($new_path != $localeinpath . '/' . $pathalias_witoutlocale) { + $path=$new_path; + } + } + } + + //echo "

?q was $qpath, recomputed path is $path, and the link_item's path is $lpath.

"; + if ($lpath == $path) { + $_GET['q'] = $lpath; + } + $result = l($item['title'], $link_item['path'], isset($item['description']) ? array('title' => $item['description']) : array()); + $_GET['q'] = $qpath; + return $result; } /** @@ -723,7 +908,7 @@ */ function theme_menu_local_tasks() { $output = ''; - + if ($primary = menu_primary_local_tasks()) { $output .= "\n"; } @@ -738,16 +923,17 @@ * Returns the rendered HTML of the primary local tasks. */ function menu_primary_local_tasks() { + global $user; $local_tasks = menu_get_local_tasks(); - $pid = menu_get_active_nontask_item(); + $pid = menu_get_active_nontask_item_original_path(); $output = ''; - - if (count($local_tasks[$pid]['children'])) { - foreach ($local_tasks[$pid]['children'] as $mid) { - $output .= theme('menu_local_task', $mid, menu_in_active_trail($mid), TRUE); - } + if ($user->uid > 0) { + if (count($local_tasks[$pid]['children'])) { + foreach ($local_tasks[$pid]['children'] as $mid) { + $output .= theme('menu_local_task', $mid, menu_in_active_trail($mid), TRUE); + } + } } - return $output; } @@ -1359,4 +1545,4 @@ } } return FALSE; -} \ No newline at end of file +}