]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
persist 'selected' state of site menu
authorMatt Beckett <beck24@gmail.com>
Sun, 15 Jul 2012 07:40:02 +0000 (01:40 -0600)
committerMatt Beckett <beck24@gmail.com>
Sun, 15 Jul 2012 07:40:02 +0000 (01:40 -0600)
engine/lib/navigation.php

index 4ff009bfb7cc14dacfa795a96d9d5c50341c5d31..8845d5164f9f28b3a3cbc37f8c5f25223676224a 100644 (file)
@@ -308,6 +308,41 @@ function elgg_site_menu_setup($hook, $type, $return, $params) {
                        $return['more'] = array_splice($return['default'], $max_display_items);
                }
        }
+       
+       // check if we have anything selected
+       $selected = false;
+       foreach ($return as $section_name => $section) {
+               foreach ($section as $key => $item) {
+                       if ($item->getSelected()) {
+                               $selected = true;
+                               break 2;
+                       }
+               }
+       }
+       
+       if (!$selected) {
+               // nothing selected, match by handler
+               $handler = get_input('handler');
+               
+               foreach ($return as $section_name => $section) {
+                       foreach ($section as $key => $item) {
+                               // determine the 'handler' of this url, if there is one
+                               if (strpos($item->getHref(), elgg_get_site_url()) === 0) {
+                                       // this is an internal link, so it has a page handler
+                                       $path = array(str_replace(elgg_get_site_url(), '', $item->getHref()));
+                                       $separators = array('/', '?', '#');
+                                       foreach ($separators as $separator) {
+                                               $path = explode($separator, $path[0]);
+                                       }
+                                       
+                                       if ($path[0] == $handler) {
+                                               $return[$section_name][$key]->setSelected(true);
+                                               break 2;
+                                       }
+                               }
+                       }
+               }
+       }
 
        return $return;
 }