2002-12-24 15:40:32 +00:00
|
|
|
<?php
|
2003-03-12 09:51:30 +00:00
|
|
|
// $Id$
|
2002-12-24 15:40:32 +00:00
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
function menu_add() {
|
2003-02-27 22:45:00 +00:00
|
|
|
trigger_error(t("The 'menu_add()' function is deprecated."), E_USER_ERROR);
|
|
|
|
// Note that this function will be removed shortly.
|
2002-12-24 15:40:32 +00:00
|
|
|
}
|
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
function menu($path, $title, $callback = NULL, $help = NULL, $weight = 0, $hidden = 0) {
|
|
|
|
global $_gmenu;
|
2003-01-14 20:33:42 +00:00
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
if (isset($_gmenu[$path])) {
|
|
|
|
if (empty($_gmenu[$path]["callback"])) { // dummy item -> fill in
|
|
|
|
$_gmenu[$path] = array("title" => $title, "callback" => $callback, "help" => $help, "weight" => $weight, "hidden" => $hidden, "children" => $_gmenu[$path]["children"]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
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;
|
2003-01-14 20:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-20 22:44:51 +00:00
|
|
|
// 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;
|
2003-01-14 20:33:42 +00:00
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
2002-12-24 15:40:32 +00:00
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
function menu_item($in_path) {
|
|
|
|
global $_gmenu;
|
2002-12-24 15:40:32 +00:00
|
|
|
/*
|
|
|
|
** If you want to theme your links, or if you want to replace them
|
|
|
|
** by an image, this would be the function to customize.
|
|
|
|
*/
|
2003-02-20 22:44:51 +00:00
|
|
|
$trail = menu_trail();
|
|
|
|
if (end($trail) == $in_path)
|
|
|
|
return t($_gmenu[$in_path]["title"]);
|
|
|
|
else
|
|
|
|
return "<a href=\"".url($in_path)."\">". t($_gmenu[$in_path]["title"]) ."</a>";
|
|
|
|
}
|
2002-12-24 15:40:32 +00:00
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
function query_string() {
|
|
|
|
return $GLOBALS["q"];
|
2002-12-24 15:40:32 +00:00
|
|
|
}
|
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
function menu_trail() {
|
|
|
|
global $_gmenu;
|
|
|
|
static $_gmenu_trail; // cache
|
2002-12-24 15:40:32 +00:00
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
if (!isset($_gmenu_trail)) {
|
|
|
|
$_gmenu_trail = array();
|
|
|
|
$cuqs = query_string();
|
2002-12-24 15:40:32 +00:00
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
while (!empty($cuqs) && !isset($_gmenu[$cuqs])) {
|
|
|
|
$cuqs = substr($cuqs, 0, strrpos($cuqs, "/"));
|
|
|
|
}
|
2002-12-24 15:40:32 +00:00
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
if (!empty($cuqs)) {
|
|
|
|
do {
|
|
|
|
$_gmenu_trail[] = $cuqs;
|
|
|
|
$cuqs = substr($cuqs, 0, strrpos($cuqs, "/"));
|
|
|
|
} while (!empty($cuqs) && isset($_gmenu[$cuqs]));
|
|
|
|
}
|
|
|
|
$_gmenu_trail = array_reverse($_gmenu_trail);
|
2002-12-24 15:40:32 +00:00
|
|
|
}
|
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
return $_gmenu_trail;
|
2002-12-24 15:40:32 +00:00
|
|
|
}
|
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
function menu_path() {
|
2002-12-24 15:40:32 +00:00
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
$trail = menu_trail();
|
2002-12-24 15:40:32 +00:00
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
$links = array();
|
2002-12-24 15:40:32 +00:00
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
foreach ($trail as $item) {
|
|
|
|
$links[] = menu_item($item);
|
2002-12-24 15:40:32 +00:00
|
|
|
}
|
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
return implode(" > ", $links);
|
2002-12-24 15:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function menu_help() {
|
2003-02-20 22:44:51 +00:00
|
|
|
global $_gmenu;
|
2002-12-24 15:40:32 +00:00
|
|
|
$path = menu_trail();
|
|
|
|
if ($path) {
|
|
|
|
$item = array_pop($path);
|
2003-02-20 22:44:51 +00:00
|
|
|
$output = $_gmenu[$item]["help"];
|
2002-12-24 15:40:32 +00:00
|
|
|
}
|
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
return @$output;
|
2002-12-24 15:40:32 +00:00
|
|
|
}
|
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
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));
|
|
|
|
}
|
2002-12-24 15:40:32 +00:00
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
function menu_tree($parent = "") {
|
|
|
|
global $_gmenu;
|
|
|
|
|
|
|
|
if ($_gmenu[$parent]["children"]) {
|
|
|
|
$output = "\n<ul>\n";
|
|
|
|
usort($_gmenu[$parent]["children"], "_menu_sort");
|
|
|
|
foreach ($_gmenu[$parent]["children"] as $item) {
|
|
|
|
if ($_gmenu[$item]["hidden"] == 0) {
|
2003-02-25 19:48:55 +00:00
|
|
|
$trail = menu_trail($item);
|
|
|
|
$style = ($_gmenu[$item]["children"] ? (in_array($item, $trail) ? "expanded" : "collapsed") : "leaf");
|
|
|
|
$output .= "<li class=\"$style\">";
|
2003-02-20 22:44:51 +00:00
|
|
|
$output .= menu_item($item);
|
2003-02-25 19:48:55 +00:00
|
|
|
if (in_array($item, $trail)) {
|
2003-02-20 22:44:51 +00:00
|
|
|
$output .= menu_tree($item);
|
|
|
|
}
|
|
|
|
$output .= "</li>\n";
|
|
|
|
}
|
2002-12-30 15:54:06 +00:00
|
|
|
}
|
2003-02-20 22:44:51 +00:00
|
|
|
$output .= "</ul>\n";
|
2002-12-24 15:40:32 +00:00
|
|
|
}
|
|
|
|
|
2002-12-30 15:54:06 +00:00
|
|
|
return $output;
|
2002-12-24 15:40:32 +00:00
|
|
|
}
|
|
|
|
|
2003-01-26 13:27:59 +00:00
|
|
|
function menu_map($parent = "") {
|
2003-02-20 22:44:51 +00:00
|
|
|
global $_gmenu;
|
2003-01-26 13:27:59 +00:00
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
$output = "<ul>";
|
|
|
|
usort($_gmenu[$parent]["children"], "_menu_sort");
|
|
|
|
foreach ($_gmenu[$parent]["children"] as $item) {
|
|
|
|
if ($_gmenu[$item]["hidden"] == 0) {
|
2003-01-27 19:15:20 +00:00
|
|
|
$output .= "<li>";
|
|
|
|
$output .= menu_item($item);
|
2003-02-20 22:44:51 +00:00
|
|
|
$output .= menu_map($item);
|
2003-01-27 19:15:20 +00:00
|
|
|
$output .= "</li>";
|
2003-01-26 13:27:59 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-20 22:44:51 +00:00
|
|
|
$output .= "</ul>";
|
2003-01-26 13:27:59 +00:00
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
function menu_execute_action() {
|
|
|
|
global $_gmenu;
|
|
|
|
$trail = menu_trail();
|
|
|
|
$selected_menu = array_pop($trail);
|
2003-01-26 13:27:59 +00:00
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
if ($_gmenu[$selected_menu]["callback"]) {
|
2003-02-25 19:48:55 +00:00
|
|
|
$arg = substr(query_string(), 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));
|
|
|
|
}
|
2002-12-24 15:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-12 21:46:14 +00:00
|
|
|
function menu_build($type) {
|
|
|
|
|
|
|
|
// Empty the existing menu tree (if any):
|
|
|
|
unset($GLOBALS["_gmenu"]);
|
|
|
|
|
|
|
|
// Build the menu tree:
|
|
|
|
module_invoke_all("link", $type);
|
|
|
|
}
|
|
|
|
|
2003-02-20 22:44:51 +00:00
|
|
|
?>
|