diff options
-rw-r--r-- | engine/lib/elgglib.php | 13 | ||||
-rw-r--r-- | engine/lib/plugins.php | 21 | ||||
-rw-r--r-- | mod/profile/start.php | 2 | ||||
-rw-r--r-- | views/default/navigation/toolbox.php | 3 |
4 files changed, 36 insertions, 3 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 1279b8906..1c4d02138 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -449,7 +449,18 @@ * @param array $menu_children Optionally, an array of submenu items
* @return true|false Depending on success
*/
- function add_menu($menu_name, $menu_url, $menu_children = array()) {
+ function add_menu($menu_name, $menu_url, $menu_children = array(), $context = "") {
+ global $CONFIG;
+ if (!isset($CONFIG->menucontexts)) {
+ $CONFIG->menucontexts = array();
+ }
+ if (empty($menu)) {
+ get_plugin_name();
+ }
+ if (empty($context)) {
+ $context = get_plugin_name();
+ }
+ $CONFIG->menucontexts[] = $context;
return add_to_register('menu',$menu_name,$menu_url, $menu_children);
}
diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index 8a008f278..036a2d5b9 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -45,6 +45,27 @@ }
/**
+ * Get the name of the most recent plugin to be called in the call stack.
+ *
+ * i.e., if the last plugin was in /mod/foobar/, get_plugin_name would return foo_bar.
+ *
+ * @return string|false Plugin name, or false if no plugin name was called
+ */
+ function get_plugin_name() {
+ if ($backtrace = debug_backtrace()) {
+ foreach($backtrace as $step) {
+ $file = $step['file'];
+ $file = str_replace("\\","/",$file);
+ $file = str_replace("//","/",$file);
+ if (preg_match("/mod\/([a-zA-Z0-9\-\_]*)\/start\.php$/",$file,$matches)) {
+ return $matches[1];
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
* PluginException *
* A plugin Exception, thrown when an Exception occurs relating to the plugin mechanism. Subclass for specific plugin Exceptions. diff --git a/mod/profile/start.php b/mod/profile/start.php index d76be446c..354abbd58 100644 --- a/mod/profile/start.php +++ b/mod/profile/start.php @@ -32,7 +32,7 @@ menu_item(elgg_echo('profile:yours'),$CONFIG->wwwroot . "pg/profile/" . $_SESSION['user']->username),
menu_item(elgg_echo('profile:edit'),$CONFIG->wwwroot."mod/profile/edit.php"),
menu_item(elgg_echo('profile:editicon'),$CONFIG->wwwroot."mod/profile/editicon.php"),
- ));
+ ),'profile');
}
// For now, we'll hard code the profile items as follows:
diff --git a/views/default/navigation/toolbox.php b/views/default/navigation/toolbox.php index 7da992d7d..6ee04f00b 100644 --- a/views/default/navigation/toolbox.php +++ b/views/default/navigation/toolbox.php @@ -14,7 +14,8 @@ * */ - $menu = get_register('menu'); + $menu = get_register('menu');
+ $contexts = $vars['config']->menucontexts; if (is_array($menu) && sizeof($menu) > 0) { |