From 3ad7449bc7a31917aaaf38da7e09d1131c05ddc1 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Tue, 1 Apr 2003 06:05:15 +0000 Subject: - Various improvements to the menu system. - Changed the import and taxonomy module to use better URLs. Patches by Al. - Fixed locale module weirdness. Patch by Kjartan. --- includes/menu.inc | 91 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 43 deletions(-) (limited to 'includes/menu.inc') diff --git a/includes/menu.inc b/includes/menu.inc index 58422702e..3a2179376 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -1,6 +1,9 @@ fill in - $_gmenu[$path] = array("title" => $title, "callback" => $callback, "help" => $help, "weight" => $weight, "hidden" => $hidden, "children" => $_gmenu[$path]["children"]); - return true; + trigger_error("trying to add '$path' which already exists"); + } + else { + // add the menu to the flat list of menu items: + $_gmenu[$path] = array("title" => $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, "/")); } - else { // real item found - trigger_error(t("While trying to add '%path' to menu, item already exists.", array("%path" => $path)), E_USER_ERROR); - return false; + + // 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; + } + } } - } - // if this is reached we need to create a new item - $_gmenu[$path] = array("title" => $title, "callback" => $callback, "help" => $help, "weight" => $weight, "hidden" => $hidden, "children" => array()); - // does the item have an existing parent? - $parent = substr($path, 0, strrpos($path, "/")); - while (!isset($_gmenu[$parent])) { - $_gmenu[$parent] = array("children" => array($path)); - $path = $parent; - $parent = substr($parent, 0, strrpos($parent, "/")); - } - $_gmenu[$parent]["children"][] = $path; - return true; + // add the menu to the best matching parent: + $_gmenu[$parent]["children"][] = $path; + } } function menu_item($in_path) { @@ -40,38 +50,33 @@ function menu_item($in_path) { ** by an image, this would be the function to customize. */ $trail = menu_trail(); - if (end($trail) == $in_path) - return t($_gmenu[$in_path]["title"]); - else - return "". t($_gmenu[$in_path]["title"]) .""; -} + if (end($trail) == $in_path) { + $css = " class=\"current\""; + } -function query_string() { - return $GLOBALS["q"]; + return "". t($_gmenu[$in_path]["title"]) .""; } function menu_trail() { - global $_gmenu; - static $_gmenu_trail; // cache + global $_gmenu, $q; + static $trail; // cache - if (!isset($_gmenu_trail)) { - $_gmenu_trail = array(); - $cuqs = query_string(); + if (empty($trail)) { + $trail = array(); + $path = $q; - while (!empty($cuqs) && !isset($_gmenu[$cuqs])) { - $cuqs = substr($cuqs, 0, strrpos($cuqs, "/")); - } + while ($path) { + if ($_gmenu[$path]) { + $trail[] = $path; + } - if (!empty($cuqs)) { - do { - $_gmenu_trail[] = $cuqs; - $cuqs = substr($cuqs, 0, strrpos($cuqs, "/")); - } while (!empty($cuqs) && isset($_gmenu[$cuqs])); + $path = substr($path, 0, strrpos($path, "/")); } - $_gmenu_trail = array_reverse($_gmenu_trail); + + $trail = array_reverse($trail); } - return $_gmenu_trail; + return $trail; } function menu_path() { @@ -84,7 +89,7 @@ function menu_path() { $links[] = menu_item($item); } - return implode(" > ", $links); + return implode(" » ", $links); } function menu_help() { @@ -148,12 +153,12 @@ function menu_map($parent = "") { } function menu_execute_action() { - global $_gmenu; + global $_gmenu, $q; $trail = menu_trail(); $selected_menu = array_pop($trail); if ($_gmenu[$selected_menu]["callback"]) { - $arg = substr(query_string(), strlen($selected_menu) + 1); + $arg = substr($q, strlen($selected_menu) + 1); if (empty($arg)) { return call_user_func($_gmenu[$selected_menu]["callback"]); } -- cgit v1.2.3