summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2003-09-28 11:08:17 +0000
committerDries Buytaert <dries@buytaert.net>2003-09-28 11:08:17 +0000
commita5e048a5fd3b3f45fad4a94003d225d6f0401748 (patch)
tree1eb96b7fb1edc83b18e3312291d33445a056595b
parent2fe79310df8cbdcd9a749dc200ae004e37c72127 (diff)
downloadbrdo-a5e048a5fd3b3f45fad4a94003d225d6f0401748.tar.gz
brdo-a5e048a5fd3b3f45fad4a94003d225d6f0401748.tar.bz2
- Renamed some menu items for clarity and ... added basic phpDoc comments.
-rw-r--r--includes/menu.inc152
-rw-r--r--modules/admin.module4
2 files changed, 92 insertions, 64 deletions
diff --git a/includes/menu.inc b/includes/menu.inc
index 9a5e21fd3..99a298f43 100644
--- a/includes/menu.inc
+++ b/includes/menu.inc
@@ -2,7 +2,7 @@
// $Id$
/**
- * Register a menu item to the menu system.
+ * Register a menu item with the menu system.
*/
function menu($path, $title, $callback = NULL, $help = NULL, $weight = 0, $hidden = 0) {
global $_list;
@@ -12,99 +12,121 @@ function menu($path, $title, $callback = NULL, $help = NULL, $weight = 0, $hidde
}
/**
- * Returns the path of the active menu item.
+ * Returns an array with the menu items that lead to the specied path.
*/
-function menu_get_active() {
+function menu_get_trail($path) {
global $_list;
- static $path;
- if (empty($path)) {
- $path = $_GET["q"];
+ $trail = array();
- while ($path && !$_list[$path]) {
- $path = substr($path, 0, strrpos($path, "/"));
+ while ($path) {
+ if ($_list[$path]) {
+ array_unshift($trail, $path);
}
+
+ $path = substr($path, 0, strrpos($path, "/"));
}
- return $path;
+ return $trail;
}
-function menu_get_path($path) {
+/**
+ * Returns the path of the active menu item.
+ */
+function menu_get_active_item() {
global $_list;
- static $trail; // cache
-
- if (empty($trail)) {
- $trail = array();
+ static $path;
- while ($path) {
- if ($_list[$path]) {
- array_unshift($trail, $path);
- }
+ if (empty($path)) {
+ $path = $_GET["q"];
+ while ($path && !$_list[$path]) {
$path = substr($path, 0, strrpos($path, "/"));
}
}
- return $trail;
+ return $path;
}
+/**
+* Returns the title of the active menu item.
+*/
function menu_get_active_title() {
global $_list;
- if ($path = menu_get_active()) {
+ if ($path = menu_get_active_item()) {
return ucfirst($_list[$path]["title"]);
}
}
+/**
+* Returns the help associated with the active menu item.
+*/
function menu_get_active_help() {
global $_list;
- if ($path = menu_get_active()) {
+ if ($path = menu_get_active_item()) {
return $_list[$path]["help"];
}
}
-function menu_is_active($path) {
-
-}
+/**
+ * Returns an array of rendered menu items in the active breadcrumb trail.
+ */
+function menu_get_active_breadcrumb() {
-function menu_render_item($path) {
- global $_list;
+ $links[] = l(t("Home"), "");
- if ($path == $_GET["q"]) {
- $css = " class=\"active\"";
+ $trail = menu_get_trail($_GET["q"]);
+ foreach ($trail as $item) {
+ $links[] = _render_item($item);
}
- return "<a href=\"". url($path) ."\"$css>". t($_list[$path]["title"]) ."</a>";
+ return $links;
}
-function menu_active_breadcrumb() {
- $links[] = l(t("Home"), "");
+/**
+ * Execute the handler associated with the active menu item.
+ */
+function menu_execute_active_handler() {
+ global $_list;
- $trail = menu_get_path($_GET["q"]);
- foreach ($trail as $item) {
- $links[] = menu_render_item($item);
- }
+ $path = menu_get_active_item();
- return $links;
+ if ($_list[$path]["callback"]) {
+ $arg = substr($_GET["q"], strlen($path) + 1);
+ if (empty($arg)) {
+ return call_user_func($_list[$path]["callback"]);
+ }
+ else {
+ return call_user_func_array($_list[$path]["callback"], explode("/", $arg));
+ }
+ }
}
-function _menu_sort($a, $b) {
- global $_list;
+/**
+ * Returns true when the path is in the active trail.
+ */
+function menu_in_active_trail($path) {
+ static $trail;
- $a = &$_list[$a];
- $b = &$_list[$b];
+ if (empty($trail)) {
+ $trail = menu_get_trail($_GET["q"]);
+ }
- return $a["weight"] < $b["weight"] ? -1 : ($a["weight"] > $b["weight"] ? 1 : ($a["title"] < $b["title"] ? -1 : 1));
+ return in_array($path, $trail);
}
+/**
+ * Returns a rendered menu tree.
+ */
function menu_tree($parent = "") {
global $_list;
static $trail;
if (empty($tail)) {
- $trail = menu_get_path($_GET["q"]);
+ $trail = menu_get_trail($_GET["q"]);
}
if ($_list[$parent]["children"]) {
@@ -112,10 +134,10 @@ function menu_tree($parent = "") {
usort($_list[$parent]["children"], "_menu_sort");
foreach ($_list[$parent]["children"] as $item) {
if ($_list[$item]["hidden"] == 0) {
- $style = ($_list[$item]["children"] ? (in_array($item, $trail) ? "expanded" : "collapsed") : "leaf");
+ $style = ($_list[$item]["children"] ? (menu_in_active_trail($item) ? "expanded" : "collapsed") : "leaf");
$output .= "<li class=\"$style\">";
- $output .= menu_render_item($item);
- if (in_array($item, $trail)) {
+ $output .= _render_item($item);
+ if (menu_in_active_trail($item, $trail)) {
$output .= menu_tree($item);
}
$output .= "</li>\n";
@@ -127,23 +149,9 @@ function menu_tree($parent = "") {
return $output;
}
-
-function menu_execute_action() {
- global $_list;
-
- $path = menu_get_active();
-
- if ($_list[$path]["callback"]) {
- $arg = substr($_GET["q"], strlen($path) + 1);
- if (empty($arg)) {
- return call_user_func($_list[$path]["callback"]);
- }
- else {
- return call_user_func_array($_list[$path]["callback"], explode("/", $arg));
- }
- }
-}
-
+/**
+ * Query to module to build the menu.
+ */
function menu_build($type) {
/*
** Build a sequential list of all menus items.
@@ -175,4 +183,24 @@ function menu_build($type) {
}
}
+function _menu_sort($a, $b) {
+ global $_list;
+
+ $a = &$_list[$a];
+ $b = &$_list[$b];
+
+ return $a["weight"] < $b["weight"] ? -1 : ($a["weight"] > $b["weight"] ? 1 : ($a["title"] < $b["title"] ? -1 : 1));
+}
+
+function _render_item($path) {
+ global $_list;
+
+ if ($path == $_GET["q"]) {
+ $css = " class=\"active\"";
+ }
+
+ return "<a href=\"". url($path) ."\"$css>". t($_list[$path]["title"]) ."</a>";
+}
+
+
?>
diff --git a/modules/admin.module b/modules/admin.module
index 3bba68456..19a1baad4 100644
--- a/modules/admin.module
+++ b/modules/admin.module
@@ -47,14 +47,14 @@ function admin_page() {
$contents = "<small>$help</small><hr />";
}
if (arg(1)) {
- $contents .= menu_execute_action();
+ $contents .= menu_execute_active_handler();
}
else {
$contents.= watchdog_overview("actions");
$title = t("System messages");
}
- $breadcrumb = menu_active_breadcrumb();
+ $breadcrumb = menu_get_active_breadcrumb();
array_pop($breadcrumb);
$title = menu_get_active_title();