$title, "callback" => $callback, "help" => $help, "weight" => $weight, "hidden" => $hidden, "children" => array()); // find the best matching parent item: $parent = substr($path, 0, strrpos($path, "/")); while ($parent && !$_gmenu[$parent]) { $parent = substr($parent, 0, strrpos($parent, "/")); } // check if any items need to be lowered: if ($parent) { foreach ($_gmenu[$parent]["children"] as $key => $item) { if (strstr($item, $path)) { // remove the item from its parent: unset($_gmenu[$parent]["children"][$key]); // add the item to its new parent: $_gmenu[$path]["children"][] = $item; } } } // add the menu to the best matching parent: $_gmenu[$parent]["children"][] = $path; } } function menu_item($in_path) { global $_gmenu; /* ** If you want to theme your links, or if you want to replace them ** by an image, this would be the function to customize. */ $trail = menu_trail(); if (end($trail) == $in_path) { $css = " class=\"current\""; } return "". t($_gmenu[$in_path]["title"]) .""; } function menu_trail() { global $_gmenu; static $trail; // cache if (empty($trail)) { $trail = array(); $path = $_GET["q"]; while ($path) { if ($_gmenu[$path]) { $trail[] = $path; } $path = substr($path, 0, strrpos($path, "/")); } $trail = array_reverse($trail); } return $trail; } function menu_path() { $trail = menu_trail(); $links = array(); foreach ($trail as $item) { $links[] = menu_item($item); } return implode(" » ", $links); } function menu_help() { global $_gmenu; $path = menu_trail(); if ($path) { $item = array_pop($path); $output = $_gmenu[$item]["help"]; } return @$output; } function _menu_sort($a, $b) { global $_gmenu; $a = &$_gmenu[$a]; $b = &$_gmenu[$b]; return $a["weight"] < $b["weight"] ? -11 : ($a["weight"] > $b["weight"] ? 1 : ($a["name"] < $b["name"] ? -1 : 1)); } function menu_tree($parent = "") { global $_gmenu; if ($_gmenu[$parent]["children"]) { $output = "\n\n"; } return $output; } function menu_map($parent = "") { global $_gmenu; $output = ""; return $output; } function menu_execute_action() { global $_gmenu; $trail = menu_trail(); $selected_menu = array_pop($trail); if ($_gmenu[$selected_menu]["callback"]) { $arg = substr($_GET["q"], strlen($selected_menu) + 1); if (empty($arg)) { return call_user_func($_gmenu[$selected_menu]["callback"]); } else { return call_user_func_array($_gmenu[$selected_menu]["callback"], explode("/", $arg)); } } } function menu_build($type) { // Empty the existing menu tree (if any): unset($GLOBALS["_gmenu"]); // Build the menu tree: module_invoke_all("link", $type); } ?>