function menu_get_item
Search API
7.x menu.inc | menu_get_item($path) |
6.x menu.inc | menu_get_item($path) |
4.x menu.inc | menu_get_item($path) |
5.x menu.inc | menu_get_item($path) |
Figure out which menu_router path matches the supplied path and return it.
6 calls to menu_get_item()
- fp_build_tab_array in includes/
theme.inc - Looks at the current page array and returns a valid $tab_array Meant for the top of the screen.
- fp_display_page in includes/
theme.inc - Output the contents of the $page variable to the screen. $page is an array containing details about the page, as well as its original menu item (router_item) definition.
- menu_execute_page_request in includes/
menu.inc - menu_get_items_beginning_with in includes/
menu.inc - Return menu_items whose path begins with the menu_root. Ex: "tools" would return tools/fun and tools/here/there
- menu_get_items_in_tab_family in includes/
menu.inc
File
- includes/
menu.inc, line 205
Code
function menu_get_item($path) {
// Since the menu item may be using wildcards, we must
// try to figure out exactly which defined path is the best one
// to take.
$menu_items = array();
// To cut down on the amount we need to query, we will use a global variable.
if (!isset($GLOBALS ["fp_menu_items"]) || !is_array($GLOBALS ["fp_menu_items"]) || count($GLOBALS ["fp_menu_items"]) == 0) {
// The global array is not set. Let's populate it from the database.
$res = db_query("SELECT path FROM menu_router");
while ($cur = db_fetch_array($res)) {
$GLOBALS ["fp_menu_items"][] = $cur ["path"];
}
}
$menu_items = $GLOBALS ["fp_menu_items"];
// Okay, first things first, does the path *exactly* match anything in our GLOBALS array?
if (in_array($path, $menu_items)) {
return menu_get_menu_router_item_from_db($path);
}
// If we are here, we didn't see an exact match. That may mean we are using wildcards,
// and therefore we should pick only the best match.
// For example, if the path is "node/5/edit", we should return the
// menu_router item "node/%/edit", but not "node/%/%". We will figure this out
// by breaking up our paths into pieces, and then comparing each piece, and scoring URLs
// as we do on how many levels they match on. The URL with the higest match wins.
$defined_score = array();
// Now, go through and find the best URL definition that matches the given URL.
$given_pieces = explode("/", $path);
foreach ($menu_items as $defined_url) {
$defined_pieces = explode("/", $defined_url);
// First, make only look for the ones with the exact same count as us...
if (count($defined_pieces) != count($given_pieces)) {
continue;
}
if (!isset($defined_score [$defined_url])) {
$defined_score [$defined_url] = 0;
}
$defined_score [$defined_url];
// Okay, now go through the pieces and compare.
foreach (++$defined_pieces as $c => $defined_piece) {
// If it's exactly a match, then inc its score.
if ($defined_piece == $given_pieces [$c]) {
$defined_score [$defined_url];
}
// If it's totally off, then kick it out!
if (++$defined_piece != "%" && $defined_piece != $given_pieces [$c]) {
unset($defined_score [$defined_url]);
break;
}
}
}
arsort($defined_score);
$best_match_path = "";
if (count($defined_score) > 0) {
$best_match_path = key($defined_score);
}
// Okay, the best_match_path is the one that best fits our path. Let's return the details
// for it from menu_router.
if ($best_match_path) {
return menu_get_menu_router_item_from_db($best_match_path);
}
// Else, nothing was found!
return NULL;
}