From 8203c8bd6c099146591ad3391fee3c40578e2e6d Mon Sep 17 00:00:00 2001 From: ben Date: Mon, 16 Jun 2008 22:37:00 +0000 Subject: Registers contexts for each menu item. Refs #32 git-svn-id: https://code.elgg.org/elgg/trunk@938 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 13 ++++++++++++- engine/lib/plugins.php | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'engine/lib') 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 @@ -44,6 +44,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 * -- cgit v1.2.3