diff -rup -xCVS ../drupal6-chx/includes/menu.inc ./includes/menu.inc --- ../drupal6-chx/includes/menu.inc 2007-05-11 22:00:36.000000000 -0400 +++ ./includes/menu.inc 2007-05-11 22:16:58.000000000 -0400 @@ -294,7 +294,7 @@ function menu_get_item($path = NULL) { } $items[$path] = $item; } - return $items[$path]; + return drupal_clone($items[$path]); } /** @@ -600,13 +600,14 @@ function menu_tree_data($menu_name = 'na } $parents[] = '0'; - $args = array_unique($parents); + $args = $parents = array_unique($parents); $placeholders = implode(', ', array_fill(0, count($args), '%d')); - if (variable_get('menu_expanded', 0)) { + $expanded = variable_get('menu_expanded', array()); + if (in_array($menu_name, $expanded)) { do { - $result = db_query("SELECT mlid FROM {menu_links} ml WHERE expanded = 1 AND ml.menu_name = '%s' AND ml.plid IN (". $placeholders .') AND ml.mlid NOT IN ('. $placeholders .')', array_merge(array($menu_name), $args, $args)); - while ($items = db_fetch_object($result)) { - $args[] = $items->mlid; + $result = db_query("SELECT mlid FROM {menu_links} WHERE expanded != 0 AND menu_name = '%s' AND plid IN (". $placeholders .') AND mlid NOT IN ('. $placeholders .')', array_merge(array($menu_name), $args, $args)); + while ($item = db_fetch_array($result)) { + $args[] = $item['mlid']; } $placeholders = implode(', ', array_fill(0, count($args), '%d')); } while (db_num_rows($result)); @@ -618,10 +619,12 @@ function menu_tree_data($menu_name = 'na $args = array('navigation', '0'); $placeholders = '%d'; } + // LEFT JOIN since there is no match in {menu} for an external link. + // No need to order by p6 - there is a sort by weight later. list(, $tree[$menu_name]) = _menu_tree_data(db_query(" - SELECT *, ml.weight + 50000 AS weight FROM {menu_links} ml INNER JOIN {menu} m ON m.path = ml.router_path + SELECT *, ml.weight + 50000 AS weight FROM {menu_links} ml LEFT JOIN {menu} m ON m.path = ml.router_path WHERE ml.menu_name = '%s' AND ml.plid IN (". $placeholders .") - ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC", $args)); + ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC", $args), $parents); // TODO: cache_set() for the untranslated links // TODO: special case node links and access check via db_rewite_sql() @@ -641,6 +644,9 @@ function menu_tree_data($menu_name = 'na * * @param $result * The database result. + * @param $parents + * An array of the plid values that represent the path from the current page + * to the root of the menu tree. * @param $depth * The depth of the current menu tree. * @param $previous_element @@ -648,7 +654,7 @@ function menu_tree_data($menu_name = 'na * @return * See menu_tree_data for a description of the data structure. */ -function _menu_tree_data($result = NULL, $depth = 1, $previous_element = '') { +function _menu_tree_data($result = NULL, $parents = array(), $depth = 1, $previous_element = '') { $remnant = NULL; $tree = array(); while ($item = db_fetch_object($result)) { @@ -659,14 +665,16 @@ function _menu_tree_data($result = NULL, if (!$item->access) { continue; } + // We need to determine if we're on the path to root so we can later build + // the correct active trail and breadcrumb. + $item->path_to_root = in_array($item->mlid, $parents); // The weights are uniform 5 digits because of the 50000 offset in the - // query. We slap mlid at the end of the index to make very sure that - // we never create the same index twice. + // query. We add mlid at the end of the index to insure uniqeness. $index = $previous_element ? ($previous_element->weight .' '. $previous_element->title . $previous_element->mlid) : ''; // The current item is the first in a new submenu. if ($item->depth > $depth) { // _menu_tree returns an item and the menu tree structure. - list($item, $below) = _menu_tree_data($result, $item->depth, $item); + list($item, $below) = _menu_tree_data($result, $parents, $item->depth, $item); $tree[$index] = array( 'link' => $previous_element, 'below' => $below, @@ -737,7 +745,7 @@ function theme_menu_local_task($link, $a * Returns the help associated with the active menu item. */ function menu_get_active_help() { - $path = $_GET['q']; + $output = ''; $item = menu_get_item(); @@ -745,7 +753,8 @@ function menu_get_active_help() { // Don't return help text for areas the user cannot access. return; } - + $path = ($item->type == MENU_DEFAULT_LOCAL_TASK) ? $item->tab_parent : $item->path; + foreach (module_list() as $name) { if (module_hook($name, 'help')) { if ($temp = module_invoke($name, 'help', $path)) { @@ -921,7 +930,6 @@ function menu_set_active_trail($new_trai else { $href = $item->href; } - $tree = menu_tree_data(menu_get_active_menu_name()); $curr = array_shift($tree); @@ -931,7 +939,7 @@ function menu_set_active_trail($new_trai $curr = FALSE; } else { - if ($curr['below']) { + if ($curr['below'] && $curr['link']->path_to_root) { $trail[] = $curr['link']; $tree = $curr['below']; } @@ -1234,9 +1242,15 @@ function menu_link_save(&$item, $_menu = db_query("UPDATE {menu_links} SET has_children = 1 WHERE mlid = %d", $item['plid']); } - // Are there expanded items? - variable_set('menu_expanded', db_result(db_query_range('SELECT expanded FROM {menu_links} WHERE expanded = 1', 0, 1))); - + // Keep track of which menus have expanded items + if ($item['expanded']) { + $names = array(); + $result = db_query("SELECT menu_name FROM {menu_links} WHERE expanded != 0 GROUP BY menu_name"); + while ($n = db_fetch_array($result)) { + $names[] = $n['menu_name']; + } + variable_set('menu_expanded', $names); + } return TRUE; } diff -rup -xCVS ../drupal6-chx/modules/system/system.install ./modules/system/system.install --- ../drupal6-chx/modules/system/system.install 2007-05-11 22:00:36.000000000 -0400 +++ ./modules/system/system.install 2007-05-11 22:04:50.000000000 -0400 @@ -384,7 +384,7 @@ function system_install() { PRIMARY KEY (mlid), KEY parents (plid, p1, p2, p3, p4, p5), KEY menu_name_path (menu_name, href), - KEY menu_children_expanded (has_children, expanded) + KEY menu_expanded_children (expanded, has_children) ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); db_query("CREATE TABLE {node} ( @@ -882,7 +882,7 @@ function system_install() { )"); db_query("CREATE INDEX {menu_links}_parents_idx ON {menu_links} (plid, p1, p2, p3, p4, p5)"); db_query("CREATE INDEX {menu_links}_menu_name_idx ON {menu_links} (menu_name, href)"); - db_query("CREATE INDEX {menu_links}_children_expanded_idx ON {menu_links} (has_children, expanded)"); + db_query("CREATE INDEX {menu_links}_expanded_children_idx ON {menu_links} (expanded, has_children)"); db_query("CREATE TABLE {node} ( nid serial CHECK (nid >= 0),