summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2003-04-01 06:05:15 +0000
committerDries Buytaert <dries@buytaert.net>2003-04-01 06:05:15 +0000
commit3ad7449bc7a31917aaaf38da7e09d1131c05ddc1 (patch)
treeb3139b550851b12f1f7d0ee9c81a20afc618b225 /includes
parenta92bfba70710b21b50d981c12537176d91722588 (diff)
downloadbrdo-3ad7449bc7a31917aaaf38da7e09d1131c05ddc1.tar.gz
brdo-3ad7449bc7a31917aaaf38da7e09d1131c05ddc1.tar.bz2
- 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.
Diffstat (limited to 'includes')
-rw-r--r--includes/common.inc2
-rw-r--r--includes/menu.inc91
2 files changed, 49 insertions, 44 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 43f580a48..17f5f84b1 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -147,7 +147,7 @@ function t($string, $args = 0) {
** => url("user/register")));
*/
- $string = ($languages && function_exists("locale") ? locale($string) : $string);
+ $string = ($languages && module_exist("locale") ? locale($string) : $string);
if (!$args) {
return $string;
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 @@
<?php
// $Id$
+// TODO:
+// 1. add 'access' flag.
+
function menu_add() {
trigger_error(t("The 'menu_add()' function is deprecated."), E_USER_ERROR);
// Note that this function will be removed shortly.
@@ -10,27 +13,34 @@ function menu($path, $title, $callback = NULL, $help = NULL, $weight = 0, $hidde
global $_gmenu;
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;
+ 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 "<a href=\"".url($in_path)."\">". t($_gmenu[$in_path]["title"]) ."</a>";
-}
+ if (end($trail) == $in_path) {
+ $css = " class=\"current\"";
+ }
-function query_string() {
- return $GLOBALS["q"];
+ return "<a href=\"". url($in_path) ."\"$css>". t($_gmenu[$in_path]["title"]) ."</a>";
}
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(" &gt; ", $links);
+ return implode(" &raquo; ", $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"]);
}