diff options
author | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-08-14 10:47:17 +0000 |
---|---|---|
committer | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-08-14 10:47:17 +0000 |
commit | 26469396670f21e3f96922c839a397158956d351 (patch) | |
tree | fbecaac1c550af47639699a6f7a2037899fbe80b /engine | |
parent | f19a6d8e1980e41988531cbef263a1351a7631ea (diff) | |
download | elgg-26469396670f21e3f96922c839a397158956d351.tar.gz elgg-26469396670f21e3f96922c839a397158956d351.tar.bz2 |
Added the facility to group submenus
git-svn-id: https://code.elgg.org/elgg/trunk@1915 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r-- | engine/lib/elgglib.php | 79 |
1 files changed, 49 insertions, 30 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 763b69911..a793e7bee 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -525,10 +525,15 @@ * @param string $label The human-readable label
* @param string $link The URL of the submenu item
*/
- function add_submenu_item($label, $link) {
+ function add_submenu_item($label, $link, $group = 'main') {
global $CONFIG;
- add_to_register('submenu',$label,$link);
+ if (!isset($CONFIG->submenu)) $CONFIG->submenu = array();
+ if (!isset($CONFIG->submenu[$group])) $CONFIG->submenu[$group] = array();
+ $item = new stdClass;
+ $item->value = $link;
+ $item->name = $label;
+ $CONFIG->submenu[$group][] = $item;
}
@@ -539,52 +544,66 @@ */
function get_submenu() {
- $submenu = "";
+ $submenu_total = "";
global $CONFIG;
- if ($submenu_register = get_register('submenu')) {
+ if (isset($CONFIG->submenu) && $submenu_register = $CONFIG->submenu) {
$preselected = false;
$comparevals = array();
$maxcompareval = 999999;
- foreach($submenu_register as $key => $item) {
+ asort($CONFIG->submenu);
+
+ foreach($submenu_register as $groupname => $submenu_register_group) {
+
+ $submenu = "";
- $comparevals[$key] = (levenshtein($item->value, $_SERVER['REQUEST_URI']));
- if ($comparevals[$key] < $maxcompareval) {
- $maxcompareval = $comparevals[$key];
- $preselected = $key;
+ foreach($submenu_register_group as $key => $item) {
+
+ $comparevals[$key] = (levenshtein($item->value, $_SERVER['REQUEST_URI']));
+ if ($comparevals[$key] < $maxcompareval) {
+ $maxcompareval = $comparevals[$key];
+ $preselected = $key;
+ }
+
}
- }
-
- foreach($submenu_register as $key => $item) {
-
- if (!$preselected) {
- if (substr_count($item->value, $_SERVER['REQUEST_URI'])) {
- $selected = true;
- } else {
- $selected = false;
- }
- } else {
- if ($key == $preselected) {
- $selected = true;
+ foreach($submenu_register_group as $key => $item) {
+
+ if (!$preselected) {
+ if (substr_count($item->value, $_SERVER['REQUEST_URI'])) {
+ $selected = true;
+ } else {
+ $selected = false;
+ }
} else {
- $selected = false;
+ if ($key == $preselected) {
+ $selected = true;
+ } else {
+ $selected = false;
+ }
}
+
+ $submenu .= elgg_view('canvas_header/submenu_template',
+ array(
+ 'href' => $item->value,
+ 'label' => $item->name,
+ 'selected' => $selected,
+ ));
+
}
- $submenu .= elgg_view('canvas_header/submenu_template',
- array(
- 'href' => $item->value,
- 'label' => $item->name,
- 'selected' => $selected,
- ));
+ $submenu_total .= elgg_view('canvas_header/submenu_group', array(
+ 'submenu' => $submenu,
+ 'group_name' => $groupname
+ ));
}
+
}
- return $submenu;
+ return $submenu_total;
}
|