Index: modules/system/system.install =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.install,v retrieving revision 1.114 diff -u -p -r1.114 system.install --- modules/system/system.install 20 May 2007 16:44:35 -0000 1.114 +++ modules/system/system.install 22 May 2007 03:58:16 -0000 @@ -265,6 +265,17 @@ function system_install() { INDEX expire (expire) ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + db_query("CREATE TABLE {cache_menu} ( + cid varchar(255) BINARY NOT NULL default '', + data longblob, + expire int NOT NULL default '0', + created int NOT NULL default '0', + headers text, + serialized int(1) NOT NULL default '0', + PRIMARY KEY (cid), + INDEX expire (expire) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + db_query("CREATE TABLE {comments} ( cid int NOT NULL auto_increment, pid int NOT NULL default '0', @@ -398,7 +409,9 @@ function system_install() { link_title varchar(255) NOT NULL default '', options text, PRIMARY KEY (mlid), - KEY parents (plid, p1, p2, p3, p4, p5), + KEY router_path (router_path), + KEY plid (plid), + KEY parents (p1, p2, p3, p4, p5), KEY menu_name_path (menu_name, href), KEY menu_expanded_children (expanded, has_children) ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); @@ -780,10 +793,19 @@ function system_install() { serialized smallint NOT NULL default '0', PRIMARY KEY (cid) )"); - db_query("CREATE INDEX {cache}_expire_idx ON {cache} (expire)"); + db_query("CREATE TABLE {cache_menu} ( + cid varchar(255) NOT NULL default '', + data bytea, + expire int NOT NULL default '0', + created int NOT NULL default '0', + headers text, + serialized smallint NOT NULL default '0', + PRIMARY KEY (cid) + )"); db_query("CREATE INDEX {cache}_expire_idx ON {cache} (expire)"); db_query("CREATE INDEX {cache_filter}_expire_idx ON {cache_filter} (expire)"); db_query("CREATE INDEX {cache_page}_expire_idx ON {cache_page} (expire)"); db_query("CREATE INDEX {cache_form}_expire_idx ON {cache_form} (expire)"); + db_query("CREATE INDEX {cache_menu}_expire_idx ON {cache_form} (expire)"); db_query("CREATE TABLE {comments} ( cid serial, @@ -919,7 +941,10 @@ function system_install() { options text, PRIMARY KEY (mlid) )"); - db_query("CREATE INDEX {menu_links}_parents_idx ON {menu_links} (plid, p1, p2, p3, p4, p5)"); + + db_query("CREATE INDEX {menu_links}_router_path_idx ON {menu_links} (router_path)"); + db_query("CREATE INDEX {menu_links}_plid_idx ON {menu_links} (plid)"); + db_query("CREATE INDEX {menu_links}_parents_idx ON {menu_links} (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}_expanded_children_idx ON {menu_links} (expanded, has_children)"); @@ -3923,14 +3948,15 @@ function system_update_6012() { db_add_column($ret, 'cache', 'serialized', 'smallint', array('default' => "'0'", 'not null' => TRUE)); db_add_column($ret, 'cache_filter', 'serialized', 'smallint', array('default' => "'0'", 'not null' => TRUE)); db_add_column($ret, 'cache_page', 'serialized', 'smallint', array('default' => "'0'", 'not null' => TRUE)); + db_add_column($ret, 'cache_menu', 'serialized', 'smallint', array('default' => "'0'", 'not null' => TRUE)); break; case 'mysql': case 'mysqli': $ret[] = update_sql("ALTER TABLE {cache} ADD serialized int(1) NOT NULL default '0'"); $ret[] = update_sql("ALTER TABLE {cache_filter} ADD serialized int(1) NOT NULL default '0'"); $ret[] = update_sql("ALTER TABLE {cache_page} ADD serialized int(1) NOT NULL default '0'"); + $ret[] = update_sql("ALTER TABLE {cache_menu} ADD serialized int(1) NOT NULL default '0'"); break; - } return $ret; Index: modules/system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.479 diff -u -p -r1.479 system.module --- modules/system/system.module 21 May 2007 10:56:05 -0000 1.479 +++ modules/system/system.module 22 May 2007 03:58:17 -0000 @@ -401,16 +401,16 @@ function system_main_admin_page($arg = N } $result = db_query("SELECT * FROM {menu_links} ml INNER JOIN {menu_router} m ON ml.router_path = m.path WHERE ml.href like 'admin/%' AND ml.href != 'admin/help' AND ml.depth = 2 AND ml.menu_name = 'navigation' - ORDER BY p1 ASC, p2 ASC, p3 ASC"); - while ($item = db_fetch_object($result)) { + ORDER BY p1 ASC, m.weight, m.title"); + while ($item = db_fetch_array($result)) { _menu_link_translate($item); - if (!$item->access) { + if (!$item['access']) { continue; } - $block = (array)$item; + $block = $item; $block['content'] = ''; - if ($item->block_callback && function_exists($item->block_callback)) { - $function = $item->block_callback; + if ($item['block_callback'] && function_exists($item['block_callback'])) { + $function = $item['block_callback']; $block['content'] .= $function(); } $block['content'] .= theme('admin_block_content', system_admin_menu_block($item)); @@ -424,14 +424,14 @@ function system_main_admin_page($arg = N */ function system_admin_menu_block($item) { $content = array(); - if (!isset($item->mlid)) { - $item->mlid = db_result(db_query("SELECT mlid FROM {menu_links} ml WHERE ml.router_path = '%s' AND menu_name = 'navigation'", $item->path)); + if (!isset($item['mlid'])) { + $item['mlid'] = db_result(db_query("SELECT mlid FROM {menu_links} ml WHERE ml.router_path = '%s' AND menu_name = 'navigation'", $item['path'])); } $result = db_query("SELECT * FROM {menu_links} ml INNER JOIN {menu_router} m ON ml.router_path = m.path - WHERE ml.plid = '%s' AND ml.menu_name = 'navigation' ORDER BY m.weight, m.title", $item->mlid); - while ($item = db_fetch_object($result)) { + WHERE ml.plid = %d AND ml.menu_name = 'navigation' ORDER BY m.weight, m.title", $item['mlid']); + while ($item = db_fetch_array($result)) { _menu_link_translate($item); - if (!$item->access) { + if (!$item['access']) { continue; } $content[] = (array)$item; Index: includes/menu.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/menu.inc,v retrieving revision 1.166 diff -u -p -r1.166 menu.inc --- includes/menu.inc 16 May 2007 13:45:16 -0000 1.166 +++ includes/menu.inc 22 May 2007 03:58:17 -0000 @@ -149,11 +149,6 @@ define('MENU_SITE_OFFLINE', 4); * @} End of "Menu status codes". */ - -/** - * @} End of "Menu operations." - */ - /** * @Name Menu tree parameters * @{ @@ -284,21 +279,21 @@ function menu_get_item($path = NULL) { $parts = array_slice($original_map, 0, MENU_MAX_PARTS); list($ancestors, $placeholders) = menu_get_ancestors($parts); - if ($item = db_fetch_object(db_query_range('SELECT * FROM {menu_router} WHERE path IN ('. implode (',', $placeholders) .') ORDER BY fit DESC', $ancestors, 0, 1))) { + if ($item = db_fetch_array(db_query_range('SELECT * FROM {menu_router} WHERE path IN ('. implode (',', $placeholders) .') ORDER BY fit DESC', $ancestors, 0, 1))) { $map = _menu_translate($item, $original_map); if ($map === FALSE) { $items[$path] = FALSE; return FALSE; } - if ($item->access) { - $item->map = $map; - $item->page_arguments = array_merge(menu_unserialize($item->page_arguments, $map), array_slice($parts, $item->number_parts)); + if ($item['access']) { + $item['map'] = $map; + $item['page_arguments'] = array_merge(menu_unserialize($item['page_arguments'], $map), array_slice($parts, $item['number_parts'])); } } $items[$path] = $item; } - return drupal_clone($items[$path]); + return $items[$path]; } /** @@ -306,13 +301,13 @@ function menu_get_item($path = NULL) { */ function menu_execute_active_handler() { if ($item = menu_get_item()) { - return $item->access ? call_user_func_array($item->page_callback, $item->page_arguments) : MENU_ACCESS_DENIED; + return $item['access'] ? call_user_func_array($item['page_callback'], $item['page_arguments']) : MENU_ACCESS_DENIED; } return MENU_NOT_FOUND; } /** - * Loads objects into the map as defined in the $item->load_functions. + * Loads objects into the map as defined in the $item['load_functions']. * * @param $item * A menu item object @@ -322,8 +317,8 @@ function menu_execute_active_handler() { * Returns TRUE for success, FALSE if an object cannot be loaded */ function _menu_load_objects($item, &$map) { - if ($item->load_functions) { - $load_functions = unserialize($item->load_functions); + if ($item['load_functions']) { + $load_functions = unserialize($item['load_functions']); $path_map = $map; foreach ($load_functions as $index => $function) { if ($function) { @@ -331,7 +326,7 @@ function _menu_load_objects($item, &$map $return = $function(isset($path_map[$index]) ? $path_map[$index] : ''); // If callback returned an error or there is no callback, trigger 404. if ($return === FALSE) { - $item->access = FALSE; + $item['access'] = FALSE; $map = FALSE; return FALSE; } @@ -350,25 +345,25 @@ function _menu_load_objects($item, &$map * @param $map * An array of path arguments (ex: array('node', '5')) * @return - * $item->access becomes TRUE if the item is accessible, FALSE otherwise. + * $item['access'] becomes TRUE if the item is accessible, FALSE otherwise. */ function _menu_check_access(&$item, $map) { // Determine access callback, which will decide whether or not the current user has // access to this path. - $callback = $item->access_callback; + $callback = $item['access_callback']; // Check for a TRUE or FALSE value. if (is_numeric($callback)) { - $item->access = $callback; + $item['access'] = $callback; } else { - $arguments = menu_unserialize($item->access_arguments, $map); + $arguments = menu_unserialize($item['access_arguments'], $map); // As call_user_func_array is quite slow and user_access is a very common // callback, it is worth making a special case for it. if ($callback == 'user_access') { - $item->access = (count($arguments) == 1) ? user_access($arguments[0]) : user_access($arguments[0], $arguments[1]); + $item['access'] = (count($arguments) == 1) ? user_access($arguments[0]) : user_access($arguments[0], $arguments[1]); } else { - $item->access = call_user_func_array($callback, $arguments); + $item['access'] = call_user_func_array($callback, $arguments); } } } @@ -377,29 +372,29 @@ function _menu_item_localize(&$item) { // Translate the title to allow storage of English title strings // in the database, yet display of them in the language required // by the current user. - $callback = $item->title_callback; + $callback = $item['title_callback']; // t() is a special case. Since it is used very close to all the time, // we handle it directly instead of using indirect, slower methods. if ($callback == 't') { - if (empty($item->title_arguments)) { - $item->title = t($item->title); + if (empty($item['title_arguments'])) { + $item['title'] = t($item['title']); } else { - $item->title = t($item->title, unserialize($item->title_arguments)); + $item['title'] = t($item['title'], unserialize($item['title_arguments'])); } } else { - if (empty($item->title_arguments)) { - $item->title = $callback($item->title); + if (empty($item['title_arguments'])) { + $item['title'] = $callback($item['title']); } else { - $item->title = call_user_func_array($callback, unserialize($item->title_arguments)); + $item['title'] = call_user_func_array($callback, unserialize($item['title_arguments'])); } } // Translate description, see the motivation above. - if (!empty($item->description)) { - $item->description = t($item->description); + if (!empty($item['description'])) { + $item['description'] = t($item['description']); } } @@ -423,12 +418,12 @@ function _menu_item_localize(&$item) { * @param $map * An array of path arguments (ex: array('node', '5')) * @param $to_arg - * Execute $item->to_arg_functions or not. Use only if you want to render a + * Execute $item['to_arg_functions'] or not. Use only if you want to render a * path from the menu table, for example tabs. * @return * Returns the map with objects loaded as defined in the - * $item->load_functions. $item->access becomes TRUE if the item is - * accessible, FALSE otherwise. $item->href is set according to the map. + * $item['load_functions. $item['access'] becomes TRUE if the item is + * accessible, FALSE otherwise. $item['href'] is set according to the map. * If an error occurs during calling the load_functions (like trying to load * a non existing node) then this function return FALSE. */ @@ -436,21 +431,21 @@ function _menu_translate(&$item, $map, $ $path_map = $map; if (!_menu_load_objects($item, $map)) { // An error occurred loading an object. - $item->access = FALSE; + $item['access'] = FALSE; return FALSE; } if ($to_arg) { - _menu_link_map_translate($path_map, $item->to_arg_functions); + _menu_link_map_translate($path_map, $item['to_arg_functions']); } // Generate the link path for the page request or local tasks. - $link_map = explode('/', $item->path); - for ($i = 0; $i < $item->number_parts; $i++) { + $link_map = explode('/', $item['path']); + for ($i = 0; $i < $item['number_parts']; $i++) { if ($link_map[$i] == '%') { $link_map[$i] = $path_map[$i]; } } - $item->href = implode('/', $link_map); + $item['href'] = implode('/', $link_map); _menu_check_access($item, $map); _menu_item_localize($item); @@ -492,41 +487,41 @@ function _menu_link_map_translate(&$map, * A menu item object * @return * Returns the map of path arguments with objects loaded as defined in the - * $item->load_functions. - * $item->access becomes TRUE if the item is accessible, FALSE otherwise. - * $item->href is altered if there is a to_arg function. + * $item['load_functions']. + * $item['access'] becomes TRUE if the item is accessible, FALSE otherwise. + * $item['href'] is altered if there is a to_arg function. */ function _menu_link_translate(&$item) { - if ($item->external) { - $item->access = 1; + if ($item['external']) { + $item['access'] = 1; $map = array(); } else { - $map = explode('/', $item->href); - _menu_link_map_translate($map, $item->to_arg_functions); - $item->href = implode('/', $map); + $map = explode('/', $item['href']); + _menu_link_map_translate($map, $item['to_arg_functions']); + $item['href'] = implode('/', $map); // Note- skip callbacks without real values for their arguments - if (strpos($item->href, '%') !== FALSE) { - $item->access = FALSE; + if (strpos($item['href'], '%') !== FALSE) { + $item['access'] = FALSE; return FALSE; } - if (!_menu_load_objects($item, $map)) { - // An error occured loading an object - $item->access = FALSE; - return FALSE; - } - // TODO: menu_tree may set this ahead of time for links to nodes - if (!isset($item->access)) { + // TODO: menu_tree_data may set this ahead of time for links to nodes + if (!isset($item['access'])) { + if (!_menu_load_objects($item, $map)) { + // An error occured loading an object + $item['access'] = FALSE; + return FALSE; + } _menu_check_access($item, $map); } // If the link title matches that of a router item, localize it. - if (isset($item->title) && ($item->title == $item->link_title)) { + if (isset($item['title']) && ($item['title'] == $item['link_title'])) { _menu_item_localize($item); - $item->link_title = $item->title; + $item['link_title'] = $item['title']; } } - $item->options = unserialize($item->options); + $item['options'] = unserialize($item['options']); return $map; } @@ -546,7 +541,7 @@ function menu_tree($menu_name = 'navigat static $menu_output = array(); if (!isset($menu_output[$menu_name])) { - $tree = menu_tree_data($menu_name); + $tree = menu_tree_page_data($menu_name); $menu_output[$menu_name] = menu_tree_output($tree); } return $menu_output[$menu_name]; @@ -564,13 +559,13 @@ function menu_tree_output($tree) { $output = ''; foreach ($tree as $data) { - if (!$data['link']->hidden) { + if (!$data['link']['hidden']) { $link = theme('menu_item_link', $data['link']); if ($data['below']) { - $output .= theme('menu_item', $link, $data['link']->has_children, menu_tree_output($data['below'])); + $output .= theme('menu_item', $link, $data['link']['has_children'], menu_tree_output($data['below'])); } else { - $output .= theme('menu_item', $link, $data['link']->has_children); + $output .= theme('menu_item', $link, $data['link']['has_children']); } } } @@ -578,6 +573,65 @@ function menu_tree_output($tree) { } /** + * Get the data structure representing a named menu tree. Since this can be + * the full tree including hidden items, the data returned may be used for + * generating an an admin interface or a select. + * + * @param $menu_name + * The named menu links to return + * @param $item + * A fully loaded menu link, or NULL. If a link is supplied, only the + * path to root will be included in the returned tree- as if this link + * represented the current page in a visible menu. + * @param $show_hidden + * Show disabled links (includes suggested menu items). + * @return + * An array of menu links, in the order they should be rendered. + */ +function menu_tree_all_data($menu_name = 'navigation', $item = NULL, $show_hidden = FALSE) { + static $tree = array(); + + $mlid = isset($item['mlid']) ? $item['mlid'] : 0; + $cid = 'links:'. $menu_name .':all:'. $mlid .':'. (int)$show_hidden; + + if (!isset($tree[$cid])) { + $cache = cache_get($cid, 'cache_menu'); + if ($cache && isset($cache->data)) { + $tree[$cid] = $cache->data; + } + else { + if ($mlid) { + $parents = array(0, $item['p1'], $item['p2'], $item['p3'], $item['p4'], $item['p5']); + $args = array_unique($parents); + $placeholders = implode(', ', array_fill(0, count($args), '%d')); + $where = ' AND ml.plid IN ('. $placeholders .')'; + } + else { + $where = ''; + $args = array(); + $parents = array(); + } + if (!$show_hidden) { + $where .= ' AND ml.hidden = 0'; + } + else { + $where .= ' AND ml.hidden > 0'; + } + array_unshift($args, $menu_name); + list(, $tree[$cid]) = _menu_tree_data(db_query(" + SELECT *, ml.weight + 50000 AS weight FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path + WHERE ml.menu_name = '%s'". $where ." + ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC", $args), $parents); + cache_set($cid, $tree[$cid], 'cache_menu'); + } + // TODO: special case node links and access check via db_rewite_sql() + _menu_tree_check_access($tree[$cid]); + } + + return $tree[$cid]; +} + +/** * Get the data structure representing a named menu tree, based on the current * page. The tree order is maintained by storing each parent in an invidual * field, see http://drupal.org/node/141866 for more. @@ -591,54 +645,73 @@ function menu_tree_output($tree) { * submenu below the link if there is one and it is a similar list that was * described so far. */ -function menu_tree_data($menu_name = 'navigation') { +function menu_tree_page_data($menu_name = 'navigation') { static $tree = array(); if ($item = menu_get_item()) { - if (!isset($tree[$menu_name])) { - if ($item->access) { - $parents = db_fetch_array(db_query("SELECT p1, p2, p3, p4, p5 FROM {menu_links} WHERE menu_name = '%s' AND href = '%s'", $menu_name, $item->href)); - // We may be on a local task that's not in the links - // TODO how do we handle the case like a local task on a specific node in the menu? - if (empty($parents)) { - $parents = db_fetch_array(db_query("SELECT p1, p2, p3, p4, p5 FROM {menu_links} WHERE menu_name = '%s' AND href = '%s'", $menu_name, $item->tab_root)); - } - $parents[] = '0'; + $cid = 'links:'. $menu_name .':page:'. $item['href'] .':'. (int)$item['access']; - $args = $parents = array_unique($parents); - $placeholders = implode(', ', array_fill(0, count($args), '%d')); - $expanded = variable_get('menu_expanded', array()); - if (in_array($menu_name, $expanded)) { - do { - $result = db_query("SELECT mlid FROM {menu_links} WHERE expanded != 0 AND AND has_children != 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)); - } - array_unshift($args, $menu_name); + if (!isset($tree[$cid])) { + $cache = cache_get($cid, 'cache_menu'); + if ($cache && isset($cache->data)) { + $tree[$cid] = $cache->data; } - // Show the root menu for access denied. else { - $args = array('navigation', '0'); - $placeholders = '%d'; - } - // LEFT JOIN since there is no match in {menu_router} 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 LEFT JOIN {menu_router} 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", $args), $parents); - - // TODO: cache_set() for the untranslated links + if ($item['access']) { + $parents = db_fetch_array(db_query("SELECT p1, p2, p3, p4, p5 FROM {menu_links} WHERE menu_name = '%s' AND href = '%s'", $menu_name, $item['href'])); + // We may be on a local task that's not in the links + // TODO how do we handle the case like a local task on a specific node in the menu? + if (empty($parents)) { + $parents = db_fetch_array(db_query("SELECT p1, p2, p3, p4, p5 FROM {menu_links} WHERE menu_name = '%s' AND href = '%s'", $menu_name, $item['tab_root'])); + } + $parents[] = '0'; + + $args = $parents = array_unique($parents); + $placeholders = implode(', ', array_fill(0, count($args), '%d')); + $expanded = variable_get('menu_expanded', array()); + if (in_array($menu_name, $expanded)) { + do { + $result = db_query("SELECT mlid FROM {menu_links} WHERE expanded != 0 AND has_children != 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)); + } + array_unshift($args, $menu_name); + } + // Show the root menu for access denied. + else { + $args = array('navigation', '0'); + $placeholders = '%d'; + } + // LEFT JOIN since there is no match in {menu_router} for an external link. + // No need to order by p6 - there is a sort by weight later. + list(, $tree[$cid]) = _menu_tree_data(db_query(" + SELECT *, ml.weight + 50000 AS weight FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path + WHERE ml.menu_name = '%s' AND ml.plid IN (". $placeholders .") AND ml.hidden = 0 + ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC", $args), $parents); + cache_set($cid, $tree[$cid], 'cache_menu'); + } // TODO: special case node links and access check via db_rewite_sql() - // TODO: access check / _menu_link_translate on each here + _menu_tree_check_access($tree[$cid]); } - return $tree[$menu_name]; + return $tree[$cid]; } } +function _menu_tree_check_access(&$tree) { + foreach ($tree as $key => $v) { + $item = &$tree[$key]['link']; + _menu_link_translate($item); + if (!$item['access']) { + unset($tree[$key]); + } + elseif ($tree[$key]['below']) { + _menu_tree_check_access($tree[$key]['below']); + } + } +} /** * Build the data representing a menu tree. @@ -662,30 +735,23 @@ function menu_tree_data($menu_name = 'na function _menu_tree_data($result = NULL, $parents = array(), $depth = 1, $previous_element = '') { $remnant = NULL; $tree = array(); - while ($item = db_fetch_object($result)) { - // Access check and handle dynamic path translation. - // TODO - move this to the parent function, so the untranslated link data - // can be cached. - _menu_link_translate($item); - if (!$item->access) { - continue; - } + while ($item = db_fetch_array($result)) { // 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); + $item['path_to_root'] = in_array($item['mlid'], $parents); // The weights are uniform 5 digits because of the 50000 offset in the // query. We add mlid at the end of the index to insure uniqueness. - $index = $previous_element ? ($previous_element->weight .' '. $previous_element->title . $previous_element->mlid) : ''; + $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) { + if ($item['depth'] > $depth) { // _menu_tree returns an item and the menu tree structure. - list($item, $below) = _menu_tree_data($result, $parents, $item->depth, $item); + list($item, $below) = _menu_tree_data($result, $parents, $item['depth'], $item); $tree[$index] = array( 'link' => $previous_element, 'below' => $below, ); // We need to fall back one level. - if ($item->depth < $depth) { + if (!isset($item) || $item['depth'] < $depth) { ksort($tree); return array($item, $tree); } @@ -693,7 +759,7 @@ function _menu_tree_data($result = NULL, $previous_element = $item; } // We are in the same menu. We render the previous element, $previous_element. - elseif ($item->depth == $depth) { + elseif ($item['depth'] == $depth) { if ($previous_element) { // Only the first time $tree[$index] = array( 'link' => $previous_element, @@ -711,7 +777,7 @@ function _menu_tree_data($result = NULL, } if ($previous_element) { // We have one more link dangling. - $tree[$previous_element->weight .' '. $previous_element->title .' '. $previous_element->mlid] = array( + $tree[$previous_element['weight'] .' '. $previous_element['title'] .' '. $previous_element['mlid']] = array( 'link' => $previous_element, 'below' => '', ); @@ -724,7 +790,7 @@ function _menu_tree_data($result = NULL, * Generate the HTML output for a single menu link. */ function theme_menu_item_link($link) { - return l($link->link_title, $link->href, $link->options); + return l($link['link_title'], $link['href'], $link['options']); } /** @@ -753,11 +819,11 @@ function menu_get_active_help() { $output = ''; $item = menu_get_item(); - if (!$item || !$item->access) { + if (!$item || !$item['access']) { // Don't return help text for areas the user cannot access. return; } - $path = ($item->type == MENU_DEFAULT_LOCAL_TASK) ? $item->tab_parent : $item->path; + $path = ($item['type'] == MENU_DEFAULT_LOCAL_TASK) ? $item['tab_parent'] : $item['path']; foreach (module_list() as $name) { if (module_hook($name, 'help')) { @@ -781,7 +847,6 @@ function menu_get_active_help() { */ function menu_get_names($reset = FALSE) { static $names; - // TODO - use cache system to save this if ($reset || empty($names)) { $names = array(); @@ -794,13 +859,27 @@ function menu_get_names($reset = FALSE) } function menu_primary_links() { - $tree = menu_tree_data('primary links'); - return array(); + $tree = menu_tree_page_data('primary-links'); + $links = array(); + foreach ($tree as $item) { + $l = $item['link']['options']; + $l['href'] = $item['link']['href']; + $l['title'] = $item['link']['link_title']; + $links[] = $l; + } + return $links; } function menu_secondary_links() { - $tree = menu_tree_data('secondary links'); - return array(); + $tree = menu_tree_page_data('secondary-links'); + $links = array(); + foreach ($tree as $item) { + $l = $item['link']['options']; + $l['href'] = $item['link']['href']; + $l['title'] = $item['link']['link_title']; + $links[] = $l; + } + return $links; } /** @@ -816,33 +895,33 @@ function menu_local_tasks($level = 0) { if (empty($tabs)) { $router_item = menu_get_item(); - if (!$router_item || !$router_item->access) { + if (!$router_item || !$router_item['access']) { return array(); } // Get all tabs - $result = db_query("SELECT * FROM {menu_router} WHERE tab_root = '%s' AND tab_parent != '' ORDER BY weight, title", $router_item->tab_root); + $result = db_query("SELECT * FROM {menu_router} WHERE tab_root = '%s' AND tab_parent != '' ORDER BY weight, title", $router_item['tab_root']); $map = arg(); $children = array(); $tab_parent = array(); - while ($item = db_fetch_object($result)) { - $children[$item->tab_parent][$item->path] = $item; - $tab_parent[$item->path] = $item->tab_parent; + while ($item = db_fetch_array($result)) { + $children[$item['tab_parent']][$item['path']] = $item; + $tab_parent[$item['path']] = $item['tab_parent']; } // Find all tabs below the current path - $path = $router_item->path; + $path = $router_item['path']; while (isset($children[$path])) { $tabs_current = ''; $next_path = ''; foreach ($children[$path] as $item) { _menu_translate($item, $map, TRUE); - if ($item->access) { - $link = l($item->title, $item->href); // TODO options? + if ($item['access']) { + $link = l($item['title'], $item['href']); // TODO options? // The default task is always active. - if ($item->type == MENU_DEFAULT_LOCAL_TASK) { + if ($item['type'] == MENU_DEFAULT_LOCAL_TASK) { $tabs_current .= theme('menu_local_task', $link, TRUE); - $next_path = $item->path; + $next_path = $item['path']; } else { $tabs_current .= theme('menu_local_task', $link); @@ -850,12 +929,12 @@ function menu_local_tasks($level = 0) { } } $path = $next_path; - $tabs[$item->number_parts] = $tabs_current; + $tabs[$item['number_parts']] = $tabs_current; } // Find all tabs at the same level or above the current one - $parent = $router_item->tab_parent; - $path = $router_item->path; + $parent = $router_item['tab_parent']; + $path = $router_item['path']; $current = $router_item; while (isset($children[$parent])) { $tabs_current = ''; @@ -863,12 +942,12 @@ function menu_local_tasks($level = 0) { $next_parent = ''; foreach ($children[$parent] as $item) { _menu_translate($item, $map, TRUE); - if ($item->access) { - $link = l($item->title, $item->href); // TODO options? + if ($item['access']) { + $link = l($item['title'], $item['href']); // TODO options? // We check for the active tab. - if ($item->path == $path) { + if ($item['path'] == $path) { $tabs_current .= theme('menu_local_task', $link, TRUE); - $next_path = $item->tab_parent; + $next_path = $item['tab_parent']; if (isset($tab_parent[$next_path])) { $next_parent = $tab_parent[$next_path]; } @@ -880,7 +959,7 @@ function menu_local_tasks($level = 0) { } $path = $next_path; $parent = $next_parent; - $tabs[$item->number_parts] = $tabs_current; + $tabs[$item['number_parts']] = $tabs_current; } // Sort by depth ksort($tabs); @@ -898,6 +977,25 @@ function menu_secondary_local_tasks() { return menu_local_tasks(1); } +/** + * Returns the rendered local tasks. The default implementation renders + * them as tabs. + * + * @ingroup themeable + */ +function theme_menu_local_tasks() { + $output = ''; + + if ($primary = menu_primary_local_tasks()) { + $output .= "